GDI healthbars working

This commit is contained in:
Hash Borgir 2024-04-24 04:34:09 -06:00
parent c1f72087b3
commit 094a39a872
53 changed files with 71 additions and 53 deletions

Binary file not shown.

View File

@ -1,5 +1,3 @@
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(517,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
autosort_client.cpp
D:\VSCode\d2tweaks-rnd2k\src\d2tweaks\client\modules\autosort\autosort_client.cpp(1163,13): warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
D:\VSCode\d2tweaks-rnd2k\src\d2tweaks\client\modules\autosort\autosort_client.cpp(1168,32): warning C4244: '=': conversion from 'ULONGLONG' to 'long', possible loss of data
D2tweaks.vcxproj -> D:\Diablo II\MODS\ironman-dev\D2tweaks.dll

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -117,6 +117,20 @@ public:
// Function to find the Diablo II window handle
HWND FindDiabloIIWindow() {
return FindWindow(NULL, "Diablo II");
}
// Function to draw a filled rectangle using GDI
void DrawFilledRect(HWND hwnd, int left, int top, int right, int bottom, COLORREF color) {
HDC hdc = GetDC(hwnd);
HBRUSH hBrush = CreateSolidBrush(color);
RECT rect = { left, top, right, bottom };
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
ReleaseDC(hwnd, hdc);
}
@ -303,6 +317,56 @@ public:
diablo2::ui_color_t::UI_COLOR_WHITE;
// print player health, mana, and stamina bars, lastexp, nextexp, and level
// Get current HP, Mana, and Stamina along with their maximum values
int statHP = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(6), NULL);
int statMaxHP = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(7), NULL);
int statMana = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(8), NULL);
int statMaxMana = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(9), NULL);
int statStamina = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(10), NULL);
int statMaxStamina = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(11), NULL);
// Calculate the percentages of current HP, Mana, and Stamina
float healthPercentage = static_cast<float>(statHP) / static_cast<float>(statMaxHP);
float manaPercentage = static_cast<float>(statMana) / static_cast<float>(statMaxMana);
float staminaPercentage = static_cast<float>(statStamina) / static_cast<float>(statMaxStamina);
// Define the dimensions for the bars
int barWidth = 200; // Width of the bars
int barHeight = 10; // Height of the bars
// Define the coordinates for the bars
int barX = 15; // Left coordinate of the bars
int barY_HP = 600; // Top coordinate of the HP bar
int barY_Mana = barY_HP + barHeight + 4; // Top coordinate of the Mana bar with separator
int barY_Stamina = barY_Mana + barHeight + 4; // Top coordinate of the Stamina bar with separator
// Calculate the filled widths of the bars
int filledHPWidth = static_cast<int>(healthPercentage * barWidth);
int filledManaWidth = static_cast<int>(manaPercentage * barWidth);
int filledStaminaWidth = static_cast<int>(staminaPercentage * barWidth);
HWND diabloIIWnd = FindDiabloIIWindow();
// Draw the filled HP bar
// diablo2::d2_gfx::draw_filled_rect(barX, barY_HP, barX + filledHPWidth, barY_HP + barHeight, 1, 7);
DrawFilledRect(diabloIIWnd, barX, barY_HP, barX + filledHPWidth, barY_HP + barHeight, RGB(255, 0, 0)); // Red color for HP
// Draw the filled Mana bar
// diablo2::d2_gfx::draw_filled_rect(barX, barY_Mana, barX + filledManaWidth, barY_Mana + barHeight, 3, 7);
DrawFilledRect(diabloIIWnd, barX, barY_Mana, barX + filledManaWidth, barY_Mana + barHeight, RGB(100, 100, 255)); // Blue color for Mana
// Draw the filled Stamina bar
// diablo2::d2_gfx::draw_filled_rect(barX, barY_Stamina, barX + filledStaminaWidth, barY_Stamina + barHeight, 9, 7);
DrawFilledRect(diabloIIWnd, barX, barY_Stamina, barX + filledStaminaWidth, barY_Stamina + barHeight, RGB(255, 255, 0)); // Green color for Stamina
int statLevel = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(12), NULL);
int statLastExp = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(29), NULL);
int statNextExp = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(30), NULL);

View File

@ -221,80 +221,36 @@ 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();
//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");
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);
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);
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;

View File

@ -9,7 +9,7 @@
#include <DllNotify.h>
#include <D2Template.h>
bool m_stats_enabled = false;
bool m_stats_enabled = true;
d2_tweaks::client::modules::loot_filter_settings_toggle_menu::loot_filter_settings_toggle_menu(token) {
m_show = false;