20constexpr Color kHit = {255, 255, 255, 255};
21constexpr Color kHurt = {235, 70, 60, 255};
22constexpr Color kHeal = {90, 220, 90, 255};
23constexpr Color kLevel = {255, 205, 60, 255};
37 Popup popup{.unit =
event.player(),
38 .scale =
event.player() == you ? 1.0f : kTheirs};
39 switch (event.kind()) {
40 case protocol::EVENT_HIT:
41 popup.
text = std::to_string(event.amount());
42 popup.
unit =
event.monster();
46 case protocol::EVENT_HURT:
47 popup.
text =
"-" + std::to_string(event.amount());
50 case protocol::EVENT_HEAL:
51 popup.
text =
"+" + std::to_string(event.amount());
54 case protocol::EVENT_LEVEL:
55 popup.
text = absl::Substitute(
Tr(
"Level $0"), event.amount());
57 popup.
scale *= kLevelScale;
63 popups_.push_back(std::move(popup));
74 const Camera3D& camera) {
75 ImDrawList* draw = ImGui::GetBackgroundDrawList();
76 ImFont* font = ImGui::GetFont();
77 const Vector3 forward =
78 Vector3Normalize(Vector3Subtract(camera.target, camera.position));
81 std::ranges::find_if(figures, [&popup](
const Figure& figure) {
82 return figure.
id == popup.unit && figure.
monster == popup.monster &&
85 if (figure == figures.end()) {
94 if (Vector3DotProduct(Vector3Subtract(over, camera.position), forward) <=
98 const Vector2 at = GetWorldToScreen(over, camera);
100 const float alpha = std::clamp(2.0f * (1.0f - share), 0.0f, 1.0f);
101 const float size = ImGui::GetFontSize() * 2.4f * popup.scale;
102 const ImVec2 extent =
103 font->CalcTextSizeA(size, FLT_MAX, 0.0f, popup.text.c_str());
104 const ImVec2 corner{at.x - extent.x / 2, at.y - extent.y};
105 draw->AddText(font, size, {corner.x + 2, corner.y + 2},
106 IM_COL32(0, 0, 0,
static_cast<int>(200 * alpha)),
108 draw->AddText(font, size, corner,
109 IM_COL32(popup.color.r, popup.color.g, popup.color.b,
110 static_cast<int>(255 * alpha)),
const std::vector< Popup > & popups() const
static constexpr float kLife
In seconds.
void Add(const protocol::Event &event, uint32_t you)
Adds what the event shows, to the player whose id is you.
void Update(float seconds)
Ages each by the frame's time, and drops the ones past their life.
void DrawCombatText(const CombatText &text, const std::vector< Figure > &figures, const Camera3D &camera)
Draws each over the figure it's about, rising and fading as it ages.