Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/NavigationMap/NavigationMap.nas

raw
1 # Copyright 2018 Stuart Buchanan
2 # This file is part of FlightGear.
3 #
4 # FlightGear is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # FlightGear is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with FlightGear. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Navigation Map
18 var NavigationMap =
19 {
20 new : func (mfd, myCanvas, device, svg)
21 {
22 var obj = {
23 parents : [
24 NavigationMap,
25 MFDPage.new(mfd, myCanvas, device, svg, "NavigationMap", "MAP - NAVIGATION MAP")
26 ],
27 };
28
29 obj.MFDMap = fg1000.NavMap.new(
30 obj,
31 obj.getElement("NavMap"),
32 [fg1000.MAP_FULL.CENTER.X, fg1000.MAP_FULL.CENTER.Y],
33 "",
34 zindex=-10);
35 obj.setController(fg1000.NavigationMapController.new(obj, svg));
36
37 return obj;
38 },
39
40 offdisplay : func(controller=1) {
41 me._group.setVisible(0);
42 me.getElement("NavMap").setVisible(0);
43 me.getElement("NavMap-bg").setVisible(0);
44 me.MFDMap.setVisible(0);
45
46 # Reset the menu colours. Shouldn't have to do this here, but
47 # there's not currently an obvious other location to do so.
48 for(var i = 0; i < 12; i +=1) {
49 var name = sprintf("SoftKey%d",i);
50 me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0);
51 me.device.svg.getElementById(name).setColor(1.0,1.0,1.0);
52 }
53 if (controller == 1) me.getController().offdisplay();
54 },
55 ondisplay : func(controller=1) {
56 me._group.setVisible(1);
57 me.getElement("Group").setVisible(1);
58 me.getElement("NavMap").setVisible(1);
59 me.getElement("NavMap-bg").setVisible(1);
60 me.getElement("Legend").setVisible(1);
61 me.MFDMap.setVisible(1);
62
63 # Center the map's origin, modified to take into account the surround.
64 me.getElement("NavMap").setTranslation(
65 fg1000.MAP_FULL.CENTER.X,
66 fg1000.MAP_FULL.CENTER.Y
67 );
68
69 me.getElement("Legend").setTranslation(0,0);
70
71 me.mfd.setPageTitle(me.title);
72 if (controller == 1) me.getController().ondisplay();
73 },
74
75 # Display functions when we're displaying the NavigationMap as part of another
76 # page - e.g. NearestAirports.
77 ondisplayPartial : func() {
78 me._group.setVisible(1);
79 me.getElement("Group").setVisible(1);
80 me.getElement("NavMap").setVisible(1);
81 me.getElement("NavMap-bg").setVisible(1);
82 me.getElement("Legend").setVisible(1);
83 me.MFDMap.setVisible(1);
84
85 # Center the map's origin, modified to take into account the surround.
86 me.getElement("NavMap").setTranslation(
87 fg1000.MAP_PARTIAL.CENTER.X,
88 fg1000.MAP_PARTIAL.CENTER.Y
89 );
90
91 me.getElement("Legend").setTranslation(-300,0);
92 },
93 offdisplayPartial : func() {
94 me._group.setVisible(0);
95 me.getElement("Group").setVisible(0);
96 me.getElement("NavMap").setVisible(0);
97 me.getElement("NavMap-bg").setVisible(0);
98 me.getElement("Legend").setVisible(0);
99 me.MFDMap.setVisible(0);
100 #me.getController().offdisplayPartial();
101 },
102
103 # Softkey assigments. For some pages (notably the NEAREST pages)
104 # the MAP softkey is available as key 2:
105 # pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu);
106
107
108 topMenu : func(device, pg, menuitem) {
109 pg.clearMenu();
110 pg.resetMenuColors();
111 pg.addMenuItem(0, "ENGINE", pg, pg.mfd.EIS.engineMenu);
112 pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu);
113 pg.addMenuItem(8, "DCLTR", pg, func(dev, pg, mi) { pg.mfd.NavigationMap.MFDMap.incrDCLTR(dev, mi); } );
114 #pg.addMenuItem(9, "SHW CHRT", pg); # Optional
115 pg.addMenuItem(10, "CHKLIST", pg, func(dev, pg, mi) { pg.mfd.Surround.goToPage("LstPageGroup", "Checklist"); }); # Optional
116 device.updateMenus();
117 },
118
119 mapMenu : func(device, pg, menuitem) {
120 pg.clearMenu();
121 pg.resetMenuColors();
122 pg.addMenuItem(0, "TRAFFIC", pg,
123 func(dev, pg, mi) { pg.mfd.NavigationMap.MFDMap.toggleLayer("TFC"); device.updateMenus(); }, # callback
124 func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "TFC"); }
125 );
126
127 pg.addMenuItem(1, "PROFILE", pg);
128 pg.addMenuItem(2, "TOPO", pg,
129 func(dev, pg, mi) { pg.mfd.NavigationMap.MFDMap.toggleLayer("OSM"); device.updateMenus(); }, # callback
130 func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "OSM"); }
131 );
132
133 pg.addMenuItem(3, "TERRAIN", pg,
134 func(dev, pg, mi) { pg.mfd.NavigationMap.MFDMap.toggleLayer("OSM"); device.updateMenus(); }, # callback
135 func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "OSM"); }
136 );
137
138 pg.addMenuItem(4, "AIRWAYS", pg, func(dev, pg, mi) { pg.mfd.NavigationMap.MFDMap.incrAIRWAYS(dev, mi); } );
139 #pg.addMenuItem(5, "STRMSCP", pg); Optional
140 #pg.addMenuItem(6, "PRECIP", pg); Optional, or NEXRAD
141 #pg.addMenuItem(7, "XM LTNG", pg); Optional, or DL LTNG
142 #pg.addMenuItem(8, "METAR", pg);
143 #pg.addMenuItem(9, "LEGEND", pg); Optional - only available with NEXRAD/XM LTNG/METAR/PROFILE selected
144 pg.addMenuItem(10, "BACK", pg, pg.topMenu); # Or should this just be the next button?
145 device.updateMenus();
146 },
147
148 # Display map toggle softkeys which change color depending
149 # on whether a particular layer is enabled or not.
150 display_toggle : func(device, svg, mi, layer) {
151 var bg_name = sprintf("SoftKey%d-bg",mi.menu_id);
152 if (me.MFDMap.isEnabled(layer)) {
153 device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5);
154 svg.setColor(0.0,0.0,0.0);
155 } else {
156 device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0);
157 svg.setColor(1.0,1.0,1.0);
158 }
159 svg.setText(mi.title);
160 svg.setVisible(1); # display function
161 },
162
163 };