kodi
GUIAgentControllerList.h
1 /*
2  * Copyright (C) 2022-2024 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 "IAgentControllerList.h"
12 #include "addons/AddonEvents.h"
13 #include "games/GameTypes.h"
14 #include "games/controllers/ControllerTypes.h"
15 #include "utils/Observer.h"
16 
17 #include <map>
18 #include <memory>
19 #include <set>
20 #include <string>
21 
22 class CFileItem;
23 class CFileItemList;
24 class CGUIViewControl;
25 class CGUIWindow;
26 
27 namespace KODI
28 {
29 namespace GAME
30 {
31 class CAgentController;
32 
37 {
38 public:
40  ~CGUIAgentControllerList() override;
41 
42  // Implementation of IAgentControllerList
43  void OnWindowLoaded() override;
44  void OnWindowUnload() override;
45  bool Initialize(GameClientPtr gameClient) override;
46  void Deinitialize() override;
47  bool HasControl(int controlId) const override;
48  int GetCurrentControl() const override;
49  void FrameMove() override;
50  void Refresh() override;
51  void SetFocused() override;
52  void OnSelect() override;
53 
54  // Implementation of Observer
55  void Notify(const Observable& obs, const ObservableMessage msg) override;
56 
57 private:
58  // Add-on API
59  void OnEvent(const ADDON::AddonEvent& event);
60 
61  // GUI functions
62  void AddItem(const CAgentController& agentController);
63  void CleanupItems();
64  void OnItemFocus(unsigned int itemIndex);
65  void OnControllerFocus(const std::string& focusedAgent);
66  void OnItemSelect(unsigned int itemIndex);
67  void OnControllerSelect(const CFileItem& selectedAgentItem);
68  void ShowControllerDialog(const CAgentController& agentController);
69 
70  // Construction parameters
71  CGUIWindow& m_guiWindow;
72 
73  // GUI parameters
74  std::unique_ptr<CGUIViewControl> m_viewControl;
75  std::unique_ptr<CFileItemList> m_vecItems;
76  unsigned int m_currentItem{0};
77  std::string m_currentAgent;
78 
79  // Game parameters
80  GameClientPtr m_gameClient;
81 };
82 } // namespace GAME
83 } // namespace KODI
Definition: GUIViewControl.h:19
Definition: GUIAgentControllerList.h:36
A list populated by the controllers of game-playing agents (CGameAgent)
Definition: IAgentControllerList.h:29
void Deinitialize() override
Deinitialize resources.
Definition: GUIAgentControllerList.cpp:90
void Notify(const Observable &obs, const ObservableMessage msg) override
Process a message from an observable.
Definition: GUIAgentControllerList.cpp:182
Represents a list of files.
Definition: FileItem.h:702
void OnWindowLoaded() override
Callback when the GUI window is loaded.
Definition: GUIAgentControllerList.cpp:54
Class to represent the controller of a game player (a.k.a. agent)
Definition: AgentController.h:33
void OnSelect() override
The agent list has been selected in the GUI.
Definition: GUIAgentControllerList.cpp:175
void FrameMove() override
Called once per frame.
Definition: GUIAgentControllerList.cpp:116
Definition: AudioDecoder.h:18
Definition: Observer.h:31
std::shared_ptr< CGameClient > GameClientPtr
Smart pointer to a game client (CGameClient)
Definition: GameTypes.h:29
Definition: AddonEvents.h:18
void OnWindowUnload() override
Callback when the GUI window is unloaded.
Definition: GUIAgentControllerList.cpp:61
bool Initialize(GameClientPtr gameClient) override
Initialize resources.
Definition: GUIAgentControllerList.cpp:66
void SetFocused() override
The agent list has been focused in the GUI.
Definition: GUIAgentControllerList.cpp:170
int GetCurrentControl() const override
Query the ID of the current control in this list.
Definition: GUIAgentControllerList.cpp:111
bool HasControl(int controlId) const override
Query if a control with the given ID belongs to this list.
Definition: GUIAgentControllerList.cpp:106
Definition: GUIWindow.h:58
Definition: Observer.h:44
void Refresh() override
Refresh the contents of the list.
Definition: GUIAgentControllerList.cpp:132
Represents a file on a share.
Definition: FileItem.h:102