From 1d2bd11b028e14efa1bdae21a0b047cb30011d44 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 15 Dec 2019 22:24:27 +1000 Subject: [PATCH] Frontend: Add controller settings --- src/core/settings.cpp | 43 +++++++++++++++----------- src/core/settings.h | 8 ++--- src/core/system.cpp | 16 +++++----- src/core/types.h | 3 +- src/duckstation/sdl_host_interface.cpp | 37 +++++++++++++++++----- 5 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index f24d918e4..2d1c0c93e 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -33,11 +33,11 @@ void Settings::SetDefaults() bios_patch_tty_enable = false; bios_patch_fast_boot = false; - controller_a_type = ControllerType::DigitalController; - controller_b_type = ControllerType::None; + controller_1_type = ControllerType::DigitalController; + controller_2_type = ControllerType::None; - memory_card_a_path = "memory_card_a.mcd"; - memory_card_b_path.clear(); + memory_card_1_path = "memory_card_1.mcd"; + memory_card_2_path.clear(); } void Settings::Load(const char* filename) @@ -72,13 +72,13 @@ void Settings::Load(const char* filename) bios_patch_tty_enable = ini.GetBoolValue("BIOS", "PatchTTYEnable", true); bios_patch_fast_boot = ini.GetBoolValue("BIOS", "PatchFastBoot", false); - controller_a_type = ParseControllerTypeName(ini.GetValue("Controller", "PortAType", "DigitalController")) + controller_1_type = ParseControllerTypeName(ini.GetValue("Ports", "Controller1Type", "DigitalController")) .value_or(ControllerType::DigitalController); - controller_b_type = - ParseControllerTypeName(ini.GetValue("Controller", "PortBType", "None")).value_or(ControllerType::None); + controller_2_type = + ParseControllerTypeName(ini.GetValue("Ports", "Controller2Type", "None")).value_or(ControllerType::None); - memory_card_a_path = ini.GetValue("MemoryCard", "CardAPath", "memory_card_a.mcd"); - memory_card_b_path = ini.GetValue("MemoryCard", "CardBPath", ""); + memory_card_1_path = ini.GetValue("Ports", "MemoryCard1Path", "memory_card_1.mcd"); + memory_card_2_path = ini.GetValue("Ports", "MemoryCard2Path", ""); } bool Settings::Save(const char* filename) const @@ -110,18 +110,25 @@ bool Settings::Save(const char* filename) const ini.SetBoolValue("BIOS", "PatchTTYEnable", bios_patch_tty_enable); ini.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot); - ini.SetValue("Controller", "PortAType", GetControllerTypeName(controller_a_type)); - ini.SetValue("Controller", "PortBType", GetControllerTypeName(controller_b_type)); - - if (!memory_card_a_path.empty()) - ini.SetValue("MemoryCard", "CardAPath", memory_card_a_path.c_str()); + if (controller_1_type != ControllerType::None) + ini.SetValue("Ports", "Controller1Type", GetControllerTypeName(controller_1_type)); else - ini.DeleteValue("MemoryCard", "CardAPath", nullptr); + ini.DeleteValue("Ports", "Controller1Type", nullptr); - if (!memory_card_b_path.empty()) - ini.SetValue("MemoryCard", "CardBPath", memory_card_b_path.c_str()); + if (controller_2_type != ControllerType::None) + ini.SetValue("Ports", "Controller2Type", GetControllerTypeName(controller_2_type)); else - ini.DeleteValue("MemoryCard", "CardBPath", nullptr); + ini.DeleteValue("Ports", "Controller2Type", nullptr); + + if (!memory_card_1_path.empty()) + ini.SetValue("Ports", "MemoryCard1Path", memory_card_1_path.c_str()); + else + ini.DeleteValue("Ports", "MemoryCard1Path", nullptr); + + if (!memory_card_2_path.empty()) + ini.SetValue("Ports", "MemoryCard2Path", memory_card_2_path.c_str()); + else + ini.DeleteValue("Ports", "MemoryCard2Path", nullptr); err = ini.SaveFile(filename, false); if (err != SI_OK) diff --git a/src/core/settings.h b/src/core/settings.h index eaa40e6d7..923a3ff81 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -45,11 +45,11 @@ struct Settings bool bios_patch_tty_enable = false; bool bios_patch_fast_boot = false; - ControllerType controller_a_type = ControllerType::None; - ControllerType controller_b_type = ControllerType::None; + ControllerType controller_1_type = ControllerType::None; + ControllerType controller_2_type = ControllerType::None; - std::string memory_card_a_path; - std::string memory_card_b_path; + std::string memory_card_1_path; + std::string memory_card_2_path; void SetDefaults(); void Load(const char* filename); diff --git a/src/core/system.cpp b/src/core/system.cpp index 06b9b6b4c..e9683c061 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -463,16 +463,16 @@ void System::UpdateControllers() m_pad->SetController(1, nullptr); const Settings& settings = m_host_interface->GetSettings(); - if (settings.controller_a_type != ControllerType::None) + if (settings.controller_1_type != ControllerType::None) { - std::unique_ptr controller = Controller::Create(settings.controller_a_type); + std::unique_ptr controller = Controller::Create(settings.controller_1_type); if (controller) m_pad->SetController(0, std::move(controller)); } - if (settings.controller_b_type != ControllerType::None) + if (settings.controller_2_type != ControllerType::None) { - std::unique_ptr controller = Controller::Create(settings.controller_b_type); + std::unique_ptr controller = Controller::Create(settings.controller_2_type); if (controller) m_pad->SetController(1, std::move(controller)); } @@ -484,16 +484,16 @@ void System::UpdateMemoryCards() m_pad->SetMemoryCard(1, nullptr); const Settings& settings = m_host_interface->GetSettings(); - if (!settings.memory_card_a_path.empty()) + if (!settings.memory_card_1_path.empty()) { - std::unique_ptr card = MemoryCard::Open(this, settings.memory_card_a_path); + std::unique_ptr card = MemoryCard::Open(this, settings.memory_card_1_path); if (card) m_pad->SetMemoryCard(0, std::move(card)); } - if (!settings.memory_card_b_path.empty()) + if (!settings.memory_card_2_path.empty()) { - std::unique_ptr card = MemoryCard::Open(this, settings.memory_card_b_path); + std::unique_ptr card = MemoryCard::Open(this, settings.memory_card_2_path); if (card) m_pad->SetMemoryCard(1, std::move(card)); } diff --git a/src/core/types.h b/src/core/types.h index e6df4303d..132a9ba55 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -51,7 +51,8 @@ enum class ControllerType { None, DigitalController, - AnalogController + AnalogController, + Count }; enum : u32 diff --git a/src/duckstation/sdl_host_interface.cpp b/src/duckstation/sdl_host_interface.cpp index 5a53f650a..a19fc3739 100644 --- a/src/duckstation/sdl_host_interface.cpp +++ b/src/duckstation/sdl_host_interface.cpp @@ -1109,19 +1109,42 @@ void SDLHostInterface::DrawSettingsWindow() ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("Memory Cards")) + if (ImGui::BeginTabItem("Ports")) { for (int i = 0; i < 2; i++) { - if (!DrawSettingsSectionHeader(TinyString::FromFormat("Card %c", 'A' + i))) - continue; + if (DrawSettingsSectionHeader(TinyString::FromFormat("Front Port %d", 1 + i))) + { + ImGui::Text("Controller:"); + ImGui::SameLine(indent); - ImGui::Text("Card %c", 'A' + i); + int controller_type = static_cast((i == 0) ? m_settings.controller_1_type : m_settings.controller_2_type); + if (ImGui::Combo( + "##controller_type", &controller_type, + [](void*, int index, const char** out_text) { + *out_text = Settings::GetControllerTypeDisplayName(static_cast(index)); + return true; + }, + nullptr, static_cast(ControllerType::Count))) + { + if (i == 0) + m_settings.controller_1_type = static_cast(controller_type); + else + m_settings.controller_2_type = static_cast(controller_type); - ImGui::Text("Path:"); + settings_changed = true; + if (m_system) + { + m_system->UpdateControllers(); + UpdateControllerControllerMapping(); + } + } + } + + ImGui::Text("Memory Card Path:"); ImGui::SameLine(indent); - std::string* path_ptr = (i == 0) ? &m_settings.memory_card_a_path : &m_settings.memory_card_b_path; + std::string* path_ptr = (i == 0) ? &m_settings.memory_card_1_path : &m_settings.memory_card_2_path; if (DrawFileChooser(TinyString::FromFormat("##memcard_%c_path", 'a' + i), path_ptr)) { settings_changed = true; @@ -1129,7 +1152,7 @@ void SDLHostInterface::DrawSettingsWindow() m_system->UpdateMemoryCards(); } - if (ImGui::Button("Eject")) + if (ImGui::Button("Eject Memory Card")) { path_ptr->clear(); settings_changed = true;