From 1caec25d2ade4559b6bd4c56f86f4c33c37c8443 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sat, 16 Aug 2025 18:58:32 -0400 Subject: [PATCH] Revisions, SVI import fix. --- Libraries/SDLLib | 2 +- Makefile | 3 +- include/JSON.hpp | 9 + include/appstates/BackupMenuState.hpp | 21 +- include/appstates/BlacklistEditState.hpp | 10 +- include/appstates/ConfirmState.hpp | 24 +- include/appstates/DataLoadingState.hpp | 16 +- include/appstates/ExtrasMenuState.hpp | 2 +- include/appstates/FadeState.hpp | 29 +- include/appstates/MainMenuState.hpp | 12 +- include/appstates/MessageState.hpp | 22 +- include/appstates/ProgressState.hpp | 7 +- include/appstates/SaveCreateState.hpp | 16 +- include/appstates/SettingsState.hpp | 4 +- include/appstates/TaskState.hpp | 6 +- include/appstates/TextTitleSelectState.hpp | 15 +- include/appstates/TitleInfoState.hpp | 16 +- include/appstates/TitleOptionState.hpp | 20 +- include/appstates/TitleSelectState.hpp | 15 +- include/appstates/UserOptionState.hpp | 22 +- include/config/ConfigContext.hpp | 111 ++++++++ include/{ => config}/config.hpp | 31 +-- include/config/keys.hpp | 30 +++ include/curl/DownloadStruct.hpp | 8 + include/curl/UploadStruct.hpp | 2 + include/fs/PathFilter.hpp | 13 +- include/{ => graphics}/colors.hpp | 0 include/{ => graphics}/gfxutil.hpp | 8 +- include/{ => logging}/error.hpp | 0 include/{ => logging}/logger.hpp | 0 include/strings.hpp | 51 ---- include/strings/names.hpp | 44 ++++ include/strings/strings.hpp | 13 + include/ui/BoundingBox.hpp | 5 +- include/ui/DialogBox.hpp | 13 +- include/ui/IconMenu.hpp | 6 +- include/ui/Menu.hpp | 6 +- include/ui/SlideOutPanel.hpp | 6 +- include/ui/TextScroll.hpp | 21 +- include/ui/TitleView.hpp | 5 + source/JKSV.cpp | 12 +- source/StateManager.cpp | 2 - source/appstates/BackupMenuState.cpp | 35 +-- source/appstates/BaseState.cpp | 2 +- source/appstates/BaseTask.cpp | 4 +- source/appstates/BlacklistEditState.cpp | 13 +- source/appstates/DataLoadingState.cpp | 6 +- source/appstates/ExtrasMenuState.cpp | 8 +- source/appstates/FadeState.cpp | 20 +- source/appstates/MainMenuState.cpp | 61 ++--- source/appstates/MessageState.cpp | 20 +- source/appstates/ProgressState.cpp | 4 +- source/appstates/SaveCreateState.cpp | 18 +- source/appstates/SettingsState.cpp | 32 ++- source/appstates/TaskState.cpp | 4 +- source/appstates/TextTitleSelectState.cpp | 39 +-- source/appstates/TitleInfoState.cpp | 36 +-- source/appstates/TitleOptionState.cpp | 26 +- source/appstates/TitleSelectCommon.cpp | 4 +- source/appstates/TitleSelectState.cpp | 42 +-- source/appstates/UserOptionState.cpp | 51 ++-- source/config.cpp | 293 --------------------- source/config/ConfigContext.cpp | 282 ++++++++++++++++++++ source/config/config.cpp | 88 +++++++ source/curl/curl.cpp | 4 +- source/data/DataContext.cpp | 21 +- source/data/TitleInfo.cpp | 12 +- source/data/User.cpp | 12 +- source/data/data.cpp | 5 +- source/fs/MiniUnzip.cpp | 4 +- source/fs/MiniZip.cpp | 4 +- source/fs/PathFilter.cpp | 29 ++ source/fs/SaveMetaData.cpp | 2 +- source/fs/ScopedSaveMount.cpp | 2 +- source/fs/io.cpp | 4 +- source/fs/save_data_functions.cpp | 4 +- source/fs/zip.cpp | 8 +- source/gfxutil.cpp | 4 +- source/keyboard.cpp | 2 +- source/{ => logging}/error.cpp | 4 +- source/{ => logging}/logger.cpp | 4 +- source/main.cpp | 1 - source/remote/GoogleDrive.cpp | 4 +- source/remote/Item.cpp | 2 +- source/remote/Storage.cpp | 2 +- source/remote/WebDav.cpp | 6 +- source/remote/remote.cpp | 6 +- source/strings.cpp | 8 +- source/sys/Task.cpp | 2 +- source/sys/Timer.cpp | 2 +- source/tasks/backup.cpp | 8 +- source/tasks/mainmenu.cpp | 4 +- source/tasks/savecreate.cpp | 4 +- source/tasks/titleoptions.cpp | 8 +- source/tasks/useroptions.cpp | 6 +- source/ui/BoundingBox.cpp | 7 +- source/ui/DialogBox.cpp | 11 +- source/ui/IconMenu.cpp | 7 +- source/ui/Menu.cpp | 14 +- source/ui/PopMessage.cpp | 4 +- source/ui/PopMessageManager.cpp | 6 +- source/ui/SlideOutPanel.cpp | 6 +- source/ui/TextScroll.cpp | 16 +- source/ui/TitleTile.cpp | 4 +- source/ui/TitleView.cpp | 5 +- 105 files changed, 1112 insertions(+), 902 deletions(-) create mode 100644 include/config/ConfigContext.hpp rename include/{ => config}/config.hpp (61%) create mode 100644 include/config/keys.hpp rename include/{ => graphics}/colors.hpp (100%) rename include/{ => graphics}/gfxutil.hpp (71%) rename include/{ => logging}/error.hpp (100%) rename include/{ => logging}/logger.hpp (100%) delete mode 100644 include/strings.hpp create mode 100644 include/strings/names.hpp create mode 100644 include/strings/strings.hpp delete mode 100644 source/config.cpp create mode 100644 source/config/ConfigContext.cpp create mode 100644 source/config/config.cpp create mode 100644 source/fs/PathFilter.cpp rename source/{ => logging}/error.cpp (96%) rename source/{ => logging}/logger.cpp (95%) diff --git a/Libraries/SDLLib b/Libraries/SDLLib index 8ee7816..6a1607e 160000 --- a/Libraries/SDLLib +++ b/Libraries/SDLLib @@ -1 +1 @@ -Subproject commit 8ee78161dce7b644d2bd9a561477a654f3694b77 +Subproject commit 6a1607e155dbba0707381059af6d5516855a8c31 diff --git a/Makefile b/Makefile index c3bb93b..c33259d 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,8 @@ include $(DEVKITPRO)/libnx/switch_rules #--------------------------------------------------------------------------------- TARGET := JKSV BUILD := build -SOURCES := source source/appstates source/ui source/data source/sys source/fs source/curl source/remote source/tasks +SOURCES := source source/appstates source/config source/curl source/data source/fs \ + source/logging source/remote source/sys source/tasks source/ui DATA := data INCLUDES := include ./Libraries/FsLib/Switch/FsLib/include ./Libraries/SDLLib/SDL/include EXEFS_SRC := exefs_src diff --git a/include/JSON.hpp b/include/JSON.hpp index 3117c9d..00a4a5f 100644 --- a/include/JSON.hpp +++ b/include/JSON.hpp @@ -33,4 +33,13 @@ namespace json { return json_object_object_add(json.get(), key.data(), object) == 0; } + + /// @brief Returns the json string. + static inline const char *get_string(json::Object &json) { return json_object_get_string(json.get()); } + + /// @brief Returns the beginning for iterating. + static inline json_object_iterator iter_begin(json::Object &json) { return json_object_iter_begin(json.get()); } + + /// @brief Returns the end for iterating. + static inline json_object_iterator iter_end(json::Object &json) { return json_object_iter_end(json.get()); } } // namespace json diff --git a/include/appstates/BackupMenuState.hpp b/include/appstates/BackupMenuState.hpp index be9d2bd..c933ce0 100644 --- a/include/appstates/BackupMenuState.hpp +++ b/include/appstates/BackupMenuState.hpp @@ -1,13 +1,12 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "data/data.hpp" #include "fslib.hpp" #include "remote/remote.hpp" #include "sdl.hpp" #include "sys/sys.hpp" -#include "ui/Menu.hpp" -#include "ui/SlideOutPanel.hpp" -#include "ui/TextScroll.hpp" +#include "ui/ui.hpp" #include @@ -25,10 +24,18 @@ class BackupMenuState final : public BaseState ~BackupMenuState(); /// @brief Creates and returns a new BackupMenuState. - static std::shared_ptr create(data::User *user, data::TitleInfo *titleInfo); + static inline std::shared_ptr create(data::User *user, data::TitleInfo *titleInfo) + { + return std::make_shared(user, titleInfo); + } /// @brief Creates and pushes a new BackupMenuState to the vector. - static std::shared_ptr create_and_push(data::User *user, data::TitleInfo *titleInfo); + static inline std::shared_ptr create_and_push(data::User *user, data::TitleInfo *titleInfo) + { + auto newState = BackupMenuState::create(user, titleInfo); + StateManager::push_state(newState); + return newState; + } /// @brief Required. Inherited virtual function from AppState. void update() override; @@ -89,7 +96,7 @@ class BackupMenuState final : public BaseState remote::Storage::DirectoryListing m_remoteListing{}; /// @brief This is the scrolling text at the top. - ui::TextScroll m_titleScroll{}; + std::shared_ptr m_titleScroll{}; /// @brief Variable that saves whether or not the filesystem has data in it. bool m_saveHasData{}; @@ -110,7 +117,7 @@ class BackupMenuState final : public BaseState static inline std::shared_ptr sm_backupMenu{}; /// @brief The slide out panel used by all instances of BackupMenuState. - static inline std::unique_ptr sm_slidePanel{}; + static inline std::shared_ptr sm_slidePanel{}; /// @brief Inner render target so the menu only renders to a certain area. static inline sdl::SharedTexture sm_menuRenderTarget{}; diff --git a/include/appstates/BlacklistEditState.hpp b/include/appstates/BlacklistEditState.hpp index 7080a85..4d6f3f5 100644 --- a/include/appstates/BlacklistEditState.hpp +++ b/include/appstates/BlacklistEditState.hpp @@ -1,4 +1,5 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "ui/ui.hpp" @@ -15,10 +16,15 @@ class BlacklistEditState final : public BaseState ~BlacklistEditState(); /// @brief Creates and returns a new state. - static std::shared_ptr create(); + static inline std::shared_ptr create() { return std::make_shared(); } /// @brief Creates, pushes, then returns a new blacklist edit states. - static std::shared_ptr create_and_push(); + static inline std::shared_ptr create_and_push() + { + auto newState = BlacklistEditState::create(); + StateManager::push_state(newState); + return newState; + } /// @brief Update override. void update() override; diff --git a/include/appstates/ConfirmState.hpp b/include/appstates/ConfirmState.hpp index b22fc5c..9155067 100644 --- a/include/appstates/ConfirmState.hpp +++ b/include/appstates/ConfirmState.hpp @@ -4,11 +4,11 @@ #include "appstates/FadeState.hpp" #include "appstates/ProgressState.hpp" #include "appstates/TaskState.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "sys/sys.hpp" #include "ui/ui.hpp" @@ -42,7 +42,7 @@ class ConfirmState final : public BaseState /// @param function Function executed on confirmation. /// @param dataStruct shared_ptr that is passed to function. I tried templating this and it was a nightmare. ConfirmState(std::string_view query, bool holdRequired, TaskFunction function, std::shared_ptr dataStruct) - : BaseState{false} + : BaseState(false) , m_query(query) , m_yesText(strings::get_by_name(strings::names::YES_NO_OK, 0)) , m_noText(strings::get_by_name(strings::names::YES_NO_OK, 1)) @@ -60,19 +60,19 @@ class ConfirmState final : public BaseState ~ConfirmState() {}; /// @brief Returns a new ConfirmState. See constructor. - static std::shared_ptr create(std::string_view query, - bool holdRequired, - TaskFunction function, - std::shared_ptr dataStruct) + static inline std::shared_ptr create(std::string_view query, + bool holdRequired, + TaskFunction function, + std::shared_ptr dataStruct) { return std::make_shared(query, holdRequired, function, dataStruct); } /// @brief Creates and returns a new ConfirmState and pushes it. - static std::shared_ptr create_and_push(std::string_view query, - bool holdRequired, - TaskFunction function, - std::shared_ptr dataStruct) + static inline std::shared_ptr create_and_push(std::string_view query, + bool holdRequired, + TaskFunction function, + std::shared_ptr dataStruct) { // I'm gonna use a sneaky trick here. This shouldn't do this because it's confusing. auto newState = create(query, holdRequired, function, dataStruct); diff --git a/include/appstates/DataLoadingState.hpp b/include/appstates/DataLoadingState.hpp index 3ac1d35..f7cb2f9 100644 --- a/include/appstates/DataLoadingState.hpp +++ b/include/appstates/DataLoadingState.hpp @@ -27,19 +27,19 @@ class DataLoadingState final : public BaseTask } template - static std::shared_ptr create(data::DataContext &context, - DestructFunction destructFunction, - void (*function)(sys::Task *, Args...), - Args... args) + static inline std::shared_ptr create(data::DataContext &context, + DestructFunction destructFunction, + void (*function)(sys::Task *, Args...), + Args... args) { return std::make_shared(context, destructFunction, function, std::forward(args)...); } template - static std::shared_ptr create_and_push(data::DataContext &context, - DestructFunction destructFunction, - void (*function)(sys::Task *, Args...), - Args... args) + static inline std::shared_ptr create_and_push(data::DataContext &context, + DestructFunction destructFunction, + void (*function)(sys::Task *, Args...), + Args... args) { auto newState = DataLoadingState::create(context, destructFunction, function, std::forward(args)...); StateManager::push_state(newState); diff --git a/include/appstates/ExtrasMenuState.hpp b/include/appstates/ExtrasMenuState.hpp index 4a500d7..6a252ff 100644 --- a/include/appstates/ExtrasMenuState.hpp +++ b/include/appstates/ExtrasMenuState.hpp @@ -14,7 +14,7 @@ class ExtrasMenuState final : public BaseState ~ExtrasMenuState() {}; /// @brief Returns a new ExtrasMenuState - static std::shared_ptr create(); + static inline std::shared_ptr create() { return std::make_shared(); } /// @brief Updates the menu. void update() override; diff --git a/include/appstates/FadeState.hpp b/include/appstates/FadeState.hpp index 0604883..cf6e52e 100644 --- a/include/appstates/FadeState.hpp +++ b/include/appstates/FadeState.hpp @@ -1,4 +1,5 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "sdl.hpp" #include "sys/sys.hpp" @@ -19,19 +20,28 @@ class FadeState final : public BaseState /// @param nextState The next state to push after the the fade is finished. FadeState(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha, std::shared_ptr nextState); + /// @brief Required destructor. ~FadeState() {}; /// @brief Returns a new fade in state. See constructor. - static std::shared_ptr create(sdl::Color baseColor, - uint8_t startAlpha, - uint8_t endAlpha, - std::shared_ptr nextState); + static inline std::shared_ptr create(sdl::Color baseColor, + uint8_t startAlpha, + uint8_t endAlpha, + std::shared_ptr nextState) + { + return std::make_shared(baseColor, startAlpha, endAlpha, nextState); + } /// @brief Creates, returns and pushes a new FadeInState to the statemanager. static std::shared_ptr create_and_push(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha, - std::shared_ptr nextState); + std::shared_ptr nextState) + { + auto newState = FadeState::create(baseColor, startAlpha, endAlpha, nextState); + StateManager::push_state(newState); + return newState; + } /// @brief Update override. void update() override; @@ -48,8 +58,10 @@ class FadeState final : public BaseState /// @brief Alpha value to destruct at. uint8_t m_endAlpha{}; + /// @brief Direction (in/out) of the fade. This is auto determined according to alpha values passed. FadeState::Direction m_direction{}; + /// @brief The divisor found to make sure alpha ends evenly. uint8_t m_divisor{}; /// @brief Timer for fade. @@ -58,8 +70,15 @@ class FadeState final : public BaseState /// @brief Pointer to the next state to push. std::shared_ptr m_nextState{}; + /// @brief Finds the highest divisor for the fade to use. void find_divisor(); + + /// @brief Decreases alpha by m_divisor. void decrease_alpha(); + + /// @brief Increases alpha by m_divisor. void increase_alpha(); + + /// @brief Completes the fade. void completed(); }; diff --git a/include/appstates/MainMenuState.hpp b/include/appstates/MainMenuState.hpp index 23bff12..e97255b 100644 --- a/include/appstates/MainMenuState.hpp +++ b/include/appstates/MainMenuState.hpp @@ -1,4 +1,5 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "data/data.hpp" #include "sdl.hpp" @@ -17,10 +18,15 @@ class MainMenuState final : public BaseState ~MainMenuState() {}; /// @brief Returns a new MainMenuState - static std::shared_ptr create(); + static inline std::shared_ptr create() { return std::make_shared(); } /// @brief Creates and returns a new MainMenuState. Pushes it automatically. - static std::shared_ptr create_and_push(); + static inline std::shared_ptr create_and_push() + { + auto newState = MainMenuState::create(); + StateManager::push_state(newState); + return newState; + } /// @brief Runs update routine. void update() override; @@ -57,7 +63,7 @@ class MainMenuState final : public BaseState sdl::SharedTexture m_extrasIcon{}; /// @brief Special menu type that uses icons. - ui::IconMenu m_mainMenu; + std::shared_ptr m_mainMenu{}; /// @brief Pointer to control guide string so I don't need to call string::getByName every loop. const char *m_controlGuide{}; diff --git a/include/appstates/MessageState.hpp b/include/appstates/MessageState.hpp index 4a1e11f..222e256 100644 --- a/include/appstates/MessageState.hpp +++ b/include/appstates/MessageState.hpp @@ -1,5 +1,8 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" +#include "appstates/FadeState.hpp" +#include "graphics/colors.hpp" #include "ui/DialogBox.hpp" #include @@ -16,13 +19,26 @@ class MessageState final : public BaseState ~MessageState(); /// @brief Creates and returns a new MessageState. See constructor. - static std::shared_ptr create(std::string_view message); + static inline std::shared_ptr create(std::string_view message) + { + return std::make_shared(message); + } /// @brief Same as above, only pushed to the StateManager before return. - static std::shared_ptr create_and_push(std::string_view message); + static inline std::shared_ptr create_and_push(std::string_view message) + { + auto newState = MessageState::create(message); + StateManager::push_state(newState); + return newState; + } /// @brief Same as above, but creates and pushes a transition fade in between. - static std::shared_ptr create_and_push_fade(std::string_view message); + static inline std::shared_ptr create_and_push_fade(std::string_view message) + { + auto newState = MessageState::create(message); + auto fadeState = FadeState::create_and_push(colors::DIM_BACKGROUND, 0x00, 0x88, newState); + return newState; + } /// @brief Update override. void update() override; diff --git a/include/appstates/ProgressState.hpp b/include/appstates/ProgressState.hpp index fd074f3..4614a98 100644 --- a/include/appstates/ProgressState.hpp +++ b/include/appstates/ProgressState.hpp @@ -28,14 +28,17 @@ class ProgressState final : public BaseTask /// @brief Required destructor. ~ProgressState(); + /// @brief Creates and returns a new progress state. template - static std::shared_ptr create(void (*function)(sys::ProgressTask *, Args...), Args... args) + static inline std::shared_ptr create(void (*function)(sys::ProgressTask *, Args...), Args... args) { return std::make_shared(function, std::forward(args)...); } + /// @brief Creates, pushes, then returns a new ProgressState. template - static std::shared_ptr create_and_push(void (*function)(sys::ProgressTask *, Args...), Args... args) + static inline std::shared_ptr create_and_push(void (*function)(sys::ProgressTask *, Args...), + Args... args) { auto newState = ProgressState::create(function, std::forward(args)...); StateManager::push_state(newState); diff --git a/include/appstates/SaveCreateState.hpp b/include/appstates/SaveCreateState.hpp index 00dc44e..83f898a 100644 --- a/include/appstates/SaveCreateState.hpp +++ b/include/appstates/SaveCreateState.hpp @@ -1,9 +1,9 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "appstates/TitleSelectCommon.hpp" #include "data/data.hpp" -#include "ui/Menu.hpp" -#include "ui/SlideOutPanel.hpp" +#include "ui/ui.hpp" #include #include @@ -21,10 +21,18 @@ class SaveCreateState final : public BaseState ~SaveCreateState(); /// @brief Returns a new SaveCreate state. See constructor for arguments. - static std::shared_ptr create(data::User *user, TitleSelectCommon *titleSelect); + static inline std::shared_ptr create(data::User *user, TitleSelectCommon *titleSelect) + { + return std::make_shared(user, titleSelect); + } /// @brief Creates, pushes, returns and new SaveCreateState. - static std::shared_ptr create_and_push(data::User *user, TitleSelectCommon *titleSelect); + static inline std::shared_ptr create_and_push(data::User *user, TitleSelectCommon *titleSelect) + { + auto newState = SaveCreateState::create(user, titleSelect); + StateManager::push_state(newState); + return newState; + } /// @brief Runs the update routine. void update() override; diff --git a/include/appstates/SettingsState.hpp b/include/appstates/SettingsState.hpp index fc95426..8662140 100644 --- a/include/appstates/SettingsState.hpp +++ b/include/appstates/SettingsState.hpp @@ -14,7 +14,7 @@ class SettingsState final : public BaseState ~SettingsState() {}; /// @brief Returns a new SettingsState. - std::shared_ptr create(); + static inline std::shared_ptr create() { return std::make_shared(); } /// @brief Runs the update routine. void update() override; @@ -24,7 +24,7 @@ class SettingsState final : public BaseState private: /// @brief Menu for selecting and toggling settings. - ui::Menu m_settingsMenu; + std::shared_ptr m_settingsMenu{}; /// @brief Pointer to the control guide string. const char *m_controlGuide{}; diff --git a/include/appstates/TaskState.hpp b/include/appstates/TaskState.hpp index 76bb8f6..c10062a 100644 --- a/include/appstates/TaskState.hpp +++ b/include/appstates/TaskState.hpp @@ -23,14 +23,16 @@ class TaskState final : public BaseTask /// @brief Required destructor. ~TaskState(); + /// @brief Creates and returns a new TaskState. template - static std::shared_ptr create(void (*function)(sys::Task *, Args...), Args... args) + static inline std::shared_ptr create(void (*function)(sys::Task *, Args...), Args... args) { return std::make_shared(function, std::forward(args)...); } + /// @brief Creates, pushes, then returns and new TaskState. template - static std::shared_ptr create_and_push(void (*function)(sys::Task *, Args...), Args... args) + static inline std::shared_ptr create_and_push(void (*function)(sys::Task *, Args...), Args... args) { auto newState = TaskState::create(function, std::forward(args)...); StateManager::push_state(newState); diff --git a/include/appstates/TextTitleSelectState.hpp b/include/appstates/TextTitleSelectState.hpp index 43ab09b..4e0c36a 100644 --- a/include/appstates/TextTitleSelectState.hpp +++ b/include/appstates/TextTitleSelectState.hpp @@ -1,4 +1,5 @@ #pragma once +#include "StateManager.hpp" #include "appstates/TitleSelectCommon.hpp" #include "data/data.hpp" #include "sdl.hpp" @@ -16,10 +17,18 @@ class TextTitleSelectState final : public TitleSelectCommon ~TextTitleSelectState() {}; /// @brief Creates and returns a new TextTitleSelect. See constructor. - static std::shared_ptr create(data::User *user); + static inline std::shared_ptr create(data::User *user) + { + return std::make_shared(user); + } /// @brief Creates, pushes, and returns a new TextTitleSelect. - static std::shared_ptr create_and_push(data::User *user); + static std::shared_ptr create_and_push(data::User *user) + { + auto newState = TextTitleSelectState::create(user); + StateManager::push_state(newState); + return newState; + } /// @brief Runs update routine. void update() override; @@ -35,7 +44,7 @@ class TextTitleSelectState final : public TitleSelectCommon data::User *m_user{}; /// @brief Menu to display titles to select from. - ui::Menu m_titleSelectMenu; + std::shared_ptr m_titleSelectMenu{}; /// @brief Target to render to. sdl::SharedTexture m_renderTarget{}; diff --git a/include/appstates/TitleInfoState.hpp b/include/appstates/TitleInfoState.hpp index 0041e8d..f932751 100644 --- a/include/appstates/TitleInfoState.hpp +++ b/include/appstates/TitleInfoState.hpp @@ -1,9 +1,9 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "data/data.hpp" #include "sys/sys.hpp" -#include "ui/SlideOutPanel.hpp" -#include "ui/TextScroll.hpp" +#include "ui/ui.hpp" #include #include @@ -21,10 +21,18 @@ class TitleInfoState final : public BaseState ~TitleInfoState(); /// @brief Creates a new TitleInfoState. - static std::shared_ptr create(data::User *user, data::TitleInfo *titleInfo); + static inline std::shared_ptr create(data::User *user, data::TitleInfo *titleInfo) + { + return std::make_shared(user, titleInfo); + } /// @brief Creates, pushes, and returns a new TitleInfoState. - static std::shared_ptr create_and_push(data::User *user, data::TitleInfo *titleInfo); + static inline std::shared_ptr create_and_push(data::User *user, data::TitleInfo *titleInfo) + { + auto newState = TitleInfoState::create(user, titleInfo); + StateManager::push_state(newState); + return newState; + } /// @brief Runs update routine. void update() override; diff --git a/include/appstates/TitleOptionState.hpp b/include/appstates/TitleOptionState.hpp index 8142d05..bfb36e2 100644 --- a/include/appstates/TitleOptionState.hpp +++ b/include/appstates/TitleOptionState.hpp @@ -1,9 +1,9 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "appstates/TitleSelectCommon.hpp" #include "data/data.hpp" -#include "ui/Menu.hpp" -#include "ui/SlideOutPanel.hpp" +#include "ui/ui.hpp" #include @@ -19,14 +19,22 @@ class TitleOptionState final : public BaseState ~TitleOptionState(); /// @brief Returns a new TitleOptionState. See constructor. - static std::shared_ptr create(data::User *user, - data::TitleInfo *titleInfo, - TitleSelectCommon *titleSelect); + static inline std::shared_ptr create(data::User *user, + data::TitleInfo *titleInfo, + TitleSelectCommon *titleSelect) + { + return std::make_shared(user, titleInfo, titleSelect); + } /// @brief Creates, pushes, and returns a new TitleOptionState static std::shared_ptr create_and_push(data::User *user, data::TitleInfo *titleInfo, - TitleSelectCommon *titleSelect); + TitleSelectCommon *titleSelect) + { + auto newState = TitleOptionState::create(user, titleInfo, titleSelect); + StateManager::push_state(newState); + return newState; + } /// @brief Runs update routine. void update() override; diff --git a/include/appstates/TitleSelectState.hpp b/include/appstates/TitleSelectState.hpp index b0b079b..2a9a8b7 100644 --- a/include/appstates/TitleSelectState.hpp +++ b/include/appstates/TitleSelectState.hpp @@ -1,4 +1,5 @@ #pragma once +#include "StateManager.hpp" #include "appstates/TitleSelectCommon.hpp" #include "data/data.hpp" #include "sdl.hpp" @@ -16,10 +17,18 @@ class TitleSelectState final : public TitleSelectCommon ~TitleSelectState() {}; /// @brief Returns a new TitleSelect state. - static std::shared_ptr create(data::User *user); + static inline std::shared_ptr create(data::User *user) + { + return std::make_shared(user); + } /// @brief Creates, pushes, and returns a new TitleSelectState. - static std::shared_ptr create_and_push(data::User *user); + static inline std::shared_ptr create_and_push(data::User *user) + { + auto newState = TitleSelectState::create(user); + StateManager::push_state(newState); + return newState; + } /// @brief Runs the update routine. void update() override; @@ -38,7 +47,7 @@ class TitleSelectState final : public TitleSelectCommon sdl::SharedTexture m_renderTarget{}; /// @brief Tiled title selection view. - ui::TitleView m_titleView; + std::shared_ptr m_titleView{}; /// @brief Checks if the user still has any games left to list. This is a safety measure. bool title_count_check(); diff --git a/include/appstates/UserOptionState.hpp b/include/appstates/UserOptionState.hpp index 876ace4..603c4ab 100644 --- a/include/appstates/UserOptionState.hpp +++ b/include/appstates/UserOptionState.hpp @@ -1,9 +1,9 @@ #pragma once +#include "StateManager.hpp" #include "appstates/BaseState.hpp" #include "appstates/TitleSelectCommon.hpp" #include "data/data.hpp" -#include "ui/Menu.hpp" -#include "ui/SlideOutPanel.hpp" +#include "ui/ui.hpp" #include @@ -17,13 +17,21 @@ class UserOptionState final : public BaseState UserOptionState(data::User *user, TitleSelectCommon *titleSelect); /// @brief Required destructor. - ~UserOptionState() {}; + ~UserOptionState(); /// @brief Returns a new UserOptionState. See constructor. - static std::shared_ptr create(data::User *user, TitleSelectCommon *titleSelect); + static inline std::shared_ptr create(data::User *user, TitleSelectCommon *titleSelect) + { + return std::make_shared(user, titleSelect); + } /// @brief Creates, pushes, and returns a new UserOptionState. - static std::shared_ptr create_and_push(data::User *user, TitleSelectCommon *titleSelect); + static inline std::shared_ptr create_and_push(data::User *user, TitleSelectCommon *titleSelect) + { + auto newState = UserOptionState::create(user, titleSelect); + StateManager::push_state(newState); + return newState; + } /// @brief Runs the render routine. void update() override; @@ -53,7 +61,7 @@ class UserOptionState final : public BaseState TitleSelectCommon *m_titleSelect{}; /// @brief Menu that displays the options available. - ui::Menu m_userOptionMenu; + std::shared_ptr m_userOptionMenu{}; /// @brief Shared pointer to pass data to tasks and functions. std::shared_ptr m_dataStruct{}; @@ -62,7 +70,7 @@ class UserOptionState final : public BaseState bool m_refreshRequired{}; /// @brief Slide panel all instances shared. - static inline std::unique_ptr sm_menuPanel{}; + static inline std::shared_ptr sm_menuPanel{}; /// @brief Creates the panel if it hasn't been yet. void create_menu_panel(); diff --git a/include/config/ConfigContext.hpp b/include/config/ConfigContext.hpp new file mode 100644 index 0000000..9f75e8e --- /dev/null +++ b/include/config/ConfigContext.hpp @@ -0,0 +1,111 @@ +#pragma once +#include "fslib.hpp" + +#include +#include +#include + +namespace config +{ + class ConfigContext + { + public: + using AppIDList = std::vector; + + ConfigContext() = default; + + /// @brief Resets the config to its default state. + void reset(); + + /// @brief Saves the config to the file. + void save(); + + /// @brief Loads the config from SD. + void load(); + + /// @brief Retrieves the value of the key passed. + uint8_t get_by_key(std::string_view key); + + /// @brief Toggles a basic setting by the key passed. + void toggle_by_key(std::string_view key); + + /// @brief Sets the value of a key. + void set_by_key(std::string_view key, uint8_t value); + + /// @brief Returns the current working directory for JKSV. + fslib::Path get_working_directory() const; + + /// @brief Sets the current working directory for JKSV. + bool set_working_directory(std::string_view workDir); + + /// @brief Returns the current UI transition scaling. + double get_animation_scaling() const; + + /// @brief Sets the current UI transistion scaling. + void set_animation_scaling(double scaling); + + /// @brief Adds a favorite to the list if it hasn't been already. + void add_favorite(uint64_t applicationID); + + /// @brief Removes a favorite from the lift it it's there. + void remove_favorite(uint64_t applicationID); + + /// @brief Returns whether or not the application ID passed is a favorite title. + bool is_favorite(uint64_t applicationID); + + /// @brief Adds the application ID to the blacklist if it hasn't been already. + void add_to_blacklist(uint64_t applicationID); + + /// @brief Removes the application ID passed from the blacklist. + void remove_from_blacklist(uint64_t applicationID); + + /// @brief Gets an array of the currently blacklisted titles. + void get_blacklisted_titles(std::vector &listOut); + + /// @brief Returns whether or not the application ID passed is blacklisted. + bool is_blacklisted(uint64_t applicationID); + + /// @brief Returns if the blacklist is empty. + bool blacklist_is_empty() const; + + /// @brief Adds a custom output path. + void add_custom_path(uint64_t applicationID, std::string_view path); + + /// @brief Returns whether or not the application ID has a custom output path. + bool has_custom_path(uint64_t applicationID); + + /// @brief Gets the output path of the application ID passed. + void get_custom_path(uint64_t applicationID, char *pathBuffer, size_t bufferSize); + + private: + /// @brief This is where most values are stored. + std::map m_configMap{}; + + /// @brief This is the main directory JKSV uses. + fslib::Path m_workingDirectory{}; + + /// @brief The scaling of transitions. + double m_animationScaling{}; + + /// @brief Vector of favorites + ConfigContext::AppIDList m_favorites{}; + + /// @brief Vector of blacklisted title ids. + ConfigContext::AppIDList m_blacklist{}; + + /// @brief Map of custom output paths for titles. + std::map m_pathMap; + + /// @brief Reads an array from a json_object into the vector passed. + void read_array_to_vector(std::vector &vector, json_object *array); + + /// @brief Saves the custom paths set by the user. + void save_custom_paths(); + + /// @brief Searches for and returns an iterator to the application ID (if found); + ConfigContext::AppIDList::iterator find_favorite(uint64_t applicationID); + + /// @brief Searches for and returns an iterator to the application ID (if found); + ConfigContext::AppIDList::iterator find_blacklist(uint64_t applicationID); + }; +} diff --git a/include/config.hpp b/include/config/config.hpp similarity index 61% rename from include/config.hpp rename to include/config/config.hpp index 33e8236..19a5303 100644 --- a/include/config.hpp +++ b/include/config/config.hpp @@ -1,4 +1,5 @@ #pragma once +#include "config/keys.hpp" #include "fslib.hpp" #include @@ -33,6 +34,9 @@ namespace config /// @return Working directory. fslib::Path get_working_directory(); + /// @brief Sets JKSV's current working directory. + bool set_working_directory(std::string_view path); + /// @brief Returns the scaling speed of UI transitions and animations. /// @return Scaling variable. double get_animation_scaling(); @@ -81,31 +85,4 @@ namespace config /// @param pathOut Buffer to write the path to. /// @param pathOutSize Size of the buffer to write the path to. void get_custom_path(uint64_t applicationID, char *pathOut, size_t pathOutSize); - - // Names of keys. Note: Not all of these are retrievable with GetByKey. Some of these are purely for config reading and - // writing. - namespace keys - { - static constexpr std::string_view WORKING_DIRECTORY = "WorkingDirectory"; - static constexpr std::string_view INCLUDE_DEVICE_SAVES = "IncludeDeviceSaves"; - static constexpr std::string_view AUTO_BACKUP_ON_RESTORE = "AutoBackupOnRestore"; - static constexpr std::string_view AUTO_NAME_BACKUPS = "AutoNameBackups"; - static constexpr std::string_view AUTO_UPLOAD = "AutoUploadToRemote"; - static constexpr std::string_view USE_TITLE_IDS = "AlwaysUseTitleID"; - static constexpr std::string_view HOLD_FOR_DELETION = "HoldForDeletion"; - static constexpr std::string_view HOLD_FOR_RESTORATION = "HoldForRestoration"; - static constexpr std::string_view HOLD_FOR_OVERWRITE = "HoldForOverWrite"; - static constexpr std::string_view ONLY_LIST_MOUNTABLE = "OnlyListMountable"; - static constexpr std::string_view LIST_ACCOUNT_SYS_SAVES = "ListAccountSystemSaves"; - static constexpr std::string_view ALLOW_WRITING_TO_SYSTEM = "AllowSystemSaveWriting"; - static constexpr std::string_view EXPORT_TO_ZIP = "ExportToZip"; - static constexpr std::string_view ZIP_COMPRESSION_LEVEL = "ZipCompressionLevel"; - static constexpr std::string_view TITLE_SORT_TYPE = "TitleSortType"; - static constexpr std::string_view JKSM_TEXT_MODE = "JKSMTextMode"; - static constexpr std::string_view FORCE_ENGLISH = "ForceEnglish"; - static constexpr std::string_view ENABLE_TRASH_BIN = "EnableTrash"; - static constexpr std::string_view UI_ANIMATION_SCALE = "UIAnimationScaling"; - static constexpr std::string_view FAVORITES = "Favorites"; - static constexpr std::string_view BLACKLIST = "BlackList"; - } // namespace keys } // namespace config diff --git a/include/config/keys.hpp b/include/config/keys.hpp new file mode 100644 index 0000000..ac011c8 --- /dev/null +++ b/include/config/keys.hpp @@ -0,0 +1,30 @@ +#pragma once +#include + +namespace config +{ + namespace keys + { + inline constexpr std::string_view WORKING_DIRECTORY = "WorkingDirectory"; + inline constexpr std::string_view INCLUDE_DEVICE_SAVES = "IncludeDeviceSaves"; + inline constexpr std::string_view AUTO_BACKUP_ON_RESTORE = "AutoBackupOnRestore"; + inline constexpr std::string_view AUTO_NAME_BACKUPS = "AutoNameBackups"; + inline constexpr std::string_view AUTO_UPLOAD = "AutoUploadToRemote"; + inline constexpr std::string_view USE_TITLE_IDS = "AlwaysUseTitleID"; + inline constexpr std::string_view HOLD_FOR_DELETION = "HoldForDeletion"; + inline constexpr std::string_view HOLD_FOR_RESTORATION = "HoldForRestoration"; + inline constexpr std::string_view HOLD_FOR_OVERWRITE = "HoldForOverWrite"; + inline constexpr std::string_view ONLY_LIST_MOUNTABLE = "OnlyListMountable"; + inline constexpr std::string_view LIST_ACCOUNT_SYS_SAVES = "ListAccountSystemSaves"; + inline constexpr std::string_view ALLOW_WRITING_TO_SYSTEM = "AllowSystemSaveWriting"; + inline constexpr std::string_view EXPORT_TO_ZIP = "ExportToZip"; + inline constexpr std::string_view ZIP_COMPRESSION_LEVEL = "ZipCompressionLevel"; + inline constexpr std::string_view TITLE_SORT_TYPE = "TitleSortType"; + inline constexpr std::string_view JKSM_TEXT_MODE = "JKSMTextMode"; + inline constexpr std::string_view FORCE_ENGLISH = "ForceEnglish"; + inline constexpr std::string_view ENABLE_TRASH_BIN = "EnableTrash"; + inline constexpr std::string_view UI_ANIMATION_SCALE = "UIAnimationScaling"; + inline constexpr std::string_view FAVORITES = "Favorites"; + inline constexpr std::string_view BLACKLIST = "BlackList"; + } // namespace keys +} diff --git a/include/curl/DownloadStruct.hpp b/include/curl/DownloadStruct.hpp index 82bc9db..419dc2c 100644 --- a/include/curl/DownloadStruct.hpp +++ b/include/curl/DownloadStruct.hpp @@ -11,13 +11,21 @@ namespace curl // clang-format off struct DownloadStruct { + /// @brief Buffer mutex. std::mutex lock{}; + /// @brief Conditional for when the buffer is full. std::condition_variable condition{}; + /// @brief Shared buffer that is read into. std::vector sharedBuffer{}; + /// @brief Bool to signal when the buffer is ready/empty. bool bufferReady{}; + /// @brief Destination file to write to. fslib::File *dest{}; + /// @brief Optional. Task to update with progress. sys::ProgressTask *task{}; + /// @brief Current offset in the file. size_t offset{}; + /// @brief Size of the file being downloaded. int64_t fileSize{}; }; // clang-format on diff --git a/include/curl/UploadStruct.hpp b/include/curl/UploadStruct.hpp index 5e82bbb..e3dd921 100644 --- a/include/curl/UploadStruct.hpp +++ b/include/curl/UploadStruct.hpp @@ -7,7 +7,9 @@ namespace curl // clang-format off struct UploadStruct { + /// @brief Source file to upload from. fslib::File *source{}; + /// @brief Optional. Task to update with progress. sys::ProgressTask *task{}; }; // clang-format on diff --git a/include/fs/PathFilter.hpp b/include/fs/PathFilter.hpp index 79b8328..05cfc2b 100644 --- a/include/fs/PathFilter.hpp +++ b/include/fs/PathFilter.hpp @@ -1,4 +1,6 @@ #pragma once +#include "fslib.hpp" + #include #include @@ -7,12 +9,17 @@ namespace fs class PathFilter { public: - - PathFilter(std::string_view filterPath); + /// @brief Loads a path filter JSON file. + PathFilter(const fslib::Path &filterPath); - bool is_filtered(std::string_view path); + /// @brief Returns whether or not the filter has valid paths. + bool has_paths() const; + + /// @brief Returns whether or not the path passed is filtered. + bool is_filtered(const fslib::Path &path); private: + /// @brief Vector of paths to filter from deletion and backup. std::vector m_paths{}; }; } diff --git a/include/colors.hpp b/include/graphics/colors.hpp similarity index 100% rename from include/colors.hpp rename to include/graphics/colors.hpp diff --git a/include/gfxutil.hpp b/include/graphics/gfxutil.hpp similarity index 71% rename from include/gfxutil.hpp rename to include/graphics/gfxutil.hpp index 2b6cf18..a6f2407 100644 --- a/include/gfxutil.hpp +++ b/include/graphics/gfxutil.hpp @@ -1,5 +1,6 @@ #pragma once #include "sdl.hpp" + #include // This file contains basic graphics functions various parts of JKSV use. @@ -7,12 +8,9 @@ namespace gfxutil { /// @brief Generates a generic icon for saves and titles that lack one. /// @param text Text to be centered and rendered to the icon. - /// @param fontSize + /// @param fontSize Size of the font to use. /// @param background Background color to use. /// @param foreground Color to use to render the text. /// @return sdl::SharedTexture of the icon. - sdl::SharedTexture create_generic_icon(std::string_view text, - int fontSize, - sdl::Color background, - sdl::Color foreground); + sdl::SharedTexture create_generic_icon(std::string_view text, int fontSize, sdl::Color background, sdl::Color foreground); } // namespace gfxutil diff --git a/include/error.hpp b/include/logging/error.hpp similarity index 100% rename from include/error.hpp rename to include/logging/error.hpp diff --git a/include/logger.hpp b/include/logging/logger.hpp similarity index 100% rename from include/logger.hpp rename to include/logging/logger.hpp diff --git a/include/strings.hpp b/include/strings.hpp deleted file mode 100644 index bc053cc..0000000 --- a/include/strings.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#include - -namespace strings -{ - // Attempts to load strings from file in RomFS. - bool initialize(); - - // Returns string with name and index. Returns nullptr if string doesn't exist. - const char *get_by_name(std::string_view name, int index); - - // Names of strings to prevent typos. - namespace names - { - static constexpr std::string_view BACKUPMENU_MENU = "BackupMenu"; - static constexpr std::string_view BACKUPMENU_CONFS = "BackupMenuConfirmations"; - static constexpr std::string_view BACKUPMENU_POPS = "BackupMenuPops"; - static constexpr std::string_view BACKUPMENU_STATUS = "BackupMenuStatus"; - static constexpr std::string_view CONTROL_GUIDES = "ControlGuides"; - static constexpr std::string_view DATA_LOADING_STATUS = "DataLoadingStatus"; - static constexpr std::string_view EXTRASMENU_MENU = "ExtrasMenu"; - static constexpr std::string_view EXTRASMENU_POPS = "ExtrasPops"; - static constexpr std::string_view GENERAL_POPS = "GeneralPops"; - static constexpr std::string_view GOOGLE_DRIVE = "GoogleDriveStrings"; - static constexpr std::string_view HOLDING_STRINGS = "HoldingStrings"; - static constexpr std::string_view IO_STATUSES = "IOStatuses"; - static constexpr std::string_view IO_POPS = "IOPops"; - static constexpr std::string_view KEYBOARD = "KeyboardStrings"; - static constexpr std::string_view MAINMENU_CONFS = "MainMenuConfs"; - static constexpr std::string_view MAINMENU_POPS = "MainMenuPops"; - static constexpr std::string_view ON_OFF = "OnOff"; - static constexpr std::string_view REMOTE_POPS = "RemotePops"; - static constexpr std::string_view SAVECREATE_POPS = "SaveCreatePops"; - static constexpr std::string_view SAVE_DATA_TYPES = "SaveDataTypes"; - static constexpr std::string_view SETTINGS_DESCRIPTIONS = "SettingsDescriptions"; - static constexpr std::string_view SETTINGS_MENU = "SettingsMenu"; - static constexpr std::string_view SETTINGS_POPS = "SettingsPops"; - static constexpr std::string_view SORT_TYPES = "SortTypes"; - static constexpr std::string_view TITLEINFO = "TitleInfo"; - static constexpr std::string_view TITLEOPTION_CONFS = "TitleOptionConfirmations"; - static constexpr std::string_view TITLEOPTION_POPS = "TitleOptionPops"; - static constexpr std::string_view TITLEOPTION_STATUS = "TitleOptionStatus"; - static constexpr std::string_view TITLEOPTION = "TitleOptions"; - static constexpr std::string_view TRANSLATION = "TranslationInfo"; - static constexpr std::string_view USEROPTION_CONFS = "UserOptionConfirmations"; - static constexpr std::string_view USEROPTION_STATUS = "UserOptionStatus"; - static constexpr std::string_view USEROPTION_MENU = "UserOptions"; - static constexpr std::string_view WEBDAV = "WebDavStrings"; - static constexpr std::string_view YES_NO_OK = "YesNoOK"; - } // namespace names -} // namespace strings diff --git a/include/strings/names.hpp b/include/strings/names.hpp new file mode 100644 index 0000000..09df553 --- /dev/null +++ b/include/strings/names.hpp @@ -0,0 +1,44 @@ +#pragma once +#include + +namespace strings +{ + namespace names + { + inline constexpr std::string_view BACKUPMENU_MENU = "BackupMenu"; + inline constexpr std::string_view BACKUPMENU_CONFS = "BackupMenuConfirmations"; + inline constexpr std::string_view BACKUPMENU_POPS = "BackupMenuPops"; + inline constexpr std::string_view BACKUPMENU_STATUS = "BackupMenuStatus"; + inline constexpr std::string_view CONTROL_GUIDES = "ControlGuides"; + inline constexpr std::string_view DATA_LOADING_STATUS = "DataLoadingStatus"; + inline constexpr std::string_view EXTRASMENU_MENU = "ExtrasMenu"; + inline constexpr std::string_view EXTRASMENU_POPS = "ExtrasPops"; + inline constexpr std::string_view GENERAL_POPS = "GeneralPops"; + inline constexpr std::string_view GOOGLE_DRIVE = "GoogleDriveStrings"; + inline constexpr std::string_view HOLDING_STRINGS = "HoldingStrings"; + inline constexpr std::string_view IO_STATUSES = "IOStatuses"; + inline constexpr std::string_view IO_POPS = "IOPops"; + inline constexpr std::string_view KEYBOARD = "KeyboardStrings"; + inline constexpr std::string_view MAINMENU_CONFS = "MainMenuConfs"; + inline constexpr std::string_view MAINMENU_POPS = "MainMenuPops"; + inline constexpr std::string_view ON_OFF = "OnOff"; + inline constexpr std::string_view REMOTE_POPS = "RemotePops"; + inline constexpr std::string_view SAVECREATE_POPS = "SaveCreatePops"; + inline constexpr std::string_view SAVE_DATA_TYPES = "SaveDataTypes"; + inline constexpr std::string_view SETTINGS_DESCRIPTIONS = "SettingsDescriptions"; + inline constexpr std::string_view SETTINGS_MENU = "SettingsMenu"; + inline constexpr std::string_view SETTINGS_POPS = "SettingsPops"; + inline constexpr std::string_view SORT_TYPES = "SortTypes"; + inline constexpr std::string_view TITLEINFO = "TitleInfo"; + inline constexpr std::string_view TITLEOPTION_CONFS = "TitleOptionConfirmations"; + inline constexpr std::string_view TITLEOPTION_POPS = "TitleOptionPops"; + inline constexpr std::string_view TITLEOPTION_STATUS = "TitleOptionStatus"; + inline constexpr std::string_view TITLEOPTION = "TitleOptions"; + inline constexpr std::string_view TRANSLATION = "TranslationInfo"; + inline constexpr std::string_view USEROPTION_CONFS = "UserOptionConfirmations"; + inline constexpr std::string_view USEROPTION_STATUS = "UserOptionStatus"; + inline constexpr std::string_view USEROPTION_MENU = "UserOptions"; + inline constexpr std::string_view WEBDAV = "WebDavStrings"; + inline constexpr std::string_view YES_NO_OK = "YesNoOK"; + } +} diff --git a/include/strings/strings.hpp b/include/strings/strings.hpp new file mode 100644 index 0000000..3d9ae9e --- /dev/null +++ b/include/strings/strings.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "strings/names.hpp" + +#include + +namespace strings +{ + // Attempts to load strings from file in RomFS. + bool initialize(); + + // Returns string with name and index. Returns nullptr if string doesn't exist. + const char *get_by_name(std::string_view name, int index); +} // namespace strings diff --git a/include/ui/BoundingBox.hpp b/include/ui/BoundingBox.hpp index 04d953f..bf7db12 100644 --- a/include/ui/BoundingBox.hpp +++ b/include/ui/BoundingBox.hpp @@ -21,7 +21,10 @@ namespace ui ~BoundingBox() {}; /// @brief Creates a returns a new BoundingBox. See constructor. - static std::shared_ptr create(int x, int y, int width, int height); + static inline std::shared_ptr create(int x, int y, int width, int height) + { + return std::make_shared(x, y, width, height); + } /// @brief Update override. void update(bool hasFocus) override; diff --git a/include/ui/DialogBox.hpp b/include/ui/DialogBox.hpp index 802116d..cfb0e4b 100644 --- a/include/ui/DialogBox.hpp +++ b/include/ui/DialogBox.hpp @@ -26,11 +26,14 @@ namespace ui ~DialogBox() {}; /// @brief Creates and returns a new DialogBox instance. See constructor. - static std::shared_ptr create(int x, - int y, - int width, - int height, - DialogBox::Type type = DialogBox::Type::Dark); + static inline std::shared_ptr create(int x, + int y, + int width, + int height, + DialogBox::Type type = DialogBox::Type::Dark) + { + return std::make_shared(x, y, width, height, type); + } /// @brief Update override. This does NOTHING! void update(bool hasFocus) override {}; diff --git a/include/ui/IconMenu.hpp b/include/ui/IconMenu.hpp index 9dd1c63..0d8565f 100644 --- a/include/ui/IconMenu.hpp +++ b/include/ui/IconMenu.hpp @@ -21,7 +21,11 @@ namespace ui /// @brief Required destructor. ~IconMenu() {}; - std::shared_ptr create(int x, int y, int renderTargetHeight); + /// @brief Creates and returns a new IconMenu instance. + static inline std::shared_ptr create(int x, int y, int renderTargetHeight) + { + return std::make_shared(x, y, renderTargetHeight); + } /// @brief Initializes the menu. /// @param x X coordinate to render the menu to. diff --git a/include/ui/Menu.hpp b/include/ui/Menu.hpp index cc741d0..70daaec 100644 --- a/include/ui/Menu.hpp +++ b/include/ui/Menu.hpp @@ -26,7 +26,11 @@ namespace ui /// @brief Required destructor. ~Menu() {}; - static std::shared_ptr create(int x, int y, int width, int fontSize, int renderTargetHeight); + /// @brief Creates and returns a new ui::Menu instance. + static inline std::shared_ptr create(int x, int y, int width, int fontSize, int renderTargetHeight) + { + return std::make_shared(x, y, width, fontSize, renderTargetHeight); + } /// @brief Runs the update routine. /// @param hasFocus Whether or not the calling state has focus. diff --git a/include/ui/SlideOutPanel.hpp b/include/ui/SlideOutPanel.hpp index 87b38e2..c56ed03 100644 --- a/include/ui/SlideOutPanel.hpp +++ b/include/ui/SlideOutPanel.hpp @@ -25,7 +25,11 @@ namespace ui /// @brief Required destructor. ~SlideOutPanel() {}; - std::shared_ptr create(int width, SlideOutPanel::Side side); + /// @brief Creates and returns and new ui::SlideOutPanel instance. + static inline std::shared_ptr create(int width, SlideOutPanel::Side side) + { + return std::make_shared(width, side); + } /// @brief Runs the update routine. /// @param hasFocus Whether or not the calling state has focus. diff --git a/include/ui/TextScroll.hpp b/include/ui/TextScroll.hpp index 37f71de..2bc64a2 100644 --- a/include/ui/TextScroll.hpp +++ b/include/ui/TextScroll.hpp @@ -36,15 +36,18 @@ namespace ui ~TextScroll() {}; /// @brief Creates and returns a new TextScroll. See constructor. - static std::shared_ptr create(std::string_view text, - int x, - int y, - int width, - int height, - int fontSize, - sdl::Color textColor, - sdl::Color clearColor, - bool center = true); + static inline std::shared_ptr create(std::string_view text, + int x, + int y, + int width, + int height, + int fontSize, + sdl::Color textColor, + sdl::Color clearColor, + bool center = true) + { + return std::make_shared(text, x, y, width, height, fontSize, textColor, clearColor, center); + } /// @brief Creates/sets the text and parameters for TextScroll. /// @param text Text to display/scroll. diff --git a/include/ui/TitleView.hpp b/include/ui/TitleView.hpp index 8206bc0..dc5aa4e 100644 --- a/include/ui/TitleView.hpp +++ b/include/ui/TitleView.hpp @@ -21,6 +21,11 @@ namespace ui /// @brief Required destructor. ~TitleView() {}; + static inline std::shared_ptr create(data::User *user) + { + return std::make_shared(user); + } + /// @brief Runs the update routine. /// @param hasFocus Whether the calling state has focus. void update(bool hasFocus) override; diff --git a/source/JKSV.cpp b/source/JKSV.cpp index 296af64..784fc9f 100644 --- a/source/JKSV.cpp +++ b/source/JKSV.cpp @@ -3,17 +3,17 @@ #include "StateManager.hpp" #include "appstates/MainMenuState.hpp" #include "appstates/TaskState.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "curl/curl.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fslib.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/PopMessageManager.hpp" @@ -159,7 +159,7 @@ bool JKSV::initialize_sdl() { bool sdlInit = sdl::initialize("JKSV", 1280, 720); sdlInit = sdlInit && sdl::text::initialize(); - m_headerIcon = sdl::TextureManager::create_load_texture("headerIcon", "romfs:/Textures/HeaderIcon.png"); + m_headerIcon = sdl::TextureManager::load("headerIcon", "romfs:/Textures/HeaderIcon.png"); JKSV::add_color_chars(); return sdlInit && m_headerIcon; } diff --git a/source/StateManager.cpp b/source/StateManager.cpp index f7ee0bd..2e5a43a 100644 --- a/source/StateManager.cpp +++ b/source/StateManager.cpp @@ -1,7 +1,5 @@ #include "StateManager.hpp" -#include "logger.hpp" - void StateManager::update() { // Grab the instance. diff --git a/source/appstates/BackupMenuState.cpp b/source/appstates/BackupMenuState.cpp index ac8e9b3..9ce78ce 100644 --- a/source/appstates/BackupMenuState.cpp +++ b/source/appstates/BackupMenuState.cpp @@ -4,15 +4,15 @@ #include "appstates/ConfirmState.hpp" #include "appstates/FadeState.hpp" #include "appstates/ProgressState.hpp" -#include "colors.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/fs.hpp" #include "fslib.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "keyboard.hpp" +#include "logging/error.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "tasks/backup.hpp" @@ -55,18 +55,6 @@ BackupMenuState::~BackupMenuState() if (remote) { remote->return_to_root(); } } -std::shared_ptr BackupMenuState::create(data::User *user, data::TitleInfo *titleInfo) -{ - return std::make_shared(user, titleInfo); -} - -std::shared_ptr BackupMenuState::create_and_push(data::User *user, data::TitleInfo *titleInfo) -{ - auto newState = BackupMenuState::create(user, titleInfo); - StateManager::push_state(newState); - return newState; -} - void BackupMenuState::update() { const bool hasFocus = BaseState::has_focus(); @@ -98,7 +86,6 @@ void BackupMenuState::update() else if (bPressed) { sm_slidePanel->close(); } else if (sm_slidePanel->is_closed()) { BaseState::deactivate(); } - m_titleScroll.update(hasFocus); sm_backupMenu->update(hasFocus); } @@ -108,7 +95,6 @@ void BackupMenuState::render() sdl::SharedTexture &target = sm_slidePanel->get_target(); sm_slidePanel->clear_target(); - m_titleScroll.render(target, hasFocus); sdl::render_line(target, 10, 42, sm_panelWidth - 10, 42, colors::WHITE); sdl::render_line(target, 10, 648, sm_panelWidth - 10, 648, colors::WHITE); @@ -125,6 +111,7 @@ void BackupMenuState::refresh() { const bool autoUpload = config::get_by_key(config::keys::AUTO_UPLOAD); remote::Storage *remote = remote::get_remote_storage(); + m_directoryListing.open(m_directoryPath); if (!autoUpload && !m_directoryListing.is_open()) { return; } sm_backupMenu->reset(); @@ -166,11 +153,10 @@ void BackupMenuState::initialize_static_members() { if (sm_backupMenu && sm_slidePanel && sm_menuRenderTarget && sm_panelWidth) { return; } - sm_panelWidth = sdl::text::get_width(22, m_controlGuide) + 64; - sm_backupMenu = std::make_shared(8, 8, sm_panelWidth - 16, 24, 600); - sm_slidePanel = std::make_unique(sm_panelWidth, ui::SlideOutPanel::Side::Right); - sm_menuRenderTarget = - sdl::TextureManager::create_load_texture("backupMenuTarget", sm_panelWidth, 600, SDL_TEXTUREACCESS_TARGET); + sm_panelWidth = sdl::text::get_width(22, m_controlGuide) + 64; + sm_backupMenu = ui::Menu::create(8, 8, sm_panelWidth - 16, 24, 600); + sm_slidePanel = ui::SlideOutPanel::create(sm_panelWidth, ui::SlideOutPanel::Side::Right); + sm_menuRenderTarget = sdl::TextureManager::load("backupMenuTarget", sm_panelWidth, 600, SDL_TEXTUREACCESS_TARGET); } void BackupMenuState::ensure_target_directory() @@ -199,8 +185,9 @@ void BackupMenuState::initialize_info_string() const char *nickname = m_user->get_nickname(); const char *title = m_titleInfo->get_title(); const std::string infoString = stringutil::get_formatted_string("`%s` - %s", nickname, title); + m_titleScroll = ui::TextScroll::create(infoString, 8, 8, sm_panelWidth - 16, 30, 22, colors::WHITE, colors::TRANSPARENT); - m_titleScroll.initialize(infoString, 8, 8, sm_panelWidth - 16, 30, 22, colors::WHITE, colors::TRANSPARENT); + sm_slidePanel->push_new_element(m_titleScroll); } void BackupMenuState::save_data_check() diff --git a/source/appstates/BaseState.cpp b/source/appstates/BaseState.cpp index c7f1d20..615929a 100644 --- a/source/appstates/BaseState.cpp +++ b/source/appstates/BaseState.cpp @@ -1,6 +1,6 @@ #include "appstates/BaseState.hpp" -#include "error.hpp" +#include "logging/error.hpp" #include diff --git a/source/appstates/BaseTask.cpp b/source/appstates/BaseTask.cpp index dbc68fe..0cac3e1 100644 --- a/source/appstates/BaseTask.cpp +++ b/source/appstates/BaseTask.cpp @@ -1,8 +1,8 @@ #include "appstates/BaseTask.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "ui/PopMessageManager.hpp" namespace diff --git a/source/appstates/BlacklistEditState.cpp b/source/appstates/BlacklistEditState.cpp index 22a9f56..e221664 100644 --- a/source/appstates/BlacklistEditState.cpp +++ b/source/appstates/BlacklistEditState.cpp @@ -2,10 +2,10 @@ #include "StateManager.hpp" #include "appstates/MainMenuState.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" -#include "error.hpp" #include "input.hpp" +#include "logging/error.hpp" BlacklistEditState::BlacklistEditState() : BaseState() @@ -22,15 +22,6 @@ BlacklistEditState::~BlacklistEditState() sm_slidePanel->reset(); } -std::shared_ptr BlacklistEditState::create() { return std::make_shared(); } - -std::shared_ptr BlacklistEditState::create_and_push() -{ - auto newState = std::make_shared(); - StateManager::push_state(newState); - return newState; -} - void BlacklistEditState::update() { const bool hasFocus = BaseState::has_focus(); diff --git a/source/appstates/DataLoadingState.cpp b/source/appstates/DataLoadingState.cpp index cffe6a2..bfda1e1 100644 --- a/source/appstates/DataLoadingState.cpp +++ b/source/appstates/DataLoadingState.cpp @@ -1,7 +1,7 @@ #include "appstates/DataLoadingState.hpp" -#include "colors.hpp" -#include "logger.hpp" +#include "graphics/colors.hpp" +#include "logging/logger.hpp" namespace { @@ -43,5 +43,5 @@ void DataLoadingState::initialize_static_members() { if (sm_jksvIcon) { return; } - sm_jksvIcon = sdl::TextureManager::create_load_texture("LoadingIcon", "romfs:/Textures/LoadingIcon.png"); + sm_jksvIcon = sdl::TextureManager::load("LoadingIcon", "romfs:/Textures/LoadingIcon.png"); } diff --git a/source/appstates/ExtrasMenuState.cpp b/source/appstates/ExtrasMenuState.cpp index 59d64ef..81e1f7d 100644 --- a/source/appstates/ExtrasMenuState.cpp +++ b/source/appstates/ExtrasMenuState.cpp @@ -1,11 +1,11 @@ #include "appstates/ExtrasMenuState.hpp" #include "appstates/MainMenuState.hpp" -#include "colors.hpp" #include "data/data.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "keyboard.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "ui/PopMessageManager.hpp" #include @@ -33,13 +33,11 @@ static void finish_reinitialization(); ExtrasMenuState::ExtrasMenuState() : m_extrasMenu(32, 8, 1000, 24, 555) - , m_renderTarget(sdl::TextureManager::create_load_texture(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) + , m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) { ExtrasMenuState::initialize_menu(); } -std::shared_ptr create() { return std::make_shared(); } - void ExtrasMenuState::update() { const bool hasFocus = BaseState::has_focus(); diff --git a/source/appstates/FadeState.cpp b/source/appstates/FadeState.cpp index 254bde2..7a0fd47 100644 --- a/source/appstates/FadeState.cpp +++ b/source/appstates/FadeState.cpp @@ -1,7 +1,7 @@ #include "appstates/FadeState.hpp" #include "StateManager.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "mathutil.hpp" #include "sdl.hpp" @@ -22,24 +22,6 @@ FadeState::FadeState(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha, m_fadeTimer.start(TICKS_TIMER_TRIGGER); } -std::shared_ptr FadeState::create(sdl::Color baseColor, - uint8_t startAlpha, - uint8_t endAlpha, - std::shared_ptr nextState) -{ - return std::make_shared(baseColor, startAlpha, endAlpha, nextState); -} - -std::shared_ptr FadeState::create_and_push(sdl::Color baseColor, - uint8_t startAlpha, - uint8_t endAlpha, - std::shared_ptr nextState) -{ - auto newState = std::make_shared(baseColor, startAlpha, endAlpha, nextState); - StateManager::push_state(newState); - return newState; -} - void FadeState::update() { if (m_alpha == m_endAlpha) diff --git a/source/appstates/MainMenuState.cpp b/source/appstates/MainMenuState.cpp index 22a2663..230702f 100644 --- a/source/appstates/MainMenuState.cpp +++ b/source/appstates/MainMenuState.cpp @@ -8,13 +8,13 @@ #include "appstates/TitleSelectCommon.hpp" #include "appstates/TitleSelectState.hpp" #include "appstates/UserOptionState.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "tasks/mainmenu.hpp" #include "ui/PopMessageManager.hpp" @@ -25,11 +25,11 @@ namespace } MainMenuState::MainMenuState() - : m_renderTarget(sdl::TextureManager::create_load_texture("mainMenuTarget", 200, 555, SDL_TEXTUREACCESS_TARGET)) - , m_background(sdl::TextureManager::create_load_texture("mainBackground", "romfs:/Textures/MenuBackground.png")) - , m_settingsIcon(sdl::TextureManager::create_load_texture("settingsIcon", "romfs:/Textures/SettingsIcon.png")) - , m_extrasIcon(sdl::TextureManager::create_load_texture("extrasIcon", "romfs:/Textures/ExtrasIcon.png")) - , m_mainMenu(50, 15, 555) + : m_renderTarget(sdl::TextureManager::load("mainMenuTarget", 200, 555, SDL_TEXTUREACCESS_TARGET)) + , m_background(sdl::TextureManager::load("mainBackground", "romfs:/Textures/MenuBackground.png")) + , m_settingsIcon(sdl::TextureManager::load("settingsIcon", "romfs:/Textures/SettingsIcon.png")) + , m_extrasIcon(sdl::TextureManager::load("extrasIcon", "romfs:/Textures/ExtrasIcon.png")) + , m_mainMenu(ui::IconMenu::create(50, 15, 555)) , m_controlGuide(strings::get_by_name(strings::names::CONTROL_GUIDES, 0)) , m_controlGuideX(1220 - sdl::text::get_width(22, m_controlGuide)) , m_dataStruct(std::make_shared()) @@ -40,18 +40,9 @@ MainMenuState::MainMenuState() MainMenuState::initialize_data_struct(); } -std::shared_ptr MainMenuState::create() { return std::make_shared(); } - -std::shared_ptr MainMenuState::create_and_push() -{ - auto newState = MainMenuState::create(); - StateManager::push_state(newState); - return newState; -} - void MainMenuState::update() { - const int selected = m_mainMenu.get_selected(); + const int selected = m_mainMenu->get_selected(); const bool hasFocus = BaseState::has_focus(); const bool aPressed = input::button_pressed(HidNpadButton_A); const bool xPressed = input::button_pressed(HidNpadButton_X); @@ -63,23 +54,23 @@ void MainMenuState::update() else if (toUserOptions) { MainMenuState::create_user_options(); } else if (yPressed) { MainMenuState::backup_all_for_all(); } - m_mainMenu.update(hasFocus); + m_mainMenu->update(hasFocus); } void MainMenuState::render() { const bool hasFocus = BaseState::has_focus(); - const int selected = m_mainMenu.get_selected(); + const int selected = m_mainMenu->get_selected(); m_background->render(m_renderTarget, 0, 0); - m_mainMenu.render(m_renderTarget, hasFocus); + m_mainMenu->render(m_renderTarget, hasFocus); m_renderTarget->render(sdl::Texture::Null, 0, 91); if (hasFocus) { - BaseState *target = sm_states.at(selected).get(); - target->render(); + BaseState *target = sm_states[selected].get(); + target->render(); sdl::text::render(sdl::Texture::Null, m_controlGuideX, 673, 22, sdl::text::NO_WRAP, colors::WHITE, m_controlGuide); } } @@ -92,8 +83,10 @@ void MainMenuState::initialize_view_states() for (data::User *user : sm_users) { std::shared_ptr state{}; - if (jksmMode) { state = std::make_shared(user); } - else { state = std::make_shared(user); } + + if (jksmMode) { state = TextTitleSelectState::create(user); } + else { state = TitleSelectState::create(user); } + sm_states.push_back(state); } sm_states.push_back(sm_settingsState); @@ -113,8 +106,8 @@ void MainMenuState::initialize_settings_extras() { if (!sm_settingsState || !sm_extrasState) { - sm_settingsState = std::make_shared(); - sm_extrasState = std::make_shared(); + sm_settingsState = SettingsState::create(); + sm_extrasState = ExtrasMenuState::create(); } } @@ -122,9 +115,9 @@ void MainMenuState::initialize_menu() { data::get_users(sm_users); sm_userCount = sm_users.size(); - for (data::User *user : sm_users) { m_mainMenu.add_option(user->get_icon()); } - m_mainMenu.add_option(m_settingsIcon); - m_mainMenu.add_option(m_extrasIcon); + for (data::User *user : sm_users) { m_mainMenu->add_option(user->get_icon()); } + m_mainMenu->add_option(m_settingsIcon); + m_mainMenu->add_option(m_extrasIcon); } void MainMenuState::initialize_data_struct() { m_dataStruct->userList = sm_users; } @@ -134,7 +127,7 @@ void MainMenuState::push_target_state() const int popTicks = ui::PopMessageManager::DEFAULT_TICKS; const char *popNoSaveFormat = strings::get_by_name(strings::names::MAINMENU_POPS, 0); - const int selected = m_mainMenu.get_selected(); + const int selected = m_mainMenu->get_selected(); const int userCount = sm_users.size(); if (selected < userCount) { @@ -156,8 +149,8 @@ void MainMenuState::push_target_state() void MainMenuState::create_user_options() { - const int selected = m_mainMenu.get_selected(); - data::User *user = sm_users.at(selected); + const int selected = m_mainMenu->get_selected(); + data::User *user = sm_users[selected]; TitleSelectCommon *titleSelect = static_cast(sm_states[selected].get()); UserOptionState::create_and_push(user, titleSelect); diff --git a/source/appstates/MessageState.cpp b/source/appstates/MessageState.cpp index 8532121..0e24628 100644 --- a/source/appstates/MessageState.cpp +++ b/source/appstates/MessageState.cpp @@ -2,9 +2,9 @@ #include "StateManager.hpp" #include "appstates/FadeState.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" MessageState::MessageState(std::string_view message) : m_message(message) @@ -17,22 +17,6 @@ MessageState::~MessageState() FadeState::create_and_push(colors::DIM_BACKGROUND, colors::ALPHA_FADE_END, colors::ALPHA_FADE_BEGIN, nullptr); } -std::shared_ptr MessageState::create(std::string_view message) { return std::make_shared(message); } - -std::shared_ptr MessageState::create_and_push(std::string_view message) -{ - auto newState = MessageState::create(message); - StateManager::push_state(newState); - return newState; -} - -std::shared_ptr MessageState::create_and_push_fade(std::string_view message) -{ - auto newState = MessageState::create(message); - FadeState::create_and_push(colors::DIM_BACKGROUND, 0x00, 0x88, newState); - return newState; -} - void MessageState::update() { // To do: I only use this in one place right now. I'm not sure this guards correctly here? diff --git a/source/appstates/ProgressState.cpp b/source/appstates/ProgressState.cpp index 3cb3182..e7bad20 100644 --- a/source/appstates/ProgressState.cpp +++ b/source/appstates/ProgressState.cpp @@ -1,10 +1,10 @@ #include "appstates/ProgressState.hpp" #include "appstates/FadeState.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/appstates/SaveCreateState.cpp b/source/appstates/SaveCreateState.cpp index f781a71..4d571c6 100644 --- a/source/appstates/SaveCreateState.cpp +++ b/source/appstates/SaveCreateState.cpp @@ -3,11 +3,11 @@ #include "StateManager.hpp" #include "appstates/TaskState.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fs/fs.hpp" #include "input.hpp" -#include "logger.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "tasks/savecreate.hpp" @@ -37,18 +37,6 @@ SaveCreateState::~SaveCreateState() sm_slidePanel->reset(); } -std::shared_ptr SaveCreateState::create(data::User *user, TitleSelectCommon *titleSelect) -{ - return std::make_shared(user, titleSelect); -} - -std::shared_ptr SaveCreateState::create_and_push(data::User *user, TitleSelectCommon *titleSelect) -{ - auto newState = SaveCreateState::create(user, titleSelect); - StateManager::push_state(newState); - return newState; -} - void SaveCreateState::update() { const bool hasFocus = BaseState::has_focus(); diff --git a/source/appstates/SettingsState.cpp b/source/appstates/SettingsState.cpp index 7e555eb..6a194bf 100644 --- a/source/appstates/SettingsState.cpp +++ b/source/appstates/SettingsState.cpp @@ -3,14 +3,14 @@ #include "appstates/BlacklistEditState.hpp" #include "appstates/MainMenuState.hpp" #include "appstates/MessageState.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" #include "fslib.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "keyboard.hpp" -#include "logger.hpp" -#include "strings.hpp" +#include "logging/logger.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include @@ -56,18 +56,16 @@ namespace } // namespace SettingsState::SettingsState() - : m_settingsMenu(32, 8, 1000, 24, 555) + : m_settingsMenu(ui::Menu::create(32, 8, 1000, 24, 555)) , m_controlGuide(strings::get_by_name(strings::names::CONTROL_GUIDES, 3)) , m_controlGuideX(1220 - sdl::text::get_width(22, m_controlGuide)) - , m_renderTarget(sdl::TextureManager::create_load_texture(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) + , m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) { SettingsState::load_settings_menu(); SettingsState::load_extra_strings(); SettingsState::update_menu_options(); } -std::shared_ptr SettingsState::create() { return std::make_shared(); } - void SettingsState::update() { const bool hasFocus = BaseState::has_focus(); @@ -75,7 +73,7 @@ void SettingsState::update() const bool bPressed = input::button_pressed(HidNpadButton_B); const bool minusPressed = input::button_pressed(HidNpadButton_Minus); - m_settingsMenu.update(hasFocus); + m_settingsMenu->update(hasFocus); if (aPressed) { SettingsState::toggle_options(); } else if (minusPressed) { SettingsState::create_push_description_message(); } else if (bPressed) { BaseState::deactivate(); } @@ -86,7 +84,7 @@ void SettingsState::render() const bool hasFocus = BaseState::has_focus(); m_renderTarget->clear(colors::TRANSPARENT); - m_settingsMenu.render(m_renderTarget, hasFocus); + m_settingsMenu->render(m_renderTarget, hasFocus); m_renderTarget->render(sdl::Texture::Null, 201, 91); if (hasFocus) @@ -99,7 +97,7 @@ void SettingsState::load_settings_menu() { for (int i = 0; const char *option = strings::get_by_name(strings::names::SETTINGS_MENU, i); i++) { - m_settingsMenu.add_option(option); + m_settingsMenu->add_option(option); } } @@ -120,14 +118,14 @@ void SettingsState::update_menu_options() const uint8_t value = config::get_by_key(CONFIG_KEY_ARRAY[i]); const char *status = SettingsState::get_status_text(value); const std::string option = stringutil::get_formatted_string(optionTemplate, status); - m_settingsMenu.edit_option(i, option); + m_settingsMenu->edit_option(i, option); } { const char *zipCompTemplate = strings::get_by_name(strings::names::SETTINGS_MENU, 14); const uint8_t zipLevel = config::get_by_key(CONFIG_KEY_ARRAY[14]); const std::string zipOption = stringutil::get_formatted_string(zipCompTemplate, zipLevel); - m_settingsMenu.edit_option(14, zipOption); + m_settingsMenu->edit_option(14, zipOption); } { @@ -135,14 +133,14 @@ void SettingsState::update_menu_options() const uint8_t sortType = config::get_by_key(CONFIG_KEY_ARRAY[15]); const char *typeText = SettingsState::get_sort_type_text(sortType); const std::string sortTypeOption = stringutil::get_formatted_string(titleSortTemplate, typeText); - m_settingsMenu.edit_option(15, sortTypeOption); + m_settingsMenu->edit_option(15, sortTypeOption); } { const char *scalingTemplate = strings::get_by_name(strings::names::SETTINGS_MENU, 19); const double scaling = config::get_animation_scaling(); const std::string scalingOption = stringutil::get_formatted_string(scalingTemplate, scaling); - m_settingsMenu.edit_option(19, scalingOption); + m_settingsMenu->edit_option(19, scalingOption); } } @@ -164,7 +162,7 @@ void SettingsState::create_push_blacklist_edit() void SettingsState::toggle_options() { - const int selected = m_settingsMenu.get_selected(); + const int selected = m_settingsMenu->get_selected(); switch (selected) { case CHANGE_WORK_DIR: SettingsState::change_working_directory(); break; @@ -181,7 +179,7 @@ void SettingsState::toggle_options() void SettingsState::create_push_description_message() { - const int selected = m_settingsMenu.get_selected(); + const int selected = m_settingsMenu->get_selected(); const char *description = strings::get_by_name(strings::names::SETTINGS_DESCRIPTIONS, selected); MessageState::create_and_push_fade(description); diff --git a/source/appstates/TaskState.cpp b/source/appstates/TaskState.cpp index ff1b982..eaeed24 100644 --- a/source/appstates/TaskState.cpp +++ b/source/appstates/TaskState.cpp @@ -1,10 +1,10 @@ #include "appstates/TaskState.hpp" #include "appstates/FadeState.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "ui/PopMessageManager.hpp" TaskState::~TaskState() { FadeState::create_and_push(colors::DIM_BACKGROUND, 0x88, 0x00, nullptr); } diff --git a/source/appstates/TextTitleSelectState.cpp b/source/appstates/TextTitleSelectState.cpp index fc706d6..061cc8f 100644 --- a/source/appstates/TextTitleSelectState.cpp +++ b/source/appstates/TextTitleSelectState.cpp @@ -4,12 +4,12 @@ #include "appstates/BackupMenuState.hpp" #include "appstates/MainMenuState.hpp" #include "appstates/TitleOptionState.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "fs/save_mount.hpp" #include "fslib.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "sdl.hpp" #include @@ -23,24 +23,12 @@ namespace TextTitleSelectState::TextTitleSelectState(data::User *user) : TitleSelectCommon() , m_user(user) - , m_titleSelectMenu(32, 8, 1000, 20, 555) - , m_renderTarget(sdl::TextureManager::create_load_texture(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) + , m_titleSelectMenu(ui::Menu::create(32, 8, 1000, 20, 555)) + , m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) { TextTitleSelectState::refresh(); } -std::shared_ptr TextTitleSelectState::create(data::User *user) -{ - return std::make_shared(user); -} - -std::shared_ptr TextTitleSelectState::create_and_push(data::User *user) -{ - auto newState = TextTitleSelectState::create(user); - StateManager::push_state(newState); - return newState; -} - void TextTitleSelectState::update() { const bool hasFocus = BaseState::has_focus(); @@ -49,7 +37,7 @@ void TextTitleSelectState::update() const bool xPressed = input::button_pressed(HidNpadButton_X); const bool yPressed = input::button_pressed(HidNpadButton_Y); - m_titleSelectMenu.update(hasFocus); + m_titleSelectMenu->update(hasFocus); if (aPressed) { TextTitleSelectState::create_backup_menu(); } else if (xPressed) { TextTitleSelectState::create_title_option_menu(); } @@ -60,7 +48,7 @@ void TextTitleSelectState::update() void TextTitleSelectState::render() { m_renderTarget->clear(colors::TRANSPARENT); - m_titleSelectMenu.render(m_renderTarget, BaseState::has_focus()); + m_titleSelectMenu->render(m_renderTarget, BaseState::has_focus()); TitleSelectCommon::render_control_guide(); m_renderTarget->render(sdl::Texture::Null, 201, 91); } @@ -69,7 +57,7 @@ void TextTitleSelectState::refresh() { static constexpr const char *STRING_HEART = "^\uE017^ "; - m_titleSelectMenu.reset(); + m_titleSelectMenu->reset(); const size_t totalEntries = m_user->get_total_data_entries(); for (size_t i = 0; i < totalEntries; i++) @@ -82,13 +70,14 @@ void TextTitleSelectState::refresh() std::string option{}; if (favorite) { option = std::string{STRING_HEART} + title; } else { option = title; } - m_titleSelectMenu.add_option(option); + + m_titleSelectMenu->add_option(option); } } void TextTitleSelectState::create_backup_menu() { - const int selected = m_titleSelectMenu.get_selected(); + const int selected = m_titleSelectMenu->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID); @@ -98,7 +87,7 @@ void TextTitleSelectState::create_backup_menu() void TextTitleSelectState::create_title_option_menu() { - const int selected = m_titleSelectMenu.get_selected(); + const int selected = m_titleSelectMenu->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID); @@ -108,7 +97,7 @@ void TextTitleSelectState::create_title_option_menu() void TextTitleSelectState::add_remove_favorite() { - const int selected = m_titleSelectMenu.get_selected(); + const int selected = m_titleSelectMenu->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); config::add_remove_favorite(applicationID); @@ -125,7 +114,7 @@ void TextTitleSelectState::add_remove_favorite() const uint64_t appIDAt = m_user->get_application_id_at(i); if (appIDAt == applicationID) { break; } } - m_titleSelectMenu.set_selected(i); + m_titleSelectMenu->set_selected(i); MainMenuState::refresh_view_states(); } diff --git a/source/appstates/TitleInfoState.cpp b/source/appstates/TitleInfoState.cpp index 2f51f6b..5914bd7 100644 --- a/source/appstates/TitleInfoState.cpp +++ b/source/appstates/TitleInfoState.cpp @@ -1,11 +1,11 @@ #include "appstates/TitleInfoState.hpp" #include "StateManager.hpp" -#include "colors.hpp" -#include "error.hpp" +#include "graphics/colors.hpp" #include "input.hpp" +#include "logging/error.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include @@ -40,18 +40,6 @@ TitleInfoState::~TitleInfoState() sm_slidePanel->clear_elements(); } -std::shared_ptr TitleInfoState::create(data::User *user, data::TitleInfo *titleInfo) -{ - return std::make_shared(user, titleInfo); -} - -std::shared_ptr TitleInfoState::create_and_push(data::User *user, data::TitleInfo *titleInfo) -{ - auto newState = TitleInfoState::create(user, titleInfo); - StateManager::push_state(newState); - return newState; -} - void TitleInfoState::update() { // Grab this instead of calling the function over and over. @@ -154,15 +142,15 @@ void TitleInfoState::create_info_scrolls() std::shared_ptr TitleInfoState::create_new_scroll(std::string_view text, int y) { static constexpr int SIZE_FIELD_WIDTH = SIZE_PANEL_WIDTH - SIZE_PANEL_SUB; - auto textFieldScroll = std::make_shared(text, - 8, - y, - SIZE_FIELD_WIDTH, - SIZE_TEXT_TARGET_HEIGHT, - SIZE_FONT, - colors::WHITE, - m_fieldClear ? colors::CLEAR_COLOR : colors::DIALOG_DARK, - false); + auto textFieldScroll = ui::TextScroll::create(text, + 8, + y, + SIZE_FIELD_WIDTH, + SIZE_TEXT_TARGET_HEIGHT, + SIZE_FONT, + colors::WHITE, + m_fieldClear ? colors::CLEAR_COLOR : colors::DIALOG_DARK, + false); m_fieldClear = m_fieldClear ? false : true; return textFieldScroll; } diff --git a/source/appstates/TitleOptionState.cpp b/source/appstates/TitleOptionState.cpp index a5dc0b2..cc071ef 100644 --- a/source/appstates/TitleOptionState.cpp +++ b/source/appstates/TitleOptionState.cpp @@ -4,16 +4,16 @@ #include "appstates/ConfirmState.hpp" #include "appstates/MainMenuState.hpp" #include "appstates/TitleInfoState.hpp" -#include "colors.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/fs.hpp" #include "fslib.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "keyboard.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "tasks/titleoptions.hpp" @@ -58,22 +58,6 @@ TitleOptionState::~TitleOptionState() sm_titleOptionMenu->set_selected(0); } -std::shared_ptr TitleOptionState::create(data::User *user, - data::TitleInfo *titleInfo, - TitleSelectCommon *titleSelect) -{ - return std::make_shared(user, titleInfo, titleSelect); -} - -std::shared_ptr TitleOptionState::create_and_push(data::User *user, - data::TitleInfo *titleInfo, - TitleSelectCommon *titleSelect) -{ - auto newState = TitleOptionState::create(user, titleInfo, titleSelect); - StateManager::push_state(newState); - return newState; -} - void TitleOptionState::update() { const bool hasFocus = BaseState::has_focus(); diff --git a/source/appstates/TitleSelectCommon.cpp b/source/appstates/TitleSelectCommon.cpp index 6b928f4..9fdd60d 100644 --- a/source/appstates/TitleSelectCommon.cpp +++ b/source/appstates/TitleSelectCommon.cpp @@ -1,8 +1,8 @@ #include "appstates/TitleSelectCommon.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" TitleSelectCommon::TitleSelectCommon() { diff --git a/source/appstates/TitleSelectState.cpp b/source/appstates/TitleSelectState.cpp index 5aa1cb0..9474508 100644 --- a/source/appstates/TitleSelectState.cpp +++ b/source/appstates/TitleSelectState.cpp @@ -4,14 +4,12 @@ #include "appstates/BackupMenuState.hpp" #include "appstates/MainMenuState.hpp" #include "appstates/TitleOptionState.hpp" -#include "colors.hpp" -#include "config.hpp" -#include "fs/fs.hpp" -#include "fslib.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "sdl.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include @@ -24,20 +22,8 @@ namespace TitleSelectState::TitleSelectState(data::User *user) : TitleSelectCommon() , m_user(user) - , m_renderTarget(sdl::TextureManager::create_load_texture(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) - , m_titleView(m_user) {}; - -std::shared_ptr TitleSelectState::create(data::User *user) -{ - return std::make_shared(user); -} - -std::shared_ptr TitleSelectState::create_and_push(data::User *user) -{ - auto newState = TitleSelectState::create(user); - StateManager::push_state(newState); - return newState; -} + , m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET)) + , m_titleView(ui::TitleView::create(m_user)) {}; void TitleSelectState::update() { @@ -54,7 +40,7 @@ void TitleSelectState::update() else if (yPressed) { TitleSelectState::add_remove_favorite(); } else if (bPressed) { TitleSelectState::deactivate_state(); } - m_titleView.update(hasFocus); + m_titleView->update(hasFocus); } void TitleSelectState::render() @@ -62,12 +48,12 @@ void TitleSelectState::render() const bool hasFocus = BaseState::has_focus(); m_renderTarget->clear(colors::TRANSPARENT); - m_titleView.render(m_renderTarget, hasFocus); + m_titleView->render(m_renderTarget, hasFocus); TitleSelectCommon::render_control_guide(); m_renderTarget->render(sdl::Texture::Null, 201, 91); } -void TitleSelectState::refresh() { m_titleView.refresh(); } +void TitleSelectState::refresh() { m_titleView->refresh(); } bool TitleSelectState::title_count_check() { @@ -83,7 +69,7 @@ bool TitleSelectState::title_count_check() void TitleSelectState::create_backup_menu() { - const int selected = m_titleView.get_selected(); + const int selected = m_titleView->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID); @@ -93,7 +79,7 @@ void TitleSelectState::create_backup_menu() void TitleSelectState::create_title_option_menu() { - const int selected = m_titleView.get_selected(); + const int selected = m_titleView->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID); @@ -103,13 +89,13 @@ void TitleSelectState::create_title_option_menu() void TitleSelectState::deactivate_state() { - m_titleView.reset(); + m_titleView->reset(); BaseState::deactivate(); } void TitleSelectState::add_remove_favorite() { - const int selected = m_titleView.get_selected(); + const int selected = m_titleView->get_selected(); const uint64_t applicationID = m_user->get_application_id_at(selected); config::add_remove_favorite(applicationID); @@ -127,7 +113,7 @@ void TitleSelectState::add_remove_favorite() const uint64_t appIDAt = m_user->get_application_id_at(i); if (appIDAt == applicationID) { break; } } - m_titleView.set_selected(i); + m_titleView->set_selected(i); MainMenuState::refresh_view_states(); } diff --git a/source/appstates/UserOptionState.cpp b/source/appstates/UserOptionState.cpp index cba090a..e3d3ff3 100644 --- a/source/appstates/UserOptionState.cpp +++ b/source/appstates/UserOptionState.cpp @@ -6,15 +6,15 @@ #include "appstates/ProgressState.hpp" #include "appstates/SaveCreateState.hpp" #include "appstates/TaskState.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fs/fs.hpp" #include "fslib.hpp" #include "input.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "tasks/useroptions.hpp" @@ -31,15 +31,15 @@ namespace DELETE_ALL_SAVE }; + // These make things easier to type later. using TaskConfirm = ConfirmState; using ProgressConfirm = ConfirmState; - } // namespace UserOptionState::UserOptionState(data::User *user, TitleSelectCommon *titleSelect) : m_user(user) , m_titleSelect(titleSelect) - , m_userOptionMenu(8, 8, 460, 22, 720) + , m_userOptionMenu(ui::Menu::create(8, 8, 460, 22, 720)) , m_dataStruct(std::make_shared()) { UserOptionState::create_menu_panel(); @@ -47,30 +47,20 @@ UserOptionState::UserOptionState(data::User *user, TitleSelectCommon *titleSelec UserOptionState::initialize_data_struct(); } -std::shared_ptr UserOptionState::create(data::User *user, TitleSelectCommon *titleSelect) +UserOptionState::~UserOptionState() { - return std::make_shared(user, titleSelect); -} - -std::shared_ptr UserOptionState::create_and_push(data::User *user, TitleSelectCommon *titleSelect) -{ - auto newState = UserOptionState::create(user, titleSelect); - StateManager::push_state(newState); - return newState; + sm_menuPanel->clear_elements(); + sm_menuPanel->reset(); } void UserOptionState::update() { const bool hasFocus = BaseState::has_focus(); - sm_menuPanel->update(hasFocus); - - const bool isOpen = sm_menuPanel->is_open(); - if (!isOpen) { return; } - const bool aPressed = input::button_pressed(HidNpadButton_A); const bool bPressed = input::button_pressed(HidNpadButton_B); - // See if this needs to be done. + sm_menuPanel->update(hasFocus); + if (m_refreshRequired) { m_user->load_user_data(); @@ -80,7 +70,7 @@ void UserOptionState::update() if (aPressed) { - const int selected = m_userOptionMenu.get_selected(); + const int selected = m_userOptionMenu->get_selected(); switch (selected) { @@ -91,24 +81,16 @@ void UserOptionState::update() } } else if (bPressed) { sm_menuPanel->close(); } - else if (sm_menuPanel->is_closed()) - { - BaseState::deactivate(); - sm_menuPanel->reset(); - } - - m_userOptionMenu.update(BaseState::has_focus()); + else if (sm_menuPanel->is_closed()) { BaseState::deactivate(); } } void UserOptionState::render() { // Render target user's title selection screen. m_titleSelect->render(); - sdl::SharedTexture &panelTarget = sm_menuPanel->get_target(); // Render panel. sm_menuPanel->clear_target(); - m_userOptionMenu.render(panelTarget, BaseState::has_focus()); sm_menuPanel->render(sdl::Texture::Null, BaseState::has_focus()); } @@ -117,7 +99,9 @@ void UserOptionState::refresh_required() { m_refreshRequired = true; } void UserOptionState::create_menu_panel() { static constexpr int SIZE_PANEL_WIDTH = 480; - if (!sm_menuPanel) { sm_menuPanel = std::make_unique(SIZE_PANEL_WIDTH, ui::SlideOutPanel::Side::Right); } + if (sm_menuPanel) { return; } + + sm_menuPanel = ui::SlideOutPanel::create(SIZE_PANEL_WIDTH, ui::SlideOutPanel::Side::Right); } void UserOptionState::load_menu_strings() @@ -127,8 +111,9 @@ void UserOptionState::load_menu_strings() for (int i = 0; const char *format = strings::get_by_name(strings::names::USEROPTION_MENU, i); i++) { const std::string option = stringutil::get_formatted_string(format, nickname); - m_userOptionMenu.add_option(option); + m_userOptionMenu->add_option(option); } + sm_menuPanel->push_new_element(m_userOptionMenu); } void UserOptionState::initialize_data_struct() diff --git a/source/config.cpp b/source/config.cpp deleted file mode 100644 index de36782..0000000 --- a/source/config.cpp +++ /dev/null @@ -1,293 +0,0 @@ -#include "config.hpp" - -#include "JSON.hpp" -#include "error.hpp" -#include "logger.hpp" -#include "stringutil.hpp" - -#include -#include -#include -#include -#include -#include - -namespace -{ - /// @brief This is the default working directory path. - constexpr std::string_view PATH_DEFAULT_WORK_DIR = "sdmc:/JKSV"; - // Folder path. - constexpr std::string_view PATH_CONFIG_FOLDER = "sdmc:/config/JKSV"; - // Paths file. Funny name too. - constexpr const char *PATH_PATHS_PATH = "sdmc:/config/JKSV/Paths.json"; - // Actual config path. - constexpr const char *PATH_CONFIG_FILE = "sdmc:/config/JKSV/JKSV.json"; - - /// @brief This map holds the majority of config values. - std::map s_configMap; - - // Working directory - fslib::Path s_workingDirectory; - // UI animation scaling. - double s_uiAnimationScaling; - // Vector of favorite title ids - std::vector s_favorites; - // Vector of titles to ignore. - std::vector s_blacklist; - - // Map of paths. - std::map s_pathMap; -} // namespace - -// Definitions at bottom. -static void read_array_to_vector(std::vector &vector, json_object *array); -static void save_custom_paths(); - -void config::initialize() -{ - // This is so we don't constantly construct new Paths - const fslib::Path configDir{PATH_CONFIG_FOLDER}; - - const bool configDirExists = fslib::directory_exists(configDir); - const bool configDirError = !configDirExists && error::fslib(fslib::create_directories_recursively(configDir)); - if (!configDirExists && configDirError) - { - config::reset_to_default(); - return; - } - - json::Object configJSON = json::new_object(json_object_from_file, PATH_CONFIG_FILE); - if (!configJSON) - { - logger::log("Error opening config for reading: %s", fslib::error::get_string()); - config::reset_to_default(); - return; - } - - json_object_iterator configIterator = json_object_iter_begin(configJSON.get()); - json_object_iterator configEnd = json_object_iter_end(configJSON.get()); - while (!json_object_iter_equal(&configIterator, &configEnd)) - { - const char *keyName = json_object_iter_peek_name(&configIterator); - json_object *configValue = json_object_iter_peek_value(&configIterator); - - // These are exemptions. - const bool workingDirectory = std::strcmp(keyName, config::keys::WORKING_DIRECTORY.data()) == 0; - const bool animationScaling = std::strcmp(keyName, config::keys::UI_ANIMATION_SCALE.data()) == 0; - const bool favorites = std::strcmp(keyName, config::keys::FAVORITES.data()) == 0; - const bool blacklist = std::strcmp(keyName, config::keys::BLACKLIST.data()) == 0; - - if (workingDirectory) { s_workingDirectory = json_object_get_string(configValue); } - else if (animationScaling) { s_uiAnimationScaling = json_object_get_double(configValue); } - else if (favorites) { read_array_to_vector(s_favorites, configValue); } - else if (blacklist) { read_array_to_vector(s_blacklist, configValue); } - else { s_configMap[keyName] = json_object_get_uint64(configValue); } - - json_object_iter_next(&configIterator); - } - - // Load custom output paths. - if (!fslib::file_exists(PATH_PATHS_PATH)) - { - // Just bail. - return; - } - - json::Object pathsJSON = json::new_object(json_object_from_file, PATH_PATHS_PATH); - if (!pathsJSON) { return; } - - json_object_iterator pathsIterator = json_object_iter_begin(pathsJSON.get()); - json_object_iterator pathsEnd = json_object_iter_end(pathsJSON.get()); - while (!json_object_iter_equal(&pathsIterator, &pathsEnd)) - { - const char *idString = json_object_iter_peek_name(&pathsIterator); - json_object *pathObject = json_object_iter_peek_value(&pathsIterator); - const uint64_t applicationID = std::strtoull(idString, nullptr, 16); - const char *path = json_object_get_string(pathObject); - - s_pathMap[applicationID] = path; - - json_object_iter_next(&pathsIterator); - } -} - -void config::reset_to_default() -{ - s_workingDirectory = PATH_DEFAULT_WORK_DIR; - s_configMap[config::keys::INCLUDE_DEVICE_SAVES.data()] = 0; - s_configMap[config::keys::AUTO_BACKUP_ON_RESTORE.data()] = 1; - s_configMap[config::keys::AUTO_NAME_BACKUPS.data()] = 0; - s_configMap[config::keys::AUTO_UPLOAD.data()] = 0; - s_configMap[config::keys::USE_TITLE_IDS.data()] = 0; - s_configMap[config::keys::HOLD_FOR_DELETION.data()] = 1; - s_configMap[config::keys::HOLD_FOR_RESTORATION.data()] = 1; - s_configMap[config::keys::HOLD_FOR_OVERWRITE.data()] = 1; - s_configMap[config::keys::ONLY_LIST_MOUNTABLE.data()] = 1; - s_configMap[config::keys::LIST_ACCOUNT_SYS_SAVES.data()] = 0; - s_configMap[config::keys::ALLOW_WRITING_TO_SYSTEM.data()] = 0; - s_configMap[config::keys::EXPORT_TO_ZIP.data()] = 1; - s_configMap[config::keys::ZIP_COMPRESSION_LEVEL.data()] = 6; - s_configMap[config::keys::TITLE_SORT_TYPE.data()] = 0; - s_configMap[config::keys::JKSM_TEXT_MODE.data()] = 0; - s_configMap[config::keys::FORCE_ENGLISH.data()] = 0; - s_configMap[config::keys::ENABLE_TRASH_BIN.data()] = 0; - s_uiAnimationScaling = 2.5f; -} - -void config::save() -{ - { - json::Object configJSON = json::new_object(json_object_new_object); - - json_object *workingDirectory = json_object_new_string(s_workingDirectory.full_path()); - json::add_object(configJSON, config::keys::WORKING_DIRECTORY.data(), workingDirectory); - - for (const auto &[key, value] : s_configMap) - { - json_object *jsonValue = json_object_new_uint64(value); - json::add_object(configJSON, key.c_str(), jsonValue); - } - - json_object *scaling = json_object_new_double(s_uiAnimationScaling); - json::add_object(configJSON, config::keys::UI_ANIMATION_SCALE.data(), scaling); - - json_object *favoritesArray = json_object_new_array(); - for (const uint64_t &titleID : s_favorites) - { - const std::string idHex = stringutil::get_formatted_string("%016llX", titleID); - json_object *newFavorite = json_object_new_string(idHex.c_str()); - - json_object_array_add(favoritesArray, newFavorite); - } - json::add_object(configJSON, config::keys::FAVORITES.data(), favoritesArray); - - json_object *blacklistArray = json_object_new_array(); - for (const uint64_t &titleID : s_blacklist) - { - const std::string idHex = stringutil::get_formatted_string("%016llX", titleID); - json_object *newBlacklist = json_object_new_string(idHex.c_str()); - - json_object_array_add(blacklistArray, newBlacklist); - } - json::add_object(configJSON, config::keys::BLACKLIST.data(), blacklistArray); - - const char *jsonString = json_object_get_string(configJSON.get()); - const int64_t configLength = std::char_traits::length(jsonString); - fslib::File configFile{PATH_CONFIG_FILE, FsOpenMode_Create | FsOpenMode_Write, configLength}; - if (configFile) { configFile << jsonString; } - } -} - -uint8_t config::get_by_key(std::string_view key) -{ - // See if the key can be found. - auto findKey = s_configMap.find(key.data()); - if (findKey == s_configMap.end()) { return 0; } - return findKey->second; -} - -void config::toggle_by_key(std::string_view key) -{ - auto findKey = s_configMap.find(key.data()); - if (findKey == s_configMap.end()) { return; } - findKey->second = findKey->second ? 0 : 1; -} - -void config::set_by_key(std::string_view key, uint8_t value) -{ - auto findKey = s_configMap.find(key.data()); - if (findKey == s_configMap.end()) { return; } - findKey->second = value; -} - -fslib::Path config::get_working_directory() { return s_workingDirectory; } - -double config::get_animation_scaling() { return s_uiAnimationScaling; } - -void config::set_animation_scaling(double newScale) { s_uiAnimationScaling = newScale; } - -void config::add_remove_favorite(uint64_t applicationID) -{ - auto findTitle = std::find(s_favorites.begin(), s_favorites.end(), applicationID); - if (findTitle == s_favorites.end()) { s_favorites.push_back(applicationID); } - else { s_favorites.erase(findTitle); } - - config::save(); -} - -bool config::is_favorite(uint64_t applicationID) -{ - return std::find(s_favorites.begin(), s_favorites.end(), applicationID) != s_favorites.end(); -} - -void config::add_remove_blacklist(uint64_t applicationID) -{ - auto findTitle = std::find(s_blacklist.begin(), s_blacklist.end(), applicationID); - if (findTitle == s_blacklist.end()) { s_blacklist.push_back(applicationID); } - else { s_blacklist.erase(findTitle); } - - config::save(); -} - -void config::get_blacklisted_titles(std::vector &listOut) -{ - listOut.clear(); - listOut.assign(s_blacklist.begin(), s_blacklist.end()); -} - -bool config::is_blacklisted(uint64_t applicationID) -{ - return std::find(s_blacklist.begin(), s_blacklist.end(), applicationID) != s_blacklist.end(); -} - -bool config::blacklist_is_empty() { return s_blacklist.size() <= 0; } - -void config::add_custom_path(uint64_t applicationID, std::string_view customPath) -{ - s_pathMap[applicationID] = customPath.data(); - save_custom_paths(); -} - -bool config::has_custom_path(uint64_t applicationID) { return s_pathMap.find(applicationID) != s_pathMap.end(); } - -void config::get_custom_path(uint64_t applicationID, char *pathOut, size_t pathOutSize) -{ - const auto findPath = s_pathMap.find(applicationID); - if (findPath == s_pathMap.end()) { return; } - std::memcpy(pathOut, s_pathMap[applicationID].c_str(), s_pathMap[applicationID].length()); -} - -static void read_array_to_vector(std::vector &vector, json_object *array) -{ - // Just in case. Shouldn't happen though. - vector.clear(); - - const size_t arrayLength = json_object_array_length(array); - for (size_t i = 0; i < arrayLength; i++) - { - json_object *arrayEntry = json_object_array_get_idx(array, i); - if (!arrayEntry) { continue; } - vector.push_back(std::strtoull(json_object_get_string(arrayEntry), NULL, 16)); - } -} - -static void save_custom_paths() -{ - json::Object pathsJson = json::new_object(json_object_new_object); - if (!pathsJson) { return; } - - for (const auto &[applicationId, path] : s_pathMap) - { - const std::string titleIdHex = stringutil::get_formatted_string("%016llX", applicationId); - json_object *jsonPath = json_object_new_string(path.c_str()); - - json::add_object(pathsJson, titleIdHex, jsonPath); - } - - const char *jsonString = json_object_get_string(pathsJson.get()); - const int64_t jsonLength = std::char_traits::length(jsonString); - fslib::File pathsFile{PATH_PATHS_PATH, FsOpenMode_Create | FsOpenMode_Write, jsonLength}; - if (error::fslib(pathsFile)) { return; } - - pathsFile << jsonString; -} diff --git a/source/config/ConfigContext.cpp b/source/config/ConfigContext.cpp new file mode 100644 index 0000000..fa12414 --- /dev/null +++ b/source/config/ConfigContext.cpp @@ -0,0 +1,282 @@ +#include "config/ConfigContext.hpp" + +#include "JSON.hpp" +#include "config/keys.hpp" +#include "logging/error.hpp" +#include "stringutil.hpp" + +#include +namespace +{ + constexpr std::string_view PATH_DEFAULT_WORK_DIR = "sdmc:/JKSV"; + constexpr const char *PATH_PATHS_PATH = "sdmc:/config/JKSV/Paths.json"; + constexpr const char *PATH_CONFIG_FILE = "sdmc:/config/JKSV/JKSV.json"; + + constexpr const char *STRING_APP_ID_FORMAT = "%016llX"; +} + +void config::ConfigContext::reset() +{ + m_workingDirectory = PATH_DEFAULT_WORK_DIR; + m_configMap[config::keys::INCLUDE_DEVICE_SAVES.data()] = 0; + m_configMap[config::keys::AUTO_BACKUP_ON_RESTORE.data()] = 1; + m_configMap[config::keys::AUTO_NAME_BACKUPS.data()] = 0; + m_configMap[config::keys::AUTO_UPLOAD.data()] = 0; + m_configMap[config::keys::USE_TITLE_IDS.data()] = 0; + m_configMap[config::keys::HOLD_FOR_DELETION.data()] = 1; + m_configMap[config::keys::HOLD_FOR_RESTORATION.data()] = 1; + m_configMap[config::keys::HOLD_FOR_OVERWRITE.data()] = 1; + m_configMap[config::keys::ONLY_LIST_MOUNTABLE.data()] = 1; + m_configMap[config::keys::LIST_ACCOUNT_SYS_SAVES.data()] = 0; + m_configMap[config::keys::ALLOW_WRITING_TO_SYSTEM.data()] = 0; + m_configMap[config::keys::EXPORT_TO_ZIP.data()] = 1; + m_configMap[config::keys::ZIP_COMPRESSION_LEVEL.data()] = 6; + m_configMap[config::keys::TITLE_SORT_TYPE.data()] = 0; + m_configMap[config::keys::JKSM_TEXT_MODE.data()] = 0; + m_configMap[config::keys::FORCE_ENGLISH.data()] = 0; + m_configMap[config::keys::ENABLE_TRASH_BIN.data()] = 0; + m_animationScaling = 2.5f; +} + +void config::ConfigContext::save() +{ + + json::Object configJSON = json::new_object(json_object_new_object); + if (!configJSON) { return; } + + json_object *workDir = json_object_new_string(m_workingDirectory.full_path()); + json::add_object(configJSON, config::keys::WORKING_DIRECTORY.data(), workDir); + + for (const auto &[key, value] : m_configMap) + { + json_object *valueObject = json_object_new_uint64(value); + json::add_object(configJSON, key.c_str(), valueObject); + } + + json_object *scaling = json_object_new_double(m_animationScaling); + json::add_object(configJSON, config::keys::UI_ANIMATION_SCALE.data(), scaling); + + json_object *favoritesArray = json_object_new_array(); + for (const uint64_t &applicationID : m_favorites) + { + const std::string appIDHex = stringutil::get_formatted_string(STRING_APP_ID_FORMAT, applicationID); + json_object *newFavorite = json_object_new_string(appIDHex.c_str()); + + json_object_array_add(favoritesArray, newFavorite); + } + json::add_object(configJSON, config::keys::FAVORITES.data(), favoritesArray); + + json_object *blacklistArray = json_object_new_array(); + for (const uint64_t &applicationID : m_blacklist) + { + const std::string appIDHex = stringutil::get_formatted_string(STRING_APP_ID_FORMAT, applicationID); + json_object *newBlacklist = json_object_new_string(appIDHex.c_str()); + + json_object_array_add(blacklistArray, newBlacklist); + } + json::add_object(configJSON, config::keys::BLACKLIST.data(), blacklistArray); + + const char *configString = json::get_string(configJSON); + const int64_t configLength = std::char_traits::length(configString); + fslib::File configFile{PATH_CONFIG_FILE, FsOpenMode_Create | FsOpenMode_Write, configLength}; + if (configFile.is_open()) { configFile << configString; } +} + +void config::ConfigContext::load() +{ + json::Object configJSON = json::new_object(json_object_from_file, PATH_CONFIG_FILE); + if (!configJSON) + { + error::fslib(false); // This seems weird, but it should catch the problem. + return; + } + + json_object_iterator configIter = json::iter_begin(configJSON); + json_object_iterator configEnd = json::iter_end(configJSON); + while (!json_object_iter_equal(&configIter, &configEnd)) + { + const char *key = json_object_iter_peek_name(&configIter); + json_object *value = json_object_iter_peek_value(&configIter); + + const bool workingDir = std::strcmp(config::keys::WORKING_DIRECTORY.data(), key) == 0; + const bool scaling = std::strcmp(config::keys::UI_ANIMATION_SCALE.data(), key) == 0; + const bool favorites = std::strcmp(config::keys::FAVORITES.data(), key) == 0; + const bool blacklist = std::strcmp(config::keys::BLACKLIST.data(), key) == 0; + + if (workingDir) { m_workingDirectory = json_object_get_string(value); } + else if (scaling) { m_animationScaling = json_object_get_double(value); } + else if (favorites) { ConfigContext::read_array_to_vector(m_favorites, value); } + else if (blacklist) { ConfigContext::read_array_to_vector(m_blacklist, value); } + else { m_configMap[key] = json_object_get_uint64(value); } + + json_object_iter_next(&configIter); + } + + const fslib::Path pathsPath{PATH_PATHS_PATH}; + const bool pathsExists = fslib::file_exists(pathsPath); + if (!pathsExists) { return; } + + json::Object pathsJSON = json::new_object(json_object_from_file, pathsPath.full_path()); + if (!pathsJSON) + { + error::fslib(false); + return; + } + + json_object_iterator pathsIter = json::iter_begin(configJSON); + json_object_iterator pathsEnd = json::iter_end(configJSON); + while (!json_object_iter_equal(&pathsIter, &pathsEnd)) + { + const char *appIDString = json_object_iter_peek_name(&pathsIter); + json_object *pathObject = json_object_iter_peek_value(&pathsIter); + + const uint64_t applicationID = std::strtoull(appIDString, nullptr, 16); + const char *path = json_object_get_string(pathObject); + m_pathMap[applicationID] = path; + + json_object_iter_next(&pathsIter); + } +} + +uint8_t config::ConfigContext::get_by_key(std::string_view key) +{ + auto findKey = m_configMap.find(key.data()); + if (findKey == m_configMap.end()) { return 0; } + return findKey->second; +} + +void config::ConfigContext::toggle_by_key(std::string_view key) +{ + auto findKey = m_configMap.find(key.data()); + if (findKey == m_configMap.end()) { return; } + findKey->second = findKey->second ? 0 : 1; +} + +void config::ConfigContext::set_by_key(std::string_view key, uint8_t value) +{ + auto findKey = m_configMap.find(key.data()); + if (findKey == m_configMap.end()) { return; } + findKey->second = value; +} + +fslib::Path config::ConfigContext::get_working_directory() const { return m_workingDirectory; } + +bool config::ConfigContext::set_working_directory(std::string_view path) +{ + fslib::Path testPath{path}; + if (!testPath.is_valid()) { return false; } + + m_workingDirectory = std::move(testPath); + return true; +} + +double config::ConfigContext::get_animation_scaling() const { return m_animationScaling; } + +void config::ConfigContext::set_animation_scaling(double scaling) { m_animationScaling = scaling; } + +void config::ConfigContext::add_favorite(uint64_t applicationID) +{ + auto findID = ConfigContext::find_favorite(applicationID); + if (findID != m_favorites.end()) { return; } + m_favorites.push_back(applicationID); +} + +void config::ConfigContext::remove_favorite(uint64_t applicationID) +{ + auto findID = ConfigContext::find_favorite(applicationID); + if (findID == m_favorites.end()) { return; } + m_favorites.erase(findID); +} + +bool config::ConfigContext::is_favorite(uint64_t applicationID) +{ + return ConfigContext::find_favorite(applicationID) != m_favorites.end(); +} + +void config::ConfigContext::add_to_blacklist(uint64_t applicationID) +{ + auto findID = ConfigContext::find_blacklist(applicationID); + if (findID != m_blacklist.end()) { return; } + m_blacklist.push_back(applicationID); +} + +void config::ConfigContext::remove_from_blacklist(uint64_t applicationID) +{ + auto findID = ConfigContext::find_blacklist(applicationID); + if (findID == m_blacklist.end()) { return; } + m_blacklist.erase(findID); +} + +void config::ConfigContext::get_blacklisted_titles(std::vector &listOut) +{ + listOut.clear(); + listOut.assign(m_blacklist.begin(), m_blacklist.end()); +} + +bool config::ConfigContext::is_blacklisted(uint64_t applicationID) +{ + return ConfigContext::find_blacklist(applicationID) != m_blacklist.end(); +} + +bool config::ConfigContext::blacklist_is_empty() const { return m_blacklist.empty(); } + +void config::ConfigContext::add_custom_path(uint64_t applicationID, std::string_view path) +{ + m_pathMap[applicationID] = path.data(); + ConfigContext::save_custom_paths(); +} + +bool config::ConfigContext::has_custom_path(uint64_t applicationID) { return m_pathMap.find(applicationID) != m_pathMap.end(); } + +void config::ConfigContext::get_custom_path(uint64_t applicationID, char *pathBuffer, size_t bufferSize) +{ + if (!ConfigContext::has_custom_path(applicationID)) { return; } + + const std::string &path = m_pathMap[applicationID]; + if (path.length() > bufferSize) { return; } + + std::memset(pathBuffer, 0x00, bufferSize); + std::memcpy(pathBuffer, path.c_str(), path.length()); +} + +void config::ConfigContext::read_array_to_vector(std::vector &vector, json_object *array) +{ + const int arrayLength = json_object_array_length(array); + for (int i = 0; i < arrayLength; i++) + { + json_object *arrayElement = json_object_array_get_idx(array, i); + if (!arrayElement) { break; } + + const char *appIDStr = json_object_get_string(arrayElement); + const uint64_t applicationID = std::strtoull(appIDStr, nullptr, 16); + vector.push_back(applicationID); + } +} + +void config::ConfigContext::save_custom_paths() +{ + json::Object pathsJSON = json::new_object(json_object_new_object); + for (auto &[applicationID, outputPath] : m_pathMap) + { + const std::string appIDHex = stringutil::get_formatted_string(STRING_APP_ID_FORMAT, applicationID); + const char *path = outputPath.c_str(); + + json_object *outputString = json_object_new_string(path); + json::add_object(pathsJSON, appIDHex, outputString); + } + + const char *pathsString = json::get_string(pathsJSON); + const int64_t pathsLength = std::char_traits::length(pathsString); + fslib::File pathsFile{PATH_PATHS_PATH, FsOpenMode_Create | FsOpenMode_Write, pathsLength}; + if (pathsFile.is_open()) { pathsFile << pathsString; }; +} + +config::ConfigContext::AppIDList::iterator config::ConfigContext::find_favorite(uint64_t applicationID) +{ + return std::find(m_favorites.begin(), m_favorites.end(), applicationID); +} + +config::ConfigContext::AppIDList::iterator config::ConfigContext::find_blacklist(uint64_t applicationID) +{ + return std::find(m_blacklist.begin(), m_blacklist.end(), applicationID); +} diff --git a/source/config/config.cpp b/source/config/config.cpp new file mode 100644 index 0000000..828c92b --- /dev/null +++ b/source/config/config.cpp @@ -0,0 +1,88 @@ +#include "config/config.hpp" + +#include "config/ConfigContext.hpp" +#include "logging/error.hpp" + +namespace +{ + config::ConfigContext s_context{}; + + constexpr std::string_view PATH_CONFIG_FOLDER = "sdmc:/config/JKSV"; + constexpr const char *PATH_CONFIG_FILE = "sdmc:/config/JKSV/JKSV.json"; +} // namespace + +void config::initialize() +{ + // This is so we don't constantly construct new Paths + const fslib::Path configDir{PATH_CONFIG_FOLDER}; + const fslib::Path configFile{PATH_CONFIG_FILE}; + + const bool configDirExists = fslib::directory_exists(configDir); + const bool configDirError = !configDirExists && error::fslib(fslib::create_directories_recursively(configDir)); + if (!configDirExists && configDirError) + { + s_context.reset(); + return; + } + + const bool configExists = fslib::file_exists(configFile); + if (!configExists) + { + s_context.reset(); + return; + } + + s_context.load(); +} + +void config::reset_to_default() { s_context.reset(); } + +void config::save() { s_context.save(); } + +uint8_t config::get_by_key(std::string_view key) { return s_context.get_by_key(key); } + +void config::toggle_by_key(std::string_view key) { s_context.toggle_by_key(key); } + +void config::set_by_key(std::string_view key, uint8_t value) { s_context.set_by_key(key, value); } + +fslib::Path config::get_working_directory() { return s_context.get_working_directory(); } + +bool config::set_working_directory(std::string_view path) { return s_context.set_working_directory(path); } + +double config::get_animation_scaling() { return s_context.get_animation_scaling(); } + +void config::set_animation_scaling(double newScale) { s_context.set_animation_scaling(newScale); } + +void config::add_remove_favorite(uint64_t applicationID) +{ + if (s_context.is_favorite(applicationID)) { s_context.remove_favorite(applicationID); } + else { s_context.add_favorite(applicationID); } + s_context.save(); +} + +bool config::is_favorite(uint64_t applicationID) { return s_context.is_favorite(applicationID); } + +void config::add_remove_blacklist(uint64_t applicationID) +{ + if (s_context.is_blacklisted(applicationID)) { s_context.remove_from_blacklist(applicationID); } + else { s_context.add_to_blacklist(applicationID); } + s_context.save(); +} + +void config::get_blacklisted_titles(std::vector &listOut) { s_context.get_blacklisted_titles(listOut); } + +bool config::is_blacklisted(uint64_t applicationID) { return s_context.is_blacklisted(applicationID); } + +bool config::blacklist_is_empty() { return s_context.blacklist_is_empty(); } + +void config::add_custom_path(uint64_t applicationID, std::string_view customPath) +{ + s_context.add_custom_path(applicationID, customPath); +} + +bool config::has_custom_path(uint64_t applicationID) { return s_context.has_custom_path(applicationID); } + +void config::get_custom_path(uint64_t applicationID, char *pathOut, size_t pathOutSize) +{ + s_context.get_custom_path(applicationID, pathOut, pathOutSize); +} diff --git a/source/curl/curl.cpp b/source/curl/curl.cpp index 0cf663e..25c1bb7 100644 --- a/source/curl/curl.cpp +++ b/source/curl/curl.cpp @@ -1,7 +1,7 @@ #include "curl/curl.hpp" -#include "error.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "stringutil.hpp" #include diff --git a/source/data/DataContext.cpp b/source/data/DataContext.cpp index a929deb..e2450d1 100644 --- a/source/data/DataContext.cpp +++ b/source/data/DataContext.cpp @@ -1,10 +1,10 @@ #include "data/DataContext.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/fs.hpp" -#include "logger.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" namespace @@ -152,8 +152,9 @@ void data::DataContext::get_title_info_list_by_type(FsSaveDataType type, data::T void data::DataContext::import_svi_files(sys::Task *task) { + static constexpr size_t SIZE_UINT32 = sizeof(uint32_t); static constexpr size_t SIZE_UINT64 = sizeof(uint64_t); - static constexpr size_t SIZE_SVI = SIZE_UINT64 + SIZE_CTRL_DATA; + static constexpr size_t SIZE_SVI = SIZE_UINT32 + SIZE_UINT64 + SIZE_CTRL_DATA; if (error::is_null(task)) { return; } @@ -174,11 +175,13 @@ void data::DataContext::import_svi_files(sys::Task *task) const bool goodSvi = sviFile.is_open() && sviFile.get_size() == SIZE_SVI; if (!goodSvi) { continue; } + uint32_t magic{}; uint64_t applicationID{}; - auto controlData = std::make_unique(); - const bool idRead = sviFile.read(&applicationID, SIZE_UINT64) == SIZE_UINT64; - const bool dataRead = sviFile.read(controlData.get(), SIZE_CTRL_DATA) == SIZE_CTRL_DATA; - if (!idRead || !dataRead) { continue; } + auto controlData = std::make_unique(); + const bool magicRead = sviFile.read(&magic, SIZE_UINT32) == SIZE_UINT32; + const bool idRead = sviFile.read(&applicationID, SIZE_UINT64) == SIZE_UINT64; + const bool dataRead = sviFile.read(controlData.get(), SIZE_CTRL_DATA) == SIZE_CTRL_DATA; + if (!magicRead || magic != fs::SAVE_META_MAGIC || !idRead || !dataRead) { continue; } const bool exists = DataContext::title_is_loaded(applicationID); if (exists) { continue; } diff --git a/source/data/TitleInfo.cpp b/source/data/TitleInfo.cpp index ac72539..19b7701 100644 --- a/source/data/TitleInfo.cpp +++ b/source/data/TitleInfo.cpp @@ -1,10 +1,10 @@ #include "data/TitleInfo.hpp" -#include "colors.hpp" -#include "config.hpp" -#include "error.hpp" -#include "gfxutil.hpp" -#include "logger.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" +#include "graphics/gfxutil.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "stringutil.hpp" #include @@ -215,7 +215,7 @@ void data::TitleInfo::load_icon() if (m_hasData) { const std::string textureName = stringutil::get_formatted_string("%016llX", m_applicationID); - m_icon = sdl::TextureManager::create_load_texture(textureName, m_data->icon, SIZE_ICON); + m_icon = sdl::TextureManager::load(textureName, m_data->icon, SIZE_ICON); } else { diff --git a/source/data/User.cpp b/source/data/User.cpp index 0b0b1da..c6b1ccd 100644 --- a/source/data/User.cpp +++ b/source/data/User.cpp @@ -1,12 +1,12 @@ #include "data/User.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fs/fs.hpp" -#include "gfxutil.hpp" -#include "logger.hpp" +#include "graphics/colors.hpp" +#include "graphics/gfxutil.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "sdl.hpp" #include "stringutil.hpp" @@ -221,7 +221,7 @@ void data::User::load_icon() if (loadError) { return; } accountProfileClose(&profile); - m_icon = sdl::TextureManager::create_load_texture(m_nickname, iconBuffer.get(), iconSize); + m_icon = sdl::TextureManager::load(m_nickname, iconBuffer.get(), iconSize); } else { m_icon = gfxutil::create_generic_icon(m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE); } } diff --git a/source/data/data.cpp b/source/data/data.cpp index 97e7cf6..e3819ec 100644 --- a/source/data/data.cpp +++ b/source/data/data.cpp @@ -2,8 +2,8 @@ #include "appstates/DataLoadingState.hpp" #include "data/DataContext.hpp" -#include "error.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "strings/strings.hpp" #include @@ -44,6 +44,7 @@ static void data_initialize_task(sys::Task *task, bool clearCache) if (clearCache) { s_context.delete_cache(); } s_context.read_cache(task); s_context.load_application_records(task); + s_context.import_svi_files(task); s_context.load_create_users(task); s_context.load_user_save_info(task); s_context.write_cache(task); diff --git a/source/fs/MiniUnzip.cpp b/source/fs/MiniUnzip.cpp index 2bd79fb..0b2df73 100644 --- a/source/fs/MiniUnzip.cpp +++ b/source/fs/MiniUnzip.cpp @@ -1,7 +1,7 @@ #include "fs/MiniUnzip.hpp" -#include "error.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" fs::MiniUnzip::MiniUnzip(const fslib::Path &path) { MiniUnzip::open(path); } diff --git a/source/fs/MiniZip.cpp b/source/fs/MiniZip.cpp index 27fcc90..fa15251 100644 --- a/source/fs/MiniZip.cpp +++ b/source/fs/MiniZip.cpp @@ -1,7 +1,7 @@ #include "fs/MiniZip.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" +#include "logging/error.hpp" #include diff --git a/source/fs/PathFilter.cpp b/source/fs/PathFilter.cpp new file mode 100644 index 0000000..844b246 --- /dev/null +++ b/source/fs/PathFilter.cpp @@ -0,0 +1,29 @@ +#include "fs/PathFilter.hpp" + +#include "JSON.hpp" + +fs::PathFilter::PathFilter(const fslib::Path &filePath) +{ + json::Object filterJSON = json::new_object(json_object_from_file, filePath.full_path()); + if (!filterJSON) { return; } + + json_object *filter = json::get_object(filterJSON, "filters"); + if (!filter) { return; } + + const size_t arrayLength = json_object_array_length(filter); + for (size_t i = 0; i < arrayLength; i++) + { + json_object *pathObject = json_object_array_get_idx(filter, i); + if (!pathObject) { break; } + + const char *path = json_object_get_string(pathObject); + m_paths.emplace_back(path); + } +} + +bool fs::PathFilter::has_paths() const { return !m_paths.empty(); } + +bool fs::PathFilter::is_filtered(const fslib::Path &path) +{ + return std::find(m_paths.begin(), m_paths.end(), path.full_path()) != m_paths.end(); +} diff --git a/source/fs/SaveMetaData.cpp b/source/fs/SaveMetaData.cpp index f410321..2f13482 100644 --- a/source/fs/SaveMetaData.cpp +++ b/source/fs/SaveMetaData.cpp @@ -1,10 +1,10 @@ #include "fs/SaveMetaData.hpp" -#include "error.hpp" #include "fs/directory_functions.hpp" #include "fs/save_data_functions.hpp" #include "fs/save_mount.hpp" #include "fslib.hpp" +#include "logging/error.hpp" namespace { diff --git a/source/fs/ScopedSaveMount.cpp b/source/fs/ScopedSaveMount.cpp index 7bb6cd5..702fe32 100644 --- a/source/fs/ScopedSaveMount.cpp +++ b/source/fs/ScopedSaveMount.cpp @@ -1,7 +1,7 @@ #include "fs/ScopedSaveMount.hpp" -#include "error.hpp" #include "fslib.hpp" +#include "logging/error.hpp" fs::ScopedSaveMount::ScopedSaveMount(std::string_view mount, const FsSaveDataInfo *saveInfo, bool log) : m_mountPoint(mount) diff --git a/source/fs/io.cpp b/source/fs/io.cpp index c5accf4..69505c9 100644 --- a/source/fs/io.cpp +++ b/source/fs/io.cpp @@ -1,9 +1,9 @@ #include "fs/io.hpp" -#include "error.hpp" #include "fs/SaveMetaData.hpp" #include "fslib.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/fs/save_data_functions.cpp b/source/fs/save_data_functions.cpp index 2296f48..801eab1 100644 --- a/source/fs/save_data_functions.cpp +++ b/source/fs/save_data_functions.cpp @@ -1,7 +1,7 @@ #include "fs/save_data_functions.hpp" -#include "error.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" bool fs::create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo) { diff --git a/source/fs/zip.cpp b/source/fs/zip.cpp index b461257..917fb2b 100644 --- a/source/fs/zip.cpp +++ b/source/fs/zip.cpp @@ -1,10 +1,10 @@ #include "fs/zip.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/SaveMetaData.hpp" -#include "logger.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "sys/sys.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/gfxutil.cpp b/source/gfxutil.cpp index 7ab0ad4..6d6d68e 100644 --- a/source/gfxutil.cpp +++ b/source/gfxutil.cpp @@ -1,4 +1,4 @@ -#include "gfxutil.hpp" +#include "graphics/gfxutil.hpp" namespace { @@ -15,7 +15,7 @@ sdl::SharedTexture gfxutil::create_generic_icon(std::string_view text, sdl::Color foreground) { // Create base icon texture. - sdl::SharedTexture icon = sdl::TextureManager::create_load_texture(text, 256, 256, SDL_TEXTUREACCESS_TARGET); + sdl::SharedTexture icon = sdl::TextureManager::load(text, 256, 256, SDL_TEXTUREACCESS_TARGET); // Get the centered X and Y coordinates. const int textX = (SIZE_ICON_WIDTH / 2) - (sdl::text::get_width(fontSize, text) / 2); diff --git a/source/keyboard.cpp b/source/keyboard.cpp index b8021ec..184a367 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -1,6 +1,6 @@ #include "keyboard.hpp" -#include "error.hpp" +#include "logging/error.hpp" #include diff --git a/source/error.cpp b/source/logging/error.cpp similarity index 96% rename from source/error.cpp rename to source/logging/error.cpp index 26c315a..bc61c8d 100644 --- a/source/error.cpp +++ b/source/logging/error.cpp @@ -1,7 +1,7 @@ -#include "error.hpp" +#include "logging/error.hpp" #include "fslib.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include #include diff --git a/source/logger.cpp b/source/logging/logger.cpp similarity index 95% rename from source/logger.cpp rename to source/logging/logger.cpp index 5b6cf1f..0b4c1af 100644 --- a/source/logger.cpp +++ b/source/logging/logger.cpp @@ -1,6 +1,6 @@ -#include "logger.hpp" +#include "logging/logger.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "fslib.hpp" #include diff --git a/source/main.cpp b/source/main.cpp index b2f5a7b..4642d45 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,5 +1,4 @@ #include "JKSV.hpp" -#include "config.hpp" #include diff --git a/source/remote/GoogleDrive.cpp b/source/remote/GoogleDrive.cpp index 93a8a45..b46a80d 100644 --- a/source/remote/GoogleDrive.cpp +++ b/source/remote/GoogleDrive.cpp @@ -1,10 +1,10 @@ #include "remote/GoogleDrive.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include "remote/Form.hpp" #include "remote/URL.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include diff --git a/source/remote/Item.cpp b/source/remote/Item.cpp index 216d548..045c412 100644 --- a/source/remote/Item.cpp +++ b/source/remote/Item.cpp @@ -1,6 +1,6 @@ #include "remote/Item.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" remote::Item::Item(std::string_view name, std::string_view id, std::string_view parent, size_t size, bool directory) : m_name{name} diff --git a/source/remote/Storage.cpp b/source/remote/Storage.cpp index 948396d..89516d8 100644 --- a/source/remote/Storage.cpp +++ b/source/remote/Storage.cpp @@ -1,6 +1,6 @@ #include "remote/Storage.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include #include diff --git a/source/remote/WebDav.cpp b/source/remote/WebDav.cpp index 4f2b24c..e157f41 100644 --- a/source/remote/WebDav.cpp +++ b/source/remote/WebDav.cpp @@ -2,10 +2,10 @@ #include "JSON.hpp" #include "curl/curl.hpp" -#include "error.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp index fef7570..51daac2 100644 --- a/source/remote/remote.cpp +++ b/source/remote/remote.cpp @@ -2,11 +2,11 @@ #include "StateManager.hpp" #include "appstates/TaskState.hpp" -#include "error.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/GoogleDrive.hpp" #include "remote/WebDav.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "ui/PopMessageManager.hpp" #include diff --git a/source/strings.cpp b/source/strings.cpp index 31df92e..b879941 100644 --- a/source/strings.cpp +++ b/source/strings.cpp @@ -1,8 +1,8 @@ -#include "strings.hpp" +#include "strings/strings.hpp" #include "JSON.hpp" -#include "error.hpp" #include "fslib.hpp" +#include "logging/error.hpp" #include "stringutil.hpp" #include @@ -44,8 +44,8 @@ bool strings::initialize() json::Object stringJSON = json::new_object(json_object_from_file, filePath.full_path()); if (!stringJSON) { return false; } - json_object_iterator stringIterator = json_object_iter_begin(stringJSON.get()); - json_object_iterator stringEnd = json_object_iter_end(stringJSON.get()); + json_object_iterator stringIterator = json::iter_begin(stringJSON); + json_object_iterator stringEnd = json::iter_end(stringJSON); while (!json_object_iter_equal(&stringIterator, &stringEnd)) { // Get name of string(s) and pointer to array diff --git a/source/sys/Task.cpp b/source/sys/Task.cpp index 3fe44de..572e567 100644 --- a/source/sys/Task.cpp +++ b/source/sys/Task.cpp @@ -1,6 +1,6 @@ #include "sys/Task.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" sys::Task::~Task() { m_thread.join(); } diff --git a/source/sys/Timer.cpp b/source/sys/Timer.cpp index f23a776..65b3148 100644 --- a/source/sys/Timer.cpp +++ b/source/sys/Timer.cpp @@ -1,6 +1,6 @@ #include "sys/Timer.hpp" -#include "logger.hpp" +#include "logging/logger.hpp" #include diff --git a/source/tasks/backup.cpp b/source/tasks/backup.cpp index ee58504..68d483b 100644 --- a/source/tasks/backup.cpp +++ b/source/tasks/backup.cpp @@ -1,11 +1,11 @@ #include "tasks/backup.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/fs.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/tasks/mainmenu.cpp b/source/tasks/mainmenu.cpp index 1b2bb6a..7985772 100644 --- a/source/tasks/mainmenu.cpp +++ b/source/tasks/mainmenu.cpp @@ -1,9 +1,9 @@ #include "tasks/mainmenu.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fs/fs.hpp" +#include "logging/error.hpp" #include "remote/remote.hpp" #include "stringutil.hpp" #include "tasks/backup.hpp" diff --git a/source/tasks/savecreate.cpp b/source/tasks/savecreate.cpp index c7095a7..1039ab7 100644 --- a/source/tasks/savecreate.cpp +++ b/source/tasks/savecreate.cpp @@ -1,8 +1,8 @@ #include "tasks/savecreate.hpp" -#include "error.hpp" #include "fs/fs.hpp" -#include "strings.hpp" +#include "logging/error.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/PopMessageManager.hpp" diff --git a/source/tasks/titleoptions.cpp b/source/tasks/titleoptions.cpp index c1fde69..79e16fc 100644 --- a/source/tasks/titleoptions.cpp +++ b/source/tasks/titleoptions.cpp @@ -1,13 +1,13 @@ #include "tasks/titleoptions.hpp" -#include "config.hpp" +#include "config/config.hpp" #include "data/data.hpp" -#include "error.hpp" #include "fs/fs.hpp" #include "keyboard.hpp" -#include "logger.hpp" +#include "logging/error.hpp" +#include "logging/logger.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "ui/ui.hpp" diff --git a/source/tasks/useroptions.cpp b/source/tasks/useroptions.cpp index 1b315e6..6f9cd90 100644 --- a/source/tasks/useroptions.cpp +++ b/source/tasks/useroptions.cpp @@ -1,10 +1,10 @@ #include "tasks/useroptions.hpp" -#include "config.hpp" -#include "error.hpp" +#include "config/config.hpp" #include "fs/fs.hpp" +#include "logging/error.hpp" #include "remote/remote.hpp" -#include "strings.hpp" +#include "strings/strings.hpp" #include "stringutil.hpp" #include "tasks/backup.hpp" #include "ui/ui.hpp" diff --git a/source/ui/BoundingBox.cpp b/source/ui/BoundingBox.cpp index ea7bc2d..71c4ebd 100644 --- a/source/ui/BoundingBox.cpp +++ b/source/ui/BoundingBox.cpp @@ -18,11 +18,6 @@ ui::BoundingBox::BoundingBox(int x, int y, int width, int height) BoundingBox::initialize_static_members(); } -std::shared_ptr ui::BoundingBox::create(int x, int y, int width, int height) -{ - return std::make_shared(x, y, width, height); -} - void ui::BoundingBox::update(bool hasFocus) { m_colorMod.update(); } void ui::BoundingBox::render(sdl::SharedTexture &target, bool hasFocus) @@ -66,5 +61,5 @@ void ui::BoundingBox::set_width_height(int width, int height) void ui::BoundingBox::initialize_static_members() { if (sm_corners) { return; } - sm_corners = sdl::TextureManager::create_load_texture("menuCorners", "romfs:/Textures/MenuBounding.png"); + sm_corners = sdl::TextureManager::load("menuCorners", "romfs:/Textures/MenuBounding.png"); } diff --git a/source/ui/DialogBox.cpp b/source/ui/DialogBox.cpp index 2911df6..fb454e0 100644 --- a/source/ui/DialogBox.cpp +++ b/source/ui/DialogBox.cpp @@ -1,6 +1,6 @@ #include "ui/DialogBox.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" namespace { @@ -18,11 +18,6 @@ ui::DialogBox::DialogBox(int x, int y, int width, int height, ui::DialogBox::Typ ui::DialogBox::initialize_static_members(); } -std::shared_ptr ui::DialogBox::create(int x, int y, int width, int height, ui::DialogBox::Type type) -{ - return std::make_shared(x, y, width, height, type); -} - void ui::DialogBox::render(sdl::SharedTexture &target, bool hasFocus) { const bool darkDialog = m_type == DialogBox::Type::Dark; @@ -70,6 +65,6 @@ void ui::DialogBox::initialize_static_members() { if (sm_darkCorners && sm_lightCorners) { return; } - sm_darkCorners = sdl::TextureManager::create_load_texture("darkCorners", "romfs:/Textures/DialogCornersDark.png"); - sm_lightCorners = sdl::TextureManager::create_load_texture("lightCorners", "romfs:/Textures/DialogCornersLight.png"); + sm_darkCorners = sdl::TextureManager::load("darkCorners", "romfs:/Textures/DialogCornersDark.png"); + sm_lightCorners = sdl::TextureManager::load("lightCorners", "romfs:/Textures/DialogCornersLight.png"); } diff --git a/source/ui/IconMenu.cpp b/source/ui/IconMenu.cpp index 95a9f76..b1d27fc 100644 --- a/source/ui/IconMenu.cpp +++ b/source/ui/IconMenu.cpp @@ -1,6 +1,6 @@ #include "ui/IconMenu.hpp" -#include "colors.hpp" +#include "graphics/colors.hpp" namespace { @@ -18,11 +18,6 @@ ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight) m_boundingBox->set_width_height(152, 146); } -std::shared_ptr ui::IconMenu::create(int x, int y, int renderTargetHeight) -{ - return std::make_shared(x, y, renderTargetHeight); -} - void ui::IconMenu::update(bool hasFocus) { Menu::update(hasFocus); } void ui::IconMenu::render(sdl::SharedTexture &target, bool hasFocus) diff --git a/source/ui/Menu.cpp b/source/ui/Menu.cpp index 171a4a2..144eceb 100644 --- a/source/ui/Menu.cpp +++ b/source/ui/Menu.cpp @@ -1,7 +1,7 @@ #include "ui/Menu.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "input.hpp" #include "mathutil.hpp" #include "ui/BoundingBox.hpp" @@ -19,13 +19,12 @@ ui::Menu::Menu(int x, int y, int width, int fontSize, int renderTargetHeight) , m_textY((m_optionHeight / 2) - (m_fontSize / 2)) // This seems to be the best alignment. , m_renderTargetHeight(renderTargetHeight) , m_optionScroll( - ui::TextScroll::create("temp", 16, 0, m_width, m_optionHeight, m_fontSize, colors::BLUE_GREEN, colors::TRANSPARENT)) + ui::TextScroll::create("", 16, 0, m_width, m_optionHeight, m_fontSize, colors::BLUE_GREEN, colors::TRANSPARENT)) { // Create render target for options static int MENU_ID = 0; std::string menuTargetName = "MENU_" + std::to_string(MENU_ID++); - m_optionTarget = - sdl::TextureManager::create_load_texture(menuTargetName, m_width, m_optionHeight, SDL_TEXTUREACCESS_TARGET); + m_optionTarget = sdl::TextureManager::load(menuTargetName, m_width, m_optionHeight, SDL_TEXTUREACCESS_TARGET); // Outside the initializer list because I'm tired and don't wanna deal with the headache. m_boundingBox = ui::BoundingBox::create(0, 0, m_width + 12, m_optionHeight + 12); @@ -35,11 +34,6 @@ ui::Menu::Menu(int x, int y, int width, int fontSize, int renderTargetHeight) m_scrollLength = std::floor(static_cast(m_maxDisplayOptions) / 2.0f); } -std::shared_ptr ui::Menu::create(int x, int y, int width, int fontSize, int renderTargetHeight) -{ - return std::make_shared(x, y, width, fontSize, renderTargetHeight); -} - void ui::Menu::update(bool hasFocus) { if (m_options.empty()) { return; } diff --git a/source/ui/PopMessage.cpp b/source/ui/PopMessage.cpp index 39a856e..c0b550c 100644 --- a/source/ui/PopMessage.cpp +++ b/source/ui/PopMessage.cpp @@ -1,7 +1,7 @@ #include "ui/PopMessage.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "mathutil.hpp" #include "sdl.hpp" diff --git a/source/ui/PopMessageManager.cpp b/source/ui/PopMessageManager.cpp index 26d11f1..c2001eb 100644 --- a/source/ui/PopMessageManager.cpp +++ b/source/ui/PopMessageManager.cpp @@ -1,8 +1,8 @@ #include "ui/PopMessageManager.hpp" -#include "colors.hpp" -#include "config.hpp" -#include "logger.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" +#include "logging/logger.hpp" #include "sdl.hpp" #include "ui/PopMessage.hpp" diff --git a/source/ui/SlideOutPanel.cpp b/source/ui/SlideOutPanel.cpp index 9c0ff46..442b5b4 100644 --- a/source/ui/SlideOutPanel.cpp +++ b/source/ui/SlideOutPanel.cpp @@ -1,7 +1,7 @@ #include "ui/SlideOutPanel.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "mathutil.hpp" #include @@ -20,7 +20,7 @@ ui::SlideOutPanel::SlideOutPanel(int width, Side side) { static int targetID = 0; std::string targetName = "panelTarget_" + std::to_string(targetID++); - m_renderTarget = sdl::TextureManager::create_load_texture(targetName, width, 720, SDL_TEXTUREACCESS_TARGET); + m_renderTarget = sdl::TextureManager::load(targetName, width, 720, SDL_TEXTUREACCESS_TARGET); } void ui::SlideOutPanel::update(bool hasFocus) diff --git a/source/ui/TextScroll.cpp b/source/ui/TextScroll.cpp index 012bbcc..f0271db 100644 --- a/source/ui/TextScroll.cpp +++ b/source/ui/TextScroll.cpp @@ -24,19 +24,6 @@ ui::TextScroll::TextScroll(std::string_view text, TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center); } -std::shared_ptr ui::TextScroll::create(std::string_view text, - int x, - int y, - int width, - int height, - int fontSize, - sdl::Color textColor, - sdl::Color clearColor, - bool center) -{ - return std::make_shared(text, x, y, width, height, fontSize, textColor, clearColor, center); -} - void ui::TextScroll::initialize(std::string_view text, int x, int y, @@ -61,8 +48,7 @@ void ui::TextScroll::initialize(std::string_view text, { const std::string targetName = "textScroll_" + std::to_string(TARGET_ID++); - m_renderTarget = - sdl::TextureManager::create_load_texture(targetName, m_targetWidth, m_targetHeight, SDL_TEXTUREACCESS_TARGET); + m_renderTarget = sdl::TextureManager::load(targetName, m_targetWidth, m_targetHeight, SDL_TEXTUREACCESS_TARGET); } TextScroll::set_text(text, center); diff --git a/source/ui/TitleTile.cpp b/source/ui/TitleTile.cpp index 3be004d..d1c082b 100644 --- a/source/ui/TitleTile.cpp +++ b/source/ui/TitleTile.cpp @@ -1,7 +1,7 @@ #include "ui/TitleTile.hpp" -#include "colors.hpp" -#include "logger.hpp" +#include "graphics/colors.hpp" +#include "logging/logger.hpp" ui::TitleTile::TitleTile(bool isFavorite, int index, sdl::SharedTexture icon) : m_isFavorite(isFavorite) diff --git a/source/ui/TitleView.cpp b/source/ui/TitleView.cpp index 9caa59d..3ffe786 100644 --- a/source/ui/TitleView.cpp +++ b/source/ui/TitleView.cpp @@ -1,8 +1,9 @@ #include "ui/TitleView.hpp" -#include "colors.hpp" -#include "config.hpp" +#include "config/config.hpp" +#include "graphics/colors.hpp" #include "input.hpp" +#include "logging/logger.hpp" #include