]> git.mxchange.org Git - flightgear.git/commitdiff
A first stab at an aircraft selection dialog
authorehofman <ehofman>
Sat, 29 Mar 2003 15:04:52 +0000 (15:04 +0000)
committerehofman <ehofman>
Sat, 29 Mar 2003 15:04:52 +0000 (15:04 +0000)
docs-mini/README.gui
src/Aircraft/aircraft.cxx
src/Aircraft/aircraft.hxx
src/GUI/dialog.cxx
src/Main/fg_commands.cxx
src/Main/main.cxx
src/Sound/fg_sound.cxx
src/Sound/soundmgr.cxx

index 2f6dfe63fd3923e65ee628ee62074f975dd20feb..4b76917285c34b9378e0353ed649a690e03aa3f8 100644 (file)
@@ -105,10 +105,10 @@ All objects, including the top-level dialog, accept the following
 properties, though they will ignore any that are not relevant:
 
  x - the X position of the bottom left corner of the object, in
-   pseudo-pixels.  The default is 0.
+   pseudo-pixels.  The default is to center the dialog.
 
  y - the Y position of the bottom left corner of the object, in
-   pseudo-pixels.  The default is 0.
+   pseudo-pixels.  The default is to center the dialog.
 
  width - the width of the object, in pseudo-pixels.  The default is
    the width of the parent container.
@@ -290,6 +290,27 @@ Example:
   </combo>
 
 
+
+select
+------
+
+A scrollable list of selections.
+
+  selection - a path in the property tree which holds the selectable items.
+
+Example:
+
+  <select>
+   <x>10</x>
+   <y>50</y>
+   <width>200</width>
+   <height>25</height>
+   <property>/sim/aircraft</property>
+   <selection>/sim/aircraft-types</selection>
+  </select>
+
+
+
 slider
 ------
 
index 886cc149d93170d141159758c9d443a565794c11..6679d6486c8f3e578ed1c470807a07c91f9a8049 100644 (file)
 
 
 #include <stdio.h>
+#include <string.h>            // strdup
+
+#include <plib/ul.h>
+#include <plib/ssg.h>
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/commands.hxx>
+#include <simgear/misc/exception.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <Main/fgfs.hxx>
 
 #include "aircraft.hxx"
 
+extern void fgInitFDM(void);
+class FGFX;
+
 // This is a record containing all the info for the aircraft currently
 // being operated
 fgAIRCRAFT current_aircraft;
@@ -69,3 +81,116 @@ void fgAircraftOutputCurrent(fgAIRCRAFT *a) {
 }
 
 
+// Show available aircraft types
+void fgReadAircraft(void) {
+
+   SGPropertyNode *aircraft_types = fgGetNode("/sim/aircraft-types", true);
+
+   SGPath path( globals->get_fg_root() );
+   path.append("Aircraft");
+
+   ulDirEnt* dire;
+   ulDir *dirp;
+
+   dirp = ulOpenDir(path.c_str());
+   if (dirp == NULL) {
+      SG_LOG( SG_AIRCRAFT, SG_ALERT, "Unable to open aircraft directory." );
+      ulCloseDir(dirp);
+      return;
+   }
+
+   while ((dire = ulReadDir(dirp)) != NULL) {
+      char *ptr;
+
+      if ((ptr = strstr(dire->d_name, "-set.xml")) && strlen(ptr) == 8) {
+
+          *ptr = '\0';
+#if 0
+          SGPath afile = path;
+          afile.append(dire->d_name);
+
+          SGPropertyNode root;
+          try {
+             readProperties(afile.str(), &root);
+          } catch (...) {
+             continue;
+          }
+
+          SGPropertyNode *node = root.getNode("sim");
+          if (node) {
+             SGPropertyNode *desc = node->getNode("description");
+
+             if (desc) {
+#endif
+                SGPropertyNode *aircraft =
+                                aircraft_types->getChild(dire->d_name, 0, true);
+#if 0
+
+                aircraft->setStringValue(strdup(desc->getStringValue()));
+             }
+          }
+#endif
+      }
+   }
+
+   ulCloseDir(dirp);
+
+   globals->get_commands()->addCommand("load-aircraft", fgLoadAircraft);
+}
+
+static inline bool
+fgLoadAircraft (const SGPropertyNode * arg)
+{
+    static const SGPropertyNode *master_freeze
+        = fgGetNode("/sim/freeze/master");
+
+    bool freeze = master_freeze->getBoolValue();
+    if ( !freeze ) {
+        fgSetBool("/sim/freeze/master", true);
+    }
+
+    cur_fdm_state->unbind();
+
+    string aircraft = fgGetString("/sim/aircraft", "");
+    globals->restoreInitialState();
+
+    if ( aircraft.size() > 0 ) {
+        SGPath aircraft_path(globals->get_fg_root());
+        aircraft_path.append("Aircraft");
+        aircraft_path.append(aircraft);
+        aircraft_path.concat("-set.xml");
+        SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
+               << " from " << aircraft_path.str());
+        try {
+            readProperties(aircraft_path.str(), globals->get_props());
+        } catch (const sg_exception &e) {
+            string message = "Error reading default aircraft: ";
+            message += e.getFormattedMessage();
+            SG_LOG(SG_INPUT, SG_ALERT, message);
+            exit(2);
+        }
+    } else {
+        SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
+    }
+
+    // Update the FDM
+    //
+    fgSetString("/sim/aircraft", aircraft.c_str());
+    fgInitFDM();
+
+    // update our position based on current presets
+    fgInitPosition();
+
+    SGTime *t = globals->get_time_params();
+    delete t;
+    t = fgInitTime();
+    globals->set_time_params( t );
+
+    fgReInitSubsystems();
+
+    if ( !freeze ) {
+        fgSetBool("/sim/freeze/master", false);
+    }
+
+    return true;
+}
index a05a4cb3acd7f82d542efadc33a517384f5c18c8..65450ffb18f3d8d412a6beb970198e949fcf8796 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <FDM/flight.hxx>
 #include <Controls/controls.hxx>
