mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
Qt: fix emulated button reset
This commit is contained in:
parent
95060efb7d
commit
cb1b71bc57
@ -226,6 +226,11 @@ namespace cfg
|
||||
return m_value;
|
||||
}
|
||||
|
||||
T get_default() const
|
||||
{
|
||||
return def;
|
||||
}
|
||||
|
||||
void set(T value)
|
||||
{
|
||||
m_value = value;
|
||||
|
@ -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<T>* 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<T>* item = get_button(id))
|
||||
|
@ -9,12 +9,17 @@
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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<int>(pad_button::pad_button_max_enum); p++)
|
||||
{
|
||||
const QString translated = localized_emu::translated_pad_button(static_cast<pad_button>(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<int>())
|
||||
return;
|
||||
|
||||
const pad_button btn_id = static_cast<pad_button>(combo->itemData(index).toInt());
|
||||
const pad_button btn_id = static_cast<pad_button>(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<int>())
|
||||
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<buzz_btn>(data.toInt()));
|
||||
break;
|
||||
case pad_type::turntable:
|
||||
def_btn_id = ::at32(g_cfg_turntable.players, player)->default_pad_button(static_cast<turntable_btn>(data.toInt()));
|
||||
break;
|
||||
case pad_type::ghltar:
|
||||
def_btn_id = ::at32(g_cfg_ghltar.players, player)->default_pad_button(static_cast<ghltar_btn>(data.toInt()));
|
||||
break;
|
||||
case pad_type::usio:
|
||||
def_btn_id = ::at32(g_cfg_usio.players, player)->default_pad_button(static_cast<usio_btn>(data.toInt()));
|
||||
break;
|
||||
case pad_type::ds3gem:
|
||||
def_btn_id = ::at32(g_cfg_gem.players, player)->default_pad_button(static_cast<gem_btn>(data.toInt()));
|
||||
break;
|
||||
}
|
||||
|
||||
combo->setCurrentIndex(combo->findData(static_cast<int>(def_btn_id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@
|
||||
|
||||
#include "Emu/Io/pad_types.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QTabWidget>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class emulated_pad_settings_dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -30,4 +33,6 @@ private:
|
||||
void reset_config();
|
||||
|
||||
pad_type m_type;
|
||||
|
||||
std::array<std::vector<QComboBox*>, 7> m_combos{};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user