1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

use stacks

This commit is contained in:
Laserlicht 2023-12-22 22:26:35 +01:00 committed by GitHub
parent 72911ec9a3
commit 56e1265097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 53 deletions

View File

@ -447,7 +447,7 @@ void HeroInfoBasicPanel::show(Canvas & to)
}
ArmyInfoBasicPanel::ArmyInfoBasicPanel(const InfoAboutArmy & army, Point * position, bool initializeBackground)
StackInfoBasicPanel::StackInfoBasicPanel(const CStack * stack, Point * position, bool initializeBackground)
: CIntObject(0)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -458,18 +458,50 @@ ArmyInfoBasicPanel::ArmyInfoBasicPanel(const InfoAboutArmy & army, Point * posit
{
background = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
background->colorize(army.owner);
background->colorize(stack->getOwner());
}
initializeData(army);
initializeData(stack);
}
void ArmyInfoBasicPanel::initializeData(const InfoAboutArmy & army)
void StackInfoBasicPanel::initializeData(const CStack * stack)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
/*auto attack = hero.details->primskills[0];
auto defense = hero.details->primskills[1];
auto power = hero.details->primskills[2];
auto knowledge = hero.details->primskills[3];
auto morale = hero.details->morale;
auto luck = hero.details->luck;
auto currentSpellPoints = hero.details->mana;
auto maxSpellPoints = hero.details->manaLimit;
icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero.getIconIndex(), 0, 10, 6));
//primary stats
labels.push_back(std::make_shared<CLabel>(9, 75, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[380] + ":"));
labels.push_back(std::make_shared<CLabel>(9, 87, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[381] + ":"));
labels.push_back(std::make_shared<CLabel>(9, 99, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[382] + ":"));
labels.push_back(std::make_shared<CLabel>(9, 111, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[383] + ":"));
labels.push_back(std::make_shared<CLabel>(69, 87, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(attack)));
labels.push_back(std::make_shared<CLabel>(69, 99, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(defense)));
labels.push_back(std::make_shared<CLabel>(69, 111, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(power)));
labels.push_back(std::make_shared<CLabel>(69, 123, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(knowledge)));
//morale+luck
labels.push_back(std::make_shared<CLabel>(9, 131, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[384] + ":"));
labels.push_back(std::make_shared<CLabel>(9, 143, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[385] + ":"));
icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), morale + 3, 0, 47, 131));
icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), luck + 3, 0, 47, 143));
//spell points
labels.push_back(std::make_shared<CLabel>(39, 174, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[387]));
labels.push_back(std::make_shared<CLabel>(39, 186, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(currentSpellPoints) + "/" + std::to_string(maxSpellPoints)));*/
}
void ArmyInfoBasicPanel::update(const InfoAboutArmy & updatedInfo)
void StackInfoBasicPanel::update(const CStack * updatedInfo)
{
icons.clear();
labels.clear();
@ -477,7 +509,7 @@ void ArmyInfoBasicPanel::update(const InfoAboutArmy & updatedInfo)
initializeData(updatedInfo);
}
void ArmyInfoBasicPanel::show(Canvas & to)
void StackInfoBasicPanel::show(Canvas & to)
{
showAll(to);
CIntObject::show(to);

View File

@ -20,7 +20,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
struct BattleResult;
struct InfoAboutHero;
struct InfoAboutArmy;
class CStack;
namespace battle
@ -145,19 +144,19 @@ public:
void update(const InfoAboutHero & updatedInfo);
};
class ArmyInfoBasicPanel : public CIntObject
class StackInfoBasicPanel : public CIntObject
{
private:
std::shared_ptr<CPicture> background;
std::vector<std::shared_ptr<CLabel>> labels;
std::vector<std::shared_ptr<CAnimImage>> icons;
public:
ArmyInfoBasicPanel(const InfoAboutArmy & army, Point * position, bool initializeBackground = true);
StackInfoBasicPanel(const CStack * stack, Point * position, bool initializeBackground = true);
void show(Canvas & to) override;
void initializeData(const InfoAboutArmy & army);
void update(const InfoAboutArmy & updatedInfo);
void initializeData(const CStack * stack);
void update(const CStack * updatedInfo);
};
class HeroInfoWindow : public CWindowObject

View File

@ -816,7 +816,10 @@ void BattleStacksController::updateHoveredStacks()
continue;
if (stack == activeStack)
{
owner.windowObject->updateStackInfoWindow(stack);
stackAnimation[stack->unitId()]->setBorderColor(AnimationControls::getGoldBorder());
}
else
stackAnimation[stack->unitId()]->setBorderColor(AnimationControls::getNoBorder());
}

