00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "../ascstring.h"
00022 #include "../paradialog.h"
00023 #include "../windowing.h"
00024 #include <pgpropertyfield_string.h>
00025 #include "../gamemap.h"
00026
00027 #include <pgcolorselector.h>
00028
00029
00030
00031 class EditPlayerData : public ASC_PG_Dialog
00032 {
00033 ASC_PropertyEditor* editor;
00034 ASCString name;
00035 Player& myPlayer;
00036 bool ok();
00037
00038 PG_DropDown* playerMode;
00039 map<int,Player::PlayerStatus> modes;
00040
00041 PG_ColorSelector* colorSelector;
00042
00043 public:
00044 EditPlayerData( Player& player );
00045 GameMap* getMap();
00046 bool search( int id );
00047 };
00048
00049 EditPlayerData :: EditPlayerData(Player& player ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 500, 400), "Edit Player Data" ), editor(NULL), myPlayer( player ), colorSelector(NULL)
00050 {
00051 name = player.getName();
00052 editor = new ASC_PropertyEditor( this, PG_Rect( 10, 40, Width()-20, 70));
00053 new PG_PropertyField_String<ASCString>( editor , "Name", &name );
00054 new PG_PropertyField_String<ASCString>( editor , "Email Address", &player.email );
00055
00056
00057 playerMode = new PG_DropDown( this, PG_Rect( 10, 110, Width() - 30, 25 ));
00058 playerMode->AddItem( Player :: playerStatusNames[player.stat] );
00059 modes[0] = player.stat;
00060
00061 int counter = 1;
00062 int pos = 0;
00063 while ( Player :: playerStatusNames[pos] ) {
00064 if( pos != Player::supervisor && pos != player.stat ) {
00065 playerMode->AddItem( Player :: playerStatusNames[pos] );
00066 modes[counter++] = Player::PlayerStatus(pos);
00067 }
00068 ++pos;
00069 }
00070
00071 playerMode->SelectItem(0);
00072
00073
00074
00075
00076 StandardButtonDirection( Horizontal );
00077 AddStandardButton( "OK")->sigClick.connect( SigC::slot( *this, &EditPlayerData::ok ));
00078 }
00079
00080 bool EditPlayerData :: ok()
00081 {
00082 if ( editor->Apply() ) {
00083 myPlayer.setName( name );
00084 myPlayer.stat = modes[playerMode->GetSelectedItemIndex()];
00085
00086 QuitModal();
00087 }
00088 return true;
00089 }
00090
00091
00092
00093 void editPlayerData( GameMap* gamemap )
00094 {
00095 int humanNum = 0;
00096 for ( int i = 0; i < gamemap->getPlayerCount(); ++i )
00097 if ( gamemap->getPlayer(i).isHuman() )
00098 ++humanNum;
00099
00100 if ( humanNum <= 1 )
00101 infoMessage("Only available for multiplayer games");
00102 else {
00103 EditPlayerData epd( gamemap->getPlayer( gamemap->actplayer) );
00104 epd.Show();
00105 epd.RunModal();
00106 }
00107
00108 }
00109