Skip to content

Commit

Permalink
Controllers: Add dialog for controller ports
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Nov 4, 2021
1 parent 586449a commit 4cfc4ba
Show file tree
Hide file tree
Showing 16 changed files with 1,092 additions and 6 deletions.
29 changes: 27 additions & 2 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -6576,7 +6576,9 @@ msgctxt "#13297"
msgid "Not connected. Check network settings."
msgstr ""

#empty string with id 13298
msgctxt "#13298"
msgid "Disconnected"
msgstr ""

msgctxt "#13299"
msgid "Target temperature"
Expand Down Expand Up @@ -17663,7 +17665,30 @@ msgctxt "#35109"
msgid "Keypad"
msgstr ""

#empty strings from id 35110 to 35149
#. Label for button that allows the user to select which type of controllers are being used by a game. Used in the in-game OSD when the user selects "settings".
msgctxt "#35110"
msgid "Ports"
msgstr ""

#. Title of the window for setting up controller ports used by the game
msgctxt "#35111"
msgid "Port Setup"
msgstr ""

#. Label of a port with its identifier. {0:s} is the port ID, e.g. "1" for "Port 1"
#. TODO: Remove this string
msgctxt "#35112"
msgid "Port {0:s}"
msgstr ""

#empty string with id 35113

#. Title of the dialog for selecting a game controller
msgctxt "#35114"
msgid "Select a Controller"
msgstr ""

#empty strings from id 35115 to 35149

#. Name of keyboard category in the settings category window
#: system/settings/settings.xml
Expand Down
11 changes: 9 additions & 2 deletions addons/skin.estuary/xml/Custom_1101_SettingsList.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<controls>
<control type="group">
<centerleft>50%</centerleft>
<height>460</height>
<height>530</height>
<centertop>50%</centertop>
<width>700</width>
<visible>!Window.IsActive(DialogSettings.xml) + !Window.IsActive(DialogSlider.xml) + !Window.IsActive(GameVideoFilter) + !Window.IsActive(GameStretchMode) + !Window.IsActive(GameControllers) + !Window.IsActive(GameVideoRotation)</visible>
Expand Down Expand Up @@ -118,7 +118,7 @@
<defaultcontrol always="true">14101</defaultcontrol>
<visible>String.IsEqual(window(home).Property(settingslist_content),games)</visible>
<width>700</width>
<height>430</height>
<height>500</height>
<itemgap>0</itemgap>
<onup>14100</onup>
<ondown>14100</ondown>
Expand Down Expand Up @@ -159,6 +159,13 @@
<label>$LOCALIZE[35234]</label>
<onclick>ActivateWindow(GameControllers)</onclick>
</control>
<control type="button" id="14107">
<description>Controller port configuration</description>
<width>700</width>
<include>DialogSettingButton</include>
<label>$LOCALIZE[35110]</label>
<onclick>ActivateWindow(GamePorts)</onclick>
</control>
<control type="button" id="14105">
<description>Advanced settings</description>
<width>700</width>
Expand Down
1 change: 1 addition & 0 deletions addons/skin.estuary/xml/DialogGameControllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<include>Animation_DialogPopupOpenClose</include>
<controls>
<include condition="Window.IsActive(gamecontrollers)">GameDialogControllers</include>
<include condition="Window.IsActive(gameports)">GameDialogPorts</include>
</controls>
<controls>
</controls>
Expand Down
133 changes: 133 additions & 0 deletions addons/skin.estuary/xml/Includes_Controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,137 @@
</control>
</control>
</include>
<include name="GameDialogPorts">
<control type="group">
<centertop>50%</centertop>
<centerleft>50%</centerleft>
<width>1820</width>
<height>870</height>
<include content="DialogBackgroundCommons">
<param name="width" value="1820" />
<param name="height" value="870" />
<param name="header_label" value="" />
<param name="header_id" value="2" />
</include>
<control type="group">
<description>Content area</description>
<top>100</top>
<bottom>30</bottom>
<left>30</left>
<right>30</right>
<!--
<control type="image">
<description>Content area background for testing</description>
<top>-20</top>
<bottom>-20</bottom>
<left>-20</left>
<right>-20</right>
<texture border="40">buttons/dialogbutton-nofo.png</texture>
</control>
-->
<control type="group">
<description>Port list</description>
<width>1440</width>
<height>700</height>
<control type="image">
<description>Port list background</description>
<top>-20</top>
<bottom>-20</bottom>
<left>-20</left>
<right>-20</right>
<texture border="40">buttons/dialogbutton-nofo.png</texture>
</control>
<control type="list" id="3">
<description>Port item list</description>
<onright>9001</onright>
<onup>3</onup>
<ondown>3</ondown>
<pagecontrol>62</pagecontrol>
<scrolltime tween="sine">200</scrolltime>
<orientation>vertical</orientation>
<itemlayout width="1440" height="100">
<control type="group">
<control type="label">
<top>20</top>
<left>20</left>
<label>$INFO[ListItem.Label]</label>
<font>font37</font>
<shadowcolor>text_shadow</shadowcolor>
<align>left</align>
</control>
<control type="label">
<top>20</top>
<right>132</right>
<label>$INFO[ListItem.Label2]</label>
<font>font37</font>
<shadowcolor>text_shadow</shadowcolor>
<align>right</align>
</control>
<control type="image">
<right>12</right>
<width>100</width>
<texture>$INFO[ListItem.Icon]</texture>
</control>
</control>
</itemlayout>
<focusedlayout width="1440" height="100">
<control type="group">
<control type="image">
<top>-20</top>
<bottom>-20</bottom>
<left>-20</left>
<right>-20</right>
<texture border="40" colordiffuse="button_focus">buttons/dialogbutton-fo.png</texture>
<visible>Control.HasFocus(3)</visible>
</control>
<control type="label">
<top>20</top>
<left>20</left>
<label>$INFO[ListItem.Label]</label>
<font>font37</font>
<shadowcolor>text_shadow</shadowcolor>
<align>left</align>
</control>
<control type="label">
<top>20</top>
<right>132</right>
<label>$INFO[ListItem.Label2]</label>
<font>font37</font>
<shadowcolor>text_shadow</shadowcolor>
<align>right</align>
</control>
<control type="image">
<right>12</right>
<width>100</width>
<texture>$INFO[ListItem.Icon]</texture>
</control>
</control>
</focusedlayout>
</control>
<control type="scrollbar" id="62">
<right>0</right>
<width>12</width>
<orientation>vertical</orientation>
</control>
</control>
<control type="grouplist" id="9001">
<top>-20</top>
<right>-20</right>
<width>330</width>
<onleft>3</onleft>
<itemgap>dialogbuttons_itemgap</itemgap>
<include content="DefaultDialogButton">
<param name="width" value="330" />
<param name="id" value="18" />
<param name="label" value="$LOCALIZE[186]" />
</include>
<include content="DefaultDialogButton">
<param name="width" value="330" />
<param name="id" value="19" />
<param name="label" value="$LOCALIZE[13007]" />
</include>
</control>
</control>
</control>
</include>
</includes>
14 changes: 12 additions & 2 deletions xbmc/games/controllers/windows/CMakeLists.txt
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)
119 changes: 119 additions & 0 deletions xbmc/games/controllers/windows/ControllerSelect.cpp
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);
}
}

0 comments on commit 4cfc4ba

Please sign in to comment.