| 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 |
{ |
| 30 |
/*! |
| 31 |
* \ingroup game |
| 32 |
*/ |
| 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 |