From 01262e88c99e20cfd3e57b20feabcb42c10d3161 Mon Sep 17 00:00:00 2001 From: XorTroll Date: Sat, 16 Sep 2023 17:42:45 +0200 Subject: [PATCH] Support moving back entries in menu, other minor fixes --- libs/uCommon/include/ul/menu/menu_Entries.hpp | 2 + libs/uCommon/source/ul/menu/menu_Entries.cpp | 34 ++++++- .../include/ul/man/ui/ui_MainMenuLayout.hpp | 4 + projects/uManager/romfs/lang/en-US.json | 10 +- projects/uManager/source/main.cpp | 2 + .../source/ul/man/ui/ui_MainMenuLayout.cpp | 37 ++++++++ projects/uMenu/romfs/lang/en-US.json | 6 ++ .../source/ul/menu/ui/ui_MainMenuLayout.cpp | 91 ++++++++++++++----- 8 files changed, 159 insertions(+), 27 deletions(-) diff --git a/libs/uCommon/include/ul/menu/menu_Entries.hpp b/libs/uCommon/include/ul/menu/menu_Entries.hpp index b76fd70e..5b3d43cc 100644 --- a/libs/uCommon/include/ul/menu/menu_Entries.hpp +++ b/libs/uCommon/include/ul/menu/menu_Entries.hpp @@ -92,6 +92,8 @@ namespace ul::menu { void ReloadApplicationInfo(); void MoveTo(const std::string &new_folder_path); + void MoveToParentFolder(); + void MoveToRoot(); void Save() const; void Remove(); diff --git a/libs/uCommon/source/ul/menu/menu_Entries.cpp b/libs/uCommon/source/ul/menu/menu_Entries.cpp index 71701b38..9a9e854d 100644 --- a/libs/uCommon/source/ul/menu/menu_Entries.cpp +++ b/libs/uCommon/source/ul/menu/menu_Entries.cpp @@ -294,6 +294,25 @@ namespace ul::menu { this->entry_path = new_entry_path; } + void Entry::MoveToParentFolder() { + // Note: not moving the folder's actual fs folder (for folder entries) to avoid messy logic, this should work just fine + + const auto cur_folder_path = fs::GetBaseDirectory(this->entry_path); + const auto cur_parent_folder_path = fs::GetBaseDirectory(cur_folder_path); + + const auto new_entry_path = fs::JoinPath(cur_parent_folder_path, fs::GetBaseName(this->entry_path)); + fs::RenameFile(this->entry_path, new_entry_path); + this->entry_path = new_entry_path; + } + + void Entry::MoveToRoot() { + // Note: not moving the folder's actual fs folder (for folder entries) to avoid messy logic, this should work just fine + + const auto new_entry_path = fs::JoinPath(MenuPath, fs::GetBaseName(this->entry_path)); + fs::RenameFile(this->entry_path, new_entry_path); + this->entry_path = new_entry_path; + } + void Entry::Save() const { auto entry_json = util::JSON::object(); entry_json["type"] = static_cast(this->type); @@ -503,7 +522,15 @@ namespace ul::menu { if(i < (entries.size() - 1)) { auto &next_entry = entries.at(i + 1); - if((next_entry.index - cur_entry.index) == 1) { + if(next_entry.index == (cur_entry.index + 1)) { + needs_reindexing = true; + break; + } + if(cur_entry.index == (next_entry.index + 1)) { + needs_reindexing = true; + break; + } + if(next_entry.index == cur_entry.index) { needs_reindexing = true; break; } @@ -511,13 +538,14 @@ namespace ul::menu { } if(needs_reindexing) { + UL_LOG_INFO("Reindexing entries at '%s'...", path.c_str()); const auto index_gap = UINT32_MAX / entries.size(); u32 cur_start_idx = 0; for(auto &entry : entries) { entry.Remove(); - u32 new_idx; - entry.entry_path = AllocateEntryPath(cur_start_idx, cur_start_idx + index_gap, path, new_idx); + const auto new_idx = cur_start_idx + index_gap / 2; + entry.entry_path = MakeEntryPath(path, new_idx); entry.index = new_idx; entry.Save(); cur_start_idx += index_gap; diff --git a/projects/uManager/include/ul/man/ui/ui_MainMenuLayout.hpp b/projects/uManager/include/ul/man/ui/ui_MainMenuLayout.hpp index f84c63f4..a2f098a9 100644 --- a/projects/uManager/include/ul/man/ui/ui_MainMenuLayout.hpp +++ b/projects/uManager/include/ul/man/ui/ui_MainMenuLayout.hpp @@ -13,6 +13,8 @@ namespace ul::man::ui { pu::ui::elm::Menu::Ref options_menu; pu::ui::elm::MenuItem::Ref activate_menu_item; + pu::ui::elm::MenuItem::Ref reset_menu_menu_item; + pu::ui::elm::MenuItem::Ref reset_cache_menu_item; pu::ui::elm::MenuItem::Ref update_menu_item; inline void ResetInfoText() { @@ -24,6 +26,8 @@ namespace ul::man::ui { PU_SMART_CTOR(MainMenuLayout) void activate_DefaultKey(); + void resetMenu_DefaultKey(); + void resetCache_DefaultKey(); void update_DefaultKey(); }; diff --git a/projects/uManager/romfs/lang/en-US.json b/projects/uManager/romfs/lang/en-US.json index 38993484..a850bb33 100644 --- a/projects/uManager/romfs/lang/en-US.json +++ b/projects/uManager/romfs/lang/en-US.json @@ -7,11 +7,19 @@ "status_active": "active", "status_not_active": "not active", "status_not_present": "not present", - "update_item": "Check for updates", "activate_changes_title": "Changes", "activate_changes": "The (de)activation of uLaunch needs a reboot for changes to take effect.", "activate_continue": "Continue", "activate_not_present": "uLaunch was not found in the SD card.", + "reset_menu_item": "Reset menu entries", + "reset_menu_title": "Reset menu", + "reset_menu_conf": "This will reset all the menu entries to default.\nAre you sure you want to continue?", + "reset_menu_success": "Menu entries were successfully reset.", + "reset_cache_item": "Reset menu cache", + "reset_cache_title": "Reset menu cache", + "reset_cache_conf": "This will reset all the menu cache (app/homebrew/user images, etc.).\nAre you sure you want to continue?", + "reset_cache_success": "Menu cache was successfully reset.", + "update_item": "Check for updates", "update_title": "Update check", "update_error": "Unable to retrieve last update information...", "update_version": "Last release", diff --git a/projects/uManager/source/main.cpp b/projects/uManager/source/main.cpp index a75f9e25..ed2ef561 100644 --- a/projects/uManager/source/main.cpp +++ b/projects/uManager/source/main.cpp @@ -5,6 +5,7 @@ ul::man::ui::MainApplication::Ref g_MainApplication; int main() { ul::InitializeLogging("uManager"); + UL_RC_ASSERT(nsInitialize()); auto renderer_opts = pu::ui::render::RendererInitOptions(SDL_INIT_EVERYTHING, pu::ui::render::RendererHardwareFlags); renderer_opts.UseImage(pu::ui::render::IMGAllFlags); @@ -17,5 +18,6 @@ int main() { g_MainApplication->Prepare(); g_MainApplication->ShowWithFadeIn(); + nsExit(); return 0; } \ No newline at end of file diff --git a/projects/uManager/source/ul/man/ui/ui_MainMenuLayout.cpp b/projects/uManager/source/ul/man/ui/ui_MainMenuLayout.cpp index e2ca3a2c..d3e501dd 100644 --- a/projects/uManager/source/ul/man/ui/ui_MainMenuLayout.cpp +++ b/projects/uManager/source/ul/man/ui/ui_MainMenuLayout.cpp @@ -1,8 +1,11 @@ #include