summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-18 23:09:13 +0100
committerAki <please@ignore.pl>2023-02-18 23:09:13 +0100
commit30452999b8afb37cb224661545570cd882880e95 (patch)
tree403674c415870eabd3aa879576ae1d5af45a58cd /kurator
parentc5a8295619d1b803380b244e4162ca359740e3c1 (diff)
downloadkurator-30452999b8afb37cb224661545570cd882880e95.zip
kurator-30452999b8afb37cb224661545570cd882880e95.tar.gz
kurator-30452999b8afb37cb224661545570cd882880e95.tar.bz2
Inspection tool will select ship turrets additionally when available
Diffstat (limited to 'kurator')
-rw-r--r--kurator/src/inspect.cpp39
-rw-r--r--kurator/src/inspect.h4
2 files changed, 34 insertions, 9 deletions
diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp
index 2adcb6e..4dff0a6 100644
--- a/kurator/src/inspect.cpp
+++ b/kurator/src/inspect.cpp
@@ -7,7 +7,9 @@
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/HitPoints.h>
+#include <kurator/sim/TurretControl.h>
#include <kurator/universe/ShipType.h>
+#include <kurator/universe/TurretType.h>
#include <kurator/universe/UniqueIdentifier.h>
@@ -36,15 +38,21 @@ InspectionWindow::show()
if (!open)
return;
if (ImGui::Begin("Inspect", &open)) {
- if (selected) {
- inspect<universe::UniqueIdentifier>(selected);
- inspect<universe::ShipType>(selected);
- inspect<sim::FloatingMovement>(selected);
- inspect<sim::HitPoints>(selected);
+ auto it = selected.begin();
+ while (it != selected.end()) {
+ if (!it->valid()) {
+ it = selected.erase(it);
+ continue;
+ }
+ inspect<universe::UniqueIdentifier>(*it);
+ inspect<universe::ShipType>(*it);
+ inspect<universe::TurretType>(*it);
+ inspect<sim::FloatingMovement>(*it);
+ inspect<sim::HitPoints>(*it);
+ it = std::next(it);
}
- else {
+ if (selected.empty())
ImGui::Text("Nothing selected");
- }
}
ImGui::End();
}
@@ -53,7 +61,14 @@ InspectionWindow::show()
void
InspectionWindow::select(entt::handle entity)
{
- selected = std::move(entity);
+ selected.clear();
+ auto* registry = entity.registry();
+ auto turrets = registry->view<sim::TurretControl>();
+ selected.push_back(std::move(entity));
+ for (auto&& [entity_, turret] : turrets.each()) {
+ if (turret.owner == entity)
+ selected.push_back(entt::handle{*registry, entity_});
+ }
open = true;
}
@@ -76,6 +91,14 @@ inspect(entt::handle&, universe::ShipType& type)
template <>
void
+inspect(entt::handle&, universe::TurretType& type)
+{
+ ImGui::Text("Type: %s", type.name.c_str());
+}
+
+
+template <>
+void
inspect(entt::handle&, sim::FloatingMovement& movement)
{
ImGui::Text("Speed: %.2f", movement.speed.magnitude());
diff --git a/kurator/src/inspect.h b/kurator/src/inspect.h
index a8b206f..77daa76 100644
--- a/kurator/src/inspect.h
+++ b/kurator/src/inspect.h
@@ -1,5 +1,7 @@
#pragma once
+#include <vector>
+
#include <entt/entt.hpp>
@@ -10,7 +12,7 @@ namespace kurator
struct InspectionWindow
{
bool open = false;
- entt::handle selected = {};
+ std::vector<entt::handle> selected = {};
void show();
void select(entt::handle entity);
};