Get DOOM Cache to show up in menu, Start working on Extras + File Mode

This commit is contained in:
J-D-K 2021-08-01 00:28:44 -04:00
parent 1e3e01a810
commit 92d0f3f74e
25 changed files with 522 additions and 116 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc inc/ui
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK
APP_VERSION := 07.27.2021
APP_VERSION := 08.01.2021
ROMFS := romfs
ICON := icon.jpg

View File

@ -10,8 +10,8 @@
#define curUser users[data::selUser]
#define curData users[data::selUser].titleInfo[data::selData]
#define BLD_MON 7
#define BLD_DAY 27
#define BLD_MON 8
#define BLD_DAY 1
#define BLD_YEAR 2021
namespace data

View File

@ -10,14 +10,14 @@
//ui headers - split up to keep a bit more organized
#include "ui/miscui.h"
#include "ui/uistr.h"
#include "ui/ttlview.h"
#include "ui/thrdProc.h"
#include "ui/sldpanel.h"
#include "ui/usr.h"
#include "ui/ttl.h"
#include "ui/sett.h"
#include "ui/ext.h"
#include "ui/fm.h"
#include "ui/ttlview.h"
#include "ui/thrdProc.h"
#include "ui/sldpanel.h"
enum menuState
{
@ -25,7 +25,8 @@ enum menuState
TTL_SEL,
ADV_MDE,
EX_MNU,
OPT_MNU
OPT_MNU,
FIL_MDE
};
namespace ui

View File

@ -5,6 +5,6 @@ namespace ui
void fmInit();
void fmExit();
void fmPrep(const FsSaveDataType& _type, const std::string& _dev, bool _commit);
void fmUpdate(SDL_Texture *target);
void fmDraw();
void fmUpdate();
void fmDraw(SDL_Texture *target);
}

View File

@ -85,6 +85,9 @@ namespace ui
//Returns selected option
int getSelected() { return selected; }
//Returns menu option count
int getCount() { return opt.size(); }
//Draws the menu at x and y. rectWidth is the width of the rectangle drawn under the selected
void draw(SDL_Texture *target, const SDL_Color *textClr, bool drawText);

View File

@ -2,22 +2,31 @@
namespace ui
{
//Maybe more later *if* needed, but not now.
typedef enum
{
SLD_LEFT,
SLD_RIGHT
} slidePanelOrientation;
//_draw is called and passed the panel texture/target when this.draw() is called.
class slideOutPanel
{
public:
slideOutPanel(int _w, int _h, int _y, funcPtr _draw);
slideOutPanel(int _w, int _h, int _y, slidePanelOrientation _side, funcPtr _draw);
~slideOutPanel();
void update();
void setCallback(funcPtr _cb, void *_args) { callback = _cb; cbArgs = _args; }
void openPanel() { open = true; }
void closePanel() { open = false; }
void setX(int _nX){ x = _nX; };
bool isOpen() { return open; }
void draw(const SDL_Color *backCol);
private:
int w, h, x = 1280, y;
int w, h, x, y;
uint8_t sldSide;
bool open = false;
SDL_Texture *panel;
funcPtr drawFunc, callback = NULL;

View File

@ -12,4 +12,7 @@ namespace ui
void ttlReset();
void ttlUpdate();
void ttlDraw(SDL_Texture *target);
//File mode needs access to this.
extern ui::slideOutPanel *ttlOptsPanel;
}

View File

@ -49,7 +49,7 @@ namespace ui
bool active = false, showSel = false, clrAdd = true;
uint8_t clrShft = 0;
funcPtr callback = NULL;
int x = 34, y = 62, selected = 0, selRectX = 10, selRectY = 45;
int x = 200, y = 62, selected = 0, selRectX = 10, selRectY = 45;
int iconW, iconH, horGap, vertGap, rowCount;
std::vector<ui::titleTile *> tiles;
};

View File

@ -24,5 +24,5 @@ namespace ui
//Strings for user options
extern std::string usrOptString[2];
//Strings for title options
extern std::string titleOptString[6];
extern std::string titleOptString[7];
}

View File

@ -7,6 +7,7 @@ namespace ui
void usrUpdate();
void usrDraw(SDL_Texture *target);
//A lot of stuff needs access to this
//A lot of stuff needs access to these
extern ui::menu *usrMenu;
extern ui::slideOutPanel *usrSelPanel;
}

View File

@ -50,7 +50,7 @@ namespace util
void replaceButtonsInString(std::string& rep);
//Creates a basic generic icon for stuff without one
SDL_Texture *createIconGeneric(const char *txt, int fontSize);
SDL_Texture *createIconGeneric(const char *txt, int fontSize, bool clearBack);
inline u128 accountUIDToU128(AccountUid uid)
{

View File

@ -160,7 +160,7 @@ static inline void addTitleToList(const uint64_t& tid)
data::titles[tid].icon = gfx::loadJPEGMem(ctrlData->icon, iconSize);
if(!data::titles[tid].icon)
data::titles[tid].icon = util::createIconGeneric(util::getIDStrLower(tid).c_str(), 32);
data::titles[tid].icon = util::createIconGeneric(util::getIDStrLower(tid).c_str(), 32, true);
}
else
{
@ -172,7 +172,7 @@ static inline void addTitleToList(const uint64_t& tid)
else
data::titles[tid].safeTitle = util::getIDStr(tid);
data::titles[tid].icon = util::createIconGeneric(util::getIDStrLower(tid).c_str(), 32);
data::titles[tid].icon = util::createIconGeneric(util::getIDStrLower(tid).c_str(), 32, true);
}
delete ctrlData;
}
@ -415,7 +415,7 @@ data::user::user(const AccountUid& _id, const std::string& _backupName)
{
username = _backupName.empty() ? util::getIDStr((uint64_t)uID128) : _backupName;
userSafe = _backupName.empty() ? util::getIDStr((uint64_t)uID128) : _backupName;
userIcon = util::createIconGeneric(_backupName.c_str(), 40);
userIcon = util::createIconGeneric(_backupName.c_str(), 48, false);
}
titles.reserve(64);
}

