Debian Codegraph @

gui/dialogs/weather.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <nasal>
5 <open>
6 <![CDATA[
7
8 setprop("sim/gui/dialogs/metar/description[1]",
9 "Simple and fast weather engine that interprets METAR data " ~
10 "directly or a set of manually defined parameters. Recommended for use with Multiplayer.");
11 setprop("sim/gui/dialogs/metar/description[2]",
12 "Advanced weather engine that gives more detailed and realistic results based on METAR " ~
13 "data and a set of predefined parameters. Click on 'Apply' to run the engine, as the engine " ~
14 "does not automatically load upon startup.");
15
16 var normalize_string = func(src) {
17 if( src == nil ) src = "";
18 var dst = "";
19 for( var i = 0; i < size(src); i+=1 ) {
20 if( src[i] == `\n` or src[i] == `\r` )
21 src[i] = ` `;
22
23 if (i == 0 and src[i] == ` `)
24 continue;
25
26 if( i != 0 and src[i] == ` ` and src[i-1] == ` ` )
27 continue;
28
29 dst = dst ~ " ";
30 dst[size(dst)-1] = src[i];
31 }
32 return dst;
33 }
34
35 var GlobalWeatherDialogController = {
36
37 new : func( dlgRoot ) {
38 var obj = { parents: [GlobalWeatherDialogController] };
39 obj.dlgRoot = dlgRoot;
40 obj.base = "sim/gui/dialogs/metar";
41 obj.baseN = props.globals.getNode( obj.base, 1 );
42
43 return obj;
44 },
45
46 refresh : func {
47
48 var scenarioName = getprop( me.base ~ "/source-selection");
49
50 if (getprop( me.base ~ "/mode/manual-weather")) {
51 # In manual weather mode we have to disable live weather
52 # fetch so the weather can be changed by the user in the
53 # weather configuration dialog.
54
55 setprop( "/environment/params/metar-updates-environment", 0 );
56 setprop( "/environment/realwx/enabled", 0 );
57 setprop( "/environment/config/enabled", 1 );
58 setprop( "/environment/atmosphere/is-isa", 0 );
59 } else if( scenarioName == "Live data" ) {
60 # If we've selected Live Data we need to force
61 # a refresh of the Live Data setting.
62 setprop( "/environment/realwx/enabled", 1 );
63 setprop( "/environment/atmosphere/is-isa", 0 );
64 } else if( scenarioName == "International Standard Atmosphere" ) {
65 # If we've selected International Standard Atmosphere we need to
66 # enable the ISA setting.
67 setprop( "/environment/atmosphere/is-isa", 1 );
68 }
69 },
70
71 open : func {
72
73 # Determine the weather mode.
74 if ( getprop("/nasal/local_weather/enabled") == 1) {
75 # Local weather mode
76 setprop( me.base ~ "/mode/global-weather", "0" );
77 setprop( me.base ~ "/mode/local-weather", "1" );
78 setprop( me.base ~ "/mode/manual-weather", "0" );
79 } else if ( getprop( "environment/params/metar-updates-environment" ) == 0 ) {
80 # Manual weather mode
81 setprop( me.base ~ "/mode/global-weather", "1" );
82 setprop( me.base ~ "/mode/local-weather", "0" );
83 setprop( me.base ~ "/mode/manual-weather", "1" );
84 } else {
85 # Global weather mode
86 setprop( me.base ~ "/mode/global-weather", "1" );
87 setprop( me.base ~ "/mode/local-weather", "0" );
88 setprop( me.base ~ "/mode/manual-weather", "0" );
89 }
90
91 # initialize the METAR source selection
92 if( getprop( "environment/realwx/enabled" ) ) {
93 setprop( me.base ~ "/source-selection", "Live data" );
94 } else {
95 # preset configured scenario
96 var wsn = props.globals.getNode( "/environment/weather-scenarios" );
97 var current = getprop("/environment/weather-scenario", "");
98 var found = 0;
99 if( wsn != nil ) {
100 var scenarios = wsn.getChildren("scenario");
101 forindex (var i; scenarios ) {
102 var metarN = scenarios[i].getNode("metar");
103 metarN == nil and continue;
104 if( scenarios[i].getNode("name").getValue() == current ) {
105 setprop( me.base ~ "/source-selection", scenarios[i].getNode("name").getValue() );
106 found = 1;
107 break;
108 }
109 }
110 }
111 if( found == 0 )
112 setprop( me.base ~ "/source-selection", "Manual input" );
113 }
114
115 setprop( me.base ~ "/metar-string", normalize_string(getprop("environment/metar/data")) );
116 gui.findElementByName( me.dlgRoot, "metar-string-input" ).getNode("legend", 1).setValue(normalize_string(getprop("environment/metar/data")));
117
118 # fill the METAR source combo box
119 var combo = gui.findElementByName( me.dlgRoot, "source-selection" );
120 var wsn = props.globals.getNode( "/environment/weather-scenarios" );
121 if( wsn != nil ) {
122 var scenarios = wsn.getChildren("scenario");
123 forindex (var i; scenarios ) {
124 combo.getChild("value", i, 1).setValue(scenarios[i].getNode("name").getValue());
125 }
126 }
127
128 me.scenarioListenerId = setlistener( me.base ~ "/source-selection", func(n) { me.scenarioListener(n); }, 1, 1 );
129 me.metarListenerId = setlistener( "environment/metar/valid", func(n) { me.metarListener(n); }, 1, 1 );
130
131 # Update the dialog itself
132 me.refresh();
133 },
134
135 close : func {
136 removelistener( me.scenarioListenerId );
137 removelistener( me.metarListenerId );
138 },
139
140 apply : func {
141 var scenarioName = getprop( me.base ~ "/source-selection");
142 var metar = getprop( "environment/metar/data" );
143 var global_weather_enabled = getprop( me.base ~ "/mode/global-weather");
144 var local_weather_enabled = getprop( me.base ~ "/mode/local-weather");
145 var manual_weather_enabled = getprop( me.base ~ "/mode/manual-weather");
146
147 # General weather settings based on scenario
148 if (manual_weather_enabled == 1) {
149 setprop( "/environment/params/metar-updates-environment", 0 );
150 setprop( "/environment/realwx/enabled", 0 );
151 setprop( "/environment/config/enabled", 1 );
152 metar = "";
153 } else if( scenarioName == "Live data" ) {
154 setprop( "/environment/params/metar-updates-environment", 1 );
155 setprop( "/environment/realwx/enabled", 1 );
156 setprop( "/environment/config/enabled", 1 );
157 } else if( scenarioName == "Manual input" ) {
158 setprop( "/environment/params/metar-updates-environment", 1 );
159 setprop( "/environment/realwx/enabled", 0 );
160 setprop( "/environment/config/enabled", 1 );
161 metar = getprop( me.base ~ "/metar-string" );
162 setprop("/environment/weather-scenario", scenarioName);
163 } else {
164 setprop( "/environment/params/metar-updates-environment", 1 );
165 setprop( "/environment/realwx/enabled", 0 );
166 setprop( "/environment/config/enabled", 1 );
167 metar = getprop( me.base ~ "/metar-string" );
168 setprop("/environment/weather-scenario", scenarioName);
169 }
170
171 if( metar != nil ) {
172 setprop( "environment/metar/data", normalize_string(metar) );
173 }
174
175 # Clear any local weather that might be running
176 if (getprop("/nasal/local_weather/enabled")) local_weather.clear_all();
177 setprop("/nasal/local_weather/enabled", "false");
178
179 if (local_weather_enabled) {
180 # If Local Weather is enabled, re-initialize with updated
181 # initial tile and tile selection.
182 setprop("/nasal/local_weather/enabled", "true");
183
184 # Re-initialize local weather.
185 settimer( func {local_weather.set_tile();}, 0.2);
186 }
187 },
188
189 findScenarioByName : func(name) {
190 var wsn = props.globals.getNode( "/environment/weather-scenarios" );
191 if( wsn != nil ) {
192 var scenarios = wsn.getChildren("scenario");
193 foreach (var scenario; scenarios ) {
194 if( scenario.getNode("name").getValue() == name )
195 return scenario;
196 }
197 }
198 return nil;
199 },
200
201 scenarioListener : func( n ) {
202 var description = "";
203 var metar = "nil";
204 var local_weather_props = nil;
205
206 var scenario = me.findScenarioByName( n.getValue() );
207 if( scenario != nil ) {
208 description = normalize_string(scenario.getNode("description", 1 ).getValue());
209 metar = normalize_string(scenario.getNode("metar", 1 ).getValue());
210 local_weather_props = scenario.getNode("local-weather");
211 }
212
213 if (n.getValue() == "Live data") {
214 # Special case - retrieve live data
215 var metar = getprop( "environment/metar/data" );
216 }
217
218 if (n.getValue() == "Manual input") {
219 # Special case - retain current values
220 var metar = getprop( me.base ~ "/metar-string" );
221 }
222
223 setprop(me.base ~ "/description", description );
224 setprop(me.base ~ "/metar-string", metar );
225
226 # Set the wind from the METAR string.
227 var result = [];
228 var msplit = split(" ", string.uc(metar));
229 foreach (var word; msplit) {
230
231 if ((size(word) > 6) and string.match(word, "*[0-9][0-9]KT")) {
232 # We've got the wind definition word. Now to split it up.
233 # Format is nnnmmKT or nnnmmGppKT
234 # Direction is easy - the first 3 characters.
235 var dir = chr(word[0]) ~ chr(word[1]) ~ chr(word[2]);
236
237 if (dir == "VRB") {
238 setprop("/local-weather/tmp/tile-orientation-deg", 360.0 * rand());
239 setprop("/local-weather/tmp/gust-angular-variation-deg", 180.0);
240 setprop("/local-weather/tmp/gust-frequency-hz", 0.001);
241 } else {
242 setprop("/local-weather/tmp/tile-orientation-deg", dir);
243 setprop("/local-weather/tmp/gust-angular-variation-deg", 0.0);
244 setprop("/local-weather/tmp/gust-frequency-hz", 0.0);
245 }
246
247 # Next two are the base wind
248 var spd = chr(word[3]) ~ chr(word[4]);
249 setprop("/local-weather/tmp/windspeed-kt", spd);
250
251 var gst = 0;
252 if ((size(word) > 7) and (chr(word[5]) == 'G')) {
253 # Gusty case
254 gst = chr(word[6]) ~ chr(word[7]);
255 }
256
257 if ((gst > spd) and (spd > 0)) {
258 setprop("/local-weather/tmp/gust-relative-strength", (gst - spd) / spd);
259 setprop("/local-weather/tmp/gust-frequency-hz", 0.7);
260 } else {
261 setprop("/local-weather/tmp/gust-relative-strength", 0.0);
262 }
263 }
264 }
265
266
267 if (local_weather_props != nil) {
268 # The local weather properties need to be set now, so they can
269 # be configured by the user if they select Advanced Settings
270 props.copy(local_weather_props, props.globals.getNode("/local-weather/tmp", 1));
271 } else {
272 # If no local weather properties have been set, we'll read from the scenario
273 # METAR
274 setprop("/local-weather/tmp/tile-type", "manual");
275 setprop("/local-weather/tmp/tile-management", "METAR");
276 }
277
278 me.refresh();
279 },
280
281 metarListener : func( n ) {
282 var metar = getprop("environment/metar/data");
283 if( metar == nil or metar == "" ) metar = "NIL";
284 metar = normalize_string(metar);
285 logprint(LOG_DEBUG, "new METAR: " ~ metar );
286 setprop( me.base ~ "/metar-string", metar );
287 gui.dialog_update( "weather-conditions", "metar-string" );
288 },
289
290 };
291
292 var controller = GlobalWeatherDialogController.new( cmdarg() );
293 controller.open();
294 ]]>
295 </open>
296
297 <close>
298 <![CDATA[
299 controller.close();
300 ]]>
301 </close>
302 </nasal>
303
304 <!-- Control the weather -->
305 <name>weather</name>
306 <modal>false</modal>
307 <resizable>true</resizable>
308 <layout>vbox</layout>
309 <default-padding>3</default-padding>
310
311 <!-- Title bar with close button -->
312 <group>
313 <layout>hbox</layout>
314 <default-padding>1</default-padding>
315
316 <text>
317 <label>Weather Conditions</label>
318 </text>
319
320 <empty>
321 <stretch>true</stretch>
322 </empty>
323
324 <button>
325 <legend>X</legend>
326 <key>Esc</key>
327 <pref-width>20</pref-width>
328 <pref-height>20</pref-height>
329 <binding>
330 <command>dialog-close</command>
331 </binding>
332 </button>
333 </group>
334
335 <hrule/>
336
337 <group>
338 <layout>hbox</layout>
339 <valign>fill</valign>
340 <stretch>true</stretch>
341
342 <group>
343 <layout>vbox</layout>
344 <valign>fill</valign>
345 <padding>5</padding>
346
347 <text>
348 <halign>left</halign>
349 <label>Select Weather Engine</label>
350 </text>
351
352 <group>
353 <layout>table</layout>
354
355 <radio>
356 <row>0</row>
357 <col>0</col>
358 <halign>left</halign>
359 <name>simple-weather</name>
360 <property>sim/gui/dialogs/metar/mode/global-weather</property>
361 <live>true</live>
362 <label>Basic Weather</label>
363 <binding>
364 <command>property-assign</command>
365 <property>sim/gui/dialogs/metar/mode/global-weather</property>
366 <value>1</value>
367 </binding>
368 <binding>
369 <command>property-assign</command>
370 <property>sim/gui/dialogs/metar/mode/local-weather</property>
371 <value>0</value>
372 </binding>
373 <binding>
374 <command>property-assign</command>
375 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
376 <value>0</value>
377 </binding>
378 <binding>
379 <command>nasal</command>
380 <script>
381 controller.refresh();
382 </script>
383 </binding>
384 </radio>
385
386 <group>
387 <row>0</row>
388 <col>1</col>
389 <layout>hbox</layout>
390 <halign>right</halign>
391
392 <checkbox>
393 <halign>right</halign>
394 <name>manual-weather-config</name>
395 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
396 <label>Manual Configuration</label>
397 <live>true</live>
398 <enable>
399 <property>sim/gui/dialogs/metar/mode/global-weather</property>
400 </enable>
401 <binding>
402 <command>dialog-apply</command>
403 <object-name>manual-weather-config</object-name>
404 </binding>
405 <binding>
406 <command>nasal</command>
407 <script>
408 controller.refresh();
409 </script>
410 </binding>
411 </checkbox>
412
413 <button>
414 <halign>right</halign>
415
416 <legend>Manual Configuration...</legend>
417 <enable>
418 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
419 </enable>
420 <binding>
421 <command>dialog-show</command>
422 <dialog-name>weather-configuration</dialog-name>
423 </binding>
424 <!--<binding>
425 <command>property-assign</command>
426 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
427 <value>1</value>
428 </binding>-->
429 </button>
430 </group>
431 </group>
432
433 <textbox>
434 <name>basic description</name>
435 <halign>fill</halign>
436 <valign>fill</valign>
437 <stretch>true</stretch>
438 <pref-height>90</pref-height>
439 <slider>15</slider>
440 <editable>false</editable>
441 <wrap>true</wrap>
442 <live>true</live>
443 <top-line>0</top-line>
444 <property>sim/gui/dialogs/metar/description[1]</property>
445 </textbox>
446
447 <group>
448 <layout>table</layout>
449
450 <radio>
451 <row>0</row>
452 <col>0</col>
453 <label>Detailed Weather</label>
454 <halign>left</halign>
455 <name>simple-weather</name>
456 <property>sim/gui/dialogs/metar/mode/local-weather</property>
457 <live>true</live>
458 <binding>
459 <command>property-assign</command>
460 <property>sim/gui/dialogs/metar/mode/local-weather</property>
461 <value>1</value>
462 </binding>
463 <binding>
464 <command>property-assign</command>
465 <property>sim/gui/dialogs/metar/mode/global-weather</property>
466 <value>0</value>
467 </binding>
468 <binding>
469 <command>property-assign</command>
470 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
471 <value>0</value>
472 </binding>
473 <binding>
474 <command>nasal</command>
475 <script>
476 controller.refresh();
477 </script>
478 </binding>
479 </radio>
480
481 <group>
482 <row>0</row>
483 <col>1</col>
484 <layout>hbox</layout>
485 <halign>right</halign>
486
487 <button>
488 <halign>right</halign>
489 <legend>Weather help</legend>
490 <binding>
491 <command>open-browser</command>
492 <path>Docs/README.local_weather.html</path>
493 </binding>
494 </button>
495
496 <button>
497 <legend>Advanced Settings...</legend>
498 <halign>right</halign>
499 <enable>
500 <property>sim/gui/dialogs/metar/mode/local-weather</property>
501 <value>1</value>
502 </enable>
503 <binding>
504 <command>dialog-show</command>
505 <dialog-name>local-weather</dialog-name>
506 </binding>
507 </button>
508 </group>
509 </group>
510
511 <textbox>
512 <name>advance-description</name>
513 <halign>fill</halign>
514 <valign>fill</valign>
515 <stretch>true</stretch>
516 <pref-height>100</pref-height>
517 <slider>15</slider>
518 <editable>false</editable>
519 <wrap>true</wrap>
520 <live>true</live>
521 <top-line>0</top-line>
522 <property>sim/gui/dialogs/metar/description[2]</property>
523 </textbox>
524 </group>
525 </group>
526
527 <hrule/>
528
529 <group>
530 <layout>vbox</layout>
531 <valign>fill</valign>
532 <stretch>true</stretch>
533
534 <group>
535 <layout>vbox</layout>
536 <padding>5</padding>
537
538 <group>
539 <layout>table</layout>
540
541 <text>
542 <row>0</row>
543 <col>0</col>
544 <label>Weather Conditions</label>
545 <halign>left</halign>
546 </text>
547
548 <combo>
549 <row>0</row>
550 <col>1</col>
551 <name>source-selection</name>
552 <halign>right</halign>
553 <stretch>true</stretch>
554 <pref-width>300</pref-width>
555 <property>sim/gui/dialogs/metar/source-selection</property>
556 <enable>
557 <equals>
558 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
559 <value>0</value>
560 </equals>
561 </enable>
562 <binding>
563 <command>dialog-apply</command>
564 <object-name>source-selection</object-name>
565 </binding>
566 <binding>
567 <command>dialog-update</command>
568 <object-name>metar-string-input</object-name>
569 </binding>
570 </combo>
571 </group>
572
573 <textbox>
574 <name>description</name>
575 <halign>fill</halign>
576 <valign>fill</valign>
577 <stretch>true</stretch>
578 <pref-height>100</pref-height>
579 <slider>15</slider>
580 <editable>false</editable>
581 <wrap>true</wrap>
582 <live>true</live>
583 <top-line>0</top-line>
584 <property>sim/gui/dialogs/metar/description[0]</property>
585 </textbox>
586 </group>
587
588 <group>
589 <layout>vbox</layout>
590 <padding>5</padding>
591
592 <group>
593 <layout>table</layout>
594
595 <text>
596 <row>0</row>
597 <col>0</col>
598 <label>METAR Data</label>
599 <halign>left</halign>
600 </text>
601
602 <group>
603 <row>0</row>
604 <col>1</col>
605 <layout>hbox</layout>
606 <halign>right</halign>
607
608 <text>
609 <label>Data is valid</label>
610 </text>
611 <checkbox>
612 <property>/environment/metar/valid</property>
613 <label/>
614 <live>true</live>
615 <enable>
616 <false/>
617 </enable>
618 </checkbox>
619 </group>
620 </group>
621
622 <textbox>
623 <name>metar-string-input</name>
624 <halign>fill</halign>
625 <valign>fill</valign>
626 <stretch>true</stretch>
627 <pref-height>70</pref-height>
628 <slider>15</slider>
629 <editable>true</editable>
630 <wrap>true</wrap>
631 <!-- <live>true</live> -->
632 <top-line>0</top-line>
633 <property>sim/gui/dialogs/metar/metar-string</property>
634 <enable>
635 <and>
636 <equals>
637 <property>sim/gui/dialogs/metar/mode/manual-weather</property>
638 <value>0</value>
639 </equals>
640 <equals>
641 <property>sim/gui/dialogs/metar/source-selection</property>
642 <value>Manual input</value>
643 </equals>
644 </and>
645 </enable>
646 <binding>
647 <command>dialog-apply</command>
648 <object-name>metar-string-input</object-name>
649 </binding>
650 </textbox>
651
652 <group>
653 <layout>hbox</layout>
654 <halign>left</halign>
655 <button>
656 <legend>METAR Description...</legend>
657 <binding>
658 <command>dialog-show</command>
659 <dialog-name>weather-metar-description</dialog-name>
660 </binding>
661 </button>
662 </group>
663 </group>
664 </group>
665
666 <hrule/>
667
668 <group>
669 <layout>hbox</layout>
670
671 <empty>
672 <stretch>true</stretch>
673 </empty>
674
675 <button>
676 <legend>OK</legend>
677 <equal>true</equal>
678 <binding>
679 <command>dialog-apply</command>
680 <object-name>metar-string-input</object-name>
681 </binding>
682 <binding>
683 <command>nasal</command>
684 <script>
685 controller.apply();
686 </script>
687 </binding>
688 <binding>
689 <command>dialog-close</command>
690 </binding>
691 </button>
692
693 <button>
694 <legend>Apply</legend>
695 <equal>true</equal>
696 <binding>
697 <command>dialog-apply</command>
698 <object-name>metar-string-input</object-name>
699 </binding>
700 <binding>
701 <command>nasal</command>
702 <script>
703 controller.apply();
704 </script>
705 </binding>
706 </button>
707
708 <button>
709 <legend>Close</legend>
710 <equal>true</equal>
711 <default>true</default>
712 <key>Esc</key>
713 <binding>
714 <command>dialog-close</command>
715 </binding>
716 </button>
717
718 <empty>
719 <stretch>true</stretch>
720 </empty>
721 </group>
722 </PropertyList>