mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2025-02-18 00:08:24 +00:00
more refactoring
This commit is contained in:
parent
660a762f9d
commit
258b4a7d70
11 changed files with 176 additions and 159 deletions
|
@ -37,6 +37,7 @@
|
||||||
#include "colors.hpp"
|
#include "colors.hpp"
|
||||||
#include "clickable.hpp"
|
#include "clickable.hpp"
|
||||||
#include "hid.hpp"
|
#include "hid.hpp"
|
||||||
|
#include "multiselection.hpp"
|
||||||
#include "scrollable.hpp"
|
#include "scrollable.hpp"
|
||||||
#include "sprites.h"
|
#include "sprites.h"
|
||||||
#include "title.hpp"
|
#include "title.hpp"
|
||||||
|
|
|
@ -70,48 +70,6 @@ std::string Gui::nameFromCell(size_t index)
|
||||||
return directoryList->cellName(index);
|
return directoryList->cellName(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multi selection
|
|
||||||
|
|
||||||
static std::vector<size_t> selEnt;
|
|
||||||
|
|
||||||
std::vector<size_t> Gui::selectedEntries(void)
|
|
||||||
{
|
|
||||||
return selEnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Gui::multipleSelectionEnabled(void)
|
|
||||||
{
|
|
||||||
return !selEnt.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gui::clearSelectedEntries(void)
|
|
||||||
{
|
|
||||||
selEnt.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gui::addSelectedEntry(size_t idx)
|
|
||||||
{
|
|
||||||
int existing = -1;
|
|
||||||
for (size_t i = 0, sz = selEnt.size(); i < sz && existing == -1; i++)
|
|
||||||
{
|
|
||||||
if (selEnt.at(i) == idx)
|
|
||||||
{
|
|
||||||
existing = (int)i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existing == -1)
|
|
||||||
{
|
|
||||||
selEnt.push_back(idx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selEnt.erase(selEnt.begin() + existing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gui implementation
|
|
||||||
|
|
||||||
static void drawBackground(gfxScreen_t screen)
|
static void drawBackground(gfxScreen_t screen)
|
||||||
{
|
{
|
||||||
if (screen == GFX_TOP)
|
if (screen == GFX_TOP)
|
||||||
|
@ -151,39 +109,32 @@ void drawPulsingOutline(u32 x, u32 y, u16 w, u16 h, u8 size, u32 color)
|
||||||
|
|
||||||
void Gui::drawCopy(const std::u16string& src, u32 offset, u32 size)
|
void Gui::drawCopy(const std::u16string& src, u32 offset, u32 size)
|
||||||
{
|
{
|
||||||
// C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
C2D_Text copyText, srcText;
|
||||||
// C2D_TargetClear(top, COLOR_BG);
|
std::string sizeString = StringUtils::sizeString(offset) + " of " + StringUtils::sizeString(size);
|
||||||
// C2D_TargetClear(bottom, COLOR_BG);
|
C2D_TextParse(&srcText, dynamicBuf, StringUtils::UTF16toUTF8(src).c_str());
|
||||||
|
C2D_TextParse(©Text, dynamicBuf, sizeString.c_str());
|
||||||
|
C2D_TextOptimize(&srcText);
|
||||||
|
C2D_TextOptimize(©Text);
|
||||||
|
const float scale = 0.6f;
|
||||||
|
const u32 size_h = fontGetInfo()->lineFeed;
|
||||||
|
const u32 src_w = StringUtils::textWidth(srcText, scale);
|
||||||
|
const u32 size_w = StringUtils::textWidth(copyText, scale);
|
||||||
|
|
||||||
// C2D_SceneBegin(top);
|
C2D_TextBufClear(dynamicBuf);
|
||||||
// drawBackground(GFX_TOP);
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||||
|
C2D_SceneBegin(bottom);
|
||||||
// C2D_SceneBegin(bottom);
|
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
||||||
// drawBackground(GFX_BOTTOM);
|
C2D_DrawRectSolid(40, 160, 0.5f, (float)offset / (float)size * 240, 40, COLOR_BLUE);
|
||||||
|
C2D_DrawText(&srcText, C2D_WithColor, 40 + (240 - src_w) / 2, 40 + ceilf((120 - size_h) / 2), 0.5f, scale, scale, COLOR_WHITE);
|
||||||
// static const int barHeight = 19;
|
C2D_DrawText(©Text, C2D_WithColor, 40 + (240 - size_w) / 2, 160 + ceilf((40 - size_h) / 2), 0.5f, scale, scale, COLOR_WHITE);
|
||||||
// static const int progressBarHeight = 50;
|
frameEnd();
|
||||||
// static const int spacingFromSides = 20;
|
|
||||||
// static const int spacingFromBars = (240 - barHeight * 2 - progressBarHeight) / 2;
|
|
||||||
// static const int width = 320 - spacingFromSides * 2;
|
|
||||||
|
|
||||||
// C2D_DrawRectSolid(spacingFromSides - 2, barHeight + spacingFromBars - 2, 0.5f, width + 4, progressBarHeight + 4, COLOR_GREY_LIGHT);
|
|
||||||
// C2D_DrawRectSolid(spacingFromSides, barHeight + spacingFromBars, 0.5f, width, progressBarHeight, COLOR_WHITE);
|
|
||||||
// C2D_DrawRectSolid(spacingFromSides, barHeight + spacingFromBars, 0.5f, (float)offset / (float)size * width, progressBarHeight, C2D_Color32(116, 222, 126, 255));
|
|
||||||
|
|
||||||
// std::string sizeString = StringUtils::sizeString(offset) + " of " + StringUtils::sizeString(size);
|
|
||||||
// C2D_TextBufClear(dynamicBuf);
|
|
||||||
// C2D_TextParse(©Text, dynamicBuf, sizeString.c_str());
|
|
||||||
// C2D_TextOptimize(©Text);
|
|
||||||
// C2D_DrawText(©Text, 0, (320 - ceilf(copyText.width*0.5f))/2, 112, 0.5f, 0.5f, 0.5f);
|
|
||||||
// frameEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Gui::askForConfirmation(const std::string& message)
|
bool Gui::askForConfirmation(const std::string& message)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
Clickable* buttonYes = new Clickable(42, 142, 116, 56, COLOR_GREY_DARK, COLOR_WHITE, "\uE000 Yes", true);
|
Clickable* buttonYes = new Clickable(42, 162, 116, 36, COLOR_GREY_DARK, COLOR_WHITE, "\uE000 Yes", true);
|
||||||
Clickable* buttonNo = new Clickable(162, 142, 116, 56, COLOR_GREY_DARK, COLOR_WHITE, "\uE001 No", true);
|
Clickable* buttonNo = new Clickable(162, 162, 116, 36, COLOR_GREY_DARK, COLOR_WHITE, "\uE001 No", true);
|
||||||
HidHorizontal* hid = new HidHorizontal(2, 2);
|
HidHorizontal* hid = new HidHorizontal(2, 2);
|
||||||
C2D_Text text;
|
C2D_Text text;
|
||||||
C2D_TextParse(&text, dynamicBuf, message.c_str());
|
C2D_TextParse(&text, dynamicBuf, message.c_str());
|
||||||
|
@ -211,22 +162,23 @@ bool Gui::askForConfirmation(const std::string& message)
|
||||||
buttonYes->selected(hid->index() == 0);
|
buttonYes->selected(hid->index() == 0);
|
||||||
buttonNo->selected(hid->index() == 1);
|
buttonNo->selected(hid->index() == 1);
|
||||||
|
|
||||||
|
C2D_TextBufClear(dynamicBuf);
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||||
C2D_SceneBegin(bottom);
|
C2D_SceneBegin(bottom);
|
||||||
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
||||||
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - text.width * 0.6) / 2, 40 + ceilf(100 - 0.6f * fontGetInfo()->lineFeed) / 2, 0.5f, 0.6f, 0.6f, COLOR_WHITE);
|
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - text.width * 0.6) / 2, 40 + ceilf(120 - 0.6f * fontGetInfo()->lineFeed) / 2, 0.5f, 0.6f, 0.6f, COLOR_WHITE);
|
||||||
C2D_DrawRectSolid(40, 140, 0.5f, 240, 60, COLOR_GREY_LIGHT);
|
C2D_DrawRectSolid(40, 160, 0.5f, 240, 40, COLOR_GREY_LIGHT);
|
||||||
|
|
||||||
buttonYes->draw(0.7, 0);
|
buttonYes->draw(0.7, 0);
|
||||||
buttonNo->draw(0.7, 0);
|
buttonNo->draw(0.7, 0);
|
||||||
|
|
||||||
if (hid->index() == 0)
|
if (hid->index() == 0)
|
||||||
{
|
{
|
||||||
drawPulsingOutline(42, 142, 116, 56, 2, COLOR_BLUE);
|
drawPulsingOutline(42, 162, 116, 36, 2, COLOR_BLUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawPulsingOutline(162, 142, 116, 56, 2, COLOR_BLUE);
|
drawPulsingOutline(162, 162, 116, 36, 2, COLOR_BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
frameEnd();
|
frameEnd();
|
||||||
|
@ -241,7 +193,7 @@ bool Gui::askForConfirmation(const std::string& message)
|
||||||
void Gui::showInfo(const std::string& message)
|
void Gui::showInfo(const std::string& message)
|
||||||
{
|
{
|
||||||
const float size = 0.6f;
|
const float size = 0.6f;
|
||||||
Clickable* button = new Clickable(40, 140, 240, 60, COLOR_GREY_DARK, COLOR_WHITE, "OK", true);
|
Clickable* button = new Clickable(42, 162, 236, 36, COLOR_GREY_DARK, COLOR_WHITE, "OK", true);
|
||||||
button->selected(true);
|
button->selected(true);
|
||||||
std::string t = StringUtils::wrap(message, size, 220);
|
std::string t = StringUtils::wrap(message, size, 220);
|
||||||
C2D_Text text;
|
C2D_Text text;
|
||||||
|
@ -261,12 +213,13 @@ void Gui::showInfo(const std::string& message)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
C2D_TextBufClear(dynamicBuf);
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||||
C2D_SceneBegin(bottom);
|
C2D_SceneBegin(bottom);
|
||||||
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
||||||
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - w) / 2, 40 + ceilf(100 - h) / 2, 0.5f, size, size, COLOR_WHITE);
|
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - w) / 2, 40 + ceilf(120 - h) / 2, 0.5f, size, size, COLOR_WHITE);
|
||||||
button->draw(0.7f, COLOR_BLUE);
|
button->draw(0.7f, COLOR_BLUE);
|
||||||
drawPulsingOutline(42, 142, 236, 56, 2, COLOR_BLUE);
|
drawPulsingOutline(42, 162, 236, 36, 2, COLOR_BLUE);
|
||||||
frameEnd();
|
frameEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +229,7 @@ void Gui::showInfo(const std::string& message)
|
||||||
void Gui::showError(Result res, const std::string& message)
|
void Gui::showError(Result res, const std::string& message)
|
||||||
{
|
{
|
||||||
const float size = 0.6f;
|
const float size = 0.6f;
|
||||||
Clickable* button = new Clickable(40, 140, 240, 60, COLOR_GREY_DARKER, COLOR_WHITE, "OK", true);
|
Clickable* button = new Clickable(42, 162, 236, 36, COLOR_GREY_DARKER, COLOR_WHITE, "OK", true);
|
||||||
button->selected(true);
|
button->selected(true);
|
||||||
std::string t = StringUtils::wrap(message, size, 220);
|
std::string t = StringUtils::wrap(message, size, 220);
|
||||||
std::string e = StringUtils::format("Error: 0x%08lX", res);
|
std::string e = StringUtils::format("Error: 0x%08lX", res);
|
||||||
|
@ -299,13 +252,14 @@ void Gui::showError(Result res, const std::string& message)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
C2D_TextBufClear(dynamicBuf);
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||||
C2D_SceneBegin(bottom);
|
C2D_SceneBegin(bottom);
|
||||||
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
|
||||||
C2D_DrawText(&error, C2D_WithColor, 44, 44, 0.5f, 0.5f, 0.5f, COLOR_RED);
|
C2D_DrawText(&error, C2D_WithColor, 44, 44, 0.5f, 0.5f, 0.5f, COLOR_RED);
|
||||||
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - w) / 2, 40 + ceilf(100 - h) / 2, 0.5f, size, size, COLOR_WHITE);
|
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - w) / 2, 40 + ceilf(120 - h) / 2, 0.5f, size, size, COLOR_WHITE);
|
||||||
button->draw(0.7f, COLOR_RED);
|
button->draw(0.7f, COLOR_RED);
|
||||||
drawPulsingOutline(42, 142, 236, 56, 2, COLOR_RED);
|
drawPulsingOutline(42, 162, 236, 36, 2, COLOR_RED);
|
||||||
frameEnd();
|
frameEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,6 +297,8 @@ void Gui::init(void)
|
||||||
buttonBackup = new Clickable(204, 102, 110, 54, COLOR_GREY_DARKER, COLOR_WHITE, "Backup \uE004", true);
|
buttonBackup = new Clickable(204, 102, 110, 54, COLOR_GREY_DARKER, COLOR_WHITE, "Backup \uE004", true);
|
||||||
buttonRestore = new Clickable(204, 158, 110, 54, COLOR_GREY_DARKER, COLOR_WHITE, "Restore \uE005", true);
|
buttonRestore = new Clickable(204, 158, 110, 54, COLOR_GREY_DARKER, COLOR_WHITE, "Restore \uE005", true);
|
||||||
directoryList = new Scrollable(6, 102, 196, 110, 5);
|
directoryList = new Scrollable(6, 102, 196, 110, 5);
|
||||||
|
buttonBackup->canInvertColor(true);
|
||||||
|
buttonRestore->canInvertColor(true);
|
||||||
|
|
||||||
spritesheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
|
spritesheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
|
||||||
flag = C2D_SpriteSheetGetImage(spritesheet, sprites_checkpoint_idx);
|
flag = C2D_SpriteSheetGetImage(spritesheet, sprites_checkpoint_idx);
|
||||||
|
@ -406,7 +362,7 @@ void Gui::bottomScroll(bool enable)
|
||||||
|
|
||||||
void Gui::updateButtonsColor(void)
|
void Gui::updateButtonsColor(void)
|
||||||
{
|
{
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
buttonBackup->setColors(COLOR_WHITE, COLOR_BLACK);
|
buttonBackup->setColors(COLOR_WHITE, COLOR_BLACK);
|
||||||
buttonRestore->setColors(COLOR_WHITE, COLOR_GREY_LIGHT);
|
buttonRestore->setColors(COLOR_WHITE, COLOR_GREY_LIGHT);
|
||||||
|
@ -469,6 +425,7 @@ static int selectorY(size_t i)
|
||||||
|
|
||||||
void Gui::draw(void)
|
void Gui::draw(void)
|
||||||
{
|
{
|
||||||
|
auto selEnt = MS::selectedEntries();
|
||||||
const size_t entries = hid->maxVisibleEntries();
|
const size_t entries = hid->maxVisibleEntries();
|
||||||
const size_t max = hid->maxEntries(getTitleCount()) + 1;
|
const size_t max = hid->maxEntries(getTitleCount()) + 1;
|
||||||
const Mode_t mode = Archive::mode();
|
const Mode_t mode = Archive::mode();
|
||||||
|
|
|
@ -159,7 +159,7 @@ Result io::deleteFolderRecursively(FS_Archive arch, const std::u16string& path)
|
||||||
void io::backup(size_t index)
|
void io::backup(size_t index)
|
||||||
{
|
{
|
||||||
// check if multiple selection is enabled and don't ask for confirmation if that's the case
|
// check if multiple selection is enabled and don't ask for confirmation if that's the case
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
if (!Gui::askForConfirmation("Backup selected save?"))
|
if (!Gui::askForConfirmation("Backup selected save?"))
|
||||||
{
|
{
|
||||||
|
@ -192,7 +192,7 @@ void io::backup(size_t index)
|
||||||
std::string suggestion = DateTime::dateTimeStr();
|
std::string suggestion = DateTime::dateTimeStr();
|
||||||
|
|
||||||
std::u16string customPath;
|
std::u16string customPath;
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
|
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ void io::backup(size_t index)
|
||||||
std::string suggestion = DateTime::dateTimeStr();
|
std::string suggestion = DateTime::dateTimeStr();
|
||||||
|
|
||||||
std::u16string customPath;
|
std::u16string customPath;
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
|
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ int main() {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Activate backup list only if multiple selections are not enabled
|
// Activate backup list only if multiple selections are not enabled
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
Gui::bottomScroll(true);
|
Gui::bottomScroll(true);
|
||||||
Gui::updateButtonsColor();
|
Gui::updateButtonsColor();
|
||||||
|
@ -78,7 +78,7 @@ int main() {
|
||||||
if (kDown & KEY_B)
|
if (kDown & KEY_B)
|
||||||
{
|
{
|
||||||
Gui::bottomScroll(false);
|
Gui::bottomScroll(false);
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::resetScrollableIndex();
|
Gui::resetScrollableIndex();
|
||||||
Gui::updateButtonsColor();
|
Gui::updateButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ int main() {
|
||||||
{
|
{
|
||||||
Gui::resetIndex();
|
Gui::resetIndex();
|
||||||
Archive::mode(Archive::mode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
|
Archive::mode(Archive::mode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::resetScrollableIndex();
|
Gui::resetScrollableIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ int main() {
|
||||||
Gui::resetScrollableIndex();
|
Gui::resetScrollableIndex();
|
||||||
Gui::bottomScroll(false);
|
Gui::bottomScroll(false);
|
||||||
}
|
}
|
||||||
Gui::addSelectedEntry(Gui::index());
|
MS::addSelectedEntry(Gui::index());
|
||||||
Gui::updateButtonsColor(); // Do this last
|
Gui::updateButtonsColor(); // Do this last
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ int main() {
|
||||||
|
|
||||||
if (selectionTimer > 90)
|
if (selectionTimer > 90)
|
||||||
{
|
{
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
for (size_t i = 0, sz = getTitleCount(); i < sz; i++)
|
for (size_t i = 0, sz = getTitleCount(); i < sz; i++)
|
||||||
{
|
{
|
||||||
Gui::addSelectedEntry(i);
|
MS::addSelectedEntry(i);
|
||||||
}
|
}
|
||||||
selectionTimer = 0;
|
selectionTimer = 0;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ int main() {
|
||||||
if (refreshTimer > 90)
|
if (refreshTimer > 90)
|
||||||
{
|
{
|
||||||
Gui::resetIndex();
|
Gui::resetIndex();
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::resetScrollableIndex();
|
Gui::resetScrollableIndex();
|
||||||
Threads::create((ThreadFunc)Threads::titles);
|
Threads::create((ThreadFunc)Threads::titles);
|
||||||
refreshTimer = 0;
|
refreshTimer = 0;
|
||||||
|
@ -159,15 +159,15 @@ int main() {
|
||||||
|
|
||||||
if (Gui::isBackupReleased() || (kDown & KEY_L))
|
if (Gui::isBackupReleased() || (kDown & KEY_L))
|
||||||
{
|
{
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
Gui::resetScrollableIndex();
|
Gui::resetScrollableIndex();
|
||||||
std::vector<size_t> list = Gui::selectedEntries();
|
std::vector<size_t> list = MS::selectedEntries();
|
||||||
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
||||||
{
|
{
|
||||||
io::backup(list.at(i));
|
io::backup(list.at(i));
|
||||||
}
|
}
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::updateButtonsColor();
|
Gui::updateButtonsColor();
|
||||||
}
|
}
|
||||||
else if (Gui::bottomScroll())
|
else if (Gui::bottomScroll())
|
||||||
|
@ -178,16 +178,15 @@ int main() {
|
||||||
|
|
||||||
if (Gui::isRestoreReleased() || (kDown & KEY_R))
|
if (Gui::isRestoreReleased() || (kDown & KEY_R))
|
||||||
{
|
{
|
||||||
// if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
// {
|
{
|
||||||
// Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
// Gui::updateButtonsColor();
|
Gui::updateButtonsColor();
|
||||||
// }
|
}
|
||||||
// else if (Gui::bottomScroll())
|
else if (Gui::bottomScroll())
|
||||||
// {
|
{
|
||||||
// io::restore(Gui::index());
|
io::restore(Gui::index());
|
||||||
// }
|
}
|
||||||
Gui::showError(0xFADE, "This is a complex error message. Report to FlagBrew.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::updateSelector();
|
Gui::updateSelector();
|
||||||
|
|
65
common/multiselection.cpp
Normal file
65
common/multiselection.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* 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 "multiselection.hpp"
|
||||||
|
|
||||||
|
static std::vector<size_t> selEnt;
|
||||||
|
|
||||||
|
std::vector<size_t> MS::selectedEntries(void)
|
||||||
|
{
|
||||||
|
return selEnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MS::multipleSelectionEnabled(void)
|
||||||
|
{
|
||||||
|
return !selEnt.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MS::clearSelectedEntries(void)
|
||||||
|
{
|
||||||
|
selEnt.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MS::addSelectedEntry(size_t idx)
|
||||||
|
{
|
||||||
|
int existing = -1;
|
||||||
|
for (size_t i = 0, sz = selEnt.size(); i < sz && existing == -1; i++)
|
||||||
|
{
|
||||||
|
if (selEnt.at(i) == idx)
|
||||||
|
{
|
||||||
|
existing = (int)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing == -1)
|
||||||
|
{
|
||||||
|
selEnt.push_back(idx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selEnt.erase(selEnt.begin() + existing);
|
||||||
|
}
|
||||||
|
}
|
35
common/multiselection.hpp
Normal file
35
common/multiselection.hpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* 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 <vector>
|
||||||
|
|
||||||
|
namespace MS
|
||||||
|
{
|
||||||
|
std::vector<size_t> selectedEntries(void);
|
||||||
|
bool multipleSelectionEnabled(void);
|
||||||
|
void clearSelectedEntries(void);
|
||||||
|
void addSelectedEntry(size_t idx);
|
||||||
|
}
|
2
sharkive
2
sharkive
|
@ -1 +1 @@
|
||||||
Subproject commit e1e2054dd533ae3c8b4e5ceb199bebc08d5e0154
|
Subproject commit 8c12de59f660a4b77463f6710986c477bd0f2dbd
|
|
@ -36,6 +36,7 @@
|
||||||
#include "SDLHelper.hpp"
|
#include "SDLHelper.hpp"
|
||||||
#include "hid.hpp"
|
#include "hid.hpp"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
#include "multiselection.hpp"
|
||||||
#include "scrollable.hpp"
|
#include "scrollable.hpp"
|
||||||
#include "status.hpp"
|
#include "status.hpp"
|
||||||
#include "title.hpp"
|
#include "title.hpp"
|
||||||
|
|
|
@ -91,48 +91,6 @@ void Gui::index(entryType_t type, size_t i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multi selection
|
|
||||||
|
|
||||||
static std::vector<size_t> selEnt;
|
|
||||||
|
|
||||||
std::vector<size_t> Gui::selectedEntries(void)
|
|
||||||
{
|
|
||||||
return selEnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Gui::multipleSelectionEnabled(void)
|
|
||||||
{
|
|
||||||
return !selEnt.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gui::clearSelectedEntries(void)
|
|
||||||
{
|
|
||||||
selEnt.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gui::addSelectedEntry(size_t idx)
|
|
||||||
{
|
|
||||||
int existing = -1;
|
|
||||||
for (size_t i = 0, sz = selEnt.size(); i < sz && existing == -1; i++)
|
|
||||||
{
|
|
||||||
if (selEnt.at(i) == idx)
|
|
||||||
{
|
|
||||||
existing = (int)i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existing == -1)
|
|
||||||
{
|
|
||||||
selEnt.push_back(idx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selEnt.erase(selEnt.begin() + existing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gui implementation
|
|
||||||
|
|
||||||
static void drawOutline(u32 x, u32 y, u16 w, u16 h, u8 size, SDL_Color color)
|
static void drawOutline(u32 x, u32 y, u16 w, u16 h, u8 size, SDL_Color color)
|
||||||
{
|
{
|
||||||
SDLH_DrawRect(x - size, y - size, w + 2*size, size, color); // top
|
SDLH_DrawRect(x - size, y - size, w + 2*size, size, color); // top
|
||||||
|
@ -303,6 +261,7 @@ void Gui::exit(void)
|
||||||
|
|
||||||
void Gui::draw(u128 uid)
|
void Gui::draw(u128 uid)
|
||||||
{
|
{
|
||||||
|
auto selEnt = MS::selectedEntries();
|
||||||
const size_t entries = hid->maxVisibleEntries();
|
const size_t entries = hid->maxVisibleEntries();
|
||||||
const size_t max = hid->maxEntries(getTitleCount(g_currentUId)) + 1;
|
const size_t max = hid->maxEntries(getTitleCount(g_currentUId)) + 1;
|
||||||
|
|
||||||
|
@ -453,7 +412,7 @@ bool Gui::isCheatReleased(void)
|
||||||
|
|
||||||
void Gui::updateButtons(void)
|
void Gui::updateButtons(void)
|
||||||
{
|
{
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
buttonRestore->canInvertColor(true);
|
buttonRestore->canInvertColor(true);
|
||||||
buttonRestore->canInvertColor(false);
|
buttonRestore->canInvertColor(false);
|
||||||
|
|
|
@ -149,7 +149,7 @@ Result io::deleteFolderRecursively(const std::string& path)
|
||||||
void io::backup(size_t index, u128 uid)
|
void io::backup(size_t index, u128 uid)
|
||||||
{
|
{
|
||||||
// check if multiple selection is enabled and don't ask for confirmation if that's the case
|
// check if multiple selection is enabled and don't ask for confirmation if that's the case
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
if (!Gui::askForConfirmation("Backup selected save?"))
|
if (!Gui::askForConfirmation("Backup selected save?"))
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@ void io::backup(size_t index, u128 uid)
|
||||||
std::string suggestion = DateTime::dateTimeStr() + " " + (StringUtils::containsInvalidChar(Account::username(title.userId())) ? "" : StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(title.userId()))));
|
std::string suggestion = DateTime::dateTimeStr() + " " + (StringUtils::containsInvalidChar(Account::username(title.userId())) ? "" : StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(title.userId()))));
|
||||||
std::string customPath;
|
std::string customPath;
|
||||||
|
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
customPath = isNewFolder ? suggestion : "";
|
customPath = isNewFolder ? suggestion : "";
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ void io::backup(size_t index, u128 uid)
|
||||||
refreshDirectories(title.id());
|
refreshDirectories(title.id());
|
||||||
|
|
||||||
FileSystem::unmount();
|
FileSystem::unmount();
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
Gui::showInfo("Progress correctly saved to disk.");
|
Gui::showInfo("Progress correctly saved to disk.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ int main(int argc, char** argv)
|
||||||
(int)touch.py < 656))
|
(int)touch.py < 656))
|
||||||
{
|
{
|
||||||
// Activate backup list only if multiple selections are enabled
|
// Activate backup list only if multiple selections are enabled
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
g_backupScrollEnabled = true;
|
g_backupScrollEnabled = true;
|
||||||
Gui::updateButtons();
|
Gui::updateButtons();
|
||||||
|
@ -134,7 +134,7 @@ int main(int argc, char** argv)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Activate backup list only if multiple selections are not enabled
|
// Activate backup list only if multiple selections are not enabled
|
||||||
if (!Gui::multipleSelectionEnabled())
|
if (!MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
g_backupScrollEnabled = true;
|
g_backupScrollEnabled = true;
|
||||||
Gui::updateButtons();
|
Gui::updateButtons();
|
||||||
|
@ -154,7 +154,7 @@ int main(int argc, char** argv)
|
||||||
Gui::index(CELLS, 0);
|
Gui::index(CELLS, 0);
|
||||||
g_backupScrollEnabled = false;
|
g_backupScrollEnabled = false;
|
||||||
Gui::entryType(TITLES);
|
Gui::entryType(TITLES);
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::setPKSMBridgeFlag(false);
|
Gui::setPKSMBridgeFlag(false);
|
||||||
Gui::updateButtons(); // Do this last
|
Gui::updateButtons(); // Do this last
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ int main(int argc, char** argv)
|
||||||
g_backupScrollEnabled = false;
|
g_backupScrollEnabled = false;
|
||||||
}
|
}
|
||||||
Gui::entryType(TITLES);
|
Gui::entryType(TITLES);
|
||||||
Gui::addSelectedEntry(Gui::index(TITLES));
|
MS::addSelectedEntry(Gui::index(TITLES));
|
||||||
Gui::setPKSMBridgeFlag(false);
|
Gui::setPKSMBridgeFlag(false);
|
||||||
Gui::updateButtons(); // Do this last
|
Gui::updateButtons(); // Do this last
|
||||||
}
|
}
|
||||||
|
@ -206,10 +206,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (selectionTimer > 45)
|
if (selectionTimer > 45)
|
||||||
{
|
{
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
for (size_t i = 0, sz = getTitleCount(g_currentUId); i < sz; i++)
|
for (size_t i = 0, sz = getTitleCount(g_currentUId); i < sz; i++)
|
||||||
{
|
{
|
||||||
Gui::addSelectedEntry(i);
|
MS::addSelectedEntry(i);
|
||||||
}
|
}
|
||||||
selectionTimer = 0;
|
selectionTimer = 0;
|
||||||
}
|
}
|
||||||
|
@ -217,15 +217,15 @@ int main(int argc, char** argv)
|
||||||
// Handle pressing/touching L
|
// Handle pressing/touching L
|
||||||
if (Gui::isBackupReleased() || (kdown & KEY_L))
|
if (Gui::isBackupReleased() || (kdown & KEY_L))
|
||||||
{
|
{
|
||||||
if (Gui::multipleSelectionEnabled())
|
if (MS::multipleSelectionEnabled())
|
||||||
{
|
{
|
||||||
Gui::resetIndex(CELLS);
|
Gui::resetIndex(CELLS);
|
||||||
std::vector<size_t> list = Gui::selectedEntries();
|
std::vector<size_t> list = MS::selectedEntries();
|
||||||
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
||||||
{
|
{
|
||||||
io::backup(list.at(i), g_currentUId);
|
io::backup(list.at(i), g_currentUId);
|
||||||
}
|
}
|
||||||
Gui::clearSelectedEntries();
|
MS::clearSelectedEntries();
|
||||||
Gui::updateButtons();
|
Gui::updateButtons();
|
||||||
Gui::showInfo("Progress correctly saved to disk.");
|
Gui::showInfo("Progress correctly saved to disk.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue