1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Merge pull request #5399 from Laserlicht/combat_health

[1.6.6] Combat Health Bar & Calculation fix
This commit is contained in:
Ivan Savenko 2025-02-14 13:09:49 +02:00 committed by GitHub
commit b69e1ce1fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 2 deletions

View File

@ -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.",

View File

@ -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.",

View File

@ -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();

View File

@ -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));
}

View File

@ -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();
}

View File

@ -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);
};

View File

@ -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
}
}
},

View File

@ -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",