mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-11-15 06:07:06 +00:00
Implement multiselection, fix #6. Add cosmetic changes
This commit is contained in:
parent
930911f274
commit
0d9ddc0241
10 changed files with 97 additions and 11 deletions
BIN
assets/romfs/checkbox.png
Normal file
BIN
assets/romfs/checkbox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 517 B |
BIN
assets/romfs/checkpoint.png
Normal file
BIN
assets/romfs/checkpoint.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 583 B |
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#define TEXTURE_CHECKPOINT 1
|
||||
#define TEXTURE_CHECKBOX 2
|
||||
|
||||
#define COLOR_BACKGROUND ABGR8(255, 51, 51, 51)
|
||||
#define COLOR_BARS RGBA8(150, 150, 150, 255)
|
||||
#define WHITE RGBA8(255, 255, 255, 255)
|
||||
|
@ -32,6 +35,12 @@
|
|||
|
||||
size_t getScrollableIndex(void);
|
||||
|
||||
std::vector<size_t> getSelectedEntries(void);
|
||||
bool multipleSelectionEnabled(void);
|
||||
void clearSelectedEntries(void);
|
||||
void addSelectedEntry(size_t index);
|
||||
void resetDirectoryListIndex(void);
|
||||
|
||||
class Gui
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -23,6 +23,6 @@
|
|||
|
||||
#define CUSTOM_PATH_LEN 40
|
||||
|
||||
std::u16string getPath(void);
|
||||
std::u16string getPath(std::string suggestion);
|
||||
|
||||
#endif
|
|
@ -200,7 +200,8 @@ void backup(size_t index)
|
|||
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
std::u16string customPath = isNewFolder ? getPath() : u8tou16(getPathFromCell(cellIndex).c_str());
|
||||
std::string suggestion = multipleSelectionEnabled() ? title.getShortDescription() + " - Autobackup" : getPathDateTime();
|
||||
std::u16string customPath = isNewFolder ? getPath(suggestion) : u8tou16(getPathFromCell(cellIndex).c_str());
|
||||
if (!customPath.compare(u8tou16(" ")))
|
||||
{
|
||||
FSUSER_CloseArchive(archive);
|
||||
|
|
|
@ -25,6 +25,53 @@ static Clickable* buttonBackup;
|
|||
static Clickable* buttonRestore;
|
||||
static Scrollable* directoryList;
|
||||
|
||||
/// Multi selection
|
||||
|
||||
static std::vector<size_t> selectedEntries;
|
||||
|
||||
std::vector<size_t> getSelectedEntries(void)
|
||||
{
|
||||
return selectedEntries;
|
||||
}
|
||||
|
||||
bool multipleSelectionEnabled(void)
|
||||
{
|
||||
return !selectedEntries.empty();
|
||||
}
|
||||
|
||||
void clearSelectedEntries(void)
|
||||
{
|
||||
selectedEntries.clear();
|
||||
}
|
||||
|
||||
void addSelectedEntry(size_t index)
|
||||
{
|
||||
int existing = -1;
|
||||
for (size_t i = 0, sz = selectedEntries.size(); i < sz && existing == -1; i++)
|
||||
{
|
||||
if (selectedEntries.at(i) == index)
|
||||
{
|
||||
existing = (int)i;
|
||||
}
|
||||
}
|
||||
|
||||
if (existing == -1)
|
||||
{
|
||||
selectedEntries.push_back(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedEntries.erase(selectedEntries.begin() + existing);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gui implementation
|
||||
|
||||
void resetDirectoryListIndex(void)
|
||||
{
|
||||
directoryList->resetIndex();
|
||||
}
|
||||
|
||||
size_t getScrollableIndex(void)
|
||||
{
|
||||
return directoryList->getIndex();
|
||||
|
@ -141,11 +188,17 @@ void Gui::draw(void)
|
|||
|
||||
pp2d_draw_text(4, 3, 0.45f, 0.45f, GREYISH, getTime().c_str());
|
||||
pp2d_draw_text(TOP_WIDTH - 4 - versionLen, 3, 0.45f, 0.45f, GREYISH, version);
|
||||
pp2d_draw_text(TOP_WIDTH - 6 - versionLen - smLen, 2, 0.50f, 0.50f, WHITE, "checkpoint");
|
||||
pp2d_draw_texture(TEXTURE_CHECKPOINT, TOP_WIDTH - 5 - versionLen - 19, 0);
|
||||
pp2d_draw_text(TOP_WIDTH - 6 - versionLen - smLen - 19, 2, 0.50f, 0.50f, WHITE, "checkpoint");
|
||||
|
||||
for (size_t k = page*entries; k < page*entries + max; k++)
|
||||
{
|
||||
pp2d_draw_texture(getTextureId(k), getSelectorX(k) + 1, getSelectorY(k) + 1);
|
||||
pp2d_draw_texture(getTextureId(k), getSelectorX(k) + 1, getSelectorY(k) + 1);
|
||||
if (!selectedEntries.empty() && std::find(selectedEntries.begin(), selectedEntries.end(), k) != selectedEntries.end())
|
||||
{
|
||||
pp2d_draw_rectangle(getSelectorX(k) + 28, getSelectorY(k) + 28, 16, 16, WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_CHECKBOX, getSelectorX(k) + 24, getSelectorY(k) + 24, RGBA8(51, 51, 51, 255));
|
||||
}
|
||||
}
|
||||
|
||||
if (getTitlesCount() > 0)
|
||||
|
@ -200,12 +253,13 @@ void Gui::draw(void)
|
|||
|
||||
pp2d_draw_rectangle(4, 100, 312, 114, GREYISH);
|
||||
pp2d_draw_rectangle(6, 102, 308, 110, COLOR_BARS);
|
||||
pp2d_draw_rectangle(202, 102, 2, 110, GREYISH);
|
||||
pp2d_draw_rectangle(204, 156, 110, 2, GREYISH);
|
||||
|
||||
directoryList->draw();
|
||||
buttonBackup->draw();
|
||||
buttonRestore->draw();
|
||||
|
||||
pp2d_draw_rectangle(202, 102, 2, 110, GREYISH);
|
||||
pp2d_draw_rectangle(204, 156, 110, 2, GREYISH);
|
||||
}
|
||||
|
||||
pp2d_draw_text_center(GFX_BOTTOM, 224, 0.46f, 0.46f, WHITE, "Press \uE073 to exit.");
|
||||
|
|
|
@ -52,6 +52,7 @@ int main() {
|
|||
menu->setBottomScroll(false);
|
||||
menu->updateButtonsColor();
|
||||
setEntryType(TITLES);
|
||||
clearSelectedEntries();
|
||||
}
|
||||
|
||||
if (hidKeysDown() & KEY_X)
|
||||
|
@ -60,9 +61,27 @@ int main() {
|
|||
setMode(getMode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
|
||||
}
|
||||
|
||||
if (hidKeysDown() & KEY_Y)
|
||||
{
|
||||
addSelectedEntry(menu->getNormalizedIndex());
|
||||
}
|
||||
|
||||
if (menu->isBackupReleased())
|
||||
{
|
||||
backup(menu->getNormalizedIndex());
|
||||
if (multipleSelectionEnabled())
|
||||
{
|
||||
resetDirectoryListIndex();
|
||||
std::vector<size_t> list = getSelectedEntries();
|
||||
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
||||
{
|
||||
backup(list.at(i));
|
||||
}
|
||||
clearSelectedEntries();
|
||||
}
|
||||
else
|
||||
{
|
||||
backup(menu->getNormalizedIndex());
|
||||
}
|
||||
}
|
||||
|
||||
if (menu->isRestoreReleased())
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "swkbd.h"
|
||||
|
||||
std::u16string getPath(void)
|
||||
std::u16string getPath(std::string suggestion)
|
||||
{
|
||||
static SwkbdState swkbd;
|
||||
SwkbdButton button = SWKBD_BUTTON_NONE;
|
||||
|
@ -26,7 +26,7 @@ std::u16string getPath(void)
|
|||
|
||||
swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, CUSTOM_PATH_LEN - 1);
|
||||
swkbdSetHintText(&swkbd, "Choose a name for your backup.");
|
||||
swkbdSetInitialText(&swkbd, getPathDateTime().c_str());
|
||||
swkbdSetInitialText(&swkbd, suggestion.c_str());
|
||||
|
||||
button = swkbdInputText(&swkbd, buf, CUSTOM_PATH_LEN);
|
||||
buf[CUSTOM_PATH_LEN - 1] = '\0';
|
||||
|
|
|
@ -27,7 +27,7 @@ static std::vector<Title> titleExtdatas;
|
|||
bool Title::load(u64 _id, FS_MediaType _media)
|
||||
{
|
||||
bool loadTitle = false;
|
||||
static size_t index = 1;
|
||||
static size_t index = 3;
|
||||
id = _id;
|
||||
media = _media;
|
||||
|
||||
|
|
|
@ -26,12 +26,13 @@ void servicesExit(void)
|
|||
hidExit();
|
||||
pp2d_exit();
|
||||
sdmcExit();
|
||||
romfsExit();
|
||||
}
|
||||
|
||||
void servicesInit(void)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
romfsInit();
|
||||
sdmcInit();
|
||||
pp2d_init();
|
||||
hidInit();
|
||||
|
@ -51,4 +52,6 @@ void servicesInit(void)
|
|||
|
||||
pp2d_set_screen_color(GFX_TOP, COLOR_BACKGROUND);
|
||||
pp2d_set_screen_color(GFX_BOTTOM, COLOR_BACKGROUND);
|
||||
pp2d_load_texture_png(TEXTURE_CHECKBOX, "romfs:/checkbox.png");
|
||||
pp2d_load_texture_png(TEXTURE_CHECKPOINT, "romfs:/checkpoint.png");
|
||||
}
|
Loading…
Reference in a new issue