diff --git a/gx/gui/cheats.c b/gx/gui/cheats.c index 829044c..8c31d46 100644 --- a/gx/gui/cheats.c +++ b/gx/gui/cheats.c @@ -3,7 +3,7 @@ * * Cheats menu * - * Copyright Eke-Eke (2010-2012) + * Copyright Eke-Eke (2010-2014) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -46,7 +46,7 @@ #define BG_COLOR_1 {0x49,0x49,0x49,0xff} #define BG_COLOR_2 {0x66,0x66,0x66,0xff} -#define MAX_CHEATS (150) +#define MAX_CHEATS (350) #define MAX_DESC_LENGTH (63) #ifdef HW_RVL @@ -853,38 +853,52 @@ void CheatMenu(void) while (update != -1) { /* update arrows buttons */ - if (offset > 0) m->arrows[0]->state |= BUTTON_VISIBLE; - else m->arrows[0]->state &= ~BUTTON_VISIBLE; - if ((offset + 10) < (maxcheats + 1)) m->arrows[1]->state |= BUTTON_VISIBLE; - else m->arrows[1]->state &= ~BUTTON_VISIBLE; + if (offset > 0) + m->arrows[0]->state |= BUTTON_VISIBLE; + else + m->arrows[0]->state &= ~BUTTON_VISIBLE; + if (((offset + 10) < (maxcheats + 1)) && ((offset + 10) < MAX_CHEATS)) + m->arrows[1]->state |= BUTTON_VISIBLE; + else + m->arrows[1]->state &= ~BUTTON_VISIBLE; /* draw menu */ GUI_DrawMenu(m); - /* restore cheats offset */ - if (!(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) + /* check if browsing cheats list */ + if (!(m->bg_images[6].state & IMAGE_VISIBLE)) { + /* restore cheats list offset */ m->offset = offset; - m->max_items = maxcheats + 1; + m->max_items = (maxcheats < MAX_CHEATS) ? (maxcheats + 1) : MAX_CHEATS; m->max_buttons = 10; + m->helpers[1] = NULL; } /* update menu */ update = GUI_UpdateMenu(m); - /* update selected cheat */ - if ((m->selected < 10) && (selection != m->selected)) - { - selection = m->selected; - string_offset = 0; - } - - /* save offset then restore default */ + /* check if browsing cheats list */ if (!(m->bg_images[6].state & IMAGE_VISIBLE)) { - offset = m->offset; + /* update selected cheat */ + if ((m->selected < 10) && (selection != m->selected)) + { + selection = m->selected; + string_offset = 0; + } + + /* save cheats list offset */ + if (offset != m->offset) + { + offset = m->offset; + string_offset = 0; + } + + /* restore default GUI settings */ m->offset = 0; m->max_items = m->max_buttons = 30; + m->helpers[1] = &action_select; } @@ -1194,35 +1208,38 @@ void CheatMenu(void) /* Special inputs */ if (m_input.keys & PAD_TRIGGER_R) { - /* sort cheat list */ - for (i = offset + selection + 1; i < maxcheats; i++) + if (GUI_WaitConfirm("Warning","Delete Cheat Entry ?")) { - strcpy(cheatlist[i-1].text,cheatlist[i].text); - strcpy(cheatlist[i-1].code,cheatlist[i].code); - cheatlist[i-1].address = cheatlist[i].address; - cheatlist[i-1].data = cheatlist[i].data; - cheatlist[i-1].enable = cheatlist[i].enable; + /* sort cheat list */ + for (i = offset + selection + 1; i < maxcheats; i++) + { + strcpy(cheatlist[i-1].text,cheatlist[i].text); + strcpy(cheatlist[i-1].code,cheatlist[i].code); + cheatlist[i-1].address = cheatlist[i].address; + cheatlist[i-1].data = cheatlist[i].data; + cheatlist[i-1].enable = cheatlist[i].enable; + } + + /* clear last cheat */ + cheatlist[maxcheats-1].text[0] = 0; + cheatlist[maxcheats-1].code[0] = 0; + cheatlist[maxcheats-1].address = 0; + cheatlist[maxcheats-1].data = 0; + cheatlist[maxcheats-1].enable = 0; + + /* disable last button */ + if ((maxcheats - offset) < 10) + { + m->buttons[maxcheats - offset].state &= ~BUTTON_ACTIVE; + m->buttons[maxcheats - offset - 1].shift[1] = 0; + } + + /* decrease cheat count */ + maxcheats--; + + /* reset scrolling */ + string_offset = 0; } - - /* clear last cheat */ - cheatlist[maxcheats-1].text[0] = 0; - cheatlist[maxcheats-1].code[0] = 0; - cheatlist[maxcheats-1].address = 0; - cheatlist[maxcheats-1].data = 0; - cheatlist[maxcheats-1].enable = 0; - - /* disable last button */ - if ((maxcheats - offset) < 10) - { - m->buttons[maxcheats - offset].state &= ~BUTTON_ACTIVE; - m->buttons[maxcheats - offset - 1].shift[1] = 0; - } - - /* decrease cheat count */ - maxcheats--; - - /* reset scrolling */ - string_offset = 0; } else if (m_input.keys & PAD_TRIGGER_L) { diff --git a/gx/gui/cheats.h b/gx/gui/cheats.h index e6759a6..5a6f216 100644 --- a/gx/gui/cheats.h +++ b/gx/gui/cheats.h @@ -3,7 +3,7 @@ * * Cheats menu * - * Copyright Eke-Eke (2010-2012) + * Copyright Eke-Eke (2010-2014) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/gx/gui/gui.c b/gx/gui/gui.c index cccab34..0dbcb72 100644 --- a/gx/gui/gui.c +++ b/gx/gui/gui.c @@ -1770,8 +1770,17 @@ static void *MsgBox_Thread(gui_message *message_box) /* draw exit message */ if (message_box->buttonA) { - FONT_writeCenter("Press to continue.",18,166,166+message_box->window->width,248+22,(GXColor)WHITE); - gxDrawTexture(message_box->buttonA, 166+116, 248+4+(18-message_box->buttonA->height)/2,message_box->buttonA->width, message_box->buttonA->height,255); + if (message_box->buttonB) + { + FONT_writeCenter(" Confirm Cancel ",18,166,166+message_box->window->width,248+18+8,(GXColor)WHITE); + gxDrawTexture(message_box->buttonA, 166+56, 248+8+(18-message_box->buttonA->height)/2,message_box->buttonA->width, message_box->buttonA->height,255); + gxDrawTexture(message_box->buttonB, 166+166, 248+8+(18-message_box->buttonB->height)/2,message_box->buttonB->width, message_box->buttonB->height,255); + } + else + { + FONT_writeCenter("Press to continue.",18,166,166+message_box->window->width,248+18+4,(GXColor)WHITE); + gxDrawTexture(message_box->buttonA, 166+116, 248+4+(18-message_box->buttonA->height)/2,message_box->buttonA->width, message_box->buttonA->height,255); + } } /* update display */ @@ -1936,6 +1945,7 @@ void GUI_MsgBoxClose(void) gxTextureClose(&message_box.window); gxTextureClose(&message_box.top); gxTextureClose(&message_box.buttonA); + gxTextureClose(&message_box.buttonB); gxTextureClose(&message_box.throbber); } } @@ -1964,6 +1974,32 @@ void GUI_WaitPrompt(char *title, char *msg) GUI_MsgBoxClose(); } +int GUI_WaitConfirm(char *title, char *msg) +{ + /* clear unused texture */ + gxTextureClose(&message_box.throbber); + + /* open or update message box */ + GUI_MsgBoxOpen(title, msg, 0); + + /* allocate texture */ + message_box.buttonA = gxTextureOpenPNG(Key_A_png,0); + message_box.buttonB = gxTextureOpenPNG(Key_B_png,0); + + /* wait for button A or Button B*/ + while (m_input.keys & (PAD_BUTTON_A | PAD_BUTTON_B)) + VIDEO_WaitVSync(); + while (!(m_input.keys & (PAD_BUTTON_A | PAD_BUTTON_B))) + VIDEO_WaitVSync(); + + int ret = m_input.keys & PAD_BUTTON_A; + + /* always close message box */ + GUI_MsgBoxClose(); + + return ret; +} + /* Basic Fading */ void GUI_FadeOut() { diff --git a/gx/gui/gui.h b/gx/gui/gui.h index 57d8f58..4500f60 100644 --- a/gx/gui/gui.h +++ b/gx/gui/gui.h @@ -120,11 +120,11 @@ typedef struct typedef struct { char title[64]; /* menu title */ - s8 selected; /* index of selected item */ - s8 offset; /* items list offset */ - u8 max_items; /* total number of items */ - u8 max_buttons; /* total number of buttons */ - u8 max_images; /* total number of background images */ + int selected; /* index of selected item */ + int offset; /* items list offset */ + int max_items; /* total number of items */ + int max_buttons; /* total number of buttons */ + int max_images; /* total number of background images */ u8 screenshot; /* game screen background */ gui_item *items; /* menu items */ gui_butn *buttons; /* menu buttons */ @@ -144,6 +144,7 @@ typedef struct gx_texture *window; /* pointer to box texture */ gx_texture *top; /* pointer to box title texture */ gx_texture *buttonA; /* pointer to button A texture */ + gx_texture *buttonB; /* pointer to button A texture */ gx_texture *throbber; /* pointer to throbber texture */ } gui_message; @@ -238,6 +239,7 @@ extern void GUI_MsgBoxOpen(char *title, char *msg, bool throbber); extern void GUI_MsgBoxUpdate(char *title, char *msg); extern void GUI_MsgBoxClose(void); extern void GUI_WaitPrompt(char *title, char *msg); +extern int GUI_WaitConfirm(char *title, char *msg); extern void GUI_FadeOut(); extern GXColor *GUI_GetBgColor(void); extern void GUI_SetBgColor(u8 color);