diff --git a/src/gui/PlusRomsMenu.cxx b/src/gui/PlusRomsMenu.cxx new file mode 100644 index 000000000..c62bf0493 --- /dev/null +++ b/src/gui/PlusRomsMenu.cxx @@ -0,0 +1,50 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "Dialog.hxx" +#include "OSystem.hxx" +#include "FrameBuffer.hxx" +#include "PlusRomsSetupDialog.hxx" +#include "PlusRomsMenu.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PlusRomsMenu::PlusRomsMenu(OSystem& osystem) + : DialogContainer(osystem) +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PlusRomsMenu::~PlusRomsMenu() +{ + delete myPlusRomsSetupDialog; myPlusRomsSetupDialog = nullptr; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Dialog* PlusRomsMenu::baseDialog() +{ + return &plusRomsSetupDialog(); +} +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PlusRomsSetupDialog& PlusRomsMenu::plusRomsSetupDialog() +{ + StringList labels; // empty list + + if(myPlusRomsSetupDialog == nullptr) + myPlusRomsSetupDialog = new PlusRomsSetupDialog(myOSystem, *this, myOSystem.frameBuffer().font(), labels); + + return *myPlusRomsSetupDialog; +} diff --git a/src/gui/PlusRomsMenu.hxx b/src/gui/PlusRomsMenu.hxx new file mode 100644 index 000000000..7841cadee --- /dev/null +++ b/src/gui/PlusRomsMenu.hxx @@ -0,0 +1,59 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef INPUT_MENU_HXX +#define INPUT_MENU_HXX + +class OSystem; +class PlusRomsSetupDialog; + +#include "DialogContainer.hxx" + +/** + The dialog for Plus ROMs setup. + + @author Thomas Jentzsch +*/ +class PlusRomsMenu : public DialogContainer +{ + public: + /** + Create a new menu stack + */ + explicit PlusRomsMenu(OSystem& osystem); + ~PlusRomsMenu() override; + + private: + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + Dialog* baseDialog() override; + PlusRomsSetupDialog& plusRomsSetupDialog(); + + private: + PlusRomsSetupDialog* myPlusRomsSetupDialog{nullptr}; + + private: + // Following constructors and assignment operators not supported + PlusRomsMenu() = delete; + PlusRomsMenu(const PlusRomsMenu&) = delete; + PlusRomsMenu(PlusRomsMenu&&) = delete; + PlusRomsMenu& operator=(const PlusRomsMenu&) = delete; + PlusRomsMenu& operator=(PlusRomsMenu&&) = delete; +}; + +#endif diff --git a/src/gui/PlusRomsSetupDialog.cxx b/src/gui/PlusRomsSetupDialog.cxx new file mode 100644 index 000000000..f26a0d5ef --- /dev/null +++ b/src/gui/PlusRomsSetupDialog.cxx @@ -0,0 +1,70 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "OSystem.hxx" +#include "EventHandler.hxx" + +#include "PlusRomsSetupDialog.hxx" + +static const int MIN_NICK_LEN = 2; +static const int MAX_NICK_LEN = 16; +static const char* MIN_NICK_LEN_STR = "Two"; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, + const GUI::Font& font, const StringList& labels, const string& title) + : 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::handleCommand(CommandSender* sender, int cmd, + int data, int id) +{ + switch(cmd) + { + case GuiObject::kOKCmd: + case EditableWidget::kAcceptCmd: + { + const string nick = getResult(0); + + if(nick.length() >= MIN_NICK_LEN) + { + instance().settings().setValue("plusroms.nick", nick); + instance().eventHandler().leaveMenuMode(); + } + else + setMessage("Two characters minimum"); + break; + } + case kCloseCmd: + instance().eventHandler().leaveMenuMode(); + break; + + case EditableWidget::kCancelCmd: + break; + + default: + InputTextDialog::handleCommand(sender, cmd, data, id); + break; + } +} \ No newline at end of file diff --git a/src/gui/PlusRomsSetupDialog.hxx b/src/gui/PlusRomsSetupDialog.hxx new file mode 100644 index 000000000..ee8638978 --- /dev/null +++ b/src/gui/PlusRomsSetupDialog.hxx @@ -0,0 +1,47 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef PLUSROMS_SETUP_DIALOG_HXX +#define PLUSROMS_SETUP_DIALOG_HXX + +//class GuiObject; +//class StaticTextWidget; +//class EditTextWidget; + +#include "InputTextDialog.hxx" + +class PlusRomsSetupDialog: public InputTextDialog +{ + public: + PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, + const StringList& labels, const string& title = ""); + + ~PlusRomsSetupDialog() override = default; + + protected: + void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + + private: + // Following constructors and assignment operators not supported + PlusRomsSetupDialog() = delete; + PlusRomsSetupDialog(const PlusRomsSetupDialog&) = delete; + PlusRomsSetupDialog(PlusRomsSetupDialog&&) = delete; + PlusRomsSetupDialog& operator=(const PlusRomsSetupDialog&) = delete; + PlusRomsSetupDialog& operator=(PlusRomsSetupDialog&&) = delete; + }; + +#endif