| 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 |
# NearestAirportsPFD Controller |
| 18 |
var NearestAirportsPFDController = |
| 19 |
{ |
| 20 |
MODE : { |
| 21 |
NONE : 0, # Nothing displayed |
| 22 |
NEAREST : 1, # Nearest Airports pane visible |
| 23 |
INFO : 2, # Airport Info pane visible |
| 24 |
}, |
| 25 |
|
| 26 |
new : func (page, svg) |
| 27 |
{ |
| 28 |
var obj = { parents : [ NearestAirportsPFDController, MFDPageController.new(page) ] }; |
| 29 |
|
| 30 |
# Current active UI group. |
| 31 |
obj.page = page; |
| 32 |
obj._mode = NearestAirportsPFDController.MODE.NONE; |
| 33 |
obj._crsrToggle = 0; |
| 34 |
return obj; |
| 35 |
}, |
| 36 |
|
| 37 |
selectNearest : func() { |
| 38 |
me.selectGroup(NearestAirportsPFDController.MODE.NEAREST) |
| 39 |
}, |
| 40 |
selectInfo : func() { |
| 41 |
me.selectGroup(NearestAirportsPFDController.MODE.INFO); |
| 42 |
}, |
| 43 |
selectNone : func() { |
| 44 |
me.selectGroup(NearestAirportsPFDController.MODE.NONE); |
| 45 |
}, |
| 46 |
getSelectedMode : func() { |
| 47 |
return me._mode; |
| 48 |
}, |
| 49 |
selectGroup : func(grp) { |
| 50 |
me._mode = grp; |
| 51 |
if (grp == NearestAirportsPFDController.MODE.NONE) { |
| 52 |
me.page.offdisplay(); |
| 53 |
} |
| 54 |
if (grp == NearestAirportsPFDController.MODE.NEAREST) { |
| 55 |
me.page.displayNearest(); |
| 56 |
} |
| 57 |
if (grp == NearestAirportsPFDController.MODE.INFO) { |
| 58 |
var aptdata = me.getAirport(me.page.getSelectedAirportID()); |
| 59 |
me.page.updateAirportData(aptdata); |
| 60 |
me.page.displayInfo(); |
| 61 |
} |
| 62 |
}, |
| 63 |
|
| 64 |
# Input Handling |
| 65 |
handleCRSR : func(value) { |
| 66 |
me._crsrToggle = (! me._crsrToggle); |
| 67 |
if (me._crsrToggle) { |
| 68 |
me.page.airportSelect.showCRSR(); |
| 69 |
} else { |
| 70 |
# Hide the cursor and reset any highlighting |
| 71 |
me.page.airportSelect.hideCRSR(); |
| 72 |
} |
| 73 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 74 |
}, |
| 75 |
handleFMSInner : func(value) { |
| 76 |
if (me._crsrToggle and (me._mode == NearestAirportsPFDController.MODE.NEAREST)) { |
| 77 |
# Scroll through the nearest airports list |
| 78 |
me.page.airportSelect.incrSmall(value); |
| 79 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 80 |
} else { |
| 81 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 82 |
} |
| 83 |
}, |
| 84 |
handleFMSOuter : func(value) { |
| 85 |
return me.handleFMSInner(value); |
| 86 |
}, |
| 87 |
handleEnter : func(value) { |
| 88 |
if (me._mode == NearestAirportsPFDController.MODE.NEAREST) { |
| 89 |
# Enable the cursor if it's not already enabled. |
| 90 |
me._crsrToggle = 1; |
| 91 |
me.page.airportSelect.showCRSR(); |
| 92 |
|
| 93 |
# Load the current airport and display it |
| 94 |
if (me.page.getSelectedAirportID() != nil) { |
| 95 |
me.selectInfo(); |
| 96 |
} |
| 97 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 98 |
} else if (me._mode == NearestAirportsPFDController.MODE.INFO) { |
| 99 |
# Pressing Enter on the Info window hides the info window and selects the |
| 100 |
# next airport on the list. |
| 101 |
# Load the current airport and display it |
| 102 |
me.selectNearest(); |
| 103 |
me.page.airportSelect.incrSmall(1); |
| 104 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 105 |
} else { |
| 106 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 107 |
} |
| 108 |
}, |
| 109 |
handleClear : func(value) { |
| 110 |
if (me._mode == NearestAirportsPFDController.MODE.NEAREST) { |
| 111 |
# Finished - unload the page. |
| 112 |
me.page.offdisplay(); |
| 113 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 114 |
} else if (me._mode == NearestAirportsPFDController.MODE.INFO) { |
| 115 |
# Pressing Clear on the Info window hides the info window and selects the |
| 116 |
# next airport on the list, just like Enter |
| 117 |
# Load the current airport and display it |
| 118 |
me.selectNearest(); |
| 119 |
me.page.airportSelect.incrSmall(1); |
| 120 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 121 |
} else { |
| 122 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 123 |
} |
| 124 |
}, |
| 125 |
|
| 126 |
# Reset controller if required when the page is displayed or hidden |
| 127 |
ondisplay : func() { |
| 128 |
me.RegisterWithEmesary(); |
| 129 |
me.getNearestAirportsPFD(); |
| 130 |
me.selectNearest(); |
| 131 |
}, |
| 132 |
offdisplay : func() { |
| 133 |
me.DeRegisterWithEmesary(); |
| 134 |
}, |
| 135 |
|
| 136 |
getNearestAirportsPFD : func() { |
| 137 |
var notification = notifications.PFDEventNotification.new( |
| 138 |
"MFD", |
| 139 |
me.getDeviceID(), |
| 140 |
notifications.PFDEventNotification.NavData, |
| 141 |
{Id: "NearestAirports", Value: nil}); |
| 142 |
|
| 143 |
var response = me._transmitter.NotifyAll(notification); |
| 144 |
|
| 145 |
if (! me._transmitter.IsFailed(response)) { |
| 146 |
me.page.updateAirports(notification.EventParameter.Value); |
| 147 |
} else { |
| 148 |
return nil; |
| 149 |
} |
| 150 |
}, |
| 151 |
|
| 152 |
getAirport : func(id) { |
| 153 |
# Use Emesary to get the airport |
| 154 |
var notification = notifications.PFDEventNotification.new( |
| 155 |
"MFD", |
| 156 |
me.getDeviceID(), |
| 157 |
notifications.PFDEventNotification.NavData, |
| 158 |
{Id: "AirportByID", Value: id}); |
| 159 |
|
| 160 |
var response = me._transmitter.NotifyAll(notification); |
| 161 |
|
| 162 |
if (! me._transmitter.IsFailed(response)) { |
| 163 |
var apt_list = notification.EventParameter.Value; |
| 164 |
if ((apt_list != nil) and (size(apt_list) > 0)) { |
| 165 |
return apt_list[0]; |
| 166 |
} else { |
| 167 |
return nil; |
| 168 |
} |
| 169 |
} else { |
| 170 |
return nil; |
| 171 |
} |
| 172 |
}, |
| 173 |
}; |