From ed45995645952766c3323bdb7e5d658e652c9e46 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 2 Jan 2023 14:32:37 +0100 Subject: [PATCH] add mob send cooldown --- include/render/gui/SummonMenu.h | 4 ++++ src/render/gui/SummonMenu.cpp | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/render/gui/SummonMenu.h b/include/render/gui/SummonMenu.h index 7053f4a..f13fbe0 100644 --- a/include/render/gui/SummonMenu.h +++ b/include/render/gui/SummonMenu.h @@ -12,11 +12,15 @@ class SummonMenu : public GuiWidget { private: bool m_MenuOpened; int m_ImageWidth = 100; + float m_Cooldown; + float m_LastCooldown; static constexpr int m_MobTypeCount = static_cast(td::game::MobType::MOB_COUNT); std::array(m_MobTypeCount)> m_Values; public: SummonMenu(client::Client* client); + void SetCooldown(float cooldown); + virtual void Render(); private: void SetSummonMax(int valueIndex); diff --git a/src/render/gui/SummonMenu.cpp b/src/render/gui/SummonMenu.cpp index 193de05..ac6195d 100644 --- a/src/render/gui/SummonMenu.cpp +++ b/src/render/gui/SummonMenu.cpp @@ -7,9 +7,18 @@ namespace gui { SummonMenu::SummonMenu(client::Client* client) : GuiWidget(client), m_MenuOpened(true) { m_Values.fill(0); + SetCooldown(10); +} + +void SummonMenu::SetCooldown(float cooldown) { + m_LastCooldown = cooldown; + m_Cooldown = cooldown; } void SummonMenu::Render() { + if (m_Cooldown > 0) + m_Cooldown = std::max(0.0f, m_Cooldown - ImGui::GetIO().DeltaTime); + if (m_MenuOpened) { ImGui::Begin("Summon", &m_MenuOpened); ImTextureID my_tex_id = ImGui::GetIO().Fonts->TexID; @@ -48,7 +57,9 @@ void SummonMenu::Render() { ImGui::PopID(); } ImGui::PopItemWidth(); - if (ImGui::Button("Send")) { + if (m_Cooldown > 0) { + ImGui::ProgressBar((m_LastCooldown - m_Cooldown) / m_LastCooldown, {}, std::string{ std::to_string((int)m_Cooldown + 1) + "s" }.c_str()); + } else if (ImGui::Button("Send")) { std::vector mobSent; protocol::MobSend mobSend; for (int i = 0; i < m_MobTypeCount; i++) { @@ -59,8 +70,11 @@ void SummonMenu::Render() { mobSent.push_back(mobSend); } } - m_Client->SendMobs(mobSent); - m_Values.fill(0); + if (mobSent.size() > 0) { + m_Client->SendMobs(mobSent); + m_Values.fill(0); + SetCooldown(10); + } } ImGui::End(); }