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: Player selection dialog
// Also contains player creation, editing and crew management
2016-04-03 18:07:56 +00:00
# include "C4Include.h"
# include "gui/C4StartupPlrSelDlg.h"
2009-05-08 13:28:41 +00:00
2016-10-20 21:42:46 +00:00
# include "graphics/C4Draw.h"
2017-04-30 08:49:09 +00:00
# include "graphics/C4GraphicsResource.h"
# include "gui/C4FileSelDlg.h"
2011-10-30 19:43:45 +00:00
# include "gui/C4MouseControl.h"
2017-04-30 08:49:09 +00:00
# include "gui/C4StartupMainDlg.h"
# include "lib/C4Random.h"
2016-02-08 01:13:18 +00:00
# include "lib/StdColors.h"
2017-04-30 08:49:09 +00:00
# include "player/C4RankSystem.h"
2009-05-08 13:28:41 +00:00
// font clrs
2013-05-26 15:51:35 +00:00
const uint32_t ClrPlayerItem = 0xffffffff ;
2009-05-08 13:28:41 +00:00
2011-10-30 19:43:45 +00:00
// Arbitrary cut-off value for player color value. This avoids pitch black
// colors which look ugly. Note that this limit is only applied in the UI,
// it's still possible to edit the Player.txt by hand.
const uint32_t PlayerColorValueLowBound = 64 ;
2009-05-08 13:28:41 +00:00
// ----- C4Utilities
StdStrBuf TimeString ( int iSeconds )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int iHours = iSeconds / 3600 ; iSeconds - = 3600 * iHours ;
int iMinutes = iSeconds / 60 ; iSeconds - = 60 * iMinutes ;
return FormatString ( " %02d:%02d:%02d " , iHours , iMinutes , iSeconds ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
StdStrBuf DateString ( int iTime )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! iTime ) return StdStrBuf ( " " , true ) ;
2015-03-25 18:04:04 +00:00
time_t tTime = iTime ;
2009-05-08 13:28:41 +00:00
struct tm * pLocalTime ;
2010-03-27 16:05:02 +00:00
pLocalTime = localtime ( & tTime ) ;
2010-03-28 18:58:01 +00:00
return FormatString ( " %02d.%02d.%d %02d:%02d " ,
pLocalTime - > tm_mday ,
pLocalTime - > tm_mon + 1 ,
pLocalTime - > tm_year + 1900 ,
pLocalTime - > tm_hour ,
pLocalTime - > tm_min ) ;
}
2009-05-08 13:28:41 +00:00
// ------------------------------------------------
// --- C4StartupPlrSelDlg::ListItem
C4StartupPlrSelDlg : : ListItem : : ListItem ( C4StartupPlrSelDlg * pForDlg , C4GUI : : ListBox * pForListBox , C4GUI : : Element * pInsertBeforeElement , bool fActivated )
2016-11-02 23:58:02 +00:00
: Control ( C4Rect ( 0 , 0 , 0 , 0 ) ) , pCheck ( nullptr ) , pNameLabel ( nullptr ) , pPlrSelDlg ( pForDlg ) , pIcon ( nullptr )
2010-03-28 18:58:01 +00:00
{
2013-05-26 15:51:35 +00:00
CStdFont & rUseFont = GraphicsResource . FontRegular ;
2009-05-08 13:28:41 +00:00
// calc height
int32_t iHeight = rUseFont . GetLineHeight ( ) + 2 * IconLabelSpacing ;
// create subcomponents
2016-11-02 23:58:02 +00:00
pCheck = new C4GUI : : CheckBox ( C4Rect ( 0 , 0 , iHeight , iHeight ) , nullptr , fActivated ) ;
2009-05-08 13:28:41 +00:00
pCheck - > SetOnChecked ( new C4GUI : : CallbackHandler < C4StartupPlrSelDlg > ( pForDlg , & C4StartupPlrSelDlg : : OnItemCheckChange ) ) ;
pKeyCheck = new C4KeyBinding ( C4KeyCodeEx ( K_SPACE ) , " StartupPlrSelTogglePlayerActive " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : ControlKeyCB < ListItem > ( * this , & ListItem : : KeyCheck ) , C4CustomKey : : PRIO_Ctrl ) ;
2009-05-08 13:28:41 +00:00
pIcon = new C4GUI : : Icon ( C4Rect ( iHeight + IconLabelSpacing , 0 , iHeight , iHeight ) , C4GUI : : Ico_Player ) ;
pNameLabel = new C4GUI : : Label ( " Q " , ( iHeight + IconLabelSpacing ) * 2 , IconLabelSpacing , ALeft , ClrPlayerItem , & rUseFont , false , false ) ;
pNameLabel - > SetAutosize ( false ) ;
// calc own bounds - use icon bounds only, because only the height is used when the item is added
SetBounds ( pIcon - > GetBounds ( ) ) ;
// add components
AddElement ( pCheck ) ;
AddElement ( pIcon ) ; AddElement ( pNameLabel ) ;
// add to listbox (will get resized horizontally and moved) - zero indent; no tree structure in this dialog
pForListBox - > InsertElement ( this , pInsertBeforeElement , 0 ) ;
// update name label width to stretch max listbox width
C4Rect rcNameLabelBounds = pNameLabel - > GetBounds ( ) ;
rcNameLabelBounds . Wdt = GetClientRect ( ) . Wdt - rcNameLabelBounds . x - IconLabelSpacing ;
pNameLabel - > SetBounds ( rcNameLabelBounds ) ;
// context menu
SetContextHandler ( new C4GUI : : CBContextHandler < C4StartupPlrSelDlg : : ListItem > ( this , & C4StartupPlrSelDlg : : ListItem : : ContextMenu ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4StartupPlrSelDlg : : ListItem : : ~ ListItem ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
delete pKeyCheck ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
const char * C4StartupPlrSelDlg : : ListItem : : GetName ( ) const
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// name is stored in label only
return pNameLabel - > GetText ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ListItem : : SetName ( const char * szNewName )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// update name in label
pNameLabel - > SetText ( szNewName ) ;
// tooltip by name, so long names can be read via tooltip
SetToolTip ( szNewName ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ListItem : : GrabIcon ( C4FacetSurface & rFromFacet )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// take over icon gfx from facet - deletes them from source facet!
if ( rFromFacet . Surface )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pIcon - > GetMFacet ( ) . GrabFrom ( rFromFacet ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// reset custom icon
// following update-call will reset to default icon
pIcon - > GetMFacet ( ) . Clear ( ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ListItem : : SetIcon ( C4GUI : : Icons icoNew )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pIcon - > SetIcon ( icoNew ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ListItem : : UpdateOwnPos ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// parent for client rect
typedef C4GUI : : Window ParentClass ;
ParentClass : : UpdateOwnPos ( ) ;
// reposition items
C4GUI : : ComponentAligner caBounds ( GetContainedClientRect ( ) , IconLabelSpacing , IconLabelSpacing ) ;
// nothing to reposition for now...
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ListItem : : SetFilename ( const StdStrBuf & sNewFN )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// just set fn - UpdateCore-call will follow later
Filename . Copy ( sNewFN ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupPlrSelDlg : : ListItem : : CheckNameHotkey ( const char * c )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// return whether this item can be selected by entering given char:
// first char of name must match
// FIXME: Unicode
if ( ! pNameLabel ) return false ;
const char * szName = pNameLabel - > GetText ( ) ;
return szName & & ( toupper ( * szName ) = = toupper ( c [ 0 ] ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// ------------------------------------------------
// --- C4StartupPlrSelDlg::PlayerListItem
C4StartupPlrSelDlg : : PlayerListItem : : PlayerListItem ( C4StartupPlrSelDlg * pForDlg , C4GUI : : ListBox * pForListBox , C4GUI : : Element * pInsertBeforeElement , bool fActivated )
2010-03-28 18:58:01 +00:00
: ListItem ( pForDlg , pForListBox , pInsertBeforeElement , fActivated ) , fHasCustomIcon ( false )
{
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : PlayerListItem : : Load ( const StdStrBuf & rsFilename )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int32_t iHeight = GetBounds ( ) . Hgt ;
// backup filename
SetFilename ( rsFilename ) ;
// load player info
C4Group PlrGroup ;
2010-02-08 19:58:48 +00:00
if ( ! PlrGroup . Open ( Config . AtUserDataPath ( rsFilename . getData ( ) ) ) )
2009-05-08 13:28:41 +00:00
throw LoadError ( FormatString ( " Error loading player file from %s: Error opening group: %s " , rsFilename . getData ( ) , PlrGroup . GetError ( ) ) ) ;
if ( ! Core . Load ( PlrGroup ) )
throw LoadError ( FormatString ( " Error loading player file from %s: Core data invalid or missing (Group: %s) ! " , rsFilename.getData(), PlrGroup.GetError())) ;
// load icon
C4FacetSurface fctIcon ;
2015-09-19 01:10:39 +00:00
if ( PlrGroup . FindEntry ( C4CFN_BigIcon ) & & fctIcon . Load ( PlrGroup , C4CFN_BigIcon , C4FCT_Full , C4FCT_Full , false , 0 ) )
2009-05-08 13:28:41 +00:00
fHasCustomIcon = true ;
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no custom icon: create default by player color
fctIcon . Create ( iHeight , iHeight ) ;
2009-08-15 18:50:32 +00:00
: : GraphicsResource . fctPlayerClr . DrawClr ( fctIcon , true , Core . PrefColorDw ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
GrabIcon ( fctIcon ) ;
// done loading
if ( ! PlrGroup . Close ( ) )
throw LoadError ( FormatString ( " Error loading player file from %s: Error closing group: %s " , rsFilename . getData ( ) , PlrGroup . GetError ( ) ) ) ;
// default name
if ( ! * Core . PrefName ) SCopy ( GetFilenameOnly ( rsFilename . getData ( ) ) , Core . PrefName , sizeof ( Core . PrefName ) - 1 ) ;
SetName ( Core . PrefName ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * C4StartupPlrSelDlg : : PlayerListItem : : ContextMenu ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// menu operations work on selected item only
pPlrSelDlg - > SetSelection ( this ) ;
// context menu operations
C4GUI : : ContextMenu * pCtx = new C4GUI : : ContextMenu ( ) ;
pCtx - > AddItem ( LoadResStr ( " IDS_BTN_PROPERTIES " ) , LoadResStr ( " IDS_DLGTIP_PLAYERPROPERTIES " ) , C4GUI : : Ico_None , new C4GUI : : CBMenuHandler < C4StartupPlrSelDlg > ( pPlrSelDlg , & C4StartupPlrSelDlg : : OnPropertyCtx ) ) ;
pCtx - > AddItem ( LoadResStr ( " IDS_BTN_DELETE " ) , LoadResStr ( " IDS_DLGTIP_PLAYERDELETE " ) , C4GUI : : Ico_None , new C4GUI : : CBMenuHandler < C4StartupPlrSelDlg > ( pPlrSelDlg , & C4StartupPlrSelDlg : : OnDelCtx ) ) ;
return pCtx ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : PlayerListItem : : GrabCustomIcon ( C4FacetSurface & fctGrabFrom )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// set flag
fHasCustomIcon = ! ! fctGrabFrom . Surface ;
// base class grab
GrabIcon ( fctGrabFrom ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : PlayerListItem : : UpdateCore ( C4PlayerInfoCore & NewCore )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Group PlrGroup ;
2010-02-08 19:58:48 +00:00
if ( ! PlrGroup . Open ( Config . AtUserDataPath ( GetFilename ( ) . getData ( ) ) )
2010-03-28 18:58:01 +00:00
| | ! NewCore . Save ( PlrGroup )
| | ! PlrGroup . Close ( ) )
{
2009-05-08 13:28:41 +00:00
GetScreen ( ) - > ShowMessage ( LoadResStr ( " IDS_FAIL_MODIFY " ) , " " , C4GUI : : Ico_Error ) ;
return ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
Core = NewCore ;
SetName ( Core . PrefName ) ;
// re-set non-custom icons
if ( ! fHasCustomIcon )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
fHasCustomIcon = false ;
int32_t iHeight = GetBounds ( ) . Hgt ;
C4FacetSurface fctIcon ; fctIcon . Create ( iHeight , iHeight ) ;
2009-08-15 18:50:32 +00:00
: : GraphicsResource . fctPlayerClr . DrawClr ( fctIcon , true , Core . PrefColorDw ) ;
2009-05-08 13:28:41 +00:00
GrabIcon ( fctIcon ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// update in selection
C4StartupPlrSelDlg * pDlg = static_cast < C4StartupPlrSelDlg * > ( GetDlg ( ) ) ;
if ( pDlg & & pDlg - > GetSelection ( ) = = this ) pDlg - > UpdateSelection ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : PlayerListItem : : SetSelectionInfo ( C4GUI : : TextWindow * pSelectionInfo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// write info text for player
pSelectionInfo - > ClearText ( false ) ;
pSelectionInfo - > AddTextLine ( FormatString ( " %s " , Core . PrefName ) . getData ( ) , & C4Startup : : Get ( ) - > Graphics . BookFontCapt , ClrPlayerItem , false , false ) ;
2010-04-21 19:12:49 +00:00
pSelectionInfo - > AddTextLine ( FormatString ( LoadResStr ( " IDS_DESC_PLAYER " ) , ( int ) Core . TotalScore , ( int ) Core . Rounds , ( int ) Core . RoundsWon , ( int ) Core . RoundsLost , TimeString ( Core . TotalPlayingTime ) . getData ( ) , Core . Comment ) . getData ( ) , & C4Startup : : Get ( ) - > Graphics . BookFont , ClrPlayerItem , false , false ) ;
2009-05-08 13:28:41 +00:00
if ( Core . LastRound . Title [ 0 ] )
pSelectionInfo - > AddTextLine ( FormatString ( LoadResStr ( " IDS_DESC_LASTGAME " ) , Core . LastRound . Title . getData ( ) , DateString ( Core . LastRound . Date ) . getData ( ) , TimeString ( Core . LastRound . Duration ) . getData ( ) , ( int ) Core . LastRound . FinalScore ) . getData ( ) , & C4Startup : : Get ( ) - > Graphics . BookFont , ClrPlayerItem , false , false ) ;
pSelectionInfo - > UpdateHeight ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
StdStrBuf C4StartupPlrSelDlg : : PlayerListItem : : GetDelWarning ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf sWarning ;
sWarning . Format ( LoadResStr ( " IDS_MSG_DELETEPLR " ) , Core . PrefName ) ;
int32_t iPlrTime = Core . TotalPlayingTime ;
if ( iPlrTime > 60 * 60 * 10 )
sWarning . Append ( FormatString ( LoadResStr ( " IDS_MSG_DELETEPLR_PLAYTIME " ) ,
2010-03-28 18:58:01 +00:00
TimeString ( iPlrTime ) . getData ( ) ) . getData ( ) ) ;
2009-05-08 13:28:41 +00:00
return sWarning ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupPlrSelDlg : : PlayerListItem : : MoveFilename ( const char * szToFilename )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// anything to do?
2011-08-05 00:43:11 +00:00
if ( ItemIdentical ( GetFilename ( ) . getData ( ) , szToFilename ) ) return true ;
2009-05-08 13:28:41 +00:00
// do it
2011-08-05 00:43:11 +00:00
StdStrBuf PathFrom ( Config . General . UserDataPath ) ;
PathFrom . Append ( GetFilename ( ) ) ;
StdStrBuf PathTo ( Config . General . UserDataPath ) ;
PathTo . Append ( szToFilename ) ;
if ( ! MoveItem ( PathFrom . getData ( ) , PathTo . getData ( ) ) ) return false ;
2009-05-08 13:28:41 +00:00
// reflect change in class
SetFilename ( StdStrBuf ( szToFilename ) ) ;
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// ------------------------------------------------
// --- C4StartupPlrSelDlg::CrewListItem
C4StartupPlrSelDlg : : CrewListItem : : CrewListItem ( C4StartupPlrSelDlg * pForDlg , C4GUI : : ListBox * pForListBox , uint32_t dwPlrClr )
2016-11-02 23:58:02 +00:00
: ListItem ( pForDlg , pForListBox , nullptr , false ) , fLoaded ( false ) , dwPlrClr ( dwPlrClr ) , pParentGrp ( nullptr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
SetIcon ( C4GUI : : Ico_Wait ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : UpdateClonkEnabled ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! fLoaded ) return ;
Core . Participation = pCheck - > GetChecked ( ) ;
// immediate save of changes
RewriteCore ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : Load ( C4Group & rGrp , const StdStrBuf & rsFilename )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// backup filename (doesn't include path)
SetFilename ( rsFilename ) ;
// load core
C4Group CrewGroup ;
if ( ! CrewGroup . OpenAsChild ( & rGrp , rsFilename . getData ( ) ) )
throw LoadError ( FormatString ( " Error loading crew file from %s in %s: Error opening group: %s " ,
2010-03-28 18:58:01 +00:00
rsFilename . getData ( ) , rGrp . GetFullName ( ) . getData ( ) , CrewGroup . GetError ( ) ) ) ;
2009-05-08 13:28:41 +00:00
if ( ! Core . Load ( CrewGroup ) )
throw LoadError ( FormatString ( " Error loading crew file from %s: Core data invalid or missing (Group: %s)! " ,
2010-03-28 18:58:01 +00:00
CrewGroup . GetFullName ( ) . getData ( ) , CrewGroup . GetError ( ) ) ) ;
2009-05-08 13:28:41 +00:00
ListItem : : SetName ( Core . Name ) ;
pCheck - > SetChecked ( ! ! Core . Participation ) ;
// load rank as icon
C4FacetSurface fctIcon ;
if ( fctIcon . Load ( CrewGroup , C4CFN_ClonkRank , C4FCT_Full , C4FCT_Full , false , true ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
GrabIcon ( fctIcon ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no custom icon: create default by rank system
2009-06-05 15:19:15 +00:00
if ( C4RankSystem : : DrawRankSymbol ( & fctIcon , Core . Rank , & : : GraphicsResource . fctRank , : : GraphicsResource . iNumRanks , true ) )
2009-05-08 13:28:41 +00:00
GrabIcon ( fctIcon ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// backup group loaded from - assumes it stays valid!
pParentGrp = & rGrp ;
// load success!
fLoaded = true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : ContextMenu * C4StartupPlrSelDlg : : CrewListItem : : ContextMenu ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// menu operations work on selected item only
pPlrSelDlg - > SetSelection ( this ) ;
// context menu operations
C4GUI : : ContextMenu * pCtx = new C4GUI : : ContextMenu ( ) ;
pCtx - > AddItem ( LoadResStr ( " IDS_BTN_RENAME " ) , LoadResStr ( " IDS_DESC_CREWRENAME " ) , C4GUI : : Ico_None , new C4GUI : : CBMenuHandler < C4StartupPlrSelDlg > ( pPlrSelDlg , & C4StartupPlrSelDlg : : OnPropertyCtx ) ) ;
pCtx - > AddItem ( LoadResStr ( " IDS_BTN_DELETE " ) , LoadResStr ( " IDS_MSG_DELETECLONK_DESC " ) , C4GUI : : Ico_None , new C4GUI : : CBMenuHandler < C4StartupPlrSelDlg > ( pPlrSelDlg , & C4StartupPlrSelDlg : : OnDelCtx ) ) ;
pCtx - > AddItem ( LoadResStr ( " IDS_MSG_SETDEATHMESSAGE " ) , LoadResStr ( " IDS_MSG_SETTHEMESSAGETHATAPPEARWH " ) , C4GUI : : Ico_None , new C4GUI : : CBMenuHandler < C4StartupPlrSelDlg : : CrewListItem > ( this , & C4StartupPlrSelDlg : : CrewListItem : : OnDeathMessageCtx ) ) ;
return pCtx ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : OnDeathMessageCtx ( C4GUI : : Element * el )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Death message dialog
C4GUI : : InputDialog * pDlg ;
GetScreen ( ) - > ShowRemoveDlg ( pDlg = new C4GUI : : InputDialog ( LoadResStr ( " IDS_MSG_ENTERNEWDEATHMESSAGE " ) , LoadResStr ( " IDS_MSG_SETDEATHMESSAGE " ) , C4GUI : : Ico_Ex_Comment , new C4GUI : : InputCallback < C4StartupPlrSelDlg : : CrewListItem > ( this , & C4StartupPlrSelDlg : : CrewListItem : : OnDeathMessageSet ) , false ) ) ;
pDlg - > SetMaxText ( C4MaxDeathMsg ) ;
pDlg - > SetInputText ( Core . DeathMessage ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : OnDeathMessageSet ( const StdStrBuf & rsNewMessage )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// copy msg
if ( ! rsNewMessage ) * Core . DeathMessage = ' \0 ' ; else SCopy ( rsNewMessage . getData ( ) , Core . DeathMessage , C4MaxDeathMsg ) ;
// save
RewriteCore ( ) ;
// acoustic feedback
2015-12-15 06:41:25 +00:00
C4GUI : : GUISound ( " UI::Confirmed " ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : RewriteCore ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! fLoaded ) return ;
C4Group CrewGroup ;
if ( ! CrewGroup . OpenAsChild ( pParentGrp , GetFilename ( ) . getData ( ) )
2016-11-02 23:58:02 +00:00
| | ! Core . Save ( CrewGroup , nullptr )
2010-03-28 18:58:01 +00:00
| | ! CrewGroup . Close ( ) | | ! pParentGrp - > Save ( true ) )
{
2009-05-08 13:28:41 +00:00
GetScreen ( ) - > ShowMessage ( LoadResStr ( " IDS_FAIL_MODIFY " ) , " " , C4GUI : : Ico_Error ) ;
return ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupPlrSelDlg : : CrewListItem : : SetName ( const char * szNewName )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! fLoaded ) return false ;
// validate name
if ( ! szNewName | | ! * szNewName ) return false ;
if ( SEqual ( szNewName , Core . Name ) ) return true ;
// generate filename from new name
char fn [ _MAX_PATH + 1 ] ;
SCopy ( szNewName , fn , _MAX_PATH ) ;
MakeFilenameFromTitle ( fn ) ;
if ( ! * fn ) return false ;
2011-03-13 15:56:26 +00:00
SAppend ( " .oci " , fn , _MAX_PATH ) ;
2009-05-08 13:28:41 +00:00
// check if a rename is due
if ( ! ItemIdentical ( fn , GetFilename ( ) . getData ( ) ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// check for duplicate filename
if ( pParentGrp - > FindEntry ( fn ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf sMsg ; sMsg . Format ( LoadResStr ( " IDS_ERR_CLONKCOLLISION " ) , fn ) ;
2009-06-05 16:53:56 +00:00
: : pGUI - > ShowMessageModal ( sMsg . getData ( ) , LoadResStr ( " IDS_FAIL_RENAME " ) , C4GUI : : MessageDialog : : btnOK , C4GUI : : Ico_Error ) ;
2009-05-08 13:28:41 +00:00
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// OK; then rename
2009-08-15 18:50:32 +00:00
if ( ! pParentGrp - > Rename ( GetFilename ( ) . getData ( ) , fn ) | | ! pParentGrp - > Save ( true ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf sMsg ; sMsg . Format ( LoadResStr ( " IDS_ERR_RENAMEFILE " ) , GetFilename ( ) . getData ( ) , fn ) ;
2009-06-05 16:53:56 +00:00
: : pGUI - > ShowMessageModal ( sMsg . getData ( ) , LoadResStr ( " IDS_FAIL_RENAME " ) , C4GUI : : MessageDialog : : btnOK , C4GUI : : Ico_Error ) ;
2009-05-08 13:28:41 +00:00
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
const char * szConstFn = fn ;
SetFilename ( StdStrBuf ( szConstFn ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// update clonk name and core
ListItem : : SetName ( szNewName ) ;
SCopy ( szNewName , Core . Name , C4MaxName ) ;
RewriteCore ( ) ;
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : SetSelectionInfo ( C4GUI : : TextWindow * pSelectionInfo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// write info text for player
pSelectionInfo - > ClearText ( false ) ;
pSelectionInfo - > AddTextLine ( FormatString ( " %s %s " , Core . sRankName . getData ( ) , Core . Name ) . getData ( ) , & C4Startup : : Get ( ) - > Graphics . BookFontCapt , ClrPlayerItem , false , false ) ;
StdStrBuf sPromo ;
int32_t iNextRankExp ; StdStrBuf sNextRankName ;
2009-06-05 15:13:33 +00:00
if ( Core . GetNextRankInfo ( : : DefaultRanks , & iNextRankExp , & sNextRankName ) )
2009-05-08 13:28:41 +00:00
sPromo . Format ( LoadResStr ( " IDS_DESC_PROMO " ) , sNextRankName . getData ( ) , ( int ) iNextRankExp ) ;
else
sPromo . Copy ( LoadResStr ( " IDS_DESC_NOPROMO " ) ) ;
pSelectionInfo - > AddTextLine ( FormatString ( LoadResStr ( " IDS_DESC_OBJECT " ) ,
2010-03-28 18:58:01 +00:00
Core . TypeName , Core . Experience , Core . Rounds , Core . DeathCount ,
sPromo . getData ( ) , TimeString ( Core . TotalPlayingTime ) . getData ( ) , DateString ( Core . Birthday ) . getData ( ) ) . getData ( ) ,
& C4Startup : : Get ( ) - > Graphics . BookFont , ClrPlayerItem , false , false ) ;
2009-05-08 13:28:41 +00:00
pSelectionInfo - > UpdateHeight ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
StdStrBuf C4StartupPlrSelDlg : : CrewListItem : : GetDelWarning ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf sWarning ;
sWarning . Format ( LoadResStr ( " IDS_MSG_DELETECLONK " ) ,
2010-03-28 18:58:01 +00:00
Core . sRankName . getData ( ) , Core . Name , GetFilename ( ) . getData ( ) ) ;
2009-05-08 13:28:41 +00:00
int32_t iPlrTime = Core . TotalPlayingTime ;
if ( iPlrTime > 60 * 60 * 10 )
sWarning . Append ( static_cast < const StdStrBuf & > ( FormatString ( LoadResStr ( " IDS_MSG_DELETECLONK_PLAYTIME " ) , TimeString ( iPlrTime ) . getData ( ) ) ) ) ;
return sWarning ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : CrewRename ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( pPlrSelDlg - > pRenameEdit ) return ;
// rename this entry
pPlrSelDlg - > pRenameEdit = new C4GUI : : CallbackRenameEdit < C4StartupPlrSelDlg : : CrewListItem , RenameParams > ( pNameLabel , this , RenameParams ( ) , & C4StartupPlrSelDlg : : CrewListItem : : DoRenaming , & C4StartupPlrSelDlg : : CrewListItem : : AbortRenaming ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : CrewListItem : : AbortRenaming ( RenameParams par )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no renaming
2016-11-02 23:58:02 +00:00
pPlrSelDlg - > pRenameEdit = nullptr ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : RenameEdit : : RenameResult C4StartupPlrSelDlg : : CrewListItem : : DoRenaming ( RenameParams par , const char * szNewName )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// accept if name can be set; will fail if name is invalid or already given to another Crew member
if ( ! SetName ( szNewName ) ) return C4GUI : : RenameEdit : : RR_Invalid ;
2016-11-02 23:58:02 +00:00
pPlrSelDlg - > pRenameEdit = nullptr ;
2009-05-08 13:28:41 +00:00
// update in selection
C4StartupPlrSelDlg * pDlg = static_cast < C4StartupPlrSelDlg * > ( GetDlg ( ) ) ;
if ( pDlg & & pDlg - > GetSelection ( ) = = this ) pDlg - > UpdateSelection ( ) ;
return C4GUI : : RenameEdit : : RR_Accepted ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// ------------------------------------------------
// --- C4StartupPlrSelDlg
2017-05-07 11:50:00 +00:00
C4StartupPlrSelDlg : : C4StartupPlrSelDlg ( ) : C4StartupDlg ( " W " )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// ctor
UpdateSize ( ) ; // for clientrect
// screen calculations
int iButtonHeight = C4GUI_ButtonHgt ;
int iButtonXSpacing = ( GetClientRect ( ) . Wdt > 700 ) ? GetClientRect ( ) . Wdt / 58 : 2 ;
int iButtonCount = 6 ;
C4GUI : : ComponentAligner caMain ( GetClientRect ( ) , 0 , 0 , true ) ;
2015-11-15 12:53:01 +00:00
C4GUI : : ComponentAligner caButtonArea ( caMain . GetFromBottom ( std : : max ( caMain . GetHeight ( ) / 15 , iButtonHeight ) ) , 0 , 0 ) ;
2009-05-08 13:28:41 +00:00
rcBottomButtons = caButtonArea . GetCentered ( caMain . GetWidth ( ) , iButtonHeight ) ;
iBottomButtonWidth = ( caButtonArea . GetWidth ( ) - iButtonXSpacing * ( iButtonCount - 1 ) ) / iButtonCount ;
C4Rect rcMain = caMain . GetAll ( ) ;
2013-05-26 15:51:35 +00:00
C4Rect rcPlrList = C4Rect ( rcMain . Wdt / 8 , rcMain . Hgt / 8 , rcMain . Wdt * 5 / 16 , rcMain . Hgt * 6 / 8 ) ;
C4Rect rcInfoWindow = C4Rect ( rcMain . Wdt * 9 / 16 , rcMain . Hgt / 8 , rcMain . Wdt * 5 / 16 , rcMain . Hgt * 6 / 8 ) ;
2009-05-08 13:28:41 +00:00
AddElement ( pPlrListBox = new C4GUI : : ListBox ( rcPlrList ) ) ;
pPlrListBox - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_PLAYERFILES " ) ) ;
2013-05-26 15:51:35 +00:00
pPlrListBox - > SetDecoration ( true , & C4Startup : : Get ( ) - > Graphics . sfctBookScroll , true ) ;
2009-05-08 13:28:41 +00:00
pPlrListBox - > UpdateElementPositions ( ) ;
pPlrListBox - > SetSelectionChangeCallbackFn ( new C4GUI : : CallbackHandler < C4StartupPlrSelDlg > ( this , & C4StartupPlrSelDlg : : OnSelChange ) ) ;
pPlrListBox - > SetSelectionDblClickFn ( new C4GUI : : CallbackHandler < C4StartupPlrSelDlg > ( this , & C4StartupPlrSelDlg : : OnSelDblClick ) ) ;
2016-11-02 23:58:02 +00:00
AddElement ( pSelectionInfo = new C4GUI : : TextWindow ( rcInfoWindow , 0 , 0 , 0 , 100 , 4096 , " " , false , nullptr , 0 , true ) ) ;
2013-05-26 15:51:35 +00:00
pSelectionInfo - > SetDecoration ( true , true , & C4Startup : : Get ( ) - > Graphics . sfctBookScroll , true ) ;
2009-05-08 13:28:41 +00:00
pSelectionInfo - > UpdateHeight ( ) ;
// bottom line buttons - positioning done in UpdateBottomButtons by UpdatePlayerList
C4Rect rcDefault ( 0 , 0 , 10 , 10 ) ;
AddElement ( btnBack = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( LoadResStr ( " IDS_BTN_BACK " ) , rcDefault , & C4StartupPlrSelDlg : : OnBackBtn ) ) ;
AddElement ( btnNew = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( LoadResStr ( " IDS_BTN_NEW " ) , rcDefault , & C4StartupPlrSelDlg : : OnNewBtn ) ) ;
btnNew - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_NEWPLAYER " ) ) ;
2016-11-02 23:58:02 +00:00
AddElement ( btnActivatePlr = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( nullptr , rcDefault , & C4StartupPlrSelDlg : : OnActivateBtn ) ) ;
2009-05-08 13:28:41 +00:00
AddElement ( btnDelete = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( LoadResStr ( " IDS_BTN_DELETE " ) , rcDefault , & C4StartupPlrSelDlg : : OnDelBtn ) ) ;
2016-11-02 23:58:02 +00:00
AddElement ( btnProperties = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( nullptr , rcDefault , & C4StartupPlrSelDlg : : OnPropertyBtn ) ) ;
2009-05-08 13:28:41 +00:00
AddElement ( btnCrew = new C4GUI : : CallbackButton < C4StartupPlrSelDlg > ( LoadResStr ( " IDS_SELECT_CREW " ) , rcDefault , & C4StartupPlrSelDlg : : OnCrewBtn ) ) ;
btnCrew - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_PLAYERCREW " ) ) ;
// refill listboxes
UpdatePlayerList ( ) ;
// Just safety incase listbox was empty, in which case no selection change callback will have been done:
// Update current listbox selection to that of no selected item
if ( ! pPlrListBox - > GetFirst ( ) ) UpdateSelection ( ) ;
// initial focus on player list
SetFocus ( pPlrListBox , false ) ;
// key bindings
C4CustomKey : : CodeList keys ;
2017-05-03 18:28:00 +00:00
keys . emplace_back ( K_BACK ) ;
keys . emplace_back ( K_LEFT ) ;
keys . emplace_back ( K_ESCAPE ) ;
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 : : Cancel ( keys ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
pKeyBack = new C4KeyBinding ( keys , " StartupPlrSelBack " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCB < C4StartupPlrSelDlg > ( * this , & C4StartupPlrSelDlg : : KeyBack ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2009-05-08 13:28:41 +00:00
pKeyProperties = new C4KeyBinding ( C4KeyCodeEx ( K_F2 ) , " StartupPlrSelProp " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCB < C4StartupPlrSelDlg > ( * this , & C4StartupPlrSelDlg : : KeyProperties ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2009-05-08 13:28:41 +00:00
pKeyCrew = new C4KeyBinding ( C4KeyCodeEx ( K_RIGHT ) , " StartupPlrSelCrew " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : ControlKeyDlgCB < C4StartupPlrSelDlg > ( pPlrListBox , * this , & C4StartupPlrSelDlg : : KeyCrew ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2009-05-08 13:28:41 +00:00
pKeyDelete = new C4KeyBinding ( C4KeyCodeEx ( K_DELETE ) , " StartupPlrSelDelete " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCB < C4StartupPlrSelDlg > ( * this , & C4StartupPlrSelDlg : : KeyDelete ) , C4CustomKey : : PRIO_CtrlOverride ) ;
2009-05-08 13:28:41 +00:00
pKeyNew = new C4KeyBinding ( C4KeyCodeEx ( K_INSERT ) , " StartupPlrSelNew " , KEYSCOPE_Gui ,
2010-03-28 18:58:01 +00:00
new C4GUI : : DlgKeyCB < C4StartupPlrSelDlg > ( * this , & C4StartupPlrSelDlg : : KeyNew ) , C4CustomKey : : PRIO_CtrlOverride ) ;
}
2009-05-08 13:28:41 +00:00
C4StartupPlrSelDlg : : ~ C4StartupPlrSelDlg ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
delete pKeyDelete ;
delete pKeyCrew ;
delete pKeyProperties ;
delete pKeyBack ;
delete pKeyNew ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : AbortRenaming ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( pRenameEdit ) pRenameEdit - > Abort ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : DrawElement ( C4TargetFacet & cgo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// draw background
2013-05-26 15:51:35 +00:00
typedef C4GUI : : FullscreenDialog Base ;
Base : : DrawElement ( cgo ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : UpdateBottomButtons ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// bottom line buttons depend on list mode
C4GUI : : ComponentAligner caBottomButtons ( rcBottomButtons , 0 , 0 ) ;
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
{
// update some buttons for player mode
btnProperties - > SetText ( LoadResStr ( " IDS_BTN_PROPERTIES " ) ) ;
btnProperties - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_PLAYERPROPERTIES " ) ) ;
btnNew - > SetVisibility ( true ) ;
btnCrew - > SetVisibility ( true ) ;
btnDelete - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_PLAYERDELETE " ) ) ;
btnBack - > SetToolTip ( LoadResStr ( " IDS_DLGTIP_BACKMAIN " ) ) ;
btnBack - > SetBounds ( caBottomButtons . GetGridCell ( 0 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnNew - > SetBounds ( caBottomButtons . GetGridCell ( 1 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnActivatePlr - > SetBounds ( caBottomButtons . GetGridCell ( 2 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnDelete - > SetBounds ( caBottomButtons . GetGridCell ( 3 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnProperties - > SetBounds ( caBottomButtons . GetGridCell ( 4 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnCrew - > SetBounds ( caBottomButtons . GetGridCell ( 5 , 6 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
}
break ;
case PSDM_Crew :
{
// update some buttons for player mode
btnProperties - > SetText ( LoadResStr ( " IDS_BTN_RENAME " ) ) ;
btnProperties - > SetToolTip ( LoadResStr ( " IDS_DESC_CREWRENAME " ) ) ;
btnNew - > SetVisibility ( false ) ;
btnCrew - > SetVisibility ( false ) ;
btnDelete - > SetToolTip ( LoadResStr ( " IDS_MSG_DELETECLONK_DESC " ) ) ;
btnBack - > SetToolTip ( LoadResStr ( " IDS_MSG_BACKTOPLAYERDLG " ) ) ;
btnBack - > SetBounds ( caBottomButtons . GetGridCell ( 0 , 4 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnActivatePlr - > SetBounds ( caBottomButtons . GetGridCell ( 1 , 4 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnDelete - > SetBounds ( caBottomButtons . GetGridCell ( 2 , 4 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
btnProperties - > SetBounds ( caBottomButtons . GetGridCell ( 3 , 4 , 0 , 1 , iBottomButtonWidth , C4GUI_ButtonHgt , true ) ) ;
}
break ;
} ;
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : UpdatePlayerList ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// something has changed!
AbortRenaming ( ) ;
// refill pPlrListBox with players in player folder or crew
// clear old items
C4GUI : : Element * pEl ;
2010-01-25 04:00:59 +00:00
while ( ( pEl = pPlrListBox - > GetFirst ( ) ) ) delete pEl ;
2009-05-08 13:28:41 +00:00
// update command buttons
UpdateBottomButtons ( ) ;
// create new
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
{
SetTitle ( LoadResStrNoAmp ( " IDS_DLG_PLAYERSELECTION " ) ) ;
// player mode: insert all players
const char * szFn ;
StdStrBuf sSearchPath ( Config . General . UserDataPath ) ;
2016-11-02 23:58:02 +00:00
PlayerListItem * pFirstActivatedPlrItem = nullptr , * pFirstDeactivatedPlrItem = nullptr , * pPlrItem = nullptr ;
2010-03-28 18:58:01 +00:00
for ( DirectoryIterator i ( sSearchPath . getData ( ) ) ; ( szFn = * i ) ; i + + )
2009-05-08 13:28:41 +00:00
{
2010-03-28 18:58:01 +00:00
szFn = Config . AtRelativePath ( szFn ) ;
if ( * GetFilename ( szFn ) = = ' . ' ) continue ; // ignore ".", ".." and private files (".*")
if ( ! WildcardMatch ( C4CFN_PlayerFiles , GetFilename ( szFn ) ) ) continue ;
2016-11-02 23:58:02 +00:00
bool fIsParticipating = ! ! SIsModule ( Config . General . Participants , szFn , nullptr , false ) ;
pPlrItem = new PlayerListItem ( this , pPlrListBox , nullptr , fIsParticipating ) ;
2010-03-28 18:58:01 +00:00
try
2009-05-08 13:28:41 +00:00
{
2010-03-28 18:58:01 +00:00
pPlrItem - > Load ( StdStrBuf ( szFn ) ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
catch ( ListItem : : LoadError & e )
{
// invalid player: ignore but log error message
DebugLog ( e . getData ( ) ) ;
delete pPlrItem ;
continue ;
}
if ( fIsParticipating )
{
if ( ! pFirstActivatedPlrItem ) pFirstActivatedPlrItem = pPlrItem ;
}
else if ( ! pFirstDeactivatedPlrItem ) pFirstDeactivatedPlrItem = pPlrItem ;
}
// select first element; prefer activated player
if ( ! ( pPlrItem = pFirstActivatedPlrItem ) )
pPlrItem = pFirstDeactivatedPlrItem ;
if ( pPlrItem )
pPlrListBox - > SelectEntry ( pPlrItem , false ) ;
// re-validate Game.PlayerFilename
UpdateActivatedPlayers ( ) ;
break ;
}
2009-05-08 13:28:41 +00:00
2010-03-28 18:58:01 +00:00
case PSDM_Crew :
{
SetTitle ( FormatString ( " %s %s " , LoadResStrNoAmp ( " IDS_CTL_CREW " ) , CurrPlayer . Core . PrefName ) . getData ( ) ) ;
// crew mode: Insert complete crew of player (2do: sort)
bool fSucc ; char szFn [ _MAX_PATH + 1 ] ;
2016-11-02 23:58:02 +00:00
for ( fSucc = CurrPlayer . Grp . FindEntry ( C4CFN_ObjectInfoFiles , szFn ) ; fSucc ; fSucc = CurrPlayer . Grp . FindNextEntry ( C4CFN_ObjectInfoFiles , szFn , nullptr , true ) )
2010-03-28 18:58:01 +00:00
{
CrewListItem * pCrewItem = new CrewListItem ( this , pPlrListBox , CurrPlayer . Core . PrefColorDw ) ;
try
2009-05-08 13:28:41 +00:00
{
2010-03-28 18:58:01 +00:00
pCrewItem - > Load ( CurrPlayer . Grp , StdStrBuf ( szFn ) ) ;
}
catch ( ListItem : : LoadError & e )
{
// invalid player: ignore but log error message
DebugLog ( e . getData ( ) ) ;
delete pCrewItem ;
continue ;
2009-05-08 13:28:41 +00:00
}
}
2010-03-28 18:58:01 +00:00
// resort crew by type and experience
ResortCrew ( ) ;
pPlrListBox - > SelectFirstEntry ( false ) ;
break ;
}
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4StartupPlrSelDlg : : ListItem * C4StartupPlrSelDlg : : GetSelection ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get selected item: There's only instances of PlrListItem in this list
return static_cast < ListItem * > ( pPlrListBox - > GetSelectedItem ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : SetSelection ( ListItem * pNewItem )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// update selection in listbox
pPlrListBox - > SelectEntry ( pNewItem , false ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : UpdateSelection ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// something has changed!
AbortRenaming ( ) ;
// get currently selected player
ListItem * pSel = GetSelection ( ) ;
// button text 'activate' if current player is deactivated; 'deactivate' otherwise
if ( pSel & & pSel - > IsActivated ( ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
btnActivatePlr - > SetText ( LoadResStr ( " IDS_BTN_DEACTIVATE " ) ) ;
btnActivatePlr - > SetToolTip ( FormatString ( LoadResStr ( " IDS_MSG_NOPARTICIPATE_DESC " ) , pSel - > GetName ( ) ) . getData ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
btnActivatePlr - > SetText ( LoadResStr ( " IDS_BTN_ACTIVATE " ) ) ;
btnActivatePlr - > SetToolTip ( FormatString ( LoadResStr ( " IDS_MSG_PARTICIPATE_DESC " ) , pSel ? pSel - > GetName ( ) : " " ) . getData ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// no item selected?
if ( ! pSel )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pSelectionInfo - > ClearText ( true ) ;
// 2do: disable buttons
return ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// info text for selection
pSel - > SetSelectionInfo ( pSelectionInfo ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnItemCheckChange ( C4GUI : : Element * pCheckBox )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
2016-01-12 02:28:23 +00:00
// Deselect all other players
2016-11-02 23:58:02 +00:00
for ( ListItem * pEl = static_cast < ListItem * > ( pPlrListBox - > GetFirst ( ) ) ; pEl ! = nullptr ; pEl = pEl - > GetNext ( ) )
2016-01-12 02:28:23 +00:00
if ( pCheckBox & & pEl ! = pCheckBox - > GetParent ( ) )
pEl - > SetActivated ( false ) ;
2010-03-28 18:58:01 +00:00
// update Config.General.Participants
UpdateActivatedPlayers ( ) ;
break ;
case PSDM_Crew :
// update affected crew item
if ( pCheckBox ) static_cast < CrewListItem * > ( pCheckBox - > GetParent ( ) ) - > UpdateClonkEnabled ( ) ;
break ;
}
2009-05-08 13:28:41 +00:00
// update player selection text
UpdateSelection ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : UpdateActivatedPlayers ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
assert ( eMode = = PSDM_Player ) ;
// refill Config.General.Participants-list
* Config . General . Participants = ' \0 ' ;
for ( ListItem * pPlrItem = static_cast < ListItem * > ( pPlrListBox - > GetFirst ( ) ) ; pPlrItem ; pPlrItem = pPlrItem - > GetNext ( ) )
if ( pPlrItem - > IsActivated ( ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
const char * szAddFilename = pPlrItem - > GetFilename ( ) . getData ( ) ;
2010-01-25 04:00:59 +00:00
if ( std : : strlen ( Config . General . Participants ) + 1 + std : : strlen ( szAddFilename ) < sizeof ( Config . General . Participants ) )
2009-05-08 13:28:41 +00:00
SAddModule ( Config . General . Participants , szAddFilename ) ;
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pPlrItem - > SetActivated ( false ) ;
GetScreen ( ) - > ShowMessage ( FormatString ( LoadResStr ( " IDS_ERR_PLAYERSTOOLONG " ) , pPlrItem - > GetName ( ) ) . getData ( ) , LoadResStr ( " IDS_ERR_TITLE " ) , C4GUI : : Ico_Error ) ;
}
2010-03-28 18:58:01 +00:00
}
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnActivateBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// toggle activation state of current item
// get currently selected player
ListItem * pSel = GetSelection ( ) ;
if ( ! pSel ) return ;
pSel - > SetActivated ( ! pSel - > IsActivated ( ) ) ;
// update stuff
2016-01-12 02:28:23 +00:00
OnItemCheckChange ( pSel - > GetCheckBox ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : DoBack ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
{
// back 2 main
C4Startup : : Get ( ) - > SwitchDialog ( C4Startup : : SDID_Back ) ;
break ;
}
2009-05-08 13:28:41 +00:00
2010-03-28 18:58:01 +00:00
case PSDM_Crew :
// back 2 player list
SetPlayerMode ( ) ;
break ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnNewBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( eMode ! = PSDM_Player ) return ;
C4GUI : : Dialog * pDlg ;
2016-11-02 23:58:02 +00:00
GetScreen ( ) - > ShowRemoveDlg ( pDlg = new C4StartupPlrPropertiesDlg ( nullptr , this ) ) ;
2015-11-15 12:53:01 +00:00
pDlg - > SetPos ( std : : min < int32_t > ( GetBounds ( ) . Wdt / 10 , GetBounds ( ) . Wdt - pDlg - > GetBounds ( ) . Wdt ) , std : : min < int32_t > ( GetBounds ( ) . Hgt / 4 , GetBounds ( ) . Hgt - pDlg - > GetBounds ( ) . Hgt ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupPlrSelDlg : : CheckPlayerName ( const StdStrBuf & Playername , StdStrBuf & Filename , const StdStrBuf * pPrevFilename , bool fWarnEmpty )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// must not be empty
if ( ! Playername . getLength ( ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( fWarnEmpty ) C4GUI : : Screen : : GetScreenS ( ) - > ShowMessage ( LoadResStr ( " IDS_ERR_PLRNAME_EMPTY " ) , " " , C4GUI : : Ico_Error ) ;
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// generate valid filename
2014-06-05 01:09:46 +00:00
Filename . Copy ( Playername ) ;
2009-05-08 13:28:41 +00:00
// Slashes in Filenames are no good
SReplaceChar ( Filename . getMData ( ) , ' \\ ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' / ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' : ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' * ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' ? ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' " ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' < ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' > ' , ' _ ' ) ;
SReplaceChar ( Filename . getMData ( ) , ' | ' , ' _ ' ) ;
if ( * Filename . getData ( ) = = ' . ' ) * Filename . getMData ( ) = ' _ ' ;
2011-03-13 15:39:48 +00:00
Filename . Append ( " .ocp " ) ;
2009-05-08 13:28:41 +00:00
StdStrBuf Path ( Config . General . UserDataPath ) ; // start at local path
2011-08-05 00:43:11 +00:00
2009-05-08 13:28:41 +00:00
Path . Append ( Filename ) ;
// validity check: Must not exist yet if renamed
2010-02-08 19:58:48 +00:00
if ( ! pPrevFilename | | ! ItemIdentical ( Path . getData ( ) , Config . AtUserDataPath ( pPrevFilename - > getData ( ) ) ) ) if ( ItemExists ( Path . getData ( ) ) )
2011-08-05 00:43:11 +00:00
{
C4GUI : : Screen : : GetScreenS ( ) - > ShowMessage ( FormatString ( LoadResStr ( " IDS_ERR_PLRNAME_TAKEN " ) ,
Playername . getData ( ) ) . getData ( ) , " " , C4GUI : : Ico_Error ) ;
return false ;
}
2009-05-08 13:28:41 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnCrewBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// display crew for activated player
if ( eMode ! = PSDM_Player ) return ;
PlayerListItem * pSel = static_cast < PlayerListItem * > ( GetSelection ( ) ) ;
if ( ! pSel ) return ;
SetCrewMode ( pSel ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : SetPlayerMode ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// change view to listing players
2015-12-15 05:25:19 +00:00
C4GUI : : GUISound ( " UI::Close " ) ;
2009-05-08 13:28:41 +00:00
StdStrBuf LastPlrFilename ;
LastPlrFilename . Copy ( static_cast < const StdStrBuf & > ( CurrPlayer . Grp . GetFullName ( ) ) ) ;
CurrPlayer . Grp . Close ( ) ;
eMode = PSDM_Player ;
UpdatePlayerList ( ) ;
SelectItem ( LastPlrFilename , false ) ;
UpdateSelection ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : SetCrewMode ( PlayerListItem * pSel )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// change view to listing crew of a player
CurrPlayer . Core = pSel - > GetCore ( ) ;
2010-04-05 12:16:45 +00:00
StdStrBuf Path ( Config . General . UserDataPath ) ; // start at local path
// Path.Append(Config.General.PlayerPath);
Path . Append ( pSel - > GetFilename ( ) ) ;
if ( ! CurrPlayer . Grp . Open ( Path . getData ( ) ) ) return ;
2009-05-08 13:28:41 +00:00
if ( ! CurrPlayer . Grp . FindEntry ( C4CFN_ObjectInfoFiles ) )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
StdCopyStrBuf strCrew ( FormatString ( " %s %s " , LoadResStrNoAmp ( " IDS_CTL_CREW " ) , CurrPlayer . Core . PrefName ) ) ;
2009-05-08 13:28:41 +00:00
// player has no crew!
GetScreen ( ) - > ShowMessage ( FormatString ( LoadResStr ( " IDS_ERR_PLRNOCREW " ) ,
2010-03-28 18:58:01 +00:00
CurrPlayer . Core . PrefName ) . getData ( ) ,
strCrew . getData ( ) , C4GUI : : Ico_Player ) ;
2009-05-08 13:28:41 +00:00
return ;
2010-03-28 18:58:01 +00:00
}
2015-12-15 05:25:19 +00:00
C4GUI : : GUISound ( " UI::Open " ) ;
2009-05-08 13:28:41 +00:00
eMode = PSDM_Crew ;
UpdatePlayerList ( ) ;
UpdateSelection ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnDelBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// something has changed!
AbortRenaming ( ) ;
// delete selected player
ListItem * pSel = GetSelection ( ) ;
if ( ! pSel ) return ;
StdStrBuf sWarning ; sWarning . Take ( pSel - > GetDelWarning ( ) ) ;
GetScreen ( ) - > ShowRemoveDlg ( new C4GUI : : ConfirmationDialog ( sWarning . getData ( ) , LoadResStr ( " IDS_BTN_DELETE " ) ,
2010-03-28 18:58:01 +00:00
new C4GUI : : CallbackHandlerExPar < C4StartupPlrSelDlg , ListItem * > ( this , & C4StartupPlrSelDlg : : OnDelBtnConfirm , pSel ) , C4GUI : : MessageDialog : : btnYesNo ) ) ;
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnDelBtnConfirm ( ListItem * pSel )
2010-03-28 18:58:01 +00:00
{
2010-04-22 14:48:44 +00:00
StdStrBuf Path ;
2010-04-05 12:16:45 +00:00
2009-05-08 13:28:41 +00:00
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
2010-04-22 14:48:44 +00:00
Path . Append ( Config . General . UserDataPath ) ; // start at local path
Path . Append ( pSel - > GetFilename ( ) ) ;
2010-04-05 12:16:45 +00:00
if ( ! C4Group_DeleteItem ( Path . getData ( ) ) )
2009-05-08 13:28:41 +00:00
{
2010-03-28 18:58:01 +00:00
StdStrBuf sMsg ; sMsg . Copy ( LoadResStr ( " IDS_FAIL_DELETE " ) ) ;
GetScreen ( ) - > ShowMessage ( sMsg . getData ( ) , LoadResStr ( " IDS_DLG_CLEAR " ) , C4GUI : : Ico_Error ) ;
}
break ;
2009-05-08 13:28:41 +00:00
2010-03-28 18:58:01 +00:00
case PSDM_Crew :
2010-04-22 14:48:44 +00:00
if ( ! CurrPlayer . Grp . DeleteEntry ( pSel - > GetFilename ( ) . getData ( ) ) )
2010-03-28 18:58:01 +00:00
{
StdStrBuf sMsg ; sMsg . Copy ( LoadResStr ( " IDS_FAIL_DELETE " ) ) ;
GetScreen ( ) - > ShowMessage ( sMsg . getData ( ) , LoadResStr ( " IDS_DLG_CLEAR " ) , C4GUI : : Ico_Error ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
break ;
}
2009-05-08 13:28:41 +00:00
// update buttons 'n stuff
UpdatePlayerList ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : SelectItem ( const StdStrBuf & Filename , bool fActivate )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// find item
for ( ListItem * pPlrItem = static_cast < ListItem * > ( pPlrListBox - > GetFirst ( ) ) ; pPlrItem ; pPlrItem = pPlrItem - > GetNext ( ) )
if ( ItemIdentical ( pPlrItem - > GetFilename ( ) . getData ( ) , Filename . getData ( ) ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// select it
pPlrListBox - > SelectEntry ( pPlrItem , false ) ;
// activate it
if ( fActivate )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pPlrItem - > SetActivated ( true ) ;
// player activation updates
2016-01-12 02:28:23 +00:00
OnItemCheckChange ( pPlrItem - > GetCheckBox ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// max one
return ;
2010-03-28 18:58:01 +00:00
}
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : OnPropertyBtn ( C4GUI : : Control * btn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// something has changed!
AbortRenaming ( ) ;
switch ( eMode )
2010-03-28 18:58:01 +00:00
{
case PSDM_Player :
{
// show property dialog for selected player
PlayerListItem * pSel = static_cast < PlayerListItem * > ( GetSelection ( ) ) ;
if ( ! pSel ) return ;
C4GUI : : Dialog * pDlg ;
GetScreen ( ) - > ShowRemoveDlg ( pDlg = new C4StartupPlrPropertiesDlg ( pSel , this ) ) ;
2015-11-15 12:53:01 +00:00
pDlg - > SetPos ( std : : min < int32_t > ( GetBounds ( ) . Wdt / 10 , GetBounds ( ) . Wdt - pDlg - > GetBounds ( ) . Wdt ) ,
2010-03-28 18:58:01 +00:00
( GetBounds ( ) . Hgt - pDlg - > GetBounds ( ) . Hgt ) / 2 ) ;
}
break ;
case PSDM_Crew :
// rename crew
CrewListItem * pSel = static_cast < CrewListItem * > ( GetSelection ( ) ) ;
if ( ! pSel ) return ;
pSel - > CrewRename ( ) ;
break ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
/* -- Crew sorting -- */
struct C4StartupPlrSelDlg_CrewSortDataEntry
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int32_t iMaxExp ;
C4ID idType ;
C4StartupPlrSelDlg_CrewSortDataEntry ( int32_t iMaxExp , C4ID idType ) : iMaxExp ( iMaxExp ) , idType ( idType ) { }
2010-03-28 18:58:01 +00:00
} ;
2009-05-08 13:28:41 +00:00
class C4StartupPlrSelDlg_CrewSortDataMatchType
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4ID idType ;
2010-03-28 18:58:01 +00:00
public :
C4StartupPlrSelDlg_CrewSortDataMatchType ( C4ID idType ) : idType ( idType ) { }
bool operator ( ) ( C4StartupPlrSelDlg_CrewSortDataEntry Check ) { return Check . idType = = idType ; }
} ;
2009-05-08 13:28:41 +00:00
typedef std : : vector < C4StartupPlrSelDlg_CrewSortDataEntry > C4StartupPlrSelDlg_CrewSortData ;
int32_t C4StartupPlrSelDlg : : CrewSortFunc ( const C4GUI : : Element * pEl1 , const C4GUI : : Element * pEl2 , void * par )
2010-03-28 18:58:01 +00:00
{
2017-05-03 18:28:00 +00:00
const auto * pItem1 = static_cast < const CrewListItem * > ( pEl1 ) ;
const auto * pItem2 = static_cast < const CrewListItem * > ( pEl2 ) ;
2009-05-08 13:28:41 +00:00
C4StartupPlrSelDlg_CrewSortData & rSortData = * static_cast < C4StartupPlrSelDlg_CrewSortData * > ( par ) ;
C4StartupPlrSelDlg_CrewSortData : : iterator i = std : : find_if ( rSortData . begin ( ) , rSortData . end ( ) , C4StartupPlrSelDlg_CrewSortDataMatchType ( pItem1 - > GetCore ( ) . id ) ) ,
2010-03-28 18:58:01 +00:00
j = std : : find_if ( rSortData . begin ( ) , rSortData . end ( ) , C4StartupPlrSelDlg_CrewSortDataMatchType ( pItem2 - > GetCore ( ) . id ) ) ;
2009-05-08 13:28:41 +00:00
// primary sort: By Clonk type, where high exp Clonk types are sorted atop low exp Clonk types
if ( i ! = j )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( i = = rSortData . end ( ) ) return - 1 ; else if ( j = = rSortData . end ( ) ) return + 1 ; // can't really happen
return ( * i ) . iMaxExp - ( * j ) . iMaxExp ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// secondary: By experience
return pItem1 - > GetCore ( ) . Experience - pItem2 - > GetCore ( ) . Experience ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrSelDlg : : ResortCrew ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
assert ( eMode = = PSDM_Crew ) ;
// create a list of Clonk types and their respective maximum experience
C4StartupPlrSelDlg_CrewSortData SortData ;
for ( CrewListItem * pCrewItem = static_cast < CrewListItem * > ( pPlrListBox - > GetFirst ( ) ) ; pCrewItem ; pCrewItem = pCrewItem - > GetNext ( ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4StartupPlrSelDlg_CrewSortData : : iterator i = std : : find_if ( SortData . begin ( ) , SortData . end ( ) , C4StartupPlrSelDlg_CrewSortDataMatchType ( pCrewItem - > GetCore ( ) . id ) ) ;
if ( i = = SortData . end ( ) )
2017-05-03 18:28:00 +00:00
SortData . emplace_back ( pCrewItem - > GetCore ( ) . Experience , pCrewItem - > GetCore ( ) . id ) ;
2009-05-08 13:28:41 +00:00
else
2015-11-15 12:53:01 +00:00
( * i ) . iMaxExp = std : : max < int32_t > ( ( * i ) . iMaxExp , pCrewItem - > GetCore ( ) . Experience ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
pPlrListBox - > SortElements ( & CrewSortFunc , & SortData ) ;
}
2009-05-08 13:28:41 +00:00
2011-10-30 19:43:45 +00:00
// ------------------------------------------------
// --- Player color HSV chooser
class C4StartupPlrColorPickerDlg : public C4GUI : : Dialog
{
public :
C4StartupPlrColorPickerDlg ( C4PlayerInfoCore * plrcore ) ;
protected :
// Event handler
2017-05-03 18:28:00 +00:00
void OnClosed ( bool commit ) override ;
2011-10-30 19:43:45 +00:00
private :
class Picker : public C4GUI : : Control
{
public :
Picker ( const C4Rect & bounds ) ;
// Set/retrieve current color value
void SetColor ( uint32_t rgb ) ;
uint32_t GetColor ( ) const ;
protected :
// Event handlers, overridden from C4GUI::Control
2017-05-03 18:28:00 +00:00
void DrawElement ( C4TargetFacet & cgo ) override ;
void MouseInput ( C4GUI : : CMouse & rMouse , int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam ) override ;
void DoDragging ( C4GUI : : CMouse & rMouse , int32_t iX , int32_t iY , DWORD dwKeyParam ) override ;
2011-10-30 19:43:45 +00:00
private :
2013-09-15 13:35:48 +00:00
static const unsigned int HSPickerCursorSize = 5 ;
static const unsigned int VPickerCursorSize = 7 ;
2011-10-30 19:43:45 +00:00
C4FacetSurface hsFacet , vFacet ; // chooser backgrounds
C4Rect hsPickerRect , vPickerRect ;
C4GUI : : Picture * flagPreview , * crewPreview ;
uint32_t hsv ; // current color
2013-09-15 13:43:30 +00:00
enum {
PS_Idle , // user isn't dragging anything
PS_IdleDragging , // user started the drag on empty space
PS_DragHS , // user started the drag over the HS picker
PS_DragV // user started the drag over the V picker
} state ;
2011-10-30 19:43:45 +00:00
bool HandleMouseDown ( int32_t x , int32_t y ) ;
void UpdateVFacet ( uint32_t h , uint32_t s ) ;
void UpdatePreview ( ) ;
} ;
C4PlayerInfoCore * plrcore ;
Picker * picker ;
static uint32_t HSV2RGB ( uint32_t hsv )
{
float h = GetRedValue ( hsv ) / 255.f * 6.f ;
float s = GetGreenValue ( hsv ) / 255.f ;
float v = GetBlueValue ( hsv ) / 255.f ;
float chroma = s * v ;
float x = chroma * ( 1.f - std : : abs ( std : : fmod ( h , 2.f ) - 1.f ) ) ;
float r = 0 ;
float g = 0 ;
float b = 0 ;
switch ( static_cast < int > ( h ) )
{
case 0 : case 6 :
r = chroma ; g = x ; break ;
case 1 :
r = x ; g = chroma ; break ;
case 2 :
g = chroma ; b = x ; break ;
case 3 :
g = x ; b = chroma ; break ;
case 4 :
b = chroma ; r = x ; break ;
case 5 :
b = x ; r = chroma ; break ;
}
r + = v - chroma ;
g + = v - chroma ;
b + = v - chroma ;
return RGBA ( r * 255.f , g * 255.f , b * 255.f , hsv > > 24 ) ;
}
static uint32_t RGB2HSV ( uint32_t rgb )
{
float r = GetRedValue ( rgb ) / 255.f ;
float g = GetGreenValue ( rgb ) / 255.f ;
float b = GetBlueValue ( rgb ) / 255.f ;
float min = std : : min ( r , std : : min ( g , b ) ) ;
float max = std : : max ( r , std : : max ( g , b ) ) ;
float chroma = max - min ;
float hue = 0 ;
if ( r = = max )
hue = std : : fmod ( ( g - b ) / chroma , 6.f ) ;
else if ( g = = max )
hue = ( b - r ) / chroma + 2.f ;
else
hue = ( r - g ) / chroma + 4.f ;
float h = hue / 6.f ;
float s = max = = 0 ? 0.f : chroma / max ;
float v = max ;
return RGBA ( h * 255.f , s * 255.f , v * 255.f , rgb > > 24 ) ;
}
} ;
C4StartupPlrColorPickerDlg : : C4StartupPlrColorPickerDlg ( C4PlayerInfoCore * plrcore )
: Dialog ( 400 , 296 + C4GUI_ButtonAreaHgt , LoadResStr ( " IDS_DLG_PLAYERCOLORSELECTION " ) , false ) , plrcore ( plrcore )
{
C4GUI : : ComponentAligner caMain ( GetClientRect ( ) , 0 , 1 , true ) ;
picker = new Picker ( caMain . GetFromTop ( 280 ) ) ;
picker - > SetColor ( plrcore - > PrefColorDw ) ;
AddElement ( picker ) ;
// buttons
C4GUI : : ComponentAligner caButtonArea ( caMain . GetFromBottom ( C4GUI_ButtonAreaHgt ) , 0 , 0 ) ;
caButtonArea = C4GUI : : ComponentAligner ( caButtonArea . GetCentered ( 2 * 128 + 4 * 8 , C4GUI_ButtonAreaHgt ) , 8 , 8 ) ;
C4GUI : : Button * cancelButton = new C4GUI : : CancelButton ( caButtonArea . GetFromRight ( 128 ) ) ;
C4GUI : : Button * okButton = new C4GUI : : OKButton ( caButtonArea . GetFromRight ( 128 ) ) ;
AddElement ( okButton ) ;
AddElement ( cancelButton ) ;
}
void C4StartupPlrColorPickerDlg : : OnClosed ( bool commit )
{
// Write chosen color back to player core
if ( commit )
plrcore - > PrefColorDw = picker - > GetColor ( ) ;
}
C4StartupPlrColorPickerDlg : : Picker : : Picker ( const C4Rect & bounds )
2013-09-15 13:43:30 +00:00
: Control ( bounds ) , state ( PS_Idle )
2011-10-30 19:43:45 +00:00
{
C4GUI : : ComponentAligner caMain ( bounds , 8 , 8 , true ) ;
caMain . ExpandBottom ( - ( caMain . GetInnerHeight ( ) - 256 ) ) ;
hsPickerRect = caMain . GetFromLeft ( 256 ) ;
2013-09-15 13:35:48 +00:00
vPickerRect = caMain . GetFromLeft ( 16 + VPickerCursorSize ) ;
2011-10-30 19:43:45 +00:00
vPickerRect . Hgt = 256 - PlayerColorValueLowBound ;
C4Facet & flagPreviewPic = : : GraphicsResource . fctFlagClr ;
2012-10-28 14:33:58 +00:00
int preview_width = std : : min < int > ( flagPreviewPic . Wdt , caMain . GetInnerWidth ( ) ) ;
2011-10-30 19:43:45 +00:00
flagPreview = new C4GUI : : Picture ( caMain . GetFromTop ( flagPreviewPic . GetHeightByWidth ( preview_width ) , preview_width ) , true ) ;
flagPreview - > SetFacet ( flagPreviewPic ) ;
AddElement ( flagPreview ) ;
C4Facet & crewPreviewPic = : : GraphicsResource . fctCrewClr ;
2012-10-28 14:33:58 +00:00
preview_width = std : : min < int > ( crewPreviewPic . Wdt , caMain . GetInnerWidth ( ) ) ;
2011-10-30 19:43:45 +00:00
crewPreview = new C4GUI : : Picture ( caMain . GetFromTop ( crewPreviewPic . GetHeightByWidth ( preview_width ) , preview_width ) , true ) ;
crewPreview - > SetFacet ( crewPreviewPic ) ;
AddElement ( crewPreview ) ;
// Pre-draw the H+S chooser background, it never changes anyway
2013-09-15 13:35:48 +00:00
hsFacet . Create ( hsPickerRect . Wdt , hsPickerRect . Hgt ) ;
2011-10-30 19:43:45 +00:00
hsFacet . Surface - > Lock ( ) ;
2013-09-15 13:35:48 +00:00
for ( int y = 0 ; y < hsFacet . Hgt ; + + y )
for ( int x = 0 ; x < hsFacet . Wdt ; + + x )
2011-10-30 19:43:45 +00:00
hsFacet . Surface - > SetPixDw ( x , y , HSV2RGB ( C4RGB ( x , 255 - y , 255 ) ) ) ;
hsFacet . Surface - > Unlock ( ) ;
2013-09-15 13:35:48 +00:00
vFacet . Create ( vPickerRect . Wdt - VPickerCursorSize , vPickerRect . Hgt ) ;
2011-10-30 19:43:45 +00:00
UpdateVFacet ( 255 , 255 ) ;
}
void C4StartupPlrColorPickerDlg : : Picker : : UpdateVFacet ( uint32_t h , uint32_t s )
{
// Draw the V chooser background according to current H+S values
vFacet . Surface - > Lock ( ) ;
2013-09-15 13:35:48 +00:00
for ( int y = 0 ; y < vPickerRect . Hgt ; + + y )
2011-10-30 19:43:45 +00:00
for ( int x = 0 ; x < vFacet . Wdt ; + + x )
vFacet . Surface - > SetPixDw ( x , y , HSV2RGB ( C4RGB ( h , s , 255 - y ) ) ) ;
vFacet . Surface - > Unlock ( ) ;
}
void C4StartupPlrColorPickerDlg : : Picker : : UpdatePreview ( )
{
flagPreview - > SetDrawColor ( HSV2RGB ( hsv ) ) ;
crewPreview - > SetDrawColor ( HSV2RGB ( hsv ) ) ;
}
void C4StartupPlrColorPickerDlg : : Picker : : SetColor ( uint32_t rgb )
{
hsv = RGB2HSV ( rgb ) ;
UpdateVFacet ( GetRedValue ( hsv ) , GetGreenValue ( hsv ) ) ;
UpdatePreview ( ) ;
}
uint32_t C4StartupPlrColorPickerDlg : : Picker : : GetColor ( ) const
{
return HSV2RGB ( hsv ) ;
}
void C4StartupPlrColorPickerDlg : : Picker : : DrawElement ( C4TargetFacet & cgo )
{
// H+S chooser background
C4Facet cgoPicker ( cgo . Surface , cgo . TargetX + hsPickerRect . x , cgo . TargetY + hsPickerRect . y , hsPickerRect . Wdt , hsPickerRect . Hgt ) ;
hsFacet . Draw ( cgoPicker . Surface , cgoPicker . X , cgoPicker . Y ) ;
// H+S cursor
2013-09-15 13:35:48 +00:00
cgoPicker . Wdt = cgoPicker . Hgt = HSPickerCursorSize ;
2011-10-30 19:43:45 +00:00
cgoPicker . X + = GetRedValue ( hsv ) - cgoPicker . Wdt / 2 ;
cgoPicker . Y + = 255 - GetGreenValue ( hsv ) - cgoPicker . Hgt / 2 ;
pDraw - > DrawLineDw ( cgoPicker . Surface , cgoPicker . X , cgoPicker . Y , cgoPicker . X + cgoPicker . Wdt , cgoPicker . Y + cgoPicker . Hgt , C4RGB ( 0 , 0 , 0 ) ) ;
pDraw - > DrawLineDw ( cgoPicker . Surface , cgoPicker . X + cgoPicker . Wdt , cgoPicker . Y , cgoPicker . X , cgoPicker . Y + cgoPicker . Hgt , C4RGB ( 0 , 0 , 0 ) ) ;
// V chooser background
2013-09-15 13:35:48 +00:00
cgoPicker . Set ( cgo . Surface , cgo . TargetX + vPickerRect . x + VPickerCursorSize , cgo . TargetY + vPickerRect . y , vPickerRect . Wdt - VPickerCursorSize , vPickerRect . Hgt ) ;
2011-10-30 19:43:45 +00:00
vFacet . Draw ( cgoPicker . Surface , cgoPicker . X , cgoPicker . Y ) ;
// V cursor
2013-09-15 13:35:48 +00:00
cgoPicker . Wdt = cgoPicker . Hgt = VPickerCursorSize ;
2011-10-30 19:43:45 +00:00
cgoPicker . X - = cgoPicker . Wdt / 2 + 1 ;
cgoPicker . Y + = 255 - GetBlueValue ( hsv ) - cgoPicker . Hgt / 2 ;
for ( int i = 0 ; i < cgoPicker . Hgt / 2 + 1 ; + + i )
pDraw - > DrawLineDw ( cgoPicker . Surface , cgoPicker . X + i , cgoPicker . Y + i , cgoPicker . X + i , cgoPicker . Y + cgoPicker . Hgt - i , C4RGB ( 255 , 255 , 255 ) ) ;
}
bool C4StartupPlrColorPickerDlg : : Picker : : HandleMouseDown ( int32_t x , int32_t y )
{
2013-09-15 13:43:30 +00:00
if ( state = = PS_IdleDragging )
2011-10-30 19:43:45 +00:00
{
2013-09-15 13:43:30 +00:00
// User is dragging something that is neither of the pickers. Ignore.
return false ;
}
// Check if a drag starts or was originally started over a picker
else if ( state = = PS_DragHS | | ( state = = PS_Idle & & hsPickerRect . Contains ( x , y ) ) )
{
2015-02-12 22:05:55 +00:00
int h = Clamp ( x - hsPickerRect . x , 0 , hsPickerRect . Wdt - 1 ) ;
2013-09-15 13:43:30 +00:00
assert ( Inside ( h , 0 , 255 ) ) ;
2015-02-12 22:05:55 +00:00
int s = 255 - Clamp ( y - hsPickerRect . y , 0 , hsPickerRect . Hgt - 1 ) ;
2013-09-15 13:43:30 +00:00
assert ( Inside ( s , 0 , 255 ) ) ;
2011-10-30 19:43:45 +00:00
hsv = C4RGB ( h , s , GetBlueValue ( hsv ) ) ;
UpdateVFacet ( h , s ) ;
UpdatePreview ( ) ;
2013-09-15 13:43:30 +00:00
state = PS_DragHS ;
2011-10-30 19:43:45 +00:00
return true ;
}
2013-09-15 13:43:30 +00:00
else if ( state = = PS_DragV | | ( state = = PS_Idle & & vPickerRect . Contains ( x , y ) ) )
2011-10-30 19:43:45 +00:00
{
2015-02-12 22:05:55 +00:00
int v = 255 - Clamp ( y - vPickerRect . y , 0 , vPickerRect . Hgt - 1 ) ;
2013-09-15 13:43:30 +00:00
assert ( Inside ( v , 0 , 255 ) ) ;
2011-10-30 19:43:45 +00:00
hsv = ( hsv & 0xFFFFFF00 ) | v ;
UpdatePreview ( ) ;
2013-09-15 13:43:30 +00:00
state = PS_DragV ;
2011-10-30 19:43:45 +00:00
return true ;
}
2013-09-15 13:43:30 +00:00
else
{
// Drag started outside of all picker areas; ignore movement until user releases mouse button.
state = PS_IdleDragging ;
return false ;
}
2011-10-30 19:43:45 +00:00
}
void C4StartupPlrColorPickerDlg : : Picker : : MouseInput ( C4GUI : : CMouse & rMouse , int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam )
{
Control : : MouseInput ( rMouse , iButton , iX , iY , dwKeyParam ) ;
2013-09-15 13:43:30 +00:00
if ( ! rMouse . IsLDown ( ) ) state = PS_Idle ;
2011-10-30 19:43:45 +00:00
if ( rMouse . pDragElement ) return ;
if ( rMouse . IsLDown ( ) )
{
if ( HandleMouseDown ( iX , iY ) )
{
rMouse . pDragElement = this ;
2015-12-15 05:25:19 +00:00
C4GUI : : GUISound ( " UI::Select " ) ;
2011-10-30 19:43:45 +00:00
}
else
{
2016-11-02 23:58:02 +00:00
rMouse . pDragElement = nullptr ;
2011-10-30 19:43:45 +00:00
}
}
}
void C4StartupPlrColorPickerDlg : : Picker : : DoDragging ( C4GUI : : CMouse & rMouse , int32_t iX , int32_t iY , DWORD dwKeyParam )
{
HandleMouseDown ( iX , iY ) ;
}
2009-05-08 13:28:41 +00:00
/* ---- Player property dlg ---- */
C4StartupPlrPropertiesDlg : : C4StartupPlrPropertiesDlg ( C4StartupPlrSelDlg : : PlayerListItem * pForPlayer , C4StartupPlrSelDlg * pParentDlg )
2011-08-05 12:58:16 +00:00
: Dialog ( C4Startup : : Get ( ) - > Graphics . fctPlrPropBG . Wdt , C4Startup : : Get ( ) - > Graphics . fctPlrPropBG . Hgt , " " , false ) , pMainDlg ( pParentDlg ) , pForPlayer ( pForPlayer ) , fClearBigIcon ( false )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( pForPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// edit existing player
C4P = pForPlayer - > GetCore ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// create new player: Use default C4P values, with a few exceptions
// FIXME: Use Player, not Clonkranks
2009-06-05 15:13:33 +00:00
C4P . Default ( & : : DefaultRanks ) ;
2009-05-08 13:28:41 +00:00
// Set name, color, comment
SCopy ( LoadResStr ( " IDS_PLR_NEWCOMMENT " ) , C4P . Comment , C4MaxComment ) ;
2016-04-25 15:32:23 +00:00
C4P . PrefColor = UnsyncedRandom ( 8 ) ;
2009-05-08 13:28:41 +00:00
C4P . PrefColorDw = C4P . GetPrefColorValue ( C4P . PrefColor ) ;
2009-10-14 16:46:22 +00:00
C4P . OldPrefControlStyle = 1 ;
C4P . OldPrefAutoContextMenu = 1 ;
2016-02-03 02:07:20 +00:00
C4P . OldPrefControl = 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
const int32_t BetweenElementDist = 2 ;
// use black fonts here
CStdFont * pUseFont = & C4Startup : : Get ( ) - > Graphics . BookFont ;
CStdFont * pSmallFont = & C4Startup : : Get ( ) - > Graphics . BookSmallFont ;
// get positions
UpdateSize ( ) ;
C4GUI : : ComponentAligner caMain ( GetClientRect ( ) , 0 , 1 , true ) ;
C4GUI : : ComponentAligner caButtonArea ( caMain . GetFromBottom ( C4GUI_ButtonAreaHgt ) , 0 , 0 ) ;
// dlg title
const char * szTitle ;
if ( pForPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
szTitle = LoadResStr ( " IDS_DLG_PLAYER2 " ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
szTitle = LoadResStr ( " IDS_PLR_NEWPLAYER " ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
C4GUI : : Label * pLbl = new C4GUI : : Label ( szTitle , caMain . GetFromTop ( pUseFont - > GetLineHeight ( ) ) , ALeft , C4StartupFontClr , pUseFont , false ) ;
AddElement ( pLbl ) ;
caMain . ExpandTop ( - BetweenElementDist ) ;
// place name label
AddElement ( new C4GUI : : Label ( LoadResStr ( " IDS_CTL_NAME2 " ) , caMain . GetFromTop ( pSmallFont - > GetLineHeight ( ) ) , ALeft , C4StartupFontClr , pSmallFont , false ) ) ;
// place name edit
pNameEdit = new C4GUI : : Edit ( caMain . GetFromTop ( C4GUI : : Edit : : GetCustomEditHeight ( pUseFont ) ) ) ;
pNameEdit - > SetFont ( pUseFont ) ;
pNameEdit - > SetColors ( C4StartupEditBGColor , C4StartupFontClr , C4StartupEditBorderColor ) ;
pNameEdit - > InsertText ( C4P . PrefName , false ) ;
pNameEdit - > SetMaxText ( C4MaxName ) ;
AddElement ( pNameEdit ) ;
SetFocus ( pNameEdit , false ) ;
caMain . ExpandTop ( - BetweenElementDist ) ;
2012-01-29 02:16:22 +00:00
int32_t iControlPicSize = C4GUI : : ArrowButton : : GetDefaultHeight ( ) ; // GetGridCell(0,3,0,1,-1,-1,false,2)
int32_t label_hgt = pSmallFont - > GetLineHeight ( ) ;
2009-05-08 13:28:41 +00:00
// place color label
2012-01-29 02:16:22 +00:00
C4GUI : : ComponentAligner caColorArea ( caMain . GetFromTop ( iControlPicSize + BetweenElementDist + label_hgt ) , 2 , 0 ) ;
C4GUI : : ComponentAligner caPictureArea ( caColorArea . GetFromRight ( iControlPicSize , iControlPicSize + BetweenElementDist + label_hgt ) , 2 , 0 ) ;
2009-05-08 13:28:41 +00:00
caColorArea . ExpandLeft ( 2 ) ;
2012-01-29 02:16:22 +00:00
AddElement ( new C4GUI : : Label ( FormatString ( " %s: " , LoadResStr ( " IDS_CTL_COLOR " ) ) . getData ( ) , caColorArea . GetFromTop ( label_hgt ) , ALeft , C4StartupFontClr , pSmallFont , false ) ) ;
caColorArea . ExpandTop ( - BetweenElementDist ) ;
// place picture label
AddElement ( new C4GUI : : Label ( LoadResStr ( " IDS_CTL_PICTURE " ) , caPictureArea . GetFromTop ( label_hgt ) , ALeft , C4StartupFontClr , pSmallFont , false ) ) ;
caPictureArea . ExpandTop ( - BetweenElementDist ) ;
// place color controls
2009-05-08 13:28:41 +00:00
C4GUI : : Button * pBtn ; const char * szTip ;
szTip = LoadResStr ( " IDS_DLGTIP_PLAYERCOLORS " ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Left , caColorArea . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnClrChangeLeft ) ) ;
pBtn - > SetToolTip ( szTip ) ;
2015-03-25 18:04:04 +00:00
C4Facet & rfctClrPreviewPic = : : GraphicsResource . fctFlagClr ;
2011-10-30 19:43:45 +00:00
pClrPreview = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : IconButton > ( C4GUI : : Ico_None , caColorArea . GetFromLeft ( rfctClrPreviewPic . GetWidthByHeight ( caColorArea . GetHeight ( ) ) ) , ' C ' , & C4StartupPlrPropertiesDlg : : OnClrChangeCustom ) ;
2009-05-08 13:28:41 +00:00
pClrPreview - > SetFacet ( rfctClrPreviewPic ) ;
AddElement ( pClrPreview ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Right , caColorArea . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnClrChangeRight ) ) ;
pBtn - > SetToolTip ( szTip ) ;
if ( ! C4P . PrefColorDw ) C4P . PrefColorDw = 0xff ;
2012-01-29 02:16:22 +00:00
// Place picture controls
AddElement ( pPictureBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : IconButton > ( C4GUI : : Ico_Player , caPictureArea . GetAll ( ) , ' P ' /* 2do */ , & C4StartupPlrPropertiesDlg : : OnPictureBtn ) ) ;
pPictureBtn - > SetToolTip ( LoadResStr ( " IDS_DESC_SELECTAPICTUREANDORLOBBYI " ) ) ;
UpdateBigIcon ( ) ;
UpdatePlayerColor ( true ) ;
2009-05-08 13:28:41 +00:00
caMain . ExpandTop ( - BetweenElementDist ) ;
2012-01-29 02:16:22 +00:00
// place control label
C4GUI : : ComponentAligner caControlArea ( caMain . GetFromTop ( iControlPicSize + label_hgt + BetweenElementDist ) , 0 , 0 , false ) ;
C4GUI : : ComponentAligner caSkinArea ( caControlArea . GetFromRight ( iControlPicSize + label_hgt + BetweenElementDist ) , 0 , 0 , false ) ;
AddElement ( new C4GUI : : Label ( FormatString ( " %s: " , LoadResStr ( " IDS_CTL_CONTROL " ) ) . getData ( ) , caControlArea . GetFromTop ( label_hgt ) , ALeft , C4StartupFontClr , pSmallFont , false ) ) ;
caControlArea . ExpandTop ( - BetweenElementDist ) ;
// place clonk style label
AddElement ( new C4GUI : : Label ( LoadResStr ( " IDS_CTL_CLONKSKIN " ) , caSkinArea . GetFromTop ( label_hgt ) , ALeft , C4StartupFontClr , pSmallFont , false ) ) ;
caSkinArea . ExpandTop ( - BetweenElementDist ) ;
2009-05-08 13:28:41 +00:00
// place control controls
C4GUI : : ComponentAligner caControl ( caControlArea . GetFromTop ( iControlPicSize ) , 2 , 0 ) ;
szTip = LoadResStr ( " IDS_DLGTIP_PLAYERCONTROL " ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Left , caControl . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnCtrlChangeLeft ) ) ;
pBtn - > SetToolTip ( szTip ) ;
2012-01-29 02:16:22 +00:00
caControl . ExpandBottom ( label_hgt ) ; C4Rect ctrl_name_rect = caControl . GetFromBottom ( label_hgt ) ;
2009-06-05 15:19:15 +00:00
C4Facet & rfctCtrlPic = : : GraphicsResource . fctKeyboard ; // UpdatePlayerControl() will alternatively set fctGamepad
2009-05-08 13:28:41 +00:00
AddElement ( pCtrlImg = new C4GUI : : Picture ( caControl . GetFromLeft ( rfctCtrlPic . GetWidthByHeight ( caControl . GetHeight ( ) ) ) , true ) ) ;
pCtrlImg - > SetToolTip ( szTip ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Right , caControl . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnCtrlChangeRight ) ) ;
pBtn - > SetToolTip ( szTip ) ;
caControl . ExpandLeft ( - 10 ) ;
2015-02-12 22:05:55 +00:00
C4P . OldPrefControl = Clamp < int32_t > ( C4P . OldPrefControl , 0 , C4MaxControlSet - 1 ) ;
2009-10-14 17:52:40 +00:00
ctrl_name_lbl = new C4GUI : : Label ( " CtrlName " , ctrl_name_rect , ALeft , C4StartupFontClr , pSmallFont , false , false , true ) ;
AddElement ( ctrl_name_lbl ) ;
2009-05-08 13:28:41 +00:00
UpdatePlayerControl ( ) ;
2012-01-29 02:16:22 +00:00
C4GUI : : ComponentAligner caSkin ( caSkinArea . GetFromTop ( iControlPicSize ) , 2 , 0 ) ;
szTip = LoadResStr ( " IDS_DLGTIP_PLAYERCREWSKIN " ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Left , caSkin . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnSkinChangeLeft ) ) ;
pBtn - > SetToolTip ( szTip ) ;
2012-01-29 13:38:18 +00:00
C4Facet rfctSkinPic = : : GraphicsResource . fctClonkSkin . GetPhase ( 0 ) ;
2012-01-29 02:16:22 +00:00
AddElement ( pSkinImg = new C4GUI : : Picture ( caSkin . GetFromLeft ( rfctSkinPic . GetWidthByHeight ( caSkin . GetHeight ( ) ) ) , true ) ) ;
pSkinImg - > SetToolTip ( szTip ) ;
pSkinImg - > SetFacet ( : : GraphicsResource . fctClonkSkin . GetPhase ( 0 ) ) ;
AddElement ( pBtn = new C4GUI : : CallbackButton < C4StartupPlrPropertiesDlg , C4GUI : : ArrowButton > ( C4GUI : : ArrowButton : : Right , caSkin . GetFromLeft ( C4GUI : : ArrowButton : : GetDefaultWidth ( ) ) , & C4StartupPlrPropertiesDlg : : OnSkinChangeRight ) ) ;
pBtn - > SetToolTip ( szTip ) ;
caSkin . ExpandLeft ( - 10 ) ;
UpdatePlayerSkin ( ) ;
2009-05-08 13:28:41 +00:00
caMain . ExpandTop ( - BetweenElementDist ) ;
// place buttons
// OK
C4GUI : : Button * pBtnOK = new C4GUI : : OKIconButton ( C4Rect ( 147 - GetMarginLeft ( ) , 295 + 35 - GetMarginTop ( ) , 54 , 33 ) , C4GUI : : Ico_None ) ;
2015-03-25 18:04:04 +00:00
AddElement ( pBtnOK ) ;
2009-05-08 13:28:41 +00:00
// Cancel
C4GUI : : Button * pBtnAbort = new C4GUI : : CancelIconButton ( C4Rect ( 317 - GetMarginLeft ( ) , 16 - GetMarginTop ( ) , 21 , 21 ) , C4GUI : : Ico_None ) ;
2015-03-25 18:04:04 +00:00
AddElement ( pBtnAbort ) ;
2009-05-08 13:28:41 +00:00
// when called from player selection screen: input dlg always closed in the end
// otherwise, modal proc will delete
if ( pMainDlg ) SetDelOnClose ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : DrawElement ( C4TargetFacet & cgo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Startup : : Get ( ) - > Graphics . fctPlrPropBG . Draw ( cgo . Surface , rcBounds . x + cgo . TargetX , rcBounds . y + cgo . TargetY ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool IsColorConflict ( DWORD dwClr1 , DWORD dwClr2 ) ;
void C4StartupPlrPropertiesDlg : : UpdatePlayerColor ( bool fUpdateSliders )
2009-09-21 18:52:40 +00:00
{
C4P . PrefColorDw = C4P . PrefColorDw | 0xFF000000 ; // Ensure full opacity
2011-10-30 19:43:45 +00:00
pClrPreview - > SetColor ( C4P . PrefColorDw ) ;
2009-05-08 13:28:41 +00:00
pPictureBtn - > SetColor ( C4P . PrefColorDw ) ;
2009-09-21 18:52:40 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnClrChangeLeft ( C4GUI : : Control * pBtn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// previous standard color in list
C4P . PrefColor = C4P . PrefColor ? C4P . PrefColor - 1 : 11 ;
C4P . PrefColorDw = C4PlayerInfoCore : : GetPrefColorValue ( C4P . PrefColor ) ;
UpdatePlayerColor ( true ) ;
2010-03-28 18:58:01 +00:00
}
2011-10-30 19:43:45 +00:00
void C4StartupPlrPropertiesDlg : : OnClrChangeCustom ( C4GUI : : Control * pBtn )
{
GetScreen ( ) - > ShowModalDlg ( new C4StartupPlrColorPickerDlg ( & C4P ) ) ;
UpdatePlayerColor ( true ) ;
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnClrChangeRight ( C4GUI : : Control * pBtn )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// next standard color in list
C4P . PrefColor = ( C4P . PrefColor + 1 ) % 12 ;
C4P . PrefColorDw = C4PlayerInfoCore : : GetPrefColorValue ( C4P . PrefColor ) ;
UpdatePlayerColor ( true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : UpdatePlayerControl ( )
2009-10-14 16:46:22 +00:00
{
2011-03-30 20:11:47 +00:00
C4PlayerControlAssignmentSet * control_set = Game . PlayerControlUserAssignmentSets . GetSetByName ( C4P . PrefControl . getData ( ) ) ;
if ( ! control_set ) control_set = Game . PlayerControlUserAssignmentSets . GetDefaultSet ( ) ;
2009-05-08 13:28:41 +00:00
// update keyboard image of selected control
2009-10-14 16:46:22 +00:00
C4Facet fctCtrlPic ;
if ( control_set ) fctCtrlPic = control_set - > GetPicture ( ) ;
pCtrlImg - > SetFacet ( fctCtrlPic ) ;
2009-10-14 17:52:40 +00:00
if ( control_set )
2012-01-25 04:53:59 +00:00
ctrl_name_lbl - > SetText ( control_set - > GetGUIName ( ) ) ;
2009-10-14 17:52:40 +00:00
else
ctrl_name_lbl - > SetText ( " ??? " ) ;
2009-10-14 16:46:22 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnCtrlChangeLeft ( C4GUI : : Control * pBtn )
2009-10-14 16:46:22 +00:00
{
2009-05-08 13:28:41 +00:00
// previous control set in list
2011-03-30 20:11:47 +00:00
C4PlayerControlAssignmentSet * control_set = Game . PlayerControlUserAssignmentSets . GetSetByName ( C4P . PrefControl . getData ( ) ) ;
int32_t index = Game . PlayerControlUserAssignmentSets . GetSetIndex ( control_set ) ;
2010-02-08 19:58:48 +00:00
if ( index < 0 ) index = 0 ; // defined control set not found - probably an old CR player file
2011-03-30 20:11:47 +00:00
if ( ! index - - ) index = Game . PlayerControlUserAssignmentSets . GetSetCount ( ) - 1 ;
control_set = Game . PlayerControlUserAssignmentSets . GetSetByIndex ( index ) ;
2009-10-14 16:46:22 +00:00
if ( control_set ) C4P . PrefControl = control_set - > GetName ( ) ;
2009-05-08 13:28:41 +00:00
UpdatePlayerControl ( ) ;
2009-10-14 16:46:22 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnCtrlChangeRight ( C4GUI : : Control * pBtn )
2009-10-14 16:46:22 +00:00
{
2009-05-08 13:28:41 +00:00
// next control set in list
2011-03-30 20:11:47 +00:00
C4PlayerControlAssignmentSet * control_set = Game . PlayerControlUserAssignmentSets . GetSetByName ( C4P . PrefControl . getData ( ) ) ;
int32_t index = Game . PlayerControlUserAssignmentSets . GetSetIndex ( control_set ) ;
2010-02-08 19:58:48 +00:00
if ( index < 0 ) index = 0 ; // defined control set not found - probably an old CR player file
2011-03-30 20:11:47 +00:00
if ( + + index > = int32_t ( Game . PlayerControlUserAssignmentSets . GetSetCount ( ) ) ) index = 0 ;
control_set = Game . PlayerControlUserAssignmentSets . GetSetByIndex ( index ) ;
2009-10-14 16:46:22 +00:00
if ( control_set ) C4P . PrefControl = control_set - > GetName ( ) ;
2009-05-08 13:28:41 +00:00
UpdatePlayerControl ( ) ;
2009-10-14 16:46:22 +00:00
}
2009-05-08 13:28:41 +00:00
2012-01-29 02:16:22 +00:00
void C4StartupPlrPropertiesDlg : : UpdatePlayerSkin ( )
2010-03-28 18:58:01 +00:00
{
2012-01-29 02:16:22 +00:00
pSkinImg - > SetFacet ( : : GraphicsResource . fctClonkSkin . GetPhase ( C4P . PrefClonkSkin ) ) ;
}
void C4StartupPlrPropertiesDlg : : OnSkinChangeLeft ( C4GUI : : Control * pBtn )
{
// previous skin in list
C4P . PrefClonkSkin = C4P . PrefClonkSkin ? C4P . PrefClonkSkin - 1 : 3 ;
UpdatePlayerSkin ( ) ;
}
void C4StartupPlrPropertiesDlg : : OnSkinChangeRight ( C4GUI : : Control * pBtn )
{
// next skin in list
C4P . PrefClonkSkin = ( C4P . PrefClonkSkin + 1 ) % 4 ;
UpdatePlayerSkin ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : UserClose ( bool fOK )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// check name validity
if ( fOK )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf PlrName ( pNameEdit - > GetText ( ) ) , Filename ;
2016-11-02 23:58:02 +00:00
if ( ! C4StartupPlrSelDlg : : CheckPlayerName ( PlrName , Filename , pForPlayer ? & pForPlayer - > GetFilename ( ) : nullptr , true ) ) return ;
2018-01-28 16:18:20 +00:00
// Warn that gamepad controls are still unfinished.
C4PlayerControlAssignmentSet * control_set = Game . PlayerControlUserAssignmentSets . GetSetByName ( C4P . PrefControl . getData ( ) ) ;
if ( control_set & & control_set - > HasGamepad ( ) )
{
GetScreen ( ) - > ShowMessageModal (
LoadResStr ( " IDS_DLG_GAMEPADEXPERIMENTAL " ) ,
LoadResStr ( " IDS_DLG_GAMEPADEXPTITLE " ) ,
C4GUI : : MessageDialog : : btnOK ,
C4GUI : : Ico_Gamepad
) ;
}
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
Close ( fOK ) ;
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnClosed ( bool fOK )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( fOK )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// store selected data if desired
StdStrBuf PlrName ( pNameEdit - > GetText ( ) ) , Filename ;
2016-11-02 23:58:02 +00:00
if ( C4StartupPlrSelDlg : : CheckPlayerName ( PlrName , Filename , pForPlayer ? & pForPlayer - > GetFilename ( ) : nullptr , true ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
SCopy ( PlrName . getData ( ) , C4P . PrefName , C4MaxName ) ;
C4Group PlrGroup ;
bool fSucc = false ;
// existant player: update file
if ( pForPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! pForPlayer - > MoveFilename ( Filename . getData ( ) ) )
GetScreen ( ) - > ShowMessage ( LoadResStr ( " IDS_FAIL_RENAME " ) , " " , C4GUI : : Ico_Error ) ;
2011-08-05 12:58:16 +00:00
// update bigicon
if ( fClearBigIcon | | fctNewBigIcon . Surface )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Group PlrGroup ;
2011-08-05 11:52:53 +00:00
if ( PlrGroup . Open ( Config . AtUserDataPath ( Filename . getData ( ) ) ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( fClearBigIcon | | fctNewBigIcon . Surface ) PlrGroup . Delete ( C4CFN_BigIcon ) ;
if ( fctNewBigIcon . Surface ) fctNewBigIcon . GetFace ( ) . SavePNG ( PlrGroup , C4CFN_BigIcon ) ;
if ( PlrGroup . Close ( ) ) fSucc = true ;
if ( fClearBigIcon | | fctNewBigIcon . Surface ) pForPlayer - > GrabCustomIcon ( fctNewBigIcon ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
fSucc = true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
pForPlayer - > UpdateCore ( C4P ) ;
// player may have been activated: Make sure any new filename is reflected in participants list
if ( pMainDlg ) pMainDlg - > UpdateActivatedPlayers ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// NewPlayer: Open new player group
2011-08-05 11:52:53 +00:00
if ( PlrGroup . Open ( Config . AtUserDataPath ( Filename . getData ( ) ) , true ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Do not overwrite (should have been caught earlier anyway)
if ( PlrGroup . FindEntry ( C4CFN_PlayerInfoCore ) ) return ;
// Save info core
C4P . Save ( PlrGroup ) ;
// Add BigIcon
if ( fctNewBigIcon . Surface )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
fctNewBigIcon . GetFace ( ) . SavePNG ( PlrGroup , C4CFN_BigIcon ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Close group
if ( PlrGroup . Close ( ) ) fSucc = true ;
// update activate button text
if ( pMainDlg )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pMainDlg - > UpdatePlayerList ( ) ;
pMainDlg - > SelectItem ( Filename , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no main player selection dialog: This means that this dlg was shown as a creation dialog from the main startup dlg
// Just set the newly created player as current selection
SCopy ( Config . AtRelativePath ( Filename . getData ( ) ) , Config . General . Participants , sizeof Config . General . Participants ) ;
}
}
}
2010-03-28 18:58:01 +00:00
if ( ! fSucc ) GetScreen ( ) - > ShowErrorMessage ( PlrGroup . GetError ( ) ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Make the dialog go away
Dialog : : OnClosed ( fOK ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4StartupPlrPropertiesDlg : : SetNewPicture ( C4Surface & srcSfc , C4FacetSurface * trgFct , int32_t iMaxSize , bool fColorize )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( fColorize )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Surface srcSfcClr ;
if ( ! srcSfcClr . CreateColorByOwner ( & srcSfc ) ) return false ;
return trgFct - > CopyFromSfcMaxSize ( srcSfcClr , iMaxSize , C4P . PrefColorDw ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return trgFct - > CopyFromSfcMaxSize ( srcSfc , iMaxSize ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2011-08-05 12:58:16 +00:00
void C4StartupPlrPropertiesDlg : : SetNewPicture ( const char * szFromFilename )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! szFromFilename )
2010-03-28 18:58:01 +00:00
{
2016-11-02 23:58:02 +00:00
// If szFromFilename==nullptr, clear bigicon
2011-08-05 12:58:16 +00:00
fClearBigIcon = true ;
fctNewBigIcon . Clear ( ) ;
2010-03-28 18:58:01 +00:00
}
2011-08-05 12:58:16 +00:00
else
2010-03-28 18:58:01 +00:00
{
2011-08-05 12:58:16 +00:00
// else set new bigicon by loading and scaling if necessary.
2009-05-08 13:28:41 +00:00
C4Surface sfcNewPic ;
C4Group SrcGrp ;
StdStrBuf sParentPath ;
GetParentPath ( szFromFilename , & sParentPath ) ;
bool fSucc = false ;
if ( SrcGrp . Open ( sParentPath . getData ( ) ) )
2010-03-28 18:58:01 +00:00
{
2015-09-19 01:10:39 +00:00
if ( sfcNewPic . Load ( SrcGrp , GetFilename ( szFromFilename ) , false , false , 0 ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
fSucc = true ;
2011-08-05 12:58:16 +00:00
if ( ! SetNewPicture ( sfcNewPic , & fctNewBigIcon , C4MaxBigIconSize , true ) ) fSucc = false ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
if ( ! fSucc )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// error!
GetScreen ( ) - > ShowErrorMessage ( FormatString ( LoadResStr ( " IDS_PRC_NOGFXFILE " ) , szFromFilename , SrcGrp . GetError ( ) ) . getData ( ) ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// update icon
2011-08-05 12:58:16 +00:00
UpdateBigIcon ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : OnPictureBtn ( C4GUI : : Control * pBtn )
2010-03-28 18:58:01 +00:00
{
2011-08-05 12:58:16 +00:00
StdStrBuf sNewPic ;
if ( C4PortraitSelDlg : : SelectPortrait ( GetScreen ( ) , & sNewPic ) )
2010-03-28 18:58:01 +00:00
{
2011-08-05 12:58:16 +00:00
SetNewPicture ( sNewPic . getData ( ) ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4StartupPlrPropertiesDlg : : UpdateBigIcon ( )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// new icon?
bool fHasIcon = false ;
if ( fctNewBigIcon . Surface )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pPictureBtn - > SetFacet ( fctNewBigIcon ) ;
fHasIcon = true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// old icon in existing player?
else if ( ! fClearBigIcon & & pForPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Group PlrGroup ;
2011-08-04 16:46:47 +00:00
if ( PlrGroup . Open ( Config . AtUserDataPath ( pForPlayer - > GetFilename ( ) . getData ( ) ) ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( PlrGroup . FindEntry ( C4CFN_BigIcon ) )
2010-03-28 18:58:01 +00:00
{
2015-09-19 01:10:39 +00:00
if ( fctOldBigIcon . Load ( PlrGroup , C4CFN_BigIcon , C4FCT_Full , C4FCT_Full , false , 0 ) )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pPictureBtn - > SetFacet ( fctOldBigIcon ) ;
fHasIcon = true ;
}
}
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// no icon: Set default
if ( ! fHasIcon )
2010-03-28 18:58:01 +00:00
{
2009-06-05 15:19:15 +00:00
pPictureBtn - > SetFacet ( : : GraphicsResource . fctPlayerClr ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}