From 7a964c828234b5012cc2db43aa3501cff2a68c0d Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Mon, 14 Jun 2021 16:54:33 -0400 Subject: [PATCH] UI: add AboutTab class. --- include/about_tab.hpp | 61 ++++++++++++++++++ include/defines.h | 3 + include/gamecard_tab.hpp | 3 +- romfs/i18n/en-US/about_tab.json | 5 ++ romfs/i18n/en-US/gamecard_tab.json | 3 +- romfs/i18n/en-US/generic.json | 3 + source/about_tab.cpp | 100 +++++++++++++++++++++++++++++ source/core/nxdt_utils.c | 2 +- source/gamecard_tab.cpp | 12 ++-- source/root_view.cpp | 5 +- 10 files changed, 183 insertions(+), 14 deletions(-) create mode 100644 include/about_tab.hpp create mode 100644 romfs/i18n/en-US/about_tab.json create mode 100644 romfs/i18n/en-US/generic.json create mode 100644 source/about_tab.cpp diff --git a/include/about_tab.hpp b/include/about_tab.hpp new file mode 100644 index 0000000..a3f0edd --- /dev/null +++ b/include/about_tab.hpp @@ -0,0 +1,61 @@ +/* + * about_tab.hpp + * + * Copyright (c) 2020-2021, DarkMatterCore . + * + * This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool). + * + * nxdumptool is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nxdumptool is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#ifndef __ABOUT_TAB_HPP__ +#define __ABOUT_TAB_HPP__ + +#include + +namespace nxdt::views +{ + /* Extended class to display a focusable (but unhighlightable) image. */ + class AboutTabLogo: public brls::Image + { + protected: + void layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) override; + brls::View* getDefaultFocus(void); + //void onFocusGained(void); + + public: + AboutTabLogo(void); + }; + + /* Extended class to display a focusable (but unhighlightable) label. */ + class AboutTabLabel: public brls::Label + { + protected: + brls::View* getDefaultFocus(void); + //void onFocusGained(void); + + public: + AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center = false, bool multiline = true); + }; + + class AboutTab: public brls::List + { + public: + AboutTab(void); + }; +} + +#endif /* __ABOUT_TAB_HPP__ */ diff --git a/include/defines.h b/include/defines.h index 338b570..03a8b38 100644 --- a/include/defines.h +++ b/include/defines.h @@ -72,4 +72,7 @@ #define GITHUB_REPOSITORY_URL "https://github.com/DarkMatterCore/nxdumptool" #define GITHUB_NEW_ISSUE_URL GITHUB_REPOSITORY_URL "/issues/new/choose" +#define BOREALIS_URL "https://github.com/natinusala/borealis" +#define LIBUSBHSFS_URL "https://github.com/DarkMatterCore/libusbhsfs" + #endif /* __DEFINES_H__ */ diff --git a/include/gamecard_tab.hpp b/include/gamecard_tab.hpp index 08307f5..2660c62 100644 --- a/include/gamecard_tab.hpp +++ b/include/gamecard_tab.hpp @@ -29,6 +29,7 @@ namespace nxdt::views { + /* Extended class to display a focusable (but unhighlightable) table. */ class GameCardTable: public brls::Table { protected: @@ -37,9 +38,9 @@ namespace nxdt::views public: GameCardTable(void); - ~GameCardTable(void); }; + /* Extended class to switch between ErrorFrame and List views whenever the gamecard status event is triggered. */ class GameCardTab: public brls::LayerView { private: diff --git a/romfs/i18n/en-US/about_tab.json b/romfs/i18n/en-US/about_tab.json new file mode 100644 index 0000000..f6e4e44 --- /dev/null +++ b/romfs/i18n/en-US/about_tab.json @@ -0,0 +1,5 @@ +{ + "description": "Nintendo Switch Dump Tool", + "copyright": "Licensed under GPLv3+\n\u00A9 2020 - 2021 {0}", + "links": "\uE016 Source code is available at: {0}.\n\uE016 {1} is powered by Borealis, a hardware-accelerated UI library: {2}.\n\uE016 USB Mass Storage device support is powered by libusbhsfs: {3}." +} diff --git a/romfs/i18n/en-US/gamecard_tab.json b/romfs/i18n/en-US/gamecard_tab.json index 65922e7..7180c47 100644 --- a/romfs/i18n/en-US/gamecard_tab.json +++ b/romfs/i18n/en-US/gamecard_tab.json @@ -17,8 +17,7 @@ "lafw_version": "Required LAFW version", "lafw_version_value": "%lu or greater (%s)", "sdk_version": "SDK version", - "compatibility_type": "Compatibility type", - "unknown": "Unknown" + "compatibility_type": "Compatibility type" }, "dump_options": "Dump options", diff --git a/romfs/i18n/en-US/generic.json b/romfs/i18n/en-US/generic.json new file mode 100644 index 0000000..47a19eb --- /dev/null +++ b/romfs/i18n/en-US/generic.json @@ -0,0 +1,3 @@ +{ + "unknown": "Unknown" +} diff --git a/source/about_tab.cpp b/source/about_tab.cpp new file mode 100644 index 0000000..2265802 --- /dev/null +++ b/source/about_tab.cpp @@ -0,0 +1,100 @@ +/* + * about_tab.cpp + * + * Copyright (c) 2020-2021, DarkMatterCore . + * + * This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool). + * + * nxdumptool is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nxdumptool is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#define LOGO_SIZE 256 + +namespace i18n = brls::i18n; /* For getStr(). */ +using namespace i18n::literals; /* For _i18n. */ + +namespace nxdt::views +{ + AboutTabLogo::AboutTabLogo(void) : brls::Image(BOREALIS_ASSET("icon/" APP_TITLE ".jpg")) + { + this->setScaleType(brls::ImageScaleType::NO_RESIZE); + } + + void AboutTabLogo::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) + { + this->setBoundaries(this->x + this->width / 2 - LOGO_SIZE / 2, this->y, LOGO_SIZE, LOGO_SIZE); + brls::Image::layout(vg, style, stash); + } + + brls::View* AboutTabLogo::getDefaultFocus(void) + { + return this; + } + /* + void AboutTabLogo::onFocusGained(void) + { + this->focused = true; + this->focusEvent.fire(this); + if (this->hasParent()) this->getParent()->onChildFocusGained(this); + } + */ + AboutTabLabel::AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center, bool multiline) : brls::Label(labelStyle, text, multiline) + { + if (center) this->setHorizontalAlign(NVG_ALIGN_CENTER); + } + + brls::View* AboutTabLabel::getDefaultFocus(void) + { + return this; + } + /* + void AboutTabLabel::onFocusGained(void) + { + this->focused = true; + this->focusEvent.fire(this); + if (this->hasParent()) this->getParent()->onChildFocusGained(this); + } + */ + AboutTab::AboutTab(void) : brls::List() + { + this->setSpacing(this->getSpacing() / 2); + this->setMarginBottom(20); + + /* Logo. */ + this->addView(new AboutTabLogo()); + + /* Description. */ + brls::Label* description = new brls::Label(brls::LabelStyle::REGULAR, "about_tab/description"_i18n, true); + description->setHorizontalAlign(NVG_ALIGN_CENTER); + this->addView(description); + + /* Copyright. */ + brls::Label* copyright = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("about_tab/copyright"_i18n, APP_AUTHOR), true); + copyright->setHorizontalAlign(NVG_ALIGN_CENTER); + this->addView(copyright); + + /* Links and resources. */ + this->addView(new brls::Header("Links and resources")); + + AboutTabLabel* links = new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/links"_i18n, GITHUB_REPOSITORY_URL, APP_TITLE, BOREALIS_URL, LIBUSBHSFS_URL)); + this->addView(links); + + + + + } +} diff --git a/source/core/nxdt_utils.c b/source/core/nxdt_utils.c index 7aec4d3..9024f20 100644 --- a/source/core/nxdt_utils.c +++ b/source/core/nxdt_utils.c @@ -105,7 +105,7 @@ bool utilsInitializeResources(const int program_argc, const char **program_argv) /* Create logfile. */ logWriteStringToLogFile("________________________________________________________________\r\n"); - LOG_MSG(APP_TITLE " v%u.%u.%u starting. Built on " __DATE__ " - " __TIME__ ".", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO); + LOG_MSG(APP_TITLE " v%u.%u.%u starting (" GIT_COMMIT "). Built on " __DATE__ " - " __TIME__ ".", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO); if (g_appLaunchPath) LOG_MSG("Launch path: \"%s\".", g_appLaunchPath); /* Log Horizon OS version. */ diff --git a/source/gamecard_tab.cpp b/source/gamecard_tab.cpp index ebcd12d..2f5bbbb 100644 --- a/source/gamecard_tab.cpp +++ b/source/gamecard_tab.cpp @@ -43,8 +43,6 @@ namespace nxdt::views GameCardTable::GameCardTable(void) : brls::Table() { } - GameCardTable::~GameCardTable(void) { } - brls::View* GameCardTable::getDefaultFocus(void) { return this; @@ -53,9 +51,7 @@ namespace nxdt::views void GameCardTable::onFocusGained(void) { this->focused = true; - this->focusEvent.fire(this); - if (this->hasParent()) this->getParent()->onChildFocusGained(this); } @@ -151,15 +147,15 @@ namespace nxdt::views card_info.upp_version.major_relstep, card_info.upp_version.minor_relstep, card_info.upp_version.value); this->update_version->setValue(std::string(strbuf)); - snprintf(strbuf, sizeof(strbuf), "gamecard_tab/list/properties_table/lafw_version_value"_i18n.c_str(), card_info.fw_version, \ - card_info.fw_version >= GameCardFwVersion_Count ? "gamecard_tab/list/properties_table/unknown"_i18n.c_str() : GameCardFwVersionStrings[card_info.fw_version]); + snprintf(strbuf, sizeof(strbuf), "%lu (%s)", card_info.fw_version, \ + card_info.fw_version >= GameCardFwVersion_Count ? "generic/unknown"_i18n.c_str() : GameCardFwVersionStrings[card_info.fw_version]); this->lafw_version->setValue(std::string(strbuf)); snprintf(strbuf, sizeof(strbuf), "%u.%u.%u-%u (v%u)", card_info.fw_mode.major, card_info.fw_mode.minor, card_info.fw_mode.micro, card_info.fw_mode.relstep, card_info.fw_mode.value); this->sdk_version->setValue(std::string(strbuf)); - snprintf(strbuf, sizeof(strbuf), "%s (%u)", card_info.compatibility_type >= GameCardCompatibilityType_Count ? \ - "gamecard_tab/list/properties_table/unknown"_i18n.c_str() : GameCardCompatibilityTypeStrings[card_info.compatibility_type], \ + snprintf(strbuf, sizeof(strbuf), "%s (%u)", \ + card_info.compatibility_type >= GameCardCompatibilityType_Count ? "generic/unknown"_i18n.c_str() : GameCardCompatibilityTypeStrings[card_info.compatibility_type], \ card_info.compatibility_type); this->compatibility_type->setValue(std::string(strbuf)); diff --git a/source/root_view.cpp b/source/root_view.cpp index e6a44c5..37451d3 100644 --- a/source/root_view.cpp +++ b/source/root_view.cpp @@ -25,7 +25,7 @@ //#include //#include //#include -//#include +#include using namespace brls::i18n::literals; /* For _i18n. */ @@ -51,7 +51,8 @@ namespace nxdt::views this->addTab("root_view/tabs/system_titles"_i18n, new brls::Rectangle(nvgRGB(0, 0, 255))); this->addSeparator(); this->addTab("root_view/tabs/options"_i18n, new brls::Rectangle(nvgRGB(255, 255, 0))); - this->addTab("root_view/tabs/about"_i18n, new brls::Rectangle(nvgRGB(255, 0, 255))); + this->addSeparator(); + this->addTab("root_view/tabs/about"_i18n, new AboutTab()); } RootView::~RootView(void)