New healthbar working

This commit is contained in:
Hash Borgir 2024-04-23 13:41:08 -06:00
parent 24e1d0238d
commit c1f72087b3
5 changed files with 25 additions and 8 deletions

View File

@ -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);
};
}

View File

@ -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();

View File

@ -9,7 +9,7 @@
#include <diablo2/d2client.h>
#include <d2tweaks/ui/ui_manager.h>
#include <diablo2/d2win.h>
#include <diablo2/d2gfx.h>
#include <fw/pool.h>
#include <diablo2/structures/gfxdata.h>
@ -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<uint32_t>(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<int>(healthPercentage * 100.0f)) + L"% " + barText;
std::wstring combinedText = std::to_wstring(static_cast<int>(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<wchar_t*>(combinedText.c_str()), textX, textY, textColor, 0);
//diablo2::d2_win::draw_text(const_cast<wchar_t*>(combinedTcombinedTextext.c_str()), textX, textY, textColor, 0);
//diablo2::d2_win::draw_boxed_text(const_cast<wchar_t*>(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<wchar_t*>(fractionStr.c_str()), textX + diablo2::d2_win::get_text_pixel_width(const_cast<wchar_t*>(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<wchar_t*>(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<wchar_t*>(combinedText.c_str()), textX, textY, 0, 3, textColor);
diablo2::d2_win::draw_text(const_cast<wchar_t*>(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<wchar_t*>(combinedText.c_str()), textX, textY, 0, 3, textColor);
const auto offset = static_cast<int32_t>(lerp(static_cast<float>(label->unit_height) + 5.f, static_cast<float>(label->unit_height) + 30.f, static_cast<float>(delta) / static_cast<float>(DISPLAY_TIME)));

View File

@ -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<void(int, int, int, int, ULONG, ULONG)> draw_boxed_text(10055, get_base());
draw_boxed_text(left, top, right, bottom, color, transTbl);
}

View File

@ -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<void(wchar_t*, uint32_t, uint32_t, int32_t, int32_t)> hover_text(10129, get_base());
hover_text(str, x, y, color, align);