Add Settings Stuff. :P

This commit is contained in:
VoltZ
2019-11-02 04:32:23 +01:00
committed by GitHub
parent 44c31c46d5
commit 7ee50d5418
16 changed files with 907 additions and 39 deletions
+59
View File
@@ -0,0 +1,59 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef COLORS_HPP
#define COLORS_HPP
#include <citro2d.h>
#include <citro3d.h>
#include <sstream>
#include <string>
/**
* @brief Creates a 8 byte RGBA color
* @param r red component of the color
* @param g green component of the color
* @param b blue component of the color
* @param a alpha component of the color
*/
#define RGBA8(r, g, b, a) ((((r)&0xFF)<<0) | (((g)&0xFF)<<8) | (((b)&0xFF)<<16) | (((a)&0xFF)<<24))
#define BarColor C2D_Color32(57, 84, 114, 255)
#define TopBGColor C2D_Color32(96, 168, 192, 255)
#define BottomBGColor C2D_Color32(38, 44, 77, 255)
#define SelectedColordefault C2D_Color32(120, 192, 216, 255)
#define UnselectedColordefault C2D_Color32(77, 118, 132, 255)
#define BLACK C2D_Color32(0, 0, 0, 255)
#define WHITE C2D_Color32(255, 255, 255, 255)
typedef u32 Color;
namespace ColorHelper {
int getColorValue(int color, int bgr);
std::string getColorName(int color, int bgr);
}
#endif
+1 -9
View File
@@ -27,6 +27,7 @@
#ifndef GUI_HPP
#define GUI_HPP
#include "colors.hpp"
#include "screens/screen.hpp"
#include <3ds.h>
@@ -38,15 +39,6 @@
#include <unordered_map>
#include <wchar.h>
#define BarColor C2D_Color32(57, 84, 114, 255)
#define TopBGColor C2D_Color32(96, 168, 192, 255)
#define BottomBGColor C2D_Color32(38, 44, 77, 255)
#define SelectedColor C2D_Color32(120, 192, 216, 255)
#define UnselectedColor C2D_Color32(77, 118, 132, 255)
#define BLACK C2D_Color32(0, 0, 0, 255)
#define WHITE C2D_Color32(255, 255, 255, 255)
#define TextColor C2D_Color32(102, 179, 255, 255)
namespace Gui
{
// Init and Exit of the GUI.
+14
View File
@@ -0,0 +1,14 @@
#ifndef KEYBOARD_HPP
#define KEYBOARD_HPP
#include <string>
namespace Input {
void DrawNumpad();
std::string Numpad(std::string Text);
std::string Numpad(uint maxLength, std::string Text);
// -1 if invaild text entered
int getUint(int max, std::string Text);
}
#endif
+4 -1
View File
@@ -31,15 +31,18 @@
#include "utils/structs.hpp"
#include <vector>
class MainMenu : public Screen
{
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
private:
int Selection = 0;
std::vector<Structs::ButtonPos> mainButtons = {
{90, 40, 140, 35, -1}, // ScriptList.
{90, 160, 140, 35, -1}, // Settings?
{90, 100, 140, 35, -1}, // Language.
{90, 160, 140, 35, -1}, // Colors.
};
};
+67
View File
@@ -0,0 +1,67 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef SETTINGS_HPP
#define SETTINGS_HPP
#include "screens/screen.hpp"
#include "screens/screenCommon.hpp"
#include "utils/structs.hpp"
#include <vector>
class Settings : public Screen
{
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
private:
void DrawLanguageSelection(void) const;
void DrawColorChanging(void) const;
void LanguageSelection(u32 hDown, touchPosition touch);
void colorChanging(u32 hDown, touchPosition touch);
std::vector<Structs::ButtonPos> langBlocks = {
{37, 52, 20, 20, -1},
{37, 92, 20, 20, -1},
{37, 132, 20, 20, -1},
{37, 172, 20, 20, -1},
{177, 52, 20, 20, -1},
{177, 92, 20, 20, -1},
{177, 132, 20, 20, -1},
{177, 172, 20, 20, -1},
{293, 213, 27, 27, -1},
};
std::vector<Structs::ButtonPos> buttons = {
{10, 85, 95, 41, -1},
{115, 85, 95, 41, -1},
{220, 85, 95, 41, -1},
};
};
#endif
+42
View File
@@ -0,0 +1,42 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CONFIG_HPP
#define CONFIG_HPP
#include <string>
namespace Config {
// [UI]
extern int lang; // The current Language.
extern int Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor; // Colors!
void loadConfig();
void saveConfig();
}
#endif
+6
View File
@@ -39,6 +39,12 @@ public:
int h;
int link;
};
struct Key {
std::string character;
int x;
int y;
};
private:
};
+15 -6
View File
@@ -9,11 +9,20 @@
"FILE_EXTRACTED": "file extracted.",
"FILES_EXTRACTED": "files extracted.",
"DOWNLOAD_NDSBOOTSTRAP_NIGHTLY": "Downloading nds-bootstrap...\n(Nightly)",
"EXTRACT_NDSBOOTSTRAP_NIGHTLY": "Extracting nds-bootstrap...\n(Nightly)",
"DOWNLOAD_NDSBOOTSTRAP_RELEASE": "Downloading nds-bootstrap...\n(Release)",
"EXTRACT_NDSBOOTSTRAP_RELEASE": "Extracting nds-bootstrap...\n(Release)",
"SCRIPTLIST": "Scriptlist",
"SETTINGS": "Settings"
"LANGUAGE": "Language",
"COLORS": "Colors",
"SELECT_LANG": "Choose the current language.",
"BAR_COLOR": "Bar Color",
"TOP_BG_COLOR": "Top Background Color",
"BOTTOM_BG_COLOR": "Bottom Background Color",
"TEXT_COLOR": "Text Color",
"SELECTED_COLOR": "Selected Color",
"UNSELECTED_COLOR": "Unselected Color",
"ENTER_RED_RGB": "Enter the Red RGB.",
"ENTER_GREEN_RGB": "Enter the Green RGB.",
"ENTER_BLUE_RGB": "Enter the Blue RGB."
}
+49
View File
@@ -0,0 +1,49 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "colors.hpp"
int ColorHelper::getColorValue(int color, int bgr)
{
char colorName[10];
int i;
std::stringstream ss;
itoa(color, colorName, 16);
std::string colorNamePart(colorName, 2*bgr+2, 2);
ss << std::hex << colorNamePart.c_str();
ss >> i;
return i;
}
std::string ColorHelper::getColorName(int color, int bgr)
{
char colorName[10];
int i = getColorValue(color, bgr);
itoa(i, colorName, 10);
return colorName;
}
+9 -7
View File
@@ -28,6 +28,8 @@
#include "screens/screenCommon.hpp"
#include "utils/config.hpp"
#include <3ds.h>
#include <assert.h>
#include <stdarg.h>
@@ -74,7 +76,7 @@ void DisplayMsg(std::string text) {
C2D_TargetClear(top, BLACK);
C2D_TargetClear(bottom, BLACK);
Gui::DrawTop();
Gui::DrawString(10, 40, 0.45f, WHITE, text, 380);
Gui::DrawString(10, 40, 0.45f, Config::TxtColor, text, 380);
Gui::DrawBottom();
C3D_FrameEnd(0);
}
@@ -146,14 +148,14 @@ void Gui::ScreenDraw(C3D_RenderTarget * screen)
void Gui::DrawTop(void) {
Gui::ScreenDraw(top);
Gui::Draw_Rect(0, 0, 400, 30, BarColor);
Gui::Draw_Rect(0, 30, 400, 180, TopBGColor);
Gui::Draw_Rect(0, 210, 400, 30, BarColor);
Gui::Draw_Rect(0, 0, 400, 30, Config::Color1);
Gui::Draw_Rect(0, 30, 400, 180, Config::Color2);
Gui::Draw_Rect(0, 210, 400, 30, Config::Color1);
}
void Gui::DrawBottom(void) {
Gui::ScreenDraw(bottom);
Gui::Draw_Rect(0, 0, 320, 30, BarColor);
Gui::Draw_Rect(0, 30, 320, 180, BottomBGColor);
Gui::Draw_Rect(0, 210, 320, 30, BarColor);
Gui::Draw_Rect(0, 0, 320, 30, Config::Color1);
Gui::Draw_Rect(0, 30, 320, 180, Config::Color3);
Gui::Draw_Rect(0, 210, 320, 30, Config::Color1);
}
+152
View File
@@ -0,0 +1,152 @@
#include "gui.hpp"
#include "keyboard.hpp"
#include "utils/config.hpp"
#include "utils/structs.hpp"
#include <string>
#include <stdio.h>
#include <ctype.h>
extern C3D_RenderTarget* top;
extern C3D_RenderTarget* bottom;
bool caps = false, enter = false;
int shift = 0;
Structs::Key NumpadStruct[] = {
{"1", 10, 30},
{"2", 90, 30},
{"3", 170, 30},
{"4", 10, 100},
{"5", 90, 100},
{"6", 170, 100},
{"7", 10, 170},
{"8", 90, 170},
{"9", 170, 170},
{"0", 250, 100},
{"Enter", 250, 170},
{"Backspace", 250, 30},
};
Structs::ButtonPos Numbers [] = {
{10, 30, 60, 50}, // 1
{90, 30, 60, 50}, // 2
{170, 30, 60, 50}, // 3
{10, 100, 60, 50},
{90, 100, 60, 50},
{170, 100, 60, 50},
{10, 170, 60, 50},
{90, 170, 60, 50},
{170, 170, 60, 50},
{250, 100, 60, 50}, // 0.
{250, 170, 60, 50}, // Enter.
{250, 30, 60, 50}, // Backspace.
};
extern bool touching(touchPosition touch, Structs::ButtonPos button);
void Input::DrawNumpad()
{
for(uint i=0;i<(sizeof(NumpadStruct)/sizeof(NumpadStruct[0]));i++) {
Gui::Draw_Rect(NumpadStruct[i].x, NumpadStruct[i].y, 60, 50, Config::Color3);
char c[2] = {NumpadStruct[i].character[0]};
Gui::DrawString(NumpadStruct[i].x+25, NumpadStruct[i].y+15, 0.72f, BLACK, c, 50);
}
}
std::string Input::Numpad(std::string Text) { return Input::Numpad(-1, Text); }
std::string Input::Numpad(uint maxLength, std::string Text)
{
int hDown;
touchPosition touch;
std::string string;
int keyDownDelay = 10, cursorBlink = 20;
enter = false;
while(1) {
do {
C3D_FrameEnd(0);
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(top, BLACK);
C2D_TargetClear(bottom, BLACK);
Gui::DrawTop();
Gui::DrawString((400-Gui::GetStringWidth(0.8f, Text))/2, 2, 0.8f, WHITE, Text, 400);
Gui::DrawString(180, 212, 0.8, WHITE, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400);
if(cursorBlink < -20) cursorBlink = 20;
Gui::ScreenDraw(bottom);
Gui::Draw_Rect(0, 0, 320, 240, Config::Color3);
DrawNumpad();
scanKeys();
hDown = keysDown();
if(keyDownDelay > 0) {
keyDownDelay--;
} else if(keyDownDelay == 0) {
keyDownDelay--;
}
} while(!hDown);
if(keyDownDelay > 0) {
}
keyDownDelay = 10;
if(hDown & KEY_TOUCH) {
touchRead(&touch);
if(string.length() < maxLength) {
if (touching(touch, Numbers[0])) {
string += "1";
} else if (touching(touch, Numbers[1])) {
string += "2";
} else if (touching(touch, Numbers[2])) {
string += "3";
} else if (touching(touch, Numbers[3])) {
string += "4";
} else if (touching(touch, Numbers[4])) {
string += "5";
} else if (touching(touch, Numbers[5])) {
string += "6";
} else if (touching(touch, Numbers[6])) {
string += "7";
} else if (touching(touch, Numbers[7])) {
string += "8";
} else if (touching(touch, Numbers[8])) {
string += "9";
} else if (touching(touch, Numbers[9])) {
string += "0";
}
}
}
if(hDown & KEY_B || touching(touch, Numbers[11])) {
string = string.substr(0, string.length()-1);
}
if(hDown & KEY_START || touching(touch, Numbers[10]) || enter) {
break;
}
}
return string;
enter = false;
}
int Input::getUint(int max, std::string Text) {
std::string s = Input::Numpad(3, Text);
if(s == "" || (atoi(s.c_str()) == 0 && s[0] != '0')) return -1;
int i = atoi(s.c_str());
if(i>max) return 255;
return i;
}
+9 -1
View File
@@ -31,10 +31,12 @@
#include "screens/mainMenu.hpp"
#include "screens/screenCommon.hpp"
#include "utils/config.hpp"
#include "utils/structs.hpp"
#include <3ds.h>
#include <dirent.h>
#include <unistd.h>
bool exiting = false;
@@ -55,12 +57,18 @@ int main()
romfsInit();
sdmcInit();
cfguInit();
Lang::load(1);
// Create Folder if missing.
mkdir("sdmc:/3ds", 0777);
mkdir("sdmc:/3ds/Universal-Updater", 0777);
mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777);
Config::loadConfig();
// We need to make sure, the file exist.
if(access("sdmc:/3ds/Universal-Updater/Settings.ini", F_OK) == -1 ) {
Config::saveConfig();
}
Lang::load(1);
Gui::setScreen(std::make_unique<MainMenu>());
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
+45 -7
View File
@@ -25,22 +25,32 @@
*/
#include "screens/mainMenu.hpp"
#include "screens/settings.hpp"
#include "screens/scriptlist.hpp"
#include "utils/config.hpp"
extern int mode;
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
void MainMenu::Draw(void) const {
Gui::DrawTop();
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
Gui::DrawString(395-Gui::GetStringWidth(0.72f, VERSION_STRING), 218, 0.72f, WHITE, VERSION_STRING);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawString(395-Gui::GetStringWidth(0.72f, VERSION_STRING), 218, 0.72f, Config::TxtColor, VERSION_STRING);
Gui::DrawBottom();
// Draw 2 'Buttons'.
Gui::Draw_Rect(mainButtons[0].x, mainButtons[0].y, mainButtons[0].w, mainButtons[0].h, TopBGColor);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2, mainButtons[0].y+10, 0.6f, WHITE, Lang::get("SCRIPTLIST"), 140);
Gui::Draw_Rect(mainButtons[1].x, mainButtons[1].y, mainButtons[1].w, mainButtons[1].h, TopBGColor);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2, mainButtons[1].y+10, 0.6f, WHITE, Lang::get("SETTINGS"), 140);
for (int i = 0; i < 3; i++) {
if (Selection == i) {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor);
} else {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor);
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("LANGUAGE")))/2, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("LANGUAGE"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("COLORS")))/2, mainButtons[2].y+10, 0.6f, Config::TxtColor, Lang::get("COLORS"), 140);
}
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
@@ -48,9 +58,37 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
exiting = true;
}
if (hDown & KEY_UP) {
if(Selection > 0) Selection--;
} else if (hDown & KEY_DOWN) {
if(Selection < 2) Selection++;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
Gui::setScreen(std::make_unique<ScriptList>());
break;
case 1:
mode = 0;
Gui::setScreen(std::make_unique<Settings>());
break;
case 2:
mode = 0;
Gui::setScreen(std::make_unique<Settings>());
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Gui::setScreen(std::make_unique<ScriptList>());
} else if (touching(touch, mainButtons[1])) {
mode = 0;
Gui::setScreen(std::make_unique<Settings>());
} else if (touching(touch, mainButtons[2])) {
mode = 1;
Gui::setScreen(std::make_unique<Settings>());
}
}
}
+9 -8
View File
@@ -29,6 +29,7 @@
#include "screens/mainMenu.hpp"
#include "screens/scriptlist.hpp"
#include "utils/config.hpp"
#include "utils/parse.hpp"
#include <algorithm>
@@ -138,16 +139,16 @@ ScriptList::ScriptList() {
void ScriptList::DrawList(void) const {
std::string titleinfo;
Gui::DrawTop();
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawBottom();
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size();i++) {
titleinfo = fileInfo[screenPos + i].title + '\n' + fileInfo[screenPos + i].description;
if(screenPos + i == selection) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, SelectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::SelectedColor);
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, UnselectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
}
Gui::DrawString(0, 40+(i*57), 0.7f, WHITE, titleinfo, 320);
Gui::DrawString(0, 40+(i*57), 0.7f, Config::TxtColor, titleinfo, 320);
}
}
@@ -163,16 +164,16 @@ void ScriptList::Draw(void) const {
void ScriptList::DrawSingleObject(void) const {
std::string info;
Gui::DrawTop();
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawBottom();
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo2.size();i++) {
info = fileInfo2[screenPos2 + i];
if(screenPos2 + i == selection2) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, SelectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::SelectedColor);
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, UnselectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
}
Gui::DrawString(0, 40+(i*57), 0.7f, WHITE, info, 320);
Gui::DrawString(0, 40+(i*57), 0.7f, Config::TxtColor, info, 320);
}
}
+357
View File
@@ -0,0 +1,357 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "keyboard.hpp"
#include "screens/settings.hpp"
#include "utils/config.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
int mode;
int colorMode = 0;
void Settings::Draw(void) const {
if (mode == 0) {
DrawLanguageSelection();
} else if (mode == 1) {
DrawColorChanging();
}
}
void Settings::DrawLanguageSelection(void) const {
Gui::DrawTop();
Gui::DrawString((400-Gui::GetStringWidth(0.8f, Lang::get("SELECT_LANG")))/2, 2, 0.8f, Config::TxtColor, Lang::get("SELECT_LANG"), 400);
Gui::DrawBottom();
if (Config::lang == 0) {
Gui::Draw_Rect(37, 52, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 1) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 2) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 3) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 4) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 5) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::SelectedColor);
} else if (Config::lang == 6) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
} else if (Config::lang == 7) {
Gui::Draw_Rect(37, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 132, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(37, 172, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 52, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 92, 20, 20, Config::UnselectedColor);
Gui::Draw_Rect(177, 132, 20, 20, Config::SelectedColor);
Gui::Draw_Rect(177, 172, 20, 20, Config::UnselectedColor);
}
Gui::DrawString(langBlocks[0].x+25, langBlocks[0].y-2, 0.7f, Config::TxtColor, "Deutsch", 320);
Gui::DrawString(langBlocks[1].x+25, langBlocks[1].y-2, 0.7f, Config::TxtColor, "English", 320);
Gui::DrawString(langBlocks[2].x+25, langBlocks[2].y-2, 0.7f, Config::TxtColor, "Español", 320);
Gui::DrawString(langBlocks[3].x+25, langBlocks[3].y-2, 0.7f, Config::TxtColor, "Français", 320);
Gui::DrawString(langBlocks[4].x+25, langBlocks[4].y-2, 0.7f, Config::TxtColor, "Italiano", 320);
Gui::DrawString(langBlocks[5].x+25, langBlocks[5].y-2, 0.7f, Config::TxtColor, "Lietuvių", 320);
Gui::DrawString(langBlocks[6].x+25, langBlocks[6].y-2, 0.7f, Config::TxtColor, "Português", 320);
Gui::DrawString(langBlocks[7].x+25, langBlocks[7].y-2, 0.7f, Config::TxtColor, "日本語", 320);
}
void Settings::DrawColorChanging(void) const {
Gui::DrawTop();
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
if (colorMode == 3) {
Gui::Draw_Rect(0, 40, 400, 45, Config::SelectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("TEXT_COLOR"), 320);
} else if (colorMode == 4) {
Gui::Draw_Rect(0, 40, 400, 45, Config::SelectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("SELECTED_COLOR"), 320);
} else if (colorMode == 5) {
Gui::Draw_Rect(0, 40, 400, 45, Config::UnselectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("UNSELECTED_COLOR"), 320);
}
Gui::DrawBottom();
for (int i = 0; i < 6; i++) {
if (colorMode == i) {
Gui::Draw_Rect(25 + i * 25, 5, 16, 16, Config::SelectedColor);
}
}
Gui::DrawString(29 + 0 * 25, 5, 0.5f, Config::TxtColor, "1", 400);
Gui::DrawString(29 + 1 * 25, 5, 0.5f, Config::TxtColor, "2", 400);
Gui::DrawString(29 + 2 * 25, 5, 0.5f, Config::TxtColor, "3", 400);
Gui::DrawString(29 + 3 * 25, 5, 0.5f, Config::TxtColor, "4", 400);
Gui::DrawString(29 + 4 * 25, 5, 0.5f, Config::TxtColor, "5", 400);
Gui::DrawString(29 + 5 * 25, 5, 0.5f, Config::TxtColor, "6", 400);
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);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color1, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color1, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color1, 0).c_str(), 400);
} else if (colorMode == 1) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("TOP_BG_COLOR"), 320);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color2, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color2, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color2, 0).c_str(), 400);
} else if (colorMode == 2) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("BOTTOM_BG_COLOR"), 320);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color3, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color3, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::Color3, 0).c_str(), 400);
} else if (colorMode == 3) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("TEXT_COLOR"), 320);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::TxtColor, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::TxtColor, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::TxtColor, 0).c_str(), 400);
} else if (colorMode == 4) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("SELECTED_COLOR"), 320);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::SelectedColor, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::SelectedColor, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::SelectedColor, 0).c_str(), 400);
} else if (colorMode == 5) {
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("UNSELECTED_COLOR"), 320);
Gui::DrawString(40, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::UnselectedColor, 2).c_str(), 400);
Gui::DrawString(140, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::UnselectedColor, 1).c_str(), 400);
Gui::DrawString(245, 98, 0.7f, Config::TxtColor, ColorHelper::getColorName(Config::UnselectedColor, 0).c_str(), 400);
}
}
void Settings::LanguageSelection(u32 hDown, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (touching(touch, langBlocks[0])) {
Config::lang = 0;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[1])) {
Config::lang = 1;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[2])) {
Config::lang = 2;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[3])) {
Config::lang = 3;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[4])) {
Config::lang = 4;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[5])) {
Config::lang = 6;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[6])) {
Config::lang = 7;
Lang::load(Config::lang);
Config::saveConfig();
} else if (touching(touch, langBlocks[7])) {
Config::lang = 5;
Lang::load(Config::lang);
Config::saveConfig();
}
}
if (hDown & KEY_B) {
Gui::screenBack();
return;
}
}
void Settings::colorChanging(u32 hDown, touchPosition touch) {
int red;
int green;
int blue;
if (hDown & KEY_B) {
Config::saveConfig();
Gui::screenBack();
return;
}
if (hDown & KEY_L || hDown & KEY_LEFT) {
if(colorMode > 0) colorMode--;
}
if (hDown & KEY_R || hDown & KEY_RIGHT) {
if(colorMode < 5) colorMode++;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, buttons[0])) {
int temp = Input::getUint(255, Lang::get("ENTER_RED_RGB"));
if(temp != -1) {
red = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(red, ColorHelper::getColorValue(Config::Color1, 1), ColorHelper::getColorValue(Config::Color1, 0), 255);
} else if (colorMode == 1) {
Config::Color2 = RGBA8(red, ColorHelper::getColorValue(Config::Color2, 1), ColorHelper::getColorValue(Config::Color2, 0), 255);
} else if (colorMode == 2) {
Config::Color3 = RGBA8(red, ColorHelper::getColorValue(Config::Color3, 1), ColorHelper::getColorValue(Config::Color3, 0), 255);
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(red, ColorHelper::getColorValue(Config::TxtColor, 1), ColorHelper::getColorValue(Config::TxtColor, 0), 255);
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(red, ColorHelper::getColorValue(Config::SelectedColor, 1), ColorHelper::getColorValue(Config::SelectedColor, 0), 255);
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(red, ColorHelper::getColorValue(Config::UnselectedColor, 1), ColorHelper::getColorValue(Config::UnselectedColor, 0), 255);
}
}
} else if (touching(touch, buttons[1])) {
int temp = Input::getUint(255, Lang::get("ENTER_GREEN_RGB"));
if(temp != -1) {
green = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(ColorHelper::getColorValue(Config::Color1, 2), green, ColorHelper::getColorValue(Config::Color1, 0), 255);
} else if (colorMode == 1) {
Config::Color2 = RGBA8(ColorHelper::getColorValue(Config::Color2, 2), green, ColorHelper::getColorValue(Config::Color2, 0), 255);
} else if (colorMode == 2) {
Config::Color3 = RGBA8(ColorHelper::getColorValue(Config::Color3, 2), green, ColorHelper::getColorValue(Config::Color3, 0), 255);
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(ColorHelper::getColorValue(Config::TxtColor, 2), green, ColorHelper::getColorValue(Config::TxtColor, 0), 255);
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(ColorHelper::getColorValue(Config::SelectedColor, 2), green, ColorHelper::getColorValue(Config::SelectedColor, 0), 255);
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(ColorHelper::getColorValue(Config::UnselectedColor, 2), green, ColorHelper::getColorValue(Config::UnselectedColor, 0), 255);
}
}
} else if (touching(touch, buttons[2])) {
int temp = Input::getUint(255, Lang::get("ENTER_BLUE_RGB"));
if(temp != -1) {
blue = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(ColorHelper::getColorValue(Config::Color1, 2), ColorHelper::getColorValue(Config::Color1, 1), blue, 255);
} else if (colorMode == 1) {
Config::Color2 = RGBA8(ColorHelper::getColorValue(Config::Color2, 2), ColorHelper::getColorValue(Config::Color2, 1), blue, 255);
} else if (colorMode == 2) {
Config::Color3 = RGBA8(ColorHelper::getColorValue(Config::Color3, 2), ColorHelper::getColorValue(Config::Color3, 1), blue, 255);
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(ColorHelper::getColorValue(Config::TxtColor, 2), ColorHelper::getColorValue(Config::TxtColor, 1), blue, 255);
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(ColorHelper::getColorValue(Config::SelectedColor, 2), ColorHelper::getColorValue(Config::SelectedColor, 1), blue, 255);
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(ColorHelper::getColorValue(Config::UnselectedColor, 2), ColorHelper::getColorValue(Config::UnselectedColor, 1), blue, 255);
}
}
}
}
}
void Settings::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (mode == 0) {
LanguageSelection(hDown, touch);
} else if (mode == 1) {
colorChanging(hDown, touch);
}
}
+69
View File
@@ -0,0 +1,69 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "gui.hpp"
#include "utils/inifile.h"
#include "utils/config.hpp"
#include <string>
#include <unistd.h>
using std::string;
using std::wstring;
static CIniFile settingsini( "sdmc:/3ds/Universal-Updater/Settings.ini" );
int Config::lang; // Current Language.
int Config::Color1;
int Config::Color2;
int Config::Color3;
int Config::TxtColor;
int Config::SelectedColor;
int Config::UnselectedColor;
void Config::loadConfig() {
// [UI]
Config::lang = settingsini.GetInt("UI", "LANGUAGE", 1);
Config::Color1 = settingsini.GetInt("UI", "BARCOLOR", BarColor);
Config::Color2 = settingsini.GetInt("UI", "TOPBGCOLOR", TopBGColor);
Config::Color3 = settingsini.GetInt("UI", "BOTTOMBGCOLOR", BottomBGColor);
Config::TxtColor = settingsini.GetInt("UI", "TEXTCOLOR", WHITE);
Config::SelectedColor = settingsini.GetInt("UI", "SELECTEDCOLOR", SelectedColordefault);
Config::UnselectedColor = settingsini.GetInt("UI", "UNSELECTEDCOLOR", UnselectedColordefault);
}
void Config::saveConfig() {
// [UI]
settingsini.SetInt("UI", "LANGUAGE", Config::lang);
settingsini.SetInt("UI", "BARCOLOR", Config::Color1);
settingsini.SetInt("UI", "TOPBGCOLOR", Config::Color2);
settingsini.SetInt("UI", "BOTTOMBGCOLOR", Config::Color3);
settingsini.SetInt("UI", "TEXTCOLOR", Config::TxtColor);
settingsini.SetInt("UI", "SELECTEDCOLOR", Config::SelectedColor);
settingsini.SetInt("UI", "UNSELECTEDCOLOR", Config::UnselectedColor);
settingsini.SaveIniFile("sdmc:/3ds/Universal-Updater/Settings.ini");
}