+#include <Main/fg_init.hxx>
 
 
 // Define a structure containing all the parameters for an aircraft
@@ -56,6 +57,9 @@ void fgAircraftInit( void );
 void fgAircraftOutputCurrent(fgAIRCRAFT *a);
 
 
-#endif // _AIRCRAFT_HXX
+// Read the list of available aircraft into to property tree
+void fgReadAircraft(void);
+bool fgLoadAircraft (const SGPropertyNode * arg);
 
+#endif // _AIRCRAFT_HXX
 
index 7dca5bf1a38119b022680ab843cdd6a5648262a6..c5191099061b0433582be8fc8f956a64cd9bd12d 100644 (file)
@@ -196,7 +196,9 @@ FGDialog::display (SGPropertyNode * props)
         return;
     }
 
-    _object = makeObject(props, 1024, 768);
+    _object = makeObject(props,
+                      globals->get_props()->getIntValue("/sim/startup/xsize"),
+                      globals->get_props()->getIntValue("/sim/startup/ysize"));
 
     if (_object != 0) {
         _object->reveal();
@@ -280,6 +282,23 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         dial->setWrap(props->getBoolValue("wrap", true));
         setupObject(dial, props);
         return dial;
+    } else if (type == "select") {
+        vector<SGPropertyNode_ptr> value_nodes;
+        SGPropertyNode * selection_node =
+                fgGetNode(props->getChild("selection")->getStringValue(), true);
+
+        for (int q = 0; q < selection_node->nChildren(); q++)
+            value_nodes.push_back(selection_node->getChild(q));
+
+        char ** entries = make_char_array(value_nodes.size());
+        for (int i = 0, j = value_nodes.size() - 1;
+             i < value_nodes.size();
+             i++, j--)
+            entries[i] = strdup((char *)value_nodes[i]->getName());
+        puSelectBox * select =
+            new puSelectBox(x, y, x + width, y + height, entries);
+        setupObject(select, props);
+        return select;
     } else {
         return 0;
     }
index d8764c17b4b3bf2144242e5fc87e79b029fad9bc..a56a21ef99c81284f127b5ead2096f0e4df62b5d 100644 (file)
@@ -208,7 +208,6 @@ do_reinit (const SGPropertyNode * arg)
     return result;
 }
 
-
 /**
  * Built-in command: suspend one or more subsystems.
  *
index b32e5c6243d5c4e776322c8a109145665036718f..9f3ca07c2aa672b9a759ca3ef02b548e5017f761 100644 (file)
@@ -1368,6 +1368,9 @@ static void fgIdleFunction ( void ) {
        // setup OpenGL view parameters
        fgInitVisuals();
 
+        // Read the list of available aircrafts
+        fgReadAircraft();
+
        idle_state++;
     } else if ( idle_state == 5 ) {
 
@@ -1631,6 +1634,9 @@ static bool fgMainInit( int argc, char **argv ) {
     // fonts !!!
     guiInit();
 
+    // Read the list of available aircrafts
+    fgReadAircraft();
+
 #ifdef GL_EXT_texture_lod_bias
     glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
 #endif
index 9f76ce0aca6d6034fd0ae5aea9698d4bb8224950..867a6e5c8b67dc4eb3a2a2441ad3a75a22915221 100644 (file)
@@ -77,6 +77,8 @@ FGSound::FGSound()
 
 FGSound::~FGSound()
 {
+   _mgr->get_scheduler()->stopSample(_sample->get_sample());
+
    if (_property)
       delete _property;
 
@@ -85,7 +87,6 @@ FGSound::~FGSound()
 
    _volume.clear();
    _pitch.clear();
-
    delete _sample;
 }
 
index 7faa4be4a78cd65159ed863b4f47d0b2cf285323..94e3099a1db6258fffda4142e583d1009cfe2dce 100644 (file)
@@ -125,6 +125,8 @@ FGSoundMgr::~FGSoundMgr() {
     sample_map_iterator sample_end = samples.end();
     for ( ; sample_current != sample_end; ++sample_current ) {
        sample_ref *sr = sample_current->second;
+
+        audio_sched->stopSample(sr->sample);
        delete sr->sample;
        delete sr;
     }
@@ -136,6 +138,8 @@ FGSoundMgr::~FGSoundMgr() {
     sound_map_iterator sound_end = sounds.end();
     for ( ; sound_current != sound_end; ++sound_current ) {
         FGSimpleSound *s = sound_current->second;
+
+        audio_sched->stopSample(s->get_sample());
         delete s;
     }