From 083ebbbff9894991b06dcd971f01baccaa83366d Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 2 Apr 2024 06:33:03 -0700 Subject: [PATCH] HUD tracking: polish bubble trap button prompt --- src/k_hud_track.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/k_hud_track.cpp b/src/k_hud_track.cpp index 55ca6260f..4c37a78ce 100644 --- a/src/k_hud_track.cpp +++ b/src/k_hud_track.cpp @@ -1,9 +1,12 @@ #include +#include #include #include +#include #include #include "core/static_vec.hpp" +#include "cxxutil.hpp" #include "v_draw.hpp" #include "g_game.h" @@ -66,7 +69,8 @@ struct TargetTracking struct Tooltip { - Tooltip(srb2::Draw::TextElement&& text_) : text(text_) {} + Tooltip(srb2::Draw::TextElement&& text_) : var(text_) {} + Tooltip(std::function&& fn) : var(fn) {} Tooltip& offset3d(fixed_t x, fixed_t y, fixed_t z) { @@ -76,7 +80,7 @@ struct TargetTracking return *this; } - srb2::Draw::TextElement text; + std::variant> var; vector3_t ofs = {}; }; @@ -403,7 +407,18 @@ std::optional object_tooltip(const mobj_t* mobj) case MT_BUBBLESHIELDTRAP: return conditional( mobj->tracer == stplyr->mo, - [&] { return TextElement(((leveltime / 3) % 2) ? "\xB3 " : " \xB2").font(Draw::Font::kMenu); } + [&] + { + return [](const Draw& box) + { + bool left = (leveltime / 3) % 2; + box + .x(12 * (left ? -1 : 1)) + .font(Draw::Font::kMenu) + .align(left ? Draw::Align::kRight : Draw::Align::kLeft) + .text(left ? "\xB3" : "\xB2"); + }; + } ); case MT_GARDENTOP: @@ -461,9 +476,14 @@ void K_DrawTargetTracking(const TargetTracking& target) return; } - srb2::Draw(FixedToFloat(result.x), FixedToFloat(result.y)) - .align(srb2::Draw::Align::kCenter) - .text(target.tooltip->text); + using srb2::Draw; + Draw box = Draw(FixedToFloat(result.x), FixedToFloat(result.y)).align(Draw::Align::kCenter); + auto visitor = srb2::Overload { + [&](const srb2::Draw::TextElement& text) { box.text(text); }, + [&](const std::function& fn) { fn(box); }, + }; + std::visit(visitor, target.tooltip->var); + return; } @@ -818,15 +838,19 @@ void K_drawTargetHUD(const vector3_t* origin, player_t* player) if (tooltip) { - tooltip->text.flags(tooltip->text.flags().value_or(0) | V_SPLITSCREEN); - tr.tooltip = tooltip; + if (auto* text = std::get_if(&tooltip->var)) + { + text->flags(text->flags().value_or(0) | V_SPLITSCREEN); + } const vector3_t copy = pos; FV3_Add(&pos, &tooltip->ofs); K_ObjectTracking(&tr.result, &pos, false); pos = copy; + tr.tooltip = tooltip; targetList.push_back(tr); + tr.tooltip = {}; } if (!mobj->player)