refactored dialogs to use only one pointer for other dialogs

This commit is contained in:
thrust26 2021-01-12 11:24:24 +01:00
parent b2acd8b266
commit 29685703d4
5 changed files with 55 additions and 129 deletions

View File

@ -38,7 +38,7 @@ CommandMenu::~CommandMenu()
Dialog* CommandMenu::baseDialog() Dialog* CommandMenu::baseDialog()
{ {
if (myBaseDialog == nullptr) { if (myBaseDialog == nullptr) {
if (myOSystem.settings().getBool("minimal_ui")) if(myOSystem.settings().getBool("minimal_ui"))
myBaseDialog = new MinUICommandDialog(myOSystem, *this); myBaseDialog = new MinUICommandDialog(myOSystem, *this);
else else
myBaseDialog = new CommandDialog(myOSystem, *this); myBaseDialog = new CommandDialog(myOSystem, *this);

View File

@ -320,25 +320,23 @@ void MinUICommandDialog::openSettings()
// Create an options dialog, similar to the in-game one // Create an options dialog, similar to the in-game one
if (instance().settings().getBool("basic_settings")) if (instance().settings().getBool("basic_settings"))
{ {
if (myStellaSettingsDialog == nullptr) myDialog = make_unique<StellaSettingsDialog>(instance(), parent(),
myStellaSettingsDialog = make_unique<StellaSettingsDialog>(instance(), parent(), 1280, 720, Menu::AppMode::launcher);
1280, 720, Menu::AppMode::launcher); myDialog->open();
myStellaSettingsDialog->open();
} }
else else
{ {
if (myOptionsDialog == nullptr) myDialog = make_unique<OptionsDialog>(instance(), parent(), this,
myOptionsDialog = make_unique<OptionsDialog>(instance(), parent(), this, FBMinimum::Width, FBMinimum::Height,
FBMinimum::Width, FBMinimum::Height, Menu::AppMode::launcher); Menu::AppMode::launcher);
myOptionsDialog->open(); myDialog->open();
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MinUICommandDialog::openHighscores() void MinUICommandDialog::openHighscores()
{ {
if(myHighScoresDialog == nullptr) myDialog = make_unique<HighScoresDialog>(instance(), parent(),
myHighScoresDialog = make_unique<HighScoresDialog>(instance(), parent(), 1280, 720, Menu::AppMode::emulator);
1280, 720, Menu::AppMode::emulator); myDialog->open();
myHighScoresDialog->open();
} }

View File

@ -22,9 +22,6 @@ class Properties;
class CommandSender; class CommandSender;
class DialogContainer; class DialogContainer;
class OSystem; class OSystem;
class StellaSettingsDialog;
class OptionsDialog;
class HighScoresDialog;
#include "Dialog.hxx" #include "Dialog.hxx"
@ -61,9 +58,7 @@ class MinUICommandDialog : public Dialog
ButtonWidget* myStretchButton{nullptr}; ButtonWidget* myStretchButton{nullptr};
ButtonWidget* myPhosphorButton{nullptr}; ButtonWidget* myPhosphorButton{nullptr};
unique_ptr<StellaSettingsDialog> myStellaSettingsDialog; unique_ptr<Dialog> myDialog;
unique_ptr<OptionsDialog> myOptionsDialog;
unique_ptr<HighScoresDialog> myHighScoresDialog;
enum enum
{ {

View File

@ -135,21 +135,6 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent,
wid.push_back(b); wid.push_back(b);
addCancelWidget(b); addCancelWidget(b);
// Now create all the dialogs attached to each menu button
myVideoDialog = make_unique<VideoAudioDialog>(osystem, parent, _font, max_w, max_h);
myEmulationDialog= make_unique<EmulationDialog>(osystem, parent, _font, max_w, max_h);
myInputDialog = make_unique<InputDialog>(osystem, parent, _font, max_w, max_h);
myUIDialog = make_unique<UIDialog>(osystem, parent, _font, boss, max_w, max_h);
mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, _font, max_w, max_h);
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h);
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this, max_w, max_h);
#ifdef CHEATCODE_SUPPORT
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font);
#endif
myRomAuditDialog = make_unique<RomAuditDialog>(osystem, parent, _font, max_w, max_h);
myHelpDialog = make_unique<HelpDialog>(osystem, parent, _font);
myAboutDialog = make_unique<AboutDialog>(osystem, parent, _font);
addToFocusList(wid); addToFocusList(wid);
// Certain buttons are disabled depending on mode // Certain buttons are disabled depending on mode
@ -205,133 +190,108 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
break; break;
case kEmuCmd:
myEmulationDialog->open();
break;
case kVidCmd: case kVidCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(myVideoDialog == nullptr || myVideoDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<VideoAudioDialog>(instance(), parent(), _font, w, h);
myVideoDialog = make_unique<VideoAudioDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), w, h); break;
} }
myVideoDialog->open(); case kEmuCmd:
{
uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
myDialog = make_unique<EmulationDialog>(instance(), parent(), _font, w, h);
myDialog->open();
break; break;
} }
case kInptCmd: case kInptCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(myInputDialog == nullptr || myInputDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<InputDialog>(instance(), parent(), _font, w, h);
myInputDialog = make_unique<InputDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), w, h);
}
myInputDialog->open();
break; break;
} }
case kUsrIfaceCmd: case kUsrIfaceCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(myUIDialog == nullptr || myUIDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<UIDialog>(instance(), parent(), _font, myBoss, w, h);
myUIDialog = make_unique<UIDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), myBoss, w, h);
}
myUIDialog->open();
break; break;
} }
case kSnapCmd: case kSnapCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(mySnapshotDialog == nullptr || mySnapshotDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<SnapshotDialog>(instance(), parent(), _font, w, h);
mySnapshotDialog = make_unique<SnapshotDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), w, h);
}
mySnapshotDialog->open();
break; break;
} }
case kDevelopCmd: case kDevelopCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(myDeveloperDialog == nullptr || myDeveloperDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<DeveloperDialog>(instance(), parent(), _font, w, h);
myDeveloperDialog = make_unique<DeveloperDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), w, h);
}
myDeveloperDialog->open();
break; break;
} }
case kInfoCmd: case kInfoCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
if(myGameInfoDialog == nullptr || myGameInfoDialog->shouldResize(w, h)) getDynamicBounds(w, h);
{ myDialog = make_unique<GameInfoDialog>(instance(), parent(), _font, this, w, h);
myGameInfoDialog = make_unique<GameInfoDialog>(instance(), parent(), myDialog->open();
instance().frameBuffer().font(), this, w, h);
}
myGameInfoDialog->open();
break; break;
} }
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
case kCheatCmd: case kCheatCmd:
myCheatCodeDialog->open(); myDialog = make_unique<CheatCodeDialog>(instance(), parent(), _font);
myDialog->open();
break; break;
#endif #endif
case kAuditCmd: case kAuditCmd:
myRomAuditDialog->open(); {
break; uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
myDialog = make_unique<RomAuditDialog>(instance(), parent(), _font, w, h);
myDialog->open();
break;
}
case kLoggerCmd: case kLoggerCmd:
{ {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
bool uselargefont = getDynamicBounds(w, h); bool uselargefont = getDynamicBounds(w, h);
if(myLoggerDialog == nullptr || myLoggerDialog->shouldResize(w, h)) myDialog = make_unique<LoggerDialog>(instance(), parent(), _font, w, h, uselargefont);
{ myDialog->open();
myLoggerDialog = make_unique<LoggerDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h, uselargefont);
}
myLoggerDialog->open();
break; break;
} }
case kHelpCmd: case kHelpCmd:
myHelpDialog->open(); myDialog = make_unique<HelpDialog>(instance(), parent(), _font);
myDialog->open();
break; break;
case kAboutCmd: case kAboutCmd:
myAboutDialog->open(); myDialog = make_unique<AboutDialog>(instance(), parent(), _font);
myDialog->open();
break; break;
case kExitCmd: case kExitCmd:

