summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-19 01:44:18 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-19 02:30:30 +0000
commit1f14089d0d6adbd1072b022dfaeb17a1975e8b38 (patch)
tree8d0065a94c8467ebe5860c3d9f05bafa1b2445e0
parentReplace basic rail builder UI with a ImGui version (diff)
downloadilt-1f14089d0d6adbd1072b022dfaeb17a1975e8b38.tar.bz2
ilt-1f14089d0d6adbd1072b022dfaeb17a1975e8b38.tar.xz
ilt-1f14089d0d6adbd1072b022dfaeb17a1975e8b38.zip
Replace basic query tool with a ImGui version
-rw-r--r--ui/gameMainSelector.cpp22
-rw-r--r--ui/gameMainSelector.h2
-rw-r--r--ui/gameMainWindow.cpp4
-rw-r--r--ui/queryTool.cpp39
-rw-r--r--ui/queryTool.h14
5 files changed, 58 insertions, 23 deletions
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index d5cbf62..55977ed 100644
--- a/ui/gameMainSelector.cpp
+++ b/ui/gameMainSelector.cpp
@@ -1,5 +1,4 @@
#include "gameMainSelector.h"
-#include "collection.h"
#include "text.h"
#include "ui/uiComponent.h"
#include <SDL2/SDL.h>
@@ -8,9 +7,7 @@
#include <game/terrain.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/camera.h>
-#include <optional>
#include <stream_support.h>
-#include <typeinfo>
const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
@@ -27,9 +24,6 @@ GameMainSelector::render(const UIShader & shader, const Position & parentPos) co
if (target) {
target->render(shader, parentPos + position + TargetPos);
}
- if (!clicked.empty()) {
- Text {clicked, font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
- }
}
void
@@ -73,22 +67,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
}
void
-GameMainSelector::defaultClick(const Ray<GlobalPosition3D> & ray)
+GameMainSelector::defaultClick(const Ray<GlobalPosition3D> &)
{
- BaryPosition baryPos {};
- RelativeDistance distance {};
-
- if (const auto selected = gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, baryPos, distance);
- selected != gameState->world.end()) {
- const auto & ref = *selected.base()->get();
- clicked = typeid(ref).name();
- }
- else if (const auto pos = gameState->terrain->intersectRay(ray)) {
- clicked = streamed_string(*pos);
- }
- else {
- clicked.clear();
- }
}
bool
diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h
index 16f70eb..df29842 100644
--- a/ui/gameMainSelector.h
+++ b/ui/gameMainSelector.h
@@ -7,7 +7,6 @@
#include "worldOverlay.h"
#include <glm/glm.hpp>
#include <memory>
-#include <string>
class SceneShader;
template<typename> class Ray;
@@ -41,5 +40,4 @@ public:
private:
const Camera * camera;
const Font font;
- std::string clicked;
};
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index c1e135b..356d522 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -3,6 +3,7 @@
#include "gameMainSelector.h"
#include "imgui_extras.h"
#include "manualCameraController.h"
+#include "queryTool.h"
#include <SDL2/SDL.h>
#include <collection.h>
#include <game/environment.h>
@@ -29,6 +30,9 @@ public:
if (ImGui::ImageButton("Build rails", *buildRailsIcon, TOOLBAR_ICON_SIZE)) {
gms->target = std::make_unique<EditNetworkOf<RailLinks>>();
}
+ if (ImGui::ImageButton("Query", *buildRailsIcon, TOOLBAR_ICON_SIZE)) {
+ gms->target = std::make_unique<QueryTool>();
+ }
IltGui::EndToolbar();
}
}
diff --git a/ui/queryTool.cpp b/ui/queryTool.cpp
new file mode 100644
index 0000000..e48bae1
--- /dev/null
+++ b/ui/queryTool.cpp
@@ -0,0 +1,39 @@
+#include "queryTool.h"
+#include "imgui_wrap.h"
+#include <game/gamestate.h>
+#include <game/selectable.h>
+#include <game/terrain.h>
+#include <game/worldobject.h>
+#include <ray.h>
+#include <stream_support.h>
+
+bool
+QueryTool::click(const SDL_MouseButtonEvent & event, const Ray<GlobalPosition3D> & ray)
+{
+ if (event.button != SDL_BUTTON_LEFT) {
+ return false;
+ }
+ BaryPosition baryPos {};
+ RelativeDistance distance {};
+
+ if (const auto selected = gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, baryPos, distance);
+ selected != gameState->world.end()) {
+ const auto & ref = *selected.base()->get();
+ clicked = typeid(ref).name();
+ }
+ else if (const auto pos = gameState->terrain->intersectRay(ray)) {
+ clicked = streamed_string(*pos);
+ }
+ else {
+ clicked.clear();
+ }
+ return true;
+}
+
+void
+QueryTool::render(const UIShader &, const UIComponent::Position &)
+{
+ ImGui::Begin("Query Tool");
+ ImGui::TextUnformatted(clicked.c_str());
+ ImGui::End();
+}
diff --git a/ui/queryTool.h b/ui/queryTool.h
new file mode 100644
index 0000000..8462214
--- /dev/null
+++ b/ui/queryTool.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "gameMainSelector.h"
+
+class QueryTool : public GameMainSelector::Component {
+protected:
+ using GameMainSelector::Component::render;
+
+ bool click(const SDL_MouseButtonEvent &, const Ray<GlobalPosition3D> &) override;
+ void render(const UIShader & shader, const UIComponent::Position & pos) override;
+
+private:
+ std::string clicked;
+};