View File

@ -78,8 +78,8 @@ bool fs::commitToDevice(const std::string& dev)
Result res = fsdevCommitDevice(dev.c_str());
if(R_FAILED(res))
{
fs::logWrite("Error committing to device -> 0x%X", res);
ui::showPopMessage(POP_FRAME_DEFAULT, "Error commmitting file to device!");
fs::logWrite("Error committing file to device -> 0x%X\n", res);
ui::showPopMessage(POP_FRAME_DEFAULT, "Error committing file to device!");
ret = false;
}
return ret;
@ -108,7 +108,7 @@ void fs::init()
void fs::exit()
{
fs::logClose();
}
bool fs::mountSave(const FsSaveDataInfo& _m)
@ -637,7 +637,8 @@ void fs::createNewBackup(void *a)
util::generateAbbrev(data::curData.saveID),
".zip"
};
out = util::getStringInput(SwkbdType_QWERTY, "", "Enter a name", 64, 9, dict);
std::string defaultText = data::curUser.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD);
out = util::getStringInput(SwkbdType_QWERTY, defaultText, "Enter a name", 64, 9, dict);
}
if(!out.empty())
@ -792,22 +793,20 @@ void fs::deleteBackup(void *a)
void fs::logOpen()
{
std::string logPath = wd + "log.txt";
remove(logPath.c_str());
debLog = fsfopen(logPath.c_str(), FsOpenMode_Write);
fsfclose(debLog);
}
void fs::logWrite(const char *fmt, ...)
{
std::string logPath = wd + "log.txt";
debLog = fsfopen(logPath.c_str(), FsOpenMode_Append | FsOpenMode_Write);
char tmp[256];
va_list args;
va_start(args, fmt);
vsprintf(tmp, fmt, args);
va_end(args);
fsfwrite(tmp, 1, strlen(tmp), debLog);
}
void fs::logClose()
{
fsfclose(debLog);
}

View File

@ -21,7 +21,10 @@ static uint64_t getJournalSize(const data::titleInfo *t)
break;
case FsSaveDataType_Cache:
journalSize = t->nacp.cache_storage_journal_size;
if(t->nacp.cache_storage_journal_size > 0)
journalSize = t->nacp.cache_storage_journal_size;
else
journalSize = t->nacp.cache_storage_data_and_journal_size_max;
break;
default:

View File

@ -29,6 +29,7 @@ static const uint32_t redMask = 0xFF000000;
static const uint32_t greenMask = 0x00FF0000;
static const uint32_t blueMask = 0x0000FF00;
static const uint32_t alphaMask = 0x000000FF;
static const uint32_t breakPoints[7] = {' ', L' ', '/', '_', '-', L'', L''};
static uint8_t *alphaMod;
@ -302,6 +303,33 @@ void gfx::drawTextf(SDL_Texture *target, int fontSize, int x, int y, const SDL_C
SDL_SetRenderTarget(gfx::render, NULL);
}
inline bool isBreakChar(uint32_t point)
{
for(int i = 0; i < 7; i++)
{
if(breakPoints[i] == point)
return true;
}
return false;
}
inline size_t findNextBreak(const char *str)
{
size_t length = strlen(str);
for(size_t i = 0; i < length; )
{
uint32_t nextPoint = 0;
ssize_t unitCnt = decode_utf8(&nextPoint, (const uint8_t *)&str[i]);
i += unitCnt;
if(unitCnt <= 0)
return length;
if(isBreakChar(nextPoint))
return i;
}
return length;
}
void gfx::drawTextfWrap(SDL_Texture *target, int fontSize, int x, int y, int maxWidth, const SDL_Color *c, const char *fmt, ...)
{
SDL_SetRenderTarget(gfx::render, target);
@ -319,9 +347,9 @@ void gfx::drawTextfWrap(SDL_Texture *target, int fontSize, int x, int y, int max
for(unsigned i = 0; i < strlength; )
{
nextBreak = strcspn(&tmp[i], " /_-");
nextBreak = findNextBreak(&tmp[i]);
memset(wordBuff, 0, 128);
memcpy(wordBuff, &tmp[i], nextBreak + 1);
memcpy(wordBuff, &tmp[i], nextBreak);
size_t width = gfx::getTextWidth(wordBuff, fontSize);

View File

@ -43,7 +43,7 @@ SDL_Texture *ui::mnuTopLeft, *ui::mnuTopRight, *ui::mnuBotLeft, *ui::mnuBotRight
//Select box + top left icon
SDL_Texture *ui::sideBar;
static SDL_Texture *icn, *leftPanel, *rightPanel;
static SDL_Texture *icn, *corePanel;
SDL_Color ui::heartColor = {0xFF, 0x44, 0x44, 0xFF};
//X position of help texts. Calculated to make editing quicker/easier
@ -103,10 +103,8 @@ void ui::init()
mnuBotLeft = gfx::loadImageFile("romfs:/img/fb/menuBotLeft.png");
mnuBotRight = gfx::loadImageFile("romfs:/img/fb/menuBotRight.png");
leftPanel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET | SDL_TEXTUREACCESS_STATIC, 200, 559);
rightPanel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET | SDL_TEXTUREACCESS_STATIC, 1080, 559);
SDL_SetTextureBlendMode(leftPanel, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(rightPanel, SDL_BLENDMODE_BLEND);
corePanel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET | SDL_TEXTUREACCESS_STATIC, 1220, 559);
SDL_SetTextureBlendMode(corePanel, SDL_BLENDMODE_BLEND);
switch(ui::thmID)
{
@ -158,11 +156,11 @@ void ui::init()
//Setup touch
hidInitializeTouchScreen();
//advCopyMenuPrep();
ui::usrInit();
ui::ttlInit();
ui::settInit();
ui::extInit();
ui::fmInit();
popMessages = new ui::popMessageMngr;
threadMngr = new ui::threadProcMngr;
@ -178,6 +176,7 @@ void ui::exit()
ui::ttlExit();
ui::settExit();
ui::extExit();
ui::fmExit();
delete popMessages;
delete threadMngr;
@ -194,8 +193,7 @@ void ui::exit()
SDL_DestroyTexture(mnuBotLeft);
SDL_DestroyTexture(mnuBotRight);
SDL_DestroyTexture(leftPanel);
SDL_DestroyTexture(rightPanel);
SDL_DestroyTexture(corePanel);
SDL_DestroyTexture(icn);
}
@ -224,8 +222,7 @@ void ui::showLoadScreen()
void ui::drawUI()
{
gfx::clearTarget(NULL, &ui::clearClr);
gfx::clearTarget(leftPanel, &transparent);
gfx::clearTarget(rightPanel, &transparent);
gfx::clearTarget(corePanel, &transparent);
gfx::drawLine(NULL, &divClr, 30, 88, 1250, 88);
gfx::drawLine(NULL, &divClr, 30, 648, 1250, 648);
@ -237,18 +234,16 @@ void ui::drawUI()
if(author != "NULL")
gfx::drawTextf(NULL, 12, 8, 682, &ui::txtCont, "Translation: %s", author.c_str());
gfx::texDraw(leftPanel, sideBar, 0, 89);
ui::usrDraw(leftPanel);
if(ui::usrMenu->getSelected() == settPos || ui::mstate == OPT_MNU)
ui::settDraw(rightPanel);
else if(usrMenu->getSelected() == extPos || ui::mstate == EX_MNU)
ui::extDraw(rightPanel);
if((ui::usrMenu->getActive() && ui::usrMenu->getSelected() == settPos) || ui::mstate == OPT_MNU)
ui::settDraw(corePanel);
else if((ui::usrMenu->getActive() && ui::usrMenu->getSelected() == extPos) || ui::mstate == EX_MNU)
ui::extDraw(corePanel);
else if(ui::mstate == FIL_MDE)
ui::fmDraw(corePanel);
else
ui::ttlDraw(rightPanel);
ui::ttlDraw(corePanel);
gfx::texDraw(NULL, rightPanel, 200, 89);
gfx::texDraw(NULL, leftPanel, 0, 89);
gfx::texDraw(NULL, corePanel, 30, 89);
for(slideOutPanel *s : panels)
s->draw(&ui::slidePanelColor);
@ -289,6 +284,10 @@ bool ui::runApp()
case EX_MNU:
ui::extUpdate();
break;
case FIL_MDE:
ui::fmUpdate();
break;
}
}
else

