From add607c38fcab21af635f039fab67ddf1f3ee3ca Mon Sep 17 00:00:00 2001 From: BearOso Date: Tue, 7 May 2024 14:27:28 -0500 Subject: [PATCH] Qt: Add save slot status info. --- qt/src/EmuApplication.cpp | 21 ++++++++++----------- qt/src/Snes9xController.cpp | 5 +++++ qt/src/Snes9xController.hpp | 3 +-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/qt/src/EmuApplication.cpp b/qt/src/EmuApplication.cpp index 9b6668cb..b6c4a5e6 100644 --- a/qt/src/EmuApplication.cpp +++ b/qt/src/EmuApplication.cpp @@ -335,22 +335,21 @@ void EmuApplication::handleBinding(std::string name, bool pressed) window->pauseContinue(); } - else if (name == "IncreaseSlot") + else if (name == "IncreaseSlot" || name == "DecreaseSlot") { - save_slot++; + if (name == "IncreaseSlot") + save_slot++; + else + save_slot--; + if (save_slot > 999) save_slot = 0; - emu_thread->runOnThread([&] { - core->setMessage("Current slot: " + std::to_string(save_slot)); - }); - } - else if (name == "DecreaseSlot") - { - save_slot--; if (save_slot < 0) save_slot = 999; - emu_thread->runOnThread([&] { - core->setMessage("Current slot: " + std::to_string(save_slot)); + + emu_thread->runOnThread([&, slot = this->save_slot] { + std::string status = core->slotUsed(slot) ? " [used]" : " [empty]"; + core->setMessage("Current slot: " + std::to_string(save_slot) + status); }); } else if (name == "SaveState") diff --git a/qt/src/Snes9xController.cpp b/qt/src/Snes9xController.cpp index 83373e23..c006066f 100644 --- a/qt/src/Snes9xController.cpp +++ b/qt/src/Snes9xController.cpp @@ -718,6 +718,11 @@ std::string Snes9xController::getStateFolder() return S9xGetDirectory(SNAPSHOT_DIR); } +bool Snes9xController::slotUsed(int slot) +{ + return fs::exists(save_slot_path(slot)); +} + bool Snes9xController::loadState(int slot) { return loadState(save_slot_path(slot).u8string()); diff --git a/qt/src/Snes9xController.hpp b/qt/src/Snes9xController.hpp index fac58945..c69b681a 100644 --- a/qt/src/Snes9xController.hpp +++ b/qt/src/Snes9xController.hpp @@ -16,13 +16,12 @@ class Snes9xController void deinit(); void mainLoop(); bool openFile(std::string filename); + bool slotUsed(int slot); bool loadState(std::string filename); bool loadState(int slot); void loadUndoState(); bool saveState(std::string filename); bool saveState(int slot); - void increaseSaveSlot(); - void decreaseSaveSlot(); void updateSettings(const EmuConfig * const config); void updateBindings(const EmuConfig * const config); void reportBinding(EmuBinding b, bool active);