Settings: Fix double source of truth for controller names
This commit is contained in:
parent
5477f2eae2
commit
3e99084770
|
@ -873,13 +873,14 @@ static const SettingInfo s_settings[] = {
|
||||||
nullptr, s_invert_settings, 0.0f},
|
nullptr, s_invert_settings, 0.0f},
|
||||||
};
|
};
|
||||||
|
|
||||||
const Controller::ControllerInfo AnalogController::INFO = {ControllerType::AnalogController,
|
const Controller::ControllerInfo AnalogController::INFO = {
|
||||||
"AnalogController",
|
ControllerType::AnalogController,
|
||||||
TRANSLATE_NOOP("ControllerType", "Analog Controller"),
|
"AnalogController",
|
||||||
ICON_PF_GAMEPAD,
|
TRANSLATE_NOOP("ControllerType", "Analog Controller"),
|
||||||
s_binding_info,
|
ICON_PF_GAMEPAD,
|
||||||
s_settings,
|
s_binding_info,
|
||||||
Controller::VibrationCapabilities::LargeSmallMotors};
|
s_settings,
|
||||||
|
Controller::VibrationCapabilities::LargeSmallMotors};
|
||||||
|
|
||||||
void AnalogController::LoadSettings(SettingsInterface& si, const char* section)
|
void AnalogController::LoadSettings(SettingsInterface& si, const char* section)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,9 +23,14 @@ static const Controller::ControllerInfo s_none_info = {ControllerType::None,
|
||||||
|
|
||||||
static const Controller::ControllerInfo* s_controller_info[] = {
|
static const Controller::ControllerInfo* s_controller_info[] = {
|
||||||
&s_none_info, &DigitalController::INFO, &AnalogController::INFO, &AnalogJoystick::INFO,
|
&s_none_info, &DigitalController::INFO, &AnalogController::INFO, &AnalogJoystick::INFO,
|
||||||
&NeGcon::INFO, &NeGconRumble::INFO,&GunCon::INFO, &PlayStationMouse::INFO,
|
&NeGcon::INFO, &NeGconRumble::INFO, &GunCon::INFO, &PlayStationMouse::INFO,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char* Controller::ControllerInfo::GetDisplayName() const
|
||||||
|
{
|
||||||
|
return Host::TranslateToCString("ControllerType", display_name);
|
||||||
|
}
|
||||||
|
|
||||||
Controller::Controller(u32 index) : m_index(index)
|
Controller::Controller(u32 index) : m_index(index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -100,7 +105,7 @@ std::unique_ptr<Controller> Controller::Create(ControllerType type, u32 index)
|
||||||
|
|
||||||
case ControllerType::NeGcon:
|
case ControllerType::NeGcon:
|
||||||
return NeGcon::Create(index);
|
return NeGcon::Create(index);
|
||||||
|
|
||||||
case ControllerType::NeGconRumble:
|
case ControllerType::NeGconRumble:
|
||||||
return NeGconRumble::Create(index);
|
return NeGconRumble::Create(index);
|
||||||
|
|
||||||
|
@ -112,8 +117,8 @@ std::unique_ptr<Controller> Controller::Create(ControllerType type, u32 index)
|
||||||
|
|
||||||
const char* Controller::GetDefaultPadType(u32 pad)
|
const char* Controller::GetDefaultPadType(u32 pad)
|
||||||
{
|
{
|
||||||
return Settings::GetControllerTypeName((pad == 0) ? Settings::DEFAULT_CONTROLLER_1_TYPE :
|
return GetControllerInfo((pad == 0) ? Settings::DEFAULT_CONTROLLER_1_TYPE : Settings::DEFAULT_CONTROLLER_2_TYPE)
|
||||||
Settings::DEFAULT_CONTROLLER_2_TYPE);
|
->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Controller::ControllerInfo* Controller::GetControllerInfo(ControllerType type)
|
const Controller::ControllerInfo* Controller::GetControllerInfo(ControllerType type)
|
||||||
|
@ -127,7 +132,7 @@ const Controller::ControllerInfo* Controller::GetControllerInfo(ControllerType t
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Controller::ControllerInfo* Controller::GetControllerInfo(const std::string_view& name)
|
const Controller::ControllerInfo* Controller::GetControllerInfo(std::string_view name)
|
||||||
{
|
{
|
||||||
for (const ControllerInfo* info : s_controller_info)
|
for (const ControllerInfo* info : s_controller_info)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
std::span<const ControllerBindingInfo> bindings;
|
std::span<const ControllerBindingInfo> bindings;
|
||||||
std::span<const SettingInfo> settings;
|
std::span<const SettingInfo> settings;
|
||||||
VibrationCapabilities vibration_caps;
|
VibrationCapabilities vibration_caps;
|
||||||
|
|
||||||
|
/// Returns localized controller type name.
|
||||||
|
const char* GetDisplayName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Default stick deadzone/sensitivity.
|
/// Default stick deadzone/sensitivity.
|
||||||
|
@ -106,7 +109,7 @@ public:
|
||||||
|
|
||||||
/// Returns general information for the specified controller type.
|
/// Returns general information for the specified controller type.
|
||||||
static const ControllerInfo* GetControllerInfo(ControllerType type);
|
static const ControllerInfo* GetControllerInfo(ControllerType type);
|
||||||
static const ControllerInfo* GetControllerInfo(const std::string_view& name);
|
static const ControllerInfo* GetControllerInfo(std::string_view name);
|
||||||
|
|
||||||
/// Converts a global pad index to a multitap port and slot.
|
/// Converts a global pad index to a multitap port and slot.
|
||||||
static std::tuple<u32, u32> ConvertPadToPortAndSlot(u32 index);
|
static std::tuple<u32, u32> ConvertPadToPortAndSlot(u32 index);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||||
|
|
||||||
#include "game_database.h"
|
#include "game_database.h"
|
||||||
|
#include "controller.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
@ -652,15 +653,16 @@ void GameDatabase::Entry::ApplySettings(Settings& settings, bool display_osd_mes
|
||||||
if (!supported_controller_string.empty())
|
if (!supported_controller_string.empty())
|
||||||
supported_controller_string.append(", ");
|
supported_controller_string.append(", ");
|
||||||
|
|
||||||
supported_controller_string.append(Settings::GetControllerTypeDisplayName(supported_ctype));
|
supported_controller_string.append(Controller::GetControllerInfo(supported_ctype)->GetDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Host::AddKeyedOSDMessage(
|
Host::AddKeyedOSDMessage(
|
||||||
"gamedb_controller_unsupported",
|
"gamedb_controller_unsupported",
|
||||||
fmt::format(
|
fmt::format(TRANSLATE_FS("OSDMessage",
|
||||||
TRANSLATE_FS("OSDMessage", "Controller in port {0} ({1}) is not supported for {2}.\nSupported controllers: "
|
"Controller in port {0} ({1}) is not supported for {2}.\nSupported controllers: "
|
||||||
"{3}\nPlease configure a supported controller from the list above."),
|
"{3}\nPlease configure a supported controller from the list above."),
|
||||||
i + 1u, Settings::GetControllerTypeDisplayName(ctype), System::GetGameTitle(), supported_controller_string),
|
i + 1u, Controller::GetControllerInfo(ctype)->GetDisplayName(), System::GetGameTitle(),
|
||||||
|
supported_controller_string),
|
||||||
Host::OSD_CRITICAL_ERROR_DURATION);
|
Host::OSD_CRITICAL_ERROR_DURATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -981,8 +983,8 @@ bool GameDatabase::ParseYamlEntry(Entry* entry, const ryml::ConstNodeRef& value)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ControllerType> ctype = Settings::ParseControllerTypeName(controller_str);
|
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(controller_str);
|
||||||
if (!ctype.has_value())
|
if (!cinfo)
|
||||||
{
|
{
|
||||||
Log_WarningFmt("Invalid controller type {} in {}", controller_str, entry->serial);
|
Log_WarningFmt("Invalid controller type {} in {}", controller_str, entry->serial);
|
||||||
continue;
|
continue;
|
||||||
|
@ -994,7 +996,7 @@ bool GameDatabase::ParseYamlEntry(Entry* entry, const ryml::ConstNodeRef& value)
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->supported_controllers |= (1u << static_cast<u16>(ctype.value()));
|
entry->supported_controllers |= (1u << static_cast<u16>(cinfo->type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,13 +187,17 @@ u32 Pad::GetMaximumRollbackFrames()
|
||||||
|
|
||||||
bool Pad::DoStateController(StateWrapper& sw, u32 i)
|
bool Pad::DoStateController(StateWrapper& sw, u32 i)
|
||||||
{
|
{
|
||||||
ControllerType controller_type = s_controllers[i] ? s_controllers[i]->GetType() : ControllerType::None;
|
const ControllerType controller_type = s_controllers[i] ? s_controllers[i]->GetType() : ControllerType::None;
|
||||||
ControllerType state_controller_type = controller_type;
|
ControllerType state_controller_type = controller_type;
|
||||||
|
|
||||||
sw.Do(&state_controller_type);
|
// Data type change...
|
||||||
|
u32 state_controller_type_value = static_cast<u32>(state_controller_type);
|
||||||
|
sw.Do(&state_controller_type_value);
|
||||||
|
state_controller_type = static_cast<ControllerType>(state_controller_type_value);
|
||||||
|
|
||||||
if (controller_type != state_controller_type)
|
if (controller_type != state_controller_type)
|
||||||
{
|
{
|
||||||
|
const Controller::ControllerInfo* state_cinfo = Controller::GetControllerInfo(state_controller_type);
|
||||||
Assert(sw.GetMode() == StateWrapper::Mode::Read);
|
Assert(sw.GetMode() == StateWrapper::Mode::Read);
|
||||||
|
|
||||||
// UI notification portion is separated from emulation portion (intentional condition check redundancy)
|
// UI notification portion is separated from emulation portion (intentional condition check redundancy)
|
||||||
|
@ -201,19 +205,19 @@ bool Pad::DoStateController(StateWrapper& sw, u32 i)
|
||||||
{
|
{
|
||||||
Host::AddFormattedOSDMessage(
|
Host::AddFormattedOSDMessage(
|
||||||
10.0f, TRANSLATE("OSDMessage", "Save state contains controller type %s in port %u, but %s is used. Switching."),
|
10.0f, TRANSLATE("OSDMessage", "Save state contains controller type %s in port %u, but %s is used. Switching."),
|
||||||
Settings::GetControllerTypeName(state_controller_type), i + 1u,
|
state_cinfo ? state_cinfo->GetDisplayName() : "", i + 1u,
|
||||||
Settings::GetControllerTypeName(controller_type));
|
Controller::GetControllerInfo(controller_type)->GetDisplayName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Host::AddFormattedOSDMessage(10.0f, TRANSLATE("OSDMessage", "Ignoring mismatched controller type %s in port %u."),
|
Host::AddFormattedOSDMessage(10.0f, TRANSLATE("OSDMessage", "Ignoring mismatched controller type %s in port %u."),
|
||||||
Settings::GetControllerTypeName(state_controller_type), i + 1u);
|
state_cinfo ? state_cinfo->GetDisplayName() : "", i + 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dev-friendly untranslated console log.
|
// dev-friendly untranslated console log.
|
||||||
Log_DevPrintf("Controller type mismatch in slot %u: state=%s(%u) ui=%s(%u) load_from_state=%s", i + 1u,
|
Log_DevPrintf("Controller type mismatch in slot %u: state=%s(%u) ui=%s(%u) load_from_state=%s", i + 1u,
|
||||||
Settings::GetControllerTypeName(state_controller_type), static_cast<unsigned>(state_controller_type),
|
state_cinfo ? state_cinfo->name : "", static_cast<unsigned>(state_controller_type),
|
||||||
Settings::GetControllerTypeName(controller_type), static_cast<unsigned>(controller_type),
|
Controller::GetControllerInfo(controller_type)->name, static_cast<unsigned>(controller_type),
|
||||||
g_settings.load_devices_from_save_states ? "yes" : "no");
|
g_settings.load_devices_from_save_states ? "yes" : "no");
|
||||||
|
|
||||||
if (g_settings.load_devices_from_save_states)
|
if (g_settings.load_devices_from_save_states)
|
||||||
|
|
|
@ -335,13 +335,8 @@ void Settings::Load(SettingsInterface& si)
|
||||||
si.GetStringValue("ControllerPorts", "MultitapMode", GetMultitapModeName(DEFAULT_MULTITAP_MODE)).c_str())
|
si.GetStringValue("ControllerPorts", "MultitapMode", GetMultitapModeName(DEFAULT_MULTITAP_MODE)).c_str())
|
||||||
.value_or(DEFAULT_MULTITAP_MODE);
|
.value_or(DEFAULT_MULTITAP_MODE);
|
||||||
|
|
||||||
controller_types[0] = ParseControllerTypeName(si.GetStringValue(Controller::GetSettingsSection(0).c_str(), "Type",
|
|
||||||
GetControllerTypeName(DEFAULT_CONTROLLER_1_TYPE))
|
|
||||||
.c_str())
|
|
||||||
.value_or(DEFAULT_CONTROLLER_1_TYPE);
|
|
||||||
|
|
||||||
const std::array<bool, 2> mtap_enabled = {{IsPort1MultitapEnabled(), IsPort2MultitapEnabled()}};
|
const std::array<bool, 2> mtap_enabled = {{IsPort1MultitapEnabled(), IsPort2MultitapEnabled()}};
|
||||||
for (u32 i = 1; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
||||||
{
|
{
|
||||||
// Ignore types when multitap not enabled
|
// Ignore types when multitap not enabled
|
||||||
const auto [port, slot] = Controller::ConvertPadToPortAndSlot(i);
|
const auto [port, slot] = Controller::ConvertPadToPortAndSlot(i);
|
||||||
|
@ -351,10 +346,10 @@ void Settings::Load(SettingsInterface& si)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller_types[i] = ParseControllerTypeName(si.GetStringValue(Controller::GetSettingsSection(i).c_str(), "Type",
|
const ControllerType default_type = (i == 0) ? DEFAULT_CONTROLLER_1_TYPE : DEFAULT_CONTROLLER_2_TYPE;
|
||||||
GetControllerTypeName(DEFAULT_CONTROLLER_2_TYPE))
|
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(si.GetTinyStringValue(
|
||||||
.c_str())
|
Controller::GetSettingsSection(i).c_str(), "Type", Controller::GetControllerInfo(default_type)->name));
|
||||||
.value_or(DEFAULT_CONTROLLER_2_TYPE);
|
controller_types[i] = cinfo ? cinfo->type : default_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_card_types[0] =
|
memory_card_types[0] =
|
||||||
|
@ -588,7 +583,11 @@ void Settings::Save(SettingsInterface& si, bool ignore_base) const
|
||||||
si.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot);
|
si.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot);
|
||||||
|
|
||||||
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
||||||
si.SetStringValue(Controller::GetSettingsSection(i).c_str(), "Type", GetControllerTypeName(controller_types[i]));
|
{
|
||||||
|
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(controller_types[i]);
|
||||||
|
DebugAssert(cinfo);
|
||||||
|
si.SetStringValue(Controller::GetSettingsSection(i).c_str(), "Type", cinfo->name);
|
||||||
|
}
|
||||||
|
|
||||||
si.SetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(memory_card_types[0]));
|
si.SetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(memory_card_types[0]));
|
||||||
si.SetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(memory_card_types[1]));
|
si.SetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(memory_card_types[1]));
|
||||||
|
@ -1569,43 +1568,6 @@ const char* Settings::GetDisplayScreenshotFormatExtension(DisplayScreenshotForma
|
||||||
return s_display_screenshot_format_extensions[static_cast<size_t>(format)];
|
return s_display_screenshot_format_extensions[static_cast<size_t>(format)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr const std::array s_controller_type_names = {
|
|
||||||
"None", "DigitalController", "AnalogController", "AnalogJoystick",
|
|
||||||
"GunCon", "PlayStationMouse", "NeGcon", "NeGconRumble"};
|
|
||||||
static constexpr const std::array s_controller_display_names = {
|
|
||||||
TRANSLATE_NOOP("ControllerType", "None"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "Digital Controller"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "Analog Controller (DualShock)"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "Analog Joystick"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "GunCon"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "PlayStation Mouse"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "NeGcon"),
|
|
||||||
TRANSLATE_NOOP("ControllerType", "NeGcon Rumble")};
|
|
||||||
|
|
||||||
std::optional<ControllerType> Settings::ParseControllerTypeName(std::string_view str)
|
|
||||||
{
|
|
||||||
int index = 0;
|
|
||||||
for (const char* name : s_controller_type_names)
|
|
||||||
{
|
|
||||||
if (StringUtil::EqualNoCase(str, name))
|
|
||||||
return static_cast<ControllerType>(index);
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Settings::GetControllerTypeName(ControllerType type)
|
|
||||||
{
|
|
||||||
return s_controller_type_names[static_cast<int>(type)];
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Settings::GetControllerTypeDisplayName(ControllerType type)
|
|
||||||
{
|
|
||||||
return Host::TranslateToCString("ControllerType", s_controller_display_names[static_cast<int>(type)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const std::array s_memory_card_type_names = {"None", "Shared", "PerGame",
|
static constexpr const std::array s_memory_card_type_names = {"None", "Shared", "PerGame",
|
||||||
"PerGameTitle", "PerGameFileTitle", "NonPersistent"};
|
"PerGameTitle", "PerGameFileTitle", "NonPersistent"};
|
||||||
static constexpr const std::array s_memory_card_type_display_names = {
|
static constexpr const std::array s_memory_card_type_display_names = {
|
||||||
|
|
|
@ -430,10 +430,6 @@ struct Settings
|
||||||
static const char* GetDisplayScreenshotFormatDisplayName(DisplayScreenshotFormat mode);
|
static const char* GetDisplayScreenshotFormatDisplayName(DisplayScreenshotFormat mode);
|
||||||
static const char* GetDisplayScreenshotFormatExtension(DisplayScreenshotFormat mode);
|
static const char* GetDisplayScreenshotFormatExtension(DisplayScreenshotFormat mode);
|
||||||
|
|
||||||
static std::optional<ControllerType> ParseControllerTypeName(std::string_view str);
|
|
||||||
static const char* GetControllerTypeName(ControllerType type);
|
|
||||||
static const char* GetControllerTypeDisplayName(ControllerType type);
|
|
||||||
|
|
||||||
static std::optional<MemoryCardType> ParseMemoryCardTypeName(const char* str);
|
static std::optional<MemoryCardType> ParseMemoryCardTypeName(const char* str);
|
||||||
static const char* GetMemoryCardTypeName(MemoryCardType type);
|
static const char* GetMemoryCardTypeName(MemoryCardType type);
|
||||||
static const char* GetMemoryCardTypeDisplayName(MemoryCardType type);
|
static const char* GetMemoryCardTypeDisplayName(MemoryCardType type);
|
||||||
|
|
|
@ -185,7 +185,7 @@ enum class DisplayScreenshotFormat : u8
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ControllerType
|
enum class ControllerType : u8
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DigitalController,
|
DigitalController,
|
||||||
|
|
|
@ -63,14 +63,18 @@ void ControllerBindingWidget::populateControllerTypes()
|
||||||
if (!cinfo)
|
if (!cinfo)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_ui.controllerType->addItem(qApp->translate("ControllerType", cinfo->display_name), QVariant(static_cast<int>(i)));
|
m_ui.controllerType->addItem(QString::fromUtf8(cinfo->GetDisplayName()), QVariant(static_cast<int>(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string controller_type_name(
|
m_controller_info = Controller::GetControllerInfo(
|
||||||
m_dialog->getStringValue(m_config_section.c_str(), "Type", Controller::GetDefaultPadType(m_port_number)));
|
m_dialog->getStringValue(m_config_section.c_str(), "Type", Controller::GetDefaultPadType(m_port_number)));
|
||||||
m_controller_type = Settings::ParseControllerTypeName(controller_type_name.c_str()).value_or(ControllerType::None);
|
if (!m_controller_info)
|
||||||
|
{
|
||||||
|
m_controller_info = Controller::GetControllerInfo(m_port_number == 0 ? Settings::DEFAULT_CONTROLLER_1_TYPE :
|
||||||
|
Settings::DEFAULT_CONTROLLER_2_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
const int index = m_ui.controllerType->findData(QVariant(static_cast<int>(m_controller_type)));
|
const int index = m_ui.controllerType->findData(QVariant(static_cast<int>(m_controller_info->type)));
|
||||||
if (index >= 0 && index != m_ui.controllerType->currentIndex())
|
if (index >= 0 && index != m_ui.controllerType->currentIndex())
|
||||||
{
|
{
|
||||||
QSignalBlocker sb(m_ui.controllerType);
|
QSignalBlocker sb(m_ui.controllerType);
|
||||||
|
@ -100,14 +104,13 @@ void ControllerBindingWidget::populateWidgets()
|
||||||
m_macros_widget = nullptr;
|
m_macros_widget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(m_controller_type);
|
const bool has_settings = !m_controller_info->settings.empty();
|
||||||
const bool has_settings = (cinfo && !cinfo->settings.empty());
|
const bool has_macros = !m_controller_info->bindings.empty();
|
||||||
const bool has_macros = (cinfo && !cinfo->bindings.empty());
|
|
||||||
m_ui.settings->setEnabled(has_settings);
|
m_ui.settings->setEnabled(has_settings);
|
||||||
m_ui.macros->setEnabled(has_macros);
|
m_ui.macros->setEnabled(has_macros);
|
||||||
|
|
||||||
m_bindings_widget = new QWidget(this);
|
m_bindings_widget = new QWidget(this);
|
||||||
switch (m_controller_type)
|
switch (m_controller_info->type)
|
||||||
{
|
{
|
||||||
case ControllerType::AnalogController:
|
case ControllerType::AnalogController:
|
||||||
{
|
{
|
||||||
|
@ -224,19 +227,19 @@ void ControllerBindingWidget::onTypeChanged()
|
||||||
if (!ok || index < 0 || index >= static_cast<int>(ControllerType::Count))
|
if (!ok || index < 0 || index >= static_cast<int>(ControllerType::Count))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_controller_type = static_cast<ControllerType>(index);
|
m_controller_info = Controller::GetControllerInfo(static_cast<ControllerType>(index));
|
||||||
|
DebugAssert(m_controller_info);
|
||||||
|
|
||||||
SettingsInterface* sif = m_dialog->getProfileSettingsInterface();
|
SettingsInterface* sif = m_dialog->getProfileSettingsInterface();
|
||||||
if (sif)
|
if (sif)
|
||||||
{
|
{
|
||||||
sif->SetStringValue(m_config_section.c_str(), "Type", Settings::GetControllerTypeName(m_controller_type));
|
sif->SetStringValue(m_config_section.c_str(), "Type", m_controller_info->name);
|
||||||
QtHost::SaveGameSettings(sif, false);
|
QtHost::SaveGameSettings(sif, false);
|
||||||
g_emu_thread->reloadGameSettings();
|
g_emu_thread->reloadGameSettings();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Host::SetBaseStringSettingValue(m_config_section.c_str(), "Type",
|
Host::SetBaseStringSettingValue(m_config_section.c_str(), "Type", m_controller_info->name);
|
||||||
Settings::GetControllerTypeName(m_controller_type));
|
|
||||||
Host::CommitBaseSettingChanges();
|
Host::CommitBaseSettingChanges();
|
||||||
g_emu_thread->applySettings();
|
g_emu_thread->applySettings();
|
||||||
}
|
}
|
||||||
|
@ -356,10 +359,7 @@ void ControllerBindingWidget::saveAndRefresh()
|
||||||
void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
||||||
{
|
{
|
||||||
SettingsInterface* sif = getDialog()->getProfileSettingsInterface();
|
SettingsInterface* sif = getDialog()->getProfileSettingsInterface();
|
||||||
const ControllerType type = getControllerType();
|
DebugAssert(m_controller_info);
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(type);
|
|
||||||
if (!cinfo)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QGroupBox* axis_gbox = nullptr;
|
QGroupBox* axis_gbox = nullptr;
|
||||||
QGridLayout* axis_layout = nullptr;
|
QGridLayout* axis_layout = nullptr;
|
||||||
|
@ -377,7 +377,7 @@ void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
||||||
constexpr int NUM_AXIS_COLUMNS = 2;
|
constexpr int NUM_AXIS_COLUMNS = 2;
|
||||||
int column = 0;
|
int column = 0;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
|
for (const Controller::ControllerBindingInfo& bi : m_controller_info->bindings)
|
||||||
{
|
{
|
||||||
if (bi.type == InputBindingInfo::Type::Axis || bi.type == InputBindingInfo::Type::HalfAxis ||
|
if (bi.type == InputBindingInfo::Type::Axis || bi.type == InputBindingInfo::Type::HalfAxis ||
|
||||||
bi.type == InputBindingInfo::Type::Pointer)
|
bi.type == InputBindingInfo::Type::Pointer)
|
||||||
|
@ -406,7 +406,7 @@ void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
||||||
const int num_button_columns = axis_layout ? 2 : 4;
|
const int num_button_columns = axis_layout ? 2 : 4;
|
||||||
row = 0;
|
row = 0;
|
||||||
column = 0;
|
column = 0;
|
||||||
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
|
for (const Controller::ControllerBindingInfo& bi : m_controller_info->bindings)
|
||||||
{
|
{
|
||||||
if (bi.type == InputBindingInfo::Type::Button)
|
if (bi.type == InputBindingInfo::Type::Button)
|
||||||
{
|
{
|
||||||
|
@ -452,13 +452,10 @@ void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
||||||
void ControllerBindingWidget::bindBindingWidgets(QWidget* parent)
|
void ControllerBindingWidget::bindBindingWidgets(QWidget* parent)
|
||||||
{
|
{
|
||||||
SettingsInterface* sif = getDialog()->getProfileSettingsInterface();
|
SettingsInterface* sif = getDialog()->getProfileSettingsInterface();
|
||||||
const ControllerType type = getControllerType();
|
DebugAssert(m_controller_info);
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(type);
|
|
||||||
if (!cinfo)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const std::string& config_section = getConfigSection();
|
const std::string& config_section = getConfigSection();
|
||||||
for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
|
for (const Controller::ControllerBindingInfo& bi : m_controller_info->bindings)
|
||||||
{
|
{
|
||||||
if (bi.type == InputBindingInfo::Type::Axis || bi.type == InputBindingInfo::Type::HalfAxis ||
|
if (bi.type == InputBindingInfo::Type::Axis || bi.type == InputBindingInfo::Type::HalfAxis ||
|
||||||
bi.type == InputBindingInfo::Type::Button || bi.type == InputBindingInfo::Type::Pointer)
|
bi.type == InputBindingInfo::Type::Button || bi.type == InputBindingInfo::Type::Pointer)
|
||||||
|
@ -466,7 +463,7 @@ void ControllerBindingWidget::bindBindingWidgets(QWidget* parent)
|
||||||
InputBindingWidget* widget = parent->findChild<InputBindingWidget*>(QString::fromUtf8(bi.name));
|
InputBindingWidget* widget = parent->findChild<InputBindingWidget*>(QString::fromUtf8(bi.name));
|
||||||
if (!widget)
|
if (!widget)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("No widget found for '%s' (%s)", bi.name, cinfo->name);
|
Log_ErrorPrintf("No widget found for '%s' (%s)", bi.name, m_controller_info->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +471,7 @@ void ControllerBindingWidget::bindBindingWidgets(QWidget* parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cinfo->vibration_caps)
|
switch (m_controller_info->vibration_caps)
|
||||||
{
|
{
|
||||||
case Controller::VibrationCapabilities::LargeSmallMotors:
|
case Controller::VibrationCapabilities::LargeSmallMotors:
|
||||||
{
|
{
|
||||||
|
@ -549,12 +546,8 @@ ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroWidget* pare
|
||||||
|
|
||||||
ControllerSettingsWindow* dialog = m_bwidget->getDialog();
|
ControllerSettingsWindow* dialog = m_bwidget->getDialog();
|
||||||
const std::string& section = m_bwidget->getConfigSection();
|
const std::string& section = m_bwidget->getConfigSection();
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(m_bwidget->getControllerType());
|
const Controller::ControllerInfo* cinfo = m_bwidget->getControllerInfo();
|
||||||
if (!cinfo)
|
DebugAssert(cinfo);
|
||||||
{
|
|
||||||
// Shouldn't ever happen.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load binds (single string joined by &)
|
// load binds (single string joined by &)
|
||||||
const std::string binds_string(
|
const std::string binds_string(
|
||||||
|
@ -652,9 +645,8 @@ void ControllerMacroEditWidget::updateFrequencyText()
|
||||||
void ControllerMacroEditWidget::updateBinds()
|
void ControllerMacroEditWidget::updateBinds()
|
||||||
{
|
{
|
||||||
ControllerSettingsWindow* dialog = m_bwidget->getDialog();
|
ControllerSettingsWindow* dialog = m_bwidget->getDialog();
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(m_bwidget->getControllerType());
|
const Controller::ControllerInfo* cinfo = m_bwidget->getControllerInfo();
|
||||||
if (!cinfo)
|
DebugAssert(cinfo);
|
||||||
return;
|
|
||||||
|
|
||||||
std::vector<const Controller::ControllerBindingInfo*> new_binds;
|
std::vector<const Controller::ControllerBindingInfo*> new_binds;
|
||||||
u32 bind_index = 0;
|
u32 bind_index = 0;
|
||||||
|
@ -703,8 +695,9 @@ void ControllerMacroEditWidget::updateBinds()
|
||||||
ControllerCustomSettingsWidget::ControllerCustomSettingsWidget(ControllerBindingWidget* parent)
|
ControllerCustomSettingsWidget::ControllerCustomSettingsWidget(ControllerBindingWidget* parent)
|
||||||
: QWidget(parent), m_parent(parent)
|
: QWidget(parent), m_parent(parent)
|
||||||
{
|
{
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(parent->getControllerType());
|
const Controller::ControllerInfo* cinfo = parent->getControllerInfo();
|
||||||
if (!cinfo || cinfo->settings.empty())
|
DebugAssert(cinfo);
|
||||||
|
if (cinfo->settings.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QScrollArea* sarea = new QScrollArea(this);
|
QScrollArea* sarea = new QScrollArea(this);
|
||||||
|
@ -865,8 +858,9 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge
|
||||||
|
|
||||||
void ControllerCustomSettingsWidget::restoreDefaults()
|
void ControllerCustomSettingsWidget::restoreDefaults()
|
||||||
{
|
{
|
||||||
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(m_parent->getControllerType());
|
const Controller::ControllerInfo* cinfo = m_parent->getControllerInfo();
|
||||||
if (!cinfo || cinfo->settings.empty())
|
DebugAssert(cinfo);
|
||||||
|
if (cinfo->settings.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const SettingInfo& si : cinfo->settings)
|
for (const SettingInfo& si : cinfo->settings)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE ControllerSettingsWindow* getDialog() const { return m_dialog; }
|
ALWAYS_INLINE ControllerSettingsWindow* getDialog() const { return m_dialog; }
|
||||||
ALWAYS_INLINE const std::string& getConfigSection() const { return m_config_section; }
|
ALWAYS_INLINE const std::string& getConfigSection() const { return m_config_section; }
|
||||||
ALWAYS_INLINE ControllerType getControllerType() const { return m_controller_type; }
|
ALWAYS_INLINE const Controller::ControllerInfo* getControllerInfo() const { return m_controller_info; }
|
||||||
ALWAYS_INLINE u32 getPortNumber() const { return m_port_number; }
|
ALWAYS_INLINE u32 getPortNumber() const { return m_port_number; }
|
||||||
ALWAYS_INLINE const QIcon& getIcon() { return m_icon; }
|
ALWAYS_INLINE const QIcon& getIcon() { return m_icon; }
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ private:
|
||||||
ControllerSettingsWindow* m_dialog;
|
ControllerSettingsWindow* m_dialog;
|
||||||
|
|
||||||
std::string m_config_section;
|
std::string m_config_section;
|
||||||
ControllerType m_controller_type;
|
const Controller::ControllerInfo* m_controller_info;
|
||||||
u32 m_port_number;
|
u32 m_port_number;
|
||||||
|
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
|
|
|
@ -390,9 +390,7 @@ void ControllerSettingsWindow::createWidgets()
|
||||||
m_port_bindings[global_slot] = new ControllerBindingWidget(m_ui.settingsContainer, this, global_slot);
|
m_port_bindings[global_slot] = new ControllerBindingWidget(m_ui.settingsContainer, this, global_slot);
|
||||||
m_ui.settingsContainer->addWidget(m_port_bindings[global_slot]);
|
m_ui.settingsContainer->addWidget(m_port_bindings[global_slot]);
|
||||||
|
|
||||||
const Controller::ControllerInfo* ci =
|
const QString display_name(QString::fromUtf8(m_port_bindings[global_slot]->getControllerInfo()->GetDisplayName()));
|
||||||
Controller::GetControllerInfo(m_port_bindings[global_slot]->getControllerType());
|
|
||||||
const QString display_name(ci ? qApp->translate("ControllerType", ci->display_name) : QStringLiteral("Unknown"));
|
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem();
|
QListWidgetItem* item = new QListWidgetItem();
|
||||||
item->setText(mtap_enabled[port] ?
|
item->setText(mtap_enabled[port] ?
|
||||||
|
@ -431,8 +429,7 @@ void ControllerSettingsWindow::updateListDescription(u32 global_slot, Controller
|
||||||
const std::array<bool, 2> mtap_enabled = getEnabledMultitaps();
|
const std::array<bool, 2> mtap_enabled = getEnabledMultitaps();
|
||||||
const auto [port, slot] = Controller::ConvertPadToPortAndSlot(global_slot);
|
const auto [port, slot] = Controller::ConvertPadToPortAndSlot(global_slot);
|
||||||
|
|
||||||
const Controller::ControllerInfo* ci = Controller::GetControllerInfo(widget->getControllerType());
|
const QString display_name = QString::fromUtf8(widget->getControllerInfo()->GetDisplayName());
|
||||||
const QString display_name(ci ? qApp->translate("ControllerType", ci->display_name) : QStringLiteral("Unknown"));
|
|
||||||
|
|
||||||
item->setText(mtap_enabled[port] ?
|
item->setText(mtap_enabled[port] ?
|
||||||
(tr("Controller Port %1%2\n%3").arg(port + 1).arg(s_mtap_slot_names[slot]).arg(display_name)) :
|
(tr("Controller Port %1%2\n%3").arg(port + 1).arg(s_mtap_slot_names[slot]).arg(display_name)) :
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "qtprogresscallback.h"
|
#include "qtprogresscallback.h"
|
||||||
#include "settingswindow.h"
|
#include "settingswindow.h"
|
||||||
|
|
||||||
|
#include "core/controller.h"
|
||||||
#include "core/game_database.h"
|
#include "core/game_database.h"
|
||||||
#include "core/game_list.h"
|
#include "core/game_list.h"
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ void GameSummaryWidget::populateUi(const std::string& path, const std::string& s
|
||||||
{
|
{
|
||||||
if (!controllers.isEmpty())
|
if (!controllers.isEmpty())
|
||||||
controllers.append(", ");
|
controllers.append(", ");
|
||||||
controllers.append(Settings::GetControllerTypeDisplayName(static_cast<ControllerType>(i)));
|
controllers.append(Controller::GetControllerInfo(static_cast<ControllerType>(i))->GetDisplayName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue