From 917b3049a10dcc41d6d02f332e81b5dd05aff33d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 18 Jan 2022 02:07:33 +0000 Subject: Beginnings of network editor Pushes gameMainSelector clicks/moves into a different target --- ui/gameMainWindow.cpp | 77 ++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 59 deletions(-) (limited to 'ui/gameMainWindow.cpp') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index f895a20..3617ca8 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -1,97 +1,56 @@ #include "gameMainWindow.h" +#include "editNetwork.h" +#include "gameMainSelector.h" #include "gfx/camera_controller.h" #include "manualCameraController.h" #include "maths.h" -#include "text.h" #include "toolbar.h" -#include "ui/uiComponent.h" #include "window.h" #include #include #include #include -#include -#include #include // IWYU pragma: keep #include #include #include -#include -#include -#include -#include -#include - -class UIShader; +#include class GameMainToolbar : public Toolbar { public: - GameMainToolbar() : + explicit GameMainToolbar(GameMainSelector * gms_) : Toolbar { {"ui/icon/network.png", - [](const SDL_Event &) { - // fprintf(stderr, "network click\n"); + [this](const SDL_Event &) { + toggleSetMode(); }}, - } + }, + gms {gms_} { } -}; - -#include - -class GameMainSelector : public UIComponent { -public: - GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } +private: + template void - render(const UIShader & shader, const Position & pos) const override + toggleSetMode(Params &&... params) { - if (!clicked.empty()) { - Text {clicked, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, pos); + if (dynamic_cast(gms->target.get())) { + gms->target.reset(); } - } - - bool - handleInput(const SDL_Event & e, const Position &) override - { - switch (e.type) { - case SDL_MOUSEBUTTONDOWN: - if (e.button.button == SDL_BUTTON_LEFT) { - const auto mouse = glm::vec2 {e.button.x, e.button.y} / position.size; - - glm::vec2 baryPos {}; - float distance; - - const auto ray = camera->unProject(mouse); - if (const auto selected = gameState->world.applyOne( - &Selectable::intersectRay, ray, &baryPos, &distance); - selected != gameState->world.end()) { - const auto & ref = *selected.base()->get(); - clicked = typeid(ref).name(); - } - else if (const auto pos = gameState->geoData->intersectRay(ray)) { - clicked = streamed_string(*pos); - } - else { - clicked.clear(); - } - return true; - } + else { + gms->target = std::make_unique(std::forward(params)...); } - return false; } -private: - const Camera * camera; - std::string clicked; + GameMainSelector * gms; }; GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains"}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h), 0.1F, 10000.0F} { uiComponents.create(glm::vec2 {-1150, -1150}); - uiComponents.create(&camera, glm::vec2 {w, h}); - uiComponents.create(); + auto gms = uiComponents.create(&camera, glm::vec2 {w, h}); + uiComponents.create(gms.get()); shader.setUniform("lightDirection", glm::normalize(glm::vec3 {1, 0, -1})); shader.setUniform("lightColor", {.6, .6, .6}); -- cgit v1.2.3