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

#include <base.h>

Classes

class  Room
 

Public Member Functions

void Terminate ()
 
void GotoLink (int linknum)
 
void InitCallbacks ()
 
void CallCommonLinks (const std::string &name, const std::string &value)
 
void Load (const char *filename, const char *time_of_day, const char *faction)
 
void Click (int x, int y, int button, int state)
 
void Key (unsigned int ch, unsigned int mod, bool release, int x, int y)
 
void MouseOver (int x, int y)
 
 BaseInterface (const char *basefile, Unit *base, Unit *un)
 
 ~BaseInterface ()
 
void Draw ()
 
void setDJEnabled (bool enabled)
 
bool isDJEnabled () const
 

Static Public Member Functions

static void ClickWin (int x, int y, int button, int state)
 
static void PassiveMouseOverWin (int x, int y)
 
static void ActiveMouseOverWin (int x, int y)
 
static void ProcessKeyboardBuffer ()
 

Public Attributes

int curroom
 
std::vector< Room * > rooms
 
TextPlane othtext
 
bool CallComp
 
UnitContainer caller
 
UnitContainer baseun
 
std::string python_kbhandler
 

Static Public Attributes

static BaseInterfaceCurrentBase = NULL
 

Friends

class Room
 
class Room::BaseTalk
 

Detailed Description

Definition at line 21 of file base.h.

Constructor & Destructor Documentation

BaseInterface::BaseInterface ( const char *  basefile,
Unit base,
Unit un 
)

Definition at line 1084 of file base_interface.cpp.

References AUDHighestSoundPlaying(), BASE_EXTENSION, baseun, CallComp, caller, BaseUtil::Comp(), compute_time_of_day(), createdbase, createdmusic, CurrentBase, curroom, ExecuteDirector(), Unit::faction, TextPlane::GetCharSize(), FactionUtil::GetFaction(), UniverseUtil::GetGalaxyFaction(), UnitUtil::getUnitSystemFile(), GotoLink(), i, UnitUtil::isPlayerStarship(), BaseUtil::Launch(), Load(), mission_key, Unit::name, othtext, QVector, Room, rooms, saveStringList(), TextPlane::SetCharSize(), TextPlane::SetSize(), VSFileSystem::vs_fprintf(), x, and y.

1084  :
1085  curtext( getConfigColor( "Base_Text_Color_Foreground",
1086  GFXColor( 0, 1, 0, 1 ) ), getConfigColor( "Base_Text_Color_Background", GFXColor( 0, 0, 0, 1 ) ) )
1087  , othtext( getConfigColor( "Fixer_Text_Color_Foreground",
1088  GFXColor( 1, 1, .5, 1 ) ), getConfigColor( "FixerTextColor_Background", GFXColor( 0, 0, 0, 1 ) ) )
1089 {
1090  CurrentBase = this;
1091  CallComp = false;
1092  lastmouseindex = 0;
1093  enabledj = true;
1094  createdbase = true;
1095  midloop = false;
1096  terminate_scheduled = false;
1097  createdmusic = -1;
1098  caller = un;
1099  curroom = 0;
1100  curlinkindex = 0;
1101  this->baseun = base;
1102  float x, y;
1103  curtext.GetCharSize( x, y );
1104  curtext.SetCharSize( x*2, y*2 );
1105  curtext.SetSize( 1-.01, -2 );
1106  othtext.GetCharSize( x, y );
1107  othtext.SetCharSize( x*2, y*2 );
1108  othtext.SetSize( 1-.01, -.75 );
1109 
1110  std::string fac = base ? FactionUtil::GetFaction( base->faction ) : "neutral";
1111  if (base && fac == "neutral")
1113  Load( basefile, compute_time_of_day( base, un ), fac.c_str() );
1115  if (base && un) {
1116  vector< string >vec;
1117  vec.push_back( base->name );
1118  int cpt = UnitUtil::isPlayerStarship( un );
1119  if (cpt >= 0)
1120  saveStringList( cpt, mission_key, vec );
1121  }
1122  if ( !rooms.size() ) {
1123  VSFileSystem::vs_fprintf( stderr,
1124  "ERROR: there are no rooms in basefile \"%s%s%s\" ...\n",
1125  basefile,
1126  compute_time_of_day( base, un ),
1127  BASE_EXTENSION );
1128  rooms.push_back( new Room() );
1129  rooms.back()->deftext = "ERROR: No rooms specified...";
1130 #ifndef BASE_MAKER
1131  rooms.back()->objs.push_back( new Room::BaseShip( -1, 0, 0, 0, 0, -1, 0, 1, 0, QVector( 0, 0, 2 ), "default room" ) );
1132  BaseUtil::Launch( 0, "default room", -1, -1, 1, 2, "ERROR: No rooms specified... - Launch" );
1133  BaseUtil::Comp( 0, "default room", 0, -1, 1, 2, "ERROR: No rooms specified... - Computer",
1134  "Cargo Upgrade Info ShipDealer News Missions" );
1135 #endif
1136  }
1137  GotoLink( 0 );
1138  {
1139  for (unsigned int i = 0; i < 16; ++i)
1140  ExecuteDirector();
1141  }
1142 }
BaseInterface::~BaseInterface ( )

