mirror of
https://gitlab.com/hashborgir/d2tweaks-rnd2k.git
synced 2025-09-19 01:52:08 +00:00
GDI healthbars working
This commit is contained in:
@@ -221,79 +221,35 @@ static void draw_damage_labels() {
|
||||
|
||||
// Determine the color based on healthPercentage
|
||||
diablo2::ui_color_t textColor;
|
||||
if (healthPercentage >= 0.67f) {
|
||||
textColor = diablo2::UI_COLOR_GREEN;
|
||||
}
|
||||
else if (healthPercentage <= 0.33f) {
|
||||
textColor = diablo2::UI_COLOR_RED;
|
||||
}
|
||||
else {
|
||||
textColor = diablo2::UI_COLOR_YELLOW;
|
||||
}
|
||||
|
||||
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);
|
||||
barWidth = (barWidth > bMaxWidth) ? bMaxWidth : barWidth; // Ensure barWidth doesn't exceed 10
|
||||
barWidth = (label->currentHp > 0 && barWidth == 0) ? 1 : barWidth; // Ensure at least one '#' if currentHp is not 0
|
||||
|
||||
char barChar[1]; GetPrivateProfileStringA("Options", "char", "", barChar, sizeof(barChar), "./D2Tweaks.ini");
|
||||
|
||||
LPWSTR barCharW = reinterpret_cast<LPWSTR>(barChar);
|
||||
|
||||
// Construct the health bar string representation
|
||||
std::wstring barText;
|
||||
for (uint32_t i = 0; i < barWidth; ++i) {
|
||||
barText.append(barCharW); // Use '#' to represent filled portion of the bar
|
||||
}
|
||||
for (uint32_t i = barWidth; i < bMaxWidth; ++i) {
|
||||
barText.append(L""); // Use '-' to represent empty portion of the bar
|
||||
}
|
||||
textColor = healthPercentage >= 0.67f ? diablo2::UI_COLOR_GREEN : (healthPercentage <= 0.33f ? diablo2::UI_COLOR_RED : diablo2::UI_COLOR_YELLOW);
|
||||
|
||||
// Construct the health fraction string
|
||||
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"% [" + fractionStr + L"]";
|
||||
|
||||
const WCHAR* combinedTextPtr = combinedText.c_str();
|
||||
|
||||
// Calculate text position for the combined text
|
||||
uint32_t textX = mx;
|
||||
uint32_t textY = my;
|
||||
|
||||
|
||||
// Draw the combined text (health percentage and bar text)
|
||||
//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_6); // 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_6); // 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();
|
||||
|
||||
|
||||
int _barHeight = GetPrivateProfileIntA("Options", "barHeight", 0, "./D2Tweaks.ini");
|
||||
int _barWidth = GetPrivateProfileIntA("Options", "barWidth", 0, "./D2Tweaks.ini");
|
||||
|
||||
if (GetTickCount64() >= nEndTime) {
|
||||
nEndTime = GetTickCount64() + DURATION;
|
||||
}
|
||||
//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));
|
||||
|
||||
//diablo2::d2_win::draw_boxed_text(const_cast<wchar_t*>(combinedText.c_str()), textX, textY, 0, 3, textColor);
|
||||
|
||||
int _barHeight = GetPrivateProfileIntA("Options", "barHeight", 0, "./D2Tweaks.ini");
|
||||
|
||||
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_gfx::draw_filled_rect(textX, textY, textX + healthPercentage * 60, textY + _barHeight, 9, 7);
|
||||
|
||||
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)));
|
||||
my -= offset;
|
||||
|
Reference in New Issue
Block a user