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 Class Reference

#include <basecomputer.h>

Inheritance diagram for BaseComputer:
WctlBase< BaseComputer > WindowController

Classes

class  BuyUpgradeOperation
 
class  LoadSaveQuitConfirm
 
class  SellUpgradeOperation
 
struct  TransactionList
 
class  UpgradeOperation
 

Public Types

enum  DisplayMode {
  CARGO =0, UPGRADE, SHIP_DEALER, MISSIONS,
  NEWS, INFO, LOADSAVE, NETWORK,
  DISPLAY_MODE_COUNT, NULL_DISPLAY =DISPLAY_MODE_COUNT
}
 
enum  TransactionType {
  BUY_CARGO, SELL_CARGO, BUY_UPGRADE, SELL_UPGRADE,
  BUY_SHIP, ACCEPT_MISSION, NULL_TRANSACTION
}
 
- Public Types inherited from WctlBase< BaseComputer >
typedef
WindowControllerTableEntry
< BaseComputer
WctlTableEntry
 

Public Member Functions

virtual void init (void)
 
virtual void run (void)
 
virtual void draw (void)
 
 BaseComputer (Unit *player, Unit *base, const vector< DisplayMode > &modes)
 
virtual ~BaseComputer (void)
 
void updateTransactionControls (const Cargo &item, bool skipFirstCategory=false)
 
void updateTransactionControlsForSelection (TransactionList *list)
 
void loadShipDealerControls (void)
 
void secondStageJoinGame (void)
 
void finalizeJoinGame (int launchShip=0)
 
void finalizeNetSaveGame (void)
 
- Public Member Functions inherited from WctlBase< BaseComputer >
virtual bool processWindowCommand (const EventCommandId &command, Control *control)
 
- Public Member Functions inherited from WindowController
virtual Windowwindow (void)
 
virtual void setWindow (Window *w)
 
 WindowController ()
 
virtual ~WindowController (void)
 

Public Attributes

UnitContainer m_player
 
UnitContainer m_base
 

Static Public Attributes

static int dirty = 0
 

Protected Member Functions

bool newsPickerChangedSelection (const EventCommandId &command, Control *control)
 
bool loadSavePickerChangedSelection (const EventCommandId &command, Control *control)
 
bool pickerChangedSelection (const EventCommandId &command, Control *control)
 
bool buyCargo (const EventCommandId &command, Control *control)
 
bool buy10Cargo (const EventCommandId &command, Control *control)
 
bool buyAllCargo (const EventCommandId &command, Control *control)
 
bool sellCargo (const EventCommandId &command, Control *control)
 
bool sell10Cargo (const EventCommandId &command, Control *control)
 
bool sellAllCargo (const EventCommandId &command, Control *control)
 
bool buyUpgrade (const EventCommandId &command, Control *control)
 
bool sellUpgrade (const EventCommandId &command, Control *control)
 
bool fixUpgrade (const EventCommandId &command, Control *control)
 
bool buyShip (const EventCommandId &command, Control *control)
 
bool sellShip (const EventCommandId &command, Control *control)
 
bool acceptMission (const EventCommandId &command, Control *control)
 
bool actionConfirmedLoadGame ()
 
bool actionLoadGame (const EventCommandId &command, Control *control)
 
bool actionConfirmedSaveGame ()
 
bool actionSaveGame (const EventCommandId &command, Control *control)
 
bool actionNewGame (const EventCommandId &command, Control *control)
 
bool actionConfirmedQuitGame ()
 
bool actionQuitGame (const EventCommandId &command, Control *control)
 
bool actionNetSaveGame (const EventCommandId &command, Control *control)
 
bool actionNetDie (const EventCommandId &command, Control *control)
 
bool actionJoinGame (const EventCommandId &command, Control *control)
 
bool actionShowAccountMenu (const EventCommandId &command, Control *control)
 
bool actionShowServerMenu (const EventCommandId &command, Control *control)
 
bool actionDone (const EventCommandId &command, Control *control)
 
bool showPlayerInfo (const EventCommandId &command, Control *control)
 
bool showShipStats (const EventCommandId &command, Control *control)
 
bool changeToCargoMode (const EventCommandId &command, Control *control)
 
bool changeToUpgradeMode (const EventCommandId &command, Control *control)
 
bool changeToShipDealerMode (const EventCommandId &command, Control *control)
 
bool changeToNewsMode (const EventCommandId &command, Control *control)
 
bool changeToMissionsMode (const EventCommandId &command, Control *control)
 
bool changeToInfoMode (const EventCommandId &command, Control *control)
 
bool changeToLoadSaveMode (const EventCommandId &command, Control *control)
 
bool changeToNetworkMode (const EventCommandId &command, Control *control)
 
void showNetworkStatus (bool show=true)
 
bool hideNetworkStatus (const EventCommandId &command, Control *control)
 
void recalcTitle (void)
 
void refresh (void)
 
bool isTransactionOK (const Cargo &originalItem, TransactionType transType, int quantity=1)
 
SimplePickerCellcreateCategoryCell (SimplePickerCells &cells, const string &category, bool skipFirstCategory)
 
void loadListPicker (TransactionList &list, SimplePicker &picker, TransactionType transType, bool skipFirstCategory=false)
 
bool scrollToItem (Picker *picker, const Cargo &item, bool select, bool skipFirstCategory)
 
void hideCommitControls (void)
 
void configureCargoCommitControls (const Cargo &item, TransactionType trans)
 
bool configureUpgradeCommitControls (const Cargo &item, TransactionType trans)
 
void resetTransactionLists (void)
 
void loadCargoControls (void)
 
bool buySelectedCargo (int requestedQuantity)
 
int maxQuantityForPlayer (const Cargo &item, int suggestedQuantity)
 
bool sellSelectedCargo (int requestedQuantity)
 
void loadNewsControls (void)
 
void loadLoadSaveControls (void)
 
void loadNetworkControls (void)
 
void loadMissionsControls (void)
 
void loadUpgradeControls (void)
 
void loadBuyUpgradeControls (void)
 
void loadSellUpgradeControls (void)
 
CargoselectedItem (void)
 
void switchToControls (DisplayMode mode)
 
void createModeButtons (void)
 
void createControls (void)
 
void constructControls (void)
 
GFXColor getColorForGroup (std::string id)
 
void loadMasterList (Unit *un, const vector< string > &filterthis, const vector< string > &invfilterthis, bool removezero, TransactionList &list)
 
void loadMissionsMasterList (TransactionList &list)
 

Protected Attributes

vector< DisplayModem_displayModes
 
DisplayMode m_currentDisplay
 
TransactionList m_transList1
 
TransactionList m_transList2
 
TransactionListm_selectedList
 
Controlm_modeGroups [DISPLAY_MODE_COUNT]
 
bool m_playingMuzak
 

Friends

class WctlBase< BaseComputer >
 
class LoadSaveQuitConfirm
 
class UpgradeOperation
 
class BuyUpgradeOperation
 
class SellUpgradeOperation
 

Additional Inherited Members

- Static Protected Attributes inherited from WctlBase< BaseComputer >
static const WctlTableEntry WctlCommandTable []
 

Detailed Description

Definition at line 39 of file basecomputer.h.

Member Enumeration Documentation

Enumerator
CARGO 
UPGRADE 
SHIP_DEALER 
MISSIONS 
NEWS 
INFO 
LOADSAVE 
NETWORK 
DISPLAY_MODE_COUNT 
NULL_DISPLAY 

Definition at line 47 of file basecomputer.h.

48  {
49  CARGO=0, //Buy and sell cargo.
50  UPGRADE, //Buy and sell ship upgrades.
51  SHIP_DEALER, //Replace current ship.
52  MISSIONS, //Show available missions.
53  NEWS, //Show news items.
54  INFO, //Show basic info.
55  LOADSAVE, //LOAD SAVE
56  NETWORK, //Network submenu of Loadsave.
57  DISPLAY_MODE_COUNT, //Number of display modes.
58  NULL_DISPLAY=DISPLAY_MODE_COUNT, //No display.
59  };
Enumerator
BUY_CARGO 
SELL_CARGO 
BUY_UPGRADE 
SELL_UPGRADE 
BUY_SHIP 
ACCEPT_MISSION 
NULL_TRANSACTION 

Definition at line 80 of file basecomputer.h.

81  {
82  BUY_CARGO, //Buy item and put in ship.
83  SELL_CARGO, //Sell item to base.
84  BUY_UPGRADE, //Buy an improvement for current ship.
85  SELL_UPGRADE, //Sell an improvement on current ship.
86  BUY_SHIP, //Replace our current ship with a new one.
87  ACCEPT_MISSION, //Accept a mission.
88  NULL_TRANSACTION, //Not initialized yet.
89  };

Constructor & Destructor Documentation

BaseComputer::BaseComputer ( Unit player,
Unit base,
const vector< DisplayMode > &  modes 
)

Definition at line 443 of file basecomputer.cpp.

References DISPLAY_MODE_COUNT, i, and m_modeGroups.

443  :
444  m_displayModes( modes )
445  , m_player( player )
446  , m_base( base )
448  , m_selectedList( NULL )
449  , m_playingMuzak( false )
450 {
451  //Make sure we get this color loaded.
452  //Initialize mode group controls array.
453  for (int i = 0; i < DISPLAY_MODE_COUNT; i++)
454  m_modeGroups[i] = NULL;
455 }
BaseComputer::~BaseComputer ( void  )
virtual

Definition at line 458 of file basecomputer.cpp.

References DISPLAY_MODE_COUNT, i, m_base, m_modeGroups, m_player, m_playingMuzak, muzak, UnitContainer::SetUnit(), and Music::Skip().

459 {
460  m_player.SetUnit( NULL );
461  m_base.SetUnit( NULL );
462  //Delete any group controls that the window doesn't "own".
463  for (int i = 0; i < DISPLAY_MODE_COUNT; i++)
464  if (m_modeGroups[i] != NULL)
465  delete m_modeGroups[i];
466  //If we are playing muzak, stop it.
467  if (m_playingMuzak)
468  muzak->Skip();
469 }

Member Function Documentation

bool BaseComputer::acceptMission ( const EventCommandId command,
Control control 
)
protected

Definition at line 3190 of file basecomputer.cpp.

References _Universe, ACCEPT_MISSION, Subcmd::AcceptMission, active_missions, Cargo::category, CATEGORY_SEP, Cargo::content, eraseSaveString(), Cargo::GetCategory(), Cargo::GetContent(), Mission::getPlayerMissionNumber(), getSaveString(), getSaveStringLength(), UnitContainer::GetUnit(), i, UnitUtil::isPlayerStarship(), isTransactionOK(), LoadMission(), loadMissionsControls(), m_base, m_player, mission, MISSION_DESC_LABEL, MISSION_NAMES_LABEL, MISSION_SCRIPTS_LABEL, NetClient::missionRequest(), Network, refresh(), selectedItem(), Subcmd::TerminateMission, Mission::terminateMission(), updateTransactionControlsForSelection(), and Universe::whichPlayerStarship().

3191 {
3192  Unit *playerUnit = m_player.GetUnit();
3193  Unit *baseUnit = m_base.GetUnit();
3194  if ( !(playerUnit && baseUnit) ) return true;
3195  Cargo *item = selectedItem();
3196  if ( !item || !isTransactionOK( *item, ACCEPT_MISSION ) ) {
3197  //Better reload the UI -- we shouldn't have gotten here.
3200  return true;
3201  }
3202  if (item->GetCategory().find( "Active_Missions" ) != string::npos) {
3203  unsigned int whichmission = atoi( item->GetContent().c_str() );
3204  if ( whichmission > 0 && whichmission < active_missions.size() ) {
3205  Mission *miss = active_missions[whichmission];
3206  if (Network == NULL) {
3207  miss->terminateMission();
3208  if (miss == mission)
3209  mission = active_missions[0];
3210  refresh();
3211  } else if ( m_player.GetUnit() ) {
3213  if (cp < 0) cp = 0;
3214  int num = miss->getPlayerMissionNumber();
3215 
3216  Network[cp].missionRequest( Subcmd::TerminateMission, string(), num );
3217  }
3218  return true;
3219  }
3220  return false;
3221  }
3222  const int playernum = UnitUtil::isPlayerStarship( playerUnit );
3223  const size_t stringCount = getSaveStringLength( playernum, MISSION_NAMES_LABEL );
3224  if (Network == NULL)
3225  assert( stringCount == getSaveStringLength( playernum, MISSION_SCRIPTS_LABEL ) );
3226  string qualifiedName;
3227  if ( item->GetCategory().empty() )
3228  qualifiedName = item->content;
3229  else
3230  qualifiedName = item->GetCategory()+CATEGORY_SEP+item->GetContent();
3231  string finalScript;
3232  for (size_t i = 0; i < stringCount; i++)
3233  if (getSaveString( playernum, MISSION_NAMES_LABEL, i ) == qualifiedName) {
3234  if (Network == NULL) {
3235  finalScript = getSaveString( playernum, MISSION_SCRIPTS_LABEL, i );
3236  eraseSaveString( playernum, MISSION_SCRIPTS_LABEL, i );
3237  eraseSaveString( playernum, MISSION_NAMES_LABEL, i );
3238  eraseSaveString( playernum, MISSION_DESC_LABEL, i );
3239  } else {
3240  finalScript = "#";
3241  }
3242  break;
3243  }
3244  if ( finalScript.empty() ) {
3245  return false;
3246  } else {
3247  if (Network == NULL) {
3248  LoadMission( ("#"+item->category).c_str(),
3249  finalScript, false );
3250  refresh();
3251  } else if ( m_player.GetUnit() ) {
3253  if (cp < 0) cp = 0;
3254  Network[cp].missionRequest( Subcmd::AcceptMission, qualifiedName, active_missions.size() );
3255  }
3256  }
3257  //We handled the command, whether we successfully accepted the mission or not.
3258  return true;
3259 }
bool BaseComputer::actionConfirmedLoadGame ( )
protected

Definition at line 6120 of file basecomputer.cpp.

References _Universe, NetClient::CleanUp(), Window::findControlById(), UnitContainer::GetUnit(), globalWindowManager(), Universe::isPlayerStarship(), Unit::Kill(), m_player, RespawnNow(), UniverseUtil::setCurrentSaveGame(), showAlert(), UniverseUtil::showSplashMessage(), UniverseUtil::showSplashScreen(), WindowManager::shutDown(), TerminateCurrentBase(), StaticDisplay::text(), and WindowController::window().

6121 {
6122  Unit *player = m_player.GetUnit();
6123  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
6124  if (desc) {
6125  std::string tmp = desc->text();
6126  if (tmp.length() > 0) {
6127  Cockpit *cockpit = player ? _Universe->isPlayerStarship( player ) : 0;
6128  if (player && cockpit) {
6130  UniverseUtil::showSplashMessage( "Loading saved game." );
6133  player->Kill();
6134  RespawnNow( cockpit );
6136  TerminateCurrentBase(); //BaseInterface::CurrentBase->Terminate();
6137  } else {
6138  showAlert( "Oops - unexpected error (player or cockpit is null)" );
6139  }
6140  } else {
6141  showAlert( "You Must Type In a Name To Load...." );
6142  }
6143  } else {
6144  showAlert( "Oops - unexpected error (desc control not found!)" );
6145  }
6146  return true;
6147 }
bool BaseComputer::actionConfirmedQuitGame ( )
protected

Definition at line 6032 of file basecomputer.cpp.

References CockpitKeys::QuitNow().

6033 {
6035  return true;
6036 }
bool BaseComputer::actionConfirmedSaveGame ( )
protected

Definition at line 6046 of file basecomputer.cpp.

References _Universe, VSFileSystem::VSFile::Close(), Window::findControlById(), UnitContainer::GetUnit(), Universe::isPlayerStarship(), loadLoadSaveControls(), m_player, Unit::name, VSFileSystem::Ok, VSFileSystem::VSFile::OpenCreateWrite(), VSFileSystem::SaveFile, UniverseUtil::setCurrentSaveGame(), showAlert(), StaticDisplay::text(), WindowController::window(), and WriteSaveGame().

Referenced by actionSaveGame().

6047 {
6048  Unit *player = m_player.GetUnit();
6049  if (player && player->name == "return_to_cockpit") {
6050  showAlert( "Return to a base to save." );
6051  return false; //should be false, but causes badness.
6052  }
6053  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
6054  if (desc) {
6055  std::string tmp = desc->text();
6058  if (err > Ok) {
6059  showAlert(
6060  "Could not create the saved game because it contains invalid characters or you do not have permissions or free space." );
6061  } else {
6062  fp.Close();
6063  if (tmp.length() > 0) {
6064  Cockpit *cockpit = player ? _Universe->isPlayerStarship( player ) : 0;
6065  if (player && cockpit) {
6067  WriteSaveGame( cockpit, false );
6069  showAlert( "Game saved successfully." );
6070  } else {
6071  showAlert( "Oops - unexpected error (player or cockpit is null)" );
6072  }
6073  } else {
6074  showAlert( "You Must Type In a Name To Save." );
6075  }
6076  }
6077  } else {
6078  showAlert( "Oops - unexpected error (desc control not found!)" );
6079  }
6080  return true;
6081 }
bool BaseComputer::actionDone ( const EventCommandId command,
Control control 
)
protected

Definition at line 288 of file basecomputer.cpp.

References AUDStopAllSounds(), Window::close(), and WindowController::window().

289 {
291  window()->close();
292  return true;
293 }
bool BaseComputer::actionJoinGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6218 of file basecomputer.cpp.

References NetActionConfirm::confirmedJoinGame(), NetActionConfirm::init(), NetActionConfirm::JOINGAME, Network, WindowController::run(), and WindowController::window().

6219 {
6221  if (Network != NULL) {
6222  //confirm.
6223  nak->init();
6224  nak->run();
6225  } else {
6226  nak->confirmedJoinGame();
6227  }
6228  return true;
6229 }
bool BaseComputer::actionLoadGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6156 of file basecomputer.cpp.

References _Universe, Window::findControlById(), UnitContainer::GetUnit(), BaseComputer::LoadSaveQuitConfirm::init(), Universe::isPlayerStarship(), LoadSaveQuitConfirm, m_player, WindowController::run(), showAlert(), StaticDisplay::text(), and WindowController::window().

Referenced by actionNewGame().

6157 {
6158  Unit *player = m_player.GetUnit();
6159  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
6160  if (desc) {
6161  std::string tmp = desc->text();
6162  if (tmp.length() > 0) {
6163  if (player) {
6164  Cockpit *cockpit = _Universe->isPlayerStarship( player );
6165  if (cockpit) {
6166  LoadSaveQuitConfirm *saver = new LoadSaveQuitConfirm( this,
6167  "Load",
6168  "Are you sure that you want to load this game?" );
6169  saver->init();
6170  saver->run();
6171  return true;
6172  }
6173  }
6174  }
6175  }
6176  showAlert( "You Must Type In a Name To Load...." );
6177  return true;
6178 }
bool BaseComputer::actionNetDie ( const EventCommandId command,
Control control 
)
protected

Definition at line 6198 of file basecomputer.cpp.

References NetActionConfirm::DIE, NetActionConfirm::init(), Network, WindowController::run(), and WindowController::window().

6199 {
6200  if (Network != NULL) {
6202  nak->init();
6203  nak->run();
6204  }
6205  return true;
6206 }
bool BaseComputer::actionNetSaveGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6208 of file basecomputer.cpp.

References NetActionConfirm::init(), Network, WindowController::run(), NetActionConfirm::SAVEACCT, and WindowController::window().

6209 {
6210  if (Network != NULL) {
6212  nak->init();
6213  nak->run();
6214  }
6215  return true;
6216 }
bool BaseComputer::actionNewGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6149 of file basecomputer.cpp.

References actionLoadGame(), Window::findControlById(), UniverseUtil::getNewGameSaveName(), StaticDisplay::setText(), and WindowController::window().

6150 {
6151  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
6153  return this->actionLoadGame( command, control );
6154 }
bool BaseComputer::actionQuitGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6038 of file basecomputer.cpp.

References BaseComputer::LoadSaveQuitConfirm::init(), LoadSaveQuitConfirm, and WindowController::run().

6039 {
6040  LoadSaveQuitConfirm *saver = new LoadSaveQuitConfirm( this, "Quit", "Are you sure that you want to quit?" );
6041  saver->init();
6042  saver->run();
6043  return true;
6044 }
bool BaseComputer::actionSaveGame ( const EventCommandId command,
Control control 
)
protected

Definition at line 6083 of file basecomputer.cpp.

References _Universe, actionConfirmedSaveGame(), VSFileSystem::VSFile::Close(), Window::findControlById(), UnitContainer::GetUnit(), BaseComputer::LoadSaveQuitConfirm::init(), Universe::isPlayerStarship(), LoadSaveQuitConfirm, m_player, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), WindowController::run(), VSFileSystem::SaveFile, showAlert(), StaticDisplay::text(), and WindowController::window().

6084 {
6085  Unit *player = m_player.GetUnit();
6086  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
6087  bool ok = true;
6088  std::string tmp;
6089  if (desc) {
6090  tmp = desc->text();
6091  if (tmp.length() <= 0)
6092  ok = false;
6093  }
6094  if (player && ok) {
6095  Cockpit *cockpit = _Universe->isPlayerStarship( player );
6096  if (cockpit) {
6098  VSFileSystem::VSError err = fp.OpenReadOnly( tmp, SaveFile );
6099  if (err > Ok) {
6101  } else {
6102  fp.Close();
6103  if (string( "New_Game" ) != tmp) {
6104  LoadSaveQuitConfirm *saver = new LoadSaveQuitConfirm( this,
6105  "Save",
6106  "Do you want to overwrite your old saved game?" );
6107  saver->init();
6108  saver->run();
6109  } else {
6110  showAlert( "You may not save to the name New_Game." );
6111  }
6112  }
6113  }
6114  }
6115  if (!ok)
6116  showAlert( "You Must Type In a Name To Save." );
6117  return true;
6118 }
bool BaseComputer::actionShowAccountMenu ( const EventCommandId command,
Control control 
)
protected

Definition at line 6191 of file basecomputer.cpp.

References Window::findControlById(), Control::setHidden(), and WindowController::window().

