make 'Cancel' work in command dialogs

This commit is contained in:
thrust26 2019-05-04 12:55:39 +02:00
parent 951b13ed97
commit 39d3eefcef
6 changed files with 74 additions and 51 deletions

View File

@ -101,6 +101,10 @@ CommandDialog::CommandDialog(OSystem& osystem, DialogContainer& parent)
wid.push_back(bw);
addToFocusList(wid);
// We don't have a close/cancel button, but we still want the cancel
// event to be processed
processCancelWithoutWidget(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -233,6 +237,12 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
instance().eventHandler().handleEvent(event);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CommandDialog::processCancel()
{
instance().eventHandler().leaveMenuMode();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CommandDialog::updateSlot(int slot)
{

View File

@ -37,6 +37,7 @@ class CommandDialog : public Dialog
void updateSlot(int slot);
void updateTVFormat();
void updatePalette();
void processCancel() override;
// column 0
ButtonWidget* myColorButton;

View File

@ -722,7 +722,7 @@ bool Dialog::handleNavEvent(Event::Type e)
{
// Some dialogs want the ability to cancel without actually having
// a corresponding cancel button
close();
processCancel();
return true;
}
break;

View File

@ -159,6 +159,7 @@ class Dialog : public GuiObject
bool focusOKButton = true);
void processCancelWithoutWidget(bool state) { _processCancel = state; }
virtual void processCancel() { close(); }
/** Define the size (allowed) for the dialog. */
void setSize(uInt32 w, uInt32 h, uInt32 max_w, uInt32 max_h);

View File

@ -104,6 +104,10 @@ MinUICommandDialog::MinUICommandDialog(OSystem& osystem, DialogContainer& parent
wid.push_back(bw);
addToFocusList(wid);
// We don't have a close/cancel button, but we still want the cancel
// event to be processed
processCancelWithoutWidget(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -248,6 +252,12 @@ void MinUICommandDialog::handleCommand(CommandSender* sender, int cmd,
instance().eventHandler().handleEvent(event);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MinUICommandDialog::processCancel()
{
instance().eventHandler().leaveMenuMode();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MinUICommandDialog::updateSlot(int slot)
{

View File

@ -30,63 +30,64 @@ class OptionsDialog;
class MinUICommandDialog : public Dialog
{
public:
MinUICommandDialog(OSystem& osystem, DialogContainer& parent);
virtual ~MinUICommandDialog() = default;
MinUICommandDialog(OSystem& osystem, DialogContainer& parent);
virtual ~MinUICommandDialog() = default;
protected:
void loadConfig() override;
void handleKeyDown(StellaKey key, StellaMod mod) override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void updateSlot(int slot);
void updateWinds();
void updateTVFormat();
void openSettings();
void loadConfig() override;
void handleKeyDown(StellaKey key, StellaMod mod) override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void updateSlot(int slot);
void updateWinds();
void updateTVFormat();
void openSettings();
void processCancel() override;
// column 0
ButtonWidget* myColorButton;
ButtonWidget* myLeftDiffButton;
ButtonWidget* myRightDiffButton;
// column 1
ButtonWidget* mySaveStateButton;
ButtonWidget* myStateSlotButton;
ButtonWidget* myLoadStateButton;
ButtonWidget* myRewindButton;
ButtonWidget* myUnwindButton;
// column 2
ButtonWidget* myTVFormatButton;
ButtonWidget* myStretchButton;
ButtonWidget* myPhosphorButton;
// column 0
ButtonWidget* myColorButton;
ButtonWidget* myLeftDiffButton;
ButtonWidget* myRightDiffButton;
// column 1
ButtonWidget* mySaveStateButton;
ButtonWidget* myStateSlotButton;
ButtonWidget* myLoadStateButton;
ButtonWidget* myRewindButton;
ButtonWidget* myUnwindButton;
// column 2
ButtonWidget* myTVFormatButton;
ButtonWidget* myStretchButton;
ButtonWidget* myPhosphorButton;
unique_ptr<StellaSettingsDialog> myStellaSettingsDialog;
unique_ptr<OptionsDialog> myOptionsDialog;
unique_ptr<StellaSettingsDialog> myStellaSettingsDialog;
unique_ptr<OptionsDialog> myOptionsDialog;
enum
{
kSelectCmd = 'Csel',
kResetCmd = 'Cres',
kColorCmd = 'Ccol',
kLeftDiffCmd = 'Cldf',
kRightDiffCmd = 'Crdf',
kSaveStateCmd = 'Csst',
kStateSlotCmd = 'Ccst',
kLoadStateCmd = 'Clst',
kSnapshotCmd = 'Csnp',
kRewindCmd = 'Crew',
kUnwindCmd = 'Cunw',
kFormatCmd = 'Cfmt',
kStretchCmd = 'Cstr',
kPhosphorCmd = 'Cpho',
kSettings = 'Cscn',
kExitGameCmd = 'Cext',
};
enum
{
kSelectCmd = 'Csel',
kResetCmd = 'Cres',
kColorCmd = 'Ccol',
kLeftDiffCmd = 'Cldf',
kRightDiffCmd = 'Crdf',
kSaveStateCmd = 'Csst',
kStateSlotCmd = 'Ccst',
kLoadStateCmd = 'Clst',
kSnapshotCmd = 'Csnp',
kRewindCmd = 'Crew',
kUnwindCmd = 'Cunw',
kFormatCmd = 'Cfmt',
kStretchCmd = 'Cstr',
kPhosphorCmd = 'Cpho',
kSettings = 'Cscn',
kExitGameCmd = 'Cext',
};
private:
// Following constructors and assignment operators not supported
MinUICommandDialog() = delete;
MinUICommandDialog(const MinUICommandDialog&) = delete;
MinUICommandDialog(MinUICommandDialog&&) = delete;
MinUICommandDialog& operator=(const MinUICommandDialog&) = delete;
MinUICommandDialog& operator=(MinUICommandDialog&&) = delete;
// Following constructors and assignment operators not supported
MinUICommandDialog() = delete;
MinUICommandDialog(const MinUICommandDialog&) = delete;
MinUICommandDialog(MinUICommandDialog&&) = delete;
MinUICommandDialog& operator=(const MinUICommandDialog&) = delete;
MinUICommandDialog& operator=(MinUICommandDialog&&) = delete;
};
#endif