diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 83ebce4c9..c72982be3 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -2156,7 +2156,6 @@ bool EventHandler::changeStateByEvent(Event::Type type) break; case Event::PlusRomsSetupMode: - { if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE || myState == EventHandlerState::TIMEMACHINE || myState == EventHandlerState::PLAYBACK) enterMenuMode(EventHandlerState::PLUSROMSMENU); @@ -2165,7 +2164,7 @@ bool EventHandler::changeStateByEvent(Event::Type type) else handled = false; break; - } + #endif // GUI_SUPPORT case Event::TimeMachineMode: @@ -3092,7 +3091,7 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { { { Event::OptionsMenuMode, "Enter Options menu UI", "" }, { Event::CmdMenuMode, "Toggle Commands menu UI", "" }, { Event::HighScoresMenuMode, "Toggle High Scores UI", "" }, - { Event::PlusRomsSetupMode, "Toggle PlusROM setup UI", "" }, + { Event::PlusRomsSetupMode, "Toggle PlusROMs setup UI", "" }, { Event::TogglePauseMode, "Toggle Pause mode", "" }, { Event::StartPauseMode, "Start Pause mode", "" }, { Event::Fry, "Fry cartridge", "" }, diff --git a/src/gui/InputTextDialog.cxx b/src/gui/InputTextDialog.cxx index 726508f6a..8f5fcf401 100644 --- a/src/gui/InputTextDialog.cxx +++ b/src/gui/InputTextDialog.cxx @@ -31,11 +31,9 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, const StringList& labels, const string& title) : Dialog(boss->instance(), boss->parent(), font, title), - CommandSender(boss), - lfont(font), - nfont(font) + CommandSender(boss) { - initialize(labels); + initialize(font, font, labels); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -43,11 +41,9 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, const StringList& labels, const string& title) : Dialog(boss->instance(), boss->parent(), lfont, title), - CommandSender(boss), - lfont(lfont), - nfont(nfont) + CommandSender(boss) { - initialize(labels); + initialize(lfont, nfont, labels); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -55,19 +51,19 @@ InputTextDialog::InputTextDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, const string& label, const string& title, int numInput) : Dialog(osystem, parent, font, title), - CommandSender(nullptr), - lfont(font), - nfont(font) + CommandSender(nullptr) { StringList labels; clear(); labels.push_back(label); - initialize(labels, static_cast(label.length()) + (numInput ? numInput : 24) + 2, numInput); + initialize(font, font, labels, + static_cast(label.length()) + (numInput ? numInput : 24) + 2, numInput); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputTextDialog::initialize(const StringList& labels, int widthChars, int numInput) +void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont, + const StringList& labels, int widthChars, int numInput) { const int lineHeight = Dialog::lineHeight(), fontHeight = Dialog::fontHeight(), diff --git a/src/gui/InputTextDialog.hxx b/src/gui/InputTextDialog.hxx index ff64b16fd..93f4f7b71 100644 --- a/src/gui/InputTextDialog.hxx +++ b/src/gui/InputTextDialog.hxx @@ -57,15 +57,14 @@ class InputTextDialog : public Dialog, public CommandSender void setFocus(int idx = 0); protected: - void initialize(const StringList& labels, int widthChars = 39, int numInput = 0); + void initialize(const GUI::Font& lfont, const GUI::Font& nfont, + const StringList& labels, int widthChars = 39, int numInput = 0); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; /** This dialog uses its own positioning, so we override Dialog::center() */ void setPosition() override; private: - const GUI::Font& lfont; - const GUI::Font& nfont; vector myLabel; vector myInput; StaticTextWidget* myMessage{nullptr}; diff --git a/src/gui/PlusRomsMenu.cxx b/src/gui/PlusRomsMenu.cxx index c62bf0493..5381a22d4 100644 --- a/src/gui/PlusRomsMenu.cxx +++ b/src/gui/PlusRomsMenu.cxx @@ -15,10 +15,10 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include "Dialog.hxx" #include "OSystem.hxx" #include "FrameBuffer.hxx" #include "PlusRomsSetupDialog.hxx" + #include "PlusRomsMenu.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -41,10 +41,8 @@ Dialog* PlusRomsMenu::baseDialog() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PlusRomsSetupDialog& PlusRomsMenu::plusRomsSetupDialog() { - StringList labels; // empty list - if(myPlusRomsSetupDialog == nullptr) - myPlusRomsSetupDialog = new PlusRomsSetupDialog(myOSystem, *this, myOSystem.frameBuffer().font(), labels); + myPlusRomsSetupDialog = new PlusRomsSetupDialog(myOSystem, *this, myOSystem.frameBuffer().font()); return *myPlusRomsSetupDialog; } diff --git a/src/gui/PlusRomsMenu.hxx b/src/gui/PlusRomsMenu.hxx index 7841cadee..9f1345923 100644 --- a/src/gui/PlusRomsMenu.hxx +++ b/src/gui/PlusRomsMenu.hxx @@ -15,8 +15,8 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#ifndef INPUT_MENU_HXX -#define INPUT_MENU_HXX +#ifndef PLUSROMS_MENU_HXX +#define PLUSROMS_MENU_HXX class OSystem; class PlusRomsSetupDialog; @@ -24,7 +24,7 @@ class PlusRomsSetupDialog; #include "DialogContainer.hxx" /** - The dialog for Plus ROMs setup. + The dialog container for PlusROMs setup. @author Thomas Jentzsch */ @@ -42,6 +42,7 @@ class PlusRomsMenu : public DialogContainer Return (and possibly create) the bottom-most dialog of this container. */ Dialog* baseDialog() override; + PlusRomsSetupDialog& plusRomsSetupDialog(); private: diff --git a/src/gui/PlusRomsSetupDialog.cxx b/src/gui/PlusRomsSetupDialog.cxx index be095219e..72355a04f 100644 --- a/src/gui/PlusRomsSetupDialog.cxx +++ b/src/gui/PlusRomsSetupDialog.cxx @@ -26,16 +26,28 @@ static const char* MIN_NICK_LEN_STR = "Two"; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, - const GUI::Font& font, const StringList& labels, const string& title) + const GUI::Font& font) : InputTextDialog(osystem, parent, font, "Nickname", "PlusROMs setup", MAX_NICK_LEN) { - setText(instance().settings().getString("plusroms.nick"), 0); EditableWidget::TextFilter filter = [](char c) { return isalnum(c) || (c == '_'); }; + setTextFilter(filter, 0); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void PlusRomsSetupDialog::loadConfig() +{ + setText(instance().settings().getString("plusroms.nick"), 0); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void PlusRomsSetupDialog::saveConfig() +{ + instance().settings().setValue("plusroms.nick", getResult(0)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) @@ -44,18 +56,15 @@ void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd, { case GuiObject::kOKCmd: case EditableWidget::kAcceptCmd: - { - const string nick = getResult(0); - - if(nick.length() >= MIN_NICK_LEN) + if(getResult(0).length() >= MIN_NICK_LEN) { - instance().settings().setValue("plusroms.nick", nick); + saveConfig(); instance().eventHandler().leaveMenuMode(); } else setMessage(MIN_NICK_LEN_STR + string(" characters minimum")); break; - } + case kCloseCmd: instance().eventHandler().leaveMenuMode(); break; diff --git a/src/gui/PlusRomsSetupDialog.hxx b/src/gui/PlusRomsSetupDialog.hxx index ee8638978..69fa9267c 100644 --- a/src/gui/PlusRomsSetupDialog.hxx +++ b/src/gui/PlusRomsSetupDialog.hxx @@ -18,21 +18,22 @@ #ifndef PLUSROMS_SETUP_DIALOG_HXX #define PLUSROMS_SETUP_DIALOG_HXX -//class GuiObject; -//class StaticTextWidget; -//class EditTextWidget; - #include "InputTextDialog.hxx" +/** + The dialog for PlusROMs setup. + + @author Thomas Jentzsch +*/ class PlusRomsSetupDialog: public InputTextDialog { public: - PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, - const StringList& labels, const string& title = ""); - + PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font); ~PlusRomsSetupDialog() override = default; protected: + void loadConfig() override; + void saveConfig() override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; private: