xbmc
GUIAgentList.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 "IAgentList.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 {
34 class CGUIAgentList : public IAgentList, public Observer
35 {
36 public:
37  CGUIAgentList(CGUIWindow& window);
38  ~CGUIAgentList() override;
39 
40  // Implementation of IAgentList
41  void OnWindowLoaded() override;
42  void OnWindowUnload() override;
43  bool Initialize(GameClientPtr gameClient) override;
44  void Deinitialize() override;
45  bool HasControl(int controlId) const override;
46  int GetCurrentControl() const override;
47  void FrameMove() override;
48  void Refresh() override;
49  void SetFocused() override;
50  void OnSelect() override;
51 
52  // Implementation of Observer
53  void Notify(const Observable& obs, const ObservableMessage msg) override;
54 
55 private:
56  // Add-on API
57  void OnEvent(const ADDON::AddonEvent& event);
58 
59  // GUI functions
60  void AddItem(const CGameAgent& agent);
61  void CleanupItems();
62  void OnItemFocus(unsigned int itemIndex);
63  void OnAgentFocus(const std::string& focusedAgent);
64  void OnItemSelect(unsigned int itemIndex);
65  void OnAgentSelect(const CFileItem& selectedAgentItem);
66  void ShowAgentDialog(const CGameAgent& agent);
67 
68  // Construction parameters
69  CGUIWindow& m_guiWindow;
70 
71  // GUI parameters
72  std::unique_ptr<CGUIViewControl> m_viewControl;
73  std::unique_ptr<CFileItemList> m_vecItems;
74  unsigned int m_currentItem{0};
75  std::string m_currentAgent;
76 
77  // Game parameters
78  GameClientPtr m_gameClient;
79 };
80 } // namespace GAME
81 } // namespace KODI
Definition: GUIViewControl.h:19
void SetFocused() override
The agent list has been focused in the GUI.
Definition: GUIAgentList.cpp:168
void OnWindowUnload() override
Callback when the GUI window is unloaded.
Definition: GUIAgentList.cpp:61
bool Initialize(GameClientPtr gameClient) override
Initialize resources.
Definition: GUIAgentList.cpp:66
void Notify(const Observable &obs, const ObservableMessage msg) override
Process a message from an observable.
Definition: GUIAgentList.cpp:180
A list populated by game-playing agents (CGameAgent)
Definition: IAgentList.h:35
Represents a list of files.
Definition: FileItem.h:721
bool HasControl(int controlId) const override
Query if a control with the given ID belongs to this list.
Definition: GUIAgentList.cpp:105
void OnSelect() override
The agent list has been selected in the GUI.
Definition: GUIAgentList.cpp:173
void Deinitialize() override
Deinitialize resources.
Definition: GUIAgentList.cpp:89
Definition: GUIAgentList.h:34
Definition: AudioDecoder.h:18
void OnWindowLoaded() override
Callback when the GUI window is loaded.
Definition: GUIAgentList.cpp:54
Definition: Observer.h:31
std::shared_ptr< CGameClient > GameClientPtr
Smart pointer to a game client (CGameClient)
Definition: GameTypes.h:29
Definition: AddonEvents.h:18
Definition: GUIWindow.h:58
void Refresh() override
Refresh the contents of the list.
Definition: GUIAgentList.cpp:131
void FrameMove() override
Called once per frame.
Definition: GUIAgentList.cpp:115
Definition: Observer.h:44
Class to represent a game player (a.k.a. agent)
Definition: GameAgent.h:31
Represents a file on a share.
Definition: FileItem.h:102
int GetCurrentControl() const override
Query the ID of the current control in this list.
Definition: GUIAgentList.cpp:110