From 8dd1bcd82466399daed5245f12bc29a6150060cf Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sun, 19 Aug 2018 17:22:18 -0400 Subject: [PATCH] Some final touches --- JKSM.rsf | 2 +- inc/util.h | 1 + src/data.cpp | 35 ++--------------------------------- src/fs.cpp | 2 +- src/ui.cpp | 28 ++++++++++++++++++---------- src/util.cpp | 31 +++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/JKSM.rsf b/JKSM.rsf index 8667aef..c60f4d0 100644 --- a/JKSM.rsf +++ b/JKSM.rsf @@ -1,6 +1,6 @@ BasicInfo: Title : "JKSM" - ProductCode : "CTR-HB-JKSV" + ProductCode : "CTR-HB-JKSM" Logo : Nintendo RomFs: diff --git a/inc/util.h b/inc/util.h index ad45344..f24fc92 100644 --- a/inc/util.h +++ b/inc/util.h @@ -19,6 +19,7 @@ namespace util std::u16string toUtf16(const std::string& conv); std::u16string createPath(data::titleData& dat, const uint32_t& mode); std::string getString(const std::string& hint, bool def); + std::u16string safeString(const std::u16string& s); int getInt(const std::string& hint, const int& init, const int& max); std::string getDateString(const int& fmt); diff --git a/src/data.cpp b/src/data.cpp index 62b0e04..c0a4385 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -11,8 +11,6 @@ #include "ui.h" #include "gfx.h" -static const char16_t verboten[] = { L'.', L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*' }; - static uint32_t extdataRedirect(const uint32_t& low) { //Pokemon Y @@ -63,35 +61,6 @@ namespace data titleData curData; - bool isVerboten(const char16_t& c) - { - for(unsigned i = 0; i < 11; i++) - { - if(c == verboten[i]) - return true; - } - - return false; - } - - std::u16string safeTitle(const std::u16string& s) - { - std::u16string ret; - for(unsigned i = 0; i < s.length(); i++) - { - if(isVerboten(s[i])) - ret += L' '; - else - ret += s[i]; - } - - //Erase space if last char - if(ret[ret.length() - 1] == L' ') - ret.erase(ret.length() - 1, ret.length()); - - return ret; - } - bool titleData::init(const uint64_t& _id, const FS_MediaType& mt) { m = mt; @@ -107,7 +76,7 @@ namespace data return false; title.assign((char16_t *)(smdh->applicationTitles[1].shortDescription)); - titleSafe.assign(safeTitle(title)); + titleSafe.assign(util::safeString(title)); char tmp[16]; AM_GetTitleProductCode(m, id, tmp); @@ -129,7 +98,7 @@ namespace data title.assign(_title); - titleSafe.assign(safeTitle(title)); + titleSafe.assign(util::safeString(title)); prodCode.assign(code); return true; diff --git a/src/fs.cpp b/src/fs.cpp index 4ecdb16..70f687e 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -222,7 +222,7 @@ namespace fs else { if(R_SUCCEEDED(FSUSER_CreateFile(_arch, fsMakePath(PATH_UTF16, _path.data()), 0, crSize)) && \ - R_SUCCEEDED(FSUSER_OpenFile(&fHandle, _arch, fsMakePath(PATH_UTF16, _path.data()), openFlags, 0))) + R_SUCCEEDED(FSUSER_OpenFile(&fHandle, _arch, fsMakePath(PATH_UTF16, _path.data()), openFlags, 0))) { FSFILE_GetSize(fHandle, &fSize); open = true; diff --git a/src/ui.cpp b/src/ui.cpp index 1f9f24e..3eee45e 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -110,7 +110,7 @@ namespace ui gfx::frameBegin(); gfx::frameStartTop(); - drawTopBar("JKSM - 08/18/2018"); + drawTopBar("JKSM - 08/19/2018"); mainMenu.draw(40, 82, 0xFFFFFFFF, 320); gfx::frameStartBot(); gfx::frameEnd(); @@ -184,16 +184,18 @@ namespace ui } else if(jumpTo.getEvent() == BUTTON_RELEASED) { - std::string getChar = util::getString("Enter a letter to jump to", false); - if(!getChar.empty()) + char16_t getChar = util::toUtf16(util::getString("Enter a letter to jump to", false))[0]; + if(getChar != 0x00) { - //Only use first char - char jmpTo = std::tolower(getChar[0]); + unsigned i; + if(data::titles[0].getMedia() == MEDIATYPE_GAME_CARD) + i = 1; + else + i = 0; - //Skip cart - for(unsigned i = 1; i < titleMenu.getCount(); i++) + for( ; i < titleMenu.getCount(); i++) { - if(std::tolower(titleMenu.getOpt(i)[0]) == jmpTo) + if(std::tolower(data::titles[i].getTitle()[0]) == getChar) { titleMenu.setSelected(i); break; @@ -395,7 +397,7 @@ namespace ui else if(held & KEY_R) newFolder = util::toUtf16(util::getDateString(util::DATE_FMT_YMD)); else - newFolder = util::toUtf16(util::getString("Enter a new folder name", true)); + newFolder = util::safeString(util::toUtf16(util::getString("Enter a new folder name", true))); if(!newFolder.empty()) { @@ -567,18 +569,24 @@ namespace ui void showMessage(const std::string& mess) { + ui:: button ok("OK (A)", 96, 192, 128, 32); while(1) { hidScanInput(); uint32_t down = hidKeysDown(); + touchPosition p; + hidTouchRead(&p); + + ok.update(p); - if(down & KEY_A) + if(down & KEY_A || ok.getEvent() == BUTTON_RELEASED) break; gfx::frameBegin(); gfx::frameStartBot(); C2D_DrawRectSolid(8, 8, 0.5f, 304, 224, 0xFFE7E7E7); + ok.draw(); gfx::drawTextWrap(mess, 16, 16, 224, 0xFF000000); gfx::frameEnd(); } diff --git a/src/util.cpp b/src/util.cpp index 9145d70..d770ef4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -9,6 +9,19 @@ #include "ui.h" +static const char16_t verboten[] = { L'.', L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*' }; + +static inline bool isVerboten(const char16_t& c) +{ + for(unsigned i = 0; i < 11; i++) + { + if(c == verboten[i]) + return true; + } + + return false; +} + namespace util { std::string toUtf8(const std::u16string& conv) @@ -87,6 +100,24 @@ namespace util return std::string(input); } + std::u16string safeString(const std::u16string& s) + { + std::u16string ret; + for(unsigned i = 0; i < s.length(); i++) + { + if(isVerboten(s[i])) + ret += L' '; + else + ret += s[i]; + } + + //Erase space if last char + if(ret[ret.length() - 1] == L' ') + ret.erase(ret.length() - 1, ret.length()); + + return ret; + } + int getInt(const std::string& hint, const int& init, const int& max) { int ret = 0;