diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..11d863d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Universal-Core"] + path = Universal-Core + url = https://github.com/Universal-Team/Universal-Core.git diff --git a/Makefile b/Makefile index bce14e4..294980c 100644 --- a/Makefile +++ b/Makefile @@ -75,9 +75,10 @@ endif #--------------------------------------------------------------------------------- TARGET := Universal-Updater BUILD := build -SOURCES := source source/download source/lang source/screens source/utils +UNIVCORE := Universal-Core +SOURCES := $(UNIVCORE) source source/download source/lang source/screens source/utils DATA := data -INCLUDES := include include/download include/lang include/screens include/utils +INCLUDES := $(UNIVCORE) include include/download include/lang include/screens include/utils GRAPHICS := assets/gfx #GFXBUILD := $(BUILD) ROMFS := romfs diff --git a/Universal-Core b/Universal-Core new file mode 160000 index 0000000..c82ad8d --- /dev/null +++ b/Universal-Core @@ -0,0 +1 @@ +Subproject commit c82ad8d6e11e4842c6099b53595aa3692f24910b diff --git a/assets/gfx/sprites/credits/stackZ.png b/assets/gfx/sprites/credits/stackZ.png index d84b165..0c186b0 100644 Binary files a/assets/gfx/sprites/credits/stackZ.png and b/assets/gfx/sprites/credits/stackZ.png differ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4cc6006..c527d30 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,7 @@ trigger: branches: include: ['*'] - exclude: [translation, cleanup] + exclude: [translation, cleanup, full-rewrite] tags: include: ['*'] @@ -39,6 +39,7 @@ steps: sudo 7z e makerom_015_ctrtool.zip Linux_x86_64/makerom sudo chmod +x makerom rm makerom_015_ctrtool.zip + git submodule update --init --recursive displayName: 'Setup devkitPro' - script: | diff --git a/include/colors.hpp b/include/colorHelper.hpp similarity index 84% rename from include/colors.hpp rename to include/colorHelper.hpp index e28e6fc..25f8f32 100644 --- a/include/colors.hpp +++ b/include/colorHelper.hpp @@ -1,59 +1,60 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 -#include -#include -#include - -/** - * @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); -} - +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 COLORHELPER_HPP +#define COLORHELPER_HPP + +#include +#include +#include +#include + +/** + * @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) +#define TRANSPARENT C2D_Color32(0, 0, 0, 0) + +typedef u32 Color; + +namespace ColorHelper { + int getColorValue(int color, int bgr); + std::string getColorName(int color, int bgr); +} + #endif \ No newline at end of file diff --git a/include/download/download.hpp b/include/download/download.hpp index 5fed430..11ca685 100644 --- a/include/download/download.hpp +++ b/include/download/download.hpp @@ -24,12 +24,13 @@ * reasonable ways as different from the original version. */ -#pragma once +#ifndef DOWNLOAD_HPP +#define DOWNLOAD_HPP -#include "utils/common.hpp" +#include "common.hpp" #define APP_TITLE "Universal-Updater" -#define VERSION_STRING "2.2.0" +#define VERSION_STRING "2.2.1" enum DownloadError { DL_ERROR_NONE = 0, @@ -86,4 +87,6 @@ std::string getLatestCommit(std::string repo, std::string item); * item is that to get from the API. (Ex. "message") * @return the string from the API. */ -std::string getLatestCommit(std::string repo, std::string array, std::string item); \ No newline at end of file +std::string getLatestCommit(std::string repo, std::string array, std::string item); + +#endif \ No newline at end of file diff --git a/include/screens/screen.hpp b/include/gfx.hpp similarity index 73% rename from include/screens/screen.hpp rename to include/gfx.hpp index 1c61364..b6aa6e1 100644 --- a/include/screens/screen.hpp +++ b/include/gfx.hpp @@ -1,49 +1,46 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 SCREEN_HPP -#define SCREEN_HPP - -#include <3ds.h> -#include - -class screen -{ -public: - virtual ~screen() {} - virtual void Logic(u32 hDown, u32 hHeld, touchPosition touch) = 0; - virtual void Draw() const = 0; -private: -}; - -namespace Screen { - void set(std::unique_ptr screen2); - void fade(std::unique_ptr screen2, bool fadeout = true); - void back(void); - void loop(u32 hDown, u32 hHeld, touchPosition touch); -} - +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 GFX_HPP +#define GFX_HPP + +#include "colorHelper.hpp" +#include "gui.hpp" +#include "sprites.h" + +namespace GFX +{ + // Basic GUI. + void DrawTop(void); + void DrawBottom(void); + // Draw arrow. + void DrawArrow(int x, int y, float rotation = 0, int arrowSprite = 0); + // Draw Sprites. + void DrawSprite(int img, int x, int y, float ScaleX = 1, float ScaleY = 1); + void DrawSpriteBlend(int img, int x, int y, float ScaleX = 1, float ScaleY = 1); +} + #endif \ No newline at end of file diff --git a/include/gui.hpp b/include/gui.hpp deleted file mode 100644 index 414f79d..0000000 --- a/include/gui.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 GUI_HPP -#define GUI_HPP - -#include "colors.hpp" -#include "sprites.h" - -#include "screens/screen.hpp" - -namespace Gui -{ - // Init and Exit of the GUI. - Result init(void); - void exit(void); - - C3D_RenderTarget* target(gfxScreen_t t); - void setDraw(C3D_RenderTarget * screen); - - // Clear Text. - void clearTextBufs(void); - - // Draw a Sprite from the sheet. - void sprite(int key, int x, int y, float ScaleX = 1, float ScaleY = 1); - void spriteBlend(int key, int x, int y, float ScaleX = 1, float ScaleY = 1); - void DrawArrow(int x, int y, float rotation = 0, int arrowSprite = 0); - void drawAnimatedSelector(float xPos, float yPos, float Width, float Height, float speed = .060, u32 colour = C2D_Color32(0, 0, 0, 0)); - - // Misc. - bool Draw_Rect(float x, float y, float w, float h, u32 color); - - // Text / String Functions. - void DrawStringCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0); - void DrawString(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0); - void GetStringSize(float size, float *width, float *height, std::string Text); - float GetStringWidth(float size, std::string Text); - float GetStringHeight(float size, std::string Text); - - // Basic GUI. - void DrawTop(void); - void DrawBottom(void); - - void DisplayWarnMsg(std::string Text); - bool promptMsg(std::string promptMsg); -} - -void DisplayMsg(std::string text); - -#endif \ No newline at end of file diff --git a/include/utils/structs.hpp b/include/init.hpp similarity index 81% rename from include/utils/structs.hpp rename to include/init.hpp index 497265d..389d70a 100644 --- a/include/utils/structs.hpp +++ b/include/init.hpp @@ -1,52 +1,44 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 STRUCTS_HPP -#define STRUCTS_HPP - -#include - -class Structs -{ -public: - struct ButtonPos { - int x; - int y; - int w; - int h; - int link; - }; - - struct Key { - std::string character; - int x; - int y; - int w; - }; -private: -}; - +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 INIT_HPP +#define INIT_HPP + +#include <3ds.h> + +namespace Init { + // Init, Mainloop & Exit. + Result Initialize(); + Result MainLoop(); + Result Exit(); + + // Sound / Music stuff. + void loadSoundEffects(void); + void playMusic(void); + void stopMusic(void); +} + #endif \ No newline at end of file diff --git a/include/lang/lang.hpp b/include/lang/lang.hpp index e4e7c9a..2f6c705 100644 --- a/include/lang/lang.hpp +++ b/include/lang/lang.hpp @@ -1,7 +1,7 @@ #ifndef LANG_HPP #define LANG_HPP -#include "utils/json.hpp" +#include "json.hpp" #include diff --git a/include/screens/screenCommon.hpp b/include/msg.hpp similarity index 86% rename from include/screens/screenCommon.hpp rename to include/msg.hpp index 3ff6dad..1a0a21c 100644 --- a/include/screens/screenCommon.hpp +++ b/include/msg.hpp @@ -1,37 +1,39 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 SCREENCOMMON_HPP -#define SCREENCOMMON_HPP - -#include "gui.hpp" - -#include "lang/lang.hpp" - -extern C3D_RenderTarget* top; -extern C3D_RenderTarget* bottom; - +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 MSG_HPP +#define MSG_HPP + +#include + +namespace Msg +{ + void DisplayMsg(std::string text); + void DisplayWarnMsg(std::string Text); + bool promptMsg(std::string promptMsg); +} + #endif \ No newline at end of file diff --git a/include/screens/credits.hpp b/include/screens/credits.hpp index 498c489..dfa5c58 100644 --- a/include/screens/credits.hpp +++ b/include/screens/credits.hpp @@ -27,14 +27,12 @@ #ifndef CREDITS_HPP #define CREDITS_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" - -#include "utils/structs.hpp" +#include "common.hpp" +#include "structs.hpp" #include -class Credits : public screen +class Credits : public Screen { public: void Draw(void) const override; @@ -43,8 +41,8 @@ private: int creditsPage = 1; std::vector arrowPos = { - {0, 215, 25, 25, -1}, // Back Arrow. - {295, 215, 25, 25, -1}, // Next Page. + {0, 215, 25, 25}, // Back Arrow. + {295, 215, 25, 25}, // Next Page. }; }; diff --git a/include/screens/ftpScreen.hpp b/include/screens/ftpScreen.hpp index e3062c7..61a530b 100644 --- a/include/screens/ftpScreen.hpp +++ b/include/screens/ftpScreen.hpp @@ -24,13 +24,12 @@ * reasonable ways as different from the original version. */ -#include "screens/screen.hpp" - -#include "utils/structs.hpp" +#include "common.hpp" +#include "structs.hpp" #include -class FTPScreen : public screen +class FTPScreen : public Screen { public: void Draw(void) const override; @@ -39,6 +38,6 @@ public: private: int ftpEnabled = 1; std::vector arrowPos = { - {0, 215, 25, 25, -1}, // Back Arrow. + {0, 215, 25, 25}, // Back Arrow. }; }; \ No newline at end of file diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index 1b7c9ed..ceb4bbc 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -27,13 +27,12 @@ #ifndef MAINMENU_HPP #define MAINMENU_HPP -#include "screens/screen.hpp" - -#include "utils/structs.hpp" +#include "common.hpp" +#include "structs.hpp" #include -class MainMenu : public screen +class MainMenu : public Screen { public: void Draw(void) const override; @@ -42,11 +41,11 @@ private: int Selection = 0; std::vector mainButtons = { - {10, 70, 140, 40, -1}, // Scripts. - {170, 70, 140, 40, -1}, // UniStore. - {10, 145, 140, 40, -1}, // Settings. - {170, 145, 140, 40, -1}, // FTP. - {0, 215, 25, 25, -1}, // Back Arrow. + {10, 70, 140, 40}, // Scripts. + {170, 70, 140, 40}, // UniStore. + {10, 145, 140, 40}, // Settings. + {170, 145, 140, 40}, // FTP. + {0, 215, 25, 25}, // Back Arrow. }; }; diff --git a/include/screens/scriptBrowse.hpp b/include/screens/scriptBrowse.hpp index 984645a..e6d85e6 100644 --- a/include/screens/scriptBrowse.hpp +++ b/include/screens/scriptBrowse.hpp @@ -27,14 +27,13 @@ #ifndef SCRIPTBROWSE_HPP #define SCRIPTBROWSE_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" +#include "common.hpp" +#include "fileBrowse.hpp" +#include "structs.hpp" -#include "utils/config.hpp" -#include "utils/fileBrowse.h" -#include "utils/structs.hpp" +#include -class ScriptBrowse : public screen +class ScriptBrowse : public Screen { public: void Draw(void) const override; @@ -49,12 +48,12 @@ private: int keyRepeatDelay = 0; int fastMode = false; std::vector arrowPos = { - {295, 0, 25, 25, -1}, // Arrow Up. - {295, 215, 25, 25, -1}, // Arrow Down. - {0, 215, 25, 25, -1}, // Back Arrow. - {5, 0, 25, 25, -1}, // Download All. - {45, 0, 25, 25, -1}, // ViewMode Change. - {80, 0, 25, 25, -1}, // Search. + {295, 0, 25, 25}, // Arrow Up. + {295, 215, 25, 25}, // Arrow Down. + {0, 215, 25, 25}, // Back Arrow. + {5, 0, 25, 25}, // Download All. + {45, 0, 25, 25}, // ViewMode Change. + {80, 0, 25, 25}, // Search. }; }; diff --git a/include/screens/scriptCreator.hpp b/include/screens/scriptCreator.hpp index 44bd9ad..a441b18 100644 --- a/include/screens/scriptCreator.hpp +++ b/include/screens/scriptCreator.hpp @@ -27,15 +27,12 @@ #ifndef SCRIPTCREATOR_HPP #define SCRIPTCREATOR_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" - -#include "utils/json.hpp" -#include "utils/structs.hpp" +#include "common.hpp" +#include "structs.hpp" #include -class ScriptCreator : public screen +class ScriptCreator : public Screen { public: void Draw(void) const override; @@ -88,18 +85,18 @@ private: std::string jsonFileName; // Main Pos. std::vector mainButtons = { - {90, 40, 140, 35, -1}, // New Script. - {90, 100, 140, 35, -1}, // Existing Script. + {90, 40, 140, 35}, // New Script. + {90, 100, 140, 35}, // Existing Script. }; // Creator Button Pos. std::vector creatorButtons = { - {10, 40, 140, 35, -1}, - {170, 40, 140, 35, -1}, - {10, 100, 140, 35, -1}, - {170, 100, 140, 35, -1}, - {10, 160, 140, 35, -1}, - {170, 160, 140, 35, -1}, + {10, 40, 140, 35}, + {170, 40, 140, 35}, + {10, 100, 140, 35}, + {170, 100, 140, 35}, + {10, 160, 140, 35}, + {170, 160, 140, 35}, }; }; diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index fb59069..560bf3c 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -27,13 +27,13 @@ #ifndef SCRIPTLIST_HPP #define SCRIPTLIST_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" +#include "common.hpp" +#include "fileBrowse.hpp" +#include "structs.hpp" -#include "utils/fileBrowse.h" -#include "utils/structs.hpp" +#include -class ScriptList : public screen +class ScriptList : public Screen { public: void Draw(void) const override; @@ -61,18 +61,18 @@ private: int fastMode = false; std::vector arrowPos = { - {295, 0, 25, 25, -1}, // Arrow Up. - {295, 215, 25, 25, -1}, // Arrow Down. - {0, 215, 25, 25, -1}, // Back Arrow. - {5, 0, 25, 25, -1}, // viewMode Change - {45, 0, 25, 25, -1}, // Search. + {295, 0, 25, 25}, // Arrow Up. + {295, 215, 25, 25}, // Arrow Down. + {0, 215, 25, 25}, // Back Arrow. + {5, 0, 25, 25}, // viewMode Change + {45, 0, 25, 25}, // Search. }; std::vector subPos = { - {10, 70, 140, 40, -1}, // Script list. - {170, 70, 140, 40, -1}, // Get Scripts. - {10, 145, 140, 40, -1}, // Script Creator. - {170, 145, 140, 40, -1}, // Script path change. + {10, 70, 140, 40}, // Script list. + {170, 70, 140, 40}, // Get Scripts. + {10, 145, 140, 40}, // Script Creator. + {170, 145, 140, 40}, // Script path change. }; }; diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index 80bd0f6..d52d0ec 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -27,15 +27,13 @@ #ifndef SETTINGS_HPP #define SETTINGS_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" - -#include "utils/fileBrowse.h" -#include "utils/structs.hpp" +#include "common.hpp" +#include "fileBrowse.hpp" +#include "structs.hpp" #include -class Settings : public screen +class Settings : public Screen { public: void Draw(void) const override; @@ -58,36 +56,36 @@ private: void MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch); std::vector mainButtons = { - {90, 40, 140, 35, -1}, // Language. - {90, 100, 140, 35, -1}, // Colors. - {90, 160, 140, 35, -1}, // Misc. + {90, 40, 140, 35}, // Language. + {90, 100, 140, 35}, // Colors. + {90, 160, 140, 35}, // Misc. }; std::vector langBlocks = { - {37, 32, 20, 20, -1}, - {37, 72, 20, 20, -1}, - {37, 112, 20, 20, -1}, - {37, 152, 20, 20, -1}, - {37, 188, 20, 20, -1}, - {177, 32, 20, 20, -1}, - {177, 72, 20, 20, -1}, - {177, 112, 20, 20, -1}, - {177, 152, 20, 20, -1}, - {177, 188, 20, 20, -1}, + {37, 32, 20, 20}, + {37, 72, 20, 20}, + {37, 112, 20, 20}, + {37, 152, 20, 20}, + {37, 188, 20, 20}, + {177, 32, 20, 20}, + {177, 72, 20, 20}, + {177, 112, 20, 20}, + {177, 152, 20, 20}, + {177, 188, 20, 20}, }; std::vector buttons = { - {10, 85, 95, 41, -1}, - {115, 85, 95, 41, -1}, - {220, 85, 95, 41, -1}, + {10, 85, 95, 41}, + {115, 85, 95, 41}, + {220, 85, 95, 41}, }; std::vector arrowPos = { - {0, 0, 25, 25, -1}, // Previous Arrow. - {295, 0, 25, 25, -1}, // Next Arrow. - {0, 215, 25, 25, -1}, // Back Arrow. - {0, 0, 25, 25, -1}, // Back Arrow top left. - {295, 215, 25, 25, -1}, // Next Page / Misc Arrow. + {0, 0, 25, 25}, // Previous Arrow. + {295, 0, 25, 25}, // Next Arrow. + {0, 215, 25, 25}, // Back Arrow. + {0, 0, 25, 25}, // Back Arrow top left. + {295, 215, 25, 25}, // Next Page / Misc Arrow. }; }; diff --git a/include/screens/unistore.hpp b/include/screens/unistore.hpp index e254ced..82c0f39 100644 --- a/include/screens/unistore.hpp +++ b/include/screens/unistore.hpp @@ -27,13 +27,13 @@ #ifndef UNISTORE_HPP #define UNISTORE_HPP -#include "screens/screen.hpp" -#include "screens/screenCommon.hpp" +#include "common.hpp" +#include "fileBrowse.hpp" +#include "structs.hpp" -#include "utils/fileBrowse.h" -#include "utils/structs.hpp" +#include -class UniStore : public screen +class UniStore : public Screen { public: void Draw(void) const override; @@ -83,31 +83,31 @@ private: std::vector dirContents; std::vector arrowPos = { - {295, 0, 25, 25, -1}, // Arrow Up. - {295, 215, 25, 25, -1}, // Arrow Down. - {0, 215, 25, 25, -1}, // Back Arrow. - {5, 0, 25, 25, -1}, // ViewMode Change. - {45, 0, 25, 25, -1}, // Search. - {85, 0, 25, 25, -1}, // Update. + {295, 0, 25, 25}, // Arrow Up. + {295, 215, 25, 25}, // Arrow Down. + {0, 215, 25, 25}, // Back Arrow. + {5, 0, 25, 25}, // ViewMode Change. + {45, 0, 25, 25}, // Search. + {85, 0, 25, 25}, // Update. }; std::vector URLBtn = { - {10, 70, 140, 40, -1}, // FULL URL. - {170, 70, 140, 40, -1}, // Github. - {10, 145, 140, 40, -1}, // TinyDB. - {170, 145, 140, 40, -1}, // QR Code? + {10, 70, 140, 40}, // FULL URL. + {170, 70, 140, 40}, // Github. + {10, 145, 140, 40}, // TinyDB. + {170, 145, 140, 40}, // QR Code? }; std::vector GitHubPos = { - {30, 50, 260, 30, -1}, // Owner & Repo. - {30, 130, 260, 30, -1}, // Filename. - {135, 180, 50, 30, -1}, // OK. + {30, 50, 260, 30}, // Owner & Repo. + {30, 130, 260, 30}, // Filename. + {135, 180, 50, 30}, // OK. }; std::vector subPos = { - {90, 40, 140, 35, -1}, // StoreList. - {90, 100, 140, 35, -1}, // storeSearch. - {90, 160, 140, 35, -1}, // storePathChange. + {90, 40, 140, 35}, // StoreList. + {90, 100, 140, 35}, // storeSearch. + {90, 160, 140, 35}, // storePathChange. }; }; diff --git a/include/utils/common.hpp b/include/utils/common.hpp index 95406f6..dd76f93 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -31,7 +31,7 @@ #ifdef __cplusplus extern "C" { #endif -#include "utils/files.h" +#include "files.h" #include #include @@ -42,8 +42,14 @@ extern "C" { #ifdef __cplusplus } -#include "utils/json.hpp" -#include "utils/stringutils.hpp" +#include "config.hpp" +#include "gfx.hpp" +#include "gui.hpp" +#include "json.hpp" +#include "lang.hpp" +#include "msg.hpp" +#include "screenCommon.hpp" +#include "stringutils.hpp" #include #include diff --git a/include/utils/extract.hpp b/include/utils/extract.hpp index 6644a13..ed85f6d 100644 --- a/include/utils/extract.hpp +++ b/include/utils/extract.hpp @@ -24,7 +24,8 @@ * reasonable ways as different from the original version. */ -#pragma once +#ifndef EXTRACT_HPP +#define EXTRACT_HPP #include "common.hpp" @@ -38,4 +39,6 @@ enum ExtractError { EXTRACT_ERROR_WRITEFILE, }; -Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath); \ No newline at end of file +Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath); + +#endif \ No newline at end of file diff --git a/include/utils/fileBrowse.h b/include/utils/fileBrowse.hpp similarity index 70% rename from include/utils/fileBrowse.h rename to include/utils/fileBrowse.hpp index 3cef0ba..d7c29f5 100644 --- a/include/utils/fileBrowse.h +++ b/include/utils/fileBrowse.hpp @@ -1,35 +1,27 @@ -#ifndef FILE_BROWSE_H -#define FILE_BROWSE_H - -#include -#include -#include -#include - -using namespace std; - -struct DirEntry { - std::string name; - std::string path; - bool isDirectory; - char tid[5]; - off_t size; -}; - -typedef struct { - char gameTitle[12]; //!< 12 characters for the game title. - char gameCode[4]; //!< 4 characters for the game code. -} sNDSHeadertitlecodeonly; - -void findNdsFiles(vector& dirContents); - -bool nameEndsWith(const std::string& name, const std::vector extensionList); -void getDirectoryContents(std::vector& dirContents, const std::vector extensionList); -void getDirectoryContents(std::vector& dirContents); -std::vector getContents(const std::string &name, const std::vector &extensionList); - -bool returnIfExist(const std::string &path, const std::vector &extensionList); - -std::string selectFilePath(std::string selectText, const std::vector &extensionList, int selectionMode = 1); - -#endif //FILE_BROWSE_H \ No newline at end of file +#ifndef FILE_BROWSE_HPP +#define FILE_BROWSE_HPP + +#include +#include +#include +#include + +using namespace std; + +struct DirEntry { + std::string name; + std::string path; + bool isDirectory; + off_t size; +}; + +bool nameEndsWith(const std::string& name, const std::vector extensionList); +void getDirectoryContents(std::vector& dirContents, const std::vector extensionList); +void getDirectoryContents(std::vector& dirContents); +std::vector getContents(const std::string &name, const std::vector &extensionList); + +bool returnIfExist(const std::string &path, const std::vector &extensionList); + +std::string selectFilePath(std::string selectText, const std::vector &extensionList, int selectionMode = 1); + +#endif //FILE_BROWSE_HPP \ No newline at end of file diff --git a/include/utils/formatting.hpp b/include/utils/formatting.hpp index 7078ad7..f1e41cd 100644 --- a/include/utils/formatting.hpp +++ b/include/utils/formatting.hpp @@ -24,6 +24,11 @@ * reasonable ways as different from the original version. */ -#pragma once +#ifndef FORMATTING_HPP +#define FORMATTING_HPP -std::string formatBytes(int bytes); \ No newline at end of file +#include + +std::string formatBytes(int bytes); + +#endif \ No newline at end of file diff --git a/include/utils/stringutils.hpp b/include/utils/stringutils.hpp index c25316d..f08a4b0 100644 --- a/include/utils/stringutils.hpp +++ b/include/utils/stringutils.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef STRINGUTILS_HPP +#define STRINGUTILS_HPP #include "common.hpp" @@ -7,4 +8,6 @@ bool matchPattern(std::string pattern, std::string tested); namespace StringUtils { std::string format(const std::string& fmt_str, ...); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/source/colors.cpp b/source/colorHelper.cpp similarity index 96% rename from source/colors.cpp rename to source/colorHelper.cpp index 6e1a6e7..c311312 100644 --- a/source/colors.cpp +++ b/source/colorHelper.cpp @@ -1,49 +1,49 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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; +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 "colorHelper.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; } \ No newline at end of file diff --git a/source/download/download.cpp b/source/download/download.cpp index 03d89b3..ae7f376 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -24,19 +24,15 @@ * reasonable ways as different from the original version. */ +#include "config.hpp" +#include "download.hpp" +#include "formatting.hpp" #include "gui.hpp" +#include "lang.hpp" +#include "screenCommon.hpp" -#include "download/download.hpp" - -#include "lang/lang.hpp" - -#include "screens/screenCommon.hpp" - -#include "utils/config.hpp" -#include "utils/formatting.hpp" - -#include #include +#include #define USER_AGENT APP_TITLE "-" VERSION_STRING @@ -410,28 +406,28 @@ bool checkWifiStatus(void) { } void downloadFailed(void) { - DisplayMsg(Lang::get("DOWNLOAD_FAILED")); + Msg::DisplayMsg(Lang::get("DOWNLOAD_FAILED")); for (int i = 0; i < 60*2; i++) { gspWaitForVBlank(); } } void notImplemented(void) { - DisplayMsg(Lang::get("NOT_IMPLEMENTED")); + Msg::DisplayMsg(Lang::get("NOT_IMPLEMENTED")); for (int i = 0; i < 60*2; i++) { gspWaitForVBlank(); } } void doneMsg(void) { - DisplayMsg(Lang::get("DONE")); + Msg::DisplayMsg(Lang::get("DONE")); for (int i = 0; i < 60*2; i++) { gspWaitForVBlank(); } } void notConnectedMsg(void) { - DisplayMsg(Lang::get("CONNECT_WIFI")); + Msg::DisplayMsg(Lang::get("CONNECT_WIFI")); for (int i = 0; i < 60*2; i++) { gspWaitForVBlank(); } @@ -654,9 +650,9 @@ void displayProgressBar() { Gui::clearTextBufs(); C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + GFX::DrawTop(); Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400); // Display 'Currently Extracting: '. @@ -675,7 +671,7 @@ void displayProgressBar() { Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, Config::progressbarColor); } } - Gui::DrawBottom(); + GFX::DrawBottom(); C3D_FrameEnd(0); gspWaitForVBlank(); } diff --git a/source/gfx.cpp b/source/gfx.cpp new file mode 100644 index 0000000..717dcc3 --- /dev/null +++ b/source/gfx.cpp @@ -0,0 +1,125 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 "common.hpp" + +extern bool isScriptSelected; +extern u32 barColor; +extern u32 bgTopColor; +extern u32 bgBottomColor; +extern u32 TextColor; + +void GFX::DrawTop(void) { + Gui::ScreenDraw(Top); + if (isScriptSelected == false) { + Gui::Draw_Rect(0, 0, 400, 25, Config::Color1); + Gui::Draw_Rect(0, 25, 400, 190, Config::Color2); + Gui::Draw_Rect(0, 215, 400, 25, Config::Color1); + if (Config::UseBars == true) { + DrawSprite(sprites_top_screen_top_idx, 0, 0); + DrawSprite(sprites_top_screen_bot_idx, 0, 215); + } + } else if (isScriptSelected == true) { + Gui::Draw_Rect(0, 0, 400, 30, barColor); + Gui::Draw_Rect(0, 25, 400, 190, bgBottomColor); + Gui::Draw_Rect(0, 215, 400, 25, barColor); + if (Config::UseBars == true) { + DrawSprite(sprites_top_screen_top_idx, 0, 0); + DrawSprite(sprites_top_screen_bot_idx, 0, 215); + } + } +} + +void GFX::DrawBottom(void) { + Gui::ScreenDraw(Bottom); + if (isScriptSelected == false) { + Gui::Draw_Rect(0, 0, 320, 25, Config::Color1); + Gui::Draw_Rect(0, 25, 320, 190, Config::Color3); + Gui::Draw_Rect(0, 215, 320, 25, Config::Color1); + if (Config::UseBars == true) { + DrawSprite(sprites_bottom_screen_top_idx, 0, 0); + DrawSprite(sprites_bottom_screen_bot_idx, 0, 215); + } + } else if (isScriptSelected == true) { + Gui::Draw_Rect(0, 0, 320, 30, barColor); + Gui::Draw_Rect(0, 25, 320, 190, bgBottomColor); + Gui::Draw_Rect(0, 215, 320, 25, barColor); + if (Config::UseBars == true) { + DrawSprite(sprites_bottom_screen_top_idx, 0, 0); + DrawSprite(sprites_bottom_screen_bot_idx, 0, 215); + } + } +} + +extern C2D_SpriteSheet sprites; + +void GFX::DrawSprite(int img, int x, int y, float ScaleX, float ScaleY) +{ + Gui::DrawSprite(sprites, img, x, y, ScaleX, ScaleY); +} + +void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY) +{ + C2D_ImageTint tint; + if (isScriptSelected) { + C2D_SetImageTint(&tint, C2D_TopLeft, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_TopRight, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5); + } else { + C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5); + } + C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, img), x, y, 0.5f, &tint, ScaleX, ScaleY); +} + +void GFX::DrawArrow(int x, int y, float rotation, int arrowSprite) { + C2D_Sprite sprite; + C2D_ImageTint tint; + if (isScriptSelected) { + C2D_SetImageTint(&tint, C2D_TopLeft, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_TopRight, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5); + } else { + C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5); + C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5); + } + + if (arrowSprite == 0) { + C2D_SpriteFromSheet(&sprite, sprites, sprites_arrow_idx); + } else { + C2D_SpriteFromSheet(&sprite, sprites, sprites_side_arrow_idx); + } + C2D_SpriteRotateDegrees(&sprite, rotation); + C2D_SpriteSetPos(&sprite, x, y); + C2D_SpriteSetDepth(&sprite, 0.5); + C2D_DrawSpriteTinted(&sprite, &tint); +} \ No newline at end of file diff --git a/source/gui.cpp b/source/gui.cpp deleted file mode 100644 index b5de563..0000000 --- a/source/gui.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 "screens/screenCommon.hpp" - -#include "utils/config.hpp" -#include "utils/structs.hpp" - -C3D_RenderTarget* top; -C3D_RenderTarget* bottom; - -C2D_TextBuf sizeBuf; -C2D_SpriteSheet sprites; -bool currentScreen = false; -extern bool isScriptSelected; - -extern u32 barColor; -extern u32 bgTopColor; -extern u32 bgBottomColor; -extern u32 TextColor; - -// Clear Text. -void Gui::clearTextBufs(void) -{ - C2D_TextBufClear(sizeBuf); -} - -// Initialize GUI. -Result Gui::init(void) -{ - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - C2D_Init(C2D_DEFAULT_MAX_OBJECTS); - C2D_Prepare(); - top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); - bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); - sprites = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x"); - sizeBuf = C2D_TextBufNew(4096); - return 0; -} - -// Exit the whole GUI. -void Gui::exit(void) -{ - C2D_TextBufDelete(sizeBuf); - C2D_SpriteSheetFree(sprites); - C2D_Fini(); - C3D_Fini(); -} - -void DisplayMsg(std::string text) { - Gui::clearTextBufs(); - C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); - if (isScriptSelected == false) { - Gui::DrawString(10, 40, 0.45f, Config::TxtColor, text, 380); - } else if (isScriptSelected == true) { - Gui::DrawString(10, 40, 0.45f, TextColor, text, 380); - } - Gui::DrawBottom(); - C3D_FrameEnd(0); -} - -void Gui::sprite(int key, int x, int y, float ScaleX, float ScaleY) -{ - C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, key), x, y, 0.5f, NULL, ScaleX, ScaleY); -} - -void Gui::spriteBlend(int key, int x, int y, float ScaleX, float ScaleY) -{ - C2D_ImageTint tint; - if (isScriptSelected) { - C2D_SetImageTint(&tint, C2D_TopLeft, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_TopRight, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5); - } else { - C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5); - } - - C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, key), x, y, 0.5f, &tint, ScaleX, ScaleY); -} - -void Gui::DrawArrow(int x, int y, float rotation, int arrowSprite) { - C2D_Sprite sprite; - C2D_ImageTint tint; - if (isScriptSelected) { - C2D_SetImageTint(&tint, C2D_TopLeft, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_TopRight, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5); - } else { - C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5); - C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5); - } - - if (arrowSprite == 0) { - C2D_SpriteFromSheet(&sprite, sprites, sprites_arrow_idx); - } else { - C2D_SpriteFromSheet(&sprite, sprites, sprites_side_arrow_idx); - } - C2D_SpriteRotateDegrees(&sprite, rotation); - C2D_SpriteSetPos(&sprite, x, y); - C2D_SpriteSetDepth(&sprite, 0.5); - C2D_DrawSpriteTinted(&sprite, &tint); -} - -void Gui::drawAnimatedSelector(float xPos, float yPos, float Width, float Height, float speed, u32 colour) -{ - static constexpr int w = 2; - static float timer = 0.0f; - float highlight_multiplier = fmax(0.0, fabs(fmod(timer, 1.0) - 0.5) / 0.5); - u8 r = Config::SelectedColor & 0xFF; - u8 g = (Config::SelectedColor >> 8) & 0xFF; - u8 b = (Config::SelectedColor >> 16) & 0xFF; - u32 color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255); - - // BG Color for the Selector. - C2D_DrawRectSolid(xPos, yPos, 0.5, Width, Height, colour); // Black. - - // Animated Selector part. - C2D_DrawRectSolid(xPos, yPos, 0.5, Width, w, color); // top - C2D_DrawRectSolid(xPos, yPos + w, 0.5, w, Height - 2 * w, color); // left - C2D_DrawRectSolid(xPos + Width - w, yPos + w, 0.5, w, Height - 2 * w, color); // right - C2D_DrawRectSolid(xPos, yPos + Height - w, 0.5, Width, w, color); // bottom - - timer += speed; // Speed of the animation. Example : .030 / .060 -} - -void Gui::DisplayWarnMsg(std::string Text) -{ - Gui::clearTextBufs(); - C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); - if (isScriptSelected == false) { - Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, Text, 400); - } else if (isScriptSelected == true) { - Gui::DrawStringCentered(0, 1, 0.6f, TextColor, Text, 400); - } - Gui::DrawBottom(); - C3D_FrameEnd(0); - for (int i = 0; i < 60*3; i++) { - gspWaitForVBlank(); - } -} - -void Gui::DrawStringCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth) { - Gui::DrawString((currentScreen ? 200 : 160)+x-((maxWidth == 0 ? (int)Gui::GetStringWidth(size, Text) : std::min(maxWidth, (int)Gui::GetStringWidth(size, Text)))/2), y, size, color, Text, maxWidth); -} - -// Draw String or Text. -void Gui::DrawString(float x, float y, float size, u32 color, std::string Text, int maxWidth) { - C2D_Text c2d_text; - C2D_TextParse(&c2d_text, sizeBuf, Text.c_str()); - C2D_TextOptimize(&c2d_text); - if(maxWidth == 0) { - C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, size, size, color); - } else { - C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, std::min(size, size*(maxWidth/Gui::GetStringWidth(size, Text))), size, color); - } -} - - -// Get String or Text Width. -float Gui::GetStringWidth(float size, std::string Text) { - float width = 0; - GetStringSize(size, &width, NULL, Text); - return width; -} - -// Get String or Text Size. -void Gui::GetStringSize(float size, float *width, float *height, std::string Text) { - C2D_Text c2d_text; - C2D_TextParse(&c2d_text, sizeBuf, Text.c_str()); - C2D_TextGetDimensions(&c2d_text, size, size, width, height); -} - - -// Get String or Text Height. -float Gui::GetStringHeight(float size, std::string Text) { - float height = 0; - GetStringSize(size, NULL, &height, Text.c_str()); - return height; -} - -// Draw a Rectangle. -bool Gui::Draw_Rect(float x, float y, float w, float h, u32 color) { - return C2D_DrawRectSolid(x, y, 0.5f, w, h, color); -} - -// Select, on which Screen should be drawn. -void Gui::setDraw(C3D_RenderTarget * screen) -{ - C2D_SceneBegin(screen); - currentScreen = screen == top ? 1 : 0; -} - -void Gui::DrawTop(void) { - Gui::setDraw(top); - if (isScriptSelected == false) { - Gui::Draw_Rect(0, 0, 400, 25, Config::Color1); - Gui::Draw_Rect(0, 25, 400, 190, Config::Color2); - Gui::Draw_Rect(0, 215, 400, 25, Config::Color1); - if (Config::UseBars == true) { - Gui::sprite(sprites_top_screen_top_idx, 0, 0); - Gui::sprite(sprites_top_screen_bot_idx, 0, 215); - } - } else if (isScriptSelected == true) { - Gui::Draw_Rect(0, 0, 400, 30, barColor); - Gui::Draw_Rect(0, 25, 400, 190, bgBottomColor); - Gui::Draw_Rect(0, 215, 400, 25, barColor); - if (Config::UseBars == true) { - Gui::sprite(sprites_top_screen_top_idx, 0, 0); - Gui::sprite(sprites_top_screen_bot_idx, 0, 215); - } - } -} - -void Gui::DrawBottom(void) { - Gui::setDraw(bottom); - if (isScriptSelected == false) { - Gui::Draw_Rect(0, 0, 320, 25, Config::Color1); - Gui::Draw_Rect(0, 25, 320, 190, Config::Color3); - Gui::Draw_Rect(0, 215, 320, 25, Config::Color1); - if (Config::UseBars == true) { - Gui::sprite(sprites_bottom_screen_top_idx, 0, 0); - Gui::sprite(sprites_bottom_screen_bot_idx, 0, 215); - } - } else if (isScriptSelected == true) { - Gui::Draw_Rect(0, 0, 320, 30, barColor); - Gui::Draw_Rect(0, 25, 320, 190, bgBottomColor); - Gui::Draw_Rect(0, 215, 320, 25, barColor); - if (Config::UseBars == true) { - Gui::sprite(sprites_bottom_screen_top_idx, 0, 0); - Gui::sprite(sprites_bottom_screen_bot_idx, 0, 215); - } - } -} - -std::vector promptBtn = { - {10, 100, 140, 35, -1}, // Yes. - {170, 100, 140, 35, -1}, // No. -}; - -extern touchPosition touch; -extern bool touching(touchPosition touch, Structs::ButtonPos button); - -// Display a Message, which needs to be confirmed with A/B. -bool Gui::promptMsg(std::string promptMsg) -{ - Gui::clearTextBufs(); - C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); - if (isScriptSelected == false) { - Gui::DrawString((400-Gui::GetStringWidth(0.6f, promptMsg.c_str()))/2, 100, 0.6f, Config::TxtColor, promptMsg.c_str(), 400); - Gui::DrawString((400-Gui::GetStringWidth(0.72f, Lang::get("CONFIRM_OR_CANCEL")))/2, 217, 0.72f, Config::TxtColor, Lang::get("CONFIRM_OR_CANCEL"), 400); - } else if (isScriptSelected == true) { - Gui::DrawString((400-Gui::GetStringWidth(0.6f, promptMsg.c_str()))/2, 100, 0.6f, TextColor, promptMsg.c_str(), 400); - Gui::DrawString((400-Gui::GetStringWidth(0.72f, Lang::get("CONFIRM_OR_CANCEL")))/2, 217, 0.72f, TextColor, Lang::get("CONFIRM_OR_CANCEL"), 400); - } - Gui::DrawBottom(); - if (isScriptSelected == false) { - Gui::Draw_Rect(10, 100, 140, 35, Config::Color1); - Gui::Draw_Rect(170, 100, 140, 35, Config::Color1); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, Config::TxtColor, Lang::get("YES"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, Config::TxtColor, Lang::get("NO"), 140); - } else if (isScriptSelected == true) { - Gui::Draw_Rect(10, 100, 140, 35, barColor); - Gui::Draw_Rect(170, 100, 140, 35, barColor); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, TextColor, Lang::get("YES"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, TextColor, Lang::get("NO"), 140); - } - - C3D_FrameEnd(0); - while(1) - { - gspWaitForVBlank(); - hidScanInput(); - hidTouchRead(&touch); - if ((hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[0]))) { - return true; - } else if ((hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[1]))) { - return false; - } - } -} \ No newline at end of file diff --git a/source/init.cpp b/source/init.cpp new file mode 100644 index 0000000..87ff5d9 --- /dev/null +++ b/source/init.cpp @@ -0,0 +1,171 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 "config.hpp" +#include "init.hpp" +#include "gfx.hpp" +#include "gui.hpp" +#include "lang.hpp" +#include "logging.hpp" +#include "mainMenu.hpp" +#include "screenCommon.hpp" +#include "sound.h" + +#include <3ds.h> +#include +#include + +// The classic Fade Effect! ;P +int fadealpha = 255; +bool fadein = true; + +bool exiting = false; +bool dspFound = false; +touchPosition touch; +sound *bgm = NULL; +bool songIsFound = false; + +// Include all spritesheet's. +C2D_SpriteSheet sprites; + +// If button Position pressed -> Do something. +bool touching(touchPosition touch, Structs::ButtonPos button) { + if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) + return true; + else + return false; +} + +void Init::loadSoundEffects(void) { + if (dspFound == true) { + if( access( Config::MusicPath.c_str(), F_OK ) != -1 ) { + bgm = new sound(Config::MusicPath, 1, true); + songIsFound = true; + } + } +} + +void Init::playMusic(void) { + if (songIsFound == true) { + bgm->play(); + } +} + +void Init::stopMusic(void) { + if (songIsFound == true) { + bgm->stop(); + } +} + + +Result Init::Initialize() { + gfxInitDefault(); + romfsInit(); + Gui::init(); + Gui::loadSheet("romfs:/gfx/sprites.t3x", sprites); + sdmcInit(); + cfguInit(); + acInit(); + // Create Folder if missing. + mkdir("sdmc:/3ds", 0777); + mkdir("sdmc:/3ds/Universal-Updater", 0777); + mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777); + mkdir("sdmc:/3ds/Universal-Updater/stores", 0777); + + // We need to make sure, the file exist. + if(access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) == -1 ) { + Config::initializeNewConfig(); + } + Config::load(); + Lang::load(Config::lang); + + if (Config::Logging == true) { + Logging::createLogFile(); + } + + Gui::setScreen(std::make_unique()); + osSetSpeedupEnable(true); // Enable speed-up for New 3DS users + + if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) { + ndspInit(); + dspFound = true; + loadSoundEffects(); + playMusic(); + } + + return 0; +} + +Result Init::MainLoop() { + // Initialize everything. + Initialize(); + + // Loop as long as the status is not exiting. + while (aptMainLoop() && !exiting) + { + hidScanInput(); + u32 hHeld = hidKeysHeld(); + u32 hDown = hidKeysDown(); + hidTouchRead(&touch); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + Gui::clearTextBufs(); + Gui::mainLoop(hDown, hHeld, touch); + C3D_FrameEnd(0); + gspWaitForVBlank(); + + if (fadein == true) { + fadealpha -= 3; + if (fadealpha < 0) { + fadealpha = 0; + fadein = false; + } + } + } + // Exit all services and exit the app. + Exit(); + return 0; +} + +Result Init::Exit() { + if (songIsFound == true) { + stopMusic(); + } + delete bgm; + if (dspFound == true) { + ndspExit(); + } + Config::save(); + Gui::exit(); + Gui::unloadSheet(sprites); + gfxExit(); + cfguExit(); + acExit(); + romfsExit(); + sdmcExit(); + return 0; +} \ No newline at end of file diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 5855368..d157655 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -1,15 +1,15 @@ +#include "config.hpp" +#include "gfx.hpp" #include "gui.hpp" #include "keyboard.hpp" - -#include "utils/config.hpp" -#include "utils/structs.hpp" +#include "structs.hpp" #include #include #include -extern C3D_RenderTarget* top; -extern C3D_RenderTarget* bottom; +extern C3D_RenderTarget* Top; +extern C3D_RenderTarget* Bottom; bool caps = false, enter = false; int shift = 0; @@ -128,13 +128,13 @@ std::string Input::Numpad(uint maxLength, std::string Text) C3D_FrameEnd(0); Gui::clearTextBufs(); C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::DrawTop(); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + GFX::DrawTop(); Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400); Gui::DrawString(180, 217, 0.8, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400); if(cursorBlink < -20) cursorBlink = 20; - Gui::setDraw(bottom); + Gui::ScreenDraw(Bottom); Gui::Draw_Rect(0, 0, 320, 240, Config::Color3); DrawNumpad(); scanKeys(); @@ -211,9 +211,9 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi C3D_FrameEnd(0); Gui::clearTextBufs(); C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - Gui::DrawTop(); + GFX::DrawTop(); Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400); - Gui::DrawBottom(); + GFX::DrawBottom(); drawKeyboard(); C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, Config::Color1 & C2D_Color32(200, 200, 200, 200)); Gui::DrawString(2, 82, inputTextSize, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 316); diff --git a/source/lang/lang.cpp b/source/lang/lang.cpp index 82b2ef5..bd9b1b9 100644 --- a/source/lang/lang.cpp +++ b/source/lang/lang.cpp @@ -1,6 +1,5 @@ -#include "lang/lang.hpp" - -#include "utils/config.hpp" +#include "config.hpp" +#include "lang.hpp" #include diff --git a/source/main.cpp b/source/main.cpp index af4fa60..8f0849a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -24,122 +24,9 @@ * reasonable ways as different from the original version. */ -#include "gui.hpp" -#include "logging.hpp" +#include "init.hpp" -#include "lang/lang.hpp" - -#include "screens/mainMenu.hpp" -#include "screens/screenCommon.hpp" - -#include "utils/config.hpp" -#include "utils/sound.h" -#include "utils/structs.hpp" - -#include <3ds.h> -#include -#include - -bool exiting = false; -bool dspFound = false; -touchPosition touch; -sound *bgm = NULL; -bool songIsFound = false; - -// If button Position pressed -> Do something. -bool touching(touchPosition touch, Structs::ButtonPos button) { - if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) - return true; - else - return false; -} - - -void loadSoundEffects(void) { - if (dspFound == true) { - if( access( Config::MusicPath.c_str(), F_OK ) != -1 ) { - bgm = new sound(Config::MusicPath, 1, true); - songIsFound = true; - } - } -} - -void playMusic(void) { - if (songIsFound == true) { - bgm->play(); - } -} - -void stopMusic(void) { - if (songIsFound == true) { - bgm->stop(); - } -} - -int main() -{ - gfxInitDefault(); - romfsInit(); - Gui::init(); - sdmcInit(); - cfguInit(); - acInit(); - // Create Folder if missing. - mkdir("sdmc:/3ds", 0777); - mkdir("sdmc:/3ds/Universal-Updater", 0777); - mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777); - mkdir("sdmc:/3ds/Universal-Updater/stores", 0777); - - // We need to make sure, the file exist. - if(access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) == -1 ) { - Config::initializeNewConfig(); - } - Config::load(); - Lang::load(Config::lang); - - if (Config::Logging == true) { - Logging::createLogFile(); - } - - Screen::set(std::make_unique()); - osSetSpeedupEnable(true); // Enable speed-up for New 3DS users - - if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) { - ndspInit(); - dspFound = true; - loadSoundEffects(); - playMusic(); - } - - // Loop as long as the status is not exit - while (aptMainLoop() && !exiting) - { - hidScanInput(); - u32 hHeld = hidKeysHeld(); - u32 hDown = hidKeysDown(); - hidTouchRead(&touch); - C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - C2D_TargetClear(top, BLACK); - C2D_TargetClear(bottom, BLACK); - Gui::clearTextBufs(); - Screen::loop(hDown, hHeld, touch); - C3D_FrameEnd(0); - gspWaitForVBlank(); - } - - if (songIsFound == true) { - stopMusic(); - } - delete bgm; - if (dspFound == true) { - ndspExit(); - } - Config::save(); - Gui::exit(); - gfxExit(); - cfguExit(); - acExit(); - romfsExit(); - sdmcExit(); +int main() { + Init::MainLoop(); // Init::MainLoop() has the whole logic already. ;P return 0; } \ No newline at end of file diff --git a/source/msg.cpp b/source/msg.cpp new file mode 100644 index 0000000..e04661b --- /dev/null +++ b/source/msg.cpp @@ -0,0 +1,120 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . +* +* 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 "common.hpp" +#include "msg.hpp" + +extern bool isScriptSelected; + +extern u32 barColor; +extern u32 bgTopColor; +extern u32 bgBottomColor; +extern u32 TextColor; + +void Msg::DisplayMsg(std::string text) { + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + GFX::DrawTop(); + if (isScriptSelected == false) { + Gui::DrawString(10, 40, 0.45f, Config::TxtColor, text, 380); + } else if (isScriptSelected == true) { + Gui::DrawString(10, 40, 0.45f, TextColor, text, 380); + } + GFX::DrawBottom(); + C3D_FrameEnd(0); +} + +void Msg::DisplayWarnMsg(std::string Text) +{ + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + GFX::DrawTop(); + if (isScriptSelected == false) { + Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, Text, 400); + } else if (isScriptSelected == true) { + Gui::DrawStringCentered(0, 1, 0.6f, TextColor, Text, 400); + } + GFX::DrawBottom(); + C3D_FrameEnd(0); + for (int i = 0; i < 60*3; i++) { + gspWaitForVBlank(); + } +} + + +std::vector promptBtn = { + {10, 100, 140, 35}, // Yes. + {170, 100, 140, 35}, // No. +}; + +extern touchPosition touch; +extern bool touching(touchPosition touch, Structs::ButtonPos button); + +// Display a Message, which needs to be confirmed with A/B. +bool Msg::promptMsg(std::string promptMsg) +{ + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(Top, BLACK); + C2D_TargetClear(Bottom, BLACK); + GFX::DrawTop(); + if (isScriptSelected == false) { + Gui::DrawString((400-Gui::GetStringWidth(0.6f, promptMsg.c_str()))/2, 100, 0.6f, Config::TxtColor, promptMsg.c_str(), 400); + Gui::DrawString((400-Gui::GetStringWidth(0.72f, Lang::get("CONFIRM_OR_CANCEL")))/2, 217, 0.72f, Config::TxtColor, Lang::get("CONFIRM_OR_CANCEL"), 400); + } else if (isScriptSelected == true) { + Gui::DrawString((400-Gui::GetStringWidth(0.6f, promptMsg.c_str()))/2, 100, 0.6f, TextColor, promptMsg.c_str(), 400); + Gui::DrawString((400-Gui::GetStringWidth(0.72f, Lang::get("CONFIRM_OR_CANCEL")))/2, 217, 0.72f, TextColor, Lang::get("CONFIRM_OR_CANCEL"), 400); + } + GFX::DrawBottom(); + if (isScriptSelected == false) { + Gui::Draw_Rect(10, 100, 140, 35, Config::Color1); + Gui::Draw_Rect(170, 100, 140, 35, Config::Color1); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, Config::TxtColor, Lang::get("YES"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, Config::TxtColor, Lang::get("NO"), 140); + } else if (isScriptSelected == true) { + Gui::Draw_Rect(10, 100, 140, 35, barColor); + Gui::Draw_Rect(170, 100, 140, 35, barColor); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, TextColor, Lang::get("YES"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, TextColor, Lang::get("NO"), 140); + } + + C3D_FrameEnd(0); + while(1) + { + gspWaitForVBlank(); + hidScanInput(); + hidTouchRead(&touch); + if ((hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[0]))) { + return true; + } else if ((hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[1]))) { + return false; + } + } +} \ No newline at end of file diff --git a/source/screens/credits.cpp b/source/screens/credits.cpp index 2772774..708805f 100644 --- a/source/screens/credits.cpp +++ b/source/screens/credits.cpp @@ -24,38 +24,36 @@ * reasonable ways as different from the original version. */ -#include "screens/credits.hpp" - -#include "utils/config.hpp" +#include "credits.hpp" extern bool touching(touchPosition touch, Structs::ButtonPos button); void Credits::Draw(void) const { std::string title = "Universal-Updater - "; title += Lang::get("CREDITS"); - Gui::DrawTop(); + GFX::DrawTop(); if (creditsPage != 4) { if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, title, 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, title, 400); } - Gui::DrawStringCentered(0, 40, 0.8f, Config::TxtColor, Lang::get("DEVELOPED_BY"), 400); - Gui::DrawStringCentered(0, 70, 0.8f, Config::TxtColor, Lang::get("MAIN_DEV"), 400); - Gui::sprite(sprites_stackZ_idx, 150, 95); + Gui::DrawStringCentered(0, 30, 0.7f, Config::TxtColor, Lang::get("DEVELOPED_BY"), 390); + Gui::DrawStringCentered(0, 70, 0.7f, Config::TxtColor, Lang::get("MAIN_DEV"), 390); + GFX::DrawSprite(sprites_stackZ_idx, 120, 105); std::string currentVersion = Lang::get("CURRENT_VERSION"); currentVersion += V_STRING; Gui::DrawString(395-Gui::GetStringWidth(0.70f, currentVersion), 219, 0.70f, Config::TxtColor, currentVersion, 400); } else { Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190)); - Gui::sprite(sprites_discord_idx, 115, 35); + GFX::DrawSprite(sprites_discord_idx, 115, 35); } - Gui::DrawBottom(); + GFX::DrawBottom(); if (creditsPage != 4) { - Gui::DrawArrow(0, 218, 0, 1); - Gui::DrawArrow(318, 240, 180.0, 1); + GFX::DrawArrow(0, 218, 0, 1); + GFX::DrawArrow(318, 240, 180.0, 1); } if (creditsPage == 1) { @@ -77,14 +75,14 @@ void Credits::Draw(void) const { } else if (creditsPage == 4) { Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, 190)); Gui::DrawStringCentered(0, -2, 0.55f, Config::TxtColor, Lang::get("LINK"), 320); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawArrow(0, 218, 0, 1); } } void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if ((hDown & KEY_LEFT || hDown & KEY_L) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { if (creditsPage == 1) { - Screen::back(); + Gui::screenBack(); return; } else if (creditsPage > 1) { creditsPage--; @@ -96,7 +94,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_B) { - Screen::back(); + Gui::screenBack(); return; } } \ No newline at end of file diff --git a/source/screens/ftpScreen.cpp b/source/screens/ftpScreen.cpp index fe3305c..09e28d3 100644 --- a/source/screens/ftpScreen.cpp +++ b/source/screens/ftpScreen.cpp @@ -24,12 +24,8 @@ * reasonable ways as different from the original version. */ -#include "lang/lang.hpp" -#include "screens/ftpScreen.hpp" -#include "screens/screenCommon.hpp" - -#include "utils/config.hpp" +#include "ftpScreen.hpp" #include #include @@ -54,14 +50,14 @@ void FTPScreen::Draw(void) const ftp_loop(); Gui::clearTextBufs(); C3D_FrameBegin(C3D_FRAME_SYNCDRAW); - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 0, 0.7f, Config::TxtColor, Lang::get("FTP_MODE"), 400); } else { Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 2, 0.7f, Config::TxtColor, Lang::get("FTP_MODE"), 400); } - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); ret = ACU_GetWifiStatus(&wifiStatus); if ((wifiStatus != 0) && R_SUCCEEDED(ret)) { @@ -95,7 +91,7 @@ void FTPScreen::Draw(void) const memset(ftp_file_transfer, 0, 50); // Empty transfer status. ftp_exit(); - Screen::back(); + Gui::screenBack(); return; } diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index 305524c..04b1241 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -24,13 +24,12 @@ * reasonable ways as different from the original version. */ -#include "screens/ftpScreen.hpp" -#include "screens/mainMenu.hpp" -#include "screens/scriptlist.hpp" -#include "screens/settings.hpp" -#include "screens/unistore.hpp" - -#include "utils/config.hpp" +#include "config.hpp" +#include "ftpScreen.hpp" +#include "mainMenu.hpp" +#include "scriptlist.hpp" +#include "settings.hpp" +#include "unistore.hpp" extern bool exiting; extern bool touching(touchPosition touch, Structs::ButtonPos button); @@ -38,7 +37,7 @@ extern int fadealpha; extern bool fadein; void MainMenu::Draw(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); @@ -49,13 +48,13 @@ void MainMenu::Draw(void) const { } if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, fadealpha)); // Fade in out effect - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); for (int i = 0; i < 4; i++) { Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); if (Selection == i) { - Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -65,7 +64,7 @@ void MainMenu::Draw(void) const { Gui::DrawStringCentered(80, mainButtons[3].y+12, 0.6f, Config::TxtColor, "FTP", 130); // Draw UniStore Icon. ;P - Gui::sprite(sprites_uniStore_idx, 10, 65); + GFX::DrawSprite(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 } @@ -88,29 +87,29 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_A) { switch(Selection) { case 0: - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); break; case 1: - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); break; case 2: - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); break; case 3: - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); break; } } if (hDown & KEY_TOUCH) { if (touching(touch, mainButtons[0])) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else if (touching(touch, mainButtons[1])) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else if (touching(touch, mainButtons[2])) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else if (touching(touch, mainButtons[3])) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } } } \ No newline at end of file diff --git a/source/screens/screen.cpp b/source/screens/screen.cpp deleted file mode 100644 index e6ab77a..0000000 --- a/source/screens/screen.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* This file is part of Universal-Updater -* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, 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 . -* -* 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 "screens/screen.hpp" - -#include - -// Fade stuff. -int fadealpha = 255; -bool fadein = true; - -std::stack> screens; - -// Set a specific Screen. -void Screen::set(std::unique_ptr screen2) -{ - screens.push(std::move(screen2)); -} - -// Fade into another Screen, but first do a fadeout. -void Screen::fade(std::unique_ptr screen2, bool fadeout) { - if (fadeout) { - fadealpha += 6; - if (fadealpha > 255) { - fadealpha = 255; - screens.push(std::move(screen2)); - fadein = true; - fadeout = false; - } - } -} - -// Go a Screen back. -void Screen::back() -{ - screens.pop(); -} - -// For the Mainloop. -void Screen::loop(u32 hDown, u32 hHeld, touchPosition touch) { - screens.top()->Draw(); - screens.top()->Logic(hDown, hHeld, touch); - if (fadein == true) { - fadealpha -= 6; - if (fadealpha < 0) { - fadealpha = 0; - fadein = false; - } - } -} \ No newline at end of file diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index f04d76d..07cc3e9 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -24,12 +24,10 @@ * reasonable ways as different from the original version. */ -#include "download/download.hpp" - -#include "screens/scriptBrowse.hpp" - -#include "utils/fileBrowse.h" -#include "utils/json.hpp" +#include "download.hpp" +#include "fileBrowse.hpp" +#include "json.hpp" +#include "scriptBrowse.hpp" #include @@ -94,7 +92,7 @@ void findExistingFiles(nlohmann::json &json) { } ScriptBrowse::ScriptBrowse() { - DisplayMsg(Lang::get("GETTING_SCRIPT_LIST")); + Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST")); // Get repo info downloadToFile("https://github.com/Universal-Team/extras/raw/scripts/info/scriptInfo.json", metaFile); @@ -107,7 +105,7 @@ ScriptBrowse::ScriptBrowse() { } void ScriptBrowse::Draw(void) const { - Gui::DrawTop(); + GFX::DrawTop(); std::string revision = std::to_string(int64_t(infoJson[selection]["curRevision"])); revision += " / "; revision += std::to_string(int64_t(infoJson[selection]["revision"])); @@ -128,13 +126,13 @@ void ScriptBrowse::Draw(void) const { } else if(infoJson[selection]["curRevision"] > infoJson[selection]["revision"]) { Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 370); } - Gui::DrawBottom(); - Gui::DrawArrow(295, -1); - Gui::DrawArrow(315, 240, 180.0); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(295, -1); + GFX::DrawArrow(315, 240, 180.0); + GFX::DrawArrow(0, 218, 0, 1); - Gui::spriteBlend(sprites_download_all_idx, arrowPos[3].x, arrowPos[3].y); - Gui::spriteBlend(sprites_view_idx, arrowPos[4].x, arrowPos[4].y); + GFX::DrawSpriteBlend(sprites_download_all_idx, arrowPos[3].x, arrowPos[3].y); + GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[4].x, arrowPos[4].y); //Gui::spriteBlend(sprites_search_idx, arrowPos[5].x, arrowPos[5].y); Gui::DrawStringCentered(-23, 1, 0.6f, Config::TxtColor, std::to_string(selection + 1) + " / " + maxScripts); @@ -143,7 +141,7 @@ void ScriptBrowse::Draw(void) const { for(int i=0;i #include @@ -80,14 +77,14 @@ void ScriptCreator::Draw(void) const { } void ScriptCreator::DrawSubMenu(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400); } - Gui::DrawBottom(); + GFX::DrawBottom(); for (int i = 0; i < 2; i++) { if (Selection == i) { @@ -102,14 +99,14 @@ void ScriptCreator::DrawSubMenu(void) const { } void ScriptCreator::DrawScriptScreen(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Selected Entry: " + entryName, 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Selected Entry: " + entryName, 400); } - Gui::DrawBottom(); + GFX::DrawBottom(); // Draw Page. for (int i = 0; i < 2; i++) { @@ -287,7 +284,7 @@ void ScriptCreator::setInfoStuff(void) { void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_B) { - Screen::back(); + Gui::screenBack(); return; } diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index 30ca840..cc03ecd 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -24,14 +24,11 @@ * reasonable ways as different from the original version. */ -#include "download/download.hpp" - -#include "screens/scriptBrowse.hpp" -#include "screens/scriptCreator.hpp" -#include "screens/scriptlist.hpp" - -#include "utils/config.hpp" -#include "utils/scriptHelper.hpp" +#include "download.hpp" +#include "scriptBrowse.hpp" +#include "scriptCreator.hpp" +#include "scriptHelper.hpp" +#include "scriptlist.hpp" #include #include @@ -82,7 +79,7 @@ void checkForValidate(void) { fclose(file); int ver = ScriptHelper::getNum(json, "info", "version"); if (ver < SCRIPT_VERSION || ver > SCRIPT_VERSION) { - Gui::DisplayWarnMsg(Lang::get("INCOMPATIBLE_SCRIPT")); + Msg::DisplayWarnMsg(Lang::get("INCOMPATIBLE_SCRIPT")); } } @@ -190,7 +187,7 @@ void runFunctions(nlohmann::json &json) { else missing = true; promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory; if(!missing) { - if (Gui::promptMsg(promptmsg)) { + if (Msg::promptMsg(promptmsg)) { removeDirRecursive(directory.c_str()); } } @@ -270,20 +267,20 @@ void loadColors(nlohmann::json &json) { } void ScriptList::DrawSubMenu(void) const { - Gui::DrawTop(); + GFX::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); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); for (int i = 0; i < 4; i++) { Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor); if (SubSelection == i) { - Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -298,7 +295,7 @@ void ScriptList::DrawList(void) const { std::string line1; std::string line2; std::string scriptAmount = std::to_string(selection +1) + " / " + std::to_string(fileInfo.size()); - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 239-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount); @@ -310,11 +307,11 @@ void ScriptList::DrawList(void) const { Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(fileInfo[selection].author), 400); Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(fileInfo[selection].shortDesc), 400); - Gui::DrawBottom(); - Gui::DrawArrow(295, -1); - Gui::DrawArrow(315, 240, 180.0); - Gui::DrawArrow(0, 218, 0, 1); - Gui::spriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); + GFX::DrawBottom(); + GFX::DrawArrow(295, -1); + GFX::DrawArrow(315, 240, 180.0); + GFX::DrawArrow(0, 218, 0, 1); + GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); if (Config::viewMode == 0) { for(int i=0;i()); + Gui::setScreen(std::make_unique()); } else { notConnectedMsg(); } break; case 2: if (isTesting == true) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else { notImplemented(); } @@ -467,17 +464,17 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } mode = 1; } else { - Gui::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST")); + Msg::DisplayWarnMsg(Lang::get("GET_SCRIPTS_FIRST")); } } else if (touching(touch, subPos[1])) { if (checkWifiStatus() == true) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else { notConnectedMsg(); } } else if (touching(touch, subPos[2])) { if (isTesting == true) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } else { notImplemented(); } diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index 66a6c70..e977f3b 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -24,12 +24,9 @@ * reasonable ways as different from the original version. */ +#include "credits.hpp" #include "keyboard.hpp" - -#include "screens/credits.hpp" -#include "screens/settings.hpp" - -#include "utils/config.hpp" +#include "settings.hpp" extern bool touching(touchPosition touch, Structs::ButtonPos button); @@ -53,20 +50,20 @@ void Settings::Draw(void) const { void Settings::DrawSubMenu(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); } - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); - Gui::DrawArrow(318, 240, 180.0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); + GFX::DrawArrow(318, 240, 180.0, 1); for (int i = 0; i < 3; i++) { Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); if (Selection == i) { - Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -76,19 +73,19 @@ void Settings::DrawSubMenu(void) const { } void Settings::DrawLanguageSelection(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SELECT_LANG"), 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SELECT_LANG"), 400); } - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); for (int language = 0; language < 10; language++) { Gui::Draw_Rect(langBlocks[language].x, langBlocks[language].y, langBlocks[language].w, langBlocks[language].h, Config::UnselectedColor); if (Config::lang == language) { - Gui::drawAnimatedSelector(langBlocks[language].x, langBlocks[language].y, langBlocks[language].w, langBlocks[language].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(langBlocks[language].x, langBlocks[language].y, langBlocks[language].w, langBlocks[language].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -106,7 +103,7 @@ void Settings::DrawLanguageSelection(void) const { } void Settings::DrawColorChanging(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); } else { @@ -128,15 +125,15 @@ void Settings::DrawColorChanging(void) const { - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); - Gui::DrawArrow(0, 0, 0, 1); - Gui::DrawArrow(318, 22, 180.0, 1); + GFX::DrawArrow(0, 0, 0, 1); + GFX::DrawArrow(318, 22, 180.0, 1); for (int i = 0; i < 7; i++) { if (colorMode == i) { - Gui::drawAnimatedSelector(54 + i * 25, 2, 16, 16, .060, C2D_Color32(140, 140, 140, 255)); + Gui::drawAnimatedSelector(54 + i * 25, 2, 16, 16, .060, TRANSPARENT, C2D_Color32(140, 140, 140, 255)); } } @@ -187,20 +184,20 @@ void Settings::DrawColorChanging(void) const { } void Settings::DrawMiscSettings(void) const { - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); } else { Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); } - Gui::DrawBottom(); - Gui::DrawArrow(0, 218, 0, 1); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); for (int i = 0; i < 2; i++) { Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor); if (Selection == i) { - Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -258,7 +255,7 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_A) { - if (Selection + 1 == 3) Screen::set(std::make_unique()); + if (Selection + 1 == 3) Gui::setScreen(std::make_unique()); else mode = Selection+1; } @@ -268,12 +265,12 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } else if (touching(touch, mainButtons[1])) { mode = 2; } else if (touching(touch, mainButtons[2])) { - Screen::set(std::make_unique()); + Gui::setScreen(std::make_unique()); } } if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { - Screen::back(); + Gui::screenBack(); return; } diff --git a/source/screens/unistore.cpp b/source/screens/unistore.cpp index bc83006..820c258 100644 --- a/source/screens/unistore.cpp +++ b/source/screens/unistore.cpp @@ -24,17 +24,13 @@ * reasonable ways as different from the original version. */ +#include "download.hpp" +#include "fileBrowse.hpp" +#include "formatting.hpp" +#include "json.hpp" #include "keyboard.hpp" - -#include "download/download.hpp" - -#include "screens/unistore.hpp" - -#include "utils/config.hpp" -#include "utils/fileBrowse.h" -#include "utils/formatting.hpp" -#include "utils/json.hpp" -#include "utils/scriptHelper.hpp" +#include "scriptHelper.hpp" +#include "unistore.hpp" #include #include @@ -186,21 +182,21 @@ void loadStoreColors(nlohmann::json &json) { } void UniStore::DrawSubMenu(void) const { - Gui::DrawTop(); + GFX::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); + GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2); + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); for (int i = 0; i < 3; i++) { Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor); if (subSelection == i) { - Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, Config::SelectedColor); + Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -215,7 +211,7 @@ void UniStore::DrawStoreList(void) const { std::string line1; std::string line2; std::string storeAmount = std::to_string(selection +1) + " / " + std::to_string(storeInfo.size()); - Gui::DrawTop(); + GFX::DrawTop(); if (Config::UseBars == true) { Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, storeInfo[selection].title, 400); Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 239-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, Config::TxtColor, storeAmount); @@ -227,13 +223,13 @@ void UniStore::DrawStoreList(void) const { Gui::DrawStringCentered(0, 120-((descLines.size()*20)/2)+i*20, 0.6f, Config::TxtColor, descLines[i], 400); } - Gui::DrawBottom(); - Gui::DrawArrow(295, -1); - Gui::DrawArrow(315, 240, 180.0); - Gui::DrawArrow(0, 218, 0, 1); - Gui::spriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); - Gui::spriteBlend(sprites_search_idx, arrowPos[4].x, arrowPos[4].y); - Gui::spriteBlend(sprites_update_idx, arrowPos[5].x, arrowPos[5].y); + GFX::DrawBottom(); + GFX::DrawArrow(295, -1); + GFX::DrawArrow(315, 240, 180.0); + GFX::DrawArrow(0, 218, 0, 1); + GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); + GFX::DrawSpriteBlend(sprites_search_idx, arrowPos[4].x, arrowPos[4].y); + GFX::DrawSpriteBlend(sprites_update_idx, arrowPos[5].x, arrowPos[5].y); if (Config::viewMode == 0) { for(int i=0;i #include diff --git a/source/utils/console.c b/source/utils/console.c index d00e0f2..0c383c1 100644 --- a/source/utils/console.c +++ b/source/utils/console.c @@ -1,4 +1,4 @@ -#include "utils/console.h" +#include "console.h" #include #include diff --git a/source/utils/extract.cpp b/source/utils/extract.cpp index e88cb56..769ab9c 100644 --- a/source/utils/extract.cpp +++ b/source/utils/extract.cpp @@ -24,7 +24,7 @@ * reasonable ways as different from the original version. */ -#include "utils/extract.hpp" +#include "extract.hpp" #include #include diff --git a/source/utils/fileBrowse.cpp b/source/utils/fileBrowse.cpp index 3ddb7aa..14368c5 100644 --- a/source/utils/fileBrowse.cpp +++ b/source/utils/fileBrowse.cpp @@ -1,11 +1,10 @@ +#include "common.hpp" +#include "config.hpp" +#include "fileBrowse.hpp" +#include "gfx.hpp" #include "gui.hpp" - -#include "screens/screenCommon.hpp" - -#include "utils/common.hpp" -#include "utils/config.hpp" -#include "utils/fileBrowse.h" -#include "utils/structs.hpp" +#include "screenCommon.hpp" +#include "structs.hpp" #include <3ds.h> #include @@ -31,82 +30,15 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button); extern touchPosition touch; std::vector buttonPositions = { - {295, 0, 25, 25, -1}, // Arrow Up. - {295, 215, 25, 25, -1}, // Arrow Down. - {15, 220, 50, 15, -1}, // Open. - {80, 220, 50, 15, -1}, // Select. - {145, 220, 50, 15, -1}, // Refresh. - {210, 220, 50, 15, -1}, // Back. - {0, 0, 25, 25, -1}, // ViewMode Change. + {295, 0, 25, 25}, // Arrow Up. + {295, 215, 25, 25}, // Arrow Down. + {15, 220, 50, 15}, // Open. + {80, 220, 50, 15}, // Select. + {145, 220, 50, 15}, // Refresh. + {210, 220, 50, 15}, // Back. + {0, 0, 25, 25}, // ViewMode Change. }; -/** - * Get the title ID. - * @param ndsFile DS ROM image. - * @param buf Output buffer for title ID. (Must be at least 4 characters.) - * @return 0 on success; non-zero on error. - */ -int grabTID(FILE *ndsFile, char *buf) { - fseek(ndsFile, offsetof(sNDSHeadertitlecodeonly, gameCode), SEEK_SET); - size_t read = fread(buf, 1, 4, ndsFile); - return !(read == 4); -} - -void findNdsFiles(vector& dirContents) { - struct stat st; - DIR *pdir = opendir("."); - - if (pdir == NULL) { - DisplayMsg("Unable to open the directory."); - for(int i=0;i<120;i++) - gspWaitForVBlank(); - } else { - while (continueNdsScan) - { - DirEntry dirEntry; - - struct dirent* pent = readdir(pdir); - if (pent == NULL) break; - - stat(pent->d_name, &st); - dirEntry.name = pent->d_name; - char scanningMessage[512]; - snprintf(scanningMessage, sizeof(scanningMessage), "Scanning SD card for DS roms...\n\n(Press B to cancel)\n\n\n\n\n\n\n\n\n%s", dirEntry.name.c_str()); - DisplayMsg(scanningMessage); - dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false; - if(!(dirEntry.isDirectory) && dirEntry.name.length() >= 3) { - if (strcasecmp(dirEntry.name.substr(dirEntry.name.length()-3, 3).c_str(), "nds") == 0) { - // Get game's TID - FILE *f_nds_file = fopen(dirEntry.name.c_str(), "rb"); - // char game_TID[5]; - grabTID(f_nds_file, dirEntry.tid); - dirEntry.tid[4] = 0; - fclose(f_nds_file); - - // dirEntry.tid = game_TID; - - dirContents.push_back(dirEntry); - file_count++; - } - } else if (dirEntry.isDirectory - && dirEntry.name.compare(".") != 0 - && dirEntry.name.compare("_nds") != 0 - && dirEntry.name.compare("3ds") != 0 - && dirEntry.name.compare("DCIM") != 0 - && dirEntry.name.compare("gm9") != 0 - && dirEntry.name.compare("luma") != 0 - && dirEntry.name.compare("Nintendo 3DS") != 0 - && dirEntry.name.compare("private") != 0 - && dirEntry.name.compare("retroarch") != 0) { - chdir(dirEntry.name.c_str()); - findNdsFiles(dirContents); - chdir(".."); - } - } - closedir(pdir); - } -} - off_t getFileSize(const char *fileName) { FILE* fp = fopen(fileName, "rb"); @@ -153,7 +85,7 @@ void getDirectoryContents(std::vector& dirContents, const std::vector< DIR *pdir = opendir("."); if(pdir == NULL) { - DisplayMsg("Unable to open the directory."); + Msg::DisplayMsg("Unable to open the directory."); for(int i=0;i<120;i++) gspWaitForVBlank(); } else { while(true) { @@ -223,9 +155,9 @@ std::string selectFilePath(std::string selectText, const std::vector - -#include "utils/formatting.hpp" +#include "formatting.hpp" // adapted from GM9i's byte parsing. std::string formatBytes(int bytes) { diff --git a/source/utils/ftp.c b/source/utils/ftp.c index 7109759..e5df31c 100644 --- a/source/utils/ftp.c +++ b/source/utils/ftp.c @@ -4,8 +4,8 @@ * from https://cr.yp.to/ftp/filesystem.html */ -#include "utils/console.h" -#include "utils/ftp.h" +#include "console.h" +#include "ftp.h" #include #include diff --git a/source/utils/scriptHelper.cpp b/source/utils/scriptHelper.cpp index 873d64f..ec66f19 100644 --- a/source/utils/scriptHelper.cpp +++ b/source/utils/scriptHelper.cpp @@ -24,18 +24,17 @@ * reasonable ways as different from the original version. */ +#include "download.hpp" +#include "extract.hpp" #include "gui.hpp" - -#include "download/download.hpp" - -#include "utils/extract.hpp" -#include "utils/scriptHelper.hpp" -#include "utils/thread.hpp" +#include "msg.hpp" +#include "scriptHelper.hpp" +#include "thread.hpp" #include extern "C" { - #include "utils/cia.h" + #include "cia.h" } extern bool showProgressBar; @@ -96,13 +95,13 @@ void ScriptHelper::downloadFile(std::string file, std::string output, std::strin // Remove a File. void ScriptHelper::removeFile(std::string file, std::string message) { - DisplayMsg(message); + Msg::DisplayMsg(message); deleteFile(file.c_str()); } // Install a file. void ScriptHelper::installFile(std::string file, std::string message) { - DisplayMsg(message); + Msg::DisplayMsg(message); installCia(file.c_str()); } @@ -127,7 +126,7 @@ Result ScriptHelper::createFile(const char * path) { // Display a Message for a specific amount of time. void ScriptHelper::displayTimeMsg(std::string message, int seconds) { - DisplayMsg(message); + Msg::DisplayMsg(message); for (int i = 0; i < 60*seconds; i++) { gspWaitForVBlank(); } diff --git a/source/utils/sound.cpp b/source/utils/sound.cpp index 3f26ac3..80fbd8d 100644 --- a/source/utils/sound.cpp +++ b/source/utils/sound.cpp @@ -1,4 +1,4 @@ -#include "utils/sound.h" +#include "sound.h" #include #include diff --git a/source/utils/stringutils.cpp b/source/utils/stringutils.cpp index 007c6ee..a3856d6 100644 --- a/source/utils/stringutils.cpp +++ b/source/utils/stringutils.cpp @@ -1,4 +1,4 @@ -#include "utils/stringutils.hpp" +#include "stringutils.hpp" bool matchPattern(std::string pattern, std::string tested) { diff --git a/source/utils/thread.cpp b/source/utils/thread.cpp index ca30d79..019e716 100644 --- a/source/utils/thread.cpp +++ b/source/utils/thread.cpp @@ -1,4 +1,4 @@ -#include "utils/thread.hpp" +#include "thread.hpp" #include <3ds.h> #include