Skip to content

Commit

Permalink
Some final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
J-D-K committed Aug 19, 2018
1 parent a2c32c2 commit 8dd1bcd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion JKSM.rsf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BasicInfo:
Title : "JKSM"
ProductCode : "CTR-HB-JKSV"
ProductCode : "CTR-HB-JKSM"
Logo : Nintendo

RomFs:
Expand Down
1 change: 1 addition & 0 deletions inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 2 additions & 33 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -129,7 +98,7 @@ namespace data


title.assign(_title);
titleSafe.assign(safeTitle(title));
titleSafe.assign(util::safeString(title));
prodCode.assign(code);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 18 additions & 10 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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();
}
Expand Down
31 changes: 31 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8dd1bcd

Please sign in to comment.