cleaned the PlusROM setup code a bit

This commit is contained in:
Thomas Jentzsch 2021-09-02 09:07:14 +02:00
parent 2d8ef7f1b3
commit 2fa60f0bca
7 changed files with 44 additions and 41 deletions

View File

@ -2156,7 +2156,6 @@ bool EventHandler::changeStateByEvent(Event::Type type)
break; break;
case Event::PlusRomsSetupMode: case Event::PlusRomsSetupMode:
{
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE
|| myState == EventHandlerState::TIMEMACHINE || myState == EventHandlerState::PLAYBACK) || myState == EventHandlerState::TIMEMACHINE || myState == EventHandlerState::PLAYBACK)
enterMenuMode(EventHandlerState::PLUSROMSMENU); enterMenuMode(EventHandlerState::PLUSROMSMENU);
@ -2165,7 +2164,7 @@ bool EventHandler::changeStateByEvent(Event::Type type)
else else
handled = false; handled = false;
break; break;
}
#endif // GUI_SUPPORT #endif // GUI_SUPPORT
case Event::TimeMachineMode: case Event::TimeMachineMode:
@ -3092,7 +3091,7 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { {
{ Event::OptionsMenuMode, "Enter Options menu UI", "" }, { Event::OptionsMenuMode, "Enter Options menu UI", "" },
{ Event::CmdMenuMode, "Toggle Commands menu UI", "" }, { Event::CmdMenuMode, "Toggle Commands menu UI", "" },
{ Event::HighScoresMenuMode, "Toggle High Scores 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::TogglePauseMode, "Toggle Pause mode", "" },
{ Event::StartPauseMode, "Start Pause mode", "" }, { Event::StartPauseMode, "Start Pause mode", "" },
{ Event::Fry, "Fry cartridge", "" }, { Event::Fry, "Fry cartridge", "" },

View File

@ -31,11 +31,9 @@
InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font,
const StringList& labels, const string& title) const StringList& labels, const string& title)
: Dialog(boss->instance(), boss->parent(), font, title), : Dialog(boss->instance(), boss->parent(), font, title),
CommandSender(boss), CommandSender(boss)
lfont(font),
nfont(font)
{ {
initialize(labels); initialize(font, font, labels);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -43,11 +41,9 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& lfont,
const GUI::Font& nfont, const GUI::Font& nfont,
const StringList& labels, const string& title) const StringList& labels, const string& title)
: Dialog(boss->instance(), boss->parent(), lfont, title), : Dialog(boss->instance(), boss->parent(), lfont, title),
CommandSender(boss), CommandSender(boss)
lfont(lfont),
nfont(nfont)
{ {
initialize(labels); initialize(lfont, nfont, labels);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -55,19 +51,19 @@ InputTextDialog::InputTextDialog(OSystem& osystem, DialogContainer& parent,
const GUI::Font& font, const string& label, const GUI::Font& font, const string& label,
const string& title, int numInput) const string& title, int numInput)
: Dialog(osystem, parent, font, title), : Dialog(osystem, parent, font, title),
CommandSender(nullptr), CommandSender(nullptr)
lfont(font),
nfont(font)
{ {
StringList labels; StringList labels;
clear(); clear();
labels.push_back(label); labels.push_back(label);
initialize(labels, static_cast<int>(label.length()) + (numInput ? numInput : 24) + 2, numInput); initialize(font, font, labels,
static_cast<int>(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(), const int lineHeight = Dialog::lineHeight(),
fontHeight = Dialog::fontHeight(), fontHeight = Dialog::fontHeight(),

View File

@ -57,15 +57,14 @@ class InputTextDialog : public Dialog, public CommandSender
void setFocus(int idx = 0); void setFocus(int idx = 0);
protected: 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; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
/** This dialog uses its own positioning, so we override Dialog::center() */ /** This dialog uses its own positioning, so we override Dialog::center() */
void setPosition() override; void setPosition() override;
private: private:
const GUI::Font& lfont;
const GUI::Font& nfont;
vector<StaticTextWidget*> myLabel; vector<StaticTextWidget*> myLabel;
vector<EditTextWidget*> myInput; vector<EditTextWidget*> myInput;
StaticTextWidget* myMessage{nullptr}; StaticTextWidget* myMessage{nullptr};

View File

@ -15,10 +15,10 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include "Dialog.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "PlusRomsSetupDialog.hxx" #include "PlusRomsSetupDialog.hxx"
#include "PlusRomsMenu.hxx" #include "PlusRomsMenu.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -41,10 +41,8 @@ Dialog* PlusRomsMenu::baseDialog()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PlusRomsSetupDialog& PlusRomsMenu::plusRomsSetupDialog() PlusRomsSetupDialog& PlusRomsMenu::plusRomsSetupDialog()
{ {
StringList labels; // empty list
if(myPlusRomsSetupDialog == nullptr) if(myPlusRomsSetupDialog == nullptr)
myPlusRomsSetupDialog = new PlusRomsSetupDialog(myOSystem, *this, myOSystem.frameBuffer().font(), labels); myPlusRomsSetupDialog = new PlusRomsSetupDialog(myOSystem, *this, myOSystem.frameBuffer().font());
return *myPlusRomsSetupDialog; return *myPlusRomsSetupDialog;
} }

View File

@ -15,8 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#ifndef INPUT_MENU_HXX #ifndef PLUSROMS_MENU_HXX
#define INPUT_MENU_HXX #define PLUSROMS_MENU_HXX
class OSystem; class OSystem;
class PlusRomsSetupDialog; class PlusRomsSetupDialog;
@ -24,7 +24,7 @@ class PlusRomsSetupDialog;
#include "DialogContainer.hxx" #include "DialogContainer.hxx"
/** /**
The dialog for Plus ROMs setup. The dialog container for PlusROMs setup.
@author Thomas Jentzsch @author Thomas Jentzsch
*/ */
@ -42,6 +42,7 @@ class PlusRomsMenu : public DialogContainer
Return (and possibly create) the bottom-most dialog of this container. Return (and possibly create) the bottom-most dialog of this container.
*/ */
Dialog* baseDialog() override; Dialog* baseDialog() override;
PlusRomsSetupDialog& plusRomsSetupDialog(); PlusRomsSetupDialog& plusRomsSetupDialog();
private: private:

View File

@ -26,16 +26,28 @@ static const char* MIN_NICK_LEN_STR = "Two";
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, 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) : InputTextDialog(osystem, parent, font, "Nickname", "PlusROMs setup", MAX_NICK_LEN)
{ {
setText(instance().settings().getString("plusroms.nick"), 0);
EditableWidget::TextFilter filter = [](char c) { EditableWidget::TextFilter filter = [](char c) {
return isalnum(c) || (c == '_'); return isalnum(c) || (c == '_');
}; };
setTextFilter(filter, 0); 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, void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id) int data, int id)
@ -44,18 +56,15 @@ void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd,
{ {
case GuiObject::kOKCmd: case GuiObject::kOKCmd:
case EditableWidget::kAcceptCmd: case EditableWidget::kAcceptCmd:
{ if(getResult(0).length() >= MIN_NICK_LEN)
const string nick = getResult(0);
if(nick.length() >= MIN_NICK_LEN)
{ {
instance().settings().setValue("plusroms.nick", nick); saveConfig();
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
} }
else else
setMessage(MIN_NICK_LEN_STR + string(" characters minimum")); setMessage(MIN_NICK_LEN_STR + string(" characters minimum"));
break; break;
}
case kCloseCmd: case kCloseCmd:
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
break; break;

View File

@ -18,21 +18,22 @@
#ifndef PLUSROMS_SETUP_DIALOG_HXX #ifndef PLUSROMS_SETUP_DIALOG_HXX
#define PLUSROMS_SETUP_DIALOG_HXX #define PLUSROMS_SETUP_DIALOG_HXX
//class GuiObject;
//class StaticTextWidget;
//class EditTextWidget;
#include "InputTextDialog.hxx" #include "InputTextDialog.hxx"
/**
The dialog for PlusROMs setup.
@author Thomas Jentzsch
*/
class PlusRomsSetupDialog: public InputTextDialog class PlusRomsSetupDialog: public InputTextDialog
{ {
public: public:
PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font);
const StringList& labels, const string& title = "");
~PlusRomsSetupDialog() override = default; ~PlusRomsSetupDialog() override = default;
protected: protected:
void loadConfig() override;
void saveConfig() override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
private: private: