diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index fab723463..cd36ec2bf 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1292,6 +1292,8 @@ void CommonHostInterface::UpdateHotkeyInputMap(SettingsInterface& si) AddButtonToInputMap(binding, device, button, hi.handler); } } + + m_save_state_selector_ui->RefreshHotkeyLegend(); } bool CommonHostInterface::AddButtonToInputMap(const std::string& binding, const std::string_view& device, diff --git a/src/frontend-common/save_state_selector_ui.cpp b/src/frontend-common/save_state_selector_ui.cpp index 471e3c542..41bb085f9 100644 --- a/src/frontend-common/save_state_selector_ui.cpp +++ b/src/frontend-common/save_state_selector_ui.cpp @@ -1,5 +1,6 @@ #include "save_state_selector_ui.h" #include "common/log.h" +#include "common/string_util.h" #include "common/timestamp.h" #include "core/host_display.h" #include "core/system.h" @@ -23,6 +24,7 @@ void SaveStateSelectorUI::Open(float open_time /* = DEFAULT_OPEN_TIME */) m_open = true; RefreshList(); + RefreshHotkeyLegend(); } void SaveStateSelectorUI::Close() @@ -78,6 +80,32 @@ void SaveStateSelectorUI::RefreshList() m_current_selection = 0; } +void SaveStateSelectorUI::RefreshHotkeyLegend() +{ + if (!m_open) + return; + + auto format_legend_entry = [](std::string_view setting, std::string_view caption) { + auto slash_pos = setting.find_first_of('/'); + if (slash_pos != setting.npos) + { + setting = setting.substr(slash_pos + 1); + } + + return StringUtil::StdStringFromFormat("%.*s - %.*s", static_cast(setting.size()), setting.data(), + static_cast(caption.size()), caption.data()); + }; + + m_load_legend = format_legend_entry(m_host_interface->GetStringSettingValue("Hotkeys", "LoadSelectedSaveState"), + m_host_interface->TranslateStdString("SaveStateSelectorUI", "Load")); + m_save_legend = format_legend_entry(m_host_interface->GetStringSettingValue("Hotkeys", "SaveSelectedSaveState"), + m_host_interface->TranslateStdString("SaveStateSelectorUI", "Save")); + m_prev_legend = format_legend_entry(m_host_interface->GetStringSettingValue("Hotkeys", "SelectPreviousSaveStateSlot"), + m_host_interface->TranslateStdString("SaveStateSelectorUI", "Select Previous")); + m_next_legend = format_legend_entry(m_host_interface->GetStringSettingValue("Hotkeys", "SelectNextSaveStateSlot"), + m_host_interface->TranslateStdString("SaveStateSelectorUI", "Select Next")); +} + const char* SaveStateSelectorUI::GetSelectedStatePath() const { if (m_slots.empty() || m_slots[m_current_selection].path.empty()) @@ -256,42 +284,14 @@ void SaveStateSelectorUI::Draw() ImGui::SetCursorPosX(padding); ImGui::BeginTable("table", 2); - auto strip_device_name = [](std::string str) { - std::string result; - - auto slash_pos = str.find_first_of('/'); - if (slash_pos != str.npos) - { - result = str.substr(slash_pos + 1); - } - else - { - result = std::move(str); - } - return result; - }; - - const std::string load_savestate_hotkey = - strip_device_name(m_host_interface->GetStringSettingValue("Hotkeys", "LoadSelectedSaveState")); - const std::string save_savestate_hotkey = - strip_device_name(m_host_interface->GetStringSettingValue("Hotkeys", "SaveSelectedSaveState")); - const std::string next_savestate_hotkey = - strip_device_name(m_host_interface->GetStringSettingValue("Hotkeys", "SelectNextSaveStateSlot")); - const std::string prev_savestate_hotkey = - strip_device_name(m_host_interface->GetStringSettingValue("Hotkeys", "SelectPreviousSaveStateSlot")); - ImGui::TableNextColumn(); - ImGui::Text("%s - %s", load_savestate_hotkey.c_str(), - m_host_interface->TranslateString("SaveStateSelectorUI", "Load").GetCharArray()); + ImGui::TextUnformatted(m_load_legend.c_str()); ImGui::TableNextColumn(); - ImGui::Text("%s - %s", prev_savestate_hotkey.c_str(), - m_host_interface->TranslateString("SaveStateSelectorUI", "Select Previous").GetCharArray()); + ImGui::TextUnformatted(m_prev_legend.c_str()); ImGui::TableNextColumn(); - ImGui::Text("%s - %s", save_savestate_hotkey.c_str(), - m_host_interface->TranslateString("SaveStateSelectorUI", "Save").GetCharArray()); + ImGui::TextUnformatted(m_save_legend.c_str()); ImGui::TableNextColumn(); - ImGui::Text("%s - %s", next_savestate_hotkey.c_str(), - m_host_interface->TranslateString("SaveStateSelectorUI", "Select Next").GetCharArray()); + ImGui::TextUnformatted(m_next_legend.c_str()); ImGui::EndTable(); } diff --git a/src/frontend-common/save_state_selector_ui.h b/src/frontend-common/save_state_selector_ui.h index 5fc694795..dbb88ebaf 100644 --- a/src/frontend-common/save_state_selector_ui.h +++ b/src/frontend-common/save_state_selector_ui.h @@ -1,6 +1,6 @@ #pragma once -#include "common_host_interface.h" #include "common/timer.h" +#include "common_host_interface.h" #include class HostDisplayTexture; @@ -24,6 +24,8 @@ public: void ClearList(); void RefreshList(); + void RefreshHotkeyLegend(); + const char* GetSelectedStatePath() const; s32 GetSelectedStateSlot() const; @@ -51,6 +53,11 @@ private: void InitializeListEntry(ListEntry* li, CommonHostInterface::ExtendedSaveStateInfo* ssi); std::pair GetSlotTypeFromSelection(u32 selection) const; + std::string m_load_legend; + std::string m_save_legend; + std::string m_prev_legend; + std::string m_next_legend; + CommonHostInterface* m_host_interface; std::vector m_slots; u32 m_current_selection = 0;