Definition at line 952 of file base_interface.cpp.

References BASE_EXTENSION, CurrentBase, i, restore_main_loop(), rooms, VSFileSystem::vs_close(), and VSFileSystem::vs_open().

953 {
954 #ifdef BASE_MAKER
955  FILE *fp = VSFileSystem::vs_open( "bases/NEW_BASE" BASE_EXTENSION, "wt" );
956  if (fp) {
957  EndXML( fp );
959  }
960 #endif
961  CurrentBase = 0;
963  for (size_t i = 0; i < rooms.size(); i++)
964  delete rooms[i];
965 }

Member Function Documentation

void BaseInterface::ActiveMouseOverWin ( int  x,
int  y 
)
static

Definition at line 892 of file base_interface.cpp.

References CallComp, CurrentBase, ModifyMouseSensitivity(), NavigationSystem::mouseDrag(), MouseOver(), and SetSoftwareMousePosition().

Referenced by InitCallbacks(), and GameCockpit::NavScreen().

893 {
896  if (CurrentBase) {
897  if (CurrentBase->CallComp) {
898 #ifdef NEW_GUI
899  EventManager::
900 #else
901  UpgradingInfo::
902 #endif
903  ProcessMouseActive( x, y );
904  } else {
905  CurrentBase->MouseOver( x, y );
906  }
907  } else {
909  }
910 }
void BaseInterface::CallCommonLinks ( const std::string &  name,
const std::string &  value 
)
void BaseInterface::Click ( int  x,
int  y,
int  button,
int  state 
)

Definition at line 841 of file base_interface.cpp.

References CalculateRealXAndY(), curroom, rooms, x, and y.

Referenced by ClickWin().

842 {
843  float x, y;
844  CalculateRealXAndY( xint, yint, &x, &y );
845  rooms[curroom]->Click( this, x, y, button, state );
846 }
void BaseInterface::ClickWin ( int  x,
int  y,
int  button,
int  state 
)
static

Definition at line 848 of file base_interface.cpp.

References CallComp, Click(), CurrentBase, getMouseButtonMask(), ModifyMouseSensitivity(), NavigationSystem::mouseClick(), WS_MOUSE_DOWN, and WS_MOUSE_UP.

Referenced by InitCallbacks(), and GameCockpit::NavScreen().

849 {
851  if (state == WS_MOUSE_DOWN)
852  getMouseButtonMask() |= ( 1<<(button-1) );
853 
854  else if (state == WS_MOUSE_UP)
855  getMouseButtonMask() &= ~( 1<<(button-1) );
856  if (CurrentBase) {
857  if (CurrentBase->CallComp) {
858 #ifdef NEW_GUI
859  EventManager::
860 #else
861  UpgradingInfo::
862 #endif
863  ProcessMouseClick( button, state, x, y );
864  } else {
865  CurrentBase->Click( x, y, button, state );
866  }
867  } else {
868  NavigationSystem::mouseClick( button, state, x, y );
869  }
870 }
void BaseInterface::Draw ( )

