diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-08 18:40:58 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-08 18:40:58 +0100 |
commit | 920ae293f6830833146a524345dfbf00669e785b (patch) | |
tree | b971a645b4bb3347ac1ccac31efc05b9445b4ca4 | |
parent | Move addStraight to impl.h (diff) | |
download | ilt-920ae293f6830833146a524345dfbf00669e785b.tar.bz2 ilt-920ae293f6830833146a524345dfbf00669e785b.tar.xz ilt-920ae293f6830833146a524345dfbf00669e785b.zip |
Add a rather dumb builder for joining nodes
-rw-r--r-- | game/network/network.h | 2 | ||||
-rw-r--r-- | game/network/network.impl.h | 7 | ||||
-rw-r--r-- | ui/builders/join.cpp | 43 | ||||
-rw-r--r-- | ui/builders/join.h | 15 | ||||
-rw-r--r-- | ui/editNetwork.cpp | 4 |
5 files changed, 70 insertions, 1 deletions
diff --git a/game/network/network.h b/game/network/network.h index c795d86..9dbca7c 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -31,6 +31,7 @@ public: [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const NodePtr &) const; virtual LinkPtr addStraight(glm::vec3, glm::vec3) = 0; + virtual LinkPtr addJoins(glm::vec3, glm::vec3) = 0; protected: static void joinLinks(const LinkPtr & l, const LinkPtr & ol); @@ -63,6 +64,7 @@ public: } LinkPtr addStraight(glm::vec3 n1, glm::vec3 n2) override; + LinkPtr addJoins(glm::vec3, glm::vec3) override; void render(const Shader &) const override; }; diff --git a/game/network/network.impl.h b/game/network/network.impl.h index f4466b7..37d03f8 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -43,3 +43,10 @@ NetworkOf<T>::addStraight(glm::vec3 n1, glm::vec3 n2) { return addLink<typename T::StraightLink>(n1, n2); } + +template<typename T> +LinkPtr +NetworkOf<T>::addJoins(glm::vec3 n1, glm::vec3 n2) +{ + return addLink<typename T::StraightLink>(n1, n2); +} diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp new file mode 100644 index 0000000..90b1d61 --- /dev/null +++ b/ui/builders/join.cpp @@ -0,0 +1,43 @@ +#include "join.h" +#include <game/geoData.h> + +void +BuilderJoin::render(const Shader &) const +{ +} + +std::string +BuilderJoin::hint() const +{ + if (p1) { + return "Pick second node"; + } + return "Pick first node"; +} + +void +BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEvent & e, const Ray & ray) +{ + switch (e.button) { + case SDL_BUTTON_LEFT: + if (const auto p = network->intersectRayNodes(ray)) { + if (p1) { + create(network, p1, p); + p1.reset(); + } + else { + p1 = p; + } + } + return; + case SDL_BUTTON_MIDDLE: + p1.reset(); + return; + } +} + +void +BuilderJoin::create(Network * network, const NodePtr & p1, const NodePtr & p2) const +{ + network->addJoins(p1->pos, p2->pos); +} diff --git a/ui/builders/join.h b/ui/builders/join.h new file mode 100644 index 0000000..d4fb534 --- /dev/null +++ b/ui/builders/join.h @@ -0,0 +1,15 @@ +#pragma once +#include "../editNetwork.h" + +class Network; +class GeoData; + +class BuilderJoin : public EditNetwork::Builder { + void render(const Shader &) const override; + std::string hint() const override; + void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; + + void create(Network * network, const NodePtr & p1, const NodePtr & p2) const; + + NodePtr p1; +}; diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp index a51d7fb..3ab7059 100644 --- a/ui/editNetwork.cpp +++ b/ui/editNetwork.cpp @@ -1,4 +1,5 @@ #include "editNetwork.h" +#include "builders/join.h" #include "builders/straight.h" #include "text.h" #include <game/gamestate.h> @@ -7,6 +8,7 @@ EditNetwork::EditNetwork(Network * n) : network {n}, builderToolbar { {"ui/icon/network.png", mode.toggle<BuilderStraight>()}, + {"ui/icon/network.png", mode.toggle<BuilderJoin>()}, } { } @@ -16,7 +18,7 @@ EditNetwork::~EditNetwork() = default; bool EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray & ray) { - if (builder) { + if (builder && (e.button == SDL_BUTTON_LEFT || e.button == SDL_BUTTON_MIDDLE)) { builder->click(network, gameState->geoData.get(), e, ray); return true; } |