add mob send cooldown
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user