| 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 |
#include "GUIAgentWindow.h" |
| 10 |
|
| 11 |
#include "GUIAgentControllerList.h" |
| 12 |
#include "GUIAgentDefines.h" |
| 13 |
#include "ServiceBroker.h" |
| 14 |
#include "addons/AddonManager.h" |
| 15 |
#include "addons/IAddon.h" |
| 16 |
#include "addons/addoninfo/AddonType.h" |
| 17 |
#include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h" |
| 18 |
#include "cores/RetroPlayer/guibridge/GUIGameSettingsHandle.h" |
| 19 |
#include "games/addons/GameClient.h" |
| 20 |
#include "games/controllers/types/ControllerTree.h" |
| 21 |
#include "games/ports/guicontrols/GUIActivePortList.h" |
| 22 |
#include "guilib/GUIButtonControl.h" |
| 23 |
#include "guilib/GUIControl.h" |
| 24 |
#include "guilib/GUIMessage.h" |
| 25 |
#include "guilib/WindowIDs.h" |
| 26 |
#include "input/actions/ActionIDs.h" |
| 27 |
#include "utils/StringUtils.h" |
| 28 |
|
| 29 |
using namespace KODI; |
| 30 |
using namespace GAME; |
| 31 |
|
| 32 |
CGUIAgentWindow::CGUIAgentWindow() |
| 33 |
: CGUIDialog(WINDOW_DIALOG_GAME_AGENTS, AGENT_DIALOG_XML), |
| 34 |
m_portList(std::make_unique<CGUIActivePortList>(*this, CONTROL_ACTIVE_PORT_LIST, true)), |
| 35 |
m_controllerList(std::make_unique<CGUIAgentControllerList>(*this)) |
| 36 |
{ |
| 37 |
// Initialize CGUIWindow |
| 38 |
m_loadType = KEEP_IN_MEMORY; |
| 39 |
} |
| 40 |
|
| 41 |
CGUIAgentWindow::~CGUIAgentWindow() = default; |
| 42 |
|
| 43 |
bool CGUIAgentWindow::OnMessage(CGUIMessage& message) |
| 44 |
{ |
| 45 |
// Set to true to block the call to the super class |
| 46 |
bool bHandled = false; |
| 47 |
|
| 48 |
switch (message.GetMessage()) |
| 49 |
{ |
| 50 |
case GUI_MSG_SETFOCUS: |
| 51 |
{ |
| 52 |
const int controlId = message.GetControlId(); |
| 53 |
if (m_controllerList->HasControl(controlId) && |
| 54 |
m_controllerList->GetCurrentControl() != controlId) |
| 55 |
{ |
| 56 |
FocusControllerList(); |
| 57 |
bHandled = true; |
| 58 |
} |
| 59 |
break; |
| 60 |
} |
| 61 |
case GUI_MSG_CLICKED: |
| 62 |
{ |
| 63 |
const int controlId = message.GetSenderId(); |
| 64 |
|
| 65 |
if (controlId == CONTROL_AGENT_CLOSE_BUTTON) |
| 66 |
{ |
| 67 |
CloseDialog(); |
| 68 |
bHandled = true; |
| 69 |
} |
| 70 |
else if (m_controllerList->HasControl(controlId)) |
| 71 |
{ |
| 72 |
const int actionId = message.GetParam1(); |
| 73 |
if (actionId == ACTION_SELECT_ITEM || actionId == ACTION_MOUSE_LEFT_CLICK) |
| 74 |
{ |
| 75 |
OnControllerClick(); |
| 76 |
bHandled = true; |
| 77 |
} |
| 78 |
} |
| 79 |
break; |
| 80 |
} |
| 81 |
case GUI_MSG_REFRESH_LIST: |
| 82 |
{ |
| 83 |
const int controlId = message.GetControlId(); |
| 84 |
switch (controlId) |
| 85 |
{ |
| 86 |
case CONTROL_ACTIVE_PORT_LIST: |
| 87 |
{ |
| 88 |
UpdateActivePortList(); |
| 89 |
bHandled = true; |
| 90 |
break; |
| 91 |
} |
| 92 |
case CONTROL_AGENT_CONTROLLER_LIST: |
| 93 |
{ |
| 94 |
UpdateControllerList(); |
| 95 |
bHandled = true; |
| 96 |
break; |
| 97 |
} |
| 98 |
default: |
| 99 |
break; |
| 100 |
} |
| 101 |
break; |
| 102 |
} |
| 103 |
|
| 104 |
default: |
| 105 |
break; |
| 106 |
} |
| 107 |
|
| 108 |
if (!bHandled) |
| 109 |
bHandled = CGUIDialog::OnMessage(message); |
| 110 |
|
| 111 |
return bHandled; |
| 112 |
} |
| 113 |
|
| 114 |
void CGUIAgentWindow::FrameMove() |
| 115 |
{ |
| 116 |
CGUIDialog::FrameMove(); |
| 117 |
|
| 118 |
m_controllerList->FrameMove(); |
| 119 |
} |
| 120 |
|
| 121 |
void CGUIAgentWindow::OnWindowLoaded() |
| 122 |
{ |
| 123 |
CGUIDialog::OnWindowLoaded(); |
| 124 |
|
| 125 |
m_controllerList->OnWindowLoaded(); |
| 126 |
} |
| 127 |
|
| 128 |
void CGUIAgentWindow::OnWindowUnload() |
| 129 |
{ |
| 130 |
m_controllerList->OnWindowUnload(); |
| 131 |
|
| 132 |
CGUIDialog::OnWindowUnload(); |
| 133 |
} |
| 134 |
|
| 135 |
void CGUIAgentWindow::OnInitWindow() |
| 136 |
{ |
| 137 |
CGUIDialog::OnInitWindow(); |
| 138 |
|
| 139 |
// Get active game add-on |
| 140 |
GameClientPtr gameClient; |
| 141 |
{ |
| 142 |
auto gameSettingsHandle = CServiceBroker::GetGameRenderManager().RegisterGameSettingsDialog(); |
| 143 |
if (gameSettingsHandle) |
| 144 |
{ |
| 145 |
ADDON::AddonPtr addon; |
| 146 |
if (CServiceBroker::GetAddonMgr().GetAddon(gameSettingsHandle->GameClientID(), addon, |
| 147 |
ADDON::AddonType::GAMEDLL, |
| 148 |
ADDON::OnlyEnabled::CHOICE_YES)) |
| 149 |
gameClient = std::static_pointer_cast<CGameClient>(addon); |
| 150 |
} |
| 151 |
} |
| 152 |
m_gameClient = std::move(gameClient); |
| 153 |
|
| 154 |
// Initialize GUI |
| 155 |
m_portList->Initialize(m_gameClient); |
| 156 |
m_controllerList->Initialize(m_gameClient); |
| 157 |
} |
| 158 |
|
| 159 |
void CGUIAgentWindow::OnDeinitWindow(int nextWindowID) |
| 160 |
{ |
| 161 |
// Deinitialize GUI |
| 162 |
m_controllerList->Deinitialize(); |
| 163 |
m_portList->Deinitialize(); |
| 164 |
|
| 165 |
// Deinitialize game properties |
| 166 |
m_gameClient.reset(); |
| 167 |
|
| 168 |
CGUIDialog::OnDeinitWindow(nextWindowID); |
| 169 |
} |
| 170 |
|
| 171 |
void CGUIAgentWindow::CloseDialog() |
| 172 |
{ |
| 173 |
Close(); |
| 174 |
} |
| 175 |
|
| 176 |
void CGUIAgentWindow::UpdateActivePortList() |
| 177 |
{ |
| 178 |
m_portList->Refresh(); |
| 179 |
} |
| 180 |
|
| 181 |
void CGUIAgentWindow::UpdateControllerList() |
| 182 |
{ |
| 183 |
m_controllerList->Refresh(); |
| 184 |
} |
| 185 |
|
| 186 |
void CGUIAgentWindow::FocusControllerList() |
| 187 |
{ |
| 188 |
m_controllerList->SetFocused(); |
| 189 |
} |
| 190 |
|
| 191 |
void CGUIAgentWindow::OnControllerClick() |
| 192 |
{ |
| 193 |
m_controllerList->OnSelect(); |
| 194 |
} |