summaryrefslogtreecommitdiff
path: root/ui/editNetwork.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-08 17:04:40 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-08 17:04:40 +0100
commitf6890e8077133b5dd2cc0a92270d2a328d6c5ab9 (patch)
treee24cf13bf3e5d90409ed46a86f87668718e48fcf /ui/editNetwork.h
parentAdd collection methods for finding and/or creating objects (diff)
downloadilt-f6890e8077133b5dd2cc0a92270d2a328d6c5ab9.tar.bz2
ilt-f6890e8077133b5dd2cc0a92270d2a328d6c5ab9.tar.xz
ilt-f6890e8077133b5dd2cc0a92270d2a328d6c5ab9.zip
Initial commit of a basic working network editor
Diffstat (limited to 'ui/editNetwork.h')
-rw-r--r--ui/editNetwork.h45
1 files changed, 41 insertions, 4 deletions
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index 0a27609..72e0955 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -1,12 +1,49 @@
#pragma once
#include "gameMainSelector.h"
+#include "modeHelper.hpp"
+#include "toolbar.h"
+#include "worldOverlay.h"
+#include <game/gamestate.h>
+#include <game/network/network.h>
+#include <optional>
class Ray;
-class EditNetwork : public GameMainSelector::ClickReceiver {
+class EditNetwork : public GameMainSelector::Component, public WorldOverlay {
public:
- void click(const Ray &) override;
- void move(const Ray &) override;
- bool handleMove() override;
+ explicit EditNetwork(Network *);
+ virtual ~EditNetwork();
+
+ bool click(const SDL_MouseButtonEvent & e, const Ray &) override;
+ bool move(const SDL_MouseMotionEvent & e, const Ray &) override;
+ bool handleInput(const SDL_Event & e, const UIComponent::Position &) override;
+ void render(const Shader &) const override;
+ void render(const UIShader & shader, const UIComponent::Position & pos) const override;
+
+ using NetworkClickPos = std::variant<glm::vec3, NodePtr>;
+
+ class Builder {
+ public:
+ virtual ~Builder() = default;
+ virtual void render(const Shader & shader) const = 0;
+ virtual std::string hint() const = 0;
+ virtual void click(Network *, const GeoData *, const SDL_MouseButtonEvent &, const Ray &) = 0;
+ };
+
+private:
+ using BuilderPtr = std::unique_ptr<Builder>;
+
+ Network * network;
+ BuilderPtr builder;
+ Mode<BuilderPtr, ModeSecondClick::NoAction> mode {builder};
+ Toolbar builderToolbar;
+};
+
+template<typename T> class EditNetworkOf : public EditNetwork {
+public:
+ template<typename... P>
+ EditNetworkOf(P &&... p) : EditNetwork(gameState->world.findOrCreate<T>(), std::forward<P>(p)...)
+ {
+ }
};