Skip to content

Commit

Permalink
gui-ui - move rename and delete functionality into game menu and map …
Browse files Browse the repository at this point in the history
…info submenu to square
  • Loading branch information
KrahJohlito committed Oct 18, 2019
1 parent deb2b0a commit 0e8e583
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 82 deletions.
75 changes: 67 additions & 8 deletions src/menusys.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum GAME_MENU_IDs {
GAME_REMOVE_CHANGES,
GAME_SAVE_CHANGES,
GAME_TEST_CHANGES,
GAME_RENAME_GAME,
GAME_DELETE_GAME,
};

// global menu variables
Expand All @@ -69,6 +71,61 @@ static submenu_list_t *gameMenuCurrent;
static s32 menuSemaId;
static ee_sema_t menuSema;

static void menuRenameGame(void)
{
if (!selected_item->item->current) {
return;
}

if (!gEnableWrite)
return;

item_list_t *support = selected_item->item->userdata;

if (support) {
if (support->itemRename) {
if (menuCheckParentalLock() == 0) {
sfxPlay(SFX_MESSAGE);
int nameLength = support->itemGetNameLength(selected_item->item->current->item.id);
char newName[nameLength];
strncpy(newName, selected_item->item->current->item.text, nameLength);
if (guiShowKeyboard(newName, nameLength)) {
guiSwitchScreen(GUI_SCREEN_MAIN);
submenuDestroy(&gameMenu);
support->itemRename(selected_item->item->current->item.id, newName);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
}
}
} else
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void menuDeleteGame(void)
{
if (!selected_item->item->current)
return;

if (!gEnableWrite)
return;

item_list_t *support = selected_item->item->userdata;

if (support) {
if (support->itemDelete) {
if (menuCheckParentalLock() == 0) {
if (guiMsgBox(_l(_STR_DELETE_WARNING), 1, NULL)) {
guiSwitchScreen(GUI_SCREEN_MAIN);
submenuDestroy(&gameMenu);
support->itemDelete(selected_item->item->current->item.id);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
}
}
} else
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void _menuLoadConfig()
{
WaitSema(menuSemaId);
Expand Down Expand Up @@ -169,6 +226,10 @@ void menuInitGameMenu(void)
submenuAppendItem(&gameMenu, -1, NULL, GAME_REMOVE_CHANGES, _STR_REMOVE_ALL_SETTINGS);
submenuAppendItem(&gameMenu, -1, NULL, GAME_SAVE_CHANGES, _STR_SAVE_CHANGES);
submenuAppendItem(&gameMenu, -1, NULL, GAME_TEST_CHANGES, _STR_TEST);
if (gEnableWrite) {
submenuAppendItem(&gameMenu, -1, NULL, GAME_RENAME_GAME, _STR_RENAME);
submenuAppendItem(&gameMenu, -1, NULL, GAME_DELETE_GAME, _STR_DELETE);
}

gameMenuCurrent = gameMenu;
}
Expand Down Expand Up @@ -808,17 +869,11 @@ void menuHandleInputMain()
} else if (getKey(KEY_DOWN)) {
menuNextV();
} else if (getKeyOn(KEY_CROSS)) {
if (gSelectButton == KEY_CROSS && (selected_item->item->current && gUseInfoScreen && gTheme->infoElems.first))
guiSwitchScreen(GUI_SCREEN_INFO);
else
selected_item->item->execCross(selected_item->item);
selected_item->item->execCross(selected_item->item);
} else if (getKeyOn(KEY_TRIANGLE)) {
selected_item->item->execTriangle(selected_item->item);
} else if (getKeyOn(KEY_CIRCLE)) {
if (gSelectButton == KEY_CIRCLE && (selected_item->item->current && gUseInfoScreen && gTheme->infoElems.first))
guiSwitchScreen(GUI_SCREEN_INFO);
else
selected_item->item->execCircle(selected_item->item);
selected_item->item->execCircle(selected_item->item);
} else if (getKeyOn(KEY_SQUARE)) {
selected_item->item->execSquare(selected_item->item);
} else if (getKeyOn(KEY_START)) {
Expand Down Expand Up @@ -997,6 +1052,10 @@ void menuHandleInputGameMenu()
guiGameLoadConfig(support, configSet);
} else if (menuID == GAME_TEST_CHANGES) {
guiGameTestSettings(gameID, support, itemConfig);
} else if (menuID == GAME_RENAME_GAME) {
menuRenameGame();
} else if (menuID == GAME_DELETE_GAME) {
menuDeleteGame();
}
// so the exit press wont propagate twice
readPads();
Expand Down
95 changes: 21 additions & 74 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,15 @@ void moduleUpdateMenu(int mode, int themeChanged, int langChanged)
if (!mod->support->enabled)
menuAddHint(&mod->menuItem, _STR_START_DEVICE, gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON);
else {
menuAddHint(&mod->menuItem, (gUseInfoScreen && gTheme->infoElems.first) ? _STR_INFO : _STR_RUN, gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON);
menuAddHint(&mod->menuItem, _STR_RUN, gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON);

if (gUseInfoScreen && 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);

menuAddHint(&mod->menuItem, _STR_REFRESH, SELECT_ICON);

if (gEnableWrite) {
if (mod->support->itemRename)
menuAddHint(&mod->menuItem, _STR_RENAME, gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON);
if (mod->support->itemDelete)
menuAddHint(&mod->menuItem, _STR_DELETE, SQUARE_ICON);
}
}

// refresh Cache
Expand Down Expand Up @@ -184,40 +180,32 @@ static void itemExecSelect(struct menu_item *curMenu)
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void itemExecCancel(struct menu_item *curMenu)
static void itemExecRefresh(struct menu_item *curMenu)
{
if (!curMenu->current) {
return;
}

if (!gEnableWrite)
return;

item_list_t *support = curMenu->userdata;

if (support) {
if (support->itemRename) {
if (menuCheckParentalLock() == 0) {
sfxPlay(SFX_MESSAGE);
int nameLength = support->itemGetNameLength(curMenu->current->item.id);
char newName[nameLength];
strncpy(newName, curMenu->current->item.text, nameLength);
if (guiShowKeyboard(newName, nameLength)) {
support->itemRename(curMenu->current->item.id, newName);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
}
}
} else
guiMsgBox("NULL Support object. Please report", 0, NULL);
if (support && support->enabled) {
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
sfxPlay(SFX_CONFIRM);
}
}

static void itemExecCross(struct menu_item *curMenu)
{
if (gSelectButton == KEY_CROSS)
itemExecSelect(curMenu);
else
itemExecCancel(curMenu);
}

static void itemExecCircle(struct menu_item *curMenu)
{
if (gSelectButton == KEY_CIRCLE)
itemExecSelect(curMenu);
}

static void itemExecSquare(struct menu_item *curMenu)
{
if (curMenu->current && gUseInfoScreen && gTheme->infoElems.first)
guiSwitchScreen(GUI_SCREEN_INFO);
}

static void itemExecTriangle(struct menu_item *curMenu)
Expand All @@ -240,47 +228,6 @@ static void itemExecTriangle(struct menu_item *curMenu)
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void itemExecSquare(struct menu_item *curMenu)
{
if (!curMenu->current)
return;

if (!gEnableWrite)
return;

item_list_t *support = curMenu->userdata;

if (support) {
if (support->itemDelete) {
if (menuCheckParentalLock() == 0) {
if (guiMsgBox(_l(_STR_DELETE_WARNING), 1, NULL)) {
support->itemDelete(curMenu->current->item.id);
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
}
}
}
} else
guiMsgBox("NULL Support object. Please report", 0, NULL);
}

static void itemExecCircle(struct menu_item *curMenu)
{
if (gSelectButton == KEY_CIRCLE)
itemExecSelect(curMenu);
else
itemExecCancel(curMenu);
}

static void itemExecRefresh(struct menu_item *curMenu)
{
item_list_t *support = curMenu->userdata;

if (support && support->enabled) {
ioPutRequest(IO_MENU_UPDATE_DEFFERED, &support->mode);
sfxPlay(SFX_CONFIRM);
}
}

static void initMenuForListSupport(int mode)
{
opl_io_module_t *mod = &list_support[mode];
Expand Down

0 comments on commit 0e8e583

Please sign in to comment.