Save State UI: Add legend showing hotkeys

This commit is contained in:
Silent 2021-02-18 00:13:07 +01:00
parent 30bcf280d4
commit 82a217570c
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
1 changed files with 84 additions and 31 deletions

View File

@ -187,9 +187,16 @@ void SaveStateSelectorUI::Draw()
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, rounding);
if (ImGui::Begin("##save_state_selector", nullptr,
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar))
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoScrollbar))
{
// Leave 2 lines for the legend
const float legend_margin = ImGui::GetFontSize() * 2.0f + ImGui::GetStyle().ItemSpacing.y * 3.0f;
const float padding = 10.0f * framebuffer_scale;
ImGui::BeginChild("##item_list", ImVec2(0, -legend_margin), false,
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar);
{
const ImVec2 image_size = ImVec2(128.0f * framebuffer_scale, (128.0f / (4.0f / 3.0f)) * framebuffer_scale);
const float item_height = image_size.y + padding * 2.0f;
const float text_indent = image_size.x + padding + padding;
@ -220,8 +227,8 @@ void SaveStateSelectorUI::Draw()
ImGui::Indent(text_indent);
ImGui::Text("%s Slot %d", entry.global ? "Global" : (entry.game_code.empty() ? "Game" : entry.game_code.c_str()),
entry.slot);
ImGui::Text("%s Slot %d",
entry.global ? "Global" : (entry.game_code.empty() ? "Game" : entry.game_code.c_str()), entry.slot);
ImGui::TextUnformatted(entry.title.c_str());
ImGui::TextUnformatted(entry.formatted_timestamp.c_str());
ImGui::TextUnformatted(entry.path.c_str());
@ -229,10 +236,56 @@ void SaveStateSelectorUI::Draw()
ImGui::Unindent(text_indent);
}
}
ImGui::EndChild();
ImGui::BeginChild("##legend", ImVec2(0, 0), false,
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoScrollbar);
{
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(), "Load");
ImGui::TableNextColumn();
ImGui::Text("%s - %s", prev_savestate_hotkey.c_str(), "Select Previous");
ImGui::TableNextColumn();
ImGui::Text("%s - %s", save_savestate_hotkey.c_str(), "Save");
ImGui::TableNextColumn();
ImGui::Text("%s - %s", next_savestate_hotkey.c_str(), "Select Next");
ImGui::EndTable();
}
ImGui::EndChild();
}
ImGui::End();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::End();
// auto-close
if (m_open_timer.GetTimeSeconds() >= m_open_time)