From 320b3d8252786c0b831414824643c41bed80bfd7 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 17 Feb 2023 00:58:41 +0100 Subject: Ships markers can now be selected to show inspection window --- kurator/CMakeLists.txt | 1 + kurator/src/Battle.cpp | 5 ++++- kurator/src/Battle.h | 2 ++ kurator/src/inspect.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ kurator/src/inspect.h | 19 +++++++++++++++++++ kurator/src/markers.cpp | 6 +++++- kurator/src/markers.h | 4 +++- 7 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 kurator/src/inspect.cpp create mode 100644 kurator/src/inspect.h 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 +#include #include #include #include @@ -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 #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 + +#include +#include + +#include + + +namespace kurator +{ + + +void +InspectionWindow::show() +{ + if (!open) + return; + if (ImGui::Begin("Inspect", &open)) { + if (selected) { + const auto& identifier = selected.get(); + 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 + + +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 +#include #include #include #include +#include #include #include @@ -36,7 +38,7 @@ attach_markers(sim::State& ctx) void -update_markers(sim::State& ctx) +update_markers(sim::State& ctx, std::function select) { engine::Point mouse {static_cast(GetMouseX()), static_cast(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(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 #include +#include #include #include @@ -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 select); void draw_markers(const sim::State& ctx); -- cgit v1.1