1
0
Fork 0
fgdata/gui/dialogs/weather_scenario.xml

265 lines
7.3 KiB
XML
Raw Normal View History

<?xml version="1.0"?>
<PropertyList>
<name>weather_scenario</name>
<modal>false</modal>
<layout>vbox</layout>
<resizable>true</resizable>
2009-05-29 10:27:30 +00:00
<default-padding>3</default-padding>
2009-05-29 10:27:30 +00:00
<group>
<layout>hbox</layout>
<default-padding>1</default-padding>
2009-05-29 10:27:30 +00:00
<empty><stretch>true</stretch></empty>
<text>
<label>Automatic Weather Generation</label>
</text>
2009-05-29 10:27:30 +00:00
<empty><stretch>true</stretch></empty>
<button>
<legend></legend>
<key>Esc</key>
<pref-width>16</pref-width>
<pref-height>16</pref-height>
<border>2</border>
<binding>
<command>dialog-close</command>
</binding>
</button>
</group>
2009-05-29 10:27:30 +00:00
<hrule/>
<group>
<layout>hbox</layout>
<text>
2009-05-29 10:27:30 +00:00
<label>METAR Source</label>
</text>
2009-05-29 10:27:30 +00:00
<empty><stretch>true</stretch></empty>
</group>
2009-05-29 10:27:30 +00:00
<combo>
<name>source-selection</name>
<halign>fill</halign>
<stretch>true</stretch>
<property>sim/gui/dialogs/weather-scenario/source-selection</property>
<binding>
<command>dialog-apply</command>
<object-name>source-selection</object-name>
</binding>
2009-05-29 18:08:02 +00:00
<binding>
<command>dialog-update</command>
<object-name>metar</object-name>
</binding>
2009-05-29 10:27:30 +00:00
</combo>
<textbox>
2009-05-29 10:27:30 +00:00
<name>description</name>
2006-02-24 11:01:17 +00:00
<halign>fill</halign>
<stretch>true</stretch>
2009-05-29 10:27:30 +00:00
<pref-width>180</pref-width>
<pref-height>100</pref-height>
2006-02-24 11:01:17 +00:00
<slider>20</slider>
2009-05-29 10:27:30 +00:00
<editable>false</editable>
<wrap>true</wrap>
<live>true</live>
2009-05-29 10:27:30 +00:00
<property>sim/gui/dialogs/weather-scenario/description</property>
</textbox>
<group>
<layout>hbox</layout>
<text>
<label>METAR Data</label>
</text>
<empty><stretch>true</stretch></empty>
</group>
<textbox>
<name>metar</name>
<halign>fill</halign>
<stretch>true</stretch>
<pref-width>180</pref-width>
<pref-height>50</pref-height>
<slider>20</slider>
<editable>true</editable>
<wrap>true</wrap>
2009-05-29 18:08:02 +00:00
<live>false</live>
2009-05-29 10:27:30 +00:00
<property>sim/gui/dialogs/weather-scenario/metar</property>
</textbox>
2009-05-29 10:27:30 +00:00
<hrule/>
<group>
<layout>hbox</layout>
<empty><stretch>true</stretch></empty>
<checkbox>
<property>/environment/params/metar-updates-winds-aloft</property>
<label>Update winds aloft</label>
<name>aloft</name>
</checkbox>
<empty><stretch>true</stretch></empty>
</group>
<group>
<layout>hbox</layout>
<empty><stretch>true</stretch></empty>
2009-05-29 10:27:30 +00:00
<button>
<legend>OK</legend>
<default>true</default>
<equal>true</equal>
<binding>
<command>dialog-apply</command>
</binding>
<binding>
<command>dialog-close</command>
</binding>
</button>
<button>
2009-05-29 10:27:30 +00:00
<legend>Apply</legend>
<equal>true</equal>
<binding>
<command>nasal</command>
<script>apply()</script>
</binding>
<binding>
<command>dialog-apply</command>
</binding>
</button>
<button>
2009-05-29 10:27:30 +00:00
<legend>Instant-Apply</legend>
<equal>true</equal>
<binding>
<command>nasal</command>
<script>apply()</script>
</binding>
<binding>
<command>dialog-apply</command>
</binding>
<binding>
<command>reinit</command>
<subsystem>environment</subsystem>
</binding>
</button>
<button>
2009-05-29 10:27:30 +00:00
<legend>Cancel</legend>
<equal>true</equal>
<key>Esc</key>
<binding>
<command>dialog-close</command>
</binding>
</button>
<empty><stretch>true</stretch></empty>
</group>
2009-05-29 10:27:30 +00:00
<nasal>
<open><![CDATA[
2009-05-29 16:24:10 +00:00
var dlg_root = cmdarg();
2009-05-29 10:27:30 +00:00
var normalize_string = func(src) {
if( src == nil ) src = "";
var dst = "";
for( var i = 0; i < size(src); i+=1 ) {
2009-05-29 16:24:10 +00:00
if( src[i] == `\n` or src[i] == `\r` )
src[i] = ` `;
2009-05-29 10:27:30 +00:00
2009-05-29 18:08:02 +00:00
if( i != 0 and src[i] == ` ` and src[i-1] == ` ` )
2009-05-29 10:27:30 +00:00
continue;
dst = dst ~ " ";
dst[size(dst)-1] = src[i];
}
return dst;
}
var findScenarioByName = func(name) {
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
if( wsn != nil ) {
var scenarios = wsn.getChildren("scenario");
foreach (var scenario; scenarios ) {
if( scenario.getNode("name").getValue() == name )
return scenario;
}
}
return nil;
}
2009-05-29 18:08:02 +00:00
var findElementByName = func(rootN, name) {
foreach( var child; rootN.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = findElementByName(child,name);
if( f != nil ) return f;
}
return nil;
};
2009-05-29 10:27:30 +00:00
var propertyChangeListener = setlistener( "sim/gui/dialogs/weather-scenario/source-selection", func(n) {
description = "";
metar = "nil";
var scenario = findScenarioByName( n.getValue() );
if( scenario != nil ) {
description = normalize_string(scenario.getNode("description", 1 ).getValue());
metar = normalize_string(scenario.getNode("metar", 1 ).getValue());
}
setprop("sim/gui/dialogs/weather-scenario/description", description );
setprop("sim/gui/dialogs/weather-scenario/metar", metar );
});
#initialize the METAR source selection
if( getprop( "environment/params/metar-updates-environment" ) == 0 ) {
setprop("sim/gui/dialogs/weather-scenario/source-selection", "Disabled" );
} else if( getprop( "environment/params/real-world-weather-fetch" ) ) {
setprop("sim/gui/dialogs/weather-scenario/source-selection", "Live data" );
} else {
setprop("sim/gui/dialogs/weather-scenario/source-selection", "Manual input" );
}
setprop( "sim/gui/dialogs/weather-scenario/metar", normalize_string(getprop("environment/metar/data")) );
# fill the METAR source combo box
var combo = findElementByName( dlg_root, "source-selection" );
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
if( wsn != nil ) {
var scenarios = wsn.getChildren("scenario");
forindex (var i; scenarios )
combo.getChild("value", i, 1).setValue(scenarios[i].getNode("name").getValue());
}
var apply = func {
var scenarioName = getprop("sim/gui/dialogs/weather-scenario/source-selection");
var metar = nil;
if( scenarioName == "Disabled" ) {
setprop( "/environment/params/metar-updates-environment", 0 );
setprop( "/environment/params/real-world-weather-fetch", 0 );
} else if( scenarioName == "Live data" ) {
setprop( "/environment/params/metar-updates-environment", 1 );
setprop( "/environment/params/real-world-weather-fetch", 1 );
} else if( scenarioName == "Manual input" ) {
setprop( "/environment/params/metar-updates-environment", 1 );
setprop( "/environment/params/real-world-weather-fetch", 0 );
metar = getprop( "sim/gui/dialogs/weather-scenario/metar" );
} else {
metar = getprop( "sim/gui/dialogs/weather-scenario/metar" );
}
if( metar != nil )
setprop( "environment/metar/data", normalize_string(metar) );
}
]]></open>
<close><![CDATA[
removelistener( propertyChangeListener );
]]></close>
</nasal>
</PropertyList>