View File

@ -22,20 +22,6 @@ class CommandSender;
class DialogContainer; class DialogContainer;
class GuiObject; class GuiObject;
class OSystem; 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 "Menu.hxx"
#include "Dialog.hxx" #include "Dialog.hxx"
@ -52,20 +38,7 @@ class OptionsDialog : public Dialog
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
private: private:
unique_ptr<VideoAudioDialog> myVideoDialog; unique_ptr<Dialog> myDialog;
unique_ptr<EmulationDialog> myEmulationDialog;
unique_ptr<InputDialog> myInputDialog;
unique_ptr<UIDialog> myUIDialog;
unique_ptr<SnapshotDialog> mySnapshotDialog;
unique_ptr<DeveloperDialog> myDeveloperDialog;
unique_ptr<GameInfoDialog> myGameInfoDialog;
#ifdef CHEATCODE_SUPPORT
unique_ptr<CheatCodeDialog> myCheatCodeDialog;
#endif
unique_ptr<RomAuditDialog> myRomAuditDialog;
unique_ptr<LoggerDialog> myLoggerDialog;
unique_ptr<HelpDialog> myHelpDialog;
unique_ptr<AboutDialog> myAboutDialog;
ButtonWidget* myRomAuditButton{nullptr}; ButtonWidget* myRomAuditButton{nullptr};
ButtonWidget* myGameInfoButton{nullptr}; ButtonWidget* myGameInfoButton{nullptr};