1
0
Fork 0

GlobalWeather: (better) support for weather-scenario

- handle /environment/weather-scenario property on startup
- try to detect predefined scenario on startup of global
weather dialog box and select the corresponding entry in
the scenario combo box.
This commit is contained in:
Torsten Dreyer 2011-01-17 21:05:01 +01:00
parent 44a4f82481
commit cdb21a52e4
2 changed files with 44 additions and 1 deletions

View file

@ -0,0 +1,27 @@
# Set the global weather according to the defined
# scenario in /environment/weather-scenario
#
var initialize_weather_scenario = func {
getprop( "/environment/params/metar-updates-environment", 0 ) == 0 and return;
getprop( "/environment/realwx/enabled", 0 ) and return;
getprop( "/environment/metar/data", "" ) != "" and return;
# preset configured scenario
var scn = getprop("/environment/weather-scenario", "");
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
if( wsn != nil ) {
var scenarios = wsn.getChildren("scenario");
forindex (var i; scenarios ) {
if( scenarios[i].getNode("name").getValue() == scn ) {
setprop("/environment/metar/data", scenarios[i].getNode("metar").getValue() );
break;
}
}
}
};
_setlistener("/sim/signals/nasal-dir-initialized", func {
initialize_weather_scenario();
delete(globals, "weather_scenario");
});

View file

@ -1599,7 +1599,23 @@
} else if( getprop( "environment/realwx/enabled" ) ) {
setprop( me.base ~ "/source-selection", "Live data" );
} else {
setprop( me.base ~ "/source-selection", "Manual input" );
# preset configured scenario
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
var found = 0;
if( wsn != nil ) {
var scenarios = wsn.getChildren("scenario");
forindex (var i; scenarios ) {
var metarN = scenarios[i].getNode("metar");
metarN == nil and continue;
if( metarN.getValue() == getprop("/environment/metar/data","") ) {
setprop( me.base ~ "/source-selection", scenarios[i].getNode("name").getValue() );
found = 1;
break;
}
}
}
if( found == 0 )
setprop( me.base ~ "/source-selection", "Manual input" );
}
setprop( me.base ~ "/metar", normalize_string(getprop("environment/metar/data")) );