From d98ce78c341768d12e7a3952682dad20a4f0f52e Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:48:21 +0100 Subject: [PATCH] add setting for hp bar --- Mods/vcmi/Content/config/english.json | 2 ++ Mods/vcmi/Content/config/german.json | 2 ++ client/battle/BattleStacksController.cpp | 2 +- client/windows/settings/BattleOptionsTab.cpp | 15 +++++++++++++++ client/windows/settings/BattleOptionsTab.h | 1 + config/schemas/settings.json | 6 +++++- config/widgets/settings/battleOptionsTab.json | 8 ++++++++ 7 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Mods/vcmi/Content/config/english.json b/Mods/vcmi/Content/config/english.json index 8384c2009..32456e6b0 100644 --- a/Mods/vcmi/Content/config/english.json +++ b/Mods/vcmi/Content/config/english.json @@ -363,6 +363,8 @@ "vcmi.battleOptions.endWithAutocombat.help": "{Ends battle}\n\nAuto-Combat plays battle to end instant", "vcmi.battleOptions.showQuickSpell.hover": "Show Quickspell panel", "vcmi.battleOptions.showQuickSpell.help": "{Show Quickspell panel}\n\nShow panel for quick selecting spells", + "vcmi.battleOptions.showHealthBar.hover": "Show health bar", + "vcmi.battleOptions.showHealthBar.help": "{Show health bar}\n\nShow health bar indicating remaining health before one unit dies.", "vcmi.adventureMap.revisitObject.hover" : "Revisit Object", "vcmi.adventureMap.revisitObject.help" : "{Revisit Object}\n\nIf a hero currently stands on a Map Object, he can revisit the location.", diff --git a/Mods/vcmi/Content/config/german.json b/Mods/vcmi/Content/config/german.json index aa34553b1..f6ca204e4 100644 --- a/Mods/vcmi/Content/config/german.json +++ b/Mods/vcmi/Content/config/german.json @@ -363,6 +363,8 @@ "vcmi.battleOptions.endWithAutocombat.help": "{Kampf beenden}\n\nAutokampf spielt den Kampf sofort zu Ende", "vcmi.battleOptions.showQuickSpell.hover": "Schnellzauber-Panel anzeigen", "vcmi.battleOptions.showQuickSpell.help": "{Schnellzauber-Panel anzeigen}\n\nZeigt ein Panel, auf dem schnell Zauber ausgewählt werden können", + "vcmi.battleOptions.showHealthBar.hover": "Gesundheits-Balken anzeigen", + "vcmi.battleOptions.showHealthBar.help": "{Gesundheits-Balken anzeigen}\n\nAnzeige eines Gesundheitsbalkens, der die verbleibende Gesundheit anzeigt, bevor eine Einheit stirbt.", "vcmi.adventureMap.revisitObject.hover" : "Objekt erneut besuchen", "vcmi.adventureMap.revisitObject.help" : "{Objekt erneut besuchen}\n\nSteht ein Held gerade auf einem Kartenobjekt, kann er den Ort erneut aufsuchen.", diff --git a/client/battle/BattleStacksController.cpp b/client/battle/BattleStacksController.cpp index 8170d4868..56b6b65bf 100644 --- a/client/battle/BattleStacksController.cpp +++ b/client/battle/BattleStacksController.cpp @@ -319,7 +319,7 @@ void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * Point textPosition = Point(amountBG->dimensions().x/2 + boxPosition.x, boxPosition.y + amountBG->dimensions().y/2); - if(settings["general"]["enableUiEnhancements"].Bool()) // combat health bar + if(settings["battle"]["showHealthBar"].Bool()) { float health = CGI->creatures()->getByIndex(stack->creatureIndex())->getMaxHealth(); float healthRemaining = std::max(stack->getAvailableHealth() - (stack->getCount() - 1) * health, .0f); diff --git a/client/windows/settings/BattleOptionsTab.cpp b/client/windows/settings/BattleOptionsTab.cpp index adefb75c3..a683e724c 100644 --- a/client/windows/settings/BattleOptionsTab.cpp +++ b/client/windows/settings/BattleOptionsTab.cpp @@ -76,6 +76,10 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) { endWithAutocombatChangedCallback(value); }); + addCallback("showHealthBarChanged", [this, owner](bool value) + { + showHealthBarCallback(value, owner); + }); build(config); std::shared_ptr animationSpeedToggle = widget("animationSpeedPicker"); @@ -113,6 +117,9 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) std::shared_ptr endWithAutocombatCheckbox = widget("endWithAutocombatCheckbox"); endWithAutocombatCheckbox->setSelected(settings["battle"]["endWithAutocombat"].Bool()); + + std::shared_ptr showHealthBarCheckbox = widget("showHealthBarCheckbox"); + showHealthBarCheckbox->setSelected(settings["battle"]["showHealthBar"].Bool()); } int BattleOptionsTab::getAnimSpeed() const @@ -280,3 +287,11 @@ void BattleOptionsTab::endWithAutocombatChangedCallback(bool value) Settings endWithAutocombat = settings.write["battle"]["endWithAutocombat"]; endWithAutocombat->Bool() = value; } + +void BattleOptionsTab::showHealthBarCallback(bool value, BattleInterface * parentBattleInterface) +{ + Settings showHealthBar = settings.write["battle"]["showHealthBar"]; + showHealthBar->Bool() = value; + if(parentBattleInterface) + parentBattleInterface->redrawBattlefield(); +} diff --git a/client/windows/settings/BattleOptionsTab.h b/client/windows/settings/BattleOptionsTab.h index 59e7e3c88..9df03f24b 100644 --- a/client/windows/settings/BattleOptionsTab.h +++ b/client/windows/settings/BattleOptionsTab.h @@ -35,6 +35,7 @@ private: void showQuickSpellChangedCallback(bool value, BattleInterface * parentBattleInterface); void enableAutocombatSpellsChangedCallback(bool value); void endWithAutocombatChangedCallback(bool value); + void showHealthBarCallback(bool value, BattleInterface * parentBattleInterface); public: BattleOptionsTab(BattleInterface * owner = nullptr); }; diff --git a/config/schemas/settings.json b/config/schemas/settings.json index e89cf8487..6a7820c0c 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -428,7 +428,7 @@ "type" : "object", "additionalProperties" : false, "default" : {}, - "required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows", "enableAutocombatSpells", "endWithAutocombat", "queueSmallSlots", "queueSmallOutside", "enableQuickSpellPanel" ], + "required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows", "enableAutocombatSpells", "endWithAutocombat", "queueSmallSlots", "queueSmallOutside", "enableQuickSpellPanel", "showHealthBar" ], "properties" : { "speedFactor" : { "type" : "number", @@ -490,6 +490,10 @@ "enableQuickSpellPanel" : { "type": "boolean", "default": true + }, + "showHealthBar" : { + "type" : "boolean", + "default" : false } } }, diff --git a/config/widgets/settings/battleOptionsTab.json b/config/widgets/settings/battleOptionsTab.json index 0fdcd7757..81ca4c02b 100644 --- a/config/widgets/settings/battleOptionsTab.json +++ b/config/widgets/settings/battleOptionsTab.json @@ -125,6 +125,9 @@ }, { "text": "vcmi.battleOptions.skipBattleIntroMusic.hover", + }, + { + "text": "vcmi.battleOptions.showHealthBar.hover", } ] }, @@ -173,6 +176,11 @@ "name": "skipBattleIntroMusicCheckbox", "help": "vcmi.battleOptions.skipBattleIntroMusic", "callback": "skipBattleIntroMusicChanged" + }, + { + "name": "showHealthBarCheckbox", + "help": "vcmi.battleOptions.showHealthBar", + "callback": "showHealthBarChanged" } ] },