From bd25846c4dc8cf670a34f321fce69e4b35f3a3c7 Mon Sep 17 00:00:00 2001 From: VoltZ <47382115+SuperSaiyajinVoltZ@users.noreply.github.com> Date: Fri, 15 Nov 2019 19:13:41 +0100 Subject: [PATCH] =?UTF-8?q?Simulate=20a=20progressbar.=20(For=20testing=20?= =?UTF-8?q?purpose)=20(=20=CD=A1=C2=B0=20=CD=9C=CA=96=20=CD=A1=C2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Press Select in the MainMenu, to show the progressbar. This will get removed after the download progressbar is implemented. --- include/screens/mainMenu.hpp | 7 ++ source/screens/mainMenu.cpp | 186 +++++++++++++++++++++++------------ 2 files changed, 128 insertions(+), 65 deletions(-) diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index bbf7ffa..96c8567 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -38,7 +38,14 @@ public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; private: + void DrawMainMenu(void) const; + void DisplayTestbar(void) const; + void ProgressBarLogic(u32 hDown, u32 hHeld); + + int keyRepeatDelay = 3; + int mode = 0; int Selection = 0; + std::vector mainButtons = { {10, 40, 140, 35, -1}, // Scriptlist. {170, 40, 140, 35, -1}, // ScriptBrowse. diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index bb4cbda..e309480 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -40,10 +40,21 @@ extern bool exiting; extern bool touching(touchPosition touch, Structs::ButtonPos button); extern bool checkWifiStatus(void); +u64 current = 0; +u64 total = 100; + // This is for the Script Creator, so no one can access it for now, until it is stable or so. bool isTesting = false; void MainMenu::Draw(void) const { + if (mode == 0) { + DrawMainMenu(); + } else if (mode == 1) { + DisplayTestbar(); + } +} + +void MainMenu::DrawMainMenu(void) const { Gui::DrawTop(); Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 237-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, Config::TxtColor, V_STRING); @@ -65,97 +76,142 @@ void MainMenu::Draw(void) const { Gui::DrawString((320-Gui::GetStringWidth(0.6f, "FTP"))/2+150-70, mainButtons[5].y+10, 0.6f, Config::TxtColor, "FTP", 140); } +void MainMenu::DisplayTestbar(void) const { + Gui::DrawTop(); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Downloading . ...", 400); + std::string progressDownload = std::to_string(current); + progressDownload += " KB / "; + progressDownload += std::to_string(total); + progressDownload += " KB downloaded."; + Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, progressDownload, 400); + Gui::Draw_Rect(30, 120, 340, 30, BLACK); + Gui::Draw_Rect(31, 121, (((double)current/(double)total) * 338.0), 28, WHITE); + Gui::DrawBottom(); +} + +void MainMenu::ProgressBarLogic(u32 hDown, u32 hHeld) { + if (keyRepeatDelay) keyRepeatDelay--; + if (hHeld & KEY_LEFT && !keyRepeatDelay) { + if (current > 0) { + current--; + } else { + current = total; + } + } + + if (hHeld & KEY_RIGHT && !keyRepeatDelay) { + if (current < total) { + current++; + } else { + current = 0; + } + } + + if (hDown & KEY_SELECT) { + mode = 0; + } +} + + void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { - if (hDown & KEY_START) { - exiting = true; - } + if (mode == 1) { + ProgressBarLogic(hDown, hHeld); + } else { + if (hDown & KEY_SELECT) { + mode = 1; + } - if (hDown & KEY_UP) { - if(Selection > 1) Selection -= 2; - } + if (hDown & KEY_START) { + exiting = true; + } - if (hDown & KEY_DOWN) { - if(Selection < 4) Selection += 2; - } + if (hDown & KEY_UP) { + if(Selection > 1) Selection -= 2; + } - if (hDown & KEY_LEFT) { - if (Selection%2) Selection--; - } + if (hDown & KEY_DOWN) { + if(Selection < 4) Selection += 2; + } - if (hDown & KEY_RIGHT) { - if (!(Selection%2)) Selection++; - } + if (hDown & KEY_LEFT) { + if (Selection%2) Selection--; + } - if (hDown & KEY_A) { - switch(Selection) { - case 0: + if (hDown & KEY_RIGHT) { + if (!(Selection%2)) Selection++; + } + + if (hDown & KEY_A) { + switch(Selection) { + case 0: + Gui::setScreen(std::make_unique()); + break; + case 1: + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + case 2: + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + case 3: + if (isTesting == true) { + Gui::setScreen(std::make_unique()); + } + break; + case 4: + Gui::setScreen(std::make_unique()); + break; + case 5: + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } + break; + } + } + + if (hDown & KEY_X) { + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, mainButtons[0])) { Gui::setScreen(std::make_unique()); - break; - case 1: + } else if (touching(touch, mainButtons[1])) { if (checkWifiStatus() == true) { Gui::setScreen(std::make_unique()); } else { notConnectedMsg(); } - break; - case 2: + + } else if (touching(touch, mainButtons[2])) { if (checkWifiStatus() == true) { Gui::setScreen(std::make_unique()); } else { notConnectedMsg(); } - break; - case 3: + } else if (touching(touch, mainButtons[3])) { if (isTesting == true) { Gui::setScreen(std::make_unique()); } - break; - case 4: + } else if (touching(touch, mainButtons[4])) { Gui::setScreen(std::make_unique()); - break; - case 5: + } else if (touching(touch, mainButtons[5])) { if (checkWifiStatus() == true) { Gui::setScreen(std::make_unique()); } else { notConnectedMsg(); } - break; - } - } - - if (hDown & KEY_X) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } - } - - if (hDown & KEY_TOUCH) { - if (touching(touch, mainButtons[0])) { - Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[1])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - - } else if (touching(touch, mainButtons[2])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); - } - } else if (touching(touch, mainButtons[3])) { - if (isTesting == true) { - Gui::setScreen(std::make_unique()); - } - } else if (touching(touch, mainButtons[4])) { - Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[5])) { - if (checkWifiStatus() == true) { - Gui::setScreen(std::make_unique()); - } else { - notConnectedMsg(); } } }