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

#include <base.h>

Classes

class  BaseObj
 
class  BasePython
 
class  BaseShip
 
class  BaseTalk
 
class  BaseText
 
class  BaseVSMovie
 
class  BaseVSSprite
 
class  Comp
 
class  Eject
 
class  Goto
 
class  Launch
 
class  Link
 
class  Python
 
class  Talk
 

Public Member Functions

void Draw (::BaseInterface *base)
 
void Click (::BaseInterface *base, float x, float y, int button, int state)
 
int MouseOver (::BaseInterface *base, float x, float y)
 
 Room ()
 
 ~Room ()
 

Public Attributes

std::string soundfile
 
std::string deftext
 
std::vector< Link * > links
 
std::vector< BaseObj * > objs
 

Detailed Description

Definition at line 31 of file base.h.

Constructor & Destructor Documentation

BaseInterface::Room::Room ( )

Definition at line 125 of file base_interface.cpp.

Referenced by BaseInterface::GotoLink().

126 {
127 //Do nothing...
128 }
BaseInterface::Room::~Room ( )

Definition at line 114 of file base_interface.cpp.

References i.

115 {
116  size_t i;
117  for (i = 0; i < links.size(); i++)
118  if (links[i])
119  delete links[i];
120  for (i = 0; i < objs.size(); i++)
121  if (objs[i])
122  delete objs[i];
123 }

Member Function Documentation

void BaseInterface::Room::Click ( ::BaseInterface base,
float  x,
float  y,
int  button,
int  state 
)

Definition at line 670 of file base_interface.cpp.

References biModifyMouseSensitivity(), BaseInterface::Room::Link::Click(), BaseUtil::Comp(), g_game, BaseInterface::Room::Link::hei, i, index, int, BaseUtil::Launch(), links, MouseOver(), objs, BaseInterface::PassiveMouseOverWin(), VSFileSystem::vs_close(), VSFileSystem::vs_feof(), VSFileSystem::vs_fscanf(), VSFileSystem::vs_open(), BaseInterface::Room::Link::wid, winsys_warp_pointer(), WS_LEFT_BUTTON, WS_MIDDLE_BUTTON, WS_MOUSE_UP, WS_RIGHT_BUTTON, BaseInterface::Room::Link::x, x, game_data_t::x_resolution, BaseInterface::Room::Link::y, y, and game_data_t::y_resolution.

