| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "StdInc.h"
- #include "CBattleHero.h"
- #include "CBattleInterface.h"
- #include "../CGameInfo.h"
- #include "../CDefHandler.h"
- #include "../CCursorHandler.h"
- #include "../CPlayerInterface.h"
- #include "../../CCallback.h"
- #include "../SDL_Extensions.h"
- #include "../CSpellWindow.h"
- #include "../Graphics.h"
- #include "../CConfigHandler.h"
- #include "../UIFramework/CGuiHandler.h"
- void CBattleHero::show(SDL_Surface *to)
- {
- //animation of flag
- if(flip)
- {
- SDL_Rect temp_rect = genRect(
- flag->ourImages[flagAnim].bitmap->h,
- flag->ourImages[flagAnim].bitmap->w,
- pos.x + 61,
- pos.y + 39);
- CSDL_Ext::blit8bppAlphaTo24bpp(
- flag->ourImages[flagAnim].bitmap,
- NULL,
- screen,
- &temp_rect);
- }
- else
- {
- SDL_Rect temp_rect = genRect(
- flag->ourImages[flagAnim].bitmap->h,
- flag->ourImages[flagAnim].bitmap->w,
- pos.x + 72,
- pos.y + 39);
- CSDL_Ext::blit8bppAlphaTo24bpp(
- flag->ourImages[flagAnim].bitmap,
- NULL,
- screen,
- &temp_rect);
- }
- ++flagAnimCount;
- if(flagAnimCount%4==0)
- {
- ++flagAnim;
- flagAnim %= flag->ourImages.size();
- }
- //animation of hero
- int tick=-1;
- for(size_t i = 0; i < dh->ourImages.size(); ++i)
- {
- if(dh->ourImages[i].groupNumber==phase)
- ++tick;
- if(tick==image)
- {
- SDL_Rect posb = pos;
- CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
- if(phase != 4 || nextPhase != -1 || image < 4)
- {
- if(flagAnimCount%2==0)
- {
- ++image;
- }
- if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
- {
- image = 0;
- }
- }
- if(phase == 4 && nextPhase != -1 && image == 7)
- {
- phase = nextPhase;
- nextPhase = -1;
- image = 0;
- }
- break;
- }
- }
- }
- void CBattleHero::activate()
- {
- activateLClick();
- }
- void CBattleHero::deactivate()
- {
- deactivateLClick();
- }
- void CBattleHero::setPhase(int newPhase)
- {
- if(phase != 4)
- {
- phase = newPhase;
- image = 0;
- }
- else
- {
- nextPhase = newPhase;
- }
- }
- void CBattleHero::clickLeft(tribool down, bool previousState)
- {
- if(myOwner->spellDestSelectMode) //we are casting a spell
- return;
- if(!down && myHero != NULL && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions
- {
- for(int it=0; it<GameConstants::BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
- {
- if(myOwner->bfield[it].hovered && myOwner->bfield[it].strictHovered)
- return;
- }
- CCS->curh->changeGraphic(0,0);
- CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt);
- GH.pushInt(spellWindow);
- }
- }
- CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0)
- {
- dh = CDefHandler::giveDef( defName );
- for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images
- {
- if(flip)
- {
- SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
- SDL_FreeSurface(dh->ourImages[i].bitmap);
- dh->ourImages[i].bitmap = hlp;
- }
- CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
- }
- if(flip)
- flag = CDefHandler::giveDef("CMFLAGR.DEF");
- else
- flag = CDefHandler::giveDef("CMFLAGL.DEF");
- //coloring flag and adding transparency
- for(size_t i = 0; i < flag->ourImages.size(); ++i)
- {
- CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
- graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
- }
- }
- CBattleHero::~CBattleHero()
- {
- delete dh;
- delete flag;
- }
|