6192 {
6193  window()->findControlById( "MultiPlayerAccountServer" )->setHidden( false );
6194  window()->findControlById( "MultiPlayerHostPort" )->setHidden( true );
6195  return true;
6196 }
bool BaseComputer::actionShowServerMenu ( const EventCommandId command,
Control control 
)
protected

Definition at line 6184 of file basecomputer.cpp.

References Window::findControlById(), Control::setHidden(), and WindowController::window().

6185 {
6186  window()->findControlById( "MultiPlayerAccountServer" )->setHidden( true );
6187  window()->findControlById( "MultiPlayerHostPort" )->setHidden( false );
6188  return true;
6189 }
bool BaseComputer::buy10Cargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2863 of file basecomputer.cpp.

References buySelectedCargo().

2864 {
2865  return buySelectedCargo( 10 );
2866 }
bool BaseComputer::buyAllCargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2869 of file basecomputer.cpp.

References buySelectedCargo().

2870 {
2871  return buySelectedCargo( -1 );
2872 }
bool BaseComputer::buyCargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2857 of file basecomputer.cpp.

References buySelectedCargo().

2858 {
2859  return buySelectedCargo( 1 );
2860 }
bool BaseComputer::buySelectedCargo ( int  requestedQuantity)
protected

Definition at line 2836 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), Unit::BuyCargo(), Cargo::content, Cockpit::credits, eliminateZeroCargo(), UnitContainer::GetUnit(), m_base, m_player, maxQuantityForPlayer(), Cargo::quantity, refresh(), and selectedItem().

Referenced by buy10Cargo(), buyAllCargo(), and buyCargo().

2837 {
2838  Unit *playerUnit = m_player.GetUnit();
2839  Unit *baseUnit = m_base.GetUnit();
2840  if ( !(playerUnit && baseUnit) )
2841  return true;
2842  Cargo *item = selectedItem();
2843  if (item) {
2844  int quantity = (requestedQuantity <= 0 ? item->quantity : requestedQuantity);
2845  quantity = maxQuantityForPlayer( *item, quantity );
2846  playerUnit->BuyCargo( item->content, quantity, baseUnit, _Universe->AccessCockpit()->credits );
2847  eliminateZeroCargo( playerUnit );
2848  //Reload the UI -- inventory has changed. Because we reload the UI, we need to
2849  //find, select, and scroll to the thing we bought. The item might be gone from the
2850  //list (along with some categories) after the transaction.
2851  refresh(); //This will reload master lists.
2852  }
2853  return true;
2854 }
bool BaseComputer::buyShip ( const EventCommandId command,
Control control 
)
protected

Definition at line 4616 of file basecomputer.cpp.

References Cargo::GetCategory(), Cargo::GetContent(), UnitContainer::GetUnit(), m_base, m_player, and selectedItem().

4617 {
4618  Unit *playerUnit = m_player.GetUnit();
4619  Unit *baseUnit = m_base.GetUnit();
4620  Cargo *item = selectedItem();
4621  if ( !(playerUnit && baseUnit && item) )
4622  return true;
4623  ::buyShip( baseUnit, playerUnit, item->GetContent(), item->GetCategory().find( "My_Fleet" ) != string::npos, true, this ); //last was false BUCO
4624  return true;
4625 }
bool BaseComputer::buyUpgrade ( const EventCommandId command,
Control control 
)
protected

Definition at line 3951 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), BASIC_REPAIR_NAME, BasicRepair(), Unit::BuyCargo(), BuyUpgradeOperation, Cargo::category, Cargo::content, Cockpit::credits, UnitContainer::GetUnit(), isWeapon(), m_base, m_player, m_selectedList, m_transList1, BaseComputer::TransactionList::picker, refresh(), Picker::selectCell(), selectedItem(), BaseComputer::BuyUpgradeOperation::start(), and Unit::Upgrade().

3952 {
3953  //Take care of Basic Repair, which is implemented entirely in this module.
3954  Cargo *item = selectedItem();
3955  if (item) {
3956  Unit *playerUnit = m_player.GetUnit();
3957  if (item->content == BASIC_REPAIR_NAME) {
3958  if (playerUnit) {
3959  BasicRepair( playerUnit );
3960  if (m_selectedList == NULL)
3961  return true;
3962  refresh();
3963  m_transList1.picker->selectCell( NULL ); //Turn off selection.
3964  }
3965  return true;
3966  }
3967  if ( !isWeapon( item->category ) ) {
3968  if (playerUnit) {
3969  Unit *baseUnit = m_base.GetUnit();
3970  if (baseUnit) {
3971  const int quantity = 1;
3972  playerUnit->BuyCargo( item->content, quantity, baseUnit, _Universe->AccessCockpit()->credits );
3973  playerUnit->Upgrade( item->content, 0, 0, true, false );
3974  refresh();
3975  }
3976  }
3977  return true;
3978  }
3979  }
3980  //This complicated operation is done in a separate object.
3981  BuyUpgradeOperation *op = new BuyUpgradeOperation( *this );
3982  op->start();
3983 
3984  return true;
3985 }
bool BaseComputer::changeToCargoMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 1688 of file basecomputer.cpp.

References CARGO, loadCargoControls(), m_currentDisplay, switchToControls(), and updateTransactionControlsForSelection().

1689 {
1690  if (m_currentDisplay != CARGO)
1694  return true;
1695 }
bool BaseComputer::changeToInfoMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 4628 of file basecomputer.cpp.

References INFO, m_currentDisplay, recalcTitle(), EventResponder::sendCommand(), switchToControls(), and WindowController::window().

4629 {
4630  if (m_currentDisplay != INFO) {
4632  //Initialize description with player info.
4633  window()->sendCommand( "ShowPlayerInfo", NULL );
4634  recalcTitle();
4635  }
4636  return true;
4637 }
bool BaseComputer::changeToLoadSaveMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 1697 of file basecomputer.cpp.

References loadLoadSaveControls(), LOADSAVE, m_currentDisplay, and switchToControls().

1698 {
1699  if (m_currentDisplay != LOADSAVE)
1702  return true;
1703 }
bool BaseComputer::changeToMissionsMode ( const EventCommandId command,
Control control 
)
protected
bool BaseComputer::changeToNetworkMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 1719 of file basecomputer.cpp.

References loadNetworkControls(), m_currentDisplay, Network, NETWORK, showNetworkStatus(), and switchToControls().

1720 {
1721  if (m_currentDisplay != NETWORK)
1723  if (Network)
1724  showNetworkStatus( true );
1725  else
1726  showNetworkStatus( false );
1728  return true;
1729 }
bool BaseComputer::changeToNewsMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 2922 of file basecomputer.cpp.

References loadNewsControls(), m_currentDisplay, NEWS, and switchToControls().

2923 {
2924  if (m_currentDisplay != NEWS)
2926  loadNewsControls();
2927  return true;
2928 }
bool BaseComputer::changeToShipDealerMode ( const EventCommandId command,
Control control 
)
protected
bool BaseComputer::changeToUpgradeMode ( const EventCommandId command,
Control control 
)
protected

Definition at line 3363 of file basecomputer.cpp.

References UnitContainer::GetUnit(), loadUpgradeControls(), m_base, m_currentDisplay, m_player, switchToControls(), updateTransactionControlsForSelection(), and UPGRADE.

3364 {
3365  Unit *playerUnit = m_player.GetUnit();
3366  Unit *baseUnit = m_base.GetUnit();
3367  if ( !(playerUnit && baseUnit) ) return true;
3368  if (m_currentDisplay != UPGRADE)
3372  return true;
3373 }
void BaseComputer::configureCargoCommitControls ( const Cargo item,
TransactionType  trans 
)
protected

Definition at line 1943 of file basecomputer.cpp.

References BUY_CARGO, Window::findControlById(), maxQuantityForPlayer(), Cargo::mission, Cargo::price, Cargo::quantity, SELL_CARGO, NewButton::setCommand(), Control::setHidden(), NewButton::setLabel(), StaticDisplay::setText(), and WindowController::window().

Referenced by updateTransactionControlsForSelection().

1944 {
1945  if (trans == BUY_CARGO) {
1946  //"Buy 1" button.
1947  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
1948  assert( commitButton != NULL );
1949  commitButton->setHidden( false );
1950  commitButton->setLabel( "Buy 1" );
1951  commitButton->setCommand( "BuyCargo" );
1952 
1953  //"Buy 10" button.
1954  NewButton *commit10Button = static_cast< NewButton* > ( window()->findControlById( "Commit10" ) );
1955  assert( commit10Button != NULL );
1956  commit10Button->setHidden( false );
1957  commit10Button->setLabel( "Buy 10" );
1958  commit10Button->setCommand( "Buy10Cargo" );
1959 
1960  //"Buy All" button.
1961  NewButton *commitAllButton = static_cast< NewButton* > ( window()->findControlById( "CommitAll" ) );
1962  assert( commitAllButton != NULL );
1963  commitAllButton->setHidden( false );
1964  commitAllButton->setLabel( "Buy" );
1965  commitAllButton->setCommand( "BuyAllCargo" );
1966 
1967  const int maxQuantity = maxQuantityForPlayer( item, item.quantity );
1968 
1969  //Total price display.
1970  const double totalPrice = item.price*maxQuantity;
1971  char tempString[2048];
1972  sprintf( tempString, "Total: #b#%.2f#-b", totalPrice );
1973  StaticDisplay *totalDisplay = static_cast< StaticDisplay* > ( window()->findControlById( "TotalPrice" ) );
1974  assert( totalDisplay != NULL );
1975  totalDisplay->setText( tempString );
1976 
1977  //Limit if we have one.
1978  StaticDisplay *maxForPlayer = static_cast< StaticDisplay* > ( window()->findControlById( "MaxQuantity" ) );
1979  assert( maxForPlayer != NULL );
1980  if (maxQuantity >= item.quantity) {
1981  //No limits, so let's not mention anything.
1982  maxForPlayer->setText( "" );
1983  } else {
1984  char maxString[2048];
1985  sprintf( maxString, "Max: #b#%d#-b", maxQuantity );
1986  maxForPlayer->setText( maxString );
1987  }
1988  } else {
1989  assert( trans == SELL_CARGO );
1990 
1991  //"Sell" button.
1992  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
1993  assert( commitButton != NULL );
1994  commitButton->setHidden( false );
1995  commitButton->setLabel( item.mission ? "Dump 1" : "Sell 1" );
1996  commitButton->setCommand( "SellCargo" );
1997 
1998  //"Sell 10" button.
1999  NewButton *commit10Button = static_cast< NewButton* > ( window()->findControlById( "Commit10" ) );
2000  assert( commit10Button != NULL );
2001  commit10Button->setHidden( false );
2002  commit10Button->setLabel( item.mission ? "Dump 10" : "Sell 10" );
2003  commit10Button->setCommand( "Sell10Cargo" );
2004 
2005  //"Sell All" button.
2006  NewButton *commitAllButton = static_cast< NewButton* > ( window()->findControlById( "CommitAll" ) );
2007  assert( commitAllButton != NULL );
2008  commitAllButton->setHidden( false );
2009  commitAllButton->setLabel( item.mission ? "Dump" : "Sell" );
2010  commitAllButton->setCommand( "SellAllCargo" );
2011 
2012  //Total price display.
2013  const double totalPrice = item.price*item.quantity*(item.mission ? 0 : 1);
2014  char tempString[2048];
2015  sprintf( tempString, "Total: #b#%.2f#-b", totalPrice );
2016  StaticDisplay *totalDisplay = static_cast< StaticDisplay* > ( window()->findControlById( "TotalPrice" ) );
2017  assert( totalDisplay != NULL );
2018  totalDisplay->setText( tempString );
2019 
2020  //No limit.
2021  StaticDisplay *maxForPlayer = static_cast< StaticDisplay* > ( window()->findControlById( "MaxQuantity" ) );
2022  assert( maxForPlayer != NULL );
2023  maxForPlayer->setText( "" );
2024  }
2025 }
bool BaseComputer::configureUpgradeCommitControls ( const Cargo item,
TransactionType  trans 
)
protected

Definition at line 2028 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), BUY_UPGRADE, c, Cargo::category, Cargo::content, Cockpit::credits, emergency_downgrade_mode, Window::findControlById(), Unit::GetCargo(), Cargo::GetCategory(), UnitContainer::GetUnit(), VegaConfig::getVariable(), i, isWeapon(), m_base, m_player, Unit::numCargo(), XMLSupport::parse_bool(), UnitUtil::PercentOperational(), Unit::PriceCargo(), RepairPrice(), NewButton::setCommand(), Control::setHidden(), NewButton::setLabel(), vs_config, and WindowController::window().

Referenced by updateTransactionControlsForSelection().

2029 {
2030  bool damaged_mode = false;
2031  if (trans == BUY_UPGRADE) {
2032  //base inventory
2033  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
2034  assert( commitButton != NULL );
2035  commitButton->setHidden( false );
2036  commitButton->setLabel( "Buy" );
2037  commitButton->setCommand( "BuyUpgrade" );
2038 
2039  NewButton *commitFixButton = static_cast< NewButton* > ( window()->findControlById( "CommitFix" ) );
2040  assert( commitButton != NULL );
2041  commitFixButton->setHidden( true );
2042  commitFixButton->setLabel( "Fix" );
2043  commitFixButton->setCommand( "FixUpgrade" );
2044  } else {
2045  //Sell Upgrade - Local Inventory
2046  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
2047  assert( commitButton != NULL );
2048  if ( m_player.GetUnit() ) {
2049  bool CanDoSell = true;
2050  Unit *player = m_player.GetUnit();
2051  unsigned int numc = player->numCargo();
2052  if ( !isWeapon( item.category ) ) {
2053  //weapons can always be sold
2054  for (unsigned int i = 0; i < numc; ++i) {
2055  Cargo *c = &player->GetCargo( i );
2056  if ( c->GetCategory().find( "upgrades/" ) == 0 && !isWeapon( c->category ) ) {
2057  float po = UnitUtil::PercentOperational( player, c->content, c->category, false );
2058  if (po > .02 && po < .98) {
2059  static bool must_fix_first =
2060  XMLSupport::parse_bool( vs_config->getVariable( "physics", "must_repair_to_sell", "true" ) );
2061 
2062  CanDoSell = (emergency_downgrade_mode.length() != 0 || must_fix_first == false);
2063  }
2064  }
2065  }
2066  }
2067  if (CanDoSell) {
2068  commitButton->setHidden( false );
2069  commitButton->setLabel( "Sell" );
2070  commitButton->setCommand( "SellUpgrade" );
2071  } else {
2072  damaged_mode = true;
2073  commitButton->setHidden( true );
2074  commitButton->setLabel( "Fix1st" );
2075  commitButton->setCommand( "" );
2076  }
2077  }
2078  NewButton *commitFixButton = static_cast< NewButton* > ( window()->findControlById( "CommitFix" ) );
2079  bool unhidden = true;
2080  if (m_player.GetUnit() && UnitUtil::PercentOperational( m_player.GetUnit(), item.content, item.category, false ) < 1) {
2081  if ( m_base.GetUnit() ) {
2083  item.content, item.category, false ),
2084  m_base.GetUnit()->PriceCargo( item.content ) )
2085  <= _Universe->AccessCockpit()->credits) {
2086  assert( commitFixButton != NULL );
2087  if (commitFixButton) {
2088  commitFixButton->setHidden( false );
2089  commitFixButton->setLabel( "Fix" );
2090  commitFixButton->setCommand( "FixUpgrade" );
2091  unhidden = false;
2092  }
2093  }
2094  }
2095  }
2096  if (unhidden && commitFixButton)
2097  commitFixButton->setHidden( true );
2098  }
2099  return damaged_mode;
2100 }
void BaseComputer::constructControls ( void  )
protected

Definition at line 507 of file basecomputer.cpp.

References GroupControl::addChild(), Window::addControl(), GFXColor::b, base_keyboard_queue, BOLD_STROKE, CENTER_JUSTIFY, GameMenu::createNetworkControls(), done, Unit::faction, GFXColor::g, NetClient::getCallsign(), getColorForGroup(), getConfigColor(), NetClient::GetCurrentServerAddress(), FactionUtil::GetFaction(), Unit::getFullname(), FactionUtil::GetSparkColor(), NetClient::getUnit(), VegaConfig::getVariable(), GUI_CLEAR(), GUI_OPAQUE_BLACK(), GUI_OPAQUE_MEDIUM_GRAY(), GUI_OPAQUE_WHITE(), m_displayModes, Network, NETWORK, XMLSupport::parse_bool(), q, quit, GFXColor::r, NetClient::serial, NewButton::setBorderColor(), Scroller::setButtonColor(), Scroller::setColor(), Control::setColor(), NewButton::setCommand(), NewButton::setDownColor(), NewButton::setDownTextColor(), NewButton::setEndBorderColor(), StaticDisplay::setFont(), Control::setFont(), Control::setHidden(), NewButton::setHighlightColor(), Picker::setHighlightColor(), Picker::setHighlightTextColor(), Control::setId(), StaticDisplay::setJustification(), NewButton::setLabel(), StaticDisplay::setMultiLine(), Control::setOutlineColor(), Control::setRect(), Scroller::setRect(), StaticDisplay::setRect(), StaticDisplay::setScroller(), Picker::setScroller(), Picker::setSelectionColor(), NewButton::setShadowWidth(), StaticDisplay::setText(), Scroller::setTextColor(), StaticDisplay::setTextColor(), Control::setTextColor(), StaticDisplay::setTextMargins(), Picker::setTextMargins(), StaticImageDisplay::setTexture(), Scroller::setThumbColor(), NewButton::setVariableBorderCycleTime(), UnsaturatedColor(), vs_config, and WindowController::window().

Referenced by createControls().

