Qt: Fix labels when changing multi-tap controller type

This commit is contained in:
Stenzek 2024-02-15 22:05:58 +09:00
parent d9846093c3
commit 1faecd8853
No known key found for this signature in database
3 changed files with 19 additions and 15 deletions

View file

@ -13,8 +13,6 @@ class Multitap;
namespace Pad {
static constexpr u32 NUM_SLOTS = 2;
void Initialize();
void Shutdown();
void Reset();

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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<bool, 2> mtap_enabled = {
{(mtap_mode == MultitapMode::Port1Only || mtap_mode == MultitapMode::BothPorts),
(mtap_mode == MultitapMode::Port2Only || mtap_mode == MultitapMode::BothPorts)}};
const std::array<bool, 2> mtap_enabled = getEnabledMultitaps();
// we reorder things a little to make it look less silly for mtap
static constexpr const std::array<u32, MAX_PORTS> 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<bool, 2> 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<bool, 2> 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<std::string> names(InputManager::GetInputProfileNames());

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once
@ -14,6 +14,7 @@
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtWidgets/QDialog>
#include <array>
#include <string>
@ -89,6 +90,8 @@ private:
void refreshProfileList();
void switchProfile(const QString& name);
std::array<bool, 2> getEnabledMultitaps() const;
Ui::ControllerSettingsWindow m_ui;
ControllerGlobalSettingsWidget* m_global_settings = nullptr;