diff --git a/Mods/vcmi/Content/config/english.json b/Mods/vcmi/Content/config/english.json index 776e5f523..1fd43210d 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 27afb0bf4..8b6650d88 100644 --- a/Mods/vcmi/Content/config/german.json +++ b/Mods/vcmi/Content/config/german.json @@ -361,6 +361,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/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index ac9410963..431a410db 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -636,7 +636,7 @@ void StackInfoBasicPanel::initializeData(const CStack * stack) auto attack = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getAttack(stack->isShooter())) + "(" + std::to_string(stack->getAttack(stack->isShooter())) + ")"; auto defense = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getDefense(stack->isShooter())) + "(" + std::to_string(stack->getDefense(stack->isShooter())) + ")"; auto damage = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getMinDamage(stack->isShooter())) + "-" + std::to_string(stack->getMaxDamage(stack->isShooter())); - auto health = CGI->creatures()->getByIndex(stack->creatureIndex())->getMaxHealth(); + auto health = stack->getMaxHealth(); auto morale = stack->moraleVal(); auto luck = stack->luckVal(); diff --git a/client/battle/BattleStacksController.cpp b/client/battle/BattleStacksController.cpp index d0be307cc..7e59ec2fe 100644 --- a/client/battle/BattleStacksController.cpp +++ b/client/battle/BattleStacksController.cpp @@ -38,6 +38,7 @@ #include "../../lib/battle/BattleAction.h" #include "../../lib/battle/BattleHex.h" #include "../../lib/texts/TextOperations.h" +#include "../../lib/CConfigHandler.h" #include "../../lib/CRandomGenerator.h" #include "../../lib/CStack.h" @@ -318,6 +319,15 @@ void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * Point textPosition = Point(amountBG->dimensions().x/2 + boxPosition.x, boxPosition.y + amountBG->dimensions().y/2); + if(settings["battle"]["showHealthBar"].Bool()) + { + float health = stack->getMaxHealth(); + float healthRemaining = std::max(stack->getAvailableHealth() - (stack->getCount() - 1) * health, .0f); + Rect r(boxPosition.x, boxPosition.y - 3, amountBG->width(), 4); + canvas.drawColor(r, Colors::RED); + canvas.drawColor(Rect(r.x, r.y, (r.w / health) * healthRemaining, r.h), Colors::GREEN); + canvas.drawBorder(r, Colors::YELLOW); + } canvas.draw(amountBG, boxPosition); canvas.drawText(textPosition, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, TextOperations::formatMetric(stack->getCount(), 4)); } 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 1cd0aa104..6b1176dfa 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -433,7 +433,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", @@ -495,6 +495,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..f637e7e75 100644 --- a/config/widgets/settings/battleOptionsTab.json +++ b/config/widgets/settings/battleOptionsTab.json @@ -114,6 +114,9 @@ { "text": "vcmi.battleOptions.rangeLimitHighlightOnHover.hover", }, + { + "text": "vcmi.battleOptions.showHealthBar.hover", + }, { "text": "vcmi.battleOptions.showStickyHeroInfoWindows.hover", }, @@ -154,6 +157,11 @@ "help": "vcmi.battleOptions.rangeLimitHighlightOnHover", "callback": "rangeLimitHighlightOnHoverChanged" }, + { + "name": "showHealthBarCheckbox", + "help": "vcmi.battleOptions.showHealthBar", + "callback": "showHealthBarChanged" + }, { "name": "showStickyHeroInfoWindowsCheckbox", "help": "vcmi.battleOptions.showStickyHeroInfoWindows",