Simplify quicksave/quickload logic

This commit is contained in:
Silent 2020-09-12 16:07:22 +02:00
parent 605992f294
commit cf513c1c24
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 16 additions and 17 deletions

View File

@ -45,7 +45,7 @@ void SaveStateSelectorUI::RefreshList()
if (!System::GetRunningCode().empty()) if (!System::GetRunningCode().empty())
{ {
for (s32 i = 1; i <= CommonHostInterface::GLOBAL_SAVE_STATE_SLOTS; i++) for (s32 i = 1; i <= CommonHostInterface::PER_GAME_SAVE_STATE_SLOTS; i++)
{ {
std::optional<CommonHostInterface::ExtendedSaveStateInfo> ssi = std::optional<CommonHostInterface::ExtendedSaveStateInfo> ssi =
m_host_interface->GetExtendedSaveStateInfo(System::GetRunningCode().c_str(), i); m_host_interface->GetExtendedSaveStateInfo(System::GetRunningCode().c_str(), i);
@ -146,6 +146,16 @@ void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, CommonHostInterface
Log_ErrorPrintf("Failed to upload save state image to GPU"); Log_ErrorPrintf("Failed to upload save state image to GPU");
} }
std::pair<s32, bool> SaveStateSelectorUI::GetSlotTypeFromSelection(u32 selection) const
{
if (selection < CommonHostInterface::PER_GAME_SAVE_STATE_SLOTS)
{
return {selection + 1, false};
}
return {selection - CommonHostInterface::PER_GAME_SAVE_STATE_SLOTS + 1, true};
}
void SaveStateSelectorUI::InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global) void SaveStateSelectorUI::InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global)
{ {
li->title = "No Save State"; li->title = "No Save State";
@ -231,27 +241,15 @@ void SaveStateSelectorUI::Draw()
void SaveStateSelectorUI::LoadCurrentSlot() void SaveStateSelectorUI::LoadCurrentSlot()
{ {
if (m_current_selection >= m_slots.size()) const auto slot_info = GetSlotTypeFromSelection(m_current_selection);
{ m_host_interface->LoadState(slot_info.second, slot_info.first);
RefreshList();
return;
}
const ListEntry& le = m_slots.at(m_current_selection);
m_host_interface->LoadState(le.global, le.slot);
Close(); Close();
} }
void SaveStateSelectorUI::SaveCurrentSlot() void SaveStateSelectorUI::SaveCurrentSlot()
{ {
if (m_current_selection >= m_slots.size()) const auto slot_info = GetSlotTypeFromSelection(m_current_selection);
{ m_host_interface->SaveState(slot_info.second, slot_info.first);
RefreshList();
return;
}
const ListEntry& le = m_slots.at(m_current_selection);
m_host_interface->SaveState(le.global, le.slot);
Close(); Close();
} }

View File

@ -49,6 +49,7 @@ private:
void InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global); void InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global);
void InitializeListEntry(ListEntry* li, CommonHostInterface::ExtendedSaveStateInfo* ssi); void InitializeListEntry(ListEntry* li, CommonHostInterface::ExtendedSaveStateInfo* ssi);
std::pair<s32, bool> GetSlotTypeFromSelection(u32 selection) const;
CommonHostInterface* m_host_interface; CommonHostInterface* m_host_interface;
std::vector<ListEntry> m_slots; std::vector<ListEntry> m_slots;