Working on health bar

This commit is contained in:
Vladislav Khorev committed 2026-06-01 22:03:05 +03:00
1 parent 8552725dfc
commit 22b0e1992f
12 files changed
+121 -57

No files matched your search

+23
View File
@@ -110,6 +110,7 @@ namespace ZL {
void MenuManager::enterGameplay() {
state = GameState::Gameplay;
uiManager.replaceRoot(hudRoot);
applyCurrentHealthBar();
/*
uiManager.setTextButtonCallback("inventory_button", [this](const std::string&) {
openInventory();
@@ -366,12 +367,14 @@ namespace ZL {
if (locationName == "uni_exterior") {
uiManager.replaceRoot(currentIsDarklands_ ? hudUniExtDarkRoot : hudUniExtRoot);
applyCurrentHealthBar();
setupGameplayHudCallbacks();
} else if (locationName == "uni_interior") {
applyUniIntHud();
} else {
// Returning to dorm: reuse step5ab, suppress already-completed hints
uiManager.replaceRoot(hudStep5abRoot);
applyCurrentHealthBar();
setupStep5Callbacks();
}
}
@@ -402,6 +405,7 @@ namespace ZL {
if (state == GameState::Gameplay && nextRoot) {
uiManager.replaceRoot(nextRoot);
applyCurrentHealthBar();
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) {
openInventory();
@@ -450,6 +454,7 @@ namespace ZL {
if (nextRoot) {
uiManager.replaceRoot(nextRoot);
applyCurrentHealthBar();
// Register item-screen buttons and re-apply any already-completed hint visibility.
setupStep5Callbacks();
}
@@ -628,6 +633,7 @@ namespace ZL {
} else if (currentLocationName_ == "uni_exterior") {
if (state == GameState::Gameplay) {
uiManager.replaceRoot(enabled ? hudUniExtDarkRoot : hudUniExtRoot);
applyCurrentHealthBar();
setupGameplayHudCallbacks();
}
} else {
@@ -654,6 +660,7 @@ namespace ZL {
}
}
uiManager.replaceRoot(root);
applyCurrentHealthBar();
setupGameplayHudCallbacks();
}
@@ -684,4 +691,20 @@ namespace ZL {
applyUniIntHud();
}
void MenuManager::updateHealthBar(float hp, float maxHp) {
currentPlayerHp_ = hp;
currentPlayerMaxHp_ = maxHp;
applyCurrentHealthBar();
}
void MenuManager::applyCurrentHealthBar() {
if (currentPlayerMaxHp_ <= 0.f) return;
const float fraction = std::clamp(currentPlayerHp_ / currentPlayerMaxHp_, 0.f, 1.f);
uiManager.setSliderValue("healthBarFill", fraction);
std::string hpText = std::to_string(static_cast<int>(currentPlayerHp_)) + "/" +
std::to_string(static_cast<int>(currentPlayerMaxHp_));
if (hpText.size() < 7) hpText.insert(0, 7 - hpText.size(), ' ');
uiManager.setText("healthValue", hpText);
}
} // namespace ZL