diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-08 16:12:33 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-08 16:12:33 +0100 |
commit | ab80acf605ed5dd50d558c6bac439a19fdf10ada (patch) | |
tree | bbb639f3581e253a77e22a96e260c193656989af /ui | |
parent | Add toolber mode switching helper (diff) | |
download | ilt-ab80acf605ed5dd50d558c6bac439a19fdf10ada.tar.bz2 ilt-ab80acf605ed5dd50d558c6bac439a19fdf10ada.tar.xz ilt-ab80acf605ed5dd50d558c6bac439a19fdf10ada.zip |
Use mode helper in main window toolbar
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gameMainWindow.cpp | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index c84781c..daa5494 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -4,6 +4,7 @@ #include "gfx/camera_controller.h" #include "manualCameraController.h" #include "maths.h" +#include "modeHelper.hpp" #include "toolbar.h" #include "window.h" #include <GL/glew.h> @@ -16,33 +17,15 @@ #include <memory> #include <utility> -class GameMainToolbar : public Toolbar { +class GameMainToolbar : Mode<decltype(GameMainSelector::target)>, public Toolbar { public: explicit GameMainToolbar(GameMainSelector * gms_) : - Toolbar { - {"ui/icon/network.png", - [this](const SDL_Event &) { - toggleSetMode<EditNetwork>(); - }}, - }, - gms {gms_} + Mode<decltype(GameMainSelector::target)> {gms_->target}, Toolbar { + {"ui/icon/network.png", + toggle<EditNetwork>()}, + } { } - -private: - template<typename UiMode, typename... Params> - void - toggleSetMode(Params &&... params) - { - if (dynamic_cast<UiMode *>(gms->target.get())) { - gms->target.reset(); - } - else { - gms->target = std::make_unique<UiMode>(std::forward<Params>(params)...); - } - } - - GameMainSelector * gms; }; GameMainWindow::GameMainWindow(size_t w, size_t h) : |