View File

@ -154,41 +154,6 @@ void BattleWindow::createStickyHeroInfoWindows()
}
}
void BattleWindow::createStickyArmyInfoWindows(std::optional<uint32_t> unitId)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
if(owner.defendingHeroInstance)
{
InfoAboutHero info;
info.initFromHero(owner.defendingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, pos.y + 250)
: Point(pos.x + pos.w -79, pos.y + 135);
defenderArmyWindow = std::make_shared<ArmyInfoBasicPanel>(info, &position);
}
if(owner.attackingHeroInstance)
{
InfoAboutHero info;
info.initFromHero(owner.attackingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, pos.y + 250)
: Point(pos.x + 1, pos.y + 135);
attackerArmyWindow = std::make_shared<ArmyInfoBasicPanel>(info, &position);
}
bool showInfoWindows = settings["battle"]["stickyHeroInfoWindows"].Bool();
if(!showInfoWindows)
{
if(attackerArmyWindow)
attackerArmyWindow->disable();
if(defenderArmyWindow)
defenderArmyWindow->disable();
}
}
BattleWindow::~BattleWindow()
{
CPlayerInterface::battleInt = nullptr;
@ -292,6 +257,28 @@ void BattleWindow::updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero
panelToUpdate->update(hero);
}
void BattleWindow::updateStackInfoWindow(const CStack * stack)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, pos.y + 250)
: Point(pos.x + pos.w -79, pos.y + 135);
defenderStackWindow = std::make_shared<StackInfoBasicPanel>(stack, &position);
position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, pos.y + 250)
: Point(pos.x + 1, pos.y + 135);
attackerStackWindow = std::make_shared<StackInfoBasicPanel>(stack, &position);
//const CStack * stack = owner.getBattle()->battleGetStackByID(unitId.value(), true);
bool showInfoWindows = settings["battle"]["stickyHeroInfoWindows"].Bool();
attackerStackWindow->setEnabled(showInfoWindows && stack && stack->unitSide() == BattleSide::ATTACKER);
defenderStackWindow->setEnabled(showInfoWindows && stack && stack->unitSide() == BattleSide::DEFENDER);
}
void BattleWindow::heroManaPointsChanged(const CGHeroInstance * hero)
{
if(hero == owner.attackingHeroInstance || hero == owner.defendingHeroInstance)
@ -706,9 +693,7 @@ void BattleWindow::blockUI(bool on)
std::optional<uint32_t> BattleWindow::getQueueHoveredUnitId()
{
std::optional<uint32_t> unitId = queue->getHoveredUnitIdIfAny();
createStickyArmyInfoWindows(unitId);
return unitId;
return queue->getHoveredUnitIdIfAny();
}
void BattleWindow::showAll(Canvas & to)

View File

@ -25,7 +25,7 @@ class BattleConsole;
class BattleRenderer;
class StackQueue;
class HeroInfoBasicPanel;
class ArmyInfoBasicPanel;
class StackInfoBasicPanel;
/// GUI object that handles functionality of panel at the bottom of combat screen
class BattleWindow : public InterfaceObjectConfigurable
@ -36,8 +36,8 @@ class BattleWindow : public InterfaceObjectConfigurable
std::shared_ptr<BattleConsole> console;
std::shared_ptr<HeroInfoBasicPanel> attackerHeroWindow;
std::shared_ptr<HeroInfoBasicPanel> defenderHeroWindow;
std::shared_ptr<ArmyInfoBasicPanel> attackerArmyWindow;
std::shared_ptr<ArmyInfoBasicPanel> defenderArmyWindow;
std::shared_ptr<StackInfoBasicPanel> attackerStackWindow;
std::shared_ptr<StackInfoBasicPanel> defenderStackWindow;
/// button press handling functions
void bOptionsf();
@ -68,7 +68,6 @@ class BattleWindow : public InterfaceObjectConfigurable
void toggleStickyHeroWindowsVisibility();
void createStickyHeroInfoWindows();
void createStickyArmyInfoWindows(std::optional<uint32_t> unitId);
std::shared_ptr<BattleConsole> buildBattleConsole(const JsonNode &) const;
@ -99,6 +98,9 @@ public:
/// Refresh sticky variant of hero info window after spellcast, side same as in BattleSpellCast::side
void updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero);
/// Refresh sticky variant of hero info window after spellcast, side same as in BattleSpellCast::side
void updateStackInfoWindow(const CStack * stack);
/// Get mouse-hovered battle queue unit ID if any found
std::optional<uint32_t> getQueueHoveredUnitId();