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"
19 #include "cmd/music.h"
25 const GameMenu::WctlTableEntry WctlBase< GameMenu >::WctlCommandTable[] = {
33 GameMenu::WctlTableEntry(
"",
"", NULL )
37 m_firstTime( firstTime )
44 WindowController::run();
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;
59 || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ?
shiftup( ch ) : ch );
67 globalWindowManager().draw();
76 NewButton *joinAcct =
new NewButton;
77 joinAcct->setRect( Rect( -.50, .7, .37, .09 ) );
78 joinAcct->setLabel(
"Online Account Server" );
79 joinAcct->setCommand(
"ShowJoinAccount" );
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 );
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 );
104 GroupControl *acctConnGroup =
new GroupControl;
105 acctConnGroup->setId(
"MultiPlayerAccountServer" );
106 acctConnGroup->setHidden( !useacctserver );
107 serverConnGroup->addChild( acctConnGroup );
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 );
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" );
133 hostConnGroup->addChild( serverInputText );
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 );
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" );
155 hostConnGroup->addChild( portInputText );
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 );
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" );
176 "http://vegastrike.sourceforge.net/cgi-bin/accountserver.py?" ) );
177 acctConnGroup->addChild( acctserverInput );
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 );
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 );
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 );
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 );
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 );
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 );
244 namespace UniverseUtil
249 winsys_set_mouse_func( EventManager::ProcessMouseClick );
250 winsys_set_passive_motion_func( EventManager::ProcessMousePassive );
251 winsys_set_motion_func( EventManager::ProcessMouseActive );
256 if ( !error.empty() ) {
257 gm->window()->findControlById(
"MainMenu" )->setHidden(
true );
258 gm->window()->findControlById(
"MultiPlayerMenu" )->setHidden(
false );
267 Window *w =
new Window;
270 window()->setFullScreen();
271 window()->setColor( GUI_CLEAR );
272 window()->setTexture(
"basecomputer.png" );
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" );
290 GroupControl *mainMenuGroup =
new GroupControl;
291 mainMenuGroup->setId(
"MainMenu" );
292 window()->addControl( mainMenuGroup );
294 mainMenuGroup->addChild( baseTitle );
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 );
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 );
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 );
329 GroupControl *serverConnGroup =
new GroupControl;
330 serverConnGroup->setId(
"MultiPlayerMenu" );
331 serverConnGroup->setHidden(
true );
332 window()->addControl( serverConnGroup );
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" );
342 serverConnGroup->addChild( mplayTitle );
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 );
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 );
404 NetClient::CleanUp();
411 globalWindowManager().shutDown();
418 window()->findControlById(
"MainMenu" )->setHidden(
true );
419 window()->findControlById(
"MultiPlayerMenu" )->setHidden(
false );
420 window()->findControlById(
"MultiPlayerAccountServer" )->setHidden(
true );
421 window()->findControlById(
"MultiPlayerHostPort" )->setHidden(
false );
427 window()->findControlById(
"MainMenu" )->setHidden(
true );
428 window()->findControlById(
"MultiPlayerMenu" )->setHidden(
false );
429 window()->findControlById(
"MultiPlayerAccountServer" )->setHidden(
false );
430 window()->findControlById(
"MultiPlayerHostPort" )->setHidden(
true );
436 window()->findControlById(
"MainMenu" )->setHidden(
true );
437 window()->findControlById(
"MultiPlayerMenu" )->setHidden(
false );
443 window()->findControlById(
"MainMenu" )->setHidden(
false );
444 window()->findControlById(
"MultiPlayerMenu" )->setHidden(
true );
460 , onlyMessage( onlyMessage ) {}
461 virtual void modalDialogResult(
const std::string &
id,
int result, WindowController &controller )
465 if (result == YES_ANSWER)
479 Window *window =
new Window;
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 );
490 StaticDisplay *text =
new StaticDisplay;
491 text->setRect( Rect( -.4, -.15, .8, .3 ) );
493 text->setText(
"Leaving your current game and joining a new one will lose all progress since your last save." );
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" );
504 window->addControl( text );
507 NewButton *cont =
new NewButton;
508 cont->setRect( Rect( .05, -.19, .30, .1 ) );
510 cont->setLabel(
"Save Account" );
511 cont->setCommand(
"Save" );
512 }
else if (netAction ==
DIE) {
513 cont->setLabel(
"Die" );
514 cont->setCommand(
"Load" );
516 cont->setLabel(
"Join New Game" );
517 cont->setCommand(
"JoinGame" );
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 ) );
526 window->addControl( cont );
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 ) );
540 window->addControl( resume );
542 window->setModal(
true );
548 if (command ==
"Save") {
551 }
else if (command ==
"Load") {
554 }
else if (command ==
"JoinGame") {
558 return WindowController::processWindowCommand( command, control );
566 user =
static_cast< TextInputDisplay*
> ( window->findControlById(
"Username" ) )->text();
567 string::size_type pos = user.find(
' ' );
568 while (pos != string::npos) {
570 pos = user.find(
' ', pos );
572 pass =
static_cast< TextInputDisplay*
> ( window->findControlById(
"Password" ) )->text();
575 if ( window->findControlById(
"MultiPlayerAccountServer" )->hidden() ) {
578 static_cast< TextInputDisplay* > ( window->findControlById(
"VegaserverHost" ) )->text() );
580 static_cast< TextInputDisplay* > ( window->findControlById(
"VegaserverPort" ) )->text() );
584 static_cast< TextInputDisplay* > ( window->findControlById(
"AccountServer" ) )->text() );
610 string user, pass, err;
611 NetClient::CleanUp();
619 Network[player].SetConfigServerAddress( srvipadr, port );
621 int numships =
Network[player].connectLoad( user, pass, err );
624 if (shipList.size() > 1) {
626 showListQuestion( err+
" Select a ship to fly, or hit cancel ", shipList,
632 showYesNoQuestion(
"Warning: "+err+
"\n\nDo you want to join to this server?",
637 if ( window() ) window()->close();
639 err =
"\nThe server said: "+err;
640 showAlert(
"Error when joining game!\n"+err );
641 NetClient::CleanUp();
651 if (launchShip == -1) {
652 if ( window() ) window()->close();
653 NetClient::CleanUp();
660 if ( !
Network[player].loginSavedGame( launchShip ) ) {
661 showAlert(
"Error when logging into game with this ship!" );
662 if ( window() ) window()->close();
663 NetClient::CleanUp();
671 playun = cp->GetParent();
680 Window *parentWin = m_parent;
682 globalWindowManager().shutDown();
685 playerClient->startGame();