508 {
509  if (m_displayModes.size() != 1 || m_displayModes[0] != NETWORK) {
510  //Base info title.
511  StaticDisplay *baseTitle = new StaticDisplay;
512  baseTitle->setRect( Rect( -.96, .76, 1.9, .08 ) );
513  baseTitle->setText( "ERROR" );
514  static GFXColor baseNameColor = getConfigColor( "base_name_color", GFXColor( .1, .8, .1 ) );
515  baseTitle->setTextColor( baseNameColor );
516  baseTitle->setColor( GUI_CLEAR );
517  baseTitle->setFont( Font( .07, 1.75 ) );
518  baseTitle->setId( "BaseInfoTitle" );
519  //Put it on the window.
520  window()->addControl( baseTitle );
521 
522  //Player info title.
523  StaticDisplay *playerTitle = new StaticDisplay;
524  static GFXColor basePlayerColor = getConfigColor( "base_player_color", GFXColor( .7, .7, .9 ) );
525  playerTitle->setRect( Rect( -.96, .69, 1.9, .07 ) );
526  playerTitle->setTextColor( basePlayerColor );
527  playerTitle->setColor( GUI_CLEAR );
528  playerTitle->setFont( Font( .06, BOLD_STROKE ) );
529  playerTitle->setId( "PlayerInfoTitle" );
530  //Put it on the window.
531  window()->addControl( playerTitle );
532 
533  static GFXColor saveLoadColor = getConfigColor( "base_save_load_color", GFXColor( .75, 0, 0 ) );
534  //Options button.
535  NewButton *options = new NewButton;
536  options->setRect( Rect( .64, .85, .32, .1 ) );
537  if (Network) {
538  options->setLabel( "Net Play" );
539  options->setCommand( "ShowNetworkMenu" );
540  } else {
541  options->setLabel( "Save/Load" );
542  options->setCommand( "ShowOptionsMenu" );
543  }
544  options->setColor( UnsaturatedColor( saveLoadColor.r, saveLoadColor.g, saveLoadColor.b, .25 ) );
545  options->setTextColor( GUI_OPAQUE_WHITE() );
546  options->setDownColor( UnsaturatedColor( saveLoadColor.r, saveLoadColor.g, saveLoadColor.b, .6 ) );
547  options->setDownTextColor( GUI_OPAQUE_BLACK() );
548  options->setHighlightColor( GFXColor( 0, 0, 1, .4 ) );
549  options->setFont( Font( .08 ) );
550  //Put the button on the window.
551  window()->addControl( options );
552  }
553  static GFXColor doneColor = getConfigColor( "base_done_color", GFXColor( .75, 0, 0 ) );
554  //Done button.
555  NewButton *done = new NewButton;
556  done->setRect( Rect( .74, .71, .22, .1 ) );
557  done->setLabel( "Done" );
558  done->setCommand( "DoneComputer" );
559  done->setColor( UnsaturatedColor( doneColor.r, doneColor.g, doneColor.b, .25 ) );
560  done->setTextColor( GUI_OPAQUE_WHITE() );
561  done->setDownColor( UnsaturatedColor( doneColor.r, doneColor.g, doneColor.b, .6 ) );
563  done->setHighlightColor( GFXColor( 0, 0, 1, .4 ) );
564  done->setFont( Font( .08, BOLD_STROKE ) );
565  window()->addControl( done );
566 
567  //Mode button.
568  NewButton *mode = new NewButton;
569  static GFXColor mode_color = getConfigColor( "base_mode_color", GFXColor( 0, .5, 0 ) );
570  mode->setRect( Rect( -.96, .86, .24, .09 ) );
571  mode->setLabel( "ERROR" );
572  mode->setColor( GFXColor( mode_color.r, mode_color.g, mode_color.b, .25 ) );
573  mode->setTextColor( GUI_OPAQUE_WHITE() );
574  mode->setDownColor( GFXColor( mode_color.r, mode_color.g, mode_color.b, .5 ) );
576  mode->setHighlightColor( GFXColor( mode_color.r, mode_color.g, mode_color.b, .4 ) );
577  mode->setFont( Font( .07, BOLD_STROKE ) );
578  mode->setId( "ModeButton" );
579  //Put the button on the window.
580  window()->addControl( mode );
581  {
582  //CARGO group control.
583  GroupControl *cargoGroup = new GroupControl;
584  cargoGroup->setId( "CargoGroup" );
585  window()->addControl( cargoGroup );
586  GFXColor color = getColorForGroup( "CargoGroup" );
587 
588  //Seller text display.
589  StaticDisplay *sellLabel = new StaticDisplay;
590  sellLabel->setRect( Rect( -.96, .56, .81, .1 ) );
591  sellLabel->setText( "Seller" );
592  sellLabel->setTextColor( GUI_OPAQUE_WHITE() );
593  sellLabel->setColor( GUI_CLEAR );
594  sellLabel->setFont( Font( .08, BOLD_STROKE ) );
595  sellLabel->setJustification( CENTER_JUSTIFY );
596  cargoGroup->addChild( sellLabel );
597 
598  //Player inventory text display.
599  StaticDisplay *inv = new StaticDisplay;
600  *inv = *sellLabel;
601  inv->setRect( Rect( .15, .56, .81, .1 ) );
602  inv->setText( "Inventory" );
603  cargoGroup->addChild( inv );
604 
605  //Total price text display.
606  StaticDisplay *totalPrice = new StaticDisplay;
607  totalPrice->setRect( Rect( -.2, .56, .4, .07 ) );
608  totalPrice->setTextColor( GUI_OPAQUE_WHITE() );
609  totalPrice->setColor( GUI_CLEAR );
610  totalPrice->setFont( Font( .06 ) );
611  totalPrice->setJustification( CENTER_JUSTIFY );
612  totalPrice->setId( "TotalPrice" );
613  cargoGroup->addChild( totalPrice );
614 
615  //"Max" text display.
616  StaticDisplay *maxForPlayer = new StaticDisplay;
617  maxForPlayer->setRect( Rect( -.14, .49, .28, .07 ) );
618  maxForPlayer->setTextColor( GUI_OPAQUE_WHITE() );
619  maxForPlayer->setColor( GUI_CLEAR );
620  maxForPlayer->setFont( Font( .06 ) );
621  maxForPlayer->setJustification( CENTER_JUSTIFY );
622  maxForPlayer->setId( "MaxQuantity" );
623  cargoGroup->addChild( maxForPlayer );
624 
625  //Scroller for seller.
626  Scroller *sellerScroller = new Scroller;
627  sellerScroller->setRect( Rect( -.20, -.4, .05, .95 ) );
628  sellerScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
629  sellerScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
630  sellerScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
631  sellerScroller->setTextColor( GUI_OPAQUE_WHITE() );
632  sellerScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
633 
634  //Seller picker.
635  SimplePicker *sellpick = new SimplePicker;
636  sellpick->setRect( Rect( -.96, -.4, .76, .95 ) );
637  sellpick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
639  sellpick->setTextColor( GUI_OPAQUE_WHITE() );
640  sellpick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
641  sellpick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
643  sellpick->setFont( Font( .07 ) );
644  sellpick->setTextMargins( Size( 0.02, 0.01 ) );
645  sellpick->setId( "BaseCargo" );
646  sellpick->setScroller( sellerScroller );
647  cargoGroup->addChild( sellpick );
648 
649  cargoGroup->addChild( sellerScroller ); //Want this "over" the picker.
650 
651  //Scroller for inventory.
652  Scroller *invScroller = new Scroller;
653  invScroller->setRect( Rect( .91, -.4, .05, .95 ) );
654  invScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
655  invScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
656  invScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
657  invScroller->setTextColor( GUI_OPAQUE_WHITE() );
658  invScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
659 
660  //Inventory picker.
661  SimplePicker *ipick = new SimplePicker;
662  ipick->setRect( Rect( .15, -.4, .76, .95 ) );
663  ipick->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
665  ipick->setTextColor( GUI_OPAQUE_WHITE() );
666  ipick->setFont( Font( .07 ) );
667  ipick->setTextMargins( Size( 0.02, 0.01 ) );
668  ipick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
669  ipick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
671  ipick->setId( "PlayerCargo" );
672  ipick->setScroller( invScroller );
673  cargoGroup->addChild( ipick );
674 
675  cargoGroup->addChild( invScroller ); //Want this "over" the picker.
676 
677  //Buy button.
678  NewButton *buy = new NewButton;
679  buy->setRect( Rect( -.11, .3, .22, .13 ) );
680  buy->setColor( GFXColor( 0, 1, 1, .1 ) );
681  buy->setTextColor( GUI_OPAQUE_WHITE() );
682  buy->setDownColor( GFXColor( 0, 1, 1, .4 ) );
683  buy->setDownTextColor( GFXColor( .2, .2, .2 ) );
684  buy->setVariableBorderCycleTime( 1.0 );
685  buy->setBorderColor( GFXColor( .2, .2, .2 ) );
686  buy->setEndBorderColor( GFXColor( .4, .4, .4 ) );
687  buy->setShadowWidth( 2.0 );
688  buy->setFont( Font( .1, BOLD_STROKE ) );
689  buy->setId( "CommitAll" );
690  cargoGroup->addChild( buy );
691 
692  //"Buy 10" button.
693  NewButton *buy10 = new NewButton;
694  buy10->setRect( Rect( -.11, .1, .22, .1 ) );
695  buy10->setColor( GFXColor( 0, 1, 1, .1 ) );
696  buy10->setTextColor( GUI_OPAQUE_WHITE() );
697  buy10->setDownColor( GFXColor( 0, 1, 1, .4 ) );
698  buy10->setDownTextColor( GFXColor( .2, .2, .2 ) );
699  buy10->setVariableBorderCycleTime( 1.0 );
700  buy10->setBorderColor( GFXColor( .2, .2, .2 ) );
701  buy10->setEndBorderColor( GFXColor( .4, .4, .4 ) );
702  buy10->setShadowWidth( 2.0 );
703  buy10->setFont( Font( .08, BOLD_STROKE ) );
704  buy10->setId( "Commit10" );
705  cargoGroup->addChild( buy10 );
706 
707  //"Buy 1" button.
708  NewButton *buy1 = new NewButton;
709  buy1->setRect( Rect( -.11, -.1, .22, .1 ) );
710  buy1->setColor( GFXColor( 0, 1, 1, .1 ) );
711  buy1->setTextColor( GUI_OPAQUE_WHITE() );
712  buy1->setDownColor( GFXColor( 0, 1, 1, .4 ) );
713  buy1->setDownTextColor( GFXColor( .2, .2, .2 ) );
714  buy1->setVariableBorderCycleTime( 1.0 );
715  buy1->setBorderColor( GFXColor( .2, .2, .2 ) );
716  buy1->setEndBorderColor( GFXColor( .4, .4, .4 ) );
717  buy1->setShadowWidth( 2.0 );
718  buy1->setFont( Font( .08, BOLD_STROKE ) );
719  buy1->setId( "Commit" );
720  cargoGroup->addChild( buy1 );
721 
722  //Scroller for description.
723  Scroller *descScroller = new Scroller;
724  descScroller->setRect( Rect( .91, -.95, .05, .5 ) );
725  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
726  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
727  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
728  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
729  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
730 
731  //Description box.
732  StaticDisplay *ms = new StaticDisplay;
733  StaticImageDisplay *picture = new StaticImageDisplay;
734  picture->setRect( Rect( -.96, -.45, .46*.75, -.47 ) );
735  picture->setTexture( "blackclear.png" );
736  picture->setId( "DescriptionImage" );
737  ms->setRect( Rect( -.6, -.95, 1.51, .5 ) );
738  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
740  ms->setFont( Font( .06 ) );
741  ms->setMultiLine( true );
743  ms->setTextMargins( Size( .02, .01 ) );
744  ms->setId( "Description" );
745  ms->setScroller( descScroller );
746  cargoGroup->addChild( ms );
747 
748  cargoGroup->addChild( descScroller ); //Want this "over" the description.
749  cargoGroup->addChild( picture );
750  }
751  {
752  //UPGRADE group control.
753  GroupControl *upgradeGroup = new GroupControl;
754  upgradeGroup->setId( "UpgradeGroup" );
755  window()->addControl( upgradeGroup );
756  GFXColor color = getColorForGroup( "UpgradeGroup" );
757 
758  //Seller text display.
759  StaticDisplay *sellLabel = new StaticDisplay;
760  sellLabel->setRect( Rect( -.96, .55, .81, .1 ) );
761  sellLabel->setText( "Available Upgrades" );
762  sellLabel->setTextColor( GUI_OPAQUE_WHITE() );
763  sellLabel->setColor( GUI_CLEAR );
764  sellLabel->setFont( Font( .07, BOLD_STROKE ) );
765  sellLabel->setJustification( CENTER_JUSTIFY );
766  upgradeGroup->addChild( sellLabel );
767 
768  //Player inventory text display.
769  StaticDisplay *inv = new StaticDisplay;
770  *inv = *sellLabel;
771  inv->setRect( Rect( .15, .55, .81, .1 ) );
772  inv->setText( "Improvements To Sell" );
773  upgradeGroup->addChild( inv );
774 
775  //Scroller for seller.
776  Scroller *sellerScroller = new Scroller;
777  sellerScroller->setRect( Rect( -.20, -.4, .05, .95 ) );
778  sellerScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
779  sellerScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
780  sellerScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
781  sellerScroller->setTextColor( GUI_OPAQUE_WHITE() );
782  sellerScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
783 
784  //Seller picker.
785  SimplePicker *sellpick = new SimplePicker;
786  sellpick->setRect( Rect( -.96, -.4, .76, .95 ) );
787  sellpick->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
789  sellpick->setTextColor( GUI_OPAQUE_WHITE() );
790  sellpick->setFont( Font( .07 ) );
791  sellpick->setTextMargins( Size( 0.02, 0.01 ) );
792  sellpick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
793  sellpick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
795  sellpick->setId( "BaseUpgrades" );
796  sellpick->setScroller( sellerScroller );
797  upgradeGroup->addChild( sellpick );
798 
799  upgradeGroup->addChild( sellerScroller ); //Want this "over" the picker.
800 
801  //Scroller for inventory.
802  Scroller *invScroller = new Scroller;
803  invScroller->setRect( Rect( .91, -.4, .05, .95 ) );
804  invScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
805  invScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
806  invScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
807  invScroller->setTextColor( GUI_OPAQUE_WHITE() );
808  invScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
809 
810  //Inventory picker.
811  SimplePicker *ipick = new SimplePicker;
812  ipick->setRect( Rect( .15, -.4, .76, .95 ) );
813  ipick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
815  ipick->setTextColor( GUI_OPAQUE_WHITE() );
816  ipick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
817  ipick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
819  ipick->setFont( Font( .07 ) );
820  ipick->setTextMargins( Size( 0.02, 0.01 ) );
821  ipick->setId( "PlayerUpgrades" );
822  ipick->setScroller( invScroller );
823  upgradeGroup->addChild( ipick );
824 
825  upgradeGroup->addChild( invScroller ); //Want this "over" picker.
826 
827  //Buy button.
828  NewButton *buy = new NewButton;
829  buy->setRect( Rect( -.11, .2, .22, .12 ) );
830  buy->setColor( GFXColor( 0, 1, 1, .1 ) );
831  buy->setTextColor( GUI_OPAQUE_WHITE() );
832  buy->setDownColor( GFXColor( 0, 1, 1, .4 ) );
833  buy->setDownTextColor( GFXColor( .2, .2, .2 ) );
834  buy->setVariableBorderCycleTime( 1.0 );
835  buy->setBorderColor( GFXColor( .2, .2, .2 ) );
836  buy->setEndBorderColor( GFXColor( .4, .4, .4 ) );
837  buy->setShadowWidth( 2.0 );
838  buy->setFont( Font( .1, BOLD_STROKE ) );
839  buy->setId( "Commit" );
840  upgradeGroup->addChild( buy );
841 
842  //Fix button.
843  NewButton *fix = new NewButton;
844  fix->setRect( Rect( -.11, .0, .22, .12 ) );
845  fix->setColor( GFXColor( 0, 1, 1, .1 ) );
846  fix->setTextColor( GUI_OPAQUE_WHITE() );
847  fix->setDownColor( GFXColor( 0, 1, 1, .4 ) );
848  fix->setDownTextColor( GFXColor( .2, .2, .2 ) );
849  fix->setVariableBorderCycleTime( 1.0 );
850  fix->setBorderColor( GFXColor( .2, .2, .2 ) );
851  fix->setEndBorderColor( GFXColor( .4, .4, .4 ) );
852  fix->setShadowWidth( 2.0 );
853  fix->setFont( Font( .1, BOLD_STROKE ) );
854  fix->setId( "CommitFix" );
855  upgradeGroup->addChild( fix );
856 
857  //Scroller for description.
858  Scroller *descScroller = new Scroller;
859  descScroller->setRect( Rect( .91, -.95, .05, .5 ) );
860  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
861  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
862  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
863  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
864  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
865 
866  //Description box.
867  StaticDisplay *ms = new StaticDisplay;
868  StaticImageDisplay *picture = new StaticImageDisplay;
869  picture->setRect( Rect( -.96, -.45, .46*.75, -.47 ) );
870  picture->setTexture( "blackclear.png" );
871  picture->setId( "DescriptionImage" );
872  ms->setRect( Rect( -.6, -.95, 1.51, .5 ) );
873 
874  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
876  ms->setFont( Font( .06 ) );
877  ms->setMultiLine( true );
879  ms->setTextMargins( Size( .02, .01 ) );
880  ms->setId( "Description" );
881  ms->setScroller( descScroller );
882  upgradeGroup->addChild( ms );
883 
884  upgradeGroup->addChild( descScroller ); //Want this "over" description box.
885  upgradeGroup->addChild( picture );
886  }
887  {
888  //NEWS group control.
889  GroupControl *newsGroup = new GroupControl;
890  newsGroup->setId( "NewsGroup" );
891  window()->addControl( newsGroup );
892  GFXColor color = getColorForGroup( "NewsGroup" );
893 
894  //Scroller for picker.
895  Scroller *pickScroller = new Scroller;
896  pickScroller->setRect( Rect( .91, 0, .05, .65 ) );
897  pickScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
898  pickScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
899  pickScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
900  pickScroller->setTextColor( GUI_OPAQUE_WHITE() );
901  pickScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
902 
903  //News picker.
904  SimplePicker *pick = new SimplePicker;
905  pick->setRect( Rect( -.96, 0, 1.87, .65 ) );
906  pick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
908  pick->setTextColor( GUI_OPAQUE_WHITE() );
909  pick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
910  pick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
912  pick->setFont( Font( .07 ) );
913  pick->setTextMargins( Size( 0.02, 0.01 ) );
914  pick->setId( "NewsPicker" );
915  pick->setScroller( pickScroller );
916  newsGroup->addChild( pick );
917 
918  newsGroup->addChild( pickScroller ); //Want scroller "over" picker.
919 
920  //Scroller for description.
921  Scroller *descScroller = new Scroller;
922  descScroller->setRect( Rect( .91, -.95, .05, .90 ) );
923  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
924  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
925  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
926  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
927  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
928 
929  //Description box.
930  StaticDisplay *ms = new StaticDisplay;
931  ms->setRect( Rect( -.96, -.95, 1.87, .90 ) );
932  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
934  ms->setFont( Font( .07 ) );
935  ms->setMultiLine( true );
937  ms->setTextMargins( Size( .02, .01 ) );
938  ms->setId( "Description" );
939  ms->setScroller( descScroller );
940  newsGroup->addChild( ms );
941 
942  newsGroup->addChild( descScroller ); //Want scroller "over" description box.
943  }
944  {
945  GroupControl *loadSaveGroup = new GroupControl;
946  loadSaveGroup->setId( "LoadSaveGroup" );
947  window()->addControl( loadSaveGroup );
948  GFXColor color = getColorForGroup( "LoadSaveGroup" );
949  //Scroller for picker.
950  Scroller *pickScroller = new Scroller;
951  pickScroller->setRect( Rect( -.20, -.7, .05, 1.4 ) );
952  pickScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
953  pickScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
954  pickScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
955  pickScroller->setTextColor( GUI_OPAQUE_WHITE() );
956  pickScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
957 
958  //Save game picker.
959  SimplePicker *pick = new SimplePicker;
960  pick->setRect( Rect( -.96, -.7, .76, 1.4 ) );
961  pick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
963  pick->setTextColor( GUI_OPAQUE_WHITE() );
964  pick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
965  pick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
967  pick->setFont( Font( .07 ) );
968  pick->setTextMargins( Size( 0.02, 0.01 ) );
969  pick->setId( "LoadSavePicker" );
970  pick->setScroller( pickScroller );
971  loadSaveGroup->addChild( pick );
972 
973  loadSaveGroup->addChild( pickScroller ); //Want scroller "over" picker.
974 
975  //Scroller for description.
976  Scroller *descScroller = new Scroller;
977  descScroller->setRect( Rect( .91, -.7, .05, 1.4 ) );
978  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
979  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
980  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
981  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
982  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
983 
984  //Description box.
985  StaticDisplay *ms = new StaticDisplay;
986  ms->setRect( Rect( .15, -.7, .76, 1.4 ) );
987  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
989  ms->setFont( Font( .07 ) );
990  ms->setMultiLine( true );
992  ms->setTextMargins( Size( .02, .01 ) );
993  ms->setId( "Description" );
994  ms->setScroller( descScroller );
995  loadSaveGroup->addChild( ms );
996 
997  loadSaveGroup->addChild( descScroller ); //Want scroller "over" description box.
998 
999  //Scroller for description.
1000  Scroller *inputTextScroller = new Scroller;
1001  inputTextScroller->setRect( Rect( .61, -0.95, .05, .2 ) );
1002  inputTextScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1003  inputTextScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1004  inputTextScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1005  inputTextScroller->setTextColor( GUI_OPAQUE_WHITE() );
1006  inputTextScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1007 
1008  //Description box.
1009  StaticDisplay *inputText = new TextInputDisplay( &base_keyboard_queue, "\x1b\n \t\r*?\\/|:<>\"^" );
1010  inputText->setRect( Rect( -.6, -.95, 1.21, .2 ) );
1011  inputText->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1012  inputText->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1013  inputText->setFont( Font( .07 ) );
1014  inputText->setMultiLine( true );
1015  inputText->setTextColor( GUI_OPAQUE_WHITE() );
1016  inputText->setTextMargins( Size( .02, .01 ) );
1017  inputText->setId( "InputText" );
1018  inputText->setScroller( inputTextScroller );
1019  loadSaveGroup->addChild( inputText );
1020 
1021  loadSaveGroup->addChild( inputTextScroller ); //Want scroller "over" description box.
1022  //Accept button.
1023  if (!Network) {
1024  //no save in network mode!
1025  NewButton *buy10 = new NewButton;
1026  buy10->setRect( Rect( -.11, 0, .22, .12 ) );
1027  buy10->setColor( GFXColor( 0, 1, 1, .1 ) );
1028  buy10->setTextColor( GUI_OPAQUE_WHITE() );
1029  buy10->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1030  buy10->setDownTextColor( GFXColor( .2, .2, .2 ) );
1031  buy10->setVariableBorderCycleTime( 1.0 );
1032  buy10->setBorderColor( GFXColor( .2, .2, .2 ) );
1033  buy10->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1034  buy10->setShadowWidth( 2.0 );
1035  buy10->setFont( Font( .08, BOLD_STROKE ) );
1036  buy10->setId( "Commit10" );
1037  buy10->setLabel( "Save" );
1038  buy10->setCommand( "Save" );
1039  loadSaveGroup->addChild( buy10 );
1040  }
1041  NewButton *accept = new NewButton;
1042  accept->setRect( Rect( -.11, -.2, .22, .12 ) );
1043  accept->setColor( GFXColor( 0, 1, 1, .1 ) );
1044  accept->setTextColor( GUI_OPAQUE_WHITE() );
1045  accept->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1046  accept->setDownTextColor( GFXColor( .2, .2, .2 ) );
1047  accept->setVariableBorderCycleTime( 1.0 );
1048  accept->setBorderColor( GFXColor( .2, .2, .2 ) );
1049  accept->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1050  accept->setShadowWidth( 2.0 );
1051  accept->setFont( Font( .08, BOLD_STROKE ) );
1052  accept->setId( "Commit" );
1053  accept->setLabel( "Load" );
1054  accept->setCommand( "Load" );
1055  loadSaveGroup->addChild( accept );
1056 
1057  NewButton *quit = new NewButton;
1058  quit->setRect( Rect( -.95, -.9, .3, .1 ) );
1059  quit->setColor( GFXColor( .8, 1, .1, .1 ) );
1060  quit->setTextColor( GUI_OPAQUE_WHITE() );
1061  quit->setDownColor( GFXColor( .8, 1, .1, .4 ) );
1062  quit->setDownTextColor( GFXColor( .2, .2, .2 ) );
1063  quit->setVariableBorderCycleTime( 1.0 );
1064  quit->setBorderColor( GFXColor( .5, .2, .2 ) );
1065  quit->setEndBorderColor( GFXColor( .7, .4, .4 ) );
1066  quit->setShadowWidth( 2.0 );
1067  quit->setFont( Font( .07, BOLD_STROKE ) );
1068  quit->setId( "CommitAll" );
1069  quit->setLabel( "Quit Game" );
1070  quit->setCommand( "Quit" );
1071  loadSaveGroup->addChild( quit );
1072 
1073  NewButton *net = new NewButton;
1074  net->setRect( Rect( .7, -.9, .25, .1 ) );
1075  net->setColor( GFXColor( 1, .5, .1, .1 ) );
1076  net->setTextColor( GUI_OPAQUE_WHITE() );
1077  net->setDownColor( GFXColor( 1, .5, .1, .4 ) );
1078  net->setDownTextColor( GFXColor( .2, .2, .2 ) );
1079  net->setVariableBorderCycleTime( 1.0 );
1080  net->setBorderColor( GFXColor( .2, .5, .2 ) );
1081  net->setEndBorderColor( GFXColor( .4, .7, .4 ) );
1082  net->setShadowWidth( 2.0 );
1083  net->setFont( Font( .07, 1 ) );
1084  net->setId( "CommitAll" );
1085  net->setLabel( "Net Play" );
1086  net->setCommand( "ShowNetworkMenu" );
1087  loadSaveGroup->addChild( net );
1088 
1089  NewButton *newgame = new NewButton;
1090  newgame->setRect( Rect( -.11, -.4, .22, .12 ) );
1091  newgame->setColor( GFXColor( 0, 1, 1, .1 ) );
1092  newgame->setTextColor( GUI_OPAQUE_WHITE() );
1093  newgame->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1094  newgame->setDownTextColor( GFXColor( .2, .2, .2 ) );
1095  newgame->setVariableBorderCycleTime( 1.0 );
1096  newgame->setBorderColor( GFXColor( .2, .2, .2 ) );
1097  newgame->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1098  newgame->setShadowWidth( 2.0 );
1099  newgame->setFont( Font( .08, BOLD_STROKE ) );
1100  newgame->setId( "NewGame" );
1101  newgame->setLabel( "New" );
1102  newgame->setCommand( "New" );
1103  loadSaveGroup->addChild( newgame );
1104  }
1105  {
1106  GroupControl *networkGroup = new GroupControl;
1107  networkGroup->setId( "NetworkGroup" );
1108  window()->addControl( networkGroup );
1109  GroupControl *netJoinGroup = new GroupControl;
1110  netJoinGroup->setId( "NetworkJoinGroup" );
1111  networkGroup->addChild( netJoinGroup );
1112  GroupControl *netStatGroup = new GroupControl;
1113  netStatGroup->setId( "NetworkStatGroup" );
1114  netStatGroup->setHidden( true );
1115  networkGroup->addChild( netStatGroup );
1116 
1117  GFXColor color = getColorForGroup( "NetworkGroup" );
1118 
1120  if (Network) {
1121  NetClient &nc = Network[0]; //Hack?: Assume 0th player.
1122  netStatGroup->setHidden( false );
1123  netJoinGroup->setHidden( true );
1124 
1125  std::string serverip;
1126  unsigned short serverport;
1127  nc.GetCurrentServerAddress( serverip, serverport );
1128 
1129  StaticDisplay *mplayTitle = new StaticDisplay;
1130  mplayTitle->setRect( Rect( -.7, .6, 1, .1 ) );
1131  mplayTitle->setText( "Independent Server IP Address:" );
1132  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1133  mplayTitle->setColor( GUI_CLEAR );
1134  mplayTitle->setFont( Font( .07, 2 ) );
1135  netStatGroup->addChild( mplayTitle );
1136 
1137  //Description box.
1138  StaticDisplay *serverInputText = new StaticDisplay;
1139  serverInputText->setRect( Rect( -.6, .5, 1.2, .1 ) );
1140  serverInputText->setColor( GUI_CLEAR );
1141  serverInputText->setFont( Font( .07 ) );
1142  serverInputText->setMultiLine( false );
1143  if (serverip == "localhost" || serverip == "127.0.0.1") {
1144  serverInputText->setText( "Locally Hosted Game" );
1145  serverInputText->setTextColor( GFXColor( .5, 1, .5 ) );
1146  } else if (serverip.substr( 0, 3 ) == "10." || serverip.substr( 0, 8 ) == "192.168."
1147  || serverip.substr( 0, 8 ) == "169.254." || serverip.find( '.' ) == std::string::npos) {
1148  serverInputText->setText( "LAN: "+serverip );
1149  serverInputText->setTextColor( GFXColor( 1, 1, .5 ) );
1150  } else {
1151  serverInputText->setText( serverip );
1152  serverInputText->setTextColor( GFXColor( 1, .8, .5 ) );
1153  }
1154  netStatGroup->addChild( serverInputText );
1155 
1156  mplayTitle = new StaticDisplay;
1157  mplayTitle->setRect( Rect( -.7, .4, 1, .1 ) );
1158  mplayTitle->setText( "Server Port: (default 6777)" );
1159  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1160  mplayTitle->setColor( GUI_CLEAR );
1161  mplayTitle->setFont( Font( .07, 2 ) );
1162  netStatGroup->addChild( mplayTitle );
1163 
1164  StaticDisplay *portInputText = new StaticDisplay;
1165  portInputText->setRect( Rect( -.6, .3, .4, .1 ) );
1166  portInputText->setColor( GUI_CLEAR );
1167  portInputText->setFont( Font( .07 ) );
1168  portInputText->setMultiLine( false );
1169  portInputText->setTextColor( GFXColor( .7, .7, 1 ) );
1170  {
1171  char portstr[15];
1172  sprintf( portstr, "%d", (int) (serverport) );
1173  portInputText->setText( portstr );
1174  }
1175  netStatGroup->addChild( portInputText );
1176 
1177  mplayTitle = new StaticDisplay;
1178  mplayTitle->setRect( Rect( -.7, .2, 1, .1 ) );
1179  mplayTitle->setText( "Account Server:" );
1180  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1181  mplayTitle->setColor( GUI_CLEAR );
1182  mplayTitle->setFont( Font( .07, 2 ) );
1183  netStatGroup->addChild( mplayTitle );
1184 
1185  StaticDisplay *acctserverInput = new StaticDisplay;
1186  acctserverInput->setRect( Rect( -.6, .1, 1.2, .1 ) );
1187  acctserverInput->setColor( GUI_CLEAR );
1188  acctserverInput->setFont( Font( .07 ) );
1189  acctserverInput->setMultiLine( false );
1190  acctserverInput->setTextColor( GFXColor( .9, 1, .6 ) );
1191 
1192  std::string acctserver;
1193  bool useacctserver = XMLSupport::parse_bool( vs_config->getVariable( "network", "use_account_server", "true" ) );
1194  if (useacctserver) {
1195  acctserver = vs_config->getVariable( "network", "account_server_url", "http://vegastrike.sourceforge.net/" );
1196  std::string::size_type s1, s3, q;
1197  s1 = acctserver.find( '/' );
1198  if (s1 != std::string::npos) {
1199  if (s1+1 < acctserver.length() && acctserver[s1+1] == '/') {
1200  s3 = acctserver.find( '/', s1+3 );
1201  if (s3 != std::string::npos) {
1202  std::string mod;
1203  q = acctserver.find( '?', s3 );
1204  if (q != std::string::npos)
1205  mod = "; "+acctserver.substr( q+1 );
1206  acctserver = acctserver.substr( s1+2, s3-s1-2 )+mod;
1207  }
1208  }
1209  }
1210  } else {
1211  acctserverInput->setTextColor( GFXColor( .7, 1, .6 ) );
1212  acctserver = "(Private Game)";
1213  }
1214  acctserverInput->setText( acctserver );
1215  netStatGroup->addChild( acctserverInput );
1216 
1217  mplayTitle = new StaticDisplay;
1218  mplayTitle->setRect( Rect( -.7, 0, .7, .1 ) );
1219  mplayTitle->setText( "Callsign:" );
1220  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1221  mplayTitle->setColor( GUI_CLEAR );
1222  mplayTitle->setFont( Font( .07, 2 ) );
1223  netStatGroup->addChild( mplayTitle );
1224 
1225  StaticDisplay *usernameInput = new StaticDisplay;
1226  usernameInput->setRect( Rect( -.6, -.1, .6, .1 ) );
1227  usernameInput->setColor( GUI_CLEAR );
1228  usernameInput->setFont( Font( .07 ) );
1229  usernameInput->setMultiLine( false );
1230  usernameInput->setTextColor( GFXColor( 1, .7, .9 ) );
1231  usernameInput->setText( nc.getCallsign() );
1232  netStatGroup->addChild( usernameInput );
1233 
1234  mplayTitle = new StaticDisplay;
1235  mplayTitle->setRect( Rect( 0, 0, .7, .1 ) );
1236  mplayTitle->setText( "Serial Number:" );
1237  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1238  mplayTitle->setColor( GUI_CLEAR );
1239  mplayTitle->setFont( Font( .07, 2 ) );
1240  netStatGroup->addChild( mplayTitle );
1241 
1242  StaticDisplay *currentSerial = new StaticDisplay;
1243  currentSerial->setRect( Rect( .1, -.1, .6, .1 ) );
1244  currentSerial->setColor( GUI_CLEAR );
1245  currentSerial->setFont( Font( .07 ) );
1246  currentSerial->setMultiLine( false );
1247  currentSerial->setTextColor( GFXColor( 1, .7, .9 ) );
1248  {
1249  char serial[15];
1250  sprintf( serial, "%d", (int) nc.serial );
1251  currentSerial->setText( serial );
1252  }
1253  netStatGroup->addChild( currentSerial );
1254 
1255  mplayTitle = new StaticDisplay;
1256  mplayTitle->setRect( Rect( -.7, -.2, .7, .1 ) );
1257  mplayTitle->setText( "Current Ship:" );
1258  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1259  mplayTitle->setColor( GUI_CLEAR );
1260  mplayTitle->setFont( Font( .07, 2 ) );
1261  netStatGroup->addChild( mplayTitle );
1262 
1263  StaticDisplay *currentFighter = new StaticDisplay;
1264  currentFighter->setRect( Rect( -.6, -.3, .6, .1 ) );
1265  currentFighter->setColor( GUI_CLEAR );
1266  currentFighter->setFont( Font( .07 ) );
1267  currentFighter->setMultiLine( false );
1268  currentFighter->setTextColor( GFXColor( 1, .7, .9 ) );
1269  Unit *player = nc.getUnit();
1270  if (player) {
1271  currentFighter->setText( player->getFullname() );
1272  } else {
1273  currentFighter->setTextColor( GFXColor( 1, .6, .6 ) );
1274  currentFighter->setText( "(Currently Destroyed)" );
1275  }
1276  netStatGroup->addChild( currentFighter );
1277 
1278  mplayTitle = new StaticDisplay;
1279  mplayTitle->setRect( Rect( 0, -.2, .7, .1 ) );
1280  mplayTitle->setText( "Faction:" );
1281  mplayTitle->setTextColor( GUI_OPAQUE_WHITE() );
1282  mplayTitle->setColor( GUI_CLEAR );
1283  mplayTitle->setFont( Font( .07, 2 ) );
1284  netStatGroup->addChild( mplayTitle );
1285 
1286  StaticDisplay *currentFaction = new StaticDisplay;
1287  currentFaction->setRect( Rect( .1, -.3, .6, .1 ) );
1288  currentFaction->setColor( GUI_CLEAR );
1289  currentFaction->setFont( Font( .07 ) );
1290  currentFaction->setMultiLine( false );
1291  if (player) {
1292  int fact = player->faction;
1293  const float *col = FactionUtil::GetSparkColor( fact );
1294  currentFaction->setTextColor( GFXColor( col[0], col[1], col[2] ) );
1295  currentFaction->setText( FactionUtil::GetFaction( fact ) );
1296  } else {
1297  currentFaction->setTextColor( GFXColor( 1, .6, .6 ) );
1298  currentFaction->setText( "(Currently Destroyed)" );
1299  }
1300  netStatGroup->addChild( currentFaction );
1301 
1302  NewButton *saveNetGame = new NewButton;
1303  saveNetGame->setRect( Rect( -.7, -.65, .4, .13 ) );
1304  saveNetGame->setColor( GFXColor( .2, 1, 0, .1 ) );
1305  saveNetGame->setTextColor( GUI_OPAQUE_WHITE() );
1306  saveNetGame->setDownColor( GFXColor( .2, 1, 0, .4 ) );
1307  saveNetGame->setDownTextColor( GFXColor( .2, .2, .2 ) );
1308  saveNetGame->setFont( Font( .07, 1 ) );
1309  saveNetGame->setCommand( "NetworkSaveGame" );
1310  saveNetGame->setLabel( "Save Progress" );
1311  netStatGroup->addChild( saveNetGame );
1312 
1313  NewButton *reloadNet = new NewButton;
1314  reloadNet->setRect( Rect( .3, -.65, .4, .13 ) );
1315  reloadNet->setColor( GFXColor( 1, .2, 0, .1 ) );
1316  reloadNet->setTextColor( GUI_OPAQUE_WHITE() );
1317  reloadNet->setDownColor( GFXColor( 1, .2, 0, .4 ) );
1318  reloadNet->setDownTextColor( GFXColor( .2, .2, .2 ) );
1319  reloadNet->setFont( Font( .07, 1 ) );
1320  reloadNet->setCommand( "NetworkDie" );
1321  reloadNet->setLabel( "Die and Reload" );
1322  netStatGroup->addChild( reloadNet );
1323 
1324  NewButton *hideNetStatus = new NewButton;
1325  hideNetStatus->setRect( Rect( -.2, -.65, .4, .13 ) );
1326  hideNetStatus->setColor( GFXColor( .2, .8, 1, .1 ) );
1327  hideNetStatus->setTextColor( GUI_OPAQUE_WHITE() );
1328  hideNetStatus->setDownColor( GFXColor( .2, .8, 1, .4 ) );
1329  hideNetStatus->setDownTextColor( GFXColor( .2, .2, .2 ) );
1330  hideNetStatus->setFont( Font( .07, 1 ) );
1331  hideNetStatus->setCommand( "HideNetworkStatus" );
1332  hideNetStatus->setLabel( "Join Another Server" );
1333  netStatGroup->addChild( hideNetStatus );
1334  }
1335  if (m_displayModes.size() != 1 || m_displayModes[0] != NETWORK) {
1336  NewButton *loadsave = new NewButton;
1337  loadsave->setRect( Rect( .7, -.9, .25, .1 ) );
1338  loadsave->setColor( GFXColor( 1, .5, .1, .1 ) );
1339  loadsave->setTextColor( GUI_OPAQUE_WHITE() );
1340  loadsave->setDownColor( GFXColor( 1, .5, .1, .4 ) );
1341  loadsave->setDownTextColor( GFXColor( .2, .2, .2 ) );
1342  loadsave->setVariableBorderCycleTime( 1.0 );
1343  loadsave->setBorderColor( GFXColor( .2, .5, .2 ) );
1344  loadsave->setEndBorderColor( GFXColor( .4, .7, .4 ) );
1345  loadsave->setShadowWidth( 2.0 );
1346  loadsave->setFont( Font( .07, 1 ) );
1347  loadsave->setId( "CommitAll" );
1348  if (Network != NULL)
1349  loadsave->setLabel( "Single Player" );
1350  else
1351  loadsave->setLabel( "Save/Load" );
1352  loadsave->setCommand( "ShowOptionsMenu" );
1353  networkGroup->addChild( loadsave );
1354  }
1355  if ( (m_displayModes.size() == 1 && m_displayModes[0] == NETWORK) || Network != NULL ) {
1356  NewButton *quit = new NewButton;
1357  quit->setRect( Rect( -.95, -.9, .3, .1 ) );
1358  quit->setColor( GFXColor( .8, 1, .1, .1 ) );
1359  quit->setTextColor( GUI_OPAQUE_WHITE() );
1360  quit->setDownColor( GFXColor( .8, 1, .1, .4 ) );
1361  quit->setDownTextColor( GFXColor( .2, .2, .2 ) );
1362  quit->setVariableBorderCycleTime( 1.0 );
1363  quit->setBorderColor( GFXColor( .5, .2, .2 ) );
1364  quit->setEndBorderColor( GFXColor( .7, .4, .4 ) );
1365  quit->setShadowWidth( 2.0 );
1366  quit->setFont( Font( .07, BOLD_STROKE ) );
1367  quit->setId( "CommitAll" );
1368  quit->setLabel( "Quit Game" );
1369  quit->setCommand( "Quit" );
1370  networkGroup->addChild( quit );
1371  }
1372  }
1373  {
1374  //MISSIONS group control.
1375  GroupControl *missionsGroup = new GroupControl;
1376  missionsGroup->setId( "MissionsGroup" );
1377  window()->addControl( missionsGroup );
1378  GFXColor color = getColorForGroup( "MissionsGroup" );
1379 
1380  //Scroller for picker.
1381  Scroller *pickScroller = new Scroller;
1382  pickScroller->setRect( Rect( -.20, -.8, .05, 1.45 ) );
1383  pickScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1384  pickScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1385  pickScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1386  pickScroller->setTextColor( GUI_OPAQUE_WHITE() );
1387  pickScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1388 
1389  //Picker.
1390  SimplePicker *pick = new SimplePicker;
1391  pick->setRect( Rect( -.96, -.8, .76, 1.45 ) );
1392  pick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1394  pick->setTextColor( GUI_OPAQUE_WHITE() );
1395  pick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
1396  pick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
1398  pick->setFont( Font( .07 ) );
1399  pick->setTextMargins( Size( 0.02, 0.01 ) );
1400  pick->setId( "Missions" );
1401  pick->setScroller( pickScroller );
1402  missionsGroup->addChild( pick );
1403 
1404  missionsGroup->addChild( pickScroller ); //Want scroller "over" picker.
1405 
1406  //Scroller for description.
1407  Scroller *descScroller = new Scroller;
1408  descScroller->setRect( Rect( .91, -.8, .05, 1.45 ) );
1409  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1410  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1411  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1412  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
1413  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1414 
1415  //Description box.
1416  StaticDisplay *ms = new StaticDisplay;
1417  ms->setRect( Rect( -.10, -.8, 1.01, 1.45 ) );
1418  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1420  ms->setFont( Font( .06 ) );
1421  ms->setMultiLine( true );
1422  ms->setTextColor( GUI_OPAQUE_WHITE() );
1423  ms->setTextMargins( Size( .02, .01 ) );
1424  ms->setId( "Description" );
1425  ms->setScroller( descScroller );
1426  missionsGroup->addChild( ms );
1427 
1428  missionsGroup->addChild( descScroller ); //Want scroller "over" description box.
1429 
1430  //Accept button.
1431  NewButton *accept = new NewButton;
1432  accept->setRect( Rect( -.23, -.95, .22, .11 ) );
1433  accept->setColor( GFXColor( 0, 1, 1, .1 ) );
1434  accept->setTextColor( GUI_OPAQUE_WHITE() );
1435  accept->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1436  accept->setDownTextColor( GFXColor( .2, .2, .2 ) );
1437  accept->setVariableBorderCycleTime( 1.0 );
1438  accept->setBorderColor( GFXColor( .2, .2, .2 ) );
1439  accept->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1440  accept->setShadowWidth( 2.0 );
1441  accept->setFont( Font( .08, BOLD_STROKE ) );
1442  accept->setId( "Commit" );
1443  missionsGroup->addChild( accept );
1444  }
1445  {
1446  //SHIP_DEALER group control.
1447  GroupControl *shipDealerGroup = new GroupControl;
1448  shipDealerGroup->setId( "ShipDealerGroup" );
1449  window()->addControl( shipDealerGroup );
1450  GFXColor color = getColorForGroup( "ShipDealerGroup" );
1451 
1452  //Scroller for picker.
1453  Scroller *pickScroller = new Scroller;
1454  pickScroller->setRect( Rect( -.20, -.8, .05, 1.45 ) );
1455  pickScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1456  pickScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1457  pickScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1458  pickScroller->setTextColor( GUI_OPAQUE_WHITE() );
1459  pickScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1460 
1461  //Picker.
1462  SimplePicker *pick = new SimplePicker;
1463  pick->setRect( Rect( -.96, -.8, .76, 1.45 ) );
1464  pick->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1466  pick->setTextColor( GUI_OPAQUE_WHITE() );
1467  pick->setSelectionColor( UnsaturatedColor( 0, .6, 0, .8 ) );
1468  pick->setHighlightColor( UnsaturatedColor( 0, .6, 0, .35 ) );
1470  pick->setFont( Font( .07 ) );
1471  pick->setTextMargins( Size( 0.02, 0.01 ) );
1472  pick->setId( "Ships" );
1473  pick->setScroller( pickScroller );
1474  shipDealerGroup->addChild( pick );
1475 
1476  shipDealerGroup->addChild( pickScroller ); //Want scroller to be "over" picker.
1477 
1478  //Scroller for description.
1479  Scroller *descScroller = new Scroller;
1480  descScroller->setRect( Rect( .91, -.5, .05, 1.15 ) );
1481  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1482  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1483  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1484  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
1485  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1486 
1487  //Description box.
1488  StaticDisplay *ms = new StaticDisplay;
1489  StaticImageDisplay *picture = new StaticImageDisplay;
1490  picture->setRect( Rect( -.10, -.51, .48*.75, -.48 ) );
1491  picture->setTexture( "blackclear.png" );
1492  picture->setId( "DescriptionImage" );
1493  ms->setRect( Rect( -.10, -.5, 1.01, 1.15 ) );
1494  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1496  ms->setFont( Font( .06 ) );
1497  ms->setMultiLine( true );
1498  ms->setTextColor( GUI_OPAQUE_WHITE() );
1499  ms->setTextMargins( Size( .02, .01 ) );
1500  ms->setId( "Description" );
1501  ms->setScroller( descScroller );
1502  shipDealerGroup->addChild( ms );
1503 
1504  shipDealerGroup->addChild( descScroller ); //Want scroller "over" description box.
1505  shipDealerGroup->addChild( picture );
1506  //Buy button.
1507  NewButton *buy = new NewButton;
1508  buy->setRect( Rect( -.53, -.95, .22, .11 ) );
1509  buy->setColor( GFXColor( 0, 1, 1, .1 ) );
1510  buy->setTextColor( GUI_OPAQUE_WHITE() );
1511  buy->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1512  buy->setDownTextColor( GFXColor( .2, .2, .2 ) );
1513  buy->setVariableBorderCycleTime( 1.0 );
1514  buy->setBorderColor( GFXColor( .2, .2, .2 ) );
1515  buy->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1516  buy->setShadowWidth( 2.0 );
1517  buy->setFont( Font( .08, BOLD_STROKE ) );
1518  buy->setId( "Commit" );
1519  shipDealerGroup->addChild( buy );
1520  NewButton *sell = new NewButton;
1521  sell->setRect( Rect( -.23, -.95, .22, .11 ) );
1522  sell->setColor( GFXColor( 0, 1, 1, .1 ) );
1523  sell->setTextColor( GUI_OPAQUE_WHITE() );
1524  sell->setDownColor( GFXColor( 0, 1, 1, .4 ) );
1525  sell->setDownTextColor( GFXColor( .2, .2, .2 ) );
1526  sell->setVariableBorderCycleTime( 1.0 );
1527  sell->setBorderColor( GFXColor( .2, .2, .2 ) );
1528  sell->setEndBorderColor( GFXColor( .4, .4, .4 ) );
1529  sell->setShadowWidth( 2.0 );
1530  sell->setFont( Font( .08, BOLD_STROKE ) );
1531  sell->setId( "Commit10" );
1532  shipDealerGroup->addChild( sell );
1533  }
1534  {
1535  //INFO group control.
1536  GroupControl *infoGroup = new GroupControl;
1537  infoGroup->setId( "InfoGroup" );
1538  window()->addControl( infoGroup );
1539  GFXColor color = getColorForGroup( "InfoGroup" );
1540 
1541  //Player Info button.
1542  NewButton *playerInfo = new NewButton;
1543  playerInfo->setRect( Rect( -.40, .52, .27, .09 ) );
1544  playerInfo->setLabel( "Player Info" );
1545  static GFXColor pinfo_col = getConfigColor( "player_info", GFXColor( 0, .4, 0 ) );
1546  playerInfo->setCommand( "ShowPlayerInfo" );
1547 
1548  playerInfo->setColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .25 ) );
1549  playerInfo->setTextColor( GUI_OPAQUE_WHITE() );
1550  playerInfo->setDownColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .5 ) );
1551  playerInfo->setDownTextColor( GUI_OPAQUE_BLACK() );
1552  playerInfo->setHighlightColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .4 ) );
1553  playerInfo->setFont( Font( .07 ) );
1554  infoGroup->addChild( playerInfo );
1555 
1556  //Ship Stats button.
1557  NewButton *shipStats = new NewButton;
1558  shipStats->setRect( Rect( -.05, .52, .27, .09 ) );
1559  shipStats->setLabel( "Ship Stats" );
1560  shipStats->setCommand( "ShowShipStats" );
1561  shipStats->setColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .25 ) );
1562  shipStats->setTextColor( GUI_OPAQUE_WHITE() );
1563  shipStats->setDownColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .5 ) );
1564  shipStats->setDownTextColor( GUI_OPAQUE_BLACK() );
1565  shipStats->setHighlightColor( GFXColor( pinfo_col.r, pinfo_col.g, pinfo_col.b, .4 ) );
1566  shipStats->setFont( Font( .07 ) );
1567  infoGroup->addChild( shipStats );
1568 
1569  //Scroller for description.
1570  Scroller *descScroller = new Scroller;
1571  descScroller->setRect( Rect( .91, -.95, .05, 1.4 ) );
1572  descScroller->setColor( UnsaturatedColor( color.r, color.g, color.b, .1 ) );
1573  descScroller->setThumbColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
1574  descScroller->setButtonColor( UnsaturatedColor( color.r*.4, color.g*.4, color.b*.4 ) );
1575  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
1576  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1577 
1578  //Description box.
1579  StaticDisplay *ms = new StaticDisplay;
1580  ms->setRect( Rect( -.96, -.95, 1.87, 1.4 ) );
1581  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
1583  ms->setFont( Font( .07 ) );
1584  ms->setMultiLine( true );
1585  ms->setTextColor( GUI_OPAQUE_WHITE() );
1586  ms->setTextMargins( Size( .02, .01 ) );
1587  ms->setId( "Description" );
1588  ms->setScroller( descScroller );
1589  infoGroup->addChild( ms );
1590 
1591  infoGroup->addChild( descScroller );
1592  }
1593 }
SimplePickerCell * BaseComputer::createCategoryCell ( SimplePickerCells cells,
const string &  category,
bool  skipFirstCategory 
)
protected