Definition at line 1429 of file base_interface.cpp.

References GFXColor::a, MessageCenter::add(), AnimationDraw(), baseun, TextPlane::bgcol, caller, curroom, UnitImages< BOGUS >::dockedunits, TextPlane::Draw(), EndGUIFrame(), Unit::FreeDockingPort(), g_game, GetElapsedTime(), Singleton< SceneManager >::getSingleton(), TextPlane::GetText(), UnitContainer::GetUnit(), VegaConfig::getVariable(), GFXTRUE, BaseInterface::Room::BaseTalk::hastalked, i, mission, Mission::msgcenter, othtext, XMLSupport::parse_float(), Unit::pImage, rooms, TextPlane::SetPos(), SetupViewport(), game_data_t::sound_enabled, StartGUIFrame(), Terminate(), AnimatedTexture::UpdateAllFrame(), vs_config, VSFileSystem::vs_fprintf(), x, game_data_t::x_resolution, y, and game_data_t::y_resolution.

Referenced by RefreshGUI().

1430 {
1431  // Some operations cannot be performed in the middle of a Draw() loop
1432  midloop = true;
1433 
1434  GFXColor( 0, 0, 0, 0 );
1435  SetupViewport();
1437  if (GetElapsedTime() < 1) {
1439  }
1440  Room::BaseTalk::hastalked = false;
1441  rooms[curroom]->Draw( this );
1442  AnimationDraw();
1443 
1444  float x, y;
1445  glViewport( 0, 0, g_game.x_resolution, g_game.y_resolution );
1446  static float base_text_background_alpha =
1447  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_text_background_alpha", "0.0625" ) );
1448 
1449  curtext.GetCharSize( x, y );
1450  curtext.SetPos( -.99, -1+(y*1.5) );
1451 
1452  if (curtext.GetText().find( "XXX" ) != 0) {
1453  GFXColor tmpbg = curtext.bgcol;
1454  bool automatte = (0 == tmpbg.a);
1455  if (automatte) curtext.bgcol = GFXColor( 0, 0, 0, base_text_background_alpha );
1456  curtext.Draw( curtext.GetText(), 0, true, false, automatte );
1457  curtext.bgcol = tmpbg;
1458  }
1459  othtext.SetPos( -.99, 1 );
1460 
1461  if (othtext.GetText().length() != 0) {
1462  GFXColor tmpbg = othtext.bgcol;
1463  bool automatte = (0 == tmpbg.a);
1464  if (automatte) othtext.bgcol = GFXColor( 0, 0, 0, base_text_background_alpha );
1465  othtext.Draw( othtext.GetText(), 0, true, false, automatte );
1466  othtext.bgcol = tmpbg;
1467  }
1468  SetupViewport();
1469  EndGUIFrame( mousePointerStyle );
1470  glViewport( 0, 0, g_game.x_resolution, g_game.y_resolution );
1471  Unit *un = caller.GetUnit();
1472  Unit *base = baseun.GetUnit();
1473  if ( un && (!base) ) {
1474  VSFileSystem::vs_fprintf( stderr, "Error: Base NULL" );
1475  mission->msgcenter->add( "game", "all", "[Computer] Docking unit destroyed. Emergency launch initiated." );
1476  for (size_t i = 0; i < un->pImage->dockedunits.size(); i++)
1477  if (un->pImage->dockedunits[i]->uc.GetUnit() == base)
1478  un->FreeDockingPort( i );
1479  Terminate();
1480  }
1481 
1482  //Commit audio scene status to renderer
1483  if (g_game.sound_enabled)
1485 
1486  // Some operations cannot be performed in the middle of a Draw() loop
1487  // If any of them are scheduled for deferred execution, do so now
1488  midloop = false;
1489  if (terminate_scheduled)
1490  Terminate();
1491 }
void BaseInterface::GotoLink ( int  linknum)