671 {
672  if (button == WS_LEFT_BUTTON) {
673  int linknum = MouseOver( base, x, y );
674  if (linknum >= 0) {
675  Link *link = links[linknum];
676  if (link)
677  link->Click( base, x, y, button, state );
678  }
679  } else {
680 #ifdef BASE_MAKER
681  if (state == WS_MOUSE_UP) {
682  char input[201];
683  char *str;
684  if (button == WS_RIGHT_BUTTON)
685  str = "Please create a file named stdin.txt and type\nin the sprite file that you wish to use.";
686  else if (button == WS_MIDDLE_BUTTON)
687  str =
688  "Please create a file named stdin.txt and type\nin the type of room followed by arguments for the room followed by text in quotations:\n1 ROOM# \"TEXT\"\n2 \"TEXT\"\n3 vector<MODES>.size vector<MODES> \"TEXT\"";
689  else
690  return;
691 #ifdef _WIN32
692  int ret = MessageBox( NULL, str, "Input", MB_OKCANCEL );
693 #else
694  printf( "\n%s\n", str );
695  int ret = 1;
696 #endif
697  int index;
698  int rmtyp;
699  if (ret == 1) {
700  if (button == WS_RIGHT_BUTTON) {
701 #ifdef _WIN32
702  FILE *fp = VSFileSystem::vs_open( "stdin.txt", "rt" );
703 #else
704  FILE *fp = stdin;
705 #endif
706  VSFileSystem::vs_fscanf( fp, "%200s", input );
707 #ifdef _WIN32
709 #endif
710  } else if (button == WS_MIDDLE_BUTTON && makingstate == 0) {
711  int i;
712 #ifdef _WIN32
713  FILE *fp = VSFileSystem::vs_open( "stdin.txt", "rt" );
714 #else
715  FILE *fp = stdin;
716 #endif
717  VSFileSystem::vs_fscanf( fp, "%d", &rmtyp );
718  switch (rmtyp)
719  {
720  case 1:
721  links.push_back( new Goto( "linkind", "link" ) );
722  VSFileSystem::vs_fscanf( fp, "%d", &( (Goto*) links.back() )->index );
723  break;
724  case 2:
725  links.push_back( new Launch( "launchind", "launch" ) );
726  break;
727  case 3:
728  links.push_back( new Comp( "compind", "comp" ) );
729  VSFileSystem::vs_fscanf( fp, "%d", &index );
730  for (i = 0; i < index && ( !VSFileSystem::vs_feof( fp ) ); i++) {
731  VSFileSystem::vs_fscanf( fp, "%d", &ret );
732  ( (Comp*) links.back() )->modes.push_back( (BaseComputer::DisplayMode) ret );
733  }
734  break;
735  default:
736 #ifdef _WIN32
738  MessageBox( NULL, "warning: invalid basemaker option", "Error", MB_OK );
739 #endif
740  printf( "warning: invalid basemaker option: %d", rmtyp );
741  return;
742  }
743  VSFileSystem::vs_fscanf( fp, "%200s", input );
744  input[200] = input[199] = '\0';
745  links.back()->text = string( input );
746 #ifdef _WIN32
748 #endif
749  }
750  if (button == WS_RIGHT_BUTTON) {
751  input[200] = input[199] = '\0';
752  objs.push_back( new BaseVSSprite( input, "tex" ) );
753  ( (BaseVSSprite*) objs.back() )->texfile = string( input );
754  ( (BaseVSSprite*) objs.back() )->spr.SetPosition( x, y );
755  } else if (button == WS_MIDDLE_BUTTON && makingstate == 0) {
756  links.back()->x = x;
757  links.back()->y = y;
758  links.back()->wid = 0;
759  links.back()->hei = 0;
760  makingstate = 1;
761  } else if (button == WS_MIDDLE_BUTTON && makingstate == 1) {
762  links.back()->wid = x-links.back()->x;
763  if (links.back()->wid < 0)
764  links.back()->wid = -links.back()->wid;
765  links.back()->hei = y-links.back()->y;
766  if (links.back()->hei < 0)
767  links.back()->hei = -links.back()->hei;
768  makingstate = 0;
769  }
770  }
771  }
772 #else
773  if ( state == WS_MOUSE_UP && links.size() ) {
774  size_t count = 0;
775  while ( count++ < links.size() ) {
776  Link *curlink = links[base->curlinkindex++%links.size()];
777  if (curlink) {
778  int x = int( ( ( ( curlink->x+(curlink->wid/2) )+1 )/2 )*g_game.x_resolution );
779  int y = -int( ( ( ( curlink->y+(curlink->hei/2) )-1 )/2 )*g_game.y_resolution );
780  biModifyMouseSensitivity( x, y, true );
781  winsys_warp_pointer( x, y );
782  PassiveMouseOverWin( x, y );
783  break;
784  }
785  }
786  }
787 #endif
788  }
789 }
void BaseInterface::Room::Draw ( ::BaseInterface base)

Definition at line 337 of file base_interface.cpp.

