1
0
Fork 0

new weather scenario dialog

This commit is contained in:
torsten 2009-05-29 10:27:30 +00:00
parent a13361766b
commit 92a0c2d02f

View file

@ -5,78 +5,146 @@
<modal>false</modal> <modal>false</modal>
<layout>vbox</layout> <layout>vbox</layout>
<resizable>true</resizable> <resizable>true</resizable>
<default-padding>3</default-padding>
<text> <group>
<label>Weather Scenario</label> <layout>hbox</layout>
</text> <default-padding>1</default-padding>
<empty><stretch>true</stretch></empty>
<text>
<label>Automatic Weather Generation</label>
</text>
<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>
<hrule/> <hrule/>
<group>
<layout>hbox</layout>
<text>
<label>METAR Source</label>
</text>
<empty><stretch>true</stretch></empty>
</group>
<text> <combo>
<label></label> <name>source-selection</name>
</text> <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>
</combo>
<textbox>
<name>description</name>
<halign>fill</halign>
<stretch>true</stretch>
<pref-width>180</pref-width>
<pref-height>100</pref-height>
<slider>20</slider>
<editable>false</editable>
<wrap>true</wrap>
<live>true</live>
<property>sim/gui/dialogs/weather-scenario/description</property>
</textbox>
<group> <group>
<layout>hbox</layout> <layout>hbox</layout>
<text> <text>
<label>Weather source</label> <label>METAR Data</label>
<halign>left</halign>
</text> </text>
<combo> <empty><stretch>true</stretch></empty>
<halign>fill</halign>
<stretch>true</stretch>
<pref-width>200</pref-width>
<property>/environment/weather-scenario</property>
<value>Fair weather</value>
<value>Thunderstorm</value>
<value>METAR</value>
<value>none</value>
</combo>
</group> </group>
<text><label>Last metar used</label></text>
<textbox> <textbox>
<name>metar</name>
<halign>fill</halign> <halign>fill</halign>
<valign>fill</valign>
<stretch>true</stretch> <stretch>true</stretch>
<pref-width>400</pref-width> <pref-width>180</pref-width>
<pref-height>120</pref-height> <pref-height>50</pref-height>
<slider>20</slider> <slider>20</slider>
<live>true</live> <editable>true</editable>
<wrap>true</wrap> <wrap>true</wrap>
<editable>false</editable> <live>true</live>
<property>/environment/metar/last-metar</property> <property>sim/gui/dialogs/weather-scenario/metar</property>
</textbox> </textbox>
<text> <hrule/>
<label></label>
</text> <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> <group>
<layout>hbox</layout> <layout>hbox</layout>
<empty><stretch>true</stretch></empty> <empty><stretch>true</stretch></empty>
<button> <button>
<legend>OK</legend> <legend>OK</legend>
<default>true</default> <default>true</default>
<binding> <equal>true</equal>
<command>dialog-apply</command> <binding>
</binding> <command>dialog-apply</command>
<binding> </binding>
<command>dialog-close</command> <binding>
</binding> <command>dialog-close</command>
</binding>
</button> </button>
<button> <button>
<legend>Apply</legend> <legend>Apply</legend>
<binding> <equal>true</equal>
<command>dialog-apply</command> <binding>
</binding> <command>nasal</command>
<script>apply()</script>
</binding>
<binding>
<command>dialog-apply</command>
</binding>
</button> </button>
<button> <button>
<legend>Close</legend> <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>
<legend>Cancel</legend>
<equal>true</equal>
<key>Esc</key> <key>Esc</key>
<binding> <binding>
<command>dialog-close</command> <command>dialog-close</command>
@ -85,4 +153,108 @@
<empty><stretch>true</stretch></empty> <empty><stretch>true</stretch></empty>
</group> </group>
<nasal>
<open><![CDATA[
var dlg_root = cmdarg().getNode("/");
var normalize_string = func(src) {
if( src == nil ) src = "";
var dst = "";
for( var i = 0; i < size(src); i+=1 ) {
if( src[i] == 10 or src[i] == 13 )
src[i] = 32;
if( i != 0 and src[i] == 32 and src[i-1] == 32 )
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;
}
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")) );
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;
};
# 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> </PropertyList>