Definition at line 2520 of file basecomputer.cpp.

References SimplePickerCells::addCell(), beautify(), CATEGORY_SEP, CATEGORY_TAG, CATEGORY_TEXT_COLOR(), SimplePickerCells::cellAt(), SimplePickerCell::children(), SimplePickerCells::count(), SimplePickerCell::createEmptyChildList(), VegaConfig::getVariable(), XMLSupport::parse_bool(), PickerCell::setHideChildren(), and vs_config.

Referenced by loadListPicker().

2523 {
2524  string category = origCategory;
2525  if (skipFirstCategory) {
2526  //Skip over the first category piece.
2527  const string::size_type sepLoc = category.find( CATEGORY_SEP );
2528  if (sepLoc == string::npos)
2529  //No category separator. At most one category.
2530  category.erase( 0, category.size() );
2531  else
2532  //Skip the first piece.
2533  category = origCategory.substr( sepLoc+1 );
2534  }
2535  if (category.size() == 0)
2536  //No category at all.
2537  return NULL;
2538  //Create or reuse a cell for the first part of the category.
2539  const string::size_type loc = category.find( CATEGORY_SEP );
2540  const string currentCategory = category.substr( 0, loc );
2541  if (cells.count() > 0 && cells.cellAt( cells.count()-1 )->id() == currentCategory) {
2542  //Re-use the category we have.
2543  } else {
2544  //Need to make a new cell for this.
2545  cells.addCell( new SimplePickerCell( beautify( currentCategory ), currentCategory, CATEGORY_TEXT_COLOR(), CATEGORY_TAG ) );
2546  }
2547  SimplePickerCell *parentCell = static_cast< SimplePickerCell* > ( cells.cellAt( cells.count()-1 ) ); //Last cell in list.
2548  static bool showDefault = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "open_picker_categories", "false" ) );
2549  parentCell->setHideChildren( !showDefault );
2550  if (loc == string::npos) {
2551  //This is a simple category -- we are done.
2552  return parentCell;
2553  } else {
2554  //The category string has more stuff in it -- finish it up.
2555  SimplePickerCells *childCellList = static_cast< SimplePickerCells* > ( parentCell->children() );
2556  if (!childCellList) {
2557  //If parent doesn't have room children, we create the room manually.
2558  parentCell->createEmptyChildList();
2559  childCellList = static_cast< SimplePickerCells* > ( parentCell->children() );
2560  }
2561  const string newCategory = category.substr( loc+1 );
2562  return createCategoryCell( *childCellList, newCategory, false );
2563  }
2564  assert( false );
2565  //Never get here.
2566 }
void BaseComputer::createControls ( void  )
protected

