2009-05-20 13:08:56 +03:00
# include "../stdafx.h"
2008-08-26 00:14:00 +03:00
# include "AdventureMapButton.h"
2008-01-11 20:56:39 +02:00
# include "CAdvmapInterface.h"
2009-05-20 13:08:56 +03:00
# include "../CCallback.h"
2008-08-26 00:14:00 +03:00
# include "CGameInfo.h"
# include "CHeroWindow.h"
2008-01-15 20:50:52 +02:00
# include "CMessage.h"
2010-02-04 17:50:59 +02:00
# include "CKingdomInterface.h"
2008-08-26 00:14:00 +03:00
# include "SDL.h"
# include "SDL_Extensions.h"
2009-05-20 13:08:56 +03:00
# include "CBitmapHandler.h"
# include "Graphics.h"
# include "CSpellWindow.h"
# include "CConfigHandler.h"
# include "../global.h"
# include "../hch/CArtHandler.h"
# include "../hch/CDefHandler.h"
# include "../hch/CGeneralTextHandler.h"
# include "../hch/CHeroHandler.h"
# include "../hch/CLodHandler.h"
# include "../hch/CObjectHandler.h"
2008-08-28 20:36:34 +03:00
# include <boost/algorithm/string/replace.hpp>
# include <boost/assign/list_of.hpp>
2008-08-26 00:14:00 +03:00
# include <boost/assign/std/vector.hpp>
# include <cstdlib>
2008-01-13 18:24:24 +02:00
# include <sstream>
2009-11-13 18:02:25 +02:00
# include <boost/lexical_cast.hpp>
2009-01-07 21:40:19 +02:00
2009-11-29 04:46:30 +02:00
# undef min
2009-11-21 00:35:18 +02:00
2009-04-15 17:03:31 +03:00
/*
* CHeroWindow . cpp , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
2008-01-19 15:19:58 +02:00
extern SDL_Surface * screen ;
2008-08-26 00:14:00 +03:00
using namespace boost : : assign ;
2010-07-13 08:25:40 +03:00
void CHeroSwitcher : : clickLeft ( tribool down , bool previousState )
{
if ( ! down )
{
owner - > deactivate ( ) ;
const CGHeroInstance * buf = LOCPLINT - > getWHero ( id ) ;
owner - > setHero ( buf ) ;
owner - > redrawCurBack ( ) ;
owner - > activate ( ) ;
}
}
CHeroSwitcher : : CHeroSwitcher ( )
{
used = LCLICK ;
}
2008-01-30 12:55:43 +02:00
CHeroWindow : : CHeroWindow ( int playerColor ) :
2009-06-18 18:05:00 +03:00
player ( playerColor )
2008-01-10 21:01:25 +02:00
{
2008-06-12 09:45:51 +03:00
background = BitmapHandler : : loadBitmap ( " HEROSCR4.bmp " ) ;
2008-06-30 03:06:41 +03:00
graphics - > blueToPlayersAdv ( background , playerColor ) ;
2008-11-28 03:36:34 +02:00
pos . x = screen - > w / 2 - background - > w / 2 - 65 ;
pos . y = screen - > h / 2 - background - > h / 2 - 8 ;
2008-01-10 21:01:25 +02:00
pos . h = background - > h ;
pos . w = background - > w ;
2008-01-15 20:50:52 +02:00
curBack = NULL ;
curHero = NULL ;
2010-02-01 01:30:47 +02:00
char bufor [ 400 ] ;
2009-06-18 18:05:00 +03:00
2010-07-20 09:05:45 +03:00
artifs = new CArtifactsOfHero ( pos . topLeft ( ) ) ;
2009-07-26 18:37:27 +03:00
artifs - > commonInfo = new CArtifactsOfHero : : SCommonPart ;
2009-11-28 21:55:40 +02:00
artifs - > commonInfo - > participants . insert ( artifs ) ;
2008-01-11 20:56:39 +02:00
2009-04-14 15:47:09 +03:00
garr = NULL ;
2008-11-28 03:36:34 +02:00
ourBar = new CStatusBar ( pos . x + 72 , pos . y + 567 , " ADROLLVR.bmp " , 660 ) ;
2008-01-30 15:18:08 +02:00
2008-11-28 03:36:34 +02:00
quitButton = new AdventureMapButton ( CGI - > generaltexth - > heroscrn [ 17 ] , std : : string ( ) , boost : : function < void ( ) > ( ) , pos . x + 674 , pos . y + 524 , " hsbtns.def " , SDLK_RETURN ) ;
dismissButton = new AdventureMapButton ( std : : string ( ) , CGI - > generaltexth - > heroscrn [ 28 ] , boost : : bind ( & CHeroWindow : : dismissCurrent , this ) , pos . x + 519 , pos . y + 437 , " hsbtns2.def " , SDLK_d ) ;
questlogButton = new AdventureMapButton ( CGI - > generaltexth - > heroscrn [ 0 ] , std : : string ( ) , boost : : bind ( & CHeroWindow : : questlog , this ) , pos . x + 379 , pos . y + 437 , " hsbtns4.def " , SDLK_q ) ;
2008-01-12 14:55:45 +02:00
2008-09-24 11:15:49 +03:00
formations = new CHighlightableButtonsGroup ( 0 ) ;
2008-11-28 03:36:34 +02:00
formations - > addButton ( map_list_of ( 0 , CGI - > generaltexth - > heroscrn [ 23 ] ) , CGI - > generaltexth - > heroscrn [ 29 ] , " hsbtns6.def " , pos . x + 546 , pos . y + 491 , 0 , 0 , SDLK_t ) ;
formations - > addButton ( map_list_of ( 0 , CGI - > generaltexth - > heroscrn [ 24 ] ) , CGI - > generaltexth - > heroscrn [ 30 ] , " hsbtns7.def " , pos . x + 546 , pos . y + 527 , 1 , 0 , SDLK_l ) ;
2008-09-24 11:15:49 +03:00
2008-09-19 11:16:19 +03:00
2008-11-28 03:36:34 +02:00
gar2button = new CHighlightableButton ( 0 , 0 , map_list_of ( 0 , CGI - > generaltexth - > heroscrn [ 26 ] ) ( 3 , CGI - > generaltexth - > heroscrn [ 25 ] ) , CGI - > generaltexth - > heroscrn [ 31 ] , false , " hsbtns8.def " , NULL , pos . x + 604 , pos . y + 491 , SDLK_b ) ;
2008-01-13 21:42:21 +02:00
2009-06-19 15:10:36 +03:00
//right list of heroes
2008-01-13 21:42:21 +02:00
for ( int g = 0 ; g < 8 ; + + g )
{
2008-01-25 21:09:41 +02:00
//heroList.push_back(new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::switchHero, 677, 95+g*54, "hsbtns5.def", this));
2010-07-13 08:25:40 +03:00
heroListMi . push_back ( new CHeroSwitcher ( ) ) ;
2009-06-19 15:10:36 +03:00
heroListMi [ g ] - > pos = genRect ( 32 , 48 , pos . x + 677 , pos . y + 95 + g * 54 ) ;
2008-01-25 21:09:41 +02:00
heroListMi [ g ] - > owner = this ;
heroListMi [ g ] - > id = g ;
2008-01-13 21:42:21 +02:00
}
2008-11-28 03:36:34 +02:00
2009-06-17 19:46:16 +03:00
flags = CDefHandler : : giveDefEss ( " CREST58.DEF " ) ;
2008-01-19 20:58:24 +02:00
//areas
2008-01-27 18:07:27 +02:00
portraitArea = new LRClickableAreaWText ( ) ;
2009-06-19 15:10:36 +03:00
portraitArea - > pos = genRect ( 64 , 58 , pos . x + 83 , pos . y + 26 ) ;
2010-02-01 01:22:25 +02:00
for ( int v = 0 ; v < PRIMARY_SKILLS ; + + v )
2008-01-27 18:07:27 +02:00
{
primSkillAreas . push_back ( new LRClickableAreaWTextComp ( ) ) ;
2010-02-01 01:22:25 +02:00
primSkillAreas [ v ] - > pos = genRect ( 64 , 42 , pos . x + 95 + 70 * v , pos . y + 117 ) ;
2009-03-27 01:05:40 +02:00
primSkillAreas [ v ] - > text = CGI - > generaltexth - > arraytxt [ 2 + v ] ;
2008-01-27 18:07:27 +02:00
primSkillAreas [ v ] - > type = v ;
2010-07-13 08:25:40 +03:00
primSkillAreas [ v ] - > bonusValue = - 1 ; // to be initilized when hero is being set
2010-02-01 01:30:47 +02:00
primSkillAreas [ v ] - > baseType = 0 ;
2010-02-01 01:22:25 +02:00
sprintf ( bufor , CGI - > generaltexth - > heroscrn [ 1 ] . c_str ( ) , CGI - > generaltexth - > primarySkillNames [ v ] . c_str ( ) ) ;
primSkillAreas [ v ] - > hoverText = std : : string ( bufor ) ;
2010-02-01 01:30:47 +02:00
}
2010-02-01 01:22:25 +02:00
specArea = new LRClickableAreaWText ( ) ;
specArea - > pos = genRect ( 42 , 136 , pos . x + 83 , pos . y + 188 ) ;
2010-02-01 01:30:47 +02:00
specArea - > hoverText = CGI - > generaltexth - > heroscrn [ 27 ] ;
2010-02-01 01:22:25 +02:00
2008-01-27 18:07:27 +02:00
expArea = new LRClickableAreaWText ( ) ;
2009-06-19 15:10:36 +03:00
expArea - > pos = genRect ( 42 , 136 , pos . x + 83 , pos . y + 236 ) ;
2008-01-31 14:10:59 +02:00
expArea - > hoverText = CGI - > generaltexth - > heroscrn [ 9 ] ;
2008-01-29 15:55:14 +02:00
2010-07-13 08:25:40 +03:00
morale = new MoraleLuckBox ( true ) ;
2009-02-03 07:28:05 +02:00
morale - > pos = genRect ( 45 , 53 , pos . x + 240 , pos . y + 187 ) ;
2010-07-13 08:25:40 +03:00
luck = new MoraleLuckBox ( false ) ;
2009-02-03 07:28:05 +02:00
luck - > pos = genRect ( 45 , 53 , pos . x + 298 , pos . y + 187 ) ;
2008-01-29 15:55:14 +02:00
spellPointsArea = new LRClickableAreaWText ( ) ;
2009-06-19 15:10:36 +03:00
spellPointsArea - > pos = genRect ( 42 , 136 , pos . x + 227 , pos . y + 236 ) ;
2008-01-31 14:10:59 +02:00
spellPointsArea - > hoverText = CGI - > generaltexth - > heroscrn [ 22 ] ;
2008-01-29 15:55:14 +02:00
2010-02-01 01:22:25 +02:00
for ( int i = 0 ; i < SKILL_PER_HERO ; + + i )
2008-01-28 14:28:18 +02:00
{
secSkillAreas . push_back ( new LRClickableAreaWTextComp ( ) ) ;
2009-06-19 15:10:36 +03:00
secSkillAreas [ i ] - > pos = genRect ( 42 , 136 , pos . x + ( ( i % 2 = = 0 ) ? ( 83 ) : ( 227 ) ) , pos . y + ( 284 + 48 * ( i / 2 ) ) ) ;
2008-01-28 14:28:18 +02:00
secSkillAreas [ i ] - > baseType = 1 ;
}
2008-11-28 03:36:34 +02:00
pos . x + = 65 ;
pos . y + = 8 ;
2008-01-10 21:01:25 +02:00
}
CHeroWindow : : ~ CHeroWindow ( )
{
SDL_FreeSurface ( background ) ;
2008-01-11 20:56:39 +02:00
delete quitButton ;
2008-01-12 14:55:45 +02:00
delete dismissButton ;
delete questlogButton ;
2008-09-24 11:15:49 +03:00
delete formations ;
2008-01-13 18:24:24 +02:00
delete gar2button ;
2009-09-09 09:04:42 +03:00
//delete gar4button;
2008-01-13 21:42:21 +02:00
2008-12-23 15:59:03 +02:00
for ( size_t g = 0 ; g < heroListMi . size ( ) ; + + g )
{
2008-01-25 21:09:41 +02:00
delete heroListMi [ g ] ;
2008-12-23 15:59:03 +02:00
}
2008-01-12 14:55:45 +02:00
2008-12-23 15:59:03 +02:00
if ( curBack )
{
2008-01-12 14:55:45 +02:00
SDL_FreeSurface ( curBack ) ;
2008-12-23 15:59:03 +02:00
}
2008-01-12 14:55:45 +02:00
2008-01-13 18:24:24 +02:00
delete flags ;
2008-01-19 15:19:58 +02:00
2009-04-14 15:47:09 +03:00
delete garr ;
2008-01-31 14:10:59 +02:00
delete ourBar ;
2009-06-18 18:05:00 +03:00
delete artifs ;
2008-01-19 20:58:24 +02:00
delete portraitArea ;
2008-01-27 18:07:27 +02:00
delete expArea ;
2009-02-03 07:28:05 +02:00
delete luck ;
2010-02-01 01:30:47 +02:00
delete morale ;
2010-02-01 01:22:25 +02:00
delete specArea ;
2008-01-29 15:55:14 +02:00
delete spellPointsArea ;
2008-12-21 21:17:35 +02:00
for ( size_t v = 0 ; v < primSkillAreas . size ( ) ; + + v )
2008-01-27 18:07:27 +02:00
{
delete primSkillAreas [ v ] ;
}
2008-12-21 21:17:35 +02:00
for ( size_t v = 0 ; v < secSkillAreas . size ( ) ; + + v )
2008-01-28 14:28:18 +02:00
{
delete secSkillAreas [ v ] ;
}
2008-01-10 21:01:25 +02:00
}
void CHeroWindow : : show ( SDL_Surface * to )
{
2008-01-26 21:36:31 +02:00
if ( curBack )
blitAt ( curBack , pos . x , pos . y , to ) ;
2009-04-14 15:47:09 +03:00
quitButton - > show ( to ) ;
dismissButton - > show ( to ) ;
questlogButton - > show ( to ) ;
formations - > show ( to ) ;
gar2button - > show ( to ) ;
2009-09-09 09:04:42 +03:00
//gar4button->show(to);
2009-04-14 15:47:09 +03:00
garr - > show ( to ) ;
ourBar - > show ( to ) ;
2008-01-30 15:18:08 +02:00
2010-07-23 15:02:15 +03:00
artifs - > showAll ( to ) ;
2008-01-10 21:01:25 +02:00
}
2009-06-19 15:10:36 +03:00
void CHeroWindow : : setHero ( const CGHeroInstance * hero )
2008-01-10 21:01:25 +02:00
{
2008-09-29 00:01:49 +03:00
char bufor [ 400 ] ;
2009-06-19 15:10:36 +03:00
//CGHeroInstance *hero = const_cast<CGHeroInstance*>(Hero); //but don't modify hero! - it's only for easy map reading
2008-01-28 14:28:18 +02:00
if ( ! hero ) //something strange... no hero? it shouldn't happen
2008-01-25 21:09:41 +02:00
{
2008-08-02 18:08:03 +03:00
return ;
2008-01-25 21:09:41 +02:00
}
2008-01-10 21:01:25 +02:00
curHero = hero ;
2008-01-31 14:10:59 +02:00
2010-07-21 22:50:15 +03:00
artifs - > updateState = true ;
artifs - > setHero ( hero ) ;
artifs - > updateState = false ;
2009-06-17 12:38:03 +03:00
//pos temporarily switched, restored later
2008-11-28 03:36:34 +02:00
pos . x - = 65 ;
pos . y - = 8 ;
2010-02-01 01:30:47 +02:00
specArea - > text = CGI - > generaltexth - > hTxts [ hero - > subID ] . longBonus ;
2008-11-28 03:36:34 +02:00
2008-08-28 20:36:34 +03:00
gar2button - > callback . clear ( ) ;
gar2button - > callback2 . clear ( ) ;
2008-09-29 00:01:49 +03:00
sprintf ( bufor , CGI - > generaltexth - > heroscrn [ 16 ] . c_str ( ) , curHero - > name . c_str ( ) , curHero - > type - > heroClass - > name . c_str ( ) ) ;
dismissButton - > hoverTexts [ 0 ] = std : : string ( bufor ) ;
2008-01-31 14:10:59 +02:00
2008-09-29 00:01:49 +03:00
sprintf ( bufor , CGI - > generaltexth - > allTexts [ 15 ] . c_str ( ) , curHero - > name . c_str ( ) , curHero - > type - > heroClass - > name . c_str ( ) ) ;
portraitArea - > hoverText = std : : string ( bufor ) ;
2008-01-31 14:10:59 +02:00
2008-11-28 03:36:34 +02:00
portraitArea - > text = hero - > getBiography ( ) ;
2008-01-19 15:19:58 +02:00
2009-04-14 15:47:09 +03:00
delete garr ;
2009-07-18 00:53:28 +03:00
garr = new CGarrisonInt ( pos . x + 80 , pos . y + 493 , 8 , Point ( ) , curBack , Point ( 16 , 486 ) , curHero ) ;
2009-04-14 15:47:09 +03:00
garr - > update = false ;
2009-09-09 09:04:42 +03:00
AdventureMapButton * split = new AdventureMapButton ( CGI - > generaltexth - > allTexts [ 256 ] , CGI - > generaltexth - > heroscrn [ 32 ] , boost : : bind ( & CGarrisonInt : : splitClick , garr ) , pos . x + 604 , pos . y + 527 , " hsbtns9.def " , false , NULL , false ) ; //deleted by garrison destructor
boost : : algorithm : : replace_first ( split - > hoverTexts [ 0 ] , " %s " , CGI - > generaltexth - > allTexts [ 43 ] ) ;
garr - > splitButtons . push_back ( split ) ;
2008-06-21 16:27:52 +03:00
2009-06-19 15:10:36 +03:00
//primary skills support
2008-12-21 21:17:35 +02:00
for ( size_t g = 0 ; g < primSkillAreas . size ( ) ; + + g )
2008-01-27 18:07:27 +02:00
{
2010-07-13 08:25:40 +03:00
primSkillAreas [ g ] - > bonusValue = hero - > getPrimSkillLevel ( g ) ;
2008-01-27 18:07:27 +02:00
}
2009-07-03 22:57:14 +03:00
2009-06-19 15:10:36 +03:00
//secondary skills support
2009-11-21 00:35:18 +02:00
for ( size_t g = 0 ; g < std : : min ( secSkillAreas . size ( ) , hero - > secSkills . size ( ) ) ; + + g )
2008-01-28 14:28:18 +02:00
{
2009-07-03 22:57:14 +03:00
int skill = hero - > secSkills [ g ] . first ,
level = hero - > secSkills [ g ] . second ;
secSkillAreas [ g ] - > type = skill ;
2010-07-13 08:25:40 +03:00
secSkillAreas [ g ] - > bonusValue = level ;
2009-07-03 22:57:14 +03:00
secSkillAreas [ g ] - > text = CGI - > generaltexth - > skillInfoTexts [ skill ] [ level - 1 ] ;
2008-08-02 18:08:03 +03:00
2009-07-03 22:57:14 +03:00
sprintf ( bufor , CGI - > generaltexth - > heroscrn [ 21 ] . c_str ( ) , CGI - > generaltexth - > levels [ level - 1 ] . c_str ( ) , CGI - > generaltexth - > skillName [ skill ] . c_str ( ) ) ;
2008-09-29 00:01:49 +03:00
secSkillAreas [ g ] - > hoverText = std : : string ( bufor ) ;
2008-01-28 14:28:18 +02:00
}
2008-01-27 18:07:27 +02:00
2009-10-28 12:45:45 +02:00
//printing experience - original format does not support ui64
2009-10-27 22:40:11 +02:00
expArea - > text = CGI - > generaltexth - > allTexts [ 2 ] . c_str ( ) ;
boost : : replace_first ( expArea - > text , " %d " , boost : : lexical_cast < std : : string > ( hero - > level ) ) ;
boost : : replace_first ( expArea - > text , " %d " , boost : : lexical_cast < std : : string > ( CGI - > heroh - > reqExp ( hero - > level + 1 ) ) ) ;
boost : : replace_first ( expArea - > text , " %d " , boost : : lexical_cast < std : : string > ( hero - > exp ) ) ;
2008-09-29 00:01:49 +03:00
2009-06-19 15:10:36 +03:00
//printing spell points
2010-02-01 01:30:47 +02:00
sprintf ( bufor , CGI - > generaltexth - > allTexts [ 205 ] . c_str ( ) , hero - > name . c_str ( ) , hero - > mana , hero - > manaLimit ( ) ) ;
2008-09-29 00:01:49 +03:00
spellPointsArea - > text = std : : string ( bufor ) ;
2008-01-27 18:07:27 +02:00
2008-01-30 12:55:43 +02:00
2010-02-04 17:50:59 +02:00
//if we have exchange window with this hero open
bool noDismiss = false ;
for ( std : : list < IShowActivable * > : : iterator it = GH . listInt . begin ( ) ; it ! = GH . listInt . end ( ) ; it + + )
{
CExchangeWindow * cew = dynamic_cast < CExchangeWindow * > ( ( * it ) ) ;
if ( cew )
for ( int g = 0 ; g < ARRAY_COUNT ( cew - > heroInst ) ; + + g )
if ( cew - > heroInst [ g ] = = hero )
noDismiss = true ;
CKingdomInterface * cki = dynamic_cast < CKingdomInterface * > ( ( * it ) ) ;
if ( cki )
noDismiss = true ;
}
dismissButton - > block ( ! ! hero - > visitedTown | | noDismiss ) ;
2008-09-28 16:29:37 +03:00
if ( hero - > getSecSkillLevel ( 19 ) = = 0 )
2008-08-28 20:36:34 +03:00
gar2button - > block ( true ) ;
else
{
gar2button - > block ( false ) ;
2008-09-18 16:54:54 +03:00
gar2button - > callback = vstd : : assigno ( hero - > tacticFormationEnabled , true ) ;
gar2button - > callback2 = vstd : : assigno ( hero - > tacticFormationEnabled , false ) ;
2008-08-28 20:36:34 +03:00
}
2008-09-24 11:15:49 +03:00
2009-06-19 15:10:36 +03:00
//setting formations
2008-10-26 22:58:34 +02:00
formations - > onChange = 0 ;
2010-05-02 21:20:26 +03:00
formations - > select ( hero - > formation , true ) ;
2009-06-19 15:10:36 +03:00
formations - > onChange = boost : : bind ( & CCallback : : setFormation , LOCPLINT - > cb , hero , _1 ) ;
2008-09-24 11:15:49 +03:00
2010-07-13 08:25:40 +03:00
morale - > set ( hero ) ;
luck - > set ( hero ) ;
2009-02-03 07:28:05 +02:00
2009-06-19 15:10:36 +03:00
//restoring pos
2008-11-28 03:36:34 +02:00
pos . x + = 65 ;
pos . y + = 8 ;
2008-01-26 21:36:31 +02:00
redrawCurBack ( ) ;
2008-01-11 20:56:39 +02:00
}
void CHeroWindow : : quit ( )
{
2009-08-07 01:36:51 +03:00
GH . popInt ( this ) ;
2009-06-10 23:48:55 +03:00
dispose ( ) ;
2008-01-11 20:56:39 +02:00
}
void CHeroWindow : : activate ( )
{
quitButton - > activate ( ) ;
2008-01-12 14:55:45 +02:00
dismissButton - > activate ( ) ;
questlogButton - > activate ( ) ;
2008-01-13 18:24:24 +02:00
gar2button - > activate ( ) ;
2008-09-24 11:15:49 +03:00
formations - > activate ( ) ;
2009-09-09 09:04:42 +03:00
//gar4button->activate();
2010-02-01 01:30:47 +02:00
portraitArea - > activate ( ) ;
2010-02-01 01:22:25 +02:00
specArea - > activate ( ) ;
2008-01-27 18:07:27 +02:00
expArea - > activate ( ) ;
2008-01-29 15:55:14 +02:00
spellPointsArea - > activate ( ) ;
2009-02-03 07:28:05 +02:00
morale - > activate ( ) ;
luck - > activate ( ) ;
2008-01-30 15:18:08 +02:00
2009-04-14 15:47:09 +03:00
garr - > activate ( ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar = ourBar ;
2008-01-30 15:18:08 +02:00
2008-12-21 21:17:35 +02:00
for ( size_t v = 0 ; v < primSkillAreas . size ( ) ; + + v )
2008-01-27 18:07:27 +02:00
{
primSkillAreas [ v ] - > activate ( ) ;
}
2009-11-21 00:35:18 +02:00
for ( size_t v = 0 ; v < std : : min ( secSkillAreas . size ( ) , curHero - > secSkills . size ( ) ) ; + + v )
2008-01-13 21:42:21 +02:00
{
2008-01-28 14:28:18 +02:00
secSkillAreas [ v ] - > activate ( ) ;
2008-01-13 21:42:21 +02:00
}
2008-01-15 20:50:52 +02:00
redrawCurBack ( ) ;
2008-01-20 15:53:11 +02:00
2009-06-18 18:05:00 +03:00
artifs - > activate ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t e = 0 ; e < heroListMi . size ( ) ; + + e )
2008-01-26 21:36:31 +02:00
{
heroListMi [ e ] - > activate ( ) ;
}
2008-01-15 20:50:52 +02:00
}
2008-01-20 14:34:39 +02:00
void CHeroWindow : : deactivate ( )
{
quitButton - > deactivate ( ) ;
dismissButton - > deactivate ( ) ;
questlogButton - > deactivate ( ) ;
gar2button - > deactivate ( ) ;
2010-02-01 01:30:47 +02:00
formations - > deactivate ( ) ;
2010-02-01 01:22:25 +02:00
specArea - > deactivate ( ) ;
2009-09-09 09:04:42 +03:00
//gar4button->deactivate();
2008-01-20 14:34:39 +02:00
portraitArea - > deactivate ( ) ;
2008-01-27 18:07:27 +02:00
expArea - > deactivate ( ) ;
2008-01-29 15:55:14 +02:00
spellPointsArea - > deactivate ( ) ;
2009-02-05 11:49:45 +02:00
morale - > deactivate ( ) ;
luck - > deactivate ( ) ;
2008-01-30 15:18:08 +02:00
2009-04-14 15:47:09 +03:00
garr - > deactivate ( ) ;
2008-01-30 15:18:08 +02:00
2008-12-21 21:17:35 +02:00
for ( size_t v = 0 ; v < primSkillAreas . size ( ) ; + + v )
2008-01-27 18:07:27 +02:00
{
primSkillAreas [ v ] - > deactivate ( ) ;
}
2009-11-21 00:35:18 +02:00
for ( size_t v = 0 ; v < std : : min ( secSkillAreas . size ( ) , curHero - > secSkills . size ( ) ) ; + + v )
2008-01-25 21:09:41 +02:00
{
2008-01-28 14:28:18 +02:00
secSkillAreas [ v ] - > deactivate ( ) ;
2008-01-25 21:09:41 +02:00
}
2009-06-18 18:05:00 +03:00
artifs - > deactivate ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t e = 0 ; e < heroListMi . size ( ) ; + + e )
2008-01-26 21:36:31 +02:00
{
heroListMi [ e ] - > deactivate ( ) ;
}
2008-01-20 14:34:39 +02:00
}
2008-01-15 20:50:52 +02:00
void CHeroWindow : : dismissCurrent ( )
{
2008-08-27 13:19:18 +03:00
CFunctionList < void ( ) > ony = boost : : bind ( & CHeroWindow : : quit , this ) ;
ony + = boost : : bind ( & CCallback : : dismissHero , LOCPLINT - > cb , curHero ) ;
2009-04-14 15:47:09 +03:00
LOCPLINT - > showYesNoDialog ( CGI - > generaltexth - > allTexts [ 22 ] , std : : vector < SComponent * > ( ) , ony , 0 , false ) ;
2008-01-15 20:50:52 +02:00
}
void CHeroWindow : : questlog ( )
{
}
2009-04-04 01:34:31 +03:00
2008-01-15 20:50:52 +02:00
void CHeroWindow : : redrawCurBack ( )
{
if ( curBack )
SDL_FreeSurface ( curBack ) ;
2008-02-10 15:09:56 +02:00
curBack = SDL_DisplayFormat ( background ) ;
2008-01-15 20:50:52 +02:00
2009-06-26 18:41:19 +03:00
//primary skills & exp and mana
2008-08-13 03:44:31 +03:00
blitAt ( graphics - > pskillsm - > ourImages [ 0 ] . bitmap , 32 , 111 , curBack ) ;
blitAt ( graphics - > pskillsm - > ourImages [ 1 ] . bitmap , 102 , 111 , curBack ) ;
blitAt ( graphics - > pskillsm - > ourImages [ 2 ] . bitmap , 172 , 111 , curBack ) ;
blitAt ( graphics - > pskillsm - > ourImages [ 5 ] . bitmap , 242 , 111 , curBack ) ;
blitAt ( graphics - > pskillsm - > ourImages [ 4 ] . bitmap , 20 , 230 , curBack ) ;
blitAt ( graphics - > pskillsm - > ourImages [ 3 ] . bitmap , 162 , 230 , curBack ) ;
2008-01-13 18:24:24 +02:00
2009-06-17 12:38:03 +03:00
//blitting portrait
2008-08-02 18:08:03 +03:00
blitAt ( graphics - > portraitLarge [ curHero - > portrait ] , 19 , 19 , curBack ) ;
2008-01-13 18:24:24 +02:00
2009-06-17 12:38:03 +03:00
//printing hero's name
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( curHero - > name , 190 , 38 , FONT_BIG , tytulowy , curBack ) ;
2008-01-13 18:24:24 +02:00
2009-06-17 12:38:03 +03:00
//printing hero's level
2009-06-17 19:46:16 +03:00
std : : ostringstream secondLine ;
2008-01-13 18:24:24 +02:00
secondLine < < " Level " < < curHero - > level < < " " < < curHero - > type - > heroClass - > name ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( secondLine . str ( ) , 190 , 65 , FONT_MEDIUM , zwykly , curBack ) ;
2008-01-13 18:24:24 +02:00
2009-06-01 06:04:50 +03:00
//primary skills names
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > jktexts [ 1 ] , 52 , 99 , FONT_SMALL , tytulowy , curBack ) ;
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > jktexts [ 2 ] , 123 , 99 , FONT_SMALL , tytulowy , curBack ) ;
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > jktexts [ 3 ] , 193 , 99 , FONT_SMALL , tytulowy , curBack ) ;
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > jktexts [ 4 ] , 262 , 99 , FONT_SMALL , tytulowy , curBack ) ;
2008-01-13 18:24:24 +02:00
2008-01-15 20:50:52 +02:00
//dismiss / quest log
2010-07-06 05:10:26 +03:00
std : : vector < std : : string > toPrin = CMessage : : breakText ( CGI - > generaltexth - > jktexts [ 8 ] . substr ( 1 , CGI - > generaltexth - > jktexts [ 8 ] . size ( ) - 2 ) ) ;
if ( toPrin . size ( ) = = 1 )
2008-01-15 20:50:52 +02:00
{
2010-07-06 05:10:26 +03:00
CSDL_Ext : : printAt ( toPrin [ 0 ] , 372 , 439 , FONT_SMALL , zwykly , curBack ) ;
2008-01-15 20:50:52 +02:00
}
else
{
2010-07-06 05:10:26 +03:00
CSDL_Ext : : printAt ( toPrin [ 0 ] , 372 , 430 , FONT_SMALL , zwykly , curBack ) ;
CSDL_Ext : : printAt ( toPrin [ 1 ] , 372 , 446 , FONT_SMALL , zwykly , curBack ) ;
2008-01-15 20:50:52 +02:00
}
toPrin = CMessage : : breakText ( CGI - > generaltexth - > jktexts [ 9 ] . substr ( 1 , CGI - > generaltexth - > jktexts [ 9 ] . size ( ) - 2 ) ) ;
2010-07-06 05:10:26 +03:00
if ( toPrin . size ( ) = = 1 )
2008-01-15 20:50:52 +02:00
{
2010-07-06 05:10:26 +03:00
CSDL_Ext : : printAt ( toPrin [ 0 ] , 512 , 439 , FONT_SMALL , zwykly , curBack ) ;
2008-01-15 20:50:52 +02:00
}
else
{
2010-07-06 05:10:26 +03:00
CSDL_Ext : : printAt ( toPrin [ 0 ] , 512 , 430 , FONT_SMALL , zwykly , curBack ) ;
CSDL_Ext : : printAt ( toPrin [ 1 ] , 512 , 446 , FONT_SMALL , zwykly , curBack ) ;
2008-01-15 20:50:52 +02:00
}
//printing primary skills' amounts
2009-06-17 19:46:16 +03:00
for ( int m = 0 ; m < 4 ; + + m )
{
std : : ostringstream primarySkill ;
primarySkill < < curHero - > getPrimSkillLevel ( m ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( primarySkill . str ( ) , 53 + 70 * m , 166 , FONT_SMALL , zwykly , curBack ) ;
2009-06-17 19:46:16 +03:00
}
2008-01-13 18:24:24 +02:00
2009-06-26 18:41:19 +03:00
//morale and luck printing
2010-05-02 21:20:26 +03:00
blitAt ( graphics - > luck42 - > ourImages [ curHero - > LuckVal ( ) + 3 ] . bitmap , 239 , 182 , curBack ) ;
blitAt ( graphics - > morale42 - > ourImages [ curHero - > MoraleVal ( ) + 3 ] . bitmap , 181 , 182 , curBack ) ;
2008-01-13 18:24:24 +02:00
blitAt ( flags - > ourImages [ player ] . bitmap , 606 , 8 , curBack ) ;
2008-01-13 21:42:21 +02:00
//hero list blitting
2009-06-10 04:23:17 +03:00
2009-06-11 20:21:06 +03:00
for ( int pos = 0 , g = 0 ; g < LOCPLINT - > wanderingHeroes . size ( ) ; + + g )
2008-01-13 21:42:21 +02:00
{
2009-06-11 20:21:06 +03:00
const CGHeroInstance * cur = LOCPLINT - > wanderingHeroes [ g ] ;
2009-06-10 04:23:17 +03:00
if ( cur - > inTownGarrison )
// Only display heroes that are not in garrison
continue ;
blitAt ( graphics - > portraitSmall [ cur - > portrait ] , 611 , 87 + pos * 54 , curBack ) ;
2008-01-13 21:42:21 +02:00
//printing yellow border
if ( cur - > name = = curHero - > name )
{
2008-08-02 18:08:03 +03:00
for ( int f = 0 ; f < graphics - > portraitSmall [ cur - > portrait ] - > w ; + + f )
2008-01-13 21:42:21 +02:00
{
2008-08-02 18:08:03 +03:00
for ( int h = 0 ; h < graphics - > portraitSmall [ cur - > portrait ] - > h ; + + h )
if ( f = = 0 | | h = = 0 | | f = = graphics - > portraitSmall [ cur - > portrait ] - > w - 1 | | h = = graphics - > portraitSmall [ cur - > portrait ] - > h - 1 )
2008-01-13 21:42:21 +02:00
{
2009-06-10 04:23:17 +03:00
CSDL_Ext : : SDL_PutPixelWithoutRefresh ( curBack , 611 + f , 87 + pos * 54 + h , 240 , 220 , 120 ) ;
2008-01-13 21:42:21 +02:00
}
}
}
2009-06-10 04:23:17 +03:00
pos + + ;
2008-01-13 21:42:21 +02:00
}
2008-01-15 20:50:52 +02:00
//secondary skills
2009-06-17 19:46:16 +03:00
for ( int g = 1 ; g < = 8 ; + + g )
2008-01-15 20:50:52 +02:00
{
2009-06-17 19:46:16 +03:00
if ( curHero - > secSkills . size ( ) > = g )
{
blitAt ( graphics - > abils44 - > ourImages [ curHero - > secSkills [ g - 1 ] . first * 3 + 3 + curHero - > secSkills [ g - 1 ] . second - 1 ] . bitmap , g % 2 ? 18 : 161 , 276 + 48 * ( ( g - 1 ) / 2 ) , curBack ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > levels [ curHero - > secSkills [ g - 1 ] . second - 1 ] , g % 2 ? 68 : 212 , 280 + 48 * ( ( g - 1 ) / 2 ) , FONT_SMALL , zwykly , curBack ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > skillName [ curHero - > secSkills [ g - 1 ] . first ] , g % 2 ? 68 : 212 , 300 + 48 * ( ( g - 1 ) / 2 ) , FONT_SMALL , zwykly , curBack ) ;
2009-06-17 19:46:16 +03:00
}
2008-01-15 20:50:52 +02:00
}
//printing special ability
2010-02-01 01:30:47 +02:00
blitAt ( graphics - > un44 - > ourImages [ curHero - > subID ] . bitmap , 18 , 180 , curBack ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > jktexts [ 5 ] . substr ( 1 , CGI - > generaltexth - > jktexts [ 5 ] . size ( ) - 2 ) , 69 , 183 , FONT_SMALL , tytulowy , curBack ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > hTxts [ curHero - > subID ] . bonusName , 69 , 205 , FONT_SMALL , zwykly , curBack ) ;
2008-01-15 20:50:52 +02:00
//printing necessery texts
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > jktexts [ 6 ] . substr ( 1 , CGI - > generaltexth - > jktexts [ 6 ] . size ( ) - 2 ) , 69 , 232 , FONT_SMALL , tytulowy , curBack ) ;
2009-06-17 19:46:16 +03:00
std : : ostringstream expstr ;
2008-01-15 20:50:52 +02:00
expstr < < curHero - > exp ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAt ( expstr . str ( ) , 68 , 252 , FONT_SMALL , zwykly , curBack ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > jktexts [ 7 ] . substr ( 1 , CGI - > generaltexth - > jktexts [ 7 ] . size ( ) - 2 ) , 213 , 232 , FONT_SMALL , tytulowy , curBack ) ;
2009-06-17 19:46:16 +03:00
std : : ostringstream manastr ;
2009-05-22 22:20:30 +03:00
manastr < < curHero - > mana < < ' / ' < < curHero - > manaLimit ( ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAt ( manastr . str ( ) , 211 , 252 , FONT_SMALL , zwykly , curBack ) ;
2008-01-19 15:19:58 +02:00
}
2009-06-10 23:48:55 +03:00
void CHeroWindow : : dispose ( )
{
SDL_FreeSurface ( curBack ) ;
curBack = NULL ;
curHero = NULL ;
2009-06-18 18:05:00 +03:00
artifs - > dispose ( ) ;
2008-01-27 18:07:27 +02:00
}
2008-01-25 21:09:41 +02:00
2010-02-26 13:18:09 +02:00
void CHeroWindow : : setPlayer ( int Player )
{
player = Player ;
graphics - > blueToPlayersAdv ( background , player ) ;
}