1
0
Fork 0

Make METAR string editable in GUI. Fix bug 1764

This commit is contained in:
Stuart Buchanan 2015-06-03 20:14:28 +01:00
parent 7c3762108c
commit d04903ddb1

View file

@ -4,22 +4,22 @@
<nasal> <nasal>
<open> <open>
<![CDATA[ <![CDATA[
setprop("sim/gui/dialogs/metar/description[1]", setprop("sim/gui/dialogs/metar/description[1]",
"Simple and fast weather engine that interprets METAR data " ~ "Simple and fast weather engine that interprets METAR data " ~
"directly or a set of manually defined parameters. Recommended for use with Multiplayer."); "directly or a set of manually defined parameters. Recommended for use with Multiplayer.");
setprop("sim/gui/dialogs/metar/description[2]", setprop("sim/gui/dialogs/metar/description[2]",
"Advanced weather engine that gives more detailed and realistic results based on METAR " ~ "Advanced weather engine that gives more detailed and realistic results based on METAR " ~
"data and a set of predefined parameters. Click on 'Apply' to run the engine, as the engine " ~ "data and a set of predefined parameters. Click on 'Apply' to run the engine, as the engine " ~
"does not automatically load upon startup."); "does not automatically load upon startup.");
var normalize_string = func(src) { var normalize_string = func(src) {
if( src == nil ) src = ""; if( src == nil ) src = "";
var dst = ""; var dst = "";
for( var i = 0; i < size(src); i+=1 ) { for( var i = 0; i < size(src); i+=1 ) {
if( src[i] == `\n` or src[i] == `\r` ) if( src[i] == `\n` or src[i] == `\r` )
src[i] = ` `; src[i] = ` `;
if (i == 0 and src[i] == ` `) if (i == 0 and src[i] == ` `)
continue; continue;
@ -44,14 +44,14 @@
}, },
refresh : func { refresh : func {
var scenarioName = getprop( me.base ~ "/source-selection"); var scenarioName = getprop( me.base ~ "/source-selection");
if (getprop( me.base ~ "/mode/manual-weather")) { if (getprop( me.base ~ "/mode/manual-weather")) {
# In manual weather mode we have to disable live weather # In manual weather mode we have to disable live weather
# fetch so the weather can be changed by the user in the # fetch so the weather can be changed by the user in the
# weather configuration dialog. # weather configuration dialog.
setprop( "/environment/params/metar-updates-environment", 0 ); setprop( "/environment/params/metar-updates-environment", 0 );
setprop( "/environment/realwx/enabled", 0 ); setprop( "/environment/realwx/enabled", 0 );
setprop( "/environment/config/enabled", 1 ); setprop( "/environment/config/enabled", 1 );
@ -63,13 +63,13 @@
}, },
open : func { open : func {
# Determine the weather mode. # Determine the weather mode.
if ( getprop("/nasal/local_weather/enabled") == 1) { if ( getprop("/nasal/local_weather/enabled") == 1) {
# Local weather mode # Local weather mode
setprop( me.base ~ "/mode/global-weather", "0" ); setprop( me.base ~ "/mode/global-weather", "0" );
setprop( me.base ~ "/mode/local-weather", "1" ); setprop( me.base ~ "/mode/local-weather", "1" );
setprop( me.base ~ "/mode/manual-weather", "0" ); setprop( me.base ~ "/mode/manual-weather", "0" );
} else if ( getprop( "environment/params/metar-updates-environment" ) == 0 ) { } else if ( getprop( "environment/params/metar-updates-environment" ) == 0 ) {
# Manual weather mode # Manual weather mode
setprop( me.base ~ "/mode/global-weather", "1" ); setprop( me.base ~ "/mode/global-weather", "1" );
@ -81,7 +81,7 @@
setprop( me.base ~ "/mode/local-weather", "0" ); setprop( me.base ~ "/mode/local-weather", "0" );
setprop( me.base ~ "/mode/manual-weather", "0" ); setprop( me.base ~ "/mode/manual-weather", "0" );
} }
# initialize the METAR source selection # initialize the METAR source selection
if( getprop( "environment/realwx/enabled" ) ) { if( getprop( "environment/realwx/enabled" ) ) {
setprop( me.base ~ "/source-selection", "Live data" ); setprop( me.base ~ "/source-selection", "Live data" );
@ -105,7 +105,7 @@
if( found == 0 ) if( found == 0 )
setprop( me.base ~ "/source-selection", "Manual input" ); setprop( me.base ~ "/source-selection", "Manual input" );
} }
setprop( me.base ~ "/metar-string", normalize_string(getprop("environment/metar/data")) ); setprop( me.base ~ "/metar-string", normalize_string(getprop("environment/metar/data")) );
gui.findElementByName( me.dlgRoot, "metar-string" ).getNode("legend", 1).setValue(normalize_string(getprop("environment/metar/data"))); gui.findElementByName( me.dlgRoot, "metar-string" ).getNode("legend", 1).setValue(normalize_string(getprop("environment/metar/data")));
@ -121,7 +121,7 @@
me.scenarioListenerId = setlistener( me.base ~ "/source-selection", func(n) { me.scenarioListener(n); }, 1, 1 ); me.scenarioListenerId = setlistener( me.base ~ "/source-selection", func(n) { me.scenarioListener(n); }, 1, 1 );
me.metarListenerId = setlistener( "environment/metar/valid", func(n) { me.metarListener(n); }, 1, 1 ); me.metarListenerId = setlistener( "environment/metar/valid", func(n) { me.metarListener(n); }, 1, 1 );
# Update the dialog itself # Update the dialog itself
me.refresh(); me.refresh();
}, },
@ -137,8 +137,8 @@
var global_weather_enabled = getprop( me.base ~ "/mode/global-weather"); var global_weather_enabled = getprop( me.base ~ "/mode/global-weather");
var local_weather_enabled = getprop( me.base ~ "/mode/local-weather"); var local_weather_enabled = getprop( me.base ~ "/mode/local-weather");
var manual_weather_enabled = getprop( me.base ~ "/mode/manual-weather"); var manual_weather_enabled = getprop( me.base ~ "/mode/manual-weather");
# General weather settings based on scenario # General weather settings based on scenario
if (manual_weather_enabled == 1) { if (manual_weather_enabled == 1) {
setprop( "/environment/params/metar-updates-environment", 0 ); setprop( "/environment/params/metar-updates-environment", 0 );
setprop( "/environment/realwx/enabled", 0 ); setprop( "/environment/realwx/enabled", 0 );
@ -160,23 +160,23 @@
metar = getprop( me.base ~ "/metar-string" ); metar = getprop( me.base ~ "/metar-string" );
setprop("/environment/weather-scenario", scenarioName); setprop("/environment/weather-scenario", scenarioName);
} }
if( metar != nil ) { if( metar != nil ) {
setprop( "environment/metar/data", normalize_string(metar) ); setprop( "environment/metar/data", normalize_string(metar) );
} }
# Clear any local weather that might be running # Clear any local weather that might be running
if (getprop("/nasal/local_weather/loaded")) local_weather.clear_all(); if (getprop("/nasal/local_weather/loaded")) local_weather.clear_all();
setprop("/nasal/local_weather/enabled", "false"); setprop("/nasal/local_weather/enabled", "false");
if (local_weather_enabled) { if (local_weather_enabled) {
# If Local Weather is enabled, re-initialize with updated # If Local Weather is enabled, re-initialize with updated
# initial tile and tile selection. # initial tile and tile selection.
setprop("/nasal/local_weather/enabled", "true"); setprop("/nasal/local_weather/enabled", "true");
# Re-initialize local weather. # Re-initialize local weather.
settimer( func {local_weather.set_tile();}, 0.2); settimer( func {local_weather.set_tile();}, 0.2);
} }
}, },
findScenarioByName : func(name) { findScenarioByName : func(name) {
@ -195,58 +195,58 @@
var description = ""; var description = "";
var metar = "nil"; var metar = "nil";
var local_weather_props = nil; var local_weather_props = nil;
var scenario = me.findScenarioByName( n.getValue() ); var scenario = me.findScenarioByName( n.getValue() );
if( scenario != nil ) { if( scenario != nil ) {
description = normalize_string(scenario.getNode("description", 1 ).getValue()); description = normalize_string(scenario.getNode("description", 1 ).getValue());
metar = normalize_string(scenario.getNode("metar", 1 ).getValue()); metar = normalize_string(scenario.getNode("metar", 1 ).getValue());
local_weather_props = scenario.getNode("local-weather"); local_weather_props = scenario.getNode("local-weather");
} }
if (n.getValue() == "Live data") { if (n.getValue() == "Live data") {
# Special case - retrieve live data # Special case - retrieve live data
var metar = getprop( "environment/metar/data" ); var metar = getprop( "environment/metar/data" );
} }
if (n.getValue() == "Manual input") { if (n.getValue() == "Manual input") {
# Special case - retain current values # Special case - retain current values
var metar = getprop( me.base ~ "/metar-string" ); var metar = getprop( me.base ~ "/metar-string" );
} }
setprop(me.base ~ "/description", description ); setprop(me.base ~ "/description", description );
setprop(me.base ~ "/metar-string", metar ); setprop(me.base ~ "/metar-string", metar );
# Set the wind from the METAR string. # Set the wind from the METAR string.
var result = []; var result = [];
var msplit = split(" ", string.uc(metar)); var msplit = split(" ", string.uc(metar));
foreach (var word; msplit) { foreach (var word; msplit) {
if ((size(word) > 6) and string.match(word, "*[0-9][0-9]KT")) { if ((size(word) > 6) and string.match(word, "*[0-9][0-9]KT")) {
# We've got the wind definition word. Now to split it up. # We've got the wind definition word. Now to split it up.
# Format is nnnmmKT or nnnmmGppKT # Format is nnnmmKT or nnnmmGppKT
# Direction is easy - the first 3 characters. # Direction is easy - the first 3 characters.
var dir = chr(word[0]) ~ chr(word[1]) ~ chr(word[2]); var dir = chr(word[0]) ~ chr(word[1]) ~ chr(word[2]);
if (dir == "VRB") { if (dir == "VRB") {
setprop("/local-weather/tmp/tile-orientation-deg", 360.0 * rand()); setprop("/local-weather/tmp/tile-orientation-deg", 360.0 * rand());
setprop("/local-weather/tmp/gust-angular-variation-deg", 180.0); setprop("/local-weather/tmp/gust-angular-variation-deg", 180.0);
setprop("/local-weather/tmp/gust-frequency-hz", 0.001); setprop("/local-weather/tmp/gust-frequency-hz", 0.001);
} else { } else {
setprop("/local-weather/tmp/tile-orientation-deg", dir); setprop("/local-weather/tmp/tile-orientation-deg", dir);
setprop("/local-weather/tmp/gust-angular-variation-deg", 0.0); setprop("/local-weather/tmp/gust-angular-variation-deg", 0.0);
setprop("/local-weather/tmp/gust-frequency-hz", 0.0); setprop("/local-weather/tmp/gust-frequency-hz", 0.0);
} }
# Next two are the base wind # Next two are the base wind
var spd = chr(word[3]) ~ chr(word[4]); var spd = chr(word[3]) ~ chr(word[4]);
setprop("/local-weather/tmp/windspeed-kt", spd); setprop("/local-weather/tmp/windspeed-kt", spd);
var gst = 0; var gst = 0;
if ((size(word) > 7) and (chr(word[5]) == 'G')) { if ((size(word) > 7) and (chr(word[5]) == 'G')) {
# Gusty case # Gusty case
gst = chr(word[6]) ~ chr(word[7]); gst = chr(word[6]) ~ chr(word[7]);
} }
if ((gst > spd) and (spd > 0)) { if ((gst > spd) and (spd > 0)) {
setprop("/local-weather/tmp/gust-relative-strength", (gst - spd) / spd); setprop("/local-weather/tmp/gust-relative-strength", (gst - spd) / spd);
setprop("/local-weather/tmp/gust-frequency-hz", 0.7); setprop("/local-weather/tmp/gust-frequency-hz", 0.7);
@ -255,10 +255,10 @@
} }
} }
} }
if (local_weather_props != nil) { if (local_weather_props != nil) {
# The local weather properties need to be set now, so they can # The local weather properties need to be set now, so they can
# be configured by the user if they select Advanced Settings # be configured by the user if they select Advanced Settings
props.copy(local_weather_props, props.globals.getNode("/local-weather/tmp", 1)); props.copy(local_weather_props, props.globals.getNode("/local-weather/tmp", 1));
} else { } else {
@ -266,20 +266,20 @@
# METAR # METAR
setprop("/local-weather/tmp/tile-type", "manual"); setprop("/local-weather/tmp/tile-type", "manual");
setprop("/local-weather/tmp/tile-management", "METAR"); setprop("/local-weather/tmp/tile-management", "METAR");
} }
me.refresh(); me.refresh();
}, },
metarListener : func( n ) { metarListener : func( n ) {
var metar = getprop("environment/metar/data"); var metar = getprop("environment/metar/data");
if( metar == nil or metar == "" ) metar = "NIL"; if( metar == nil or metar == "" ) metar = "NIL";
metar = normalize_string(metar); metar = normalize_string(metar);
printlog( "info", "new METAR: " ~ metar ); printlog( "info", "new METAR: " ~ metar );
setprop( me.base ~ "/metar-string", metar ); setprop( me.base ~ "/metar-string", metar );
gui.dialog_update( "weather-conditions", "metar-string" ); gui.dialog_update( "weather-conditions", "metar-string" );
}, },
}; };
var controller = GlobalWeatherDialogController.new( cmdarg() ); var controller = GlobalWeatherDialogController.new( cmdarg() );
@ -665,9 +665,9 @@
--> -->
<pref-height>70</pref-height> <pref-height>70</pref-height>
<slider>15</slider> <slider>15</slider>
<editable>false</editable> <editable>true</editable>
<wrap>true</wrap> <wrap>true</wrap>
<live>true</live> <live>false</live>
<top-line>0</top-line> <top-line>0</top-line>
<property>sim/gui/dialogs/metar/metar-string</property> <property>sim/gui/dialogs/metar/metar-string</property>
<enable> <enable>