From 8373dd1cb9ad1cf18c11e9baf3796a61bc28cfaf Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:17:09 -0500 Subject: [PATCH] [Commands] Cleanup #timers Command. (#2562) - Cleanup popup window and add a message for if there are no recast timers. --- zone/gm_commands/timers.cpp | 54 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/zone/gm_commands/timers.cpp b/zone/gm_commands/timers.cpp index daeef1d20..efee6da55 100755 --- a/zone/gm_commands/timers.cpp +++ b/zone/gm_commands/timers.cpp @@ -1,40 +1,48 @@ #include "../client.h" +#include "../dialogue_window.h" void command_timers(Client *c, const Seperator *sep) { - auto target = c; + auto t = c; if (c->GetTarget() && c->GetTarget()->IsClient()) { - target = c->GetTarget()->CastToClient(); + t = c->GetTarget()->CastToClient(); } - std::vector> timers; - target->GetPTimers().ToVector(timers); + std::vector> l; + t->GetPTimers().ToVector(l); - std::string popup_title = fmt::format( - "Recast Timers for {}", - c->GetTargetDescription(target, TargetDescriptionType::UCSelf) + if (l.empty()) { + c->Message( + Chat::White, + fmt::format( + "{} {} no recast timers.", + c->GetTargetDescription(t, TargetDescriptionType::UCYou), + c == t ? "have" : "has" + ).c_str() + ); + return; + } + + auto m = DialogueWindow::TableRow( + DialogueWindow::TableCell("Timer ID") + + DialogueWindow::TableCell("Remaining Time") ); - std::string popup_text = ""; - - popup_text += ""; - - for (const auto& timer : timers) { - auto remaining_time = timer.second->GetRemainingTime(); - if (remaining_time) { - popup_text += fmt::format( - "", - timer.first, - Strings::SecondsToTime(remaining_time) + for (const auto& e : l) { + auto r = e.second->GetRemainingTime(); + if (r) { + m += DialogueWindow::TableRow( + DialogueWindow::TableCell(std::to_string(e.first)) + + DialogueWindow::TableCell(Strings::SecondsToTime(r)) ); } } - popup_text += "
Timer IDRemaining
{}{}
"; - c->SendPopupToClient( - popup_title.c_str(), - popup_text.c_str() + fmt::format( + "Recast Timers for {}", + c->GetTargetDescription(t, TargetDescriptionType::UCSelf) + ).c_str(), + DialogueWindow::Table(m).c_str() ); } -