Definition at line 1596 of file basecomputer.cpp.

References constructControls(), createModeButtons(), DISPLAY_MODE_COUNT, Window::findControlById(), GUI_CLEAR(), i, m_modeGroups, Window::removeControlFromWindow(), Window::setColor(), Window::setFullScreen(), Window::setTexture(), and WindowController::window().

Referenced by init().

1597 {
1598  //Set up the window.
1599  window()->setFullScreen();
1600  window()->setColor( GUI_CLEAR );
1601  window()->setTexture( "basecomputer.png" );
1602 
1603  //Put all the controls in the window.
1605  //Take the mode group controls out of the window.
1606  for (int i = 0; i < DISPLAY_MODE_COUNT; i++) {
1607  Control *group = window()->findControlById( modeInfo[i].groupId );
1608  if (group) {
1609  window()->removeControlFromWindow( group );
1610  m_modeGroups[i] = group;
1611  }
1612  }
1614 }
void BaseComputer::createModeButtons ( void  )
protected

Definition at line 1617 of file basecomputer.cpp.

References Window::addControl(), Window::findControlById(), i, m_displayModes, MODE_BUTTON_SPACE, Rect::origin, Control::rect(), NewButton::setCommand(), Control::setHidden(), NewButton::setLabel(), Control::setRect(), Rect::size, Size::width, WindowController::window(), and Point::x.

Referenced by createControls().

1618 {
1619  NewButton *originalButton = static_cast< NewButton* > ( window()->findControlById( "ModeButton" ) );
1620  assert( originalButton != NULL );
1621  if (m_displayModes.size() > 1) {
1622  //Create a button for each display mode, copying the original button.
1623  Rect rect = originalButton->rect();
1624  for (unsigned int i = 0; i < m_displayModes.size(); i++) {
1625  DisplayMode mode = m_displayModes[i];
1626  NewButton *newButton = new NewButton( *originalButton );
1627  newButton->setRect( rect );
1628  newButton->setLabel( modeInfo[mode].button );
1629  newButton->setCommand( modeInfo[mode].command );
1630  window()->addControl( newButton );
1631  rect.origin.x += rect.size.width+MODE_BUTTON_SPACE;
1632  }
1633  }
1634  //Make sure this original doesn't show.
1635  originalButton->setHidden( true );
1636 }
void BaseComputer::draw ( void  )
virtual

Reimplemented from WindowController.

Definition at line 2823 of file basecomputer.cpp.

References dirty, eliminateZeroCargo(), UnitContainer::GetUnit(), globalWindowManager(), Unit::hull, m_player, refresh(), WindowManager::shutDown(), and TerminateCurrentBase().

2824 {
2825  if ( ( !m_player.GetUnit() ) || m_player.GetUnit()->hull <= 0 ) {
2828  }
2829  if ( BaseComputer::dirty && m_player.GetUnit() ) {
2831  refresh();
2832  }
2833 }
void BaseComputer::finalizeJoinGame ( int  launchShip = 0)
void BaseComputer::finalizeNetSaveGame ( void  )
bool BaseComputer::fixUpgrade ( const EventCommandId command,
Control control 
)
protected

Definition at line 4013 of file basecomputer.cpp.

References _Universe, Cargo::content, Cockpit::credits, emergency_downgrade_mode, UnitContainer::GetUnit(), Universe::isPlayerStarship(), m_base, m_player, UnitUtil::PercentOperational(), refresh(), Unit::RepairUpgradeCargo(), and selectedItem().

4014 {
4015  Cargo *item = selectedItem();
4016  Unit *playerUnit = m_player.GetUnit();
4017  Unit *baseUnit = m_base.GetUnit();
4018  if (baseUnit && playerUnit && item) {
4019  float *credits = NULL;
4020  Cockpit *cp = _Universe->isPlayerStarship( playerUnit );
4021  if (cp)
4022  credits = &(cp->credits);
4023  if ( playerUnit->RepairUpgradeCargo( item, baseUnit, credits ) )
4024  if (UnitUtil::PercentOperational( playerUnit, item->content, "upgrades/", false ) < 1.0)
4025  emergency_downgrade_mode = "EMERGENCY MODE ";
4026  refresh();
4027  }
4028  return true;
4029 }
GFXColor BaseComputer::getColorForGroup ( std::string  id)
protected

Definition at line 471 of file basecomputer.cpp.

References _Universe, Unit::faction, FactionUtil::GetFactionIndex(), FactionUtil::GetFactionName(), Universe::getGalaxyProperty(), FactionUtil::GetSparkColor(), UniverseUtil::getSystemFile(), UnitContainer::GetUnit(), VegaConfig::getVariable(), m_base, XMLSupport::parse_bool(), XMLSupport::parse_float(), and vs_config.

Referenced by constructControls().

472 {
473  static bool use_faction_background =
474  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "use_faction_gui_background_color", "true" ) );
475  static float faction_color_darkness =
476  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_faction_color_darkness", ".75" ) );
477  if (use_faction_background) {
478  int fac = m_base.GetUnit()->faction;
479  if (FactionUtil::GetFactionName( fac ) == "neutral")
481  const float *stuff = FactionUtil::GetSparkColor( fac );
482 
483  return GFXColor( stuff[0]*faction_color_darkness, stuff[1]*faction_color_darkness, stuff[2]*faction_color_darkness );
484  } else {
485  if (id == "CargoGroup")
486  return GFXColor( 0, 0, faction_color_darkness );
487  else if (id == "NewsGroup")
488  return GFXColor( faction_color_darkness, 0, faction_color_darkness );
489  else if (id == "UpgradeGroup")
490  return GFXColor( 0, faction_color_darkness, 0 );
491  else if (id == "InfoGroup")
492  return GFXColor( 0, faction_color_darkness, faction_color_darkness );
493  else if (id == "MissionsGroup")
494  return GFXColor( faction_color_darkness, 0, 0 );
495  else if (id == "ShipDealerGroup")
496  return GFXColor( faction_color_darkness, faction_color_darkness, 0 );
497  else if (id == "LoadSaveGroup")
498  return GFXColor( 0, faction_color_darkness, faction_color_darkness );
499  else if (id == "NetworkGroup")
500  return GFXColor( 0, faction_color_darkness, faction_color_darkness );
501  else
502  return GFXColor( 0, 0, 0 );
503  }
504 }
void BaseComputer::hideCommitControls ( void  )
protected

Definition at line 1924 of file basecomputer.cpp.

References Window::findControlById(), Control::setHidden(), StaticDisplay::setText(), and WindowController::window().

Referenced by updateTransactionControlsForSelection().

1925 {
1926  //The three buy/sell buttons.
1927  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
1928  commitButton->setHidden( true );
1929  NewButton *commit10Button = static_cast< NewButton* > ( window()->findControlById( "Commit10" ) );
1930  if (commit10Button != NULL) commit10Button->setHidden( true );
1931  NewButton *commitAllButton = static_cast< NewButton* > ( window()->findControlById( "CommitAll" ) );
1932  if (commitAllButton != NULL) commitAllButton->setHidden( true );
1933  NewButton *commitFixButton = static_cast< NewButton* > ( window()->findControlById( "CommitFix" ) );
1934  if (commitFixButton != NULL) commitFixButton->setHidden( true );
1935  //The price and "max" displays.
1936  StaticDisplay *totalPrice = static_cast< StaticDisplay* > ( window()->findControlById( "TotalPrice" ) );
1937  if (totalPrice != NULL) totalPrice->setText( "" );
1938  StaticDisplay *maxForPlayer = static_cast< StaticDisplay* > ( window()->findControlById( "MaxQuantity" ) );
1939  if (maxForPlayer != NULL) maxForPlayer->setText( "" );
1940 }
bool BaseComputer::hideNetworkStatus ( const EventCommandId command,
Control control 
)
protected

Definition at line 1713 of file basecomputer.cpp.

References showNetworkStatus().

1714 {
1715  showNetworkStatus( false );
1716  return true;
1717 }
void BaseComputer::init ( void  )
virtual

Implements WindowController.

Definition at line 1732 of file basecomputer.cpp.

References createControls(), and WindowController::setWindow().

Referenced by BaseInterface::Room::Comp::Click().

1733 {
1734  //Create a new window.
1735  Window *w = new Window;
1736  setWindow( w );
1737 
1738  //Read in the controls for all the modes.
1739  createControls();
1740 }
bool BaseComputer::isTransactionOK ( const Cargo originalItem,
TransactionType  transType,
int  quantity = 1 
)
protected

Definition at line 2429 of file basecomputer.cpp.

References _Universe, ACCEPT_MISSION, active_missions, BUY_CARGO, BUY_SHIP, BUY_UPGRADE, Unit::CanAddCargo(), Cargo::category, color_downgrade_or_noncompatible_flag, color_insufficient_money_flag, color_insufficient_space_flag, Cockpit::credits, Cargo::GetCategory(), UnitContainer::GetUnit(), Universe::isPlayerStarship(), m_base, m_player, UniverseUtil::maxMissions(), Cargo::mission, Cargo::price, Cargo::quantity, SELL_CARGO, SELL_UPGRADE, UpgradeAllowed(), and upgradeNotAddedToCargo().

Referenced by acceptMission(), loadListPicker(), and updateTransactionControlsForSelection().

2430 {
2431  if (originalItem.mission && transType != SELL_CARGO) {
2433  return false;
2434  }
2435  //Make sure we have somewhere to put stuff.
2436  Unit *playerUnit = m_player.GetUnit();
2437  if (!playerUnit) return false;
2438  Cockpit *cockpit = _Universe->isPlayerStarship( playerUnit );
2439  if (!cockpit) return false;
2440  //Need to fix item so there is only one for cost calculations.
2441  Cargo item = originalItem;
2442  item.quantity = quantity;
2443  Unit *baseUnit = m_base.GetUnit();
2444  bool havemoney = true;
2445  bool havespace = true;
2446  switch (transType)
2447  {
2448  case BUY_CARGO:
2449  //Enough credits and room for the item in the ship.
2450  havemoney = item.price*quantity <= cockpit->credits;
2451  havespace = playerUnit->CanAddCargo( item );
2452  if (havemoney && havespace) {
2453  return true;
2454  } else {
2455  if (!havemoney)
2457  if (!havespace)
2459  }
2460  break;
2461  case SELL_CARGO:
2462  //There is a base here, and it is willing to buy the item.
2463  if (!originalItem.mission) {
2464  if (baseUnit) {
2465  havespace = baseUnit->CanAddCargo( item );
2466  if (havespace)
2467  return true;
2468  else
2470  }
2471  } else {
2472  return true;
2473  }
2474  break;
2475  case BUY_SHIP:
2476  //Either you are buying this ship for your fleet, or you already own the
2477  //ship and it will be transported to you.
2478  if (baseUnit) {
2479  if (item.price*quantity <= cockpit->credits)
2480  return true;
2481  else
2483  }
2484  break;
2485  case ACCEPT_MISSION:
2486  //Make sure the player doesn't take too many missions.
2487  if ( item.GetCategory().find( "Active_Missions" ) != string::npos || active_missions.size() < UniverseUtil::maxMissions() )
2488  return true;
2489  break;
2490  case SELL_UPGRADE:
2491  if (baseUnit) {
2492  havespace = baseUnit->CanAddCargo( item );
2493  if (havespace)
2494  return true;
2495  else
2497  }
2498  case BUY_UPGRADE:
2499  //cargo.mission == true means you can't do the transaction.
2500  havemoney = item.price*quantity <= cockpit->credits;
2501  havespace = ( playerUnit->CanAddCargo( item ) || upgradeNotAddedToCargo( item.category ) );
2502  //UpgradeAllowed must be first -- short circuit && operator
2503  if (UpgradeAllowed( item, playerUnit ) && havemoney && havespace && !item.mission) {
2504  return true;
2505  } else {
2506  if (!havemoney)
2508  if (!havespace)
2510  }
2511  break;
2512  default:
2513  assert( false ); //Missed an enum in transaction switch statement.
2514  break;
2515  }
2516  return false;
2517 }
void BaseComputer::loadBuyUpgradeControls ( void  )
protected

Definition at line 3276 of file basecomputer.cpp.

References BASIC_REPAIR_DESC, BASIC_REPAIR_NAME, BASIC_REPAIR_TEXT_COLOR(), basicRepairPrice(), BUY_UPGRADE, CargoColor::cargo, SimplePickerCells::cellAt(), Picker::cells(), Cargo::content, SimplePickerCells::count(), DEFAULT_UPGRADE_COLOR(), Cargo::description, equalColors(), Unit::FilterUpgradeList(), Window::findControlById(), UnitContainer::GetUnit(), isClear(), loadListPicker(), loadMasterList(), m_base, m_player, m_transList1, BaseComputer::TransactionList::masterList, Cargo::price, UnitUtil::repair(), Unit::RepairCost(), SimplePickerCell::setTextColor(), SimplePickerCell::text(), SimplePickerCell::textColor(), and WindowController::window().

Referenced by loadUpgradeControls().

3277 {
3278  Unit *playerUnit = m_player.GetUnit();
3279  Unit *baseUnit = m_base.GetUnit();
3280 
3281  TransactionList &tlist = m_transList1;
3282  tlist.masterList.clear(); //Just in case
3283 
3284  //Get all the upgrades.
3285  assert( equalColors( CargoColor().color, DEFAULT_UPGRADE_COLOR() ) );
3286  std::vector< std::string >filtervec;
3287  filtervec.push_back( "upgrades" );
3288  loadMasterList( baseUnit, filtervec, std::vector< std::string > (), true, tlist );
3289  playerUnit->FilterUpgradeList( tlist.masterList );
3290 
3291  //Mark all the upgrades that we can't do.
3292  //cargo.mission == true means we can't upgrade this.
3293  vector< CargoColor >::iterator iter;
3294  for (iter = tlist.masterList.begin(); iter != tlist.masterList.end(); iter++)
3295  iter->cargo.mission = ( !equalColors( iter->color, DEFAULT_UPGRADE_COLOR() ) );
3296  //Add Basic Repair.
3298  repair.cargo.content = BASIC_REPAIR_NAME;
3299  repair.cargo.price = basicRepairPrice()*playerUnit->RepairCost();
3301  tlist.masterList.push_back( repair );
3302 
3303  //Load the upgrade picker from the master tlist.
3304  SimplePicker *basePicker = static_cast< SimplePicker* > ( window()->findControlById( "BaseUpgrades" ) );
3305  assert( basePicker != NULL );
3306  loadListPicker( tlist, *basePicker, BUY_UPGRADE, true );
3307 
3308  //Fix the Basic Repair color.
3309  SimplePickerCells *baseCells = static_cast< SimplePickerCells* > ( basePicker->cells() );
3310  SimplePickerCell *repairCell = static_cast< SimplePickerCell* > ( baseCells->cellAt( baseCells->count()-1 ) );
3311  assert( repairCell->text() == BASIC_REPAIR_NAME );
3312  if ( isClear( repairCell->textColor() ) )
3313  //Have repair cell, and its color is normal.
3314  repairCell->setTextColor( BASIC_REPAIR_TEXT_COLOR() );
3315 }
void BaseComputer::loadCargoControls ( void  )
protected

Definition at line 2654 of file basecomputer.cpp.

References BUY_CARGO, Window::findControlById(), UnitContainer::GetUnit(), VegaConfig::getVariable(), loadListPicker(), loadMasterList(), m_base, m_player, m_transList1, m_transList2, XMLSupport::parse_bool(), recalcTitle(), resetTransactionLists(), Orders::SelectDockPort(), SELL_CARGO, vs_config, and WindowController::window().

Referenced by changeToCargoMode().

2655 {
2656  //Make sure there's nothing in the transaction lists.
2658  static bool requireportforlaunch =
2659  XMLSupport::parse_bool( vs_config->getVariable( "physics", "cargo_wingmen_only_with_dockport", "false" ) );
2660  static bool portallowsupgrades =
2661  XMLSupport::parse_bool( vs_config->getVariable( "physics", "dockport_allows_ugrade_storage", "false" ) );
2662  //Set up the base dealer's transaction list. Note that you need a docking port to buy starships!
2663  vector< string >donttakethis;
2664  donttakethis.push_back( "missions" );
2665 //if no docking port OR no permission, no upgrades
2666  if ( (SelectDockPort( m_player.GetUnit(), m_player.GetUnit() ) < 0) || (!portallowsupgrades) )
2667  donttakethis.push_back( "upgrades" );
2668 //if no docking port AND no permission, no ships (different from above for VS compatibility)
2669  if ( (SelectDockPort( m_player.GetUnit(), m_player.GetUnit() ) < 0) && (requireportforlaunch) )
2670  donttakethis.push_back( "starships" );
2671  static bool starship_purchase = XMLSupport::parse_bool( vs_config->getVariable( "physics", "starships_as_cargo", "true" ) );
2672  if (!starship_purchase) {
2673  donttakethis.push_back( "starships" );
2674  donttakethis.push_back( "starship" );
2675  }
2676  loadMasterList( m_base.GetUnit(), vector< string > (), donttakethis, true, m_transList1 ); //Anything but a mission.
2677  SimplePicker *basePicker = static_cast< SimplePicker* > ( window()->findControlById( "BaseCargo" ) );
2678  assert( basePicker != NULL );
2679  loadListPicker( m_transList1, *basePicker, BUY_CARGO );
2680 
2681  //Set up the player's transaction list.
2682  loadMasterList( m_player.GetUnit(), vector< string > (), donttakethis, true, m_transList2 ); //Anything but a mission.
2683  SimplePicker *inventoryPicker = static_cast< SimplePicker* > ( window()->findControlById( "PlayerCargo" ) );
2684  assert( inventoryPicker != NULL );
2685  loadListPicker( m_transList2, *inventoryPicker, SELL_CARGO );
2686 
2687  //Make the title right.
2688  recalcTitle();
2689 }
void BaseComputer::loadListPicker ( TransactionList list,
SimplePicker picker,
TransactionType  transType,
bool  skipFirstCategory = false 
)
protected

