var isNoSid = [0, 0]; var departurePage = { title: [nil, nil, nil], subtitle: [nil, nil], fontMatrix: [[0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0]], arrowsMatrix: [[0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0]], arrowsColour: [["ack", "ack", "ack", "ack", "ack", "ack"],["ack", "ack", "ack", "ack", "ack", "ack"]], L1: [nil, nil, "ack"], # content, title, colour L2: [nil, nil, "ack"], L3: [nil, nil, "ack"], L4: [nil, nil, "ack"], L5: [nil, nil, "ack"], L6: [nil, nil, "ack"], C1: [nil, nil, "ack"], C2: [nil, nil, "ack"], C3: [nil, nil, "ack"], C4: [nil, nil, "ack"], C5: [nil, nil, "ack"], C6: [nil, nil, "ack"], R1: [nil, nil, "ack"], R2: [nil, nil, "ack"], R3: [nil, nil, "ack"], R4: [nil, nil, "ack"], R5: [nil, nil, "ack"], R6: [nil, nil, "ack"], depAirport: nil, runways: nil, selectedRunway: nil, selectedSID: nil, selectedTransition: nil, sids: nil, transitions: nil, computer: nil, enableScrollRwy: 0, enableScrollSids: 0, scrollRwy: 0, scrollSids: 0, activePage: 0, # runways, sids, trans hasPressNoTrans: 0, # temporary _runways: nil, _sids: nil, _transitions: nil, new: func(icao, computer) { var page = {parents:[departurePage]}; page.id = icao; page.computer = computer; page._setupFirstTime(); page._setupPageWithData(); return page; }, del: func() { return nil; }, reset: func() { isNoSid[me.computer] = 0; me.selectedSID = nil; me.hasPressNoTrans = 0; }, _setupFirstTime: func() { if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { if (fmgc.flightPlanController.flightplans[2].departure_runway != nil) { me.selectedRunway = fmgc.flightPlanController.flightplans[2].departure_runway; } if (fmgc.flightPlanController.flightplans[2].sid != nil) { me.selectedSID = fmgc.flightPlanController.flightplans[2].sid; isNoSid[me.computer] = 0; } elsif (isNoSid[me.computer] == 1) { me.selectedSID = "NO SID"; me.hasPressNoTrans = 1; } } else { if (fmgc.flightPlanController.flightplans[me.computer].departure_runway != nil) { me.selectedRunway = fmgc.flightPlanController.flightplans[me.computer].departure_runway; } elsif (fmgc.flightPlanController.flightplans[2].departure_runway != nil) { me.selectedRunway = fmgc.flightPlanController.flightplans[2].departure_runway; } if (fmgc.flightPlanController.flightplans[me.computer].sid != nil) { me.selectedSID = fmgc.flightPlanController.flightplans[me.computer].sid; me.selectedTransition = fmgc.flightPlanController.flightplans[me.computer].sid_trans; isNoSid[me.computer] = 0; } elsif (fmgc.flightPlanController.flightplans[2].sid != nil) { me.selectedSID = fmgc.flightPlanController.flightplans[2].sid; me.selectedTransition = fmgc.flightPlanController.flightplans[2].sid_trans; isNoSid[me.computer] = 0; } elsif (isNoSid[me.computer] == 1) { me.selectedSID = "NO SID"; me.hasPressNoTrans = 1; } } }, _setupPageWithData: func() { me.title = ["DEPARTURE", " FROM ", left(me.id, 4)]; me.fontMatrix = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; me.arrowsMatrix = [[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0]]; me.arrowsColour = [["ack", "ack", "ack", "ack", "ack", "wht"], ["ack", "ack", "ack", "ack", "ack", "ack"]]; if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { me.L6 = [" RETURN END", nil, "wht"]; } else { me.L6 = [" F-PLN", " TMPY", "yel"]; me.arrowsColour[0][5] = "yel"; } if (me.activePage == 0) { me.updateRunways(); } else { me.updateSIDs(); } me.updateActiveRunway(); me.updateActiveSIDs(); me.updateActiveTransitions(); }, _clearPage: func() { me.L1 = [nil, nil, "ack"]; me.L2 = [nil, nil, "ack"]; me.L3 = [nil, nil, "ack"]; me.L4 = [nil, nil, "ack"]; me.L5 = [nil, nil, "ack"]; me.L6 = [nil, nil, "ack"]; me.C1 = [nil, nil, "ack"]; me.C2 = [nil, nil, "ack"]; me.C3 = [nil, nil, "ack"]; me.C4 = [nil, nil, "ack"]; me.C5 = [nil, nil, "ack"]; me.C6 = [nil, nil, "ack"]; me.R1 = [nil, nil, "ack"]; me.R2 = [nil, nil, "ack"]; me.R3 = [nil, nil, "ack"]; me.R4 = [nil, nil, "ack"]; me.R5 = [nil, nil, "ack"]; me.R6 = [nil, nil, "ack"]; me.fontMatrix = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; me.arrowsMatrix = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; me.arrowsColour = [["ack", "ack", "ack", "ack", "ack", "ack"], ["ack", "ack", "ack", "ack", "ack", "ack"]]; }, updatePage: func() { me._clearPage(); me._setupPageWithData(); }, updateActiveRunway: func() { if (me.selectedRunway != nil) { if (fmgc.flightPlanController.flightplans[2].departure_runway != nil) { if (fmgc.flightPlanController.flightplans[me.computer].departure_runway != nil) { me.L1 = [fmgc.flightPlanController.flightplans[me.computer].departure_runway.id, " RWY", "yel"]; } elsif (fmgc.flightPlanController.flightplans[2].departure_runway.id == me.selectedRunway.id) { me.L1 = [fmgc.flightPlanController.flightplans[2].departure_runway.id, " RWY", "grn"]; } else { me.L1 = ["---", " RWY", "wht"]; } } elsif (fmgc.flightPlanController.flightplans[me.computer].departure_runway != nil) { me.L1 = [fmgc.flightPlanController.flightplans[me.computer].departure_runway.id, " RWY", "yel"]; } else { me.L1 = ["---", " RWY", "wht"]; } } else { me.L1 = ["---", " RWY", "wht"]; } canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateActiveSIDs: func() { if (me.selectedSID == "NO SID") { if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { me.C1 = ["NONE", "SID", "grn"]; } else { me.C1 = ["NONE", "SID", "yel"]; } } elsif (me.selectedSID != nil) { if (fmgc.flightPlanController.flightplans[2].sid != nil) { if (fmgc.flightPlanController.flightplans[me.computer].sid != nil) { me.C1 = [fmgc.flightPlanController.flightplans[me.computer].sid.id, "SID", "yel"]; } elsif (fmgc.flightPlanController.flightplans[2].sid.id == me.selectedSID.id) { me.C1 = [fmgc.flightPlanController.flightplans[2].sid.id, "SID", "grn"]; } else { me.C1 = ["------- ", "SID", "wht"]; } } elsif (fmgc.flightPlanController.flightplans[me.computer].sid != nil) { me.C1 = [fmgc.flightPlanController.flightplans[me.computer].sid.id, "SID", "yel"]; } else { me.C1 = ["------- ", "SID", "wht"]; } } else { me.C1 = ["------- ", "SID", "wht"]; } canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateActiveTransitions: func() { if (!me.hasPressNoTrans) { if (me.selectedTransition != nil) { if (fmgc.flightPlanController.flightplans[2].sid_trans != nil) { if (fmgc.flightPlanController.flightplans[me.computer].sid_trans != nil) { me.R1 = [fmgc.flightPlanController.flightplans[me.computer].sid_trans.id, "TRANS", "yel"]; } elsif (fmgc.flightPlanController.flightplans[2].sid_trans.id == me.selectedTransition.id) { me.R1 = [fmgc.flightPlanController.flightplans[2].sid_trans.id, "TRANS", "grn"]; } else { me.R1 = ["-------", "TRANS ", "wht"]; } } elsif (fmgc.flightPlanController.flightplans[me.computer].sid_trans != nil) { me.R1 = [fmgc.flightPlanController.flightplans[me.computer].sid_trans.id, "SID", "yel"]; } else { me.R1 = ["-------", "TRANS ", "wht"]; } } else { me.R1 = ["-------", "TRANS ", "wht"]; } } else { if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { me.R1 = ["NONE", "TRANS ", "grn"]; } else { me.R1 = ["NONE", "TRANS ", "yel"]; } } canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateRunways: func() { if (me.depAirport == nil) { me.depAirport = findAirportsByICAO(left(me.id, 4)); } me._runways = keys(me.depAirport[0].runways); me.runways = sort(me._runways,func(a,b) cmp(a,b)); if (size(me.runways) >= 1) { me.L2 = [" " ~ me.runways[0 + me.scrollRwy], nil, "blu"]; me.C2 = [math.round(me.depAirport[0].runways[me.runways[0 + me.scrollRwy]].length) ~ "M", "AVAILABLE RUNWAYS", "blu"]; me.R2 = ["CRS" ~ math.round(me.depAirport[0].runways[me.runways[0 + me.scrollRwy]].heading), nil, "blu"]; if (me.runways[0 + me.scrollRwy] != me.selectedRunway) { me.arrowsMatrix[0][1] = 1; me.arrowsColour[0][1] = "blu"; } else { me.arrowsMatrix[0][1] = 0; me.arrowsColour[0][1] = "ack"; } } if (size(me.runways) >= 2) { me.L3 = [" " ~ me.runways[1 + me.scrollRwy], nil, "blu"]; me.C3 = [math.round(me.depAirport[0].runways[me.runways[1 + me.scrollRwy]].length) ~ "M", nil, "blu"]; me.R3 = ["CRS" ~ math.round(me.depAirport[0].runways[me.runways[1 + me.scrollRwy]].heading), nil, "blu"]; if (me.runways[1 + me.scrollRwy] != me.selectedRunway) { me.arrowsMatrix[0][2] = 1; me.arrowsColour[0][2] = "blu"; } else { me.arrowsMatrix[0][2] = 0; me.arrowsColour[0][2] = "ack"; } } if (size(me.runways) >= 3) { me.L4 = [" " ~ me.runways[2 + me.scrollRwy], nil, "blu"]; me.C4 = [math.round(me.depAirport[0].runways[me.runways[2 + me.scrollRwy]].length) ~ "M", nil, "blu"]; me.R4 = ["CRS" ~ math.round(me.depAirport[0].runways[me.runways[2 + me.scrollRwy]].heading), nil, "blu"]; if (me.runways[2 + me.scrollRwy] != me.selectedRunway) { me.arrowsMatrix[0][3] = 1; me.arrowsColour[0][3] = "blu"; } else { me.arrowsMatrix[0][3] = 0; me.arrowsColour[0][3] = "ack"; } } if (size(me.runways) >= 4) { me.L5 = [" " ~ me.runways[3 + me.scrollRwy], nil, "blu"]; me.C5 = [math.round(me.depAirport[0].runways[me.runways[3 + me.scrollRwy]].length) ~ "M", nil, "blu"]; me.R5 = ["CRS" ~ math.round(me.depAirport[0].runways[me.runways[3 + me.scrollRwy]].heading), nil, "blu"]; if (me.runways[3 + me.scrollRwy] != me.selectedRunway) { me.arrowsMatrix[0][4] = 1; me.arrowsColour[0][4] = "blu"; } else { me.arrowsMatrix[0][4] = 0; me.arrowsColour[0][4] = "ack"; } } if (size(me.runways) > 4) { me.enableScrollRwy = 1; } canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateSIDs: func() { if (me.depAirport == nil) { me.depAirport = findAirportsByICAO(left(me.id, 4)); } if (me.selectedRunway != nil) { me._sids = me.depAirport[0].sids(me.selectedRunway.id); } else { me._sids = me.depAirport[0].sids(); } me.sids = sort(me._sids,func(a,b) cmp(a,b)); if (me.sids == nil) { me.sids = ["NO SID"]; } else { append(me.sids, "NO SID"); } if (size(me.sids) >= 1) { me.L2 = [" " ~ me.sids[0 + me.scrollSids], "SIDS", "blu"]; if (me.sids[0 + me.scrollSids] != me.selectedSID) { me.arrowsMatrix[0][1] = 1; me.arrowsColour[0][1] = "blu"; } else { me.arrowsMatrix[0][1] = 0; me.arrowsColour[0][1] = "ack"; } } if (size(me.sids) >= 2) { me.L3 = [" " ~ me.sids[1 + me.scrollSids], nil, "blu"]; if (me.sids[1 + me.scrollSids] != me.selectedSID) { me.arrowsMatrix[0][2] = 1; me.arrowsColour[0][2] = "blu"; } else { me.arrowsMatrix[0][2] = 0; me.arrowsColour[0][2] = "ack"; } } if (size(me.sids) >= 3) { me.L4 = [" " ~ me.sids[2 + me.scrollSids], nil, "blu"]; if (me.sids[2 + me.scrollSids] != me.selectedSID) { me.arrowsMatrix[0][3] = 1; me.arrowsColour[0][3] = "blu"; } else { me.arrowsMatrix[0][3] = 0; me.arrowsColour[0][3] = "ack"; } } if (size(me.sids) >= 4) { me.L5 = [" " ~ me.sids[3 + me.scrollSids], nil, "blu"]; if (me.sids[3 + me.scrollSids] != me.selectedSID) { me.arrowsMatrix[0][4] = 1; me.arrowsColour[0][4] = "blu"; } else { me.arrowsMatrix[0][4] = 0; me.arrowsColour[0][4] = "ack"; } } me.C2 = [nil, "AVAILABLE", "wht"]; me.R2 = [nil, "TRANS ", "wht"]; if (size(me.sids) > 4) { me.enableScrollSids = 1; } canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, clearTransitions: func() { me.R2 = [nil, "TRANS", "wht"]; me.R3 = [nil, "TRANS", "wht"]; me.R4 = [nil, "TRANS", "wht"]; me.R5 = [nil, "TRANS", "wht"]; me.arrowsMatrix[1][1] = 0; me.arrowsColour[1][1] = "ack"; me.arrowsMatrix[1][2] = 0; me.arrowsColour[1][2] = "ack"; me.arrowsMatrix[1][3] = 0; me.arrowsColour[1][3] = "ack"; me.arrowsMatrix[1][4] = 0; me.arrowsColour[1][4] = "ack"; }, updateTransitions: func() { if (me.depAirport == nil) { me.depAirport = findAirportsByICAO(left(me.id, 4)); } if (me.selectedSID == nil) { me.R2 = ["NO TRANS ", "TRANS", "blu"]; if (!me.hasPressNoTrans) { me.arrowsMatrix[1][1] = 1; me.arrowsColour[1][1] = "blu"; } else { me.arrowsMatrix[1][1] = 0; me.arrowsColour[1][1] = "ack"; } return; } me._transitions = me.depAirport[0].getSid(me.selectedSID).transitions; me.transitions = sort(me._transitions,func(a,b) cmp(a,b)); if (size(me.transitions) == 0) { me.R2 = ["NO TRANS ", "TRANS", "blu"]; if (!me.hasPressNoTrans) { me.arrowsMatrix[1][1] = 1; me.arrowsColour[1][1] = "blu"; } else { me.arrowsMatrix[1][1] = 0; me.arrowsColour[1][1] = "ack"; } } elsif (size(me.transitions) >= 1) { me.R2 = [me.transitions[0] ~ " ", "TRANS", "blu"]; if (me.transitions[0] != me.selectedTransition) { me.arrowsMatrix[1][1] = 1; me.arrowsColour[1][1] = "blu"; } else { me.arrowsMatrix[1][1] = 0; me.arrowsColour[1][1] = "ack"; } } elsif (size(me.transitions) >= 2) { me.R3 = [me.transitions[1] ~ " ", nil, "blu"]; if (me.transitions[1] != me.selectedTransition) { me.arrowsMatrix[1][2] = 1; me.arrowsColour[1][2] = "blu"; } else { me.arrowsMatrix[1][2] = 0; me.arrowsColour[1][2] = "ack"; } } elsif (size(me.transitions) >= 3) { me.R4 = [me.transitions[2] ~ " ", nil, "blu"]; if (me.transitions[2] != me.selectedTransition) { me.arrowsMatrix[1][3] = 1; me.arrowsColour[1][3] = "blu"; } else { me.arrowsMatrix[1][3] = 0; me.arrowsColour[1][3] = "ack"; } } elsif (size(me.transitions) >= 4) { me.R5 = [me.transitions[3] ~ " ", nil, "blu"]; if (me.transitions[3] != me.selectedTransition) { me.arrowsMatrix[1][4] = 1; me.arrowsColour[1][4] = "blu"; } else { me.arrowsMatrix[1][4] = 0; me.arrowsColour[1][4] = "ack"; } } }, makeTmpy: func() { if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { if (!dirToFlag) { fmgc.flightPlanController.createTemporaryFlightPlan(me.computer); me.L6 = [" F-PLN", " TMPY", "yel"]; me.arrowsColour[0][5] = "yel"; canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); } else { setprop("MCDU[" ~ i ~ "]/scratchpad-msg", 1); setprop("MCDU[" ~ i ~ "]/scratchpad", "DIR TO IN PROGRESS"); } } }, scrollUp: func() { if (me.activePage == 0) { if (me.enableScrollRwy) { me.scrollRwy += 1; if (me.scrollRwy > size(me.runways) - 4) { me.scrollRwy = 0; } me.updateRunways(); } } else { if (me.enableScrollSids) { me.scrollSids += 1; if (me.scrollSids > size(me.sids) - 4) { me.scrollSids = 0; } me.updateSIDs(); if (me.selectedSID == nil or me.selectedSID == "NO SID") { me.clearTransitions(); } else { me.updateTransitions(); } me.hasPressNoTrans = 0; } } }, scrollDn: func() { if (me.activePage == 0) { if (me.enableScrollRwy) { me.scrollRwy -= 1; if (me.scrollRwy < 0) { me.scrollRwy = size(me.runways) - 4; } me.updateRunways(); } } else { if (me.enableScrollSids) { me.scrollSids -= 1; if (me.scrollSids < 0) { me.scrollSids = size(me.sids) - 4; } me.updateSIDs(); if (me.selectedSID == nil or me.selectedSID == "NO SID") { me.clearTransitions(); } else { me.updateTransitions(); } me.hasPressNoTrans = 0; } } }, scrollLeft: func() { me.activePage = !me.activePage; me.updatePage(); }, scrollRight: func() { me.activePage = !me.activePage; me.updatePage(); }, depPushbuttonLeft: func(index) { if (me.activePage == 0) { if (size(me.runways) >= (index - 1)) { if (!dirToFlag) { me.selectedSID = nil; isNoSid[me.computer] = 0; me.hasPressNoTrans = 0; me.selectedRunway = me.depAirport[0].runway(me.runways[index - 2 + me.scrollRwy]); me.makeTmpy(); fmgc.flightPlanController.flightplans[me.computer].departure_runway = me.selectedRunway; me.updateActiveRunway(); me.updateRunways(); fmgc.flightPlanController.flightPlanChanged(me.computer); me.scrollRight(); } else { setprop("MCDU[" ~ me.computer ~ "]/scratchpad-msg", 1); setprop("MCDU[" ~ me.computer ~ "]/scratchpad", "DIR TO IN PROGRESS"); } } else { notAllowed(me.computer); } } else { if (size(me.sids) >= (index - 1)) { if (!dirToFlag) { me.selectedSID = me.sids[index - 2 + me.scrollSids]; me.makeTmpy(); if (me.selectedSID != "NO SID") { isNoSid[me.computer] = 0; fmgc.flightPlanController.flightplans[me.computer].sid = me.selectedSID; } else { isNoSid[me.computer] = 1; fmgc.flightPlanController.flightplans[me.computer].sid = nil; fmgc.flightPlanController.insertNOSID(me.computer); } me.updateActiveSIDs(); me.updateSIDs(); if (me.selectedSID != "NO SID") { me.hasPressNoTrans = 0; me.updateTransitions(); } else { me.hasPressNoTrans = 1; } me.updateActiveTransitions(); fmgc.flightPlanController.flightPlanChanged(me.computer); } else { setprop("MCDU[" ~ me.computer ~ "]/scratchpad-msg", 1); setprop("MCDU[" ~ me.computer ~ "]/scratchpad", "DIR TO IN PROGRESS"); } } else { notAllowed(me.computer); } } }, depPushbuttonRight: func(index) { if (index == 2 and size(me.transitions) == 0) { if (!dirToFlag) { me.hasPressNoTrans = 1; me.updateActiveTransitions(); me.updateTransitions(); } else { setprop("MCDU[" ~ me.computer ~ "]/scratchpad-msg", 1); setprop("MCDU[" ~ me.computer ~ "]/scratchpad", "DIR TO IN PROGRESS"); } } elsif (size(me.transitions) >= (index - 1)) { if (!dirToFlag) { me.selectedTransition = me.transitions[index - 2]; me.makeTmpy(); fmgc.flightPlanController.flightplans[me.computer].sid_trans = me.depAirport[0].getSid(me.selectedSID).transition(me.selectedTransition); me.updateActiveTransitions(); me.updateTransitions(); fmgc.flightPlanController.flightPlanChanged(me.computer); } else { setprop("MCDU[" ~ me.computer ~ "]/scratchpad-msg", 1); setprop("MCDU[" ~ me.computer ~ "]/scratchpad", "DIR TO IN PROGRESS"); } } else { notAllowed(me.computer); } }, };