From f7259082403a17444bd46bb91bc354fa7f966962 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Thu, 25 Sep 2025 21:00:44 -0400 Subject: [PATCH] Tweak StateManager update routine to fix overlap. Add create_push_fade to ProgressState. Cleanup some inconsistencies. --- include/appstates/ProgressState.hpp | 11 +++++++++++ source/StateManager.cpp | 12 +++++++++--- source/appstates/BackupMenuState.cpp | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/appstates/ProgressState.hpp b/include/appstates/ProgressState.hpp index 5f42a2d..88e8b47 100644 --- a/include/appstates/ProgressState.hpp +++ b/include/appstates/ProgressState.hpp @@ -1,6 +1,8 @@ #pragma once #include "StateManager.hpp" #include "appstates/BaseTask.hpp" +#include "appstates/FadeState.hpp" +#include "graphics/colors.hpp" #include "sys/sys.hpp" #include "ui/ui.hpp" @@ -31,6 +33,15 @@ class ProgressState final : public BaseTask return newState; } + static inline std::shared_ptr create_push_fade(sys::threadpool::JobFunction function, + sys::Task::TaskData taskData) + { + auto newState = ProgressState::create(function, taskData); + auto fade = + FadeState::create_and_push(colors::DIM_BACKGROUND, colors::ALPHA_FADE_BEGIN, colors::ALPHA_FADE_END, newState); + return newState; + } + /// @brief Checks if the thread is finished and deactivates this state. void update() override; diff --git a/source/StateManager.cpp b/source/StateManager.cpp index 7911015..6a568ad 100644 --- a/source/StateManager.cpp +++ b/source/StateManager.cpp @@ -8,6 +8,11 @@ void StateManager::update() if (stateVector.empty()) { return; } + { + auto &back = stateVector.back(); + if (back->is_active() && back->has_focus()) { back->update(); } + } + // Purge uneeded states. for (auto current = stateVector.begin(); current != stateVector.end();) { @@ -27,9 +32,10 @@ void StateManager::update() // Run sub update routines. for (auto iter = stateVector.begin(); iter < stateVector.end() - 1; iter++) { (*iter)->sub_update(); } - std::shared_ptr &back = stateVector.back(); - if (!back->has_focus()) { back->give_focus(); } - back->update(); + { + auto &back = stateVector.back(); + if (!back->has_focus()) { back->give_focus(); } + } } void StateManager::render() noexcept diff --git a/source/appstates/BackupMenuState.cpp b/source/appstates/BackupMenuState.cpp index 29e6b6d..a488219 100644 --- a/source/appstates/BackupMenuState.cpp +++ b/source/appstates/BackupMenuState.cpp @@ -241,7 +241,7 @@ void BackupMenuState::name_and_create_backup() if (keepLocal) { m_dataStruct->path = m_directoryPath / name; } m_dataStruct->remoteName = name; - ProgressState::create_and_push(tasks::backup::create_new_backup_remote, m_dataStruct); + ProgressState::create_push_fade(tasks::backup::create_new_backup_remote, m_dataStruct); } else { @@ -249,7 +249,7 @@ void BackupMenuState::name_and_create_backup() if (!hasZipExt && (autoUpload || exportZip)) { target += STRING_ZIP_EXT; } // We're going to append zip either way. m_dataStruct->path = std::move(target); - ProgressState::create_and_push(tasks::backup::create_new_backup_local, m_dataStruct); + ProgressState::create_push_fade(tasks::backup::create_new_backup_local, m_dataStruct); } } @@ -384,7 +384,7 @@ void BackupMenuState::upload_backup() ConfirmProgress::create_push_fade(query, holdRequired, tasks::backup::patch_backup, m_dataStruct); } - else { ProgressState::create_and_push(tasks::backup::upload_backup, m_dataStruct); } + else { ProgressState::create_push_fade(tasks::backup::upload_backup, m_dataStruct); } } void BackupMenuState::pop_save_empty()