From 3c551c4e98bb542306b5091852cf1bab14a049c7 Mon Sep 17 00:00:00 2001 From: Huntereb Date: Sat, 26 Oct 2019 16:03:15 -0400 Subject: [PATCH] Settings menu --- include/ui/MainApplication.hpp | 2 + include/ui/optionsPage.hpp | 19 ++++++++++ source/ui/MainApplication.cpp | 2 + source/ui/mainPage.cpp | 2 +- source/ui/optionsPage.cpp | 67 ++++++++++++++++++++++++++++++++++ source/util/config.cpp | 2 +- 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100755 include/ui/optionsPage.hpp create mode 100755 source/ui/optionsPage.cpp diff --git a/include/ui/MainApplication.hpp b/include/ui/MainApplication.hpp index d752518..792ad0e 100755 --- a/include/ui/MainApplication.hpp +++ b/include/ui/MainApplication.hpp @@ -4,6 +4,7 @@ #include "ui/netInstPage.hpp" #include "ui/nspInstPage.hpp" #include "ui/instPage.hpp" +#include "ui/optionsPage.hpp" namespace inst::ui { class MainApplication : public pu::ui::Application { @@ -15,5 +16,6 @@ namespace inst::ui { netInstPage::Ref netinstPage; nspInstPage::Ref nspinstPage; instPage::Ref instpage; + optionsPage::Ref optionspage; }; } \ No newline at end of file diff --git a/include/ui/optionsPage.hpp b/include/ui/optionsPage.hpp new file mode 100755 index 0000000..688216c --- /dev/null +++ b/include/ui/optionsPage.hpp @@ -0,0 +1,19 @@ +#pragma once +#include + +using namespace pu::ui::elm; +namespace inst::ui { + class optionsPage : public pu::ui::Layout + { + public: + optionsPage(); + PU_SMART_CTOR(optionsPage) + void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos); + private: + TextBlock::Ref topText; + TextBlock::Ref pageInfoText; + pu::ui::elm::Menu::Ref menu; + void setMenuText(); + std::string getMenuOptionText(bool ourBool); + }; +} \ No newline at end of file diff --git a/source/ui/MainApplication.cpp b/source/ui/MainApplication.cpp index 376ef04..927e432 100755 --- a/source/ui/MainApplication.cpp +++ b/source/ui/MainApplication.cpp @@ -10,10 +10,12 @@ namespace inst::ui { this->netinstPage = netInstPage::New(); this->nspinstPage = nspInstPage::New(); this->instpage = instPage::New(); + this->optionspage = optionsPage::New(); this->mainPage->SetOnInput(std::bind(&MainPage::onInput, this->mainPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); this->netinstPage->SetOnInput(std::bind(&netInstPage::onInput, this->netinstPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); this->nspinstPage->SetOnInput(std::bind(&nspInstPage::onInput, this->nspinstPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); this->instpage->SetOnInput(std::bind(&instPage::onInput, this->instpage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); + this->optionspage->SetOnInput(std::bind(&optionsPage::onInput, this->optionspage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); this->LoadLayout(this->mainPage); } } \ No newline at end of file diff --git a/source/ui/mainPage.cpp b/source/ui/mainPage.cpp index 2d86b06..9e93380 100755 --- a/source/ui/mainPage.cpp +++ b/source/ui/mainPage.cpp @@ -3,7 +3,6 @@ #include "ui/mainPage.hpp" #include "util/util.hpp" #include "sigInstall.hpp" -#include "netInstall.hpp" #define COLOR(hex) pu::ui::Color::FromHex(hex) @@ -56,6 +55,7 @@ namespace inst::ui { } void MainPage::settingsMenuItem_Click() { + mainApp->LoadLayout(mainApp->optionspage); } void MainPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) { diff --git a/source/ui/optionsPage.cpp b/source/ui/optionsPage.cpp new file mode 100755 index 0000000..a84d9c8 --- /dev/null +++ b/source/ui/optionsPage.cpp @@ -0,0 +1,67 @@ +#include +#include "ui/MainApplication.hpp" +#include "ui/mainPage.hpp" +#include "ui/optionsPage.hpp" +#include "util/util.hpp" +#include "util/config.hpp" + +#define COLOR(hex) pu::ui::Color::FromHex(hex) + +namespace inst::ui { + extern MainApplication *mainApp; + + std::vector ourMenuEntries = {"Ignore Required Firmware Version - ", "Disable Anime - "}; + + optionsPage::optionsPage() : Layout::Layout() { + this->SetBackgroundColor(COLOR("#670000FF")); + this->topText = TextBlock::New(10, 2, "Awoo Installer", 35); + this->topText->SetColor(COLOR("#FFFFFFFF")); + this->pageInfoText = TextBlock::New(10, 45, "Settings Menu", 35); + this->pageInfoText->SetColor(COLOR("#FFFFFFFF")); + this->menu = pu::ui::elm::Menu::New(0, 160, 1280, COLOR("#FFFFFF00"), 80, (560 / 80)); + this->menu->SetOnFocusColor(COLOR("#00000033")); + this->Add(this->topText); + this->Add(this->pageInfoText); + optionsPage::setMenuText(); + this->Add(this->menu); + } + + std::string optionsPage::getMenuOptionText(bool ourBool) { + if(ourBool) return "Enabled"; + else return "Disabled"; + } + + void optionsPage::setMenuText() { + this->menu->ClearItems(); + auto ignoreFirmOption = pu::ui::elm::MenuItem::New(ourMenuEntries[0] + getMenuOptionText(inst::config::ignoreReqVers)); + ignoreFirmOption->SetColor(COLOR("#FFFFFFFF")); + this->menu->AddItem(ignoreFirmOption); + auto gayModeOption = pu::ui::elm::MenuItem::New(ourMenuEntries[1] + getMenuOptionText(inst::config::gayMode)); + gayModeOption->SetColor(COLOR("#FFFFFFFF")); + this->menu->AddItem(gayModeOption); + } + + void optionsPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) { + if (Down & KEY_B) { + mainApp->LoadLayout(mainApp->mainPage); + } + if (Down & KEY_A) { + switch (this->menu->GetSelectedIndex()) { + case 0: + if (inst::config::ignoreReqVers) inst::config::ignoreReqVers = false; + else inst::config::ignoreReqVers = true; + inst::config::setConfig(); + optionsPage::setMenuText(); + break; + case 1: + if (inst::config::gayMode) inst::config::gayMode = false; + else inst::config::gayMode = true; + inst::config::setConfig(); + optionsPage::setMenuText(); + break; + default: + break; + } + } + } +} diff --git a/source/util/config.cpp b/source/util/config.cpp index 023c3e1..ea1b738 100755 --- a/source/util/config.cpp +++ b/source/util/config.cpp @@ -13,7 +13,7 @@ namespace inst::config { INIReader reader(inst::config::configPath); inst::config::ignoreReqVers = reader.GetBoolean("settings", "ignoreReqVers", true); inst::config::gayMode = reader.GetBoolean("settings", "gayMode", false); - return ; + return; } void setConfig() {