2011-12-14 00:23:17 +03:00
# include "StdInc.h"
2008-08-02 18:08:03 +03:00
# include "CPreGame.h"
2011-12-14 00:23:17 +03:00
2013-04-07 13:48:07 +03:00
# include "../lib/filesystem/CResourceLoader.h"
# include "../lib/filesystem/CFileInfo.h"
# include "../lib/filesystem/CCompressedStream.h"
2012-08-01 15:02:54 +03:00
2011-12-17 21:59:59 +03:00
# include "../lib/CStopWatch.h"
2013-04-07 14:52:07 +03:00
# include "gui/SDL_Extensions.h"
2008-08-02 18:08:03 +03:00
# include "CGameInfo.h"
2013-04-07 14:52:07 +03:00
# include "gui/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/CTownHandler.h"
# include "../lib/CHeroHandler.h"
# include "../lib/CObjectHandler.h"
2013-04-07 13:48:07 +03:00
# include "../lib/mapping/CCampaignHandler.h"
2010-12-20 23:22:53 +02:00
# include "../lib/CCreatureHandler.h"
2011-09-03 22:51:45 +03:00
# include "../lib/JsonNode.h"
2010-12-20 23:22:53 +02:00
# include "CMusicHandler.h"
# include "CVideoHandler.h"
2009-05-20 13:08:56 +03:00
# include "Graphics.h"
# include "../lib/Connection.h"
2009-10-10 08:47:59 +03:00
# include "../lib/VCMIDirs.h"
2013-04-07 13:48:07 +03:00
# include "../lib/mapping/CMap.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"
2010-02-08 16:38:06 +02:00
# 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"
2011-12-14 00:23:17 +03:00
# include "../lib/RegisterTypes.h"
# include "../lib/CThreadHelper.h"
2012-09-29 13:59:43 +03:00
# include "../lib/CConfigHandler.h"
2011-12-14 00:23:17 +03:00
# include "../lib/GameConstants.h"
2013-04-07 14:52:07 +03:00
# include "gui/CGuiHandler.h"
# include "gui/CIntObjectClasses.h"
2013-04-07 13:48:07 +03:00
# include "../lib/mapping/CMapService.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
2011-11-27 18:39:44 +03:00
//#define bind boost::bind
//#define ref boost::ref
2010-02-20 15:24:38 +02:00
# endif
2010-10-24 14:35:14 +03:00
void startGame ( StartInfo * options , CConnection * serv = NULL ) ;
2009-04-15 17:03:31 +03:00
2012-05-18 20:35:46 +03:00
CGPreGame * CGP = nullptr ;
2010-10-24 14:35:14 +03:00
ISelectionScreenInfo * SEL ;
2013-03-03 20:06:03 +03:00
static PlayerColor playerColor ; //if more than one player - applies to the first
2008-12-21 21:17:35 +02:00
2012-11-20 20:53:45 +03:00
/**
* Stores the current name of the savegame .
*
* TODO better solution for auto - selection when saving already saved games .
* - > CSelectionScreen should be divided into CLoadGameScreen , CSaveGameScreen , . . .
* The name of the savegame can then be stored non - statically in CGameState and
* passed separately to CSaveGameScreen .
*/
static std : : string saveGameName ;
2010-10-24 14:35:14 +03:00
struct EvilHlpStruct
{
CConnection * serv ;
StartInfo * sInfo ;
2011-11-27 16:14:20 +03:00
void reset ( bool strong = true )
2010-10-24 14:35:14 +03:00
{
if ( strong )
{
2011-12-14 00:23:17 +03:00
vstd : : clear_pointer ( serv ) ;
vstd : : clear_pointer ( sInfo ) ;
2010-10-24 14:35:14 +03:00
}
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 ( )
{
2012-11-11 15:23:31 +03:00
CMapInfo * ret = new CMapInfo ( ) ;
ret - > mapHeader = std : : unique_ptr < CMapHeader > ( new CMapHeader ( * LOCPLINT - > cb - > getMapHeader ( ) ) ) ;
2010-03-08 00:56:51 +02:00
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
{
2012-12-02 15:21:44 +03:00
std : : swap ( a . playerID , b . playerID ) ;
2010-10-24 14:35:14 +03:00
std : : swap ( a . name , b . name ) ;
2012-12-02 15:21:44 +03:00
if ( a . playerID = = 1 )
2010-10-24 14:35:14 +03:00
playerColor = a . color ;
2012-12-02 15:21:44 +03:00
else if ( b . playerID = = 1 )
2010-10-24 14:35:14 +03:00
playerColor = b . color ;
2010-03-08 00:56:51 +02:00
}
2013-03-03 20:06:03 +03:00
void setPlayer ( PlayerSettings & pset , ui8 player , const std : : map < ui8 , std : : string > & playerNames )
2010-10-30 17:53:23 +03:00
{
if ( vstd : : contains ( playerNames , player ) )
pset . name = playerNames . find ( player ) - > second ;
else
pset . name = CGI - > generaltexth - > allTexts [ 468 ] ; //Computer
2012-12-02 15:21:44 +03:00
pset . playerID = player ;
2010-10-30 17:53:23 +03:00
if ( player = = playerNames . begin ( ) - > first )
playerColor = pset . color ;
}
2013-03-03 20:06:03 +03:00
void updateStartInfo ( std : : string filename , StartInfo & sInfo , const CMapHeader * mapHeader , const std : : map < ui8 , std : : string > & playerNames )
2010-10-30 17:53:23 +03:00
{
sInfo . playerInfos . clear ( ) ;
2012-11-20 20:53:45 +03:00
if ( ! mapHeader )
{
2010-10-30 17:53:23 +03:00
return ;
2012-11-20 20:53:45 +03:00
}
2010-10-30 17:53:23 +03:00
sInfo . mapname = filename ;
2013-03-03 20:06:03 +03:00
playerColor = PlayerColor : : NEUTRAL ;
2010-10-30 17:53:23 +03:00
2012-09-24 19:14:53 +03:00
auto namesIt = playerNames . cbegin ( ) ;
2010-10-30 17:53:23 +03:00
2012-11-20 20:53:45 +03:00
for ( int i = 0 ; i < mapHeader - > players . size ( ) ; i + + )
2010-10-30 17:53:23 +03:00
{
const PlayerInfo & pinfo = mapHeader - > players [ i ] ;
//neither computer nor human can play - no player
2012-09-26 16:13:39 +03:00
if ( ! ( pinfo . canHumanPlay | | pinfo . canComputerPlay ) )
2010-10-30 17:53:23 +03:00
continue ;
2013-03-03 20:06:03 +03:00
PlayerSettings & pset = sInfo . playerInfos [ PlayerColor ( i ) ] ;
pset . color = PlayerColor ( i ) ;
2012-09-24 19:14:53 +03:00
if ( pinfo . canHumanPlay & & namesIt ! = playerNames . cend ( ) )
2013-01-06 22:30:12 +03:00
{
2010-10-30 17:53:23 +03:00
setPlayer ( pset , namesIt + + - > first , playerNames ) ;
2013-01-06 22:30:12 +03:00
}
2010-10-30 17:53:23 +03:00
else
2013-01-06 22:30:12 +03:00
{
2010-10-30 17:53:23 +03:00
setPlayer ( pset , 0 , playerNames ) ;
2013-01-06 22:30:12 +03:00
if ( ! pinfo . canHumanPlay )
{
pset . compOnly = true ;
}
}
2010-10-30 17:53:23 +03:00
pset . castle = pinfo . defaultCastle ( ) ;
2011-03-19 16:35:29 +02:00
pset . hero = pinfo . defaultHero ( ) ;
2010-10-30 17:53:23 +03:00
2012-12-10 17:28:27 +03:00
if ( pinfo . customHeroID > = 0 )
2010-10-30 17:53:23 +03:00
{
2012-12-10 17:28:27 +03:00
pset . hero = pinfo . customHeroID ;
if ( ! pinfo . mainHeroName . empty ( ) )
pset . heroName = pinfo . mainHeroName ;
else
pset . heroName = CGI - > heroh - > heroes [ pinfo . customHeroID ] - > name ;
if ( pinfo . mainHeroPortrait > = 0 )
pset . heroPortrait = pinfo . mainHeroPortrait ;
else
pset . heroPortrait = pinfo . customHeroID ;
2010-10-30 17:53:23 +03:00
}
2013-02-02 01:04:25 +03:00
pset . handicap = PlayerSettings : : NO_HANDICAP ;
2010-10-30 17:53:23 +03:00
}
}
2010-09-04 17:47:39 +03:00
template < typename T > class CApplyOnPG ;
2010-09-03 21:42:54 +03:00
class CBaseForPGApply
{
public :
2011-11-27 16:14:20 +03:00
virtual void applyOnPG ( CSelectionScreen * selScr , void * pack ) const = 0 ;
2010-09-03 21:42:54 +03:00
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
2011-11-27 16:14:20 +03:00
static CPicture * createPicture ( const JsonNode & config )
2009-02-06 13:15:39 +02:00
{
2011-11-27 16:14:20 +03:00
return new CPicture ( config [ " name " ] . String ( ) , config [ " x " ] . Float ( ) , config [ " y " ] . Float ( ) ) ;
}
2009-08-17 11:50:31 +03:00
2011-11-27 16:14:20 +03:00
CMenuScreen : : CMenuScreen ( const JsonNode & configNode ) :
config ( configNode )
{
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2012-05-20 14:03:21 +03:00
background = new CPicture ( config [ " background " ] . String ( ) ) ;
if ( config [ " scalable " ] . Bool ( ) )
{
if ( background - > bg - > format - > palette )
background - > convertToScreenBPP ( ) ;
background - > scaleTo ( Point ( screen - > w , screen - > h ) ) ;
}
pos = background - > center ( ) ;
2011-11-27 16:14:20 +03:00
BOOST_FOREACH ( const JsonNode & node , config [ " items " ] . Vector ( ) )
menuNameToEntry . push_back ( node [ " name " ] . String ( ) ) ;
BOOST_FOREACH ( const JsonNode & node , config [ " images " ] . Vector ( ) )
images . push_back ( createPicture ( node ) ) ;
//Hardcoded entry
menuNameToEntry . push_back ( " credits " ) ;
tabs = new CTabbedInt ( boost : : bind ( & CMenuScreen : : createTab , this , _1 ) , CTabbedInt : : DestroyFunc ( ) ) ;
tabs - > type | = REDRAW_PARENT ;
}
CIntObject * CMenuScreen : : createTab ( size_t index )
{
if ( config [ " items " ] . Vector ( ) . size ( ) = = index )
return new CreditsScreen ( ) ;
return new CMenuEntry ( this , config [ " items " ] . Vector ( ) [ index ] ) ;
}
2012-05-18 20:35:46 +03:00
void CMenuScreen : : showAll ( SDL_Surface * to )
{
CIntObject : : showAll ( to ) ;
if ( pos . h ! = to - > h | | pos . w ! = to - > w )
2013-03-03 20:06:03 +03:00
CMessage : : drawBorder ( PlayerColor ( 1 ) , to , pos . w + 28 , pos . h + 30 , pos . x - 14 , pos . y - 15 ) ;
2012-05-18 20:35:46 +03:00
}
2011-11-27 16:14:20 +03:00
void CMenuScreen : : show ( SDL_Surface * to )
{
if ( ! config [ " video " ] . isNull ( ) )
2012-05-18 20:35:46 +03:00
CCS - > videoh - > update ( config [ " video " ] [ " x " ] . Float ( ) + pos . x , config [ " video " ] [ " y " ] . Float ( ) + pos . y , to , true , false ) ;
2011-11-27 16:14:20 +03:00
CIntObject : : show ( to ) ;
}
void CMenuScreen : : activate ( )
{
2012-08-06 10:34:37 +03:00
CCS - > musich - > playMusic ( " Music/MainMenu " , true ) ;
2011-11-27 16:14:20 +03:00
if ( ! config [ " video " ] . isNull ( ) )
CCS - > videoh - > open ( config [ " video " ] [ " name " ] . String ( ) ) ;
CIntObject : : activate ( ) ;
}
void CMenuScreen : : deactivate ( )
{
if ( ! config [ " video " ] . isNull ( ) )
CCS - > videoh - > close ( ) ;
CIntObject : : deactivate ( ) ;
}
void CMenuScreen : : switchToTab ( size_t index )
{
tabs - > setActive ( index ) ;
}
//funciton for std::string -> boost::function conversion for main menu
static boost : : function < void ( ) > genCommand ( CMenuScreen * menu , std : : vector < std : : string > menuType , const std : : string & string )
{
static const std : : vector < std : : string > commandType = boost : : assign : : list_of
( " to " ) ( " campaigns " ) ( " start " ) ( " load " ) ( " exit " ) ( " highscores " ) ;
static const std : : vector < std : : string > gameType = boost : : assign : : list_of
( " single " ) ( " multi " ) ( " campaign " ) ( " tutorial " ) ;
std : : list < std : : string > commands ;
boost : : split ( commands , string , boost : : is_any_of ( " \t " ) ) ;
if ( ! commands . empty ( ) )
2009-02-06 13:15:39 +02:00
{
2011-11-27 16:14:20 +03:00
size_t index = std : : find ( commandType . begin ( ) , commandType . end ( ) , commands . front ( ) ) - commandType . begin ( ) ;
commands . pop_front ( ) ;
if ( index > 3 | | ! commands . empty ( ) )
2009-02-06 13:15:39 +02:00
{
2011-11-27 16:14:20 +03:00
switch ( index )
{
break ; case 0 : //to - switch to another tab, if such tab exists
{
size_t index2 = std : : find ( menuType . begin ( ) , menuType . end ( ) , commands . front ( ) ) - menuType . begin ( ) ;
if ( index2 ! = menuType . size ( ) )
return boost : : bind ( & CMenuScreen : : switchToTab , menu , index2 ) ;
}
break ; case 1 : //open campaign selection window
{
return boost : : bind ( & CGPreGame : : openCampaignScreen , CGP , commands . front ( ) ) ;
}
break ; case 2 : //start
{
switch ( std : : find ( gameType . begin ( ) , gameType . end ( ) , commands . front ( ) ) - gameType . begin ( ) )
{
case 0 : return bind ( & CGPreGame : : openSel , CGP , CMenuScreen : : newGame , CMenuScreen : : SINGLE_PLAYER ) ;
case 1 : return & pushIntT < CMultiMode > ;
case 2 : return boost : : bind ( & CGPreGame : : openSel , CGP , CMenuScreen : : campaignList , CMenuScreen : : SINGLE_PLAYER ) ;
case 3 : return boost : : function < void ( ) > ( ) ; //TODO: start tutorial
}
}
break ; case 3 : //load
{
switch ( std : : find ( gameType . begin ( ) , gameType . end ( ) , commands . front ( ) ) - gameType . begin ( ) )
{
case 0 : return boost : : bind ( & CGPreGame : : openSel , CGP , CMenuScreen : : loadGame , CMenuScreen : : SINGLE_PLAYER ) ;
case 1 : return boost : : bind ( & CGPreGame : : openSel , CGP , CMenuScreen : : loadGame , CMenuScreen : : MULTI_HOT_SEAT ) ;
case 2 : return boost : : function < void ( ) > ( ) ; //TODO: load campaign
case 3 : return boost : : function < void ( ) > ( ) ; //TODO: load tutorial
}
}
break ; case 4 : //exit
{
2013-03-03 20:06:03 +03:00
return boost : : bind ( CInfoWindow : : showYesNoDialog , boost : : ref ( CGI - > generaltexth - > allTexts [ 69 ] ) , ( const std : : vector < CComponent * > * ) 0 , do_quit , 0 , false , PlayerColor ( 1 ) ) ;
2011-11-27 16:14:20 +03:00
}
break ; case 5 : //highscores
{
return boost : : function < void ( ) > ( ) ; //TODO: high scores &pushIntT<CHighScores>;
}
}
2010-02-08 16:38:06 +02:00
}
2009-02-06 13:15:39 +02:00
}
2011-11-27 16:14:20 +03:00
tlog0 < < " Failed to parse command: " < < string < < " \n " ;
return boost : : function < void ( ) > ( ) ;
}
2011-12-22 16:05:19 +03:00
CAdventureMapButton * CMenuEntry : : createButton ( CMenuScreen * parent , const JsonNode & button )
2011-11-27 16:14:20 +03:00
{
boost : : function < void ( ) > command = genCommand ( parent , parent - > menuNameToEntry , button [ " command " ] . String ( ) ) ;
2009-08-17 11:50:31 +03:00
2011-11-27 16:14:20 +03:00
std : : pair < std : : string , std : : string > help ;
if ( ! button [ " help " ] . isNull ( ) & & button [ " help " ] . Float ( ) > 0 )
help = CGI - > generaltexth - > zelp [ button [ " help " ] . Float ( ) ] ;
2012-05-20 14:03:21 +03:00
int posx = button [ " x " ] . Float ( ) ;
if ( posx < 0 )
posx = pos . w + posx ;
int posy = button [ " y " ] . Float ( ) ;
if ( posy < 0 )
posy = pos . h + posy ;
return new CAdventureMapButton ( help , command , posx , posy , button [ " name " ] . String ( ) , button [ " hotkey " ] . Float ( ) ) ;
2009-02-06 13:15:39 +02:00
}
2011-11-27 16:14:20 +03:00
CMenuEntry : : CMenuEntry ( CMenuScreen * parent , const JsonNode & config )
2008-08-06 01:11:32 +03:00
{
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
type | = REDRAW_PARENT ;
2012-05-20 14:03:21 +03:00
pos = parent - > pos ;
2011-11-27 16:14:20 +03:00
BOOST_FOREACH ( const JsonNode & node , config [ " images " ] . Vector ( ) )
images . push_back ( createPicture ( node ) ) ;
BOOST_FOREACH ( const JsonNode & node , config [ " buttons " ] . Vector ( ) )
{
buttons . push_back ( createButton ( parent , node ) ) ;
buttons . back ( ) - > hoverable = true ;
buttons . back ( ) - > type | = REDRAW_PARENT ;
}
2009-08-17 11:50:31 +03:00
}
2011-11-27 16:14:20 +03:00
CreditsScreen : : CreditsScreen ( )
2008-08-06 01:11:32 +03:00
{
2012-06-02 18:16:54 +03:00
addUsedEvents ( LCLICK | RCLICK ) ;
2011-11-27 16:14:20 +03:00
type | = REDRAW_PARENT ;
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2012-05-18 20:35:46 +03:00
pos . w = CGP - > menu - > pos . w ;
pos . h = CGP - > menu - > pos . h ;
2012-08-01 15:02:54 +03:00
auto textFile = CResourceHandler : : get ( ) - > loadData ( ResourceID ( " DATA/CREDITS.TXT " ) ) ;
std : : string text ( ( char * ) textFile . first . get ( ) , textFile . second ) ;
2011-11-27 16:14:20 +03:00
size_t firstQuote = text . find ( ' \" ' ) + 1 ;
text = text . substr ( firstQuote , text . find ( ' \" ' , firstQuote ) - firstQuote ) ;
2012-11-11 15:23:31 +03:00
credits = new CTextBox ( text , Rect ( pos . w - 350 , 600 , 350 , 32000 ) , 0 , FONT_CREDITS , CENTER , Colors : : WHITE ) ;
2011-11-27 16:14:20 +03:00
credits - > pos . h = credits - > maxH ;
2008-08-06 01:11:32 +03:00
}
2009-08-17 11:50:31 +03:00
2012-05-18 20:35:46 +03:00
void CreditsScreen : : showAll ( SDL_Surface * to )
{
//Do not draw anything
}
2011-12-22 16:05:19 +03:00
void CreditsScreen : : show ( SDL_Surface * to )
2009-01-25 18:19:34 +02:00
{
2011-11-27 16:14:20 +03:00
static int count = 0 ;
count + + ;
if ( count = = 2 )
{
credits - > pos . y - - ;
count = 0 ;
}
2012-05-18 20:35:46 +03:00
Rect creditsArea = credits - > pos & pos ;
SDL_SetClipRect ( screenBuf , & creditsArea ) ;
SDL_SetClipRect ( screen , & creditsArea ) ;
2011-11-27 16:14:20 +03:00
redraw ( ) ;
2012-05-18 20:35:46 +03:00
CIntObject : : showAll ( to ) ;
2011-11-27 16:14:20 +03:00
SDL_SetClipRect ( screen , NULL ) ;
2012-05-18 20:35:46 +03:00
SDL_SetClipRect ( screenBuf , NULL ) ;
2011-11-27 16:14:20 +03:00
//end of credits, close this screen
if ( credits - > pos . y + credits - > pos . h < 0 )
clickRight ( false , false ) ;
}
void CreditsScreen : : clickLeft ( tribool down , bool previousState )
{
clickRight ( down , previousState ) ;
2009-01-25 18:19:34 +02:00
}
2009-08-17 11:50:31 +03:00
2011-11-27 16:14:20 +03:00
void CreditsScreen : : clickRight ( tribool down , bool previousState )
2008-08-02 18:08:03 +03:00
{
2011-11-27 16:14:20 +03:00
CTabbedInt * menu = dynamic_cast < CTabbedInt * > ( parent ) ;
assert ( menu ) ;
menu - > setActive ( 0 ) ;
2008-08-02 18:08:03 +03:00
}
2011-11-27 16:14:20 +03:00
CGPreGame : : CGPreGame ( ) :
2012-08-02 14:03:26 +03:00
pregameConfig ( new JsonNode ( ResourceID ( " config/mainmenu.json " ) ) )
2008-08-02 18:08:03 +03:00
{
2012-07-21 23:16:54 +03:00
pos . w = screen - > w ;
pos . h = screen - > h ;
2009-08-27 11:04:32 +03:00
GH . defActionsDef = 63 ;
2009-08-17 11:50:31 +03:00
CGP = this ;
2011-11-27 16:14:20 +03:00
menu = new CMenuScreen ( ( * pregameConfig ) [ " window " ] ) ;
2012-03-11 19:29:01 +03:00
loadGraphics ( ) ;
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
{
2013-02-07 18:27:22 +03:00
boost : : unique_lock < boost : : recursive_mutex > lock ( * CPlayerInterface : : pim ) ;
2012-03-11 19:29:01 +03:00
disposeGraphics ( ) ;
2013-02-05 23:06:13 +03:00
if ( CGP = = this )
CGP = nullptr ;
2013-02-07 18:27:22 +03:00
if ( GH . curInt = = this )
GH . curInt = nullptr ;
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
void CGPreGame : : loadGraphics ( )
2008-08-02 18:08:03 +03:00
{
2012-07-21 23:16:54 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
new CFilledTexture ( " DIBOXBCK " , pos ) ;
2009-08-17 11:50:31 +03:00
victory = CDefHandler : : giveDef ( " SCNRVICT.DEF " ) ;
loss = CDefHandler : : giveDef ( " SCNRLOSS.DEF " ) ;
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 ;
2008-08-02 18:08:03 +03:00
}
2009-12-28 06:08:24 +02:00
void CGPreGame : : update ( )
{
2013-02-06 00:19:08 +03:00
boost : : unique_lock < boost : : recursive_mutex > lock ( * CPlayerInterface : : pim ) ;
if ( CGP ! = this ) //don't update if you are not a main interface
return ;
2011-11-27 16:14:20 +03:00
if ( GH . listInt . empty ( ) )
2009-12-28 06:08:24 +02:00
{
2012-05-18 20:35:46 +03:00
GH . pushInt ( this ) ;
2011-11-27 16:14:20 +03:00
GH . pushInt ( menu ) ;
menu - > switchToTab ( 0 ) ;
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
2012-12-17 21:01:17 +03:00
//if (GH.curInt == NULL) // no redraw, when a new game was created
//return;
2011-04-17 21:02:13 +03:00
2011-04-26 16:30:29 +03:00
GH . topInt ( ) - > show ( screen ) ;
2011-04-17 21:02:13 +03:00
2012-01-12 18:23:00 +03:00
if ( settings [ " general " ] [ " showfps " ] . Bool ( ) )
2011-04-17 21:02:13 +03:00
GH . drawFPSCounter ( ) ;
// draw the mouse cursor and update the screen
2012-12-14 18:32:53 +03:00
CCS - > curh - > drawWithScreenRestore ( ) ;
2011-04-17 21:02:13 +03:00
CSDL_Ext : : update ( screen ) ;
2012-12-14 18:32:53 +03:00
CCS - > curh - > drawRestored ( ) ;
2009-12-28 06:08:24 +02:00
}
2011-11-27 16:14:20 +03:00
void CGPreGame : : openCampaignScreen ( std : : string name )
{
BOOST_FOREACH ( const JsonNode & node , ( * pregameConfig ) [ " campaignsset " ] . Vector ( ) )
{
if ( node [ " name " ] . String ( ) = = name )
{
GH . pushInt ( new CCampaignScreen ( node ) ) ;
return ;
}
}
tlog1 < < " Unknown campaign set: " < < name < < " \n " ;
}
2012-05-18 20:35:46 +03:00
CGPreGame * CGPreGame : : create ( )
2012-03-11 19:29:01 +03:00
{
if ( ! CGP )
CGP = new CGPreGame ( ) ;
2012-05-18 20:35:46 +03:00
return CGP ;
2012-03-11 19:29:01 +03:00
}
2012-05-26 20:59:00 +03:00
void CGPreGame : : removeFromGui ( )
{
//remove everything but main menu and background
GH . popInts ( GH . listInt . size ( ) - 2 ) ;
GH . popInt ( GH . topInt ( ) ) ; //remove main menu
GH . popInt ( GH . topInt ( ) ) ; //remove background
}
2013-03-03 20:06:03 +03:00
CSelectionScreen : : CSelectionScreen ( CMenuScreen : : EState Type , CMenuScreen : : EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/ , const std : : map < ui8 , 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
{
2012-05-18 20:35:46 +03:00
CGPreGame : : create ( ) ; //we depend on its graphics
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 ( ) ;
}
2011-12-17 21:59:59 +03:00
IShowActivatable : : type = BLOCK_ADV_HOTKEYS ;
2009-08-27 11:04:32 +03:00
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
{
2012-05-18 20:35:46 +03:00
bordered = false ;
2009-08-27 11:04:32 +03:00
center ( pos ) ;
}
2010-02-15 14:12:21 +02:00
else if ( Type = = CMenuScreen : : campaignList )
{
2012-05-18 20:35:46 +03:00
bordered = false ;
2012-08-06 10:34:37 +03:00
bg = new CPicture ( " CamCust.bmp " , 0 , 0 ) ;
2012-05-18 20:35:46 +03:00
pos = bg - > center ( ) ;
2010-02-15 14:12:21 +02:00
}
2009-08-27 11:04:32 +03:00
else
{
2012-05-18 20:35:46 +03:00
bordered = true ;
2012-08-06 10:34:37 +03:00
//load random background
const JsonVector & bgNames = ( * CGP - > pregameConfig ) [ " game-select " ] . Vector ( ) ;
bg = new CPicture ( bgNames [ rand ( ) % bgNames . size ( ) ] . String ( ) , 0 , 0 ) ;
2012-05-18 20:35:46 +03:00
pos = bg - > center ( ) ;
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 ;
2011-11-27 16:14:20 +03:00
}
2010-02-13 18:26:47 +02:00
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 ;
2012-11-11 15:23:31 +03:00
2012-11-13 15:55:47 +03:00
randMapTab = new RandomMapTab ( ) ;
2012-11-20 20:53:45 +03:00
randMapTab - > getMapInfoChanged ( ) + = bind ( & CSelectionScreen : : changeSelection , this , _1 ) ;
2012-11-11 15:23:31 +03:00
randMapTab - > recActions = DISPOSE ;
2010-02-13 18:26:47 +02:00
}
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 ) ;
2012-11-20 20:53:45 +03:00
CAdventureMapButton * select = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 45 ] , 0 , 411 , 80 , " GSPBUTT.DEF " , SDLK_s ) ;
select - > callback = [ & ] ( )
{
toggleTab ( sel ) ;
changeSelection ( sel - > getSelectedMapInfo ( ) ) ;
} ;
2009-08-17 11:50:31 +03:00
select - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 500 ] , FONT_SMALL ) ;
2012-05-18 20:35:46 +03:00
CAdventureMapButton * opts = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 46 ] , bind ( & CSelectionScreen : : toggleTab , this , opt ) , 411 , 510 , " GSPBUTT.DEF " , SDLK_a ) ;
2009-08-17 11:50:31 +03:00
opts - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 501 ] , FONT_SMALL ) ;
2012-11-11 15:23:31 +03:00
CAdventureMapButton * randomBtn = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 47 ] , 0 , 411 , 105 , " GSPBUTT.DEF " , SDLK_r ) ;
randomBtn - > addTextOverlay ( CGI - > generaltexth - > allTexts [ 740 ] , FONT_SMALL ) ;
2013-01-26 16:48:20 +03:00
randomBtn - > callback = [ & ] ( )
2012-11-11 15:23:31 +03:00
{
2013-01-26 16:48:20 +03:00
toggleTab ( randMapTab ) ;
changeSelection ( & randMapTab - > getMapInfo ( ) ) ;
} ;
2009-08-17 11:50:31 +03:00
2012-12-17 21:01:17 +03:00
start = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 103 ] , bind ( & CSelectionScreen : : startScenario , this ) , 411 , 535 , " 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
{
2012-05-18 20:35:46 +03:00
CAdventureMapButton * hideChat = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 48 ] , bind ( & InfoCard : : toggleChat , card ) , 619 , 83 , " 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 } ;
2012-11-11 15:23:31 +03:00
select - > text - > color = opts - > text - > color = randomBtn - > text - > color = orange ;
2010-10-24 14:35:14 +03:00
select - > block ( true ) ;
opts - > block ( true ) ;
2012-11-11 15:23:31 +03:00
randomBtn - > block ( true ) ;
2010-10-24 14:35:14 +03:00
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 ;
2012-12-17 21:01:17 +03:00
start = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 103 ] , bind ( & CSelectionScreen : : startScenario , this ) , 411 , 535 , " SCNRLOD.DEF " , SDLK_l ) ;
2009-08-27 11:04:32 +03:00
break ;
2010-02-13 18:26:47 +02:00
case CMenuScreen : : saveGame :
2009-08-27 11:04:32 +03:00
sel - > recActions = 255 ;
2012-12-17 21:01:17 +03:00
start = new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 103 ] . second , bind ( & CSelectionScreen : : startScenario , this ) , 411 , 535 , " 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 ;
2012-05-18 20:35:46 +03:00
start = new CAdventureMapButton ( std : : pair < std : : string , std : : string > ( ) , bind ( & CSelectionScreen : : startCampaign , this ) , 411 , 535 , " SCNRLOD.DEF " , SDLK_b ) ;
2010-02-13 18:26:47 +02:00
break ;
2008-08-02 18:08:03 +03:00
}
2011-11-27 16:14:20 +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 " ;
}
2012-05-18 20:35:46 +03:00
back = new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 105 ] . second , bind ( & CGuiHandler : : popIntTotally , & GH , this ) , 581 , 535 , 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 ( ) ;
}
2013-02-14 18:19:35 +03:00
serv - > enterPregameConnectionMode ( ) ;
2010-10-24 14:35:14 +03:00
* 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 ;
}
2013-03-03 20:06:03 +03:00
playerColor = PlayerColor : : CANNOT_DETERMINE ;
2010-02-16 18:35:24 +02:00
playerNames . clear ( ) ;
2010-10-24 14:35:14 +03:00
assert ( ! serv ) ;
2011-12-14 00:23:17 +03:00
vstd : : clear_pointer ( applier ) ;
2010-10-24 14:35:14 +03:00
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 ;
2012-11-11 15:23:31 +03:00
else if ( tab = = randMapTab )
pga . action = PregameGuiAction : : OPEN_RANDOM_MAP_OPTIONS ;
2010-10-24 14:35:14 +03:00
* 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
}
2012-11-20 20:53:45 +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
{
2011-12-14 00:23:17 +03:00
vstd : : clear_pointer ( 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 ;
2011-09-26 03:01:47 +03:00
if ( to & & ( screenType = = CMenuScreen : : loadGame | |
screenType = = CMenuScreen : : saveGame ) )
SEL - > sInfo . difficulty = to - > scenarioOpts - > difficulty ;
if ( screenType ! = CMenuScreen : : campaignList )
2010-02-16 18:35:24 +02:00
{
2012-11-11 15:23:31 +03:00
updateStartInfo ( to ? to - > fileURI : " " , sInfo , to ? to - > mapHeader . get ( ) : NULL ) ;
2012-11-20 20:53:45 +03:00
if ( screenType = = CMenuScreen : : newGame )
{
2012-12-19 21:19:09 +03:00
if ( to & & to - > isRandomMap )
2012-11-20 20:53:45 +03:00
{
2012-12-19 21:19:09 +03:00
sInfo . createRandomMap = true ;
2012-11-20 20:53:45 +03:00
sInfo . mapGenOptions = std : : shared_ptr < CMapGenOptions > ( new CMapGenOptions ( randMapTab - > getMapGenOptions ( ) ) ) ;
}
else
{
2012-12-19 21:19:09 +03:00
sInfo . createRandomMap = false ;
2012-12-14 18:32:53 +03:00
sInfo . mapGenOptions . reset ( ) ;
2012-11-20 20:53:45 +03:00
}
}
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 ( )
{
2011-11-27 21:55:11 +03:00
if ( SEL - > current )
{
2012-09-21 20:59:54 +03:00
GH . pushInt ( new CBonusSelection ( SEL - > current - > fileURI ) ) ;
2011-11-27 21:55:11 +03:00
}
2010-02-15 14:12:21 +02:00
}
2012-12-17 21:01:17 +03:00
void CSelectionScreen : : startScenario ( )
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
2013-03-03 20:06:03 +03:00
std : : map < PlayerColor , PlayerSettings > : : const_iterator i ;
2012-09-24 19:14:53 +03:00
for ( i = SEL - > sInfo . playerInfos . cbegin ( ) ; i ! = SEL - > sInfo . playerInfos . cend ( ) ; i + + )
2012-12-02 15:21:44 +03:00
if ( i - > second . playerID ! = PlayerSettings : : PLAYER_AI )
2010-03-08 00:56:51 +02:00
break ;
2012-09-24 19:14:53 +03:00
if ( i = = SEL - > sInfo . playerInfos . cend ( ) )
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 ;
2012-11-20 20:53:45 +03:00
saveGameName . clear ( ) ;
if ( screenType = = CMenuScreen : : loadGame )
{
saveGameName = sInfo . mapname ;
}
StartInfo * si = new StartInfo ( sInfo ) ;
2012-05-26 20:59:00 +03:00
CGP - > removeFromGui ( ) ;
2012-12-17 21:01:17 +03:00
CGP - > showLoadingScreen ( boost : : bind ( & startGame , si , ( CConnection * ) nullptr ) ) ;
2009-08-27 11:04:32 +03:00
}
else
{
if ( ! ( sel & & sel - > txt & & sel - > txt - > text . size ( ) ) )
return ;
2009-08-17 11:50:31 +03:00
2012-11-20 20:53:45 +03:00
saveGameName = " Saves/ " + sel - > txt - > text ;
2010-03-08 00:56:51 +02:00
CFunctionList < void ( ) > overWrite ;
2012-11-20 20:53:45 +03:00
overWrite + = boost : : bind ( & CCallback : : save , LOCPLINT - > cb , saveGameName ) ;
2010-03-08 00:56:51 +02:00
overWrite + = bind ( & CGuiHandler : : popIntTotally , & GH , this ) ;
2013-02-19 01:37:22 +03:00
if ( CResourceHandler : : get ( ) - > existsResource ( ResourceID ( saveGameName , EResType : : CLIENT_SAVEGAME ) ) )
2010-03-08 00:56:51 +02:00
{
std : : string hlp = CGI - > generaltexth - > allTexts [ 493 ] ; //%s exists. Overwrite?
boost : : algorithm : : replace_first ( hlp , " %s " , sel - > txt - > text ) ;
2012-04-09 05:53:50 +03:00
LOCPLINT - > showYesNoDialog ( hlp , overWrite , 0 , false ) ;
2010-03-08 00:56:51 +02:00
}
else
overWrite ( ) ;
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 ( ) ;
2011-11-27 16:14:20 +03:00
redraw ( ) ;
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 ( )
{
2012-06-27 23:44:01 +03:00
setThreadName ( " 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 ;
2013-02-14 18:19:35 +03:00
tlog5 < < " Received a pack of type " < < typeid ( * pack ) . name ( ) < < std : : endl ;
2010-10-24 14:35:14 +03:00
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
{
2013-03-03 20:06:03 +03:00
std : : map < PlayerColor , PlayerSettings > : : const_iterator i ;
2012-09-24 19:14:53 +03:00
for ( i = si . playerInfos . cbegin ( ) ; i ! = si . playerInfos . cend ( ) ; i + + )
2010-10-24 14:35:14 +03:00
{
2012-12-02 15:21:44 +03:00
if ( i - > second . playerID = = myNameID )
2010-10-24 14:35:14 +03:00
{
playerColor = i - > first ;
break ;
}
}
2012-09-24 19:14:53 +03:00
if ( i = = si . playerInfos . cend ( ) ) //not found
2013-03-03 20:06:03 +03:00
playerColor = PlayerColor : : CANNOT_DETERMINE ;
2010-10-24 14:35:14 +03:00
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
}
2012-05-18 20:35:46 +03:00
void CSelectionScreen : : showAll ( SDL_Surface * to )
{
CIntObject : : showAll ( to ) ;
if ( bordered & & ( pos . h ! = to - > h | | pos . w ! = to - > w ) )
2013-03-03 20:06:03 +03:00
CMessage : : drawBorder ( PlayerColor ( 1 ) , to , pos . w + 28 , pos . h + 30 , pos . x - 14 , pos . y - 15 ) ;
2012-05-18 20:35:46 +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 )
{
2011-11-27 16:14:20 +03:00
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
{
2011-11-27 16:14:20 +03:00
for ( size_t i = 0 ; i < allItems . size ( ) ; i + + )
2010-02-13 18:26:47 +02:00
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
2012-08-01 15:02:54 +03:00
std : : vector < ResourceID > SelectionTab : : getFiles ( std : : string dirURI , int resType )
2008-08-02 18:08:03 +03:00
{
2012-08-01 15:02:54 +03:00
std : : vector < ResourceID > ret ;
boost : : to_upper ( dirURI ) ;
auto iterator = CResourceHandler : : get ( ) - > getIterator ( [ & ] ( const ResourceID & ident )
{
return ident . getType ( ) = = resType
2012-11-11 15:23:31 +03:00
& & boost : : algorithm : : starts_with ( ident . getName ( ) , dirURI ) ;
2012-08-01 15:02:54 +03:00
} ) ;
while ( iterator . hasNext ( ) )
{
ret . push_back ( * iterator ) ;
+ + iterator ;
}
return ret ;
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
2012-11-03 16:30:47 +03:00
void SelectionTab : : parseMaps ( const std : : vector < ResourceID > & files )
2008-08-02 18:08:03 +03:00
{
2012-11-11 15:23:31 +03:00
allItems . clear ( ) ;
for ( int i = 0 ; i < files . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
2012-11-03 22:31:16 +03:00
try
{
CMapInfo mapInfo ;
mapInfo . mapInit ( files [ i ] . getName ( ) ) ;
allItems . push_back ( mapInfo ) ;
}
catch ( std : : exception & e )
{
tlog2 < < " Map " < < files [ i ] . getName ( ) < < " is invalid. Message: " < < e . what ( ) < < std : : endl ;
}
2008-08-02 18:08:03 +03:00
}
2009-08-17 11:50:31 +03:00
}
2012-08-01 15:02:54 +03:00
void SelectionTab : : parseGames ( const std : : vector < ResourceID > & 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
{
2012-06-08 03:12:31 +03:00
try
2008-08-02 18:08:03 +03:00
{
2012-08-01 15:02:54 +03:00
CLoadFile lf ( CResourceHandler : : get ( ) - > getResourceName ( files [ i ] ) ) ;
2013-02-19 01:37:22 +03:00
lf . checkMagicBytes ( SAVEGAME_MAGIC ) ;
// ui8 sign[8];
// lf >> sign;
// if(std::memcmp(sign,"VCMISVG",7))
// {
// throw std::runtime_error("not a correct savefile!");
// }
2012-06-08 03:12:31 +03:00
2012-11-13 21:01:31 +03:00
// Create the map info object
CMapInfo mapInfo ;
mapInfo . mapHeader = std : : shared_ptr < CMapHeader > ( new CMapHeader ) ;
mapInfo . scenarioOpts = new StartInfo ;
lf > > * ( mapInfo . mapHeader . get ( ) ) > > mapInfo . scenarioOpts ;
mapInfo . fileURI = files [ i ] . getName ( ) ;
mapInfo . countPlayers ( ) ;
2012-08-01 15:02:54 +03:00
std : : time_t time = CFileInfo ( CResourceHandler : : get ( ) - > getResourceName ( files [ i ] ) ) . getDate ( ) ;
2012-11-13 21:01:31 +03:00
mapInfo . date = std : : asctime ( std : : localtime ( & time ) ) ;
2012-06-08 03:12:31 +03:00
2012-11-13 21:01:31 +03:00
// If multi mode then only multi games, otherwise single
if ( ( mapInfo . actualHumanPlayers > 1 ) ! = multi )
2012-06-08 03:12:31 +03:00
{
2012-11-13 21:01:31 +03:00
mapInfo . mapHeader . reset ( ) ;
2012-06-08 03:12:31 +03:00
}
2012-11-13 21:01:31 +03:00
allItems . push_back ( mapInfo ) ;
2012-06-08 03:12:31 +03:00
}
2013-01-06 22:30:12 +03:00
catch ( const std : : exception & e )
2010-02-24 15:03:36 +02:00
{
2013-01-06 22:30:12 +03:00
tlog3 < < " Error: Failed to process " < < files [ i ] . getName ( ) < < " : " < < e . what ( ) < < std : : endl ;
2010-02-24 15:03:36 +02:00
}
2008-08-02 18:08:03 +03:00
}
}
2009-02-06 13:15:39 +02:00
2012-08-01 15:02:54 +03:00
void SelectionTab : : parseCampaigns ( const std : : vector < ResourceID > & files )
2010-02-13 18:26:47 +02:00
{
2013-02-07 02:24:43 +03:00
allItems . resize ( files . size ( ) ) ;
2010-02-13 18:26:47 +02:00
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));
2012-08-01 15:02:54 +03:00
allItems [ i ] . fileURI = files [ i ] . getName ( ) ;
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 ;
2012-06-02 18:16:54 +03:00
addUsedEvents ( 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
{
2012-05-18 20:35:46 +03:00
bg = new CPicture ( " SCSELBCK.bmp " , 0 , 6 ) ;
pos = bg - > pos ;
2010-02-15 15:28:33 +02:00
}
else
{
2012-05-18 20:35:46 +03:00
bg = nullptr ; //use background from parent
pos . w = parent - > pos . w ;
pos . h = parent - > pos . h ;
pos . x + = 3 ; pos . y + = 6 ;
2010-02-15 15:28:33 +02:00
}
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 < CCampaignHeader > cpm ;
switch ( tabType )
2008-08-02 18:08:03 +03:00
{
2010-10-24 14:35:14 +03:00
case CMenuScreen : : newGame :
2012-08-01 15:02:54 +03:00
parseMaps ( getFiles ( " Maps/ " , EResType : : MAP ) ) ;
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 :
2013-02-19 01:37:22 +03:00
parseGames ( getFiles ( " Saves/ " , EResType : : CLIENT_SAVEGAME ) , MultiPlayer ) ;
2010-10-24 14:35:14 +03:00
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 ;
2011-11-27 16:14:20 +03:00
}
2010-10-24 14:35:14 +03:00
if ( tabType = = CMenuScreen : : saveGame )
2012-06-13 16:04:06 +03:00
{
2011-12-22 16:05:19 +03:00
txt = new CTextInput ( Rect ( 32 , 539 , 350 , 20 ) , Point ( - 32 , - 25 ) , " GSSTRIP.bmp " , 0 ) ;
2012-06-13 16:04:06 +03:00
txt - > filters . add ( CTextInput : : filenameFilter ) ;
}
2010-10-24 14:35:14 +03:00
break ;
2012-08-01 15:02:54 +03:00
2010-10-24 14:35:14 +03:00
case CMenuScreen : : campaignList :
2012-08-01 15:02:54 +03:00
parseCampaigns ( getFiles ( " Maps/ " , EResType : : CAMPAIGN ) ) ;
2010-10-24 14:35:14 +03:00
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
2011-11-27 16:14:20 +03: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 + + )
2011-12-22 16:05:19 +03:00
new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 54 + i ] . second , bind ( & SelectionTab : : filter , this , sizes [ i ] , true ) , 158 + 47 * i , 46 , names [ i ] ) ;
2010-02-13 18:26:47 +02:00
}
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 + + )
2011-12-22 16:05:19 +03:00
new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 107 + i ] . second , bind ( & SelectionTab : : sortBy , this , i ) , xpos [ i ] , 86 , names [ i ] ) ;
2010-02-13 18:26:47 +02:00
}
2009-02-11 19:03:30 +02:00
}
2010-02-15 15:28:33 +02:00
else
{
//sort by buttons
2011-12-22 16:05:19 +03:00
new CAdventureMapButton ( " " , " " , bind ( & SelectionTab : : sortBy , this , _numOfMaps ) , 23 , 86 , " CamCusM.DEF " ) ; //by num of maps
new CAdventureMapButton ( " " , " " , bind ( & SelectionTab : : sortBy , this , _name ) , 55 , 86 , " CamCusL.DEF " ) ; //by name
2010-02-15 15:28:33 +02:00
}
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 ) ;
2012-06-02 18:16:54 +03:00
slider - > addUsedEvents ( WHEEL ) ;
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 :
2012-08-01 15:02:54 +03:00
selectFName ( " Maps/Arrogance " ) ;
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 : ;
2012-11-20 20:53:45 +03:00
if ( saveGameName . empty ( ) )
2009-08-27 11:04:32 +03:00
{
2012-11-20 20:53:45 +03:00
txt - > setTxt ( " NEWGAME " ) ;
}
else
{
selectFName ( saveGameName ) ;
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 ;
2011-12-14 00:23:17 +03:00
vstd : : amax ( py , 0 ) ;
vstd : : 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 )
2012-08-01 15:02:54 +03:00
{
std : : string filename = CResourceHandler : : get ( ) - > getResourceName (
2013-02-19 01:37:22 +03:00
ResourceID ( curItems [ py ] - > fileURI , EResType : : CLIENT_SAVEGAME ) ) ;
2012-08-01 15:02:54 +03:00
txt - > setTxt ( CFileInfo ( filename ) . getBaseName ( ) ) ;
}
2010-03-08 00:56:51 +02:00
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
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 )
2012-11-11 15:23:31 +03:00
itemColor = Colors : : YELLOW ;
2011-11-27 16:14:20 +03:00
else
2012-11-11 15:23:31 +03:00
itemColor = Colors : : WHITE ;
2010-02-15 14:12:21 +02:00
2010-02-13 18:26:47 +02:00
if ( tabType ! = CMenuScreen : : campaignList )
{
//amount of players
std : : ostringstream ostr ( std : : ostringstream : : out ) ;
2012-08-01 15:02:54 +03:00
ostr < < currentItem - > playerAmnt < < " / " < < currentItem - > humanPlayers ;
2012-12-19 20:24:53 +03:00
printAtLoc ( ostr . str ( ) , 29 , 120 + line * 25 , FONT_SMALL , itemColor , to ) ;
2010-02-13 18:26:47 +02:00
//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 ;
}
2012-12-19 20:24:53 +03:00
printAtMiddleLoc ( temp2 , 70 , 128 + line * 25 , 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
{
2012-11-11 15:23:31 +03:00
case EMapFormat : : ROE :
2010-02-13 18:26:47 +02:00
temp = 0 ;
break ;
2012-11-11 15:23:31 +03:00
case EMapFormat : : AB :
2010-02-13 18:26:47 +02:00
temp = 1 ;
break ;
2012-11-11 15:23:31 +03:00
case EMapFormat : : SOD :
2010-02-13 18:26:47 +02:00
temp = 2 ;
break ;
2012-11-11 15:23:31 +03:00
case EMapFormat : : WOG :
2010-02-13 18:26:47 +02:00
temp = 3 ;
break ;
default :
// Unknown version. Be safe and ignore that map
2012-08-01 15:02:54 +03:00
tlog2 < < " Warning: " < < currentItem - > fileURI < < " has wrong version! \n " ;
2010-02-13 18:26:47 +02:00
continue ;
}
2012-12-19 20:24:53 +03:00
blitAtLoc ( format - > ourImages [ temp ] . bitmap , 88 , 117 + line * 25 , to ) ;
2010-02-13 18:26:47 +02:00
//victory conditions
2011-12-14 00:23:17 +03:00
if ( currentItem - > mapHeader - > victoryCondition . condition = = EVictoryConditionType : : WINSTANDARD )
2010-02-13 18:26:47 +02:00
temp = 11 ;
2011-11-27 16:14:20 +03:00
else
2010-10-24 14:35:14 +03:00
temp = currentItem - > mapHeader - > victoryCondition . condition ;
2012-12-19 20:24:53 +03:00
blitAtLoc ( CGP - > victory - > ourImages [ temp ] . bitmap , 306 , 117 + line * 25 , to ) ;
2010-02-13 18:26:47 +02:00
//loss conditions
2011-12-14 00:23:17 +03:00
if ( currentItem - > mapHeader - > lossCondition . typeOfLossCon = = ELossConditionType : : LOSSSTANDARD )
2010-02-13 18:26:47 +02:00
temp = 3 ;
2011-11-27 16:14:20 +03:00
else
2010-10-24 14:35:14 +03:00
temp = currentItem - > mapHeader - > lossCondition . typeOfLossCon ;
2012-12-19 20:24:53 +03:00
blitAtLoc ( CGP - > loss - > ourImages [ temp ] . bitmap , 339 , 117 + line * 25 , to ) ;
2010-02-13 18:26:47 +02:00
}
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 ( ) ;
2012-12-19 20:24:53 +03:00
printAtLoc ( ostr . str ( ) , 29 , 120 + line * 25 , FONT_SMALL , itemColor , to ) ;
2010-02-15 14:12:21 +02:00
}
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
{
2012-08-07 14:28:52 +03:00
name = CFileInfo ( CResourceHandler : : get ( ) - > getResourceName (
2013-02-19 01:37:22 +03:00
ResourceID ( currentItem - > fileURI , EResType : : CLIENT_SAVEGAME ) ) ) . getBaseName ( ) ;
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
2012-12-19 20:24:53 +03:00
printAtMiddleLoc ( name , 213 , 128 + line * 25 , FONT_SMALL , itemColor , to ) ;
2008-08-02 18:08:03 +03:00
}
}
2009-05-04 02:38:08 +03:00
2011-12-22 16:05:19 +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 :
2013-02-07 02:24:43 +03:00
title = CGI - > generaltexth - > allTexts [ 726 ] ;
2010-02-13 18:26:47 +02:00
break ;
2009-10-23 04:48:03 +03:00
}
2012-12-19 20:24:53 +03:00
printAtMiddleLoc ( title , 205 , 28 , FONT_MEDIUM , Colors : : YELLOW , to ) ; //Select a Scenario to Play
2010-02-15 14:12:21 +02:00
if ( tabType ! = CMenuScreen : : campaignList )
{
2012-12-19 20:24:53 +03:00
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 510 ] , 87 , 62 , FONT_SMALL , Colors : : YELLOW , to ) ; //Map sizes
2010-02-15 14:12:21 +02:00
}
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 :
2011-11-27 16:14:20 +03:00
moveBy = + positions - 1 ;
2009-08-23 21:01:08 +03:00
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
}
2011-11-27 16:14:20 +03:00
select ( selectionPos - slider - > value + moveBy ) ;
2009-08-23 21:01:08 +03:00
}
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 ;
2011-12-22 16:05:19 +03:00
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 ;
}
2012-08-01 15:02:54 +03:00
void SelectionTab : : selectFName ( std : : string fname )
2009-08-27 11:04:32 +03:00
{
2012-08-01 15:02:54 +03:00
boost : : to_upper ( fname ) ;
2009-08-27 11:04:32 +03:00
for ( int i = curItems . size ( ) - 1 ; i > = 0 ; i - - )
{
2012-08-01 15:02:54 +03:00
if ( curItems [ i ] - > fileURI = = fname )
2009-08-27 11:04:32 +03:00
{
slider - > moveTo ( i ) ;
selectAbs ( i ) ;
return ;
}
}
selectAbs ( 0 ) ;
2009-08-23 21:01:08 +03:00
}
2012-11-20 20:53:45 +03:00
const CMapInfo * SelectionTab : : getSelectedMapInfo ( ) const
{
return curItems . empty ( ) ? nullptr : curItems [ selectionPos ] ;
}
2012-11-11 15:23:31 +03:00
RandomMapTab : : RandomMapTab ( )
{
OBJ_CONSTRUCTION ;
bg = new CPicture ( " RANMAPBK " , 0 , 6 ) ;
// Map Size
mapSizeBtnGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
mapSizeBtnGroup - > pos . y + = 81 ;
mapSizeBtnGroup - > pos . x + = 158 ;
2012-11-11 15:23:31 +03:00
const std : : vector < std : : string > mapSizeBtns = boost : : assign : : list_of ( " RANSIZS " ) ( " RANSIZM " ) ( " RANSIZL " ) ( " RANSIZX " ) ;
addButtonsToGroup ( mapSizeBtnGroup , mapSizeBtns , 0 , 3 , 47 , 198 ) ;
mapSizeBtnGroup - > select ( 1 , false ) ;
mapSizeBtnGroup - > onChange = [ & ] ( int btnId )
{
2012-11-13 21:01:31 +03:00
const std : : vector < int > mapSizeVal = boost : : assign : : list_of ( 36 ) ( 72 ) ( 108 ) ( 144 ) ; // Map sizes in this order: S, M, L, XL
2012-11-20 20:53:45 +03:00
mapGenOptions . setWidth ( mapSizeVal [ btnId ] ) ;
mapGenOptions . setHeight ( mapSizeVal [ btnId ] ) ;
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
} ;
// Two levels
twoLevelsBtn = new CHighlightableButton ( 0 , 0 , std : : map < int , std : : string > ( ) ,
CGI - > generaltexth - > zelp [ 202 ] . second , false , " RANUNDR " , nullptr , 346 , 81 ) ;
twoLevelsBtn - > select ( true ) ;
2012-11-20 20:53:45 +03:00
twoLevelsBtn - > callback = [ & ] ( ) { mapGenOptions . setHasTwoLevels ( true ) ; updateMapInfo ( ) ; } ;
twoLevelsBtn - > callback2 = [ & ] ( ) { mapGenOptions . setHasTwoLevels ( false ) ; updateMapInfo ( ) ; } ;
2012-11-11 15:23:31 +03:00
// Create number defs list
std : : vector < std : : string > numberDefs ;
for ( int i = 0 ; i < = 8 ; + + i )
{
numberDefs . push_back ( " RANNUM " + boost : : lexical_cast < std : : string > ( i ) ) ;
}
const int NUMBERS_WIDTH = 32 ;
const int BTNS_GROUP_LEFT_MARGIN = 67 ;
// Amount of players
playersCntGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
playersCntGroup - > pos . y + = 153 ;
playersCntGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
addButtonsWithRandToGroup ( playersCntGroup , numberDefs , 1 , 8 , NUMBERS_WIDTH , 204 , 212 ) ;
playersCntGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setPlayersCnt ( btnId ) ;
2012-11-11 15:23:31 +03:00
deactivateButtonsFrom ( teamsCntGroup , btnId ) ;
deactivateButtonsFrom ( compOnlyPlayersCntGroup , 8 - btnId + 1 ) ;
validatePlayersCnt ( btnId ) ;
2012-11-20 20:53:45 +03:00
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
} ;
// Amount of teams
teamsCntGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
teamsCntGroup - > pos . y + = 219 ;
teamsCntGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
addButtonsWithRandToGroup ( teamsCntGroup , numberDefs , 0 , 7 , NUMBERS_WIDTH , 214 , 222 ) ;
teamsCntGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setTeamsCnt ( btnId ) ;
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
} ;
// Computer only players
compOnlyPlayersCntGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
compOnlyPlayersCntGroup - > pos . y + = 285 ;
compOnlyPlayersCntGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
addButtonsWithRandToGroup ( compOnlyPlayersCntGroup , numberDefs , 0 , 7 , NUMBERS_WIDTH , 224 , 232 ) ;
2012-11-20 20:53:45 +03:00
compOnlyPlayersCntGroup - > select ( 0 , true ) ;
2012-11-11 15:23:31 +03:00
compOnlyPlayersCntGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setCompOnlyPlayersCnt ( btnId ) ;
2012-11-11 15:23:31 +03:00
deactivateButtonsFrom ( compOnlyTeamsCntGroup , btnId ) ;
validateCompOnlyPlayersCnt ( btnId ) ;
2012-11-20 20:53:45 +03:00
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
} ;
// Computer only teams
compOnlyTeamsCntGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
compOnlyTeamsCntGroup - > pos . y + = 351 ;
compOnlyTeamsCntGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
addButtonsWithRandToGroup ( compOnlyTeamsCntGroup , numberDefs , 0 , 6 , NUMBERS_WIDTH , 234 , 241 ) ;
2012-11-20 20:53:45 +03:00
deactivateButtonsFrom ( compOnlyTeamsCntGroup , 0 ) ;
2012-11-11 15:23:31 +03:00
compOnlyTeamsCntGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setCompOnlyTeamsCnt ( btnId ) ;
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
} ;
const int WIDE_BTN_WIDTH = 85 ;
// Water content
waterContentGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
waterContentGroup - > pos . y + = 419 ;
waterContentGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
const std : : vector < std : : string > waterContentBtns = boost : : assign : : list_of ( " RANNONE " ) ( " RANNORM " ) ( " RANISLD " ) ;
addButtonsWithRandToGroup ( waterContentGroup , waterContentBtns , 0 , 2 , WIDE_BTN_WIDTH , 243 , 246 ) ;
waterContentGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setWaterContent ( static_cast < EWaterContent : : EWaterContent > ( btnId ) ) ;
2012-11-11 15:23:31 +03:00
} ;
// Monster strength
monsterStrengthGroup = new CHighlightableButtonsGroup ( 0 ) ;
2013-01-06 22:30:12 +03:00
monsterStrengthGroup - > pos . y + = 485 ;
monsterStrengthGroup - > pos . x + = BTNS_GROUP_LEFT_MARGIN ;
2012-11-11 15:23:31 +03:00
const std : : vector < std : : string > monsterStrengthBtns = boost : : assign : : list_of ( " RANWEAK " ) ( " RANNORM " ) ( " RANSTRG " ) ;
addButtonsWithRandToGroup ( monsterStrengthGroup , monsterStrengthBtns , 0 , 2 , WIDE_BTN_WIDTH , 248 , 251 ) ;
monsterStrengthGroup - > onChange = [ & ] ( int btnId )
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setMonsterStrength ( static_cast < EMonsterStrength : : EMonsterStrength > ( btnId ) ) ;
2012-11-11 15:23:31 +03:00
} ;
// Show random maps btn
showRandMaps = new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 252 ] . second , 0 , 54 , 535 , " RANSHOW " ) ;
2012-11-20 20:53:45 +03:00
// Initialize map info object
mapInfo . isRandomMap = true ;
shared_ptr < CMapHeader > mapHeader ( new CMapHeader ( ) ) ;
mapHeader - > version = EMapFormat : : SOD ;
mapHeader - > name = CGI - > generaltexth - > allTexts [ 740 ] ;
mapHeader - > description = CGI - > generaltexth - > allTexts [ 741 ] ;
mapHeader - > difficulty = 1 ; // Normal
mapInfo . mapHeader = mapHeader ;
updateMapInfo ( ) ;
2012-11-11 15:23:31 +03:00
}
void RandomMapTab : : addButtonsWithRandToGroup ( CHighlightableButtonsGroup * group , const std : : vector < std : : string > & defs , int nStart , int nEnd , int btnWidth , int helpStartIndex , int helpRandIndex ) const
{
addButtonsToGroup ( group , defs , nStart , nEnd , btnWidth , helpStartIndex ) ;
2012-11-20 20:53:45 +03:00
// Buttons are relative to button group, TODO better solution?
SObjectConstruction obj__i ( group ) ;
const std : : string RANDOM_DEF = " RANRAND " ;
group - > addButton ( new CHighlightableButton ( " " , CGI - > generaltexth - > zelp [ helpRandIndex ] . second , 0 , 256 , 0 , RANDOM_DEF , CMapGenOptions : : RANDOM_SIZE ) ) ;
group - > select ( CMapGenOptions : : RANDOM_SIZE , true ) ;
2012-11-11 15:23:31 +03:00
}
void RandomMapTab : : addButtonsToGroup ( CHighlightableButtonsGroup * group , const std : : vector < std : : string > & defs , int nStart , int nEnd , int btnWidth , int helpStartIndex ) const
{
// Buttons are relative to button group, TODO better solution?
SObjectConstruction obj__i ( group ) ;
2012-11-20 20:53:45 +03:00
int cnt = nEnd - nStart + 1 ;
2012-11-11 15:23:31 +03:00
for ( int i = 0 ; i < cnt ; + + i )
{
group - > addButton ( new CHighlightableButton ( " " , CGI - > generaltexth - > zelp [ helpStartIndex + i ] . second , 0 , i * btnWidth , 0 , defs [ i + nStart ] , i + nStart ) ) ;
}
}
void RandomMapTab : : deactivateButtonsFrom ( CHighlightableButtonsGroup * group , int startId )
{
BOOST_FOREACH ( CHighlightableButton * btn , group - > buttons )
{
2012-11-20 20:53:45 +03:00
if ( startId = = CMapGenOptions : : RANDOM_SIZE | | btn - > ID < startId )
2012-11-11 15:23:31 +03:00
{
if ( btn - > isBlocked ( ) )
{
btn - > setOffset ( 0 ) ;
btn - > setState ( CButtonBase : : NORMAL ) ;
}
}
else
{
// Blocked state looks like frame 'selected'=1
btn - > setOffset ( - 1 ) ;
btn - > setState ( CButtonBase : : BLOCKED ) ;
}
}
}
void RandomMapTab : : validatePlayersCnt ( int playersCnt )
{
2012-11-20 20:53:45 +03:00
if ( playersCnt = = CMapGenOptions : : RANDOM_SIZE )
2012-11-11 15:23:31 +03:00
{
return ;
}
2012-11-20 20:53:45 +03:00
if ( mapGenOptions . getTeamsCnt ( ) > = playersCnt )
2012-11-11 15:23:31 +03:00
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setTeamsCnt ( playersCnt - 1 ) ;
teamsCntGroup - > select ( mapGenOptions . getTeamsCnt ( ) , true ) ;
2012-11-11 15:23:31 +03:00
}
2012-11-20 20:53:45 +03:00
if ( mapGenOptions . getCompOnlyPlayersCnt ( ) > 8 - playersCnt )
2012-11-11 15:23:31 +03:00
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setCompOnlyPlayersCnt ( 8 - playersCnt ) ;
compOnlyPlayersCntGroup - > select ( mapGenOptions . getCompOnlyPlayersCnt ( ) , true ) ;
2012-11-11 15:23:31 +03:00
}
2012-11-20 20:53:45 +03:00
validateCompOnlyPlayersCnt ( mapGenOptions . getCompOnlyPlayersCnt ( ) ) ;
2012-11-11 15:23:31 +03:00
}
void RandomMapTab : : validateCompOnlyPlayersCnt ( int compOnlyPlayersCnt )
{
2012-11-20 20:53:45 +03:00
if ( compOnlyPlayersCnt = = CMapGenOptions : : RANDOM_SIZE )
2012-11-11 15:23:31 +03:00
{
return ;
}
2010-02-13 18:26:47 +02:00
2012-11-20 20:53:45 +03:00
if ( mapGenOptions . getCompOnlyTeamsCnt ( ) > = compOnlyPlayersCnt )
2012-11-11 15:23:31 +03:00
{
2012-11-20 20:53:45 +03:00
mapGenOptions . setCompOnlyTeamsCnt ( compOnlyPlayersCnt - 1 ) ;
compOnlyTeamsCntGroup - > select ( mapGenOptions . getCompOnlyTeamsCnt ( ) , true ) ;
2012-11-11 15:23:31 +03:00
}
}
void RandomMapTab : : showAll ( SDL_Surface * to )
{
CIntObject : : showAll ( to ) ;
// Headline
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 738 ] , 222 , 36 , FONT_BIG , Colors : : YELLOW , to ) ;
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 739 ] , 222 , 56 , FONT_SMALL , Colors : : WHITE , to ) ;
// Map size
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 752 ] , 104 , 97 , FONT_SMALL , Colors : : WHITE , to ) ;
// Players cnt
printAtLoc ( CGI - > generaltexth - > allTexts [ 753 ] , 68 , 133 , FONT_SMALL , Colors : : WHITE , to ) ;
// Teams cnt
printAtLoc ( CGI - > generaltexth - > allTexts [ 754 ] , 68 , 199 , FONT_SMALL , Colors : : WHITE , to ) ;
// Computer only players cnt
printAtLoc ( CGI - > generaltexth - > allTexts [ 755 ] , 68 , 265 , FONT_SMALL , Colors : : WHITE , to ) ;
// Computer only teams cnt
printAtLoc ( CGI - > generaltexth - > allTexts [ 756 ] , 68 , 331 , FONT_SMALL , Colors : : WHITE , to ) ;
// Water content
printAtLoc ( CGI - > generaltexth - > allTexts [ 757 ] , 68 , 398 , FONT_SMALL , Colors : : WHITE , to ) ;
// Monster strength
printAtLoc ( CGI - > generaltexth - > allTexts [ 758 ] , 68 , 465 , FONT_SMALL , Colors : : WHITE , to ) ;
}
2010-02-13 18:26:47 +02:00
2012-11-20 20:53:45 +03:00
void RandomMapTab : : updateMapInfo ( )
{
mapInfo . mapHeader - > height = mapGenOptions . getHeight ( ) ;
mapInfo . mapHeader - > width = mapGenOptions . getWidth ( ) ;
mapInfo . mapHeader - > twoLevel = mapGenOptions . getHasTwoLevels ( ) ;
// Generate player information
mapInfo . mapHeader - > players . clear ( ) ;
int playersToGen = ( mapGenOptions . getPlayersCnt ( ) = = CMapGenOptions : : RANDOM_SIZE
| | mapGenOptions . getCompOnlyPlayersCnt ( ) = = CMapGenOptions : : RANDOM_SIZE )
? 8 : mapGenOptions . getPlayersCnt ( ) + mapGenOptions . getCompOnlyPlayersCnt ( ) ;
mapInfo . mapHeader - > howManyTeams = playersToGen ;
for ( int i = 0 ; i < playersToGen ; + + i )
{
PlayerInfo player ;
player . canComputerPlay = true ;
if ( i > = mapGenOptions . getPlayersCnt ( ) & & mapGenOptions . getPlayersCnt ( ) ! = CMapGenOptions : : RANDOM_SIZE )
{
player . canHumanPlay = false ;
}
else
{
player . canHumanPlay = true ;
}
2013-03-03 20:06:03 +03:00
player . team = TeamID ( i ) ;
2013-01-20 17:43:58 +03:00
player . hasMainTown = true ;
player . generateHeroAtMainTown = true ;
2012-11-20 20:53:45 +03:00
mapInfo . mapHeader - > players . push_back ( player ) ;
}
mapInfoChanged ( & mapInfo ) ;
}
CFunctionList < void ( const CMapInfo * ) > & RandomMapTab : : getMapInfoChanged ( )
{
return mapInfoChanged ;
}
const CMapInfo & RandomMapTab : : getMapInfo ( ) const
{
return mapInfo ;
}
const CMapGenOptions & RandomMapTab : : getMapGenOptions ( ) const
{
return mapGenOptions ;
}
2011-12-22 16:05:19 +03:00
CChatBox : : CChatBox ( const Rect & rect )
2010-09-03 21:42:54 +03:00
{
2010-10-24 14:35:14 +03:00
OBJ_CONSTRUCTION ;
pos + = rect ;
2012-06-02 18:16:54 +03:00
addUsedEvents ( KEYBOARD ) ;
2010-10-24 14:35:14 +03:00
captureAllKeys = true ;
2012-12-19 20:24:53 +03:00
const int height = graphics - > fonts [ FONT_SMALL ] - > getLineHeight ( ) ;
2011-12-22 16:05:19 +03:00
inputBox = new CTextInput ( Rect ( 0 , rect . h - height , rect . w , height ) ) ;
2012-06-02 18:16:54 +03:00
inputBox - > removeUsedEvents ( KEYBOARD ) ;
2011-12-22 16:05:19 +03:00
chatHistory = new CTextBox ( " " , Rect ( 0 , 0 , rect . w , rect . h - height ) , 1 ) ;
2010-10-24 14:35:14 +03:00
2012-12-19 20:24:53 +03:00
chatHistory - > color = Colors : : GREEN ;
2010-10-24 14:35:14 +03:00
}
void CChatBox : : keyPressed ( const SDL_KeyboardEvent & key )
{
if ( key . keysym . sym = = SDLK_RETURN & & key . state = = SDL_PRESSED & & inputBox - > text . size ( ) )
{
SEL - > postChatMessage ( inputBox - > text ) ;
2012-06-13 16:04:06 +03:00
inputBox - > setTxt ( " " ) ;
2010-10-24 14:35:14 +03:00
}
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
{
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2009-08-27 11:04:32 +03:00
pos . x + = 393 ;
2012-05-18 20:35:46 +03:00
pos . y + = 6 ;
2012-06-02 18:16:54 +03:00
addUsedEvents ( RCLICK ) ;
2010-07-06 05:10:26 +03:00
mapDescription = NULL ;
2009-08-27 11:04:32 +03:00
2011-12-22 16:05:19 +03:00
Rect descriptionRect ( 26 , 149 , 320 , 115 ) ;
2010-07-06 05:10:26 +03:00
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 ) ;
2012-06-02 18:16:54 +03:00
mapDescription - > addChild ( new CPicture ( * ss - > bg , descriptionRect + Point ( - 393 , 0 ) ) , true ) ; //move subpicture bg to our description control (by default it's our (Infocard) child)
2010-02-15 14:12:21 +02:00
}
else
{
2012-05-18 20:35:46 +03:00
bg = new CPicture ( " GSELPOP1.bmp " , 0 , 0 ) ;
2012-06-02 18:16:54 +03:00
parent - > addChild ( bg ) ;
2012-02-22 22:22:11 +03:00
auto it = vstd : : find ( parent - > children , this ) ; //our position among parent children
parent - > children . insert ( it , bg ) ; //put BG before us
2011-11-27 16:14:20 +03:00
parent - > children . pop_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
2012-06-02 18:16:54 +03:00
mapDescription - > addChild ( new CPicture ( * bg , descriptionRect ) , 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 ) ;
2012-06-02 18:16:54 +03:00
chat - > chatHistory - > addChild ( new CPicture ( * bg , chat - > chatHistory - > pos - pos ) , true ) ; //move subpicture bg to our description control (by default it's our (Infocard) child)
2010-10-24 14:35:14 +03:00
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
2011-12-22 16:05:19 +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
{
2012-11-11 15:23:31 +03:00
printAtLoc ( CGI - > generaltexth - > allTexts [ 390 ] + " : " , 24 , 400 , FONT_SMALL , Colors : : WHITE , to ) ; //Allies
printAtLoc ( CGI - > generaltexth - > allTexts [ 391 ] + " : " , 190 , 400 , FONT_SMALL , Colors : : WHITE , to ) ; //Enemies
printAtLoc ( CGI - > generaltexth - > allTexts [ 494 ] , 33 , 430 , FONT_SMALL , Colors : : YELLOW , to ) ; //"Map Diff:"
printAtLoc ( CGI - > generaltexth - > allTexts [ 492 ] + " : " , 133 , 430 , FONT_SMALL , Colors : : YELLOW , to ) ; //player difficulty
printAtLoc ( CGI - > generaltexth - > allTexts [ 218 ] + " : " , 290 , 430 , FONT_SMALL , Colors : : YELLOW , to ) ; //"Rating:"
printAtLoc ( CGI - > generaltexth - > allTexts [ 495 ] , 26 , 22 , FONT_SMALL , Colors : : YELLOW , to ) ; //Scenario Name:
2010-10-24 14:35:14 +03:00
if ( ! chatOn )
{
2012-11-11 15:23:31 +03:00
printAtLoc ( CGI - > generaltexth - > allTexts [ 496 ] , 26 , 132 , FONT_SMALL , Colors : : YELLOW , to ) ; //Scenario Description:
printAtLoc ( CGI - > generaltexth - > allTexts [ 497 ] , 26 , 283 , FONT_SMALL , Colors : : YELLOW , to ) ; //Victory Condition:
printAtLoc ( CGI - > generaltexth - > allTexts [ 498 ] , 26 , 339 , FONT_SMALL , Colors : : YELLOW , to ) ; //Loss Condition:
2010-10-24 14:35:14 +03:00
}
else //players list
{
2013-03-03 20:06:03 +03:00
std : : map < ui8 , std : : string > playerNames = SEL - > playerNames ;
2010-10-24 14:35:14 +03:00
int playerSoFar = 0 ;
2012-09-24 19:14:53 +03:00
for ( auto i = SEL - > sInfo . playerInfos . cbegin ( ) ; i ! = SEL - > sInfo . playerInfos . cend ( ) ; i + + )
2010-10-24 14:35:14 +03:00
{
2012-12-02 15:21:44 +03:00
if ( i - > second . playerID ! = PlayerSettings : : PLAYER_AI )
2010-10-24 14:35:14 +03:00
{
2012-12-19 20:24:53 +03:00
printAtLoc ( i - > second . name , 24 , 285 + playerSoFar + + * graphics - > fonts [ FONT_SMALL ] - > getLineHeight ( ) , FONT_SMALL , Colors : : WHITE , to ) ;
2012-12-02 15:21:44 +03:00
playerNames . erase ( i - > second . playerID ) ;
2010-10-24 14:35:14 +03:00
}
}
playerSoFar = 0 ;
2012-09-24 19:14:53 +03:00
for ( auto i = playerNames . cbegin ( ) ; i ! = playerNames . cend ( ) ; i + + )
2010-10-24 14:35:14 +03:00
{
2012-12-19 20:24:53 +03:00
printAtLoc ( i - > second , 193 , 285 + playerSoFar + + * graphics - > fonts [ FONT_SMALL ] - > getLineHeight ( ) , FONT_SMALL , Colors : : WHITE , to ) ;
2010-10-24 14:35:14 +03:00
}
}
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
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 ] ;
2012-11-11 15:23:31 +03:00
printAtLoc ( sss , 60 , 307 , FONT_SMALL , Colors : : WHITE , to ) ;
2010-10-24 14:35:14 +03:00
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 ] ;
2012-11-11 15:23:31 +03:00
printAtLoc ( sss , 60 , 366 , FONT_SMALL , Colors : : WHITE , to ) ;
2010-10-24 14:35:14 +03:00
temp = SEL - > current - > mapHeader - > lossCondition . typeOfLossCon ;
if ( temp > 12 ) temp = 3 ;
2011-11-27 16:14:20 +03:00
blitAtLoc ( CGP - > loss - > ourImages [ temp ] . bitmap , 24 , 359 , to ) ; //loss cond
2010-10-24 14:35:14 +03:00
}
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 ] ;
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( diff , 62 , 472 , FONT_SMALL , Colors : : WHITE , to ) ;
2010-02-13 18:26:47 +02:00
//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 )
2012-11-11 15:23:31 +03:00
printToLoc ( ( static_cast < const CMapInfo * > ( SEL - > current ) ) - > date , 308 , 34 , FONT_SMALL , Colors : : WHITE , to ) ;
2010-02-13 18:26:47 +02:00
//print flags
2012-12-19 20:24:53 +03:00
int fx = 34 + graphics - > fonts [ FONT_SMALL ] - > getStringWidth ( CGI - > generaltexth - > allTexts [ 390 ] ) ;
int ex = 200 + graphics - > fonts [ FONT_SMALL ] - > getStringWidth ( CGI - > generaltexth - > allTexts [ 391 ] ) ;
2011-11-27 16:14:20 +03:00
2013-03-03 20:06:03 +03:00
TeamID myT ;
2010-10-24 14:35:14 +03:00
2013-03-03 20:06:03 +03:00
if ( playerColor < PlayerColor : : PLAYER_LIMIT )
myT = SEL - > current - > mapHeader - > players [ playerColor . getNum ( ) ] . team ;
2011-11-27 16:14:20 +03:00
else
2013-03-03 20:06:03 +03:00
myT = TeamID : : NO_TEAM ;
2010-10-24 14:35:14 +03:00
2012-09-24 19:14:53 +03:00
for ( auto i = SEL - > sInfo . playerInfos . cbegin ( ) ; i ! = SEL - > sInfo . playerInfos . cend ( ) ; i + + )
2010-02-13 18:26:47 +02:00
{
2013-03-03 20:06:03 +03:00
int * myx = ( ( i - > first = = playerColor | | SEL - > current - > mapHeader - > players [ i - > first . getNum ( ) ] . team = = myT ) ? & fx : & ex ) ;
blitAtLoc ( sFlags - > ourImages [ i - > first . getNum ( ) ] . bitmap , * myx , 399 , to ) ;
* myx + = sFlags - > ourImages [ i - > first . getNum ( ) ] . 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 ;
}
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( tob , 311 , 472 , FONT_SMALL , Colors : : WHITE , to ) ;
2010-02-13 18:26:47 +02:00
}
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 ;
2011-11-27 16:14:20 +03:00
}
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 ( ) )
2012-12-19 20:24:53 +03:00
printAtLoc ( name , 26 , 39 , FONT_BIG , Colors : : YELLOW , to ) ;
2011-11-27 16:14:20 +03:00
else
2012-11-11 15:23:31 +03:00
printAtLoc ( " Unnamed " , 26 , 39 , FONT_BIG , Colors : : YELLOW , 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
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 ) ;
2011-09-26 03:01:47 +03:00
if ( SEL - > screenType ! = CMenuScreen : : newGame & & SEL - > screenType ! = CMenuScreen : : campaignList ) {
difficulty - > block ( true ) ;
2010-10-24 14:35:14 +03:00
difficulty - > select ( SEL - > sInfo . difficulty , 0 ) ;
2011-09-26 03:01:47 +03:00
}
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 )
{
2011-12-22 16:05:19 +03:00
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 ( )
{
2012-05-13 18:04:21 +03:00
SDL_Surface * bmp = CMessage : : drawDialogBox ( 256 , 90 + 50 * SEL - > current - > mapHeader - > howManyTeams ) ;
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_MEDIUM ] - > renderTextCenter ( bmp , CGI - > generaltexth - > allTexts [ 657 ] , Colors : : YELLOW , Point ( 128 , 30 ) ) ;
2009-08-22 16:59:15 +03:00
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 ) ) ;
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_SMALL ] - > renderTextCenter ( bmp , hlp , Colors : : WHITE , Point ( 128 , 65 + 50 * i ) ) ;
2009-08-22 16:59:15 +03:00
2013-03-03 20:06:03 +03:00
for ( int j = 0 ; j < PlayerColor : : PLAYER_LIMIT_I ; j + + )
2010-10-24 14:35:14 +03:00
if ( ( SEL - > current - > mapHeader - > players [ j ] . canHumanPlay | | SEL - > current - > mapHeader - > players [ j ] . canComputerPlay )
2013-03-03 20:06:03 +03:00
& & SEL - > current - > mapHeader - > players [ j ] . team = = TeamID ( 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 ;
2011-11-27 16:14:20 +03:00
}
2009-08-22 16:59:15 +03:00
}
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 ;
2012-05-18 20:35:46 +03:00
bg = new CPicture ( " ADVOPTBK " , 0 , 6 ) ;
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
2011-12-22 16:05:19 +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 ) ;
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 515 ] , 222 , 30 , FONT_BIG , Colors : : YELLOW , to ) ;
2012-12-19 20:24:53 +03:00
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 516 ] , 222 , 68 , FONT_SMALL , 300 , Colors : : WHITE , to ) ; //Select starting options, handicap, and name for each player in the game.
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 517 ] , 107 , 110 , FONT_SMALL , 100 , Colors : : YELLOW , to ) ; //Player Name Handicap Type
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 518 ] , 197 , 110 , FONT_SMALL , 70 , Colors : : YELLOW , to ) ; //Starting Town
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 519 ] , 273 , 110 , FONT_SMALL , 70 , Colors : : YELLOW , to ) ; //Starting Hero
printAtMiddleWBLoc ( CGI - > generaltexth - > allTexts [ 520 ] , 349 , 110 , FONT_SMALL , 70 , Colors : : YELLOW , to ) ; //Starting Bonus
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( CGI - > generaltexth - > allTexts [ 521 ] , 222 , 538 , FONT_SMALL , Colors : : YELLOW , to ) ; // Player Turn Duration
2011-01-17 18:07:08 +02:00
if ( turnDuration )
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( CGI - > generaltexth - > turnDurations [ turnDuration - > value ] , 319 , 559 , FONT_SMALL , Colors : : WHITE , to ) ; //Turn duration value
2009-08-17 11:50:31 +03:00
}
2013-03-03 20:06:03 +03:00
void OptionsTab : : nextCastle ( PlayerColor player , int dir )
2009-08-17 11:50:31 +03:00
{
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) )
{
SEL - > postRequest ( RequestOptionsChange : : TOWN , dir ) ;
return ;
}
PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2012-12-02 15:21:44 +03:00
si16 & cur = s . castle ;
2013-03-03 20:06:03 +03:00
auto & allowed = SEL - > current - > mapHeader - > players [ s . color . getNum ( ) ] . allowedFactions ;
2009-08-17 11:50:31 +03:00
2012-12-10 17:28:27 +03:00
if ( cur = = PlayerSettings : : NONE ) //no change
2010-08-04 14:18:13 +03:00
return ;
2012-12-10 17:28:27 +03:00
if ( cur = = PlayerSettings : : RANDOM ) //first/last available
2010-08-04 14:18:13 +03:00
{
2012-09-23 17:32:49 +03:00
if ( dir > 0 )
cur = * allowed . begin ( ) ; //id of first town
else
cur = * allowed . rbegin ( ) ; //id of last town
2010-08-04 14:18:13 +03:00
}
else // next/previous available
{
2012-09-23 17:32:49 +03:00
if ( ( cur = = * allowed . begin ( ) & & dir < 0 )
| | ( cur = = * allowed . rbegin ( ) & & dir > 0 ) )
cur = - 1 ;
else
2010-08-04 14:18:13 +03:00
{
2012-09-23 17:32:49 +03:00
assert ( dir > = - 1 & & dir < = 1 ) ; //othervice std::advance may go out of range
auto iter = allowed . find ( cur ) ;
std : : advance ( iter , dir ) ;
cur = * iter ;
2010-08-04 14:18:13 +03:00
}
}
2009-08-17 11:50:31 +03:00
2013-03-03 20:06:03 +03:00
if ( s . hero > = 0 & & SEL - > current - > mapHeader - > players [ s . color . getNum ( ) ] . customHeroID < 0 ) // remove hero unless it set to fixed one in map editor
2012-12-10 17:28:27 +03:00
s . hero = PlayerSettings : : RANDOM ;
2012-12-02 15:21:44 +03:00
if ( cur < 0 & & s . bonus = = PlayerSettings : : RESOURCE )
s . bonus = PlayerSettings : : RANDOM ;
2009-08-18 11:22:56 +03:00
entries [ player ] - > selectButtons ( ) ;
2010-10-24 14:35:14 +03:00
SEL - > propagateOptions ( ) ;
2012-12-10 17:28:27 +03:00
entries [ player ] - > update ( ) ;
2009-08-17 11:50:31 +03:00
redraw ( ) ;
}
2013-03-03 20:06:03 +03:00
void OptionsTab : : nextHero ( PlayerColor player , int dir )
2009-08-17 11:50:31 +03:00
{
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 ;
2012-12-02 15:21:44 +03:00
if ( s . castle < 0 | | s . playerID = = PlayerSettings : : PLAYER_AI | | s . hero = = PlayerSettings : : NONE )
2009-08-17 11:50:31 +03:00
return ;
2008-08-02 18:08:03 +03:00
2012-12-10 17:28:27 +03:00
if ( s . hero = = PlayerSettings : : RANDOM ) // first/last available
2009-02-11 19:48:40 +02:00
{
2012-12-17 15:55:29 +03:00
int max = CGI - > heroh - > heroes . size ( ) ,
min = 0 ;
s . hero = nextAllowedHero ( player , 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 )
2012-12-17 15:55:29 +03:00
s . hero = nextAllowedHero ( player , s . hero , CGI - > heroh - > heroes . size ( ) , 1 , dir ) ;
2009-08-17 11:50:31 +03:00
else
2012-12-17 15:55:29 +03:00
s . hero = nextAllowedHero ( player , 0 , 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 ) ;
2012-12-10 17:28:27 +03:00
entries [ player ] - > update ( ) ;
2009-08-17 11:50:31 +03:00
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
}
2013-03-03 20:06:03 +03:00
int OptionsTab : : nextAllowedHero ( PlayerColor player , int min , int max , int incl , int dir )
2009-08-17 11:50:31 +03:00
{
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 + + )
2012-12-17 15:55:29 +03:00
if ( canUseThisHero ( player , i ) )
2009-08-17 11:50:31 +03:00
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 - - )
2012-12-17 15:55:29 +03:00
if ( canUseThisHero ( player , i ) )
2009-08-17 11:50:31 +03:00
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
2013-03-03 20:06:03 +03:00
bool OptionsTab : : canUseThisHero ( PlayerColor player , int ID )
2009-08-17 11:50:31 +03:00
{
2012-10-06 11:47:13 +03:00
return CGI - > heroh - > heroes . size ( ) > ID
2012-12-17 15:55:29 +03:00
& & SEL - > sInfo . playerInfos [ player ] . castle = = CGI - > heroh - > heroes [ ID ] - > heroClass - > faction
& & ! 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
2013-03-03 20:06:03 +03:00
void OptionsTab : : nextBonus ( PlayerColor player , int dir )
2009-08-17 11:50:31 +03:00
{
2010-10-24 14:35:14 +03:00
if ( SEL - > isGuest ( ) )
{
SEL - > postRequest ( RequestOptionsChange : : BONUS , dir ) ;
return ;
}
PlayerSettings & s = SEL - > sInfo . playerInfos [ player ] ;
2013-02-02 01:04:25 +03:00
PlayerSettings : : Ebonus & ret = s . bonus = static_cast < PlayerSettings : : Ebonus > ( static_cast < int > ( s . bonus ) + dir ) ;
2009-06-24 09:56:36 +03:00
2012-12-10 17:28:27 +03:00
if ( s . hero = = PlayerSettings : : NONE & &
2013-03-03 20:06:03 +03:00
! SEL - > current - > mapHeader - > players [ s . color . getNum ( ) ] . heroesNames . size ( ) & &
2012-12-10 17:28:27 +03:00
ret = = PlayerSettings : : ARTIFACT ) //no hero - can't be artifact
2009-08-17 11:50:31 +03:00
{
if ( dir < 0 )
2012-12-02 15:21:44 +03:00
ret = PlayerSettings : : RANDOM ;
else ret = PlayerSettings : : GOLD ;
2008-08-02 18:08:03 +03:00
}
2009-06-28 02:33:59 +03:00
2012-12-02 15:21:44 +03:00
if ( ret > PlayerSettings : : RESOURCE )
ret = PlayerSettings : : RANDOM ;
if ( ret < PlayerSettings : : RANDOM )
ret = PlayerSettings : : RESOURCE ;
2009-06-24 09:56:36 +03:00
2012-12-10 17:28:27 +03:00
if ( s . castle = = PlayerSettings : : RANDOM & & ret = = PlayerSettings : : RESOURCE ) //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 )
2012-12-02 15:21:44 +03:00
ret = PlayerSettings : : GOLD ;
else ret = PlayerSettings : : RANDOM ;
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 ( ) ;
2012-12-10 17:28:27 +03:00
entries [ player ] - > update ( ) ;
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
{
2013-03-03 20:06:03 +03:00
for ( auto it = entries . begin ( ) ; it ! = entries . end ( ) ; + + it )
2008-08-02 18:08:03 +03:00
{
2010-08-03 14:36:52 +03:00
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 ;
2012-09-24 19:14:53 +03:00
for ( auto 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 ) ) ) ;
2013-03-03 20:06:03 +03:00
const std : : vector < SHeroName > & heroes = SEL - > current - > mapHeader - > players [ it - > first . getNum ( ) ] . heroesNames ;
2009-08-17 11:50:31 +03:00
for ( size_t hi = 0 ; hi < heroes . size ( ) ; hi + + )
2012-11-11 15:23:31 +03:00
usedHeroes . insert ( heroes [ hi ] . heroId ) ;
2008-08-02 18:08:03 +03:00
}
2010-10-24 14:35:14 +03:00
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 } ;
2011-12-14 00:23:17 +03:00
vstd : : amin ( npos , ARRAY_COUNT ( times ) - 1 ) ;
2009-08-17 11:50:31 +03:00
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
}
2013-03-03 20:06:03 +03:00
void OptionsTab : : flagPressed ( PlayerColor 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
2012-12-02 15:21:44 +03:00
int clickedNameID = clicked . playerID ; //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
{
2012-09-24 19:14:53 +03:00
auto i = SEL - > playerNames . find ( clickedNameID ) ; //clicked one
2010-10-24 14:35:14 +03:00
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
{
2012-09-24 19:14:53 +03:00
for ( auto i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
2010-02-16 18:35:24 +02:00
{
2012-12-02 15:21:44 +03:00
int curNameID = i - > second . playerID ;
2010-10-24 14:35:14 +03:00
if ( i - > first ! = color & & curNameID = = newPlayer )
2010-02-16 18:35:24 +02:00
{
2012-12-02 15:21:44 +03:00
assert ( i - > second . playerID ) ;
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 ( ) ;
2012-03-26 14:38:51 +03:00
if ( old - > hero > = 0 )
usedHeroes . erase ( old - > hero ) ;
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 )
2013-03-03 20:06:03 +03:00
: pi ( SEL - > current - > mapHeader - > players [ S . color . getNum ( ) ] ) , 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 ;
2013-03-03 20:06:03 +03:00
for ( int g = 0 ; g < s . color . getNum ( ) ; + + g )
2010-08-03 14:36:52 +03:00
{
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 + + ;
}
2012-06-02 18:16:54 +03:00
pos . x + = 54 ;
pos . y + = 122 + serial * 50 ;
2008-11-16 03:06:15 +02:00
2011-11-27 16:14:20 +03:00
static const char * flags [ ] = { " AOFLGBR.DEF " , " AOFLGBB.DEF " , " AOFLGBY.DEF " , " AOFLGBG.DEF " ,
2009-08-17 11:50:31 +03:00
" AOFLGBO.DEF " , " AOFLGBP.DEF " , " AOFLGBT.DEF " , " AOFLGBS.DEF " } ;
2011-11-27 16:14:20 +03:00
static const char * bgs [ ] = { " ADOPRPNL.bmp " , " ADOPBPNL.bmp " , " ADOPYPNL.bmp " , " ADOPGPNL.bmp " ,
2009-08-17 11:50:31 +03:00
" ADOPOPNL.bmp " , " ADOPPPNL.bmp " , " ADOPTPNL.bmp " , " ADOPSPNL.bmp " } ;
2008-11-16 03:06:15 +02:00
2013-03-03 20:06:03 +03:00
bg = new CPicture ( BitmapHandler : : loadBitmap ( bgs [ s . color . getNum ( ) ] ) , 0 , 0 , true ) ;
2010-10-24 14:35:14 +03:00
if ( SEL - > screenType = = CMenuScreen : : newGame )
2009-08-27 11:04:32 +03:00
{
2011-12-22 16:05:19 +03:00
btns [ 0 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 132 ] , bind ( & OptionsTab : : nextCastle , owner , s . color , - 1 ) , 107 , 5 , " ADOPLFA.DEF " ) ;
btns [ 1 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 133 ] , bind ( & OptionsTab : : nextCastle , owner , s . color , + 1 ) , 168 , 5 , " ADOPRTA.DEF " ) ;
btns [ 2 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 148 ] , bind ( & OptionsTab : : nextHero , owner , s . color , - 1 ) , 183 , 5 , " ADOPLFA.DEF " ) ;
btns [ 3 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 149 ] , bind ( & OptionsTab : : nextHero , owner , s . color , + 1 ) , 244 , 5 , " ADOPRTA.DEF " ) ;
btns [ 4 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 164 ] , bind ( & OptionsTab : : nextBonus , owner , s . color , - 1 ) , 259 , 5 , " ADOPLFA.DEF " ) ;
btns [ 5 ] = new CAdventureMapButton ( 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 ) ;
2013-03-03 20:06:03 +03:00
const PlayerInfo & p = SEL - > current - > mapHeader - > players [ s . color . getNum ( ) ] ;
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
2011-11-27 16:14:20 +03:00
if ( SEL - > screenType ! = CMenuScreen : : scenarioInfo
2013-03-03 20:06:03 +03:00
& & SEL - > current - > mapHeader - > players [ s . color . getNum ( ) ] . canHumanPlay
2010-10-24 14:35:14 +03:00
& & SEL - > multiPlayer ! = CMenuScreen : : MULTI_NETWORK_GUEST )
2009-08-17 11:50:31 +03:00
{
2013-03-03 20:06:03 +03:00
flag = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 180 ] , bind ( & OptionsTab : : flagPressed , owner , s . color ) , - 43 , 2 , flags [ s . color . getNum ( ) ] ) ;
2009-08-17 11:50:31 +03:00
flag - > hoverable = true ;
}
else
flag = NULL ;
2012-12-10 17:28:27 +03:00
town = new SelectedBox ( Point ( 119 , 2 ) , s , TOWN ) ;
hero = new SelectedBox ( Point ( 195 , 2 ) , s , HERO ) ;
bonus = new SelectedBox ( Point ( 271 , 2 ) , s , BONUS ) ;
2008-11-16 03:06:15 +02:00
}
2011-12-22 16:05:19 +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 ) ;
2012-11-11 15:23:31 +03:00
printAtMiddleLoc ( s . name , 55 , 10 , FONT_SMALL , Colors : : WHITE , to ) ;
2012-12-19 20:24:53 +03:00
printAtMiddleWBLoc ( CGI - > generaltexth - > arraytxt [ 206 + whoCanPlay ] , 28 , 39 , FONT_TINY , 50 , Colors : : WHITE , to ) ;
2008-11-16 03:06:15 +02:00
}
2012-12-10 17:28:27 +03:00
void OptionsTab : : PlayerOptionsEntry : : update ( )
{
town - > update ( ) ;
hero - > update ( ) ;
bonus - > update ( ) ;
}
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
{
2012-06-02 18:16:54 +03:00
btns [ 0 ] - > enable ( ) ;
btns [ 1 ] - > enable ( ) ;
2010-10-24 14:35:14 +03:00
}
2012-12-02 15:21:44 +03:00
if ( ( pi . defaultHero ( ) ! = - 1 | | ! s . playerID | | s . castle < 0 ) //fixed hero
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 [ 2 ] - > disable ( ) ;
btns [ 3 ] - > disable ( ) ;
}
else
{
2012-06-02 18:16:54 +03:00
btns [ 2 ] - > enable ( ) ;
btns [ 3 ] - > enable ( ) ;
2009-08-18 11:22:56 +03:00
}
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
{
2012-06-02 18:16:54 +03:00
btns [ 4 ] - > enable ( ) ;
btns [ 5 ] - > enable ( ) ;
2010-10-24 14:35:14 +03:00
}
2009-08-18 11:22:56 +03:00
}
2012-12-10 17:28:27 +03:00
size_t OptionsTab : : CPlayerSettingsHelper : : getImageIndex ( )
2012-10-05 16:11:26 +03:00
{
enum EBonusSelection //frames of bonuses file
{
WOOD_ORE = 0 , CRYSTAL = 1 , GEM = 2 ,
MERCURY = 3 , SULFUR = 5 , GOLD = 8 ,
ARTIFACT = 9 , RANDOM = 10 ,
2012-12-10 17:28:27 +03:00
WOOD = 0 , ORE = 0 , MITHRIL = 10 , // resources unavailable in bonuses file
TOWN_RANDOM = 38 , TOWN_NONE = 39 , // Special frames in ITPA
HERO_RANDOM = 200 , HERO_NONE = 201 // Special frames in PortraitsSmall
2012-10-05 16:11:26 +03:00
} ;
2012-12-10 17:28:27 +03:00
switch ( type )
2012-10-05 16:11:26 +03:00
{
2012-12-10 17:28:27 +03:00
case TOWN :
switch ( settings . castle )
2012-10-05 16:11:26 +03:00
{
2012-12-10 17:28:27 +03:00
case PlayerSettings : : NONE : return TOWN_NONE ;
case PlayerSettings : : RANDOM : return TOWN_RANDOM ;
default : return CGI - > townh - > towns [ settings . castle ] . clientInfo . icons [ true ] [ false ] + 2 ;
2012-10-05 16:11:26 +03:00
}
2009-08-22 16:59:15 +03:00
case HERO :
2012-12-10 17:28:27 +03:00
switch ( settings . hero )
2009-08-17 11:50:31 +03:00
{
2012-12-10 17:28:27 +03:00
case PlayerSettings : : NONE : return HERO_NONE ;
case PlayerSettings : : RANDOM : return HERO_RANDOM ;
default :
{
if ( settings . heroPortrait > = 0 )
return settings . heroPortrait ;
2012-12-16 16:47:53 +03:00
return CGI - > heroh - > heroes [ settings . hero ] - > imageIndex ;
2012-12-10 17:28:27 +03:00
}
2009-08-17 11:50:31 +03:00
}
2012-12-10 17:28:27 +03:00
case BONUS :
2009-08-17 11:50:31 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( settings . bonus )
{
case PlayerSettings : : RANDOM : return RANDOM ;
case PlayerSettings : : ARTIFACT : return ARTIFACT ;
case PlayerSettings : : GOLD : return GOLD ;
case PlayerSettings : : RESOURCE :
{
switch ( CGI - > townh - > towns [ settings . castle ] . primaryRes )
{
case 127 : return WOOD_ORE ;
case Res : : WOOD : return WOOD ;
case Res : : MERCURY : return MERCURY ;
case Res : : ORE : return ORE ;
case Res : : SULFUR : return SULFUR ;
case Res : : CRYSTAL : return CRYSTAL ;
case Res : : GEMS : return GEM ;
case Res : : GOLD : return GOLD ;
case Res : : MITHRIL : return MITHRIL ;
}
}
}
2009-08-22 16:59:15 +03:00
}
2012-12-10 17:28:27 +03:00
}
return 0 ;
}
std : : string OptionsTab : : CPlayerSettingsHelper : : getImageName ( )
{
switch ( type )
{
case OptionsTab : : TOWN : return " ITPA " ;
case OptionsTab : : HERO : return " PortraitsSmall " ;
case OptionsTab : : BONUS : return " SCNRSTAR " ;
}
return " " ;
}
std : : string OptionsTab : : CPlayerSettingsHelper : : getTitle ( )
{
switch ( type )
{
case OptionsTab : : TOWN : return ( settings . castle < 0 ) ? CGI - > generaltexth - > allTexts [ 103 ] : CGI - > generaltexth - > allTexts [ 80 ] ;
case OptionsTab : : HERO : return ( settings . hero < 0 ) ? CGI - > generaltexth - > allTexts [ 101 ] : CGI - > generaltexth - > allTexts [ 77 ] ;
case OptionsTab : : BONUS :
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( settings . bonus )
{
case PlayerSettings : : RANDOM : return CGI - > generaltexth - > allTexts [ 86 ] ; //{Random Bonus}
case PlayerSettings : : ARTIFACT : return CGI - > generaltexth - > allTexts [ 83 ] ; //{Artifact Bonus}
case PlayerSettings : : GOLD : return CGI - > generaltexth - > allTexts [ 84 ] ; //{Gold Bonus}
case PlayerSettings : : RESOURCE : return CGI - > generaltexth - > allTexts [ 85 ] ; //{Resource Bonus}
}
2009-08-17 11:50:31 +03:00
}
}
2012-12-10 17:28:27 +03:00
return " " ;
2009-08-22 16:59:15 +03:00
}
2009-08-18 11:22:56 +03:00
2012-12-10 17:28:27 +03:00
std : : string OptionsTab : : CPlayerSettingsHelper : : getName ( )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( type )
2009-08-22 16:59:15 +03:00
{
case TOWN :
{
2012-12-10 17:28:27 +03:00
switch ( settings . castle )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
case PlayerSettings : : NONE : return CGI - > generaltexth - > allTexts [ 523 ] ;
case PlayerSettings : : RANDOM : return CGI - > generaltexth - > allTexts [ 522 ] ;
default : return CGI - > townh - > factions [ settings . castle ] . name ;
2009-08-22 16:59:15 +03:00
}
}
2012-12-10 17:28:27 +03:00
case HERO :
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( settings . hero )
{
case PlayerSettings : : NONE : return CGI - > generaltexth - > allTexts [ 523 ] ;
case PlayerSettings : : RANDOM : return CGI - > generaltexth - > allTexts [ 522 ] ;
default :
{
if ( ! settings . heroName . empty ( ) )
return settings . heroName ;
return CGI - > heroh - > heroes [ settings . hero ] - > name ;
}
}
2009-08-22 16:59:15 +03:00
}
case BONUS :
{
2012-12-10 17:28:27 +03:00
switch ( settings . bonus )
{
case PlayerSettings : : RANDOM : return CGI - > generaltexth - > allTexts [ 522 ] ;
default : return CGI - > generaltexth - > arraytxt [ 214 + settings . bonus ] ;
}
2009-08-22 16:59:15 +03:00
}
}
2012-12-10 17:28:27 +03:00
return " " ;
2008-11-16 03:06:15 +02:00
}
2012-12-10 17:28:27 +03:00
std : : string OptionsTab : : CPlayerSettingsHelper : : getSubtitle ( )
2008-11-16 03:06:15 +02:00
{
2012-12-10 17:28:27 +03:00
switch ( type )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
case TOWN : return getName ( ) ;
2011-11-27 16:14:20 +03:00
case HERO :
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
if ( settings . hero > = 0 )
return getName ( ) + " - " + CGI - > heroh - > heroes [ settings . hero ] - > heroClass - > name ;
return getName ( ) ;
2009-08-22 16:59:15 +03:00
}
2012-12-10 17:28:27 +03:00
2011-11-27 16:14:20 +03:00
case BONUS :
2012-12-10 17:28:27 +03:00
{
switch ( settings . bonus )
{
case PlayerSettings : : GOLD : return CGI - > generaltexth - > allTexts [ 87 ] ; //500-1000
case PlayerSettings : : RESOURCE :
{
switch ( CGI - > townh - > towns [ settings . castle ] . primaryRes )
{
case Res : : MERCURY : return CGI - > generaltexth - > allTexts [ 694 ] ;
case Res : : SULFUR : return CGI - > generaltexth - > allTexts [ 695 ] ;
case Res : : CRYSTAL : return CGI - > generaltexth - > allTexts [ 692 ] ;
case Res : : GEMS : return CGI - > generaltexth - > allTexts [ 693 ] ;
case 127 : return CGI - > generaltexth - > allTexts [ 89 ] ; //At the start of the game, 5-10 wood and 5-10 ore are added to your Kingdom's resource pool
}
}
}
}
2009-08-22 16:59:15 +03:00
}
2012-12-10 17:28:27 +03:00
return " " ;
}
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
std : : string OptionsTab : : CPlayerSettingsHelper : : getDescription ( )
{
switch ( type )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
case TOWN : return CGI - > generaltexth - > allTexts [ 104 ] ;
case HERO : return CGI - > generaltexth - > allTexts [ 102 ] ;
case BONUS :
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( settings . bonus )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
case PlayerSettings : : RANDOM : return CGI - > generaltexth - > allTexts [ 94 ] ; //Gold, wood and ore, or an artifact is randomly chosen as your starting bonus
case PlayerSettings : : ARTIFACT : return CGI - > generaltexth - > allTexts [ 90 ] ; //An artifact is randomly chosen and equipped to your starting hero
case PlayerSettings : : GOLD : return CGI - > generaltexth - > allTexts [ 92 ] ; //At the start of the game, 500-1000 gold is added to your Kingdom's resource pool
case PlayerSettings : : RESOURCE :
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
switch ( CGI - > townh - > towns [ settings . castle ] . primaryRes )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
case Res : : MERCURY : return CGI - > generaltexth - > allTexts [ 690 ] ;
case Res : : SULFUR : return CGI - > generaltexth - > allTexts [ 691 ] ;
case Res : : CRYSTAL : return CGI - > generaltexth - > allTexts [ 688 ] ;
case Res : : GEMS : return CGI - > generaltexth - > allTexts [ 689 ] ;
case 127 : return 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
2009-08-22 16:59:15 +03:00
}
}
}
}
}
2012-12-10 17:28:27 +03:00
return " " ;
}
OptionsTab : : CPregameTooltipBox : : CPregameTooltipBox ( CPlayerSettingsHelper & helper ) :
CWindowObject ( BORDERED | RCLICK_POPUP ) ,
CPlayerSettingsHelper ( helper )
{
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2012-12-14 18:32:53 +03:00
int value = PlayerSettings : : NONE ;
2012-12-10 17:28:27 +03:00
switch ( CPlayerSettingsHelper : : type )
2009-08-22 16:59:15 +03:00
{
2012-12-10 17:28:27 +03:00
break ; case TOWN :
value = settings . castle ;
break ; case HERO :
value = settings . hero ;
break ; case BONUS :
value = settings . bonus ;
2009-08-22 16:59:15 +03:00
}
2012-12-10 17:28:27 +03:00
if ( value = = PlayerSettings : : RANDOM )
genBonusWindow ( ) ;
else if ( CPlayerSettingsHelper : : type = = BONUS )
genBonusWindow ( ) ;
else if ( CPlayerSettingsHelper : : type = = HERO )
genHeroWindow ( ) ;
else if ( CPlayerSettingsHelper : : type = = TOWN )
genTownWindow ( ) ;
2011-11-27 16:14:20 +03:00
2012-12-10 17:28:27 +03:00
center ( ) ;
}
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
void OptionsTab : : CPregameTooltipBox : : genHeader ( )
{
new CFilledTexture ( " DIBOXBCK " , pos ) ;
updateShadow ( ) ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
new CLabel ( pos . w / 2 + 8 , 21 , FONT_MEDIUM , CENTER , Colors : : YELLOW , getTitle ( ) ) ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
new CLabel ( pos . w / 2 , 88 , FONT_SMALL , CENTER , Colors : : WHITE , getSubtitle ( ) ) ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
new CAnimImage ( getImageName ( ) , getImageIndex ( ) , 0 , pos . w / 2 - 24 , 45 ) ;
}
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
void OptionsTab : : CPregameTooltipBox : : genTownWindow ( )
{
pos = Rect ( 0 , 0 , 228 , 290 ) ;
genHeader ( ) ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
new CLabel ( pos . w / 2 + 8 , 122 , FONT_MEDIUM , CENTER , Colors : : YELLOW , CGI - > generaltexth - > allTexts [ 79 ] ) ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
std : : vector < CComponent * > components ;
const CTown & town = CGI - > townh - > towns [ settings . castle ] ;
2009-08-22 16:59:15 +03:00
2012-12-10 17:28:27 +03:00
for ( size_t i = 0 ; i < town . creatures . size ( ) ; i + + )
components . push_back ( new CComponent ( CComponent : : creature , town . creatures [ i ] . front ( ) , 0 , CComponent : : tiny ) ) ;
2009-08-22 16:59:15 +03:00
2012-12-20 16:57:29 +03:00
new CComponentBox ( components , Rect ( 10 , 140 , pos . w - 20 , 140 ) ) ;
2012-12-10 17:28:27 +03:00
}
void OptionsTab : : CPregameTooltipBox : : genHeroWindow ( )
{
pos = Rect ( 0 , 0 , 292 , 226 ) ;
genHeader ( ) ;
2013-01-17 21:15:00 +03:00
// specialty
2012-12-16 16:47:53 +03:00
new CAnimImage ( " UN44 " , CGI - > heroh - > heroes [ settings . hero ] - > imageIndex , 0 , pos . w / 2 - 22 , 134 ) ;
2012-12-10 17:28:27 +03:00
new CLabel ( pos . w / 2 + 4 , 117 , FONT_MEDIUM , CENTER , Colors : : YELLOW , CGI - > generaltexth - > allTexts [ 78 ] ) ;
2012-12-16 16:47:53 +03:00
new CLabel ( pos . w / 2 , 188 , FONT_SMALL , CENTER , Colors : : WHITE , CGI - > heroh - > heroes [ settings . hero ] - > specName ) ;
2012-12-10 17:28:27 +03:00
}
void OptionsTab : : CPregameTooltipBox : : genBonusWindow ( )
{
pos = Rect ( 0 , 0 , 228 , 162 ) ;
genHeader ( ) ;
2012-12-20 16:57:29 +03:00
new CTextBox ( getDescription ( ) , Rect ( 10 , 100 , pos . w - 20 , 70 ) , 0 , FONT_SMALL , CENTER , Colors : : WHITE ) ;
2012-12-10 17:28:27 +03:00
}
OptionsTab : : SelectedBox : : SelectedBox ( Point position , PlayerSettings & settings , SelType type )
: CIntObject ( RCLICK , position ) ,
CPlayerSettingsHelper ( settings , type )
{
OBJ_CONSTRUCTION_CAPTURING_ALL ;
image = new CAnimImage ( getImageName ( ) , getImageIndex ( ) ) ;
subtitle = new CLabel ( 23 , 39 , FONT_TINY , CENTER , Colors : : WHITE , getName ( ) ) ;
pos = image - > pos ;
}
void OptionsTab : : SelectedBox : : update ( )
{
image - > setFrame ( getImageIndex ( ) ) ;
subtitle - > setTxt ( getName ( ) ) ;
}
void OptionsTab : : SelectedBox : : clickRight ( tribool down , bool previousState )
{
if ( down )
{
// cases when we do not need to display a message
if ( settings . castle = = - 2 & & CPlayerSettingsHelper : : type = = TOWN )
return ;
2013-03-03 20:06:03 +03:00
if ( settings . hero = = - 2 & & SEL - > current - > mapHeader - > players [ settings . color . getNum ( ) ] . customHeroID = = - 1 & & CPlayerSettingsHelper : : type = = HERO )
2012-12-10 17:28:27 +03:00
return ;
GH . pushInt ( new CPregameTooltipBox ( * this ) ) ;
}
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 ;
2012-09-24 19:14:53 +03:00
for ( auto it = startInfo - > playerInfos . cbegin ( ) ; it ! = startInfo - > playerInfos . cend ( ) ; + + it )
2009-10-06 04:14:00 +03:00
{
2012-12-02 15:21:44 +03:00
if ( it - > second . playerID )
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 ( ) ;
2012-02-22 22:22:11 +03:00
card - > changeSelection ( current ) ;
2009-08-27 11:04:32 +03:00
card - > difficulty - > select ( startInfo - > difficulty , 0 ) ;
2011-12-22 16:05:19 +03:00
back = new CAdventureMapButton ( " " , CGI - > generaltexth - > zelp [ 105 ] . second , bind ( & CGuiHandler : : popIntTotally , & GH , this ) , 584 , 535 , " SCNRBACK.DEF " , SDLK_ESCAPE ) ;
2009-08-27 11:04:32 +03:00
}
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
{
2012-11-11 15:23:31 +03:00
const CMapHeader * a = aaa - > mapHeader . get ( ) ,
* b = bbb - > mapHeader . get ( ) ;
2010-02-13 18:26:47 +02:00
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
2012-02-29 04:31:48 +03:00
return boost : : ilexicographical_compare ( a - > name , b - > name ) ;
2010-02-13 18:26:47 +02:00
default :
2012-02-29 04:31:48 +03:00
return boost : : ilexicographical_compare ( a - > name , b - > name ) ;
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
2011-11-27 16:14:20 +03:00
return CGI - > generaltexth - > campaignRegionNames [ aaa - > campaignHeader - > mapVersion ] . size ( ) <
2010-02-15 15:28:33 +02:00
CGI - > generaltexth - > campaignRegionNames [ bbb - > campaignHeader - > mapVersion ] . size ( ) ;
break ;
case _name : //by name
2012-02-29 04:31:48 +03:00
return boost : : ilexicographical_compare ( aaa - > campaignHeader - > name , bbb - > campaignHeader - > name ) ;
2010-02-15 15:28:33 +02:00
default :
2012-02-29 04:31:48 +03:00
return boost : : ilexicographical_compare ( aaa - > campaignHeader - > name , bbb - > campaignHeader - > name ) ;
2010-02-15 15:28:33 +02:00
}
2010-02-08 16:38:06 +02:00
}
2010-02-15 08:54:57 +02:00
}
CMultiMode : : CMultiMode ( )
{
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-02-15 08:54:57 +02:00
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
2011-12-22 16:05:19 +03:00
bar = new CGStatusBar ( new CPicture ( Rect ( 7 , 465 , 440 , 18 ) , 0 ) ) ; //226, 472
txt = new CTextInput ( Rect ( 19 , 436 , 334 , 16 ) , * bg ) ;
2012-06-13 16:04:06 +03:00
txt - > setTxt ( settings [ " general " ] [ " playerName " ] . String ( ) ) ; //Player
2010-02-15 08:54:57 +02:00
2011-12-22 16:05:19 +03:00
btns [ 0 ] = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 266 ] , bind ( & CMultiMode : : openHotseat , this ) , 373 , 78 , " MUBHOT.DEF " ) ;
btns [ 1 ] = new CAdventureMapButton ( " Host TCP/IP game " , " " , bind ( & CMultiMode : : hostTCP , this ) , 373 , 78 + 57 * 1 , " MUBHOST.DEF " ) ;
btns [ 2 ] = new CAdventureMapButton ( " Join TCP/IP game " , " " , bind ( & CMultiMode : : joinTCP , this ) , 373 , 78 + 57 * 2 , " MUBJOIN.DEF " ) ;
btns [ 6 ] = new CAdventureMapButton ( 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 ( )
{
2012-01-12 18:23:00 +03:00
Settings name = settings . write [ " general " ] [ " playerName " ] ;
name - > String ( ) = 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 ( )
{
2012-01-12 18:23:00 +03:00
Settings name = settings . write [ " general " ] [ " playerName " ] ;
name - > String ( ) = txt - > text ;
2010-10-24 14:35:14 +03:00
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 )
{
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-02-15 08:54:57 +02:00
bg = new CPicture ( " MUHOTSEA.bmp " ) ;
pos = bg - > center ( ) ; //center, window has size of bg graphic
2011-11-27 21:55:11 +03:00
std : : string text = CGI - > generaltexth - > allTexts [ 446 ] ;
boost : : replace_all ( text , " \t " , " \n " ) ;
2011-12-22 16:05:19 +03:00
Rect boxRect ( 25 , 20 , 315 , 50 ) ;
2012-11-11 15:23:31 +03:00
title = new CTextBox ( text , boxRect , 0 , FONT_BIG , CENTER , Colors : : WHITE ) ; //HOTSEAT Please enter names
2011-11-27 21:55:11 +03:00
2010-02-15 08:54:57 +02:00
for ( int i = 0 ; i < ARRAY_COUNT ( txt ) ; i + + )
2011-11-27 21:55:11 +03:00
{
2011-12-22 16:05:19 +03:00
txt [ i ] = new CTextInput ( Rect ( 60 , 85 + i * 30 , 280 , 16 ) , * bg ) ;
2011-11-27 21:55:11 +03:00
txt [ i ] - > cb + = boost : : bind ( & CHotSeatPlayers : : onChange , this , _1 ) ;
}
2010-02-15 13:37:47 +02:00
2011-12-22 16:05:19 +03:00
ok = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 560 ] , bind ( & CHotSeatPlayers : : enterSelectionScreen , this ) , 95 , 338 , " MUBCHCK.DEF " , SDLK_RETURN ) ;
cancel = new CAdventureMapButton ( CGI - > generaltexth - > zelp [ 561 ] , bind ( & CGuiHandler : : popIntTotally , ref ( GH ) , this ) , 205 , 338 , " MUBCANC.DEF " , SDLK_ESCAPE ) ;
bar = new CGStatusBar ( new CPicture ( Rect ( 7 , 381 , 348 , 18 ) , 0 ) ) ; //226, 472
2011-11-27 21:55:11 +03:00
2012-06-13 16:04:06 +03:00
txt [ 0 ] - > setTxt ( firstPlayer , true ) ;
2011-11-27 21:55:11 +03:00
txt [ 0 ] - > giveFocus ( ) ;
}
void CHotSeatPlayers : : onChange ( std : : string newText )
{
size_t namesCount = 0 ;
for ( int i = 0 ; i < ARRAY_COUNT ( txt ) ; i + + )
if ( ! txt [ i ] - > text . empty ( ) )
namesCount + + ;
ok - > block ( namesCount < 2 ) ;
2010-02-15 13:37:47 +02:00
}
void CHotSeatPlayers : : enterSelectionScreen ( )
{
2013-03-03 20:06:03 +03:00
std : : map < ui8 , std : : string > names ;
2010-10-24 14:35:14 +03:00
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 ;
2012-01-12 18:23:00 +03:00
Settings name = settings . write [ " general " ] [ " playerName " ] ;
name - > String ( ) = names . begin ( ) - > second ;
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
}
2012-09-21 20:59:54 +03:00
void CBonusSelection : : init ( )
2010-02-15 14:12:21 +02:00
{
2012-09-21 20:59:54 +03:00
highlightedRegion = nullptr ;
ourHeader = nullptr ;
diffLb = nullptr ;
diffRb = nullptr ;
bonuses = nullptr ;
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 " } ;
2011-11-27 16:14:20 +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 ] ) ;
2012-05-18 20:35:46 +03:00
pos . h = background - > h ;
pos . w = background - > w ;
center ( ) ;
2010-02-15 14:12:21 +02:00
SDL_Surface * panel = BitmapHandler : : loadBitmap ( " CAMPBRF.BMP " ) ;
blitAt ( panel , 456 , 6 , background ) ;
2011-12-22 16:05:19 +03:00
startB = new CAdventureMapButton ( " " , " " , bind ( & CBonusSelection : : startMap , this ) , 475 , 536 , " CBBEGIB.DEF " , SDLK_RETURN ) ;
backB = new CAdventureMapButton ( " " , " " , bind ( & CBonusSelection : : goBack , this ) , 624 , 536 , " CBCANCB.DEF " , SDLK_ESCAPE ) ;
2010-02-15 14:12:21 +02:00
//campaign name
2010-08-04 14:18:13 +03:00
if ( ourCampaign - > camp - > header . name . length ( ) )
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_BIG ] - > renderTextLeft ( background , ourCampaign - > camp - > header . name , Colors : : YELLOW , Point ( 481 , 28 ) ) ;
2011-11-27 16:14:20 +03:00
else
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_BIG ] - > renderTextLeft ( background , CGI - > generaltexth - > allTexts [ 508 ] , Colors : : YELLOW , Point ( 481 , 28 ) ) ;
2010-02-15 14:12:21 +02:00
//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
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_SMALL ] - > renderTextLeft ( background , CGI - > generaltexth - > allTexts [ 38 ] , Colors : : YELLOW , Point ( 481 , 63 ) ) ;
2011-11-27 16:14:20 +03:00
2011-12-22 16:05:19 +03:00
cmpgDesc = new CTextBox ( ourCampaign - > camp - > header . description , Rect ( 480 , 86 , 286 , 117 ) , 1 ) ;
2012-05-18 20:35:46 +03:00
//cmpgDesc->showAll(background);
2010-07-29 20:00:34 +03:00
//map description
2011-12-22 16:05:19 +03:00
mapDesc = new CTextBox ( " " , Rect ( 480 , 280 , 286 , 117 ) , 1 ) ;
2010-07-29 20:00:34 +03:00
//bonus choosing
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_MEDIUM ] - > renderTextLeft ( background , CGI - > generaltexth - > allTexts [ 71 ] , Colors : : WHITE , Point ( 511 , 432 ) ) ;
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 ( ) ;
2013-02-05 22:33:09 +03:00
selectMap ( g , true ) ;
2010-02-18 14:34:44 +02:00
}
}
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
2012-09-24 22:23:11 +03:00
//unlock if no bonuses -- it's acceptable
2012-11-03 22:31:16 +03:00
2012-09-24 22:23:11 +03:00
2012-09-21 20:59:54 +03:00
// //init campaign state if necessary
// if (ourCampaign->campaignName.size() == 0)
// {
// ourCampaign->initNewCampaign(sInfo);
// }
2010-08-04 14:18:13 +03:00
2010-02-15 14:12:21 +02:00
//allies / enemies
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_SMALL ] - > renderTextLeft ( background , CGI - > generaltexth - > allTexts [ 390 ] + " : " , Colors : : WHITE , Point ( 486 , 407 ) ) ;
graphics - > fonts [ FONT_SMALL ] - > renderTextLeft ( background , CGI - > generaltexth - > allTexts [ 391 ] + " : " , Colors : : WHITE , Point ( 619 , 407 ) ) ;
2010-02-15 14:12:21 +02:00
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 ( " " ) ) ;
2012-12-19 20:24:53 +03:00
graphics - > fonts [ FONT_MEDIUM ] - > renderTextLeft ( background , difficulty . back ( ) , Colors : : WHITE , Point ( 689 , 432 ) ) ;
2011-11-27 16:14:20 +03:00
2011-04-26 16:30:29 +03:00
//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-11-27 16:14:20 +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
{
2011-12-22 16:05:19 +03:00
diffLb = new CAdventureMapButton ( " " , " " , bind ( & CBonusSelection : : changeDiff , this , false ) , 694 , 508 , " SCNRBLF.DEF " ) ;
diffRb = new CAdventureMapButton ( " " , " " , bind ( & CBonusSelection : : changeDiff , this , true ) , 738 , 508 , " SCNRBRT.DEF " ) ;
2010-08-01 17:40:34 +03:00
}
2010-07-31 16:55:05 +03:00
//load miniflags
sFlags = CDefHandler : : giveDef ( " ITGFLAGS.DEF " ) ;
2012-09-21 20:59:54 +03:00
}
2011-11-27 16:14:20 +03:00
2012-09-21 20:59:54 +03:00
CBonusSelection : : CBonusSelection ( shared_ptr < CCampaignState > _ourCampaign )
: ourCampaign ( std : : move ( _ourCampaign ) )
{
init ( ) ;
}
CBonusSelection : : CBonusSelection ( std : : string campaignFName )
{
2012-09-22 18:16:45 +03:00
ourCampaign = make_shared < CCampaignState > ( CCampaignHandler : : getCampaign ( campaignFName ) ) ;
2012-09-21 20:59:54 +03:00
sInfo . campState = ourCampaign ;
init ( ) ;
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 ) ;
}
2011-12-22 16:05:19 +03:00
void CBonusSelection : : showAll ( SDL_Surface * to )
2010-02-15 14:12:21 +02:00
{
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 ) ;
2012-05-18 20:35:46 +03:00
if ( pos . h ! = to - > h | | pos . w ! = to - > w )
2013-03-03 20:06:03 +03:00
CMessage : : drawBorder ( PlayerColor ( 1 ) , to , pos . w + 28 , pos . h + 30 , pos . x - 14 , pos . y - 15 ) ;
2010-02-15 15:28:33 +02:00
}
2010-02-16 19:28:56 +02:00
void CBonusSelection : : loadPositionsOfGraphics ( )
{
2012-08-02 14:03:26 +03:00
const JsonNode config ( ResourceID ( " config/campaign_regions.json " ) ) ;
2011-09-03 22:51:45 +03:00
int idx = 0 ;
2010-02-16 19:28:56 +02:00
2011-09-03 22:51:45 +03:00
BOOST_FOREACH ( const JsonNode & campaign , config [ " campaign_regions " ] . Vector ( ) )
2010-02-16 19:28:56 +02:00
{
SCampPositions sc ;
2011-09-03 22:51:45 +03:00
sc . campPrefix = campaign [ " prefix " ] . String ( ) ;
sc . colorSuffixLength = campaign [ " color_suffix_length " ] . Float ( ) ;
BOOST_FOREACH ( const JsonNode & desc , campaign [ " desc " ] . Vector ( ) )
2010-02-16 19:28:56 +02:00
{
SCampPositions : : SRegionDesc rd ;
2011-09-03 22:51:45 +03:00
rd . infix = desc [ " infix " ] . String ( ) ;
rd . xpos = desc [ " x " ] . Float ( ) ;
rd . ypos = desc [ " y " ] . Float ( ) ;
sc . regions . push_back ( rd ) ;
2010-02-16 19:28:56 +02:00
}
campDescriptions . push_back ( sc ) ;
2011-09-03 22:51:45 +03:00
idx + + ;
2010-02-16 19:28:56 +02:00
}
2011-09-03 22:51:45 +03:00
assert ( idx = = CGI - > generaltexth - > campaignMapNames . size ( ) ) ;
2010-02-16 19:28:56 +02:00
}
2013-02-05 22:33:09 +03:00
void CBonusSelection : : selectMap ( int whichOne , bool initialSelect )
2010-02-18 14:34:44 +02:00
{
2013-02-05 22:33:09 +03:00
if ( initialSelect | | ourCampaign - > currentMap ! = whichOne )
{
sInfo . difficulty = ourCampaign - > camp - > scenarios [ whichOne ] . difficulty ;
sInfo . mapname = ourCampaign - > camp - > header . filename ;
sInfo . mode = StartInfo : : CAMPAIGN ;
sInfo . campState = ourCampaign ;
ourCampaign - > currentMap = whichOne ;
2010-02-18 14:34:44 +02:00
2013-02-05 22:33:09 +03:00
//get header
delete ourHeader ;
std : : string & headerStr = ourCampaign - > camp - > mapPieces . find ( whichOne ) - > second ;
auto buffer = reinterpret_cast < const ui8 * > ( headerStr . data ( ) ) ;
ourHeader = CMapService : : loadMapHeader ( buffer , headerStr . size ( ) ) . release ( ) ;
2011-11-27 16:14:20 +03:00
2013-03-03 20:06:03 +03:00
std : : map < ui8 , std : : string > names ;
2013-02-05 22:33:09 +03:00
names [ 1 ] = settings [ " general " ] [ " playerName " ] . String ( ) ;
updateStartInfo ( ourCampaign - > camp - > header . filename , sInfo , ourHeader , names ) ;
sInfo . turnTime = 0 ;
sInfo . difficulty = ourCampaign - > camp - > scenarios [ whichOne ] . difficulty ;
2010-08-04 14:18:13 +03:00
2013-02-05 22:33:09 +03:00
mapDesc - > setTxt ( ourHeader - > description ) ;
2010-07-29 20:00:34 +03:00
2013-02-05 22:33:09 +03:00
updateBonusSelection ( ) ;
}
2010-02-18 14:34:44 +02:00
}
2011-12-22 16:05:19 +03:00
void CBonusSelection : : show ( SDL_Surface * to )
2010-02-18 14:34:44 +02:00
{
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 ( ) )
2012-11-11 15:23:31 +03:00
printAtLoc ( mapName , 481 , 219 , FONT_BIG , Colors : : YELLOW , to ) ;
2011-11-27 16:14:20 +03:00
else
2012-11-11 15:23:31 +03:00
printAtLoc ( " Unnamed " , 481 , 219 , FONT_BIG , Colors : : YELLOW , to ) ;
2010-02-18 14:34:44 +02:00
//map description
2012-11-11 15:23:31 +03:00
printAtLoc ( CGI - > generaltexth - > allTexts [ 496 ] , 481 , 253 , FONT_SMALL , Colors : : YELLOW , to ) ;
2010-02-18 14:34:44 +02:00
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
2012-12-19 20:24:53 +03:00
int fx = 496 + graphics - > fonts [ FONT_SMALL ] - > getStringWidth ( CGI - > generaltexth - > allTexts [ 390 ] ) ;
int ex = 629 + graphics - > fonts [ FONT_SMALL ] - > getStringWidth ( CGI - > generaltexth - > allTexts [ 391 ] ) ;
2013-03-03 20:06:03 +03:00
TeamID myT ;
myT = ourHeader - > players [ playerColor . getNum ( ) ] . team ;
2012-09-24 19:14:53 +03:00
for ( auto i = sInfo . playerInfos . cbegin ( ) ; i ! = sInfo . playerInfos . cend ( ) ; i + + )
2010-07-31 16:55:05 +03:00
{
2013-03-03 20:06:03 +03:00
int * myx = ( ( i - > first = = playerColor | | ourHeader - > players [ i - > first . getNum ( ) ] . team = = myT ) ? & fx : & ex ) ;
blitAtLoc ( sFlags - > ourImages [ i - > first . getNum ( ) ] . bitmap , pos . x + * myx , pos . y + 405 , to ) ;
* myx + = sFlags - > ourImages [ i - > first . getNum ( ) ] . bitmap - > w ;
2010-07-31 16:55:05 +03:00
}
2010-08-01 17:40:34 +03:00
//difficulty
2012-05-18 20:35:46 +03:00
blitAtLoc ( diffPics [ sInfo . difficulty ] , 709 , 455 , to ) ;
2010-08-01 17:40:34 +03:00
2010-02-18 14:34:44 +02:00
CIntObject : : show ( to ) ;
}
2010-02-23 17:39:31 +02:00
void CBonusSelection : : updateBonusSelection ( )
{
2012-05-18 20:35:46 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2010-02-23 17:39:31 +02:00
//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)
2012-09-21 20:59:54 +03:00
const CCampaignScenario & scenario = ourCampaign - > camp - > scenarios [ sInfo . campState - > currentMap ] ;
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
2012-09-26 21:10:29 +03:00
updateStartButtonState ( - 1 ) ;
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 ( ) ;
2012-06-02 18:16:54 +03:00
delete bonuses - > buttons [ i ] ;
2011-03-20 00:27:05 +02:00
}
bonuses - > buttons . clear ( ) ;
2011-02-20 11:24:53 +02:00
static const char * bonusPics [ ] = { " SPELLBON.DEF " , " TWCRPORT.DEF " , " " , " ARTIFBON.DEF " , " SPELLBON.DEF " ,
2013-02-09 22:19:14 +03:00
" PSKILBON.DEF " , " SSKILBON.DEF " , " BORES.DEF " , " PORTRAITSLARGE " , " 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 )
{
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : SPELL :
2010-07-29 20:00:34 +03:00
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 ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : 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 ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : BUILDING :
2010-07-30 17:26:37 +03:00
{
2010-08-02 17:29:30 +03:00
int faction = - 1 ;
2012-09-24 19:14:53 +03:00
for ( auto it = sInfo . playerInfos . begin ( ) ; it ! = sInfo . playerInfos . end ( ) ; + + it )
2010-08-02 17:29:30 +03:00
{
2012-12-02 15:21:44 +03:00
if ( it - > second . playerID )
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
}
2011-11-27 16:14:20 +03:00
2010-08-02 17:29:30 +03:00
}
assert ( faction ! = - 1 ) ;
2010-07-30 17:26:37 +03:00
2013-02-11 22:11:34 +03:00
BuildingID buildID = CBuildingHandler : : campToERMU ( bonDescs [ i ] . info1 , faction , std : : set < BuildingID > ( ) ) ;
2011-03-20 00:27:05 +02:00
picName = graphics - > ERMUtoPicture [ faction ] [ buildID ] ;
2011-02-20 11:24:53 +02:00
picNumber = - 1 ;
2011-03-20 00:27:05 +02:00
2012-09-02 13:33:41 +03:00
if ( vstd : : contains ( CGI - > townh - > towns [ faction ] . buildings , buildID ) )
2013-02-13 17:21:11 +03:00
desc = CGI - > townh - > towns [ faction ] . buildings . find ( buildID ) - > second - > Name ( ) ;
2010-07-30 17:26:37 +03:00
}
2010-07-29 20:00:34 +03:00
break ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : ARTIFACT :
2010-07-29 20:00:34 +03:00
desc = CGI - > generaltexth - > allTexts [ 715 ] ;
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > arth - > artifacts [ bonDescs [ i ] . info2 ] - > Name ( ) ) ;
break ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : SPELL_SCROLL :
2010-07-29 20:00:34 +03:00
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 ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : PRIMARY_SKILL :
2010-07-29 20:00:34 +03:00
{
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 ) ;
2011-12-14 00:23:17 +03:00
for ( int g = 0 ; g < GameConstants : : PRIMARY_SKILLS ; + + g )
2010-07-29 20:00:34 +03:00
{
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 ;
}
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : SECONDARY_SKILL :
2010-07-29 20:00:34 +03:00
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 ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : 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 ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : PLAYER_PREV_SCENARIO :
2013-02-09 22:19:14 +03:00
{
2013-03-03 20:06:03 +03:00
auto superhero = ourCampaign - > camp - > scenarios [ bonDescs [ i ] . info2 ] . strongestHero ( PlayerColor ( bonDescs [ i ] . info1 ) ) ;
2013-02-09 22:19:14 +03:00
if ( ! superhero ) tlog5 < < " No superhero! How could it be transfered? \n " ;
picNumber = superhero ? superhero - > portrait : 0 ;
desc = CGI - > generaltexth - > allTexts [ 719 ] ;
2010-08-28 17:52:20 +03:00
2013-02-09 22:19:14 +03:00
boost : : algorithm : : replace_first ( desc , " %s " , ourCampaign - > camp - > scenarios [ bonDescs [ i ] . info2 ] . scenarioName ) ; //scenario
}
2010-08-28 17:52:20 +03:00
2010-07-29 20:00:34 +03:00
break ;
2012-09-22 20:23:28 +03:00
case CScenarioTravel : : STravelBonus : : HERO :
2012-11-03 22:31:16 +03:00
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 )
{
2012-09-22 20:23:28 +03:00
boost : : algorithm : : replace_first ( desc , " %s " , CGI - > generaltexth - > allTexts [ 101 ] ) ; //hero's name
2012-09-23 14:26:26 +03:00
picNumber = - 1 ;
picName = " CBONN1A3.BMP " ;
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 ) ;
2012-11-20 20:53:45 +03:00
const SDL_Color brightYellow = { 242 , 226 , 110 , 0 } ;
bonusButton - > borderColor = brightYellow ;
2011-04-26 16:30:29 +03:00
bonuses - > addButton ( bonusButton ) ;
2010-02-23 17:39:31 +02:00
}
}
2010-05-08 21:56:38 +03:00
void CBonusSelection : : startMap ( )
{
StartInfo * si = new StartInfo ( sInfo ) ;
2012-11-03 22:31:16 +03:00
2013-02-06 00:19:08 +03:00
/*if (ourCampaign->mapsConquered.size())
2010-08-28 17:52:20 +03:00
{
GH . popInts ( 1 ) ;
2013-02-06 00:19:08 +03:00
} */
2012-12-17 21:01:17 +03:00
const CCampaignScenario & scenario = ourCampaign - > camp - > scenarios [ ourCampaign - > currentMap ] ;
tlog1 < < " Starting scenario " < < int ( ourCampaign - > currentMap ) < < " \n " ;
2013-02-21 00:01:18 +03:00
auto exitCb = [ si ] ( )
{
CGP - > showLoadingScreen ( boost : : bind ( & startGame , si , ( CConnection * ) nullptr ) ) ;
} ;
2012-12-17 21:01:17 +03:00
if ( scenario . prolog . hasPrologEpilog )
2010-08-28 17:52:20 +03:00
{
2013-02-21 00:01:18 +03:00
GH . pushInt ( new CPrologEpilogVideo ( scenario . prolog , exitCb ) ) ;
2012-12-17 21:01:17 +03:00
tlog1 < < " Video: " < < scenario . prolog . prologVideo < < " \n " ;
tlog1 < < " Audio: " < < scenario . prolog . prologMusic < < " \n " ;
tlog1 < < " Text: " < < scenario . prolog . prologText < < " \n " ;
2010-08-28 17:52:20 +03:00
}
2012-12-17 21:01:17 +03:00
else
2013-02-21 00:01:18 +03:00
{
2012-12-17 21:01:17 +03:00
tlog1 < < " Without prolog \n " ;
2013-02-21 00:01:18 +03:00
exitCb ( ) ;
}
2010-05-08 21:56:38 +03:00
}
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.
2013-02-05 21:48:46 +03:00
if ( ! vstd : : contains ( sInfo . campState - > chosenCampaignBonuses , sInfo . campState - > currentMap )
| | id ! = sInfo . campState - > currentBonusID ( ) )
2011-04-26 16:30:29 +03:00
{
2012-09-21 20:59:54 +03:00
sInfo . campState - > chosenCampaignBonuses [ sInfo . campState - > currentMap ] = id ;
2011-04-26 16:30:29 +03:00
GH . totalRedraw ( ) ;
2012-09-26 21:10:29 +03:00
updateStartButtonState ( id ) ;
2011-04-26 16:30:29 +03:00
}
2011-11-27 16:14:20 +03:00
2012-09-21 20:59:54 +03:00
const CCampaignScenario & scenario = ourCampaign - > camp - > scenarios [ sInfo . campState - > currentMap ] ;
2010-09-04 17:49:15 +03:00
const std : : vector < CScenarioTravel : : STravelBonus > & bonDescs = scenario . travelOptions . bonusesToChoose ;
2012-09-23 14:26:26 +03:00
if ( bonDescs [ id ] . type = = CScenarioTravel : : STravelBonus : : HERO )
2010-09-04 17:49:15 +03:00
{
2013-03-03 20:06:03 +03:00
std : : map < ui8 , std : : string > names ;
2012-09-23 14:26:26 +03:00
names [ 1 ] = settings [ " general " ] [ " playerName " ] . String ( ) ;
for ( auto it = sInfo . playerInfos . begin ( ) ; it ! = sInfo . playerInfos . end ( ) ; + + it )
{
2013-03-03 20:06:03 +03:00
if ( it - > first = = PlayerColor ( bonDescs [ id ] . info1 ) )
2012-09-23 14:26:26 +03:00
: : setPlayer ( it - > second , 1 , names ) ;
else
: : setPlayer ( it - > second , 0 , names ) ;
}
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 ) ;
}
}
2012-09-26 21:10:29 +03:00
void CBonusSelection : : updateStartButtonState ( int selected /*= -1*/ )
{
if ( selected = = - 1 )
startB - > setState ( ourCampaign - > getCurrentScenario ( ) . travelOptions . bonusesToChoose . size ( ) ? CButtonBase : : BLOCKED : CButtonBase : : NORMAL ) ;
else if ( startB - > getState ( ) = = CButtonBase : : BLOCKED )
startB - > setState ( CButtonBase : : NORMAL ) ;
}
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 ;
2012-06-02 18:16:54 +03:00
addUsedEvents ( LCLICK | RCLICK ) ;
2010-02-18 14:34:44 +02:00
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 ] ;
2012-05-18 20:35:46 +03:00
pos . x + = desc . xpos ;
pos . y + = desc . ypos ;
2010-02-16 19:28:56 +02:00
//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
{
2013-02-05 22:33:09 +03:00
owner - > selectMap ( myNumber , false ) ;
2010-02-18 14:34:44 +02:00
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
}
2011-12-22 16:05:19 +03:00
void CBonusSelection : : CRegion : : show ( SDL_Surface * to )
2010-02-16 19:28:56 +02:00
{
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
2012-05-18 20:35:46 +03:00
blitAtLoc ( graphics [ 2 ] , 0 , 0 , to ) ;
2010-02-16 19:28:56 +02:00
}
else if ( this = = owner - > highlightedRegion )
{
//show as selected
2012-05-18 20:35:46 +03:00
blitAtLoc ( graphics [ 1 ] , 0 , 0 , to ) ;
2010-02-16 19:28:56 +02:00
}
else
{
//show as not selected selected
2012-05-18 20:35:46 +03:00
blitAtLoc ( graphics [ 0 ] , 0 , 0 , to ) ;
2010-02-16 19:28:56 +02:00
}
}
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
2013-03-03 20:06:03 +03:00
ISelectionScreenInfo : : ISelectionScreenInfo ( const std : : map < ui8 , std : : string > * Names /*= NULL*/ )
2010-10-24 14:35:14 +03:00
{
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
2012-01-12 18:23:00 +03:00
playerNames [ 1 ] = settings [ " general " ] [ " playerName " ] . String ( ) ; //by default we have only one player and his name is "Player" (or whatever the last used name was)
2010-10-24 14:35:14 +03:00
}
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
}
2013-03-03 20:06:03 +03:00
void ISelectionScreenInfo : : setPlayer ( PlayerSettings & pset , ui8 player )
2010-10-24 14:35:14 +03:00
{
2010-10-30 17:53:23 +03:00
: : setPlayer ( pset , player , playerNames ) ;
2010-10-24 14:35:14 +03:00
}
2013-03-03 20:06:03 +03:00
ui8 ISelectionScreenInfo : : getIdOfFirstUnallocatedPlayer ( )
2010-10-24 14:35:14 +03:00
{
2012-09-24 19:14:53 +03:00
for ( auto i = playerNames . cbegin ( ) ; i ! = playerNames . cend ( ) ; i + + )
2010-10-24 14:35:14 +03:00
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
2011-12-14 00:23:17 +03:00
vstd : : clear_pointer ( 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 ;
2011-11-27 16:14:20 +03:00
2010-10-24 14:35:14 +03:00
//put new player in first slot with AI
2012-09-24 19:14:53 +03:00
for ( auto i = SEL - > sInfo . playerInfos . begin ( ) ; i ! = SEL - > sInfo . playerInfos . end ( ) ; i + + )
2010-10-24 14:35:14 +03:00
{
2012-12-02 15:21:44 +03:00
if ( ! i - > second . playerID )
2010-10-24 14:35:14 +03:00
{
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 ;
2012-11-11 15:23:31 +03:00
case OPEN_RANDOM_MAP_OPTIONS :
selScreen - > toggleTab ( selScreen - > randMapTab ) ;
break ;
2010-10-24 14:35:14 +03:00
}
}
void RequestOptionsChange : : apply ( CSelectionScreen * selScreen )
{
if ( ! selScreen - > isHost ( ) )
return ;
2013-03-03 20:06:03 +03:00
PlayerColor color = selScreen - > sInfo . getPlayersSettings ( playerID ) - > color ;
2010-10-24 14:35:14 +03:00
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 ( ) ;
}
2011-11-27 16:14:20 +03:00
2010-10-24 14:35:14 +03:00
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
2011-12-14 00:23:17 +03:00
vstd : : clear_pointer ( selScreen - > serverHandlingThread ) ; //detach us
2012-11-20 20:53:45 +03:00
saveGameName . clear ( ) ;
2010-10-24 14:35:14 +03:00
2012-12-17 21:01:17 +03:00
CGP - > showLoadingScreen ( boost : : bind ( & startGame , startingInfo . sInfo , startingInfo . serv ) ) ;
2010-10-24 14:35:14 +03:00
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
2011-11-27 16:14:20 +03:00
CCampaignScreen : : CCampaignButton : : CCampaignButton ( const JsonNode & config )
2011-03-15 16:35:36 +02:00
{
2011-11-27 16:14:20 +03:00
pos . x + = config [ " x " ] . Float ( ) ;
pos . y + = config [ " y " ] . Float ( ) ;
pos . w = 200 ;
pos . h = 116 ;
2012-11-03 22:31:16 +03:00
2011-11-27 16:14:20 +03:00
campFile = config [ " file " ] . String ( ) ;
video = config [ " video " ] . String ( ) ;
2011-03-21 21:32:48 +02:00
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2011-03-15 16:35:36 +02:00
2011-11-27 16:14:20 +03:00
status = config [ " open " ] . Bool ( ) ? CCampaignScreen : : ENABLED : CCampaignScreen : : DISABLED ;
2011-03-15 16:35:36 +02:00
2012-08-01 15:02:54 +03:00
CCampaignHeader header = CCampaignHandler : : getHeader ( campFile ) ;
2011-11-27 16:14:20 +03:00
hoverText = header . name ;
2011-03-15 16:35:36 +02:00
2011-11-27 16:14:20 +03:00
if ( status ! = CCampaignScreen : : DISABLED )
2011-03-21 21:32:48 +02:00
{
2012-06-02 18:16:54 +03:00
addUsedEvents ( LCLICK | HOVER ) ;
2011-11-27 16:14:20 +03:00
image = new CPicture ( config [ " image " ] . String ( ) ) ;
2011-03-21 21:32:48 +02:00
2012-11-11 15:23:31 +03:00
hoverLabel = new CLabel ( pos . w / 2 , pos . h + 20 , FONT_MEDIUM , CENTER , Colors : : YELLOW , " " ) ;
2012-06-02 18:16:54 +03:00
parent - > addChild ( hoverLabel ) ;
2011-04-26 16:30:29 +03:00
}
2011-11-27 16:14:20 +03:00
if ( status = = CCampaignScreen : : COMPLETED )
checkMark = new CPicture ( " CAMPCHK " ) ;
2011-03-15 16:35:36 +02:00
}
2011-11-27 16:14:20 +03:00
void CCampaignScreen : : CCampaignButton : : clickLeft ( tribool down , bool previousState )
2011-03-15 16:35:36 +02:00
{
2011-11-27 16:14:20 +03:00
if ( down )
2011-03-19 16:27:51 +02:00
{
2011-11-27 16:14:20 +03:00
// Close running video and open the selected campaign
CCS - > videoh - > close ( ) ;
2012-09-21 20:59:54 +03:00
GH . pushInt ( new CBonusSelection ( campFile ) ) ;
2011-03-19 16:27:51 +02:00
}
2011-03-15 16:35:36 +02:00
}
void CCampaignScreen : : CCampaignButton : : hover ( bool on )
2011-11-27 16:14:20 +03:00
{
2011-03-15 16:35:36 +02:00
if ( on )
hoverLabel - > setTxt ( hoverText ) ; // Shows the name of the campaign when you get into the bounds of the button
else
2011-11-27 16:14:20 +03:00
hoverLabel - > setTxt ( " " ) ;
2011-03-15 16:35:36 +02:00
}
2011-12-22 16:05:19 +03:00
void CCampaignScreen : : CCampaignButton : : show ( SDL_Surface * to )
2011-03-15 16:35:36 +02:00
{
2011-11-27 16:14:20 +03:00
if ( status = = CCampaignScreen : : DISABLED )
2011-03-15 16:35:36 +02:00
return ;
2011-11-27 16:14:20 +03:00
CIntObject : : show ( to ) ;
2011-03-15 16:35:36 +02:00
// Play the campaign button video when the mouse cursor is placed over the button
2011-11-27 16:14:20 +03:00
if ( hovered )
2011-03-15 16:35:36 +02:00
{
if ( CCS - > videoh - > fname ! = video )
CCS - > videoh - > open ( video ) ;
2011-11-27 16:14:20 +03:00
2011-03-15 16:35:36 +02:00
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 ( ) ;
2011-11-27 16:14:20 +03:00
redraw ( ) ;
2011-03-15 16:35:36 +02:00
}
2011-11-27 16:14:20 +03:00
}
2011-04-17 21:02:13 +03:00
2011-12-22 16:05:19 +03:00
CAdventureMapButton * CCampaignScreen : : createExitButton ( const JsonNode & button )
2011-11-27 16:14:20 +03:00
{
std : : pair < std : : string , std : : string > help ;
if ( ! button [ " help " ] . isNull ( ) & & button [ " help " ] . Float ( ) > 0 )
help = CGI - > generaltexth - > zelp [ button [ " help " ] . Float ( ) ] ;
2011-03-15 16:35:36 +02:00
2011-11-27 16:14:20 +03:00
boost : : function < void ( ) > close = boost : : bind ( & CGuiHandler : : popIntTotally , & GH , this ) ;
2011-12-22 16:05:19 +03:00
return new CAdventureMapButton ( help , close , button [ " x " ] . Float ( ) , button [ " y " ] . Float ( ) , button [ " name " ] . String ( ) , button [ " hotkey " ] . Float ( ) ) ;
2011-03-15 16:35:36 +02:00
}
2011-11-27 16:14:20 +03:00
CCampaignScreen : : CCampaignScreen ( const JsonNode & config )
2011-03-15 16:35:36 +02:00
{
2011-11-27 16:14:20 +03:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
BOOST_FOREACH ( const JsonNode & node , config [ " images " ] . Vector ( ) )
images . push_back ( createPicture ( node ) ) ;
2012-05-18 20:35:46 +03:00
if ( ! images . empty ( ) )
{
images [ 0 ] - > center ( ) ; // move background to center
moveTo ( images [ 0 ] - > pos . topLeft ( ) ) ; // move everything else to center
images [ 0 ] - > moveTo ( pos . topLeft ( ) ) ; // restore moved twice background
pos = images [ 0 ] - > pos ; // fix height\width of this window
}
2011-11-27 16:14:20 +03:00
if ( ! config [ " exitbutton " ] . isNull ( ) )
2011-03-15 16:35:36 +02:00
{
2011-11-27 16:14:20 +03:00
back = createExitButton ( config [ " exitbutton " ] ) ;
back - > hoverable = true ;
2011-03-15 16:35:36 +02:00
}
2012-11-03 22:31:16 +03:00
2011-11-27 16:14:20 +03:00
BOOST_FOREACH ( const JsonNode & node , config [ " items " ] . Vector ( ) )
campButtons . push_back ( new CCampaignButton ( node ) ) ;
2011-04-17 21:02:13 +03:00
}
2012-05-18 20:35:46 +03:00
void CCampaignScreen : : showAll ( SDL_Surface * to )
{
CIntObject : : showAll ( to ) ;
if ( pos . h ! = to - > h | | pos . w ! = to - > w )
2013-03-03 20:06:03 +03:00
CMessage : : drawBorder ( PlayerColor ( 1 ) , to , pos . w + 28 , pos . h + 30 , pos . x - 14 , pos . y - 15 ) ;
2012-05-18 20:35:46 +03:00
}
2012-09-26 21:10:29 +03:00
2012-12-17 21:01:17 +03:00
void CGPreGame : : showLoadingScreen ( boost : : function < void ( ) > loader )
{
2012-12-19 21:19:09 +03:00
if ( GH . listInt . size ( ) & & GH . listInt . front ( ) = = CGP ) //pregame active
2012-12-17 21:01:17 +03:00
CGP - > removeFromGui ( ) ;
GH . pushInt ( new CLoadingScreen ( loader ) ) ;
}
std : : string CLoadingScreen : : getBackground ( )
{
const JsonVector & conf = ( * CGP - > pregameConfig ) [ " loading " ] . Vector ( ) ;
if ( conf . empty ( ) )
return " loadbar " ;
return conf [ rand ( ) % conf . size ( ) ] . String ( ) ;
}
CLoadingScreen : : CLoadingScreen ( boost : : function < void ( ) > loader ) :
CWindowObject ( BORDERED , getBackground ( ) ) ,
loadingThread ( loader )
2012-12-19 20:24:53 +03:00
{
CCS - > musich - > stopMusic ( 5000 ) ;
}
2012-12-17 21:01:17 +03:00
2012-12-18 13:32:11 +03:00
CLoadingScreen : : ~ CLoadingScreen ( )
{
loadingThread . join ( ) ;
}
2012-12-17 21:01:17 +03:00
void CLoadingScreen : : showAll ( SDL_Surface * to )
{
Rect rect ( 0 , 0 , to - > w , to - > h ) ;
SDL_FillRect ( to , & rect , 0 ) ;
CWindowObject : : showAll ( to ) ;
}
2013-02-19 23:39:09 +03:00
2013-02-21 00:01:18 +03:00
CPrologEpilogVideo : : CPrologEpilogVideo ( CCampaignScenario : : SScenarioPrologEpilog _spe , std : : function < void ( ) > callback )
2013-02-26 18:07:21 +03:00
: spe ( _spe ) , decrementDelayCounter ( 0 ) , exitCb ( callback )
2013-02-19 23:39:09 +03:00
{
OBJ_CONSTRUCTION_CAPTURING_ALL ;
2013-02-21 00:01:18 +03:00
addUsedEvents ( LCLICK ) ;
pos = Rect ( screen ) ;
2013-02-19 23:39:09 +03:00
CCS - > videoh - > open ( CCampaignHandler : : prologVideoName ( spe . prologVideo ) ) ;
2013-02-21 00:01:18 +03:00
auto lines = CMessage : : breakText ( spe . prologText , 500 , EFonts : : FONT_BIG ) ;
2013-02-19 23:39:09 +03:00
2013-02-23 22:16:14 +03:00
txt = CSDL_Ext : : newSurface ( 500 , 20 * lines . size ( ) + 10 ) ;
2013-02-21 00:01:18 +03:00
curTxtH = screen - > h ;
2013-02-23 22:16:14 +03:00
graphics - > fonts [ FONT_BIG ] - > renderTextLinesCenter ( txt , lines , Colors : : METALLIC_GOLD , Point ( txt - > w / 2 , txt - > h / 2 + 5 ) ) ;
2013-02-23 00:03:56 +03:00
//SDL_SaveBMP(txt, "txtsrfc.bmp");
2013-02-19 23:39:09 +03:00
}
void CPrologEpilogVideo : : show ( SDL_Surface * to )
{
2013-02-21 00:01:18 +03:00
memset ( to - > pixels , 0 , to - > h * to - > pitch ) ; //make bg black
2013-02-23 00:03:56 +03:00
CCS - > videoh - > update ( pos . x , pos . y , to , true , false ) ;
SDL_Rect tmp , our ;
our = Rect ( 0 , to - > h - 100 , to - > w , 100 ) ;
SDL_GetClipRect ( to , & tmp ) ;
SDL_SetClipRect ( to , & our ) ;
2013-02-21 00:01:18 +03:00
blitAt ( txt , ( to - > w - txt - > w ) / 2 , curTxtH , to ) ;
2013-02-23 00:03:56 +03:00
SDL_SetClipRect ( to , & tmp ) ;
//move text every 5 calls/frames; seems to be good enough
+ + decrementDelayCounter ;
if ( decrementDelayCounter = = 5 )
{
curTxtH = std : : max ( curTxtH - 1 , to - > h - txt - > h ) ;
decrementDelayCounter = 0 ;
}
2013-02-19 23:39:09 +03:00
}
void CPrologEpilogVideo : : clickLeft ( tribool down , bool previousState )
{
GH . popInt ( this ) ;
2013-02-21 00:01:18 +03:00
exitCb ( ) ;
2013-02-19 23:39:09 +03:00
}