summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-14 18:15:53 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-14 18:15:53 +0100
commit0d59b73de4e51a3a5b3c680f3dca97c2b942cc09 (patch)
treea4db615632e0d0ce7f4edb5cf57e60d39198bc87
parentNetwork candidate links (diff)
downloadilt-0d59b73de4e51a3a5b3c680f3dca97c2b942cc09.tar.bz2
ilt-0d59b73de4e51a3a5b3c680f3dca97c2b942cc09.tar.xz
ilt-0d59b73de4e51a3a5b3c680f3dca97c2b942cc09.zip
Builders manage a collection of candidate links rendered by the base builder
-rw-r--r--ui/builders/join.cpp19
-rw-r--r--ui/builders/join.h2
-rw-r--r--ui/builders/straight.cpp20
-rw-r--r--ui/builders/straight.h2
-rw-r--r--ui/editNetwork.cpp27
-rw-r--r--ui/editNetwork.h8
6 files changed, 60 insertions, 18 deletions
diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp
index cc2ca2d..caa635f 100644
--- a/ui/builders/join.cpp
+++ b/ui/builders/join.cpp
@@ -1,11 +1,6 @@
#include "join.h"
#include <game/geoData.h>
-void
-BuilderJoin::render(const Shader &) const
-{
-}
-
std::string
BuilderJoin::hint() const
{
@@ -16,6 +11,19 @@ BuilderJoin::hint() const
}
void
+BuilderJoin::move(Network * network, const GeoData *, const SDL_MouseMotionEvent &, const Ray & ray)
+{
+ if (p1) {
+ if (const auto p = network->intersectRayNodes(ray)) {
+ candidateLinks.objects = network->candidateJoins(p1->pos, p->pos);
+ }
+ else {
+ candidateLinks.removeAll();
+ }
+ }
+}
+
+void
BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEvent & e, const Ray & ray)
{
switch (e.button) {
@@ -24,6 +32,7 @@ BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEven
if (p1) {
create(network, p1, p);
p1.reset();
+ candidateLinks.removeAll();
}
else {
p1 = p;
diff --git a/ui/builders/join.h b/ui/builders/join.h
index 30d39cd..bb0bd4c 100644
--- a/ui/builders/join.h
+++ b/ui/builders/join.h
@@ -5,9 +5,9 @@ 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 move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override;
void create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const;
diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp
index 7024746..477b40d 100644
--- a/ui/builders/straight.cpp
+++ b/ui/builders/straight.cpp
@@ -1,11 +1,6 @@
#include "straight.h"
#include <game/geoData.h>
-void
-BuilderStraight::render(const Shader &) const
-{
-}
-
std::string
BuilderStraight::hint() const
{
@@ -16,6 +11,19 @@ BuilderStraight::hint() const
}
void
+BuilderStraight::move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent &, const Ray & ray)
+{
+ if (p1) {
+ if (const auto p = geoData->intersectRay(ray)) {
+ candidateLinks.objects = network->candidateStraight(*p1, *p);
+ }
+ else {
+ candidateLinks.removeAll();
+ }
+ }
+}
+
+void
BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray)
{
switch (e.button) {
@@ -23,12 +31,14 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou
if (const auto p = geoData->intersectRay(ray)) {
if (p1) {
create(network, *p1, *p);
+ candidateLinks.removeAll();
}
p1 = *p;
}
return;
case SDL_BUTTON_MIDDLE:
p1.reset();
+ candidateLinks.removeAll();
return;
}
}
diff --git a/ui/builders/straight.h b/ui/builders/straight.h
index 77847dd..1cde2b0 100644
--- a/ui/builders/straight.h
+++ b/ui/builders/straight.h
@@ -5,9 +5,9 @@ class Network;
class GeoData;
class BuilderStraight : 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 move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override;
void create(Network * network, glm::vec3 p1, glm::vec3 p2) const;
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp
index 3ab7059..9f4a186 100644
--- a/ui/editNetwork.cpp
+++ b/ui/editNetwork.cpp
@@ -4,12 +4,18 @@
#include "text.h"
#include <game/gamestate.h>
#include <game/geoData.h>
+#include <gfx/gl/shader.h>
+#include <gfx/models/texture.h>
+
+constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};
EditNetwork::EditNetwork(Network * n) :
- network {n}, builderToolbar {
- {"ui/icon/network.png", mode.toggle<BuilderStraight>()},
- {"ui/icon/network.png", mode.toggle<BuilderJoin>()},
- }
+ network {n},
+ builderToolbar {
+ {"ui/icon/network.png", mode.toggle<BuilderStraight>()},
+ {"ui/icon/network.png", mode.toggle<BuilderJoin>()},
+ },
+ blue {1, 1, &TRANSPARENT_BLUE}
{
}
@@ -26,8 +32,11 @@ EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray & ray)
}
bool
-EditNetwork::move(const SDL_MouseMotionEvent &, const Ray &)
+EditNetwork::move(const SDL_MouseMotionEvent & e, const Ray & ray)
{
+ if (builder) {
+ builder->move(network, gameState->geoData.get(), e, ray);
+ }
return false;
}
@@ -41,11 +50,19 @@ void
EditNetwork::render(const Shader & shader) const
{
if (builder) {
+ blue.Bind();
+ shader.setModel(Location {}, Shader::Program::StaticPos);
builder->render(shader);
}
}
void
+EditNetwork::Builder::render(const Shader & shader) const
+{
+ candidateLinks.apply<const Renderable>(&Renderable::render, shader);
+}
+
+void
EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const
{
if (builder) {
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index bd01eb8..df89cdc 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -6,6 +6,7 @@
#include "worldOverlay.h"
#include <game/gamestate.h>
#include <game/network/network.h>
+#include <gfx/models/texture.h>
#include <optional>
class Ray;
@@ -26,11 +27,15 @@ public:
class Builder {
public:
virtual ~Builder() = default;
- virtual void render(const Shader & shader) const = 0;
+ virtual void render(const Shader & shader) const;
virtual std::string hint() const = 0;
virtual void click(Network *, const GeoData *, const SDL_MouseButtonEvent &, const Ray &) = 0;
+ virtual void move(Network *, const GeoData *, const SDL_MouseMotionEvent &, const Ray &) = 0;
using Ptr = std::unique_ptr<Builder>;
+
+ protected:
+ Collection<const Link> candidateLinks;
};
private:
@@ -38,6 +43,7 @@ private:
Builder::Ptr builder;
Mode<Builder::Ptr, ModeSecondClick::NoAction> mode {builder};
Toolbar builderToolbar;
+ Texture blue;
};
template<typename T> class EditNetworkOf : public EditNetwork {