2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#include "menu.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
extern const u8 delete_png[];
|
|
|
|
extern const u8 deletes_png[];
|
|
|
|
|
|
|
|
void CMenu::_hideCode(bool instant)
|
|
|
|
{
|
2012-07-05 15:15:23 +02:00
|
|
|
for(u8 i = 0; i < 10; ++i)
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.hide(m_codeBtnKey[i], instant);
|
|
|
|
m_btnMgr.hide(m_codeBtnBack, instant);
|
|
|
|
m_btnMgr.hide(m_codeBtnErase, instant);
|
2012-05-14 07:37:10 +02:00
|
|
|
m_btnMgr.hide(m_codeBtnAge, instant);
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.hide(m_codeLblTitle, instant);
|
2012-07-05 15:15:23 +02:00
|
|
|
for(u8 i = 0; i < ARRAY_SIZE(m_codeLblUser); ++i)
|
|
|
|
if(m_codeLblUser[i] != (u16)-1)
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.hide(m_codeLblUser[i], instant);
|
2012-05-14 07:37:10 +02:00
|
|
|
m_btnMgr.hide(m_codeLblAge, true);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMenu::_showCode(void)
|
|
|
|
{
|
|
|
|
_setBg(m_codeBg, m_codeBg);
|
2012-07-05 15:15:23 +02:00
|
|
|
for(u8 i = 0; i < 10; ++i)
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.show(m_codeBtnKey[i]);
|
|
|
|
m_btnMgr.show(m_codeBtnBack);
|
|
|
|
m_btnMgr.show(m_codeLblTitle);
|
2012-07-05 15:15:23 +02:00
|
|
|
for(u8 i = 0; i < ARRAY_SIZE(m_codeLblUser); ++i)
|
|
|
|
if(m_codeLblUser[i] != (u16)-1)
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.show(m_codeLblUser[i]);
|
2012-05-14 07:37:10 +02:00
|
|
|
m_btnMgr.hide(m_codeLblAge, true);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-05-14 07:37:10 +02:00
|
|
|
|
|
|
|
void CMenu::_code(void)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
char code[4];
|
|
|
|
_hideConfig();
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
u32 n = 0;
|
|
|
|
wchar_t codeLbl[] = L"_ _ _ _";
|
|
|
|
|
|
|
|
SetupInput();
|
|
|
|
memset(code, 0, sizeof code);
|
|
|
|
m_btnMgr.setText(m_codeLblTitle, codeLbl);
|
|
|
|
_showCode();
|
2012-05-14 07:37:10 +02:00
|
|
|
bool ageLockMode = false;
|
|
|
|
bool modeChanged = false;
|
|
|
|
bool goBack = false;
|
|
|
|
if (!m_locked)
|
|
|
|
{
|
|
|
|
m_btnMgr.show(m_codeBtnAge);
|
2012-01-21 21:57:41 +01:00
|
|
|
m_btnMgr.show(m_codeBtnErase);
|
2012-05-14 07:37:10 +02:00
|
|
|
}
|
2012-09-09 20:35:15 +02:00
|
|
|
while(!m_exit)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
int c = -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
_mainLoopCommon();
|
|
|
|
if (BTN_HOME_PRESSED)
|
2012-05-14 07:37:10 +02:00
|
|
|
goBack = true;
|
|
|
|
if (WPadIR_ANY())
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
if (BTN_B_PRESSED)
|
2012-05-14 07:37:10 +02:00
|
|
|
goBack = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
else if (BTN_UP_PRESSED)
|
|
|
|
m_btnMgr.up();
|
|
|
|
else if (BTN_DOWN_PRESSED)
|
|
|
|
m_btnMgr.down();
|
2012-05-14 07:37:10 +02:00
|
|
|
else if (BTN_A_PRESSED)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
if (m_btnMgr.selected(m_codeBtnBack))
|
|
|
|
goBack = true;
|
|
|
|
else if (m_btnMgr.selected(m_codeBtnErase))
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
goBack = true;
|
|
|
|
_cfNeedsUpdate();
|
|
|
|
if (ageLockMode)
|
|
|
|
m_cfg.remove("GENERAL", "age_lock");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cfg.remove("GENERAL", "parent_code");
|
|
|
|
m_locked = false;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2012-05-14 07:37:10 +02:00
|
|
|
else if (m_btnMgr.selected(m_codeBtnAge))
|
|
|
|
modeChanged = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
else
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
if (m_btnMgr.selected(m_codeBtnKey[i]))
|
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
c = i;
|
2012-01-21 21:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 07:37:10 +02:00
|
|
|
else if (!ageLockMode)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
// Map buttons to numbers
|
2012-05-14 07:37:10 +02:00
|
|
|
c = -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
if (BTN_UP_PRESSED) c = 0;
|
|
|
|
else if (BTN_LEFT_PRESSED) c = 1;
|
|
|
|
else if (BTN_RIGHT_PRESSED) c = 2;
|
|
|
|
else if (BTN_DOWN_PRESSED) c = 3;
|
|
|
|
else if (BTN_MINUS_PRESSED) c = 4;
|
|
|
|
else if (BTN_PLUS_PRESSED) c = 5;
|
|
|
|
else if (BTN_A_PRESSED) c = 6;
|
|
|
|
else if (BTN_B_PRESSED) c = 7;
|
|
|
|
else if (BTN_1_PRESSED) c = 8;
|
|
|
|
else if (BTN_2_PRESSED) c = 9;
|
2012-05-14 07:37:10 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-05-14 07:37:10 +02:00
|
|
|
if (goBack)
|
|
|
|
{
|
|
|
|
if (!ageLockMode)
|
|
|
|
break;
|
|
|
|
modeChanged = true;
|
|
|
|
goBack = false;
|
|
|
|
}
|
|
|
|
// ageLockMode allows entry of numbers 2 - 19
|
|
|
|
// a first digit of 0 is ignored
|
|
|
|
// a first digit of 2 - 9 is taken to mean a single digit number
|
|
|
|
// a first digit of 1 will be the start of a 2 digit number
|
|
|
|
else if (c != -1 && !(ageLockMode && (n == 0 && c == 0)))
|
|
|
|
{
|
|
|
|
codeLbl[n * 2] = ageLockMode ? '0' + c : 'X';
|
|
|
|
code[n++] = '0' + c;
|
|
|
|
m_btnMgr.setText(m_codeLblTitle, codeLbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modeChanged)
|
|
|
|
{
|
|
|
|
modeChanged = false;
|
|
|
|
memset(code, 0, sizeof code);
|
|
|
|
n = 0;
|
|
|
|
ageLockMode = !ageLockMode;
|
|
|
|
|
|
|
|
if (ageLockMode)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-05-14 07:37:10 +02:00
|
|
|
int ageLockM = m_cfg.getInt("GENERAL", "age_lock");
|
|
|
|
if (ageLockM < 2 || ageLockM > 19)
|
|
|
|
ageLockM = 19;
|
|
|
|
m_btnMgr.hide(m_codeBtnAge, true);
|
|
|
|
wchar_t ageLbl[40];
|
|
|
|
wcsncpy(ageLbl, (_t("cd3", L"Age Lock")).c_str(), 35);
|
|
|
|
ageLbl[35] = 0;
|
|
|
|
swprintf(ageLbl, 40, L"%ls: %d", ageLbl, ageLockM);
|
|
|
|
m_btnMgr.setText(m_codeLblAge, ageLbl);
|
|
|
|
m_btnMgr.show(m_codeLblAge);
|
|
|
|
}
|
|
|
|
else if (!m_locked)
|
|
|
|
{
|
|
|
|
m_btnMgr.show(m_codeBtnAge);
|
|
|
|
m_btnMgr.hide(m_codeLblAge, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 i = 0; i < sizeof code; i++)
|
|
|
|
codeLbl[i*2] = (ageLockMode && i > 1) ? ' ' : '_';
|
|
|
|
m_btnMgr.setText(m_codeLblTitle, codeLbl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ageLockMode)
|
|
|
|
{
|
|
|
|
if ((n >= 2) || (n == 1 && c > 1))
|
|
|
|
{
|
|
|
|
modeChanged = true;
|
|
|
|
m_cfg.setString("GENERAL", "age_lock", string(code, 2).c_str());
|
|
|
|
_cfNeedsUpdate(); }
|
|
|
|
}
|
|
|
|
else if (n >= sizeof code)
|
|
|
|
{
|
|
|
|
if (m_locked)
|
|
|
|
{
|
|
|
|
if (memcmp(code, m_cfg.getString("GENERAL", "parent_code").c_str(), 4) == 0)
|
|
|
|
{
|
|
|
|
m_locked = false;
|
|
|
|
_cfNeedsUpdate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error(_t("cfgg25", L"Password incorrect."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cfg.setString("GENERAL", "parent_code", string(code, 4).c_str());
|
|
|
|
m_locked = true;
|
|
|
|
_cfNeedsUpdate();
|
|
|
|
}
|
|
|
|
break;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_hideCode();
|
2012-05-14 07:37:10 +02:00
|
|
|
_showConfig();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMenu::_initCodeMenu(CMenu::SThemeData &theme)
|
|
|
|
{
|
|
|
|
_addUserLabels(theme, m_codeLblUser, ARRAY_SIZE(m_codeLblUser), "CODE");
|
|
|
|
m_codeBg = _texture(theme.texSet, "CODE/BG", "texture", theme.bg);
|
|
|
|
m_codeLblTitle = _addLabel(theme, "CODE/CODE", theme.titleFont, L"_ _ _ _", 20, 30, 600, 60, theme.titleFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
|
|
|
|
m_codeBtnKey[0] = _addButton(theme, "CODE/0_BTN", theme.btnFont, L"0", 270, 340, 210, 50, theme.btnFontColor);
|
2012-02-10 19:45:42 +01:00
|
|
|
m_codeBtnErase = _addButton(theme, "CODE/ERASE_BTN", theme.btnFont, L"", 20, 400, 200, 56, theme.btnFontColor);
|
|
|
|
m_codeBtnBack = _addButton(theme, "CODE/BACK_BTN", theme.btnFont, L"", 420, 400, 200, 56, theme.btnFontColor);
|
2012-05-14 07:37:10 +02:00
|
|
|
m_codeBtnAge = _addButton(theme, "CODE/AGE_BTN", theme.btnFont, L"", 20, 340, 200, 56, theme.btnFontColor);
|
|
|
|
m_codeLblAge = _addTitle(theme, "CODE/AGE", theme.titleFont, L"", 20, 340, 200, 20, theme.titleFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
for (int i = 0; i < 10; ++i)
|
2012-05-14 07:37:10 +02:00
|
|
|
{
|
|
|
|
const char *codeText = fmt("CODE/%i_BTN", i);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
int x = i - 1;
|
|
|
|
int y = x / 3;
|
|
|
|
x %= 3;
|
|
|
|
x = 160 + x * 110;
|
|
|
|
y = 260 - y * 80;
|
|
|
|
m_codeBtnKey[i] = _addButton(theme, codeText, theme.btnFont, wfmt(L"%i", i), x, y, 100, 50, theme.btnFontColor);
|
|
|
|
}
|
|
|
|
_setHideAnim(m_codeBtnKey[i], codeText, 0, 0, 0.f, 0.f);
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
_setHideAnim(m_codeBtnErase, "CODE/ERASE_BTN", 0, 0, -2.f, 0.f);
|
|
|
|
_setHideAnim(m_codeBtnBack, "CODE/BACK_BTN", 0, 0, -2.f, 0.f);
|
2012-05-14 07:37:10 +02:00
|
|
|
_setHideAnim(m_codeBtnAge, "CODE/AGE_BTN", 0, 0, -2.f, 0.f);
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
_hideCode(true);
|
|
|
|
_textCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMenu::_textCode(void)
|
|
|
|
{
|
|
|
|
m_btnMgr.setText(m_codeBtnBack, _t("cd1", L"Back"));
|
|
|
|
m_btnMgr.setText(m_codeBtnErase, _t("cd2", L"Erase"));
|
2012-05-14 07:37:10 +02:00
|
|
|
m_btnMgr.setText(m_codeBtnAge, _t("cd3", L"Age Lock"));
|
|
|
|
// m_btnMgr.setText(m_codeLblTitle, L"_ _ _ _");
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|