~~Cleanup~~ Changes. (#14)

* No builds allowed here as always on other branches, lmao.

* Changes. ;)
This commit is contained in:
StackZ
2019-12-30 04:59:16 +01:00
committed by GitHub
parent cfd5a54b1a
commit e95b48011a
12 changed files with 345 additions and 239 deletions
+23 -125
View File
@@ -24,29 +24,18 @@
* reasonable ways as different from the original version.
*/
#include "download/download.hpp"
#include "screens/ftpScreen.hpp"
#include "screens/mainMenu.hpp"
#include "screens/scriptBrowse.hpp"
#include "screens/scriptCreator.hpp"
#include "screens/scriptlist.hpp"
#include "screens/settings.hpp"
#include "screens/unistore.hpp"
#include "utils/config.hpp"
#include <unistd.h>
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern bool checkWifiStatus(void);
extern int fadealpha;
extern bool fadein;
extern void notImplemented(void);
// 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 {
Gui::DrawTop();
@@ -63,7 +52,7 @@ void MainMenu::Draw(void) const {
Gui::DrawBottom();
Gui::DrawArrow(0, 218, 0, 1);
for (int i = 0; i < 6; i++) {
for (int i = 0; i < 4; i++) {
if (Selection == i) {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor);
} else {
@@ -71,149 +60,58 @@ void MainMenu::Draw(void) const {
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "UniStore"))/2-150+70+10, mainButtons[0].y+12, 0.6f, Config::TxtColor, "UniStore", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTS")))/2+150-70, mainButtons[1].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTS"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2-150+70, mainButtons[2].y+12, 0.6f, Config::TxtColor, Lang::get("SETTINGS"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "FTP"))/2+150-70, mainButtons[3].y+12, 0.6f, Config::TxtColor, "FTP", 140);
// Draw UniStore Icon. ;P
Gui::sprite(sprites_uniStore_idx, 15, 95);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2-150+70, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("GET_SCRIPTS")))/2+150-70, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 140);
Gui::DrawString(80, mainButtons[2].y+10, 0.6f, Config::TxtColor, "UniStore", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTCREATOR")))/2+150-70, mainButtons[3].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2-150+70, mainButtons[4].y+10, 0.6f, Config::TxtColor, Lang::get("SETTINGS"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "FTP"))/2+150-70, mainButtons[5].y+10, 0.6f, Config::TxtColor, "FTP", 140);
Gui::sprite(sprites_uniStore_idx, 10, 65);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, fadealpha)); // Fade in out effect
}
bool MainMenu::returnScriptState() {
dirContents.clear();
chdir(Config::ScriptPath.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"json"});
for(uint i=0;i<dirContentsTemp.size();i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
bool MainMenu::returnStoreState() {
dirContents.clear();
chdir(Config::StorePath.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"unistore"});
for(uint i=0;i<dirContentsTemp.size();i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_START) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, mainButtons[4]))) {
exiting = true;
}
if (hDown & KEY_UP) {
// Navigation.
if(hDown & KEY_UP) {
if(Selection > 1) Selection -= 2;
}
if (hDown & KEY_DOWN) {
if(Selection < 4) Selection += 2;
}
if (hDown & KEY_LEFT) {
} else if(hDown & KEY_DOWN) {
if(Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
} else if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
}
if (hDown & KEY_RIGHT) {
} else if (hDown & KEY_RIGHT) {
if (!(Selection%2)) Selection++;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
if (returnScriptState() == true) {
Screen::set(std::make_unique<ScriptList>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
Screen::set(std::make_unique<UniStore>());
break;
case 1:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
Screen::set(std::make_unique<ScriptList>());
break;
case 2:
if (returnStoreState() == true) {
Screen::set(std::make_unique<UniStore>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
break;
case 3:
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
break;
case 4:
Screen::set(std::make_unique<Settings>());
break;
case 5:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
}
case 3:
Screen::set(std::make_unique<FTPScreen>());
break;
}
}
if (hDown & KEY_X) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
if (returnScriptState() == true) {
Screen::set(std::make_unique<ScriptList>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
Screen::set(std::make_unique<UniStore>());
} else if (touching(touch, mainButtons[1])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
Screen::set(std::make_unique<ScriptList>());
} else if (touching(touch, mainButtons[2])) {
if (returnStoreState() == true) {
Screen::set(std::make_unique<UniStore>());
} else {
Gui::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
} else if (touching(touch, mainButtons[3])) {
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
} else if (touching(touch, mainButtons[4])) {
Screen::set(std::make_unique<Settings>());
} else if (touching(touch, mainButtons[5])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[6])) {
exiting = true;
} else if (touching(touch, mainButtons[3])) {
Screen::set(std::make_unique<FTPScreen>());
}
}
}
+132 -15
View File
@@ -26,6 +26,8 @@
#include "download/download.hpp"
#include "screens/scriptBrowse.hpp"
#include "screens/scriptCreator.hpp"
#include "screens/scriptlist.hpp"
#include "utils/config.hpp"
@@ -37,6 +39,11 @@
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern bool checkWifiStatus(void);
extern void notImplemented(void);
// This is for the Script Creator, so no one can access it for now, until it is stable or so.
bool isTesting = false;
bool isScriptSelected = false;
@@ -262,15 +269,32 @@ void loadColors(nlohmann::json &json) {
progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp;
}
ScriptList::ScriptList() {
dirContents.clear();
chdir(Config::ScriptPath.c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
void ScriptList::DrawSubMenu(void) const {
Gui::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400);
}
Gui::DrawBottom();
Gui::DrawArrow(0, 218, 0, 1);
for (int i = 0; i < 4; i++) {
if (SubSelection == i) {
Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::SelectedColor);
} else {
Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor);
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2-150+70, subPos[0].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("GET_SCRIPTS")))/2+150-70, subPos[1].y+12, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTCREATOR")))/2-150+70, subPos[2].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("CHANGE_SCRIPTPATH")))/2+150-70, subPos[3].y+12, 0.6f, Config::TxtColor, Lang::get("CHANGE_SCRIPTPATH"), 140);
}
void ScriptList::DrawList(void) const {
std::string line1;
std::string line2;
@@ -319,9 +343,11 @@ void ScriptList::DrawList(void) const {
}
void ScriptList::Draw(void) const {
if (mode == 0){
DrawList();
if (mode == 0) {
DrawSubMenu();
} else if (mode == 1) {
DrawList();
} else if (mode == 2) {
DrawSingleObject();
}
}
@@ -379,13 +405,102 @@ void ScriptList::DrawSingleObject(void) const {
}
}
void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Screen::back();
return;
}
// Navigation.
if(hDown & KEY_UP) {
if(SubSelection > 1) SubSelection -= 2;
} else if(hDown & KEY_DOWN) {
if(SubSelection < 3 && SubSelection != 2 && SubSelection != 3) SubSelection += 2;
} else if (hDown & KEY_LEFT) {
if (SubSelection%2) SubSelection--;
} else if (hDown & KEY_RIGHT) {
if (!(SubSelection%2)) SubSelection++;
}
if (hDown & KEY_A) {
switch(SubSelection) {
case 0:
if (returnIfExist(Config::ScriptPath, {"json"}) == true) {
dirContents.clear();
chdir(Config::ScriptPath.c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
}
mode = 1;
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
break;
case 1:
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
break;
case 2:
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
break;
case 3:
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
}
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, subPos[0])) {
if (returnIfExist(Config::ScriptPath, {"json"}) == true) {
dirContents.clear();
chdir(Config::ScriptPath.c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
}
mode = 1;
} else {
Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST"));
}
} else if (touching(touch, subPos[1])) {
if (checkWifiStatus() == true) {
Screen::set(std::make_unique<ScriptBrowse>());
} else {
notConnectedMsg();
}
} else if (touching(touch, subPos[2])) {
if (isTesting == true) {
Screen::set(std::make_unique<ScriptCreator>());
} else {
notImplemented();
}
} else if (touching(touch, subPos[3])) {
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
}
}
}
}
void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
fileInfo.clear();
Screen::back();
return;
mode = 0;
}
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
@@ -431,7 +546,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
loadDesc();
isScriptSelected = true;
selection = 0;
mode = 1;
mode = 2;
}
}
}
@@ -452,7 +567,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
loadDesc();
isScriptSelected = true;
selection = 0;
mode = 1;
mode = 2;
}
}
}
@@ -474,7 +589,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
loadDesc();
isScriptSelected = true;
selection = 0;
mode = 1;
mode = 2;
}
}
}
@@ -509,7 +624,7 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
selection2 = 0;
fileInfo2.clear();
isScriptSelected = false;
mode = 0;
mode = 1;
}
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
@@ -603,8 +718,10 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (mode == 0) {
ListSelection(hDown, hHeld, touch);
SubMenuLogic(hDown, hHeld, touch);
} else if (mode == 1) {
ListSelection(hDown, hHeld, touch);
} else if (mode == 2) {
SelectFunction(hDown, hHeld, touch);
}
+17 -43
View File
@@ -137,23 +137,19 @@ void Settings::DrawColorChanging(void) const {
Gui::DrawArrow(0, 0, 0, 1);
Gui::DrawArrow(318, 22, 180.0, 1);
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 7; i++) {
if (colorMode == i) {
Gui::Draw_Rect(54 + i * 25, 2, 16, 16, C2D_Color32(140, 140, 140, 255));
}
}
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 7; i++) {
Gui::DrawString(58 + i * 25, 2, 0.5f, WHITE, std::to_string(i+1), 400);
}
if (colorMode != 7) {
Gui::Draw_Rect(buttons[0].x, buttons[0].y, 95, 41, C2D_Color32(255, 0, 0, 255));
Gui::Draw_Rect(buttons[1].x, buttons[1].y, 95, 41, C2D_Color32(0, 255, 0, 255));
Gui::Draw_Rect(buttons[2].x, buttons[2].y, 95, 41, C2D_Color32(0, 0, 255, 255));
} else {
Gui::Draw_Rect(buttons[1].x, buttons[1].y, 95, 41, Config::Color1);
}
Gui::Draw_Rect(buttons[0].x, buttons[0].y, 95, 41, C2D_Color32(255, 0, 0, 255));
Gui::Draw_Rect(buttons[1].x, buttons[1].y, 95, 41, C2D_Color32(0, 255, 0, 255));
Gui::Draw_Rect(buttons[2].x, buttons[2].y, 95, 41, C2D_Color32(0, 0, 255, 255));
if (colorMode == 0) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("BAR_COLOR"), 320);
@@ -190,10 +186,6 @@ void Settings::DrawColorChanging(void) const {
Gui::DrawString(40, 98, 0.7f, WHITE, ColorHelper::getColorName(Config::progressbarColor, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, WHITE, ColorHelper::getColorName(Config::progressbarColor, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, WHITE, ColorHelper::getColorName(Config::progressbarColor, 0).c_str(), 400);
} else if (colorMode == 7) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("USE_BARS"), 320);
if (Config::UseBars == true) Gui::DrawString(140, 98, 0.7f, WHITE, Lang::get("YES"), 400);
else if (Config::UseBars == false) Gui::DrawString(140, 98, 0.7f, WHITE, Lang::get("NO"), 400);
}
}
@@ -245,7 +237,7 @@ void Settings::DrawMiscSettings(void) const {
Gui::DrawBottom();
Gui::DrawArrow(0, 218, 0, 1);
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 2; i++) {
if (Selection == i) {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor);
} else {
@@ -253,9 +245,8 @@ void Settings::DrawMiscSettings(void) const {
}
}
Gui::DrawStringCentered(0, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_STOREPATH"), 140);
Gui::DrawStringCentered(0, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_SCRIPTPATH"), 140);
Gui::DrawStringCentered(0, mainButtons[2].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_MUSICFILE"), 140);
Gui::DrawStringCentered(0, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_MUSICFILE"), 140);
Gui::DrawStringCentered(0, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_BAR_STYLE"), 140);
}
void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
@@ -264,44 +255,30 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_DOWN) {
if (Selection < 2) Selection++;
if (Selection < 1) Selection++;
}
if (hDown & KEY_A) {
if (Selection == 0) {
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {});
if (tempStore != "") {
Config::StorePath = tempStore;
}
} else if (Selection == 1) {
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
}
} else if (Selection == 2) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2);
if (tempMusic != "") {
Config::MusicPath = tempMusic;
}
} else if (Selection == 1) {
if (Config::UseBars == true) Config::UseBars = false;
else if (Config::UseBars == false) Config::UseBars = true;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {});
if (tempStore != "") {
Config::StorePath = tempStore;
}
} else if (touching(touch, mainButtons[1])) {
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
}
} else if (touching(touch, mainButtons[2])) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2);
if (tempMusic != "") {
Config::MusicPath = tempMusic;
}
} else if (touching(touch, mainButtons[1])) {
if (Config::UseBars == true) Config::UseBars = false;
else if (Config::UseBars == false) Config::UseBars = true;
}
}
@@ -401,7 +378,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) {
int blue;
if (hDown & KEY_TOUCH) {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 7; i++) {
if(touch.px > 54 + i * 25 && touch.px < 54 + i * 25+16 && touch.py > 2 && touch.py < 2+16) {
colorMode = i;
}
@@ -418,7 +395,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) {
}
if ((hDown & KEY_R || hDown & KEY_RIGHT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if(colorMode < 7) colorMode++;
if(colorMode < 6) colorMode++;
}
if (hDown & KEY_TOUCH) {
@@ -484,9 +461,6 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) {
Config::progressbarColor = RGBA8(ColorHelper::getColorValue(Config::progressbarColor, 2), ColorHelper::getColorValue(Config::progressbarColor, 1), blue, 255);
}
}
} else if (touching(touch, buttons[1]) && colorMode == 7) {
if (Config::UseBars == true) Config::UseBars = false;
else if (Config::UseBars == false) Config::UseBars = true;
}
}
}
+119 -37
View File
@@ -147,17 +147,6 @@ void loadStoreDesc(void) {
descLines.push_back(storeDesc.substr(0, storeDesc.find('\n')));
}
UniStore::UniStore() {
dirContents.clear();
chdir(Config::StorePath.c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
}
descript();
loadStoreDesc();
}
// Store colors.
void loadStoreColors(nlohmann::json &json) {
u32 colorTemp;
@@ -183,6 +172,32 @@ void loadStoreColors(nlohmann::json &json) {
progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp;
}
void UniStore::DrawSubMenu(void) const {
Gui::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SUBMENU"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SUBMENU"), 400);
}
Gui::sprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
Gui::DrawBottom();
Gui::DrawArrow(0, 218, 0, 1);
for (int i = 0; i < 3; i++) {
if (subSelection == i) {
Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::SelectedColor);
} else {
Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor);
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("STORE_LIST")))/2, subPos[0].y+10, 0.6f, Config::TxtColor, Lang::get("STORE_LIST"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("STORE_SEARCH")))/2, subPos[1].y+10, 0.6f, Config::TxtColor, Lang::get("STORE_SEARCH"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("CHANGE_STOREPATH")))/2, subPos[2].y+10, 0.6f, Config::TxtColor, Lang::get("CHANGE_STOREPATH"), 140);
}
// First Screen -> Storelist.
void UniStore::DrawStoreList(void) const {
std::string line1;
@@ -302,26 +317,101 @@ void UniStore::DrawStore(void) const {
void UniStore::Draw(void) const {
if (mode == 0) {
DrawStoreList();
DrawSubMenu();
} else if (mode == 1) {
DrawStore();
DrawStoreList();
} else if (mode == 2) {
DrawStore();
} else if (mode == 3) {
DrawSearch();
}
}
void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Screen::back();
return;
}
if (hDown & KEY_UP) {
if(subSelection > 0) subSelection--;
}
if (hDown & KEY_DOWN) {
if(subSelection < 2) subSelection++;
}
if (hDown & KEY_A) {
switch(subSelection) {
case 0:
if (returnIfExist(Config::StorePath, {"unistore"}) == true) {
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
mode = 1;
} else {
Gui::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
break;
case 1:
if (checkWifiStatus() == true) {
mode = 3;
} else {
notConnectedMsg();
}
break;
case 2:
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {});
if (tempStore != "") {
Config::StorePath = tempStore;
}
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, subPos[0])) {
if (returnIfExist(Config::StorePath, {"unistore"}) == true) {
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
mode = 1;
} else {
Gui::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
} else if (touching(touch, subPos[1])) {
if (checkWifiStatus() == true) {
mode = 3;
} else {
notConnectedMsg();
}
} else if (touching(touch, subPos[2])) {
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {});
if (tempStore != "") {
Config::StorePath = tempStore;
}
}
}
}
void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
storeInfo.clear();
Screen::back();
return;
}
// Download / search screen.
if (hDown & KEY_TOUCH && touching(touch, arrowPos[4])) {
mode = 2;
mode = 0;
}
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
@@ -396,7 +486,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
loadStoreColors(appStoreJson);
selectedOptionAppStore = appStoreList[0];
isScriptSelected = true;
mode = 1;
mode = 2;
}
}
}
@@ -440,7 +530,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
loadStoreColors(appStoreJson);
selectedOptionAppStore = appStoreList[0];
isScriptSelected = true;
mode = 1;
mode = 2;
}
}
}
@@ -460,7 +550,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
loadStoreColors(appStoreJson);
selectedOptionAppStore = appStoreList[0];
isScriptSelected = true;
mode = 1;
mode = 2;
}
}
}
@@ -472,7 +562,7 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
mode = 0;
mode = 1;
appStoreList.clear();
isScriptSelected = false;
selection2 = 0;
@@ -563,15 +653,17 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) {
void UniStore::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (mode == 0) {
StoreSelectionLogic(hDown, hHeld, touch);
SubMenuLogic(hDown, hHeld, touch);
} else if (mode == 1) {
StoreLogic(hDown, hHeld, touch);
StoreSelectionLogic(hDown, hHeld, touch);
} else if (mode == 2) {
StoreLogic(hDown, hHeld, touch);
} else if (mode == 3) {
SearchLogic(hDown, hHeld, touch);
}
// Switch ViewMode.
if (((mode != 2) && (hDown & KEY_X)) || ((mode != 2) && (hDown & KEY_TOUCH && touching(touch, arrowPos[3])))) {
if (((mode != 0 || mode != 3) && (hDown & KEY_X)) || ((mode != 0 || mode != 3) && (hDown & KEY_TOUCH && touching(touch, arrowPos[3])))) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
} else {
@@ -706,16 +798,6 @@ void UniStore::DrawSearch(void) const {
void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
// Refresh the list.
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
mode = 0;
}
+16 -1
View File
@@ -25,7 +25,7 @@ extern bool continueNdsScan;
extern uint selectedFile;
extern int keyRepeatDelay;
extern bool dirChanged;
extern std::vector<DirEntry> dirContents;
std::vector<DirEntry> dirContents;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern touchPosition touch;
@@ -191,6 +191,21 @@ std::vector<std::string> getContents(const std::string &name, const std::vector<
return dirContents;
}
// Directory exist?
bool returnIfExist(const std::string &path, const std::vector<std::string> &extensionList) {
dirContents.clear();
chdir(path.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i=0;i<dirContentsTemp.size();i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
// returns a Path or file to 'std::string'.
// selectText is the Text which is displayed on the bottom bar of the top screen.
// selectionMode is how you select it. 1 -> Path, 2 -> File.