mirror of https://github.com/stella-emu/stella.git
cleaned the PlusROM setup code a bit
This commit is contained in:
parent
6b6c568a3d
commit
2af502a618
|
@ -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", "" },
|
||||
|
|
|
@ -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<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(),
|
||||
fontHeight = Dialog::fontHeight(),
|
||||
|
|
|
@ -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<StaticTextWidget*> myLabel;
|
||||
vector<EditTextWidget*> myInput;
|
||||
StaticTextWidget* myMessage{nullptr};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue