From 1faecd8853cf8bdfe23b20faa2d345804ef17f7f Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 15 Feb 2024 22:05:58 +0900 Subject: [PATCH] Qt: Fix labels when changing multi-tap controller type --- src/core/pad.h | 2 -- .../controllersettingswindow.cpp | 27 ++++++++++--------- src/duckstation-qt/controllersettingswindow.h | 5 +++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/core/pad.h b/src/core/pad.h index 59f503f92..227ac2d39 100644 --- a/src/core/pad.h +++ b/src/core/pad.h @@ -13,8 +13,6 @@ class Multitap; namespace Pad { -static constexpr u32 NUM_SLOTS = 2; - void Initialize(); void Shutdown(); void Reset(); diff --git a/src/duckstation-qt/controllersettingswindow.cpp b/src/duckstation-qt/controllersettingswindow.cpp index 7be208b81..d0b080447 100644 --- a/src/duckstation-qt/controllersettingswindow.cpp +++ b/src/duckstation-qt/controllersettingswindow.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "controllersettingswindow.h" @@ -370,14 +370,7 @@ void ControllerSettingsWindow::createWidgets() } // load mtap settings - const MultitapMode mtap_mode = - Settings::ParseMultitapModeName( - getStringValue("ControllerPorts", "MultitapMode", Settings::GetMultitapModeName(Settings::DEFAULT_MULTITAP_MODE)) - .c_str()) - .value_or(Settings::DEFAULT_MULTITAP_MODE); - const std::array mtap_enabled = { - {(mtap_mode == MultitapMode::Port1Only || mtap_mode == MultitapMode::BothPorts), - (mtap_mode == MultitapMode::Port2Only || mtap_mode == MultitapMode::BothPorts)}}; + const std::array mtap_enabled = getEnabledMultitaps(); // we reorder things a little to make it look less silly for mtap static constexpr const std::array mtap_port_order = {{0, 2, 3, 4, 1, 5, 6, 7}}; @@ -431,14 +424,13 @@ void ControllerSettingsWindow::updateListDescription(u32 global_slot, Controller bool is_ok; if (item_data.toUInt(&is_ok) == global_slot && is_ok) { - // const bool is_mtap_port = Controller::PadIsMultitapSlot(global_slot); + const std::array mtap_enabled = getEnabledMultitaps(); const auto [port, slot] = Controller::ConvertPadToPortAndSlot(global_slot); - const bool mtap_enabled = getBoolValue("Pad", (port == 0) ? "MultitapPort1" : "MultitapPort2", false); const Controller::ControllerInfo* ci = Controller::GetControllerInfo(widget->getControllerType()); const QString display_name(ci ? qApp->translate("ControllerType", ci->display_name) : QStringLiteral("Unknown")); - item->setText(mtap_enabled ? + item->setText(mtap_enabled[port] ? (tr("Controller Port %1%2\n%3").arg(port + 1).arg(s_mtap_slot_names[slot]).arg(display_name)) : tr("Controller Port %1\n%2").arg(port + 1).arg(display_name)); item->setIcon(widget->getIcon()); @@ -446,6 +438,17 @@ void ControllerSettingsWindow::updateListDescription(u32 global_slot, Controller } } } + +std::array ControllerSettingsWindow::getEnabledMultitaps() const +{ + const MultitapMode mtap_mode = + Settings::ParseMultitapModeName( + getStringValue("ControllerPorts", "MultitapMode", Settings::GetMultitapModeName(Settings::DEFAULT_MULTITAP_MODE)) + .c_str()) + .value_or(Settings::DEFAULT_MULTITAP_MODE); + return {{(mtap_mode == MultitapMode::Port1Only || mtap_mode == MultitapMode::BothPorts), + (mtap_mode == MultitapMode::Port2Only || mtap_mode == MultitapMode::BothPorts)}}; +} void ControllerSettingsWindow::refreshProfileList() { const std::vector names(InputManager::GetInputProfileNames()); diff --git a/src/duckstation-qt/controllersettingswindow.h b/src/duckstation-qt/controllersettingswindow.h index 9283d6e4f..ae268b54d 100644 --- a/src/duckstation-qt/controllersettingswindow.h +++ b/src/duckstation-qt/controllersettingswindow.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -14,6 +14,7 @@ #include #include #include + #include #include @@ -89,6 +90,8 @@ private: void refreshProfileList(); void switchProfile(const QString& name); + std::array getEnabledMultitaps() const; + Ui::ControllerSettingsWindow m_ui; ControllerGlobalSettingsWidget* m_global_settings = nullptr;