diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2023-11-30 15:35:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 15:35:27 -0800 |
commit | 12d991a53d8115a75e11acd9c196ca4afe06f05c (patch) | |
tree | fa50b93c77092e83ed3a513ab89a379fc26d479d | |
parent | 5d443633485ee31d4af41b44f16b79650681e432 (diff) | |
parent | 18ee8e320167714bca619d80c28ee54e31862c6b (diff) |
Merge pull request #24147 from garbear/remove-combos
[Games] Remove hard-coded button combos
-rw-r--r-- | addons/skin.estuary/language/resource.language.en_gb/strings.po | 10 | ||||
-rw-r--r-- | addons/skin.estuary/xml/Custom_1101_SettingsList.xml | 2 | ||||
-rw-r--r-- | addons/skin.estuary/xml/GameOSD.xml | 4 | ||||
-rw-r--r-- | xbmc/games/GameServices.cpp | 6 | ||||
-rw-r--r-- | xbmc/games/GameServices.h | 11 | ||||
-rw-r--r-- | xbmc/games/controllers/ControllerManager.cpp | 20 | ||||
-rw-r--r-- | xbmc/games/controllers/ControllerManager.h | 11 | ||||
-rw-r--r-- | xbmc/games/controllers/ControllerTypes.h | 14 | ||||
-rw-r--r-- | xbmc/games/dialogs/osd/DialogGameOSDHelp.cpp | 9 | ||||
-rw-r--r-- | xbmc/guilib/guiinfo/GUIInfoLabel.cpp | 22 | ||||
-rw-r--r-- | xbmc/guilib/guiinfo/GUIInfoLabel.h | 10 |
11 files changed, 103 insertions, 16 deletions
diff --git a/addons/skin.estuary/language/resource.language.en_gb/strings.po b/addons/skin.estuary/language/resource.language.en_gb/strings.po index 92451c6f69..636c7ed555 100644 --- a/addons/skin.estuary/language/resource.language.en_gb/strings.po +++ b/addons/skin.estuary/language/resource.language.en_gb/strings.po @@ -308,15 +308,7 @@ msgctxt "#31058" msgid "Automatic Login on startup" msgstr "" -#: /xml/GameOSD.xml -msgctxt "#31059" -msgid "Select + X" -msgstr "" - -#: /xml/GameOSD.xml -msgctxt "#31060" -msgid "Select + Start" -msgstr "" +#empty strings from id 31059 to 31060 #: /xml/SkinSettings.xml msgctxt "#31061" diff --git a/addons/skin.estuary/xml/Custom_1101_SettingsList.xml b/addons/skin.estuary/xml/Custom_1101_SettingsList.xml index 24de2dcf5b..e15a42e39d 100644 --- a/addons/skin.estuary/xml/Custom_1101_SettingsList.xml +++ b/addons/skin.estuary/xml/Custom_1101_SettingsList.xml @@ -160,7 +160,7 @@ <width>700</width> <include>DialogSettingButton</include> <label>$LOCALIZE[13376]</label> - <label2>[COLOR grey]Select + Right Stick[/COLOR]</label2> + <label2>[COLOR grey]$FEATURE[select,game.controller.snes] + $FEATURE[rightstick,game.controller.default][/COLOR]</label2> <onclick>ActivateWindow(GameVolume)</onclick> </control> <control type="button" id="14103"> diff --git a/addons/skin.estuary/xml/GameOSD.xml b/addons/skin.estuary/xml/GameOSD.xml index 454a30c4ba..0c00a592d4 100644 --- a/addons/skin.estuary/xml/GameOSD.xml +++ b/addons/skin.estuary/xml/GameOSD.xml @@ -204,7 +204,7 @@ <item> <description>Pause / Resume button</description> <label>$LOCALIZE[35224]</label> - <label2>$LOCALIZE[31059]</label2> + <label2>$FEATURE[select,game.controller.snes] + $FEATURE[x,game.controller.default]</label2> <icon>osd/fullscreen/buttons/play.png</icon> <onclick>Play</onclick> </item> @@ -229,7 +229,7 @@ <item> <description>Stop button</description> <label>$LOCALIZE[35222]</label> - <label2>$LOCALIZE[31060]</label2> + <label2>$FEATURE[select,game.controller.snes] + $FEATURE[start,game.controller.default]</label2> <icon>osd/fullscreen/buttons/stop.png</icon> <onclick>Stop</onclick> </item> diff --git a/xbmc/games/GameServices.cpp b/xbmc/games/GameServices.cpp index 099c9a9154..da4377a4fd 100644 --- a/xbmc/games/GameServices.cpp +++ b/xbmc/games/GameServices.cpp @@ -57,6 +57,12 @@ ControllerVector CGameServices::GetControllers() return m_controllerManager.GetControllers(); } +std::string CGameServices::TranslateFeature(const std::string& controllerId, + const std::string& featureName) +{ + return m_controllerManager.TranslateFeature(controllerId, featureName); +} + std::string CGameServices::GetSavestatesFolder() const { return m_profileManager.GetSavestatesFolder(); diff --git a/xbmc/games/GameServices.h b/xbmc/games/GameServices.h index 0a0b9bd769..41331e9ad6 100644 --- a/xbmc/games/GameServices.h +++ b/xbmc/games/GameServices.h @@ -53,6 +53,17 @@ public: ControllerPtr GetDefaultMouse(); ControllerVector GetControllers(); + /*! + * \brief Translate a feature on a controller into its localized name + * + * \param controllerId The controller ID that the feature belongs to + * \param featureName The feature name + * + * \return The localized feature name, or empty if the controller or feature + * doesn't exist + */ + std::string TranslateFeature(const std::string& controllerId, const std::string& featureName); + std::string GetSavestatesFolder() const; CGameSettings& GameSettings() { return *m_gameSettings; } diff --git a/xbmc/games/controllers/ControllerManager.cpp b/xbmc/games/controllers/ControllerManager.cpp index 707733b2f9..277c62554a 100644 --- a/xbmc/games/controllers/ControllerManager.cpp +++ b/xbmc/games/controllers/ControllerManager.cpp @@ -13,6 +13,7 @@ #include "addons/AddonEvents.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonType.h" +#include "games/controllers/input/PhysicalFeature.h" #include <mutex> @@ -89,6 +90,25 @@ ControllerVector CControllerManager::GetControllers() return controllers; } +std::string CControllerManager::TranslateFeature(const std::string& controllerId, + const std::string& featureName) +{ + ControllerPtr controller = GetController(controllerId); + if (controller) + { + const std::vector<CPhysicalFeature>& features = controller->Features(); + + auto it = std::find_if(features.begin(), features.end(), + [&featureName](const CPhysicalFeature& feature) + { return feature.Name() == featureName; }); + + if (it != features.end()) + return it->Label(); + } + + return ""; +} + void CControllerManager::OnEvent(const ADDON::AddonEvent& event) { if (typeid(event) == typeid(ADDON::AddonEvents::Enabled) || // Also called on install diff --git a/xbmc/games/controllers/ControllerManager.h b/xbmc/games/controllers/ControllerManager.h index e4d11e09e8..805ca60c69 100644 --- a/xbmc/games/controllers/ControllerManager.h +++ b/xbmc/games/controllers/ControllerManager.h @@ -75,6 +75,17 @@ public: */ ControllerVector GetControllers(); + /*! + * \brief Translate a feature on a controller into its localized name + * + * \param controllerId The controller ID that the feature belongs to + * \param featureName The feature name + * + * \return The localized feature name, or empty if the controller or feature + * doesn't exist + */ + std::string TranslateFeature(const std::string& controllerId, const std::string& featureName); + private: // Add-on event handler void OnEvent(const ADDON::AddonEvent& event); diff --git a/xbmc/games/controllers/ControllerTypes.h b/xbmc/games/controllers/ControllerTypes.h index f4ecc6cbc1..31e49ffa0a 100644 --- a/xbmc/games/controllers/ControllerTypes.h +++ b/xbmc/games/controllers/ControllerTypes.h @@ -16,11 +16,23 @@ namespace KODI namespace GAME { class CController; + +/*! + * \ingroup games + * + * \brief Smart pointer to a game controller (\ref CController) + */ using ControllerPtr = std::shared_ptr<CController>; + +/*! + * \ingroup games + * + * \brief Vector of smart pointers to a game controller (\ref CController) + */ using ControllerVector = std::vector<ControllerPtr>; /*! - * \ingroup game + * \ingroup games * * \brief Type of input provided by a hardware or controller port */ diff --git a/xbmc/games/dialogs/osd/DialogGameOSDHelp.cpp b/xbmc/games/dialogs/osd/DialogGameOSDHelp.cpp index d50d8631d7..b849a0aa2e 100644 --- a/xbmc/games/dialogs/osd/DialogGameOSDHelp.cpp +++ b/xbmc/games/dialogs/osd/DialogGameOSDHelp.cpp @@ -17,6 +17,12 @@ using namespace KODI; using namespace GAME; +namespace +{ +constexpr char HELP_COMBO[] = + "[B]$FEATURE[select,game.controller.snes] + $FEATURE[x,game.controller.default][/B]"; +} + const int CDialogGameOSDHelp::CONTROL_ID_HELP_TEXT = 1101; CDialogGameOSDHelp::CDialogGameOSDHelp(CDialogGameOSD& dialog) : m_dialog(dialog) @@ -26,9 +32,8 @@ CDialogGameOSDHelp::CDialogGameOSDHelp(CDialogGameOSD& dialog) : m_dialog(dialog void CDialogGameOSDHelp::OnInitWindow() { // Set help text - //! @todo Define Select + X combo elsewhere // "Press {0:s} to open the menu." - std::string helpText = StringUtils::Format(g_localizeStrings.Get(35235), "Select + X"); + std::string helpText = StringUtils::Format(g_localizeStrings.Get(35235), HELP_COMBO); CGUIMessage msg(GUI_MSG_LABEL_SET, WINDOW_DIALOG_GAME_OSD, CONTROL_ID_HELP_TEXT); msg.SetLabel(helpText); diff --git a/xbmc/guilib/guiinfo/GUIInfoLabel.cpp b/xbmc/guilib/guiinfo/GUIInfoLabel.cpp index 07ca5a4c23..9973b44a94 100644 --- a/xbmc/guilib/guiinfo/GUIInfoLabel.cpp +++ b/xbmc/guilib/guiinfo/GUIInfoLabel.cpp @@ -10,7 +10,9 @@ #include "FileItem.h" #include "GUIInfoManager.h" +#include "ServiceBroker.h" #include "addons/Skin.h" +#include "games/GameServices.h" #include "guilib/GUIComponent.h" #include "guilib/GUIListItem.h" #include "guilib/LocalizeStrings.h" @@ -230,6 +232,16 @@ std::string AddonReplacer(const std::string &str) return g_localizeStrings.GetAddonString(addonid, stringid); } +std::string ControllerFeatureReplacer(const std::string& str) +{ + // assumes "feature name,controller ID" + const size_t length = str.find(','); + const std::string featureName = str.substr(0, length); + const std::string controllerId = str.substr(length + 1); + + return CServiceBroker::GetGameServices().TranslateFeature(controllerId, featureName); +} + std::string NumberReplacer(const std::string &str) { return str; @@ -249,6 +261,12 @@ std::string CGUIInfoLabel::ReplaceAddonStrings(std::string &&label) return std::move(label); } +std::string CGUIInfoLabel::ReplaceControllerStrings(std::string&& label) +{ + ReplaceSpecialKeywordReferences(label, "FEATURE", ControllerFeatureReplacer); + return std::move(label); +} + enum EINFOFORMAT { NONE = 0, FORMATINFO, FORMATESCINFO, FORMATVAR, FORMATESCVAR }; typedef struct @@ -272,7 +290,9 @@ void CGUIInfoLabel::Parse(const std::string& label, std::string work = ReplaceLocalize(label); // Step 2: Replace all $ADDON[id number] with the real string work = ReplaceAddonStrings(std::move(work)); - // Step 3: Find all $INFO[info,prefix,postfix] blocks + // Step 3: Replace all game controller strings with the real string + work = ReplaceControllerStrings(std::move(work)); + // Step 4: Find all $INFO[info,prefix,postfix] blocks EINFOFORMAT format; do { diff --git a/xbmc/guilib/guiinfo/GUIInfoLabel.h b/xbmc/guilib/guiinfo/GUIInfoLabel.h index 3bb4452e9f..fd5da50154 100644 --- a/xbmc/guilib/guiinfo/GUIInfoLabel.h +++ b/xbmc/guilib/guiinfo/GUIInfoLabel.h @@ -92,6 +92,16 @@ public: */ static std::string ReplaceAddonStrings(std::string &&label); + /*! + * \brief Replaces instances of $FEATURE[feature name, controller ID] with + * the appropriate localized controller string + * + * \param label The text to replace + * + * \return text with any controller strings filled in + */ + static std::string ReplaceControllerStrings(std::string&& label); + typedef std::function<std::string(const std::string&)> StringReplacerFunc; /*! |