add mob send cooldown

This commit is contained in:
2023-01-02 14:32:37 +01:00
parent 0b6d826eba
commit ed45995645
2 changed files with 21 additions and 3 deletions

View File

@@ -12,11 +12,15 @@ class SummonMenu : public GuiWidget {
private: private:
bool m_MenuOpened; bool m_MenuOpened;
int m_ImageWidth = 100; int m_ImageWidth = 100;
float m_Cooldown;
float m_LastCooldown;
static constexpr int m_MobTypeCount = static_cast<std::size_t>(td::game::MobType::MOB_COUNT); static constexpr int m_MobTypeCount = static_cast<std::size_t>(td::game::MobType::MOB_COUNT);
std::array<int, static_cast<std::size_t>(m_MobTypeCount)> m_Values; std::array<int, static_cast<std::size_t>(m_MobTypeCount)> m_Values;
public: public:
SummonMenu(client::Client* client); SummonMenu(client::Client* client);
void SetCooldown(float cooldown);
virtual void Render(); virtual void Render();
private: private:
void SetSummonMax(int valueIndex); void SetSummonMax(int valueIndex);

View File

@@ -7,9 +7,18 @@ namespace gui {
SummonMenu::SummonMenu(client::Client* client) : GuiWidget(client), m_MenuOpened(true) { SummonMenu::SummonMenu(client::Client* client) : GuiWidget(client), m_MenuOpened(true) {
m_Values.fill(0); m_Values.fill(0);
SetCooldown(10);
}
void SummonMenu::SetCooldown(float cooldown) {
m_LastCooldown = cooldown;
m_Cooldown = cooldown;
} }
void SummonMenu::Render() { void SummonMenu::Render() {
if (m_Cooldown > 0)
m_Cooldown = std::max(0.0f, m_Cooldown - ImGui::GetIO().DeltaTime);
if (m_MenuOpened) { if (m_MenuOpened) {
ImGui::Begin("Summon", &m_MenuOpened); ImGui::Begin("Summon", &m_MenuOpened);
ImTextureID my_tex_id = ImGui::GetIO().Fonts->TexID; ImTextureID my_tex_id = ImGui::GetIO().Fonts->TexID;
@@ -48,7 +57,9 @@ void SummonMenu::Render() {
ImGui::PopID(); ImGui::PopID();
} }
ImGui::PopItemWidth(); 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<protocol::MobSend> mobSent; std::vector<protocol::MobSend> mobSent;
protocol::MobSend mobSend; protocol::MobSend mobSend;
for (int i = 0; i < m_MobTypeCount; i++) { for (int i = 0; i < m_MobTypeCount; i++) {
@@ -59,8 +70,11 @@ void SummonMenu::Render() {
mobSent.push_back(mobSend); mobSent.push_back(mobSend);
} }
} }
if (mobSent.size() > 0) {
m_Client->SendMobs(mobSent); m_Client->SendMobs(mobSent);
m_Values.fill(0); m_Values.fill(0);
SetCooldown(10);
}
} }
ImGui::End(); ImGui::End();
} }