瀏覽代碼

Merge pull request #5399 from Laserlicht/combat_health

[1.6.6] Combat Health Bar & Calculation fix
Ivan Savenko 8 月之前
父節點
當前提交
b69e1ce1fb

+ 2 - 0
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.",

+ 2 - 0
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.",

+ 1 - 1
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();
 

+ 10 - 0
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));
 }

+ 15 - 0
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<CToggleGroup> animationSpeedToggle = widget<CToggleGroup>("animationSpeedPicker");
@@ -113,6 +117,9 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
 
 	std::shared_ptr<CToggleButton> endWithAutocombatCheckbox = widget<CToggleButton>("endWithAutocombatCheckbox");
 	endWithAutocombatCheckbox->setSelected(settings["battle"]["endWithAutocombat"].Bool());
+
+	std::shared_ptr<CToggleButton> showHealthBarCheckbox = widget<CToggleButton>("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();
+}

+ 1 - 0
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);
 };

+ 5 - 1
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
 				}
 			}
 		},

+ 8 - 0
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",