Skip to content

Commit

Permalink
Fix themes, add album, improve other stuff...
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Nov 17, 2019
1 parent 2b0306b commit 1744f71
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 127 deletions.
3 changes: 2 additions & 1 deletion Common/Include/am/am_QCommunications.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace am
TryLogUser,
RegisterUserPassword,
ChangeUserPassword,
RemoveUserPassword
RemoveUserPassword,
OpenAlbum,
};

struct QDaemonStatus
Expand Down
30 changes: 7 additions & 23 deletions Common/Include/cfg/cfg_Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,13 @@ 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;
std::string path;
ThemeManifest manifest;
};

struct ProcessedTheme
{
Theme base;
UIConfig ui;
SoundConfig sound;
};

struct RecordInformation
{
NacpStruct nacp;
Expand All @@ -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"
Expand All @@ -105,9 +86,12 @@ namespace cfg

Theme LoadTheme(std::string base_name);
std::vector<Theme> 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);
Expand Down
37 changes: 9 additions & 28 deletions Common/Source/cfg/cfg_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -163,6 +163,7 @@ namespace cfg
theme.manifest.author = meta.value("author", "");
theme.path = themedir;
}
else return LoadTheme("");
return theme;
}

Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down
12 changes: 9 additions & 3 deletions Common/Source/util/util_Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions CurrentChangelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion LibraryAppletQHbTarget/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion LibraryAppletQMenu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions LibraryAppletQMenu/Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ui::QMenuApplication::Ref qapp;
cfg::TitleList list;
std::vector<cfg::TitleRecord> homebrew;
cfg::Config config;
cfg::ProcessedTheme theme;
cfg::Theme theme;
u8 *app_buf;

namespace qmenu
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions LibraryAppletQMenu/Source/ui/ui_LanguagesMenuLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <am/am_LibraryApplet.hpp>

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<std::string>("text_color", "#e1e1e1ff"));
pu::ui::Color menufocusclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue<std::string>("menu_focus_color", "#5ebcffff"));
Expand Down
Loading

0 comments on commit 1744f71

Please sign in to comment.