Universal-Updater Full Rewrite based of UniStore v3.0.0. (#51)

* No Nightlies for the Full-Rewrite.

* Initial push, i guess.

* Forgot to push the Test UniStore + T3X...

* Use C2D flags for wrapping and centering

* gitignore t3x correctly

* Remove Test Store and hardcode to `sdmc:/3ds/Universal-Updater/stores/Universal-DB.unistore` for now.

* Is functional now.

* *More special checks and work.*

* const <typename T> &.

* Universal-DB, not Universal DB.

* Derp.

* Make 3DSX, NDS & Archive path configurable.

* Last fixes + Fade out screen on exit.

* See Desc. for more.

- Add QR Code scan for downloading UniStores.
- Add new Graphics.
- Some fixes + improvements.

* Fix search filtering, re-sort after search

* Fix update check

* Clear search items with X, not just reset results

* The next progress.

* PLEASE tell me, this is the only error..

Co-authored-by: Pk11 <epicpkmn11@outlook.com>
This commit is contained in:
StackZ
2020-10-30 03:31:20 +01:00
committed by GitHub
parent 5d38c98698
commit 913475eabf
142 changed files with 13937 additions and 14588 deletions
+64 -65
View File
@@ -27,85 +27,84 @@
#include "common.hpp"
#include "gfx.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
extern u32 barColor, bgTopColor, bgBottomColor, TextColor;
/*
Draw the base top screen.
*/
void GFX::DrawTop(void) {
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, isScriptSelected ? bgTopColor : config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, isScriptSelected ? barColor : config->barColor());
if (config->useBars()) {
DrawSprite(sprites_top_screen_top_idx, 0, 0);
DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
Gui::Draw_Rect(0, 0, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 25, 400, 215, BG_COLOR);
Gui::Draw_Rect(0, 25, 400, 1, BAR_OUTL_COLOR);
}
void GFX::DrawBottom(void) {
/*
Draw the base bottom screen.
*/
void GFX::DrawBottom() {
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, isScriptSelected ? bgBottomColor : config->bottomBG());
Gui::Draw_Rect(0, 215, 320, 25, isScriptSelected ? barColor : config->barColor());
if (config->useBars()) {
DrawSprite(sprites_bottom_screen_top_idx, 0, 0);
DrawSprite(sprites_bottom_screen_bot_idx, 0, 215);
}
Gui::Draw_Rect(0, 0, 320, 240, BG_COLOR);
}
/*
Draw the box.
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const float &width: Const Reference to the Width of the button.
const float &height: Const Reference to the Height of the button.
const bool &selected: Const Reference, if outline is selected (Red) or not (Black).
const uint32_t &clr: (Optional) The color of the inside of the box.
*/
void GFX::drawBox(const float &xPos, const float &yPos, const float &width, const float &height, const bool &selected, const uint32_t &clr) {
static constexpr int w = 1;
const uint32_t outlineColor = selected ? BOX_SELECTED_COLOR : BOX_UNSELECTED_COLOR; // Get Selected | Unselected color.
Gui::Draw_Rect(xPos, yPos, width, height, clr); // Draw middle BG.
Gui::Draw_Rect(xPos, yPos, width, w, outlineColor); // Top.
Gui::Draw_Rect(xPos, yPos + w, w, height - 2 * w, outlineColor); // Left.
Gui::Draw_Rect(xPos + width - w, yPos + w, w, height - 2 * w, outlineColor); // Right.
Gui::Draw_Rect(xPos, yPos + height - w, width, w, outlineColor); // Bottom.
}
extern C2D_SpriteSheet sprites;
void GFX::DrawSprite(int img, int x, int y, float ScaleX, float ScaleY) {
/*
Draw a Sprite of the sprites SpriteSheet.
const int &img: Const Reference to the Image index.
const int &x: Const Reference to the X-Position where to draw.
const int &y: Const Reference to the Y-Position where to draw.
const float &ScaleX: (Optional) Const Reference to the X-Scale of the Sprite. (1 by default)
const float &ScaleY: (Optional) Const Reference to the Y-Scale of the Sprite. (1 by default)
*/
void GFX::DrawSprite(const int &img, const int &x, const int &y, const float &ScaleX, const 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;
C2D_SetImageTint(&tint, C2D_TopLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
/*
Draw a button (actually the box) with a centered string in it.
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, img), x, y, 0.5f, &tint, ScaleX, ScaleY);
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const float &width: Const Reference to the Width of the button.
const float &height: Const Reference to the Height of the button.
const bool &selected: Const Reference, if outline is selected (Red) or not (Black).
const std::string &Text: Const Reference of the Text which should be drawn.
*/
void GFX::DrawButton(const float &xPos, const float &yPos, const float &width, const float &height, const bool &selected, const std::string &Text) {
drawBox(xPos, yPos, width, height, selected);
Gui::DrawStringCentered(xPos - 160 + (width / 2), yPos + (height / 2) - (Gui::GetStringHeight(0.4f, Text) / 2), 0.4f, TEXT_COLOR, Text, width - 4, height - 4);
}
void GFX::DrawArrow(int x, int y, float rotation, int arrowSprite) {
C2D_Sprite sprite;
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
/*
Draw the checkbox.
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);
}
// Draw a Button and draw Text on it.
void GFX::DrawButton(int x, int y, std::string ButtonText, u32 color) {
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, color, 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, color, 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, color, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, color, 0.5);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, sprites_button_idx), x, y, 0.5f, &tint);
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, isScriptSelected ? TextColor : config->textColor(), ButtonText, 145, 30);
}
void GFX::TextFormatted(float x, float y, float size, const char *format, ...) {
char str[512];
va_list va;
va_start(va, format);
vsnprintf(str, 512, format, va);
va_end(va);
char * Text = strtok(str, "\n");
Gui::DrawStringCentered(x, y, size, isScriptSelected ? TextColor : config->textColor(), Text);
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const bool &selected: Const Reference, checked or not.
*/
void GFX::DrawCheckbox(const float &xPos, const float &yPos, const bool &selected) {
GFX::DrawSprite((selected ? sprites_checked_idx : sprites_unchecked_idx), xPos, yPos);
}
-97
View File
@@ -1,97 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "gfx.hpp"
#include "keyboard.hpp"
#include "screenCommon.hpp"
extern std::unique_ptr<Config> config;
std::string Input::setkbdString(uint maxLength, std::string Text) {
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, maxLength);
char temp[maxLength] = {0};
swkbdSetHintText(&state, Text.c_str());
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, SWKBD_FILTER_PROFANITY, 0);
SwkbdButton ret = swkbdInputText(&state, temp, sizeof(temp));
temp[maxLength-1] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return temp;
}
return "";
}
int Input::setInt(int maxValue, std::string Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Text, 400);
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NUMPAD, 2, 3);
swkbdSetFeatures(&state, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[4] = {0};
SwkbdButton ret = swkbdInputText(&state, input, sizeof(input));
input[3] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return (int)std::min(std::stoi(input), maxValue);
} else {
return -1;
}
return -1;
}
std::uint8_t Input::setu8(std::string Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Text, 400);
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NUMPAD, 2, 3);
swkbdSetFeatures(&state, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[4] = {0};
SwkbdButton ret = swkbdInputText(&state, input, sizeof(input));
input[3] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return (u8)std::min(std::stoi(input), 255);
} else {
return -1;
}
return -1;
}
+65 -59
View File
@@ -27,90 +27,96 @@
#include "common.hpp"
#include "msg.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
/*
Displays just a message until the next draw frame.
extern u32 barColor, bgTopColor, bgBottomColor, TextColor;
// I do not think we need that at all.
void Msg::DisplayStartMSG() {
const std::string &Text: The Message, which should be displayed.
*/
void Msg::DisplayMsg(const std::string &Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, config->barColor());
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("STARTING_UNIVERSAL_UPDATER"));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, config->topBG());
Gui::Draw_Rect(0, 215, 320, 25, config->barColor());
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
C3D_FrameEnd(0);
}
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
void Msg::DisplayMsg(std::string text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, isScriptSelected ? TextColor : config->textColor(), text, 395, 70);
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, Text)) / 2, 0.6f, TEXT_COLOR, Text, 395, 100);
GFX::DrawBottom();
C3D_FrameEnd(0);
}
void Msg::DisplayWarnMsg(std::string Text) {
/*
Displays a warn message for 3 seconds.
const std::string &Text: The Message, which should be displayed.
*/
void Msg::DisplayWarnMsg(const std::string &Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.6f, isScriptSelected ? TextColor : config->textColor(), Text, 400);
Gui::DrawStringCentered(0, 1, 0.6f, TEXT_COLOR, Text, 400);
GFX::DrawBottom();
C3D_FrameEnd(0);
for (int i = 0; i < 60*3; i++) {
for (int i = 0; i < 60 * 3; i++) {
gspWaitForVBlank();
}
}
/*
Display a Message, which needs to be confirmed with A/B.
const std::vector<Structs::ButtonPos> 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) {
const std::string &promptMsg: The Message, which should be displayed.
*/
bool Msg::promptMsg(const std::string &promptMsg) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
C2D_TargetClear(Top, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, promptMsg))/2, 0.6f, isScriptSelected ? TextColor : config->textColor(), promptMsg, 395, 70);
Gui::DrawStringCentered(0, 217, 0.72f, isScriptSelected ? TextColor : config->textColor(), Lang::get("CONFIRM_OR_CANCEL"), 400);
GFX::DrawBottom();
Gui::Draw_Rect(10, 100, 140, 35, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(170, 100, 140, 35, isScriptSelected ? barColor : config->barColor());
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("YES"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("NO"), 140);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, promptMsg)) / 2, 0.6f, TEXT_COLOR, promptMsg, 395, 100);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("CONFIRM_OR_CANCEL"), 400);
C3D_FrameEnd(0);
for (int i = 0; i < 20; i++) gspWaitForVBlank();
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;
}
if (hidKeysDown() & KEY_A) return true;
else if (hidKeysDown() & KEY_B) return false;
}
}
/*
Display a message, which can be "confirmed" with any key.
const std::string &msg: The message which should be displayed.
*/
void Msg::waitMsg(const std::string &msg) {
bool doOut = false;
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, msg)) / 2, 0.6f, TEXT_COLOR, msg, 395, 100);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("KEY_CONTINUE"), 400);
C3D_FrameEnd(0);
for (int i = 0; i < 20; i++) gspWaitForVBlank();
while(!doOut) {
hidScanInput();
if (hidKeysDown()) doOut = !doOut;
}
}