Advanced Strategic Command
editplayerdata.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include "../ascstring.h"
22 #include "../paradialog.h"
23 #include "../windowing.h"
24 #include <pgpropertyfield_string.h>
25 #include "../gamemap.h"
26 
27 #include <pgcolorselector.h>
28 
29 
30 
32 {
33  ASC_PropertyEditor* editor;
34  ASCString name;
35  Player& myPlayer;
36  bool ok();
37 
38  PG_DropDown* playerMode;
39  map<int,Player::PlayerStatus> modes;
40 
41  PG_ColorSelector* colorSelector;
42 
43  public:
44  EditPlayerData( Player& player );
45  GameMap* getMap();
46  bool search( int id );
47 };
48 
49 EditPlayerData :: EditPlayerData(Player& player ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 500, 400), "Edit Player Data" ), editor(NULL), myPlayer( player ), colorSelector(NULL)
50 {
51  name = player.getName();
52  editor = new ASC_PropertyEditor( this, PG_Rect( 10, 40, Width()-20, 70));
53  new PG_PropertyField_String<ASCString>( editor , "Name", &name );
54  new PG_PropertyField_String<ASCString>( editor , "Email Address", &player.email );
55 
56 
57  playerMode = new PG_DropDown( this, PG_Rect( 10, 110, Width() - 30, 25 ));
58  playerMode->AddItem( Player :: playerStatusNames[player.stat] );
59  modes[0] = player.stat;
60 
61  int counter = 1;
62  int pos = 0;
63  while ( Player :: playerStatusNames[pos] ) {
64  if( pos != Player::supervisor && pos != player.stat ) {
65  playerMode->AddItem( Player :: playerStatusNames[pos] );
66  modes[counter++] = Player::PlayerStatus(pos);
67  }
68  ++pos;
69  }
70 
71  playerMode->SelectItem(0);
72 
73 // colorSelector = new PG_ColorSelector( this, PG_Rect( 10, 140, Width() - 30, 150 ));
74 // colorSelector->SetColor( player.getColor() );
75 
77  AddStandardButton( "OK")->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &EditPlayerData::ok )));
78 }
79 
80 bool EditPlayerData :: ok()
81 {
82  if ( editor->Apply() ) {
83  myPlayer.setName( name );
84  myPlayer.stat = modes[playerMode->GetSelectedItemIndex()];
85  // myPlayer.setColor( colorSelector->
86  QuitModal();
87  }
88  return true;
89 }
90 
91 
92 
93 void editPlayerData( GameMap* gamemap )
94 {
95  int humanNum = 0;
96  for ( int i = 0; i < gamemap->getPlayerCount(); ++i )
97  if ( gamemap->getPlayer(i).isHuman() )
98  ++humanNum;
99 
100  if ( humanNum <= 1 )
101  infoMessage("Only available for multiplayer games");
102  else {
103  EditPlayerData epd( gamemap->getPlayer( gamemap->actplayer) );
104  epd.Show();
105  epd.RunModal();
106  }
107 
108 }
109 
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
static const char * playerStatusNames[]
Definition: player.h:156
GameMap * getMap()
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
void StandardButtonDirection(StandardButtonDirectonType dir)
Definition: paradialog.cpp:511
bool isHuman() const
Definition: player.h:152
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void editPlayerData(GameMap *gamemap)
void setName(const ASCString &name)
Definition: player.h:160
enum Player::PlayerStatus stat
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
ASCString email
Definition: player.h:211
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
PlayerStatus
the status of the player
Definition: player.h:150
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
EditPlayerData(Player &player)
bool search(int id)
PG_Button * AddStandardButton(const ASCString &name)
Definition: paradialog.cpp:516
int getPlayerCount() const
Definition: gamemap.h:255
void infoMessage(const ASCString &string)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182