From 727ae858a73f4c36bf253a873530dc4dd78c498f Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 20 Apr 2023 23:11:51 +0200 Subject: Moved most of popups-related stuff to one compilation unit --- kurator/CMakeLists.txt | 2 +- kurator/src/Battle.cpp | 35 ++--------------------- kurator/src/PopupEmitter.cpp | 38 ------------------------- kurator/src/PopupEmitter.h | 20 -------------- kurator/src/components.h | 12 -------- kurator/src/markers.cpp | 2 +- kurator/src/popups.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ kurator/src/popups.h | 37 +++++++++++++++++++++++++ 8 files changed, 108 insertions(+), 104 deletions(-) delete mode 100644 kurator/src/PopupEmitter.cpp delete mode 100644 kurator/src/PopupEmitter.h create mode 100644 kurator/src/popups.cpp create mode 100644 kurator/src/popups.h diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 04e0c19..8cf63dd 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -13,7 +13,7 @@ add_executable( src/markers.cpp src/Mouse.cpp src/Pause.cpp - src/PopupEmitter.cpp + src/popups.cpp src/projectiles.cpp src/ScenarioEditor.cpp src/SceneBuilder.cpp diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 1d0f872..5434eb2 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -22,7 +22,7 @@ #include "inspect.h" #include "markers.h" #include "Pause.h" -#include "PopupEmitter.h" +#include "popups.h" #include "projectiles.h" #include "Session.h" #include "Summary.h" @@ -78,7 +78,6 @@ time_controls(const char* id, float& time_factor) static void progress_timers(sim::State& ctx); -static void move_ui_pops(sim::State& ctx); static void blink_crosses(sim::State& ctx); @@ -94,7 +93,7 @@ Battle::update() simulation_base(ctx); update_markers(ctx, controller); progress_timers(ctx); - move_ui_pops(ctx); + animate_popups(ctx); blink_crosses(ctx); animate_projectiles(ctx); balance.update(ctx.registry); @@ -119,21 +118,6 @@ progress_timers(sim::State& ctx) void -move_ui_pops(sim::State& ctx) -{ - auto pops = ctx.registry.view(); - for (auto&& [entity, pop, offset] : pops.each()) { - const auto speed = pop.speed.scale(ctx.clock.ui); - offset.x += speed.x; - offset.y += speed.y; - const auto damp = pop.speed.scale(pop.damp).scale(ctx.clock.ui); - pop.speed.x -= damp.x; - pop.speed.y -= damp.y; - } -} - - -void blink_crosses(sim::State& ctx) { auto crosses = ctx.registry.view(); @@ -147,7 +131,6 @@ blink_crosses(sim::State& ctx) static void draw_crosses(const sim::State& ctx); -static void draw_pops(const sim::State& ctx); void @@ -160,7 +143,7 @@ Battle::draw() const draw_crosses(ctx); draw_projectiles(ctx); draw_markers(ctx); - draw_pops(ctx); + draw_popups(ctx); controller.draw(ctx); balance.draw(); } @@ -191,18 +174,6 @@ draw_crosses(const sim::State& ctx) void -draw_pops(const sim::State& ctx) -{ - auto pops = ctx.registry.view(); - for (const auto& [entity, text, transform, offset] : pops.each()) { - const auto screen = ctx.camera.to_screen(transform.position); - const auto pos = screen.subtract(text.width/2, text.font_size/2) + offset; - DrawText(text.text.c_str(), pos.x, pos.y, text.font_size, text.color); - } -} - - -void Battle::on_end(const sim::End&) { if (report) diff --git a/kurator/src/PopupEmitter.cpp b/kurator/src/PopupEmitter.cpp deleted file mode 100644 index 886bbfd..0000000 --- a/kurator/src/PopupEmitter.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "PopupEmitter.h" - -#include - -#include -#include - -#include -#include - -#include "components.h" - - -namespace kurator -{ - - -void -PopupEmitter::emit(entt::registry& registry, const sim::Transform& transform, const double damage) -{ - constexpr int size = 10; - if (!registry.valid(popup)) { - total = 0.0; - popup = registry.create(); - registry.emplace(popup, 1.2); - registry.emplace(popup, transform.position, 0.0); - registry.emplace(popup, std::string{}, 0, size, RED); - registry.emplace(popup, 0.0, 0.0); - registry.emplace(popup, engine::Point{0.0, -20.0}, 0.9998); - } - total += damage; - auto& text = registry.get(popup); - text.text = TextFormat("%.1f", total); - text.width = MeasureText(text.text.c_str(), size); -} - - -} // namespace kurator diff --git a/kurator/src/PopupEmitter.h b/kurator/src/PopupEmitter.h deleted file mode 100644 index 4b6228d..0000000 --- a/kurator/src/PopupEmitter.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include - - -namespace kurator -{ - - -struct PopupEmitter -{ - entt::entity popup = entt::null; - double total = 0.0; - void emit(entt::registry& registry, const sim::Transform& transform, double damage); -}; - - -} // namespace kurator diff --git a/kurator/src/components.h b/kurator/src/components.h index 51e91e3..7f42107 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -27,18 +27,6 @@ struct CenteredText }; -struct UIOffset : public engine::Point -{ -}; - - -struct PopMove -{ - engine::Point speed; - double damp; -}; - - struct Cross { double phase; diff --git a/kurator/src/markers.cpp b/kurator/src/markers.cpp index e46a751..d3fe01f 100644 --- a/kurator/src/markers.cpp +++ b/kurator/src/markers.cpp @@ -16,7 +16,7 @@ #include "colors.h" #include "Controller.h" -#include "PopupEmitter.h" +#include "popups.h" namespace kurator diff --git a/kurator/src/popups.cpp b/kurator/src/popups.cpp new file mode 100644 index 0000000..d14a982 --- /dev/null +++ b/kurator/src/popups.cpp @@ -0,0 +1,66 @@ +#include "popups.h" + +#include + +#include +#include + +#include +#include +#include + +#include "components.h" + + +namespace kurator +{ + + +void +PopupEmitter::emit(entt::registry& registry, const sim::Transform& transform, const double damage) +{ + constexpr int size = 10; + if (!registry.valid(popup)) { + total = 0.0; + popup = registry.create(); + registry.emplace(popup, 1.2); + registry.emplace(popup, transform.position, 0.0); + registry.emplace(popup, std::string{}, 0, size, RED); + registry.emplace(popup, 0.0, 0.0); + registry.emplace(popup, engine::Point{0.0, -20.0}, 0.9998); + } + total += damage; + auto& text = registry.get(popup); + text.text = TextFormat("%.1f", total); + text.width = MeasureText(text.text.c_str(), size); +} + + +void +animate_popups(sim::State& ctx) +{ + auto pops = ctx.registry.view(); + for (auto&& [entity, pop, offset] : pops.each()) { + const auto speed = pop.speed.scale(ctx.clock.ui); + offset.x += speed.x; + offset.y += speed.y; + const auto damp = pop.speed.scale(pop.damp).scale(ctx.clock.ui); + pop.speed.x -= damp.x; + pop.speed.y -= damp.y; + } +} + + +void +draw_popups(const sim::State& ctx) +{ + auto pops = ctx.registry.view(); + for (const auto& [entity, text, transform, offset] : pops.each()) { + const auto screen = ctx.camera.to_screen(transform.position); + const auto pos = screen.subtract(text.width/2, text.font_size/2) + offset; + DrawText(text.text.c_str(), pos.x, pos.y, text.font_size, text.color); + } +} + + +} // namespace kurator diff --git a/kurator/src/popups.h b/kurator/src/popups.h new file mode 100644 index 0000000..49f85d3 --- /dev/null +++ b/kurator/src/popups.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include +#include + + +namespace kurator +{ + + +struct PopupEmitter +{ + entt::entity popup = entt::null; + double total = 0.0; + void emit(entt::registry& registry, const sim::Transform& transform, double damage); +}; + + +struct PopMove +{ + engine::Point speed; + double damp; +}; + + +struct UIOffset : public engine::Point +{ +}; + + +void animate_popups(sim::State& ctx); +void draw_popups(const sim::State& ctx); + + +} // namespace kurator -- cgit v1.1