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
BaseComputer::UpgradeOperation Class Referenceabstract
Inheritance diagram for BaseComputer::UpgradeOperation:
ModalDialogCallback BaseComputer::BuyUpgradeOperation BaseComputer::SellUpgradeOperation

Protected Member Functions

 UpgradeOperation (BaseComputer &p)
 
virtual ~UpgradeOperation (void)
 
bool commonInit (void)
 
void finish (void)
 
bool endInit (void)
 
bool gotSelectedMount (int index)
 
bool gotSelectedTurret (int index)
 
void updateUI (void)
 
virtual bool checkTransaction (void)=0
 
virtual void concludeTransaction (void)=0
 
virtual void selectMount (void)=0
 
virtual void showTurretPicker (void)
 
virtual void modalDialogResult (const std::string &id, int result, WindowController &controller)
 

Protected Attributes

BaseComputerm_parent
 
const Unitm_newPart
 
Cargo m_part
 
int m_selectedMount
 
int m_selectedTurret
 
Cargo m_selectedItem
 

Detailed Description

Definition at line 3396 of file basecomputer.cpp.

Constructor & Destructor Documentation

BaseComputer::UpgradeOperation::UpgradeOperation ( BaseComputer p)
inlineprotected

Definition at line 3399 of file basecomputer.cpp.

3399  :
3400  m_parent( p )
3401  , m_newPart( NULL )
3402  , m_part()
3403  , m_selectedMount( 0 )
3404  , m_selectedTurret( 0 )
3405  , m_selectedItem() {};
virtual BaseComputer::UpgradeOperation::~UpgradeOperation ( void  )
inlineprotectedvirtual

Definition at line 3406 of file basecomputer.cpp.

3406 {}

Member Function Documentation

virtual bool BaseComputer::UpgradeOperation::checkTransaction ( void  )
protectedpure virtual
bool BaseComputer::UpgradeOperation::commonInit ( void  )
protected

Definition at line 3476 of file basecomputer.cpp.

References m_parent, m_selectedItem, and BaseComputer::selectedItem().

3477 {
3479  if (selectedItem) {
3481  return true;
3482  } else {
3483  return false;
3484  }
3485 }
virtual void BaseComputer::UpgradeOperation::concludeTransaction ( void  )
protectedpure virtual
bool BaseComputer::UpgradeOperation::endInit ( void  )
protected

Definition at line 3501 of file basecomputer.cpp.

References getUnitFromUpgradeName(), and LOAD_FAILED.

3502 {
3503  if ( m_parent.m_player.GetUnit() ) {
3505  if (m_newPart->name != LOAD_FAILED)
3506  selectMount();
3507  else
3508  return false;
3509  }
3510  return true;
3511 }
void BaseComputer::UpgradeOperation::finish ( void  )
protected

Definition at line 3494 of file basecomputer.cpp.

3495 {
3496  //Destruct us now.
3497  delete this;
3498 }
bool BaseComputer::UpgradeOperation::gotSelectedMount ( int  index)
protected

Definition at line 3528 of file basecomputer.cpp.

References Unit::getSubUnits(), index, and showAlert().

3529 {
3530  Unit *playerUnit = m_parent.m_player.GetUnit();
3531  if (index < 0 || !playerUnit) {
3532  //The user cancelled somehow.
3533  finish();
3534  return false; //kill the window.
3535  } else {
3537  if ( !( *m_newPart->viewSubUnits() ) ) {
3538  //Not a turret. Proceed with the transaction.
3539  return checkTransaction();
3540  } else {
3541  //Is a turret.
3542  if (*playerUnit->getSubUnits() != NULL) {
3543  //Need to get selected turret.
3544  showTurretPicker();
3545  return false;
3546  } else {
3547  //Ship can't take turrets.
3548  finish();
3549  showAlert( "Your ship does not support turrets." );
3550  return false; //kill the window.
3551  }
3552  }
3553  }
3554 }
bool BaseComputer::UpgradeOperation::gotSelectedTurret ( int  index)
protected

Definition at line 3557 of file basecomputer.cpp.

References index.

3558 {
3559  if (index < 0) {
3560  //The user cancelled somehow.
3561  finish();
3562  return false; //kill the window.
3563  } else {
3565  return checkTransaction();
3566  }
3567 }
void BaseComputer::UpgradeOperation::modalDialogResult ( const std::string &  id,
int  result,
WindowController controller 
)
protectedvirtual

Implements ModalDialogCallback.

Definition at line 3570 of file basecomputer.cpp.

References YES_ANSWER.

3571 {
3572  if (id == GOT_MOUNT_ID) {
3573  //Got the selected mount from the user.
3574  gotSelectedMount( result );
3575  } else if (id == GOT_TURRET_ID) {
3576  //Got the selected turret from the user.
3577  gotSelectedTurret( result );
3578  } else if (id == CONFIRM_ID) {
3579  //User answered whether or not to conclude the transaction.
3580  if (result == YES_ANSWER)
3581  //User wants to do this.
3583  else
3584  //User doesn't want to do it. All done.
3585  finish();
3586  }
3587 }
virtual void BaseComputer::UpgradeOperation::selectMount ( void  )
protectedpure virtual
void BaseComputer::UpgradeOperation::showTurretPicker ( void  )
protectedvirtual

Definition at line 3514 of file basecomputer.cpp.

References Unit::getSubUnits(), and showListQuestion().

3515 {
3516  Unit *playerUnit = m_parent.m_player.GetUnit();
3517  if (!playerUnit) {
3518  finish();
3519  return;
3520  }
3521  vector< string >mounts;
3522  for (un_iter unitIter = playerUnit->getSubUnits(); *unitIter != NULL; unitIter++)
3523  mounts.push_back( (*unitIter)->name );
3524  showListQuestion( "Select turret mount for your turret:", mounts, this, GOT_TURRET_ID );
3525 }
void BaseComputer::UpgradeOperation::updateUI ( void  )
protected

Definition at line 3488 of file basecomputer.cpp.

3489 {
3490  m_parent.refresh();
3491 }

Member Data Documentation

const Unit* BaseComputer::UpgradeOperation::m_newPart
protected

Definition at line 3425 of file basecomputer.cpp.

BaseComputer& BaseComputer::UpgradeOperation::m_parent
protected

Definition at line 3424 of file basecomputer.cpp.

Referenced by commonInit().

Cargo BaseComputer::UpgradeOperation::m_part
protected

Definition at line 3426 of file basecomputer.cpp.

Cargo BaseComputer::UpgradeOperation::m_selectedItem
protected

Definition at line 3429 of file basecomputer.cpp.

Referenced by commonInit().

int BaseComputer::UpgradeOperation::m_selectedMount
protected

Definition at line 3427 of file basecomputer.cpp.

int BaseComputer::UpgradeOperation::m_selectedTurret
protected

Definition at line 3428 of file basecomputer.cpp.


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