Definition at line 2569 of file basecomputer.cpp.

References SimplePicker::addCell(), SimplePickerCell::addChild(), beautify(), Cargo::category, Picker::cells(), SimplePicker::clear(), color_downgrade_or_noncompatible_flag, color_insufficient_money_flag, color_insufficient_space_flag, color_prohibited_upgrade_flag, Cargo::content, createCategoryCell(), DOWNGRADE_OR_NONCOMPAT_COLOR(), getDisplayCategory(), UnitContainer::GetUnit(), GUI_CLEAR(), i, isTransactionOK(), ITEM_DESTROYED_COLOR(), UniverseUtil::LookupUnitStat(), m_player, BaseComputer::TransactionList::masterList, Cargo::mission, MISSION_COLOR(), NO_MONEY_COLOR(), NO_ROOM_COLOR(), UnitUtil::PercentOperational(), BaseComputer::TransactionList::picker, PROHIBITED_COLOR(), Cargo::quantity, SELL_UPGRADE, tostring(), and BaseComputer::TransactionList::transaction.

Referenced by loadBuyUpgradeControls(), loadCargoControls(), loadMissionsControls(), loadSellUpgradeControls(), and loadShipDealerControls().

2573 {
2574  //Make sure the transactionList has the correct info.
2575  tlist.picker = &picker;
2576  tlist.transaction = transType;
2577 
2578  //Make sure there is nothing old lying around in the picker.
2579  picker.clear();
2580 
2581  //Iterate through the list and load the picker from it.
2582  string currentCategory = "--ILLEGAL CATEGORY--"; //Current category we are adding cells to.
2583  SimplePickerCell *parentCell = NULL; //Place to add new items. NULL = Add to picker.
2584  for (size_t i = 0; i < tlist.masterList.size(); i++) {
2585  Cargo &item = tlist.masterList[i].cargo;
2586  std::string icategory = getDisplayCategory( item );
2587  if (icategory != currentCategory) {
2588  //Create new cell(s) for the new category.
2589  parentCell = createCategoryCell(
2590  *static_cast< SimplePickerCells* > ( picker.cells() ), icategory, skipFirstCategory );
2591  currentCategory = icategory;
2592  }
2593  //Construct the cell for this item.
2594  //JS_NUDGE -- this is where I'll need to do the upgrades colorations goop hooks
2595  const bool transOK = isTransactionOK( item, transType );
2596 
2597  string itemName = beautify( UniverseUtil::LookupUnitStat( item.content, "upgrades", "Name" ) );
2598  string originalName = itemName;
2599  if (itemName == "")
2600  itemName = beautify( item.content );
2601  if (item.quantity > 1)
2602  //If there is more than one item, show the number of items.
2603  itemName += " ("+tostring( item.quantity )+")";
2604 //*******************************************************************************
2605 
2606  //Clear color means use the text color in the picker.
2607  GFXColor bad_trans_color = NO_MONEY_COLOR();
2609  bad_trans_color = DOWNGRADE_OR_NONCOMPAT_COLOR();
2611  bad_trans_color = PROHIBITED_COLOR();
2613  bad_trans_color = NO_ROOM_COLOR();
2615  //Just in case we want to change the default reason for non-purchase
2616  bad_trans_color = NO_MONEY_COLOR();
2617  GFXColor base_color = (transOK ? (item.mission ? MISSION_COLOR() : GUI_CLEAR) : bad_trans_color);
2618  //Reset cause-color flags
2623  GFXColor final_color;
2624  if ( transType == SELL_UPGRADE && m_player.GetUnit() ) {
2625  //Adjust the base color if the item is 'damaged'
2626  double percent_working = UnitUtil::PercentOperational( m_player.GetUnit(), item.content, item.category, false );
2627 
2628  final_color = GFXColor(
2629  (1.0*percent_working)+( 1.0*(1.0-percent_working) ),
2630  (1.0*percent_working)+( 0.0*(1.0-percent_working) ),
2631  (0.0*percent_working)+( 0.0*(1.0-percent_working) ),
2632  (1.0*percent_working)+( 1.0*(1.0-percent_working) )
2633  );
2634  if (percent_working == 1.0) final_color = base_color; //working = normal color
2635  if (percent_working == 0.0) final_color = ITEM_DESTROYED_COLOR(); //dead = grey
2636  } else {
2637  final_color = base_color;
2638  }
2639  SimplePickerCell *cell = new SimplePickerCell( itemName, item.content, final_color, i );
2640 
2641  //*******************************************************************************
2642  //Add the cell.
2643  if (parentCell)
2644  parentCell->addChild( cell );
2645  else
2646  picker.addCell( cell );
2647  }
2648 }
void BaseComputer::loadLoadSaveControls ( void  )
protected

Definition at line 3057 of file basecomputer.cpp.

References SimplePicker::addCell(), SimplePicker::clear(), datesort(), Window::findControlById(), UnitContainer::GetUnit(), VSFileSystem::homedir, m_player, nodirs(), recalcTitle(), StaticDisplay::setText(), and WindowController::window().

Referenced by actionConfirmedSaveGame(), and changeToLoadSaveMode().

3058 {
3059  SimplePicker *picker = static_cast< SimplePicker* > ( window()->findControlById( "LoadSavePicker" ) );
3060  assert( picker != NULL );
3061  picker->clear();
3062 
3063  //Get news from save game.
3064  Unit *playerUnit = m_player.GetUnit();
3065  if (playerUnit) {
3066  struct dirent **dirlist;
3067  std::string savedir = VSFileSystem::homedir+"/save/";
3068  int ret = scandir( savedir.c_str(), &dirlist, nodirs, (scancompare)&datesort );
3069  while (ret-- > 0)
3070  picker->addCell( new SimplePickerCell( dirlist[ret]->d_name ) );
3071  }
3072  //Make sure the description is empty.
3073  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
3074  assert( desc != NULL );
3075  desc->setText( "" );
3076 
3077  //Make the title right.
3078  recalcTitle();
3079 }
void BaseComputer::loadMasterList ( Unit un,
const vector< string > &  filterthis,
const vector< string > &  invfilterthis,
bool  removezero,
TransactionList list 
)
protected

Definition at line 2714 of file basecomputer.cpp.

References CargoColor::cargo, Cargo::category, Unit::GetCargo(), Cargo::GetCategory(), i, BaseComputer::TransactionList::masterList, Unit::numCargo(), and Cargo::quantity.

Referenced by loadBuyUpgradeControls(), loadCargoControls(), loadSellUpgradeControls(), and loadShipDealerControls().

2719 {
2720  vector< CargoColor > *items = &tlist.masterList;
2721  for (size_t i = 0; i < un->numCargo(); i++) {
2722  bool filter = filtervec.empty();
2723  bool invfilter = true;
2724  size_t vecindex;
2725  for (vecindex = 0; !filter && ( vecindex < filtervec.size() ); vecindex++)
2726  if (un->GetCargo( i ).GetCategory().find( filtervec[vecindex] ) != string::npos)
2727  filter = true;
2728  for (vecindex = 0; invfilter && ( vecindex < invfiltervec.size() ); vecindex++)
2729  if (un->GetCargo( i ).GetCategory().find( invfiltervec[vecindex] ) != string::npos)
2730  invfilter = false;
2731  if (filter && invfilter) {
2732  if ( (!removezero) || un->GetCargo( i ).quantity > 0 ) {
2733  CargoColor col;
2734  col.cargo = un->GetCargo( i );
2735  if (col.cargo.category == "")
2736  col.cargo.category = "#c.5:1:.3#Uncategorized Cargo";
2737  items->push_back( col );
2738  }
2739  }
2740  }
2741  std::sort( items->begin(), items->end(), CargoColorSort() );
2742 }
void BaseComputer::loadMissionsControls ( void  )
protected

Definition at line 3174 of file basecomputer.cpp.

References ACCEPT_MISSION, Window::findControlById(), loadListPicker(), loadMissionsMasterList(), m_transList1, recalcTitle(), resetTransactionLists(), and WindowController::window().

Referenced by acceptMission(), and changeToMissionsMode().

3175 {
3176  //Make sure there's nothing in the transaction lists.
3178 
3179  //Load up the list of missions.
3181  SimplePicker *picker = static_cast< SimplePicker* > ( window()->findControlById( "Missions" ) );
3182  assert( picker != NULL );
3184 
3185  //Make the title right.
3186  recalcTitle();
3187 }
void BaseComputer::loadMissionsMasterList ( TransactionList list)
protected

Definition at line 3092 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, beautify(), c, CargoColor::cargo, Cargo::category, CATEGORY_SEP, CargoColor::color, Cargo::content, DEFAULT_UPGRADE_COLOR(), Cargo::description, Cargo::GetDescription(), Cockpit::GetParent(), getSaveString(), getSaveStringLength(), i, UnitUtil::isPlayerStarship(), j, BaseComputer::TransactionList::masterList, MISSION_DESC_LABEL, MISSION_NAMES_LABEL, MISSION_SCRIPTS_LABEL, Network, Cargo::price, putSaveString(), Cargo::quantity, tostring(), XMLSupport::tostring(), and VSFileSystem::vs_fprintf().

Referenced by loadMissionsControls().

3093 {
3094  //Make sure the list is clear.
3095  tlist.masterList.clear();
3096 
3097  Unit *unit = _Universe->AccessCockpit()->GetParent();
3098  int playerNum = UnitUtil::isPlayerStarship( unit );
3099  if (playerNum < 0) {
3100  VSFileSystem::vs_fprintf( stderr, "Docked ship not a player." );
3101  return;
3102  }
3103  //Number of strings to look at. And make sure they match!
3104  const size_t stringCount = getSaveStringLength( playerNum, MISSION_NAMES_LABEL );
3105  if (Network == NULL)
3106  //these aren't sent over the network.
3107  assert( stringCount == getSaveStringLength( playerNum, MISSION_SCRIPTS_LABEL ) );
3108  assert( stringCount == getSaveStringLength( playerNum, MISSION_DESC_LABEL ) );
3109  //Make sure we have different names for all the missions.
3110  //This changes the savegame -- it removes ambiguity for good.
3111  for (size_t current = 0; current < stringCount; current++) {
3112  const string currentName = getSaveString( playerNum, MISSION_NAMES_LABEL, current );
3113  size_t count = 1;
3114  //Check whether any after the current one have the same name.
3115  for (unsigned int check = current+1; check < stringCount; ++check) {
3116  const string checkName = getSaveString( playerNum, MISSION_NAMES_LABEL, check );
3117  if (check == current)
3118  {
3119  //Found identical names. Add a "count" at the end.
3120  putSaveString( playerNum, MISSION_NAMES_LABEL, current, checkName+"_"+tostring( static_cast<int>(count) ) );
3121  ++count;
3122  }
3123  }
3124  }
3125  //Create an entry for for each mission.
3126  for (size_t i = 0; i < stringCount; i++) {
3127  CargoColor c;
3128  //Take any categories out of the name and put them in the cargo.category.
3129  if (Network == NULL) {
3130  const string finalScript = getSaveString( playerNum, MISSION_SCRIPTS_LABEL, i );
3131  if (finalScript[0] == '#')
3132  continue; //Ignore any missions with comments. (those are fixer missions.)
3133  }
3134  const string originalName = getSaveString( playerNum, MISSION_NAMES_LABEL, i );
3135  const string::size_type lastCategorySep = originalName.rfind( CATEGORY_SEP );
3136  if (lastCategorySep != string::npos) {
3137  //We have a category.
3138  c.cargo.content = originalName.substr( lastCategorySep+1 );
3139  c.cargo.category = originalName.substr( 0, lastCategorySep );
3140  } else {
3141  //No category in name.
3142  c.cargo.content = originalName;
3143  c.cargo.category = "";
3144  }
3145  c.cargo.content = c.cargo.content;
3146  //Description gets name at the top.
3147  c.cargo.description = "#b#"+beautify( c.cargo.content )+":#-b#n1.75#"
3148  +getSaveString( playerNum, MISSION_DESC_LABEL, i );
3149 
3150  tlist.masterList.push_back( c );
3151  }
3152  //Sort the list. Better for display, easier to compile into categories, etc.
3153  std::sort( tlist.masterList.begin(), tlist.masterList.end(), CargoColorSort() );
3154  if ( active_missions.size() ) {
3155  for (unsigned int i = 1; i < active_missions.size(); ++i) {
3156  CargoColor amission;
3157  amission.cargo.content = XMLSupport::tostring( i )+" "+active_missions[i]->mission_name;
3158  amission.cargo.price = 0;
3159  amission.cargo.quantity = 1;
3160  amission.cargo.category = "Active_Missions";
3161  amission.cargo.description = "Objectives\\";
3162  for (unsigned int j = 0; j < active_missions[i]->objectives.size(); ++j)
3163  amission.cargo.description = amission.cargo.GetDescription()+active_missions[i]->objectives[j].objective+": "
3164  +XMLSupport::tostring( (int) (100
3165  *active_missions[i]->objectives[j].completeness) )
3166  +"%\\";
3167  amission.color = DEFAULT_UPGRADE_COLOR();
3168  tlist.masterList.push_back( amission );
3169  }
3170  }
3171 }
void BaseComputer::loadNetworkControls ( void  )
protected

Definition at line 6180 of file basecomputer.cpp.

Referenced by changeToNetworkMode().

6181 {
6182 }
void BaseComputer::loadNewsControls ( void  )
protected

Definition at line 2978 of file basecomputer.cpp.

References SimplePicker::addCell(), SimplePicker::clear(), Window::findControlById(), getSaveString(), getSaveStringLength(), UnitContainer::GetUnit(), VegaConfig::getVariable(), i, UnitUtil::isPlayerStarship(), MessageCenter::last(), m_player, gameMessage::message, mission, Mission::msgcenter, Network, NEWS_NAME_LABEL, XMLSupport::parse_bool(), recalcTitle(), StaticDisplay::setText(), vs_config, and WindowController::window().

Referenced by changeToNewsMode().

2979 {
2980  SimplePicker *picker = static_cast< SimplePicker* > ( window()->findControlById( "NewsPicker" ) );
2981  assert( picker != NULL );
2982  picker->clear();
2983 
2984  //Load the picker.
2985  static const bool newsFromCargolist =
2986  XMLSupport::parse_bool( vs_config->getVariable( "cargo", "news_from_cargolist", "false" ) );
2987  if (newsFromCargolist && Network == NULL) {
2988  gameMessage last;
2989  int i = 0;
2990  vector< std::string >who;
2991  who.push_back( "news" );
2992  while ( ( mission->msgcenter->last( i++, last, who ) ) )
2993  picker->addCell( new SimplePickerCell( last.message ) );
2994  } else {
2995  //Get news from save game.
2996  Unit *playerUnit = m_player.GetUnit();
2997  if (playerUnit) {
2998  const int playerNum = UnitUtil::isPlayerStarship( playerUnit );
2999  int len = getSaveStringLength( playerNum, NEWS_NAME_LABEL );
3000  for (int i = len-1; i >= 0; i--)
3001  {
3002  picker->addCell( new SimplePickerCell( getSaveString( playerNum, NEWS_NAME_LABEL, i ) ) );
3003  }
3004  }
3005  }
3006  //Make sure the description is empty.
3007  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
3008  assert( desc != NULL );
3009  desc->setText( "" );
3010 
3011  //Make the title right.
3012  recalcTitle();
3013 }
bool BaseComputer::loadSavePickerChangedSelection ( const EventCommandId command,
Control control 
)
protected

Definition at line 2957 of file basecomputer.cpp.

References Window::findControlById(), GarnerInfoFromSaveGame(), Picker::selectedCell(), StaticDisplay::setText(), PickerCell::text(), and WindowController::window().

2958 {
2959  assert( control != NULL );
2960  Picker *picker = static_cast< Picker* > (control);
2961  PickerCell *cell = picker->selectedCell();
2962 
2963  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
2964  StaticDisplay *inputbox = static_cast< StaticDisplay* > ( window()->findControlById( "InputText" ) );
2965  assert( desc != NULL );
2966  if (cell == NULL) {
2967  //No selection. Clear desc. (Not sure how this can happen, but it's easy to cover.)
2968  desc->setText( "" );
2969  } else {
2970  desc->setText( GarnerInfoFromSaveGame( cell->text() ) );
2971  if (inputbox != NULL)
2972  inputbox->setText( cell->text() );
2973  }
2974  return true;
2975 }
void BaseComputer::loadSellUpgradeControls ( void  )
protected

Definition at line 3318 of file basecomputer.cpp.

References ClearDowngradeMap(), DEFAULT_UPGRADE_COLOR(), equalColors(), Unit::FilterDowngradeList(), Window::findControlById(), GetListOfDowngrades(), UnitContainer::GetUnit(), GetUnitMasterPartList(), VegaConfig::getVariable(), i, loadListPicker(), loadMasterList(), m_base, m_player, m_transList2, BaseComputer::TransactionList::masterList, XMLSupport::parse_bool(), SELL_UPGRADE, vs_config, weapfiltervec, and WindowController::window().

Referenced by loadUpgradeControls().

3319 {
3320  Unit *playerUnit = m_player.GetUnit();
3321  Unit *baseUnit = m_base.GetUnit();
3322  if ( !(playerUnit && baseUnit) )
3323  return;
3324  TransactionList &tlist = m_transList2;
3325  tlist.masterList.clear(); //Just in case
3326 
3327  //Get a list of upgrades on our ship we could sell.
3328  Unit *partListUnit = &GetUnitMasterPartList();
3329 
3330  loadMasterList( partListUnit, weapfiltervec, std::vector< std::string > (), false, tlist );
3332  playerUnit->FilterDowngradeList( tlist.masterList );
3333  static const bool clearDowngrades =
3334  XMLSupport::parse_bool( vs_config->getVariable( "physics", "only_show_best_downgrade", "true" ) );
3335  if (clearDowngrades) {
3336  std::set< std::string >downgradeMap = GetListOfDowngrades();
3337  for (unsigned int i = 0; i < tlist.masterList.size(); ++i)
3338  if ( downgradeMap.find( tlist.masterList[i].cargo.content ) == downgradeMap.end() ) {
3339  tlist.masterList.erase( tlist.masterList.begin()+i );
3340  i--;
3341  }
3342  }
3343  //Mark all the upgrades that we can't do.
3344  //cargo.mission == true means we can't upgrade this.
3345  vector< CargoColor >::iterator iter;
3346  for (iter = tlist.masterList.begin(); iter != tlist.masterList.end(); iter++)
3347  iter->cargo.mission = ( !equalColors( iter->color, DEFAULT_UPGRADE_COLOR() ) );
3348  std::vector< std::string >invplayerfiltervec = weapfiltervec;
3349  std::vector< string >playerfiltervec;
3350  playerfiltervec.push_back( "upgrades" );
3351  loadMasterList( playerUnit, playerfiltervec, invplayerfiltervec, false, tlist ); //Get upgrades, but not weapons.
3352 
3353  //Sort the tlist. Better for display, easier to compile into categories, etc.
3354  std::sort( tlist.masterList.begin(), tlist.masterList.end(), CargoColorSort() );
3355 
3356  //Load the upgrade picker form the master list.
3357  SimplePicker *basePicker = static_cast< SimplePicker* > ( window()->findControlById( "PlayerUpgrades" ) );
3358  assert( basePicker != NULL );
3359  loadListPicker( tlist, *basePicker, SELL_UPGRADE, true );
3360 }
void BaseComputer::loadShipDealerControls ( void  )

Definition at line 4413 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), BUY_SHIP, CargoColor::cargo, CreateCargoForOwnerStarship(), Window::findControlById(), Cockpit::GetNumUnits(), UnitContainer::GetUnit(), i, loadListPicker(), loadMasterList(), m_base, m_transList1, BaseComputer::TransactionList::masterList, recalcTitle(), resetTransactionLists(), and WindowController::window().

Referenced by changeToShipDealerMode(), and sellShip().

4414 {
4415  //Make sure there's nothing in the transaction lists.
4417 
4418  //Set up the base dealer's transaction list.
4419  std::vector< std::string >filtervec;
4420  filtervec.push_back( "starships" );
4421  loadMasterList( m_base.GetUnit(), filtervec, std::vector< std::string > (), true, m_transList1 );
4422 
4423  //Add in the starships owned by this player.
4424  Cockpit *cockpit = _Universe->AccessCockpit();
4425  for (size_t i = 1, n = cockpit->GetNumUnits(); i < n; ++i) {
4426  CargoColor cargoColor;
4427  cargoColor.cargo = CreateCargoForOwnerStarship( cockpit, m_base.GetUnit(), i );
4428  m_transList1.masterList.push_back( cargoColor );
4429  }
4430  //remove the descriptions, we don't build them all here, it is a time consuming operation
4431  vector< CargoColor > *items = &m_transList1.masterList;
4432  for (vector< CargoColor >::iterator it = items->begin(); it != items->end(); it++)
4433  (*it).cargo.description = "";
4434  //Load the picker from the master list.
4435  SimplePicker *basePicker = static_cast< SimplePicker* > ( window()->findControlById( "Ships" ) );
4436  assert( basePicker != NULL );
4437  loadListPicker( m_transList1, *basePicker, BUY_SHIP, true );
4438 
4439  //Make the title right.
4440  recalcTitle();
4441 }
void BaseComputer::loadUpgradeControls ( void  )
protected

