From 1744f71532445376c4df163e61076b91b2f8c90d Mon Sep 17 00:00:00 2001 From: XorTroll Date: Sun, 17 Nov 2019 14:59:56 +0100 Subject: [PATCH] Fix themes, add album, improve other stuff... --- Common/Include/am/am_QCommunications.hpp | 3 +- Common/Include/cfg/cfg_Config.hpp | 30 ++------ Common/Source/cfg/cfg_Config.cpp | 37 +++------- Common/Source/util/util_Misc.cpp | 12 +++- CurrentChangelog.md | 6 ++ LibraryAppletQHbTarget/Makefile | 2 +- LibraryAppletQMenu/Makefile | 2 +- LibraryAppletQMenu/Source/Main.cpp | 24 +++---- .../Source/ui/ui_LanguagesMenuLayout.cpp | 4 +- .../Source/ui/ui_MenuLayout.cpp | 69 ++++++++++--------- .../Source/ui/ui_QMenuApplication.cpp | 10 +-- .../Source/ui/ui_SettingsMenuLayout.cpp | 6 +- .../Source/ui/ui_StartupLayout.cpp | 4 +- .../Source/ui/ui_ThemeMenuLayout.cpp | 21 +++--- SystemAppletQDaemon/Makefile | 2 +- SystemAppletQDaemon/Source/Main.cpp | 37 +++++++++- SystemApplicationQHbTarget/Makefile | 2 +- 17 files changed, 144 insertions(+), 127 deletions(-) diff --git a/Common/Include/am/am_QCommunications.hpp b/Common/Include/am/am_QCommunications.hpp index 67fa0c7c..bae3ce83 100644 --- a/Common/Include/am/am_QCommunications.hpp +++ b/Common/Include/am/am_QCommunications.hpp @@ -35,7 +35,8 @@ namespace am TryLogUser, RegisterUserPassword, ChangeUserPassword, - RemoveUserPassword + RemoveUserPassword, + OpenAlbum, }; struct QDaemonStatus diff --git a/Common/Include/cfg/cfg_Config.hpp b/Common/Include/cfg/cfg_Config.hpp index d30d7bcc..e54e4b8e 100644 --- a/Common/Include/cfg/cfg_Config.hpp +++ b/Common/Include/cfg/cfg_Config.hpp @@ -49,18 +49,6 @@ namespace cfg std::string author; }; - struct UIConfig - { - u8 suspended_final_alpha; - }; - - struct SoundConfig - { - bool loop; - bool fade_in; - bool fade_out; - }; - struct Theme { std::string base_name; @@ -68,13 +56,6 @@ namespace cfg ThemeManifest manifest; }; - struct ProcessedTheme - { - Theme base; - UIConfig ui; - SoundConfig sound; - }; - struct RecordInformation { NacpStruct nacp; @@ -91,7 +72,7 @@ namespace cfg JSON default_lang; }; - static constexpr u32 CurrentThemeFormatVersion = 0; + static constexpr u32 CurrentThemeFormatVersion = 1; #define CFG_THEME_DEFAULT "romfs:/default" #define CFG_LANG_DEFAULT "romfs:/LangDefault.json" @@ -105,9 +86,12 @@ namespace cfg Theme LoadTheme(std::string base_name); std::vector LoadThemes(); - std::string ThemeResource(Theme &base, std::string resource_base); - std::string ProcessedThemeResource(ProcessedTheme &base, std::string resource_base); - ProcessedTheme ProcessTheme(Theme &base); + std::string GetAssetByTheme(Theme &base, std::string resource_base); + + inline bool ThemeIsDefault(Theme &base) + { + return base.base_name.empty(); + } std::string GetLanguageJSONPath(std::string lang); std::string GetLanguageString(JSON &lang, JSON &def, std::string name); diff --git a/Common/Source/cfg/cfg_Config.cpp b/Common/Source/cfg/cfg_Config.cpp index ff5bb84e..25025ccf 100644 --- a/Common/Source/cfg/cfg_Config.cpp +++ b/Common/Source/cfg/cfg_Config.cpp @@ -151,7 +151,7 @@ namespace cfg Theme theme = {}; theme.base_name = base_name; auto themedir = std::string(Q_THEMES_PATH) + "/" + base_name; - if(base_name.empty()) themedir = CFG_THEME_DEFAULT; + if(base_name.empty() || !fs::ExistsDirectory(themedir)) themedir = CFG_THEME_DEFAULT; auto metajson = themedir + "/theme/Manifest.json"; auto [rc, meta] = util::LoadJSONFromFile(metajson); if(R_SUCCEEDED(rc)) @@ -163,6 +163,7 @@ namespace cfg theme.manifest.author = meta.value("author", ""); theme.path = themedir; } + else return LoadTheme(""); return theme; } @@ -179,7 +180,7 @@ namespace cfg return themes; } - std::string ThemeResource(Theme &base, std::string resource_base) + std::string GetAssetByTheme(Theme &base, std::string resource_base) { auto base_res = base.path + "/" + resource_base; if(fs::ExistsFile(base_res)) return base_res; @@ -188,32 +189,6 @@ namespace cfg return ""; } - std::string ProcessedThemeResource(ProcessedTheme &base, std::string resource_base) - { - return ThemeResource(base.base, resource_base); - } - - ProcessedTheme ProcessTheme(Theme &base) - { - ProcessedTheme processed; - processed.base = base; - auto uijson = ThemeResource(base, "ui/UI.json"); - auto [rc, ui] = util::LoadJSONFromFile(uijson); - if(R_SUCCEEDED(rc)) - { - processed.ui.suspended_final_alpha = ui.value("suspended_final_alpha", 80); - auto bgmjson = ThemeResource(base, "sound/BGM.json"); - auto [rc, bgm] = util::LoadJSONFromFile(bgmjson); - if(R_SUCCEEDED(rc)) - { - processed.sound.loop = bgm.value("loop", true); - processed.sound.fade_in = bgm.value("fade_in", true); - processed.sound.fade_out = bgm.value("fade_in", true); - } - } - return processed; - } - std::string GetLanguageJSONPath(std::string lang) { return Q_BASE_SD_DIR "/lang/" + lang + ".json"; @@ -231,6 +206,7 @@ namespace cfg Config cfg = {}; cfg.system_title_override_enabled = false; // Due to ban risk, have it disabled by default. cfg.viewer_usb_enabled = false; // Do not enable this by default due to conflicts with USB homebrew + cfg.theme_name = ""; // Default theme (none) SaveConfig(cfg); return cfg; } @@ -245,6 +221,11 @@ namespace cfg cfg.system_title_override_enabled = cfgjson.value("system_title_override_enabled", false); cfg.viewer_usb_enabled = cfgjson.value("viewer_usb_enabled", false); } + else + { + fs::DeleteFile(CFG_CONFIG_JSON); + return CreateNewAndLoadConfig(); + } return cfg; } diff --git a/Common/Source/util/util_Misc.cpp b/Common/Source/util/util_Misc.cpp index 721347f2..afc73327 100644 --- a/Common/Source/util/util_Misc.cpp +++ b/Common/Source/util/util_Misc.cpp @@ -8,9 +8,15 @@ namespace util JSON ret = JSON::object(); if(fs::ExistsFile(path)) { - std::ifstream ifs(path); - ret = JSON::parse(ifs); - return SuccessResultWith(ret); + try + { + std::ifstream ifs(path); + ret = JSON::parse(ifs); + return SuccessResultWith(ret); + } + catch(std::exception&) + { + } } return MakeResultWith(RES_VALUE(Misc, InvalidJSONFile), ret); } diff --git a/CurrentChangelog.md b/CurrentChangelog.md index acebfeb3..909b8b5d 100644 --- a/CurrentChangelog.md +++ b/CurrentChangelog.md @@ -22,6 +22,12 @@ - Serial number +- Added **controller menu applet** support to change/manage players and controllers! + +- Main menu + + - Added a new way to open menus without touchscreen: presenting the **quick menu**! Just hold L/R-stick, then move it while being held to select a menu, leave the stick and profit! + - General - Custom icons in entry JSONs can now be used with normal titles too, not just homebrew. diff --git a/LibraryAppletQHbTarget/Makefile b/LibraryAppletQHbTarget/Makefile index 26c675b4..85531297 100644 --- a/LibraryAppletQHbTarget/Makefile +++ b/LibraryAppletQHbTarget/Makefile @@ -34,7 +34,7 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\" -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 +CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) diff --git a/LibraryAppletQMenu/Makefile b/LibraryAppletQMenu/Makefile index 3ae857fb..79afcc5d 100644 --- a/LibraryAppletQMenu/Makefile +++ b/LibraryAppletQMenu/Makefile @@ -34,7 +34,7 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\" -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 +CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) diff --git a/LibraryAppletQMenu/Source/Main.cpp b/LibraryAppletQMenu/Source/Main.cpp index 3a9b941c..2a61ca17 100644 --- a/LibraryAppletQMenu/Source/Main.cpp +++ b/LibraryAppletQMenu/Source/Main.cpp @@ -22,7 +22,7 @@ ui::QMenuApplication::Ref qapp; cfg::TitleList list; std::vector homebrew; cfg::Config config; -cfg::ProcessedTheme theme; +cfg::Theme theme; u8 *app_buf; namespace qmenu @@ -38,12 +38,9 @@ namespace qmenu am::QMenu_InitializeDaemonService(); - // Load menu config + // Load menu config and theme config = cfg::EnsureConfig(); - - // Load theme - auto th = cfg::LoadTheme(config.theme_name); - theme = cfg::ProcessTheme(th); + theme = cfg::LoadTheme(config.theme_name); } void Exit() @@ -84,13 +81,16 @@ int main() setGetLanguageCode(&lcode); std::string syslang = (char*)&lcode; auto lpath = cfg::GetLanguageJSONPath(syslang); - auto [_rc, defjson] = util::LoadJSONFromFile(CFG_LANG_DEFAULT); - config.default_lang = defjson; - config.main_lang = defjson; - if(fs::ExistsFile(lpath)) + auto [rc1, defjson] = util::LoadJSONFromFile(CFG_LANG_DEFAULT); + if(R_SUCCEEDED(rc1)) { - auto [_rc2, ljson] = util::LoadJSONFromFile(lpath); - config.main_lang = ljson; + config.default_lang = defjson; + config.main_lang = defjson; + if(fs::ExistsFile(lpath)) + { + auto [rc2, ljson] = util::LoadJSONFromFile(lpath); + if(R_SUCCEEDED(rc2)) config.main_lang = ljson; + } } qapp->SetInformation(smode, status); diff --git a/LibraryAppletQMenu/Source/ui/ui_LanguagesMenuLayout.cpp b/LibraryAppletQMenu/Source/ui/ui_LanguagesMenuLayout.cpp index 895c25bd..fd4d040d 100644 --- a/LibraryAppletQMenu/Source/ui/ui_LanguagesMenuLayout.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_LanguagesMenuLayout.cpp @@ -8,14 +8,14 @@ #include extern ui::QMenuApplication::Ref qapp; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; extern cfg::Config config; namespace ui { LanguagesMenuLayout::LanguagesMenuLayout() { - this->SetBackgroundImage(cfg::ProcessedThemeResource(theme, "ui/Background.png")); + this->SetBackgroundImage(cfg::GetAssetByTheme(theme, "ui/Background.png")); pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); pu::ui::Color menufocusclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("menu_focus_color", "#5ebcffff")); diff --git a/LibraryAppletQMenu/Source/ui/ui_MenuLayout.cpp b/LibraryAppletQMenu/Source/ui/ui_MenuLayout.cpp index b0741745..ef27e903 100644 --- a/LibraryAppletQMenu/Source/ui/ui_MenuLayout.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_MenuLayout.cpp @@ -14,7 +14,7 @@ extern ui::QMenuApplication::Ref qapp; extern cfg::TitleList list; extern std::vector homebrew; extern cfg::Config config; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; namespace ui { @@ -41,11 +41,11 @@ namespace ui this->Add(this->bgSuspendedRaw); // Load banners first - this->topMenuImage = pu::ui::elm::Image::New(40, 35, cfg::ProcessedThemeResource(theme, "ui/TopMenu.png")); + this->topMenuImage = pu::ui::elm::Image::New(40, 35, cfg::GetAssetByTheme(theme, "ui/TopMenu.png")); qapp->ApplyConfigForElement("main_menu", "top_menu_bg", this->topMenuImage); this->Add(this->topMenuImage); - this->bannerImage = pu::ui::elm::Image::New(0, 585, cfg::ProcessedThemeResource(theme, "ui/BannerInstalled.png")); + this->bannerImage = pu::ui::elm::Image::New(0, 585, cfg::GetAssetByTheme(theme, "ui/BannerInstalled.png")); qapp->ApplyConfigForElement("main_menu", "banner_image", this->bannerImage); this->Add(this->bannerImage); @@ -57,14 +57,14 @@ namespace ui qapp->ApplyConfigForElement("main_menu", "logo_icon", this->logo, false); // Sorry theme makers... logo must be visible, but can be moved this->Add(this->logo); - this->connIcon = pu::ui::elm::Image::New(80, 53, cfg::ProcessedThemeResource(theme, "ui/NoConnectionIcon.png")); + this->connIcon = pu::ui::elm::Image::New(80, 53, cfg::GetAssetByTheme(theme, "ui/NoConnectionIcon.png")); qapp->ApplyConfigForElement("main_menu", "connection_icon", this->connIcon); this->Add(this->connIcon); this->users = ClickableImage::New(270, 53, ""); // On layout creation, no user is still selected... this->users->SetOnClick(std::bind(&MenuLayout::users_Click, this)); qapp->ApplyConfigForElement("main_menu", "user_icon", this->users); this->Add(this->users); - this->web = ClickableImage::New(340, 53, cfg::ProcessedThemeResource(theme, "ui/WebIcon.png")); + this->web = ClickableImage::New(340, 53, cfg::GetAssetByTheme(theme, "ui/WebIcon.png")); this->web->SetOnClick(std::bind(&MenuLayout::web_Click, this)); qapp->ApplyConfigForElement("main_menu", "web_icon", this->web); this->Add(this->web); @@ -80,15 +80,15 @@ namespace ui this->batteryText->SetColor(textclr); qapp->ApplyConfigForElement("main_menu", "battery_text", this->batteryText); this->Add(this->batteryText); - this->batteryIcon = pu::ui::elm::Image::New(700, 80, cfg::ProcessedThemeResource(theme, "ui/BatteryNormalIcon.png")); + this->batteryIcon = pu::ui::elm::Image::New(700, 80, cfg::GetAssetByTheme(theme, "ui/BatteryNormalIcon.png")); qapp->ApplyConfigForElement("main_menu", "battery_icon", this->batteryIcon); this->Add(this->batteryIcon); - this->settings = ClickableImage::New(880, 53, cfg::ProcessedThemeResource(theme, "ui/SettingsIcon.png")); + this->settings = ClickableImage::New(880, 53, cfg::GetAssetByTheme(theme, "ui/SettingsIcon.png")); this->settings->SetOnClick(std::bind(&MenuLayout::settings_Click, this)); qapp->ApplyConfigForElement("main_menu", "settings_icon", this->settings); this->Add(this->settings); - this->themes = ClickableImage::New(950, 53, cfg::ProcessedThemeResource(theme, "ui/ThemesIcon.png")); + this->themes = ClickableImage::New(950, 53, cfg::GetAssetByTheme(theme, "ui/ThemesIcon.png")); this->themes->SetOnClick(std::bind(&MenuLayout::themes_Click, this)); qapp->ApplyConfigForElement("main_menu", "themes_icon", this->themes); this->Add(this->themes); @@ -98,7 +98,7 @@ namespace ui qapp->ApplyConfigForElement("main_menu", "firmware_text", this->fwText); this->Add(this->fwText); - this->menuToggle = ClickableImage::New(520, 200, cfg::ProcessedThemeResource(theme, "ui/ToggleClick.png")); + this->menuToggle = ClickableImage::New(520, 200, cfg::GetAssetByTheme(theme, "ui/ToggleClick.png")); this->menuToggle->SetOnClick(std::bind(&MenuLayout::menuToggle_Click, this)); qapp->ApplyConfigForElement("main_menu", "menu_toggle_button", this->menuToggle); this->Add(this->menuToggle); @@ -116,29 +116,29 @@ namespace ui qapp->ApplyConfigForElement("main_menu", "banner_version_text", this->itemVersion); this->Add(this->itemVersion); - this->itemsMenu = SideMenu::New(pu::ui::Color(0, 255, 120, 255), cfg::ProcessedThemeResource(theme, "ui/Cursor.png"), cfg::ProcessedThemeResource(theme, "ui/Suspended.png"), cfg::ProcessedThemeResource(theme, "ui/Multiselect.png"), menutextx, menutexty, menutextsz, textclr, 294); + this->itemsMenu = SideMenu::New(pu::ui::Color(0, 255, 120, 255), cfg::GetAssetByTheme(theme, "ui/Cursor.png"), cfg::GetAssetByTheme(theme, "ui/Suspended.png"), cfg::GetAssetByTheme(theme, "ui/Multiselect.png"), menutextx, menutexty, menutextsz, textclr, 294); this->MoveFolder("", false); this->itemsMenu->SetOnItemSelected(std::bind(&MenuLayout::menu_Click, this, std::placeholders::_1, std::placeholders::_2)); this->itemsMenu->SetOnSelectionChanged(std::bind(&MenuLayout::menu_OnSelected, this, std::placeholders::_1)); qapp->ApplyConfigForElement("main_menu", "items_menu", this->itemsMenu, false); // Main menu must be visible, and only Y is customizable here this->Add(this->itemsMenu); - this->quickMenu = QuickMenu::New(cfg::ProcessedThemeResource(theme, "ui/QuickMenuMain.png")); + this->quickMenu = QuickMenu::New(cfg::GetAssetByTheme(theme, "ui/QuickMenuMain.png")); - this->quickMenu->SetEntry(QuickMenuDirection::Down, cfg::ProcessedThemeResource(theme, "ui/QuickMenuSettingsItem.png"), std::bind(&MenuLayout::settings_Click, this)); - this->quickMenu->SetEntry(QuickMenuDirection::Left, cfg::ProcessedThemeResource(theme, "ui/QuickMenuWebItem.png"), std::bind(&MenuLayout::web_Click, this)); - this->quickMenu->SetEntry(QuickMenuDirection::Right, cfg::ProcessedThemeResource(theme, "ui/QuickMenuThemesItem.png"), std::bind(&MenuLayout::themes_Click, this)); - this->quickMenu->SetEntry(QuickMenuDirection::UpLeft, cfg::ProcessedThemeResource(theme, "ui/QuickMenuControllerItem.png"), std::bind(&MenuLayout::HandleControllerAppletOpen, this)); - this->quickMenu->SetEntry(QuickMenuDirection::DownRight, cfg::ProcessedThemeResource(theme, "ui/QuickMenuHelpItem.png"), std::bind(&MenuLayout::HandleShowHelp, this)); + this->quickMenu->SetEntry(QuickMenuDirection::Down, cfg::GetAssetByTheme(theme, "ui/QuickMenuSettingsItem.png"), std::bind(&MenuLayout::settings_Click, this)); + this->quickMenu->SetEntry(QuickMenuDirection::Left, cfg::GetAssetByTheme(theme, "ui/QuickMenuWebItem.png"), std::bind(&MenuLayout::web_Click, this)); + this->quickMenu->SetEntry(QuickMenuDirection::Right, cfg::GetAssetByTheme(theme, "ui/QuickMenuThemesItem.png"), std::bind(&MenuLayout::themes_Click, this)); + this->quickMenu->SetEntry(QuickMenuDirection::UpLeft, cfg::GetAssetByTheme(theme, "ui/QuickMenuControllerItem.png"), std::bind(&MenuLayout::HandleControllerAppletOpen, this)); + this->quickMenu->SetEntry(QuickMenuDirection::DownRight, cfg::GetAssetByTheme(theme, "ui/QuickMenuHelpItem.png"), std::bind(&MenuLayout::HandleShowHelp, this)); this->Add(this->quickMenu); this->tp = std::chrono::steady_clock::now(); - this->sfxTitleLaunch = pu::audio::Load(cfg::ProcessedThemeResource(theme, "sound/TitleLaunch.wav")); - this->sfxMenuToggle = pu::audio::Load(cfg::ProcessedThemeResource(theme, "sound/MenuToggle.wav")); + this->sfxTitleLaunch = pu::audio::Load(cfg::GetAssetByTheme(theme, "sound/TitleLaunch.wav")); + this->sfxMenuToggle = pu::audio::Load(cfg::GetAssetByTheme(theme, "sound/MenuToggle.wav")); - this->SetBackgroundImage(cfg::ProcessedThemeResource(theme, "ui/Background.png")); + this->SetBackgroundImage(cfg::GetAssetByTheme(theme, "ui/Background.png")); this->SetOnInput(std::bind(&MenuLayout::OnInput, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } @@ -479,7 +479,7 @@ namespace ui { this->itemAuthor->SetVisible(false); this->itemVersion->SetVisible(false); - this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerHomebrew.png")); + this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerHomebrew.png")); this->itemName->SetText(cfg::GetLanguageString(config.main_lang, config.default_lang, "hbmenu_launch")); } else @@ -500,7 +500,7 @@ namespace ui } if(strlen(info.nacp.version)) this->itemVersion->SetText(info.nacp.version); else this->itemVersion->SetText("0"); - this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerHomebrew.png")); + this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerHomebrew.png")); } } else @@ -516,7 +516,7 @@ namespace ui else { auto foldr = list.folders[realidx]; - this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerFolder.png")); + this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerFolder.png")); auto sz = foldr.titles.size(); this->itemAuthor->SetText(std::to_string(sz) + " " + ((sz == 1) ? cfg::GetLanguageString(config.main_lang, config.default_lang, "folder_entry_single") : cfg::GetLanguageString(config.main_lang, config.default_lang, "folder_entry_mult"))); this->itemVersion->SetVisible(false); @@ -542,11 +542,11 @@ namespace ui } if(strlen(info.nacp.version)) this->itemVersion->SetText(info.nacp.version); else this->itemVersion->SetText("0"); - if((cfg::TitleType)title.title_type == cfg::TitleType::Homebrew) this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerHomebrew.png")); - else this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerInstalled.png")); + if((cfg::TitleType)title.title_type == cfg::TitleType::Homebrew) this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerHomebrew.png")); + else this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerInstalled.png")); } } - if(!this->curfolder.empty()) this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerFolder.png")); // This way user always knows he's inside a folder + if(!this->curfolder.empty()) this->bannerImage->SetImage(cfg::GetAssetByTheme(theme, "ui/BannerFolder.png")); // This way user always knows he's inside a folder } void MenuLayout::MoveFolder(std::string name, bool fade) @@ -566,13 +566,13 @@ namespace ui } this->itemsMenu->ClearItems(); - if(this->homebrew_mode) this->itemsMenu->AddItem(cfg::ProcessedThemeResource(theme, "ui/Hbmenu.png")); + if(this->homebrew_mode) this->itemsMenu->AddItem(cfg::GetAssetByTheme(theme, "ui/Hbmenu.png")); else { if(name.empty()) { STL_REMOVE_IF(list.folders, fldr, (fldr.titles.empty())) // Remove empty folders - for(auto folder: list.folders) this->itemsMenu->AddItem(cfg::ProcessedThemeResource(theme, "ui/Folder.png"), folder.name); + for(auto folder: list.folders) this->itemsMenu->AddItem(cfg::GetAssetByTheme(theme, "ui/Folder.png"), folder.name); } } @@ -614,8 +614,8 @@ namespace ui bool hasconn = net::HasConnection(); if(this->last_hasconn != hasconn) { - if(hasconn) this->connIcon->SetImage(cfg::ProcessedThemeResource(theme, "ui/ConnectionIcon.png")); - else this->connIcon->SetImage(cfg::ProcessedThemeResource(theme, "ui/NoConnectionIcon.png")); + if(hasconn) this->connIcon->SetImage(cfg::GetAssetByTheme(theme, "ui/ConnectionIcon.png")); + else this->connIcon->SetImage(cfg::GetAssetByTheme(theme, "ui/NoConnectionIcon.png")); this->last_hasconn = hasconn; } @@ -633,8 +633,8 @@ namespace ui if(this->last_charge != ch) { this->last_charge = ch; - if(ch) this->batteryIcon->SetImage(cfg::ProcessedThemeResource(theme, "ui/BatteryChargingIcon.png")); - else this->batteryIcon->SetImage(cfg::ProcessedThemeResource(theme, "ui/BatteryNormalIcon.png")); + if(ch) this->batteryIcon->SetImage(cfg::GetAssetByTheme(theme, "ui/BatteryChargingIcon.png")); + else this->batteryIcon->SetImage(cfg::GetAssetByTheme(theme, "ui/BatteryNormalIcon.png")); } auto ctp = std::chrono::steady_clock::now(); @@ -1082,7 +1082,12 @@ namespace ui void MenuLayout::HandleShowHelp() { - + am::QMenuCommandWriter writer(am::QDaemonMessage::OpenAlbum); + writer.FinishWrite(); + + qapp->StopPlayBGM(); + qapp->CloseWithFadeOut(); + return; } void MenuLayout::HandleMultiselectMoveToFolder(std::string folder) diff --git a/LibraryAppletQMenu/Source/ui/ui_QMenuApplication.cpp b/LibraryAppletQMenu/Source/ui/ui_QMenuApplication.cpp index 336c9719..84af2e78 100644 --- a/LibraryAppletQMenu/Source/ui/ui_QMenuApplication.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_QMenuApplication.cpp @@ -2,7 +2,7 @@ #include extern u8 *app_buf; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; namespace ui { @@ -13,7 +13,7 @@ namespace ui void QMenuApplication::OnLoad() { - pu::ui::render::SetDefaultFont(cfg::ProcessedThemeResource(theme, "ui/Font.ttf")); + pu::ui::render::SetDefaultFont(cfg::GetAssetByTheme(theme, "ui/Font.ttf")); if(this->IsSuspended()) { @@ -21,9 +21,9 @@ namespace ui appletGetLastApplicationCaptureImageEx(app_buf, RawRGBAScreenBufferSize, &flag); } - auto [_rc, jui] = util::LoadJSONFromFile(cfg::ProcessedThemeResource(theme, "ui/UI.json")); + auto [_rc, jui] = util::LoadJSONFromFile(cfg::GetAssetByTheme(theme, "ui/UI.json")); this->uijson = jui; - auto [_rc2, jbgm] = util::LoadJSONFromFile(cfg::ProcessedThemeResource(theme, "sound/BGM.json")); + auto [_rc2, jbgm] = util::LoadJSONFromFile(cfg::GetAssetByTheme(theme, "sound/BGM.json")); this->bgmjson = jbgm; this->bgm_loop = this->bgmjson.value("loop", true); this->bgm_fade_in_ms = this->bgmjson.value("fade_in_ms", 1500); @@ -33,7 +33,7 @@ namespace ui pu::ui::Color toastbaseclr = pu::ui::Color::FromHex(GetUIConfigValue("toast_base_color", "#282828ff")); this->notifToast = pu::ui::extras::Toast::New("...", 20, toasttextclr, toastbaseclr); - this->bgm = pu::audio::Open(cfg::ProcessedThemeResource(theme, "sound/BGM.mp3")); + this->bgm = pu::audio::Open(cfg::GetAssetByTheme(theme, "sound/BGM.mp3")); this->startupLayout = StartupLayout::New(); this->menuLayout = MenuLayout::New(app_buf, this->uijson.value("suspended_final_alpha", 80)); diff --git a/LibraryAppletQMenu/Source/ui/ui_SettingsMenuLayout.cpp b/LibraryAppletQMenu/Source/ui/ui_SettingsMenuLayout.cpp index 7b86128b..f4bd5d64 100644 --- a/LibraryAppletQMenu/Source/ui/ui_SettingsMenuLayout.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_SettingsMenuLayout.cpp @@ -8,7 +8,7 @@ #include extern ui::QMenuApplication::Ref qapp; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; extern cfg::Config config; namespace ui @@ -39,7 +39,7 @@ namespace ui SettingsMenuLayout::SettingsMenuLayout() { - this->SetBackgroundImage(cfg::ProcessedThemeResource(theme, "ui/Background.png")); + this->SetBackgroundImage(cfg::GetAssetByTheme(theme, "ui/Background.png")); pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); pu::ui::Color menufocusclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("menu_focus_color", "#5ebcffff")); @@ -121,7 +121,7 @@ namespace ui pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); auto itm = pu::ui::elm::MenuItem::New(name + ": " + value_display); itm->AddOnClick(std::bind(&SettingsMenuLayout::setting_Click, this, id)); - itm->SetIcon(cfg::ProcessedThemeResource(theme, "ui/Setting" + std::string((id < 0) ? "No" : "") + "Editable.png")); + itm->SetIcon(cfg::GetAssetByTheme(theme, "ui/Setting" + std::string((id < 0) ? "No" : "") + "Editable.png")); itm->SetColor(textclr); this->settingsMenu->AddItem(itm); } diff --git a/LibraryAppletQMenu/Source/ui/ui_StartupLayout.cpp b/LibraryAppletQMenu/Source/ui/ui_StartupLayout.cpp index 3356c6b4..c69f65f0 100644 --- a/LibraryAppletQMenu/Source/ui/ui_StartupLayout.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_StartupLayout.cpp @@ -5,14 +5,14 @@ #include extern ui::QMenuApplication::Ref qapp; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; extern cfg::Config config; namespace ui { StartupLayout::StartupLayout() { - this->SetBackgroundImage(cfg::ProcessedThemeResource(theme, "ui/Background.png")); + this->SetBackgroundImage(cfg::GetAssetByTheme(theme, "ui/Background.png")); this->loadmenu = false; pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); diff --git a/LibraryAppletQMenu/Source/ui/ui_ThemeMenuLayout.cpp b/LibraryAppletQMenu/Source/ui/ui_ThemeMenuLayout.cpp index 9c2b38bd..688df6e1 100644 --- a/LibraryAppletQMenu/Source/ui/ui_ThemeMenuLayout.cpp +++ b/LibraryAppletQMenu/Source/ui/ui_ThemeMenuLayout.cpp @@ -5,20 +5,20 @@ #include extern ui::QMenuApplication::Ref qapp; -extern cfg::ProcessedTheme theme; +extern cfg::Theme theme; extern cfg::Config config; namespace ui { ThemeMenuLayout::ThemeMenuLayout() { - this->SetBackgroundImage(cfg::ProcessedThemeResource(theme, "ui/Background.png")); + this->SetBackgroundImage(cfg::GetAssetByTheme(theme, "ui/Background.png")); pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); pu::ui::Color menufocusclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("menu_focus_color", "#5ebcffff")); pu::ui::Color menubgclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("menu_bg_color", "#0094ffff")); - this->curThemeBanner = pu::ui::elm::Image::New(0, 585, cfg::ProcessedThemeResource(theme, "ui/BannerTheme.png")); + this->curThemeBanner = pu::ui::elm::Image::New(0, 585, cfg::GetAssetByTheme(theme, "ui/BannerTheme.png")); qapp->ApplyConfigForElement("themes_menu", "banner_image", this->curThemeBanner); this->Add(this->curThemeBanner); @@ -56,8 +56,7 @@ namespace ui void ThemeMenuLayout::Reload() { pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue("text_color", "#e1e1e1ff")); - bool default_theme = theme.base.base_name.empty(); - if(default_theme) + if(cfg::ThemeIsDefault(theme)) { this->curThemeText->SetText(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_no_custom")); this->curThemeName->SetVisible(false); @@ -70,14 +69,14 @@ namespace ui { this->curThemeText->SetText(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_current") + ":"); this->curThemeName->SetVisible(true); - this->curThemeName->SetText(theme.base.manifest.name); + this->curThemeName->SetText(theme.manifest.name); this->curThemeAuthor->SetVisible(true); - this->curThemeAuthor->SetText(theme.base.manifest.author); + this->curThemeAuthor->SetText(theme.manifest.author); this->curThemeVersion->SetVisible(true); - this->curThemeVersion->SetText("v" + theme.base.manifest.release); + this->curThemeVersion->SetText("v" + theme.manifest.release); this->curThemeBanner->SetVisible(true); this->curThemeIcon->SetVisible(true); - this->curThemeIcon->SetImage(theme.base.path + "/theme/Icon.png"); + this->curThemeIcon->SetImage(theme.path + "/theme/Icon.png"); this->curThemeIcon->SetWidth(100); this->curThemeIcon->SetHeight(100); } @@ -121,7 +120,7 @@ namespace ui auto idx = this->themesMenu->GetSelectedIndex(); if(idx == 0) { - if(theme.base.base_name.empty()) qapp->ShowNotification(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_no_custom")); + if(cfg::ThemeIsDefault(theme)) qapp->ShowNotification(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_no_custom")); else { auto sopt = qapp->CreateShowDialog(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_reset"), cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_reset_conf"), { cfg::GetLanguageString(config.main_lang, config.default_lang, "yes"), cfg::GetLanguageString(config.main_lang, config.default_lang, "cancel") }, true); @@ -138,7 +137,7 @@ namespace ui idx--; auto seltheme = this->loadedThemes[idx]; auto iconpath = seltheme.path + "/theme/Icon.png"; - if(seltheme.base_name == theme.base.base_name) qapp->ShowNotification(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_active_this")); + if(seltheme.base_name == theme.base_name) qapp->ShowNotification(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_active_this")); else { auto sopt = qapp->CreateShowDialog(cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_set"), cfg::GetLanguageString(config.main_lang, config.default_lang, "theme_set_conf"), { cfg::GetLanguageString(config.main_lang, config.default_lang, "yes"), cfg::GetLanguageString(config.main_lang, config.default_lang, "cancel") }, true, iconpath); diff --git a/SystemAppletQDaemon/Makefile b/SystemAppletQDaemon/Makefile index bf89cf3e..a4ee8692 100644 --- a/SystemAppletQDaemon/Makefile +++ b/SystemAppletQDaemon/Makefile @@ -38,7 +38,7 @@ ifeq ($(Q_DEV),1) CFLAGS += -DQ_DEV endif -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 +CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) diff --git a/SystemAppletQDaemon/Source/Main.cpp b/SystemAppletQDaemon/Source/Main.cpp index c51aecb7..c97e5c76 100644 --- a/SystemAppletQDaemon/Source/Main.cpp +++ b/SystemAppletQDaemon/Source/Main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ hb::TargetInput hbapplaunch_copy = {}; hb::TargetInput hbapplaunch_flag = {}; u64 titlelaunch_flag = 0; WebCommonConfig webapplet_flag = {}; +bool album_flag = false; HosMutex latestqlock; am::QMenuMessage latestqmenumsg = am::QMenuMessage::Invalid; @@ -46,7 +48,7 @@ am::QDaemonStatus CreateStatus() if(am::ApplicationIsActive()) { tmptype = cfg::TitleType::Installed; - if(am::ApplicationGetId() == OS_FLOG_APP_ID) tmptype = cfg::TitleType::Homebrew; + if(os::IsFlogTitle(am::ApplicationGetId())) tmptype = cfg::TitleType::Homebrew; } if(tmptype == cfg::TitleType::Installed) status.app_id = am::ApplicationGetId(); @@ -350,6 +352,13 @@ void HandleQMenuMessage() break; } + case am::QDaemonMessage::OpenAlbum: + { + reader.FinishRead(); + album_flag = true; + + break; + } default: break; } @@ -500,6 +509,8 @@ int main() if(!am::LibraryAppletIsActive()) { am::WebAppletStart(&webapplet_flag); + + /* svcSleepThread(500'000'000); if(!am::LibraryAppletIsActive()) { @@ -507,10 +518,33 @@ int main() auto status = CreateStatus(); am::QDaemon_LaunchQMenu(am::QMenuStartMode::MenuLaunchFailure, status); } + */ + sth_done = true; memset(&webapplet_flag, 0, sizeof(webapplet_flag)); } } + if(album_flag) + { + if(!am::LibraryAppletIsActive()) + { + u8 albumflag = 2; + am::LibraryAppletStart(AppletId_photoViewer, 0x10000, &albumflag, sizeof(albumflag)); + + /* + svcSleepThread(500'000'000); + if(!am::LibraryAppletIsActive()) + { + // Web applet failed to launch... + auto status = CreateStatus(); + am::QDaemon_LaunchQMenu(am::QMenuStartMode::MenuLaunchFailure, status); + } + */ + + sth_done = true; + album_flag = false; + } + } if(titlelaunch_flag > 0) { if(!am::LibraryAppletIsActive()) @@ -544,6 +578,7 @@ int main() { case am::QHbTargetAppletId: case AppletId_web: + case AppletId_photoViewer: { auto status = CreateStatus(); am::QDaemon_LaunchQMenu(am::QMenuStartMode::Menu, status); diff --git a/SystemApplicationQHbTarget/Makefile b/SystemApplicationQHbTarget/Makefile index 26c675b4..85531297 100644 --- a/SystemApplicationQHbTarget/Makefile +++ b/SystemApplicationQHbTarget/Makefile @@ -34,7 +34,7 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\" -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 +CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)