From ab80acf605ed5dd50d558c6bac439a19fdf10ada Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 Oct 2022 16:12:33 +0100 Subject: Use mode helper in main window toolbar --- ui/gameMainWindow.cpp | 29 ++++++----------------------- 1 file 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 @@ -16,33 +17,15 @@ #include #include -class GameMainToolbar : public Toolbar { +class GameMainToolbar : Mode, public Toolbar { public: explicit GameMainToolbar(GameMainSelector * gms_) : - Toolbar { - {"ui/icon/network.png", - [this](const SDL_Event &) { - toggleSetMode(); - }}, - }, - gms {gms_} + Mode {gms_->target}, Toolbar { + {"ui/icon/network.png", + toggle()}, + } { } - -private: - template - void - toggleSetMode(Params &&... params) - { - if (dynamic_cast(gms->target.get())) { - gms->target.reset(); - } - else { - gms->target = std::make_unique(std::forward(params)...); - } - } - - GameMainSelector * gms; }; GameMainWindow::GameMainWindow(size_t w, size_t h) : -- cgit v1.2.3