From 648585d6f3b2677d20602398eb1d397b3974811f Mon Sep 17 00:00:00 2001 From: Jakub Neruda Date: Sat, 20 Jul 2024 13:24:03 +0200 Subject: [PATCH] Remove old DialogBase as everything is in modern format now --- src/lib-editor/include/Dialogs/DialogBase.hpp | 148 ----------- .../include/Dialogs/DialogInterface.hpp | 51 ++++ .../include/Dialogs/EditMetadataDialog.hpp | 4 +- .../include/Dialogs/EditPropertyDialog.hpp | 4 +- .../include/Dialogs/LoadLevelDialog.hpp | 4 +- .../include/Dialogs/MapPickerDialog.hpp | 4 +- .../include/Dialogs/NewLevelDialog.hpp | 4 +- .../include/Dialogs/ResizeLevelDialog.hpp | 21 -- .../include/Dialogs/SaveLevelDialog.hpp | 4 +- src/lib-editor/include/Editor/Editor.hpp | 4 - src/lib-editor/include/Editor/NullEditor.hpp | 2 - .../include/Interfaces/DialogInterfaces.hpp | 23 -- .../include/Interfaces/EditorInterface.hpp | 2 - src/lib-editor/src/Dialogs/DialogBase.cpp | 238 ------------------ .../src/Dialogs/DialogInterface.cpp | 64 +++++ .../src/Dialogs/EditMetadataDialog.cpp | 4 +- .../src/Dialogs/EditPropertyDialog.cpp | 2 +- .../src/Dialogs/LoadLevelDialog.cpp | 2 +- .../src/Dialogs/MapPickerDialog.cpp | 2 +- src/lib-editor/src/Dialogs/NewLevelDialog.cpp | 2 +- .../src/Dialogs/ResizeLevelDialog.cpp | 33 --- .../src/Dialogs/SaveLevelDialog.cpp | 2 +- src/lib-editor/src/Editor/Editor.cpp | 13 - src/tests/include/TestHelpers/EditorMock.hpp | 6 - 24 files changed, 134 insertions(+), 509 deletions(-) delete mode 100644 src/lib-editor/include/Dialogs/DialogBase.hpp create mode 100644 src/lib-editor/include/Dialogs/DialogInterface.hpp delete mode 100644 src/lib-editor/include/Dialogs/ResizeLevelDialog.hpp delete mode 100644 src/lib-editor/src/Dialogs/DialogBase.cpp create mode 100644 src/lib-editor/src/Dialogs/DialogInterface.cpp delete mode 100644 src/lib-editor/src/Dialogs/ResizeLevelDialog.cpp diff --git a/src/lib-editor/include/Dialogs/DialogBase.hpp b/src/lib-editor/include/Dialogs/DialogBase.hpp deleted file mode 100644 index 4697da4d..00000000 --- a/src/lib-editor/include/Dialogs/DialogBase.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once - -#include "Gui.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct [[nodiscard]] OptionInput final -{ - std::string label; - std::string id; - std::string value; -}; - -struct [[nodiscard]] OptionDeferredInput final -{ - std::string label; - std::string id; - std::function value; -}; - -struct [[nodiscard]] OptionInputWithButton final -{ - OptionInput base; - std::function buttonCallback = [] {}; -}; - -struct [[nodiscard]] OptionDeferredInputWithButton final -{ - OptionDeferredInput base; - std::function buttonCallback = [] {}; -}; - -struct [[nodiscard]] OptionCheckbox final -{ - std::string label; - std::string id; - bool defaultValue = false; -}; - -struct [[nodiscard]] OptionText final -{ - std::string text; - unsigned rowsToAllocate; -}; - -struct [[nodiscard]] OptionDropdown final -{ - std::string label; - std::string id; - std::vector values; -}; - -using OptionLine = std::variant< - OptionInput, - OptionDeferredInput, - OptionInputWithButton, - OptionDeferredInputWithButton, - OptionCheckbox, - OptionText, - OptionDropdown>; - -class DialogInterface -{ -protected: - mem::Rc gui; - const std::string DIALOG_ID; - const std::string DIALOG_TITLE; - const std::vector OPTIONS; - -protected: - virtual void customOpenCode() = 0; - - [[nodiscard]] std::string getEditboxValue(const std::string& boxId) const - { - return gui->get(boxId)->getText().toStdString(); - } - -public: - void open(std::function confirmCallback); - - void close() - { - gui->closeModal(DIALOG_ID); - } - - [[nodiscard]] bool isOpen() const - { - return gui->get(DIALOG_ID) != nullptr; - } - - DialogInterface( - mem::Rc gui, - const std::string& dialogId, - const std::string& dialogTitle, - const std::vector& options); - DialogInterface(const DialogInterface&) = delete; - DialogInterface(DialogInterface&&) = delete; - virtual ~DialogInterface() = default; -}; - -class ModernDialogInterface -{ -public: - ModernDialogInterface( - mem::Rc gui, - const std::string& dialogId, - const std::string& dialogTitle); - ~ModernDialogInterface() = default; - -public: - void open(std::function confirmCallback); - - void close() - { - gui->closeModal(DIALOG_ID); - } - - [[nodiscard]] bool isOpen() const - { - return gui->get(DIALOG_ID) != nullptr; - } - -protected: - void buildLayout(std::function confirmCallback); - void buildBottomButtons( - tgui::ChildWindow::Ptr modal, std::function confirmCallback); - - virtual std::expected - validateBeforeConfirmation() const - { - return ReturnFlag::Success; - }; - - virtual void buildLayoutImpl(tgui::Panel::Ptr target) = 0; - -protected: - mem::Rc gui; - const std::string DIALOG_ID; - const std::string DIALOG_TITLE; -}; diff --git a/src/lib-editor/include/Dialogs/DialogInterface.hpp b/src/lib-editor/include/Dialogs/DialogInterface.hpp new file mode 100644 index 00000000..80e531d6 --- /dev/null +++ b/src/lib-editor/include/Dialogs/DialogInterface.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "Gui.hpp" +#include +#include +#include +#include +#include +#include +#include + +class DialogInterface +{ +public: + DialogInterface( + mem::Rc gui, + const std::string& dialogId, + const std::string& dialogTitle); + ~DialogInterface() = default; + +public: + void open(std::function confirmCallback); + + void close() + { + gui->closeModal(DIALOG_ID); + } + + [[nodiscard]] bool isOpen() const + { + return gui->get(DIALOG_ID) != nullptr; + } + +protected: + void buildLayout(std::function confirmCallback); + void buildBottomButtons( + tgui::ChildWindow::Ptr modal, std::function confirmCallback); + + virtual std::expected + validateBeforeConfirmation() const + { + return ReturnFlag::Success; + }; + + virtual void buildLayoutImpl(tgui::Panel::Ptr target) = 0; + +protected: + mem::Rc gui; + const std::string DIALOG_ID; + const std::string DIALOG_TITLE; +}; diff --git a/src/lib-editor/include/Dialogs/EditMetadataDialog.hpp b/src/lib-editor/include/Dialogs/EditMetadataDialog.hpp index 51a19566..a9910007 100644 --- a/src/lib-editor/include/Dialogs/EditMetadataDialog.hpp +++ b/src/lib-editor/include/Dialogs/EditMetadataDialog.hpp @@ -1,6 +1,6 @@ #pragma once -#include "DialogBase.hpp" +#include "DialogInterface.hpp" #include "FormBuilder.hpp" #include "MetadataDialogBase.hpp" #include @@ -8,7 +8,7 @@ #include class [[nodiscard]] EditMetadataDialog final - : protected ModernDialogInterface + : protected DialogInterface , public MetadataDialogBase { public: diff --git a/src/lib-editor/include/Dialogs/EditPropertyDialog.hpp b/src/lib-editor/include/Dialogs/EditPropertyDialog.hpp index a656bb9c..013d165e 100644 --- a/src/lib-editor/include/Dialogs/EditPropertyDialog.hpp +++ b/src/lib-editor/include/Dialogs/EditPropertyDialog.hpp @@ -1,11 +1,11 @@ #pragma once +#include "Dialogs/DialogInterface.hpp" #include "Gui.hpp" -#include "Interfaces/DialogInterfaces.hpp" #include "Interfaces/ToolPropertyInterface.hpp" #include -class [[nodiscard]] EditPropertyDialog final : public ModernDialogInterface +class [[nodiscard]] EditPropertyDialog final : public DialogInterface { public: EditPropertyDialog( diff --git a/src/lib-editor/include/Dialogs/LoadLevelDialog.hpp b/src/lib-editor/include/Dialogs/LoadLevelDialog.hpp index 9b04346a..5811327c 100644 --- a/src/lib-editor/include/Dialogs/LoadLevelDialog.hpp +++ b/src/lib-editor/include/Dialogs/LoadLevelDialog.hpp @@ -1,9 +1,9 @@ #pragma once -#include +#include #include -class [[nodiscard]] LoadLevelDialog final : public ModernDialogInterface +class [[nodiscard]] LoadLevelDialog final : public DialogInterface { public: LoadLevelDialog(mem::Rc gui, const std::filesystem::path& rootDir); diff --git a/src/lib-editor/include/Dialogs/MapPickerDialog.hpp b/src/lib-editor/include/Dialogs/MapPickerDialog.hpp index cf7afa0e..3f54ce9b 100644 --- a/src/lib-editor/include/Dialogs/MapPickerDialog.hpp +++ b/src/lib-editor/include/Dialogs/MapPickerDialog.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include struct MapSettingsForPicker @@ -9,7 +9,7 @@ struct MapSettingsForPicker bool enabled; }; -class MapPickerDialog : public ModernDialogInterface +class MapPickerDialog : public DialogInterface { public: MapPickerDialog( diff --git a/src/lib-editor/include/Dialogs/NewLevelDialog.hpp b/src/lib-editor/include/Dialogs/NewLevelDialog.hpp index af26aa8e..5189cbbd 100644 --- a/src/lib-editor/include/Dialogs/NewLevelDialog.hpp +++ b/src/lib-editor/include/Dialogs/NewLevelDialog.hpp @@ -1,6 +1,6 @@ #pragma once -#include "DialogBase.hpp" +#include "DialogInterface.hpp" #include "MetadataDialogBase.hpp" #include #include @@ -8,7 +8,7 @@ #include class [[nodiscard]] ModernNewLevelDialog final - : public ModernDialogInterface + : public DialogInterface , public MetadataDialogBase { public: diff --git a/src/lib-editor/include/Dialogs/ResizeLevelDialog.hpp b/src/lib-editor/include/Dialogs/ResizeLevelDialog.hpp deleted file mode 100644 index d4dfe4f2..00000000 --- a/src/lib-editor/include/Dialogs/ResizeLevelDialog.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "DialogBase.hpp" -#include "Gui.hpp" - -class ResizeDialog final : public DialogInterface -{ -private: - virtual void customOpenCode() override {} - -public: - [[nodiscard]] unsigned getLevelWidth() const; - - [[nodiscard]] unsigned getLevelHeight() const; - - [[nodiscard]] bool isTranslationDisabled() const; - - ResizeDialog(mem::Rc gui); - ResizeDialog(const ResizeDialog&) = delete; - ResizeDialog(ResizeDialog&&) = delete; -}; diff --git a/src/lib-editor/include/Dialogs/SaveLevelDialog.hpp b/src/lib-editor/include/Dialogs/SaveLevelDialog.hpp index 36c78fd2..f40fe286 100644 --- a/src/lib-editor/include/Dialogs/SaveLevelDialog.hpp +++ b/src/lib-editor/include/Dialogs/SaveLevelDialog.hpp @@ -1,9 +1,9 @@ #pragma once -#include "Dialogs/DialogBase.hpp" +#include "Dialogs/DialogInterface.hpp" #include -class [[nodiscard]] NewSaveLevelDialog final : public ModernDialogInterface +class [[nodiscard]] NewSaveLevelDialog final : public DialogInterface { public: NewSaveLevelDialog( diff --git a/src/lib-editor/include/Editor/Editor.hpp b/src/lib-editor/include/Editor/Editor.hpp index ad87479f..1757bfce 100644 --- a/src/lib-editor/include/Editor/Editor.hpp +++ b/src/lib-editor/include/Editor/Editor.hpp @@ -4,7 +4,6 @@ #include "Commands/CommandQueue.hpp" #include "Dialogs/EditMetadataDialog.hpp" #include "Dialogs/EditPropertyDialog.hpp" -#include "Dialogs/ResizeLevelDialog.hpp" #include "Editor/EditorState.hpp" #include "Editor/EditorStateManager.hpp" #include "Globals.hpp" @@ -45,8 +44,6 @@ class [[nodiscard]] Editor final : public EditorInterface [[nodiscard]] virtual LevelD save() override; - virtual void resizeDialog() override; - virtual void resize( unsigned width, unsigned height, bool isTranslationDisabled) override; @@ -118,7 +115,6 @@ class [[nodiscard]] Editor final : public EditorInterface mem::Rc levelMetadata; std::filesystem::path graphicsDir; - ResizeDialog dialog = ResizeDialog(gui); mem::Box editPropertyDialog = mem::Box(gui, mem::Box()); EditMetadataDialog editMetadataDialog = EditMetadataDialog(gui); diff --git a/src/lib-editor/include/Editor/NullEditor.hpp b/src/lib-editor/include/Editor/NullEditor.hpp index 2a480ac1..628f16ec 100644 --- a/src/lib-editor/include/Editor/NullEditor.hpp +++ b/src/lib-editor/include/Editor/NullEditor.hpp @@ -18,8 +18,6 @@ class NullEditor final : public EditorInterface void switchTool(EditorState) override {} - void resizeDialog() override {} - void resize(unsigned, unsigned, bool) override {} void shrinkToFit() override {} diff --git a/src/lib-editor/include/Interfaces/DialogInterfaces.hpp b/src/lib-editor/include/Interfaces/DialogInterfaces.hpp index 13f1cab6..5456e6b4 100644 --- a/src/lib-editor/include/Interfaces/DialogInterfaces.hpp +++ b/src/lib-editor/include/Interfaces/DialogInterfaces.hpp @@ -1,6 +1,5 @@ #pragma once -#include "Dialogs/DialogBase.hpp" #include #include #include @@ -32,25 +31,3 @@ class ErrorInfoDialogInterface public: virtual void open(const std::string& text) = 0; }; - -class PlaytestSettingsDialogInterface : public DialogInterface -{ -public: - PlaytestSettingsDialogInterface( - mem::Rc gui, - const std::string& id, - const std::string& title, - const std::vector& options) - : DialogInterface(gui, id, title, options) - { - } - - virtual ~PlaytestSettingsDialogInterface() = default; - -public: - [[nodiscard]] virtual std::filesystem::path getBinaryPath() const = 0; - - [[nodiscard]] virtual std::string getLaunchParameters() const = 0; - - [[nodiscard]] virtual std::filesystem::path getWorkingDirPath() const = 0; -}; diff --git a/src/lib-editor/include/Interfaces/EditorInterface.hpp b/src/lib-editor/include/Interfaces/EditorInterface.hpp index e605e118..11097ad4 100644 --- a/src/lib-editor/include/Interfaces/EditorInterface.hpp +++ b/src/lib-editor/include/Interfaces/EditorInterface.hpp @@ -18,8 +18,6 @@ class EditorInterface virtual void switchTool(EditorState state) = 0; - virtual void resizeDialog() = 0; - virtual void resize(unsigned width, unsigned height, bool isTranslationDisabled) = 0; diff --git a/src/lib-editor/src/Dialogs/DialogBase.cpp b/src/lib-editor/src/Dialogs/DialogBase.cpp deleted file mode 100644 index 6cb69a17..00000000 --- a/src/lib-editor/src/Dialogs/DialogBase.cpp +++ /dev/null @@ -1,238 +0,0 @@ -#include "Dialogs/DialogBase.hpp" -#include "Globals.hpp" -#include - -template -struct overloaded : Ts... -{ - using Ts::operator()...; -}; - -void DialogInterface::open(std::function confirmCallback) -{ - if (gui->isAnyModalOpened()) return; - - auto modal = gui->createNewChildWindow(DIALOG_TITLE); - modal->setSize("30%", "50%"); - modal->setPosition("35%", "25%"); - modal->onEscapeKeyPress([this](auto) { close(); }); - modal->onClose([this] { close(); }); - gui->add(modal, DIALOG_ID); - - constexpr auto ROW_HEIGHT = 6_upercent; - constexpr auto ROW_HEIGHT_STR = "6%"; - constexpr auto MARGIN = 2_upercent; - constexpr auto ROW_SPACING = 1_upercent; - constexpr auto LABEL_WIDTH = "48%"; - constexpr auto INPUT_POSITION_X = "52%"; - - auto computeYposFromRow = [&](unsigned row) -> std::string - { return std::to_string(row * (ROW_HEIGHT + ROW_SPACING) + MARGIN) + "%"; }; - - auto computeMultiRowHeight = [&ROW_HEIGHT](unsigned rowCount) -> std::string - { - return std::to_string( - ROW_HEIGHT + (rowCount - 1) * (ROW_HEIGHT + ROW_SPACING)) - + "%"; - }; - - auto addLabel = [&](const std::string& text, unsigned row) - { - auto label = tgui::Label::create(text); - label->setSize(LABEL_WIDTH, ROW_HEIGHT_STR); - label->setPosition("2%", computeYposFromRow(row).c_str()); - label->setVerticalAlignment(tgui::Label::VerticalAlignment::Center); - modal->add(label); - }; - - auto addEditBox = [&](const std::string& value, - const std::string& id, - unsigned row, - bool narrow = false) - { - auto box = tgui::EditBox::create(); - box->setSize(narrow ? "38%" : "46%", ROW_HEIGHT_STR); - box->setPosition(INPUT_POSITION_X, computeYposFromRow(row).c_str()); - box->setText(value); - modal->add(box, id); - }; - - auto addCheckbox = [&](const bool, const std::string& id, unsigned row) - { - auto check = tgui::CheckBox::create(); - check->setPosition(INPUT_POSITION_X, computeYposFromRow(row).c_str()); - modal->add(check, id); - }; - - auto addHelperButton = [&](std::function callback, unsigned row) - { - auto btn = tgui::Button::create("..."); - btn->setSize("8%", "6%"); - btn->setPosition("90%", computeYposFromRow(row).c_str()); - btn->onClick(callback); - modal->add(btn); - }; - - auto addText = - [&](const std::string& text, unsigned occupiedRows, unsigned row) - { - auto label = tgui::Label::create(text); - label->setSize("96%", computeMultiRowHeight(occupiedRows).c_str()); - label->setPosition("2%", computeYposFromRow(row).c_str()); - label->setVerticalAlignment(tgui::Label::VerticalAlignment::Center); - modal->add(label); - }; - - auto addDropdown = [&](const std::string& id, - const std::vector& values, - unsigned row) - { - auto combo = tgui::ComboBox::create(); - for (auto&& opt : values) - { - combo->addItem(opt); - } - combo->setPosition(INPUT_POSITION_X, computeYposFromRow(row).c_str()); - combo->setSelectedItem(values.front()); - modal->add(combo, id); - }; - - unsigned row = 0; - for (auto&& option : OPTIONS) - { - std::visit( - overloaded { - [&](const OptionInput& input) - { - addLabel(input.label, row); - addEditBox(input.value, input.id, row); - }, - [&](const OptionDeferredInput& input) - { - addLabel(input.label, row); - addEditBox(input.value(), input.id, row); - }, - [&](const OptionInputWithButton& input) - { - addLabel(input.base.label, row); - addEditBox( - input.base.value, input.base.id, row, "narrow"_true); - addHelperButton(input.buttonCallback, row); - }, - [&](const OptionDeferredInputWithButton& input) - { - addLabel(input.base.label, row); - addEditBox( - input.base.value(), input.base.id, row, "narrow"_true); - addHelperButton(input.buttonCallback, row); - }, - [&](const OptionCheckbox& input) - { - addLabel(input.label, row); - addCheckbox(input.defaultValue, input.id, row); - }, - [&](const OptionText& input) - { - addText(input.text, input.rowsToAllocate, row); - row += input.rowsToAllocate - 1; - }, - [&](const OptionDropdown& input) - { - addLabel(input.label, row); - addDropdown(input.id, input.values, row); - } } - - , - std::forward(option)); - row++; - } - - auto btn = tgui::Button::create("Ok"); - btn->setSize("20%", "8%"); - btn->setPosition("56%", "90%"); - btn->onClick( - [this, confirmCallback] - { - confirmCallback(); - close(); - }); - modal->add(btn); - - btn = tgui::Button::create("Cancel"); - btn->setSize("20%", "8%"); - btn->setPosition("78%", "90%"); - btn->onClick([this] { close(); }); - modal->add(btn); - - customOpenCode(); -} - -DialogInterface::DialogInterface( - mem::Rc gui, - const std::string& dialogId, - const std::string& dialogTitle, - const std::vector& options) - : gui(gui), DIALOG_ID(dialogId), DIALOG_TITLE(dialogTitle), OPTIONS(options) -{ -} - -ModernDialogInterface::ModernDialogInterface( - mem::Rc gui, - const std::string& dialogId, - const std::string& dialogTitle) - : gui(gui), DIALOG_ID(dialogId), DIALOG_TITLE(dialogTitle) -{ -} - -void ModernDialogInterface::open(std::function confirmCallback) -{ - if (isOpen()) return; - buildLayout(confirmCallback); -} - -void ModernDialogInterface::buildLayout(std::function confirmCallback) -{ - auto modal = gui->createNewChildWindow(DIALOG_TITLE); - modal->setSize("30%", "50%"); - modal->setPosition("35%", "25%"); - modal->onEscapeKeyPress([this](auto) { close(); }); - modal->onClose([this] { close(); }); - gui->add(modal, DIALOG_ID); - - auto panel = tgui::Panel::create({ "90%", "85%" }); - panel->setPosition({ "5%", "5%" }); - panel->setRenderer(gui->theme->getRenderer("Panel")); - modal->add(panel); - - buildBottomButtons(modal, confirmCallback); - buildLayoutImpl(panel); -} - -void ModernDialogInterface::buildBottomButtons( - tgui::ChildWindow::Ptr modal, std::function confirmCallback) -{ - auto btn = tgui::Button::create(Strings::Dialog::SUBMIT_OK); - btn->setSize("20%", "8%"); - btn->setPosition("56%", "90%"); - btn->onClick( - [this, confirmCallback] - { - auto validationResult = validateBeforeConfirmation(); - if (!validationResult) - { - throw std::runtime_error(validationResult.error()); - } - else - { - confirmCallback(); - close(); - } - }); - modal->add(btn); - - btn = tgui::Button::create(Strings::Dialog::SUBMIT_CANCEL); - btn->setSize("20%", "8%"); - btn->setPosition("78%", "90%"); - btn->onClick([this] { close(); }); - modal->add(btn); -} diff --git a/src/lib-editor/src/Dialogs/DialogInterface.cpp b/src/lib-editor/src/Dialogs/DialogInterface.cpp new file mode 100644 index 00000000..1584e39e --- /dev/null +++ b/src/lib-editor/src/Dialogs/DialogInterface.cpp @@ -0,0 +1,64 @@ +#include "Dialogs/DialogInterface.hpp" +#include "Globals.hpp" +#include + +DialogInterface::DialogInterface( + mem::Rc gui, + const std::string& dialogId, + const std::string& dialogTitle) + : gui(gui), DIALOG_ID(dialogId), DIALOG_TITLE(dialogTitle) +{ +} + +void DialogInterface::open(std::function confirmCallback) +{ + if (isOpen()) return; + buildLayout(confirmCallback); +} + +void DialogInterface::buildLayout(std::function confirmCallback) +{ + auto modal = gui->createNewChildWindow(DIALOG_TITLE); + modal->setSize("30%", "50%"); + modal->setPosition("35%", "25%"); + modal->onEscapeKeyPress([this](auto) { close(); }); + modal->onClose([this] { close(); }); + gui->add(modal, DIALOG_ID); + + auto panel = tgui::Panel::create({ "90%", "85%" }); + panel->setPosition({ "5%", "5%" }); + panel->setRenderer(gui->theme->getRenderer("Panel")); + modal->add(panel); + + buildBottomButtons(modal, confirmCallback); + buildLayoutImpl(panel); +} + +void DialogInterface::buildBottomButtons( + tgui::ChildWindow::Ptr modal, std::function confirmCallback) +{ + auto btn = tgui::Button::create(Strings::Dialog::SUBMIT_OK); + btn->setSize("20%", "8%"); + btn->setPosition("56%", "90%"); + btn->onClick( + [this, confirmCallback] + { + auto validationResult = validateBeforeConfirmation(); + if (!validationResult) + { + throw std::runtime_error(validationResult.error()); + } + else + { + confirmCallback(); + close(); + } + }); + modal->add(btn); + + btn = tgui::Button::create(Strings::Dialog::SUBMIT_CANCEL); + btn->setSize("20%", "8%"); + btn->setPosition("78%", "90%"); + btn->onClick([this] { close(); }); + modal->add(btn); +} diff --git a/src/lib-editor/src/Dialogs/EditMetadataDialog.cpp b/src/lib-editor/src/Dialogs/EditMetadataDialog.cpp index ff3711ea..9d7f3b66 100644 --- a/src/lib-editor/src/Dialogs/EditMetadataDialog.cpp +++ b/src/lib-editor/src/Dialogs/EditMetadataDialog.cpp @@ -3,7 +3,7 @@ #include EditMetadataDialog::EditMetadataDialog(mem::Rc gui) - : ModernDialogInterface( + : DialogInterface( gui, "EditMetadataDialog", Strings::Dialog::Title::EDIT_METADATA) { } @@ -15,7 +15,7 @@ void EditMetadataDialog::open( texturePack = metadata.texturePack; author = metadata.author; - ModernDialogInterface::open(confirmCallback); + DialogInterface::open(confirmCallback); } void EditMetadataDialog::buildLayoutImpl(tgui::Panel::Ptr panel) diff --git a/src/lib-editor/src/Dialogs/EditPropertyDialog.cpp b/src/lib-editor/src/Dialogs/EditPropertyDialog.cpp index 9568d466..c8d7886c 100644 --- a/src/lib-editor/src/Dialogs/EditPropertyDialog.cpp +++ b/src/lib-editor/src/Dialogs/EditPropertyDialog.cpp @@ -5,7 +5,7 @@ static inline constexpr const char* EDIT_DIALOG_ID = "EditPropertyDialog"; EditPropertyDialog::EditPropertyDialog( mem::Rc gui, mem::Box property) - : ModernDialogInterface( + : DialogInterface( gui, EDIT_DIALOG_ID, Strings::Editor::EDIT_PROPERTIES) , property(std::move(property)) { diff --git a/src/lib-editor/src/Dialogs/LoadLevelDialog.cpp b/src/lib-editor/src/Dialogs/LoadLevelDialog.cpp index 72a1ca83..61c016a6 100644 --- a/src/lib-editor/src/Dialogs/LoadLevelDialog.cpp +++ b/src/lib-editor/src/Dialogs/LoadLevelDialog.cpp @@ -8,7 +8,7 @@ constexpr const char* SELECT_LEVEL_ID = "SelectLevelId"; LoadLevelDialog::LoadLevelDialog( mem::Rc gui, const std::filesystem::path& rootDir) - : ModernDialogInterface( + : DialogInterface( gui, "LoadLevelDialog", Strings::Dialog::Title::OPEN_LEVEL) , levelsDir(Filesystem::getLevelsDir(rootDir)) , mapPackNames(Filesystem::getLevelPackNames(levelsDir)) diff --git a/src/lib-editor/src/Dialogs/MapPickerDialog.cpp b/src/lib-editor/src/Dialogs/MapPickerDialog.cpp index 1ac8a192..68a69bf8 100644 --- a/src/lib-editor/src/Dialogs/MapPickerDialog.cpp +++ b/src/lib-editor/src/Dialogs/MapPickerDialog.cpp @@ -5,7 +5,7 @@ MapPickerDialog::MapPickerDialog( mem::Rc gui, const std::vector& settings) - : ModernDialogInterface( + : DialogInterface( gui, "MapPickerDialogId", Strings::Dialog::Title::SELECT_MAPS) , maps(settings) { diff --git a/src/lib-editor/src/Dialogs/NewLevelDialog.cpp b/src/lib-editor/src/Dialogs/NewLevelDialog.cpp index 5b3c1b19..baeb162e 100644 --- a/src/lib-editor/src/Dialogs/NewLevelDialog.cpp +++ b/src/lib-editor/src/Dialogs/NewLevelDialog.cpp @@ -3,7 +3,7 @@ #include ModernNewLevelDialog::ModernNewLevelDialog(mem::Rc gui) - : ModernDialogInterface( + : DialogInterface( gui, "ModernNewLevelDialog", Strings::Dialog::Title::NEW_LEVEL) { } diff --git a/src/lib-editor/src/Dialogs/ResizeLevelDialog.cpp b/src/lib-editor/src/Dialogs/ResizeLevelDialog.cpp deleted file mode 100644 index a6204a6a..00000000 --- a/src/lib-editor/src/Dialogs/ResizeLevelDialog.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Dialogs/ResizeLevelDialog.hpp" - -constexpr const char* INPUT_LEVEL_WIDTH_ID = "InputLevelWidth"; -constexpr const char* INPUT_LEVEL_HEIGHT_ID = "InputLevelHeight"; -constexpr const char* INPUT_NO_TRANSLATE_ID = "InputNoTranslation"; - -unsigned ResizeDialog::getLevelWidth() const -{ - return std::stoul(getEditboxValue(INPUT_LEVEL_WIDTH_ID)); -} - -unsigned ResizeDialog::getLevelHeight() const -{ - return std::stoul(getEditboxValue(INPUT_LEVEL_HEIGHT_ID)); -} - -bool ResizeDialog::isTranslationDisabled() const -{ - return gui->get(INPUT_NO_TRANSLATE_ID)->isChecked(); -} - -ResizeDialog::ResizeDialog(mem::Rc gui) - : DialogInterface( - gui, - "ResizeLevelDialog", - "Resize Level", - std::vector { - OptionInput { "Level width:", INPUT_LEVEL_WIDTH_ID, "20" }, - OptionInput { "Level height:", INPUT_LEVEL_HEIGHT_ID, "10" }, - OptionCheckbox { - "No translations:", INPUT_NO_TRANSLATE_ID, false } }) -{ -} diff --git a/src/lib-editor/src/Dialogs/SaveLevelDialog.cpp b/src/lib-editor/src/Dialogs/SaveLevelDialog.cpp index 9e56c029..cae9fe69 100644 --- a/src/lib-editor/src/Dialogs/SaveLevelDialog.cpp +++ b/src/lib-editor/src/Dialogs/SaveLevelDialog.cpp @@ -8,7 +8,7 @@ constexpr const char* LEVEL_NAME_ID = "LevelNameId"; NewSaveLevelDialog::NewSaveLevelDialog( mem::Rc gui, const std::filesystem::path& levelsDir) - : ModernDialogInterface( + : DialogInterface( gui, "SaveLevelDialogId", Strings::Dialog::Title::SAVE_LEVEL) , levelsDir(levelsDir) , mapPackNames(Filesystem::getLevelPackNames(levelsDir)) diff --git a/src/lib-editor/src/Editor/Editor.cpp b/src/lib-editor/src/Editor/Editor.cpp index 2210c248..84d21fbc 100644 --- a/src/lib-editor/src/Editor/Editor.cpp +++ b/src/lib-editor/src/Editor/Editor.cpp @@ -314,19 +314,6 @@ LevelD Editor::save() return result; } -void Editor::resizeDialog() -{ - dialog.open( - [this] - { - commandQueue->push( - *this, - dialog.getLevelWidth(), - dialog.getLevelHeight(), - dialog.isTranslationDisabled()); - }); -} - void Editor::resize(unsigned width, unsigned height, bool isTranslationDisabled) { stateMgr.forallStates( diff --git a/src/tests/include/TestHelpers/EditorMock.hpp b/src/tests/include/TestHelpers/EditorMock.hpp index d2670401..9446ea28 100644 --- a/src/tests/include/TestHelpers/EditorMock.hpp +++ b/src/tests/include/TestHelpers/EditorMock.hpp @@ -10,7 +10,6 @@ struct EditorMockState unsigned saveToFileCallCounter = 0; unsigned loadFromFileCallCounter = 0; unsigned switchToolCallCounter = 0; - unsigned resizeDialogCallCounter = 0; unsigned shrinkToFitCallCounter = 0; }; @@ -53,11 +52,6 @@ class EditorMock final : public EditorInterface state->switchToolCallCounter++; } - virtual void resizeDialog() override - { - state->resizeDialogCallCounter++; - } - virtual void resize(unsigned width, unsigned height, bool isTranslationDisabled) override {