mirror of https://github.com/PCSX2/pcsx2.git
Qt: Add clear bindings button to controllers
This commit is contained in:
parent
332346449f
commit
cefe4b773c
|
@ -83,6 +83,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearBindings">
|
||||
<property name="text">
|
||||
<string>Clear Bindings</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="file-reduce-line"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -45,6 +45,7 @@ ControllerBindingWidget::ControllerBindingWidget(QWidget* parent, ControllerSett
|
|||
SettingWidgetBinder::BindWidgetToStringSetting(nullptr, m_ui.controllerType, m_config_section, "Type", "None");
|
||||
connect(m_ui.controllerType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ControllerBindingWidget::onTypeChanged);
|
||||
connect(m_ui.automaticBinding, &QPushButton::clicked, this, &ControllerBindingWidget::doAutomaticBinding);
|
||||
connect(m_ui.clearBindings, &QPushButton::clicked, this, &ControllerBindingWidget::doClearBindings);
|
||||
}
|
||||
|
||||
ControllerBindingWidget::~ControllerBindingWidget() = default;
|
||||
|
@ -107,6 +108,22 @@ void ControllerBindingWidget::doAutomaticBinding()
|
|||
menu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::doClearBindings()
|
||||
{
|
||||
if (QMessageBox::question(QtUtils::GetRootWidget(this), tr("Clear Bindings"),
|
||||
tr("Are you sure you want to clear all bindings for this controller? This action cannot be undone.")) != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
PAD::ClearPortBindings(*Host::Internal::GetBaseSettingsLayer(), m_port_number);
|
||||
}
|
||||
|
||||
saveAndRefresh();
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
|
||||
{
|
||||
std::vector<std::pair<GenericInputBinding, std::string>> mapping = InputManager::GetGenericBindingMapping(device.toStdString());
|
||||
|
@ -123,13 +140,16 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
|
|||
result = PAD::MapController(*Host::Internal::GetBaseSettingsLayer(), m_port_number, mapping);
|
||||
}
|
||||
|
||||
// force a refresh after mapping
|
||||
if (result)
|
||||
{
|
||||
// force a refresh after mapping
|
||||
onTypeChanged();
|
||||
QtHost::QueueSettingsSave();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
saveAndRefresh();
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::saveAndRefresh()
|
||||
{
|
||||
onTypeChanged();
|
||||
QtHost::QueueSettingsSave();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,10 +40,12 @@ public:
|
|||
private Q_SLOTS:
|
||||
void onTypeChanged();
|
||||
void doAutomaticBinding();
|
||||
void doClearBindings();
|
||||
|
||||
private:
|
||||
void populateControllerTypes();
|
||||
void doDeviceAutomaticBinding(const QString& device);
|
||||
void saveAndRefresh();
|
||||
|
||||
Ui::ControllerBindingWidget m_ui;
|
||||
|
||||
|
|
|
@ -342,6 +342,19 @@ std::vector<std::string> PAD::GetControllerBinds(const std::string_view& type)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void PAD::ClearPortBindings(SettingsInterface& si, u32 port)
|
||||
{
|
||||
const std::string section(StringUtil::StdStringFromFormat("Pad%u", port + 1));
|
||||
const std::string type(si.GetStringValue(section.c_str(), "Type", GetDefaultPadType(port)));
|
||||
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
for (u32 i = 0; i < info->num_bindings; i++)
|
||||
si.DeleteValue(section.c_str(), info->bindings[i].name);
|
||||
}
|
||||
|
||||
PAD::VibrationCapabilities PAD::GetControllerVibrationCapabilities(const std::string_view& type)
|
||||
{
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
|
|
|
@ -54,6 +54,9 @@ namespace PAD
|
|||
/// Restores default configuration.
|
||||
void SetDefaultConfig(SettingsInterface& si);
|
||||
|
||||
/// Clears all bindings for a given port.
|
||||
void ClearPortBindings(SettingsInterface& si, u32 port);
|
||||
|
||||
/// Updates vibration and other internal state. Called at the *end* of a frame.
|
||||
void Update();
|
||||
|
||||
|
|
Loading…
Reference in New Issue