View File

@ -18,6 +18,59 @@ static void extMenuCallback(void *a)
}
}
static inline void closeUserPanel()
{
ui::usrMenu->setActive(false);
ui::usrSelPanel->closePanel();
}
static void toFMSDtoSD(void *a)
{
ui::fmPrep(FsSaveDataType_Account, "sdmc:/", false);
closeUserPanel();
ui::changeState(FIL_MDE);
}
static void toFMProdInfoF(void *a)
{
FsFileSystem prodf;
fsOpenBisFileSystem(&prodf, FsBisPartitionId_CalibrationFile, "");
fsdevMountDevice("prod-f", prodf);
closeUserPanel();
ui::fmPrep(FsSaveDataType_System, "prod-f:/", false);
ui::changeState(FIL_MDE);
}
static void toFMSafe(void *a)
{
FsFileSystem safe;
fsOpenBisFileSystem(&safe, FsBisPartitionId_SafeMode, "");
fsdevMountDevice("safe", safe);
closeUserPanel();
ui::fmPrep(FsSaveDataType_System, "safe:/", false);
ui::changeState(FIL_MDE);
}
static void toFMSystem(void *a)
{
FsFileSystem sys;
fsOpenBisFileSystem(&sys, FsBisPartitionId_System, "");
fsdevMountDevice("sys", sys);
closeUserPanel();
ui::fmPrep(FsSaveDataType_System, "sys:/", false);
ui::changeState(FIL_MDE);
}
static void toFMUser(void *a)
{
FsFileSystem user;
fsOpenBisFileSystem(&user, FsBisPartitionId_User, "");
fsdevMountDevice("user", user);
closeUserPanel();
ui::fmPrep(FsSaveDataType_System, "user:/", false);
ui::changeState(FIL_MDE);
}
static void _delUpdate(void *a)
{
threadInfo *t = (threadInfo *)a;
@ -38,12 +91,22 @@ static void extMenuOptRemoveUpdate(void *a)
void ui::extInit()
{
ui::extMenu = new ui::menu;
ui::extMenu->setParams(32, 32, 1016, 24, 5);
ui::extMenu->setParams(200, 32, 1016, 24, 5);
ui::extMenu->setCallback(extMenuCallback, NULL);
ui::extMenu->setActive(false);
for(unsigned i = 0; i < 11; i++)
ui::extMenu->addOpt(NULL, ui::exMenuStr[i]);
//SD to SD
ui::extMenu->optAddButtonEvent(0, HidNpadButton_A, toFMSDtoSD, NULL);
//Prodinfo-F
ui::extMenu->optAddButtonEvent(1, HidNpadButton_A, toFMProdInfoF, NULL);
//Safe
ui::extMenu->optAddButtonEvent(2, HidNpadButton_A, toFMSafe, NULL);
//System
ui::extMenu->optAddButtonEvent(3, HidNpadButton_A, toFMSystem, NULL);
//User
ui::extMenu->optAddButtonEvent(4, HidNpadButton_A, toFMUser, NULL);
//Del update
ui::extMenu->optAddButtonEvent(5, HidNpadButton_A, extMenuOptRemoveUpdate, NULL);
}

View File

@ -5,43 +5,207 @@
#include "util.h"
#include "fm.h"
static ui::slideOutPanel *copyPanel;
static ui::menu *devMenu, *sdMenu, *copyMenu;
//This is going to be a mess but the old one was too.
//Struct to hold info so i don't have to if else if if if
typedef struct
{
std::string *path;
//These can hold the same info needed for the listing menus so might as well use em
fs::backupArgs *b;
} menuFuncArgs;
static ui::slideOutPanel *devPanel, *sdPanel;
static ui::menu *devMenu, *sdMenu, *devCopyMenu, *sdCopyMenu;
static fs::dirList *devList, *sdList;
static std::string devPath, sdPath, dev;
static menuFuncArgs *devArgs, *sdmcArgs;
static FsSaveDataType type;
static bool commit = false;
//Declarations, implementations down further
static void _listFunctionA(void *a);
static void copyPanelDraw(void *a)
/*General stuff*/
static void refreshMenu(ui::menu *m, fs::dirList *d, menuFuncArgs *_args, const std::string& _path)
{
d->reassign(_path);
util::copyDirListToMenu(*d, *m);
for(int i = 1; i < m->getCount(); i++)
{
m->optAddButtonEvent(i, HidNpadButton_A, _listFunctionA, _args);
}
}
/*Callbacks and menu functions*/
static void _devMenuCallback(void *a)
{
menuFuncArgs *ma = (menuFuncArgs *)a;
fs::backupArgs *b = (fs::backupArgs *)ma->b;
switch(ui::padKeysDown())
{
case HidNpadButton_B:
if(*ma->path != dev && *ma->path != "sdmc:/")
{
util::removeLastFolderFromString(*ma->path);
refreshMenu(b->m, b->d, ma, *ma->path);
}
break;
case HidNpadButton_X:
devMenu->setActive(false);
devCopyMenu->setActive(true);
devPanel->openPanel();
break;
}
}
static void _devCopyMenuCallback(void *a)
{
switch(ui::padKeysDown())
{
case HidNpadButton_B:
devCopyMenu->setActive(false);
devMenu->setActive(true);
devPanel->closePanel();
break;
}
}
static void _sdMenuCallback(void *a)
{
menuFuncArgs *ma = (menuFuncArgs *)a;
fs::backupArgs *b = (fs::backupArgs *)ma->b;
switch(ui::padKeysDown())
{
case HidNpadButton_B:
if(*ma->path != dev && *ma->path != "sdmc:/")
{
util::removeLastFolderFromString(*ma->path);
refreshMenu(b->m, b->d, ma, *ma->path);
}
break;
case HidNpadButton_X:
sdMenu->setActive(false);
sdCopyMenu->setActive(true);
sdPanel->openPanel();
break;
}
}
static void _sdCopyMenuCallback(void *a)
{
switch(ui::padKeysDown())
{
case HidNpadButton_B:
sdCopyMenu->setActive(false);
sdMenu->setActive(true);
sdPanel->closePanel();
break;
}
}
static void _devCopyPanelDraw(void *a)
{
SDL_Texture *target = (SDL_Texture *)a;
devCopyMenu->draw(target, &ui::txtCont, true);
}
static void _sdCopyPanelDraw(void *a)
{
SDL_Texture *target = (SDL_Texture *)a;
sdCopyMenu->draw(target, &ui::txtCont, true);
}
static void _listFunctionA(void *a)
{
menuFuncArgs *ma = (menuFuncArgs *)a;
fs::backupArgs *b = (fs::backupArgs *)ma->b;
int sel = b->m->getSelected();
bool isDir = b->d->isDir(sel - 2);
if(sel == 1 && (*ma->path != dev && *ma->path != "sdmc:/"))
{
util::removeLastFolderFromString(*ma->path);
b->d->reassign(*ma->path);
util::copyDirListToMenu(*b->d, *b->m);
}
else if(sel > 1 && isDir)
{
std::string addToPath = b->d->getItem(sel - 2);
*ma->path += addToPath + "/";
b->d->reassign(*ma->path);
util::copyDirListToMenu(*b->d, *b->m);
}
for(int i = 1; i < b->m->getCount(); i++)
{
b->m->optAddButtonEvent(i, HidNpadButton_A, _listFunctionA, ma);
}
}
void ui::fmInit()
{
//This needs to be done in a strange order so everything works
devArgs = new menuFuncArgs;
devArgs->b = new fs::backupArgs;
devArgs->path = &devPath;
sdmcArgs = new menuFuncArgs;
sdmcArgs->b = new fs::backupArgs;
sdmcArgs->path = &sdPath;
devMenu = new ui::menu;
devMenu->setParams(10, 32, 520, 18, 8);
devMenu->setCallback(_devMenuCallback, devArgs);
devMenu->setParams(10, 8, 590, 18, 6);
devMenu->setActive(true);
devArgs->b->m = devMenu;
devPanel = new ui::slideOutPanel(260, 720, 0, ui::SLD_LEFT, _devCopyPanelDraw);
devCopyMenu = new ui::menu;
devCopyMenu->setActive(false);
devCopyMenu->setCallback(_devCopyMenuCallback, NULL);
devCopyMenu->setParams(10, 236, 246, 20, 5);
devCopyMenu->addOpt(NULL, ui::advMenuStr[0] + "SDMC");
for(int i = 1; i < 6; i++)
devCopyMenu->addOpt(NULL, advMenuStr[i]);
ui::registerPanel(devPanel);
sdMenu = new ui::menu;
sdMenu->setParams(560, 32, 520, 18, 18);
sdMenu->setCallback(_sdMenuCallback, sdmcArgs);
sdMenu->setParams(620, 8, 590, 18, 6);
sdMenu->setActive(false);
sdmcArgs->b->m = sdMenu;
copyPanel = new ui::slideOutPanel(410, 720, 0, copyPanelDraw);
sdPanel = new ui::slideOutPanel(260, 720, 0, ui::SLD_RIGHT, _sdCopyPanelDraw);
sdCopyMenu = new ui::menu;
sdCopyMenu->setActive(false);
sdCopyMenu->setCallback(_sdCopyMenuCallback, NULL);
sdCopyMenu->setParams(10, 236, 246, 20, 5);
for(int i = 0; i < 6; i++)
sdCopyMenu->addOpt(NULL, advMenuStr[i]);
ui::registerPanel(sdPanel);
devList = new fs::dirList;
sdList = new fs::dirList;
devArgs->b->d = devList;
sdmcArgs->b->d = sdList;
}
void ui::fmExit()
{
delete devMenu;
delete sdMenu;
delete devCopyMenu;
delete sdCopyMenu;
delete devList;
delete sdList;
delete copyPanel;
delete devArgs->b;
delete devArgs;
delete sdmcArgs->b;
delete sdmcArgs;
}
void ui::fmPrep(const FsSaveDataType& _type, const std::string& _dev, bool _commit)
@ -52,8 +216,74 @@ void ui::fmPrep(const FsSaveDataType& _type, const std::string& _dev, bool _comm
devPath = _dev;
sdPath = "sdmc:/";
sdCopyMenu->editOpt(0, NULL, ui::advMenuStr[0] + _dev);
devList->reassign(dev);
sdList->reassign("sdmc:/");
sdList->reassign(sdPath);
util::copyDirListToMenu(*devList, *devMenu);
for(int i = 1; i < devMenu->getCount(); i++)
{
devMenu->optAddButtonEvent(i, HidNpadButton_A, _listFunctionA, devArgs);
}
util::copyDirListToMenu(*sdList, *sdMenu);
for(int i = 1; i < sdMenu->getCount(); i++)
{
sdMenu->optAddButtonEvent(i, HidNpadButton_A, _listFunctionA, sdmcArgs);
}
}
void ui::fmUpdate()
{
//For now? Maybe forever?
if(devMenu->getActive() || sdMenu->getActive())
{
switch(ui::padKeysDown())
{
case HidNpadButton_ZL:
case HidNpadButton_ZR:
if(devMenu->getActive())
{
devMenu->setActive(false);
sdMenu->setActive(true);
}
else
{
devMenu->setActive(true);
sdMenu->setActive(false);
}
break;
case HidNpadButton_Minus:
//Can't be 100% sure it's fs's sv
if(dev != "sdmc:/")
fsdevUnmountDevice(dev.c_str());
if(ui::prevState == EX_MNU)
{
ui::usrSelPanel->openPanel();
ui::changeState(EX_MNU);
}
else if(ui::prevState == TTL_SEL)
{
ui::usrSelPanel->openPanel();
ui::ttlOptsPanel->openPanel();
ui::changeState(TTL_SEL);
}
break;
}
}
devMenu->update();
sdMenu->update();
devCopyMenu->update();
sdCopyMenu->update();
}
void ui::fmDraw(SDL_Texture *target)
{
devMenu->draw(target, &ui::txtCont, true);
sdMenu->draw(target, &ui::txtCont, true);
gfx::drawLine(target, &ui::divClr, 610, 0, 610, 559);
gfx::drawTextfWrap(NULL, 14, 30, 654, 600, &ui::txtCont, devPath.c_str());
gfx::drawTextfWrap(NULL, 14, 640, 654, 600, &ui::txtCont, sdPath.c_str());
}

View File

@ -185,6 +185,9 @@ void ui::menu::draw(SDL_Texture *target, const SDL_Color *textClr, bool drawText
if(opt.size() < 1)
return;
int tH = 0;
SDL_QueryTexture(target, NULL, NULL, NULL, &tH);
if(y != tY)
{
float add = (float)((float)tY - (float)y) / ui::animScale;
@ -204,7 +207,7 @@ void ui::menu::draw(SDL_Texture *target, const SDL_Color *textClr, bool drawText
clrAdd = true;
}
for(int i = 0; i < (int)opt.size(); i++)
for(int i = 0, tY = y; i < (int)opt.size(); i++, tY += rH)
{
if(i == selected)
{
@ -217,7 +220,7 @@ void ui::menu::draw(SDL_Texture *target, const SDL_Color *textClr, bool drawText
}
else
{
if(drawText)
if(drawText && (tY > -rH || tY < tH))
gfx::drawTextf(target, fSize, x + 20, (y + (rH / 2 - fSize / 2)) + (i * rH), textClr, opt[i].txt.c_str());
}

View File

@ -146,7 +146,7 @@ static void updateMenuText()
void ui::settInit()
{
ui::settMenu = new ui::menu;
ui::settMenu->setParams(32, 32, 1016, 24, 5);
ui::settMenu->setParams(200, 32, 1016, 24, 5);
ui::settMenu->setCallback(settMenuCallback, NULL);
ui::settMenu->setActive(false);

View File

@ -3,11 +3,17 @@
#include "ui.h"
#include "gfx.h"
ui::slideOutPanel::slideOutPanel(int _w, int _h, int _y, funcPtr _draw)
ui::slideOutPanel::slideOutPanel(int _w, int _h, int _y, ui::slidePanelOrientation _side, funcPtr _draw)
{
w = _w;
h = _h;
y = _y;
sldSide = _side;
if(_side == ui::SLD_LEFT)
x = -w;
else
x = 1280;
drawFunc = _draw;
panel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetTextureBlendMode(panel, SDL_BLENDMODE_BLEND);
@ -28,19 +34,29 @@ void ui::slideOutPanel::draw(const SDL_Color *backCol)
{
gfx::clearTarget(panel, backCol);
if(open && x > 1280 - w)
if(open && sldSide == ui::SLD_LEFT && x < 0)
{
float add = ((1280 - (float)w) - (float)x) / ui::animScale;
float add = (float)x / ui::animScale;
x -= ceil(add);
}
else if(open && sldSide == ui::SLD_RIGHT && x > 1280 - w)
{
float add = ((1280.0f - (float)w) - (float)x) / ui::animScale;
x += ceil(add);
}
else if(!open && x < 1280)
else if(!open && sldSide == ui::SLD_LEFT && x > -w)
{
float add = (1280 - (float)x) / ui::animScale;
float sub = ((float)w - (float)x) / ui::animScale;
x -= ceil(sub);
}
else if(!open && sldSide == ui::SLD_RIGHT && x < 1280)
{
float add = (1280.0f - (float)x) / ui::animScale;
x += ceil(add);
}
//don't waste time drawing if you can't even see it.
if(x < 1280)
if((sldSide == ui::SLD_LEFT && x > -w) || (sldSide == ui::SLD_RIGHT && x < 1280))
{
(*drawFunc)(panel);
gfx::texDraw(NULL, panel, x, y);

View File

@ -8,7 +8,8 @@
static int ttlHelpX = 0, fldHelpWidth = 0;
static std::vector<ui::titleview *> ttlViews;
static ui::menu *ttlOpts, *fldMenu;
static ui::slideOutPanel *ttlOptsPanel, *infoPanel, *fldPanel;//There's no reason to have a separate folder section
ui::slideOutPanel *ui::ttlOptsPanel;
static ui::slideOutPanel *infoPanel, *fldPanel;//There's no reason to have a separate folder section
static fs::dirList *fldList;
static fs::backupArgs *backargs;
static std::string infoPanelString;
@ -104,13 +105,10 @@ static void ttlViewCallback(void *a)
break;
case HidNpadButton_X:
if(data::curUser.getUID128() != 0)//system
{
data::selData = ttlViews[data::selUser]->getSelected();
ttlViews[data::selUser]->setActive(false, true);
ttlOpts->setActive(true);
ttlOptsPanel->openPanel();
}
data::selData = ttlViews[data::selUser]->getSelected();
ttlViews[data::selUser]->setActive(false, true);
ttlOpts->setActive(true);
ui::ttlOptsPanel->openPanel();
break;
case HidNpadButton_Y:
@ -131,7 +129,7 @@ static void ttlOptsCallback(void *a)
{
case HidNpadButton_B:
ttlOpts->setActive(false);
ttlOptsPanel->closePanel();
ui::ttlOptsPanel->closePanel();
ttlViews[data::selUser]->setActive(true, true);
ui::updateInput();
break;
@ -147,7 +145,7 @@ static void ttlOptsPanelDraw(void *a)
static void ttlOptsShowInfoPanel(void *a)
{
ttlOpts->setActive(false);
ttlOptsPanel->closePanel();
ui::ttlOptsPanel->closePanel();
infoPanelString = util::getInfoString(data::curUser, data::curData.saveID);
infoPanel->openPanel();
}
@ -170,6 +168,17 @@ static void ttlOptsDefinePath(void *a)
data::pathDefAdd(tid, newSafeTitle);
}
static void ttlOptsToFileMode(void *a)
{
if(fs::mountSave(data::curData.saveInfo))
{
ui::fmPrep((FsSaveDataType)data::curData.saveInfo.save_data_type, "sv:/", true);
ui::usrSelPanel->closePanel();
ui::ttlOptsPanel->closePanel();
ui::changeState(FIL_MDE);
}
}
static void ttlOptsResetSaveData_t(void *a)
{
threadInfo *t = (threadInfo *)a;
@ -186,9 +195,12 @@ static void ttlOptsResetSaveData_t(void *a)
static void ttlOptsResetSaveData(void *a)
{
std::string title = data::getTitleNameByTID(data::curData.saveID);
ui::confirmArgs *conf = ui::confirmArgsCreate(data::config["holdDel"], ttlOptsResetSaveData_t, NULL, true, ui::saveDataReset.c_str(), title.c_str());
ui::confirm(conf);
if(data::curData.saveInfo.save_data_type != FsSaveDataType_System)
{
std::string title = data::getTitleNameByTID(data::curData.saveID);
ui::confirmArgs *conf = ui::confirmArgsCreate(data::config["holdDel"], ttlOptsResetSaveData_t, NULL, true, ui::saveDataReset.c_str(), title.c_str());
ui::confirm(conf);
}
}
static void ttlOptsDeleteSaveData_t(void *a)
@ -202,7 +214,7 @@ static void ttlOptsDeleteSaveData_t(void *a)
if(data::curUser.titleInfo.size() == 0)
{
//Kick back to user
ttlOptsPanel->closePanel();//JIC
ui::ttlOptsPanel->closePanel();//JIC
ttlOpts->setActive(false);
ttlViews[data::selUser]->setActive(false, false);
ui::usrMenu->setActive(true);
@ -216,9 +228,12 @@ static void ttlOptsDeleteSaveData_t(void *a)
static void ttlOptsDeleteSaveData(void *a)
{
std::string title = data::getTitleNameByTID(data::curData.saveID);
ui::confirmArgs *conf = ui::confirmArgsCreate(data::config["holdDel"], ttlOptsDeleteSaveData_t, NULL, true, ui::confEraseNand.c_str(), title.c_str());
ui::confirm(conf);
if(data::curData.saveInfo.save_data_type != FsSaveDataType_System)
{
std::string title = data::getTitleNameByTID(data::curData.saveID);
ui::confirmArgs *conf = ui::confirmArgsCreate(data::config["holdDel"], ttlOptsDeleteSaveData_t, NULL, true, ui::confEraseNand.c_str(), title.c_str());
ui::confirm(conf);
}
}
static void ttlOptsExtendSaveData_t(void *a)
@ -227,13 +242,10 @@ static void ttlOptsExtendSaveData_t(void *a)
std::string expSizeStr = util::getStringInput(SwkbdType_NumPad, "", "Enter New Size in MB", 4, 0, NULL);
if(!expSizeStr.empty())
{
int64_t journ = 0, expSize;
data::titleInfo *extend = data::getTitleInfoByTID(data::curData.saveID);
w->status->setStatus("Expanding save filesystem for " + extend->title);
uint64_t expMB = strtoul(expSizeStr.c_str(), NULL, 10);
FsSaveDataSpaceId space = (FsSaveDataSpaceId)data::curData.saveInfo.save_data_space_id;
uint64_t sid = data::curData.saveInfo.save_data_id;
int64_t expSize = expMB * 1024 * 1024;
int64_t journ = 0;
//Get journal size
switch(data::curData.saveInfo.save_data_type)
{
case FsSaveDataType_Account:
@ -266,7 +278,10 @@ static void ttlOptsExtendSaveData_t(void *a)
journ = 0;
break;
}
uint64_t expMB = strtoul(expSizeStr.c_str(), NULL, 10);
expSize = expMB * 0x100000;
FsSaveDataSpaceId space = (FsSaveDataSpaceId)data::curData.saveInfo.save_data_space_id;
uint64_t sid = data::curData.saveInfo.save_data_id;
Result res = 0;
if(R_FAILED(res = fsExtendSaveDataFileSystem(space, sid, expSize, journ)))
{
@ -284,7 +299,8 @@ static void ttlOptsExtendSaveData_t(void *a)
static void ttlOptsExtendSaveData(void *a)
{
ui::newThread(ttlOptsExtendSaveData_t, NULL, NULL);
if(data::curData.saveInfo.save_data_type != FsSaveDataType_System)
ui::newThread(ttlOptsExtendSaveData_t, NULL, NULL);
}
static void infoPanelDraw(void *a)
@ -300,7 +316,7 @@ static void infoPanelCallback(void *a)
{
case HidNpadButton_B:
infoPanel->closePanel();
ttlOptsPanel->openPanel();
ui::ttlOptsPanel->openPanel();
ttlOpts->setActive(true);
ui::updateInput();
break;
@ -348,14 +364,14 @@ void ui::ttlInit()
fldMenu->setCallback(fldMenuCallback, NULL);
fldMenu->setActive(false);
ttlOptsPanel = new ui::slideOutPanel(410, 720, 0, ttlOptsPanelDraw);
ttlOptsPanel = new ui::slideOutPanel(410, 720, 0, ui::SLD_RIGHT, ttlOptsPanelDraw);
ui::registerPanel(ttlOptsPanel);
infoPanel = new ui::slideOutPanel(410, 720, 0, infoPanelDraw);
infoPanel = new ui::slideOutPanel(410, 720, 0, ui::SLD_RIGHT, infoPanelDraw);
ui::registerPanel(infoPanel);
infoPanel->setCallback(infoPanelCallback, NULL);
fldPanel = new ui::slideOutPanel(fldHelpWidth + 64, 720, 0, fldPanelDraw);
fldPanel = new ui::slideOutPanel(fldHelpWidth + 64, 720, 0, ui::SLD_RIGHT, fldPanelDraw);
fldBuffer = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, fldHelpWidth + 64, 647);
ui::registerPanel(fldPanel);
@ -370,11 +386,13 @@ void ui::ttlInit()
ttlOpts->addOpt(NULL, ui::titleOptString[2]);
ttlOpts->optAddButtonEvent(2, HidNpadButton_A, ttlOptsDefinePath, NULL);
ttlOpts->addOpt(NULL, ui::titleOptString[3]);
ttlOpts->optAddButtonEvent(3, HidNpadButton_A, ttlOptsResetSaveData, NULL);
ttlOpts->optAddButtonEvent(3, HidNpadButton_A, ttlOptsToFileMode, NULL);
ttlOpts->addOpt(NULL, ui::titleOptString[4]);
ttlOpts->optAddButtonEvent(4, HidNpadButton_A, ttlOptsDeleteSaveData, NULL);
ttlOpts->optAddButtonEvent(4, HidNpadButton_A, ttlOptsResetSaveData, NULL);
ttlOpts->addOpt(NULL, ui::titleOptString[5]);
ttlOpts->optAddButtonEvent(5, HidNpadButton_A, ttlOptsExtendSaveData, NULL);
ttlOpts->optAddButtonEvent(5, HidNpadButton_A, ttlOptsDeleteSaveData, NULL);
ttlOpts->addOpt(NULL, ui::titleOptString[6]);
ttlOpts->optAddButtonEvent(6, HidNpadButton_A, ttlOptsExtendSaveData, NULL);
}

View File

@ -45,7 +45,7 @@ std::string ui::optMenuStr[17] = { "Empty Trash Bin", "Check for Update", "Inclu
std::string ui::holdingText[3] = { "(Hold) ", "(Keep Holding) ", "(Almost there!) " };
std::string ui::sortString[3] = { "Alphabetical", "Time Played", "Last Played" };
std::string ui::usrOptString[2] = { "Create Save Data", "Delete All User Saves" };
std::string ui::titleOptString[6] = {"Information", "Blacklist", "Change Output folder", "Reset Save Data", "Delete Save Filesystem", "Extend Save Filesystem"};
std::string ui::titleOptString[7] = {"Information", "Blacklist", "Change Output folder", "Open in File Mode", "Reset Save Data", "Delete Save Filesystem", "Extend Save Filesystem"};
void ui::loadTrans()
{

View File

@ -13,6 +13,7 @@
//Main menu/Users + options, folder
ui::menu *ui::usrMenu;
ui::slideOutPanel *ui::usrSelPanel;
static ui::menu *usrOptMenu, *saveCreateMenu, *deviceSaveMenu, *bcatSaveMenu, *cacheSaveMenu;
//All save types have different entries.
@ -42,6 +43,13 @@ static void onMainChange(void *a)
data::selUser = ui::usrMenu->getSelected();
}
static void _usrSelPanelDraw(void *a)
{
SDL_Texture *target = (SDL_Texture *)a;
gfx::texDraw(target, ui::sideBar, 0, 0);
ui::usrMenu->draw(target, &ui::txtCont, false);
}
static void toOPT(void *a)
{
ui::changeState(OPT_MNU);
@ -134,10 +142,16 @@ static void usrOptDeleteAllUserSaves_t(void *a)
{
threadInfo *t = (threadInfo *)a;
data::user *u = &data::users[data::selUser];
int devUser = ui::usrMenu->getOptPos("Device");
for(data::userTitleInfo& tinf : u->titleInfo)
{
t->status->setStatus("Deleting " + data::getTitleNameByTID(tinf.saveID));
fsDeleteSaveDataFileSystemBySaveDataSpaceId(FsSaveDataSpaceId_User, tinf.saveInfo.save_data_id);;
if(tinf.saveInfo.save_data_type != FsSaveDataType_System && (tinf.saveInfo.save_data_type != FsSaveDataType_Device || data::selUser == devUser))
{
t->status->setStatus("Deleting " + data::getTitleNameByTID(tinf.saveID));
fsDeleteSaveDataFileSystemBySaveDataSpaceId(FsSaveDataSpaceId_User, tinf.saveInfo.save_data_id);
}
}
data::loadUsersTitles(false);
ui::refreshAllViews();
@ -252,7 +266,10 @@ static void createSaveData_t(void *a)
case FsSaveDataType_Cache:
saveSize = 32 * 1024 * 1024;//Todo: Add target folder/zip selection for size
journalSize = create->nacp.cache_storage_journal_size;
if(create->nacp.cache_storage_journal_size > create->nacp.cache_storage_data_and_journal_size_max)
journalSize = create->nacp.cache_storage_journal_size;
else
journalSize = create->nacp.cache_storage_data_and_journal_size_max;
break;
default:
@ -326,18 +343,23 @@ void ui::usrInit()
usrMenu->optAddButtonEvent(usrPos, HidNpadButton_A, toTTL, NULL);
}
sett = util::createIconGeneric("Settings", 40);
sett = util::createIconGeneric("Settings", 48, false);
int pos = usrMenu->addOpt(sett, "Settings");
usrMenu->optAddButtonEvent(pos, HidNpadButton_A, toOPT, NULL);
ext = util::createIconGeneric("Extras", 40);
ext = util::createIconGeneric("Extras", 48, false);
pos = usrMenu->addOpt(ext, "Extras");
usrMenu->optAddButtonEvent(pos, HidNpadButton_A, toEXT, NULL);
usrMenu->setOnChangeFunc(onMainChange);
usrMenu->editParam(MENU_RECT_WIDTH, 126);
usrOptPanel = new ui::slideOutPanel(410, 720, 0, usrOptPanelDraw);
usrSelPanel = new ui::slideOutPanel(200, 559, 89, ui::SLD_LEFT, _usrSelPanelDraw);
usrSelPanel->setX(0);
ui::registerPanel(usrSelPanel);
usrSelPanel->openPanel();
usrOptPanel = new ui::slideOutPanel(410, 720, 0, ui::SLD_RIGHT, usrOptPanelDraw);
ui::registerPanel(usrOptPanel);
usrOptMenu->addOpt(NULL, ui::usrOptString[0]);
@ -346,16 +368,16 @@ void ui::usrInit()
usrOptMenu->optAddButtonEvent(1, HidNpadButton_A, usrOptDeleteAllUserSaves, NULL);
usrOptMenu->setActive(false);
saveCreatePanel = new ui::slideOutPanel(512, 720, 0, saveCreatePanelDraw);
saveCreatePanel = new ui::slideOutPanel(512, 720, 0, ui::SLD_RIGHT, saveCreatePanelDraw);
ui::registerPanel(saveCreatePanel);
deviceSavePanel = new ui::slideOutPanel(512, 720, 0, deviceSavePanelDraw);
deviceSavePanel = new ui::slideOutPanel(512, 720, 0, ui::SLD_RIGHT, deviceSavePanelDraw);
ui::registerPanel(deviceSavePanel);
bcatSavePanel = new ui::slideOutPanel(512, 720, 0, bcatSavePanelDraw);
bcatSavePanel = new ui::slideOutPanel(512, 720, 0, ui::SLD_RIGHT, bcatSavePanelDraw);
ui::registerPanel(bcatSavePanel);
cacheSavePanel = new ui::slideOutPanel(512, 720, 0, cacheSavePanelDraw);
cacheSavePanel = new ui::slideOutPanel(512, 720, 0, ui::SLD_RIGHT, cacheSavePanelDraw);
ui::registerPanel(cacheSavePanel);
accCreate = {FsSaveDataType_Account, saveCreateMenu};
@ -387,7 +409,7 @@ void ui::usrInit()
bcatSids.push_back(t.first);
}
if(nacp->cache_storage_size > 0)
if(nacp->cache_storage_size > 0 || nacp->cache_storage_journal_size > 0 || nacp->cache_storage_data_and_journal_size_max > 0)
{
int optPos = cacheSaveMenu->addOpt(NULL, t.second.title);
cacheSaveMenu->optAddButtonEvent(optPos, HidNpadButton_A, createSaveData, &cacheCreate);
@ -399,6 +421,7 @@ void ui::usrInit()
void ui::usrExit()
{
delete usrSelPanel;
delete usrOptPanel;
delete saveCreatePanel;
delete deviceSavePanel;
@ -426,7 +449,7 @@ void ui::usrUpdate()
cacheSaveMenu->update();
//Todo: Not this
if(!usrOptMenu->getActive() && !saveCreateMenu->getActive() && !deviceSaveMenu->getActive() && !bcatSaveMenu->getActive() && !cacheSaveMenu->getActive())
if(usrMenu->getActive())
{
switch(ui::padKeysDown())
{

View File

@ -319,16 +319,23 @@ void util::replaceButtonsInString(std::string& rep)
replaceStr(rep, "[-]", "\ue0f0");
}
SDL_Texture *util::createIconGeneric(const char *txt, int fontSize)
SDL_Texture *util::createIconGeneric(const char *txt, int fontSize, bool clearBack)
{
SDL_Texture *ret = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 256, 256);
SDL_SetRenderTarget(gfx::render, ret);
SDL_SetRenderDrawColor(gfx::render, ui::rectLt.r, ui::rectLt.g, ui::rectLt.b, ui::rectLt.a);
SDL_RenderClear(gfx::render);
if(clearBack)
{
SDL_SetRenderDrawColor(gfx::render, ui::rectLt.r, ui::rectLt.g, ui::rectLt.b, ui::rectLt.a);
SDL_RenderClear(gfx::render);
}
else
gfx::clearTarget(ret, &ui::transparent);
unsigned int x = 128 - (gfx::getTextWidth(txt, fontSize) / 2);
unsigned int y = 128 - (fontSize / 2);
gfx::drawTextf(ret, fontSize, x, y, &ui::txtCont, txt);
SDL_SetRenderTarget(gfx::render, NULL);
SDL_SetTextureBlendMode(ret, SDL_BLENDMODE_BLEND);
return ret;
}