feat: add summon menu

This commit is contained in:
2021-11-04 10:03:37 +01:00
parent f2f79781db
commit 129544d127
15 changed files with 307 additions and 51 deletions

View File

@@ -0,0 +1,82 @@
#include "render/gui/SummonMenu.h"
#include "game/client/Client.h"
#include "render/gui/imgui/imgui.h"
namespace td {
namespace gui {
SummonMenu::SummonMenu(client::Client* client) : GuiWidget(client), m_MenuOpened(true){
m_Values.fill(0);
}
void SummonMenu::render(){
if (m_MenuOpened) {
ImGui::Begin("Summon", &m_MenuOpened);
ImTextureID my_tex_id = ImGui::GetIO().Fonts->TexID;
for (int i = 0; i < m_MobTypeCount / 2; i++) {
ImGui::SameLine();
ImGui::PushID(i);
ImGui::Image(my_tex_id, ImVec2(100, 100));
ImGui::PopID();
}
ImGui::Separator();
ImGui::PushItemWidth(m_ImageWidth);
for (int i = 0; i < m_MobTypeCount / 2; i++) {
ImGui::SameLine();
ImGui::PushID(i);
if (ImGui::InputInt("", m_Values.data() + i, 1, 10)) {
setSummonMax(i);
}
ImGui::PopID();
}
ImGui::PopItemWidth();
ImGui::Separator();
for (int i = m_MobTypeCount / 2; i < m_MobTypeCount; i++) {
ImGui::SameLine();
ImGui::PushID(i);
ImGui::Image(my_tex_id, ImVec2(100, 100));
ImGui::PopID();
}
ImGui::Separator();
ImGui::PushItemWidth(m_ImageWidth);
for (int i = m_MobTypeCount / 2; i < m_MobTypeCount; i++) {
ImGui::SameLine();
ImGui::PushID(i);
if (ImGui::InputInt("", m_Values.data() + i, 1, m_MobTypeCount)) {
setSummonMax(i);
}
ImGui::PopID();
}
ImGui::PopItemWidth();
if (ImGui::Button("Send")) {
std::vector<protocol::MobSend> mobSent;
protocol::MobSend mobSend;
for(int i = 0; i < m_MobTypeCount; i++){
if(m_Values[i] != 0){
mobSend.mobCount = m_Values[i];
mobSend.mobLevel = 1; // TODO: add mob levels
mobSend.mobType = td::game::MobType(i);
mobSent.push_back(mobSend);
}
}
m_Client->sendMobs(mobSent);
m_Values.fill(0);
}
ImGui::End();
}
}
void SummonMenu::setSummonMax(int valueIndex){
int& value = m_Values[valueIndex];
value = std::max(0, value);
value = std::min(12, value);
int total = 0;
for (std::size_t i = 0; i < m_Values.size(); i++) {
total += m_Values[i];
}
if (total == 13) // if the total is greater than the maximum, we substract the value
value--;
}
} // namespace gui
} // namespace td