Definition at line 3262 of file basecomputer.cpp.

References loadBuyUpgradeControls(), loadSellUpgradeControls(), recalcTitle(), and resetTransactionLists().

Referenced by changeToUpgradeMode().

3263 {
3264  //Make sure there's nothing in the transaction lists.
3266 
3267  //Load the controls.
3270 
3271  //Make the title right.
3272  recalcTitle();
3273 }
int BaseComputer::maxQuantityForPlayer ( const Cargo item,
int  suggestedQuantity 
)
protected

Definition at line 2778 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), Cockpit::credits, Unit::getCargoVolume(), Unit::getEmptyCargoVolume(), UnitContainer::GetUnit(), guiMin, int, m_player, Cargo::price, and Cargo::volume.

Referenced by buySelectedCargo(), and configureCargoCommitControls().

2779 {
2780  int result = 0;
2781 
2782  Unit *playerUnit = m_player.GetUnit();
2783  if (playerUnit) {
2784  //Limit by cargo capacity.
2785  const float volumeLeft = playerUnit->getEmptyCargoVolume()-playerUnit->getCargoVolume();
2786  result = (int) guiMin( suggestedQuantity, volumeLeft/item.volume );
2787 
2788  //Limit by price.
2789  const double credits = _Universe->AccessCockpit()->credits;
2790  result = (int) guiMin( result, credits/item.price );
2791  }
2792  return result;
2793 }
bool BaseComputer::newsPickerChangedSelection ( const EventCommandId command,
Control control 
)
protected

Definition at line 2931 of file basecomputer.cpp.

References Window::findControlById(), VegaConfig::getVariable(), Music::GotoSong(), m_playingMuzak, muzak, Picker::selectedCell(), StaticDisplay::setText(), PickerCell::text(), vs_config, and WindowController::window().

2932 {
2933  assert( control != NULL );
2934  Picker *picker = static_cast< Picker* > (control);
2935  PickerCell *cell = picker->selectedCell();
2936 
2937  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
2938  assert( desc != NULL );
2939  if (cell == NULL)
2940  //No selection. Clear desc. (Not sure how this can happen, but it's easy to cover.)
2941  desc->setText( "" );
2942  else
2943  desc->setText( cell->text() );
2944  //Turn on some cool music.
2945  static string newssong = vs_config->getVariable( "audio", "newssong", "../music/news1.ogg" );
2946  muzak->GotoSong( newssong );
2947  m_playingMuzak = true;
2948  return true;
2949 }
bool BaseComputer::pickerChangedSelection ( const EventCommandId command,
Control control 
)
protected

Definition at line 2350 of file basecomputer.cpp.

References CATEGORY_TAG, UnitContainer::GetUnit(), m_base, m_transList1, m_transList2, BaseComputer::TransactionList::picker, Picker::selectedCell(), PickerCell::tag(), and updateTransactionControlsForSelection().

2351 {
2352  assert( control != NULL );
2353  Picker *picker = static_cast< Picker* > (control);
2354  PickerCell *cell = picker->selectedCell();
2355 
2356  //Figure out which transaction list we are using.
2357  assert( picker == m_transList1.picker || picker == m_transList2.picker );
2358  TransactionList *tlist = ( (picker == m_transList1.picker) ? &m_transList1 : &m_transList2 );
2359  if ( m_base.GetUnit() ) {
2360  if (!cell) {
2361  //The selection just got cleared.
2362  TransactionList &otherList = ( (&m_transList1 == tlist) ? m_transList2 : m_transList1 );
2363  if ( otherList.picker && otherList.picker->selectedCell() ) {
2364  //Special case. The other picker has a selection -- we are seeing the selection
2365  //cleared in this picker as result. Do nothing.
2366  } else {
2368  }
2369  } else if (cell->tag() == CATEGORY_TAG) {
2370  //They just selected a category. Clear the selection no matter what.
2372  } else {
2373  //Make the controls right for this item.
2375  }
2376  }
2377  return true;
2378 }
void BaseComputer::recalcTitle ( void  )
protected

Definition at line 1753 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, CARGO, Cockpit::credits, Universe::current_stardate, emergency_downgrade_mode, Unit::faction, Window::findControlById(), Unit::getCargoVolume(), Unit::getEmptyCargoVolume(), Unit::getEmptyUpgradeVolume(), FactionUtil::GetFactionName(), StarDate::GetFullTrekDate(), UnitContainer::GetUnit(), Unit::getUpgradeVolume(), VegaConfig::getVariable(), guiMax, Unit::isUnit(), m_base, m_currentDisplay, m_player, MISSIONS, Unit::name, XMLSupport::parse_bool(), PLANETPTR, StaticDisplay::setText(), ModeInfo::title, UPGRADE, vs_config, and WindowController::window().

Referenced by changeToInfoMode(), loadCargoControls(), loadLoadSaveControls(), loadMissionsControls(), loadNewsControls(), loadShipDealerControls(), loadUpgradeControls(), and refresh().

1754 {
1755  //Generic base title for the display.
1756  string baseTitle = modeInfo[m_currentDisplay].title;
1757 
1758  //Base name.
1759  Unit *baseUnit = m_base.GetUnit();
1760  string baseName;
1761  if (baseUnit) {
1762  if (baseUnit->isUnit() == PLANETPTR) {
1763  string temp = ( (Planet*) baseUnit )->getHumanReadablePlanetType()+" Planet";
1764  baseName = temp;
1765  } else {
1766  baseName = baseUnit->name;
1767  }
1768  }
1769  baseTitle += emergency_downgrade_mode;
1770  static bool includebasename =
1771  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "include_base_name_on_dock", "true" ) );
1772  if (includebasename) {
1773  baseTitle += baseName;
1774 
1775  //Faction name for base.
1776  string baseFaction = FactionUtil::GetFactionName( baseUnit->faction );
1777  if ( !baseFaction.empty() )
1778  baseTitle += " ["+baseFaction+']';
1779  }
1780  //Set the string in the base title control.
1781  StaticDisplay *baseTitleDisplay = static_cast< StaticDisplay* > ( window()->findControlById( "BaseInfoTitle" ) );
1782  assert( baseTitleDisplay != NULL );
1783  baseTitleDisplay->setText( baseTitle );
1784 
1785  //Generic player title for display
1786  char playerTitle[256];
1787  playerTitle[0] = '\0'; //Start with an empty string.
1788 
1789  static bool showStardate =
1790  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "show_stardate", "true" ) );
1791 
1792  //Credits the player has.
1793  const float playerCredits = _Universe->AccessCockpit()->credits;
1794  const char *stardate = _Universe->current_stardate.GetFullTrekDate().c_str();
1795  switch (m_currentDisplay)
1796  {
1797  default:
1798  if (showStardate) {
1799  sprintf( playerTitle, "Stardate: %s Credits: %.2f", stardate, playerCredits );
1800  } else {
1801  sprintf( playerTitle, "Credits: %.2f", playerCredits );
1802  }
1803  break;
1804  case MISSIONS:
1805  {
1806  const int count = guiMax( 0, active_missions.size()-1 );
1807  if (showStardate) {
1808  sprintf( playerTitle, "Stardate: %s Credits: %.2f Active missions: %d", stardate, playerCredits, count );
1809  } else {
1810  sprintf( playerTitle, "Credits: %.2f Active missions: %d", playerCredits, count );
1811  }
1812  break;
1813  }
1814  case UPGRADE:
1815  //Fall through.
1816  case CARGO:
1817  {
1818  Unit *playerUnit = m_player.GetUnit();
1819  if (playerUnit) {
1820  const float emptyVolume = m_currentDisplay
1821  == CARGO ? playerUnit->getEmptyCargoVolume() : playerUnit->getEmptyUpgradeVolume();
1822  const float volumeLeft = emptyVolume
1823  -( m_currentDisplay
1824  == CARGO ? playerUnit->getCargoVolume() : playerUnit->getUpgradeVolume() );
1825  if (showStardate) {
1826  sprintf( playerTitle, "Stardate: %s Credits: %.2f Space left: %.6g of %.6g cubic meters", stardate, playerCredits, volumeLeft, emptyVolume );
1827  } else {
1828  sprintf( playerTitle, "Credits: %.2f Space left: %.6g of %.6g cubic meters", playerCredits, volumeLeft, emptyVolume );
1829  }
1830  }
1831  break;
1832  }
1833  }
1834  //Set the string in the player title control.
1835  StaticDisplay *playerTitleDisplay = static_cast< StaticDisplay* > ( window()->findControlById( "PlayerInfoTitle" ) );
1836  assert( playerTitleDisplay != NULL );
1837  playerTitleDisplay->setText( playerTitle );
1838 }
void BaseComputer::refresh ( void  )
protected

Definition at line 2802 of file basecomputer.cpp.

References eliminateZeroCargo(), UnitContainer::GetUnit(), m_currentDisplay, m_player, m_transList1, m_transList2, BaseComputer::TransactionList::picker, WctlBase< BaseComputer >::processWindowCommand(), recalcTitle(), Picker::restoreOpenCategories(), and Picker::saveOpenCategories().

Referenced by acceptMission(), buySelectedCargo(), buyUpgrade(), draw(), fixUpgrade(), sellSelectedCargo(), and sellUpgrade().

2803 {
2804  if ( m_player.GetUnit() ) {
2806  //Reload the UI -- inventory has changed. Because we reload the UI, we need to
2807  //find, select, and scroll to the thing we bought. The item might be gone from the
2808  //list (along with some categories) after the transaction.
2809  std::list< std::list< std::string > >list1save, list2save;
2810  if (m_transList1.picker)
2811  m_transList1.picker->saveOpenCategories( list1save );
2812  if (m_transList2.picker)
2813  m_transList2.picker->saveOpenCategories( list2save );
2815  if (m_transList1.picker)
2817  if (m_transList2.picker)
2819  recalcTitle();
2820  }
2821 }
void BaseComputer::resetTransactionLists ( void  )
protected

Definition at line 1639 of file basecomputer.cpp.

References m_transList1, and m_transList2.

Referenced by loadCargoControls(), loadMissionsControls(), loadShipDealerControls(), and loadUpgradeControls().

1640 {
1641  m_transList1 = TransactionList();
1642  m_transList2 = TransactionList();
1643 }
void BaseComputer::run ( void  )
virtual

Reimplemented from WindowController.

Definition at line 1743 of file basecomputer.cpp.

References m_displayModes, WctlBase< BaseComputer >::processWindowCommand(), and WindowController::run().

Referenced by BaseInterface::Room::Comp::Click().

1744 {
1745  //Simulate clicking the leftmost mode button.
1746  //We don't actually use the button because there isn't a button if there's only one mode.
1747  processWindowCommand( modeInfo[m_displayModes[0]].command, NULL );
1748 
1750 }
bool BaseComputer::scrollToItem ( Picker picker,
const Cargo item,
bool  select,
bool  skipFirstCategory 
)
protected

Definition at line 1842 of file basecomputer.cpp.

References CATEGORY_SEP, PickerCells::cellAt(), Picker::cells(), PickerCells::cellWithId(), PickerCell::children(), Cargo::content, PickerCells::count(), getDisplayCategory(), i, PickerCell::id(), Picker::scrollToCell(), Picker::selectCell(), Picker::selectedCell(), PickerCell::setHideChildren(), and Picker::setMustRecalc().

Referenced by updateTransactionControls().

1843 {
1844  PickerCells *cells = picker->cells();
1845  if (!cells) return false;
1846  PickerCell *categoryCell = NULL; //Need this if we can't find the item.
1847 
1848  //Walk through the category list(s).
1849  std::string category = getDisplayCategory( item );
1850  if (category.size() > 0) {
1851  //Make sure we have a category.
1852  string::size_type categoryStart = 0;
1853  if (skipFirstCategory) {
1854  //We need to skip the first category in the string.
1855  //Generally need to do this when there's a category level that's not in the UI, like
1856  //"upgrades" in the Upgrade UI.
1857  categoryStart = category.find( CATEGORY_SEP, 0 );
1858  if (categoryStart != string::npos) categoryStart++;
1859  }
1860  while (true) {
1861  //See if we have multiple categories left.
1862  const string::size_type categoryEnd = category.find( CATEGORY_SEP, categoryStart );
1863  const string currentCategory = category.substr( categoryStart, categoryEnd-categoryStart );
1864 
1865  PickerCell *cell = cells->cellWithId( currentCategory );
1866  if ( !cell || !cell->children() ) {
1867  //The category has no children, or we have no matching category. We are done.
1868  //WARNING: We return from here!
1869  picker->scrollToCell( categoryCell );
1870  return false;
1871  }
1872  //Found the category in the right place.
1873  categoryCell = cell;
1874  categoryCell->setHideChildren( false );
1875  picker->setMustRecalc();
1876  cells = categoryCell->children();
1877  //Next piece of the category string.
1878  if (categoryEnd == string::npos)
1879  break;
1880  categoryStart = categoryEnd+1;
1881  }
1882  }
1883  //We have the parent category, now we need the child itself.
1884  assert( cells != NULL );
1885  PickerCell *cell = cells->cellWithId( item.content );
1886  picker->setMustRecalc();
1887  if (!cell) {
1888  //Item is not here.
1889  int count = cells->count();
1890  if (count == 0) {
1891  //The category is empty.
1892  picker->scrollToCell( categoryCell );
1893  return false;
1894  }
1895  //Try to find the place where the item used to be.
1896  //We assume here that the list is sorted by id, which is the
1897  //original, un-beautified name.
1898  int i = 0;
1899  for (; i < count; i++)
1900  if ( item.content < cells->cellAt( i )->id() )
1901  break;
1902  if (i == count) i--;
1903  cell = cells->cellAt( i );
1904  assert( cell != NULL );
1905  //Drop through to get cell handled.
1906  }
1907  if (select) {
1908  picker->selectCell( cell, true );
1909  //This may not be a selectable cell.
1910  return picker->selectedCell() != NULL;
1911  } else {
1912  //Make sure we scroll it into view.
1913  //Since it's not selected, we assume it's in the "other" list and scroll
1914  //it into the middle.
1915  picker->scrollToCell( cell, true );
1916  return false;
1917  }
1918  //Shouldn't ever get here.
1919  assert( false );
1920  return false;
1921 }
void BaseComputer::secondStageJoinGame ( void  )
Cargo * BaseComputer::selectedItem ( void  )
protected

Definition at line 2745 of file basecomputer.cpp.

References m_selectedList, BaseComputer::TransactionList::masterList, BaseComputer::TransactionList::picker, Picker::selectedCell(), and PickerCell::tag().

Referenced by acceptMission(), buySelectedCargo(), buyShip(), buyUpgrade(), BaseComputer::UpgradeOperation::commonInit(), fixUpgrade(), sellSelectedCargo(), sellShip(), and sellUpgrade().

2746 {
2747  Cargo *result = NULL;
2748  if (m_selectedList) {
2749  assert( m_selectedList->picker );
2751  if (cell)
2752  result = &m_selectedList->masterList[cell->tag()].cargo;
2753  }
2754  return result;
2755 }
bool BaseComputer::sell10Cargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2910 of file basecomputer.cpp.

References sellSelectedCargo().

2911 {
2912  return sellSelectedCargo( 10 );
2913 }
bool BaseComputer::sellAllCargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2916 of file basecomputer.cpp.

References sellSelectedCargo().

2917 {
2918  return sellSelectedCargo( -1 );
2919 }
bool BaseComputer::sellCargo ( const EventCommandId command,
Control control 
)
protected

Definition at line 2904 of file basecomputer.cpp.

References sellSelectedCargo().

2905 {
2906  return sellSelectedCargo( 1 );
2907 }
bool BaseComputer::sellSelectedCargo ( int  requestedQuantity)
protected

Definition at line 2875 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), UnitImages< BOGUS >::cargo, Cargo::content, Cockpit::credits, eliminateZeroCargo(), UnitContainer::GetUnit(), m_base, m_player, Cargo::mission, Unit::pImage, Cargo::quantity, refresh(), Unit::RemoveCargo(), selectedItem(), and Unit::SellCargo().

Referenced by sell10Cargo(), sellAllCargo(), and sellCargo().

2876 {
2877  Unit *playerUnit = m_player.GetUnit();
2878  Unit *baseUnit = m_base.GetUnit();
2879  if ( !(playerUnit && baseUnit) )
2880  return true;
2881  Cargo *item = selectedItem();
2882  if (item) {
2883  Cargo itemCopy = *item; //Not sure what "sold" has in it. Need copy of sold item.
2884  Cargo sold;
2885  const int quantity = (requestedQuantity <= 0 ? item->quantity : requestedQuantity);
2886  if (item->mission) {
2887  vector< Cargo >::iterator mycargo = std::find( playerUnit->pImage->cargo.begin(),
2888  playerUnit->pImage->cargo.end(), *item );
2889  if ( mycargo != playerUnit->pImage->cargo.end() )
2890  playerUnit->RemoveCargo( mycargo-playerUnit->pImage->cargo.begin(), quantity, true );
2891  } else {
2892  playerUnit->SellCargo( item->content, quantity, _Universe->AccessCockpit()->credits, sold, baseUnit );
2893  }
2894  eliminateZeroCargo( playerUnit );
2895  //Reload the UI -- inventory has changed. Because we reload the UI, we need to
2896  //find, select, and scroll to the thing we bought. The item might be gone from the
2897  //list (along with some categories) after the transaction.
2898  refresh(); //This will reload master lists.
2899  }
2900  return true;
2901 }
bool BaseComputer::sellShip ( const EventCommandId command,
Control control 
)
protected

Definition at line 4480 of file basecomputer.cpp.

References _Universe, Cargo::content, UnitContainer::GetUnit(), Universe::isPlayerStarship(), m_base, m_player, selectedItem(), and sellShip().

4481 {
4482  Unit *playerUnit = m_player.GetUnit();
4483  Unit *baseUnit = m_base.GetUnit();
4484  Cargo *item = selectedItem();
4485  Cockpit *cockpit = _Universe->isPlayerStarship( playerUnit );
4486  if ( !(playerUnit && baseUnit && item && cockpit) )
4487  return true;
4488  return ::sellShip( baseUnit, playerUnit, item->content, this );
4489 }
bool BaseComputer::sellUpgrade ( const EventCommandId command,
Control control 
)
protected

Definition at line 3988 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), Cargo::category, Cargo::content, Cockpit::credits, UnitContainer::GetUnit(), isWeapon(), m_base, m_player, UnitUtil::RecomputeUnitUpgrades(), refresh(), selectedItem(), Unit::SellCargo(), SellUpgradeOperation, and BaseComputer::SellUpgradeOperation::start().

3989 {
3990  Cargo *item = selectedItem();
3991  if (item) {
3992  if ( !isWeapon( item->category ) ) {
3993  Cargo sold;
3994  const int quantity = 1;
3995  Unit *playerUnit = m_player.GetUnit();
3996  Unit *baseUnit = m_base.GetUnit();
3997  if (baseUnit && playerUnit) {
3998  playerUnit->SellCargo( item->content, quantity, _Universe->AccessCockpit()->credits, sold, baseUnit );
3999  UnitUtil::RecomputeUnitUpgrades( playerUnit );
4000  refresh();
4001  }
4002  return true;
4003  }
4004  }
4005  //This complicated operation is done in a separate object.
4006  SellUpgradeOperation *op = new SellUpgradeOperation( *this );
4007  op->start();
4008 
4009  return true;
4010 }
void BaseComputer::showNetworkStatus ( bool  show = true)
protected

Definition at line 1705 of file basecomputer.cpp.

References Window::findControlById(), Control::setHidden(), and WindowController::window().

Referenced by changeToNetworkMode(), and hideNetworkStatus().

1706 {
1707  Control *group = window()->findControlById( "NetworkJoinGroup" );
1708  if (group) group->setHidden( show );
1709  group = window()->findControlById( "NetworkStatGroup" );
1710  if (group) group->setHidden( !show );
1711 }
bool BaseComputer::showPlayerInfo ( const EventCommandId command,
Control control 
)
protected

Definition at line 4676 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), colorsToCommandString(), factionColorTextString(), Window::findControlById(), UniverseUtil::getCurrentPlayer(), FactionUtil::GetFactionIndex(), FactionUtil::GetFactionName(), SaveGame::getMissionData(), FactionUtil::GetNeutralFaction(), FactionUtil::GetNumFactions(), FactionUtil::GetPlanetFaction(), UniverseUtil::getPlayerX(), UnitUtil::getRelationFromFaction(), FactionUtil::GetUpgradeFaction(), VegaConfig::getVariable(), guiMax, guiMin, i, int, Cockpit::savegame, StaticDisplay::setText(), size, XMLSupport::tostring(), vs_config, and WindowController::window().

