From 29685703d41f6e8edb7efa4d3ad14a6ff8ba4f44 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 12 Jan 2021 11:24:24 +0100 Subject: [PATCH] refactored dialogs to use only one pointer for other dialogs --- src/gui/CommandMenu.cxx | 2 +- src/gui/MinUICommandDialog.cxx | 22 +++--- src/gui/MinUICommandDialog.hxx | 7 +- src/gui/OptionsDialog.cxx | 124 +++++++++++---------------------- src/gui/OptionsDialog.hxx | 29 +------- 5 files changed, 55 insertions(+), 129 deletions(-) diff --git a/src/gui/CommandMenu.cxx b/src/gui/CommandMenu.cxx index 27768dd5a..05d6bb6ed 100644 --- a/src/gui/CommandMenu.cxx +++ b/src/gui/CommandMenu.cxx @@ -38,7 +38,7 @@ CommandMenu::~CommandMenu() Dialog* CommandMenu::baseDialog() { if (myBaseDialog == nullptr) { - if (myOSystem.settings().getBool("minimal_ui")) + if(myOSystem.settings().getBool("minimal_ui")) myBaseDialog = new MinUICommandDialog(myOSystem, *this); else myBaseDialog = new CommandDialog(myOSystem, *this); diff --git a/src/gui/MinUICommandDialog.cxx b/src/gui/MinUICommandDialog.cxx index 0987b1acc..c98cb5675 100644 --- a/src/gui/MinUICommandDialog.cxx +++ b/src/gui/MinUICommandDialog.cxx @@ -320,25 +320,23 @@ void MinUICommandDialog::openSettings() // Create an options dialog, similar to the in-game one if (instance().settings().getBool("basic_settings")) { - if (myStellaSettingsDialog == nullptr) - myStellaSettingsDialog = make_unique(instance(), parent(), - 1280, 720, Menu::AppMode::launcher); - myStellaSettingsDialog->open(); + myDialog = make_unique(instance(), parent(), + 1280, 720, Menu::AppMode::launcher); + myDialog->open(); } else { - if (myOptionsDialog == nullptr) - myOptionsDialog = make_unique(instance(), parent(), this, - FBMinimum::Width, FBMinimum::Height, Menu::AppMode::launcher); - myOptionsDialog->open(); + myDialog = make_unique(instance(), parent(), this, + FBMinimum::Width, FBMinimum::Height, + Menu::AppMode::launcher); + myDialog->open(); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MinUICommandDialog::openHighscores() { - if(myHighScoresDialog == nullptr) - myHighScoresDialog = make_unique(instance(), parent(), - 1280, 720, Menu::AppMode::emulator); - myHighScoresDialog->open(); + myDialog = make_unique(instance(), parent(), + 1280, 720, Menu::AppMode::emulator); + myDialog->open(); } diff --git a/src/gui/MinUICommandDialog.hxx b/src/gui/MinUICommandDialog.hxx index 81eb48e72..185168478 100644 --- a/src/gui/MinUICommandDialog.hxx +++ b/src/gui/MinUICommandDialog.hxx @@ -22,9 +22,6 @@ class Properties; class CommandSender; class DialogContainer; class OSystem; -class StellaSettingsDialog; -class OptionsDialog; -class HighScoresDialog; #include "Dialog.hxx" @@ -61,9 +58,7 @@ class MinUICommandDialog : public Dialog ButtonWidget* myStretchButton{nullptr}; ButtonWidget* myPhosphorButton{nullptr}; - unique_ptr myStellaSettingsDialog; - unique_ptr myOptionsDialog; - unique_ptr myHighScoresDialog; + unique_ptr myDialog; enum { diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 5615d2949..f5bbcfa62 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -135,21 +135,6 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, wid.push_back(b); addCancelWidget(b); - // Now create all the dialogs attached to each menu button - myVideoDialog = make_unique(osystem, parent, _font, max_w, max_h); - myEmulationDialog= make_unique(osystem, parent, _font, max_w, max_h); - myInputDialog = make_unique(osystem, parent, _font, max_w, max_h); - myUIDialog = make_unique(osystem, parent, _font, boss, max_w, max_h); - mySnapshotDialog = make_unique(osystem, parent, _font, max_w, max_h); - myDeveloperDialog = make_unique(osystem, parent, _font, max_w, max_h); - myGameInfoDialog = make_unique(osystem, parent, _font, this, max_w, max_h); -#ifdef CHEATCODE_SUPPORT - myCheatCodeDialog = make_unique(osystem, parent, _font); -#endif - myRomAuditDialog = make_unique(osystem, parent, _font, max_w, max_h); - myHelpDialog = make_unique(osystem, parent, _font); - myAboutDialog = make_unique(osystem, parent, _font); - addToFocusList(wid); // Certain buttons are disabled depending on mode @@ -205,133 +190,108 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, instance().eventHandler().leaveMenuMode(); break; - case kEmuCmd: - myEmulationDialog->open(); - break; - case kVidCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(myVideoDialog == nullptr || myVideoDialog->shouldResize(w, h)) - { - myVideoDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), w, h); - } - myVideoDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); + break; + } + case kEmuCmd: + { + uInt32 w = 0, h = 0; + + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); break; } case kInptCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(myInputDialog == nullptr || myInputDialog->shouldResize(w, h)) - { - myInputDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), w, h); - } - - myInputDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); break; } case kUsrIfaceCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(myUIDialog == nullptr || myUIDialog->shouldResize(w, h)) - { - myUIDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), myBoss, w, h); - } - - myUIDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, myBoss, w, h); + myDialog->open(); break; } case kSnapCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(mySnapshotDialog == nullptr || mySnapshotDialog->shouldResize(w, h)) - { - mySnapshotDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), w, h); - } - mySnapshotDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); break; } case kDevelopCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(myDeveloperDialog == nullptr || myDeveloperDialog->shouldResize(w, h)) - { - myDeveloperDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), w, h); - } - myDeveloperDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); break; } case kInfoCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; - if(myGameInfoDialog == nullptr || myGameInfoDialog->shouldResize(w, h)) - { - myGameInfoDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), this, w, h); - } - myGameInfoDialog->open(); + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, this, w, h); + myDialog->open(); break; } #ifdef CHEATCODE_SUPPORT case kCheatCmd: - myCheatCodeDialog->open(); + myDialog = make_unique(instance(), parent(), _font); + myDialog->open(); break; #endif case kAuditCmd: - myRomAuditDialog->open(); - break; + { + uInt32 w = 0, h = 0; + getDynamicBounds(w, h); + myDialog = make_unique(instance(), parent(), _font, w, h); + myDialog->open(); + break; + } case kLoggerCmd: { - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary uInt32 w = 0, h = 0; bool uselargefont = getDynamicBounds(w, h); - if(myLoggerDialog == nullptr || myLoggerDialog->shouldResize(w, h)) - { - myLoggerDialog = make_unique(instance(), parent(), - instance().frameBuffer().font(), w, h, uselargefont); - } - myLoggerDialog->open(); + myDialog = make_unique(instance(), parent(), _font, w, h, uselargefont); + myDialog->open(); break; } case kHelpCmd: - myHelpDialog->open(); + myDialog = make_unique(instance(), parent(), _font); + myDialog->open(); break; case kAboutCmd: - myAboutDialog->open(); + myDialog = make_unique(instance(), parent(), _font); + myDialog->open(); break; case kExitCmd: diff --git a/src/gui/OptionsDialog.hxx b/src/gui/OptionsDialog.hxx index 82791e22f..4bc747667 100644 --- a/src/gui/OptionsDialog.hxx +++ b/src/gui/OptionsDialog.hxx @@ -22,20 +22,6 @@ class CommandSender; class DialogContainer; class GuiObject; class OSystem; -class EmulationDialog; -class VideoAudioDialog; -class InputDialog; -class UIDialog; -class SnapshotDialog; -class GameInfoDialog; -class RomAuditDialog; -#ifdef CHEATCODE_SUPPORT - class CheatCodeDialog; -#endif -class HelpDialog; -class AboutDialog; -class LoggerDialog; -class DeveloperDialog; #include "Menu.hxx" #include "Dialog.hxx" @@ -52,20 +38,7 @@ class OptionsDialog : public Dialog void handleCommand(CommandSender* sender, int cmd, int data, int id) override; private: - unique_ptr myVideoDialog; - unique_ptr myEmulationDialog; - unique_ptr myInputDialog; - unique_ptr myUIDialog; - unique_ptr mySnapshotDialog; - unique_ptr myDeveloperDialog; - unique_ptr myGameInfoDialog; - #ifdef CHEATCODE_SUPPORT - unique_ptr myCheatCodeDialog; - #endif - unique_ptr myRomAuditDialog; - unique_ptr myLoggerDialog; - unique_ptr myHelpDialog; - unique_ptr myAboutDialog; + unique_ptr myDialog; ButtonWidget* myRomAuditButton{nullptr}; ButtonWidget* myGameInfoButton{nullptr};