Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetActionConfirm Class Reference

#include <gamemenu.h>

Inheritance diagram for NetActionConfirm:
WindowController

Public Types

enum  ActionMode { SAVEACCT, JOINGAME, DIE }
 

Public Member Functions

 NetActionConfirm (int pnum, Window *w, ActionMode action)
 
virtual ~NetActionConfirm (void)
 
virtual void init (void)
 
virtual bool processWindowCommand (const EventCommandId &command, Control *control)
 
virtual bool finalizeJoinGame (int launchShip=0)
 
virtual bool confirmedJoinGame ()
 
virtual bool confirmedNetDie ()
 
virtual bool confirmedNetSaveGame ()
 
- Public Member Functions inherited from WindowController
virtual void run (void)
 
virtual void draw (void)
 
virtual Windowwindow (void)
 
virtual void setWindow (Window *w)
 
 WindowController ()
 
virtual ~WindowController (void)
 

Additional Inherited Members

- Protected Attributes inherited from WindowController
Windowm_window
 
bool m_deleteOnWindowClose
 

Detailed Description

Definition at line 38 of file gamemenu.h.

Member Enumeration Documentation

Enumerator
SAVEACCT 
JOINGAME 
DIE 

Definition at line 41 of file gamemenu.h.

Constructor & Destructor Documentation

NetActionConfirm::NetActionConfirm ( int  pnum,
Window w,
ActionMode  action 
)
inline

Definition at line 51 of file gamemenu.h.

51  :
52  player( pnum )
53  , m_parent( w )
54  , netAction( action ) {}
virtual NetActionConfirm::~NetActionConfirm ( void  )
inlinevirtual

Definition at line 55 of file gamemenu.h.

55 {}

Member Function Documentation

bool NetActionConfirm::confirmedJoinGame ( )
virtual

Definition at line 608 of file gamemenu.cpp.

References NetClient::CleanUp(), Window::close(), NetClient::connectLoad(), finalizeJoinGame(), UniverseUtil::hideSplashScreen(), Network, GameMenu::readJoinGameControls(), NetClient::SetConfigServerAddress(), shipList, NetClient::shipSelections(), showAlert(), showListQuestion(), UniverseUtil::showSplashScreen(), showYesNoQuestion(), and WindowController::window().

Referenced by BaseComputer::actionJoinGame(), GameMenu::processJoinGameButton(), and processWindowCommand().

609 {
610  string user, pass, err;
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 );
642  return false;
643  }
644  return true;
645 }
bool NetActionConfirm::confirmedNetDie ( )
virtual

Definition at line 601 of file gamemenu.cpp.

References NetClient::dieRequest(), and Network.

Referenced by processWindowCommand().

602 {
603  if (!Network) return false;
604  Network[player].dieRequest();
605  return true;
606 }
bool NetActionConfirm::confirmedNetSaveGame ( )
virtual

Definition at line 594 of file gamemenu.cpp.

References Network, and NetClient::saveRequest().

Referenced by processWindowCommand().

595 {
596  if (!Network) return false;
597  Network[player].saveRequest();
598  return true;
599 }
bool NetActionConfirm::finalizeJoinGame ( int  launchShip = 0)
virtual

Definition at line 649 of file gamemenu.cpp.

References _Universe, Universe::AccessCockpit(), NetClient::CleanUp(), Universe::clearAllSystems(), Window::close(), Cockpit::GetParent(), globalWindowManager(), UniverseUtil::isSplashScreenShowing(), Unit::Kill(), Network, restore_main_loop(), showAlert(), UniverseUtil::showSplashMessage(), UniverseUtil::showSplashScreen(), WindowManager::shutDown(), NetClient::startGame(), TerminateCurrentBase(), and WindowController::window().

Referenced by confirmedJoinGame(), and ShipSelectorCallback::modalDialogResult().

650 {
651  if (launchShip == -1) {
652  if ( window() ) window()->close();
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();
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 
684 
685  playerClient->startGame();
686 
687  return true;
688 
689 }
void NetActionConfirm::init ( void  )
virtual

Implements WindowController.

Definition at line 477 of file gamemenu.cpp.

References Window::addControl(), BOLD_STROKE, DIE, GUI_CLEAR(), GUI_OPAQUE_BLACK(), GUI_OPAQUE_WHITE(), JOINGAME, SAVEACCT, Window::setColor(), Control::setColor(), NewButton::setCommand(), Window::setController(), NewButton::setDownColor(), NewButton::setDownTextColor(), StaticDisplay::setFont(), Control::setFont(), NewButton::setHighlightColor(), Control::setId(), NewButton::setLabel(), EventResponder::setModal(), StaticDisplay::setMultiLine(), Window::setOutlineColor(), Window::setOutlineWidth(), Control::setRect(), StaticDisplay::setRect(), Window::setSizeAndCenter(), StaticDisplay::setText(), StaticDisplay::setTextColor(), Control::setTextColor(), Window::setTexture(), WindowController::setWindow(), and WindowController::window().

Referenced by BaseComputer::actionJoinGame(), BaseComputer::actionNetDie(), and BaseComputer::actionNetSaveGame().

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 ) );
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 }
bool NetActionConfirm::processWindowCommand ( const EventCommandId command,
Control control 
)
virtual

Reimplemented from WindowController.

Definition at line 546 of file gamemenu.cpp.

References Window::close(), confirmedJoinGame(), confirmedNetDie(), confirmedNetSaveGame(), WindowController::processWindowCommand(), and WindowController::window().

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 }

The documentation for this class was generated from the following files: