Skip to content

Commit

Permalink
add basic apps menu
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Jan 8, 2021
1 parent 62de32d commit d76115b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern int guiFrameId;
#define GUI_SCREEN_MENU 1
#define GUI_SCREEN_INFO 2
#define GUI_SCREEN_GAME_MENU 3
#define GUI_SCREEN_APP_MENU 4

void guiSwitchScreen(int target);

Expand Down
2 changes: 1 addition & 1 deletion include/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ enum _STR_IDS {
_STR_CACHE_HDD_GAME_LIST,
_STR_ENABLE_NOTIFICATIONS,
_STR_NOTIFICATIONS,
_STR_GAME_MENU,
_STR_OPTIONS,
_STR_GAME_SETTINGS_SAVED,
_STR_GAME_SETTINGS_REMOVED,
_STR_NET_UPDATE_HINT,
Expand Down
3 changes: 3 additions & 0 deletions include/menusys.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void menuInit();
void menuEnd();
void menuReinitMainMenu(void);
void menuInitGameMenu(void);
void menuInitAppMenu(void);

void menuAppendItem(menu_item_t *item);

Expand All @@ -102,10 +103,12 @@ void menuRenderMain();
void menuRenderMenu();
void menuRenderInfo();
void menuRenderGameMenu();
void menuRenderAppMenu();
void menuHandleInputMain();
void menuHandleInputMenu();
void menuHandleInputInfo();
void menuHandleInputGameMenu();
void menuHandleInputAppMenu();

// Sets the selected item if it is found in the menu list
void menuSetSelectedItem(menu_item_t *item);
Expand Down
2 changes: 1 addition & 1 deletion lng/lang_English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Confirm video mode change?
Cache Game List (HDD)
Enable Notifications
%s loaded from %s
Game Menu
Options
Game settings saved.
%s settings removed.
Overwrites existing game compatibility settings when enabled.
Expand Down
3 changes: 2 additions & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ typedef struct
static gui_screen_handler_t screenHandlers[] = {{&menuHandleInputMain, &menuRenderMain, 0},
{&menuHandleInputMenu, &menuRenderMenu, 1},
{&menuHandleInputInfo, &menuRenderInfo, 1},
{&menuHandleInputGameMenu, &menuRenderGameMenu, 1}};
{&menuHandleInputGameMenu, &menuRenderGameMenu, 1},
{&menuHandleInputAppMenu, &menuRenderAppMenu, 1}};