References GFXColor::a, TextPlane::bgcol, TextPlane::col, VSSprite::Draw(), TextPlane::Draw(), TextPlane::GetCharSize(), VSSprite::GetSize(), TextPlane::GetText(), VegaConfig::getVariable(), GFXBegin(), GFXBlendMode(), GFXColor4f(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINESTRIP, GFXVertexf(), i, index, INVSRCALPHA, links, objs, XMLSupport::parse_bool(), XMLSupport::parse_float(), TextPlane::SetPos(), VSSprite::SetPosition(), TextPlane::SetText(), SRCALPHA, TEXTURE0, TEXTURE1, Vector, vs_config, x, and y.

338 {
339  size_t i;
340  for (i = 0; i < objs.size(); i++)
341  if (objs[i]) {
343  objs[i]->Draw( base );
344  }
346  //draw location markers
347  //<!-- config options in the "graphics" section -->
348  //<var name="base_enable_locationmarkers" value="true"/>
349  //<var name="base_locationmarker_sprite" value="base_locationmarker.spr"/>
350  //<var name="base_draw_locationtext" value="true"/>
351  //<var name="base_locationmarker_textoffset_x" value="0.025"/>
352  //<var name="base_locationmarker_textoffset_y" value="0.025"/>
353  //<var name="base_locationmarker_drawalways" value="false"/>
354  //<var name="base_locationmarker_distance" value="0.5"/>
355  //<var name="base_locationmarker_textcolor_r" value="1.0"/>
356  //<var name="base_locationmarker_textcolor_g" value="1.0"/>
357  //<var name="base_locationmarker_textcolor_b" value="1.0"/>
358  //<var name="base_drawlocationborders" value="false"/>
359  static bool enable_markers =
360  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_enable_locationmarkers", "false" ) );
361  static bool draw_text = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_draw_locationtext", "false" ) );
362  static bool draw_always =
363  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_locationmarker_drawalways", "false" ) );
364  static float y_lower = -0.9; //shows the offset on the lower edge of the screen (for the textline there) -> Should be defined globally somewhere
365  static float base_text_background_alpha =
366  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_text_background_alpha", "0.0625" ) );
367  if (enable_markers) {
368  float x, y, text_wid, text_hei;
369  //get offset from config;
370  static float text_offset_x =
371  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textoffset_x", "0" ) );
372  static float text_offset_y =
373  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textoffset_y", "0" ) );
374  static float text_color_r =
375  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textcolor_r", "1" ) );
376  static float text_color_g =
377  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textcolor_g", "1" ) );
378  static float text_color_b =
379  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textcolor_b", "1" ) );
380  for (size_t i = 0; i < links.size(); i++) //loop through all links and draw a marker for each
381  if (links[i]) {
382  if ( (links[i]->alpha < 1) || (draw_always) ) {
383  if (draw_always) links[i]->alpha = 1; //set all alphas to visible
384  x = ( links[i]->x+(links[i]->wid/2) ); //get the center of the location
385  y = ( links[i]->y+(links[i]->hei/2) ); //get the center of the location
386 
387  /* draw marker */
388  static string spritefile_marker = vs_config->getVariable( "graphics", "base_locationmarker_sprite", "" );
389  if ( spritefile_marker.length() && links[i]->text.find("XXX") != 0 ) {
390  static VSSprite *spr_marker = new VSSprite( spritefile_marker.c_str() );
391  float wid, hei;
392  spr_marker->GetSize( wid, hei );
393  //check if the sprite is near a screenedge and correct its position if necessary
394  if ( ( x+(wid/2) ) >= 1 ) x = ( 1-(wid/2) );
395  if ( ( y+(hei/2) ) >= 1 ) y = ( 1-(hei/2) );
396  if ( ( x-(wid/2) ) <= -1 ) x = ( -1+(wid/2) );
397  if ( ( y-(hei/2) ) <= y_lower ) y = ( y_lower+(hei/2) );
398  spr_marker->SetPosition( x, y );
399  GFXDisable( TEXTURE1 );
400  GFXEnable( TEXTURE0 );
401  GFXColor4f( 1, 1, 1, links[i]->alpha );
402  spr_marker->Draw();
403  } //if spritefile
404  if (draw_text) {
405  GFXDisable( TEXTURE0 );
406  TextPlane text_marker;
407  text_marker.SetText( links[i]->text );
408  text_marker.GetCharSize( text_wid, text_hei ); //get average charactersize
409  float text_pos_x = x+text_offset_x; //align right ...
410  float text_pos_y = y+text_offset_y+text_hei; //...and on top
411  text_wid = text_wid*links[i]->text.length()*0.25; //calc ~width of text (=multiply the average characterwidth with the number of characters)
412  if ( (text_pos_x+text_offset_x+text_wid) >= 1 ) //check right screenborder
413  text_pos_x = (x-fabs( text_offset_x )-text_wid); //align left
414  if ( (text_pos_y+text_offset_y) >= 1 ) //check upper screenborder
415  text_pos_y = ( y-fabs( text_offset_y ) ); //align on bottom
416  if ( (text_pos_y+text_offset_y-text_hei) <= y_lower ) //check lower screenborder
417  text_pos_y = (y+fabs( text_offset_y )+text_hei); //align on top
418  text_marker.col = GFXColor( text_color_r, text_color_g, text_color_b, links[i]->alpha );
419  text_marker.SetPos( text_pos_x, text_pos_y );
420  if (links[i]->pythonfile != "#" && text_marker.GetText().find( "XXX" ) != 0) {
421  GFXColor tmpbg = text_marker.bgcol;
422  bool automatte = (0 == tmpbg.a);
423  if (automatte) text_marker.bgcol = GFXColor( 0, 0, 0, base_text_background_alpha );
424  text_marker.Draw( text_marker.GetText(), 0, true, false, automatte );
425  text_marker.bgcol = tmpbg;
426  }
427  GFXEnable( TEXTURE0 );
428  } //if draw_text
429  }
430  }
431  //if link
432  //for i
433  } //enable_markers
434 
435  static bool draw_borders = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_drawlocationborders", "false" ) );
436  static bool debug_markers = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "base_enable_debugmarkers", "false" ) );
437  if (draw_borders || debug_markers) {
438  float x, y, text_wid, text_hei;
439  //get offset from config;
440  static float text_offset_x =
441  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textoffset_x", "0" ) );
442  static float text_offset_y =
443  XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_locationmarker_textoffset_y", "0" ) );
444  for (size_t i = 0; i < links.size(); i++) //loop through all links and draw a marker for each
445  if (links[i]) {
446  //Debug marker
447  if (debug_markers) {
448  //compute label position
449  x = ( links[i]->x+(links[i]->wid/2) ); //get the center of the location
450  y = ( links[i]->y+(links[i]->hei/2) ); //get the center of the location
451  TextPlane text_marker;
452  text_marker.SetText( links[i]->index );
453  text_marker.GetCharSize( text_wid, text_hei ); //get average charactersize
454  float text_pos_x = x+text_offset_x; //align right ...
455  float text_pos_y = y+text_offset_y+text_hei; //...and on top
456  text_wid = text_wid*links[i]->text.length()*0.25; //calc ~width of text (=multiply the average characterwidth with the number of characters)
457  if ( (text_pos_x+text_offset_x+text_wid) >= 1 ) //check right screenborder
458  text_pos_x = (x-fabs( text_offset_x )-text_wid); //align left
459  if ( (text_pos_y+text_offset_y) >= 1 ) //check upper screenborder
460  text_pos_y = ( y-fabs( text_offset_y ) ); //align on bottom
461  if ( (text_pos_y+text_offset_y-text_hei) <= y_lower ) //check lower screenborder
462  text_pos_y = (y+fabs( text_offset_y )+text_hei); //align on top
463  if (enable_markers)
464  text_pos_y += text_hei;
465  text_marker.col = GFXColor( 1, 1, 1, 1 );
466  text_marker.SetPos( text_pos_x, text_pos_y );
467 
468  GFXDisable( TEXTURE0 );
469  GFXColor tmpbg = text_marker.bgcol;
470  bool automatte = (0 == tmpbg.a);
471  if (automatte) text_marker.bgcol = GFXColor( 0, 0, 0, base_text_background_alpha );
472  text_marker.Draw( text_marker.GetText(), 0, true, false, automatte );
473  text_marker.bgcol = tmpbg;
474  GFXEnable( TEXTURE0 );
475  }
476  //link border
477  GFXColor4f( 1, 1, 1, 1 );
478  Vector c1( links[i]->x, links[i]->y, 0 );
479  Vector c3( links[i]->wid+c1.i, links[i]->hei+c1.j, 0 );
480  Vector c2( c1.i, c3.j, 0 );
481  Vector c4( c3.i, c1.j, 0 );
482  GFXDisable( TEXTURE0 );
484  GFXVertexf( c1 );
485  GFXVertexf( c2 );
486  GFXVertexf( c3 );
487  GFXVertexf( c4 );
488  GFXVertexf( c1 );
489  GFXEnd();
490  GFXEnable( TEXTURE0 );
491  }
492  //if link
493  //for i
494  } //if draw_borders
495 }
int BaseInterface::Room::MouseOver ( ::BaseInterface base,
float  x,
float  y 
)

Definition at line 610 of file base_interface.cpp.

References i, and links.

Referenced by Click().

611 {
612  for (size_t i = 0; i < links.size(); i++)
613  if (links[i]) {
614  if ( x >= links[i]->x
615  && x <= (links[i]->x+links[i]->wid)
616  && y >= links[i]->y
617  && y <= (links[i]->y+links[i]->hei) )
618  return i;
619  }
620  return -1;
621 }

Member Data Documentation

std::string BaseInterface::Room::deftext

Definition at line 308 of file base.h.

Referenced by BaseInterface::GotoLink(), and BaseInterface::MouseOver().

std::string BaseInterface::Room::soundfile

Definition at line 307 of file base.h.


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