Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

editplayerdata.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
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 //   colorSelector = new PG_ColorSelector( this, PG_Rect( 10, 140, Width() - 30, 150 ));
00074 //   colorSelector->SetColor( player.getColor() );
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       // myPlayer.setColor( colorSelector->
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 

Generated on Tue Jun 24 01:27:40 2008 for Advanced Strategic Command by  doxygen 1.4.2