5 #include <simgear/compiler.h>
13 #include <simgear/constants.h>
14 #include <simgear/debug/logstream.hxx>
15 #include <simgear/misc/sg_path.hxx>
17 #include <Include/general.hxx>
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>
30 #include "gui_local.hxx"
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;
40 static char NewAirportId[16];
41 static char NewAirportLabel[] = "Enter New Airport ID";
43 static puOneShot *AptDialogOkButton = 0;
44 static puOneShot *AptDialogCancelButton = 0;
45 static puOneShot *AptDialogResetButton = 0;
47 void AptDialog_Cancel(puObject *)
49 FG_POP_PUI_DIALOG( AptDialog );
52 void AptDialog_OK (puObject *)
54 SGPath path( globals->get_fg_root() );
55 path.append( "Airports" );
56 path.append( "simple.mk4" );
57 FGAirports airports( path.c_str() );
61 int freeze = globals->get_freeze();
63 globals->set_freeze( true );
66 AptDialogInput->getValue(&s);
69 cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
71 AptDialog_Cancel( NULL );
73 if ( AptId.length() ) {
74 // set initial position from airport id
75 SG_LOG( SG_GENERAL, SG_INFO,
76 "Attempting to set starting position from airport code "
79 if ( airports.search( AptId, &a ) )
81 fgSetString("/sim/startup/airport-id", AptId.c_str() );
82 // fgSetDouble("/position/altitude", -9999.0 );
83 // fgSetPosFromAirportID( AptId );
84 fgSetPosFromAirportIDandHdg( AptId,
85 cur_fdm_state->get_Psi() *
86 SGD_RADIANS_TO_DEGREES);
89 if ( global_tile_mgr.init() ) {
90 // Load the local scenery data
91 global_tile_mgr.update(
92 cur_fdm_state->get_Longitude()
93 * SGD_RADIANS_TO_DEGREES,
94 cur_fdm_state->get_Latitude()
95 * SGD_RADIANS_TO_DEGREES );
97 SG_LOG( SG_GENERAL, SG_ALERT,
98 "Error in Tile Manager initialization!" );
103 AptId += " not in database.";
104 mkDialog(AptId.c_str());
108 globals->set_freeze( false );
112 void AptDialog_Reset(puObject *)
114 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
115 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
116 AptDialogInput->setValue ( NewAirportId );
117 AptDialogInput->setCursor( 0 ) ;
120 void NewAirport(puObject *cb)
122 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
123 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
124 // cout << "NewAirport " << NewAirportId << endl;
125 AptDialogInput->setValue( NewAirportId );
127 FG_PUSH_PUI_DIALOG( AptDialog );
130 void NewAirportInit(void)
132 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
133 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
134 NewAirportLabel ) / 2;
136 AptDialog = new puDialogBox (150, 50);
138 AptDialogFrame = new puFrame (0,0,350, 150);
139 AptDialogMessage = new puText (len, 110);
140 AptDialogMessage -> setLabel (NewAirportLabel);
142 AptDialogInput = new puInput (50, 70, 300, 100);
143 AptDialogInput -> setValue (NewAirportId);
144 AptDialogInput -> acceptInput();
146 AptDialogOkButton = new puOneShot (50, 10, 110, 50);
147 AptDialogOkButton -> setLegend (gui_msg_OK);
148 AptDialogOkButton -> setCallback (AptDialog_OK);
149 AptDialogOkButton -> makeReturnDefault(TRUE);
151 AptDialogCancelButton = new puOneShot (140, 10, 210, 50);
152 AptDialogCancelButton -> setLegend (gui_msg_CANCEL);
153 AptDialogCancelButton -> setCallback (AptDialog_Cancel);
155 AptDialogResetButton = new puOneShot (240, 10, 300, 50);
156 AptDialogResetButton -> setLegend (gui_msg_RESET);
157 AptDialogResetButton -> setCallback (AptDialog_Reset);
159 cout << "NewAirportInit " << NewAirportId << endl;
160 FG_FINALIZE_PUI_DIALOG( AptDialog );