summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-29 02:06:52 +0100
committerAki <please@ignore.pl>2023-01-29 02:06:52 +0100
commitdd997209468bde60f57089960f46067a375890ca (patch)
tree568f7a1b10d09d0d8fa40e45ea52be7d274b0146 /kurator
parente3fbcfc085411475cb07da84308f03dbd3405e5e (diff)
downloadkurator-dd997209468bde60f57089960f46067a375890ca.zip
kurator-dd997209468bde60f57089960f46067a375890ca.tar.gz
kurator-dd997209468bde60f57089960f46067a375890ca.tar.bz2
Damage popups will now merge when possible
Diffstat (limited to 'kurator')
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp11
-rw-r--r--kurator/src/PopupEmitter.cpp38
-rw-r--r--kurator/src/PopupEmitter.h20
4 files changed, 63 insertions, 7 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index e2e4821..5b49bfb 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -8,6 +8,7 @@ add_executable(
src/ForceBalance.cpp
src/main.cpp
src/Pause.cpp
+ src/PopupEmitter.cpp
src/ScenarioEditor.cpp
src/SceneBuilder.cpp
src/SceneFrame.cpp
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index d7232ff..8073585 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -22,6 +22,7 @@
#include "colors.h"
#include "components.h"
#include "Pause.h"
+#include "PopupEmitter.h"
#include "Session.h"
#include "Summary.h"
@@ -51,6 +52,7 @@ Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario, B
for (const auto& [entity, team, type, identifier] : ships.each()) {
std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id);
registry.emplace<Marker>(entity, 5.0, team_color(team.id), std::move(label));
+ registry.emplace<PopupEmitter>(entity);
}
}
@@ -195,15 +197,10 @@ Battle::on_hit(const sim::Hit& hit)
auto& registry = battle->registry();
if (!registry.valid(hit.victim))
return;
- const std::string text = TextFormat("%.1f", hit.damage);
const auto& source = registry.get<sim::Transform>(hit.source);
const auto& victim = registry.get<sim::Transform>(hit.victim);
- const auto popup = registry.create();
- registry.emplace<Timed>(popup, 1.2);
- registry.emplace<CenteredText>(popup, text, MeasureText(text.c_str(), 10), 10, RED);
- registry.emplace<sim::Transform>(popup, victim.position, 0.0);
- registry.emplace<UIOffset>(popup, 0, 0);
- registry.emplace<PopMove>(popup, sim::Point{0.0, -20}, 0.9998);
+ auto& popup = registry.get<PopupEmitter>(hit.victim);
+ popup.emit(registry, victim, hit.damage);
const auto line = registry.create();
registry.emplace<Timed>(line, 0.2, true);
registry.emplace<Line>(
diff --git a/kurator/src/PopupEmitter.cpp b/kurator/src/PopupEmitter.cpp
new file mode 100644
index 0000000..c382ef1
--- /dev/null
+++ b/kurator/src/PopupEmitter.cpp
@@ -0,0 +1,38 @@
+#include "PopupEmitter.h"
+
+#include <string>
+
+#include <entt/entity/registry.hpp>
+#include <raylib.h>
+
+#include <kurator/sim/components.h>
+#include <kurator/sim/Point.h>
+
+#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<Timed>(popup, 1.2);
+ registry.emplace<sim::Transform>(popup, transform.position, 0.0);
+ registry.emplace<CenteredText>(popup, std::string{}, 0, size, RED);
+ registry.emplace<UIOffset>(popup, 0, 0);
+ registry.emplace<PopMove>(popup, sim::Point{0, -20}, 0.9998);
+ }
+ total += damage;
+ auto& text = registry.get<CenteredText>(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
new file mode 100644
index 0000000..0d90427
--- /dev/null
+++ b/kurator/src/PopupEmitter.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <entt/entity/registry.hpp>
+
+#include <kurator/sim/components.h>
+
+
+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