From 08a697c5690898a2a4f973aa8dac0d2e820392fe Mon Sep 17 00:00:00 2001 From: Fr0go1 <112802612+Fr0go1@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:08:45 +1000 Subject: [PATCH] Updated Ui and Added Esp preview thanks to @phillip --- CS2_External/Cheats.cpp | 258 ++++++++++++++++++++++++++---------- CS2_External/MenuConfig.hpp | 7 +- CS2_External/Render.hpp | 209 +++++++---------------------- 3 files changed, 246 insertions(+), 228 deletions(-) diff --git a/CS2_External/Cheats.cpp b/CS2_External/Cheats.cpp index 28ae8ad..a153fe2 100644 --- a/CS2_External/Cheats.cpp +++ b/CS2_External/Cheats.cpp @@ -39,7 +39,7 @@ void Cheats::Menu() ImGui::SetNextWindowSize(ImVec2(625, 645)); - ImGui::Begin("Aeonix",nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); + ImGui::Begin("Aeonix", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); { if (ImGui::BeginChild(1, ImVec2(115, 600), true)) { @@ -85,35 +85,38 @@ void Cheats::Menu() if (tabb == 0) { //esp - ImGui::Text("-Visuals-"); + ImGui::SeparatorText("Visuals"); ImGui::Checkbox("BoxESP", &MenuConfig::ShowBoxESP); - ImGui::SameLine(); - ImGui::ColorEdit4("##BoxColor", reinterpret_cast(&MenuConfig::BoxColor), ImGuiColorEditFlags_NoInputs); - ImGui::SameLine(); - - if (ImGui::Button("VisCheck (Box)")) - ImGui::OpenPopup("##boxvis"); - - if (ImGui::BeginPopup("##boxvis")) + if (ImGui::IsItemClicked(1)) { - ImGui::TextUnformatted("Box Settings"); + ImGui::OpenPopup("##boxvis"); + } + if (ImGui::BeginPopup("##boxvis")) { + ImGui::TextUnformatted("Settings"); ImGui::Checkbox("VisibleBoxESP", &MenuConfig::EspVisCheck); ImGui::SameLine(); ImGui::ColorEdit4("##BoxVisColor", reinterpret_cast(&MenuConfig::VisibleColor), ImGuiColorEditFlags_NoInputs); ImGui::EndPopup(); } - + ImGui::SameLine(); + ImGui::ColorEdit4("##BoxColor", reinterpret_cast(&MenuConfig::BoxColor), ImGuiColorEditFlags_NoInputs); + ImGui::SameLine(); + ImGui::SetNextItemWidth(110); ImGui::Combo("BoxType", &MenuConfig::BoxType, "Normal\0Dynamic"); - ImGui::Checkbox("BoneESP", &MenuConfig::ShowBoneESP); - ImGui::SameLine(); - ImGui::ColorEdit4("##BoneColor", reinterpret_cast(&MenuConfig::BoneColor), ImGuiColorEditFlags_NoInputs); + ImGui::Checkbox("HealthBar", &MenuConfig::ShowHealthBar); ImGui::SameLine(); + ImGui::SetNextItemWidth(120); + ImGui::Combo("HealthBarType", &MenuConfig::HealthBarType, "Vertical\0Top\0Bottom"); + - if (ImGui::Button("VisCheck (Bone)")) - ImGui::OpenPopup("##bonevis"); + ImGui::Checkbox("BoneESP", &MenuConfig::ShowBoneESP); + if (ImGui::IsItemClicked(1)) + { + ImGui::OpenPopup("##bonevis"); + } if (ImGui::BeginPopup("##bonevis")) { ImGui::TextUnformatted("Bone Settings"); @@ -122,31 +125,29 @@ void Cheats::Menu() ImGui::ColorEdit4("##BoneVisColor", reinterpret_cast(&MenuConfig::BoneVisColor), ImGuiColorEditFlags_NoInputs); ImGui::EndPopup(); } + ImGui::SameLine(); + ImGui::ColorEdit4("##BoneColor", reinterpret_cast(&MenuConfig::BoneColor), ImGuiColorEditFlags_NoInputs); ImGui::Checkbox("EyeRay", &MenuConfig::ShowEyeRay); ImGui::SameLine(); ImGui::ColorEdit4("##EyeRay", reinterpret_cast(&MenuConfig::EyeRayColor), ImGuiColorEditFlags_NoInputs); - ImGui::Checkbox("HealthBar", &MenuConfig::ShowHealthBar); - ImGui::Combo("HealthBarType", &MenuConfig::HealthBarType, "Vetical\0Horizontal"); + + ImGui::Checkbox("Distance Esp", &MenuConfig::ShowDistance); + ImGui::Checkbox("Health Text", &MenuConfig::HealthText); ImGui::Checkbox("WeaponText", &MenuConfig::ShowWeaponESP); ImGui::Checkbox("PlayerName", &MenuConfig::ShowPlayerName); - ImGui::Checkbox("HeadShootLine", &MenuConfig::ShowHeadShootLine); - ImGui::SameLine(); - ImGui::ColorEdit4("##HeadShootLineColor", reinterpret_cast(&MenuConfig::HeadShootLineColor), ImGuiColorEditFlags_NoInputs); - - ImGui::Checkbox("FovLine", &MenuConfig::ShowFovLine); - ImGui::SameLine(); - ImGui::ColorEdit4("##FovLineColor", reinterpret_cast(&MenuConfig::FovLineColor), ImGuiColorEditFlags_NoInputs); - float FovLineSizeMin = 20.f, FovLineSizeMax = 120.f; - Gui.SliderScalarEx1("FovLineSize", ImGuiDataType_Float, &MenuConfig::FovLineSize, &FovLineSizeMin, &FovLineSizeMax, "%.1f", ImGuiSliderFlags_None); - ImGui::Checkbox("LineToEnemy", &MenuConfig::ShowLineToEnemy); ImGui::SameLine(); ImGui::ColorEdit4("##LineToEnemyColor", reinterpret_cast(&MenuConfig::LineToEnemyColor), ImGuiColorEditFlags_NoInputs); + ImGui::Checkbox("ESPPreview", &MenuConfig::ESPPreview); + + + + ImGui::SeparatorText("Misc"); ImGui::Checkbox("CrossHair", &MenuConfig::ShowCrossHair); ImGui::SameLine(); ImGui::ColorEdit4("##CrossHairColor", reinterpret_cast(&CrosshairConfig::CrossHairColor), ImGuiColorEditFlags_NoInputs); @@ -165,10 +166,123 @@ void Cheats::Menu() ImGui::EndPopup(); } - ImGui::Checkbox("Distance Esp", &MenuConfig::ShowDistance); - ImGui::Checkbox("Health Text", &MenuConfig::HealthText); + ImGui::Checkbox("HeadShootLine", &MenuConfig::ShowHeadShootLine); + ImGui::SameLine(); + ImGui::ColorEdit4("##HeadShootLineColor", reinterpret_cast(&MenuConfig::HeadShootLineColor), ImGuiColorEditFlags_NoInputs); + + + ImGui::Checkbox("FovLine", &MenuConfig::ShowFovLine); + ImGui::SameLine(); + ImGui::ColorEdit4("##FovLineColor", reinterpret_cast(&MenuConfig::FovLineColor), ImGuiColorEditFlags_NoInputs); + float FovLineSizeMin = 20.f, FovLineSizeMax = 120.f; + Gui.SliderScalarEx1("FovLineSize", ImGuiDataType_Float, &MenuConfig::FovLineSize, &FovLineSizeMin, &FovLineSizeMax, "%.1f", ImGuiSliderFlags_None); + + ImGui::Text("[INSERT] HideMenu"); + + if (MenuConfig::ESPPreview) { + ImGui::SetNextWindowSize(ImVec2(200, 250), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowPos(ImVec2(ImGui::GetWindowPos().x + ImGui::GetWindowSize().x, ImGui::GetWindowPos().y), ImGuiCond_FirstUseEver); + ImGui::End(); + ImGui::Begin("ESPPreview", &MenuConfig::ESPPreview, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); + + ImVec2 windowSize = ImGui::GetWindowSize(); + ImVec2 rectSize(100, 150); + ImVec2 rectPos((windowSize.x - rectSize.x) * 0.45f, (windowSize.y - rectSize.y) * 0.3f); + + ImVec2 centerPos = ImGui::GetCursorScreenPos(); + centerPos.x += rectPos.x; + centerPos.y += rectPos.y; + + if (MenuConfig::ShowBoxESP) { + ImU32 boxColor = MenuConfig::BoxColor; + ImVec2 rectStartPos = centerPos; + ImVec2 rectEndPos(rectStartPos.x + rectSize.x, rectStartPos.y + rectSize.y); + ImGui::GetWindowDrawList()->AddRect(rectStartPos, rectEndPos, IM_COL32(0, 0, 0, 255), 0.0f, ImDrawCornerFlags_All, 2.0f);//outline + ImGui::GetWindowDrawList()->AddRect(rectStartPos, rectEndPos, boxColor, 0.0f, ImDrawCornerFlags_All, 1.0f); // mainrec + } + if (MenuConfig::ShowEyeRay) { + ImU32 EyeC = MenuConfig::EyeRayColor; + ImVec2 lineStart(centerPos.x + 50, centerPos.y + 15); + ImVec2 lineEnd(centerPos.x + 95, centerPos.y + 15); + ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, EyeC, 2.0f); + + } + if (MenuConfig::ShowBoneESP) { + ImU32 boneColor = MenuConfig::BoneColor; + ImVec2 lineStart(centerPos.x + 50, centerPos.y + 15); + ImVec2 lineEnd(centerPos.x + 50, centerPos.y + 110); + ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, boneColor, 2.0f); + ImVec2 Rarm(centerPos.x + 50, centerPos.y + 30); + ImVec2 Rarme(centerPos.x + 30, centerPos.y + 60); + ImGui::GetWindowDrawList()->AddLine(Rarm, Rarme, boneColor, 2.0f); + ImVec2 Larm(centerPos.x + 50, centerPos.y + 30); + ImVec2 Larme(centerPos.x + 70, centerPos.y + 60); + ImGui::GetWindowDrawList()->AddLine(Larm, Larme, boneColor, 2.0f); + ImVec2 Rleg(centerPos.x + 50, centerPos.y + 110); + ImVec2 Rlege(centerPos.x + 30, centerPos.y + 140); + ImGui::GetWindowDrawList()->AddLine(Rleg, Rlege, boneColor, 2.0f); + ImVec2 Lleg(centerPos.x + 50, centerPos.y + 110); + ImVec2 Llege(centerPos.x + 70, centerPos.y + 140); + ImGui::GetWindowDrawList()->AddLine(Lleg, Llege, boneColor, 2.0f); + } + + //Healthbar + if (MenuConfig::ShowHealthBar) { + ImU32 greenColor = IM_COL32(0, 255, 0, 255); + if (MenuConfig::HealthBarType == 0) { + ImVec2 HBS(centerPos.x - 8, centerPos.y); + ImVec2 HBE(centerPos.x - 3, centerPos.y + rectSize.y); + ImGui::GetWindowDrawList()->AddRectFilled(HBS, HBE, greenColor, 0.0f, ImDrawCornerFlags_All); + } + if (MenuConfig::HealthBarType == 1) { + ImVec2 HBS(centerPos.x, centerPos.y - 6); + ImVec2 HBE(centerPos.x + rectSize.x, centerPos.y - 3); + ImGui::GetWindowDrawList()->AddRectFilled(HBS, HBE, greenColor, 0.0f, ImDrawCornerFlags_All); + } + if (MenuConfig::HealthBarType == 2) { + ImVec2 HBS(centerPos.x, centerPos.y + rectSize.y + 6); + ImVec2 HBE(centerPos.x + rectSize.x, centerPos.y + rectSize.y + 3); + ImGui::GetWindowDrawList()->AddRectFilled(HBS, HBE, greenColor, 0.0f, ImDrawCornerFlags_All); + } + + } + + //name text + if (MenuConfig::ShowPlayerName) { + if (MenuConfig::HealthBarType == 0 || MenuConfig::HealthBarType == 2) { + ImVec2 textPos(centerPos.x + 18, centerPos.y - 18); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "PlayerName"); + } + if (MenuConfig::HealthBarType == 1) { + ImVec2 textPos(centerPos.x + 18, centerPos.y - 22); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "PlayerName"); + } + } + //distance text + if (MenuConfig::ShowDistance) { + ImVec2 textPos(centerPos.x + 105, centerPos.y); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "20m"); + } + if (MenuConfig::HealthText) { + ImVec2 textPos(centerPos.x + 105, centerPos.y + 16); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "100"); + } + + //weapon text + if (MenuConfig::ShowWeaponESP) { + if (MenuConfig::HealthBarType == 2) { + ImVec2 textPos(centerPos.x + 29, centerPos.y + 155); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "Weapon"); + } + if (MenuConfig::HealthBarType == 0 || MenuConfig::HealthBarType == 1) { + ImVec2 textPos(centerPos.x + 29, centerPos.y + 150); + ImGui::GetWindowDrawList()->AddText(textPos, IM_COL32(255, 255, 255, 255), "Weapon"); + } + } + ImGui::End(); + } } else if (tabb == 1) { //aimbot @@ -408,15 +522,6 @@ void Cheats::Run() if (!Entity.IsInScreen()) continue; - // Bone Debug - /* for (int BoneIndex = 0; BoneIndex < Entity.BoneData.BonePosList.size(); BoneIndex++) - { - Vec2 ScreenPos{}; - if (gGame.View.WorldToScreen(Entity.BoneData.BonePosList[BoneIndex].Pos, ScreenPos)) - { - Gui.Text(std::to_string(BoneIndex), ScreenPos, ImColor(255, 255, 255, 255)); - } - }*/ DistanceToSight = Entity.GetBone().BonePosList[BONEINDEX::head].ScreenPos.DistanceTo({ Gui.Window.Size.x / 2,Gui.Window.Size.y / 2 }); @@ -436,10 +541,10 @@ void Cheats::Run() } // Draw Bone - if (MenuConfig::ShowBoneESP) { - Render::DrawBone(Entity, MenuConfig::BoneColor, 1.3); - //visible bone esp + + if (MenuConfig::ShowBoneESP) { + Render::DrawBone(Entity, MenuConfig::BoneColor, 1); if (MenuConfig::VisibleEsp) { if ((Entity.Pawn.bSpottedByMask & (DWORD64(1) << LocalPlayerControllerIndex)) || (LocalEntity.Pawn.bSpottedByMask & (DWORD64(1) << i))) { @@ -449,14 +554,18 @@ void Cheats::Run() Render::DrawBone(Entity, MenuConfig::BoneColor, 1.3); } } - else if (!MenuConfig::VisibleCheck) { + else { Render::DrawBone(Entity, MenuConfig::BoneColor, 1.3); } } + + + + // Draw eyeRay if (MenuConfig::ShowEyeRay) - Render::ShowLosLine(Entity, 50, MenuConfig::EyeRayColor, 1.3); + Render::ShowLosLine(Entity, 50, MenuConfig::EyeRayColor, 1); // Box ImVec4 Rect; @@ -479,7 +588,6 @@ void Cheats::Run() // Draw Box if (MenuConfig::ShowBoxESP) { Gui.Rectangle({ Rect.x, Rect.y }, { Rect.z, Rect.w }, { 0, 0, 0, 255 }, 3); - //Box Vis Check if (MenuConfig::EspVisCheck) { if ((Entity.Pawn.bSpottedByMask & (DWORD64(1) << LocalPlayerControllerIndex)) || (LocalEntity.Pawn.bSpottedByMask & (DWORD64(1) << i))) { @@ -494,50 +602,59 @@ void Cheats::Run() } } - // Draw HealthBar if (MenuConfig::ShowHealthBar) { ImVec2 HealthBarPos, HealthBarSize; if (MenuConfig::HealthBarType == 0) { - // Vertical - HealthBarPos = { Rect.x - 7.f,Rect.y }; - HealthBarSize = { 4 ,Rect.w }; + HealthBarPos = { Rect.x - 7.f, Rect.y }; + HealthBarSize = { 4, Rect.w }; } - else + else if (MenuConfig::HealthBarType == 1) + { + HealthBarPos = { Rect.x, Rect.y - 6 }; + HealthBarSize = { Rect.z, 4 }; + } + else if (MenuConfig::HealthBarType == 2) { // Horizontal - HealthBarPos = { Rect.x + Rect.z / 2 - 70 / 2,Rect.y - 13 }; - HealthBarSize = { 70,4 }; + HealthBarPos = { Rect.x, Rect.y + Rect.w + 2 }; + HealthBarSize = { Rect.z, 4 }; } Render::DrawHealthBar(EntityAddress, 100, Entity.Pawn.Health, HealthBarPos, HealthBarSize, MenuConfig::HealthBarType); } + if (MenuConfig::ShowDistance) { int distance = static_cast(Entity.Pawn.Pos.DistanceTo(LocalEntity.Pawn.Pos) / 100); char buffer[0x48]; sprintf_s(buffer, "%im", distance); std::string dis_str = buffer; - Gui.StrokeText(dis_str, { Rect.x + Rect.z + 4, Rect.y }, ImColor(255, 255, 255, 255), 12, false); + Gui.StrokeText(dis_str, { Rect.x + Rect.z + 4, Rect.y }, ImColor(255, 255, 255, 255), 14, false); } if (MenuConfig::HealthText) { std::string yourString = std::to_string(Entity.Pawn.Health); - Gui.StrokeText(yourString, { Rect.x + Rect.z + 4, Rect.y + 10 }, ImColor(255, 255, 255, 255), 12, false); + Gui.StrokeText(yourString, { Rect.x + Rect.z + 4, Rect.y + 13 }, ImColor(255, 255, 255, 255), 14, false); } - // Draw weaponName - if (MenuConfig::ShowWeaponESP) - Gui.StrokeText(Entity.Pawn.WeaponName, { Rect.x,Rect.y + Rect.w }, ImColor(255, 255, 255, 255), 12); + if (MenuConfig::ShowWeaponESP) { + if (MenuConfig::HealthBarType == 0 || MenuConfig::HealthBarType == 1) + Gui.StrokeText(Entity.Pawn.WeaponName, { Rect.x + Rect.z / 2,Rect.y + Rect.w }, ImColor(255, 255, 255, 255), 14, true); + else if (MenuConfig::HealthBarType == 2) + Gui.StrokeText(Entity.Pawn.WeaponName, { Rect.x + Rect.z / 2,Rect.y + Rect.w + 5 }, ImColor(255, 255, 255, 255), 14, true); + } + + if (MenuConfig::ShowPlayerName) { - if (MenuConfig::HealthBarType == 0) - Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2,Rect.y - 14 }, ImColor(255, 255, 255, 255), 12, true); - else - Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2,Rect.y - 13 - 14 }, ImColor(255, 255, 255, 255), 12, true); + if (MenuConfig::HealthBarType == 0 || MenuConfig::HealthBarType == 2) + Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2, Rect.y - 14 }, ImColor(255, 255, 255, 255), 14, true); + else if (MenuConfig::HealthBarType == 1) + Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2, Rect.y - 20 }, ImColor(255, 255, 255, 255), 14, true); } } @@ -561,9 +678,7 @@ void Cheats::Run() RenderCrossHair(ImGui::GetBackgroundDrawList()); } - // Fov circle - if (MenuConfig::ShowAimFovRange) - Render::DrawFovCircle(LocalEntity); + // TriggerBot if (MenuConfig::TriggerBot && GetAsyncKeyState(TriggerBot::HotKey)) @@ -571,11 +686,18 @@ void Cheats::Run() TriggerBot::Run(LocalEntity); } - if (MenuConfig::AimBot && GetAsyncKeyState(AimControl::HotKey)) + if (MenuConfig::AimBot) { - if (AimPos != Vec3(0, 0, 0)) + if (MenuConfig::ShowAimFovRange) { + Render::DrawFovCircle(LocalEntity); + } + if (GetAsyncKeyState(AimControl::HotKey)) { - AimControl::AimBot(LocalEntity, LocalEntity.Pawn.CameraPos, AimPos); + + if (AimPos != Vec3(0, 0, 0)) + { + AimControl::AimBot(LocalEntity, LocalEntity.Pawn.CameraPos, AimPos); + } } } } diff --git a/CS2_External/MenuConfig.hpp b/CS2_External/MenuConfig.hpp index 94e2ba5..e11ca98 100644 --- a/CS2_External/MenuConfig.hpp +++ b/CS2_External/MenuConfig.hpp @@ -11,6 +11,7 @@ namespace MenuConfig inline bool ShowEyeRay = true; inline bool ShowPlayerName = true; inline bool SpectateEsp = false; + inline bool ESPPreview = false; inline bool ShowAimFovRange = true; inline ImColor AimFovRangeColor = ImColor(230, 230, 230, 255); @@ -31,6 +32,10 @@ namespace MenuConfig inline ImColor BoxColor = ImColor(255, 255, 255, 255); inline ImColor EyeRayColor = ImColor(255, 0, 0, 255); + + inline ImColor HealthbarMax = ImColor(0, 255, 0, 255); + inline ImColor HealthbarMin = ImColor(255, 0, 0, 255); + inline bool ShowMenu = true; inline bool VisibleEsp = true; inline bool ShowRadar = true; @@ -49,7 +54,7 @@ namespace MenuConfig inline bool OBSBypass = true; inline bool HealthText = true; - + inline bool ShowHeadShootLine = true; inline ImColor HeadShootLineColor = ImColor(255, 255, 255, 255); diff --git a/CS2_External/Render.hpp b/CS2_External/Render.hpp index 5896721..6c733b2 100644 --- a/CS2_External/Render.hpp +++ b/CS2_External/Render.hpp @@ -103,7 +103,6 @@ namespace Render Gui.RectangleFilled(Vec2{ Pos.x + 6, Pos.y }, Vec2{ 17, 3 }, Color); } - // ������� ImVec4 Get2DBox(const CEntity& Entity) { BoneJointPos Head = Entity.GetBone().BonePosList[BONEINDEX::head]; @@ -117,7 +116,6 @@ namespace Render return ImVec4{ Pos.x,Pos.y,Size.x,Size.y }; } - // �������� void DrawBone(const CEntity& Entity, ImColor Color, float Thickness) { BoneJointPos Previous, Current; @@ -143,7 +141,6 @@ namespace Render } } - // ������� void ShowLosLine(const CEntity& Entity, const float Length, ImColor Color, float Thickness) { Vec2 StartPoint, EndPoint; @@ -164,7 +161,6 @@ namespace Render Gui.Line(StartPoint, EndPoint, Color, Thickness); } - // 2D��������� ImVec4 Get2DBoneRect(const CEntity& Entity) { Vec2 Min, Max, Size; @@ -190,211 +186,107 @@ namespace Render private: using TimePoint_ = std::chrono::steady_clock::time_point; private: - // ��ʾ����Ѫ��ʱ��(ms) const int ShowBackUpHealthDuration = 500; - // ���Ѫ�� float MaxHealth = 0.f; - // ��ǰѪ�� float CurrentHealth = 0.f; - // �������Ѫ����С float LastestBackupHealth = 0.f; - // Ѫ������ ImVec2 RectPos{}; - // Ѫ����С ImVec2 RectSize{}; - // ������ʾ����Ѫ�� bool InShowBackupHealth = false; - // ��ʾ����Ѫ����ʼʱ��� TimePoint_ BackupHealthTimePoint{}; public: HealthBar() {} - // ���� void DrawHealthBar_Horizontal(float MaxHealth, float CurrentHealth, ImVec2 Pos, ImVec2 Size); - // ���� void DrawHealthBar_Vertical(float MaxHealth, float CurrentHealth, ImVec2 Pos, ImVec2 Size); private: - // ��ɫ���� ImColor Mix(ImColor Col_1, ImColor Col_2, float t); - // ��һ�׶�Ѫ����ɫ 0.5-1 - ImColor FirstStageColor = ImColor(96, 246, 113, 220); - // �ڶ��׶�Ѫ����ɫ 0.5-0.2 - ImColor SecondStageColor = ImColor(247, 214, 103, 220); - // �����׶�Ѫ����ɫ 0.2-0.0 - ImColor ThirdStageColor = ImColor(255, 95, 95, 220); - // ����Ѫ����ɫ + ImColor FirstStageColor = MenuConfig::HealthbarMax; + ImColor ThirdStageColor = MenuConfig::HealthbarMin; ImColor BackupHealthColor = ImColor(255, 255, 255, 220); - // �߿���ɫ - ImColor FrameColor = ImColor(45, 45, 45, 220); - // ������ɫ - ImColor BackGroundColor = ImColor(90, 90, 90, 220); + ImColor FrameColor = ImColor(20, 20, 20, 220); + ImColor BackGroundColor = ImColor(20, 20, 20, 220); }; + + void HealthBar::DrawHealthBar_Horizontal(float MaxHealth, float CurrentHealth, ImVec2 Pos, ImVec2 Size) { - auto InRange = [&](float value, float min, float max) -> bool - { - return value > min && value <= max; - }; - ImDrawList* DrawList = ImGui::GetBackgroundDrawList(); this->MaxHealth = MaxHealth; - this->CurrentHealth = CurrentHealth; this->RectPos = Pos; this->RectSize = Size; - // Calculate the proportion of health + float AnimationSpeed = 1.0f; float Proportion = CurrentHealth / MaxHealth; - // Calculate the width of the health bar - float Width = RectSize.x * Proportion; - // Determine the health bar color - ImColor Color; - - // Draw the background - DrawList->AddRectFilled(RectPos, - { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, - BackGroundColor); - - // Interpolate color - float Color_Lerp_t = pow(Proportion, 2.5); - if (InRange(Proportion, 0.5, 1)) - Color = Mix(FirstStageColor, SecondStageColor, Color_Lerp_t * 3 - 1); - else - Color = Mix(SecondStageColor, ThirdStageColor, Color_Lerp_t * 4); - // �����������Ѫ�� - if (LastestBackupHealth == 0 - || LastestBackupHealth < CurrentHealth) - LastestBackupHealth = CurrentHealth; + float BarWidth = Size.x * Proportion; + float BarHeight = Size.y; - if (LastestBackupHealth != CurrentHealth) + if (CurrentHealth > LastestBackupHealth) { - if (!InShowBackupHealth) - { - BackupHealthTimePoint = std::chrono::steady_clock::now(); - InShowBackupHealth = true; - } - - std::chrono::steady_clock::time_point CurrentTime = std::chrono::steady_clock::now(); - if (CurrentTime - BackupHealthTimePoint > std::chrono::milliseconds(ShowBackUpHealthDuration)) - { - // ��ʱ��ֹͣ��ʾ����Ѫ�������Ҹ����������Ѫ�� + LastestBackupHealth += AnimationSpeed; + if (LastestBackupHealth > CurrentHealth) LastestBackupHealth = CurrentHealth; - InShowBackupHealth = false; - } - - if (InShowBackupHealth) - { - // ����Ѫ�����ƿ��� - float BackupHealthWidth = LastestBackupHealth / MaxHealth * RectSize.x; - // ����Ѫ��alpha���� - float BackupHealthColorAlpha = 1 - 0.95 * (std::chrono::duration_cast(CurrentTime - BackupHealthTimePoint).count() / (float)ShowBackUpHealthDuration); - ImColor BackupHealthColorTemp = BackupHealthColor; - BackupHealthColorTemp.Value.w = BackupHealthColorAlpha; - // ����Ѫ�����Ȼ��� - float BackupHealthWidth_Lerp = 1 * (std::chrono::duration_cast(CurrentTime - BackupHealthTimePoint).count() / (float)ShowBackUpHealthDuration); - BackupHealthWidth_Lerp *= (BackupHealthWidth - Width); - BackupHealthWidth -= BackupHealthWidth_Lerp; - // ����Ѫ�� - DrawList->AddRectFilled(RectPos, - { RectPos.x + BackupHealthWidth,RectPos.y + RectSize.y }, - BackupHealthColorTemp, 5); - } } + else + { + LastestBackupHealth -= AnimationSpeed; + if (LastestBackupHealth < CurrentHealth) + LastestBackupHealth = CurrentHealth; + } + + ImColor Color = Mix(FirstStageColor, ThirdStageColor, Proportion); + + // Background Box + DrawList->AddRectFilled(RectPos, { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, BackGroundColor, 1); - // Draw the health bar with thinner lines - DrawList->AddRectFilled(RectPos, - { RectPos.x + Width, RectPos.y + RectSize.y }, - Color, 0.0f); // Set line thickness to 0 for a very thin bar + // Health Bar + ImVec2 BarStart = Pos; + ImVec2 BarEnd = { BarStart.x + BarWidth, BarStart.y + BarHeight }; + DrawList->AddRectFilled(BarStart, BarEnd, Color, 0); - // Draw the border with thinner lines - DrawList->AddRect(RectPos, - { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, - FrameColor, 0.2f); // Set line thickness to 0 for a very thin border + // Frame + DrawList->AddRect(RectPos, { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, FrameColor, 0, 3); } + void HealthBar::DrawHealthBar_Vertical(float MaxHealth, float CurrentHealth, ImVec2 Pos, ImVec2 Size) { - auto InRange = [&](float value, float min, float max) -> bool - { - return value > min && value <= max; - }; - ImDrawList* DrawList = ImGui::GetBackgroundDrawList(); this->MaxHealth = MaxHealth; - this->CurrentHealth = CurrentHealth; this->RectPos = Pos; this->RectSize = Size; - // Calculate the proportion of health + float AnimationSpeed = 1.0f; float Proportion = CurrentHealth / MaxHealth; - // Calculate the height of the health bar float Height = RectSize.y * Proportion; - // Determine the health bar color - ImColor Color; - - // Draw the background - DrawList->AddRectFilled(RectPos, - { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, - BackGroundColor); - - // Interpolate color - float Color_Lerp_t = pow(Proportion, 2.5); - if (InRange(Proportion, 0.5, 1)) - Color = Mix(FirstStageColor, SecondStageColor, Color_Lerp_t * 3 - 1); - else - Color = Mix(SecondStageColor, ThirdStageColor, Color_Lerp_t * 4); - - // �����������Ѫ�� - if (LastestBackupHealth == 0 - || LastestBackupHealth < CurrentHealth) - LastestBackupHealth = CurrentHealth; - if (LastestBackupHealth != CurrentHealth) + if (CurrentHealth > LastestBackupHealth) { - if (!InShowBackupHealth) - { - BackupHealthTimePoint = std::chrono::steady_clock::now(); - InShowBackupHealth = true; - } - - std::chrono::steady_clock::time_point CurrentTime = std::chrono::steady_clock::now(); - if (CurrentTime - BackupHealthTimePoint > std::chrono::milliseconds(ShowBackUpHealthDuration)) - { - // ��ʱ��ֹͣ��ʾ����Ѫ�������Ҹ����������Ѫ�� + LastestBackupHealth += AnimationSpeed; + if (LastestBackupHealth > CurrentHealth) LastestBackupHealth = CurrentHealth; - InShowBackupHealth = false; - } - - if (InShowBackupHealth) - { - // ����Ѫ�����Ƹ߶� - float BackupHealthHeight = LastestBackupHealth / MaxHealth * RectSize.y; - // ����Ѫ��alpha���� - float BackupHealthColorAlpha = 1 - 0.95 * (std::chrono::duration_cast(CurrentTime - BackupHealthTimePoint).count() / (float)ShowBackUpHealthDuration); - ImColor BackupHealthColorTemp = BackupHealthColor; - BackupHealthColorTemp.Value.w = BackupHealthColorAlpha; - // ����Ѫ���߶Ȼ��� - float BackupHealthHeight_Lerp = 1 * (std::chrono::duration_cast(CurrentTime - BackupHealthTimePoint).count() / (float)ShowBackUpHealthDuration); - BackupHealthHeight_Lerp *= (BackupHealthHeight - Height); - BackupHealthHeight -= BackupHealthHeight_Lerp; - // ����Ѫ�� - DrawList->AddRectFilled({ RectPos.x,RectPos.y + RectSize.y - BackupHealthHeight }, - { RectPos.x + RectSize.x,RectPos.y + RectSize.y }, - BackupHealthColorTemp, 5); - } } + else + { + LastestBackupHealth -= AnimationSpeed; + if (LastestBackupHealth < CurrentHealth) + LastestBackupHealth = CurrentHealth; + } + + ImColor Color = Mix(FirstStageColor, ThirdStageColor, Proportion); + + // Background + DrawList->AddRectFilled(RectPos, { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, BackGroundColor, 1); - // Draw the health bar with thinner lines - DrawList->AddRectFilled({ RectPos.x, RectPos.y + RectSize.y - Height }, - { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, - Color, 0.0f); + // Health bar + DrawList->AddRectFilled({ RectPos.x, RectPos.y + RectSize.y - LastestBackupHealth / MaxHealth * RectSize.y }, + { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, Color, 1, 0); - // Draw the border with thinner lines - DrawList->AddRect(RectPos, - { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, - FrameColor, 0.2f); + // Frame + DrawList->AddRect(RectPos, { RectPos.x + RectSize.x, RectPos.y + RectSize.y }, FrameColor, 0, 3); } ImColor HealthBar::Mix(ImColor Col_1, ImColor Col_2, float t) @@ -407,7 +299,6 @@ namespace Render return Col; } - // Sign�����κ����͵��˱�ʶ��Ĭ�Ͽɴ����˵�ַ void DrawHealthBar(DWORD Sign, float MaxHealth, float CurrentHealth, ImVec2 Pos, ImVec2 Size, bool Horizontal) { static std::map HealthBarMap;