summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kurator/src/Battle.cpp1
-rw-r--r--kurator/src/markers.cpp33
-rw-r--r--kurator/src/markers.h4
3 files changed, 33 insertions, 5 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 68879c6..0918e30 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -95,6 +95,7 @@ Battle::update()
ctx.camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0);
ctx.clock.update();
simulation_base(ctx);
+ update_markers(ctx);
progress_timers(ctx);
move_ui_pops(ctx);
blink_crosses(ctx);
diff --git a/kurator/src/markers.cpp b/kurator/src/markers.cpp
index a4ed417..436bd33 100644
--- a/kurator/src/markers.cpp
+++ b/kurator/src/markers.cpp
@@ -4,6 +4,7 @@
#include <string>
#include <utility>
+#include <entt/entity/entity.hpp>
#include <raylib.h>
#include <kurator/engine/Point.h>
@@ -24,21 +25,41 @@ namespace kurator
void
attach_markers(sim::State& ctx)
{
- auto ships = ctx.registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier>();
- for (const auto& [entity, team, type, identifier] : ships.each()) {
+ auto ships = ctx.registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier, sim::Transform>();
+ for (const auto& [entity, team, type, identifier, transform] : ships.each()) {
+ auto pos = ctx.camera.to_screen(transform.position);
std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id);
- ctx.registry.emplace<Marker>(entity, 5.0, team_color(team.id), std::move(label));
+ ctx.registry.emplace<Marker>(entity, std::move(pos), 5.0, team_color(team.id), std::move(label));
ctx.registry.emplace<PopupEmitter>(entity);
}
}
void
+update_markers(sim::State& ctx)
+{
+ engine::Point mouse {static_cast<double>(GetMouseX()), static_cast<double>(GetMouseY())};
+ entt::entity hover {entt::null};
+ auto markers = ctx.registry.view<Marker, sim::Transform>();
+ for (auto&& [entity, marker, transform] : markers.each()) {
+ marker.screen = ctx.camera.to_screen(transform.position);
+ marker.hovered = false;
+ if (mouse.distance(marker.screen) <= marker.radius)
+ hover = entity;
+ }
+ if (ctx.registry.valid(hover)) {
+ auto& marker = ctx.registry.get<Marker>(hover);
+ marker.hovered = true;
+ }
+}
+
+
+void
draw_markers(const sim::State& ctx)
{
auto view = ctx.registry.view<Marker, sim::Transform>();
for (const auto& [entity, marker, transform] : view.each()) {
- const auto pos = ctx.camera.to_screen(transform.position);
+ const auto& pos = marker.screen;
if (ctx.registry.all_of<sim::FloatingMovement>(entity)) {
const auto& movement = ctx.registry.get<sim::FloatingMovement>(entity);
const auto& velocity = movement.speed;
@@ -48,9 +69,11 @@ 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);
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, GRAY);
+ DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, marker.hovered ? WHITE : GRAY);
}
}
diff --git a/kurator/src/markers.h b/kurator/src/markers.h
index c6522cf..f390ff6 100644
--- a/kurator/src/markers.h
+++ b/kurator/src/markers.h
@@ -4,6 +4,7 @@
#include <raylib.h>
+#include <kurator/engine/Point.h>
#include <kurator/sim/State.h>
@@ -13,13 +14,16 @@ namespace kurator
struct Marker
{
+ engine::Point screen;
double radius;
Color color;
std::string name;
+ bool hovered = false;
};
void attach_markers(sim::State& ctx);
+void update_markers(sim::State& ctx);
void draw_markers(const sim::State& ctx);