From 6198fbc47913b0bdcb01f9c81e21d2c408abc645 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Tue, 1 Apr 2025 17:00:59 +0800 Subject: [PATCH] mpsetups: a bunch of bug fixes - "load settings" becoming invalid when entering and exiting the challenges screen - when setting a setup as default, it would change the current setup - larger window width causing the marquee text to be rendered off-bounds - reduced the setup name's max length, as it wouldn't fit on the screen in some cases --- port/src/mpsetups.c | 20 ++++++++++++-------- src/game/mplayer/setup.c | 13 +++++++------ src/include/constants.h | 2 +- src/include/types.h | 3 ++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/port/src/mpsetups.c b/port/src/mpsetups.c index d347c56e2..7adf057db 100644 --- a/port/src/mpsetups.c +++ b/port/src/mpsetups.c @@ -154,8 +154,8 @@ struct menuitem g_RenameSetupItems[] = { { MENUITEMTYPE_LABEL, 0, - MENUITEMFLAG_LESSLEFTPADDING, - L_MPMENU_189, // "Enter a name for your game setup file:" + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LESSLEFTPADDING, + (uintptr_t)"Enter the setup name:\n", 0, NULL, }, @@ -663,9 +663,12 @@ static s32 deleteSetup() memcpy(dst, src, MPSETUP_BLOCKSIZE); } - if (g_MpCurrentSetup >= slotindex) { + if (g_MpCurrentSetup > slotindex) { g_MpCurrentSetup--; } + else if (g_MpCurrentSetup == slotindex) { + g_MpCurrentSetup = -1; + } if (g_MpSetupFile.defaultsetup > slotindex + 1) { g_MpSetupFile.defaultsetup--; @@ -802,8 +805,10 @@ s32 exportMpSetupFile() { struct mpsetupfile expMpSetupFile; expMpSetupFile.numsetups = 0; - - u8 maxsetups = g_MpImportExportFilter[1] == 0 ? 64 : 128; + expMpSetupFile.defaultsetup = 0; + expMpSetupFile.version = MPSETUP_VERSION; + + u8 maxsetups = MPSETUP_MAXSETUPS; maxsetups = MIN(maxsetups, g_MpSetupFile.numsetups); for (int i = 0; i < maxsetups; ++i) { u8 bank = i < 64 ? 0 : 1; @@ -840,13 +845,12 @@ static s32 mpsetupSaveFile(u8 op, struct mpsetupfile *setupfile) if (nwritten < 1) { fsFileFree(f); sysLogPrintf(LOG_ERROR, "Unable to write the MP setup file"); + sprintf(g_StatusText, "Unable to write the setup file\n"); return -1; } fsFileFree(f); - - // reload the file to update in-memory structs - return mpsetupLoadCurrentFile(); + return 0; } s32 mpsetupSaveSetup(s32 slotindex, u8 savefile) diff --git a/src/game/mplayer/setup.c b/src/game/mplayer/setup.c index 1a91d0821..a9d920c49 100644 --- a/src/game/mplayer/setup.c +++ b/src/game/mplayer/setup.c @@ -459,6 +459,7 @@ MenuItemHandlerResult menuhandlerMpConfirmSaveChr(s32 operation, struct menuitem return 0; } +extern struct menudialogdef g_StatusErrorDialog; MenuItemHandlerResult menuhandlerMpSetupName(s32 operation, struct menuitem *item, union handlerdata *data) { char *name = data->keyboard.string; @@ -475,10 +476,10 @@ MenuItemHandlerResult menuhandlerMpSetupName(s32 operation, struct menuitem *ite err = mpsetupSaveSetup(g_MpSetupFile.numsetups, true); if (!err) { menuPushDialog(&g_FilemgrFileSavedMenuDialog); + g_MpCurrentSetup = g_MpSetupFile.numsetups - 1; } else { -// menuPushDialog(&g_FilemgrErrorMenuDialog); - // TODO + menuPushDialog(&g_StatusErrorDialog); } break; } @@ -1092,8 +1093,8 @@ struct menuitem g_MpSaveSetupNameMenuItems[] = { { MENUITEMTYPE_LABEL, 0, - MENUITEMFLAG_LESSLEFTPADDING, - L_MPMENU_189, // "Enter a name for your game setup file:" + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LESSLEFTPADDING, + (uintptr_t)"Enter the setup name:\n", 0, NULL, }, @@ -2322,7 +2323,7 @@ MenuItemHandlerResult mpLoadSettingsMenuHandler(s32 operation, struct menuitem * char *mpMenuTextMpconfigMarquee(struct menuitem *item) { - char filename[20]; + char filename[MPSETUP_MAXNAME+1]; u16 numsims; u16 stagenum; u16 scenarionum; @@ -2628,7 +2629,7 @@ struct menuitem g_MpLoadSettingsMenuItems[] = { MENUITEMTYPE_LIST, 0, 0, - 160, + 0x00000078, 0x00000042, mpLoadSettingsMenuHandler, }, diff --git a/src/include/constants.h b/src/include/constants.h index 1b87a7952..6a77fda41 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -4757,7 +4757,7 @@ enum weaponnum { #define EXTRA_SLEEP_TIME 1000LL // 100us #define MPSETUP_MAXSETUPS 128 -#define MPSETUP_MAXNAME 18 +#define MPSETUP_MAXNAME 17 #define MPSETUP_BLOCKSIZE 80 #endif diff --git a/src/include/types.h b/src/include/types.h index cc0b2ed32..1ed8ee9d9 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -3983,13 +3983,14 @@ struct menu { union { struct menudata_endscreen endscreen; struct menudata_main main; - struct menudata_mpsetup mpsetup; struct menudata_mppause mppause; struct menudata_mpend mpend; struct menudata_filemgr fm; struct menudata_main4mb main4mb; struct menudata_training training; }; + + struct menudata_mpsetup mpsetup; }; struct gamefile {