Debian Codegraph @

xbmc/games/ports/windows/GUIPortWindow.cpp

raw
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 #include "GUIPortWindow.h"
10
11 #include "GUIPortDefines.h"
12 #include "GUIPortList.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 "guilib/GUIButtonControl.h"
21 #include "guilib/GUIControl.h"
22 #include "guilib/GUIMessage.h"
23 #include "guilib/WindowIDs.h"
24 #include "input/actions/ActionIDs.h"
25 #include "utils/StringUtils.h"
26
27 using namespace KODI;
28 using namespace GAME;
29
30 CGUIPortWindow::CGUIPortWindow()
31 : CGUIDialog(WINDOW_DIALOG_GAME_PORTS, PORT_DIALOG_XML),
32 m_portList(std::make_unique<CGUIPortList>(*this))
33 {
34 // Initialize CGUIWindow
35 m_loadType = KEEP_IN_MEMORY;
36 }
37
38 CGUIPortWindow::~CGUIPortWindow() = default;
39
40 bool CGUIPortWindow::OnMessage(CGUIMessage& message)
41 {
42 // Set to true to block the call to the super class
43 bool bHandled = false;
44
45 switch (message.GetMessage())
46 {
47 case GUI_MSG_SETFOCUS:
48 {
49 const int controlId = message.GetControlId();
50 if (m_portList->HasControl(controlId) && m_portList->GetCurrentControl() != controlId)
51 {
52 FocusPortList();
53 bHandled = true;
54 }
55 break;
56 }
57 case GUI_MSG_CLICKED:
58 {
59 const int controlId = message.GetSenderId();
60
61 if (controlId == CONTROL_CLOSE_BUTTON)
62 {
63 CloseDialog();
64 bHandled = true;
65 }
66 else if (controlId == CONTROL_RESET_BUTTON)
67 {
68 ResetPorts();
69 bHandled = true;
70 }
71 else if (m_portList->HasControl(controlId))
72 {
73 const int actionId = message.GetParam1();
74 if (actionId == ACTION_SELECT_ITEM || actionId == ACTION_MOUSE_LEFT_CLICK)
75 {
76 OnClickAction();
77 bHandled = true;
78 }
79 }
80 break;
81 }
82 case GUI_MSG_REFRESH_LIST:
83 {
84 UpdatePortList();
85 break;
86 }
87 default:
88 break;
89 }
90
91 if (!bHandled)
92 bHandled = CGUIDialog::OnMessage(message);
93
94 return bHandled;
95 }
96
97 void CGUIPortWindow::OnWindowLoaded()
98 {
99 CGUIDialog::OnWindowLoaded();
100
101 m_portList->OnWindowLoaded();
102 }
103
104 void CGUIPortWindow::OnWindowUnload()
105 {
106 m_portList->OnWindowUnload();
107
108 CGUIDialog::OnWindowUnload();
109 }
110
111 void CGUIPortWindow::OnInitWindow()
112 {
113 CGUIDialog::OnInitWindow();
114
115 // Get active game add-on
116 GameClientPtr gameClient;
117 {
118 auto gameSettingsHandle = CServiceBroker::GetGameRenderManager().RegisterGameSettingsDialog();
119 if (gameSettingsHandle)
120 {
121 ADDON::AddonPtr addon;
122 if (CServiceBroker::GetAddonMgr().GetAddon(gameSettingsHandle->GameClientID(), addon,
123 ADDON::AddonType::GAMEDLL,
124 ADDON::OnlyEnabled::CHOICE_YES))
125 gameClient = std::static_pointer_cast<CGameClient>(addon);
126 }
127 }
128 m_gameClient = std::move(gameClient);
129
130 // Set the heading
131 // "Port Setup - {game client name}"
132 SET_CONTROL_LABEL(CONTROL_PORT_DIALOG_LABEL,
133 StringUtils::Format("$LOCALIZE[35111] - {}", m_gameClient->Name()));
134
135 m_portList->Initialize(m_gameClient);
136
137 UpdatePortList();
138
139 // Focus the port list
140 CGUIMessage msgFocus(GUI_MSG_SETFOCUS, GetID(), CONTROL_PORT_LIST);
141 OnMessage(msgFocus);
142 }
143
144 void CGUIPortWindow::OnDeinitWindow(int nextWindowID)
145 {
146 m_portList->Deinitialize();
147
148 m_gameClient.reset();
149
150 CGUIDialog::OnDeinitWindow(nextWindowID);
151 }
152
153 void CGUIPortWindow::FrameMove()
154 {
155 CGUIDialog::FrameMove();
156
157 m_portList->FrameMove();
158 }
159
160 void CGUIPortWindow::UpdatePortList()
161 {
162 m_portList->Refresh();
163 }
164
165 void CGUIPortWindow::FocusPortList()
166 {
167 m_portList->SetFocused();
168 }
169
170 bool CGUIPortWindow::OnClickAction()
171 {
172 return m_portList->OnSelect();
173 }
174
175 void CGUIPortWindow::ResetPorts()
176 {
177 m_portList->ResetPorts();
178 }
179
180 void CGUIPortWindow::CloseDialog()
181 {
182 Close();
183 }