Qt: add button to remove gamepad config
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Emu/system_utils.hpp"
|
#include "Emu/system_utils.hpp"
|
||||||
|
#include "Utilities/File.h"
|
||||||
|
|
||||||
#include "Input/pad_thread.h"
|
#include "Input/pad_thread.h"
|
||||||
#include "Input/gui_pad_thread.h"
|
#include "Input/gui_pad_thread.h"
|
||||||
@@ -86,21 +87,7 @@ pad_settings_dialog::pad_settings_dialog(std::shared_ptr<gui_settings> gui_setti
|
|||||||
|
|
||||||
if (m_title_id.empty())
|
if (m_title_id.empty())
|
||||||
{
|
{
|
||||||
const QString input_config_dir = QString::fromStdString(rpcs3::utils::get_input_config_dir(m_title_id));
|
const auto [config_files, active_config_file] = get_config_files();
|
||||||
QStringList config_files = gui::utils::get_dir_entries(QDir(input_config_dir), QStringList() << "*.yml");
|
|
||||||
QString active_config_file = QString::fromStdString(g_cfg_input_configs.active_configs.get_value(g_cfg_input_configs.global_key));
|
|
||||||
|
|
||||||
if (!config_files.contains(active_config_file))
|
|
||||||
{
|
|
||||||
const QString default_config_file = QString::fromStdString(g_cfg_input_configs.default_config);
|
|
||||||
|
|
||||||
if (!config_files.contains(default_config_file) && CreateConfigFile(input_config_dir, default_config_file))
|
|
||||||
{
|
|
||||||
config_files.prepend(default_config_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
active_config_file = default_config_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const QString& profile : config_files)
|
for (const QString& profile : config_files)
|
||||||
{
|
{
|
||||||
@@ -145,6 +132,9 @@ pad_settings_dialog::pad_settings_dialog(std::shared_ptr<gui_settings> gui_setti
|
|||||||
// Pushbutton: Add config file
|
// Pushbutton: Add config file
|
||||||
connect(ui->b_addConfig, &QAbstractButton::clicked, this, &pad_settings_dialog::AddConfigFile);
|
connect(ui->b_addConfig, &QAbstractButton::clicked, this, &pad_settings_dialog::AddConfigFile);
|
||||||
|
|
||||||
|
// Pushbutton: Remove config file
|
||||||
|
connect(ui->b_remConfig, &QAbstractButton::clicked, this, &pad_settings_dialog::RemoveConfigFile);
|
||||||
|
|
||||||
ui->buttonBox->button(QDialogButtonBox::Reset)->setText(tr("Filter Noise"));
|
ui->buttonBox->button(QDialogButtonBox::Reset)->setText(tr("Filter Noise"));
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](QAbstractButton* button)
|
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](QAbstractButton* button)
|
||||||
@@ -272,6 +262,27 @@ void pad_settings_dialog::showEvent(QShowEvent* event)
|
|||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<QStringList, QString> pad_settings_dialog::get_config_files()
|
||||||
|
{
|
||||||
|
const QString input_config_dir = QString::fromStdString(rpcs3::utils::get_input_config_dir(m_title_id));
|
||||||
|
QStringList config_files = gui::utils::get_dir_entries(QDir(input_config_dir), QStringList() << "*.yml");
|
||||||
|
QString active_config_file = QString::fromStdString(g_cfg_input_configs.active_configs.get_value(g_cfg_input_configs.global_key));
|
||||||
|
|
||||||
|
if (!config_files.contains(active_config_file))
|
||||||
|
{
|
||||||
|
const QString default_config_file = QString::fromStdString(g_cfg_input_configs.default_config);
|
||||||
|
|
||||||
|
if (!config_files.contains(default_config_file) && CreateConfigFile(input_config_dir, default_config_file))
|
||||||
|
{
|
||||||
|
config_files.prepend(default_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
active_config_file = default_config_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair<QStringList, QString>(std::move(config_files), std::move(active_config_file));
|
||||||
|
}
|
||||||
|
|
||||||
void pad_settings_dialog::InitButtons()
|
void pad_settings_dialog::InitButtons()
|
||||||
{
|
{
|
||||||
m_pad_buttons = new QButtonGroup(this);
|
m_pad_buttons = new QButtonGroup(this);
|
||||||
@@ -321,6 +332,7 @@ void pad_settings_dialog::InitButtons()
|
|||||||
|
|
||||||
m_pad_buttons->addButton(ui->b_refresh, button_ids::id_refresh);
|
m_pad_buttons->addButton(ui->b_refresh, button_ids::id_refresh);
|
||||||
m_pad_buttons->addButton(ui->b_addConfig, button_ids::id_add_config_file);
|
m_pad_buttons->addButton(ui->b_addConfig, button_ids::id_add_config_file);
|
||||||
|
m_pad_buttons->addButton(ui->b_remConfig, button_ids::id_remove_config_file);
|
||||||
|
|
||||||
connect(m_pad_buttons, &QButtonGroup::idClicked, this, &pad_settings_dialog::OnPadButtonClicked);
|
connect(m_pad_buttons, &QButtonGroup::idClicked, this, &pad_settings_dialog::OnPadButtonClicked);
|
||||||
|
|
||||||
@@ -1320,6 +1332,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
|
|||||||
case button_ids::id_pad_begin:
|
case button_ids::id_pad_begin:
|
||||||
case button_ids::id_pad_end:
|
case button_ids::id_pad_end:
|
||||||
case button_ids::id_add_config_file:
|
case button_ids::id_add_config_file:
|
||||||
|
case button_ids::id_remove_config_file:
|
||||||
case button_ids::id_refresh:
|
case button_ids::id_refresh:
|
||||||
return;
|
return;
|
||||||
case button_ids::id_reset_parameters:
|
case button_ids::id_reset_parameters:
|
||||||
@@ -1636,6 +1649,8 @@ void pad_settings_dialog::ChangeConfig(const QString& config_file)
|
|||||||
|
|
||||||
m_config_file = config_file.toStdString();
|
m_config_file = config_file.toStdString();
|
||||||
|
|
||||||
|
ui->b_remConfig->setEnabled(m_title_id.empty() && m_config_file != g_cfg_input_configs.default_config);
|
||||||
|
|
||||||
// Load in order to get the pad handlers
|
// Load in order to get the pad handlers
|
||||||
if (!g_cfg_input.load(m_title_id, m_config_file, true))
|
if (!g_cfg_input.load(m_title_id, m_config_file, true))
|
||||||
{
|
{
|
||||||
@@ -1810,6 +1825,44 @@ void pad_settings_dialog::AddConfigFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pad_settings_dialog::RemoveConfigFile()
|
||||||
|
{
|
||||||
|
const std::string config_to_remove = m_config_file;
|
||||||
|
const QString q_config_to_remove = QString::fromStdString(config_to_remove);
|
||||||
|
|
||||||
|
if (config_to_remove == g_cfg_input_configs.default_config)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Warning!"), tr("Can't remove default configuration '%0'.").arg(q_config_to_remove));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QMessageBox::question(this, tr("Remove Configuration?"), tr("Do you really want to remove the configuration '%0'?").arg(q_config_to_remove)) != QMessageBox::StandardButton::Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string filepath = fmt::format("%s%s.yml", rpcs3::utils::get_input_config_dir(m_title_id), config_to_remove);
|
||||||
|
|
||||||
|
if (!fs::remove_file(filepath))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Warning!"), tr("Failed to remove '%0'.").arg(QString::fromStdString(filepath)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto [config_files, active_config_file] = get_config_files();
|
||||||
|
|
||||||
|
ui->chooseConfig->setCurrentText(active_config_file);
|
||||||
|
ui->chooseConfig->removeItem(ui->chooseConfig->findText(q_config_to_remove));
|
||||||
|
|
||||||
|
// Save new config if we removed the currently saved config
|
||||||
|
if (active_config_file == q_config_to_remove)
|
||||||
|
{
|
||||||
|
save(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::information(this, tr("Removed Configuration"), tr("Removed configuration '%0'.\nThe selected configuration is now '%1'.").arg(q_config_to_remove).arg(active_config_file));
|
||||||
|
}
|
||||||
|
|
||||||
void pad_settings_dialog::RefreshHandlers()
|
void pad_settings_dialog::RefreshHandlers()
|
||||||
{
|
{
|
||||||
const u32 player_id = GetPlayerIndex();
|
const u32 player_id = GetPlayerIndex();
|
||||||
@@ -1949,27 +2002,30 @@ void pad_settings_dialog::ApplyCurrentPlayerConfig(int new_player_id)
|
|||||||
cfg.product_id.set(info.product_id);
|
cfg.product_id.set(info.product_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pad_settings_dialog::SaveExit()
|
void pad_settings_dialog::save(bool check_duplicates)
|
||||||
{
|
{
|
||||||
ApplyCurrentPlayerConfig(m_last_player_id);
|
ApplyCurrentPlayerConfig(m_last_player_id);
|
||||||
|
|
||||||
for (const auto& [player_id, key] : m_duplicate_buttons)
|
if (check_duplicates)
|
||||||
{
|
{
|
||||||
if (!key.empty())
|
for (const auto& [player_id, key] : m_duplicate_buttons)
|
||||||
{
|
{
|
||||||
int result = QMessageBox::Yes;
|
if (!key.empty())
|
||||||
m_gui_settings->ShowConfirmationBox(
|
{
|
||||||
tr("Warning!"),
|
int result = QMessageBox::Yes;
|
||||||
tr("The %0 button <b>%1</b> of <b>Player %2</b> was assigned at least twice.<br>Please consider adjusting the configuration.<br><br>Continue anyway?<br>")
|
m_gui_settings->ShowConfirmationBox(
|
||||||
.arg(QString::fromStdString(g_cfg_input.player[player_id]->handler.to_string()))
|
tr("Warning!"),
|
||||||
.arg(QString::fromStdString(key))
|
tr("The %0 button <b>%1</b> of <b>Player %2</b> was assigned at least twice.<br>Please consider adjusting the configuration.<br><br>Continue anyway?<br>")
|
||||||
.arg(player_id + 1),
|
.arg(QString::fromStdString(g_cfg_input.player[player_id]->handler.to_string()))
|
||||||
gui::ib_same_buttons, &result, this);
|
.arg(QString::fromStdString(key))
|
||||||
|
.arg(player_id + 1),
|
||||||
|
gui::ib_same_buttons, &result, this);
|
||||||
|
|
||||||
if (result == QMessageBox::No)
|
if (result == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1979,6 +2035,11 @@ void pad_settings_dialog::SaveExit()
|
|||||||
g_cfg_input_configs.save();
|
g_cfg_input_configs.save();
|
||||||
|
|
||||||
g_cfg_input.save(m_title_id, m_config_file);
|
g_cfg_input.save(m_title_id, m_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pad_settings_dialog::SaveExit()
|
||||||
|
{
|
||||||
|
save(true);
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ class pad_settings_dialog : public QDialog
|
|||||||
id_reset_parameters,
|
id_reset_parameters,
|
||||||
id_blacklist,
|
id_blacklist,
|
||||||
id_refresh,
|
id_refresh,
|
||||||
id_add_config_file
|
id_add_config_file,
|
||||||
|
id_remove_config_file
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pad_button
|
struct pad_button
|
||||||
@@ -101,6 +102,7 @@ private Q_SLOTS:
|
|||||||
void ChangeDevice(int index);
|
void ChangeDevice(int index);
|
||||||
void HandleDeviceClassChange(u32 class_id) const;
|
void HandleDeviceClassChange(u32 class_id) const;
|
||||||
void AddConfigFile();
|
void AddConfigFile();
|
||||||
|
void RemoveConfigFile();
|
||||||
/** Update the current player config with the GUI values. */
|
/** Update the current player config with the GUI values. */
|
||||||
void ApplyCurrentPlayerConfig(int new_player_id);
|
void ApplyCurrentPlayerConfig(int new_player_id);
|
||||||
void RefreshPads();
|
void RefreshPads();
|
||||||
@@ -192,6 +194,9 @@ private:
|
|||||||
void start_input_thread();
|
void start_input_thread();
|
||||||
void pause_input_thread();
|
void pause_input_thread();
|
||||||
|
|
||||||
|
std::pair<QStringList, QString> get_config_files();
|
||||||
|
|
||||||
|
void save(bool check_duplicates);
|
||||||
void SaveExit();
|
void SaveExit();
|
||||||
void CancelExit();
|
void CancelExit();
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,17 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="b_addConfig">
|
<widget class="QPushButton" name="b_addConfig">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add Configuration</string>
|
<string>Add New</string>
|
||||||
|
</property>
|
||||||
|
<property name="autoDefault">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="b_remConfig">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoDefault">
|
<property name="autoDefault">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
|||||||
Reference in New Issue
Block a user