summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-17 00:58:41 +0100
committerAki <please@ignore.pl>2023-02-17 00:58:41 +0100
commit320b3d8252786c0b831414824643c41bed80bfd7 (patch)
tree38776a24df0af8d572d908fddeb62fc7ebb7bbae /kurator
parent69e4074e471bc7e2dcf285fb253bc70d0c8ffbf5 (diff)
downloadkurator-320b3d8252786c0b831414824643c41bed80bfd7.zip
kurator-320b3d8252786c0b831414824643c41bed80bfd7.tar.gz
kurator-320b3d8252786c0b831414824643c41bed80bfd7.tar.bz2
Ships markers can now be selected to show inspection window
Diffstat (limited to 'kurator')
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp5
-rw-r--r--kurator/src/Battle.h2
-rw-r--r--kurator/src/inspect.cpp41
-rw-r--r--kurator/src/inspect.h19
-rw-r--r--kurator/src/markers.cpp6
-rw-r--r--kurator/src/markers.h4
7 files changed, 75 insertions, 3 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index 82f0a3f..b97a8b5 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -7,6 +7,7 @@ add_executable(
src/colors.cpp
src/ForceBalance.cpp
src/Grid.cpp
+ src/inspect.cpp
src/lines.cpp
src/main.cpp
src/markers.cpp
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 9df0b01..93a1444 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -1,6 +1,7 @@
#include "Battle.h"
#include <algorithm>
+#include <functional>
#include <cmath>
#include <limits>
#include <memory>
@@ -19,6 +20,7 @@
#include "components.h"
#include "Grid.h"
+#include "inspect.h"
#include "lines.h"
#include "markers.h"
#include "Pause.h"
@@ -95,7 +97,7 @@ Battle::update()
ctx.camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0);
ctx.clock.update();
simulation_base(ctx);
- update_markers(ctx);
+ update_markers(ctx, std::bind(&InspectionWindow::select, &inspect, std::placeholders::_1));
progress_timers(ctx);
move_ui_pops(ctx);
blink_crosses(ctx);
@@ -106,6 +108,7 @@ Battle::update()
if (ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoFocusOnAppearing))
time_controls("TimeControls", ctx.clock.time_factor);
ImGui::End();
+ inspect.show();
}
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index f6ec8d6..0de492a 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -11,6 +11,7 @@
#include <kurator/stats/events.h>
#include "ForceBalance.h"
+#include "inspect.h"
#include "Scene.h"
#include "Session.h"
@@ -39,6 +40,7 @@ private:
ForceBalance balance;
stats::EventLog log;
Callback report;
+ InspectionWindow inspect;
};
diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp
new file mode 100644
index 0000000..9622fd7
--- /dev/null
+++ b/kurator/src/inspect.cpp
@@ -0,0 +1,41 @@
+#include "inspect.h"
+
+#include <utility>
+
+#include <entt/entity/handle.hpp>
+#include <imgui.h>
+
+#include <kurator/universe/UniqueIdentifier.h>
+
+
+namespace kurator
+{
+
+
+void
+InspectionWindow::show()
+{
+ if (!open)
+ return;
+ if (ImGui::Begin("Inspect", &open)) {
+ if (selected) {
+ const auto& identifier = selected.get<universe::UniqueIdentifier>();
+ ImGui::Text("Selected: %d", identifier.id);
+ }
+ else {
+ ImGui::Text("Nothing selected");
+ }
+ }
+ ImGui::End();
+}
+
+
+void
+InspectionWindow::select(entt::handle entity)
+{
+ selected = std::move(entity);
+ open = true;
+}
+
+
+} // namespace kurator
diff --git a/kurator/src/inspect.h b/kurator/src/inspect.h
new file mode 100644
index 0000000..c48ee5e
--- /dev/null
+++ b/kurator/src/inspect.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <entt/entity/handle.hpp>
+
+
+namespace kurator
+{
+
+
+struct InspectionWindow
+{
+ bool open = false;
+ entt::handle selected = {};
+ void show();
+ void select(entt::handle entity);
+};
+
+
+} // namespace kurator
diff --git a/kurator/src/markers.cpp b/kurator/src/markers.cpp
index 436bd33..b92f7d3 100644
--- a/kurator/src/markers.cpp
+++ b/kurator/src/markers.cpp
@@ -1,10 +1,12 @@
#include "markers.h"
#include <cmath>
+#include <functional>
#include <string>
#include <utility>
#include <entt/entity/entity.hpp>
+#include <entt/entity/handle.hpp>
#include <raylib.h>
#include <kurator/engine/Point.h>
@@ -36,7 +38,7 @@ attach_markers(sim::State& ctx)
void
-update_markers(sim::State& ctx)
+update_markers(sim::State& ctx, std::function<void(entt::handle)> select)
{
engine::Point mouse {static_cast<double>(GetMouseX()), static_cast<double>(GetMouseY())};
entt::entity hover {entt::null};
@@ -50,6 +52,8 @@ update_markers(sim::State& ctx)
if (ctx.registry.valid(hover)) {
auto& marker = ctx.registry.get<Marker>(hover);
marker.hovered = true;
+ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && select)
+ select(entt::handle{ctx.registry, hover});
}
}
diff --git a/kurator/src/markers.h b/kurator/src/markers.h
index f390ff6..600adc1 100644
--- a/kurator/src/markers.h
+++ b/kurator/src/markers.h
@@ -1,7 +1,9 @@
#pragma once
+#include <functional>
#include <string>
+#include <entt/entity/handle.hpp>
#include <raylib.h>
#include <kurator/engine/Point.h>
@@ -23,7 +25,7 @@ struct Marker
void attach_markers(sim::State& ctx);
-void update_markers(sim::State& ctx);
+void update_markers(sim::State& ctx, std::function<void(entt::handle)> select);
void draw_markers(const sim::State& ctx);