A first stab at an aircraft selection dialog
This commit is contained in:
parent
159bcc4401
commit
37c427558a
8 changed files with 185 additions and 6 deletions
|
@ -105,10 +105,10 @@ All objects, including the top-level dialog, accept the following
|
||||||
properties, though they will ignore any that are not relevant:
|
properties, though they will ignore any that are not relevant:
|
||||||
|
|
||||||
x - the X position of the bottom left corner of the object, in
|
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
|
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
|
width - the width of the object, in pseudo-pixels. The default is
|
||||||
the width of the parent container.
|
the width of the parent container.
|
||||||
|
@ -290,6 +290,27 @@ Example:
|
||||||
</combo>
|
</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
|
slider
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,26 @@
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h> // strdup
|
||||||
|
|
||||||
|
#include <plib/ul.h>
|
||||||
|
#include <plib/ssg.h>
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#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/globals.hxx>
|
||||||
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/fgfs.hxx>
|
||||||
|
|
||||||
#include "aircraft.hxx"
|
#include "aircraft.hxx"
|
||||||
|
|
||||||
|
extern void fgInitFDM(void);
|
||||||
|
class FGFX;
|
||||||
|
|
||||||
// This is a record containing all the info for the aircraft currently
|
// This is a record containing all the info for the aircraft currently
|
||||||
// being operated
|
// being operated
|
||||||
fgAIRCRAFT current_aircraft;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include <FDM/flight.hxx>
|
#include <FDM/flight.hxx>
|
||||||
#include <Controls/controls.hxx>
|
#include <Controls/controls.hxx>
|
||||||
|
#include <Main/fg_init.hxx>
|
||||||
|
|
||||||
|
|
||||||
// Define a structure containing all the parameters for an aircraft
|
// Define a structure containing all the parameters for an aircraft
|
||||||
|
@ -56,6 +57,9 @@ void fgAircraftInit( void );
|
||||||
void fgAircraftOutputCurrent(fgAIRCRAFT *a);
|
void fgAircraftOutputCurrent(fgAIRCRAFT *a);
|
||||||
|
|
||||||
|
|
||||||
|
// Read the list of available aircraft into to property tree
|
||||||
|
void fgReadAircraft(void);
|
||||||
|
bool fgLoadAircraft (const SGPropertyNode * arg);
|
||||||
|
|
||||||
#endif // _AIRCRAFT_HXX
|
#endif // _AIRCRAFT_HXX
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,9 @@ FGDialog::display (SGPropertyNode * props)
|
||||||
return;
|
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) {
|
if (_object != 0) {
|
||||||
_object->reveal();
|
_object->reveal();
|
||||||
|
@ -280,6 +282,23 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
|
||||||
dial->setWrap(props->getBoolValue("wrap", true));
|
dial->setWrap(props->getBoolValue("wrap", true));
|
||||||
setupObject(dial, props);
|
setupObject(dial, props);
|
||||||
return dial;
|
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 {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,6 @@ do_reinit (const SGPropertyNode * arg)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Built-in command: suspend one or more subsystems.
|
* Built-in command: suspend one or more subsystems.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1368,6 +1368,9 @@ static void fgIdleFunction ( void ) {
|
||||||
// setup OpenGL view parameters
|
// setup OpenGL view parameters
|
||||||
fgInitVisuals();
|
fgInitVisuals();
|
||||||
|
|
||||||
|
// Read the list of available aircrafts
|
||||||
|
fgReadAircraft();
|
||||||
|
|
||||||
idle_state++;
|
idle_state++;
|
||||||
} else if ( idle_state == 5 ) {
|
} else if ( idle_state == 5 ) {
|
||||||
|
|
||||||
|
@ -1631,6 +1634,9 @@ static bool fgMainInit( int argc, char **argv ) {
|
||||||
// fonts !!!
|
// fonts !!!
|
||||||
guiInit();
|
guiInit();
|
||||||
|
|
||||||
|
// Read the list of available aircrafts
|
||||||
|
fgReadAircraft();
|
||||||
|
|
||||||
#ifdef GL_EXT_texture_lod_bias
|
#ifdef GL_EXT_texture_lod_bias
|
||||||
glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
|
glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -77,6 +77,8 @@ FGSound::FGSound()
|
||||||
|
|
||||||
FGSound::~FGSound()
|
FGSound::~FGSound()
|
||||||
{
|
{
|
||||||
|
_mgr->get_scheduler()->stopSample(_sample->get_sample());
|
||||||
|
|
||||||
if (_property)
|
if (_property)
|
||||||
delete _property;
|
delete _property;
|
||||||
|
|
||||||
|
@ -85,7 +87,6 @@ FGSound::~FGSound()
|
||||||
|
|
||||||
_volume.clear();
|
_volume.clear();
|
||||||
_pitch.clear();
|
_pitch.clear();
|
||||||
|
|
||||||
delete _sample;
|
delete _sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,8 @@ FGSoundMgr::~FGSoundMgr() {
|
||||||
sample_map_iterator sample_end = samples.end();
|
sample_map_iterator sample_end = samples.end();
|
||||||
for ( ; sample_current != sample_end; ++sample_current ) {
|
for ( ; sample_current != sample_end; ++sample_current ) {
|
||||||
sample_ref *sr = sample_current->second;
|
sample_ref *sr = sample_current->second;
|
||||||
|
|
||||||
|
audio_sched->stopSample(sr->sample);
|
||||||
delete sr->sample;
|
delete sr->sample;
|
||||||
delete sr;
|
delete sr;
|
||||||
}
|
}
|
||||||
|
@ -136,6 +138,8 @@ FGSoundMgr::~FGSoundMgr() {
|
||||||
sound_map_iterator sound_end = sounds.end();
|
sound_map_iterator sound_end = sounds.end();
|
||||||
for ( ; sound_current != sound_end; ++sound_current ) {
|
for ( ; sound_current != sound_end; ++sound_current ) {
|
||||||
FGSimpleSound *s = sound_current->second;
|
FGSimpleSound *s = sound_current->second;
|
||||||
|
|
||||||
|
audio_sched->stopSample(s->get_sample());
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue