From c1f72087b39d0acea60d02f73f340995fa2dd62d Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Tue, 23 Apr 2024 13:41:08 -0600 Subject: [PATCH] New healthbar working --- include/diablo2/d2gfx.h | 2 ++ include/diablo2/d2win.h | 2 ++ .../damage_display/damage_display_client.cpp | 21 ++++++++++++------- src/diablo2/d2gfx.cpp | 6 ++++++ src/diablo2/d2win.cpp | 2 ++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/diablo2/d2gfx.h b/include/diablo2/d2gfx.h index c4df129..9d17f7b 100644 --- a/include/diablo2/d2gfx.h +++ b/include/diablo2/d2gfx.h @@ -17,5 +17,7 @@ namespace diablo2 { static int32_t adjust_perspective_coords(int32_t x, int32_t y, int32_t* adjustX, int32_t* adjustY); static int32_t get_resolution_mode(); static void draw_image(structures::gfxdata* data, uint32_t x, uint32_t y, int32_t gamma, int32_t drawType, void* palette); + static void draw_filled_rect(int left, int top, int right, int bottom, ULONG color, ULONG transTbl); + }; } \ No newline at end of file diff --git a/include/diablo2/d2win.h b/include/diablo2/d2win.h index f9196b7..6f3b62f 100644 --- a/include/diablo2/d2win.h +++ b/include/diablo2/d2win.h @@ -48,6 +48,8 @@ namespace diablo2 { static int32_t get_text_pixel_width(wchar_t* str); static void draw_text(wchar_t* str, uint32_t x, uint32_t y, ui_color_t color, int32_t transTbl); static void draw_boxed_text(wchar_t* str, uint32_t x, uint32_t y, int32_t paletteIndex, int32_t transTbl, ui_color_t color); + + static void set_popup_properties(wchar_t* str, uint32_t x, uint32_t y, ui_color_t color, int32_t align); static void draw_popup(); diff --git a/src/d2tweaks/client/modules/damage_display/damage_display_client.cpp b/src/d2tweaks/client/modules/damage_display/damage_display_client.cpp index b7f2101..287ccf0 100644 --- a/src/d2tweaks/client/modules/damage_display/damage_display_client.cpp +++ b/src/d2tweaks/client/modules/damage_display/damage_display_client.cpp @@ -9,7 +9,7 @@ #include #include #include - +#include #include #include @@ -231,7 +231,7 @@ static void draw_damage_labels() { textColor = diablo2::UI_COLOR_YELLOW; } - int bMaxWidth = 10; + int bMaxWidth = 100; // Calculate the width of the health bar based on the percentage (max width is 10 characters) uint32_t barWidth = static_cast(healthPercentage * 10.0f); @@ -255,7 +255,7 @@ static void draw_damage_labels() { std::wstring fractionStr = std::to_wstring(label->currentHp) + L"/" + std::to_wstring(label->maxHp); // Combine the strings for health percentage and bar text - std::wstring combinedText = std::to_wstring(static_cast(healthPercentage * 100.0f)) + L"% " + barText; + std::wstring combinedText = std::to_wstring(static_cast(healthPercentage * 100.0f)) + L"% [" + fractionStr + L"]"; const WCHAR* combinedTextPtr = combinedText.c_str(); @@ -265,13 +265,13 @@ static void draw_damage_labels() { // Draw the combined text (health percentage and bar text) - //diablo2::d2_win::draw_text(const_cast(combinedText.c_str()), textX, textY, textColor, 0); + //diablo2::d2_win::draw_text(const_cast(combinedTcombinedTextext.c_str()), textX, textY, textColor, 0); //diablo2::d2_win::draw_boxed_text(const_cast(fractionStr.c_str()), textX + label->unit_width/2, textY - 12, 0, 0, textColor); - diablo2::d2_win::set_current_font(diablo2::UI_FONT_8); // Set font to FONT16 + diablo2::d2_win::set_current_font(diablo2::UI_FONT_6); // Set font to FONT16 //diablo2::d2_win::draw_text(const_cast(fractionStr.c_str()), textX + diablo2::d2_win::get_text_pixel_width(const_cast(combinedTextPtr)) / 2, textY - 12, textColor, 0); - diablo2::d2_win::set_current_font(diablo2::UI_FONT_8); // Set font to FONT6 + diablo2::d2_win::set_current_font(diablo2::UI_FONT_6); // Set font to FONT6 //diablo2::d2_win::draw_text(const_cast(combinedText.c_str()), textX, textY, textColor, 0); HWND hWndDiabloII = findDiabloIIWindow(); @@ -285,9 +285,14 @@ static void draw_damage_labels() { } //drawHealthBar(hWndDiabloII, textX, textY, _barWidth, _barHeight, healthPercentage, RGB(255, 0, 0), RGB(0, 0, 0)); - onDraw(hWndDiabloII, textX, textY, _barWidth, _barHeight, healthPercentage, RGB(255, 0, 0), RGB(0, 0, 0)); + //onDraw(hWndDiabloII, textX, textY, _barWidth, _barHeight, healthPercentage, RGB(255, 0, 0), RGB(0, 0, 0)); + + //diablo2::d2_win::draw_boxed_text(const_cast(combinedText.c_str()), textX, textY, 0, 3, textColor); + + diablo2::d2_win::draw_text(const_cast(combinedText.c_str()), textX, textY, textColor, 0); + diablo2::d2_gfx::draw_filled_rect(textX, textY, textX + healthPercentage * 60, textY + _barHeight, 9, 7); + - diablo2::d2_win::draw_boxed_text(const_cast(combinedText.c_str()), textX, textY, 0, 3, textColor); const auto offset = static_cast(lerp(static_cast(label->unit_height) + 5.f, static_cast(label->unit_height) + 30.f, static_cast(delta) / static_cast(DISPLAY_TIME))); diff --git a/src/diablo2/d2gfx.cpp b/src/diablo2/d2gfx.cpp index 9d49299..678c762 100644 --- a/src/diablo2/d2gfx.cpp +++ b/src/diablo2/d2gfx.cpp @@ -32,3 +32,9 @@ void diablo2::d2_gfx::draw_image(structures::gfxdata* data, uint32_t x, uint32_t int32_t, int32_t, void*)> draw_image(10072, get_base()); draw_image(data, x, y, gamma, drawType, palette); } + + +void diablo2::d2_gfx::draw_filled_rect(int left , int top, int right, int bottom, ULONG color, ULONG transTbl) { + static wrap_func_std_import draw_boxed_text(10055, get_base()); + draw_boxed_text(left, top, right, bottom, color, transTbl); +} \ No newline at end of file diff --git a/src/diablo2/d2win.cpp b/src/diablo2/d2win.cpp index 66e09f4..fcf71a2 100644 --- a/src/diablo2/d2win.cpp +++ b/src/diablo2/d2win.cpp @@ -22,6 +22,8 @@ void diablo2::d2_win::draw_boxed_text(wchar_t* str, uint32_t x, uint32_t y, int3 draw_boxed_text(str, x, y, paletteIndex, transTbl, color); } + + void diablo2::d2_win::set_popup_properties(wchar_t* str, uint32_t x, uint32_t y, ui_color_t color, int32_t align) { static wrap_func_fast_import hover_text(10129, get_base()); hover_text(str, x, y, color, align);