// default screen handler (menu screen)
static gui_screen_handler_t *screenHandler = &screenHandlers[GUI_SCREEN_MENU];
Expand Down
2 changes: 1 addition & 1 deletion src/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static char *internalEnglish[LANG_STR_COUNT] = {
"Cache Game List (HDD)",
"Enable Notifications",
"%s loaded from %s",
"Game Menu",
"Options",
"Game settings saved.",
"%s settings removed.",
"Overwrites existing game compatibility settings when enabled.",
Expand Down
109 changes: 103 additions & 6 deletions src/menusys.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ static submenu_list_t *gameMenu;
// active item in game settings
static submenu_list_t *gameMenuCurrent;

static submenu_list_t *appMenu;
static submenu_list_t *appMenuCurrent;

static s32 menuSemaId;
static ee_sema_t menuSema;

static void menuRenameGame(void)
static void menuRenameGame(submenu_list_t **submenu)
{
if (!selected_item->item->current) {
return;
Expand All @@ -91,7 +94,7 @@ static void menuRenameGame(void)
strncpy(newName, selected_item->item->current->item.text, nameLength);
if (guiShowKeyboard(newName, nameLength)) {
guiSwitchScreen(GUI_SCREEN_MAIN);
submenuDestroy(&gameMenu);
submenuDestroy(submenu);
support->itemRename(selected_item->item->current->item.id, newName);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
Expand All @@ -101,7 +104,7 @@ static void menuRenameGame(void)
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void menuDeleteGame(void)
static void menuDeleteGame(submenu_list_t **submenu)
{
if (!selected_item->item->current)
return;
Expand All @@ -116,7 +119,7 @@ static void menuDeleteGame(void)
if (menuCheckParentalLock() == 0) {
if (guiMsgBox(_l(_STR_DELETE_WARNING), 1, NULL)) {
guiSwitchScreen(GUI_SCREEN_MAIN);
submenuDestroy(&gameMenu);
submenuDestroy(submenu);
support->itemDelete(selected_item->item->current->item.id);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
Expand Down Expand Up @@ -244,6 +247,18 @@ void menuInitGameMenu(void)
gameMenuCurrent = gameMenu;
}

void menuInitAppMenu(void)
{
if (appMenu)
submenuDestroy(&appMenu);

// initialize the menu
submenuAppendItem(&appMenu, -1, NULL, 0, _STR_RENAME);
submenuAppendItem(&appMenu, -1, NULL, 1, _STR_DELETE);

appMenuCurrent = appMenu;
}

// -------------------------------------------------------------------------------------------
// ---------------------------------------- Menu manipulation --------------------------------
// -------------------------------------------------------------------------------------------
Expand All @@ -257,6 +272,8 @@ void menuInit()
mainMenuCurrent = NULL;
gameMenu = NULL;
gameMenuCurrent = NULL;
appMenu = NULL;
appMenuCurrent = NULL;
menuInitMainMenu();

menuSema.init_count = 1;
Expand Down Expand Up @@ -284,6 +301,7 @@ void menuEnd()

submenuDestroy(&mainMenu);
submenuDestroy(&gameMenu);
submenuDestroy(&appMenu);

if (itemConfig) {
configFree(itemConfig);
Expand Down Expand Up @@ -1060,9 +1078,88 @@ void menuHandleInputGameMenu()
guiGameLoadConfig(selected_item->item->userdata, gameMenuLoadConfig(NULL));
}
} else if (menuID == GAME_RENAME_GAME) {
menuRenameGame();
menuRenameGame(&gameMenu);
} else if (menuID == GAME_DELETE_GAME) {
menuDeleteGame();
menuDeleteGame(&gameMenu);
}
// so the exit press wont propagate twice
readPads();
}

if (getKeyOn(KEY_START) || getKeyOn(gSelectButton == KEY_CIRCLE ? KEY_CROSS : KEY_CIRCLE)) {
guiSwitchScreen(GUI_SCREEN_MAIN);
}
}

void menuRenderAppMenu()
{
guiDrawBGPlasma();

if (!appMenu)
return;

// draw the animated menu
if (!appMenuCurrent)
appMenuCurrent = appMenu;

submenu_list_t *it = appMenu;

// calculate the number of items
int count = 0;
int sitem = 0;
for (; it; count++, it = it->next) {
if (it == appMenuCurrent)
sitem = count;
}

int spacing = 25;
int y = (gTheme->usedHeight >> 1) - (spacing * (count >> 1));
int cp = 0; // current position
for (it = appMenu; it; it = it->next, cp++) {
// render, advance
fntRenderString(gTheme->fonts[0], 320, y, ALIGN_CENTER, 0, 0, submenuItemGetText(&it->item), (cp == sitem) ? gTheme->selTextColor : gTheme->textColor);
y += spacing;
}

//hints
guiDrawSubMenuHints();
}

void menuHandleInputAppMenu()
{
if (!appMenu)
return;

if (!appMenuCurrent)
appMenuCurrent = appMenu;

if (getKey(KEY_UP)) {
sfxPlay(SFX_CURSOR);
if (appMenuCurrent->prev)
appMenuCurrent = appMenuCurrent->prev;
else // rewind to the last item
while (appMenuCurrent->next)
appMenuCurrent = appMenuCurrent->next;
}

if (getKey(KEY_DOWN)) {
sfxPlay(SFX_CURSOR);
if (appMenuCurrent->next)
appMenuCurrent = appMenuCurrent->next;
else
appMenuCurrent = appMenu;
}

if (getKeyOn(gSelectButton)) {
// execute the item via looking at the id of it
int menuID = appMenuCurrent->item.id;

sfxPlay(SFX_CONFIRM);

if (menuID == 0) {
menuRenameGame(&appMenu);
} else if (menuID == 1) {
menuDeleteGame(&appMenu);
}
// so the exit press wont propagate twice
readPads();
Expand Down
9 changes: 7 additions & 2 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ void moduleUpdateMenu(int mode, int themeChanged, int langChanged)
if (gTheme->infoElems.first)
menuAddHint(&mod->menuItem, _STR_INFO, SQUARE_ICON);

if (!(mod->support->flags & MODE_FLAG_NO_COMPAT))
menuAddHint(&mod->menuItem, _STR_GAME_MENU, TRIANGLE_ICON);
if (!(mod->support->flags & MODE_FLAG_NO_COMPAT) || gEnableWrite)
menuAddHint(&mod->menuItem, _STR_OPTIONS, TRIANGLE_ICON);

menuAddHint(&mod->menuItem, _STR_REFRESH, SELECT_ICON);
}
Expand Down Expand Up @@ -292,6 +292,11 @@ static void itemExecTriangle(struct menu_item *curMenu)
guiSwitchScreen(GUI_SCREEN_GAME_MENU);
guiGameLoadConfig(support, gameMenuLoadConfig(NULL));
}
} else {
if (menuCheckParentalLock() == 0 && gEnableWrite) {
menuInitAppMenu();
guiSwitchScreen(GUI_SCREEN_APP_MENU);
}
}
} else
guiMsgBox("NULL Support object. Please report", 0, NULL);
Expand Down

0 comments on commit d76115b

Please sign in to comment.