mirror of https://github.com/PCSX2/pcsx2.git
Qt: Hook up automatic mapping
This commit is contained in:
parent
fdc3ca1227
commit
d09b49e17c
|
@ -54,7 +54,6 @@ static bool InitializeConfig();
|
|||
static void HookSignals();
|
||||
static bool SetCriticalFolders();
|
||||
static void SetDefaultConfig();
|
||||
static void QueueSettingsSave();
|
||||
static void SaveSettings();
|
||||
}
|
||||
|
||||
|
@ -177,6 +176,11 @@ void QtHost::SetDefaultConfig()
|
|||
PAD::SetDefaultConfig(si);
|
||||
}
|
||||
|
||||
SettingsInterface* QtHost::GetBaseSettingsInterface()
|
||||
{
|
||||
return s_base_settings_interface.get();
|
||||
}
|
||||
|
||||
std::string QtHost::GetBaseStringSettingValue(const char* section, const char* key, const char* default_value /*= ""*/)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace QtHost
|
|||
void UpdateLogging();
|
||||
|
||||
/// Thread-safe settings access.
|
||||
SettingsInterface* GetBaseSettingsInterface();
|
||||
std::string GetBaseStringSettingValue(const char* section, const char* key, const char* default_value = "");
|
||||
bool GetBaseBoolSettingValue(const char* section, const char* key, bool default_value = false);
|
||||
int GetBaseIntSettingValue(const char* section, const char* key, int default_value = 0);
|
||||
|
@ -51,4 +52,5 @@ namespace QtHost
|
|||
bool AddBaseValueToStringList(const char* section, const char* key, const char* value);
|
||||
bool RemoveBaseValueFromStringList(const char* section, const char* key, const char* value);
|
||||
void RemoveBaseSettingValue(const char* section, const char* key);
|
||||
void QueueSettingsSave();
|
||||
} // namespace QtHost
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -39,13 +40,11 @@ ControllerBindingWidget::ControllerBindingWidget(QWidget* parent, ControllerSett
|
|||
onTypeChanged();
|
||||
|
||||
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.controllerType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ControllerBindingWidget::onTypeChanged);
|
||||
connect(m_ui.automaticBinding, &QPushButton::clicked, this, &ControllerBindingWidget::doAutomaticBinding);
|
||||
}
|
||||
|
||||
ControllerBindingWidget::~ControllerBindingWidget()
|
||||
{
|
||||
}
|
||||
ControllerBindingWidget::~ControllerBindingWidget() = default;
|
||||
|
||||
void ControllerBindingWidget::populateControllerTypes()
|
||||
{
|
||||
|
@ -80,6 +79,56 @@ void ControllerBindingWidget::onTypeChanged()
|
|||
m_ui.verticalLayout->addWidget(m_current_widget, 1);
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::doAutomaticBinding()
|
||||
{
|
||||
QMenu menu(this);
|
||||
bool added = false;
|
||||
|
||||
for (const QPair<QString, QString>& dev : m_dialog->getDeviceList())
|
||||
{
|
||||
// we set it as data, because the device list could get invalidated while the menu is up
|
||||
QAction* action = menu.addAction(QStringLiteral("%1 (%2)").arg(dev.first).arg(dev.second));
|
||||
action->setData(dev.first);
|
||||
connect(action, &QAction::triggered, this, [this, action]() {
|
||||
doDeviceAutomaticBinding(action->data().toString());
|
||||
});
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (!added)
|
||||
{
|
||||
QAction* action = menu.addAction(tr("No devices available"));
|
||||
action->setEnabled(false);
|
||||
}
|
||||
|
||||
menu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
|
||||
{
|
||||
std::vector<std::pair<GenericInputBinding, std::string>> mapping = InputManager::GetGenericBindingMapping(device.toStdString());
|
||||
if (mapping.empty())
|
||||
{
|
||||
QMessageBox::critical(QtUtils::GetRootWidget(this), tr("Automatic Binding"),
|
||||
tr("No generic bindings were generated for device '%1'").arg(device));
|
||||
return;
|
||||
}
|
||||
|
||||
bool result;
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
result = PAD::MapController(*QtHost::GetBaseSettingsInterface(), m_port_number, mapping);
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
// force a refresh after mapping
|
||||
onTypeChanged();
|
||||
QtHost::QueueSettingsSave();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ControllerBindingWidget_Base::ControllerBindingWidget_Base(ControllerBindingWidget* parent)
|
||||
|
|
|
@ -39,9 +39,11 @@ public:
|
|||
|
||||
private Q_SLOTS:
|
||||
void onTypeChanged();
|
||||
void doAutomaticBinding();
|
||||
|
||||
private:
|
||||
void populateControllerTypes();
|
||||
void doDeviceAutomaticBinding(const QString& device);
|
||||
|
||||
Ui::ControllerBindingWidget m_ui;
|
||||
|
||||
|
|
|
@ -89,18 +89,29 @@ void ControllerSettingsDialog::onCategoryCurrentRowChanged(int row)
|
|||
|
||||
void ControllerSettingsDialog::onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices)
|
||||
{
|
||||
m_device_list = devices;
|
||||
for (const QPair<QString, QString>& device : devices)
|
||||
m_global_settings->addDeviceToList(device.first, device.second);
|
||||
}
|
||||
|
||||
void ControllerSettingsDialog::onInputDeviceConnected(const QString& identifier, const QString& device_name)
|
||||
{
|
||||
m_device_list.emplace_back(identifier, device_name);
|
||||
m_global_settings->addDeviceToList(identifier, device_name);
|
||||
g_emu_thread->enumerateVibrationMotors();
|
||||
}
|
||||
|
||||
void ControllerSettingsDialog::onInputDeviceDisconnected(const QString& identifier)
|
||||
{
|
||||
for (auto iter = m_device_list.begin(); iter != m_device_list.end(); ++iter)
|
||||
{
|
||||
if (iter->first == identifier)
|
||||
{
|
||||
m_device_list.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_global_settings->removeDeviceFromList(identifier);
|
||||
g_emu_thread->enumerateVibrationMotors();
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
|
||||
HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; }
|
||||
|
||||
__fi const QList<QPair<QString, QString>>& getDeviceList() const { return m_device_list; }
|
||||
__fi const QStringList& getVibrationMotors() const { return m_vibration_motors; }
|
||||
|
||||
public Q_SLOTS:
|
||||
|
@ -70,5 +71,6 @@ private:
|
|||
std::array<ControllerBindingWidget*, MAX_PORTS> m_port_bindings{};
|
||||
HotkeySettingsWidget* m_hotkey_settings = nullptr;
|
||||
|
||||
QList<QPair<QString, QString>> m_device_list;
|
||||
QStringList m_vibration_motors;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue