diff options
-rw-r--r-- | kurator/CMakeLists.txt | 2 | ||||
-rw-r--r-- | kurator/src/Battle.cpp | 35 | ||||
-rw-r--r-- | kurator/src/components.h | 12 | ||||
-rw-r--r-- | kurator/src/markers.cpp | 2 | ||||
-rw-r--r-- | kurator/src/popups.cpp (renamed from kurator/src/PopupEmitter.cpp) | 30 | ||||
-rw-r--r-- | kurator/src/popups.h (renamed from kurator/src/PopupEmitter.h) | 17 |
6 files changed, 51 insertions, 47 deletions
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<PopMove, UIOffset>(); - 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<Cross>(); @@ -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<CenteredText, sim::Transform, UIOffset>(); - 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/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/PopupEmitter.cpp b/kurator/src/popups.cpp index 886bbfd..d14a982 100644 --- a/kurator/src/PopupEmitter.cpp +++ b/kurator/src/popups.cpp @@ -1,4 +1,4 @@ -#include "PopupEmitter.h" +#include "popups.h" #include <string> @@ -7,6 +7,7 @@ #include <kurator/engine/Point.h> #include <kurator/sim/components.h> +#include <kurator/sim/State.h> #include "components.h" @@ -35,4 +36,31 @@ PopupEmitter::emit(entt::registry& registry, const sim::Transform& transform, co } +void +animate_popups(sim::State& ctx) +{ + auto pops = ctx.registry.view<PopMove, UIOffset>(); + 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<CenteredText, sim::Transform, UIOffset>(); + 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/PopupEmitter.h b/kurator/src/popups.h index 4b6228d..49f85d3 100644 --- a/kurator/src/PopupEmitter.h +++ b/kurator/src/popups.h @@ -3,6 +3,7 @@ #include <entt/entt.hpp> #include <kurator/sim/components.h> +#include <kurator/sim/State.h> namespace kurator @@ -17,4 +18,20 @@ struct PopupEmitter }; +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 |