1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Implementing hero battle information window

This commit is contained in:
dydzio 2016-09-27 14:13:20 +02:00
parent d831c087d9
commit f621ef4ce8
2 changed files with 89 additions and 1 deletions

View File

@ -177,6 +177,15 @@ void CBattleHero::setPhase(int newPhase)
nextPhase = 0;
}
void CBattleHero::hover(bool on)
{
//TODO: Make lines below work properly
if (on)
CCS->curh->changeGraphic(ECursor::COMBAT, 5);
else
CCS->curh->changeGraphic(ECursor::COMBAT, 0);
}
void CBattleHero::clickLeft(tribool down, bool previousState)
{
if(myOwner->spellDestSelectMode) //we are casting a spell
@ -196,6 +205,25 @@ void CBattleHero::clickLeft(tribool down, bool previousState)
}
}
void CBattleHero::clickRight(tribool down, bool previousState)
{
Point windowPosition;
windowPosition.x = (!flip) ? myOwner->pos.topLeft().x + 1 : myOwner->pos.topRight().x - 79;
windowPosition.y = myOwner->pos.y + 135;
InfoAboutHero targetHero;
if (down && myOwner->myTurn)
{
if (myHero != nullptr)
targetHero.initFromHero(myHero, true);
else
targetHero = myOwner->enemyHero();
GH.pushInt(new CHeroInfoWindow(targetHero, &windowPosition));
}
}
void CBattleHero::switchToNextPhase()
{
if (phase != nextPhase)
@ -247,7 +275,7 @@ CBattleHero::CBattleHero(const std::string & defName, bool flipG, PlayerColor pl
CSDL_Ext::alphaTransform(elem.bitmap);
graphics->blueToPlayersAdv(elem.bitmap, player);
}
addUsedEvents(LCLICK);
addUsedEvents(LCLICK | RCLICK | HOVER);
switchToNextPhase();
}
@ -614,6 +642,47 @@ void CClickableHex::clickRight(tribool down, bool previousState)
}
}
CHeroInfoWindow::CHeroInfoWindow(const InfoAboutHero &hero, Point *position) : CWindowObject(RCLICK_POPUP | SHADOW_DISABLED, "CHRPOP")
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
if (position != nullptr)
moveTo(*position);
background->colorize(hero.owner); //maybe add this functionality to base class?
attack = hero.details->primskills[0];
defense = hero.details->primskills[1];
power = hero.details->primskills[2];
knowledge = hero.details->primskills[3];
morale = hero.details->morale;
luck = hero.details->luck;
currentSpellPoints = hero.details->mana;
maxSpellPoints = hero.details->manaLimit;
new CAnimImage("PortraitsLarge", hero.portrait, 0, 10, 6);
//primary stats
new CLabel(9, 75, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[380] + ":");
new CLabel(9, 87, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[381] + ":");
new CLabel(9, 99, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[382] + ":");
new CLabel(9, 111, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[383] + ":");
new CLabel(69, 87, EFonts::FONT_TINY, EAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(attack));
new CLabel(69, 99, EFonts::FONT_TINY, EAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(defense));
new CLabel(69, 111, EFonts::FONT_TINY, EAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(power));
new CLabel(69, 123, EFonts::FONT_TINY, EAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(knowledge));
//morale+luck
new CLabel(9, 131, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[384] + ":");
new CLabel(9, 143, EFonts::FONT_TINY, EAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[385] + ":");
new CAnimImage("IMRL22", morale + 3, 0, 47, 131);
new CAnimImage("ILCK22", luck + 3, 0, 47, 143);
//spell points
new CLabel(39, 174, EFonts::FONT_TINY, EAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[387]);
new CLabel(39, 186, EFonts::FONT_TINY, EAlignment::CENTER, Colors::WHITE, std::to_string(currentSpellPoints) + "/" + std::to_string(maxSpellPoints));
}
void CStackQueue::update()
{
stacksSorted.clear();

View File

@ -2,6 +2,7 @@
#include "../gui/CIntObject.h"
#include "../../lib/BattleHex.h"
#include "../windows/CWindowObject.h"
struct SDL_Surface;
class CDefHandler;
@ -62,11 +63,29 @@ public:
ui8 flagAnim, animCount; //for flag animation
void show(SDL_Surface * to) override; //prints next frame of animation to to
void setPhase(int newPhase); //sets phase of hero animation
void hover(bool on) override;
void clickLeft(tribool down, bool previousState) override; //call-in
void clickRight(tribool down, bool previousState) override; //call-in
CBattleHero(const std::string &defName, bool filpG, PlayerColor player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor
~CBattleHero(); //d-tor
};
class CHeroInfoWindow : public CWindowObject
{
public:
CHeroInfoWindow(const InfoAboutHero &hero, Point *position);
private:
int attack;
int defense;
int power;
int knowledge;
int morale;
int luck;
int currentSpellPoints;
int maxSpellPoints;
};
/// Class which manages the battle options window
class CBattleOptionsWindow : public CIntObject
{