2009-05-20 13:08:56 +03:00
# include "../stdafx.h"
2008-08-02 18:08:03 +03:00
# include "CPreGame.h"
2009-01-12 22:05:56 +02:00
# include <ctime>
2008-12-21 21:17:35 +02:00
# include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
# include <boost/algorithm/string.hpp>
# include <zlib.h>
2009-05-20 13:08:56 +03:00
# include "../timeHandler.h"
2008-08-02 18:08:03 +03:00
# include <sstream>
# include "SDL_Extensions.h"
# include "CGameInfo.h"
# include "CCursorHandler.h"
2010-11-15 17:15:00 +02:00
# include "CAnimation.h"
2010-12-20 23:22:53 +02:00
# include "CDefHandler.h"
# include "../lib/CDefObjInfoHandler.h"
# include "../lib/CGeneralTextHandler.h"
# include "../lib/CLodHandler.h"
# include "../lib/CTownHandler.h"
# include "../lib/CHeroHandler.h"
# include "../lib/CObjectHandler.h"
# include "../lib/CCampaignHandler.h"
# include "../lib/CCreatureHandler.h"
# include "CMusicHandler.h"
# include "CVideoHandler.h"
2008-08-02 18:08:03 +03:00
# include <cmath>
2009-05-20 13:08:56 +03:00
# include "Graphics.h"
2009-08-17 11:50:31 +03:00
//#include <boost/thread.hpp>
2008-08-02 18:08:03 +03:00
# include <boost/bind.hpp>
2011-04-01 22:09:05 +03:00
# include <boost/function.hpp>
# include <boost/ref.hpp>
2008-12-21 21:17:35 +02:00
# include <cstdlib>
2009-05-20 13:08:56 +03:00
# include "../lib/Connection.h"
2009-10-10 08:47:59 +03:00
# include "../lib/VCMIDirs.h"
2010-02-13 18:26:47 +02:00
# include "../lib/map.h"
2009-08-17 11:50:31 +03:00
# include "AdventureMapButton.h"
2009-08-22 16:59:15 +03:00
# include "GUIClasses.h"
2009-08-27 11:04:32 +03:00
# include "CPlayerInterface.h"
# include "../CCallback.h"
2009-08-28 22:34:08 +03:00
# include <boost/lexical_cast.hpp>
2010-02-08 16:38:06 +02:00
# include <cstdlib>
# include "CMessage.h"
2010-12-20 23:22:53 +02:00
# include "../lib/CSpellHandler.h" /*for campaign bonuses*/
# include "../lib/CArtHandler.h" /*for campaign bonuses*/
# include "../lib/CBuildingHandler.h" /*for campaign bonuses*/
2010-08-17 17:58:13 +03:00
# include "CBitmapHandler.h"
2010-09-03 21:42:54 +03:00
# include "Client.h"
# include "../lib/NetPacks.h"
# include "../lib/RegisterTypes.cpp"
2010-10-24 14:35:14 +03:00
# include <boost/thread/recursive_mutex.hpp>
2011-02-24 15:57:47 +02:00
# include "../CThreadHelper.h"
2011-04-17 21:02:13 +03:00
# include "CConfigHandler.h"
2011-06-20 14:41:04 +03:00
# include "../lib/CFileUtility.h"
2010-08-02 17:29:30 +03:00
2009-04-15 17:03:31 +03:00
/*
* CPreGame . 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
*
*/
2009-08-17 13:47:08 +03:00
namespace fs = boost : : filesystem ;
2009-08-27 11:04:32 +03:00
using boost : : bind ;
using boost : : ref ;
2010-02-20 15:24:38 +02:00
# if _MSC_VER >= 1600
# define bind boost::bind
# define ref boost::ref
# endif
2010-10-24 14:35:14 +03:00
void startGame ( StartInfo * options , CConnection * serv = NULL ) ;
extern SystemOptions GDefaultOptions ;
2009-04-15 17:03:31 +03:00
2009-08-17 11:50:31 +03:00
CGPreGame * CGP ;
2010-10-24 14:35:14 +03:00
ISelectionScreenInfo * SEL ;
2010-10-30 17:53:23 +03:00
static int playerColor ; //if more than one player - applies to the first
2008-12-21 21:17:35 +02:00
2009-08-27 11:04:32 +03:00
static std : : string selectedName ; //set when game is started/loaded
2010-10-24 14:35:14 +03:00
struct EvilHlpStruct
{
CConnection * serv ;
StartInfo * sInfo ;
void reset ( bool strong = true )
{
if ( strong )
{
delNull ( serv ) ;
delNull ( sInfo ) ;
}
else
{
serv = NULL ;
sInfo = NULL ;
}
}
} startingInfo ;
2009-11-01 03:15:16 +02:00
static void do_quit ( )
{
SDL_Event event ;
event . quit . type = SDL_QUIT ;
SDL_PushEvent ( & event ) ;
}
2009-10-26 07:39:30 +02:00
2010-03-08 00:56:51 +02:00
static CMapInfo * mapInfoFromGame ( )
{
CMapInfo * ret = new CMapInfo ( ) ;
CMapHeader * headerCopy = new CMapHeader ( * LOCPLINT - > cb - > getMapHeader ( ) ) ; //will be deleted by CMapInfo d-tor
ret - > setHeader ( headerCopy ) ;
return ret ;
}
static void setPlayersFromGame ( )
{
playerColor = LOCPLINT - > playerID ;
}
2010-10-24 14:35:14 +03:00
static void swapPlayers ( PlayerSettings & a , PlayerSettings & b )
2010-03-08 00:56:51 +02:00
{
2010-10-24 14:35:14 +03:00
std : : swap ( a . human , b . human ) ;
std : : swap ( a . name , b . name ) ;
if ( a . human = = 1 )
playerColor = a . color ;
else if ( b . human = = 1 )
playerColor = b . color ;
2010-03-08 00:56:51 +02:00
}
2010-10-30 17:53:23 +03:00
void setPlayer ( PlayerSettings & pset , unsigned player , const std : : map < ui32 , std : : string > & playerNames )
{
if ( vstd : : contains ( playerNames , player ) )
pset . name = playerNames . find ( player ) - > second ;
else
pset . name = CGI - > generaltexth - > allTexts [ 468 ] ; //Computer
pset . human = player ;
if ( player = = playerNames . begin ( ) - > first )
playerColor = pset . color ;
}
void updateStartInfo ( std : : string filename , StartInfo & sInfo , const CMapHeader * mapHeader , const std : : map < ui32 , std : : string > & playerNames )
{
sInfo . playerInfos . clear ( ) ;
if ( ! filename . size ( ) )
return ;
/*sInfo.playerInfos.resize(to->playerAmnt);*/
sInfo . mapname = filename ;
playerColor = - 1 ;
std : : map < ui32 , std : : string > : : const_iterator namesIt = playerNames . begin ( ) ;
for ( int i = 0 ; i < PLAYER_LIMIT ; i + + )
{
const PlayerInfo & pinfo = mapHeader - > players [ i ] ;
//neither computer nor human can play - no player
if ( ! ( pinfo . canComputerPlay | | pinfo . canComputerPlay ) )
continue ;
PlayerSettings & pset = sInfo . playerInfos [ i ] ;
pset . color = i ;
if ( pinfo . canHumanPlay & & namesIt ! = playerNames . end ( ) )
setPlayer ( pset , namesIt + + - > first , playerNames ) ;
else
setPlayer ( pset , 0 , playerNames ) ;
pset . castle = pinfo . defaultCastle ( ) ;
2011-03-19 16:35:29 +02:00
pset . hero = pinfo . defaultHero ( ) ;
2010-10-30 17:53:23 +03:00
if ( pinfo . mainHeroName . length ( ) )
{
pset . heroName = pinfo . mainHeroName ;
if ( ( pset . heroPortrait = pinfo . mainHeroPortrait ) = = 255 )
pset . heroPortrait = pinfo . p9 ;
}
pset . handicap = 0 ;
}
}
2010-09-04 17:47:39 +03:00
template < typename T > class CApplyOnPG ;
2010-09-03 21:42:54 +03:00
class CBaseForPGApply
{
public :
virtual void applyOnPG ( CSelectionScreen * selScr , void * pack ) const = 0 ;
virtual ~ CBaseForPGApply ( ) { } ;
template < typename U > static CBaseForPGApply * getApplier ( const U * t = NULL )
{
return new CApplyOnPG < U > ;
}
} ;
template < typename T > class CApplyOnPG : public CBaseForPGApply
{
public :
void applyOnPG ( CSelectionScreen * selScr , void * pack ) const
{
T * ptr = static_cast < T * > ( pack ) ;
ptr - > apply ( selScr ) ;
}
} ;
2010-09-04 17:47:39 +03:00
static CApplier < CBaseForPGApply > * applier = NULL ;
2010-09-03 21:42:54 +03:00
2009-08-17 11:50:31 +03:00
CMenuScreen : : CMenuScreen ( EState which )
2009-02-06 13:15:39 +02:00
{
2011-03-29 20:16:10 +03:00
OBJ_CONSTRUCTION ;
2009-08-17 11:50:31 +03:00
bgAd = NULL ;
switch ( which )
2009-02-06 13:15:39 +02:00
{
2009-08-17 11:50:31 +03:00
case mainMenu :
2009-02-06 13:15:39 +02:00
{
2011-03-15 16:35:36 +02:00
buttons [ 0 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 3 ] . second , // New game
bind ( & CMenuScreen : : moveTo , this , ref ( CGP - > scrs [ newGame ] ) ) , 540 , 10 , " ZMENUNG.DEF " , SDLK_n ) ;
buttons [ 1 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 4 ] . second , // Load game
bind ( & CMenuScreen : : moveTo , this , ref ( CGP - > scrs [ loadGame ] ) ) , 532 , 132 , " ZMENULG.DEF " , SDLK_l ) ;
buttons [ 2 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 5 ] . second , 0 , 524 , 251 , " ZMENUHS.DEF " , SDLK_h ) ; // Highscore
buttons [ 3 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 6 ] . second , 0 /*cb*/ , 557 , 359 , " ZMENUCR.DEF " , SDLK_c ) ; // Credits
2011-04-01 22:09:05 +03:00
boost : : function < void ( ) > confWindow = bind ( CInfoWindow : : showYesNoDialog , ref ( CGI - > generaltexth - > allTexts [ 69 ] ) , ( const std : : vector < SComponent * > * ) 0 , do_quit , 0 , false , 1 ) ;
2011-03-15 16:35:36 +02:00
buttons [ 4 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 7 ] . second , confWindow , 586 , 468 , " ZMENUQT.DEF " , SDLK_ESCAPE ) ; // Exit
2009-02-06 13:15:39 +02:00
}
2009-08-17 11:50:31 +03:00
break ;
case newGame :
2009-02-06 13:15:39 +02:00
{
2009-11-24 21:50:20 +02:00
bgAd = new CPicture ( BitmapHandler : : loadBitmap ( " ZNEWGAM.bmp " ) , 114 , 312 , true ) ;
2011-03-15 16:35:36 +02:00
buttons [ 0 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 10 ] . second , // Single player
bind ( & CGPreGame : : openSel , CGP , newGame , SINGLE_PLAYER ) , 545 , 4 , " ZTSINGL.DEF " , SDLK_s ) ;
2011-01-17 18:07:08 +02:00
buttons [ 1 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 12 ] . second , & pushIntT < CMultiMode > , 568 , 120 , " ZTMULTI.DEF " , SDLK_m ) ;
buttons [ 2 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 11 ] . second , bind ( & CMenuScreen : : moveTo , this , ref ( CGP - > scrs [ campaignMain ] ) ) , 541 , 233 , " ZTCAMPN.DEF " , SDLK_c ) ;
2009-08-17 11:50:31 +03:00
buttons [ 3 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 13 ] . second , 0 /*cb*/ , 545 , 358 , " ZTTUTOR.DEF " , SDLK_t ) ;
buttons [ 4 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 14 ] . second , bind ( & CMenuScreen : : moveTo , this , CGP - > scrs [ mainMenu ] ) , 582 , 464 , " ZTBACK.DEF " , SDLK_ESCAPE ) ;
}
break ;
case loadGame :
{
2009-11-24 21:50:20 +02:00
bgAd = new CPicture ( BitmapHandler : : loadBitmap ( " ZLOADGAM.bmp " ) , 114 , 312 , true ) ;
2010-09-03 21:42:54 +03:00
buttons [ 0 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 10 ] . second , bind ( & CGPreGame : : openSel , CGP , loadGame , SINGLE_PLAYER ) , 545 , 4 , " ZTSINGL.DEF " , SDLK_s ) ;
2011-01-17 18:07:08 +02:00
buttons [ 1 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 12 ] . second , bind ( & CGPreGame : : openSel , CGP , loadGame , MULTI_HOT_SEAT ) , 568 , 120 , " ZTMULTI.DEF " , SDLK_m ) ;
buttons [ 2 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 11 ] . second , 0 /*cb*/ , 541 , 233 , " ZTCAMPN.DEF " , SDLK_c ) ;
2009-08-17 11:50:31 +03:00
buttons [ 3 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 13 ] . second , 0 /*cb*/ , 545 , 358 , " ZTTUTOR.DEF " , SDLK_t ) ;
buttons [ 4 ] = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 14 ] . second , bind ( & CMenuScreen : : moveTo , this , CGP - > scrs [ mainMenu ] ) , 582 , 464 , " ZTBACK.DEF " , SDLK_ESCAPE ) ;
2009-02-06 13:15:39 +02:00
}
2009-08-17 11:50:31 +03:00
break ;
2010-02-08 16:38:06 +02:00
case campaignMain :
{
2011-03-17 05:56:36 +02:00
buttons [ 0 ] = new AdventureMapButton ( " " , " " , bind ( & CGPreGame : : openCampaignScreen , CGP , CCampaignScreen : : WOG ) , 535 , 8 , " ZSSSOD.DEF " , SDLK_s ) ; // WOG
buttons [ 1 ] = new AdventureMapButton ( " " , " " , bind ( & CGPreGame : : openCampaignScreen , CGP , CCampaignScreen : : ROE ) , 494 , 117 , " ZSSROE.DEF " , SDLK_m ) ; // ROE
2011-03-19 16:27:51 +02:00
buttons [ 2 ] = new AdventureMapButton ( " " , " " , bind ( & CGPreGame : : openCampaignScreen , CGP , CCampaignScreen : : AB ) , 486 , 241 , " ZSSARM.DEF " , SDLK_c ) ; // AB
2011-03-15 16:35:36 +02:00
buttons [ 3 ] = new AdventureMapButton ( " " , " " , bind ( & CGPreGame : : openSel , CGP , campaignList , SINGLE_PLAYER ) , 550 , 358 , " ZSSCUS.DEF " , SDLK_t ) ; // Custom
2011-04-23 13:27:44 +03:00
buttons [ 4 ] = new AdventureMapButton ( " " , " " , bind ( & CMenuScreen : : moveTo , this , CGP - > scrs [ newGame ] ) , 582 , 464 , " ZTBACK.DEF " , SDLK_ESCAPE ) ; // Back
2010-02-11 16:12:22 +02:00
2010-02-08 16:38:06 +02:00
}
break ;
2009-02-06 13:15:39 +02:00
}
2009-08-17 11:50:31 +03:00
for ( int i = 0 ; i < ARRAY_COUNT ( buttons ) ; i + + )
buttons [ i ] - > hoverable = true ;
2009-02-06 13:15:39 +02:00
}
2009-08-17 11:50:31 +03:00
CMenuScreen : : ~ CMenuScreen ( )
2008-08-06 01:11:32 +03:00
{
2009-08-17 11:50:31 +03:00
}
void CMenuScreen : : showAll ( SDL_Surface * to )
2008-08-06 01:11:32 +03:00
{
2009-08-17 11:50:31 +03:00
blitAt ( CGP - > mainbg , 0 , 0 , to ) ;
CIntObject : : showAll ( to ) ;
2008-08-06 01:11:32 +03:00
}
2009-08-17 11:50:31 +03:00
void CMenuScreen : : show ( SDL_Surface * to )
2009-01-25 18:19:34 +02:00
{
2011-07-23 02:34:15 +03:00
CCS - > videoh - > update ( pos . x + 8 , pos . y + 105 , to , true , false ) ;
CIntObject : : show ( to ) ;
2009-01-25 18:19:34 +02:00
}
2009-08-17 11:50:31 +03:00
void CMenuScreen : : moveTo ( CMenuScreen * next )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
GH . popInt ( this ) ;
GH . pushInt ( next ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
CGPreGame : : CGPreGame ( )
2008-08-02 18:08:03 +03:00
{
2009-08-27 11:04:32 +03:00
GH . defActionsDef = 63 ;
2009-08-17 11:50:31 +03:00
CGP = this ;
mainbg = BitmapHandler : : loadBitmap ( " ZPIC1005.bmp " ) ;
for ( int i = 0 ; i < ARRAY_COUNT ( scrs ) ; i + + )
2010-02-13 18:26:47 +02:00
scrs [ i ] = new CMenuScreen ( ( CMenuScreen : : EState ) i ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
CGPreGame : : ~ CGPreGame ( )
2008-08-06 01:11:32 +03:00
{
2009-08-17 11:50:31 +03:00
SDL_FreeSurface ( mainbg ) ;
for ( int i = 0 ; i < ARRAY_COUNT ( scrs ) ; i + + )
delete scrs [ i ] ;
2008-08-06 01:11:32 +03:00
}
2009-08-17 11:50:31 +03:00
2010-10-24 14:35:14 +03:00
void CGPreGame : : openSel ( CMenuScreen : : EState screenType , CMenuScreen : : EMultiMode multi /*= CMenuScreen::SINGLE_PLAYER*/ )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
GH . pushInt ( new CSelectionScreen ( screenType , multi ) ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
2011-03-15 16:35:36 +02:00
void CGPreGame : : openCampaignScreen ( CCampaignScreen : : CampaignSet campaigns )
{
std : : map < std : : string , CCampaignScreen : : CampaignStatus > defaultCamp ;
GH . pushInt ( new CCampaignScreen ( campaigns , defaultCamp ) ) ;
}
2009-08-17 11:50:31 +03:00
void CGPreGame : : loadGraphics ( )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
victory = CDefHandler : : giveDef ( " SCNRVICT.DEF " ) ;
loss = CDefHandler : : giveDef ( " SCNRLOSS.DEF " ) ;
bonuses = CDefHandler : : giveDef ( " SCNRSTAR.DEF " ) ;
rHero = BitmapHandler : : loadBitmap ( " HPSRAND1.bmp " ) ;
rTown = BitmapHandler : : loadBitmap ( " HPSRAND0.bmp " ) ;
nHero = BitmapHandler : : loadBitmap ( " HPSRAND6.bmp " ) ;
nTown = BitmapHandler : : loadBitmap ( " HPSRAND5.bmp " ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void CGPreGame : : disposeGraphics ( )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
delete victory ;
delete loss ;
SDL_FreeSurface ( rHero ) ;
SDL_FreeSurface ( nHero ) ;
SDL_FreeSurface ( rTown ) ;
SDL_FreeSurface ( nTown ) ;
2008-08-02 18:08:03 +03:00
}
2009-12-28 06:08:24 +02:00
void CGPreGame : : update ( )
{
if ( GH . listInt . size ( ) = = 0 )
{
2011-01-28 04:33:26 +02:00
CCS - > musich - > playMusic ( musicBase : : mainMenu , - 1 ) ;
2010-12-19 16:39:56 +02:00
CCS - > videoh - > open ( " ACREDIT.SMK " ) ;
2010-02-13 18:26:47 +02:00
GH . pushInt ( scrs [ CMenuScreen : : mainMenu ] ) ;
2009-12-28 06:08:24 +02:00
}
2010-10-24 14:35:14 +03:00
if ( SEL )
SEL - > update ( ) ;
2011-04-13 22:52:56 +03:00
// Handles mouse and key input
GH . updateTime ( ) ;
GH . handleEvents ( ) ;
2011-04-17 21:02:13 +03:00
if ( GH . curInt = = 0 ) // no redraw, when a new game was created
return ;
2011-04-26 16:30:29 +03:00
GH . topInt ( ) - > show ( screen ) ;
2011-04-17 21:02:13 +03:00
if ( conf . cc . showFPS )
GH . drawFPSCounter ( ) ;
// draw the mouse cursor and update the screen
2011-04-26 16:30:29 +03:00
CCS - > curh - > draw1 ( ) ;
2011-04-17 21:02:13 +03:00
CSDL_Ext : : update ( screen ) ;
2011-04-26 16:30:29 +03:00
CCS - > curh - > draw2 ( ) ;
2009-12-28 06:08:24 +02:00
}
2010-10-24 14:35:14 +03:00
CSelectionScreen : : CSelectionScreen ( CMenuScreen : : EState Type , CMenuScreen : : EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/ , const std : : map < ui32 , std : : string > * Names /*= NULL*/ )
2010-10-31 00:53:41 +03:00
: ISelectionScreenInfo ( Names ) , serverHandlingThread ( NULL ) , mx ( new boost : : recursive_mutex ) ,
serv ( NULL ) , ongoingClosing ( false ) , myNameID ( 255 )
2010-08-20 16:34:39 +03:00
{
2010-10-24 14:35:14 +03:00
screenType = Type ;
multiPlayer = MultiPlayer ;
2010-08-20 16:34:39 +03:00
2009-08-27 11:04:32 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-10-24 14:35:14 +03:00
bool network = ( MultiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST | | MultiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST ) ;
2010-09-03 21:42:54 +03:00
CServerHandler * sh = NULL ;
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST )
2010-09-03 21:42:54 +03:00
{
sh = new CServerHandler ;
sh - > startServer ( ) ;
}
2009-08-27 11:04:32 +03:00
IShowActivable : : type = BLOCK_ADV_HOTKEYS ;
pos . w = 762 ;
pos . h = 584 ;
2010-02-13 18:26:47 +02:00
if ( Type = = CMenuScreen : : saveGame )
2009-08-27 11:04:32 +03:00
{
center ( pos ) ;
}
2010-02-15 14:12:21 +02:00
else if ( Type = = CMenuScreen : : campaignList )
{
bg = new CPicture ( BitmapHandler : : loadBitmap ( " CamCust.bmp " ) , 0 , 0 , true ) ;
pos . x = 3 ;
pos . y = 6 ;
}
2009-08-27 11:04:32 +03:00
else
{
pos . x = 3 ;
pos . y = 6 ;
bg = new CPicture ( BitmapHandler : : loadBitmap ( rand ( ) % 2 ? " ZPIC1000.bmp " : " ZPIC1001.bmp " ) , - 3 , - 6 , true ) ;
}
2009-08-17 11:50:31 +03:00
CGP - > loadGraphics ( ) ;
2009-08-27 11:04:32 +03:00
sInfo . difficulty = 1 ;
2009-08-17 11:50:31 +03:00
current = NULL ;
2010-08-18 12:50:25 +03:00
sInfo . mode = ( Type = = CMenuScreen : : newGame ? StartInfo : : NEW_GAME : StartInfo : : LOAD_GAME ) ;
2009-08-17 11:50:31 +03:00
sInfo . turnTime = 0 ;
curTab = NULL ;
2010-10-24 14:35:14 +03:00
card = new InfoCard ( network ) ; //right info card
if ( screenType = = CMenuScreen : : campaignList )
2010-02-13 18:26:47 +02:00
{
opt = NULL ;
}
else
{
2010-10-24 14:35:14 +03:00
opt = new OptionsTab ( ) ; //scenario options tab
2010-02-13 18:26:47 +02:00
opt - > recActions = DISPOSE ;
}
2010-10-24 14:35:14 +03:00
sel = new SelectionTab ( screenType , bind ( & CSelectionScreen : : changeSelection , this , _1 ) , multiPlayer ) ; //scenario selection tab
2009-08-17 11:50:31 +03:00
sel - > recActions = DISPOSE ;
2010-10-24 14:35:14 +03:00
switch ( screenType )
2008-08-02 18:08:03 +03:00
{
2010-02-13 18:26:47 +02:00
case CMenuScreen : : newGame :
2009-08-17 11:50:31 +03:00
{
card - > difficulty - > onChange = bind ( & CSelectionScreen : : difficultyChange , this , _1 ) ;
card - > difficulty - > select ( 1 , 0 ) ;
2009-08-27 11:04:32 +03:00
AdventureMapButton * select = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 45 ] , bind ( & CSelectionScreen : : toggleTab , this , sel ) , 411 , 75 , " GSPBUTT.DEF " , SDLK_s ) ;
2009-08-17 11:50:31 +03:00
select - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 500 ] , FONT_SMALL ) ;
2009-08-27 11:04:32 +03:00
AdventureMapButton * opts = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 46 ] , bind ( & CSelectionScreen : : toggleTab , this , opt ) , 411 , 503 , " GSPBUTT.DEF " , SDLK_a ) ;
2009-08-17 11:50:31 +03:00
opts - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 501 ] , FONT_SMALL ) ;
2009-08-27 11:04:32 +03:00
AdventureMapButton * random = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 47 ] , bind ( & CSelectionScreen : : toggleTab , this , sel ) , 411 , 99 , " GSPBUTT.DEF " , SDLK_r ) ;
2009-08-17 11:50:31 +03:00
random - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 740 ] , FONT_SMALL ) ;
2009-08-27 11:04:32 +03:00
start = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 103 ] , bind ( & CSelectionScreen : : startGame , this ) , 411 , 529 , " SCNRBEG.DEF " , SDLK_b ) ;
2010-09-03 21:42:54 +03:00
2010-10-24 14:35:14 +03:00
if ( network )
2010-09-03 21:42:54 +03:00
{
2010-10-24 14:35:14 +03:00
AdventureMapButton * hideChat = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 48 ] , bind ( & InfoCard : : toggleChat , card ) , 619 , 75 , " GSPBUT2.DEF " , SDLK_h ) ;
2010-09-03 21:42:54 +03:00
hideChat - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 531 ] , FONT_SMALL ) ;
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST )
{
SDL_Color orange = { 232 , 184 , 32 , 0 } ;
select - > text - > color = opts - > text - > color = random - > text - > color = orange ;
select - > block ( true ) ;
opts - > block ( true ) ;
random - > block ( true ) ;
start - > block ( true ) ;
}
2010-09-03 21:42:54 +03:00
}
2009-08-17 11:50:31 +03:00
}
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : loadGame :
2009-08-17 11:50:31 +03:00
sel - > recActions = 255 ;
2009-08-27 11:04:32 +03:00
start = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 103 ] , bind ( & CSelectionScreen : : startGame , this ) , 411 , 529 , " SCNRLOD.DEF " , SDLK_l ) ;
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : saveGame :
2009-08-27 11:04:32 +03:00
sel - > recActions = 255 ;
start = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 103 ] . second , bind ( & CSelectionScreen : : startGame , this ) , 411 , 529 , " SCNRSAV.DEF " ) ;
2009-08-17 11:50:31 +03:00
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : campaignList :
sel - > recActions = 255 ;
2010-02-15 14:12:21 +02:00
start = new AdventureMapButton ( std : : pair < std : : string , std : : string > ( ) , bind ( & CSelectionScreen : : startCampaign , this ) , 411 , 529 , " SCNRLOD.DEF " , SDLK_b ) ;
2010-02-13 18:26:47 +02:00
break ;
2008-08-02 18:08:03 +03:00
}
2010-02-15 14:12:21 +02:00
2008-08-02 18:08:03 +03:00
2009-08-27 11:04:32 +03:00
start - > assignedKeys . insert ( SDLK_RETURN ) ;
2010-02-15 14:12:21 +02:00
std : : string backName ;
if ( Type = = CMenuScreen : : campaignList )
{
backName = " SCNRBACK.DEF " ;
}
else
{
backName = " SCNRBACK.DEF " ;
}
back = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 105 ] . second , bind ( & CGuiHandler : : popIntTotally , & GH , this ) , 581 , 529 , backName , SDLK_ESCAPE ) ;
2010-09-03 21:42:54 +03:00
2010-10-24 14:35:14 +03:00
if ( network )
2010-09-03 21:42:54 +03:00
{
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST )
{
assert ( playerNames . size ( ) = = 1 & & vstd : : contains ( playerNames , 1 ) ) ; //TODO hot-seat/network combo
serv = sh - > connectToServer ( ) ;
* serv < < ( ui8 ) 4 ;
myNameID = 1 ;
}
else
{
serv = CServerHandler : : justConnectToServer ( ) ;
}
* serv < < playerNames . begin ( ) - > second ;
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST )
{
const CMapInfo * map ;
* serv > > myNameID > > map ;
serv - > connectionID = myNameID ;
changeSelection ( map ) ;
}
else //host
{
if ( current )
{
SelectMap sm ( * current ) ;
* serv < < & sm ;
UpdateStartOptions uso ( sInfo ) ;
* serv < < & uso ;
}
}
applier = new CApplier < CBaseForPGApply > ;
registerTypes4 ( * applier ) ;
serverHandlingThread = new boost : : thread ( & CSelectionScreen : : handleConnection , this ) ;
2010-09-03 21:42:54 +03:00
}
delete sh ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
CSelectionScreen : : ~ CSelectionScreen ( )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
ongoingClosing = true ;
if ( serv )
{
assert ( serverHandlingThread ) ;
QuitMenuWithoutStarting qmws ;
* serv < < & qmws ;
// while(!serverHandlingThread->timed_join(boost::posix_time::milliseconds(50)))
// processPacks();
serverHandlingThread - > join ( ) ;
delete serverHandlingThread ;
}
2010-08-03 14:36:52 +03:00
playerColor = - 1 ;
2010-02-16 18:35:24 +02:00
playerNames . clear ( ) ;
2010-10-24 14:35:14 +03:00
assert ( ! serv ) ;
delNull ( applier ) ;
delete mx ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void CSelectionScreen : : toggleTab ( CIntObject * tab )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST & & serv )
{
PregameGuiAction pga ;
if ( tab = = curTab )
pga . action = PregameGuiAction : : NO_TAB ;
else if ( tab = = opt )
pga . action = PregameGuiAction : : OPEN_OPTIONS ;
else if ( tab = = sel )
pga . action = PregameGuiAction : : OPEN_SCENARIO_LIST ;
* serv < < & pga ;
}
2009-08-17 11:50:31 +03:00
if ( curTab & & curTab - > active )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
curTab - > deactivate ( ) ;
curTab - > recActions = DISPOSE ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
if ( curTab ! = tab )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
tab - > recActions = 255 ;
tab - > activate ( ) ;
curTab = tab ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
else
{
curTab = NULL ;
} ;
GH . totalRedraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void CSelectionScreen : : changeSelection ( const CMapInfo * to )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST )
2010-02-13 18:26:47 +02:00
{
2010-10-24 14:35:14 +03:00
delNull ( current ) ;
2010-02-13 18:26:47 +02:00
}
2008-08-02 18:08:03 +03:00
2010-10-24 14:35:14 +03:00
current = to ;
if ( to & & screenType = = CMenuScreen : : loadGame )
SEL - > sInfo . difficulty = to - > scenarioOpts - > difficulty ;
if ( screenType ! = CMenuScreen : : campaignList & & screenType ! = CMenuScreen : : saveGame )
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
updateStartInfo ( to ? to - > filename : " " , sInfo , to ? to - > mapHeader : NULL ) ;
2010-02-16 18:35:24 +02:00
}
2010-10-24 14:35:14 +03:00
card - > changeSelection ( to ) ;
if ( screenType ! = CMenuScreen : : campaignList )
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
opt - > recreate ( ) ;
2010-02-16 18:35:24 +02:00
}
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST & & serv )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
SelectMap sm ( * to ) ;
* serv < < & sm ;
2009-08-17 11:50:31 +03:00
2010-10-24 14:35:14 +03:00
UpdateStartOptions uso ( sInfo ) ;
* serv < < & uso ;
2009-08-17 11:50:31 +03:00
}
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
2010-02-15 14:12:21 +02:00
void CSelectionScreen : : startCampaign ( )
{
2010-10-24 14:35:14 +03:00
CCampaign * ourCampaign = CCampaignHandler : : getCampaign ( SEL - > current - > filename , SEL - > current - > lodCmpgn ) ;
2010-08-04 14:18:13 +03:00
CCampaignState * campState = new CCampaignState ( ) ;
2010-08-05 10:52:34 +03:00
campState - > camp = ourCampaign ;
2010-08-04 14:18:13 +03:00
GH . pushInt ( new CBonusSelection ( campState ) ) ;
2010-02-15 14:12:21 +02:00
}
2009-08-17 11:50:31 +03:00
void CSelectionScreen : : startGame ( )
2008-08-06 01:11:32 +03:00
{
2010-10-24 14:35:14 +03:00
if ( screenType = = CMenuScreen : : newGame )
2010-03-08 00:56:51 +02:00
{
//there must be at least one human player before game can be started
2010-08-03 14:36:52 +03:00
std : : map < int , PlayerSettings > : : const_iterator i ;
2010-10-24 14:35:14 +03:00
for ( i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
2010-08-03 14:36:52 +03:00
if ( i - > second . human )
2010-03-08 00:56:51 +02:00
break ;
2010-10-24 14:35:14 +03:00
if ( i = = SEL - > sInfo . playerInfos . end ( ) )
2010-03-08 00:56:51 +02:00
{
GH . pushInt ( CInfoWindow : : create ( CGI - > generaltexth - > allTexts [ 530 ] ) ) ; //You must position yourself prior to starting the game.
return ;
}
}
2010-10-24 14:35:14 +03:00
if ( multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST )
{
start - > block ( true ) ;
StartWithCurrentSettings swcs ;
* serv < < & swcs ;
ongoingClosing = true ;
return ;
}
if ( screenType ! = CMenuScreen : : saveGame )
2009-08-27 11:04:32 +03:00
{
if ( ! current )
return ;
selectedName = sInfo . mapname ;
StartInfo * si = new StartInfo ( sInfo ) ;
2010-03-08 00:56:51 +02:00
GH . popIntTotally ( this ) ; //delete me
GH . popInt ( GH . topInt ( ) ) ; //only deactivate main menu screen
2010-10-24 14:35:14 +03:00
//SEL->current = NULL;
//curOpts = NULL;
2009-08-27 11:04:32 +03:00
: : startGame ( si ) ;
}
else
{
if ( ! ( sel & & sel - > txt & & sel - > txt - > text . size ( ) ) )
return ;
2009-08-17 11:50:31 +03:00
2009-10-10 08:47:59 +03:00
selectedName = GVCMIDirs . UserPath + " /Games/ " + sel - > txt - > text + " .vlgm1 " ;
2010-03-08 00:56:51 +02:00
CFunctionList < void ( ) > overWrite ;
overWrite + = bind ( & CCallback : : save , LOCPLINT - > cb , sel - > txt - > text ) ;
overWrite + = bind ( & CGuiHandler : : popIntTotally , & GH , this ) ;
if ( fs : : exists ( selectedName ) )
{
std : : string hlp = CGI - > generaltexth - > allTexts [ 493 ] ; //%s exists. Overwrite?
boost : : algorithm : : replace_first ( hlp , " %s " , sel - > txt - > text ) ;
LOCPLINT - > showYesNoDialog ( hlp , std : : vector < SComponent * > ( ) , overWrite , 0 , false ) ;
}
else
overWrite ( ) ;
// LOCPLINT->cb->save(sel->txt->text);
// GH.popIntTotally(this);
2009-08-27 11:04:32 +03:00
}
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void CSelectionScreen : : difficultyChange ( int to )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
assert ( screenType = = CMenuScreen : : newGame ) ;
2009-08-17 11:50:31 +03:00
sInfo . difficulty = to ;
2010-10-24 14:35:14 +03:00
propagateOptions ( ) ;
2009-08-17 11:50:31 +03:00
GH . totalRedraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
2010-09-03 21:42:54 +03:00
void CSelectionScreen : : handleConnection ( )
{
2011-02-24 15:57:47 +02:00
setThreadName ( - 1 , " CSelectionScreen::handleConnection " ) ;
2010-10-24 14:35:14 +03:00
try
2010-09-03 21:42:54 +03:00
{
2010-10-24 14:35:14 +03:00
assert ( serv ) ;
while ( serv )
{
CPackForSelectionScreen * pack = NULL ;
* serv > > pack ;
assert ( pack ) ;
if ( QuitMenuWithoutStarting * endingPack = dynamic_cast < QuitMenuWithoutStarting * > ( pack ) )
{
endingPack - > apply ( this ) ;
}
else if ( StartWithCurrentSettings * endingPack = dynamic_cast < StartWithCurrentSettings * > ( pack ) )
{
endingPack - > apply ( this ) ;
}
else
{
boost : : unique_lock < boost : : recursive_mutex > lll ( * mx ) ;
upcomingPacks . push_back ( pack ) ;
}
}
} HANDLE_EXCEPTION
catch ( int i )
{
if ( i ! = 666 )
throw ;
2010-09-03 21:42:54 +03:00
}
}
2010-10-24 14:35:14 +03:00
void CSelectionScreen : : setSInfo ( const StartInfo & si )
2010-09-03 21:42:54 +03:00
{
2010-10-24 14:35:14 +03:00
std : : map < int , PlayerSettings > : : const_iterator i ;
for ( i = si . playerInfos . begin ( ) ; i ! = si . playerInfos . end ( ) ; i + + )
{
if ( i - > second . human = = myNameID )
{
playerColor = i - > first ;
break ;
}
}
if ( i = = si . playerInfos . end ( ) ) //not found
playerColor = - 1 ;
sInfo = si ;
if ( current )
opt - > recreate ( ) ; //will force to recreate using current sInfo
2010-09-03 21:42:54 +03:00
2010-10-24 14:35:14 +03:00
card - > difficulty - > select ( si . difficulty , 0 ) ;
GH . totalRedraw ( ) ;
}
void CSelectionScreen : : processPacks ( )
{
boost : : unique_lock < boost : : recursive_mutex > lll ( * mx ) ;
while ( upcomingPacks . size ( ) )
{
CPackForSelectionScreen * pack = upcomingPacks . front ( ) ;
upcomingPacks . pop_front ( ) ;
CBaseForPGApply * apply = applier - > apps [ typeList . getTypeID ( pack ) ] ; //find the applier
apply - > applyOnPG ( this , pack ) ;
delete pack ;
}
}
void CSelectionScreen : : update ( )
{
if ( serverHandlingThread )
processPacks ( ) ;
}
void CSelectionScreen : : propagateOptions ( )
{
if ( isHost ( ) & & serv )
{
UpdateStartOptions ups ( sInfo ) ;
* serv < < & ups ;
}
}
void CSelectionScreen : : postRequest ( ui8 what , ui8 dir )
{
if ( ! isGuest ( ) | | ! serv )
return ;
RequestOptionsChange roc ( what , dir , myNameID ) ;
* serv < < & roc ;
}
void CSelectionScreen : : postChatMessage ( const std : : string & txt )
{
assert ( serv ) ;
ChatMessage cm ;
cm . message = txt ;
cm . playerName = sInfo . getPlayersSettings ( myNameID ) - > name ;
* serv < < & cm ;
}
void CSelectionScreen : : propagateNames ( )
{
PlayersNames pn ;
pn . playerNames = playerNames ;
* serv < < & pn ;
2010-09-03 21:42:54 +03:00
}
2009-08-17 11:50:31 +03:00
// A new size filter (Small, Medium, ...) has been selected. Populate
// selMaps with the relevant data.
2009-08-27 11:04:32 +03:00
void SelectionTab : : filter ( int size , bool selectFirst )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
curItems . clear ( ) ;
2010-02-13 18:26:47 +02:00
if ( tabType = = CMenuScreen : : campaignList )
{
for ( size_t i = 0 ; i < allItems . size ( ) ; i + + )
2009-08-17 11:50:31 +03:00
curItems . push_back ( & allItems [ i ] ) ;
2010-02-13 18:26:47 +02:00
}
else
{
for ( size_t i = 0 ; i < allItems . size ( ) ; i + + )
if ( allItems [ i ] . mapHeader & & allItems [ i ] . mapHeader - > version & & ( ! size | | allItems [ i ] . mapHeader - > width = = size ) )
curItems . push_back ( & allItems [ i ] ) ;
}
2009-08-17 11:50:31 +03:00
if ( curItems . size ( ) )
{
slider - > block ( false ) ;
slider - > setAmount ( curItems . size ( ) ) ;
sort ( ) ;
2009-08-27 11:04:32 +03:00
if ( selectFirst )
{
slider - > moveTo ( 0 ) ;
onSelect ( curItems [ 0 ] ) ;
}
2009-09-11 14:11:01 +03:00
selectAbs ( 0 ) ;
2009-08-17 11:50:31 +03:00
}
else
{
slider - > block ( true ) ;
onSelect ( NULL ) ;
}
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : getFiles ( std : : vector < FileInfo > & out , const std : : string & dirname , const std : : string & ext )
2008-08-02 18:08:03 +03:00
{
2011-06-20 14:41:04 +03:00
CFileUtility : : getFilesWithExt ( out , dirname , ext ) ;
2009-08-17 11:50:31 +03:00
allItems . resize ( out . size ( ) ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : parseMaps ( std : : vector < FileInfo > & files , int start , int threads )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
int read = 0 ;
unsigned char mapBuffer [ 1500 ] ;
while ( start < allItems . size ( ) )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
gzFile tempf = gzopen ( files [ start ] . name . c_str ( ) , " rb " ) ;
read = gzread ( tempf , mapBuffer , 1500 ) ;
gzclose ( tempf ) ;
if ( read < 50 | | ! mapBuffer [ 4 ] )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
tlog3 < < " \t \t Warning: corrupted map file: " < < files [ start ] . name < < std : : endl ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
else //valid map
{
2010-02-13 18:26:47 +02:00
allItems [ start ] . mapInit ( files [ start ] . name , mapBuffer ) ;
2009-08-17 11:50:31 +03:00
//allItems[start].date = "DATEDATE";// files[start].date;
}
start + = threads ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
}
2010-02-24 15:03:36 +02:00
void SelectionTab : : parseGames ( std : : vector < FileInfo > & files , bool multi )
2009-08-17 11:50:31 +03:00
{
for ( int i = 0 ; i < files . size ( ) ; i + + )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
CLoadFile lf ( files [ i ] . name ) ;
if ( ! lf . sfile )
continue ;
ui8 sign [ 8 ] ;
lf > > sign ;
if ( std : : memcmp ( sign , " VCMISVG " , 7 ) )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
tlog1 < < files [ i ] . name < < " is not a correct savefile! " < < std : : endl ;
continue ;
2008-08-02 18:08:03 +03:00
}
2010-02-13 23:45:46 +02:00
allItems [ i ] . mapHeader = new CMapHeader ( ) ;
2010-02-24 15:03:36 +02:00
lf > > * ( allItems [ i ] . mapHeader ) > > allItems [ i ] . scenarioOpts ;
2009-08-17 11:50:31 +03:00
allItems [ i ] . filename = files [ i ] . name ;
allItems [ i ] . countPlayers ( ) ;
allItems [ i ] . date = std : : asctime ( std : : localtime ( & files [ i ] . date ) ) ;
2010-02-24 15:03:36 +02:00
if ( ( allItems [ i ] . actualHumanPlayers > 1 ) ! = multi ) //if multi mode then only multi games, otherwise single
{
delete allItems [ i ] . mapHeader ;
allItems [ i ] . mapHeader = NULL ;
}
2008-08-02 18:08:03 +03:00
}
}
2009-02-06 13:15:39 +02:00
2010-02-13 18:26:47 +02:00
void SelectionTab : : parseCampaigns ( std : : vector < FileInfo > & files )
{
for ( int i = 0 ; i < files . size ( ) ; i + + )
{
2010-02-18 16:09:16 +02:00
//allItems[i].date = std::asctime(std::localtime(&files[i].date));
2010-02-13 18:26:47 +02:00
allItems [ i ] . filename = files [ i ] . name ;
2010-02-18 14:34:44 +02:00
allItems [ i ] . lodCmpgn = files [ i ] . inLod ;
2010-02-13 18:26:47 +02:00
allItems [ i ] . campaignInit ( ) ;
}
}
2010-10-24 14:35:14 +03:00
SelectionTab : : SelectionTab ( CMenuScreen : : EState Type , const boost : : function < void ( CMapInfo * ) > & OnSelect , CMenuScreen : : EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/ )
2010-10-18 18:08:59 +03:00
: bg ( NULL ) , onSelect ( OnSelect )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
OBJ_CONSTRUCTION ;
selectionPos = 0 ;
2009-08-23 21:01:08 +03:00
used = LCLICK | WHEEL | KEYBOARD | DOUBLECLICK ;
2009-08-17 11:50:31 +03:00
slider = NULL ;
2009-08-27 11:04:32 +03:00
txt = NULL ;
2010-02-13 18:26:47 +02:00
tabType = Type ;
2009-08-27 11:04:32 +03:00
2010-08-04 14:18:13 +03:00
if ( Type ! = CMenuScreen : : campaignList )
2010-02-15 15:28:33 +02:00
{
2010-02-13 18:26:47 +02:00
bg = new CPicture ( BitmapHandler : : loadBitmap ( " SCSELBCK.bmp " ) , 0 , 0 , true ) ;
2010-02-15 14:12:21 +02:00
pos . w = bg - > pos . w ;
pos . h = bg - > pos . h ;
2010-02-15 15:28:33 +02:00
}
else
{
SDL_Surface * tmp1 = BitmapHandler : : loadBitmap ( " CAMCUST.bmp " ) ;
SDL_Surface * tmp = CSDL_Ext : : newSurface ( 400 , tmp1 - > h ) ;
blitAt ( tmp1 , 0 , 0 , tmp ) ;
SDL_FreeSurface ( tmp1 ) ;
bg = new CPicture ( tmp , 0 , 0 , true ) ;
pos . w = bg - > pos . w ;
pos . h = bg - > pos . h ;
bg - > pos . x = bg - > pos . y = 0 ;
}
2009-08-27 11:04:32 +03:00
2010-10-24 14:35:14 +03:00
if ( MultiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
positions = 18 ;
2010-10-24 14:35:14 +03:00
}
else
{
std : : vector < FileInfo > toParse ;
std : : vector < CCampaignHeader > cpm ;
switch ( tabType )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
case CMenuScreen : : newGame :
getFiles ( toParse , DATA_DIR " /Maps " , " h3m " ) ; //get all maps
parseMaps ( toParse ) ;
2009-08-17 11:50:31 +03:00
positions = 18 ;
2010-10-24 14:35:14 +03:00
break ;
case CMenuScreen : : loadGame :
case CMenuScreen : : saveGame :
getFiles ( toParse , GVCMIDirs . UserPath + " /Games " , " vlgm1 " ) ; //get all saves
parseGames ( toParse , MultiPlayer ) ;
if ( tabType = = CMenuScreen : : loadGame )
2010-02-18 14:34:44 +02:00
{
2010-10-24 14:35:14 +03:00
positions = 18 ;
2010-02-18 14:34:44 +02:00
}
2010-10-24 14:35:14 +03:00
else
{
positions = 16 ;
}
if ( tabType = = CMenuScreen : : saveGame )
txt = new CTextInput ( Rect ( 32 , 539 , 350 , 20 ) , Point ( - 32 , - 25 ) , " GSSTRIP.bmp " , 0 ) ;
break ;
case CMenuScreen : : campaignList :
getFiles ( toParse , DATA_DIR " /Maps " , " h3c " ) ; //get all campaigns
for ( int g = 0 ; g < toParse . size ( ) ; + + g )
{
toParse [ g ] . inLod = false ;
}
//add lod cmpgns
cpm = CCampaignHandler : : getCampaignHeaders ( CCampaignHandler : : ALL ) ;
for ( int g = 0 ; g < cpm . size ( ) ; g + + )
{
FileInfo fi ;
fi . inLod = cpm [ g ] . loadFromLod ;
fi . name = cpm [ g ] . filename ;
toParse . push_back ( fi ) ;
if ( cpm [ g ] . loadFromLod )
{
allItems . push_back ( CMapInfo ( false ) ) ;
}
}
parseCampaigns ( toParse ) ;
positions = 18 ;
break ;
2009-02-08 19:19:42 +02:00
2010-10-24 14:35:14 +03:00
default :
assert ( 0 ) ;
break ;
}
2009-08-17 11:50:31 +03:00
}
2009-02-08 19:19:42 +02:00
2010-02-15 15:28:33 +02:00
2010-02-13 18:26:47 +02:00
if ( tabType ! = CMenuScreen : : campaignList )
2009-08-17 11:50:31 +03:00
{
2010-02-15 15:28:33 +02:00
//size filter buttons
2010-02-13 18:26:47 +02:00
{
int sizes [ ] = { 36 , 72 , 108 , 144 , 0 } ;
const char * names [ ] = { " SCSMBUT.DEF " , " SCMDBUT.DEF " , " SCLGBUT.DEF " , " SCXLBUT.DEF " , " SCALBUT.DEF " } ;
for ( int i = 0 ; i < 5 ; i + + )
new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 54 + i ] . second , bind ( & SelectionTab : : filter , this , sizes [ i ] , true ) , 158 + 47 * i , 46 , names [ i ] ) ;
}
2009-08-17 11:50:31 +03:00
2010-02-15 15:28:33 +02:00
//sort buttons buttons
2010-02-13 18:26:47 +02:00
{
int xpos [ ] = { 23 , 55 , 88 , 121 , 306 , 339 } ;
const char * names [ ] = { " SCBUTT1.DEF " , " SCBUTT2.DEF " , " SCBUTCP.DEF " , " SCBUTT3.DEF " , " SCBUTT4.DEF " , " SCBUTT5.DEF " } ;
for ( int i = 0 ; i < 6 ; i + + )
new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 107 + i ] . second , bind ( & SelectionTab : : sortBy , this , i ) , xpos [ i ] , 86 , names [ i ] ) ;
}
2009-02-11 19:03:30 +02:00
}
2010-02-15 15:28:33 +02:00
else
{
//sort by buttons
new AdventureMapButton ( " " , " " , bind ( & SelectionTab : : sortBy , this , _numOfMaps ) , 23 , 86 , " CamCusM.DEF " ) ; //by num of maps
new AdventureMapButton ( " " , " " , bind ( & SelectionTab : : sortBy , this , _name ) , 55 , 86 , " CamCusL.DEF " ) ; //by name
}
2009-08-17 11:50:31 +03:00
2010-02-13 18:26:47 +02:00
slider = new CSlider ( 372 , 86 , tabType ! = CMenuScreen : : saveGame ? 480 : 430 , bind ( & SelectionTab : : sliderMove , this , _1 ) , positions , curItems . size ( ) , 0 , false , 1 ) ;
2010-07-06 05:10:26 +03:00
slider - > changeUsedEvents ( WHEEL , true ) ;
2011-04-30 22:52:35 +03:00
slider - > slider - > keepFrame = true ;
2009-08-17 11:50:31 +03:00
format = CDefHandler : : giveDef ( " SCSELC.DEF " ) ;
sortingBy = _format ;
ascending = true ;
filter ( 0 ) ;
2009-08-27 11:04:32 +03:00
//select(0);
2010-02-13 18:26:47 +02:00
switch ( tabType )
2009-08-27 11:04:32 +03:00
{
2010-02-13 18:26:47 +02:00
case CMenuScreen : : newGame :
2009-10-10 04:42:33 +03:00
selectFName ( DATA_DIR " /Maps/Arrogance.h3m " ) ;
2009-08-27 11:04:32 +03:00
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : loadGame :
case CMenuScreen : : campaignList :
2009-08-27 11:04:32 +03:00
select ( 0 ) ;
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : saveGame : ;
2009-08-27 11:04:32 +03:00
if ( selectedName . size ( ) )
{
2010-03-08 00:56:51 +02:00
if ( selectedName [ 2 ] = = ' M ' ) //name starts with ./Maps instead of ./Games => there was nothing to select
2009-08-27 11:04:32 +03:00
txt - > setText ( " NEWGAME " ) ;
else
2009-08-28 22:34:08 +03:00
selectFName ( selectedName ) ;
2009-08-27 11:04:32 +03:00
}
}
2009-08-17 11:50:31 +03:00
}
SelectionTab : : ~ SelectionTab ( )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
delete format ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : sortBy ( int criteria )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
if ( criteria = = sortingBy )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
ascending = ! ascending ;
2008-08-02 18:08:03 +03:00
}
else
{
2009-08-17 11:50:31 +03:00
sortingBy = ( ESortBy ) criteria ;
ascending = true ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
sort ( ) ;
2009-09-11 14:11:01 +03:00
selectAbs ( 0 ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : sort ( )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
if ( sortingBy ! = _name )
2010-02-13 18:26:47 +02:00
std : : stable_sort ( curItems . begin ( ) , curItems . end ( ) , mapSorter ( _name ) ) ;
std : : stable_sort ( curItems . begin ( ) , curItems . end ( ) , mapSorter ( sortingBy ) ) ;
2009-06-10 23:48:55 +03:00
2009-08-17 11:50:31 +03:00
if ( ! ascending )
std : : reverse ( curItems . begin ( ) , curItems . end ( ) ) ;
2009-06-10 23:48:55 +03:00
2009-08-17 11:50:31 +03:00
redraw ( ) ;
}
2009-06-10 23:48:55 +03:00
2009-08-17 11:50:31 +03:00
void SelectionTab : : select ( int position )
{
2009-08-27 11:04:32 +03:00
if ( ! curItems . size ( ) ) return ;
2009-08-17 11:50:31 +03:00
// New selection. py is the index in curItems.
int py = position + slider - > value ;
2009-08-23 21:01:08 +03:00
amax ( py , 0 ) ;
amin ( py , curItems . size ( ) - 1 ) ;
2009-02-06 13:15:39 +02:00
2009-08-23 21:01:08 +03:00
selectionPos = py ;
if ( position < 0 )
slider - > moveTo ( slider - > value + position ) ;
else if ( position > = positions )
slider - > moveTo ( slider - > value + position - positions + 1 ) ;
2010-03-08 00:56:51 +02:00
if ( txt )
txt - > setText ( fs : : basename ( curItems [ py ] - > filename ) ) ;
2009-08-23 21:01:08 +03:00
onSelect ( curItems [ py ] ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
2009-08-27 11:04:32 +03:00
void SelectionTab : : selectAbs ( int position )
{
select ( position - slider - > value ) ;
}
2009-08-17 11:50:31 +03:00
int SelectionTab : : getPosition ( int x , int y )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
return - 1 ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : sliderMove ( int slidPos )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
if ( ! slider ) return ; //ignore spurious call when slider is being created
redraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
2009-05-04 02:38:08 +03:00
// Display the tab with the scenario names
//
// elemIdx is the index of the maps or saved game to display on line 0
2009-08-17 11:50:31 +03:00
// slider->capacity contains the number of available screen lines
// slider->positionsAmnt is the number of elements after filtering
void SelectionTab : : printMaps ( SDL_Surface * to )
2008-08-02 18:08:03 +03:00
{
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
int elemIdx = slider - > value ;
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
// Display all elements if there's enough space
//if(slider->amount < slider->capacity)
// elemIdx = 0;
2009-05-04 02:38:08 +03:00
2010-02-13 18:26:47 +02:00
SDL_Color itemColor ;
2009-08-17 11:50:31 +03:00
# define POS(xx, yy) pos.x + xx, pos.y + yy + line*25
for ( int line = 0 ; line < positions & & elemIdx < curItems . size ( ) ; elemIdx + + , line + + )
{
2010-10-24 14:35:14 +03:00
CMapInfo * currentItem = curItems [ elemIdx ] ;
2009-05-04 02:38:08 +03:00
2010-02-15 14:12:21 +02:00
if ( elemIdx = = selectionPos )
itemColor = tytulowy ;
else
itemColor = zwykly ;
2010-02-13 18:26:47 +02:00
if ( tabType ! = CMenuScreen : : campaignList )
{
//amount of players
std : : ostringstream ostr ( std : : ostringstream : : out ) ;
2010-10-24 14:35:14 +03:00
ostr < < currentItem - > playerAmnt < < " / " < < currentItem - > humenPlayers ;
2010-02-13 18:26:47 +02:00
CSDL_Ext : : printAt ( ostr . str ( ) , POS ( 29 , 120 ) , FONT_SMALL , itemColor , to ) ;
//map size
std : : string temp2 = " C " ;
2010-10-24 14:35:14 +03:00
switch ( currentItem - > mapHeader - > width )
2010-02-13 18:26:47 +02:00
{
case 36 :
temp2 = " S " ;
break ;
case 72 :
temp2 = " M " ;
break ;
case 108 :
temp2 = " L " ;
break ;
case 144 :
temp2 = " XL " ;
break ;
}
CSDL_Ext : : printAtMiddle ( temp2 , POS ( 70 , 128 ) , FONT_SMALL , itemColor , to ) ;
2009-05-04 02:38:08 +03:00
2010-02-13 18:26:47 +02:00
int temp = - 1 ;
2010-10-24 14:35:14 +03:00
switch ( currentItem - > mapHeader - > version )
2010-02-13 18:26:47 +02:00
{
case CMapHeader : : RoE :
temp = 0 ;
break ;
case CMapHeader : : AB :
temp = 1 ;
break ;
case CMapHeader : : SoD :
temp = 2 ;
break ;
case CMapHeader : : WoG :
temp = 3 ;
break ;
default :
// Unknown version. Be safe and ignore that map
2010-10-24 14:35:14 +03:00
tlog2 < < " Warning: " < < currentItem - > filename < < " has wrong version! \n " ;
2010-02-13 18:26:47 +02:00
continue ;
}
blitAt ( format - > ourImages [ temp ] . bitmap , POS ( 88 , 117 ) , to ) ;
//victory conditions
2010-10-24 14:35:14 +03:00
if ( currentItem - > mapHeader - > victoryCondition . condition = = winStandard )
2010-02-13 18:26:47 +02:00
temp = 11 ;
else
2010-10-24 14:35:14 +03:00
temp = currentItem - > mapHeader - > victoryCondition . condition ;
2010-02-13 18:26:47 +02:00
blitAt ( CGP - > victory - > ourImages [ temp ] . bitmap , POS ( 306 , 117 ) , to ) ;
//loss conditions
2010-10-24 14:35:14 +03:00
if ( currentItem - > mapHeader - > lossCondition . typeOfLossCon = = lossStandard )
2010-02-13 18:26:47 +02:00
temp = 3 ;
else
2010-10-24 14:35:14 +03:00
temp = currentItem - > mapHeader - > lossCondition . typeOfLossCon ;
2010-02-13 18:26:47 +02:00
blitAt ( CGP - > loss - > ourImages [ temp ] . bitmap , POS ( 339 , 117 ) , to ) ;
}
2010-02-15 14:12:21 +02:00
else //if campaign
{
//number of maps in campaign
std : : ostringstream ostr ( std : : ostringstream : : out ) ;
2010-10-24 14:35:14 +03:00
ostr < < CGI - > generaltexth - > campaignRegionNames [ currentItem - > campaignHeader - > mapVersion ] . size ( ) ;
2010-02-15 14:12:21 +02:00
CSDL_Ext : : printAt ( ostr . str ( ) , POS ( 29 , 120 ) , FONT_SMALL , itemColor , to ) ;
}
2009-05-04 02:38:08 +03:00
2010-02-13 18:26:47 +02:00
std : : string name ;
2010-10-24 14:35:14 +03:00
if ( tabType = = CMenuScreen : : newGame )
{
if ( ! currentItem - > mapHeader - > name . length ( ) )
currentItem - > mapHeader - > name = " Unnamed " ;
name = currentItem - > mapHeader - > name ;
}
else if ( tabType = = CMenuScreen : : campaignList )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
name = currentItem - > campaignHeader - > name ;
2008-08-02 18:08:03 +03:00
}
2010-02-13 18:26:47 +02:00
else
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
name = fs : : basename ( currentItem - > filename ) ;
2008-08-02 18:08:03 +03:00
}
2009-01-11 00:08:18 +02:00
2010-02-13 18:26:47 +02:00
//print name
2010-10-24 14:35:14 +03:00
CSDL_Ext : : printAtMiddle ( name , POS ( 213 , 128 ) , FONT_SMALL , itemColor , to ) ;
2010-02-13 18:26:47 +02:00
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
# undef POS
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
void SelectionTab : : showAll ( SDL_Surface * to )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
CIntObject : : showAll ( to ) ;
printMaps ( to ) ;
2009-10-23 04:48:03 +03:00
2010-02-13 18:26:47 +02:00
std : : string title ;
switch ( tabType ) {
case CMenuScreen : : newGame :
title = CGI - > generaltexth - > arraytxt [ 229 ] ;
break ;
case CMenuScreen : : loadGame :
title = CGI - > generaltexth - > arraytxt [ 230 ] ;
break ;
case CMenuScreen : : saveGame :
title = CGI - > generaltexth - > arraytxt [ 231 ] ;
break ;
case CMenuScreen : : campaignList :
title = " Select a Campaign " ; //TODO: find where is the title
break ;
2009-10-23 04:48:03 +03:00
}
2010-02-13 18:26:47 +02:00
CSDL_Ext : : printAtMiddle ( title , pos . x + 205 , pos . y + 28 , FONT_MEDIUM , tytulowy , to ) ; //Select a Scenario to Play
2010-02-15 14:12:21 +02:00
if ( tabType ! = CMenuScreen : : campaignList )
{
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > allTexts [ 510 ] , pos . x + 87 , pos . y + 62 , FONT_SMALL , tytulowy , to ) ; //Map sizes
}
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void SelectionTab : : clickLeft ( tribool down , bool previousState )
2009-01-11 00:08:18 +02:00
{
2009-10-06 03:32:33 +03:00
if ( down )
{
int line = getLine ( ) ;
if ( line ! = - 1 )
select ( line ) ;
}
2009-01-11 00:08:18 +02:00
}
2009-08-23 21:01:08 +03:00
void SelectionTab : : keyPressed ( const SDL_KeyboardEvent & key )
{
if ( key . state ! = SDL_PRESSED ) return ;
int moveBy = 0 ;
switch ( key . keysym . sym )
{
case SDLK_UP :
moveBy = - 1 ;
break ;
case SDLK_DOWN :
moveBy = + 1 ;
break ;
case SDLK_PAGEUP :
moveBy = - positions + 1 ;
break ;
case SDLK_PAGEDOWN :
moveBy = + positions - 1 ;
break ;
case SDLK_HOME :
select ( - slider - > value ) ;
return ;
case SDLK_END :
select ( curItems . size ( ) - slider - > value ) ;
return ;
2009-08-27 11:04:32 +03:00
default :
return ;
2009-08-23 21:01:08 +03:00
}
select ( selectionPos - slider - > value + moveBy ) ;
}
void SelectionTab : : onDoubleClick ( )
{
2009-08-27 11:04:32 +03:00
if ( getLine ( ) ! = - 1 ) //double clicked scenarios list
{
2009-10-13 07:58:15 +03:00
//act as if start button was pressed
2009-08-27 11:04:32 +03:00
( static_cast < CSelectionScreen * > ( parent ) ) - > start - > callback ( ) ;
}
}
int SelectionTab : : getLine ( )
{
int line = - 1 ;
Point clickPos ( GH . current - > button . x , GH . current - > button . y ) ;
2009-09-26 00:11:13 +03:00
clickPos = clickPos - pos . topLeft ( ) ;
2009-08-27 11:04:32 +03:00
2009-10-06 03:32:33 +03:00
if ( clickPos . y > 115 & & clickPos . y < 564 & & clickPos . x > 22 & & clickPos . x < 371 )
2009-08-27 11:04:32 +03:00
{
line = ( clickPos . y - 115 ) / 25 ; //which line
}
return line ;
}
void SelectionTab : : selectFName ( const std : : string & fname )
{
for ( int i = curItems . size ( ) - 1 ; i > = 0 ; i - - )
{
if ( curItems [ i ] - > filename = = fname )
{
slider - > moveTo ( i ) ;
selectAbs ( i ) ;
return ;
}
}
selectAbs ( 0 ) ;
2009-08-23 21:01:08 +03:00
}
2010-02-13 18:26:47 +02:00
2010-09-03 21:42:54 +03:00
CChatBox : : CChatBox ( const Rect & rect )
{
2010-10-24 14:35:14 +03:00
OBJ_CONSTRUCTION ;
pos + = rect ;
used = KEYBOARD ;
captureAllKeys = true ;
const int height = graphics - > fonts [ FONT_SMALL ] - > height ;
inputBox = new CTextInput ( Rect ( 0 , rect . h - height , rect . w , height ) ) ;
inputBox - > used & = ~ KEYBOARD ;
chatHistory = new CTextBox ( " " , Rect ( 0 , 0 , rect . w , rect . h - height ) , 1 ) ;
SDL_Color green = { 0 , 252 , 0 } ;
chatHistory - > color = green ;
}
void CChatBox : : keyPressed ( const SDL_KeyboardEvent & key )
{
if ( key . keysym . sym = = SDLK_RETURN & & key . state = = SDL_PRESSED & & inputBox - > text . size ( ) )
{
SEL - > postChatMessage ( inputBox - > text ) ;
inputBox - > setText ( " " ) ;
}
else
inputBox - > keyPressed ( key ) ;
2010-09-03 21:42:54 +03:00
}
2010-10-24 14:35:14 +03:00
void CChatBox : : addNewMessage ( const std : : string & text )
{
chatHistory - > setTxt ( chatHistory - > text + text + " \n " ) ;
if ( chatHistory - > slider )
chatHistory - > slider - > moveToMax ( ) ;
}
InfoCard : : InfoCard ( bool Network )
2010-10-31 00:53:41 +03:00
: bg ( NULL ) , network ( Network ) , chatOn ( false ) , chat ( NULL ) , playerListBg ( NULL ) ,
difficulty ( NULL ) , sizes ( NULL ) , sFlags ( NULL )
2009-02-08 08:42:15 +02:00
{
2009-08-17 11:50:31 +03:00
OBJ_CONSTRUCTION ;
2009-08-27 11:04:32 +03:00
pos . x + = 393 ;
2009-08-22 16:59:15 +03:00
used = RCLICK ;
2010-07-06 05:10:26 +03:00
mapDescription = NULL ;
2009-08-27 11:04:32 +03:00
2010-07-06 05:10:26 +03:00
Rect descriptionRect ( 26 , 149 , 320 , 115 ) ;
mapDescription = new CTextBox ( " " , descriptionRect , 1 ) ;
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : campaignList )
2009-01-12 22:05:56 +02:00
{
2010-07-06 05:10:26 +03:00
CSelectionScreen * ss = static_cast < CSelectionScreen * > ( parent ) ;
moveChild ( new CPicture ( * ss - > bg , descriptionRect + Point ( - 393 , 0 ) ) , this , mapDescription , true ) ; //move subpicture bg to our description control (by default it's our (Infocard) child)
2010-02-15 14:12:21 +02:00
}
else
{
bg = new CPicture ( BitmapHandler : : loadBitmap ( " GSELPOP1.bmp " ) , 0 , 0 , true ) ;
2010-07-06 05:10:26 +03:00
std : : swap ( children . front ( ) , children . back ( ) ) ;
2010-02-15 14:12:21 +02:00
pos . w = bg - > pos . w ;
pos . h = bg - > pos . h ;
2010-02-13 18:26:47 +02:00
sizes = CDefHandler : : giveDef ( " SCNRMPSZ.DEF " ) ;
sFlags = CDefHandler : : giveDef ( " ITGFLAGS.DEF " ) ;
difficulty = new CHighlightableButtonsGroup ( 0 ) ;
2009-08-27 11:04:32 +03:00
{
2010-02-13 18:26:47 +02:00
static const char * difButns [ ] = { " GSPBUT3.DEF " , " GSPBUT4.DEF " , " GSPBUT5.DEF " , " GSPBUT6.DEF " , " GSPBUT7.DEF " } ;
for ( int i = 0 ; i < 5 ; i + + )
{
difficulty - > addButton ( new CHighlightableButton ( " " , CGI - > generaltexth - > zelp [ 24 + i ] . second , 0 , 110 + i * 32 , 450 , difButns [ i ] , i ) ) ;
}
2009-08-27 11:04:32 +03:00
}
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : newGame )
2010-02-13 18:26:47 +02:00
difficulty - > block ( true ) ;
2010-07-06 05:10:26 +03:00
//description needs bg
moveChild ( new CPicture ( * bg , descriptionRect ) , this , mapDescription , true ) ; //move subpicture bg to our description control (by default it's our (Infocard) child)
2010-09-03 21:42:54 +03:00
if ( network )
{
2010-10-24 14:35:14 +03:00
playerListBg = new CPicture ( " CHATPLUG.bmp " , 16 , 276 ) ;
2010-09-03 21:42:54 +03:00
chat = new CChatBox ( descriptionRect ) ;
2010-10-24 14:35:14 +03:00
moveChild ( new CPicture ( * bg , chat - > chatHistory - > pos - pos ) , this , chat - > chatHistory , true ) ; //move subpicture bg to our description control (by default it's our (Infocard) child)
chatOn = true ;
mapDescription - > disable ( ) ;
2010-09-03 21:42:54 +03:00
}
2010-02-13 18:26:47 +02:00
}
2010-07-06 05:10:26 +03:00
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
InfoCard : : ~ InfoCard ( )
2009-05-29 04:50:33 +03:00
{
2009-08-17 11:50:31 +03:00
delete sizes ;
delete sFlags ;
2008-08-02 18:08:03 +03:00
}
2009-05-29 04:50:33 +03:00
2009-08-17 11:50:31 +03:00
void InfoCard : : showAll ( SDL_Surface * to )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
CIntObject : : showAll ( to ) ;
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
//blit texts
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : campaignList )
2010-02-13 18:26:47 +02:00
{
printAtLoc ( CGI - > generaltexth - > allTexts [ 390 ] + " : " , 24 , 400 , FONT_SMALL , zwykly , to ) ; //Allies
printAtLoc ( CGI - > generaltexth - > allTexts [ 391 ] + " : " , 190 , 400 , FONT_SMALL , zwykly , to ) ; //Enemies
printAtLoc ( CGI - > generaltexth - > allTexts [ 494 ] , 33 , 430 , FONT_SMALL , tytulowy , to ) ; //"Map Diff:"
printAtLoc ( CGI - > generaltexth - > allTexts [ 492 ] + " : " , 133 , 430 , FONT_SMALL , tytulowy , to ) ; //player difficulty
printAtLoc ( CGI - > generaltexth - > allTexts [ 218 ] + " : " , 290 , 430 , FONT_SMALL , tytulowy , to ) ; //"Rating:"
printAtLoc ( CGI - > generaltexth - > allTexts [ 495 ] , 26 , 22 , FONT_SMALL , tytulowy , to ) ; //Scenario Name:
2010-10-24 14:35:14 +03:00
if ( ! chatOn )
{
printAtLoc ( CGI - > generaltexth - > allTexts [ 496 ] , 26 , 132 , FONT_SMALL , tytulowy , to ) ; //Scenario Description:
printAtLoc ( CGI - > generaltexth - > allTexts [ 497 ] , 26 , 283 , FONT_SMALL , tytulowy , to ) ; //Victory Condition:
printAtLoc ( CGI - > generaltexth - > allTexts [ 498 ] , 26 , 339 , FONT_SMALL , tytulowy , to ) ; //Loss Condition:
}
else //players list
{
std : : map < ui32 , std : : string > playerNames = SEL - > playerNames ;
int playerSoFar = 0 ;
for ( std : : map < int , PlayerSettings > : : const_iterator i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
{
if ( i - > second . human )
{
printAtLoc ( i - > second . name , 24 , 285 + playerSoFar + + * graphics - > fonts [ FONT_SMALL ] - > height , FONT_SMALL , zwykly , to ) ;
playerNames . erase ( i - > second . human ) ;
}
}
playerSoFar = 0 ;
for ( std : : map < ui32 , std : : string > : : const_iterator i = playerNames . begin ( ) ; i ! = playerNames . end ( ) ; i + + )
{
printAtLoc ( i - > second , 193 , 285 + playerSoFar + + * graphics - > fonts [ FONT_SMALL ] - > height , FONT_SMALL , zwykly , to ) ;
}
}
2010-02-13 18:26:47 +02:00
}
2009-08-17 11:50:31 +03:00
2010-10-24 14:35:14 +03:00
if ( SEL - > current )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : campaignList )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : newGame )
2008-08-02 18:08:03 +03:00
{
2010-02-13 18:26:47 +02:00
for ( int i = 0 ; i < difficulty - > buttons . size ( ) ; i + + )
{
2010-10-24 14:35:14 +03:00
//if(i == SEL->current->difficulty)
2010-02-13 18:26:47 +02:00
// difficulty->buttons[i]->state = 3;
//else
// difficulty->buttons[i]->state = 2;
2008-08-02 18:08:03 +03:00
2010-02-13 18:26:47 +02:00
difficulty - > buttons [ i ] - > showAll ( to ) ;
}
2008-08-02 18:08:03 +03:00
}
2010-10-24 14:35:14 +03:00
int temp = - 1 ;
2008-08-02 18:08:03 +03:00
2010-10-24 14:35:14 +03:00
if ( ! chatOn )
{
//victory conditions
temp = SEL - > current - > mapHeader - > victoryCondition . condition + 1 ;
if ( temp > 20 ) temp = 0 ;
std : : string sss = CGI - > generaltexth - > victoryConditions [ temp ] ;
if ( temp & & SEL - > current - > mapHeader - > victoryCondition . allowNormalVictory ) sss + = " / " + CGI - > generaltexth - > victoryConditions [ 0 ] ;
printAtLoc ( sss , 60 , 307 , FONT_SMALL , zwykly , to ) ;
temp = SEL - > current - > mapHeader - > victoryCondition . condition ;
if ( temp > 12 ) temp = 11 ;
blitAtLoc ( CGP - > victory - > ourImages [ temp ] . bitmap , 24 , 302 , to ) ; //victory cond descr
//loss conditoins
temp = SEL - > current - > mapHeader - > lossCondition . typeOfLossCon + 1 ;
if ( temp > 20 ) temp = 0 ;
sss = CGI - > generaltexth - > lossCondtions [ temp ] ;
printAtLoc ( sss , 60 , 366 , FONT_SMALL , zwykly , to ) ;
temp = SEL - > current - > mapHeader - > lossCondition . typeOfLossCon ;
if ( temp > 12 ) temp = 3 ;
blitAtLoc ( CGP - > loss - > ourImages [ temp ] . bitmap , 24 , 359 , to ) ; //loss cond
}
2008-08-02 18:08:03 +03:00
2010-02-13 18:26:47 +02:00
//difficulty
2010-10-24 14:35:14 +03:00
assert ( SEL - > current - > mapHeader - > difficulty < = 4 ) ;
std : : string & diff = CGI - > generaltexth - > arraytxt [ 142 + SEL - > current - > mapHeader - > difficulty ] ;
2010-02-13 18:26:47 +02:00
printAtMiddleLoc ( diff , 62 , 472 , FONT_SMALL , zwykly , to ) ;
//selecting size icon
2010-10-24 14:35:14 +03:00
switch ( SEL - > current - > mapHeader - > width )
2010-02-13 18:26:47 +02:00
{
case 36 :
temp = 0 ;
break ;
case 72 :
temp = 1 ;
break ;
case 108 :
temp = 2 ;
break ;
case 144 :
temp = 3 ;
break ;
default :
temp = 4 ;
break ;
}
blitAtLoc ( sizes - > ourImages [ temp ] . bitmap , 318 , 22 , to ) ;
2010-02-15 14:12:21 +02:00
2010-02-13 18:26:47 +02:00
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : loadGame )
printToLoc ( ( static_cast < const CMapInfo * > ( SEL - > current ) ) - > date , 308 , 34 , FONT_SMALL , zwykly , to ) ;
2010-02-13 18:26:47 +02:00
//print flags
2011-01-17 18:07:08 +02:00
int fx = 34 + graphics - > fonts [ FONT_SMALL ] - > getWidth ( CGI - > generaltexth - > allTexts [ 390 ] . c_str ( ) ) ;
int ex = 200 + graphics - > fonts [ FONT_SMALL ] - > getWidth ( CGI - > generaltexth - > allTexts [ 391 ] . c_str ( ) ) ;
int myT ;
2010-10-24 14:35:14 +03:00
if ( playerColor > = 0 )
myT = SEL - > current - > mapHeader - > players [ playerColor ] . team ;
else
myT = - 1 ;
for ( std : : map < int , PlayerSettings > : : const_iterator i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
2010-02-13 18:26:47 +02:00
{
2010-10-24 14:35:14 +03:00
int * myx = ( ( i - > first = = playerColor | | SEL - > current - > mapHeader - > players [ i - > first ] . team = = myT ) ? & fx : & ex ) ;
2010-08-03 14:36:52 +03:00
blitAtLoc ( sFlags - > ourImages [ i - > first ] . bitmap , * myx , 399 , to ) ;
* myx + = sFlags - > ourImages [ i - > first ] . bitmap - > w ;
2010-02-13 18:26:47 +02:00
}
std : : string tob ;
2010-10-24 14:35:14 +03:00
switch ( SEL - > sInfo . difficulty )
2010-02-13 18:26:47 +02:00
{
case 0 :
tob = " 80% " ;
break ;
case 1 :
tob = " 100% " ;
break ;
case 2 :
tob = " 130% " ;
break ;
case 3 :
tob = " 160% " ;
break ;
case 4 :
tob = " 200% " ;
break ;
}
printAtMiddleLoc ( tob , 311 , 472 , FONT_SMALL , zwykly , to ) ;
}
2008-08-02 18:08:03 +03:00
2009-05-29 04:50:33 +03:00
//blit description
2010-07-06 05:10:26 +03:00
std : : string name ;
2010-02-13 18:26:47 +02:00
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : campaignList )
2010-02-13 18:26:47 +02:00
{
2010-10-24 14:35:14 +03:00
name = SEL - > current - > campaignHeader - > name ;
2010-02-13 18:26:47 +02:00
}
else
{
2010-10-24 14:35:14 +03:00
name = SEL - > current - > mapHeader - > name ;
2010-02-13 18:26:47 +02:00
}
2009-01-12 22:05:56 +02:00
2010-02-13 18:26:47 +02:00
//name
if ( name . length ( ) )
printAtLoc ( name , 26 , 39 , FONT_BIG , tytulowy , to ) ;
2009-08-17 11:50:31 +03:00
else
printAtLoc ( " Unnamed " , 26 , 39 , FONT_BIG , tytulowy , to ) ;
2009-06-10 22:44:09 +03:00
2010-02-13 18:26:47 +02:00
2008-08-02 18:08:03 +03:00
}
}
2009-05-04 02:38:08 +03:00
2009-08-17 11:50:31 +03:00
void InfoCard : : changeSelection ( const CMapInfo * to )
2008-08-02 18:08:03 +03:00
{
2010-07-06 05:10:26 +03:00
if ( to & & mapDescription )
{
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : campaignList )
2010-07-06 05:10:26 +03:00
mapDescription - > setTxt ( to - > campaignHeader - > description ) ;
else
mapDescription - > setTxt ( to - > mapHeader - > description ) ;
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : newGame & & SEL - > screenType ! = CMenuScreen : : campaignList )
difficulty - > select ( SEL - > sInfo . difficulty , 0 ) ;
2010-07-06 05:10:26 +03:00
}
2009-08-17 11:50:31 +03:00
GH . totalRedraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-22 16:59:15 +03:00
void InfoCard : : clickRight ( tribool down , bool previousState )
{
static const Rect flagArea ( 19 , 397 , 335 , 23 ) ;
2010-10-24 14:35:14 +03:00
if ( down & & SEL - > current & & isItInLoc ( flagArea , GH . current - > motion . x , GH . current - > motion . y ) )
2009-08-22 16:59:15 +03:00
showTeamsPopup ( ) ;
}
void InfoCard : : showTeamsPopup ( )
{
2010-10-24 14:35:14 +03:00
SDL_Surface * bmp = CMessage : : drawBox1 ( 256 , 90 + 50 * SEL - > current - > mapHeader - > howManyTeams ) ;
2009-08-22 16:59:15 +03:00
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > allTexts [ 657 ] , 128 , 30 , FONT_MEDIUM , tytulowy , bmp ) ; //{Team Alignments}
2010-10-24 14:35:14 +03:00
for ( int i = 0 ; i < SEL - > current - > mapHeader - > howManyTeams ; i + + )
2009-08-22 16:59:15 +03:00
{
std : : vector < ui8 > flags ;
std : : string hlp = CGI - > generaltexth - > allTexts [ 656 ] ; //Team %d
hlp . replace ( hlp . find ( " %d " ) , 2 , boost : : lexical_cast < std : : string > ( i + 1 ) ) ;
CSDL_Ext : : printAtMiddle ( hlp , 128 , 65 + 50 * i , FONT_SMALL , zwykly , bmp ) ;
for ( int j = 0 ; j < PLAYER_LIMIT ; j + + )
2010-10-24 14:35:14 +03:00
if ( ( SEL - > current - > mapHeader - > players [ j ] . canHumanPlay | | SEL - > current - > mapHeader - > players [ j ] . canComputerPlay )
& & SEL - > current - > mapHeader - > players [ j ] . team = = i )
2009-08-22 16:59:15 +03:00
flags . push_back ( j ) ;
int curx = 128 - 9 * flags . size ( ) ;
for ( int j = 0 ; j < flags . size ( ) ; j + + )
{
blitAt ( sFlags - > ourImages [ flags [ j ] ] . bitmap , curx , 75 + 50 * i , bmp ) ;
curx + = 18 ;
}
}
GH . pushInt ( new CInfoPopup ( bmp , true ) ) ;
}
2010-09-03 21:42:54 +03:00
void InfoCard : : toggleChat ( )
{
setChat ( ! chatOn ) ;
}
void InfoCard : : setChat ( bool activateChat )
{
if ( chatOn = = activateChat )
return ;
assert ( active ) ;
if ( activateChat )
{
2010-10-24 14:35:14 +03:00
mapDescription - > disable ( ) ;
chat - > enable ( ) ;
playerListBg - > enable ( ) ;
2010-09-03 21:42:54 +03:00
}
else
{
2010-10-24 14:35:14 +03:00
mapDescription - > enable ( ) ;
chat - > disable ( ) ;
playerListBg - > disable ( ) ;
2010-09-03 21:42:54 +03:00
}
chatOn = activateChat ;
2010-10-24 14:35:14 +03:00
GH . totalRedraw ( ) ;
2010-09-03 21:42:54 +03:00
}
2011-01-17 18:07:08 +02:00
OptionsTab : : OptionsTab ( ) :
turnDuration ( NULL )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
OBJ_CONSTRUCTION ;
2009-08-27 11:04:32 +03:00
bg = new CPicture ( BitmapHandler : : loadBitmap ( " ADVOPTBK.bmp " ) , 0 , 0 , true ) ;
2009-08-17 11:50:31 +03:00
pos = bg - > pos ;
2008-08-02 18:08:03 +03:00
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : newGame )
2009-08-27 11:04:32 +03:00
turnDuration = new CSlider ( 55 , 551 , 194 , bind ( & OptionsTab : : setTurnLength , this , _1 ) , 1 , 11 , 11 , true , 1 ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
OptionsTab : : ~ OptionsTab ( )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
void OptionsTab : : showAll ( SDL_Surface * to )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
CIntObject : : showAll ( to ) ;
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 515 ] , 222 , 30 , FONT_BIG , tytulowy , to ) ;
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 516 ] , 222 , 58 , FONT_SMALL , 55 , zwykly , to ) ; //Select starting options, handicap, and name for each player in the game.
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 517 ] , 107 , 102 , FONT_SMALL , 14 , tytulowy , to ) ; //Player Name Handicap Type
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 518 ] , 197 , 102 , FONT_SMALL , 10 , tytulowy , to ) ; //Starting Town
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 519 ] , 273 , 102 , FONT_SMALL , 10 , tytulowy , to ) ; //Starting Hero
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 520 ] , 349 , 102 , FONT_SMALL , 10 , tytulowy , to ) ; //Starting Bonus
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 521 ] , 222 , 538 , FONT_SMALL , tytulowy , to ) ; // Player Turn Duration
2011-01-17 18:07:08 +02:00
if ( turnDuration )
printAtMiddleLoc ( CGI - > generaltexth - > turnDurations [ turnDuration - > value ] , 319 , 559 , FONT_SMALL , zwykly , to ) ; //Turn duration value
2009-08-17 11:50:31 +03:00
}
void OptionsTab : : nextCastle ( int player , int dir )
{
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) )
{
SEL - > postRequest ( RequestOptionsChange : : TOWN , dir ) ;
return ;
}
PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-18 11:22:56 +03:00
si32 & cur = s . castle ;
2010-10-24 14:35:14 +03:00
ui32 allowed = SEL - > current - > mapHeader - > players [ s . color ] . allowedFactions ;
2009-08-17 11:50:31 +03:00
2010-08-04 14:18:13 +03:00
if ( cur = = - 2 ) //no castle - no change
return ;
if ( cur = = - 1 ) //random => first/last available
{
int pom = ( dir > 0 ) ? ( 0 ) : ( F_NUMBER - 1 ) ; // last or first
for ( ; pom > = 0 & & pom < F_NUMBER ; pom + = dir )
{
if ( ( 1 < < pom ) & allowed )
{
cur = pom ;
break ;
}
}
}
else // next/previous available
{
for ( ; ; )
{
2009-08-17 11:50:31 +03:00
cur + = dir ;
if ( ( 1 < < cur ) & allowed )
2010-08-04 14:18:13 +03:00
break ;
if ( cur > = F_NUMBER | | cur < 0 )
{
double p1 = log ( ( double ) allowed ) / log ( 2.0f ) + 0.000001f ;
double check = p1 - ( ( int ) p1 ) ;
if ( check < 0.001 )
cur = ( int ) p1 ;
else
cur = - 1 ;
break ;
}
}
}
2009-08-17 11:50:31 +03:00
2009-08-18 11:22:56 +03:00
if ( s . hero > = 0 )
s . hero = - 1 ;
2010-08-04 14:18:13 +03:00
if ( cur < 0 & & s . bonus = = PlayerSettings : : bresource )
s . bonus = PlayerSettings : : brandom ;
2009-08-18 11:22:56 +03:00
entries [ player ] - > selectButtons ( ) ;
2010-10-24 14:35:14 +03:00
SEL - > propagateOptions ( ) ;
2009-08-17 11:50:31 +03:00
redraw ( ) ;
}
void OptionsTab : : nextHero ( int player , int dir )
{
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) )
{
SEL - > postRequest ( RequestOptionsChange : : HERO , dir ) ;
return ;
}
PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-17 11:50:31 +03:00
int old = s . hero ;
if ( s . castle < 0 | | ! s . human | | s . hero = = - 2 )
return ;
2008-08-02 18:08:03 +03:00
2009-08-17 11:50:31 +03:00
if ( s . hero = = - 1 ) //random => first/last available
2009-02-11 19:48:40 +02:00
{
2009-08-17 11:50:31 +03:00
int max = ( s . castle * HEROES_PER_TYPE * 2 + 15 ) ,
min = ( s . castle * HEROES_PER_TYPE * 2 ) ;
s . hero = nextAllowedHero ( min , max , 0 , dir ) ;
2009-02-11 19:48:40 +02:00
}
2009-08-17 11:50:31 +03:00
else
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
if ( dir > 0 )
s . hero = nextAllowedHero ( s . hero , ( s . castle * HEROES_PER_TYPE * 2 + 16 ) , 1 , dir ) ;
else
s . hero = nextAllowedHero ( s . castle * HEROES_PER_TYPE * 2 - 1 , s . hero , 1 , dir ) ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
if ( old ! = s . hero )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
usedHeroes . erase ( old ) ;
usedHeroes . insert ( s . hero ) ;
redraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2010-10-24 14:35:14 +03:00
SEL - > propagateOptions ( ) ;
2009-08-17 11:50:31 +03:00
}
int OptionsTab : : nextAllowedHero ( int min , int max , int incl , int dir )
{
if ( dir > 0 )
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
for ( int i = min + incl ; i < = max - incl ; i + + )
if ( canUseThisHero ( i ) )
return i ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
else
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
for ( int i = max - incl ; i > = min + incl ; i - - )
if ( canUseThisHero ( i ) )
return i ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
return - 1 ;
2008-08-02 18:08:03 +03:00
}
2009-05-01 19:14:29 +03:00
2009-08-17 11:50:31 +03:00
bool OptionsTab : : canUseThisHero ( int ID )
{
//for(int i=0;i<CPG->ret.playerInfos.size();i++)
// if(CPG->ret.playerInfos[i].hero==ID) //hero is already taken
// return false;
2009-06-24 09:56:36 +03:00
2010-10-24 14:35:14 +03:00
return ! vstd : : contains ( usedHeroes , ID ) & & SEL - > current - > mapHeader - > allowedHeroes [ ID ] ;
2009-08-17 11:50:31 +03:00
}
2009-02-11 19:03:30 +02:00
2009-08-17 11:50:31 +03:00
void OptionsTab : : nextBonus ( int player , int dir )
{
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) )
{
SEL - > postRequest ( RequestOptionsChange : : BONUS , dir ) ;
return ;
}
PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-17 11:50:31 +03:00
si8 & ret = s . bonus + = dir ;
2009-06-24 09:56:36 +03:00
2010-10-24 14:35:14 +03:00
if ( s . hero = = - 2 & & ! SEL - > current - > mapHeader - > players [ s . color ] . heroesNames . size ( ) & & ret = = PlayerSettings : : bartifact ) //no hero - can't be artifact
2009-08-17 11:50:31 +03:00
{
if ( dir < 0 )
2010-07-31 16:55:05 +03:00
ret = PlayerSettings : : brandom ;
else ret = PlayerSettings : : bgold ;
2008-08-02 18:08:03 +03:00
}
2009-06-28 02:33:59 +03:00
2010-07-31 16:55:05 +03:00
if ( ret > PlayerSettings : : bresource )
ret = PlayerSettings : : brandom ;
if ( ret < PlayerSettings : : brandom )
ret = PlayerSettings : : bresource ;
2009-06-24 09:56:36 +03:00
2010-07-31 16:55:05 +03:00
if ( s . castle = = - 1 & & ret = = PlayerSettings : : bresource ) //random castle - can't be resource
2008-08-02 18:08:03 +03:00
{
2009-08-17 11:50:31 +03:00
if ( dir < 0 )
2010-07-31 16:55:05 +03:00
ret = PlayerSettings : : bgold ;
else ret = PlayerSettings : : brandom ;
2008-08-02 18:08:03 +03:00
}
2009-05-29 04:54:45 +03:00
2010-10-24 14:35:14 +03:00
SEL - > propagateOptions ( ) ;
2009-08-17 11:50:31 +03:00
redraw ( ) ;
2008-08-02 18:08:03 +03:00
}
2009-05-29 04:54:45 +03:00
2010-10-24 14:35:14 +03:00
void OptionsTab : : recreate ( )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
bool wasActive = active ;
if ( active )
deactivate ( ) ;
2010-08-03 14:36:52 +03:00
for ( std : : map < int , PlayerOptionsEntry * > : : iterator it = entries . begin ( ) ; it ! = entries . end ( ) ; + + it )
2008-08-02 18:08:03 +03:00
{
2010-08-03 14:36:52 +03:00
children - = it - > second ;
delete it - > second ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
entries . clear ( ) ;
usedHeroes . clear ( ) ;
2010-03-06 00:51:09 +02:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-10-24 14:35:14 +03:00
for ( std : : map < int , PlayerSettings > : : iterator it = SEL - > sInfo . playerInfos . begin ( ) ;
it ! = SEL - > sInfo . playerInfos . end ( ) ; + + it )
2008-08-02 18:08:03 +03:00
{
2010-08-03 14:36:52 +03:00
entries . insert ( std : : make_pair ( it - > first , new PlayerOptionsEntry ( this , it - > second ) ) ) ;
2010-10-24 14:35:14 +03:00
const std : : vector < SheroName > & heroes = SEL - > current - > mapHeader - > players [ it - > first ] . heroesNames ;
2009-08-17 11:50:31 +03:00
for ( size_t hi = 0 ; hi < heroes . size ( ) ; hi + + )
usedHeroes . insert ( heroes [ hi ] . heroID ) ;
2008-08-02 18:08:03 +03:00
}
2010-10-24 14:35:14 +03:00
if ( wasActive )
activate ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
2009-08-17 11:50:31 +03:00
void OptionsTab : : setTurnLength ( int npos )
2008-11-16 03:06:15 +02:00
{
2009-08-17 11:50:31 +03:00
static const int times [ ] = { 1 , 2 , 4 , 6 , 8 , 10 , 15 , 20 , 25 , 30 , 0 } ;
amin ( npos , ARRAY_COUNT ( times ) - 1 ) ;
2010-10-24 14:35:14 +03:00
SEL - > sInfo . turnTime = times [ npos ] ;
2009-08-17 11:50:31 +03:00
redraw ( ) ;
2008-11-16 03:06:15 +02:00
}
2010-10-24 14:35:14 +03:00
void OptionsTab : : flagPressed ( int color )
2008-11-16 03:06:15 +02:00
{
2010-10-24 14:35:14 +03:00
PlayerSettings & clicked = SEL - > sInfo . playerInfos [ color ] ;
2010-02-16 18:35:24 +02:00
PlayerSettings * old = NULL ;
2010-10-24 14:35:14 +03:00
if ( SEL - > playerNames . size ( ) = = 1 ) //single player -> just swap
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
if ( color = = playerColor ) //that color is already selected, no action needed
2010-02-16 18:35:24 +02:00
return ;
2010-10-24 14:35:14 +03:00
old = & SEL - > sInfo . playerInfos [ playerColor ] ;
swapPlayers ( * old , clicked ) ;
2010-02-16 18:35:24 +02:00
}
else
{
//identify clicked player
2010-10-24 14:35:14 +03:00
int clickedNameID = clicked . human ; //human is a number of player, zero means AI
2010-02-16 18:35:24 +02:00
2010-10-24 14:35:14 +03:00
if ( clickedNameID > 0 & & playerToRestore . id = = clickedNameID ) //player to restore is about to being replaced -> put him back to the old place
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
PlayerSettings & restPos = SEL - > sInfo . playerInfos [ playerToRestore . color ] ;
SEL - > setPlayer ( restPos , playerToRestore . id ) ;
playerToRestore . reset ( ) ;
2010-02-16 18:35:24 +02:00
}
2011-05-04 05:38:58 +03:00
int newPlayer ; //which player will take clicked position
2010-10-24 14:35:14 +03:00
2010-08-04 14:18:13 +03:00
//who will be put here?
2010-10-24 14:35:14 +03:00
if ( ! clickedNameID ) //AI player clicked -> if possible replace computer with unallocated player
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
newPlayer = SEL - > getIdOfFirstUnallocatedPlayer ( ) ;
if ( ! newPlayer ) //no "free" player -> get just first one
newPlayer = SEL - > playerNames . begin ( ) - > first ;
2010-02-16 18:35:24 +02:00
}
2010-10-24 14:35:14 +03:00
else //human clicked -> take next
{
std : : map < ui32 , std : : string > : : const_iterator i = SEL - > playerNames . find ( clickedNameID ) ; //clicked one
i + + ; //player AFTER clicked one
2009-08-18 11:22:56 +03:00
2010-10-24 14:35:14 +03:00
if ( i ! = SEL - > playerNames . end ( ) )
newPlayer = i - > first ;
else
newPlayer = 0 ; //AI if we scrolled through all players
}
SEL - > setPlayer ( clicked , newPlayer ) ; //put player
2009-08-18 11:22:56 +03:00
2010-02-16 18:35:24 +02:00
//if that player was somewhere else, we need to replace him with computer
2010-10-24 14:35:14 +03:00
if ( newPlayer ) //not AI
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
for ( std : : map < int , PlayerSettings > : : iterator i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
2010-02-16 18:35:24 +02:00
{
2010-10-24 14:35:14 +03:00
int curNameID = i - > second . human ;
if ( i - > first ! = color & & curNameID = = newPlayer )
2010-02-16 18:35:24 +02:00
{
2010-08-03 14:36:52 +03:00
assert ( i - > second . human ) ;
2010-10-24 14:35:14 +03:00
playerToRestore . color = i - > first ;
playerToRestore . id = newPlayer ;
SEL - > setPlayer ( i - > second , 0 ) ; //set computer
2010-08-03 14:36:52 +03:00
old = & i - > second ;
2010-02-16 18:35:24 +02:00
break ;
}
}
}
}
2009-08-18 11:22:56 +03:00
2010-08-03 14:36:52 +03:00
entries [ clicked . color ] - > selectButtons ( ) ;
2010-02-16 18:35:24 +02:00
if ( old )
{
2010-08-03 14:36:52 +03:00
entries [ old - > color ] - > selectButtons ( ) ;
2010-10-24 14:35:14 +03:00
old - > hero = entries [ old - > color ] - > pi . defaultHero ( ) ;
2010-02-16 18:35:24 +02:00
}
2010-10-24 14:35:14 +03:00
SEL - > propagateOptions ( ) ;
2009-08-17 11:50:31 +03:00
GH . totalRedraw ( ) ;
2008-11-16 03:06:15 +02:00
}
2009-08-17 11:50:31 +03:00
OptionsTab : : PlayerOptionsEntry : : PlayerOptionsEntry ( OptionsTab * owner , PlayerSettings & S )
2010-10-31 00:53:41 +03:00
: pi ( SEL - > current - > mapHeader - > players [ S . color ] ) , s ( S )
2008-11-16 03:06:15 +02:00
{
2009-08-17 11:50:31 +03:00
OBJ_CONSTRUCTION ;
defActions | = SHARE_POS ;
2010-10-24 14:35:14 +03:00
2010-08-03 14:36:52 +03:00
int serial = 0 ;
for ( int g = 0 ; g < s . color ; + + g )
{
2010-10-24 14:35:14 +03:00
PlayerInfo & itred = SEL - > current - > mapHeader - > players [ g ] ;
if ( itred . canComputerPlay | | itred . canHumanPlay )
2010-08-03 14:36:52 +03:00
serial + + ;
}
pos = parent - > pos + Point ( 54 , 122 + serial * 50 ) ;
2008-11-16 03:06:15 +02:00
2009-08-17 11:50:31 +03:00
static const char * flags [ ] = { " AOFLGBR.DEF " , " AOFLGBB.DEF " , " AOFLGBY.DEF " , " AOFLGBG.DEF " ,
" AOFLGBO.DEF " , " AOFLGBP.DEF " , " AOFLGBT.DEF " , " AOFLGBS.DEF " } ;
static const char * bgs [ ] = { " ADOPRPNL.bmp " , " ADOPBPNL.bmp " , " ADOPYPNL.bmp " , " ADOPGPNL.bmp " ,
" ADOPOPNL.bmp " , " ADOPPPNL.bmp " , " ADOPTPNL.bmp " , " ADOPSPNL.bmp " } ;
2008-11-16 03:06:15 +02:00
2009-08-17 11:50:31 +03:00
bg = new CPicture ( BitmapHandler : : loadBitmap ( bgs [ s . color ] ) , 0 , 0 , true ) ;
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : newGame )
2009-08-27 11:04:32 +03:00
{
2010-08-03 14:36:52 +03:00
btns [ 0 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 132 ] , bind ( & OptionsTab : : nextCastle , owner , s . color , - 1 ) , 107 , 5 , " ADOPLFA.DEF " ) ;
btns [ 1 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 133 ] , bind ( & OptionsTab : : nextCastle , owner , s . color , + 1 ) , 168 , 5 , " ADOPRTA.DEF " ) ;
btns [ 2 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 148 ] , bind ( & OptionsTab : : nextHero , owner , s . color , - 1 ) , 183 , 5 , " ADOPLFA.DEF " ) ;
btns [ 3 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 149 ] , bind ( & OptionsTab : : nextHero , owner , s . color , + 1 ) , 244 , 5 , " ADOPRTA.DEF " ) ;
btns [ 4 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 164 ] , bind ( & OptionsTab : : nextBonus , owner , s . color , - 1 ) , 259 , 5 , " ADOPLFA.DEF " ) ;
btns [ 5 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 165 ] , bind ( & OptionsTab : : nextBonus , owner , s . color , + 1 ) , 320 , 5 , " ADOPRTA.DEF " ) ;
2009-08-27 11:04:32 +03:00
}
2009-09-07 05:29:44 +03:00
else
for ( int i = 0 ; i < 6 ; i + + )
btns [ i ] = NULL ;
2009-05-10 01:19:41 +03:00
2011-08-25 18:24:37 +03:00
selectButtons ( ) ;
2009-08-18 11:22:56 +03:00
2010-10-24 14:35:14 +03:00
assert ( SEL - > current & & SEL - > current - > mapHeader ) ;
const PlayerInfo & p = SEL - > current - > mapHeader - > players [ s . color ] ;
2010-03-08 00:56:51 +02:00
assert ( p . canComputerPlay | | p . canHumanPlay ) ; //someone must be able to control this player
if ( p . canHumanPlay & & p . canComputerPlay )
whoCanPlay = HUMAN_OR_CPU ;
else if ( p . canComputerPlay )
whoCanPlay = CPU ;
else
whoCanPlay = HUMAN ;
2009-08-18 11:22:56 +03:00
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType ! = CMenuScreen : : scenarioInfo
& & SEL - > current - > mapHeader - > players [ s . color ] . canHumanPlay
& & SEL - > multiPlayer ! = CMenuScreen : : MULTI_NETWORK_GUEST )
2009-08-17 11:50:31 +03:00
{
2010-08-03 14:36:52 +03:00
flag = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 180 ] , bind ( & OptionsTab : : flagPressed , owner , s . color ) , - 43 , 2 , flags [ s . color ] ) ;
2009-08-17 11:50:31 +03:00
flag - > hoverable = true ;
}
else
flag = NULL ;
2009-08-22 16:59:15 +03:00
defActions & = ~ SHARE_POS ;
2010-08-03 14:36:52 +03:00
town = new SelectedBox ( TOWN , s . color ) ;
2009-08-22 16:59:15 +03:00
town - > pos + = pos + Point ( 119 , 2 ) ;
2010-08-03 14:36:52 +03:00
hero = new SelectedBox ( HERO , s . color ) ;
2009-08-22 16:59:15 +03:00
hero - > pos + = pos + Point ( 195 , 2 ) ;
2010-08-03 14:36:52 +03:00
bonus = new SelectedBox ( BONUS , s . color ) ;
2009-08-22 16:59:15 +03:00
bonus - > pos + = pos + Point ( 271 , 2 ) ;
2008-11-16 03:06:15 +02:00
}
2009-08-17 11:50:31 +03:00
void OptionsTab : : PlayerOptionsEntry : : showAll ( SDL_Surface * to )
2008-11-16 03:06:15 +02:00
{
2009-08-17 11:50:31 +03:00
CIntObject : : showAll ( to ) ;
printAtMiddleLoc ( s . name , 55 , 10 , FONT_SMALL , zwykly , to ) ;
2011-01-17 18:07:08 +02:00
printAtMiddleWBLoc ( CGI - > generaltexth - > arraytxt [ 206 + whoCanPlay ] , 28 , 34 , FONT_TINY , 8 , zwykly , to ) ;
2008-11-16 03:06:15 +02:00
}
2011-08-25 18:24:37 +03:00
void OptionsTab : : PlayerOptionsEntry : : selectButtons ( )
2009-08-18 11:22:56 +03:00
{
2009-09-07 05:29:44 +03:00
if ( ! btns [ 0 ] )
2009-08-27 11:04:32 +03:00
return ;
2011-08-25 18:24:37 +03:00
if ( ( pi . defaultCastle ( ) ! = - 1 ) //fixed tow
2010-11-15 17:15:00 +02:00
| | ( SEL - > isGuest ( ) & & s . color ! = playerColor ) ) //or not our player
2009-08-18 11:22:56 +03:00
{
btns [ 0 ] - > disable ( ) ;
btns [ 1 ] - > disable ( ) ;
}
2010-10-24 14:35:14 +03:00
else
{
btns [ 0 ] - > enable ( active ) ;
btns [ 1 ] - > enable ( active ) ;
}
2010-11-15 17:15:00 +02:00
if ( ( pi . defaultHero ( ) ! = - 1 | | ! s . human | | s . castle < 0 ) //fixed hero
| | ( SEL - > isGuest ( ) & & s . color ! = playerColor ) ) //or not our player
2009-08-18 11:22:56 +03:00
{
btns [ 2 ] - > disable ( ) ;
btns [ 3 ] - > disable ( ) ;
}
else
{
btns [ 2 ] - > enable ( active ) ;
btns [ 3 ] - > enable ( active ) ;
}
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) & & s . color ! = playerColor ) //or not our player
{
btns [ 4 ] - > disable ( ) ;
btns [ 5 ] - > disable ( ) ;
}
else
{
btns [ 4 ] - > enable ( active ) ;
btns [ 5 ] - > enable ( active ) ;
}
2009-08-18 11:22:56 +03:00
}
2009-08-17 11:50:31 +03:00
void OptionsTab : : SelectedBox : : showAll ( SDL_Surface * to )
2008-11-16 03:06:15 +02:00
{
2010-10-24 14:35:14 +03:00
//PlayerSettings &s = SEL->sInfo.playerInfos[player];
2009-08-22 16:59:15 +03:00
SDL_Surface * toBlit = getImg ( ) ;
const std : : string * toPrint = getText ( ) ;
blitAt ( toBlit , pos , to ) ;
printAtMiddleLoc ( * toPrint , 23 , 39 , FONT_TINY , zwykly , to ) ;
}
2009-08-17 11:50:31 +03:00
2009-08-22 16:59:15 +03:00
OptionsTab : : SelectedBox : : SelectedBox ( SelType Which , ui8 Player )
: which ( Which ) , player ( Player )
{
SDL_Surface * img = getImg ( ) ;
pos . w = img - > w ;
pos . h = img - > h ;
used = RCLICK ;
}
SDL_Surface * OptionsTab : : SelectedBox : : getImg ( ) const
{
2010-10-24 14:35:14 +03:00
const PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-17 11:50:31 +03:00
switch ( which )
{
case TOWN :
2009-08-22 16:59:15 +03:00
if ( s . castle < F_NUMBER & & s . castle > = 0 )
return graphics - > getPic ( s . castle , true , false ) ;
else if ( s . castle = = - 1 )
return CGP - > rTown ;
else if ( s . castle = = - 2 )
return CGP - > nTown ;
case HERO :
if ( s . hero = = - 1 )
2009-08-17 11:50:31 +03:00
{
2009-08-22 16:59:15 +03:00
return CGP - > rHero ;
2009-08-17 11:50:31 +03:00
}
2009-08-22 16:59:15 +03:00
else if ( s . hero = = - 2 )
2009-08-17 11:50:31 +03:00
{
2009-08-22 16:59:15 +03:00
if ( s . heroPortrait > = 0 )
return graphics - > portraitSmall [ s . heroPortrait ] ;
2009-08-17 11:50:31 +03:00
else
2009-08-22 16:59:15 +03:00
return CGP - > nHero ;
}
else
{
return graphics - > portraitSmall [ s . hero ] ;
2009-08-17 11:50:31 +03:00
}
break ;
case BONUS :
{
int pom ;
switch ( s . bonus )
{
case - 1 :
pom = 10 ;
break ;
case 0 :
pom = 9 ;
break ;
case 1 :
pom = 8 ;
break ;
case 2 :
pom = CGI - > townh - > towns [ s . castle ] . bonus ;
break ;
2009-08-22 16:59:15 +03:00
default :
assert ( 0 ) ;
2009-08-17 11:50:31 +03:00
}
2009-08-22 16:59:15 +03:00
return CGP - > bonuses - > ourImages [ pom ] . bitmap ;
2009-08-17 11:50:31 +03:00
}
2009-08-22 16:59:15 +03:00
default :
return NULL ;
2009-08-17 11:50:31 +03:00
}
2009-08-22 16:59:15 +03:00
}
2009-08-18 11:22:56 +03:00
2009-08-22 16:59:15 +03:00
const std : : string * OptionsTab : : SelectedBox : : getText ( ) const
{
2010-10-24 14:35:14 +03:00
const PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-22 16:59:15 +03:00
switch ( which )
{
case TOWN :
if ( s . castle < F_NUMBER & & s . castle > = 0 )
return & CGI - > townh - > towns [ s . castle ] . Name ( ) ;
else if ( s . castle = = - 1 )
return & CGI - > generaltexth - > allTexts [ 522 ] ;
else if ( s . castle = = - 2 )
return & CGI - > generaltexth - > allTexts [ 523 ] ;
case HERO :
if ( s . hero = = - 1 )
return & CGI - > generaltexth - > allTexts [ 522 ] ;
else if ( s . hero = = - 2 )
{
if ( s . heroPortrait > = 0 )
{
if ( s . heroName . length ( ) )
return & s . heroName ;
else
return & CGI - > heroh - > heroes [ s . heroPortrait ] - > name ;
}
else
return & CGI - > generaltexth - > allTexts [ 523 ] ;
}
else
{
//if(s.heroName.length())
// return &s.heroName;
//else
return & CGI - > heroh - > heroes [ s . hero ] - > name ;
}
case BONUS :
switch ( s . bonus )
{
case - 1 :
return & CGI - > generaltexth - > allTexts [ 522 ] ;
default :
return & CGI - > generaltexth - > arraytxt [ 214 + s . bonus ] ;
}
default :
return NULL ;
}
2008-11-16 03:06:15 +02:00
}
2009-08-22 16:59:15 +03:00
void OptionsTab : : SelectedBox : : clickRight ( tribool down , bool previousState )
2008-11-16 03:06:15 +02:00
{
2009-08-22 16:59:15 +03:00
if ( indeterminate ( down ) | | ! down ) return ;
2010-10-24 14:35:14 +03:00
const PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2009-08-22 16:59:15 +03:00
SDL_Surface * bmp = NULL ;
const std : : string * title = NULL , * subTitle = NULL ;
subTitle = getText ( ) ;
2011-02-20 11:24:53 +02:00
int val = - 1 ;
2009-08-22 16:59:15 +03:00
switch ( which )
{
2009-10-06 04:14:00 +03:00
case TOWN :
val = s . castle ;
break ;
2009-08-22 16:59:15 +03:00
case HERO :
val = s . hero ;
2010-02-11 06:24:37 +02:00
if ( val = = - 2 ) //none => we may have some preset info
2009-08-22 16:59:15 +03:00
{
2010-10-24 14:35:14 +03:00
int p9 = SEL - > current - > mapHeader - > players [ s . color ] . p9 ;
if ( p9 ! = 255 & & SEL - > sInfo . playerInfos [ player ] . heroPortrait > = 0 )
2009-08-22 16:59:15 +03:00
val = p9 ;
}
break ;
2009-10-06 04:14:00 +03:00
case BONUS :
val = s . bonus ;
break ;
2009-08-22 16:59:15 +03:00
}
if ( val = = - 1 | | which = = BONUS ) //random or bonus box
{
bmp = CMessage : : drawBox1 ( 256 , 190 ) ;
std : : string * description = NULL ;
switch ( which )
{
case TOWN :
title = & CGI - > generaltexth - > allTexts [ 103 ] ;
description = & CGI - > generaltexth - > allTexts [ 104 ] ;
break ;
case HERO :
title = & CGI - > generaltexth - > allTexts [ 101 ] ;
description = & CGI - > generaltexth - > allTexts [ 102 ] ;
break ;
case BONUS :
{
switch ( val )
{
2010-07-31 16:55:05 +03:00
case PlayerSettings : : brandom :
2009-08-22 16:59:15 +03:00
title = & CGI - > generaltexth - > allTexts [ 86 ] ; //{Random Bonus}
description = & CGI - > generaltexth - > allTexts [ 94 ] ; //Gold, wood and ore, or an artifact is randomly chosen as your starting bonus
break ;
2010-07-31 16:55:05 +03:00
case PlayerSettings : : bartifact :
2009-08-22 16:59:15 +03:00
title = & CGI - > generaltexth - > allTexts [ 83 ] ; //{Artifact Bonus}
description = & CGI - > generaltexth - > allTexts [ 90 ] ; //An artifact is randomly chosen and equipped to your starting hero
break ;
2010-07-31 16:55:05 +03:00
case PlayerSettings : : bgold :
2009-08-22 16:59:15 +03:00
title = & CGI - > generaltexth - > allTexts [ 84 ] ; //{Gold Bonus}
subTitle = & CGI - > generaltexth - > allTexts [ 87 ] ; //500-1000
description = & CGI - > generaltexth - > allTexts [ 92 ] ; //At the start of the game, 500-1000 gold is added to your Kingdom's resource pool
break ;
2010-07-31 16:55:05 +03:00
case PlayerSettings : : bresource :
2009-08-22 16:59:15 +03:00
{
title = & CGI - > generaltexth - > allTexts [ 85 ] ; //{Resource Bonus}
switch ( CGI - > townh - > towns [ s . castle ] . primaryRes )
{
case 1 :
subTitle = & CGI - > generaltexth - > allTexts [ 694 ] ;
description = & CGI - > generaltexth - > allTexts [ 690 ] ;
break ;
case 3 :
subTitle = & CGI - > generaltexth - > allTexts [ 695 ] ;
description = & CGI - > generaltexth - > allTexts [ 691 ] ;
break ;
case 4 :
subTitle = & CGI - > generaltexth - > allTexts [ 692 ] ;
description = & CGI - > generaltexth - > allTexts [ 688 ] ;
break ;
case 5 :
subTitle = & CGI - > generaltexth - > allTexts [ 693 ] ;
description = & CGI - > generaltexth - > allTexts [ 689 ] ;
break ;
case 127 :
subTitle = & CGI - > generaltexth - > allTexts [ 89 ] ; //5-10 wood / 5-10 ore
description = & CGI - > generaltexth - > allTexts [ 93 ] ; //At the start of the game, 5-10 wood and 5-10 ore are added to your Kingdom's resource pool
break ;
}
}
break ;
}
}
break ;
}
if ( description )
CSDL_Ext : : printAtMiddleWB ( * description , 125 , 145 , FONT_SMALL , 37 , zwykly , bmp ) ;
}
else if ( val = = - 2 )
{
return ;
}
else if ( which = = TOWN )
{
bmp = CMessage : : drawBox1 ( 256 , 319 ) ;
title = & CGI - > generaltexth - > allTexts [ 80 ] ;
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > allTexts [ 79 ] , 135 , 137 , FONT_MEDIUM , tytulowy , bmp ) ;
const CTown & t = CGI - > townh - > towns [ val ] ;
//print creatures
int x = 60 , y = 159 ;
for ( int i = 0 ; i < 7 ; i + + )
{
int c = t . basicCreatures [ i ] ;
blitAt ( graphics - > smallImgs [ c ] , x , y , bmp ) ;
2010-05-02 21:20:26 +03:00
CSDL_Ext : : printAtMiddleWB ( CGI - > creh - > creatures [ c ] - > nameSing , x + 16 , y + 45 , FONT_TINY , 10 , zwykly , bmp ) ;
2009-08-22 16:59:15 +03:00
if ( i = = 2 )
{
x = 40 ;
y + = 76 ;
}
else
{
x + = 52 ;
}
}
}
else if ( val > = 0 )
{
const CHero * h = CGI - > heroh - > heroes [ val ] ;
bmp = CMessage : : drawBox1 ( 320 , 255 ) ;
title = & CGI - > generaltexth - > allTexts [ 77 ] ;
CSDL_Ext : : printAtMiddle ( * title , 167 , 36 , FONT_MEDIUM , tytulowy , bmp ) ;
CSDL_Ext : : printAtMiddle ( * subTitle + " - " + h - > heroClass - > name , 160 , 99 , FONT_SMALL , zwykly , bmp ) ;
blitAt ( getImg ( ) , 136 , 56 , bmp ) ;
//print specialty
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > allTexts [ 78 ] , 166 , 132 , FONT_MEDIUM , tytulowy , bmp ) ;
blitAt ( graphics - > un44 - > ourImages [ val ] . bitmap , 140 , 150 , bmp ) ;
2010-02-11 06:24:37 +02:00
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > hTxts [ val ] . bonusName , 166 , 203 , FONT_SMALL , zwykly , bmp ) ;
2009-08-22 16:59:15 +03:00
GH . pushInt ( new CInfoPopup ( bmp , true ) ) ;
return ;
}
if ( title )
CSDL_Ext : : printAtMiddle ( * title , 135 , 36 , FONT_MEDIUM , tytulowy , bmp ) ;
if ( subTitle )
CSDL_Ext : : printAtMiddle ( * subTitle , 127 , 103 , FONT_SMALL , zwykly , bmp ) ;
blitAt ( getImg ( ) , 104 , 60 , bmp ) ;
GH . pushInt ( new CInfoPopup ( bmp , true ) ) ;
2009-08-27 11:04:32 +03:00
}
2010-03-08 00:56:51 +02:00
CScenarioInfo : : CScenarioInfo ( const CMapHeader * mapHeader , const StartInfo * startInfo )
2009-08-27 11:04:32 +03:00
{
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-08-03 14:36:52 +03:00
for ( std : : map < int , PlayerSettings > : : const_iterator it = startInfo - > playerInfos . begin ( ) ;
it ! = startInfo - > playerInfos . end ( ) ; + + it )
2009-10-06 04:14:00 +03:00
{
2010-08-03 14:36:52 +03:00
if ( it - > second . human )
2009-10-06 04:14:00 +03:00
{
2010-08-03 14:36:52 +03:00
playerColor = it - > first ;
2009-10-06 04:14:00 +03:00
}
}
2009-08-27 11:04:32 +03:00
pos . w = 762 ;
pos . h = 584 ;
center ( pos ) ;
2010-03-08 00:56:51 +02:00
assert ( LOCPLINT ) ;
2010-10-24 14:35:14 +03:00
sInfo = * LOCPLINT - > cb - > getStartInfo ( ) ;
assert ( ! SEL - > current ) ;
current = mapInfoFromGame ( ) ;
2010-03-08 00:56:51 +02:00
setPlayersFromGame ( ) ;
2009-08-27 11:04:32 +03:00
2010-10-24 14:35:14 +03:00
screenType = CMenuScreen : : scenarioInfo ;
card = new InfoCard ( ) ;
opt = new OptionsTab ( ) ;
opt - > recreate ( ) ;
2009-08-27 11:04:32 +03:00
card - > difficulty - > select ( startInfo - > difficulty , 0 ) ;
back = new AdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 105 ] . second , bind ( & CGuiHandler : : popIntTotally , & GH , this ) , 584 , 535 , " SCNRBACK.DEF " , SDLK_ESCAPE ) ;
}
CScenarioInfo : : ~ CScenarioInfo ( )
{
2010-10-24 14:35:14 +03:00
delete current ;
2009-08-27 11:04:32 +03:00
}
2010-02-13 18:26:47 +02:00
bool mapSorter : : operator ( ) ( const CMapInfo * aaa , const CMapInfo * bbb )
2010-02-08 16:38:06 +02:00
{
2010-02-13 18:26:47 +02:00
const CMapHeader * a = aaa - > mapHeader ,
* b = bbb - > mapHeader ;
if ( a & & b ) //if we are sorting scenarios
2010-02-08 16:38:06 +02:00
{
2010-02-13 18:26:47 +02:00
switch ( sortBy )
2010-02-08 16:38:06 +02:00
{
2010-02-13 18:26:47 +02:00
case _format : //by map format (RoE, WoG, etc)
return ( a - > version < b - > version ) ;
break ;
case _loscon : //by loss conditions
return ( a - > lossCondition . typeOfLossCon < b - > lossCondition . typeOfLossCon ) ;
break ;
case _playerAm : //by player amount
int playerAmntB , humenPlayersB , playerAmntA , humenPlayersA ;
playerAmntB = humenPlayersB = playerAmntA = humenPlayersA = 0 ;
for ( int i = 0 ; i < 8 ; i + + )
{
if ( a - > players [ i ] . canHumanPlay ) { playerAmntA + + ; humenPlayersA + + ; }
else if ( a - > players [ i ] . canComputerPlay ) { playerAmntA + + ; }
if ( b - > players [ i ] . canHumanPlay ) { playerAmntB + + ; humenPlayersB + + ; }
else if ( b - > players [ i ] . canComputerPlay ) { playerAmntB + + ; }
}
if ( playerAmntB ! = playerAmntA )
return ( playerAmntA < playerAmntB ) ;
else
return ( humenPlayersA < humenPlayersB ) ;
break ;
case _size : //by size of map
return ( a - > width < b - > width ) ;
break ;
case _viccon : //by victory conditions
return ( a - > victoryCondition . condition < b - > victoryCondition . condition ) ;
break ;
case _name : //by name
return ( a - > name < b - > name ) ;
break ;
default :
return ( a - > name < b - > name ) ;
break ;
2010-02-08 16:38:06 +02:00
}
2010-02-13 18:26:47 +02:00
}
else //if we are sorting campaigns
{
2010-02-15 15:28:33 +02:00
switch ( sortBy )
{
case _numOfMaps : //by number of maps in campaign
return CGI - > generaltexth - > campaignRegionNames [ aaa - > campaignHeader - > mapVersion ] . size ( ) <
CGI - > generaltexth - > campaignRegionNames [ bbb - > campaignHeader - > mapVersion ] . size ( ) ;
break ;
case _name : //by name
return aaa - > campaignHeader - > name < bbb - > campaignHeader - > name ;
break ;
default :
return aaa - > campaignHeader - > name < bbb - > campaignHeader - > name ;
break ;
}
2010-02-08 16:38:06 +02:00
}
2010-02-15 08:54:57 +02:00
}
CMultiMode : : CMultiMode ( )
{
OBJ_CONSTRUCTION ;
bg = new CPicture ( " MUPOPUP.bmp " ) ;
bg - > convertToScreenBPP ( ) ; //so we could draw without problems
blitAt ( CPicture ( " MUMAP.bmp " ) , 16 , 77 , * bg ) ; //blit img
pos = bg - > center ( ) ; //center, window has size of bg graphic
2010-02-15 13:37:47 +02:00
bar = new CGStatusBar ( new CPicture ( Rect ( 7 , 465 , 440 , 18 ) , 0 ) ) ; //226, 472
2010-02-15 08:54:57 +02:00
txt = new CTextInput ( Rect ( 19 , 436 , 334 , 16 ) , * bg ) ;
2010-10-24 14:35:14 +03:00
txt - > setText ( GDefaultOptions . playerName ) ; //Player
2010-02-15 08:54:57 +02:00
btns [ 0 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 266 ] , bind ( & CMultiMode : : openHotseat , this ) , 373 , 78 , " MUBHOT.DEF " ) ;
2010-09-03 21:42:54 +03:00
btns [ 1 ] = new AdventureMapButton ( " Host TCP/IP game " , " " , bind ( & CMultiMode : : hostTCP , this ) , 373 , 78 + 57 * 1 , " MUBHOST.DEF " ) ;
btns [ 2 ] = new AdventureMapButton ( " Join TCP/IP game " , " " , bind ( & CMultiMode : : joinTCP , this ) , 373 , 78 + 57 * 2 , " MUBJOIN.DEF " ) ;
2010-02-26 13:18:09 +02:00
btns [ 6 ] = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 288 ] , bind ( & CGuiHandler : : popIntTotally , ref ( GH ) , this ) , 373 , 424 , " MUBCANC.DEF " , SDLK_ESCAPE ) ;
2010-02-15 08:54:57 +02:00
}
void CMultiMode : : openHotseat ( )
{
GH . pushInt ( new CHotSeatPlayers ( txt - > text ) ) ;
}
2010-09-03 21:42:54 +03:00
void CMultiMode : : hostTCP ( )
{
2010-10-24 14:35:14 +03:00
GDefaultOptions . setPlayerName ( txt - > text ) ;
2010-09-03 21:42:54 +03:00
GH . popIntTotally ( this ) ;
2010-10-24 14:35:14 +03:00
GH . pushInt ( new CSelectionScreen ( CMenuScreen : : newGame , CMenuScreen : : MULTI_NETWORK_HOST ) ) ;
2010-09-03 21:42:54 +03:00
}
void CMultiMode : : joinTCP ( )
{
2010-10-24 14:35:14 +03:00
GDefaultOptions . setPlayerName ( txt - > text ) ;
GH . popIntTotally ( this ) ;
GH . pushInt ( new CSelectionScreen ( CMenuScreen : : newGame , CMenuScreen : : MULTI_NETWORK_GUEST ) ) ;
2010-09-03 21:42:54 +03:00
}
2010-02-15 08:54:57 +02:00
CHotSeatPlayers : : CHotSeatPlayers ( const std : : string & firstPlayer )
{
OBJ_CONSTRUCTION ;
bg = new CPicture ( " MUHOTSEA.bmp " ) ;
bg - > convertToScreenBPP ( ) ; //so we could draw without problems
bg - > printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 446 ] , 185 , 55 , FONT_BIG , 50 , zwykly , * bg ) ; //HOTSEAT Please enter names
pos = bg - > center ( ) ; //center, window has size of bg graphic
for ( int i = 0 ; i < ARRAY_COUNT ( txt ) ; i + + )
txt [ i ] = new CTextInput ( Rect ( 60 , 85 + i * 30 , 280 , 16 ) , * bg ) ;
2010-02-15 13:37:47 +02:00
txt [ 0 ] - > setText ( firstPlayer ) ;
txt [ 0 ] - > giveFocus ( ) ;
2010-02-21 17:03:30 +02:00
ok = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 560 ] , bind ( & CHotSeatPlayers : : enterSelectionScreen , this ) , 95 , 338 , " MUBCHCK.DEF " , SDLK_RETURN ) ;
cancel = new AdventureMapButton ( CGI - > generaltexth - > zelp [ 561 ] , bind ( & CGuiHandler : : popIntTotally , ref ( GH ) , this ) , 205 , 338 , " MUBCANC.DEF " , SDLK_ESCAPE ) ;
2010-02-15 13:37:47 +02:00
bar = new CGStatusBar ( new CPicture ( Rect ( 7 , 381 , 348 , 18 ) , 0 ) ) ; //226, 472
}
void CHotSeatPlayers : : enterSelectionScreen ( )
{
2010-10-24 14:35:14 +03:00
std : : map < ui32 , std : : string > names ;
for ( int i = 0 , j = 1 ; i < ARRAY_COUNT ( txt ) ; i + + )
2010-02-15 13:37:47 +02:00
if ( txt [ i ] - > text . length ( ) )
2010-10-24 14:35:14 +03:00
names [ j + + ] = txt [ i ] - > text ;
assert ( names . size ( ) > 1 ) ; //two players at least - after all, it's hot seat mode...
GDefaultOptions . setPlayerName ( names . begin ( ) - > second ) ; //remember selected name
2010-02-15 13:37:47 +02:00
2010-09-03 21:42:54 +03:00
GH . popInts ( 2 ) ; //pop MP mode window and this
2010-10-24 14:35:14 +03:00
GH . pushInt ( new CSelectionScreen ( CMenuScreen : : newGame , CMenuScreen : : MULTI_HOT_SEAT , & names ) ) ;
2010-02-15 14:12:21 +02:00
}
2010-08-04 14:18:13 +03:00
CBonusSelection : : CBonusSelection ( CCampaignState * _ourCampaign )
2010-10-18 18:08:59 +03:00
: highlightedRegion ( NULL ) , ourCampaign ( _ourCampaign ) , ourHeader ( NULL ) ,
diffLb ( NULL ) , diffRb ( NULL ) , bonuses ( NULL )
2010-02-15 14:12:21 +02:00
{
2010-08-20 16:34:39 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-02-15 14:12:21 +02:00
static const std : : string bgNames [ ] = { " E1_BG.BMP " , " G2_BG.BMP " , " E2_BG.BMP " , " G1_BG.BMP " , " G3_BG.BMP " , " N1_BG.BMP " ,
" S1_BG.BMP " , " BR_BG.BMP " , " IS_BG.BMP " , " KR_BG.BMP " , " NI_BG.BMP " , " TA_BG.BMP " , " AR_BG.BMP " , " HS_BG.BMP " ,
" BB_BG.BMP " , " NB_BG.BMP " , " EL_BG.BMP " , " RN_BG.BMP " , " UA_BG.BMP " , " SP_BG.BMP " } ;
2010-10-24 14:35:14 +03:00
2010-02-16 19:28:56 +02:00
loadPositionsOfGraphics ( ) ;
2010-08-04 14:18:13 +03:00
background = BitmapHandler : : loadBitmap ( bgNames [ ourCampaign - > camp - > header . mapVersion ] ) ;
2010-02-15 14:12:21 +02:00
SDL_Surface * panel = BitmapHandler : : loadBitmap ( " CAMPBRF.BMP " ) ;
blitAt ( panel , 456 , 6 , background ) ;
2010-07-30 17:26:37 +03:00
startB = new AdventureMapButton ( " " , " " , bind ( & CBonusSelection : : startMap , this ) , 475 , 536 , " CBBEGIB.DEF " , SDLK_RETURN ) ;
backB = new AdventureMapButton ( " " , " " , bind ( & CBonusSelection : : goBack , this ) , 624 , 536 , " CBCANCB.DEF " , SDLK_ESCAPE ) ;
2011-04-26 16:30:29 +03:00
startB - > setState ( CButtonBase : : BLOCKED ) ;
2010-02-15 14:12:21 +02:00
//campaign name
2010-08-04 14:18:13 +03:00
if ( ourCampaign - > camp - > header . name . length ( ) )
printAtLoc ( ourCampaign - > camp - > header . name , 481 , 28 , FONT_BIG , tytulowy , background ) ;
2010-02-15 14:12:21 +02:00
else
printAtLoc ( " Unnamed " , 481 , 28 , FONT_BIG , tytulowy , background ) ;
//map size icon
2010-02-18 14:34:44 +02:00
sizes = CDefHandler : : giveDef ( " SCNRMPSZ.DEF " ) ;
2010-02-15 14:12:21 +02:00
//campaign description
printAtLoc ( CGI - > generaltexth - > allTexts [ 38 ] , 481 , 63 , FONT_SMALL , tytulowy , background ) ;
2010-07-06 05:10:26 +03:00
2010-08-04 14:18:13 +03:00
cmpgDesc = new CTextBox ( ourCampaign - > camp - > header . description , Rect ( 480 , 86 , 286 , 117 ) , 1 ) ;
2010-07-29 20:00:34 +03:00
cmpgDesc - > showAll ( background ) ;
//map description
mapDesc = new CTextBox ( " " , Rect ( 480 , 280 , 286 , 117 ) , 1 ) ;
//bonus choosing
2011-04-26 16:30:29 +03:00
printAtLoc ( CGI - > generaltexth - > allTexts [ 71 ] , 511 , 432 , FONT_MEDIUM , zwykly , background ) ; //Choose a bonus:
2010-07-31 16:55:05 +03:00
bonuses = new CHighlightableButtonsGroup ( bind ( & CBonusSelection : : selectBonus , this , _1 ) ) ;
2010-02-15 14:12:21 +02:00
2010-02-18 14:34:44 +02:00
//set left part of window
2010-08-04 14:18:13 +03:00
for ( int g = 0 ; g < ourCampaign - > camp - > scenarios . size ( ) ; + + g )
2010-02-18 14:34:44 +02:00
{
2010-08-04 14:18:13 +03:00
if ( ourCampaign - > camp - > conquerable ( g ) )
2010-02-18 14:34:44 +02:00
{
regions . push_back ( new CRegion ( this , true , true , g ) ) ;
2010-08-04 14:18:13 +03:00
regions [ regions . size ( ) - 1 ] - > rclickText = ourCampaign - > camp - > scenarios [ g ] . regionText ;
2010-02-18 14:34:44 +02:00
if ( highlightedRegion = = NULL )
{
highlightedRegion = regions . back ( ) ;
selectMap ( g ) ;
}
}
2010-08-04 14:18:13 +03:00
else if ( ourCampaign - > camp - > scenarios [ g ] . conquered ) //display as striped
2010-02-18 14:34:44 +02:00
{
regions . push_back ( new CRegion ( this , false , false , g ) ) ;
2010-08-04 14:18:13 +03:00
regions [ regions . size ( ) - 1 ] - > rclickText = ourCampaign - > camp - > scenarios [ g ] . regionText ;
2010-02-18 14:34:44 +02:00
}
}
2010-02-15 14:12:21 +02:00
2010-08-04 14:18:13 +03:00
//init campaign state if necessary
if ( ourCampaign - > campaignName . size ( ) = = 0 )
{
ourCampaign - > initNewCampaign ( sInfo ) ;
}
2010-02-15 14:12:21 +02:00
//allies / enemies
printAtLoc ( CGI - > generaltexth - > allTexts [ 390 ] + " : " , 486 , 407 , FONT_SMALL , zwykly , background ) ; //Allies
printAtLoc ( CGI - > generaltexth - > allTexts [ 391 ] + " : " , 619 , 407 , FONT_SMALL , zwykly , background ) ; //Enemies
SDL_FreeSurface ( panel ) ;
2010-02-16 19:28:56 +02:00
//difficulty
2011-04-26 16:30:29 +03:00
std : : vector < std : : string > difficulty ;
boost : : split ( difficulty , CGI - > generaltexth - > allTexts [ 492 ] , boost : : is_any_of ( " " ) ) ;
printAtLoc ( difficulty . back ( ) , 689 , 432 , FONT_MEDIUM , zwykly , background ) ; //Difficulty
//difficulty pics
for ( int b = 0 ; b < ARRAY_COUNT ( diffPics ) ; + + b )
{
CDefEssential * cde = CDefHandler : : giveDefEss ( " GSPBUT " + boost : : lexical_cast < std : : string > ( b + 3 ) + " .DEF " ) ;
SDL_Surface * surfToDuplicate = cde - > ourImages [ 0 ] . bitmap ;
diffPics [ b ] = SDL_ConvertSurface ( surfToDuplicate , surfToDuplicate - > format ,
surfToDuplicate - > flags ) ;
2010-08-01 17:40:34 +03:00
2011-04-26 16:30:29 +03:00
delete cde ;
2010-08-01 17:40:34 +03:00
}
2011-04-26 16:30:29 +03:00
2010-08-01 17:40:34 +03:00
//difficulty selection buttons
2010-08-04 14:18:13 +03:00
if ( ourCampaign - > camp - > header . difficultyChoosenByPlayer )
2010-08-01 17:40:34 +03:00
{
diffLb = new AdventureMapButton ( " " , " " , bind ( & CBonusSelection : : changeDiff , this , false ) , 694 , 508 , " SCNRBLF.DEF " ) ;
diffRb = new AdventureMapButton ( " " , " " , bind ( & CBonusSelection : : changeDiff , this , true ) , 738 , 508 , " SCNRBRT.DEF " ) ;
}
2010-07-31 16:55:05 +03:00
//load miniflags
sFlags = CDefHandler : : giveDef ( " ITGFLAGS.DEF " ) ;
2010-02-15 14:12:21 +02:00
}
CBonusSelection : : ~ CBonusSelection ( )
{
SDL_FreeSurface ( background ) ;
2010-02-18 14:34:44 +02:00
delete sizes ;
delete ourHeader ;
2010-07-31 16:55:05 +03:00
delete sFlags ;
2010-08-01 17:40:34 +03:00
for ( int b = 0 ; b < ARRAY_COUNT ( diffPics ) ; + + b )
{
SDL_FreeSurface ( diffPics [ b ] ) ;
}
2010-02-15 14:12:21 +02:00
}
void CBonusSelection : : goBack ( )
{
GH . popIntTotally ( this ) ;
}
void CBonusSelection : : showAll ( SDL_Surface * to )
{
blitAt ( background , pos . x , pos . y , to ) ;
2011-02-20 11:24:53 +02:00
CIntObject : : showAll ( to ) ;
2010-07-30 14:29:42 +03:00
show ( to ) ;
2010-02-15 15:28:33 +02:00
}
2010-02-16 19:28:56 +02:00
void CBonusSelection : : loadPositionsOfGraphics ( )
{
2010-08-18 17:24:30 +03:00
std : : ifstream is ( DATA_DIR " /config/campaign_regions.txt " , std : : ios_base : : binary | std : : ios_base : : in ) ;
2010-02-16 19:28:56 +02:00
assert ( is . is_open ( ) ) ;
for ( int g = 0 ; g < CGI - > generaltexth - > campaignMapNames . size ( ) ; + + g )
{
SCampPositions sc ;
is > > sc . campPrefix ;
is > > sc . colorSuffixLength ;
bool contReading = true ;
while ( contReading )
{
SCampPositions : : SRegionDesc rd ;
is > > rd . infix ;
if ( rd . infix = = " END " )
{
contReading = false ;
}
else
{
is > > rd . xpos > > rd . ypos ;
sc . regions . push_back ( rd ) ;
}
}
campDescriptions . push_back ( sc ) ;
}
}
2010-02-18 14:34:44 +02:00
void CBonusSelection : : selectMap ( int whichOne )
{
2010-08-04 14:18:13 +03:00
sInfo . difficulty = ourCampaign - > camp - > scenarios [ whichOne ] . difficulty ;
sInfo . mapname = ourCampaign - > camp - > header . filename ;
2010-08-18 12:50:25 +03:00
sInfo . mode = StartInfo : : CAMPAIGN ;
2010-02-18 14:34:44 +02:00
//get header
int i = 0 ;
delete ourHeader ;
ourHeader = new CMapHeader ( ) ;
2010-08-04 14:18:13 +03:00
ourHeader - > initFromMemory ( ( const unsigned char * ) ourCampaign - > camp - > mapPieces . find ( whichOne ) - > second . c_str ( ) , i ) ;
2010-02-18 14:34:44 +02:00
2010-10-30 17:53:23 +03:00
std : : map < ui32 , std : : string > names ;
names [ 1 ] = GDefaultOptions . playerName ;
updateStartInfo ( ourCampaign - > camp - > header . filename , sInfo , ourHeader , names ) ;
2010-02-18 14:34:44 +02:00
sInfo . turnTime = 0 ;
sInfo . whichMapInCampaign = whichOne ;
2010-08-04 14:18:13 +03:00
sInfo . difficulty = ourCampaign - > camp - > scenarios [ whichOne ] . difficulty ;
ourCampaign - > currentMap = whichOne ;
2010-07-29 20:00:34 +03:00
mapDesc - > setTxt ( ourHeader - > description ) ;
updateBonusSelection ( ) ;
2010-02-18 14:34:44 +02:00
}
void CBonusSelection : : show ( SDL_Surface * to )
{
2011-02-20 11:24:53 +02:00
//blitAt(background, pos.x, pos.y, to);
2010-02-18 14:34:44 +02:00
//map name
2010-07-29 20:00:34 +03:00
std : : string mapName = ourHeader - > name ;
2010-02-18 14:34:44 +02:00
if ( mapName . length ( ) )
printAtLoc ( mapName , 481 , 219 , FONT_BIG , tytulowy , to ) ;
else
printAtLoc ( " Unnamed " , 481 , 219 , FONT_BIG , tytulowy , to ) ;
//map description
printAtLoc ( CGI - > generaltexth - > allTexts [ 496 ] , 481 , 253 , FONT_SMALL , tytulowy , to ) ;
2010-07-29 20:00:34 +03:00
mapDesc - > showAll ( to ) ; //showAll because CTextBox has no show()
2010-02-18 14:34:44 +02:00
//map size icon
int temp ;
switch ( ourHeader - > width )
{
case 36 :
temp = 0 ;
break ;
case 72 :
temp = 1 ;
break ;
case 108 :
temp = 2 ;
break ;
case 144 :
temp = 3 ;
break ;
default :
temp = 4 ;
break ;
}
blitAtLoc ( sizes - > ourImages [ temp ] . bitmap , 735 , 26 , to ) ;
2010-07-31 16:55:05 +03:00
//flags
2011-01-17 18:07:08 +02:00
int fx = 496 + graphics - > fonts [ FONT_SMALL ] - > getWidth ( CGI - > generaltexth - > allTexts [ 390 ] . c_str ( ) ) ;
int ex = 629 + graphics - > fonts [ FONT_SMALL ] - > getWidth ( CGI - > generaltexth - > allTexts [ 391 ] . c_str ( ) ) ;
int myT ;
2010-07-31 16:55:05 +03:00
myT = ourHeader - > players [ playerColor ] . team ;
2010-08-03 14:36:52 +03:00
for ( std : : map < int , PlayerSettings > : : const_iterator i = sInfo . playerInfos . begin ( ) ; i ! = sInfo . playerInfos . end ( ) ; i + + )
2010-07-31 16:55:05 +03:00
{
2010-08-03 14:36:52 +03:00
int * myx = ( ( i - > first = = playerColor | | ourHeader - > players [ i - > first ] . team = = myT ) ? & fx : & ex ) ;
blitAtLoc ( sFlags - > ourImages [ i - > first ] . bitmap , * myx , 405 , to ) ;
* myx + = sFlags - > ourImages [ i - > first ] . bitmap - > w ;
2010-07-31 16:55:05 +03:00
}
2010-08-01 17:40:34 +03:00
//difficulty
blitAt ( diffPics [ sInfo . difficulty ] , 709 , 455 , to ) ;
2010-02-18 14:34:44 +02:00
CIntObject : : show ( to ) ;
}
2010-02-23 17:39:31 +02:00
void CBonusSelection : : updateBonusSelection ( )
{
//graphics:
//spell - SPELLBON.DEF
//monster - TWCRPORT.DEF
2010-07-31 16:55:05 +03:00
//building - BO*.BMP graphics
2010-02-23 17:39:31 +02:00
//artifact - ARTIFBON.DEF
//spell scroll - SPELLBON.DEF
//prim skill - PSKILBON.DEF
//sec skill - SSKILBON.DEF
//resource - BORES.DEF
2011-03-20 00:27:05 +02:00
//player - CREST58.DEF
//hero - PORTRAITSLARGE (HPL###.BMPs)
2010-08-04 14:18:13 +03:00
const CCampaignScenario & scenario = ourCampaign - > camp - > scenarios [ sInfo . whichMapInCampaign ] ;
2010-07-29 20:00:34 +03:00
const std : : vector < CScenarioTravel : : STravelBonus > & bonDescs = scenario . travelOptions . bonusesToChoose ;
2010-02-23 17:39:31 +02:00
2011-03-20 00:27:05 +02:00
for ( size_t i = 0 ; i < bonuses - > buttons . size ( ) ; i + + )
2010-02-23 17:39:31 +02:00
{
2011-03-20 00:27:05 +02:00
if ( bonuses - > buttons [ i ] - > active )
bonuses - > buttons [ i ] - > deactivate ( ) ;
bonuses - > delChild ( bonuses - > buttons [ i ] ) ;
}
bonuses - > buttons . clear ( ) ;
2011-02-20 11:24:53 +02:00
static const char * bonusPics [ ] = { " SPELLBON.DEF " , " TWCRPORT.DEF " , " " , " ARTIFBON.DEF " , " SPELLBON.DEF " ,
2011-03-20 00:27:05 +02:00
" PSKILBON.DEF " , " SSKILBON.DEF " , " BORES.DEF " , " CREST58.DEF " , " PORTRAITSLARGE " } ;
2010-02-23 17:39:31 +02:00
2010-07-29 20:00:34 +03:00
for ( int i = 0 ; i < bonDescs . size ( ) ; i + + )
2010-02-23 17:39:31 +02:00
{
2011-02-20 11:24:53 +02:00
std : : string picName = bonusPics [ bonDescs [ i ] . type ] ;
size_t picNumber = bonDescs [ i ] . info2 ;
2010-07-29 20:00:34 +03:00
std : : string desc ;
switch ( bonDescs [ i ] . type )
{
case 0 : //spell
desc = CGI - > generaltexth - > allTexts [ 715 ] ;
2010-12-19 16:39:56 +02:00
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > spellh - > spells [ bonDescs [ i ] . info2 ] - > name ) ;
2010-07-29 20:00:34 +03:00
break ;
case 1 : //monster
2011-02-20 11:24:53 +02:00
picNumber = bonDescs [ i ] . info2 + 2 ;
2010-07-29 20:00:34 +03:00
desc = CGI - > generaltexth - > allTexts [ 717 ] ;
boost : : algorithm : : replace_first ( desc , " %d " , boost : : lexical_cast < std : : string > ( bonDescs [ i ] . info3 ) ) ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > creh - > creatures [ bonDescs [ i ] . info2 ] - > namePl ) ;
break ;
case 2 : //building
2010-07-30 17:26:37 +03:00
{
2010-08-02 17:29:30 +03:00
int faction = - 1 ;
2010-08-03 14:36:52 +03:00
for ( std : : map < int , PlayerSettings > : : iterator it = sInfo . playerInfos . begin ( ) ;
it ! = sInfo . playerInfos . end ( ) ; + + it )
2010-08-02 17:29:30 +03:00
{
2010-08-03 14:36:52 +03:00
if ( it - > second . human )
2010-08-02 17:29:30 +03:00
{
2010-08-03 14:36:52 +03:00
faction = it - > second . castle ;
2010-08-02 17:29:30 +03:00
break ;
2010-07-31 16:55:05 +03:00
}
2010-08-02 17:29:30 +03:00
}
assert ( faction ! = - 1 ) ;
2010-07-30 17:26:37 +03:00
2011-03-20 00:27:05 +02:00
int buildID = CBuildingHandler : : campToERMU ( bonDescs [ i ] . info1 , faction , std : : set < si32 > ( ) ) ;
picName = graphics - > ERMUtoPicture [ faction ] [ buildID ] ;
2011-02-20 11:24:53 +02:00
picNumber = - 1 ;
2011-03-20 00:27:05 +02:00
tlog1 < < CGI - > buildh - > buildings . size ( ) < < " \t " < < faction < < " \t " < < CGI - > buildh - > buildings [ faction ] . size ( ) < < " \t " < < buildID < < " \n " ;
if ( vstd : : contains ( CGI - > buildh - > buildings [ faction ] , buildID ) )
desc = CGI - > buildh - > buildings [ faction ] . find ( buildID ) - > second - > Description ( ) ;
2010-07-30 17:26:37 +03:00
}
2010-07-29 20:00:34 +03:00
break ;
case 3 : //artifact
desc = CGI - > generaltexth - > allTexts [ 715 ] ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > arth - > artifacts [ bonDescs [ i ] . info2 ] - > Name ( ) ) ;
break ;
case 4 : //spell scroll
desc = CGI - > generaltexth - > allTexts [ 716 ] ;
2010-12-19 16:39:56 +02:00
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > spellh - > spells [ bonDescs [ i ] . info2 ] - > name ) ;
2010-07-29 20:00:34 +03:00
break ;
case 5 : //primary skill
{
int leadingSkill = - 1 ;
2010-07-30 05:08:53 +03:00
std : : vector < std : : pair < int , int > > toPrint ; //primary skills to be listed <num, val>
2010-07-29 20:00:34 +03:00
const ui8 * ptr = reinterpret_cast < const ui8 * > ( & bonDescs [ i ] . info2 ) ;
for ( int g = 0 ; g < PRIMARY_SKILLS ; + + g )
{
if ( leadingSkill = = - 1 | | ptr [ g ] > ptr [ leadingSkill ] )
{
leadingSkill = g ;
}
if ( ptr [ g ] ! = 0 )
{
toPrint . push_back ( std : : make_pair ( g , ptr [ g ] ) ) ;
}
}
2011-02-20 11:24:53 +02:00
picNumber = leadingSkill ;
2010-07-29 20:00:34 +03:00
desc = CGI - > generaltexth - > allTexts [ 715 ] ;
std : : string substitute ; //text to be printed instead of %s
for ( int v = 0 ; v < toPrint . size ( ) ; + + v )
{
substitute + = boost : : lexical_cast < std : : string > ( toPrint [ v ] . second ) ;
substitute + = " " + CGI - > generaltexth - > primarySkillNames [ toPrint [ v ] . first ] ;
if ( v ! = toPrint . size ( ) - 1 )
{
substitute + = " , " ;
}
}
boost : : algorithm : : replace_first ( desc , " %s " , substitute ) ;
break ;
}
case 6 : //secondary skill
desc = CGI - > generaltexth - > allTexts [ 718 ] ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > generaltexth - > levels [ bonDescs [ i ] . info3 ] ) ; //skill level
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > generaltexth - > skillName [ bonDescs [ i ] . info2 ] ) ; //skill name
break ;
case 7 : //resource
2010-07-30 14:29:42 +03:00
{
int serialResID = 0 ;
switch ( bonDescs [ i ] . info1 )
{
case 0 : case 1 : case 2 : case 3 : case 4 : case 5 : case 6 :
serialResID = bonDescs [ i ] . info1 ;
break ;
case 0xFD : //wood + ore
serialResID = 7 ;
break ;
case 0xFE : //rare resources
serialResID = 8 ;
break ;
}
2011-02-20 11:24:53 +02:00
picNumber = serialResID ;
2010-07-30 14:29:42 +03:00
desc = CGI - > generaltexth - > allTexts [ 717 ] ;
boost : : algorithm : : replace_first ( desc , " %d " , boost : : lexical_cast < std : : string > ( bonDescs [ i ] . info2 ) ) ;
std : : string replacement ;
if ( serialResID < = 6 )
{
replacement = CGI - > generaltexth - > restypes [ serialResID ] ;
}
else
{
replacement = CGI - > generaltexth - > allTexts [ 714 + serialResID ] ;
}
boost : : algorithm : : replace_first ( desc , " %s " , replacement ) ;
}
2010-07-29 20:00:34 +03:00
break ;
2010-08-28 17:52:20 +03:00
case 8 : //player aka hero crossover
2011-02-20 11:24:53 +02:00
picNumber = bonDescs [ i ] . info1 ;
2010-08-28 17:52:20 +03:00
desc = CGI - > generaltexth - > allTexts [ 718 ] ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > generaltexth - > capColors [ bonDescs [ i ] . info1 ] ) ; //player color
boost : : algorithm : : replace_first ( desc , " %s " , ourCampaign - > camp - > scenarios [ bonDescs [ i ] . info2 ] . mapName ) ; //scenario
2010-07-29 20:00:34 +03:00
break ;
case 9 : //hero
2010-08-28 17:52:20 +03:00
desc = CGI - > generaltexth - > allTexts [ 718 ] ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > generaltexth - > capColors [ bonDescs [ i ] . info1 ] ) ; //hero's color
if ( bonDescs [ i ] . info2 = = 0xFFFF )
{
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > heroh - > heroes [ 0 ] - > name ) ; //hero's name
2011-03-20 00:27:05 +02:00
picNumber = 0 ;
2010-08-28 17:52:20 +03:00
}
else
{
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > heroh - > heroes [ bonDescs [ i ] . info2 ] - > name ) ; //hero's name
}
2010-07-29 20:00:34 +03:00
break ;
}
2011-04-26 16:30:29 +03:00
CHighlightableButton * bonusButton = new CHighlightableButton ( desc , desc , 0 , 475 + i * 68 , 455 , " " , i ) ;
2010-07-29 20:00:34 +03:00
2011-02-20 11:24:53 +02:00
if ( picNumber ! = - 1 )
picName + = " : " + boost : : lexical_cast < std : : string > ( picNumber ) ;
CAnimation * anim = new CAnimation ( ) ;
anim - > setCustom ( picName , 0 ) ;
2011-04-26 16:30:29 +03:00
bonusButton - > setImage ( anim ) ;
2011-04-30 22:52:35 +03:00
bonusButton - > borderColor = Colors : : Yellow ; // yellow border
2011-04-26 16:30:29 +03:00
bonuses - > addButton ( bonusButton ) ;
2010-02-23 17:39:31 +02:00
}
2011-03-20 00:27:05 +02:00
if ( active )
for ( size_t i = 0 ; i < bonuses - > buttons . size ( ) ; i + + )
bonuses - > buttons [ i ] - > activate ( ) ;
2010-02-23 17:39:31 +02:00
}
2010-05-08 21:56:38 +03:00
void CBonusSelection : : startMap ( )
{
StartInfo * si = new StartInfo ( sInfo ) ;
2010-08-28 17:52:20 +03:00
if ( ourCampaign - > mapsConquered . size ( ) )
{
GH . popInts ( 1 ) ;
}
else
{
2011-04-26 16:30:29 +03:00
// Deletes either the Custom campaign selection screen + Bonus selection screen or
// one of the main campaign selection screens + Bonus selection screen and
// deactivates the main menu
GH . popInts ( 2 ) ;
GH . popInt ( GH . topInt ( ) ) ;
2010-08-28 17:52:20 +03:00
}
2010-05-08 21:56:38 +03:00
: : startGame ( si ) ;
}
2010-07-31 16:55:05 +03:00
void CBonusSelection : : selectBonus ( int id )
{
2011-04-26 16:30:29 +03:00
// Total redraw is needed because the border around the bonus images
// have to be undrawn/drawn.
if ( id ! = sInfo . choosenCampaignBonus )
{
sInfo . choosenCampaignBonus = id ;
GH . totalRedraw ( ) ;
if ( startB - > getState ( ) = = CButtonBase : : BLOCKED )
startB - > setState ( CButtonBase : : NORMAL ) ;
}
2010-09-04 17:49:15 +03:00
const CCampaignScenario & scenario = ourCampaign - > camp - > scenarios [ sInfo . whichMapInCampaign ] ;
const std : : vector < CScenarioTravel : : STravelBonus > & bonDescs = scenario . travelOptions . bonusesToChoose ;
if ( bonDescs [ id ] . type = = 8 ) //hero crossover
{
2010-10-24 14:35:14 +03:00
SEL - > setPlayer ( sInfo . playerInfos [ 0 ] , bonDescs [ id ] . info1 ) ; //TODO: substitute with appropriate color
2010-09-04 17:49:15 +03:00
}
2010-07-31 16:55:05 +03:00
}
2010-08-01 17:40:34 +03:00
void CBonusSelection : : changeDiff ( bool increase )
{
if ( increase )
{
sInfo . difficulty = std : : min ( sInfo . difficulty + 1 , 4 ) ;
}
else
{
sInfo . difficulty = std : : max ( sInfo . difficulty - 1 , 0 ) ;
}
}
2010-02-16 19:28:56 +02:00
CBonusSelection : : CRegion : : CRegion ( CBonusSelection * _owner , bool _accessible , bool _selectable , int _myNumber )
: owner ( _owner ) , accessible ( _accessible ) , selectable ( _selectable ) , myNumber ( _myNumber )
{
OBJ_CONSTRUCTION ;
2010-02-18 14:34:44 +02:00
used = LCLICK | RCLICK ;
2010-02-16 19:28:56 +02:00
static const std : : string colors [ 2 ] [ 8 ] = {
{ " R " , " B " , " N " , " G " , " O " , " V " , " T " , " P " } ,
{ " Re " , " Bl " , " Br " , " Gr " , " Or " , " Vi " , " Te " , " Pi " } } ;
2010-08-04 14:18:13 +03:00
const SCampPositions & campDsc = owner - > campDescriptions [ owner - > ourCampaign - > camp - > header . mapVersion ] ;
2010-02-16 19:28:56 +02:00
const SCampPositions : : SRegionDesc & desc = campDsc . regions [ myNumber ] ;
pos . x = desc . xpos ;
pos . y = desc . ypos ;
//loading of graphics
std : : string prefix = campDsc . campPrefix + desc . infix + " _ " ;
2010-08-04 14:18:13 +03:00
std : : string suffix = colors [ campDsc . colorSuffixLength - 1 ] [ owner - > ourCampaign - > camp - > scenarios [ myNumber ] . regionColor ] ;
2010-02-16 19:28:56 +02:00
static const std : : string infix [ ] = { " En " , " Se " , " Co " } ;
for ( int g = 0 ; g < ARRAY_COUNT ( infix ) ; g + + )
{
graphics [ g ] = BitmapHandler : : loadBitmap ( prefix + infix [ g ] + suffix + " .BMP " ) ;
}
2010-02-18 14:34:44 +02:00
pos . w = graphics [ 0 ] - > w ;
pos . h = graphics [ 0 ] - > h ;
2010-02-16 19:28:56 +02:00
}
CBonusSelection : : CRegion : : ~ CRegion ( )
{
for ( int g = 0 ; g < ARRAY_COUNT ( graphics ) ; + + g )
{
SDL_FreeSurface ( graphics [ g ] ) ;
}
}
void CBonusSelection : : CRegion : : clickLeft ( tribool down , bool previousState )
{
//select if selectable & clicked inside our graphic
2010-02-21 17:03:30 +02:00
if ( indeterminate ( down ) )
{
return ;
}
2010-02-18 14:34:44 +02:00
if ( ! down & & selectable & & ! CSDL_Ext : : isTransparent ( graphics [ 0 ] , GH . current - > motion . x - pos . x , GH . current - > motion . y - pos . y ) )
2010-02-16 19:28:56 +02:00
{
2010-02-18 14:34:44 +02:00
owner - > selectMap ( myNumber ) ;
owner - > highlightedRegion = this ;
2011-03-20 00:27:05 +02:00
parent - > showAll ( screen ) ;
2010-02-16 19:28:56 +02:00
}
}
void CBonusSelection : : CRegion : : clickRight ( tribool down , bool previousState )
{
//show r-click text
2010-02-18 14:34:44 +02:00
if ( down & & ! CSDL_Ext : : isTransparent ( graphics [ 0 ] , GH . current - > motion . x - pos . x , GH . current - > motion . y - pos . y ) & &
rclickText . size ( ) )
{
2010-03-21 00:17:19 +02:00
CRClickPopup : : createAndPush ( rclickText ) ;
2010-02-18 14:34:44 +02:00
}
2010-02-16 19:28:56 +02:00
}
void CBonusSelection : : CRegion : : show ( SDL_Surface * to )
{
2010-11-15 17:15:00 +02:00
//const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->camp->header.mapVersion].regions[myNumber];
2010-02-16 19:28:56 +02:00
if ( ! accessible )
{
//show as striped
blitAt ( graphics [ 2 ] , pos . x , pos . y , to ) ;
}
else if ( this = = owner - > highlightedRegion )
{
//show as selected
blitAt ( graphics [ 1 ] , pos . x , pos . y , to ) ;
}
else
{
//show as not selected selected
blitAt ( graphics [ 0 ] , pos . x , pos . y , to ) ;
}
}
2010-03-08 00:56:51 +02:00
2010-05-27 00:59:58 +03:00
CSavingScreen : : CSavingScreen ( bool hotseat )
2010-10-24 14:35:14 +03:00
: CSelectionScreen ( CMenuScreen : : saveGame , hotseat ? CMenuScreen : : MULTI_HOT_SEAT : CMenuScreen : : SINGLE_PLAYER )
2010-03-08 00:56:51 +02:00
{
ourGame = mapInfoFromGame ( ) ;
sInfo = * LOCPLINT - > cb - > getStartInfo ( ) ;
setPlayersFromGame ( ) ;
}
CSavingScreen : : ~ CSavingScreen ( )
{
}
2010-07-20 13:46:38 +03:00
2010-10-24 14:35:14 +03:00
ISelectionScreenInfo : : ISelectionScreenInfo ( const std : : map < ui32 , std : : string > * Names /*= NULL*/ )
{
multiPlayer = CMenuScreen : : SINGLE_PLAYER ;
assert ( ! SEL ) ;
SEL = this ;
current = NULL ;
if ( Names & & Names - > size ( ) ) //if have custom set of player names - use it
playerNames = * Names ;
else
playerNames [ 1 ] = GDefaultOptions . playerName ; //by default we have only one player and his name is "Player" (or whatever the last used name was)
}
ISelectionScreenInfo : : ~ ISelectionScreenInfo ( )
{
assert ( SEL = = this ) ;
SEL = NULL ;
}
void ISelectionScreenInfo : : updateStartInfo ( std : : string filename , StartInfo & sInfo , const CMapHeader * mapHeader )
{
2010-10-30 17:53:23 +03:00
: : updateStartInfo ( filename , sInfo , mapHeader , playerNames ) ;
2010-10-24 14:35:14 +03:00
}
void ISelectionScreenInfo : : setPlayer ( PlayerSettings & pset , unsigned player )
{
2010-10-30 17:53:23 +03:00
: : setPlayer ( pset , player , playerNames ) ;
2010-10-24 14:35:14 +03:00
}
int ISelectionScreenInfo : : getIdOfFirstUnallocatedPlayer ( )
{
for ( std : : map < ui32 , std : : string > : : const_iterator i = playerNames . begin ( ) ; i ! = playerNames . end ( ) ; i + + )
if ( ! sInfo . getPlayersSettings ( i - > first ) ) //
return i - > first ;
return 0 ;
}
bool ISelectionScreenInfo : : isGuest ( ) const
{
return multiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST ;
}
bool ISelectionScreenInfo : : isHost ( ) const
{
return multiPlayer = = CMenuScreen : : MULTI_NETWORK_HOST ;
}
2010-09-03 21:42:54 +03:00
void ChatMessage : : apply ( CSelectionScreen * selScreen )
{
2010-10-24 14:35:14 +03:00
selScreen - > card - > chat - > addNewMessage ( playerName + " : " + message ) ;
GH . totalRedraw ( ) ;
}
void QuitMenuWithoutStarting : : apply ( CSelectionScreen * selScreen )
{
if ( ! selScreen - > ongoingClosing )
{
* selScreen - > serv < < this ; //resend to confirm
GH . popIntTotally ( selScreen ) ; //will wait with deleting us before this thread ends
}
2010-09-03 21:42:54 +03:00
2010-10-24 14:35:14 +03:00
delNull ( selScreen - > serv ) ;
2010-09-03 21:42:54 +03:00
}
2010-10-24 14:35:14 +03:00
void PlayerJoined : : apply ( CSelectionScreen * selScreen )
{
//assert(SEL->playerNames.size() == connectionID); //temporary, TODO when player exits
SEL - > playerNames [ connectionID ] = playerName ;
//put new player in first slot with AI
for ( std : : map < int , PlayerSettings > : : iterator i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
{
if ( ! i - > second . human )
{
selScreen - > setPlayer ( i - > second , connectionID ) ;
selScreen - > opt - > entries [ i - > second . color ] - > selectButtons ( ) ;
break ;
}
}
selScreen - > propagateNames ( ) ;
selScreen - > propagateOptions ( ) ;
GH . totalRedraw ( ) ;
}
void SelectMap : : apply ( CSelectionScreen * selScreen )
{
if ( selScreen - > multiPlayer = = CMenuScreen : : MULTI_NETWORK_GUEST )
{
free = false ;
selScreen - > changeSelection ( mapInfo ) ;
}
}
void UpdateStartOptions : : apply ( CSelectionScreen * selScreen )
{
if ( ! selScreen - > isGuest ( ) )
return ;
selScreen - > setSInfo ( * options ) ;
}
void PregameGuiAction : : apply ( CSelectionScreen * selScreen )
{
if ( ! selScreen - > isGuest ( ) )
return ;
switch ( action )
{
case NO_TAB :
selScreen - > toggleTab ( selScreen - > curTab ) ;
break ;
case OPEN_OPTIONS :
selScreen - > toggleTab ( selScreen - > opt ) ;
break ;
case OPEN_SCENARIO_LIST :
selScreen - > toggleTab ( selScreen - > sel ) ;
break ;
}
}
void RequestOptionsChange : : apply ( CSelectionScreen * selScreen )
{
if ( ! selScreen - > isHost ( ) )
return ;
ui8 color = selScreen - > sInfo . getPlayersSettings ( playerID ) - > color ;
switch ( what )
{
case TOWN :
selScreen - > opt - > nextCastle ( color , direction ) ;
break ;
case HERO :
selScreen - > opt - > nextHero ( color , direction ) ;
break ;
case BONUS :
selScreen - > opt - > nextBonus ( color , direction ) ;
break ;
}
}
void PlayerLeft : : apply ( CSelectionScreen * selScreen )
{
if ( selScreen - > isGuest ( ) )
return ;
SEL - > playerNames . erase ( playerID ) ;
if ( PlayerSettings * s = selScreen - > sInfo . getPlayersSettings ( playerID ) ) //it's possible that player was unallocated
{
selScreen - > setPlayer ( * s , 0 ) ;
selScreen - > opt - > entries [ s - > color ] - > selectButtons ( ) ;
}
selScreen - > propagateNames ( ) ;
selScreen - > propagateOptions ( ) ;
GH . totalRedraw ( ) ;
}
void PlayersNames : : apply ( CSelectionScreen * selScreen )
{
if ( selScreen - > isGuest ( ) )
selScreen - > playerNames = playerNames ;
}
void StartWithCurrentSettings : : apply ( CSelectionScreen * selScreen )
{
startingInfo . reset ( ) ;
startingInfo . serv = selScreen - > serv ;
startingInfo . sInfo = new StartInfo ( selScreen - > sInfo ) ;
if ( ! selScreen - > ongoingClosing )
{
* selScreen - > serv < < this ; //resend to confirm
}
selScreen - > serv = NULL ; //hide it so it won't be deleted
delNull ( selScreen - > serverHandlingThread ) ; //detach us
selectedName = selScreen - > sInfo . mapname ;
GH . curInt = NULL ;
GH . popIntTotally ( selScreen ) ;
GH . popInt ( GH . topInt ( ) ) ; //only deactivate main menu screen
: : startGame ( startingInfo . sInfo , startingInfo . serv ) ;
throw 666 ; //EVIL, EVIL, EVIL workaround to kill thread (does "goto catch" outside listening loop)
2010-10-31 00:53:41 +03:00
}
2011-03-15 16:35:36 +02:00
CCampaignScreen : : CCampaignScreen ( CampaignSet campaigns , std : : map < std : : string , CampaignStatus > & camps )
{
OBJ_CONSTRUCTION ; // sets this as parent
std : : string bgImage ;
2011-03-19 16:27:51 +02:00
if ( campaigns = = ROE | | campaigns = = AB )
2011-03-15 16:35:36 +02:00
bgImage = " CAMPBACK.BMP " ;
else if ( campaigns = = SOD )
bgImage = " CAMPBKX2.BMP " ;
else if ( campaigns = = WOG )
bgImage = " CAMPZALL.BMP " ;
// Load background image
bg = BitmapHandler : : loadBitmap ( bgImage ) ;
pos . x = 0 ;
pos . y = 0 ;
pos . w = bg - > w ;
pos . h = bg - > h ;
// Create back button
back = new AdventureMapButton ( " " , " " , bind ( & CGuiHandler : : popIntTotally , & GH , this ) , 658 , 482 , " CMPSCAN.DEF " , SDLK_ESCAPE ) ;
back - > hoverable = true ;
// Load all campaign buttons
2011-03-21 21:32:48 +02:00
// 1.index: 0 => ROE, 1 => AB, 2 => WOG
2011-03-15 16:35:36 +02:00
static const int buttonCords [ 7 ] [ 2 ] = { { 90 , 72 } , { 539 , 72 } , { 43 , 245 } , { 313 , 244 } , { 586 , 246 } , { 34 , 417 } , { 404 , 414 } } ;
2011-03-21 21:32:48 +02:00
static const std : : string campFiles [ 3 ] [ 7 ] = { { " GOOD1 " , " EVIL1 " , " GOOD2 " , " NEUTRAL1 " , " EVIL2 " , " GOOD3 " , " SECRET " } ,
{ " AB " , " BLOOD " , " SLAYER " , " FESTIVAL " , " FIRE " , " FOOL " } ,
{ " ZC1 " , " ZC2 " , " ZC3 " , " ZC4 " } } ;
static const std : : string campImages [ 3 ] [ 7 ] = { { " CAMPGD1S.BMP " , " CAMPEV1S.BMP " , " CAMPGD2S.BMP " , " CAMPNEUS.BMP " , " CAMPEV2S.BMP " , " CAMPGD3S.BMP " , " CAMPSCTS.BMP " } ,
{ " CAMP1AB7.BMP " , " CAMP1DB2.BMP " , " CAMP1DS1.BMP " , " CAMP1FL3.BMP " , " CAMP1PF2.BMP " , " CAMP1FW1.BMP " } ,
{ " CAMPZ01.BMP " , " CAMPZ02.BMP " , " CAMPZ03.BMP " , " CAMPZ04.BMP " } } ;
2011-07-23 02:34:15 +03:00
# ifdef _WIN32
2011-03-21 21:32:48 +02:00
static const std : : string campVideos [ 3 ] [ 7 ] = { { " CGOOD1.BIK " , " CEVIL1.BIK " , " CGOOD2.BIK " , " CNEUTRAL.BIK " , " CEVIL2.BIK " , " CGOOD3.BIK " , " CSECRET.BIK " } ,
{ " C1ab7.BIK " , " C1db2.BIK " , " C1ds1.BIK " , " C1fl3.BIK " , " C1pf2.BIK " , " C1fw1.BIK " } } ;
2011-07-23 02:34:15 +03:00
# else
static const std : : string campVideos [ 3 ] [ 7 ] = { { " cgood1.mjpg " , " cevil1.mjpg " , " cgood2.mjpg " , " cneutral.mjpg " , " cevil2.mjpg " , " cgood3.mjpg " , " csecret.mjpg " } } ;
# endif
2011-03-21 21:32:48 +02:00
static const std : : string campTexts [ 3 ] [ 7 ] = { { getMapText ( 0 ) , getMapText ( 3 ) , getMapText ( 1 ) , getMapText ( 5 ) , getMapText ( 4 ) , getMapText ( 2 ) , getMapText ( 6 ) } ,
{ " Armageddon's Blade " , " Dragon's Blood " , " Dragon Slayer " , " Festival of Life " , " Playing With Fire " , " Foolhardy Waywardness " } ,
{ " In the Wake of Gods " , " The Samaritan " , " A Life of A-d-v-e-n-t-u-r-e " , " Evil Way Home " } } ;
static const CampaignStatus campDefaults [ 3 ] [ 7 ] = { { CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : DISABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : DISABLED ,
CCampaignScreen : : DISABLED , CCampaignScreen : : DISABLED } ,
{ CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : DISABLED } ,
{ CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED , CCampaignScreen : : ENABLED } } ;
2011-03-15 16:35:36 +02:00
if ( campaigns = = ROE )
{
2011-03-21 21:32:48 +02:00
createButtons ( buttonCords , campFiles [ 0 ] , campImages [ 0 ] , campVideos [ 0 ] , campTexts [ 0 ] , camps , campDefaults [ 0 ] ) ;
if ( camps [ campFiles [ 0 ] [ 6 ] ] = = 0 )
2011-03-15 16:35:36 +02:00
drawCampaignPlaceholder ( ) ;
}
2011-03-19 16:27:51 +02:00
if ( campaigns = = AB )
{
2011-03-21 21:32:48 +02:00
// Foolhardy Waywardness -- draw deactivated image
2011-03-19 16:27:51 +02:00
SDL_Surface * ab5Dis = BitmapHandler : : loadBitmap ( " CAMP1FWX " ) ;
Rect ab5DisRect ( buttonCords [ 5 ] [ 0 ] - 2 , buttonCords [ 5 ] [ 1 ] - 2 , ab5Dis - > w , ab5Dis - > h ) ;
blitAt ( ab5Dis , ab5DisRect , bg ) ;
2011-03-21 21:32:48 +02:00
createButtons ( buttonCords , campFiles [ 1 ] , campImages [ 1 ] , campVideos [ 1 ] , campTexts [ 1 ] , camps , campDefaults [ 1 ] ) ;
2011-03-19 16:27:51 +02:00
drawCampaignPlaceholder ( ) ;
}
2011-03-15 16:35:36 +02:00
if ( campaigns = = WOG )
{
2011-03-21 21:32:48 +02:00
createButtons ( buttonCords , campFiles [ 2 ] , campImages [ 2 ] , campVideos [ 2 ] , campTexts [ 2 ] , camps , campDefaults [ 2 ] ) ;
campButtons [ 3 ] - > pos . x - = 2 ; // special rule for the 4.th campaign
campButtons [ 3 ] - > pos . y - = 2 ;
2011-03-15 16:35:36 +02:00
drawCampaignPlaceholder ( ) ;
}
}
CCampaignScreen : : ~ CCampaignScreen ( )
{
// Free background image and re-start WOG main menu animation
SDL_FreeSurface ( bg ) ;
if ( noCamp ! = 0 )
SDL_FreeSurface ( noCamp ) ;
2011-04-26 16:30:29 +03:00
//campButtons.clear();
2011-03-15 16:35:36 +02:00
CCS - > videoh - > open ( " ACREDIT.SMK " ) ;
}
2011-03-21 21:32:48 +02:00
void CCampaignScreen : : createButtons ( const int buttonCords [ 7 ] [ 2 ] , const std : : string campFiles [ ] ,
const std : : string campImages [ ] , const std : : string campVideos [ ] , const std : : string campTexts [ ] , std : : map < std : : string , CampaignStatus > & camps , const CampaignStatus campDefaults [ ] )
{
for ( int i = 0 ; i < 7 ; i + + )
{
if ( campFiles [ i ] ! = " " ) // if it's setted in the array
{
std : : string file = campFiles [ i ] ;
CCampaignButton * button = new CCampaignButton ( bg , campImages [ i ] , buttonCords [ i ] [ 0 ] , buttonCords [ i ] [ 1 ] , camps [ file ] ! = 0 ? camps [ file ] : campDefaults [ i ] ) ;
button - > campFile = file ;
button - > hoverText = campTexts [ i ] ;
button - > video = campVideos [ i ] ;
campButtons . push_back ( button ) ;
}
}
}
std : : string CCampaignScreen : : getMapText ( int index )
{
return CGI - > generaltexth - > campaignMapNames [ index ] ;
}
2011-03-15 16:35:36 +02:00
void CCampaignScreen : : drawCampaignPlaceholder ( )
{
noCamp = BitmapHandler : : loadBitmap ( " CAMPNOSC.BMP " ) ;
noCamp - > w - = 2 ;
Rect noCampRect ( 385 , 401 , 238 , 143 ) ;
blitAt ( noCamp , noCampRect , bg ) ;
}
2011-04-26 16:30:29 +03:00
void CCampaignScreen : : show ( SDL_Surface * to )
2011-03-15 16:35:36 +02:00
{
// Draw background image and all interactive objects like buttons
blitAt ( bg , pos . x , pos . y , to ) ;
2011-04-26 16:30:29 +03:00
for ( int i = 0 ; i < this - > campButtons . size ( ) ; i + + )
{
campButtons [ i ] - > show ( to ) ;
}
back - > showAll ( to ) ;
2011-03-15 16:35:36 +02:00
}
CCampaignScreen : : CCampaignButton : : CCampaignButton ( SDL_Surface * bg , const std : : string image , const int x , const int y , CampaignStatus status )
{
OBJ_CONSTRUCTION ; // sets this as parent
// Initialize CCampaignButton members
this - > bg = bg ;
this - > image = image ;
this - > status = status ;
2011-03-19 16:27:51 +02:00
// Initialize pos and size
2011-03-15 16:35:36 +02:00
pos . x = x ;
pos . y = y ;
pos . w = 200 ;
pos . h = 116 ;
2011-03-19 16:27:51 +02:00
// Creates the button image
2011-03-15 16:35:36 +02:00
button = BitmapHandler : : loadBitmap ( image ) ;
2011-03-19 16:27:51 +02:00
if ( status ! = CCampaignScreen : : DISABLED & & button ! = 0 )
{
2011-03-15 16:35:36 +02:00
blitAt ( button , pos , bg ) ;
2011-03-19 16:27:51 +02:00
used = LCLICK | HOVER ; // set these flags to activate left click and hover event functions
}
2011-03-15 16:35:36 +02:00
2011-03-19 16:27:51 +02:00
// Create the checked image
2011-03-17 05:56:36 +02:00
if ( status = = CCampaignScreen : : COMPLETED )
2011-03-15 16:35:36 +02:00
checked = BitmapHandler : : loadBitmap ( " CAMPCHK.BMP " ) ;
2011-03-19 16:27:51 +02:00
// Create the button hover effect
2011-03-15 16:35:36 +02:00
hoverLabel = new CLabel ( pos . w / 2. , pos . h + 20 , FONT_MEDIUM , CENTER , tytulowy , " " ) ;
hoverLabel - > ignoreLeadingWhitespace = false ;
}
CCampaignScreen : : CCampaignButton : : ~ CCampaignButton ( )
{
2011-03-19 16:27:51 +02:00
if ( button ! = 0 )
SDL_FreeSurface ( button ) ;
2011-03-15 16:35:36 +02:00
2011-03-17 05:56:36 +02:00
if ( status = = CCampaignScreen : : COMPLETED )
2011-03-15 16:35:36 +02:00
SDL_FreeSurface ( checked ) ;
}
void CCampaignScreen : : CCampaignButton : : hover ( bool on )
{
if ( on )
hoverLabel - > setTxt ( hoverText ) ; // Shows the name of the campaign when you get into the bounds of the button
else
{
// Deletes the text from the screen when you hover out of the bounds of the button
hoverLabel - > setTxt ( " " ) ;
}
}
2011-04-26 16:30:29 +03:00
void CCampaignScreen : : CCampaignButton : : show ( SDL_Surface * to )
2011-03-15 16:35:36 +02:00
{
2011-04-26 16:30:29 +03:00
hoverLabel - > showAll ( to ) ;
2011-03-15 16:35:36 +02:00
2011-03-19 16:27:51 +02:00
if ( status = = CCampaignScreen : : DISABLED | | video = = " " | | button = = 0 )
2011-03-15 16:35:36 +02:00
return ;
// Play the campaign button video when the mouse cursor is placed over the button
if ( CCS - > curh - > xpos > = pos . x & & CCS - > curh - > ypos > = pos . y & & CCS - > curh - > xpos < pos . x + pos . w & & CCS - > curh - > ypos < pos . y + pos . h )
{
if ( CCS - > videoh - > fname ! = video )
CCS - > videoh - > open ( video ) ;
CCS - > videoh - > update ( pos . x , pos . y , to , true , false ) ; // plays sequentially frame by frame, starts at the beginning when the video is over
}
else if ( CCS - > videoh - > fname = = video ) // When you got out of the bounds of the button then close the video
{
CCS - > videoh - > close ( ) ;
blitAt ( button , pos , to ) ;
}
2011-04-17 21:02:13 +03:00
2011-03-15 16:35:36 +02:00
2011-03-17 05:56:36 +02:00
if ( status = = CCampaignScreen : : COMPLETED ) // Draw a checked symbol when you completed the mission
2011-03-15 16:35:36 +02:00
{
Rect chkRect ( pos . x + 5 , pos . y + 74 , 42 , 40 ) ;
blitAt ( checked , chkRect , to ) ; // this is needed because the video gets drawn on top of the screen
blitAt ( checked , chkRect , bg ) ; // this is needed because of the totalRedraw at the hover method
}
}
void CCampaignScreen : : CCampaignButton : : clickLeft ( tribool down , bool previousState )
{
if ( down )
{
// Close running video and open the selected campaign
CCS - > videoh - > close ( ) ;
CCampaign * ourCampaign = CCampaignHandler : : getCampaign ( campFile , true ) ;
CCampaignState * campState = new CCampaignState ( ) ;
campState - > camp = ourCampaign ;
GH . pushInt ( new CBonusSelection ( campState ) ) ;
}
2011-04-17 21:02:13 +03:00
}