summaryrefslogtreecommitdiff
path: root/ui/editNetwork.h
blob: 415553488f5742fc99955ceea1c7149a66c4578e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once

#include "game/geoData.h"
#include "gameMainSelector.h"
#include "worldOverlay.h"
#include <game/gamestate.h>
#include <game/network/network.h>
#include <gfx/models/texture.h>

template<typename> class Ray;

class EditNetwork : public GameMainSelector::Component, public WorldOverlay {
public:
	explicit EditNetwork(Network *);

	bool click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> &) override;
	bool move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> &) override;
	bool handleInput(const SDL_Event & e) override;
	void render(const SceneShader &, const Frustum &) const override;
	void render(bool & open) override;

	using NetworkClickPos = std::variant<GlobalPosition3D, Node::Ptr>;

	class Builder {
	public:
		virtual ~Builder() = default;
		virtual void render(const SceneShader & shader, const Frustum &) const;
		virtual std::string hint() const = 0;
		virtual void click(Network *, const GeoData *, const SDL_MouseButtonEvent &, const Ray<GlobalPosition3D> &) = 0;
		virtual void move(Network *, const GeoData *, const SDL_MouseMotionEvent &, const Ray<GlobalPosition3D> &) = 0;

		static void setHeightsFor(Network *, const Link::CCollection &, GeoData::SetHeightsOpts = {});

		using Ptr = std::unique_ptr<Builder>;

	protected:
		SharedCollection<const Link> candidateLinks;
	};

private:
	Network * network;
	Builder::Ptr builder;
	Texture blue;
};

template<typename T> class EditNetworkOf : public EditNetwork {
public:
	template<typename... P>
	explicit EditNetworkOf(P &&... p) : EditNetwork(gameState->world.findOrCreate<T>(), std::forward<P>(p)...)
	{
	}
};