00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "gTeam.h"
00029 #include "uMenu.h"
00030 #include "ePlayer.h"
00031 #include "eTeam.h"
00032
00033 static tString se_TeamMenu_Team_Ok("0xffffff");
00034 static tString se_TeamMenu_Team_Full("0xaaaaaa");
00035 static tConfItem<tString> se_TeamMenu_Team_Ok_Cfg("TEAM_MENU_COLOR_TEAM_OK",
00036 "$team_menu_color_team_ok_help",
00037 se_TeamMenu_Team_Ok);
00038 static tConfItem<tString> se_TeamMenu_Team_Full_Cfg("TEAM_MENU_COLOR_TEAM_FULL",
00039 "$team_menu_color_team_full_help",
00040 se_TeamMenu_Team_Full);
00041
00042 static tOutput* PrepareTeamText(tOutput* text, eTeam* team, const ePlayerNetID* player, const char* textTemplate)
00043 {
00044
00045 if (team==NULL)
00046 {
00047 text->SetTemplateParameter(1 , tOutput("$team_empty") );
00048
00049 int spectators = 0;
00050 for (int i = se_PlayerNetIDs.Len()-1; i>=0; i--)
00051 {
00052 ePlayerNetID *p = se_PlayerNetIDs(i);
00053 if (p->CurrentTeam()==NULL)
00054 spectators++;
00055 }
00056 text->SetTemplateParameter(2 , spectators);
00057 text->SetTemplateParameter(3, "");
00058 *text << textTemplate;
00059 return text;
00060 }
00061
00062
00063 text->SetTemplateParameter(1 , team->Name() );
00064 text->SetTemplateParameter(2 , team->NumPlayers() );
00065 if (team->PlayerMayJoin(player))
00066 text->SetTemplateParameter(3, se_TeamMenu_Team_Ok);
00067 else
00068 text->SetTemplateParameter(3, se_TeamMenu_Team_Full);
00069 *text << textTemplate << "0xffffff";
00070 return text;
00071 }
00072
00073 class gMenuItemPlayerTeam: public uMenuItem
00074 {
00075 tJUST_CONTROLLED_PTR< ePlayerNetID > player;
00076 tJUST_CONTROLLED_PTR< eTeam > team;
00077 public:
00078 gMenuItemPlayerTeam(uMenu *M,ePlayerNetID* p, eTeam* t )
00079 : uMenuItem( M, tOutput("$team_menu_join_help", t->Name())),
00080 player ( p ),
00081 team ( t)
00082 {
00083 }
00084
00085 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00086 {
00087 tOutput text;
00088 PrepareTeamText(&text, team, player, "$team_menu_join");
00089 DisplayTextSpecial( x, y, text, selected, alpha );
00090 }
00091
00092 virtual void Enter()
00093 {
00094 player->SetTeamWish( team );
00095 menu->Exit();
00096 }
00097 };
00098
00099 class gMenuItemNewTeam: public uMenuItem
00100 {
00101 ePlayerNetID* player;
00102 public:
00103 gMenuItemNewTeam( uMenu *M,ePlayerNetID* p )
00104 : uMenuItem( M, tOutput("$team_menu_create_help") ),
00105 player ( p )
00106 {
00107 }
00108
00109 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00110 {
00111 DisplayTextSpecial( x, y, se_TeamMenu_Team_Ok+(const char*)tOutput(+"$team_menu_create"), selected, alpha );
00112 }
00113
00114 virtual void Enter()
00115 {
00116 player->CreateNewTeamWish();
00117 menu->Exit();
00118 }
00119 };
00120
00121 class gMenuItemSpectate: public uMenuItem
00122 {
00123 ePlayerNetID* player;
00124 public:
00125 gMenuItemSpectate( uMenu *M,ePlayerNetID* p )
00126 : uMenuItem( M, tOutput("$team_menu_spectate_help") ),
00127 player ( p )
00128 {
00129 }
00130
00131 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00132 {
00133 DisplayTextSpecial( x, y, se_TeamMenu_Team_Ok+(const char*)tOutput("$team_menu_spectate"), selected, alpha );
00134 }
00135
00136 virtual void Enter()
00137 {
00138 player->SetTeamWish(NULL);
00139 menu->Exit();
00140 }
00141 };
00142
00143 class gMenuItemAutoSelect: public uMenuItem
00144 {
00145 ePlayerNetID* player;
00146 public:
00147 gMenuItemAutoSelect( uMenu *M,ePlayerNetID* p )
00148 : uMenuItem( M, tOutput("$team_menu_auto_help") ),
00149 player ( p )
00150 {
00151 }
00152
00153 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00154 {
00155 DisplayTextSpecial( x, y, se_TeamMenu_Team_Ok+(const char*)tOutput("$team_menu_auto"), selected, alpha );
00156 }
00157
00158 virtual void Enter()
00159 {
00160 player->SetDefaultTeam();
00161 menu->Exit();
00162 }
00163 };
00164
00165 class gMenuItemSpacer: public uMenuItem
00166 {
00167 public:
00168 gMenuItemSpacer(uMenu *M)
00169 : uMenuItem( M, tOutput() )
00170 {
00171 }
00172
00173 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00174 {
00175 }
00176
00177 virtual bool IsSelectable()
00178 {
00179 return false;
00180 }
00181 };
00182
00183 class gMenuItemStatus: public uMenuItem
00184 {
00185 ePlayerNetID *player;
00186 bool currentTeam;
00187 public:
00188 gMenuItemStatus(uMenu *M, ePlayerNetID *playerID, bool displayCurrentTeam)
00189 : uMenuItem( M, tOutput() ), player(playerID), currentTeam(displayCurrentTeam)
00190 {
00191 }
00192
00193 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00194 {
00195 tOutput text;
00196 if (currentTeam)
00197 PrepareTeamText(&text, player->CurrentTeam(), player, "$team_menu_info_current_team");
00198 else
00199 PrepareTeamText(&text, player->NextTeam(), player, "$team_menu_info_next_team");
00200 DisplayTextSpecial( x, y, text, false, alpha );
00201 }
00202
00203 virtual bool IsSelectable()
00204 {
00205 return false;
00206 }
00207 };
00208
00209 class gMenuItemPlayer: public uMenuItem
00210 {
00211 ePlayerNetID* player;
00212 public:
00213 gMenuItemPlayer(uMenu *M,ePlayerNetID* p,
00214 const tOutput& help)
00215 : uMenuItem( M, help ),
00216 player ( p )
00217 {
00218 }
00219
00220 virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
00221 {
00222 DisplayTextSpecial( x, y, player->GetName(), selected, alpha );
00223 }
00224
00225 virtual void Enter()
00226 {
00227 tOutput title;
00228 title.SetTemplateParameter( 1, player->GetName() );
00229 title << "$team_menu_player_title";
00230 uMenu playerMenu( title );
00231 tArray<uMenuItem*> items;
00232
00233
00234 int i;
00235 for ( i = MAX_PLAYERS; i>=0; --i )
00236 {
00237 if ( ePlayer::PlayerIsInGame(i))
00238 {
00239 ePlayer* localPlayer = ePlayer::PlayerConfig( i );
00240 ePlayerNetID* pni = localPlayer->netPlayer;
00241 if ( pni == this->player && localPlayer->spectate )
00242 {
00243 localPlayer->spectate = false;
00244 con << tOutput("$player_toggle_spectator_off", localPlayer->name );
00245 ePlayerNetID::Update();
00246 }
00247 }
00248 }
00249
00250 if ( player->NextTeam()!=NULL)
00251 {
00252 items[items.Len()] = tNEW(gMenuItemSpectate) (&playerMenu, player);
00253 }
00254
00255
00256 for ( i = 0; i<eTeam::teams.Len(); i++ )
00257 {
00258 eTeam *team = eTeam::teams(i);
00259 if ( team && team != player->NextTeam() && !team->PlayerMayJoin( player ) )
00260 {
00261 items[ items.Len() ] = tNEW( gMenuItemPlayerTeam ) ( &playerMenu, player, team );
00262 }
00263 }
00264
00265
00266 for ( i = 0; i<eTeam::teams.Len(); i++ )
00267 {
00268 eTeam *team = eTeam::teams(i);
00269 if ( team && team != player->NextTeam() && team->PlayerMayJoin( player ))
00270 items[ items.Len() ] = tNEW( gMenuItemPlayerTeam ) ( &playerMenu, player, team );
00271 }
00272
00273 items[items.Len()] = tNEW(gMenuItemAutoSelect) (&playerMenu, player);
00274
00275 if (
00276 !( player->NextTeam() && player->NextTeam()->NumHumanPlayers() == 1 &&
00277 player->CurrentTeam() && player->CurrentTeam()->NumHumanPlayers() == 1 )
00278 )
00279 {
00280 items[ items.Len() ] = tNEW( gMenuItemNewTeam ) ( &playerMenu, player );
00281
00282 }
00283
00284 items[items.Len()] = tNEW ( gMenuItemSpacer ) ( &playerMenu );
00285 items[items.Len()] = tNEW ( gMenuItemStatus ) ( &playerMenu, player, false);
00286 items[items.Len()] = tNEW ( gMenuItemStatus ) ( &playerMenu, player, true);
00287
00288 playerMenu.Enter();
00289
00290 for ( i = items.Len()-1; i>=0; --i )
00291 {
00292 delete items(i);
00293 }
00294 }
00295 };
00296
00297
00298
00299
00300
00301 void gTeam::TeamMenu()
00302 {
00303 int i;
00304
00305 uMenu Menu( tOutput("$team_menu_title") );
00306 tArray<uMenuItem*> items;
00307
00308 for ( i = MAX_PLAYERS; i>=0; --i )
00309 {
00310 if ( ePlayer::PlayerIsInGame(i))
00311 {
00312 ePlayer* player = ePlayer::PlayerConfig( i );
00313 tOutput help;
00314 help.SetTemplateParameter(1, player->Name() );
00315 help << "$team_menu_player_help";
00316 ePlayerNetID* pni = player->netPlayer;
00317 if ( pni )
00318 items[ items.Len() ] = tNEW( gMenuItemPlayer ) ( &Menu, pni, help );
00319 }
00320 }
00321
00322 if ( items.Len() > 1 )
00323 {
00324 Menu.Enter();
00325 }
00326 else if ( items.Len() >= 1 )
00327 {
00328 items[0]->Enter();
00329 }
00330
00331 for ( i = items.Len()-1; i>=0; --i )
00332 {
00333 delete items(i);
00334 }
00335 }