GameSettings: Add per-game input bindings from profiles

This just affects the **bindings**. You will still have to set the
controller type per game if this is different from the global default.
This commit is contained in:
Connor McLaughlin
2020-10-04 18:20:18 +10:00
parent 7278f055cb
commit 0b858658ca
7 changed files with 92 additions and 4 deletions

View File

@ -977,7 +977,10 @@ bool CommonHostInterface::HandleHostMouseEvent(HostMouseButton button, bool pres
void CommonHostInterface::UpdateInputMap(SettingsInterface& si)
{
ClearInputMap();
UpdateControllerInputMap(si);
if (!UpdateControllerInputMapFromGameSettings())
UpdateControllerInputMap(si);
UpdateHotkeyInputMap(si);
}
@ -1677,6 +1680,19 @@ void CommonHostInterface::FindInputProfiles(const std::string& base_path, InputP
}
}
std::string CommonHostInterface::GetInputProfilePath(const char* name) const
{
std::string path = GetUserDirectoryRelativePath("inputprofiles" FS_OSPATH_SEPARATOR_STR "%s.ini", name);
if (FileSystem::FileExists(path.c_str()))
return path;
path = GetProgramDirectoryRelativePath("inputprofiles" FS_OSPATH_SEPARATOR_STR "%s.ini", name);
if (FileSystem::FileExists(path.c_str()))
return path;
return {};
}
void CommonHostInterface::ClearAllControllerBindings(SettingsInterface& si)
{
for (u32 controller_index = 1; controller_index <= NUM_CONTROLLER_AND_CARD_PORTS; controller_index++)
@ -2282,6 +2298,35 @@ void CommonHostInterface::ApplyGameSettings(bool display_osd_messages)
gs->ApplySettings(display_osd_messages);
}
bool CommonHostInterface::UpdateControllerInputMapFromGameSettings()
{
// this gets called while booting, so can't use valid
if (System::IsShutdown() || System::GetRunningCode().empty() || !g_settings.apply_game_settings)
return false;
const GameSettings::Entry* gs = m_game_list->GetGameSettings(System::GetRunningPath(), System::GetRunningCode());
if (!gs || gs->input_profile_name.empty())
return false;
std::string path = GetInputProfilePath(gs->input_profile_name.c_str());
if (path.empty())
{
AddFormattedOSDMessage(10.0f, TranslateString("OSDMessage", "Input profile '%s' cannot be found."),
gs->input_profile_name.c_str());
return false;
}
if (System::GetState() == System::State::Starting)
{
AddFormattedOSDMessage(5.0f, TranslateString("OSDMessage", "Using input profile '%s'."),
gs->input_profile_name.c_str());
}
INISettingsInterface si(std::move(path));
UpdateControllerInputMap(si);
return true;
}
std::string CommonHostInterface::GetCheatFileName() const
{
const std::string& title = System::GetRunningTitle();