summaryrefslogtreecommitdiff
path: root/ui/builders/freeExtend.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-15 15:30:44 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-15 15:30:44 +0100
commitd11d99323d642ebb1cf84302b2b25019e95b5607 (patch)
tree8a2171c2929929b3d3195b6f0de25041998fc8c8 /ui/builders/freeExtend.cpp
parentRemove unnecessary destructor (diff)
downloadilt-d11d99323d642ebb1cf84302b2b25019e95b5607.tar.bz2
ilt-d11d99323d642ebb1cf84302b2b25019e95b5607.tar.xz
ilt-d11d99323d642ebb1cf84302b2b25019e95b5607.zip
Add free extend builder with placeholder network support
Diffstat (limited to 'ui/builders/freeExtend.cpp')
-rw-r--r--ui/builders/freeExtend.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/ui/builders/freeExtend.cpp b/ui/builders/freeExtend.cpp
new file mode 100644
index 0000000..1520421
--- /dev/null
+++ b/ui/builders/freeExtend.cpp
@@ -0,0 +1,57 @@
+#include "freeExtend.h"
+#include <game/geoData.h>
+
+std::string
+BuilderFreeExtend::hint() const
+{
+ if (p1) {
+ return "Pick next point";
+ }
+ return "Pick start node";
+}
+
+void
+BuilderFreeExtend::move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent &, const Ray & ray)
+{
+ if (p1) {
+ if (const auto p = network->intersectRayNodes(ray)) {
+ candidateLinks.objects = network->candidateJoins(*p1, p->pos);
+ }
+ else if (const auto p = geoData->intersectRay(ray)) {
+ candidateLinks.objects = network->candidateExtend(*p1, *p);
+ }
+ else {
+ candidateLinks.removeAll();
+ }
+ }
+ else {
+ candidateLinks.removeAll();
+ }
+}
+
+void
+BuilderFreeExtend::click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray)
+{
+ switch (e.button) {
+ case SDL_BUTTON_LEFT:
+ if (p1) {
+ if (const auto p = network->intersectRayNodes(ray)) {
+ network->addJoins(*p1, p->pos);
+ p1 = p->pos;
+ }
+ else if (const auto p = geoData->intersectRay(ray)) {
+ network->addExtend(*p1, *p);
+ p1 = *p;
+ }
+ }
+ else {
+ if (const auto p = network->intersectRayNodes(ray)) {
+ p1 = p->pos;
+ }
+ }
+ return;
+ case SDL_BUTTON_MIDDLE:
+ p1.reset();
+ return;
+ }
+}