From cb1b71bc57337fa80646942846ebd09b6c4642e4 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 22 May 2023 22:05:16 +0200 Subject: [PATCH] Qt: fix emulated button reset --- Utilities/Config.h | 5 ++ rpcs3/Emu/Io/emulated_pad_config.h | 10 ++++ .../rpcs3qt/emulated_pad_settings_dialog.cpp | 52 +++++++++++++++++-- rpcs3/rpcs3qt/emulated_pad_settings_dialog.h | 5 ++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Utilities/Config.h b/Utilities/Config.h index 889b058a53..361100dd7f 100644 --- a/Utilities/Config.h +++ b/Utilities/Config.h @@ -226,6 +226,11 @@ namespace cfg return m_value; } + T get_default() const + { + return def; + } + void set(T value) { m_value = value; diff --git a/rpcs3/Emu/Io/emulated_pad_config.h b/rpcs3/Emu/Io/emulated_pad_config.h index cd8d5d57d5..b010fc1dbc 100644 --- a/rpcs3/Emu/Io/emulated_pad_config.h +++ b/rpcs3/Emu/Io/emulated_pad_config.h @@ -73,6 +73,16 @@ struct emulated_pad_config : cfg::node return pad_button::pad_button_max_enum; } + pad_button default_pad_button(T id) + { + if (cfg_pad_btn* item = get_button(id)) + { + return item->get_default(); + } + + return pad_button::pad_button_max_enum; + } + void set_button(T id, pad_button btn_id) { if (cfg_pad_btn* item = get_button(id)) diff --git a/rpcs3/rpcs3qt/emulated_pad_settings_dialog.cpp b/rpcs3/rpcs3qt/emulated_pad_settings_dialog.cpp index b44b426f71..e02aa64b69 100644 --- a/rpcs3/rpcs3qt/emulated_pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/emulated_pad_settings_dialog.cpp @@ -9,12 +9,17 @@ #include "util/asm.hpp" #include -#include #include #include #include #include +enum button_role +{ + button = Qt::UserRole, + emulated_button +}; + emulated_pad_settings_dialog::emulated_pad_settings_dialog(pad_type type, QWidget* parent) : QDialog(parent), m_type(type) { @@ -114,7 +119,10 @@ void emulated_pad_settings_dialog::add_tabs(QTabWidget* tabs) for (int p = 0; p < static_cast(pad_button::pad_button_max_enum); p++) { const QString translated = localized_emu::translated_pad_button(static_cast(p)); - combo->addItem(translated, p); + combo->addItem(translated); + const int index = combo->findText(translated); + combo->setItemData(index, p, button_role::button); + combo->setItemData(index, i, button_role::emulated_button); } pad_button saved_btn_id = pad_button::pad_button_max_enum; @@ -144,11 +152,11 @@ void emulated_pad_settings_dialog::add_tabs(QTabWidget* tabs) if (index < 0 || !combo) return; - const QVariant data = combo->itemData(index); + const QVariant data = combo->itemData(index, button_role::button); if (!data.isValid() || !data.canConvert()) return; - const pad_button btn_id = static_cast(combo->itemData(index).toInt()); + const pad_button btn_id = static_cast(data.toInt()); switch (m_type) { @@ -176,6 +184,7 @@ void emulated_pad_settings_dialog::add_tabs(QTabWidget* tabs) col++; } + ::at32(m_combos, player).push_back(combo); h_layout->addWidget(combo); gb->setLayout(h_layout); grid_layout->addWidget(gb, row, col); @@ -265,4 +274,39 @@ void emulated_pad_settings_dialog::reset_config() g_cfg_gem.from_default(); break; } + + for (usz player = 0; player < m_combos.size(); player++) + { + for (QComboBox* combo : m_combos.at(player)) + { + if (!combo) + continue; + + const QVariant data = combo->itemData(0, button_role::emulated_button); + if (!data.isValid() || !data.canConvert()) + continue; + + pad_button def_btn_id = pad_button::pad_button_max_enum; + switch (m_type) + { + case pad_type::buzz: + def_btn_id = ::at32(g_cfg_buzz.players, player)->default_pad_button(static_cast(data.toInt())); + break; + case pad_type::turntable: + def_btn_id = ::at32(g_cfg_turntable.players, player)->default_pad_button(static_cast(data.toInt())); + break; + case pad_type::ghltar: + def_btn_id = ::at32(g_cfg_ghltar.players, player)->default_pad_button(static_cast(data.toInt())); + break; + case pad_type::usio: + def_btn_id = ::at32(g_cfg_usio.players, player)->default_pad_button(static_cast(data.toInt())); + break; + case pad_type::ds3gem: + def_btn_id = ::at32(g_cfg_gem.players, player)->default_pad_button(static_cast(data.toInt())); + break; + } + + combo->setCurrentIndex(combo->findData(static_cast(def_btn_id))); + } + } } diff --git a/rpcs3/rpcs3qt/emulated_pad_settings_dialog.h b/rpcs3/rpcs3qt/emulated_pad_settings_dialog.h index bb4646741c..d9e2e3702e 100644 --- a/rpcs3/rpcs3qt/emulated_pad_settings_dialog.h +++ b/rpcs3/rpcs3qt/emulated_pad_settings_dialog.h @@ -2,9 +2,12 @@ #include "Emu/Io/pad_types.h" +#include #include #include +#include + class emulated_pad_settings_dialog : public QDialog { Q_OBJECT @@ -30,4 +33,6 @@ private: void reset_config(); pad_type m_type; + + std::array, 7> m_combos{}; };