xbmc
GUIGameControllerProvider.h
1 /*
2  * Copyright (C) 2022-2023 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "games/controllers/ControllerTypes.h"
12 #include "listproviders/IListProvider.h"
13 
14 #include <memory>
15 #include <stdint.h>
16 #include <string>
17 #include <vector>
18 
19 namespace KODI
20 {
21 namespace GAME
22 {
41 {
42 public:
55  CGUIGameControllerProvider(unsigned int portCount,
56  int portIndex,
57  const std::string& peripheralLocation,
58  uint32_t alignment,
59  int parentID);
61 
62  ~CGUIGameControllerProvider() override;
63 
64  // Implementation of IListProvider
65  std::unique_ptr<IListProvider> Clone() override;
66  bool Update(bool forceRefresh) override;
67  void Fetch(std::vector<CGUIListItemPtr>& items) override;
68  bool OnClick(const CGUIListItemPtr& item) override { return false; }
69  bool OnInfo(const CGUIListItemPtr& item) override { return false; }
70  bool OnContextMenu(const CGUIListItemPtr& item) override { return false; }
71  void SetDefaultItem(int item, bool always) override {}
72  int GetDefaultItem() const override { return -1; }
73  bool AlwaysFocusDefaultItem() const override { return false; }
74 
75  // Game functions
76  ControllerPtr GetControllerProfile() const { return m_controllerProfile; }
77  void SetControllerProfile(ControllerPtr controllerProfile);
78  unsigned int GetPortCount() const { return m_portCount; }
79  void SetPortCount(unsigned int portCount);
80  int GetPortIndex() const { return m_portIndex; }
81  void SetPortIndex(int portIndex);
82  const std::string& GetPeripheralLocation() const { return m_peripheralLocation; }
83  void SetPeripheralLocation(const std::string& peripheralLocation);
84 
85 private:
86  // GUI functions
87  void InitializeItems();
88  void UpdateItems();
89 
90  // Game parameters
91  ControllerPtr m_controllerProfile;
92  unsigned int m_portCount{0};
93  int m_portIndex{-1}; // Not connected
94  std::string m_peripheralLocation;
95 
96  // GUI parameters
97  const uint32_t m_alignment;
98  std::vector<std::shared_ptr<CGUIListItem>> m_items;
99  bool m_bDirty{true};
100 };
101 } // namespace GAME
102 } // namespace KODI
An interface for providing lists to UI containers.
Definition: IListProvider.h:22
Controller list provider for the IAgentList control in the Player Viewer (GameAgents) window...
Definition: GUIGameControllerProvider.h:40
void SetDefaultItem(int item, bool always) override
Set the default item to focus. For backwards compatibility.
Definition: GUIGameControllerProvider.h:71
bool AlwaysFocusDefaultItem() const override
Whether to always focus the default item.
Definition: GUIGameControllerProvider.h:73
bool OnInfo(const CGUIListItemPtr &item) override
Open the info dialog for an item provided by this IListProvider.
Definition: GUIGameControllerProvider.h:69
int GetDefaultItem() const override
The default item to focus.
Definition: GUIGameControllerProvider.h:72
bool OnContextMenu(const CGUIListItemPtr &item) override
Open the context menu for an item provided by this IListProvider.
Definition: GUIGameControllerProvider.h:70
bool OnClick(const CGUIListItemPtr &item) override
Click event on an item.
Definition: GUIGameControllerProvider.h:68
void Fetch(std::vector< CGUIListItemPtr > &items) override
Fetch the current list of items.
Definition: GUIGameControllerProvider.cpp:68
std::unique_ptr< IListProvider > Clone() override
Create an instance of the derived class. Allows for polymorphic copies.
Definition: GUIGameControllerProvider.cpp:56
Definition: AudioDecoder.h:18
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
CGUIGameControllerProvider(unsigned int portCount, int portIndex, const std::string &peripheralLocation, uint32_t alignment, int parentID)
Construct a game controller provider for the player&#39;s controller list in the Player Viewer dialog...
Definition: GUIGameControllerProvider.cpp:30
bool Update(bool forceRefresh) override
Update the list content.
Definition: GUIGameControllerProvider.cpp:61