[Commands] Cleanup #timers Command. (#2562)

- Cleanup popup window and add a message for if there are no recast timers.
This commit is contained in:
Kinglykrab 2022-11-22 09:17:09 -05:00 committed by GitHub
parent 9f65159cb2
commit 8373dd1cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,40 +1,48 @@
#include "../client.h" #include "../client.h"
#include "../dialogue_window.h"
void command_timers(Client *c, const Seperator *sep) void command_timers(Client *c, const Seperator *sep)
{ {
auto target = c; auto t = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) { if (c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient(); t = c->GetTarget()->CastToClient();
} }
std::vector<std::pair<pTimerType, PersistentTimer *>> timers; std::vector<std::pair<pTimerType, PersistentTimer *>> l;
target->GetPTimers().ToVector(timers); t->GetPTimers().ToVector(l);
std::string popup_title = fmt::format( if (l.empty()) {
"Recast Timers for {}", c->Message(
c->GetTargetDescription(target, TargetDescriptionType::UCSelf) 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 = "<table>"; for (const auto& e : l) {
auto r = e.second->GetRemainingTime();
popup_text += "<tr><td>Timer ID</td><td>Remaining</td></tr>"; if (r) {
m += DialogueWindow::TableRow(
for (const auto& timer : timers) { DialogueWindow::TableCell(std::to_string(e.first)) +
auto remaining_time = timer.second->GetRemainingTime(); DialogueWindow::TableCell(Strings::SecondsToTime(r))
if (remaining_time) {
popup_text += fmt::format(
"<tr><td>{}</td><td>{}</td></tr>",
timer.first,
Strings::SecondsToTime(remaining_time)
); );
} }
} }
popup_text += "</table>";
c->SendPopupToClient( c->SendPopupToClient(
popup_title.c_str(), fmt::format(
popup_text.c_str() "Recast Timers for {}",
c->GetTargetDescription(t, TargetDescriptionType::UCSelf)
).c_str(),
DialogueWindow::Table(m).c_str()
); );
} }