Skip to content

Commit 8dd1bcd

Browse files
committed
Some final touches
1 parent a2c32c2 commit 8dd1bcd

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

JKSM.rsf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BasicInfo:
22
Title : "JKSM"
3-
ProductCode : "CTR-HB-JKSV"
3+
ProductCode : "CTR-HB-JKSM"
44
Logo : Nintendo
55

66
RomFs:

inc/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace util
1919
std::u16string toUtf16(const std::string& conv);
2020
std::u16string createPath(data::titleData& dat, const uint32_t& mode);
2121
std::string getString(const std::string& hint, bool def);
22+
std::u16string safeString(const std::u16string& s);
2223
int getInt(const std::string& hint, const int& init, const int& max);
2324
std::string getDateString(const int& fmt);
2425

src/data.cpp

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "ui.h"
1212
#include "gfx.h"
1313

14-
static const char16_t verboten[] = { L'.', L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*' };
15-
1614
static uint32_t extdataRedirect(const uint32_t& low)
1715
{
1816
//Pokemon Y
@@ -63,35 +61,6 @@ namespace data
6361

6462
titleData curData;
6563

66-
bool isVerboten(const char16_t& c)
67-
{
68-
for(unsigned i = 0; i < 11; i++)
69-
{
70-
if(c == verboten[i])
71-
return true;
72-
}
73-
74-
return false;
75-
}
76-
77-
std::u16string safeTitle(const std::u16string& s)
78-
{
79-
std::u16string ret;
80-
for(unsigned i = 0; i < s.length(); i++)
81-
{
82-
if(isVerboten(s[i]))
83-
ret += L' ';
84-
else
85-
ret += s[i];
86-
}
87-
88-
//Erase space if last char
89-
if(ret[ret.length() - 1] == L' ')
90-
ret.erase(ret.length() - 1, ret.length());
91-
92-
return ret;
93-
}
94-
9564
bool titleData::init(const uint64_t& _id, const FS_MediaType& mt)
9665
{
9766
m = mt;
@@ -107,7 +76,7 @@ namespace data
10776
return false;
10877

10978
title.assign((char16_t *)(smdh->applicationTitles[1].shortDescription));
110-
titleSafe.assign(safeTitle(title));
79+
titleSafe.assign(util::safeString(title));
11180

11281
char tmp[16];
11382
AM_GetTitleProductCode(m, id, tmp);
@@ -129,7 +98,7 @@ namespace data
12998

13099

131100
title.assign(_title);
132-
titleSafe.assign(safeTitle(title));
101+
titleSafe.assign(util::safeString(title));
133102
prodCode.assign(code);
134103

135104
return true;

src/fs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ namespace fs
222222
else
223223
{
224224
if(R_SUCCEEDED(FSUSER_CreateFile(_arch, fsMakePath(PATH_UTF16, _path.data()), 0, crSize)) && \
225-
R_SUCCEEDED(FSUSER_OpenFile(&fHandle, _arch, fsMakePath(PATH_UTF16, _path.data()), openFlags, 0)))
225+
R_SUCCEEDED(FSUSER_OpenFile(&fHandle, _arch, fsMakePath(PATH_UTF16, _path.data()), openFlags, 0)))
226226
{
227227
FSFILE_GetSize(fHandle, &fSize);
228228
open = true;

src/ui.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace ui
110110

111111
gfx::frameBegin();
112112
gfx::frameStartTop();
113-
drawTopBar("JKSM - 08/18/2018");
113+
drawTopBar("JKSM - 08/19/2018");
114114
mainMenu.draw(40, 82, 0xFFFFFFFF, 320);
115115
gfx::frameStartBot();
116116
gfx::frameEnd();
@@ -184,16 +184,18 @@ namespace ui
184184
}
185185
else if(jumpTo.getEvent() == BUTTON_RELEASED)
186186
{
187-
std::string getChar = util::getString("Enter a letter to jump to", false);
188-
if(!getChar.empty())
187+
char16_t getChar = util::toUtf16(util::getString("Enter a letter to jump to", false))[0];
188+
if(getChar != 0x00)
189189
{
190-
//Only use first char
191-
char jmpTo = std::tolower(getChar[0]);
190+
unsigned i;
191+
if(data::titles[0].getMedia() == MEDIATYPE_GAME_CARD)
192+
i = 1;
193+
else
194+
i = 0;
192195

193-
//Skip cart
194-
for(unsigned i = 1; i < titleMenu.getCount(); i++)
196+
for( ; i < titleMenu.getCount(); i++)
195197
{
196-
if(std::tolower(titleMenu.getOpt(i)[0]) == jmpTo)
198+
if(std::tolower(data::titles[i].getTitle()[0]) == getChar)
197199
{
198200
titleMenu.setSelected(i);
199201
break;
@@ -395,7 +397,7 @@ namespace ui
395397
else if(held & KEY_R)
396398
newFolder = util::toUtf16(util::getDateString(util::DATE_FMT_YMD));
397399
else
398-
newFolder = util::toUtf16(util::getString("Enter a new folder name", true));
400+
newFolder = util::safeString(util::toUtf16(util::getString("Enter a new folder name", true)));
399401

400402
if(!newFolder.empty())
401403
{
@@ -567,18 +569,24 @@ namespace ui
567569

568570
void showMessage(const std::string& mess)
569571
{
572+
ui:: button ok("OK (A)", 96, 192, 128, 32);
570573
while(1)
571574
{
572575
hidScanInput();
573576

574577
uint32_t down = hidKeysDown();
578+
touchPosition p;
579+
hidTouchRead(&p);
580+
581+
ok.update(p);
575582

576-
if(down & KEY_A)
583+
if(down & KEY_A || ok.getEvent() == BUTTON_RELEASED)
577584
break;
578585

579586
gfx::frameBegin();
580587
gfx::frameStartBot();
581588
C2D_DrawRectSolid(8, 8, 0.5f, 304, 224, 0xFFE7E7E7);
589+
ok.draw();
582590
gfx::drawTextWrap(mess, 16, 16, 224, 0xFF000000);
583591
gfx::frameEnd();
584592
}

src/util.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99

1010
#include "ui.h"
1111

12+
static const char16_t verboten[] = { L'.', L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*' };
13+
14+
static inline bool isVerboten(const char16_t& c)
15+
{
16+
for(unsigned i = 0; i < 11; i++)
17+
{
18+
if(c == verboten[i])
19+
return true;
20+
}
21+
22+
return false;
23+
}
24+
1225
namespace util
1326
{
1427
std::string toUtf8(const std::u16string& conv)
@@ -87,6 +100,24 @@ namespace util
87100
return std::string(input);
88101
}
89102

103+
std::u16string safeString(const std::u16string& s)
104+
{
105+
std::u16string ret;
106+
for(unsigned i = 0; i < s.length(); i++)
107+
{
108+
if(isVerboten(s[i]))
109+
ret += L' ';
110+
else
111+
ret += s[i];
112+
}
113+
114+
//Erase space if last char
115+
if(ret[ret.length() - 1] == L' ')
116+
ret.erase(ret.length() - 1, ret.length());
117+
118+
return ret;
119+
}
120+
90121
int getInt(const std::string& hint, const int& init, const int& max)
91122
{
92123
int ret = 0;

0 commit comments

Comments
 (0)