mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
Minor refactoring of BattleHero class
This commit is contained in:
parent
a57eec23e6
commit
6138ff1670
@ -123,44 +123,11 @@ BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *
|
|||||||
actionsController.reset( new BattleActionsController(*this));
|
actionsController.reset( new BattleActionsController(*this));
|
||||||
effectsController.reset(new BattleEffectsController(*this));
|
effectsController.reset(new BattleEffectsController(*this));
|
||||||
|
|
||||||
//loading hero animations
|
|
||||||
if(hero1) // attacking hero
|
if(hero1) // attacking hero
|
||||||
{
|
attackingHero = std::make_shared<BattleHero>(*this, hero1, false);
|
||||||
std::string battleImage;
|
|
||||||
if(!hero1->type->battleImage.empty())
|
|
||||||
{
|
|
||||||
battleImage = hero1->type->battleImage;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(hero1->sex)
|
|
||||||
battleImage = hero1->type->heroClass->imageBattleFemale;
|
|
||||||
else
|
|
||||||
battleImage = hero1->type->heroClass->imageBattleMale;
|
|
||||||
}
|
|
||||||
|
|
||||||
attackingHero = std::make_shared<BattleHero>(battleImage, false, hero1->tempOwner, hero1->tempOwner == curInt->playerID ? hero1 : nullptr, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(hero2) // defending hero
|
if(hero2) // defending hero
|
||||||
{
|
defendingHero = std::make_shared<BattleHero>(*this, hero2, true);
|
||||||
std::string battleImage;
|
|
||||||
|
|
||||||
if(!hero2->type->battleImage.empty())
|
|
||||||
{
|
|
||||||
battleImage = hero2->type->battleImage;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(hero2->sex)
|
|
||||||
battleImage = hero2->type->heroClass->imageBattleFemale;
|
|
||||||
else
|
|
||||||
battleImage = hero2->type->heroClass->imageBattleMale;
|
|
||||||
}
|
|
||||||
|
|
||||||
defendingHero = std::make_shared<BattleHero>(battleImage, true, hero2->tempOwner, hero2->tempOwner == curInt->playerID ? hero2 : nullptr, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
obstacleController.reset(new BattleObstacleController(*this));
|
obstacleController.reset(new BattleObstacleController(*this));
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "../../lib/CGameState.h"
|
#include "../../lib/CGameState.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/CTownHandler.h"
|
#include "../../lib/CTownHandler.h"
|
||||||
|
#include "../../lib/CHeroHandler.h"
|
||||||
#include "../../lib/NetPacks.h"
|
#include "../../lib/NetPacks.h"
|
||||||
#include "../../lib/StartInfo.h"
|
#include "../../lib/StartInfo.h"
|
||||||
#include "../../lib/CondSh.h"
|
#include "../../lib/CondSh.h"
|
||||||
@ -168,7 +169,7 @@ void BattleHero::render(Canvas & canvas)
|
|||||||
Point heroPosition = pos.center() - heroFrame->dimensions() / 2;
|
Point heroPosition = pos.center() - heroFrame->dimensions() / 2;
|
||||||
Point flagPosition = pos.center() - flagFrame->dimensions() / 2;
|
Point flagPosition = pos.center() - flagFrame->dimensions() / 2;
|
||||||
|
|
||||||
if(flip)
|
if(defender)
|
||||||
flagPosition += Point(-4, -41);
|
flagPosition += Point(-4, -41);
|
||||||
else
|
else
|
||||||
flagPosition += Point(4, -41);
|
flagPosition += Point(4, -41);
|
||||||
@ -234,10 +235,10 @@ void BattleHero::clickLeft(tribool down, bool previousState)
|
|||||||
if(boost::logic::indeterminate(down))
|
if(boost::logic::indeterminate(down))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!myHero || down || !owner.myTurn)
|
if(!hero || down || !owner.myTurn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(owner.getCurrentPlayerInterface()->cb->battleCanCastSpell(myHero, spells::Mode::HERO) == ESpellCastProblem::OK) //check conditions
|
if(owner.getCurrentPlayerInterface()->cb->battleCanCastSpell(hero, spells::Mode::HERO) == ESpellCastProblem::OK) //check conditions
|
||||||
{
|
{
|
||||||
BattleHex hoveredHex = owner.fieldController->getHoveredHex();
|
BattleHex hoveredHex = owner.fieldController->getHoveredHex();
|
||||||
//do nothing when any hex is hovered - hero's animation overlaps battlefield
|
//do nothing when any hex is hovered - hero's animation overlaps battlefield
|
||||||
@ -246,7 +247,7 @@ void BattleHero::clickLeft(tribool down, bool previousState)
|
|||||||
|
|
||||||
CCS->curh->set(Cursor::Map::POINTER);
|
CCS->curh->set(Cursor::Map::POINTER);
|
||||||
|
|
||||||
GH.pushIntT<CSpellWindow>(myHero, owner.getCurrentPlayerInterface());
|
GH.pushIntT<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,13 +257,13 @@ void BattleHero::clickRight(tribool down, bool previousState)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Point windowPosition;
|
Point windowPosition;
|
||||||
windowPosition.x = (!flip) ? owner.pos.topLeft().x + 1 : owner.pos.topRight().x - 79;
|
windowPosition.x = (!defender) ? owner.pos.topLeft().x + 1 : owner.pos.topRight().x - 79;
|
||||||
windowPosition.y = owner.pos.y + 135;
|
windowPosition.y = owner.pos.y + 135;
|
||||||
|
|
||||||
InfoAboutHero targetHero;
|
InfoAboutHero targetHero;
|
||||||
if(down && (owner.myTurn || settings["session"]["spectate"].Bool()))
|
if(down && (owner.myTurn || settings["session"]["spectate"].Bool()))
|
||||||
{
|
{
|
||||||
auto h = flip ? owner.defendingHeroInstance : owner.attackingHeroInstance;
|
auto h = defender ? owner.defendingHeroInstance : owner.attackingHeroInstance;
|
||||||
targetHero.initFromHero(h, InfoAboutHero::EInfoLevel::INBATTLE);
|
targetHero.initFromHero(h, InfoAboutHero::EInfoLevel::INBATTLE);
|
||||||
GH.pushIntT<HeroInfoWindow>(targetHero, &windowPosition);
|
GH.pushIntT<HeroInfoWindow>(targetHero, &windowPosition);
|
||||||
}
|
}
|
||||||
@ -278,9 +279,9 @@ void BattleHero::switchToNextPhase()
|
|||||||
copy();
|
copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleHero::BattleHero(const std::string & animationPath, bool flipG, PlayerColor player, const CGHeroInstance * hero, const BattleInterface & owner):
|
BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender):
|
||||||
flip(flipG),
|
defender(defender),
|
||||||
myHero(hero),
|
hero(hero),
|
||||||
owner(owner),
|
owner(owner),
|
||||||
phase(EHeroAnimType::HOLDING),
|
phase(EHeroAnimType::HOLDING),
|
||||||
nextPhase(EHeroAnimType::HOLDING),
|
nextPhase(EHeroAnimType::HOLDING),
|
||||||
@ -288,24 +289,34 @@ BattleHero::BattleHero(const std::string & animationPath, bool flipG, PlayerColo
|
|||||||
currentFrame(0.f),
|
currentFrame(0.f),
|
||||||
flagCurrentFrame(0.f)
|
flagCurrentFrame(0.f)
|
||||||
{
|
{
|
||||||
|
std::string animationPath;
|
||||||
|
|
||||||
|
if(!hero->type->battleImage.empty())
|
||||||
|
animationPath = hero->type->battleImage;
|
||||||
|
else
|
||||||
|
if(hero->sex)
|
||||||
|
animationPath = hero->type->heroClass->imageBattleFemale;
|
||||||
|
else
|
||||||
|
animationPath = hero->type->heroClass->imageBattleMale;
|
||||||
|
|
||||||
animation = std::make_shared<CAnimation>(animationPath);
|
animation = std::make_shared<CAnimation>(animationPath);
|
||||||
animation->preload();
|
animation->preload();
|
||||||
|
|
||||||
pos.w = 64;
|
pos.w = 64;
|
||||||
pos.h = 136;
|
pos.h = 136;
|
||||||
pos.x = owner.pos.x + (flipG ? (owner.pos.w - pos.w) : 0);
|
pos.x = owner.pos.x + (defender ? (owner.pos.w - pos.w) : 0);
|
||||||
pos.y = owner.pos.y;
|
pos.y = owner.pos.y;
|
||||||
|
|
||||||
if(flip)
|
if(defender)
|
||||||
animation->verticalFlip();
|
animation->verticalFlip();
|
||||||
|
|
||||||
if(flip)
|
if(defender)
|
||||||
flagAnimation = std::make_shared<CAnimation>("CMFLAGR");
|
flagAnimation = std::make_shared<CAnimation>("CMFLAGR");
|
||||||
else
|
else
|
||||||
flagAnimation = std::make_shared<CAnimation>("CMFLAGL");
|
flagAnimation = std::make_shared<CAnimation>("CMFLAGL");
|
||||||
|
|
||||||
flagAnimation->preload();
|
flagAnimation->preload();
|
||||||
flagAnimation->playerColored(player);
|
flagAnimation->playerColored(hero->tempOwner);
|
||||||
|
|
||||||
addUsedEvents(LCLICK | RCLICK | HOVER);
|
addUsedEvents(LCLICK | RCLICK | HOVER);
|
||||||
|
|
||||||
|
@ -79,14 +79,14 @@ public:
|
|||||||
/// Hero battle animation
|
/// Hero battle animation
|
||||||
class BattleHero : public CIntObject
|
class BattleHero : public CIntObject
|
||||||
{
|
{
|
||||||
bool flip; //false if it's attacking hero, true otherwise
|
bool defender;
|
||||||
|
|
||||||
CFunctionList<void()> phaseFinishedCallback;
|
CFunctionList<void()> phaseFinishedCallback;
|
||||||
|
|
||||||
std::shared_ptr<CAnimation> animation;
|
std::shared_ptr<CAnimation> animation;
|
||||||
std::shared_ptr<CAnimation> flagAnimation;
|
std::shared_ptr<CAnimation> flagAnimation;
|
||||||
|
|
||||||
const CGHeroInstance * myHero; //this animation's hero instance
|
const CGHeroInstance * hero; //this animation's hero instance
|
||||||
const BattleInterface & owner; //battle interface to which this animation is assigned
|
const BattleInterface & owner; //battle interface to which this animation is assigned
|
||||||
|
|
||||||
EHeroAnimType phase; //stage of animation
|
EHeroAnimType phase; //stage of animation
|
||||||
@ -111,7 +111,7 @@ public:
|
|||||||
void hover(bool on) override;
|
void hover(bool on) override;
|
||||||
void clickLeft(tribool down, bool previousState) override; //call-in
|
void clickLeft(tribool down, bool previousState) override; //call-in
|
||||||
void clickRight(tribool down, bool previousState) override; //call-in
|
void clickRight(tribool down, bool previousState) override; //call-in
|
||||||
BattleHero(const std::string & animationPath, bool filpG, PlayerColor player, const CGHeroInstance * hero, const BattleInterface & owner);
|
BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
|
||||||
};
|
};
|
||||||
|
|
||||||
class HeroInfoWindow : public CWindowObject
|
class HeroInfoWindow : public CWindowObject
|
||||||
|
Loading…
x
Reference in New Issue
Block a user