Definition at line 928 of file base_interface.cpp.

References curroom, BaseInterface::Room::deftext, MOUSE_POINTER_NORMAL, othtext, BaseInterface::Room::Room(), rooms, TextPlane::SetText(), and VSFileSystem::vs_fprintf().

Referenced by BaseInterface(), BaseInterface::Room::Goto::Click(), and BaseUtil::SetCurRoom().

929 {
930  othtext.SetText( "" );
931  if (static_cast<int>(rooms.size()) > linknum && linknum >= 0) {
932  curlinkindex = 0;
933  curroom = linknum;
934  curtext.SetText( rooms[curroom]->deftext );
935  mousePointerStyle = MOUSE_POINTER_NORMAL;
936  } else {
937 #ifndef BASE_MAKER
938  VSFileSystem::vs_fprintf( stderr, "\nWARNING: base room #%d tried to go to an invalid index: #%d", curroom, linknum );
939  assert( 0 );
940 #else
941  while (rooms.size() <= linknum) {
942  rooms.push_back( new Room() );
943  char roomnum[50];
944  sprintf( roomnum, "Room #%d", linknum );
945  rooms.back()->deftext = roomnum;
946  }
947  GotoLink( linknum );
948 #endif
949  }
950 }
bool BaseInterface::isDJEnabled ( ) const
inline

Definition at line 352 of file base.h.

352 { return enabledj; }
void BaseInterface::Key ( unsigned int  ch,
unsigned int  mod,
bool  release,
int  x,
int  y 
)

Definition at line 912 of file base_interface.cpp.

References python_kbhandler, RunPython(), and BaseUtil::SetKeyEventData().

Referenced by base_keyboard_cb(), and ProcessKeyboardBuffer().

913 {
914  if ( !python_kbhandler.empty() ) {
915  const std::string *evtype;
916  if (release) {
917  static const std::string release_evtype( "keyup" );
918  evtype = &release_evtype;
919  } else {
920  static const std::string press_evtype( "keydown" );
921  evtype = &press_evtype;
922  }
923  BaseUtil::SetKeyEventData( *evtype, ch );
924  RunPython( python_kbhandler.c_str() );
925  }
926 }
void BaseInterface::Load ( const char *  filename,
const char *  time_of_day,
const char *  faction 
)

Definition at line 34 of file base_xml.cpp.

References BASE_EXTENSION, baseun, getFullFile(), Unit::isUnit(), PLANETPTR, VSFileSystem::vs_close(), and VSFileSystem::vs_open().

Referenced by BaseInterface().

