M4: Fix crashes opening dialogs from original game dialog

This commit is contained in:
Paul Gilbert 2024-02-24 10:53:56 -08:00
parent fa10facb6e
commit b5e47c8237
8 changed files with 38 additions and 16 deletions

View File

@ -807,15 +807,21 @@ void BurgerEngine::showSaveScreen() {
}
}
void BurgerEngine::showLoadScreen(bool fromMainMenu) {
void BurgerEngine::showLoadScreen(LoadDialogSource source) {
if (_useOriginalSaveLoad) {
if (fromMainMenu)
switch (source) {
case kLoadFromMainMenu:
GUI::CreateLoadMenuFromMain(_G(master_palette));
else
break;
case kLoadFromGameDialog:
GUI::CreateLoadMenu(_G(master_palette));
break;
case kLoadFromHotkey:
GUI::CreateF3LoadMenu(_G(master_palette));
break;
}
} else {
M4Engine::showLoadScreen(fromMainMenu);
M4Engine::showLoadScreen(source);
}
}

View File

@ -84,7 +84,7 @@ public:
void syncFlags(Common::Serializer &s) override;
void showSaveScreen() override;
void showLoadScreen(bool fromMainMenu = false) override;
void showLoadScreen(LoadDialogSource source) override;
bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
void global_daemon() override;

View File

@ -49,6 +49,8 @@ namespace GUI {
#define LockMouseSprite mouse_lock_sprite
#define UnlockMouseSprite mouse_unlock_sprite
static bool buttonClosesDialog;
void UpdateThumbNails(int32 firstSlot, guiMenu *myMenu);
void CreateSaveMenu(RGB8 *myPalette);
void CreateLoadMenu(RGB8 *myPalette);
@ -770,8 +772,13 @@ bool button_Handler(void *theItem, int32 eventType, int32 event, int32 x, int32
// digi_play(inv_click_snd, 2, 255, -1, inv_click_snd_room_lock);
currMenu = (guiMenu *)myItem->myMenu;
currTag = myItem->tag;
buttonClosesDialog = false;
(myItem->callback)((void *)myItem, (void *)myItem->myMenu);
myScreen = vmng_screen_find((void *)myItem->myMenu, &status);
status = 0;
myScreen = buttonClosesDialog ? nullptr : vmng_screen_find((void *)myItem->myMenu, &status);
if ((!myScreen) || (status != SCRN_ACTIVE)) {
*currItem = nullptr;
} else {
@ -2632,6 +2639,7 @@ void cb_Game_Save(void *, void *) {
// Destroy the game menu
DestroyGameMenu();
menu_Shutdown(true);
buttonClosesDialog = true;
// Create the save game menu
g_engine->showSaveScreen();
@ -2641,9 +2649,10 @@ void cb_Game_Load(void *, void *) {
// Destroy the game menu
DestroyGameMenu();
menu_Shutdown(true);
buttonClosesDialog = true;
// Create the save game menu
g_engine->showLoadScreen();
g_engine->showLoadScreen(M4Engine::kLoadFromGameDialog);
}
void cb_Game_Main(void *, void *) {
@ -2672,6 +2681,7 @@ void cb_Game_Main(void *, void *) {
void cb_Game_Options(void *, void *) {
// Destroy the game menu
DestroyGameMenu();
buttonClosesDialog = true;
// Create the options menu
CreateOptionsMenu(nullptr);
@ -2749,6 +2759,7 @@ void cb_Options_Game_Cancel(void *, void *) {
// Destroy the options menu
DestroyOptionsMenu();
buttonClosesDialog = true;
// Create the options menu
CreateGameMenuMain(nullptr);
@ -2757,6 +2768,7 @@ void cb_Options_Game_Cancel(void *, void *) {
void cb_Options_Game_Done(void *, void *) {
// Destroy the options menu
DestroyOptionsMenu();
buttonClosesDialog = true;
// Create the options menu
CreateGameMenuMain(nullptr);
@ -3258,6 +3270,8 @@ void cb_SaveLoad_Cancel(void *, void *theMenu) {
CreateGameMenuMain(nullptr);
}
}
buttonClosesDialog = true;
}

View File

@ -150,10 +150,11 @@ menuItem *menu_TextFieldAdd(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32
const char *prompt = nullptr, int32 specialtag = 0, CALLBACK callback = nullptr, bool transparent = false);
//GAME MENU FUNCTIONS
void CreateGameMenu(RGB8 *myPalette);
void CreateOptionsMenu(RGB8 *myPalette);
void CreateF2SaveMenu(RGB8 *myPalette);
void CreateF3LoadMenu(RGB8 *myPalette);
extern void CreateGameMenu(RGB8 *myPalette);
extern void CreateOptionsMenu(RGB8 *myPalette);
extern void CreateF2SaveMenu(RGB8 *myPalette);
extern void CreateLoadMenu(RGB8 *myPalette);
extern void CreateF3LoadMenu(RGB8 *myPalette);
//routines used by the main menu
void CreateLoadMenuFromMain(RGB8 *myPalette);

View File

@ -127,7 +127,7 @@ void Room903::daemon() {
break;
case 7:
g_engine->showLoadScreen(true);
g_engine->showLoadScreen(M4Engine::kLoadFromMainMenu);
break;
case 8:

View File

@ -151,7 +151,7 @@ void Hotkeys::saveGame(void *, void *) {
}
void Hotkeys::loadGame(void *, void *) {
g_engine->showLoadScreen();
g_engine->showLoadScreen(M4Engine::kLoadFromHotkey);
}
void Hotkeys::adv_hyperwalk_to_final_destination(void *a, void *b) {

View File

@ -149,7 +149,7 @@ void M4Engine::showSaveScreen() {
saveGameDialog();
}
void M4Engine::showLoadScreen(bool fromMainMenu) {
void M4Engine::showLoadScreen(LoadDialogSource source) {
loadGameDialog();
}

View File

@ -167,10 +167,11 @@ public:
*/
virtual void showSaveScreen();
enum LoadDialogSource { kLoadFromMainMenu, kLoadFromGameDialog, kLoadFromHotkey };
/**
* Show restore game dialog
*/
virtual void showLoadScreen(bool fromMainMenu = false);
virtual void showLoadScreen(LoadDialogSource fromMainMenu);
/**
* Show the engine information