2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2005 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// Startup screen for non-parameterized engine start (stub)
2016-04-03 18:07:56 +00:00
# include "C4Include.h"
# include "gui/C4StartupMainDlg.h"
2011-11-01 22:17:41 +00:00
2016-04-03 18:07:56 +00:00
# include "C4Version.h"
2017-04-30 08:49:09 +00:00
# include "c4group/C4Components.h"
# include "game/C4Application.h"
# include "graphics/C4Draw.h"
# include "graphics/C4GraphicsResource.h"
# include "gui/C4Startup.h"
# include "gui/C4StartupAboutDlg.h"
2016-04-03 18:07:56 +00:00
# include "gui/C4StartupNetDlg.h"
# include "gui/C4StartupOptionsDlg.h"
# include "gui/C4StartupPlrSelDlg.h"
2017-04-30 08:49:09 +00:00
# include "gui/C4StartupScenSelDlg.h"
# include "gui/C4UpdateDlg.h"
2009-05-08 13:28:41 +00:00
2016-03-26 22:26:52 +00:00
# ifdef _WIN32
2016-03-26 06:15:15 +00:00
# include <shellapi.h>
# endif
2009-05-08 13:28:41 +00:00
2016-11-02 23:58:02 +00:00
C4StartupMainDlg : : C4StartupMainDlg ( ) : C4StartupDlg ( nullptr ) // create w/o title; it is drawn in custom draw proc
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// ctor
fFirstShown = true ;
// screen calculations
int iButtonPadding = 2 ;
int iButtonHeight = C4GUI_BigButtonHgt ;
C4GUI : : ComponentAligner caMain ( rcBounds , 0 , 0 , true ) ;
2010-08-15 18:20:59 +00:00
C4GUI : : ComponentAligner caRightPanel ( caMain . GetFromLeft ( rcBounds . Wdt * 2 / 5 ) , rcBounds . Wdt / 26 , 40 + rcBounds . Hgt / 5 ) ;
2009-05-08 13:28:41 +00:00
C4GUI : : ComponentAligner caButtons ( caRightPanel . GetAll ( ) , 0 , iButtonPadding ) ;
// main menu buttons
C4GUI : : CallbackButton < C4StartupMainDlg > * btn ;
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_BTN_LOCALGAME " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnStartBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_STARTGAME " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
pStartButton = btn ;
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_BTN_NETWORKGAME " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnNetJoinBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_NETWORKGAME " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_DLG_PLAYERSELECTION " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnPlayerSelectionBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_PLAYERSELECTION " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_DLG_OPTIONS " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnOptionsBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_OPTIONS " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
2016-03-26 06:15:15 +00:00
# ifdef WITH_QT_EDITOR
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_DLG_EDITOR " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnEditorBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_EDITOR " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
# endif
2009-05-08 13:28:41 +00:00
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_DLG_ABOUT " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnAboutBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_ABOUT " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
AddElement ( btn = new C4GUI : : CallbackButton < C4StartupMainDlg > ( LoadResStr ( " IDS_DLG_EXIT " ) , caButtons . GetFromTop ( iButtonHeight ) , & C4StartupMainDlg : : OnExitBtn ) ) ;
btn - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_EXIT " ) ) ;
btn - > SetCustomGraphics ( & C4Startup : : Get ( ) - > Graphics . barMainButtons , & C4Startup : : Get ( ) - > Graphics . barMainButtonsDown ) ;
// list of selected players
2010-06-27 00:42:48 +00:00
AddElement ( pParticipantsLbl = new C4GUI : : Label ( " test " , GetClientRect ( ) . Wdt * 39 / 40 , GetClientRect ( ) . Hgt * 9 / 10 , ARight , 0xffffffff , & : : GraphicsResource . TitleFont , false ) ) ;
2009-05-08 13:28:41 +00:00
pParticipantsLbl - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_SELECTEDPLAYERS " ) ) ;
// player selection shortcut - to be made optional
UpdateParticipants ( ) ;
pParticipantsLbl - > SetContextHandler ( new C4GUI : : CBContextHandler < C4StartupMainDlg > ( this , & C4StartupMainDlg : : OnPlayerSelContext ) ) ;
// key bindings
C4CustomKey : : CodeList keys ;
2017-05-03 18:28:00 +00:00
keys . emplace_back ( K_DOWN ) ; keys . emplace_back ( K_RIGHT ) ;
2009-05-08 13:28:41 +00:00
if ( Config . Controls . GamepadGuiControl )
2010-03-28 18:58:01 +00:00
{
2016-02-17 19:58:12 +00:00
ControllerKeys : : Down ( keys ) ; // right will be done by Dialog already
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
pKeyDown = new C4KeyBinding ( keys , " StartupMainCtrlNext " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCBEx < C4StartupMainDlg , bool > ( * this , false , & C4StartupMainDlg : : KeyAdvanceFocus ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2017-05-03 18:28:00 +00:00
keys . clear ( ) ; keys . emplace_back ( K_UP ) ; keys . emplace_back ( K_LEFT ) ;
2009-05-08 13:28:41 +00:00
if ( Config . Controls . GamepadGuiControl )
2010-03-28 18:58:01 +00:00
{
2016-02-17 19:58:12 +00:00
ControllerKeys : : Up ( keys ) ; // left will be done by Dialog already
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
pKeyUp = new C4KeyBinding ( keys , " StartupMainCtrlPrev " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCBEx < C4StartupMainDlg , bool > ( * this , true , & C4StartupMainDlg : : KeyAdvanceFocus ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2017-05-03 18:28:00 +00:00
keys . clear ( ) ; keys . emplace_back ( K_RETURN ) ;
2009-05-08 13:28:41 +00:00
pKeyEnter = new C4KeyBinding ( keys , " StartupMainOK " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCB < C4StartupMainDlg > ( * this , & C4StartupMainDlg : : KeyEnterDown , & C4StartupMainDlg : : KeyEnterUp ) , C4CustomKey : : PRIO_CtrlOverride ) ;
}
2009-05-08 13:28:41 +00:00
C4StartupMainDlg : : ~ C4StartupMainDlg ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// dtor
delete pKeyEnter ;
delete pKeyUp ;
delete pKeyDown ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : DrawElement ( C4TargetFacet & cgo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// inherited
typedef C4GUI : : FullscreenDialog Base ;
Base : : DrawElement ( cgo ) ;
// draw logo
2010-08-15 18:20:59 +00:00
C4FacetID * fctStartupLogo = & C4Startup : : Get ( ) - > Graphics . fctStartupLogo ;
2009-05-08 13:28:41 +00:00
float fLogoZoom = 1.0f ;
2010-08-15 18:20:59 +00:00
fctStartupLogo - > DrawX ( cgo . Surface , rcBounds . Wdt * 1 / 21 , rcBounds . Hgt / 28 , int32_t ( fLogoZoom * fctStartupLogo - > Wdt ) , int32_t ( fLogoZoom * fctStartupLogo - > Hgt ) ) ;
2009-05-08 13:28:41 +00:00
// draw version info
StdStrBuf sVer ;
sVer . Format ( LoadResStr ( " IDS_DLG_VERSION " ) , C4VERSION ) ;
2011-10-03 14:30:18 +00:00
pDraw - > TextOut ( sVer . getData ( ) , : : GraphicsResource . TextFont , 1.0f , cgo . Surface , rcBounds . Wdt * 1 / 40 , rcBounds . Hgt * 38 / 40 , 0xffffffff , ALeft , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * C4StartupMainDlg : : OnPlayerSelContext ( C4GUI : : Element * pBtn , int32_t iX , int32_t iY )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// preliminary player selection via simple context menu
C4GUI : : ContextMenu * pCtx = new C4GUI : : ContextMenu ( ) ;
2016-11-02 23:58:02 +00:00
pCtx - > AddItem ( " Add " , " Add participant " , C4GUI : : Ico_None , nullptr , new C4GUI : : CBContextHandler < C4StartupMainDlg > ( this , & C4StartupMainDlg : : OnPlayerSelContextAdd ) ) ;
pCtx - > AddItem ( " Remove " , " Remove participant " , C4GUI : : Ico_None , nullptr , new C4GUI : : CBContextHandler < C4StartupMainDlg > ( this , & C4StartupMainDlg : : OnPlayerSelContextRemove ) ) ;
2009-05-08 13:28:41 +00:00
return pCtx ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * C4StartupMainDlg : : OnPlayerSelContextAdd ( C4GUI : : Element * pBtn , int32_t iX , int32_t iY )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * pCtx = new C4GUI : : ContextMenu ( ) ;
const char * szFn ;
StdStrBuf sSearchPath ( Config . General . UserDataPath ) ;
2010-03-28 18:58:01 +00:00
// sSearchPath.Format("%s%s", (const char *) Config.General.ExePath, (const char *) Config.General.PlayerPath);
2010-01-25 04:00:59 +00:00
for ( DirectoryIterator i ( sSearchPath . getData ( ) ) ; ( szFn = * i ) ; i + + )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
szFn = Config . AtRelativePath ( szFn ) ;
if ( * GetFilename ( szFn ) = = ' . ' ) continue ;
if ( ! WildcardMatch ( C4CFN_PlayerFiles , GetFilename ( szFn ) ) ) continue ;
2016-11-02 23:58:02 +00:00
if ( ! SIsModule ( Config . General . Participants , szFn , nullptr , false ) )
2014-06-05 01:09:46 +00:00
pCtx - > AddItem ( GetFilenameOnly ( szFn ) , " Let this player join in next game " , C4GUI : : Ico_Player ,
2016-11-02 23:58:02 +00:00
new C4GUI : : CBMenuHandlerEx < C4StartupMainDlg , StdCopyStrBuf > ( this , & C4StartupMainDlg : : OnPlayerSelContextAddPlr , StdCopyStrBuf ( szFn ) ) , nullptr ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
return pCtx ;
}
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * C4StartupMainDlg : : OnPlayerSelContextRemove ( C4GUI : : Element * pBtn , int32_t iX , int32_t iY )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * pCtx = new C4GUI : : ContextMenu ( ) ;
char szPlayer [ 1024 + 1 ] ;
for ( int i = 0 ; SCopySegment ( Config . General . Participants , i , szPlayer , ' ; ' , 1024 , true ) ; i + + )
if ( * szPlayer )
2016-11-02 23:58:02 +00:00
pCtx - > AddItem ( GetFilenameOnly ( szPlayer ) , " Remove this player from participation list " , C4GUI : : Ico_Player , new C4GUI : : CBMenuHandlerEx < C4StartupMainDlg , int > ( this , & C4StartupMainDlg : : OnPlayerSelContextRemovePlr , i ) , nullptr ) ;
2009-05-08 13:28:41 +00:00
return pCtx ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnPlayerSelContextAddPlr ( C4GUI : : Element * pTarget , const StdCopyStrBuf & rsFilename )
2010-03-28 18:58:01 +00:00
{
2016-01-12 02:33:08 +00:00
// De-select all other players for now (see #1529)
SCopy ( rsFilename . getData ( ) , Config . General . Participants ) ;
//SAddModule(Config.General.Participants, rsFilename.getData());
2009-05-08 13:28:41 +00:00
UpdateParticipants ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnPlayerSelContextRemovePlr ( C4GUI : : Element * pTarget , const int & iIndex )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
char szPlayer [ 1024 + 1 ] ;
if ( SCopySegment ( Config . General . Participants , iIndex , szPlayer , ' ; ' , 1024 , true ) )
SRemoveModule ( Config . General . Participants , szPlayer , false ) ;
UpdateParticipants ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : UpdateParticipants ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// First validate all participants (files must exist)
std : : string strPlayers ( Config . General . Participants ) ;
2010-09-05 12:18:55 +00:00
std : : vector < char > strPlayer ( 1025 ) ;
2009-05-08 13:28:41 +00:00
* Config . General . Participants = 0 ;
2010-09-05 12:18:55 +00:00
for ( int i = 0 ; SCopySegment ( strPlayers . c_str ( ) , i , & strPlayer [ 0 ] , ' ; ' , strPlayer . size ( ) - 1 , true ) ; i + + )
2010-03-28 18:58:01 +00:00
{
2010-09-05 12:18:55 +00:00
const char * szPlayer = & strPlayer [ 0 ] ;
2009-05-08 13:28:41 +00:00
std : : string strPlayerFile ( Config . General . UserDataPath ) ;
strPlayerFile . append ( szPlayer ) ;
if ( ! szPlayer | | ! * szPlayer ) continue ;
if ( ! FileExists ( strPlayerFile . c_str ( ) ) ) continue ;
2011-03-13 15:39:48 +00:00
if ( ! SEqualNoCase ( GetExtension ( szPlayer ) , " ocp " ) ) continue ; // additional sanity check to clear strange exe-path-only entries in player list?
2009-05-08 13:28:41 +00:00
SAddModule ( Config . General . Participants , szPlayer ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Draw selected players - we are currently displaying the players stored in Config.General.Participants.
// Existence of the player files is not validated and player filenames are displayed directly
// (names are not loaded from the player core).
strPlayers = LoadResStr ( " IDS_DESC_PLRS " ) ;
if ( ! Config . General . Participants [ 0 ] )
strPlayers . append ( LoadResStr ( " IDS_DLG_NOPLAYERSSELECTED " ) ) ;
else
for ( int i = 0 ; SCopySegment ( Config . General . Participants , i , & strPlayer [ 0 ] , ' ; ' , 1024 , true ) ; i + + )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( i > 0 ) strPlayers . append ( " , " ) ;
2014-06-05 01:09:46 +00:00
strPlayers . append ( GetFilenameOnly ( & strPlayer [ 0 ] ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
pParticipantsLbl - > SetText ( strPlayers . c_str ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnClosed ( bool fOK )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// if dlg got aborted (by user), quit startup
// if it got closed with OK, the user pressed one of the buttons and dialog switching has been done already
2011-01-06 23:51:35 +00:00
if ( ! fOK ) Application . Quit ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnStartBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// advance to scenario selection screen
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_ScenSel ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnPlayerSelectionBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// advance to player selection screen
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_PlrSel ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnNetJoinBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// advanced net join and host dlg!
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_NetJoin ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnNetJoin ( const StdStrBuf & rsHostAddress )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no IP given: No join
if ( ! rsHostAddress | | ! * rsHostAddress . getData ( ) ) return ;
// set default startup parameters
* Game . ScenarioFilename = 0 ;
2011-03-13 15:55:00 +00:00
SCopy ( " Objects.ocd " , Game . DefinitionFilenames ) ;
2009-08-15 18:50:32 +00:00
Game . NetworkActive = true ;
Game . fLobby = true ;
Game . fObserve = false ;
2009-05-08 13:28:41 +00:00
SCopy ( rsHostAddress . getData ( ) , Game . DirectJoinAddress , sizeof ( Game . DirectJoinAddress ) - 1 ) ;
// start with this set!
2011-01-06 23:51:35 +00:00
Application . OpenGame ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnOptionsBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// advance to options screen
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_Options ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-03-26 06:15:15 +00:00
void C4StartupMainDlg : : OnEditorBtn ( C4GUI : : Control * btn )
{
2016-08-11 20:11:15 +00:00
if ( ! RestartApplication ( { " --editor " } ) )
2016-03-26 20:43:37 +00:00
{
2016-03-26 06:15:15 +00:00
C4GUI : : TheScreen . ShowErrorMessage ( LoadResStr ( " IDS_ERR_STARTEDITOR " ) ) ;
2016-08-10 23:35:07 +00:00
}
2016-03-26 06:15:15 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnAboutBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// advance to about screen
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_About ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnExitBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// callback: exit button pressed
2011-01-06 23:51:35 +00:00
Application . Quit ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnTODO ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
GetScreen ( ) - > ShowMessage ( " not yet implemented " , " 2do " , C4GUI : : Ico_Error ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupMainDlg : : KeyEnterDown ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// just execute selected button: Re-Send as space
return Game . DoKeyboardInput ( K_SPACE , KEYEV_Down , false , false , false , false , this ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupMainDlg : : KeyEnterUp ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// just execute selected button: Re-Send as space
return Game . DoKeyboardInput ( K_SPACE , KEYEV_Up , false , false , false , false , this ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupMainDlg : : OnShown ( )
2010-03-28 18:58:01 +00:00
{
2010-12-26 20:39:52 +00:00
# ifdef WITH_AUTOMATIC_UPDATE
2009-05-08 13:28:41 +00:00
// Incoming update
2017-03-16 22:18:38 +00:00
if ( ! Application . IncomingUpdate . empty ( ) )
2010-03-28 18:58:01 +00:00
{
2017-03-16 22:18:38 +00:00
C4UpdateDlg : : ApplyUpdate ( Application . IncomingUpdate . c_str ( ) , false , GetScreen ( ) ) ;
Application . IncomingUpdate . clear ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Manual update by command line or url
if ( Application . CheckForUpdates )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4UpdateDlg : : CheckForUpdates ( GetScreen ( ) , false ) ;
Application . CheckForUpdates = false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Automatic update
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( Config . Network . AutomaticUpdate )
C4UpdateDlg : : CheckForUpdates ( GetScreen ( ) , true ) ;
2010-03-28 18:58:01 +00:00
}
2010-12-26 20:39:52 +00:00
# endif
2009-05-08 13:28:41 +00:00
// first start evaluation
if ( Config . General . FirstStart )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
Config . General . FirstStart = false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// first thing that's needed is a new player, if there's none - independent of first start
bool fHasPlayer = false ;
StdStrBuf sSearchPath ( Config . General . UserDataPath ) ;
const char * szFn ;
2010-03-28 18:58:01 +00:00
// sSearchPath.Format("%s%s", (const char *) Config.General.ExePath, (const char *) Config.General.PlayerPath);
2010-01-25 04:00:59 +00:00
for ( DirectoryIterator i ( sSearchPath . getData ( ) ) ; ( szFn = * i ) ; i + + )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
szFn = Config . AtRelativePath ( szFn ) ;
if ( * GetFilename ( szFn ) = = ' . ' ) continue ; // ignore ".", ".." and private files (".*")
if ( ! WildcardMatch ( C4CFN_PlayerFiles , GetFilename ( szFn ) ) ) continue ;
fHasPlayer = true ;
break ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
if ( ! fHasPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no player created yet: Create one
C4GUI : : Dialog * pDlg ;
2016-11-02 23:58:02 +00:00
GetScreen ( ) - > ShowModalDlg ( pDlg = new C4StartupPlrPropertiesDlg ( nullptr , nullptr ) , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// make sure participants are updated after switching back from player selection
UpdateParticipants ( ) ;
// First show
if ( fFirstShown )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Activate the application (trying to prevent flickering half-focus in win32...)
Application . Activate ( ) ;
// Set the focus to the start button (we might still not have the focus after the update-check sometimes... :/)
SetFocus ( pStartButton , false ) ;
}
2010-03-28 18:58:01 +00:00
fFirstShown = false ;
}