vegastrike  0.5.1.r1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gamemenu.cpp
Go to the documentation of this file.
1 #include "vegastrike.h"
2 #include "in_kb.h"
3 #include "in_kb_data.h"
4 #include "in_mouse.h"
5 #include "main_loop.h"
6 #include "universe_util.h"
7 #include "lin_time.h"
8 #include "gui/modaldialog.h"
9 #include "gui/eventmanager.h"
10 #include "gui/newbutton.h"
11 #include "gui/staticdisplay.h"
12 #include "gui/textinputdisplay.h"
13 #include "gui/simplepicker.h"
14 #include "gui/groupcontrol.h"
15 #include "gui/scroller.h"
16 #include "networking/netclient.h"
17 #include "gamemenu.h"
18 #include "gfxlib_struct.h"
19 #include "cmd/music.h"
20 
21 extern void TerminateCurrentBase( void );
22 vector< unsigned int >gamemenu_keyboard_queue;
23 
24 template < >
25 const GameMenu::WctlTableEntry WctlBase< GameMenu >::WctlCommandTable[] = {
26  GameMenu::WctlTableEntry( "SinglePlayer", "", &GameMenu::processSinglePlayerButton ),
27  GameMenu::WctlTableEntry( "ShowJoinServer", "", &GameMenu::processMultiPlayerHostButton ),
28  GameMenu::WctlTableEntry( "ShowJoinAccount", "", &GameMenu::processMultiPlayerAcctButton ),
29  GameMenu::WctlTableEntry( "ShowMultiPlayer", "", &GameMenu::processMultiPlayerButton ),
30  GameMenu::WctlTableEntry( "ExitGame", "", &GameMenu::processExitGameButton ),
31  GameMenu::WctlTableEntry( "JoinGame", "", &GameMenu::processJoinGameButton ),
32  GameMenu::WctlTableEntry( "ReturnMainMenu", "", &GameMenu::processMainMenuButton ),
33  GameMenu::WctlTableEntry( "", "", NULL )
34 };
35 
36 GameMenu::GameMenu( bool firstTime ) :
37  m_firstTime( firstTime )
38 {}
39 
41 
43 {
44  WindowController::run();
45 }
46 
47 int shiftup( int );
48 void gamemenu_keyboard_handler( unsigned int ch, unsigned int mod, bool release, int x, int y )
49 {
50  //Set modifiers
51  unsigned int amods = 0;
52  amods |= ( mod&(WSK_MOD_LSHIFT|WSK_MOD_RSHIFT) ) ? KB_MOD_SHIFT : 0;
53  amods |= ( mod&(WSK_MOD_LCTRL|WSK_MOD_RCTRL) ) ? KB_MOD_CTRL : 0;
54  amods |= ( mod&(WSK_MOD_LALT|WSK_MOD_RALT) ) ? KB_MOD_ALT : 0;
55  setActiveModifiers( amods );
56  //Queue keystroke
57  if (!release)
58  gamemenu_keyboard_queue.push_back( ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) )
59  || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ? shiftup( ch ) : ch );
60 }
61 
63 {
64  UpdateTime();
65  Music::MuzakCycle();
66  GFXBeginScene();
67  globalWindowManager().draw();
68  GFXEndScene();
69 }
70 
71 //static
72 void GameMenu::createNetworkControls( GroupControl *serverConnGroup, std::vector< unsigned int > *inputqueue )
73 {
74  GFXColor color( 1, .5, 0, .1 );
75  //Account Server button.
76  NewButton *joinAcct = new NewButton;
77  joinAcct->setRect( Rect( -.50, .7, .37, .09 ) );
78  joinAcct->setLabel( "Online Account Server" );
79  joinAcct->setCommand( "ShowJoinAccount" );
80 
81  joinAcct->setColor( GFXColor( color.r, color.g, color.b, .25 ) );
82  joinAcct->setTextColor( GUI_OPAQUE_WHITE() );
83  joinAcct->setDownColor( GFXColor( color.r, color.g, color.b, .5 ) );
84  joinAcct->setDownTextColor( GUI_OPAQUE_BLACK() );
85  joinAcct->setHighlightColor( GFXColor( color.r, color.g, color.b, .4 ) );
86  joinAcct->setFont( Font( .07 ) );
87  serverConnGroup->addChild( joinAcct );
88 
89  //Ship Stats button.
90  NewButton *joinServer = new NewButton;
91  joinServer->setRect( Rect( .05, .7, .37, .09 ) );
92  joinServer->setLabel( "Independent Server" );
93  joinServer->setCommand( "ShowJoinServer" );
94  joinServer->setColor( GFXColor( color.r, color.g, color.b, .25 ) );
95  joinServer->setTextColor( GUI_OPAQUE_WHITE() );
96  joinServer->setDownColor( GFXColor( color.r, color.g, color.b, .5 ) );
97  joinServer->setDownTextColor( GUI_OPAQUE_BLACK() );
98  joinServer->setHighlightColor( GFXColor( color.r, color.g, color.b, .4 ) );
99  joinServer->setFont( Font( .07 ) );
100  serverConnGroup->addChild( joinServer );
101 
102  bool useacctserver = XMLSupport::parse_bool( vs_config->getVariable( "network", "use_account_server", "true" ) );
103 
104  GroupControl *acctConnGroup = new GroupControl;
105  acctConnGroup->setId( "MultiPlayerAccountServer" );
106  acctConnGroup->setHidden( !useacctserver );
107  serverConnGroup->addChild( acctConnGroup );
108 
109  GroupControl *hostConnGroup = new GroupControl;
110  hostConnGroup->setId( "MultiPlayerHostPort" );
111  hostConnGroup->setHidden( useacctserver );
112  serverConnGroup->addChild( hostConnGroup );
113  StaticDisplay *mplayTitle = new StaticDisplay;
114  mplayTitle->setRect( Rect( -.7, .6, 1, .1 ) );
115  mplayTitle->setText( "Independent Server IP Address:" );
116  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
117  mplayTitle->setColor( GUI_CLEAR );
118  mplayTitle->setFont( Font( .07, 2 ) );
119  mplayTitle->setId( "HostTitle" );
120  hostConnGroup->addChild( mplayTitle );
121 
122  //Description box.
123  StaticDisplay *serverInputText = new TextInputDisplay( inputqueue, "\x1b\n \t\r*?\\/|:<>\"^" );
124  serverInputText->setRect( Rect( -.6, .42, 1.2, .15 ) );
125  serverInputText->setColor( GFXColor( 1, .5, 0, .1 ) );
126  serverInputText->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
127  serverInputText->setFont( Font( .07 ) );
128  serverInputText->setMultiLine( false );
129  serverInputText->setTextColor( GUI_OPAQUE_WHITE() );
130  serverInputText->setTextMargins( Size( .02, .01 ) );
131  serverInputText->setId( "VegaserverHost" );
132  serverInputText->setText( vs_config->getVariable( "network", "server_ip", "" ) );
133  hostConnGroup->addChild( serverInputText );
134 
135  mplayTitle = new StaticDisplay;
136  mplayTitle->setRect( Rect( -.7, .3, 1, .1 ) );
137  mplayTitle->setText( "Server Port: (default 6777)" );
138  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
139  mplayTitle->setColor( GUI_CLEAR );
140  mplayTitle->setFont( Font( .07, 2 ) );
141  mplayTitle->setId( "PortTitle" );
142  hostConnGroup->addChild( mplayTitle );
143 
144  StaticDisplay *portInputText = new TextInputDisplay( inputqueue, "\x1b\n \t\r*?\\/|:<>\"!@#$%^&*()[]{},.=_-+`~"
145  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" );
146  portInputText->setRect( Rect( -.6, .12, .4, .15 ) );
147  portInputText->setColor( GFXColor( 1, .5, 0, .1 ) );
148  portInputText->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
149  portInputText->setFont( Font( .07 ) );
150  portInputText->setMultiLine( false );
151  portInputText->setTextColor( GUI_OPAQUE_WHITE() );
152  portInputText->setTextMargins( Size( .02, .01 ) );
153  portInputText->setId( "VegaserverPort" );
154  portInputText->setText( vs_config->getVariable( "network", "server_port", "6777" ) );
155  hostConnGroup->addChild( portInputText );
156 
157  mplayTitle = new StaticDisplay;
158  mplayTitle->setRect( Rect( -.7, .6, 1, .1 ) );
159  mplayTitle->setText( "Account Server URL:" );
160  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
161  mplayTitle->setColor( GUI_CLEAR );
162  mplayTitle->setFont( Font( .07, 2 ) );
163  mplayTitle->setId( "AcctserverTitle" );
164  acctConnGroup->addChild( mplayTitle );
165 
166  StaticDisplay *acctserverInput = new TextInputDisplay( inputqueue, "\x1b\n \t\r*\\|<>\"^" );
167  acctserverInput->setRect( Rect( -.6, .42, 1.2, .15 ) );
168  acctserverInput->setColor( GFXColor( 1, .5, 0, .1 ) );
169  acctserverInput->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
170  acctserverInput->setFont( Font( .07 ) );
171  acctserverInput->setMultiLine( false );
172  acctserverInput->setTextColor( GUI_OPAQUE_WHITE() );
173  acctserverInput->setTextMargins( Size( .02, .01 ) );
174  acctserverInput->setId( "AccountServer" );
175  acctserverInput->setText( vs_config->getVariable( "network", "account_server_url",
176  "http://vegastrike.sourceforge.net/cgi-bin/accountserver.py?" ) );
177  acctConnGroup->addChild( acctserverInput );
178 
179  mplayTitle = new StaticDisplay;
180  mplayTitle->setRect( Rect( -.7, 0, 1, .1 ) );
181  mplayTitle->setText( "Callsign:" );
182  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
183  mplayTitle->setColor( GUI_CLEAR );
184  mplayTitle->setFont( Font( .07, 2 ) );
185  mplayTitle->setId( "UsernameTitle" );
186  serverConnGroup->addChild( mplayTitle );
187 
188  string origpass( vs_config->getVariable( "player", "password", "" ) );
189  StaticDisplay *usernameInput = new TextInputDisplay( inputqueue, "\x1b\n\t\r*\\|<>\"^" );
190  usernameInput->setRect( Rect( -.6, -.18, 1.2, .15 ) );
191  usernameInput->setColor( GFXColor( 1, .5, 0, .1 ) );
192  usernameInput->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
193  usernameInput->setFont( Font( .07 ) );
194  usernameInput->setMultiLine( false );
195  usernameInput->setTextColor( GUI_OPAQUE_WHITE() );
196  usernameInput->setTextMargins( Size( .02, .01 ) );
197  usernameInput->setId( "Username" );
198  if ( !origpass.empty() ) usernameInput->setText( vs_config->getVariable( "player", "callsign", "" ) );
199  serverConnGroup->addChild( usernameInput );
200 
201  mplayTitle = new StaticDisplay;
202  mplayTitle->setRect( Rect( -.7, -.3, 1, .1 ) );
203  mplayTitle->setText( "Password: (Server password is usually blank on local games)" );
204  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
205  mplayTitle->setColor( GUI_CLEAR );
206  mplayTitle->setFont( Font( .07, 2 ) );
207  mplayTitle->setId( "PasswordTitleHost" );
208  hostConnGroup->addChild( mplayTitle );
209 
210  mplayTitle = new StaticDisplay;
211  mplayTitle->setRect( Rect( -.7, -.3, 1, .1 ) );
212  mplayTitle->setText( "Password:" );
213  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
214  mplayTitle->setColor( GUI_CLEAR );
215  mplayTitle->setFont( Font( .07, 2 ) );
216  mplayTitle->setId( "PasswordTitle" );
217  acctConnGroup->addChild( mplayTitle );
218 
219  TextInputDisplay *passwordInput = new TextInputDisplay( inputqueue, "\x1b\n\t\r" );
220  passwordInput->setPassword( '*' );
221  passwordInput->setRect( Rect( -.6, -.48, 1.2, .15 ) );
222  passwordInput->setColor( GFXColor( 1, .5, 0, .1 ) );
223  passwordInput->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
224  passwordInput->setFont( Font( .07 ) );
225  passwordInput->setMultiLine( false );
226  passwordInput->setTextColor( GUI_OPAQUE_WHITE() );
227  passwordInput->setTextMargins( Size( .02, .01 ) );
228  passwordInput->setId( "Password" );
229  passwordInput->setText( origpass );
230  serverConnGroup->addChild( passwordInput );
231 
232  NewButton *multiStart = new NewButton;
233  multiStart->setRect( Rect( -.25, -.65, .5, .15 ) );
234  multiStart->setColor( GFXColor( 1, .2, 0, .1 ) );
235  multiStart->setTextColor( GUI_OPAQUE_WHITE() );
236  multiStart->setDownColor( GFXColor( 1, .2, 0, .4 ) );
237  multiStart->setDownTextColor( GFXColor( .2, .2, .2 ) );
238  multiStart->setFont( Font( .07, 1 ) );
239  multiStart->setCommand( "JoinGame" );
240  multiStart->setLabel( "Join Game" );
241  serverConnGroup->addChild( multiStart );
242 }
243 
244 namespace UniverseUtil
245 {
246 void startMenuInterface( bool firstTime, string error )
247 {
248  winsys_set_keyboard_func( gamemenu_keyboard_handler );
249  winsys_set_mouse_func( EventManager::ProcessMouseClick );
250  winsys_set_passive_motion_func( EventManager::ProcessMousePassive );
251  winsys_set_motion_func( EventManager::ProcessMouseActive );
252 
253  GameMenu *gm = new GameMenu( firstTime );
254  gm->init();
255  gm->run();
256  if ( !error.empty() ) {
257  gm->window()->findControlById( "MainMenu" )->setHidden( true );
258  gm->window()->findControlById( "MultiPlayerMenu" )->setHidden( false );
259  showAlert( error );
260  }
262 }
263 }
264 
266 {
267  Window *w = new Window;
268  setWindow( w );
269 
270  window()->setFullScreen();
271  window()->setColor( GUI_CLEAR );
272  window()->setTexture( "basecomputer.png" );
273 
274  createControls();
275 }
276 
278 {
279  //Base info title.
280  StaticDisplay *baseTitle = new StaticDisplay;
281  baseTitle->setRect( Rect( -.96, .83, 1.9, .1 ) );
282  baseTitle->setText( "Vega Strike menu" );
283  static GFXColor baseNameColor = getConfigColor( "base_name_color", GFXColor( .1, .8, .1 ) );
284  baseTitle->setTextColor( baseNameColor );
285  baseTitle->setColor( GUI_CLEAR );
286  baseTitle->setFont( Font( .07, 2 ) );
287  baseTitle->setId( "GameTitle" );
288  //Put it on the window.
289 
290  GroupControl *mainMenuGroup = new GroupControl;
291  mainMenuGroup->setId( "MainMenu" );
292  window()->addControl( mainMenuGroup );
293 
294  mainMenuGroup->addChild( baseTitle );
295 
296  NewButton *singlePlayer = new NewButton;
297  singlePlayer->setRect( Rect( -.75, .2, 1.5, .15 ) );
298  singlePlayer->setColor( GFXColor( 0, 1, 1, .1 ) );
299  singlePlayer->setTextColor( GUI_OPAQUE_WHITE() );
300  singlePlayer->setDownColor( GFXColor( 0, 1, 1, .4 ) );
301  singlePlayer->setDownTextColor( GFXColor( .2, .2, .2 ) );
302  singlePlayer->setFont( Font( .07, 1 ) );
303  singlePlayer->setCommand( "SinglePlayer" );
304  singlePlayer->setLabel( "Single Player Game" );
305  mainMenuGroup->addChild( singlePlayer );
306 
307  NewButton *multiPlayer = new NewButton;
308  multiPlayer->setRect( Rect( -.75, 0, 1.5, .15 ) );
309  multiPlayer->setColor( GFXColor( 1, .2, 0, .1 ) );
310  multiPlayer->setTextColor( GUI_OPAQUE_WHITE() );
311  multiPlayer->setDownColor( GFXColor( 1, .2, 0, .4 ) );
312  multiPlayer->setDownTextColor( GFXColor( .2, .2, .2 ) );
313  multiPlayer->setFont( Font( .07, 1 ) );
314  multiPlayer->setCommand( "ShowMultiPlayer" );
315  multiPlayer->setLabel( "MultiPlayer" );
316  mainMenuGroup->addChild( multiPlayer );
317 
318  NewButton *exitGame = new NewButton;
319  exitGame->setRect( Rect( -.75, -.5, 1.5, .15 ) );
320  exitGame->setColor( GFXColor( .7, 0, 1, .1 ) );
321  exitGame->setTextColor( GUI_OPAQUE_WHITE() );
322  exitGame->setDownColor( GFXColor( .7, 0, 1, .4 ) );
323  exitGame->setDownTextColor( GFXColor( .2, .2, .2 ) );
324  exitGame->setFont( Font( .07, 1 ) );
325  exitGame->setCommand( "ExitGame" );
326  exitGame->setLabel( "Exit Game" );
327  mainMenuGroup->addChild( exitGame );
328 
329  GroupControl *serverConnGroup = new GroupControl;
330  serverConnGroup->setId( "MultiPlayerMenu" );
331  serverConnGroup->setHidden( true );
332  window()->addControl( serverConnGroup );
333 
334  StaticDisplay *mplayTitle = new StaticDisplay;
335  mplayTitle->setRect( Rect( -.96, .83, .8, .1 ) );
336  mplayTitle->setText( "MultiPlayer Settings" );
337  mplayTitle->setTextColor( baseNameColor );
338  mplayTitle->setColor( GUI_CLEAR );
339  mplayTitle->setFont( Font( .07, 2 ) );
340  mplayTitle->setId( "GameTitle" );
341  //Put it on the window.
342  serverConnGroup->addChild( mplayTitle );
343 
344  NewButton *returnMainMenu = new NewButton;
345  returnMainMenu->setRect( Rect( .7, .81, .25, .1 ) );
346  returnMainMenu->setColor( GFXColor( 1, .2, 0, .1 ) );
347  returnMainMenu->setTextColor( GUI_OPAQUE_WHITE() );
348  returnMainMenu->setDownColor( GFXColor( 1, .2, 0, .4 ) );
349  returnMainMenu->setDownTextColor( GFXColor( .2, .2, .2 ) );
350  returnMainMenu->setFont( Font( .07, 1 ) );
351  returnMainMenu->setCommand( "ReturnMainMenu" );
352  returnMainMenu->setLabel( "Done" );
353  serverConnGroup->addChild( returnMainMenu );
354 
355  exitGame = new NewButton;
356  exitGame->setRect( Rect( -.95, -.91, .3, .1 ) );
357  exitGame->setColor( GFXColor( .7, 0, 1, .1 ) );
358  exitGame->setTextColor( GUI_OPAQUE_WHITE() );
359  exitGame->setDownColor( GFXColor( .7, 0, 1, .4 ) );
360  exitGame->setDownTextColor( GFXColor( .2, .2, .2 ) );
361  exitGame->setFont( Font( .07, 1 ) );
362  exitGame->setCommand( "ExitGame" );
363  exitGame->setLabel( "Quit Game" );
364  serverConnGroup->addChild( exitGame );
365 
366  createNetworkControls( serverConnGroup, &gamemenu_keyboard_queue );
367 
368  //Make a tab for mode switching...
369  //(Add buttons for acctserver/modname) (acctserver mode is default).
370  //
371  //Add a user/password box (as well as create account button if in acctserver mode).
372  //Connect button
373  //
374  //Scan local network button (I guess...)
375  //Host game menu... also might take plenty of work...
376 
377  //Single Player button
378  //Options button (Requires restart if not done at the beginning... static variables)
379  //Options button requires porting vssetup code to be used inside VS... should be simple to do. Is it worth it?
380  //Network button
381  //About
382  //Exit game
383 
384  //Submenu of single player: (for now, call base computer like it does now))
385  //
386  //New Game (taken from save/load dialog?)
387  //Load Game (save/load dialog without save option?)
388  //Simple space fight (equivalent to mission command line option?)
389 
390  //Submenu of multiplayer:
391  //
392  //Account Server. // Mod name.
393  //No downloading server lists...
394  //User name
395  //Password
396  //Create account... goes through CGI page.
397 }
398 
399 extern void bootstrap_main_loop();
400 extern void enableNetwork( bool usenet );
401 
402 bool GameMenu::processSinglePlayerButton( const EventCommandId &command, Control *control )
403 {
404  NetClient::CleanUp();
405  enableNetwork( false );
406 
408  if (m_firstTime)
410  window()->close();
411  globalWindowManager().shutDown();
413  return true;
414 }
415 
416 bool GameMenu::processMultiPlayerHostButton( const EventCommandId &command, Control *control )
417 {
418  window()->findControlById( "MainMenu" )->setHidden( true );
419  window()->findControlById( "MultiPlayerMenu" )->setHidden( false );
420  window()->findControlById( "MultiPlayerAccountServer" )->setHidden( true );
421  window()->findControlById( "MultiPlayerHostPort" )->setHidden( false );
422  return true;
423 }
424 
425 bool GameMenu::processMultiPlayerAcctButton( const EventCommandId &command, Control *control )
426 {
427  window()->findControlById( "MainMenu" )->setHidden( true );
428  window()->findControlById( "MultiPlayerMenu" )->setHidden( false );
429  window()->findControlById( "MultiPlayerAccountServer" )->setHidden( false );
430  window()->findControlById( "MultiPlayerHostPort" )->setHidden( true );
431  return true;
432 }
433 
434 bool GameMenu::processMultiPlayerButton( const EventCommandId &command, Control *control )
435 {
436  window()->findControlById( "MainMenu" )->setHidden( true );
437  window()->findControlById( "MultiPlayerMenu" )->setHidden( false );
438  return true;
439 }
440 
441 bool GameMenu::processMainMenuButton( const EventCommandId &command, Control *control )
442 {
443  window()->findControlById( "MainMenu" )->setHidden( false );
444  window()->findControlById( "MultiPlayerMenu" )->setHidden( true );
445  return true;
446 }
447 
448 bool GameMenu::processExitGameButton( const EventCommandId &command, Control *control )
449 {
450  winsys_exit( 0 );
451  return true;
452 }
453 
454 class ShipSelectorCallback : public ModalDialogCallback
455 {
456  NetActionConfirm *nac;
457  bool onlyMessage;
458 public: ShipSelectorCallback( NetActionConfirm *nac, bool onlyMessage ) :
459  nac( nac )
460  , onlyMessage( onlyMessage ) {}
461  virtual void modalDialogResult( const std::string &id, int result, WindowController &controller )
462  {
463  if (onlyMessage) {
464  //The result is slightly different (OK=1 and Cancel=0)
465  if (result == YES_ANSWER)
466  result = 0;
467  else
468  result = -1;
469  }
470  //Ship = 0 or above, Cancel = -1
471  nac->finalizeJoinGame( result );
472  }
474 };
475 
476 //Create the window and controls for the Options Menu.
478 {
479  Window *window = new Window;
480  setWindow( window );
481 
482  window->setSizeAndCenter( Size( .9, .5 ) );
483  window->setTexture( "basecomputer.png" );
484  window->setColor( GFXColor( 0, 1, 0, .1 ) );
485  window->setOutlineColor( GFXColor( .7, .7, .7 ) );
486  window->setOutlineWidth( 2.0 );
487  window->setController( this );
488 
489  //Information.
490  StaticDisplay *text = new StaticDisplay;
491  text->setRect( Rect( -.4, -.15, .8, .3 ) );
492  if (netAction == JOINGAME)
493  text->setText( "Leaving your current game and joining a new one will lose all progress since your last save." );
494  else if (netAction == SAVEACCT)
495  text->setText( "Do you want to save your current account progress?" );
496  else if (netAction == DIE)
497  text->setText( "Rejoining your current game will lose all progress since your last save." );
498  text->setTextColor( GFXColor( .7, 1, .4 ) );
499  text->setMultiLine( true );
500  text->setColor( GUI_CLEAR );
501  text->setFont( Font( .07, 1.25 ) );
502  text->setId( "Information" );
503  //Put it on the window.
504  window->addControl( text );
505 
506  //Save button.
507  NewButton *cont = new NewButton;
508  cont->setRect( Rect( .05, -.19, .30, .1 ) );
509  if (netAction == SAVEACCT) {
510  cont->setLabel( "Save Account" );
511  cont->setCommand( "Save" );
512  } else if (netAction == DIE) {
513  cont->setLabel( "Die" );
514  cont->setCommand( "Load" );
515  } else if (netAction == JOINGAME) {
516  cont->setLabel( "Join New Game" );
517  cont->setCommand( "JoinGame" );
518  }
519  cont->setColor( GFXColor( 1, .5, 0, .25 ) );
520  cont->setTextColor( GUI_OPAQUE_WHITE() );
521  cont->setDownColor( GFXColor( 1, .5, 0, .6 ) );
522  cont->setDownTextColor( GUI_OPAQUE_BLACK() );
523  cont->setHighlightColor( GFXColor( 0, 1, 0, .4 ) );
524  cont->setFont( Font( .08, BOLD_STROKE ) );
525  //Put the button on the window.
526  window->addControl( cont );
527 
528  //Abort action button
529  NewButton *resume = new NewButton;
530  resume->setRect( Rect( -.35, -.20, .30, .12 ) );
531  resume->setLabel( "Cancel" );
532  resume->setCommand( "Window::Close" );
533  resume->setColor( GFXColor( 0, 1, 0, .25 ) );
534  resume->setTextColor( GUI_OPAQUE_WHITE() );
535  resume->setDownColor( GFXColor( 0, 1, 0, .6 ) );
536  resume->setDownTextColor( GUI_OPAQUE_BLACK() );
537  resume->setHighlightColor( GFXColor( 0, 1, 0, .4 ) );
538  resume->setFont( Font( .08, BOLD_STROKE ) );
539  //Put the button on the window.
540  window->addControl( resume );
541 
542  window->setModal( true );
543 }
544 
545 //Process a command event from the Options Menu window.
546 bool NetActionConfirm::processWindowCommand( const EventCommandId &command, Control *control )
547 {
548  if (command == "Save") {
550  window()->close();
551  } else if (command == "Load") {
552  confirmedNetDie();
553  window()->close();
554  } else if (command == "JoinGame") {
556  } else {
557  //Not a command we know about.
558  return WindowController::processWindowCommand( command, control );
559  }
560  return true;
561 }
562 
563 void GameMenu::readJoinGameControls( Window *window, string &user, string &pass )
564 {
565  //Magic goes here!
566  user = static_cast< TextInputDisplay* > ( window->findControlById( "Username" ) )->text();
567  string::size_type pos = user.find( ' ' );
568  while (pos != string::npos) {
569  user[pos] = '_';
570  pos = user.find( ' ', pos );
571  }
572  pass = static_cast< TextInputDisplay* > ( window->findControlById( "Password" ) )->text();
573  vs_config->setVariable( "player", "callsign", user );
574  vs_config->setVariable( "player", "password", pass );
575  if ( window->findControlById( "MultiPlayerAccountServer" )->hidden() ) {
576  vs_config->setVariable( "network", "use_account_server", "false" );
577  vs_config->setVariable( "network", "server_ip",
578  static_cast< TextInputDisplay* > ( window->findControlById( "VegaserverHost" ) )->text() );
579  vs_config->setVariable( "network", "server_port",
580  static_cast< TextInputDisplay* > ( window->findControlById( "VegaserverPort" ) )->text() );
581  } else {
582  vs_config->setVariable( "network", "use_account_server", "true" );
583  vs_config->setVariable( "network", "account_server_url",
584  static_cast< TextInputDisplay* > ( window->findControlById( "AccountServer" ) )->text() );
585  }
586  enableNetwork( true );
587  if (Network != NULL)
588  for (unsigned int i = 0; i < _Universe->numPlayers(); i++)
589  Network[i].Reinitialize();
590  else
591  Network = new NetClient[_Universe->numPlayers()]; //Hardcode 1 player anyway.
592 }
593 
595 {
596  if (!Network) return false;
597  Network[player].saveRequest();
598  return true;
599 }
600 
602 {
603  if (!Network) return false;
604  Network[player].dieRequest();
605  return true;
606 }
607 
609 {
610  string user, pass, err;
611  NetClient::CleanUp();
612  GameMenu::readJoinGameControls( m_parent, user, pass );
613 
614  UniverseUtil::showSplashScreen( string() );
615  if (!Network) return false;
616  string srvipadr;
617  unsigned short port;
618  //Are we using the directly account server to identify us ?
619  Network[player].SetConfigServerAddress( srvipadr, port ); //Sets from the config vars.
620 
621  int numships = Network[player].connectLoad( user, pass, err );
622  if (numships) {
623  const vector< string > &shipList = Network[player].shipSelections();
624  if (shipList.size() > 1) {
626  showListQuestion( err+" Select a ship to fly, or hit cancel ", shipList,
627  new ShipSelectorCallback( this, false ), "ShipSelected" );
628  } else {
629  if ( err.empty() )
630  finalizeJoinGame( 0 );
631  else
632  showYesNoQuestion( "Warning: "+err+"\n\nDo you want to join to this server?",
633  new ShipSelectorCallback( this, true ), "ServerWarning" );
634  }
635  } else {
637  if ( window() ) window()->close();
638  if ( !err.empty() )
639  err = "\nThe server said: "+err;
640  showAlert( "Error when joining game!\n"+err );
641  NetClient::CleanUp();
642  return false;
643  }
644  return true;
645 }
646 
647 //Caller is responsible for closing the window afterwards. (?)
648 //static
650 {
651  if (launchShip == -1) {
652  if ( window() ) window()->close();
653  NetClient::CleanUp();
654  return false;
655  }
658  UniverseUtil::showSplashMessage( "#cc66ffNETWORK: Loading saved game." );
659  }
660  if ( !Network[player].loginSavedGame( launchShip ) ) {
661  showAlert( "Error when logging into game with this ship!" );
662  if ( window() ) window()->close();
663  NetClient::CleanUp();
664  return false;
665  }
666  Cockpit *cp = NULL;
667  Unit *playun = NULL;
668  if (_Universe)
669  cp = _Universe->AccessCockpit( player );
670  if (cp)
671  playun = cp->GetParent();
672  if (playun)
673  playun->Kill();
674  if (_Universe)
676  string err;
677 
679  NetClient *playerClient = &Network[player];
680  Window *parentWin = m_parent;
681 
682  globalWindowManager().shutDown();
684 
685  playerClient->startGame();
686 
687  return true;
688 
689 }
690 
691 bool GameMenu::processJoinGameButton( const EventCommandId &command, Control *control )
692 {
694  nak->confirmedJoinGame();
695 
696  return true;
697 }
698