Advanced Strategic Command
playerselector.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #include "playerselector.h"
12 
13 
14 PlayerSelector :: PlayerSelector (PG_Widget *parent, const PG_Rect &r, GameMap* map, bool multiselect, int suppress ) : MultiListBox( parent, r), gamemap ( map ), suppressPlayers(suppress)
15 {
16  setup();
17 };
18 
19 void PlayerSelector :: setup()
20 {
21  for ( int i = 0; i < gamemap->getPlayerCount(); ++i )
22  if ( gamemap->getPlayer(i).exist() && !(suppressPlayers & (1<<i)) )
23  new Item( getListBox(), 15, gamemap->getPlayer(i).getName(), i );
24 }
25 
26 
28 {
29  int result = 0;
30  for ( int i = 0; i < getListBox()->GetWidgetCount(); ++i ) {
31  Item* bi = dynamic_cast< Item* >( getListBox()->FindWidget(i) );
32  if ( bi && bi->IsSelected() )
33  result |= 1 << bi->getData();
34  }
35  return result;
36 }
37 
39 {
40  for ( int i = 0; i < getListBox()->GetWidgetCount(); ++i ) {
41  Item* bi = dynamic_cast< Item* >( getListBox()->FindWidget(i) );
42  if ( bi )
43  bi->Select ( s & (1 << bi->getData()));
44  // getListBox()->SelectItem( bi, s & (1 << bi->getData()));
45  }
46 }
47 
48 
49 
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
void setSelection(int s)
PG_ListBox * getListBox()
Definition: multilistbox.h:41
PlayerSelector(PG_Widget *parent, const PG_Rect &r, GameMap *map, bool multiselect=true, int suppress=0)
int getPlayerCount() const
Definition: gamemap.h:255
bool exist() const
does the player exist at all
Definition: player.cpp:313
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182