35 {
36 #if 0
37  std::string full_filename = string( "bases/" )+filename;
38  std::string daynight_filename = full_filename+"_"+string( time_of_day_hint );
39  full_filename += BASE_EXTENSION;
40  daynight_filename += BASE_EXTENSION;
41  std::string newfile = daynight_filename;
42  cout<<"BaseInterface::LoadXML "<<full_filename<<endl;
43  FILE *inFile = VSFileSystem::vs_open( daynight_filename.c_str(), "r" );
44  if (!inFile) {
45  newfile = full_filename;
46  inFile = VSFileSystem::vs_open( full_filename.c_str(), "r" );
47  }
48  if (!inFile) {
49  Unit *baseun = this->baseun.GetUnit();
50  if (baseun) {
51  if (baseun->isUnit() == PLANETPTR) {
52  daynight_filename = string( "bases/planet_" )+time_of_day_hint+string( BASE_EXTENSION );
53  inFile = VSFileSystem::vs_open( daynight_filename.c_str(), "r" );
54  newfile = daynight_filename;
55  if (!inFile) {
56  newfile = "bases/planet" BASE_EXTENSION;
57  inFile = VSFileSystem::vs_open( newfile.c_str(), "r" );
58  }
59  } else {
60  daynight_filename = string( "bases/unit_" )+time_of_day_hint+string( BASE_EXTENSION );
61  inFile = VSFileSystem::vs_open( daynight_filename.c_str(), "r" );
62  newfile = daynight_filename;
63  if (!inFile) {
64  newfile = "bases/unit" BASE_EXTENSION;
65  inFile = VSFileSystem::vs_open( newfile.c_str(), "r" );
66  }
67  }
68  }
69  if (!inFile)
70  return;
71  }
72 #else
73  FILE *inFile = getFullFile( string( "bases/" )+filename, time_of_day_hint, faction );
74  if (!inFile) {
75  bool planet = false;
76  Unit *baseun = this->baseun.GetUnit();
77  if (baseun)
78  planet = (baseun->isUnit() == PLANETPTR);
79  string basestring( "bases/unit" );
80  if (planet)
81  basestring = "bases/planet";
82  inFile = getFullFile( basestring, time_of_day_hint, faction );
83  if (!inFile)
84  return;
85  }
86 #endif
87  //now that we have a FILE * named inFile and a std::string named newfile we can finally begin the python
88  string compilefile = string( filename )+time_of_day_hint+string( faction )+BASE_EXTENSION;
89  Python::reseterrors();
90  PyRun_SimpleFile( inFile, compilefile.c_str() );
91  Python::reseterrors();
92  VSFileSystem::vs_close( inFile );
93 }
void BaseInterface::MouseOver ( int  x,
int  y 
)

Definition at line 791 of file base_interface.cpp.

References CalculateRealXAndY(), curroom, BaseInterface::Room::deftext, getMouseButtonMask(), VegaConfig::getVariable(), i, BaseInterface::Room::links, MOUSE_POINTER_HOVER, MOUSE_POINTER_NORMAL, BaseInterface::Room::Link::MouseEnter(), BaseInterface::Room::Link::MouseLeave(), BaseInterface::Room::Link::MouseMove(), XMLSupport::parse_bool(), XMLSupport::parse_float(), BaseInterface::Room::Link::pythonfile, rooms, UniverseUtil::sqrt(), BaseInterface::Room::Link::text, vs_config, x, and y.

Referenced by ActiveMouseOverWin(), and PassiveMouseOverWin().