4677 {
4678  //Heading.
4679  string text = "#b#Factions:#-b#n1.7#";
4680 
4681  //Number of kills for each faction.
4682  vector< float > *killList = &_Universe->AccessCockpit()->savegame->getMissionData( string( "kills" ) );
4683 
4684  //Make everything bold.
4685  text += "#b#";
4686 
4687  //A line for each faction.
4688  const size_t numFactions = FactionUtil::GetNumFactions();
4689  size_t i = 0;
4690  static string disallowedFactions = vs_config->getVariable( "graphics", "unprintable_factions", "" );
4691  int totkills = 0;
4692  size_t fac_loc_before = 0, fac_loc = 0, fac_loc_after = 0;
4693  for (; i < numFactions; i++) {
4695  float relation = 0;
4696  size_t upgrades = FactionUtil::GetUpgradeFaction();
4697  size_t planets = FactionUtil::GetPlanetFaction();
4698  static size_t privateer = FactionUtil::GetFactionIndex( "privateer" );
4699  size_t neutral = FactionUtil::GetNeutralFaction();
4700  if (i < killList->size() && i != upgrades && i != planets && i != neutral && i != privateer)
4701  totkills += (int) (*killList)[i];
4702  string factionname = FactionUtil::GetFactionName( i );
4703  fac_loc_after = 0;
4704  fac_loc = disallowedFactions.find( factionname, fac_loc_after );
4705  while (fac_loc != string::npos) {
4706  fac_loc_before = fac_loc-1;
4707  if (fac_loc_before < 0)
4708  fac_loc_before = 0;
4709  fac_loc_after = fac_loc+factionname.size();
4710  if ( (fac_loc == 0 || disallowedFactions[fac_loc_before] == ' '
4711  || disallowedFactions[fac_loc_before] == '\t')
4712  && (disallowedFactions[fac_loc_after] == ' ' || disallowedFactions[fac_loc_after] == '\t'
4713  || disallowedFactions[fac_loc_after] == '\0') )
4714  break;
4715  fac_loc = disallowedFactions.find( factionname, fac_loc_after );
4716  }
4717  if (fac_loc != string::npos)
4718  continue;
4719  if (currentplayer)
4720  relation = UnitUtil::getRelationFromFaction( currentplayer, i );
4721  if (relation < -1) relation = -1;
4722  if (relation > 1) relation = 1;
4723  const int percent = (int) (relation*100.0);
4724 
4725  //Faction name.
4726  text += factionColorTextString( i )+FactionUtil::GetFactionName( i )+":#-c ";
4727 
4728  //Relation color.
4729  float normRelation = (relation+1)/2; //Move relation value into 0-1 range.
4730  normRelation = guiMax( 0, guiMin( 1, normRelation ) ); //Make *sure* it's in the right range.
4731  text += colorsToCommandString( 1-normRelation, normRelation, guiMin( 1-normRelation, normRelation ) );
4732 
4733  //End the line.
4734  text += XMLSupport::tostring( percent )+"#-c";
4735  if ( i < killList->size() )
4736  text += ", kills: "+XMLSupport::tostring( (int) (*killList)[i] );
4737  text += "#n#";
4738  }
4739  //Total Kills if we have it.
4740  text += "#n##b#Total Kills: "+XMLSupport::tostring( totkills )+"#-b#";
4741  //Put this in the description.
4742  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
4743  assert( desc != NULL );
4744  desc->setText( text );
4745 
4746  return true;
4747 }
bool BaseComputer::showShipStats ( const EventCommandId command,
Control control 
)
protected

Definition at line 5883 of file basecomputer.cpp.

References current_unit_load_mode, DEFAULT, Window::findControlById(), UnitContainer::GetUnit(), VegaConfig::getVariable(), i, m_player, MakeUnitXMLPretty(), NO_MESH, XMLSupport::parse_bool(), StaticDisplay::setText(), showUnitStats(), vs_config, WindowController::window(), and Unit::WriteUnitString().

5884 {
5886  Unit *playerUnit = m_player.GetUnit();
5888  const string rawText = MakeUnitXMLPretty( playerUnit->WriteUnitString(), playerUnit );
5889 
5890  //Need to translate some characters to make it even prettier.
5891  string text;
5892  text = "";
5893  Cargo uninitcargo;
5894  showUnitStats( playerUnit, text, 0, 0, uninitcargo );
5895  //remove picture, if any
5896  string::size_type pic;
5897  if ( ( pic = text.find( "@" ) ) != string::npos ) {
5898  std::string texture = text.substr( pic+1 );
5899  text = text.substr( 0, pic );
5900  string::size_type picend = texture.find( "@" );
5901  if (picend != string::npos)
5902  text += texture.substr( picend+1 );
5903  } //picture removed
5904  text.append( "#n##n##c0:1:.5#[RAW DIAGNOSTIC OUTPUT]#n##-c" );
5905  bool inQuote = false;
5906  bool newLine = false;
5907  static bool showdiags = XMLSupport::parse_bool( vs_config->getVariable( "debug", "showdiagnostics", "false" ) );
5908  if (showdiags) {
5909  for (string::const_iterator i = rawText.begin(); i != rawText.end(); i++) {
5910  switch (*i)
5911  {
5912  case '\n':
5913  text.append( "#n#" );
5914  if (!newLine) {
5915  text.append( "#c0:1:.5#" );
5916  newLine = true;
5917  }
5918  break;
5919  case '"':
5920  if (!inQuote) {
5921  text.append( "#c1:.3:.3#" );
5922  inQuote = true;
5923  } else {
5924  text.append( "#-c" );
5925  inQuote = false;
5926  }
5927  //Delete these, so do nothing.
5928  break;
5929  case ' ':
5930  if (newLine) {
5931  newLine = false;
5932  text.append( "#-c" );
5933  }
5934  text += (*i);
5935  break;
5936  default:
5937  text += (*i);
5938  break;
5939  }
5940  }
5941  } else {
5942  text.append( "#n# #c1:.1:.1#SUPPRESSED #n##-c" );
5943  //Put this in the description.
5944  }
5945  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
5946  assert( desc != NULL );
5947  desc->setText( text );
5948 
5949  return true;
5950 }
void BaseComputer::switchToControls ( DisplayMode  mode)
protected

Definition at line 1646 of file basecomputer.cpp.

References Window::addControl(), CARGO, Window::findControlById(), INFO, LOADSAVE, m_currentDisplay, m_modeGroups, m_playingMuzak, MISSIONS, muzak, NETWORK, NEWS, NULL_DISPLAY, Window::removeControlFromWindow(), Window::setTexture(), SHIP_DEALER, Music::Skip(), UPGRADE, and WindowController::window().

Referenced by changeToCargoMode(), changeToInfoMode(), changeToLoadSaveMode(), changeToMissionsMode(), changeToNetworkMode(), changeToNewsMode(), changeToShipDealerMode(), and changeToUpgradeMode().

1647 {
1648  if (m_currentDisplay != mode) {
1649  assert( m_modeGroups[mode] != NULL ); //We should have controls for this mode.
1650  if (mode == CARGO)
1651  window()->setTexture( "basecomputer_cargo.png" );
1652  if (mode == MISSIONS)
1653  window()->setTexture( "basecomputer_missions.png" );
1654  if (mode == UPGRADE)
1655  window()->setTexture( "basecomputer_upgrade.png" );
1656  if (mode == SHIP_DEALER)
1657  window()->setTexture( "basecomputer_ship_dealer.png" );
1658  if (mode == NEWS)
1659  window()->setTexture( "basecomputer_news.png" );
1660  if (mode == INFO)
1661  window()->setTexture( "basecomputer_info.png" );
1662  if (mode == LOADSAVE)
1663  window()->setTexture( "basecomputer_loadsave.png" );
1664  if (mode == NETWORK)
1665  window()->setTexture( "basecomputer_network.png" );
1666  if (m_currentDisplay != NULL_DISPLAY) {
1667  //Get the old controls out of the window.
1668  Control *oldControls = window()->findControlById( modeInfo[m_currentDisplay].groupId );
1669  if (oldControls)
1670  window()->removeControlFromWindow( oldControls );
1671  //We put this back in our table so that we "own" the controls.
1672  m_modeGroups[m_currentDisplay] = oldControls;
1673  //Stop playing muzak for the old mode.
1674  if (m_playingMuzak) {
1675  muzak->Skip();
1676  m_playingMuzak = false;
1677  }
1678  }
1679  m_currentDisplay = mode;
1680 
1681  window()->addControl( m_modeGroups[mode] );
1682  //Take this group out of our table because we don't own it anymore.
1683  m_modeGroups[mode] = NULL;
1684  }
1685 }
void BaseComputer::updateTransactionControls ( const Cargo item,
bool  skipFirstCategory = false 
)

Definition at line 2758 of file basecomputer.cpp.

References m_selectedList, m_transList1, m_transList2, BaseComputer::TransactionList::picker, scrollToItem(), and updateTransactionControlsForSelection().

2759 {
2760  //Go reselect the item.
2761  if (m_selectedList == NULL)
2762  return;
2763  const bool success = scrollToItem( m_selectedList->picker, item, true, skipFirstCategory );
2764  //And scroll to that item in the other picker, too.
2765  TransactionList &otherList = ( (&m_transList1 == m_selectedList) ? m_transList2 : m_transList1 );
2766  if (otherList.picker)
2767  //Scroll to the item in the other list, but don't select it.
2768  scrollToItem( otherList.picker, item, false, skipFirstCategory );
2769  if (success)
2770  //We selected the item successfully.
2772  else
2773  //Didn't find item. Clear the selection.
2775 }
void BaseComputer::updateTransactionControlsForSelection ( TransactionList list)

Definition at line 2105 of file basecomputer.cpp.

References _Universe, ACCEPT_MISSION, Universe::AccessCockpit(), BASIC_REPAIR_NAME, basicRepairPrice(), buildCargoDescription(), buildShipDescription(), buildUpgradeDescription(), BUY_CARGO, BUY_SHIP, BUY_UPGRADE, Cargo::category, configureCargoCommitControls(), configureUpgradeCommitControls(), Cargo::content, Cockpit::credits, Cargo::description, Window::findControlById(), Cargo::GetCategory(), Cargo::GetContent(), Cargo::GetDescription(), UnitContainer::GetUnit(), VegaConfig::getVariable(), hideCommitControls(), isTransactionOK(), m_base, m_player, m_selectedList, m_transList1, m_transList2, Cargo::mass, BaseComputer::TransactionList::masterList, Cargo::mission, XMLSupport::parse_bool(), UnitUtil::PercentOperational(), BaseComputer::TransactionList::picker, UniverseUtil::playSound(), PRETTY_ADDN, Cargo::price, Unit::PriceCargo(), QVector, Unit::RepairCost(), RepairPrice(), Picker::selectCell(), Picker::selectedCell(), SELL_CARGO, SELL_UPGRADE, SellPrice(), NewButton::setCommand(), Control::setHidden(), NewButton::setLabel(), StaticDisplay::setText(), StaticImageDisplay::setTexture(), UniverseUtil::StopAllSounds(), PickerCell::tag(), BaseComputer::TransactionList::transaction, usedValue(), Vector, Cargo::volume, vs_config, and WindowController::window().

Referenced by acceptMission(), changeToCargoMode(), changeToMissionsMode(), changeToShipDealerMode(), changeToUpgradeMode(), pickerChangedSelection(), sellShip(), and updateTransactionControls().

2106 {
2107  //Get the controls we need.
2108  NewButton *commitButton = static_cast< NewButton* > ( window()->findControlById( "Commit" ) );
2109  assert( commitButton != NULL );
2110  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
2111  std::string descriptiontexture;
2112  assert( desc != NULL );
2113  if (!tlist) {
2114  //We have no selection. Turn off UI that commits a transaction.
2115  m_selectedList = NULL;
2117  desc->setText( "" );
2118  //Make sure there is no selection.
2121  return;
2122  }
2123  //We have a selection of some sort.
2124 
2125  //Set the button state.
2126  m_selectedList = tlist;
2127 
2128  //Clear selection from other list.
2129  TransactionList &otherList = ( (&m_transList1 == m_selectedList) ? m_transList2 : m_transList1 );
2130  if (otherList.picker) otherList.picker->selectCell( NULL );
2131  //They selected a cell that has a description.
2132  //The selected item.
2133  const PickerCell *cell = tlist->picker->selectedCell();
2134  assert( cell != NULL );
2135  Cargo &item = tlist->masterList[cell->tag()].cargo;
2136  bool damaged_mode = false;
2137  if ( !isTransactionOK( item, tlist->transaction ) ) {
2138  //We can't do the transaction. so hide the transaction button.
2139  //This is an odd state. We have a selection, but no transaction is possible.
2141  } else {
2142  //We can do the transaction.
2143  commitButton->setHidden( false );
2144  switch (tlist->transaction)
2145  {
2146  case BUY_CARGO:
2148  break;
2149  case BUY_UPGRADE:
2151  break;
2152  case BUY_SHIP:
2153  commitButton->setLabel( "Buy" );
2154  commitButton->setCommand( "BuyShip" );
2155  if (item.GetCategory().find( "My_Fleet" ) != string::npos) {
2156  //note can only sell it if you can afford to ship it over here.
2157  NewButton *commit10Button = static_cast< NewButton* > ( window()->findControlById( "Commit10" ) );
2158  assert( commit10Button != NULL );
2159  commit10Button->setHidden( false );
2160  commit10Button->setLabel( "Sell" );
2161  commit10Button->setCommand( "SellShip" );
2162  }
2163  break;
2164  case SELL_CARGO:
2166  break;
2167  case SELL_UPGRADE:
2168  damaged_mode = configureUpgradeCommitControls( item, SELL_UPGRADE );
2169  break;
2170  case ACCEPT_MISSION:
2171  if (item.GetCategory().find( "Active_Missions" ) != string::npos) {
2172  commitButton->setLabel( "Abort" );
2173  static bool allow_abort_mission =
2174  XMLSupport::parse_bool( vs_config->getVariable( "physics", "allow_mission_abort", "true" ) );
2175  if (allow_abort_mission == false)
2176  commitButton->setHidden( true );
2177  } else {
2178  commitButton->setLabel( "Accept" );
2179  }
2180  commitButton->setCommand( "AcceptMission" );
2181  break;
2182  default:
2183  assert( false ); //Missed enum in transaction.
2184  break;
2185  }
2186  }
2187  //The description string.
2188  char conversionBuffer[128];
2189  string text = "";
2190  string descString;
2191  string tailString;
2192  char tempString[2048];
2193  Unit *baseUnit = m_base.GetUnit();
2194  if (tlist->transaction != ACCEPT_MISSION) {
2195  //Do the money.
2196  switch (tlist->transaction)
2197  {
2198  case BUY_CARGO:
2199  if (item.GetDescription() == "" || item.GetDescription()[0] != '@') {
2200  buildShipDescription( item, descriptiontexture ); //Check for ship
2201  string temp = item.description; //do first, so can override default image, if so desired
2202  if ( ( string::npos != temp.find( '@' ) ) && ("" != descriptiontexture) ) //not already pic-annotated, has non-null ship pic
2203  temp = "@"+descriptiontexture+"@"+temp;
2204  item.description = temp;
2205  }
2206  if (item.GetCategory().find( "My_Fleet" ) != string::npos) {
2207  //This ship is in my fleet -- the price is just the transport cost to get it to
2208  //the current base. "Buying" this ship makes it my current ship.
2209  sprintf( tempString, "#b#Transport cost: %.2f#-b#n1.5#", item.price );
2210  } else {
2211  sprintf( tempString, "Price: #b#%.2f#-b#n#", baseUnit->PriceCargo( item.content ) );
2212  descString += tempString;
2213  sprintf( tempString, "Cargo volume: %.2f cubic meters; Mass: %.2f metric tons#n1.5#", item.volume, item.mass );
2214  }
2215  descString += tempString;
2216  tailString = buildCargoDescription( item, *this, item.price );
2217  break;
2218  case BUY_UPGRADE:
2219  if (item.content == BASIC_REPAIR_NAME) {
2220  //Basic repair is implemented entirely in this module.
2221  //PriceCargo() doesn't know about it.
2222  Unit *playerUnit = m_player.GetUnit();
2223  int multiplier = 1;
2224  if (playerUnit)
2225  multiplier = playerUnit->RepairCost();
2226  sprintf( tempString, "Price: #b#%.2f#-b#n1.5#", basicRepairPrice()*multiplier );
2227  } else {
2228  sprintf( tempString, "Price: #b#%.2f#-b#n1.5#", baseUnit->PriceCargo( item.content ) );
2229  }
2230  descString += tempString;
2231  if (item.GetDescription() == "" || item.GetDescription()[0] != '#')
2232  item.description = buildUpgradeDescription( item );
2233  break;
2234  case BUY_SHIP:
2235  if (item.GetCategory().find( "My_Fleet" ) == string::npos) {
2237  if (item.price < _Universe->AccessCockpit()->credits) {
2238  std::string tmp = item.GetContent().substr( 0, item.GetContent().find( "." ) );
2239  UniverseUtil::playSound( "sales/salespitch"+tmp+".wav", QVector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2240  } else {
2241  UniverseUtil::playSound( "sales/salespitchnotenoughmoney.wav", QVector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2242  }
2243  }
2244  if (item.description == "" || item.GetDescription()[0] != '@')
2245  item.description = buildShipDescription( item, descriptiontexture );
2246  if (item.GetCategory().find( "My_Fleet" ) != string::npos) {
2247  //This ship is in my fleet -- the price is just the transport cost to get it to
2248  //the current base. "Buying" this ship makes it my current ship.
2249  sprintf( tempString, "#b#Transport cost: %.2f#-b#n1.5#", item.price );
2250  } else {
2251  PRETTY_ADDN("", baseUnit->PriceCargo(item.content), 2);
2252  sprintf( tempString, "Price: #b#%s#-b#n#", text.c_str() );
2253  static bool printvolume =
2254  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_print_cargo_volume", "true" ) );
2255  if (printvolume) {
2256  descString += tempString;
2257  sprintf( tempString, "Vessel volume: %.2f cubic meters; Mass: %.2f metric tons#n1.5#", item.volume, item.mass );
2258  }
2259  }
2260  descString += tempString;
2261  break;
2262  case SELL_CARGO:
2263  if (item.GetDescription() == "" || item.GetDescription()[0] != '@') {
2264  buildShipDescription( item, descriptiontexture ); //Check for ship
2265  string temp = item.description; //do first, so can override default image, if so desired
2266  if ( ( string::npos != temp.find( '@' ) ) && ("" != descriptiontexture) ) //not already pic-annotated, has non-null ship pic
2267  temp = "@"+descriptiontexture+"@"+item.description;
2268  item.description = temp;
2269  }
2270  if (item.mission)
2271  sprintf( tempString, "Destroy evidence of mission cargo. Credit received: 0.00." );
2272  else
2273  sprintf( tempString, "Value: #b#%.2f#-b, purchased for %.2f#n#",
2274  baseUnit->PriceCargo( item.content ), item.price );
2275  descString += tempString;
2276  sprintf( tempString, "Cargo volume: %.2f cubic meters; Mass: %.2f metric tons#n1.5#", item.volume, item.mass );
2277  descString += tempString;
2278  if (!item.mission)
2279  tailString = buildCargoDescription( item, *this, baseUnit->PriceCargo( item.content ) );
2280  break;
2281  case SELL_UPGRADE:
2282 
2283  //********************************************************************************************
2284  {
2285  double percent_working = m_player.GetUnit() ? UnitUtil::PercentOperational(
2286  m_player.GetUnit(), item.content, item.category, false ) : 0.0;
2287  if (percent_working < 1) {
2288  //IF DAMAGED
2289  sprintf( tempString, "Damaged and Used value: #b#%.2f#-b, purchased for %.2f#n1.5#",
2290  SellPrice( percent_working, baseUnit->PriceCargo( item.content ) ), item.price );
2291  descString += tempString;
2292 
2293  sprintf( tempString, "Percent Working: #b#%.2f#-b, Repair Cost: %.2f#n1.5#",
2294  percent_working*100, RepairPrice( percent_working, baseUnit->PriceCargo( item.content ) ) );
2295  descString += tempString;
2296  } else {
2297  sprintf( tempString, "Used value: #b#%.2f#-b, purchased for %.2f#n1.5#",
2298  usedValue( baseUnit->PriceCargo( item.content ) ), item.price );
2299  descString += tempString;
2300  }
2301  if (damaged_mode)
2302  descString +=
2303  "#c1:0:0#Warning: #b#Because pieces of your ship are damaged, you will not be able to sell this item until you fix those damaged items in this column in order to allow the mechanics to remove this item.#-c#-b#n1.5#";
2304  //********************************************************************************************
2305  if (item.GetDescription() == "" || item.GetDescription()[0] != '#')
2306  item.description = buildUpgradeDescription( item );
2307  break;
2308  }
2309  default:
2310  assert( false ); //Missed transaction enum in switch statement.
2311  break;
2312  }
2313  }
2314  //Description.
2315  descString += item.description;
2316  descString += tailString;
2317 
2318  //Change the description control.
2319  string::size_type pic;
2320  StaticImageDisplay *descimage = static_cast< StaticImageDisplay* > ( window()->findControlById( "DescriptionImage" ) );
2321  if ( ( pic = descString.find( "@" ) ) != string::npos ) {
2322  std::string texture = descString.substr( pic+1 );
2323  descString = descString.substr( 0, pic );
2324  string::size_type picend = texture.find( "@" );
2325  if (picend != string::npos) {
2326  descString += texture.substr( picend+1 );
2327  texture = texture.substr( 0, picend );
2328  }
2329  if (descimage)
2330  descimage->setTexture( texture );
2331  } else {
2332  if (descimage && descriptiontexture == "")
2333  descimage->setTexture( "blackclear.png" );
2334  else if (descimage)
2335  descimage->setTexture( descriptiontexture );
2336  }
2337  {
2338  pic = descString.find( "<" );
2339  if (pic != string::npos) {
2340  std::string tmp = descString.substr( pic+1 );
2341  descString = descString.substr( 0, pic );
2342  if ( ( pic = tmp.find( ">" ) ) != string::npos )
2343  descString += tmp.substr( pic+1 );
2344  }
2345  }
2346  desc->setText( descString );
2347 }

Friends And Related Function Documentation

friend class BuyUpgradeOperation
friend

Definition at line 316 of file basecomputer.h.

Referenced by buyUpgrade().

friend class LoadSaveQuitConfirm
friend

Definition at line 122 of file basecomputer.h.

Referenced by actionLoadGame(), actionQuitGame(), and actionSaveGame().

friend class SellUpgradeOperation
friend

Definition at line 317 of file basecomputer.h.

Referenced by sellUpgrade().

friend class UpgradeOperation
friend

Definition at line 313 of file basecomputer.h.

friend class WctlBase< BaseComputer >
friend

Definition at line 41 of file basecomputer.h.

Member Data Documentation

int BaseComputer::dirty = 0
static

Definition at line 44 of file basecomputer.h.

Referenced by base_main_loop(), draw(), and BaseUtil::refreshBaseComputerUI().

vector< DisplayMode > BaseComputer::m_displayModes
protected

Definition at line 297 of file basecomputer.h.

Referenced by constructControls(), createModeButtons(), and run().

Control* BaseComputer::m_modeGroups[DISPLAY_MODE_COUNT]
protected

Definition at line 307 of file basecomputer.h.

Referenced by BaseComputer(), createControls(), switchToControls(), and ~BaseComputer().

bool BaseComputer::m_playingMuzak
protected

Definition at line 308 of file basecomputer.h.

Referenced by newsPickerChangedSelection(), switchToControls(), and ~BaseComputer().

TransactionList* BaseComputer::m_selectedList
protected

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