From cdb21a52e4d495426622d661da9094060a5c73b5 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Mon, 17 Jan 2011 21:05:01 +0100 Subject: [PATCH] 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. --- Nasal/weather_scenario.nas | 27 +++++++++++++++++++++++++++ gui/dialogs/weather.xml | 18 +++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Nasal/weather_scenario.nas diff --git a/Nasal/weather_scenario.nas b/Nasal/weather_scenario.nas new file mode 100644 index 000000000..8d15255b1 --- /dev/null +++ b/Nasal/weather_scenario.nas @@ -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"); +}); + diff --git a/gui/dialogs/weather.xml b/gui/dialogs/weather.xml index 0d199dda1..d8594ab87 100644 --- a/gui/dialogs/weather.xml +++ b/gui/dialogs/weather.xml @@ -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")) );