UniStore list and screenshots (#54)

* Initial push.

* Fix png loading

* Remove unneeded casts

* Push my progress.

* Improve screenshot display

* Hopefully last commit here before merge?

Co-authored-by: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com>
This commit is contained in:
Pk11
2020-12-02 14:23:15 -06:00
committed by GitHub
parent 2e2acf819e
commit 78d0dad604
38 changed files with 9213 additions and 106 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ void StoreUtils::DrawDownList(const std::unique_ptr<Store> &store, const std::ve
Gui::DrawStringCentered(54 - 160 + (262 / 2), downloadBoxes[i].y + 4, 0.45f, TEXT_COLOR, entries[(i + store->GetDownloadSIndex())], 260, 0, font);
}
GFX::DrawSprite(sprites_shortcut_idx, downloadBoxes[6].x, downloadBoxes[6].y);
if (is3DSX) GFX::DrawSprite(sprites_shortcut_idx, downloadBoxes[6].x, downloadBoxes[6].y);
} else { // If no downloads available..
Gui::DrawStringCentered(54 - 160 + (262 / 2), downloadBoxes[0].y + 4, 0.5f, TEXT_COLOR, Lang::get("NO_DOWNLOADS_AVAILABLE"), 255, 0, font);
+6 -1
View File
@@ -75,6 +75,11 @@ void StoreUtils::DrawEntryInfo(const std::unique_ptr<Store> &store, const std::u
bool &showMark: Reference to showMark.. to show the mark menu.
bool &fetch: Reference to fetch, so we know, if we need to fetch, when accessing download list.
*/
void StoreUtils::EntryHandle(bool &showMark, bool &fetch) {
void StoreUtils::EntryHandle(bool &showMark, bool &fetch, bool &sFetch, int &mode) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, btn))) showMark = true;
if (hDown & KEY_SELECT) {
sFetch = true;
mode = 5;
}
}
+127
View File
@@ -0,0 +1,127 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
/*
Draw the Screenshot menu.
const C2D_Image &img: The C2D_Image of the screenshot.
const int sIndex: The Screenshot index.
const bool sFetch: If fetching screenshots or not.
const int screenshotSize: The screenshot amount.
const std::string &name: The name of the screenshot.
const int zoom: The zoom level, zoom out, 1x scale, or zoom in.
*/
void StoreUtils::DrawScreenshotMenu(const C2D_Image &img, const int sIndex, const bool sFetch, const int screenshotSize, const std::string &name, const int zoom) {
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 240, BG_COLOR);
if (screenshotSize > 0) {
float scale = 1.0f;
if (zoom == 0) {
scale = std::min(1.0f, std::min(400.0f / img.subtex->width, 240.0f / img.subtex->height));
if (img.tex) C2D_DrawImageAt(img, (400 - img.subtex->width * scale) / 2, (240 - img.subtex->height * scale) / 2, 0.5f, nullptr, scale, scale);
} else {
// Create new C2D_Image with smaller subtex
C2D_Image top = img;
if (img.subtex->height > 240)
top.subtex = new Tex3DS_SubTexture({img.subtex->width, (u16)(img.subtex->height / 2), img.subtex->left, img.subtex->top, img.subtex->right, 1.0f - (img.subtex->height / 2 / 512.0f)});
// If zoom == 2, then zoom in to fit the screen
if (zoom == 2)
scale = std::min(400.0f / top.subtex->width, 240.0f / top.subtex->height);
if (top.tex) C2D_DrawImageAt(top, (400 - top.subtex->width * scale) / 2, (240 - top.subtex->height * scale) / 2, 0.5f, nullptr, scale, scale);
// Only delete if new
if (top.subtex->height > 240)
delete top.subtex;
}
GFX::DrawBottom();
/* Bottom. */
if (zoom > 0 && img.subtex->height * scale > 240) {
C2D_Image bottom = img;
bottom.subtex = new Tex3DS_SubTexture({img.subtex->width, (u16)(img.subtex->height / 2), img.subtex->left, img.subtex->bottom + (img.subtex->height / 2 / 512.0f), img.subtex->right, img.subtex->bottom});
if (bottom.tex) C2D_DrawImageAt(bottom, (320 - bottom.subtex->width * scale) / 2, (240 - bottom.subtex->height * scale) / 2, 0.5f, nullptr, scale, scale);
delete bottom.subtex;
} else {
Gui::Draw_Rect(0, 215, 320, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 320, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 220, 0.5f, TEXT_COLOR, Lang::get("SCREENSHOT_INSTRUCTIONS"), 310, 0, font);
char screenshots[0x100];
snprintf(screenshots, sizeof(screenshots), Lang::get("SCREENSHOT").c_str(), sIndex + 1, screenshotSize);
Gui::DrawStringCentered(0, 2, 0.6f, WHITE, screenshots, 310, 0, font);
Gui::DrawStringCentered(0, 40, 0.6f, WHITE, name, 310, 0, font);
}
} else {
GFX::DrawBottom();
Gui::DrawStringCentered(0, 2, 0.6f, WHITE, Lang::get("NO_SCREENSHOTS_AVAILABLE"), 310);
}
}
/*
Screenshot Menu handle.
C2D_Image &img: The C2D_Image of the screenshot.
int &sIndex: The Screenshot index.
bool &sFetch: If fetching screenshots or not.
const int screenshotSize: The screenshot amount.
int &zoom: The zoom level, zoom out, 1x scale, or zoom in.
*/
void StoreUtils::ScreenshotMenu(C2D_Image &img, int &sIndex, bool &sFetch, int &storeMode, const int screenshotSize, int &zoom) {
if (hDown & KEY_B) {
zoom = false;
sIndex = 0;
storeMode = 0; // Go back to EntryInfo.
}
if (hDown & KEY_RIGHT) {
if (sIndex < screenshotSize - 1) {
sIndex++;
sFetch = true;
}
}
if (hDown & KEY_DOWN && zoom > 0) zoom--;
if (hDown & KEY_UP && zoom < 2) zoom++;
if (hDown & KEY_LEFT) {
if (sIndex > 0) {
sIndex--;
sFetch = true;
}
}
}
+14 -15
View File
@@ -54,7 +54,6 @@ static const std::vector<Structs::ButtonPos> langButtons = {
};
static const std::vector<Structs::ButtonPos> toggleAbles = {
{ 52, 6, 24, 24 }, // Back arrow.
{ 288, 64, 24, 24 },
{ 288, 140, 24, 24 }
};
@@ -125,11 +124,11 @@ static void DrawSettingsDir(int selection) {
Draw Auto-Update Settings page.
*/
static void DrawAutoUpdate(int selection) {
Gui::Draw_Rect(48, 0, 272, 36, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 36, 272, 1, ENTRY_BAR_OUTL_COLOR);
GFX::DrawSprite(sprites_arrow_idx, 52, 6);
Gui::Draw_Rect(48, 0, 272, 25, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 25, 272, 1, ENTRY_BAR_OUTL_COLOR);
GFX::DrawSprite(sprites_arrow_idx, back.x, back.y);
Gui::DrawStringCentered(32, 7, 0.6, TEXT_COLOR, Lang::get("AUTO_UPDATE_SETTINGS"), 240, 0, font);
Gui::DrawStringCentered(32, 2, 0.6, TEXT_COLOR, Lang::get("AUTO_UPDATE_SETTINGS"), 240, 0, font);
/* Toggle Boxes. */
Gui::Draw_Rect(48, 64, 273, 24, (selection == 0 ? SIDEBAR_UNSELECTED_COLOR : BOX_INSIDE_COLOR));
@@ -149,11 +148,11 @@ static void DrawAutoUpdate(int selection) {
int selection: The Settings Selection.
*/
static void DrawGUISettings(int selection) {
Gui::Draw_Rect(48, 0, 272, 36, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 36, 272, 1, ENTRY_BAR_OUTL_COLOR);
GFX::DrawSprite(sprites_arrow_idx, 52, 6);
Gui::Draw_Rect(48, 0, 272, 25, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 25, 272, 1, ENTRY_BAR_OUTL_COLOR);
GFX::DrawSprite(sprites_arrow_idx, back.x, back.y);
Gui::DrawStringCentered(32, 7, 0.6, TEXT_COLOR, Lang::get("GUI_SETTINGS"), 240, 0, font);
Gui::DrawStringCentered(32, 2, 0.6, TEXT_COLOR, Lang::get("GUI_SETTINGS"), 240, 0, font);
Gui::Draw_Rect(48, 64, 273, 24, (selection == 0 ? SIDEBAR_UNSELECTED_COLOR : BOX_INSIDE_COLOR));
Gui::DrawString(55, 68, 0.5f, TEXT_COLOR, Lang::get("UNISTORE_BG"), 210, 0, font);
@@ -388,14 +387,14 @@ static void AutoUpdateLogic(int &page, int &selection) {
}
if (hDown & KEY_TOUCH) {
if (touching(touch, toggleAbles[0])) {
if (touching(touch, back)) {
page = 0;
selection = 2;
} else if (touching(touch, toggleAbles[1])) {
} else if (touching(touch, toggleAbles[0])) {
config->autoupdate(!config->autoupdate());
} else if (touching(touch, toggleAbles[2])) {
} else if (touching(touch, toggleAbles[1])) {
config->updatecheck(!config->updatecheck());
}
}
@@ -438,14 +437,14 @@ static void GUISettingsLogic(int &page, int &selection) {
}
if (hDown & KEY_TOUCH) {
if (touching(touch, toggleAbles[0])) {
if (touching(touch, back)) {
page = 0;
selection = 3;
} else if (touching(touch, toggleAbles[1])) {
} else if (touching(touch, toggleAbles[0])) {
config->usebg(!config->usebg());
} else if (touching(touch, toggleAbles[2])) {
} else if (touching(touch, toggleAbles[1])) {
config->customfont(!config->customfont());
(config->customfont() ? Init::LoadFont() : Init::UnloadFont());
+54
View File
@@ -477,6 +477,12 @@ std::vector<std::string> Store::GetDownloadList(int index) const {
return temp;
}
/*
Get filesizes for each download entry.
int index: The index.
const std::string &entry: The entry name.
*/
std::string Store::GetFileSizes(int index, const std::string &entry) const {
if (!this->valid) return "";
@@ -489,4 +495,52 @@ std::string Store::GetFileSizes(int index, const std::string &entry) const {
}
return "";
}
/*
Get Screenshot URL list.
int index: The Entry Index.
*/
std::vector<std::string> Store::GetScreenshotList(int index) const {
if (!this->valid) return { };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { };
std::vector<std::string> screenshots;
if (this->storeJson["storeContent"][index]["info"].contains("screenshots")) {
if (this->storeJson["storeContent"][index]["info"]["screenshots"].is_array()) {
for(auto &item : this->storeJson["storeContent"][index]["info"]["screenshots"]) {
if (item.is_object() && item.contains("url")) screenshots.push_back(item["url"]);
else screenshots.push_back("");
}
}
}
return screenshots;
}
/*
Get Screenshot names.
int index: The Entry Index.
*/
std::vector<std::string> Store::GetScreenshotNames(int index) const {
if (!this->valid) return { };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { };
std::vector<std::string> screenshotNames;
if (this->storeJson["storeContent"][index]["info"].contains("screenshots")) {
if (this->storeJson["storeContent"][index]["info"]["screenshots"].is_array()) {
for(auto &item : this->storeJson["storeContent"][index]["info"]["screenshots"]) {
if (item.is_object() && item.contains("description")) screenshotNames.push_back(item["description"]);
else screenshotNames.push_back("");
}
}
}
return screenshotNames;
}
+3
View File
@@ -63,4 +63,7 @@ StoreEntry::StoreEntry(const std::unique_ptr<Store> &store, const std::unique_pt
this->Sizes.push_back( store->GetFileSizes(index, entries[i]) );
}
}
this->Screenshots = store->GetScreenshotList(index);
this->ScreenshotNames = store->GetScreenshotNames(index);
}