From ff02d41992bc5ce7fb5b6c51de7d81fb90a12afb Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 20 Jun 2023 00:41:21 +1000 Subject: [PATCH] USB: Make GetDeviceTypes() return C strings --- pcsx2-qt/Settings/ControllerBindingWidgets.cpp | 4 ++-- pcsx2/ImGui/FullscreenUI.cpp | 12 ++++++------ pcsx2/PAD/Host/PAD.cpp | 4 ++-- pcsx2/PAD/Host/PAD.h | 2 +- pcsx2/USB/USB.cpp | 4 ++-- pcsx2/USB/USB.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp index 168321934d..dd8f0fdc77 100644 --- a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp +++ b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp @@ -72,7 +72,7 @@ QIcon ControllerBindingWidget::getIcon() const void ControllerBindingWidget::populateControllerTypes() { for (const auto& [name, display_name] : PAD::GetControllerTypeNames()) - m_ui.controllerType->addItem(QString::fromStdString(display_name), QString::fromStdString(name)); + m_ui.controllerType->addItem(qApp->translate("Pad", display_name), QString::fromStdString(name)); } void ControllerBindingWidget::onTypeChanged() @@ -902,7 +902,7 @@ QIcon USBDeviceWidget::getIcon() const void USBDeviceWidget::populateDeviceTypes() { for (const auto& [name, display_name] : USB::GetDeviceTypes()) - m_ui.deviceType->addItem(QString::fromStdString(display_name), QString::fromStdString(name)); + m_ui.deviceType->addItem(qApp->translate("USB", display_name), QString::fromUtf8(name)); } void USBDeviceWidget::populatePages() diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index e413a7009f..22e96b46d9 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -3796,12 +3796,12 @@ void FullscreenUI::DrawControllerSettingsPage() const PAD::ControllerInfo* ci = PAD::GetControllerInfo(type); if (MenuButton(ICON_FA_GAMEPAD " Controller Type", ci ? ci->display_name : "Unknown")) { - std::vector> raw_options(PAD::GetControllerTypeNames()); + const std::vector> raw_options = PAD::GetControllerTypeNames(); ImGuiFullscreen::ChoiceDialogOptions options; options.reserve(raw_options.size()); for (auto& it : raw_options) { - options.emplace_back(std::move(it.second), type == it.first); + options.emplace_back(it.second, type == it.first); } OpenChoiceDialog(fmt::format("Port {} Controller Type", global_slot + 1).c_str(), false, std::move(options), [game_settings = IsEditingGameSettings(bsi), section, raw_options = std::move(raw_options)]( @@ -3811,7 +3811,7 @@ void FullscreenUI::DrawControllerSettingsPage() auto lock = Host::GetSettingsLock(); SettingsInterface* bsi = GetEditingSettingsInterface(game_settings); - bsi->SetStringValue(section, "Type", raw_options[index].first.c_str()); + bsi->SetStringValue(section, "Type", raw_options[index].first); SetSettingsChanged(bsi); CloseChoiceDialog(); }); @@ -3982,12 +3982,12 @@ void FullscreenUI::DrawControllerSettingsPage() const std::string type(USB::GetConfigDevice(*bsi, port)); if (MenuButton(ICON_FA_GAMEPAD " Device Type", USB::GetDeviceName(type))) { - std::vector> raw_options(USB::GetDeviceTypes()); + const std::vector> raw_options = USB::GetDeviceTypes(); ImGuiFullscreen::ChoiceDialogOptions options; options.reserve(raw_options.size()); for (auto& it : raw_options) { - options.emplace_back(std::move(it.second), type == it.first); + options.emplace_back(it.second, type == it.first); } OpenChoiceDialog(fmt::format("Port {} Device", port + 1).c_str(), false, std::move(options), [game_settings = IsEditingGameSettings(bsi), raw_options = std::move(raw_options), port]( @@ -3997,7 +3997,7 @@ void FullscreenUI::DrawControllerSettingsPage() auto lock = Host::GetSettingsLock(); SettingsInterface* bsi = GetEditingSettingsInterface(game_settings); - USB::SetConfigDevice(*bsi, port, raw_options[static_cast(index)].first.c_str()); + USB::SetConfigDevice(*bsi, port, raw_options[static_cast(index)].first); SetSettingsChanged(bsi); CloseChoiceDialog(); }); diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index b19c293f02..f1e50fc5a7 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -458,9 +458,9 @@ const PAD::ControllerInfo* PAD::GetControllerInfo(const std::string_view& name) return nullptr; } -std::vector> PAD::GetControllerTypeNames() +std::vector> PAD::GetControllerTypeNames() { - std::vector> ret; + std::vector> ret; for (const ControllerInfo& info : s_controller_info) ret.emplace_back(info.name, info.display_name); diff --git a/pcsx2/PAD/Host/PAD.h b/pcsx2/PAD/Host/PAD.h index ec91ab9df8..68feae00fc 100644 --- a/pcsx2/PAD/Host/PAD.h +++ b/pcsx2/PAD/Host/PAD.h @@ -103,7 +103,7 @@ namespace PAD void Update(); /// Returns a list of controller type names. Pair of [name, display name]. - std::vector> GetControllerTypeNames(); + std::vector> GetControllerTypeNames(); /// Returns the list of binds for the specified controller type. std::vector GetControllerBinds(const std::string_view& type); diff --git a/pcsx2/USB/USB.cpp b/pcsx2/USB/USB.cpp index 427c543412..e4bef77b5b 100644 --- a/pcsx2/USB/USB.cpp +++ b/pcsx2/USB/USB.cpp @@ -553,10 +553,10 @@ const char* USB::DeviceTypeIndexToName(s32 device) return proxy ? proxy->TypeName() : "None"; } -std::vector> USB::GetDeviceTypes() +std::vector> USB::GetDeviceTypes() { RegisterDevice& rd = RegisterDevice::instance(); - std::vector> ret; + std::vector> ret; ret.reserve(rd.Map().size() + 1); ret.emplace_back("None", "Not Connected"); for (const auto& it : rd.Map()) diff --git a/pcsx2/USB/USB.h b/pcsx2/USB/USB.h index eeb40f3631..1cc8e60c88 100644 --- a/pcsx2/USB/USB.h +++ b/pcsx2/USB/USB.h @@ -38,7 +38,7 @@ namespace USB s32 DeviceTypeNameToIndex(const std::string_view& device); const char* DeviceTypeIndexToName(s32 device); - std::vector> GetDeviceTypes(); + std::vector> GetDeviceTypes(); const char* GetDeviceName(const std::string_view& device); const char* GetDeviceSubtypeName(const std::string_view& device, u32 subtype); gsl::span GetDeviceSubtypes(const std::string_view& device);