xbmc
GUIPortList.h
1 /*
2  * Copyright (C) 2021 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 "IPortList.h"
12 #include "addons/AddonEvents.h"
13 #include "games/GameTypes.h"
14 #include "games/controllers/ControllerTypes.h"
15 #include "games/controllers/dialogs/ControllerSelect.h"
16 #include "games/controllers/types/ControllerTree.h"
17 
18 #include <map>
19 #include <memory>
20 #include <string>
21 
22 class CFileItemList;
23 class CGUIViewControl;
24 class CGUIWindow;
25 
26 namespace KODI
27 {
28 namespace GAME
29 {
33 class CGUIPortList : public IPortList
34 {
35 public:
36  CGUIPortList(CGUIWindow& window);
37  ~CGUIPortList() override;
38 
39  // Implementation of IPortList
40  void OnWindowLoaded() override;
41  void OnWindowUnload() override;
42  bool Initialize(GameClientPtr gameClient) override;
43  void Deinitialize() override;
44  bool HasControl(int controlId) override;
45  int GetCurrentControl() override;
46  void Refresh() override;
47  void FrameMove() override;
48  void SetFocused() override;
49  bool OnSelect() override;
50  void ResetPorts() override;
51 
52 private:
53  // Add-on API
54  void OnEvent(const ADDON::AddonEvent& event);
55 
56  bool AddItems(const CPortNode& port, unsigned int& itemId, const std::string& itemLabel);
57  void CleanupItems();
58  void OnItemFocus(unsigned int itemIndex);
59  void OnItemSelect(unsigned int itemIndex);
60 
61  // Controller selection callback
62  void OnControllerSelected(const CPortNode& port, const ControllerPtr& controller);
63 
64  static std::string GetLabel(const CPortNode& port);
65 
66  // Construction parameters
67  CGUIWindow& m_guiWindow;
68 
69  // GUI parameters
70  CControllerSelect m_controllerSelectDialog;
71  std::string m_focusedPort; // Address of focused port
72  int m_currentItem{-1}; // Index of the selected item, or -1 if no item is selected
73  std::unique_ptr<CGUIViewControl> m_viewControl;
74  std::unique_ptr<CFileItemList> m_vecItems;
75 
76  // Game parameters
77  GameClientPtr m_gameClient;
78  std::map<unsigned int, std::string> m_itemToAddress; // item index -> port address
79  std::map<std::string, unsigned int> m_addressToItem; // port address -> item index
80 };
81 } // namespace GAME
82 } // namespace KODI
void Refresh() override
Refresh the contents of the list.
Definition: GUIPortList.cpp:100
Definition: GUIViewControl.h:19
bool HasControl(int controlId) override
Query if a control with the given ID belongs to this list.
Definition: GUIPortList.cpp:90
Definition: GUIPortList.h:33
void SetFocused() override
The port list has been focused in the GUI.
Definition: GUIPortList.cpp:138
Represents a list of files.
Definition: FileItem.h:721
Collection of nodes that can be connected to this port.
Definition: PortNode.h:28
void Deinitialize() override
Deinitialize resources.
Definition: GUIPortList.cpp:79
void OnWindowUnload() override
Callback when the GUI window is unloaded.
Definition: GUIPortList.cpp:56
Definition: AudioDecoder.h:18
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
std::shared_ptr< CGameClient > GameClientPtr
Smart pointer to a game client (CGameClient)
Definition: GameTypes.h:29
Definition: AddonEvents.h:18
Definition: ControllerSelect.h:24
A list populated by controller ports for the port setup window.
Definition: IPortList.h:32
void OnWindowLoaded() override
Callback when the GUI window is loaded.
Definition: GUIPortList.cpp:49
void FrameMove() override
Callback when a frame is rendered by the GUI.
Definition: GUIPortList.cpp:127
bool OnSelect() override
The port list has been selected.
Definition: GUIPortList.cpp:143
int GetCurrentControl() override
Query the ID of the current control in this list.
Definition: GUIPortList.cpp:95
Definition: GUIWindow.h:58
bool Initialize(GameClientPtr gameClient) override
Initialize resources.
Definition: GUIPortList.cpp:61
void ResetPorts() override
Reset the ports to their game add-on&#39;s default configuration.
Definition: GUIPortList.cpp:155