-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controllers: Add dialog for controller ports
- Loading branch information
Showing
16 changed files
with
1,092 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
set(SOURCES ControllerInstaller.cpp | ||
ControllerSelect.cpp | ||
GUIConfigurationWizard.cpp | ||
GUIControllerList.cpp | ||
GUIControllerWindow.cpp | ||
GUIFeatureList.cpp) | ||
GUIFeatureList.cpp | ||
GUIPortList.cpp | ||
GUIPortWindow.cpp | ||
) | ||
|
||
set(HEADERS ControllerInstaller.h | ||
ControllerSelect.cpp | ||
GUIConfigurationWizard.h | ||
GUIControllerDefines.h | ||
GUIControllerList.h | ||
GUIControllerWindow.h | ||
GUIFeatureList.h | ||
IConfigurationWindow.h) | ||
GUIPortDefines.h | ||
GUIPortList.h | ||
GUIPortWindow.h | ||
IConfigurationWindow.h | ||
IPortWindow.h | ||
) | ||
|
||
core_add_library(games_controller_windows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (C) 2021 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#include "ControllerSelect.h" | ||
|
||
#include "FileItem.h" | ||
#include "ServiceBroker.h" | ||
#include "dialogs/GUIDialogSelect.h" | ||
#include "games/controllers/Controller.h" | ||
#include "games/controllers/ControllerLayout.h" | ||
#include "games/controllers/ControllerTypes.h" | ||
#include "guilib/GUIComponent.h" | ||
#include "guilib/GUIWindowManager.h" | ||
#include "guilib/LocalizeStrings.h" | ||
#include "guilib/WindowIDs.h" | ||
#include "utils/Variant.h" | ||
#include "utils/log.h" | ||
|
||
using namespace KODI; | ||
using namespace GAME; | ||
|
||
CControllerSelect::CControllerSelect() : CThread("ControllerSelect") | ||
{ | ||
} | ||
|
||
CControllerSelect::~CControllerSelect() = default; | ||
|
||
void CControllerSelect::Initialize(ControllerVector controllers, | ||
ControllerPtr defaultController, | ||
bool showDisconnect, | ||
std::function<void(ControllerPtr)> callback) | ||
{ | ||
// Validate parameters | ||
if (controllers.empty() || !callback) | ||
return; | ||
|
||
// Initialize state | ||
m_controllers = std::move(controllers); | ||
m_defaultController = std::move(defaultController); | ||
m_showDisconnect = showDisconnect; | ||
m_callback = callback; | ||
|
||
// Create thread | ||
Create(false); | ||
} | ||
|
||
void CControllerSelect::Deinitialize() | ||
{ | ||
//! @todo Stop thread and cleanup | ||
} | ||
|
||
void CControllerSelect::Process() | ||
{ | ||
// Select first controller by default | ||
unsigned int initialSelected = 0; | ||
|
||
CGUIComponent* gui = CServiceBroker::GetGUI(); | ||
if (gui == nullptr) | ||
return; | ||
|
||
CGUIWindowManager& windowManager = gui->GetWindowManager(); | ||
|
||
auto pSelectDialog = windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); | ||
if (pSelectDialog == nullptr) | ||
return; | ||
|
||
CLog::Log(LOGDEBUG, "Controller select: Showing dialog for %u controllers", m_controllers.size()); | ||
|
||
CFileItemList items; | ||
for (const ControllerPtr& controller : m_controllers) | ||
{ | ||
CFileItemPtr item(new CFileItem(controller->Layout().Label())); | ||
item->SetArt("icon", controller->Layout().ImagePath()); | ||
items.Add(std::move(item)); | ||
|
||
// Check if a specified controller should be selected by default | ||
if (m_defaultController && m_defaultController->ID() == controller->ID()) | ||
initialSelected = items.Size() - 1; | ||
} | ||
|
||
if (m_showDisconnect) | ||
{ | ||
// Add a button to disconnect the port | ||
CFileItemPtr item(new CFileItem(g_localizeStrings.Get(13298))); // "Disconnected" | ||
item->SetArt("icon", "DefaultAddonNone.png"); | ||
items.Add(std::move(item)); | ||
|
||
// Check if the disconnect button should be selected by default | ||
if (!m_defaultController) | ||
initialSelected = items.Size() - 1; | ||
} | ||
|
||
pSelectDialog->Reset(); | ||
pSelectDialog->SetHeading(CVariant{35114}); // "Select a Controller" | ||
pSelectDialog->SetUseDetails(true); | ||
pSelectDialog->EnableButton(false, 186); // "OK"" | ||
pSelectDialog->SetButtonFocus(false); | ||
for (const auto& it : items) | ||
pSelectDialog->Add(*it); | ||
pSelectDialog->SetSelected(static_cast<int>(initialSelected)); | ||
pSelectDialog->Open(); | ||
|
||
if (pSelectDialog->IsConfirmed()) | ||
{ | ||
ControllerPtr resultController; | ||
|
||
const int selected = pSelectDialog->GetSelectedItem(); | ||
if (0 <= selected && selected < static_cast<int>(m_controllers.size())) | ||
resultController = m_controllers.at(selected); | ||
|
||
// Fire a callback with the result | ||
m_callback(resultController); | ||
} | ||
} |
Oops, something went wrong.