summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-19 00:35:48 +0100
committerAki <please@ignore.pl>2023-02-19 00:35:48 +0100
commitf77c0c278f343422ce5c7a55ec5c126b3e190f77 (patch)
tree1cb43b56a05db5998035a3108e09a8caaa5a34fe /kurator
parent30452999b8afb37cb224661545570cd882880e95 (diff)
downloadkurator-f77c0c278f343422ce5c7a55ec5c126b3e190f77.zip
kurator-f77c0c278f343422ce5c7a55ec5c126b3e190f77.tar.gz
kurator-f77c0c278f343422ce5c7a55ec5c126b3e190f77.tar.bz2
Draw turret ranges for selected ships
Diffstat (limited to 'kurator')
-rw-r--r--kurator/src/Battle.cpp1
-rw-r--r--kurator/src/inspect.cpp58
-rw-r--r--kurator/src/inspect.h12
-rw-r--r--kurator/src/markers.cpp7
-rw-r--r--kurator/src/markers.h1
5 files changed, 74 insertions, 5 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 93a1444..b0719ea 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -161,6 +161,7 @@ Battle::draw() const
{
ClearBackground(BLACK);
Grid().draw(ctx.camera);
+ draw_turret_visuals(ctx);
draw_crosses(ctx);
draw_lines(ctx);
draw_markers(ctx);
diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp
index 4dff0a6..4795068 100644
--- a/kurator/src/inspect.cpp
+++ b/kurator/src/inspect.cpp
@@ -5,6 +5,7 @@
#include <entt/entt.hpp>
#include <imgui.h>
+#include <kurator/sim/components.h>
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/HitPoints.h>
#include <kurator/sim/TurretControl.h>
@@ -12,6 +13,8 @@
#include <kurator/universe/TurretType.h>
#include <kurator/universe/UniqueIdentifier.h>
+#include "markers.h"
+
namespace kurator
{
@@ -40,6 +43,7 @@ InspectionWindow::show()
if (ImGui::Begin("Inspect", &open)) {
auto it = selected.begin();
while (it != selected.end()) {
+ ImGui::PushID(it - selected.begin());
if (!it->valid()) {
it = selected.erase(it);
continue;
@@ -49,30 +53,52 @@ InspectionWindow::show()
inspect<universe::TurretType>(*it);
inspect<sim::FloatingMovement>(*it);
inspect<sim::HitPoints>(*it);
+ inspect<TurretVisuals>(*it);
it = std::next(it);
+ ImGui::PopID();
}
if (selected.empty())
ImGui::Text("Nothing selected");
}
ImGui::End();
+ if (!open)
+ deselect();
}
void
InspectionWindow::select(entt::handle entity)
{
- selected.clear();
+ deselect();
+ if (!entity)
+ return;
+ entity.get<Marker>().selected = true;
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)
+ if (turret.owner == entity) {
+ registry->emplace<TurretVisuals>(entity_);
selected.push_back(entt::handle{*registry, entity_});
+ }
}
open = true;
}
+void
+InspectionWindow::deselect()
+{
+ for (auto&& entity_ : selected) {
+ if (entity_.all_of<Marker>())
+ entity_.get<Marker>().selected = false;
+ if (entity_.all_of<TurretVisuals>())
+ entity_.remove<TurretVisuals>();
+ }
+ selected.clear();
+}
+
+
template <>
void
inspect(entt::handle&, universe::UniqueIdentifier& identifier)
@@ -117,4 +143,32 @@ inspect(entt::handle&, sim::HitPoints& points)
}
+template <>
+void
+inspect(entt::handle&, TurretVisuals& visuals)
+{
+ ImGui::Checkbox("Show Turret Ranges", &visuals.visible);
+}
+
+
+static Color OPTIMAL {0x88, 0x22, 0x22, 0xff};
+static Color EFFECTIVE {0x77, 0x50, 0x22, 0xff};
+
+void
+draw_turret_visuals(const sim::State& ctx)
+{
+ const auto helpers = ctx.registry.view<TurretVisuals, universe::TurretType, sim::TurretControl>();
+ for (const auto& [entity, visuals, type, turret] : helpers.each()) {
+ if (!visuals.visible)
+ continue;
+ const auto& transform = ctx.registry.get<sim::Transform>(turret.owner);
+ const auto center = ctx.camera.to_screen(transform.position);
+ const auto optimal = type.optimal_range * ctx.camera.scale;
+ const auto effective = type.effective_range() * ctx.camera.scale;
+ DrawCircleLines(center.x, center.y, optimal, OPTIMAL);
+ DrawCircleLines(center.x, center.y, effective, EFFECTIVE);
+ }
+}
+
+
} // namespace kurator
diff --git a/kurator/src/inspect.h b/kurator/src/inspect.h
index 77daa76..b123219 100644
--- a/kurator/src/inspect.h
+++ b/kurator/src/inspect.h
@@ -4,6 +4,8 @@
#include <entt/entt.hpp>
+#include <kurator/sim/State.h>
+
namespace kurator
{
@@ -15,7 +17,17 @@ struct InspectionWindow
std::vector<entt::handle> selected = {};
void show();
void select(entt::handle entity);
+ void deselect();
};
+struct TurretVisuals
+{
+ bool visible = true;
+};
+
+
+void draw_turret_visuals(const sim::State& ctx);
+
+
} // namespace kurator
diff --git a/kurator/src/markers.cpp b/kurator/src/markers.cpp
index 2b04129..f9e19b7 100644
--- a/kurator/src/markers.cpp
+++ b/kurator/src/markers.cpp
@@ -72,11 +72,12 @@ draw_markers(const sim::State& ctx)
}
const engine::Point direction {std::cos(transform.angle), std::sin(transform.angle)};
const auto edge = pos + direction.scale(marker.radius);
- if (marker.hovered)
- DrawCircle(pos.x, pos.y, marker.radius + 2, WHITE);
+ if (marker.hovered || marker.selected)
+ DrawCircle(pos.x, pos.y, marker.radius + 2, marker.selected ? YELLOW : WHITE);
DrawCircle(pos.x, pos.y, marker.radius, marker.color);
DrawLine(pos.x, pos.y, edge.x, edge.y, WHITE);
- DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, marker.hovered ? WHITE : GRAY);
+ const auto colour = marker.selected ? YELLOW : marker.hovered ? WHITE : GRAY;
+ DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, colour);
}
}
diff --git a/kurator/src/markers.h b/kurator/src/markers.h
index a702b2e..c2fdd8b 100644
--- a/kurator/src/markers.h
+++ b/kurator/src/markers.h
@@ -21,6 +21,7 @@ struct Marker
Color color;
std::string name;
bool hovered = false;
+ bool selected = false;
};