#include "markers.h" #include #include #include #include #include #include #include #include #include #include #include #include "colors.h" #include "PopupEmitter.h" namespace kurator { void attach_markers(sim::State& ctx) { auto ships = ctx.registry.view(); 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(entity, std::move(pos), 5.0, team_color(team.id), std::move(label)); ctx.registry.emplace(entity); } } void update_markers(sim::State& ctx) { engine::Point mouse {static_cast(GetMouseX()), static_cast(GetMouseY())}; entt::entity hover {entt::null}; auto markers = ctx.registry.view(); 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(hover); marker.hovered = true; } } void draw_markers(const sim::State& ctx) { auto view = ctx.registry.view(); for (const auto& [entity, marker, transform] : view.each()) { const auto& pos = marker.screen; if (ctx.registry.all_of(entity)) { const auto& movement = ctx.registry.get(entity); const auto& velocity = movement.speed; const auto edge = pos + velocity.normalized().scale(marker.radius); const auto tip = edge + velocity.scale(2.0 * ctx.camera.scale); DrawLine(edge.x, edge.y, tip.x, tip.y, DARKGREEN); } 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, marker.hovered ? WHITE : GRAY); } } } // namespace kurator