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
navcomputer.cpp
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #include "vegastrike.h"
23 #if defined (_WIN32) && !defined (__CYGWIN__) && !defined (__MINGW32__)
24 //For WIN32 debugging.
25 #include <crtdbg.h>
26 #endif
27 
28 #include "navscreen.h"
29 #include "navpath.h"
30 #include "in_kb.h"
31 #include "in_kb_data.h"
32 #include "in_mouse.h"
33 #include "gfx/cockpit.h"
34 #include "main_loop.h"
35 #include "lin_time.h"
36 #include "gui/modaldialog.h"
37 #include "gui/eventmanager.h"
38 #include "gui/newbutton.h"
39 #include "gui/staticdisplay.h"
40 #include "gui/textinputdisplay.h"
41 #include "gui/simplepicker.h"
42 #include "gui/groupcontrol.h"
43 #include "gui/scroller.h"
44 
45 vector< unsigned int >nav_keyboard_queue;
46 
47 //Info about each mode.
48 struct ModeInfo
49 {
50  string title;
51  string button;
52  string command;
53  string groupId;
54  ModeInfo( string t = "", string b = "", string c = "", string g = "" ) :
55  title( t )
56  , button( b )
57  , command( c )
58  , groupId( g ) {}
59 };
60 
61 static const ModeInfo displayModeInfo[] = {
62  ModeInfo( "List Mode", "Finished", "ListMode", "ListGroup" ),
63  ModeInfo( "Edit Mode", "Edit", "EditMode", "EditGroup" )
64 };
65 
66 static const ModeInfo selectorModeInfo[] = {
67  ModeInfo( "Target Select", "System", "TargetSelectMode", "TargetSelectGroup" ),
68  ModeInfo( "Criteria Select", "Criteria", "CriteriaSelectMode", "CriteriaSelectGroup" ),
69  ModeInfo( "Chain Select", "Chain", "ChainSelectMode", "ChainSelectGroup" )
70 };
71 
72 //Dispatch table for commands.
73 //Make an entry here for each command you want to handle.
74 //WARNING: The order of this table is important. There are multiple entries for
75 //some commands. Basically, you can make an entry for a particular control, and then
76 //later have an entry with an empty control id to cover the other cases.
78  NavComputer::WctlTableEntry( "Visible",
79  "",
81  NavComputer::WctlTableEntry( "Picker::NewSelection",
82  "PathLister",
84  NavComputer::WctlTableEntry( displayModeInfo[LIST].command, "", &NavComputer::changeToListMode ),
85  NavComputer::WctlTableEntry( displayModeInfo[EDIT].command, "", &NavComputer::changeToEditMode ),
86  NavComputer::WctlTableEntry( selectorModeInfo[TARGET].command, "", &NavComputer::changeToTargetMode ),
87  NavComputer::WctlTableEntry( selectorModeInfo[CRITERIA].command, "", &NavComputer::changeToCriteriaMode ),
88  NavComputer::WctlTableEntry( selectorModeInfo[CHAIN].command, "", &NavComputer::changeToChainMode ),
105  NavComputer::WctlTableEntry( "", "", NULL )
106 };
107 
108 //Process a command from the window.
109 //This just dispatches to a handler.
111 {
112  //Iterate through the dispatch table.
113  for (const WctlTableEntry *p = &WctlCommandTable[0]; p->function; p++)
114  if (p->command == command) {
115  if ( p->controlId.size() == 0 || p->controlId == control->id() )
116  //Found a handler for the command.
117  return ( this->*(p->function) )( command, control );
118  }
119  //Let the base class have a try at the command first.
120  if ( WindowController::processWindowCommand( command, control ) )
121  return true;
122  //Didn't find a handler.
123  return false;
124 }
125 
126 //CONSTRUCTOR.
128  navsys( navsystem )
129  , m_currentDisplay( NULL_DISPLAY )
130  , m_currentSelector( NULL_SELECTOR )
131 {
132  int i;
133  pathman = navsystem->pathman;
134  currentPath = NULL;
135  currentNode = NULL;
136  criteria = false;
137  //Initialize display mode group controls array.
138  for (i = 0; i < DISPLAY_MODE_COUNT; i++)
139  m_displayModeGroups[i] = NULL;
140  //Initialize selector mode group controls array.
141  for (i = 0; i < SELECTOR_MODE_COUNT; i++)
142  m_selectorModeGroups[i] = NULL;
143  m_displayModes.push_back( LIST );
144  m_displayModes.push_back( EDIT );
145 
146  m_selectorModes.push_back( TARGET );
147  m_selectorModes.push_back( CRITERIA );
148  m_selectorModes.push_back( CHAIN );
149 
150  m_visible = false;
151 }
152 
153 //Destructor.
155 {
156  int i;
157  //Delete any group controls that the window doesn't "own".
158  for (i = 0; i < DISPLAY_MODE_COUNT; i++)
159  if (m_displayModeGroups[i] != NULL)
160  delete m_displayModeGroups[i];
161  for (i = 0; i < SELECTOR_MODE_COUNT; i++)
162  if (m_selectorModeGroups[i] != NULL)
163  delete m_selectorModeGroups[i];
164 }
165 
166 //Set up the window and get everything ready.
167 void NavComputer::init( void )
168 {
169  //Create a new window.
170  Window *w = new Window;
171  setWindow( w );
172 
173  m_window->setDeleteOnClose( false );
174  m_window->setController( this );
175  m_deleteOnWindowClose = false;
176 
177  //Read in the controls for all the modes.
178  createControls();
179 
180  NavPath *path = new NavPath();
181  path->setName( "Target Search" );
182  path->setSourceNode( new CurrentPathNode() );
183  path->setDestinationNode( new TargetPathNode() );
184  pathman->paths.push_back( path );
185 }
186 
187 //Create the controls that will be used for this window.
189 {
190  int i;
191  //Set up the window.
192  window()->setFullScreen();
193  window()->setColor( GUI_CLEAR );
194  window()->setTexture( "basecomputer.png" );
195 
196  //Put all the controls in the window.
198  //Take the mode group controls out of the window.
199  for (i = 0; i < DISPLAY_MODE_COUNT; i++) {
200  Control *group = window()->findControlById( displayModeInfo[i].groupId );
201  if (group) {
202  window()->removeControlFromWindow( group );
203  m_displayModeGroups[i] = group;
204  }
205  }
206  //Take the mode group controls out of the window.
207  for (i = 0; i < SELECTOR_MODE_COUNT; i++) {
208  Control *group = window()->findControlById( selectorModeInfo[i].groupId );
209  if (group) {
210  window()->removeControlFromWindow( group );
211  m_selectorModeGroups[i] = group;
212  }
213  }
214 }
215 
217 {
218  if (id == "MainGroup")
219  return GFXColor( 0, 1, 1 );
220  else if (id == "ListGroup")
221  return GFXColor( 0, 1, 1 );
222  else if (id == "EditGroup")
223  return GFXColor( 0, 1, 1 );
224  else
225  return GFXColor( 0, 1, 1 );
226 }
227 
228 //Hack that constructs controls in code.
230 {
231  {
232  GroupControl *mainGroup = new GroupControl;
233  mainGroup->setId( "MainGroup" );
234  window()->addControl( mainGroup );
235  GFXColor color = getColorForGroup( "MainGroup" );
236 
237  //Base info title.
238  StaticDisplay *baseTitle = new StaticDisplay;
239  baseTitle->setRect( Rect( -.96, .76, 1.9, .08 ) );
240  baseTitle->setText( "Error" );
241  baseTitle->setTextColor( GFXColor( .4, 1, .4 ) );
242  baseTitle->setColor( GUI_CLEAR );
243  baseTitle->setFont( Font( .07, 1.75 ) );
244  baseTitle->setId( "NavigationTitle" );
245  mainGroup->addChild( baseTitle );
246 
247  //Done button.
248  NewButton *done = new NewButton;
249  done->setRect( Rect( .74, .74, .22, .12 ) );
250  done->setLabel( "Done" );
251  done->setCommand( "Visible" );
252  done->setColor( GFXColor( 0, 1, 1, .25 ) );
253  done->setTextColor( GUI_OPAQUE_WHITE() );
254  done->setDownColor( GFXColor( 0, 1, 1, .6 ) );
256  done->setHighlightColor( GFXColor( 0, 0, 1, .4 ) );
257  done->setFont( Font( .08, BOLD_STROKE ) );
258  mainGroup->addChild( done );
259 
260  //Scroller for description.
261  Scroller *descScroller = new Scroller;
262  descScroller->setRect( Rect( .91, -.29, .05, .99 ) );
263  descScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
264  descScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
265  descScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
266  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
267  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
268 
269  //Description box.
270  StaticDisplay *ms = new StaticDisplay;
271  ms->setRect( Rect( .24, -.29, .67, .99 ) );
272  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
274  ms->setFont( Font( .07 ) );
275  ms->setMultiLine( true );
277  ms->setTextMargins( Size( .02, .01 ) );
278  ms->setId( "Description" );
279  ms->setScroller( descScroller );
280  mainGroup->addChild( ms );
281 
282  mainGroup->addChild( descScroller ); //Want scroller "over" description box.
283  }
284 
285  {
286  GroupControl *listGroup = new GroupControl;
287  listGroup->setId( displayModeInfo[LIST].groupId );
288  window()->addControl( listGroup );
289  GFXColor color = getColorForGroup( displayModeInfo[LIST].groupId );
290 
291  //Scroller for picker.
292  Scroller *pathScroller = new Scroller;
293  pathScroller->setRect( Rect( -.50, -.95, .05, 1.65 ) );
294  pathScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
295  pathScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
296  pathScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
297  pathScroller->setTextColor( GUI_OPAQUE_WHITE() );
298  pathScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
299 
300  //Save game picker.
301  SimplePicker *pathList = new SimplePicker;
302  pathList->setRect( Rect( -.96, -.95, .46, 1.65 ) );
303  pathList->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
305  pathList->setTextColor( GUI_OPAQUE_WHITE() );
306  pathList->setSelectionColor( GFXColor( 0, .6, 0, .8 ) );
307  pathList->setHighlightColor( GFXColor( 0, .6, 0, .35 ) );
309  pathList->setFont( Font( .07 ) );
310  pathList->setTextMargins( Size( 0.02, 0.01 ) );
311  pathList->setId( "PathLister" );
312  pathList->setScroller( pathScroller );
313  listGroup->addChild( pathList );
314 
315  listGroup->addChild( pathScroller ); //Want scroller "over" picker.
316 
317  NewButton *up = new NewButton;
318  up->setRect( Rect( -.41, .58, .22, .12 ) );
319  up->setColor( GFXColor( 0, 1, 1, .1 ) );
321  up->setDownColor( GFXColor( 0, 1, 1, .4 ) );
322  up->setDownTextColor( GFXColor( .2, .2, .2 ) );
323  up->setVariableBorderCycleTime( 1.0 );
324  up->setBorderColor( GFXColor( .2, .2, .2 ) );
325  up->setEndBorderColor( GFXColor( .4, .4, .4 ) );
326  up->setShadowWidth( 2.0 );
327  up->setFont( Font( .08, BOLD_STROKE ) );
328  up->setId( "Up" );
329  up->setLabel( "Up" );
330  up->setCommand( "Up" );
331  listGroup->addChild( up );
332 
333  NewButton *add = new NewButton;
334  add->setRect( Rect( -.41, .33, .22, .12 ) );
335  add->setColor( GFXColor( 0, 1, 1, .1 ) );
336  add->setTextColor( GUI_OPAQUE_WHITE() );
337  add->setDownColor( GFXColor( 0, 1, 1, .4 ) );
338  add->setDownTextColor( GFXColor( .2, .2, .2 ) );
339  add->setVariableBorderCycleTime( 1.0 );
340  add->setBorderColor( GFXColor( .2, .2, .2 ) );
341  add->setEndBorderColor( GFXColor( .4, .4, .4 ) );
342  add->setShadowWidth( 2.0 );
343  add->setFont( Font( .08, BOLD_STROKE ) );
344  add->setId( "Add" );
345  add->setLabel( "Add" );
346  add->setCommand( "Add" );
347  listGroup->addChild( add );
348 
349  NewButton *edit = new NewButton;
350  edit->setRect( Rect( -.41, .07, .22, .12 ) );
351  edit->setColor( GFXColor( 0, 1, 1, .1 ) );
352  edit->setTextColor( GUI_OPAQUE_WHITE() );
353  edit->setDownColor( GFXColor( 0, 1, 1, .4 ) );
354  edit->setDownTextColor( GFXColor( .2, .2, .2 ) );
355  edit->setVariableBorderCycleTime( 1.0 );
356  edit->setBorderColor( GFXColor( .2, .2, .2 ) );
357  edit->setEndBorderColor( GFXColor( .4, .4, .4 ) );
358  edit->setShadowWidth( 2.0 );
359  edit->setFont( Font( .08, BOLD_STROKE ) );
360  edit->setId( displayModeInfo[EDIT].button );
361  edit->setLabel( displayModeInfo[EDIT].button );
362  edit->setCommand( displayModeInfo[EDIT].command );
363  listGroup->addChild( edit );
364 
365  NewButton *showpath = new NewButton;
366  showpath->setRect( Rect( -.41, -.18, .22, .12 ) );
367  showpath->setColor( GFXColor( 0, 1, 1, .1 ) );
368  showpath->setTextColor( GUI_OPAQUE_WHITE() );
369  showpath->setDownColor( GFXColor( 0, 1, 1, .4 ) );
370  showpath->setDownTextColor( GFXColor( .2, .2, .2 ) );
371  showpath->setVariableBorderCycleTime( 1.0 );
372  showpath->setBorderColor( GFXColor( .2, .2, .2 ) );
373  showpath->setEndBorderColor( GFXColor( .4, .4, .4 ) );
374  showpath->setShadowWidth( 2.0 );
375  showpath->setFont( Font( .08, BOLD_STROKE ) );
376  showpath->setId( "ShowPath" );
377  showpath->setLabel( "Show" );
378  showpath->setCommand( "ShowPath" );
379  listGroup->addChild( showpath );
380 
381  NewButton *rename = new NewButton;
382  rename->setRect( Rect( -.41, -.44, .22, .12 ) );
383  rename->setColor( GFXColor( 0, 1, 1, .1 ) );
384  rename->setTextColor( GUI_OPAQUE_WHITE() );
385  rename->setDownColor( GFXColor( 0, 1, 1, .4 ) );
386  rename->setDownTextColor( GFXColor( .2, .2, .2 ) );
387  rename->setVariableBorderCycleTime( 1.0 );
388  rename->setBorderColor( GFXColor( .2, .2, .2 ) );
389  rename->setEndBorderColor( GFXColor( .4, .4, .4 ) );
390  rename->setShadowWidth( 2.0 );
391  rename->setFont( Font( .08, BOLD_STROKE ) );
392  rename->setId( "Rename" );
393  rename->setLabel( "Rename" );
394  rename->setCommand( "Rename" );
395  listGroup->addChild( rename );
396 
397  NewButton *remove = new NewButton;
398  remove->setRect( Rect( -.41, -.69, .22, .12 ) );
399  remove->setColor( GFXColor( 0, 1, 1, .1 ) );
400  remove->setTextColor( GUI_OPAQUE_WHITE() );
401  remove->setDownColor( GFXColor( 0, 1, 1, .4 ) );
402  remove->setDownTextColor( GFXColor( .2, .2, .2 ) );
403  remove->setVariableBorderCycleTime( 1.0 );
404  remove->setBorderColor( GFXColor( .2, .2, .2 ) );
405  remove->setEndBorderColor( GFXColor( .4, .4, .4 ) );
406  remove->setShadowWidth( 2.0 );
407  remove->setFont( Font( .08, BOLD_STROKE ) );
408  remove->setId( "Remove" );
409  remove->setLabel( "Remove" );
410  remove->setCommand( "Remove" );
411  listGroup->addChild( remove );
412 
413  NewButton *down = new NewButton;
414  down->setRect( Rect( -.41, -.95, .22, .12 ) );
415  down->setColor( GFXColor( 0, 1, 1, .1 ) );
416  down->setTextColor( GUI_OPAQUE_WHITE() );
417  down->setDownColor( GFXColor( 0, 1, 1, .4 ) );
418  down->setDownTextColor( GFXColor( .2, .2, .2 ) );
419  down->setVariableBorderCycleTime( 1.0 );
420  down->setBorderColor( GFXColor( .2, .2, .2 ) );
421  down->setEndBorderColor( GFXColor( .4, .4, .4 ) );
422  down->setShadowWidth( 2.0 );
423  down->setFont( Font( .08, BOLD_STROKE ) );
424  down->setId( "Down" );
425  down->setLabel( "Down" );
426  down->setCommand( "Down" );
427  listGroup->addChild( down );
428 
429  NewButton *showall = new NewButton;
430  showall->setRect( Rect( -.15, .58, .35, .12 ) );
431  showall->setColor( GFXColor( 0, 1, 1, .1 ) );
432  showall->setTextColor( GUI_OPAQUE_WHITE() );
433  showall->setDownColor( GFXColor( 0, 1, 1, .4 ) );
434  showall->setDownTextColor( GFXColor( .2, .2, .2 ) );
435  showall->setVariableBorderCycleTime( 1.0 );
436  showall->setBorderColor( GFXColor( .2, .2, .2 ) );
437  showall->setEndBorderColor( GFXColor( .4, .4, .4 ) );
438  showall->setShadowWidth( 2.0 );
439  showall->setFont( Font( .08, BOLD_STROKE ) );
440  showall->setId( "ShowAll" );
441  showall->setLabel( "Show All" );
442  showall->setCommand( "ShowAll" );
443  listGroup->addChild( showall );
444 
445  NewButton *shownone = new NewButton;
446  shownone->setRect( Rect( -.15, .33, .35, .12 ) );
447  shownone->setColor( GFXColor( 0, 1, 1, .1 ) );
448  shownone->setTextColor( GUI_OPAQUE_WHITE() );
449  shownone->setDownColor( GFXColor( 0, 1, 1, .4 ) );
450  shownone->setDownTextColor( GFXColor( .2, .2, .2 ) );
451  shownone->setVariableBorderCycleTime( 1.0 );
452  shownone->setBorderColor( GFXColor( .2, .2, .2 ) );
453  shownone->setEndBorderColor( GFXColor( .4, .4, .4 ) );
454  shownone->setShadowWidth( 2.0 );
455  shownone->setFont( Font( .08, BOLD_STROKE ) );
456  shownone->setId( "ShowNone" );
457  shownone->setLabel( "Show None" );
458  shownone->setCommand( "ShowNone" );
459  listGroup->addChild( shownone );
460  }
461 
462  {
463  GroupControl *editGroup = new GroupControl;
464  editGroup->setId( displayModeInfo[EDIT].groupId );
465  window()->addControl( editGroup );
466  GFXColor color = getColorForGroup( displayModeInfo[EDIT].groupId );
467 
468  //Apply hint title.
469  StaticDisplay *applyHint = new StaticDisplay;
470  applyHint->setRect( Rect( -.96, .56, .26, .20 ) );
471  applyHint->setText( "Apply To:" );
472  applyHint->setTextColor( GFXColor( .4, 1, .4 ) );
473  applyHint->setColor( GUI_CLEAR );
474  applyHint->setFont( Font( .07, 1.75 ) );
475  applyHint->setId( "ApplyHint" );
476  editGroup->addChild( applyHint );
477 
478  NewButton *source = new NewButton;
479  source->setRect( Rect( -.66, .50, .40, .20 ) );
480  source->setColor( GFXColor( 0, 1, 1, .1 ) );
481  source->setTextColor( GUI_OPAQUE_WHITE() );
482  source->setDownColor( GFXColor( 0, 1, 1, .4 ) );
483  source->setDownTextColor( GFXColor( .2, .2, .2 ) );
484  source->setVariableBorderCycleTime( 1.0 );
485  source->setBorderColor( GFXColor( .2, .2, .2 ) );
486  source->setEndBorderColor( GFXColor( .4, .4, .4 ) );
487  source->setShadowWidth( 2.0 );
488  source->setFont( Font( .08, BOLD_STROKE ) );
489  source->setId( "Source" );
490  source->setLabel( "Source" );
491  source->setCommand( "Source" );
492  editGroup->addChild( source );
493 
494  NewButton *destination = new NewButton;
495  destination->setRect( Rect( -.20, .50, .40, .20 ) );
496  destination->setColor( GFXColor( 0, 1, 1, .1 ) );
497  destination->setTextColor( GUI_OPAQUE_WHITE() );
498  destination->setDownColor( GFXColor( 0, 1, 1, .4 ) );
499  destination->setDownTextColor( GFXColor( .2, .2, .2 ) );
500  destination->setVariableBorderCycleTime( 1.0 );
501  destination->setBorderColor( GFXColor( .2, .2, .2 ) );
502  destination->setEndBorderColor( GFXColor( .4, .4, .4 ) );
503  destination->setShadowWidth( 2.0 );
504  destination->setFont( Font( .08, BOLD_STROKE ) );
505  destination->setId( "Destination" );
506  destination->setLabel( "Destination" );
507  destination->setCommand( "Destination" );
508  editGroup->addChild( destination );
509 
510  NewButton *targetMode = new NewButton;
511  targetMode->setRect( Rect( -.96, .26, .22, .12 ) );
512  targetMode->setColor( GFXColor( 0, 1, 1, .1 ) );
513  targetMode->setTextColor( GUI_OPAQUE_WHITE() );
514  targetMode->setDownColor( GFXColor( 0, 1, 1, .4 ) );
515  targetMode->setDownTextColor( GFXColor( .2, .2, .2 ) );
516  targetMode->setVariableBorderCycleTime( 1.0 );
517  targetMode->setBorderColor( GFXColor( .2, .2, .2 ) );
518  targetMode->setEndBorderColor( GFXColor( .4, .4, .4 ) );
519  targetMode->setShadowWidth( 2.0 );
520  targetMode->setFont( Font( .08, BOLD_STROKE ) );
521  targetMode->setId( selectorModeInfo[TARGET].button );
522  targetMode->setLabel( selectorModeInfo[TARGET].button );
523  targetMode->setCommand( selectorModeInfo[TARGET].command );
524  editGroup->addChild( targetMode );
525 
526  NewButton *stringMode = new NewButton;
527  stringMode->setRect( Rect( -.96, -.04, .22, .12 ) );
528  stringMode->setColor( GFXColor( 0, 1, 1, .1 ) );
529  stringMode->setTextColor( GUI_OPAQUE_WHITE() );
530  stringMode->setDownColor( GFXColor( 0, 1, 1, .4 ) );
531  stringMode->setDownTextColor( GFXColor( .2, .2, .2 ) );
532  stringMode->setVariableBorderCycleTime( 1.0 );
533  stringMode->setBorderColor( GFXColor( .2, .2, .2 ) );
534  stringMode->setEndBorderColor( GFXColor( .4, .4, .4 ) );
535  stringMode->setShadowWidth( 2.0 );
536  stringMode->setFont( Font( .08, BOLD_STROKE ) );
537  stringMode->setId( selectorModeInfo[CRITERIA].button );
538  stringMode->setLabel( selectorModeInfo[CRITERIA].button );
539  stringMode->setCommand( selectorModeInfo[CRITERIA].command );
540  editGroup->addChild( stringMode );
541 
542  NewButton *chainMode = new NewButton;
543  chainMode->setRect( Rect( -.96, -.34, .22, .12 ) );
544  chainMode->setColor( GFXColor( 0, 1, 1, .1 ) );
545  chainMode->setTextColor( GUI_OPAQUE_WHITE() );
546  chainMode->setDownColor( GFXColor( 0, 1, 1, .4 ) );
547  chainMode->setDownTextColor( GFXColor( .2, .2, .2 ) );
548  chainMode->setVariableBorderCycleTime( 1.0 );
549  chainMode->setBorderColor( GFXColor( .2, .2, .2 ) );
550  chainMode->setEndBorderColor( GFXColor( .4, .4, .4 ) );
551  chainMode->setShadowWidth( 2.0 );
552  chainMode->setFont( Font( .08, BOLD_STROKE ) );
553  chainMode->setId( selectorModeInfo[CHAIN].button );
554  chainMode->setLabel( selectorModeInfo[CHAIN].button );
555  chainMode->setCommand( selectorModeInfo[CHAIN].command );
556  editGroup->addChild( chainMode );
557 
558  NewButton *finished = new NewButton;
559  finished->setRect( Rect( -.96, -.64, .22, .12 ) );
560  finished->setColor( GFXColor( 0, 1, 1, .1 ) );
561  finished->setTextColor( GUI_OPAQUE_WHITE() );
562  finished->setDownColor( GFXColor( 0, 1, 1, .4 ) );
563  finished->setDownTextColor( GFXColor( .2, .2, .2 ) );
564  finished->setVariableBorderCycleTime( 1.0 );
565  finished->setBorderColor( GFXColor( .2, .2, .2 ) );
566  finished->setEndBorderColor( GFXColor( .4, .4, .4 ) );
567  finished->setShadowWidth( 2.0 );
568  finished->setFont( Font( .08, BOLD_STROKE ) );
569  finished->setId( displayModeInfo[LIST].button );
570  finished->setLabel( displayModeInfo[LIST].button );
571  finished->setCommand( displayModeInfo[LIST].command );
572  editGroup->addChild( finished );
573 
574  //Scroller for description.
575  Scroller *descScroller = new Scroller;
576  descScroller->setRect( Rect( .91, -.95, .05, .62 ) );
577  descScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
578  descScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
579  descScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
580  descScroller->setTextColor( GUI_OPAQUE_WHITE() );
581  descScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
582 
583  //Description box.
584  StaticDisplay *ms = new StaticDisplay;
585  ms->setRect( Rect( .24, -.95, .67, .62 ) );
586  ms->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
588  ms->setFont( Font( .07 ) );
589  ms->setMultiLine( true );
591  ms->setTextMargins( Size( .02, .01 ) );
592  ms->setId( "NodeDescription" );
593  ms->setScroller( descScroller );
594  editGroup->addChild( ms );
595 
596  editGroup->addChild( descScroller ); //Want scroller "over" description box.
597  }
598 
599  {
600  GroupControl *targetGroup = new GroupControl;
601  targetGroup->setId( selectorModeInfo[TARGET].groupId );
602  window()->addControl( targetGroup );
603  GFXColor color = getColorForGroup( selectorModeInfo[TARGET].groupId );
604 
605  NewButton *absolute = new NewButton;
606  absolute->setRect( Rect( -.56, .26, .61, .12 ) );
607  absolute->setColor( GFXColor( 0, 1, 1, .1 ) );
608  absolute->setTextColor( GUI_OPAQUE_WHITE() );
609  absolute->setDownColor( GFXColor( 0, 1, 1, .4 ) );
610  absolute->setDownTextColor( GFXColor( .2, .2, .2 ) );
611  absolute->setVariableBorderCycleTime( 1.0 );
612  absolute->setBorderColor( GFXColor( .2, .2, .2 ) );
613  absolute->setEndBorderColor( GFXColor( .4, .4, .4 ) );
614  absolute->setShadowWidth( 2.0 );
615  absolute->setFont( Font( .08, BOLD_STROKE ) );
616  absolute->setId( "Absolute" );
617  absolute->setLabel( "ERROR" );
618  absolute->setCommand( "Absolute" );
619  targetGroup->addChild( absolute );
620 
621  NewButton *target = new NewButton;
622  target->setRect( Rect( -.56, .10, .61, .12 ) );
623  target->setColor( GFXColor( 0, 1, 1, .1 ) );
624  target->setTextColor( GUI_OPAQUE_WHITE() );
625  target->setDownColor( GFXColor( 0, 1, 1, .4 ) );
626  target->setDownTextColor( GFXColor( .2, .2, .2 ) );
627  target->setVariableBorderCycleTime( 1.0 );
628  target->setBorderColor( GFXColor( .2, .2, .2 ) );
629  target->setEndBorderColor( GFXColor( .4, .4, .4 ) );
630  target->setShadowWidth( 2.0 );
631  target->setFont( Font( .08, BOLD_STROKE ) );
632  target->setId( "Target" );
633  target->setLabel( "Target" );
634  target->setCommand( "Target" );
635  targetGroup->addChild( target );
636 
637  NewButton *current = new NewButton;
638  current->setRect( Rect( -.56, -.06, .61, .12 ) );
639  current->setColor( GFXColor( 0, 1, 1, .1 ) );
640  current->setTextColor( GUI_OPAQUE_WHITE() );
641  current->setDownColor( GFXColor( 0, 1, 1, .4 ) );
642  current->setDownTextColor( GFXColor( .2, .2, .2 ) );
643  current->setVariableBorderCycleTime( 1.0 );
644  current->setBorderColor( GFXColor( .2, .2, .2 ) );
645  current->setEndBorderColor( GFXColor( .4, .4, .4 ) );
646  current->setShadowWidth( 2.0 );
647  current->setFont( Font( .08, BOLD_STROKE ) );
648  current->setId( "Current" );
649  current->setLabel( "Current" );
650  current->setCommand( "Current" );
651  targetGroup->addChild( current );
652  }
653 
654  {
655  GroupControl *criteriaGroup = new GroupControl;
656  criteriaGroup->setId( selectorModeInfo[CRITERIA].groupId );
657  window()->addControl( criteriaGroup );
658  GFXColor color = getColorForGroup( selectorModeInfo[CRITERIA].groupId );
659 
660  //Scroller for picker.
661  Scroller *parameterScroller = new Scroller;
662  parameterScroller->setRect( Rect( .15, .15, .05, .23 ) );
663  parameterScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
664  parameterScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
665  parameterScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
666  parameterScroller->setTextColor( GUI_OPAQUE_WHITE() );
667  parameterScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
668 
669  //Parameter picker.
670  SimplePicker *parameterList = new SimplePicker;
671  parameterList->setRect( Rect( -.66, .15, .81, .23 ) );
672  parameterList->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
673  parameterList->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
674  parameterList->setTextColor( GUI_OPAQUE_WHITE() );
675  parameterList->setSelectionColor( GFXColor( 0, .6, 0, .8 ) );
676  parameterList->setHighlightColor( GFXColor( 0, .6, 0, .35 ) );
677  parameterList->setHighlightTextColor( GUI_OPAQUE_WHITE() );
678  parameterList->setFont( Font( .07 ) );
679  parameterList->setTextMargins( Size( 0.02, 0.01 ) );
680  parameterList->setId( "ParameterLister" );
681  parameterList->setScroller( parameterScroller );
682  criteriaGroup->addChild( parameterList );
683  parameterList->clear();
684  parameterList->addCell( new ValuedPickerCell< CriteriaType > ( CONTAINS, "Contains" ) );
685  parameterList->addCell( new ValuedPickerCell< CriteriaType > ( OWNEDBY, "Owned By" ) );
686  parameterList->addCell( new ValuedPickerCell< CriteriaType > ( SECTOR, "Sector" ) );
687 
688  criteriaGroup->addChild( parameterScroller ); //Want scroller "over" picker.
689 
690  //Parameter value box.
691  StaticDisplay *valueBox = new TextInputDisplay( &nav_keyboard_queue, "\x1b\n\t\r\\/&|:<>\"^" );
692  valueBox->setRect( Rect( -.66, .01, .86, .10 ) );
693  valueBox->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
695  valueBox->setFont( Font( .07 ) );
696  valueBox->setMultiLine( true );
697  valueBox->setTextColor( GUI_OPAQUE_WHITE() );
698  valueBox->setTextMargins( Size( .02, .01 ) );
699  valueBox->setId( "ParameterValueBox" );
700  criteriaGroup->addChild( valueBox );
701 
702  NewButton *andButton = new NewButton;
703  andButton->setRect( Rect( -.66, -.15, .22, .12 ) );
704  andButton->setColor( GFXColor( 0, 1, 1, .1 ) );
705  andButton->setTextColor( GUI_OPAQUE_WHITE() );
706  andButton->setDownColor( GFXColor( 0, 1, 1, .4 ) );
707  andButton->setDownTextColor( GFXColor( .2, .2, .2 ) );
708  andButton->setVariableBorderCycleTime( 1.0 );
709  andButton->setBorderColor( GFXColor( .2, .2, .2 ) );
710  andButton->setEndBorderColor( GFXColor( .4, .4, .4 ) );
711  andButton->setShadowWidth( 2.0 );
712  andButton->setFont( Font( .08, BOLD_STROKE ) );
713  andButton->setId( "And" );
714  andButton->setLabel( "And" );
715  andButton->setCommand( "And" );
716  criteriaGroup->addChild( andButton );
717 
718  NewButton *orButton = new NewButton;
719  orButton->setRect( Rect( -.34, -.15, .22, .12 ) );
720  orButton->setColor( GFXColor( 0, 1, 1, .1 ) );
721  orButton->setTextColor( GUI_OPAQUE_WHITE() );
722  orButton->setDownColor( GFXColor( 0, 1, 1, .4 ) );
723  orButton->setDownTextColor( GFXColor( .2, .2, .2 ) );
724  orButton->setVariableBorderCycleTime( 1.0 );
725  orButton->setBorderColor( GFXColor( .2, .2, .2 ) );
726  orButton->setEndBorderColor( GFXColor( .4, .4, .4 ) );
727  orButton->setShadowWidth( 2.0 );
728  orButton->setFont( Font( .08, BOLD_STROKE ) );
729  orButton->setId( "Or" );
730  orButton->setLabel( "Or" );
731  orButton->setCommand( "Or" );
732  criteriaGroup->addChild( orButton );
733 
734  NewButton *notButton = new NewButton;
735  notButton->setRect( Rect( -.02, -.15, .22, .12 ) );
736  notButton->setColor( GFXColor( 0, 1, 1, .1 ) );
737  notButton->setTextColor( GUI_OPAQUE_WHITE() );
738  notButton->setDownColor( GFXColor( 0, 1, 1, .4 ) );
739  notButton->setDownTextColor( GFXColor( .2, .2, .2 ) );
740  notButton->setVariableBorderCycleTime( 1.0 );
741  notButton->setBorderColor( GFXColor( .2, .2, .2 ) );
742  notButton->setEndBorderColor( GFXColor( .4, .4, .4 ) );
743  notButton->setShadowWidth( 2.0 );
744  notButton->setFont( Font( .08, BOLD_STROKE ) );
745  notButton->setId( "Not" );
746  notButton->setLabel( "Not" );
747  notButton->setCommand( "Not" );
748  criteriaGroup->addChild( notButton );
749 
750  NewButton *removeButton = new NewButton;
751  removeButton->setRect( Rect( -.20, -.31, .40, .12 ) );
752  removeButton->setColor( GFXColor( 0, 1, 1, .1 ) );
753  removeButton->setTextColor( GUI_OPAQUE_WHITE() );
754  removeButton->setDownColor( GFXColor( 0, 1, 1, .4 ) );
755  removeButton->setDownTextColor( GFXColor( .2, .2, .2 ) );
756  removeButton->setVariableBorderCycleTime( 1.0 );
757  removeButton->setBorderColor( GFXColor( .2, .2, .2 ) );
758  removeButton->setEndBorderColor( GFXColor( .4, .4, .4 ) );
759  removeButton->setShadowWidth( 2.0 );
760  removeButton->setFont( Font( .08, BOLD_STROKE ) );
761  removeButton->setId( "RemoveCriteria" );
762  removeButton->setLabel( "Remove" );
763  removeButton->setCommand( "RemoveCriteria" );
764  criteriaGroup->addChild( removeButton );
765 
766  //Scroller for picker.
767  Scroller *criteriaScroller = new Scroller;
768  criteriaScroller->setRect( Rect( .15, -.95, .05, .60 ) );
769  criteriaScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
770  criteriaScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
771  criteriaScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
772  criteriaScroller->setTextColor( GUI_OPAQUE_WHITE() );
773  criteriaScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
774 
775  //Criteria picker.
776  SimplePicker *criteriaList = new SimplePicker;
777  criteriaList->setRect( Rect( -.66, -.95, .81, .60 ) );
778  criteriaList->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
779  criteriaList->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
780  criteriaList->setTextColor( GUI_OPAQUE_WHITE() );
781  criteriaList->setSelectionColor( GFXColor( 0, .6, 0, .8 ) );
782  criteriaList->setHighlightColor( GFXColor( 0, .6, 0, .35 ) );
783  criteriaList->setHighlightTextColor( GUI_OPAQUE_WHITE() );
784  criteriaList->setFont( Font( .07 ) );
785  criteriaList->setTextMargins( Size( 0.02, 0.01 ) );
786  criteriaList->setId( "CriteriaLister" );
787  criteriaList->setScroller( criteriaScroller );
788  criteriaGroup->addChild( criteriaList );
789 
790  criteriaGroup->addChild( criteriaScroller ); //Want scroller "over" picker.
791  }
792 
793  {
794  GroupControl *chainGroup = new GroupControl;
795  chainGroup->setId( selectorModeInfo[CHAIN].groupId );
796  window()->addControl( chainGroup );
797  GFXColor color = getColorForGroup( selectorModeInfo[CHAIN].groupId );
798 
799  //Scroller for picker.
800  Scroller *chainScroller = new Scroller;
801  chainScroller->setRect( Rect( .15, -.31, .05, .69 ) );
802  chainScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
803  chainScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
804  chainScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
805  chainScroller->setTextColor( GUI_OPAQUE_WHITE() );
806  chainScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
807 
808  //Path picker.
809  SimplePicker *chainList = new SimplePicker;
810  chainList->setRect( Rect( -.66, -.31, .81, .69 ) );
811  chainList->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
812  chainList->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
813  chainList->setTextColor( GUI_OPAQUE_WHITE() );
814  chainList->setSelectionColor( GFXColor( 0, .6, 0, .8 ) );
815  chainList->setHighlightColor( GFXColor( 0, .6, 0, .35 ) );
816  chainList->setHighlightTextColor( GUI_OPAQUE_WHITE() );
817  chainList->setFont( Font( .07 ) );
818  chainList->setTextMargins( Size( 0.02, 0.01 ) );
819  chainList->setId( "ChainLister" );
820  chainList->setScroller( chainScroller );
821  chainGroup->addChild( chainList );
822 
823  chainGroup->addChild( chainScroller ); //Want scroller "over" picker.
824 
825  //Scroller for picker.
826  Scroller *chainTypeScroller = new Scroller;
827  chainTypeScroller->setRect( Rect( .15, -.79, .05, .44 ) );
828  chainTypeScroller->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
829  chainTypeScroller->setThumbColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ), GUI_OPAQUE_WHITE() );
830  chainTypeScroller->setButtonColor( GFXColor( color.r*.4, color.g*.4, color.b*.4 ) );
831  chainTypeScroller->setTextColor( GUI_OPAQUE_WHITE() );
832  chainTypeScroller->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
833 
834  //Type picker.
835  SimplePicker *chainTypeList = new SimplePicker;
836  chainTypeList->setRect( Rect( -.66, -.79, .81, .44 ) );
837  chainTypeList->setColor( GFXColor( color.r, color.g, color.b, .1 ) );
838  chainTypeList->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
839  chainTypeList->setTextColor( GUI_OPAQUE_WHITE() );
840  chainTypeList->setSelectionColor( GFXColor( 0, .6, 0, .8 ) );
841  chainTypeList->setHighlightColor( GFXColor( 0, .6, 0, .35 ) );
842  chainTypeList->setHighlightTextColor( GUI_OPAQUE_WHITE() );
843  chainTypeList->setFont( Font( .07 ) );
844  chainTypeList->setTextMargins( Size( 0.02, 0.01 ) );
845  chainTypeList->setId( "ChainTypeLister" );
846  chainTypeList->setScroller( chainTypeScroller );
847  chainGroup->addChild( chainTypeList );
848  chainTypeList->clear();
850  chainTypeList->addCell( new ValuedPickerCell< ChainPathNode::PartType > ( ChainPathNode::DESTINATION, "Destination" ) );
851  chainTypeList->addCell( new ValuedPickerCell< ChainPathNode::PartType > ( ChainPathNode::ALL_POINTS, "All Points" ) );
852 
853  chainGroup->addChild( chainTypeScroller ); //Want scroller "over" picker.
854 
855  NewButton *chain = new NewButton;
856  chain->setRect( Rect( -.43, -.95, .40, .12 ) );
857  chain->setColor( GFXColor( 0, 1, 1, .1 ) );
858  chain->setTextColor( GUI_OPAQUE_WHITE() );
859  chain->setDownColor( GFXColor( 0, 1, 1, .4 ) );
860  chain->setDownTextColor( GFXColor( .2, .2, .2 ) );
861  chain->setVariableBorderCycleTime( 1.0 );
862  chain->setBorderColor( GFXColor( .2, .2, .2 ) );
863  chain->setEndBorderColor( GFXColor( .4, .4, .4 ) );
864  chain->setShadowWidth( 2.0 );
865  chain->setFont( Font( .08, BOLD_STROKE ) );
866  chain->setId( "Chain" );
867  chain->setLabel( "Chain" );
868  chain->setCommand( "Chain" );
869  chainGroup->addChild( chain );
870  }
871 }
872 
873 //Switch to the set of controls used for the specified mode.
875 {
876  if (m_currentDisplay != mode) {
877  assert( m_displayModeGroups[mode] != NULL ); //We should have controls for this mode.
879  //Get the old controls out of the window.
880  Control *oldControls = window()->findControlById( displayModeInfo[m_currentDisplay].groupId );
881  if (oldControls)
882  window()->removeControlFromWindow( oldControls );
883  //We put this back in our table so that we "own" the controls.
884  m_displayModeGroups[m_currentDisplay] = oldControls;
885  }
886  m_currentDisplay = mode;
887 
889  //Take this group out of our table because we don't own it anymore.
890  m_displayModeGroups[mode] = NULL;
891 
892  recalcTitle();
893  }
894 }
895 
896 //Switch to the set of controls used for the specified mode.
898 {
899  if (m_currentSelector != mode) {
901  //Get the old controls out of the window.
902  Control *oldControls = window()->findControlById( selectorModeInfo[m_currentSelector].groupId );
903  if (oldControls)
904  window()->removeControlFromWindow( oldControls );
905  //We put this back in our table so that we "own" the controls.
907  }
908  m_currentSelector = mode;
909  if (mode != NULL_SELECTOR) {
910  assert( m_selectorModeGroups[mode] != NULL ); //We should have controls for this mode.
912  //Take this group out of our table because we don't own it anymore.
913  m_selectorModeGroups[mode] = NULL;
914  }
915  }
916 }
917 
918 //Change display mode to LIST
919 bool NavComputer::changeToListMode( const EventCommandId &command, Control *control )
920 {
921  if (m_currentDisplay != LIST) {
924  loadPathLister();
925  }
926  return true;
927 }
928 
929 //Change display mode to EDIT
930 bool NavComputer::changeToEditMode( const EventCommandId &command, Control *control )
931 {
932  if (m_currentDisplay != EDIT && currentPath != NULL) {
935  setCurrentNode();
936  criteria = false;
937  }
938  return true;
939 }
940 
941 //Change display mode to TARGET
943 {
944  assert( m_currentDisplay == EDIT ); //We should be in edit mode to have chosen a selector
945  if (m_currentSelector != TARGET) {
948  }
949  return true;
950 }
951 
952 //Change display mode to CRITERIA
954 {
955  assert( m_currentDisplay == EDIT ); //We should be in edit mode to have chosen a selector
956  if (m_currentSelector != CRITERIA) {
959  }
960  return true;
961 }
962 
963 //Change display mode to CHAIN
964 bool NavComputer::changeToChainMode( const EventCommandId &command, Control *control )
965 {
966  assert( m_currentDisplay == EDIT ); //We should be in edit mode to have chosen a selector
967  if (m_currentSelector != CHAIN) {
969  loadChainLister();
970  }
971  return true;
972 }
973 
974 //Open the window, etc.
975 void NavComputer::run( void )
976 {
977  toggleVisibility( EventCommandId(), NULL );
978 }
979 
981 {
982  GFXBeginScene();
984  GFXEndScene();
985 }
986 
987 int shiftup( int );
988 static void nav_keyboard_cb( unsigned int ch, unsigned int mod, bool release, int x, int y )
989 {
990  if (!release) {
991  nav_keyboard_queue.push_back(
992  ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) ) || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ? shiftup(
993  ch ) : ch );
994  }
995 }
996 
997 bool NavComputer::toggleVisibility( const EventCommandId &command, Control *control )
998 {
999  if (m_visible) {
1000  m_window->close();
1001  m_visible = false;
1002 
1003  pathman->updatePaths();
1004 
1005  RestoreKB();
1006  GFXLoop( main_loop );
1007  RestoreMouse();
1008 
1010  } else {
1012  //Initialize callback functions
1017  m_window->open();
1018  m_visible = true;
1020 
1021  //Simulate clicking the leftmost mode button.
1022  //We don't actually use the button because there isn't a button if there's only one mode.
1023  processWindowCommand( displayModeInfo[m_displayModes[0]].command, NULL );
1024  }
1025  return m_visible;
1026 }
1027 
1028 //Redo the title strings for the display.
1030 {
1031  //Generic nav title for the display.
1032 
1033  string baseTitle = "Navigational Computer";
1034  baseTitle += " (";
1035  baseTitle += displayModeInfo[m_currentDisplay].title;
1036  baseTitle += ")";
1037 
1038  //Set the string in the base title control.
1039  StaticDisplay *baseTitleDisplay = static_cast< StaticDisplay* > ( window()->findControlById( "NavigationTitle" ) );
1040  assert( baseTitleDisplay != NULL );
1041  baseTitleDisplay->setText( baseTitle );
1042 }
1043 
1044 //Create the window and controls for the Options Menu.
1046 {
1047  Window *window = new Window;
1048  setWindow( window );
1049 
1050  window->setSizeAndCenter( Size( .9, .62 ) );
1051  window->setTexture( "basecomputer.png" );
1052  window->setColor( GFXColor( 0, 1, 0, .1 ) );
1053  window->setOutlineColor( GFXColor( .7, .7, .7 ) );
1054  window->setOutlineWidth( 2.0 );
1055  window->setController( this );
1056 
1057  //Information.
1058  StaticDisplay *text = new StaticDisplay;
1059  text->setRect( Rect( -.4, .11, .8, .15 ) );
1060  text->setText( "Enter the new name for this path." );
1061  text->setTextColor( GFXColor( .7, 1, .4 ) );
1062  text->setMultiLine( true );
1063  text->setColor( GUI_CLEAR );
1064  text->setFont( Font( .07, 1.25 ) );
1065  text->setId( "Information" );
1066  //Put it on the window.
1067  window->addControl( text );
1068 
1069  //Path name input box.
1070  StaticDisplay *pathNameBox = new TextInputDisplay( &nav_keyboard_queue, "\x1b\n\t\r" );
1071  pathNameBox->setRect( Rect( -.4, -.09, .8, .15 ) );
1072  pathNameBox->setColor( GFXColor( 0, 1, 1, .1 ) );
1073  pathNameBox->setOutlineColor( GUI_OPAQUE_MEDIUM_GRAY() );
1074  pathNameBox->setFont( Font( .07 ) );
1075  pathNameBox->setMultiLine( true );
1076  pathNameBox->setTextColor( GUI_OPAQUE_WHITE() );
1077  pathNameBox->setTextMargins( Size( .02, .01 ) );
1078  pathNameBox->setId( "PathNameBox" );
1079  window->addControl( pathNameBox );
1080 
1081  //Confirm Button.
1082  NewButton *confirm = new NewButton;
1083  confirm->setRect( Rect( .05, -.25, .30, .10 ) );
1084  confirm->setLabel( "Rename" );
1085  confirm->setCommand( "Rename" );
1086  confirm->setColor( GFXColor( 1, .5, 0, .25 ) );
1087  confirm->setTextColor( GUI_OPAQUE_WHITE() );
1088  confirm->setDownColor( GFXColor( 1, .5, 0, .6 ) );
1089  confirm->setDownTextColor( GUI_OPAQUE_BLACK() );
1090  confirm->setHighlightColor( GFXColor( 0, 1, 0, .4 ) );
1091  confirm->setFont( Font( .08, BOLD_STROKE ) );
1092  //Put the button on the window.
1093  window->addControl( confirm );
1094 
1095  //Resume Game button.
1096  NewButton *resume = new NewButton;
1097  resume->setRect( Rect( -.35, -.26, .30, .12 ) );
1098  resume->setLabel( "Cancel" );
1099  resume->setCommand( "Window::Close" );
1100  resume->setColor( GFXColor( 0, 1, 0, .25 ) );
1101  resume->setTextColor( GUI_OPAQUE_WHITE() );
1102  resume->setDownColor( GFXColor( 0, 1, 0, .6 ) );
1103  resume->setDownTextColor( GUI_OPAQUE_BLACK() );
1104  resume->setHighlightColor( GFXColor( 0, 1, 0, .4 ) );
1105  resume->setFont( Font( .08, BOLD_STROKE ) );
1106  //Put the button on the window.
1107  window->addControl( resume );
1108 
1109  window->setModal( true );
1110 }
1111 
1112 //Process a command event from the Options Menu window.
1114 {
1115  if (command == "Rename") {
1116  TextInputDisplay *input = static_cast< TextInputDisplay* > ( window()->findControlById( "PathNameBox" ) );
1117  assert( input != NULL );
1118  m_parent->actionRenameConfirmed( input->text() );
1119  window()->close();
1120  } else {
1121  //Not a command we know about.
1122  return WindowController::processWindowCommand( command, control );
1123  }
1124  return true;
1125 }
1126 
1127 //Load the paths to be put in the lister.
1129 {
1130  SimplePicker *listPicker = static_cast< SimplePicker* > ( window()->findControlById( "PathLister" ) );
1131  assert( listPicker != NULL );
1132  listPicker->clear();
1133 
1134  currentPath = NULL;
1135  for (vector< NavPath* >::iterator i = pathman->paths.begin(); i < pathman->paths.end(); ++i)
1136  listPicker->addCell( new ValuedPickerCell< NavPath* > ( (*i), (*i)->getName() ) );
1137  //Make sure the description is empty.
1138  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
1139  assert( desc != NULL );
1140  desc->setText( "" );
1141 }
1142 
1143 //Load the paths to be put in the lister.
1145 {
1146  SimplePicker *chainPicker = static_cast< SimplePicker* > ( window()->findControlById( "ChainLister" ) );
1147  assert( chainPicker != NULL );
1148  chainPicker->clear();
1149  for (vector< NavPath* >::iterator i = pathman->paths.begin(); i < pathman->paths.end(); ++i)
1150  chainPicker->addCell( new ValuedPickerCell< NavPath* > ( (*i), (*i)->getName() ) );
1151 }
1152 
1154 {
1155  assert( node != NULL );
1156  ValuedPickerCell< CriteriaNode* > *cell = new ValuedPickerCell< CriteriaNode* > ( node, node->getText() );
1157  cell->setHideChildren( false );
1158  if (parent) {
1159  parent->addChild( cell );
1160  } else {
1161  assert( picker != NULL );
1162  picker->addCell( cell );
1163  }
1164  vector< CriteriaNode* >childList = node->getChildren();
1165  for (vector< CriteriaNode* >::iterator i = childList.begin(); i < childList.end(); ++i)
1166  loadCriteriaPickerCell( picker, cell, (*i) );
1167 }
1168 
1169 //Load the criteria to be put in the lister.
1171 {
1172  SimplePicker *picker = static_cast< SimplePicker* > ( window()->findControlById( "CriteriaLister" ) );
1173  assert( picker != NULL );
1174  picker->clear();
1175  if (criteria)
1176  if ( static_cast< CriteriaPathNode* > (currentNode)->getRoot()->getChild() )
1177  loadCriteriaPickerCell( picker, NULL, static_cast< CriteriaPathNode* > (currentNode)->getRoot()->getChild() );
1178 }
1179 
1180 //Load the absolute button.
1182 {
1183  NewButton *absolute = static_cast< NewButton* > ( window()->findControlById( "Absolute" ) );
1184  assert( absolute != NULL );
1185  absolute->setLabel( navsys->systemIter[navsys->systemselectionindex].GetName() );
1186 }
1187 
1189 {
1190  if (currentNode)
1191  delete currentNode;
1192  currentNode = source;
1194  return true;
1195 }
1196 
1198 {
1199  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "Description" ) );
1200  assert( desc != NULL );
1201  if (currentPath)
1202  desc->setText( currentPath->getDescription() );
1203  else
1204  desc->setText( "" );
1205 }
1206 
1208 {
1209  StaticDisplay *desc = static_cast< StaticDisplay* > ( window()->findControlById( "NodeDescription" ) );
1210  assert( desc != NULL );
1211  if (currentNode)
1212  desc->setText( currentNode->getDescription() );
1213  else
1214  desc->setText( "" );
1215 }
1216 
1217 //The selection in the Path lister changed.
1219 {
1220  assert( control != NULL );
1221  Picker *picker = static_cast< Picker* > (control);
1222  ValuedPickerCell< NavPath* > *cell = static_cast< ValuedPickerCell< NavPath* >* > ( picker->selectedCell() );
1223  if (cell == NULL)
1224  currentPath = NULL;
1225  else
1226  currentPath = cell->value();
1228 
1229  return true;
1230 }
1231 
1232 bool NavComputer::actionAdd( const EventCommandId &command, Control *control )
1233 {
1234  pathman->addPath();
1235  loadPathLister();
1236  return true;
1237 }
1238 
1239 bool NavComputer::actionShowPath( const EventCommandId &command, Control *control )
1240 {
1241  if (currentPath)
1244  return true;
1245 }
1246 
1247 bool NavComputer::actionRename( const EventCommandId &command, Control *control )
1248 {
1249  if (currentPath) {
1250  RenameConfirm *renamer = new RenameConfirm( this );
1251  renamer->init();
1252  renamer->run();
1253  }
1254  return true;
1255 }
1256 
1257 bool NavComputer::actionRemove( const EventCommandId &command, Control *control )
1258 {
1259  if (currentPath)
1261  loadPathLister();
1262  return true;
1263 }
1264 
1265 bool NavComputer::actionShowAll( const EventCommandId &command, Control *control )
1266 {
1267  pathman->showAll();
1269  return true;
1270 }
1271 
1272 bool NavComputer::actionShowNone( const EventCommandId &command, Control *control )
1273 {
1274  pathman->showNone();
1276  return true;
1277 }
1278 
1279 bool NavComputer::actionSource( const EventCommandId &command, Control *control )
1280 {
1281  if (currentNode) {
1282  assert( currentPath );
1285  }
1286  return true;
1287 }
1288 
1290 {
1291  if (currentNode) {
1292  assert( currentPath );
1295  }
1296  return true;
1297 }
1298 
1299 bool NavComputer::actionCurrent( const EventCommandId &command, Control *control )
1300 {
1302  criteria = false;
1303  return true;
1304 }
1305 
1306 bool NavComputer::actionTarget( const EventCommandId &command, Control *control )
1307 {
1308  setCurrentNode( new TargetPathNode() );
1309  criteria = false;
1310  return true;
1311 }
1312 
1313 bool NavComputer::actionAbsolute( const EventCommandId &command, Control *control )
1314 {
1315  setCurrentNode( new AbsolutePathNode( navsys->systemselectionindex ) );
1316  criteria = false;
1317  return true;
1318 }
1319 
1320 bool NavComputer::actionAnd( const EventCommandId &command, Control *control )
1321 {
1322  Picker *parameterPicker = static_cast< Picker* > ( window()->findControlById( "ParameterLister" ) );
1323  assert( parameterPicker != NULL );
1324 
1325  Picker *criteriaPicker = static_cast< Picker* > ( window()->findControlById( "CriteriaLister" ) );
1326  assert( criteriaPicker != NULL );
1327 
1328  TextInputDisplay *input = static_cast< TextInputDisplay* > ( window()->findControlById( "ParameterValueBox" ) );
1329  assert( input != NULL );
1330  if (input->text() == "")
1331  return true;
1332  ValuedPickerCell< CriteriaType > *parameterCell =
1333  static_cast< ValuedPickerCell< CriteriaType >* > ( parameterPicker->selectedCell() );
1334  ValuedPickerCell< CriteriaNode* > *criteriaCell =
1335  static_cast< ValuedPickerCell< CriteriaNode* >* > ( criteriaPicker->selectedCell() );
1336  if (parameterCell == NULL)
1337  return true;
1338  if (!criteria) {
1340  criteria = true;
1341  }
1342  CriteriaNode *newNode;
1343  if (parameterCell->value() == CONTAINS)
1344  newNode = new CriteriaContains( input->text() );
1345  else if (parameterCell->value() == OWNEDBY)
1346  newNode = new CriteriaOwnedBy( input->text() );
1347  else
1348  newNode = new CriteriaSector( input->text() );
1349  if (static_cast< CriteriaPathNode* > (currentNode)->getRoot()->getChild() == NULL) {
1350  static_cast< CriteriaPathNode* > (currentNode)->getRoot()->setChild( newNode );
1351  } else {
1352  if (criteriaCell == NULL)
1353  return true;
1354  new CriteriaAnd( criteriaCell->value(), newNode );
1355  }
1358  return true;
1359 }
1360 
1361 bool NavComputer::actionOr( const EventCommandId &command, Control *control )
1362 {
1363  Picker *parameterPicker = static_cast< Picker* > ( window()->findControlById( "ParameterLister" ) );
1364  assert( parameterPicker != NULL );
1365 
1366  Picker *criteriaPicker = static_cast< Picker* > ( window()->findControlById( "CriteriaLister" ) );
1367  assert( criteriaPicker != NULL );
1368 
1369  TextInputDisplay *input = static_cast< TextInputDisplay* > ( window()->findControlById( "ParameterValueBox" ) );
1370  assert( input != NULL );
1371  if (input->text() == "")
1372  return true;
1373  ValuedPickerCell< CriteriaType > *parameterCell =
1374  static_cast< ValuedPickerCell< CriteriaType >* > ( parameterPicker->selectedCell() );
1375  ValuedPickerCell< CriteriaNode* > *criteriaCell =
1376  static_cast< ValuedPickerCell< CriteriaNode* >* > ( criteriaPicker->selectedCell() );
1377  if (parameterCell == NULL)
1378  return true;
1379  if (!criteria) {
1381  criteria = true;
1382  }
1383  CriteriaNode *newNode;
1384  if (parameterCell->value() == CONTAINS)
1385  newNode = new CriteriaContains( input->text() );
1386  else if (parameterCell->value() == OWNEDBY)
1387  newNode = new CriteriaOwnedBy( input->text() );
1388  else
1389  newNode = new CriteriaSector( input->text() );
1390  if (static_cast< CriteriaPathNode* > (currentNode)->getRoot()->getChild() == NULL) {
1391  static_cast< CriteriaPathNode* > (currentNode)->getRoot()->setChild( newNode );
1392  } else {
1393  if (criteriaCell == NULL)
1394  return true;
1395  new CriteriaOr( criteriaCell->value(), newNode );
1396  }
1399  return true;
1400 }
1401 
1402 bool NavComputer::actionNot( const EventCommandId &command, Control *control )
1403 {
1404  Picker *criteriaPicker = static_cast< Picker* > ( window()->findControlById( "CriteriaLister" ) );
1405  assert( criteriaPicker != NULL );
1406  ValuedPickerCell< CriteriaNode* > *criteriaCell =
1407  static_cast< ValuedPickerCell< CriteriaNode* >* > ( criteriaPicker->selectedCell() );
1408  if (criteriaCell == NULL)
1409  return true;
1410  assert( criteriaCell->value() != NULL );
1411  new CriteriaNot( criteriaCell->value() );
1412 
1415  return true;
1416 }
1417 
1419 {
1420  Picker *criteriaPicker = static_cast< Picker* > ( window()->findControlById( "CriteriaLister" ) );
1421  assert( criteriaPicker != NULL );
1422  ValuedPickerCell< CriteriaNode* > *criteriaCell =
1423  static_cast< ValuedPickerCell< CriteriaNode* >* > ( criteriaPicker->selectedCell() );
1424  if (criteriaCell == NULL)
1425  return true;
1426  CriteriaNode *deleteHere = criteriaCell->value()->unhook();
1427  if (deleteHere)
1428  delete deleteHere;
1431  return true;
1432 }
1433 
1434 bool NavComputer::actionChain( const EventCommandId &command, Control *control )
1435 {
1436  Picker *pathPicker = static_cast< Picker* > ( window()->findControlById( "ChainLister" ) );
1437  assert( pathPicker != NULL );
1438 
1439  Picker *typePicker = static_cast< Picker* > ( window()->findControlById( "ChainTypeLister" ) );
1440  assert( typePicker != NULL );
1441 
1442  ValuedPickerCell< NavPath* > *pathCell = static_cast< ValuedPickerCell< NavPath* >* > ( pathPicker->selectedCell() );
1444  static_cast< ValuedPickerCell< ChainPathNode::PartType >* > ( typePicker->selectedCell() );
1445  if (!pathCell || !typeCell)
1446  return true;
1447  setCurrentNode( new ChainPathNode( pathCell->value(), typeCell->value() ) );
1448  criteria = false;
1449  return true;
1450 }
1451 
1452 void NavComputer::actionRenameConfirmed( std::string name )
1453 {
1454  assert( currentPath != NULL );
1455 
1456  currentPath->setName( name );
1457  loadPathLister();
1458 }
1459