| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 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 "DialogGameVideoSelect.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "ServiceBroker.h" |
| 13 |
#include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h" |
| 14 |
#include "cores/RetroPlayer/guibridge/GUIGameVideoHandle.h" |
| 15 |
#include "games/dialogs/DialogGameDefines.h" |
| 16 |
#include "guilib/GUIBaseContainer.h" |
| 17 |
#include "guilib/GUIComponent.h" |
| 18 |
#include "guilib/GUIMessage.h" |
| 19 |
#include "guilib/GUIWindowManager.h" |
| 20 |
#include "input/actions/ActionIDs.h" |
| 21 |
#include "settings/GameSettings.h" |
| 22 |
#include "settings/MediaSettings.h" |
| 23 |
#include "settings/Settings.h" |
| 24 |
#include "settings/SettingsComponent.h" |
| 25 |
#include "view/GUIViewControl.h" |
| 26 |
#include "view/ViewState.h" |
| 27 |
#include "windowing/GraphicContext.h" |
| 28 |
|
| 29 |
using namespace KODI; |
| 30 |
using namespace GAME; |
| 31 |
|
| 32 |
CDialogGameVideoSelect::CDialogGameVideoSelect(int windowId) |
| 33 |
: CGUIDialog(windowId, "DialogSelect.xml"), |
| 34 |
m_viewControl(new CGUIViewControl), |
| 35 |
m_vecItems(new CFileItemList) |
| 36 |
{ |
| 37 |
// Initialize CGUIWindow |
| 38 |
m_loadType = KEEP_IN_MEMORY; |
| 39 |
} |
| 40 |
|
| 41 |
CDialogGameVideoSelect::~CDialogGameVideoSelect() = default; |
| 42 |
|
| 43 |
bool CDialogGameVideoSelect::OnMessage(CGUIMessage& message) |
| 44 |
{ |
| 45 |
switch (message.GetMessage()) |
| 46 |
{ |
| 47 |
case GUI_MSG_WINDOW_INIT: |
| 48 |
{ |
| 49 |
RegisterDialog(); |
| 50 |
|
| 51 |
// Don't init this dialog if we aren't playing a game |
| 52 |
if (!m_gameVideoHandle || !m_gameVideoHandle->IsPlayingGame()) |
| 53 |
return false; |
| 54 |
|
| 55 |
break; |
| 56 |
} |
| 57 |
case GUI_MSG_WINDOW_DEINIT: |
| 58 |
{ |
| 59 |
UnregisterDialog(); |
| 60 |
|
| 61 |
break; |
| 62 |
} |
| 63 |
case GUI_MSG_SETFOCUS: |
| 64 |
{ |
| 65 |
const int controlId = message.GetControlId(); |
| 66 |
if (m_viewControl->HasControl(controlId) && m_viewControl->GetCurrentControl() != controlId) |
| 67 |
{ |
| 68 |
m_viewControl->SetFocused(); |
| 69 |
return true; |
| 70 |
} |
| 71 |
break; |
| 72 |
} |
| 73 |
case GUI_MSG_CLICKED: |
| 74 |
{ |
| 75 |
const int actionId = message.GetParam1(); |
| 76 |
if (actionId == ACTION_SELECT_ITEM || actionId == ACTION_MOUSE_LEFT_CLICK) |
| 77 |
{ |
| 78 |
const int controlId = message.GetSenderId(); |
| 79 |
if (m_viewControl->HasControl(controlId)) |
| 80 |
{ |
| 81 |
if (OnClickAction()) |
| 82 |
return true; |
| 83 |
} |
| 84 |
} |
| 85 |
else if (actionId == ACTION_CONTEXT_MENU || actionId == ACTION_MOUSE_RIGHT_CLICK) |
| 86 |
{ |
| 87 |
const int controlId = message.GetSenderId(); |
| 88 |
if (m_viewControl->HasControl(controlId)) |
| 89 |
{ |
| 90 |
if (OnMenuAction()) |
| 91 |
return true; |
| 92 |
} |
| 93 |
} |
| 94 |
else if (actionId == ACTION_CREATE_BOOKMARK) |
| 95 |
{ |
| 96 |
const int controlId = message.GetSenderId(); |
| 97 |
if (m_viewControl->HasControl(controlId)) |
| 98 |
{ |
| 99 |
if (OnOverwriteAction()) |
| 100 |
return true; |
| 101 |
} |
| 102 |
} |
| 103 |
else if (actionId == ACTION_RENAME_ITEM) |
| 104 |
{ |
| 105 |
const int controlId = message.GetSenderId(); |
| 106 |
if (m_viewControl->HasControl(controlId)) |
| 107 |
{ |
| 108 |
if (OnRenameAction()) |
| 109 |
return true; |
| 110 |
} |
| 111 |
} |
| 112 |
else if (actionId == ACTION_DELETE_ITEM) |
| 113 |
{ |
| 114 |
const int controlId = message.GetSenderId(); |
| 115 |
if (m_viewControl->HasControl(controlId)) |
| 116 |
{ |
| 117 |
if (OnDeleteAction()) |
| 118 |
return true; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
break; |
| 123 |
} |
| 124 |
case GUI_MSG_REFRESH_LIST: |
| 125 |
{ |
| 126 |
RefreshList(); |
| 127 |
break; |
| 128 |
} |
| 129 |
default: |
| 130 |
break; |
| 131 |
} |
| 132 |
|
| 133 |
return CGUIDialog::OnMessage(message); |
| 134 |
} |
| 135 |
|
| 136 |
void CDialogGameVideoSelect::FrameMove() |
| 137 |
{ |
| 138 |
CGUIBaseContainer* thumbs = dynamic_cast<CGUIBaseContainer*>(GetControl(CONTROL_VIDEO_THUMBS)); |
| 139 |
if (thumbs != nullptr) |
| 140 |
OnItemFocus(thumbs->GetSelectedItem()); |
| 141 |
|
| 142 |
CGUIDialog::FrameMove(); |
| 143 |
} |
| 144 |
|
| 145 |
void CDialogGameVideoSelect::OnWindowLoaded() |
| 146 |
{ |
| 147 |
CGUIDialog::OnWindowLoaded(); |
| 148 |
|
| 149 |
m_viewControl->SetParentWindow(GetID()); |
| 150 |
m_viewControl->AddView(GetControl(CONTROL_VIDEO_THUMBS)); |
| 151 |
} |
| 152 |
|
| 153 |
void CDialogGameVideoSelect::OnWindowUnload() |
| 154 |
{ |
| 155 |
m_viewControl->Reset(); |
| 156 |
|
| 157 |
CGUIDialog::OnWindowUnload(); |
| 158 |
} |
| 159 |
|
| 160 |
void CDialogGameVideoSelect::OnInitWindow() |
| 161 |
{ |
| 162 |
PreInit(); |
| 163 |
|
| 164 |
CGUIDialog::OnInitWindow(); |
| 165 |
|
| 166 |
Update(); |
| 167 |
|
| 168 |
CGUIMessage msg(GUI_MSG_SETFOCUS, GetID(), CONTROL_VIDEO_THUMBS); |
| 169 |
OnMessage(msg); |
| 170 |
|
| 171 |
std::string heading = GetHeading(); |
| 172 |
SET_CONTROL_LABEL(CONTROL_VIDEO_HEADING, heading); |
| 173 |
|
| 174 |
FrameMove(); |
| 175 |
} |
| 176 |
|
| 177 |
void CDialogGameVideoSelect::OnDeinitWindow(int nextWindowID) |
| 178 |
{ |
| 179 |
Clear(); |
| 180 |
|
| 181 |
CGUIDialog::OnDeinitWindow(nextWindowID); |
| 182 |
|
| 183 |
PostExit(); |
| 184 |
|
| 185 |
SaveSettings(); |
| 186 |
} |
| 187 |
|
| 188 |
void CDialogGameVideoSelect::Update() |
| 189 |
{ |
| 190 |
//! @todo |
| 191 |
// Lock our display, as this window is rendered from the player thread |
| 192 |
// CServiceBroker::GetWinSystem()->GetGfxContext().Lock(); |
| 193 |
|
| 194 |
m_viewControl->SetCurrentView(DEFAULT_VIEW_ICONS); |
| 195 |
|
| 196 |
// Empty the list ready for population |
| 197 |
Clear(); |
| 198 |
|
| 199 |
RefreshList(); |
| 200 |
|
| 201 |
// CServiceBroker::GetWinSystem()->GetGfxContext().Unlock(); |
| 202 |
} |
| 203 |
|
| 204 |
void CDialogGameVideoSelect::Clear() |
| 205 |
{ |
| 206 |
m_viewControl->Clear(); |
| 207 |
m_vecItems->Clear(); |
| 208 |
} |
| 209 |
|
| 210 |
void CDialogGameVideoSelect::RefreshList() |
| 211 |
{ |
| 212 |
m_vecItems->Clear(); |
| 213 |
|
| 214 |
GetItems(*m_vecItems); |
| 215 |
|
| 216 |
m_viewControl->SetItems(*m_vecItems); |
| 217 |
|
| 218 |
auto focusedIndex = GetFocusedItem(); |
| 219 |
m_viewControl->SetSelectedItem(focusedIndex); |
| 220 |
OnItemFocus(focusedIndex); |
| 221 |
|
| 222 |
// Refresh the panel container |
| 223 |
CGUIMessage message(GUI_MSG_REFRESH_THUMBS, GetID(), CONTROL_VIDEO_THUMBS); |
| 224 |
CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(message, GetID()); |
| 225 |
} |
| 226 |
|
| 227 |
void CDialogGameVideoSelect::SaveSettings() |
| 228 |
{ |
| 229 |
CGameSettings& defaultSettings = CMediaSettings::GetInstance().GetDefaultGameSettings(); |
| 230 |
CGameSettings& currentSettings = CMediaSettings::GetInstance().GetCurrentGameSettings(); |
| 231 |
|
| 232 |
if (defaultSettings != currentSettings) |
| 233 |
{ |
| 234 |
defaultSettings = currentSettings; |
| 235 |
CServiceBroker::GetSettingsComponent()->GetSettings()->Save(); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
void CDialogGameVideoSelect::OnDescriptionChange(const std::string& description) |
| 240 |
{ |
| 241 |
CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), CONTROL_VIDEO_THUMBS); |
| 242 |
msg.SetLabel(description); |
| 243 |
CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg, GetID()); |
| 244 |
} |
| 245 |
|
| 246 |
void CDialogGameVideoSelect::RegisterDialog() |
| 247 |
{ |
| 248 |
m_gameVideoHandle = CServiceBroker::GetGameRenderManager().RegisterDialog(*this); |
| 249 |
} |
| 250 |
|
| 251 |
void CDialogGameVideoSelect::UnregisterDialog() |
| 252 |
{ |
| 253 |
m_gameVideoHandle.reset(); |
| 254 |
} |