792 {
793  float x, y;
794  CalculateRealXAndY( xbeforecalc, ybeforecalc, &x, &y );
795  int i = rooms[curroom]->MouseOver( this, x, y ); //FIXME Whatever this is, it shouldn't be named just "i"; & possibly should be size_t
796  Room::Link *link = 0;
797  Room::Link *hotlink = 0;
798  if (i >= 0)
799  link = rooms[curroom]->links[i];
800  if ( lastmouseindex >= 0 && lastmouseindex < static_cast<int>(rooms[curroom]->links.size()) )
801  hotlink = rooms[curroom]->links[lastmouseindex];
802  if ( hotlink && (lastmouseindex != i) )
803  hotlink->MouseLeave( this, x, y, getMouseButtonMask() );
804  if ( link && (lastmouseindex != i) )
805  link->MouseEnter( this, x, y, getMouseButtonMask() );
806  if (link)
807  link->MouseMove( this, x, y, getMouseButtonMask() );
808  lastmouseindex = i;
809  static float overcolor[4] = {1, .666666667, 0, 1};
810  static float inactivecolor[4] = {0, 1, 0, 1};
811  if (link)
812  curtext.SetText( link->text );
813  else
814  curtext.SetText( rooms[curroom]->deftext );
815  if (link && link->pythonfile != "#") {
816  curtext.col = GFXColor( overcolor[0], overcolor[1], overcolor[2], overcolor[3] );
817  mousePointerStyle = MOUSE_POINTER_HOVER;
818  } else {
819  curtext.col = GFXColor( inactivecolor[0], inactivecolor[1], inactivecolor[2], inactivecolor[3] );
820  mousePointerStyle = MOUSE_POINTER_NORMAL;
821  }
822  static bool draw_always =
823  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_locationmarker_drawalways", "false" ) );
824  static float defined_distance =
825  fabs( XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_distance", "0.5" ) ) );
826  if (!draw_always) {
827  float cx, cy;
828  float dist_cur2link;
829  for (i = 0; i < static_cast<int>(rooms[curroom]->links.size()); i++) {
830  cx = ( rooms[curroom]->links[i]->x+(rooms[curroom]->links[i]->wid/2) ); //get the x center of the location
831  cy = ( rooms[curroom]->links[i]->y+(rooms[curroom]->links[i]->hei/2) ); //get the y center of the location
832  dist_cur2link = sqrt( pow( (cx-x), 2 )+pow( (cy-y), 2 ) );
833  if (dist_cur2link < defined_distance)
834  rooms[curroom]->links[i]->alpha = ( 1-(dist_cur2link/defined_distance) );
835  else
836  rooms[curroom]->links[i]->alpha = 1;
837  }
838  }
839 }
void BaseInterface::PassiveMouseOverWin ( int  x,
int  y 
)
static

Definition at line 872 of file base_interface.cpp.

References CallComp, CurrentBase, ModifyMouseSensitivity(), NavigationSystem::mouseMotion(), MouseOver(), and SetSoftwareMousePosition().

Referenced by BaseInterface::Room::Click(), InitCallbacks(), and GameCockpit::NavScreen().

873 {
876  if (CurrentBase) {
877  if (CurrentBase->CallComp) {
878 #ifdef NEW_GUI
879  EventManager::
880 #else
881  UpgradingInfo::
882 #endif
883  ProcessMousePassive( x, y );
884  } else {
885  CurrentBase->MouseOver( x, y );
886  }
887  } else {
889  }
890 }
void BaseInterface::ProcessKeyboardBuffer ( )
static

Definition at line 1493 of file base_interface.cpp.

References base_keyboard_queue, CallComp, CurrentBase, and Key().

Referenced by base_keyboard_cb().

1494 {
1495  if (CurrentBase) {
1496  if (!CurrentBase->CallComp) {
1497  for (std::vector< unsigned int >::iterator it = base_keyboard_queue.begin(); it != base_keyboard_queue.end();
1498  ++it) {
1499  CurrentBase->Key( *it, 0, false, 0, 0 );
1500  CurrentBase->Key( *it, 0, true, 0, 0 );
1501  }
1502  base_keyboard_queue.clear();
1503  }
1504  }
1505 }
void BaseInterface::setDJEnabled ( bool  enabled)

Definition at line 1507 of file base_interface.cpp.

Referenced by BaseUtil::SetDJEnabled().

1508 {
1509  enabledj = enabled;
1510 }
void BaseInterface::Terminate ( )

Definition at line 1185 of file base_interface.cpp.

References caller, CurrentBase, UnitContainer::GetUnit(), UnitUtil::isPlayerStarship(), mission_key, restore_main_loop(), and saveStringList().

Referenced by BaseInterface::Room::Launch::Click(), BaseInterface::Room::Eject::Click(), Draw(), BaseUtil::LoadBaseInterfaceAtDock(), and TerminateCurrentBase().

1186 {
1187  if (midloop) {
1188  terminate_scheduled = true;
1189  } else {
1190  Unit *un = caller.GetUnit();
1191  int cpt = UnitUtil::isPlayerStarship( un );
1192  if (un && cpt >= 0) {
1193  vector< string >vec;
1194  vec.push_back( string() );
1195  saveStringList( cpt, mission_key, vec );
1196  }
1199  delete this;
1200  }
1201 }

Friends And Related Function Documentation

friend class Room
friend

Definition at line 320 of file base.h.

Referenced by BaseInterface().

friend class Room::BaseTalk
friend

Definition at line 321 of file base.h.

Member Data Documentation

TextPlane BaseInterface::othtext
std::string BaseInterface::python_kbhandler

Definition at line 330 of file base.h.

Referenced by BaseUtil::GlobalKeyPython(), and Key().


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