Frontend: Add controller settings

This commit is contained in:
Connor McLaughlin 2019-12-15 22:24:27 +10:00
parent a347b3606e
commit 1d2bd11b02
5 changed files with 69 additions and 38 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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 = Controller::Create(settings.controller_a_type);
std::unique_ptr<Controller> 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 = Controller::Create(settings.controller_b_type);
std::unique_ptr<Controller> 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<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_a_path);
std::unique_ptr<MemoryCard> 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<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_b_path);
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_2_path);
if (card)
m_pad->SetMemoryCard(1, std::move(card));
}

View File

@ -51,7 +51,8 @@ enum class ControllerType
{
None,
DigitalController,
AnalogController
AnalogController,
Count
};
enum : u32

View File

@ -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<int>((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<ControllerType>(index));
return true;
},
nullptr, static_cast<int>(ControllerType::Count)))
{
if (i == 0)
m_settings.controller_1_type = static_cast<ControllerType>(controller_type);
else
m_settings.controller_2_type = static_cast<ControllerType>(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;