1
0
Fork 0
fgdata/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas
Stuart Buchanan d306e7ba10 Set standby COM frequency from Airport pages
Support selecting a frequency from the Nearest Airport
and Airport Information pages and pressing ENT.  Nice.
2018-01-13 19:17:58 +00:00

143 lines
4.3 KiB
Text

# AirportInfo Controller
var AirportInfoController =
{
# Vertical ranges, and labels.
# Unlike some other map displays, we keep the range constant at 4nm an change
# the ScreenRange to zoom in. Otherwise as we zoom in, the center of the
# runways moves out of the range of the display and they are not drawn.
# Ranges are scaled to the display height with range 1 displaying 4nm vertically.
# 2000nm = 12,152,000ft.
RANGES : [{range: 4/500/6076.12, label: "500ft"},
{range: 4/750/6076.12, label: "750ft"},
{range: 4/1000/6076.12, label: "1000ft"},
{range: 4/1500/6076.12, label: "1500ft"},
{range: 4/2000/6076.12, label: "2000ft"},
{range: 8, label: "0.5nm"},
{range: 5.33, label: "0.75nm"},
{range: 4, label: "1nm"},
{range: 2, label: "2nm"},
{range: 1.33, label: "3nm"},
{range: 1, label: "4nm"},
{range: 0.66, label: "6nm"},
{range: 0.5, label: "8nm"},
{range: 0.4, label: "10nm"} ],
new : func (page, svg)
{
var obj = { parents : [ AirportInfoController, MFDPageController.new(page)] };
obj.airport = "";
obj.runway = "";
obj.runwayIdx = -1;
obj.info = nil;
obj.page = page;
obj.crsrToggle = 0;
obj.current_zoom = 7;
# Initial airport is our current location.
var current_apt = airportinfo("airport");
obj.setAirport(current_apt.id);
obj.setZoom(7);
return obj;
},
setAirport : func(id)
{
if (id == me.airport) return;
var apt = airportinfo(id);
if (apt != nil) {
me.airport = id;
me.info= airportinfo(id);
}
# Reset airport display. We do this irrespective of whether the id
# is valid, as it allows us to clear any bad user input from the ID field
me.page.displayAirport(me.info);
},
setRunway : func(runwayID)
{
me.page.displayRunway(me.info.runways[runwayID]);
},
# Control functions for Input
zoomIn : func() {
me.setZoom(me.current_zoom -1);
},
zoomOut : func() {
me.setZoom(me.current_zoom +1);
},
handleRange : func(val)
{
var incr_or_decr = (val > 0) ? 1 : -1;
me.setZoom(me.current_zoom + incr_or_decr);
},
setZoom : func(zoom) {
if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return;
me.current_zoom = zoom;
me.page.setZoom(me.RANGES[zoom].range * fg1000.MAP_PARTIAL.HEIGHT, me.RANGES[zoom].label);
},
handleCRSR : func() {
me.crsrToggle = (! me.crsrToggle);
if (me.crsrToggle) {
me.page.showCRSR();
} else {
me.page.hideCRSR();
}
return emesary.Transmitter.ReceiptStatus_Finished;
},
handleFMSInner : func(value) {
if (me.crsrToggle == 1) {
var select = me.page.incrSmall(value);
if ((select.name == "AirportInfoRunway") and (select.value != nil)) {
# Selection values are of the form "06L-12R". We need to set the
# runway to the left half.
var idx = find("-", select.value);
if (idx != -1) {
var rwy = substr(select.value, 0, idx);
me.setRunway(rwy);
}
}
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
return me.page.mfd.SurroundController.handleFMSInner(value);
}
},
handleFMSOuter : func(value) {
if (me.crsrToggle == 1) {
me.page.moveCRSR(value);
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
return me.page.mfd.SurroundController.handleFMSOuter(value);
}
},
handleEnter : func(value) {
if (me.crsrToggle == 1) {
var select = me.page.handleEnter();
if (select.name == "AirportInfoID") me.setAirport(select.value);
if (substr(select.name, 0, 15) == "AirportInfoFreq") {
me.page.mfd.SurroundController.setStandbyComFreq(select.value);
}
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
return emesary.Transmitter.ReceiptStatus_NotProcessed;
}
},
handleClear : func(value) {
if (me.crsrToggle == 1) {
# Cancel any data entry
me.page.handleClear();
} else {
return emesary.Transmitter.ReceiptStatus_NotProcessed;
}
},
# Reset controller if required when the page is displayed or hidden
ondisplay : func() {
me.RegisterWithEmesary();
},
offdisplay : func() {
me.DeRegisterWithEmesary();
},
};