]> git.mxchange.org Git - flightgear.git/blob - src/GUI/apt_dlg.cxx
Norman's changes to display a scrolling "PAUSE" message when the simulation
[flightgear.git] / src / GUI / apt_dlg.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <simgear/compiler.h>
6
7 #ifdef HAVE_WINDOWS_H
8 #  include <windows.h>
9 #endif
10
11 #include <stdlib.h>
12
13 #include <simgear/constants.h>
14 #include <simgear/debug/logstream.hxx>
15 #include <simgear/misc/sg_path.hxx>
16
17 #include <Include/general.hxx>
18
19 #include <GL/glut.h>
20 #include <GL/gl.h>
21
22 #include <Airports/simple.hxx>
23 #include <FDM/flight.hxx>
24 #include <Main/fg_init.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Main/globals.hxx>
27 #include <Scenery/tilemgr.hxx>
28
29 #include "gui.h"
30 #include "gui_local.hxx"
31
32 /// The beginnings of teleportation :-)
33 //  Needs cleaning up but works
34 //  These statics should disapear when this is a class
35 static puDialogBox     *AptDialog = 0;
36 static puFrame         *AptDialogFrame = 0;
37 static puText          *AptDialogMessage = 0;
38 static puInput         *AptDialogInput = 0;
39
40 static char NewAirportId[16];
41 static char NewAirportLabel[] = "Enter New Airport ID"; 
42
43 static puOneShot       *AptDialogOkButton = 0;
44 static puOneShot       *AptDialogCancelButton = 0;
45 static puOneShot       *AptDialogResetButton = 0;
46
47 void AptDialog_Cancel(puObject *)
48 {
49     FG_POP_PUI_DIALOG( AptDialog );
50 }
51
52 void AptDialog_OK (puObject *)
53 {
54     static const SGPropertyNode *longitude
55         = fgGetNode("/position/longitude-deg");
56     static const SGPropertyNode *latitude
57         = fgGetNode("/position/latitude-deg");
58
59     SGPath path( globals->get_fg_root() );
60     path.append( "Airports" );
61     path.append( "simple.mk4" );
62     FGAirports airports( path.c_str() );
63
64     FGAirport a;
65
66     int freeze = globals->get_freeze();
67     if(!freeze)
68         globals->set_freeze( true );
69
70     char *s;
71     AptDialogInput->getValue(&s);
72     string AptId(s);
73
74     cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
75
76     AptDialog_Cancel( NULL );
77
78     if ( AptId.length() ) {
79         // set initial position from airport id
80         SG_LOG( SG_GENERAL, SG_INFO,
81                 "Attempting to set starting position from airport code "
82                 << AptId );
83
84         if ( airports.search( AptId, &a ) )
85         {
86             // unbind the current fdm state so property changes
87             // don't get lost when we subsequently delete this fdm
88             // and create a new one.
89             cur_fdm_state->unbind();
90         
91             AptId = a.id.c_str();  /// NHV fix wrong case crash
92             fgSetString("/sim/startup/airport-id",  AptId.c_str() );
93             // fgSetDouble("/position/altitude-ft", -9999.0 );
94             // fgSetPosFromAirportID( AptId );
95             fgSetPosFromAirportIDandHdg( AptId, 
96                                          cur_fdm_state->get_Psi() *
97                                          SGD_RADIANS_TO_DEGREES);
98             // BusyCursor(0);
99             fgReInitSubsystems();
100             // if ( global_tile_mgr.init() ) {
101             // Load the local scenery data
102             global_tile_mgr.update( longitude->getDoubleValue(),
103                                     latitude->getDoubleValue() );
104             // } else {
105             // SG_LOG( SG_GENERAL, SG_ALERT, 
106             // "Error in Tile Manager initialization!" );
107             // exit(-1);
108             // }
109             // BusyCursor(1);
110         } else {
111             AptId  += " not in database.";
112             mkDialog(AptId.c_str());
113         }
114     }
115     if ( !freeze ) {
116         globals->set_freeze( false );
117     }
118 }
119
120
121 void AptDialog_Reset(puObject *)
122 {
123     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
124     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
125     AptDialogInput->setValue ( NewAirportId );
126     AptDialogInput->setCursor( 0 ) ;
127 }
128
129 void NewAirport(puObject *cb)
130 {
131     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
132     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
133     // cout << "NewAirport " << NewAirportId << endl;
134     AptDialogInput->setValue( NewAirportId );
135
136     FG_PUSH_PUI_DIALOG( AptDialog );
137 }
138
139 void NewAirportInit(void)
140 {
141     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
142     int len = 150
143         - puGetDefaultLabelFont().getStringWidth( NewAirportLabel ) / 2;
144
145     AptDialog = new puDialogBox (150, 50);
146     {
147         AptDialogFrame   = new puFrame           (0,0,350, 150);
148         AptDialogMessage = new puText            (len, 110);
149         AptDialogMessage ->    setLabel          (NewAirportLabel);
150
151         AptDialogInput   = new puInput           (50, 70, 300, 100);
152         AptDialogInput   ->    setValue          (NewAirportId);
153         AptDialogInput   ->    acceptInput();
154
155         AptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
156         AptDialogOkButton     ->     setLegend   (gui_msg_OK);
157         AptDialogOkButton     ->     setCallback (AptDialog_OK);
158         AptDialogOkButton     ->     makeReturnDefault(TRUE);
159
160         AptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
161         AptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
162         AptDialogCancelButton ->     setCallback (AptDialog_Cancel);
163
164         AptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
165         AptDialogResetButton  ->     setLegend   (gui_msg_RESET);
166         AptDialogResetButton  ->     setCallback (AptDialog_Reset);
167     }
168     cout << "NewAirportInit " << NewAirportId << endl;
169     FG_FINALIZE_PUI_DIALOG( AptDialog );
170 }