From 10bf4c5cb897580a70330c58f86733cac7ddc30e Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Thu, 21 May 2020 19:02:59 +0100 Subject: [PATCH] It works --- Models/Instruments/MCDU/MCDU.nas | 4 +- Nasal/FMGC/flightplan-waypoints.nas | 64 ++++++++++++++++++++-- Nasal/MCDU/MCDU.nas | 21 ++++---- Nasal/MCDU/NEWWAYPOINT.nas | 83 +++++++++++++++++++++++++++++ Nasal/MCDU/PILOTWAYPOINT.nas | 20 +++---- Nasal/MCDU/STATUS.nas | 8 +-- 6 files changed, 170 insertions(+), 30 deletions(-) create mode 100644 Nasal/MCDU/NEWWAYPOINT.nas diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 2d8528f0..444d2bbb 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -809,7 +809,7 @@ var canvas_MCDU_base = { me["arrow5R"].hide(); } - if (fmgc.WaypointDatabase.confirm) { + if (fmgc.WaypointDatabase.confirm[i]) { me["Simple_R5"].setText("CONFIRM DELETE ALL "); me["Simple_R5"].setColor(getprop("/MCDUC/colors/amb/r"),getprop("/MCDUC/colors/amb/g"),getprop("/MCDUC/colors/amb/b")); me["arrow5R"].setColor(getprop("/MCDUC/colors/amb/r"),getprop("/MCDUC/colors/amb/g"),getprop("/MCDUC/colors/amb/b")); @@ -988,7 +988,7 @@ var canvas_MCDU_base = { if (myPilotWP[i] != nil) { - me["Simple_PageNum"].setText((myPilotWP[i].scroll + 1) ~ "/" ~ (fmgc.WaypointDatabase.getCount())); + me["Simple_PageNum"].setText(fmgc.WaypointDatabase.getNoOfIndex(myPilotWP[i].scroll) ~ "/" ~ (fmgc.WaypointDatabase.getCount())); me["Simple_Title"].setText(sprintf("%s", myPilotWP[i].title ~ " ")); diff --git a/Nasal/FMGC/flightplan-waypoints.nas b/Nasal/FMGC/flightplan-waypoints.nas index 765a926e..b278bbbb 100644 --- a/Nasal/FMGC/flightplan-waypoints.nas +++ b/Nasal/FMGC/flightplan-waypoints.nas @@ -9,7 +9,7 @@ var nilTree = { var WaypointDatabase = { waypointsVec: [], - confirm: 0, + confirm: [0, 0], # addWP - adds pilot waypoint to waypoints vector # arg: wpObj - passed pilot waypoint object # return: @@ -47,7 +47,8 @@ var WaypointDatabase = { }, # delete - empties waypoints vector - delete: func() { + # callerIdx is the calling mcdu + delete: func(callerIdx) { var noDel = 0; for (var i = 0; i < me.getSize(); i = i + 1) { if (me.waypointsVec[i] != nil) { @@ -57,6 +58,10 @@ var WaypointDatabase = { } } me.write(); + if (me.getCount() != 0) { + setprop("/MCDU[" ~ callerIdx ~ "]/scratchpad-msg", 1); + setprop("/MCDU[" ~ callerIdx ~ "]/scratchpad", "PILOT ELEMENT RETAINED"); + } }, # deleteAtIndex - delete at specific index. Set to nil, so it still exists in vector deleteAtIndex: func(index) { @@ -86,6 +91,47 @@ var WaypointDatabase = { } return -1; }, + # getNextFromIndex - find the next non-nil after a passed index + getNextFromIndex: func(index) { + for (var i = (index + 1); i < me.getSize(); i = i + 1) { + if (me.waypointsVec[i] != nil) { + return i; + } + } + + for (var i = 0; i <= index; i = i + 1) { + if (me.waypointsVec[i] != nil) { + return i; + } + } + return index; + }, + # getPreviousFromIndex - find the next non-nil before a passed index + getPreviousFromIndex: func(index) { + for (var i = (index - 1); i >= 0; i = i - 1) { + if (me.waypointsVec[i] != nil) { + return i; + } + } + + for (var i = (me.getSize() - 1); i >= index; i = i - 1) { + if (me.waypointsVec[i] != nil) { + return i; + } + } + return index; + }, + # getNoOfIndex - return what number passed item is in list, neglecting "nil" + getNoOfIndex: func(index) { + var count = 0; + for (var i = 0; i <= index; i = i + 1) { + if (me.waypointsVec[i] == nil) { + continue; + } + count += 1; + } + return count; + }, # getCount - return size, neglecting "nil" getCount: func() { var count = 0; @@ -224,4 +270,16 @@ var pilotWaypoint = { getId: func() { if (me.id != nil) { return id; } }, -}; \ No newline at end of file +}; + +setlistener("/MCDU[0]/page", func() { + if (getprop("/MCDU[0]/page") != "PILOTWP" and getprop("/MCDU[0]/page") != "STATUS") { + WaypointDatabase.confirm[0] = 0; + } +}, 0, 0); + +setlistener("/MCDU[1]/page", func() { + if (getprop("/MCDU[1]/page") != "PILOTWP" and getprop("/MCDU[1]/page") != "STATUS") { + WaypointDatabase.confirm[1] = 0; + } +}, 0, 0); \ No newline at end of file diff --git a/Nasal/MCDU/MCDU.nas b/Nasal/MCDU/MCDU.nas index 14e951c1..a394ca82 100644 --- a/Nasal/MCDU/MCDU.nas +++ b/Nasal/MCDU/MCDU.nas @@ -462,12 +462,16 @@ var rskbutton = func(btn, i) { } else if (getprop("/MCDU[" ~ i ~ "]/page") == "F-PLNA" or getprop("/MCDU[" ~ i ~ "]/page") == "F-PLNB") { canvas_mcdu.myFpln[i].pushButtonRight(1); } else if (getprop("/MCDU[" ~ i ~ "]/page") == "DATA2") { - if (canvas_mcdu.myPilotWP[i] != nil) { - canvas_mcdu.myPilotWP[i].del(); + if (fmgc.WaypointDatabase.getCount() > 0) { + if (canvas_mcdu.myPilotWP[i] != nil) { + canvas_mcdu.myPilotWP[i].del(); + } + canvas_mcdu.myPilotWP[i] = nil; + canvas_mcdu.myPilotWP[i] = pilotWaypointPage.new(i); + setprop("/MCDU[" ~ i ~ "]/page", "PILOTWP"); + } else { + notAllowed(i); # todo spawn new waypoints page } - canvas_mcdu.myPilotWP[i] = nil; - canvas_mcdu.myPilotWP[i] = pilotWaypointPage.new(i); - setprop("/MCDU[" ~ i ~ "]/page", "PILOTWP"); } else { notAllowed(i); } @@ -621,12 +625,11 @@ var rskbutton = func(btn, i) { canvas_mcdu.myDirTo[i].fieldR6(); } else if (getprop("/MCDU[" ~ i ~ "]/page") == "PILOTWP") { if (canvas_mcdu.myPilotWP[i] != nil) { - if (fmgc.WaypointDatabase.confirm) { - fmgc.WaypointDatabase.confirm = 0; + if (fmgc.WaypointDatabase.confirm[i]) { + fmgc.WaypointDatabase.confirm[i] = 0; canvas_mcdu.myPilotWP[i].deleteCmd(); } else { - fmgc.WaypointDatabase.confirm = 1; - canvas_mcdu.myPilotWP[i].deleteCmd(); + fmgc.WaypointDatabase.confirm[i] = 1; } } } else { diff --git a/Nasal/MCDU/NEWWAYPOINT.nas b/Nasal/MCDU/NEWWAYPOINT.nas new file mode 100644 index 00000000..7decfb41 --- /dev/null +++ b/Nasal/MCDU/NEWWAYPOINT.nas @@ -0,0 +1,83 @@ +var newWaypointPage = { + title: 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"], + new: func(computer) { + var ap = {parents:[newWaypointPage]}; + ap.computer = computer; + ap._setupPageWithData(); + return ap; + }, + del: func() { + return nil; + }, + _setupPageWithData: func() { + me.title = "PILOTS WAYPOINT"; + me.L1 = [fmgc.WaypointDatabase.waypointsVec[me.scroll].id, " IDENT", "grn"]; + + var ghost = fmgc.WaypointDatabase.waypointsVec[me.scroll].wpGhost; + me.L2 = [me.translateLatitude(ghost.lat) ~ "/" ~ me.translateLongitude(ghost.lon), " LAT/LON", "grn"]; + + me.R5 = ["WAYPOINT ", "NEW ", "wht"]; + me.R6 = ["DELETE ALL ", nil, "blu"]; + + me.arrowsMatrix = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1]]; + me.arrowsColour = [["ack", "ack", "ack", "ack", "ack", "ack"], ["ack", "ack", "ack", "ack", "wht", "blu"]]; + canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); + }, + translateLatitude: func(latitude) { + var split = split(".", sprintf("%s", latitude)); + var degree = split[0]; + if (latitude >= 0) { + var decimal = sprintf("%04.1f", (latitude - num(degree)) * 60); + return sprintf("%02.0f", degree) ~ decimal ~ "N"; + } else { + var decimal = sprintf("%04.1f", (latitude - num(degree)) * 60); + return sprintf("%02.0f", degree) ~ decimal ~ "S"; + } + }, + translateLongitude: func(longitude) { + var split = split(".", sprintf("%s", longitude)); + var degree = split[0]; + if (longitude >= 0) { + var decimal = sprintf("%04.1f", (longitude - num(degree)) * 60); + return sprintf("%03.0f", degree) ~ decimal ~ "E"; + } else { + var decimal = sprintf("%04.1f", (longitude - num(degree)) * 60); + return sprintf("%03.0f", degree) ~ decimal ~ "W"; + } + }, + deleteCmd: func() { + if (fmgc.WaypointDatabase.confirm[me.computer]) { + me.R6 = ["CONFIRM DELETE ALL ", nil, "amb"]; + me.arrowsColour[1][5] = "amb"; + canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); + } else { + me.R6 = ["DELETE ALL ", nil, "blu"]; + me.arrowsColour[1][5] = "blu"; + fmgc.WaypointDatabase.delete(me.computer); + me.scroll = fmgc.WaypointDatabase.getNonNilIndex(); + me._setupPageWithData(); + canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); + } + }, +}; \ No newline at end of file diff --git a/Nasal/MCDU/PILOTWAYPOINT.nas b/Nasal/MCDU/PILOTWAYPOINT.nas index c323b2f1..47987a83 100644 --- a/Nasal/MCDU/PILOTWAYPOINT.nas +++ b/Nasal/MCDU/PILOTWAYPOINT.nas @@ -68,31 +68,27 @@ var pilotWaypointPage = { } }, scrollLeft: func() { - me.scroll -= 1; - if (me.scroll < 0) { - me.scroll = (fmgc.WaypointDatabase.getSize() - 1); - } + me.scroll = fmgc.WaypointDatabase.getPreviousFromIndex(me.scroll); me._setupPageWithData(); canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, scrollRight: func() { - me.scroll += 1; - if (me.scroll > (fmgc.WaypointDatabase.getSize() - 1)) { - me.scroll = 0; - } + me.scroll = fmgc.WaypointDatabase.getNextFromIndex(me.scroll); me._setupPageWithData(); canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, deleteCmd: func() { - if (fmgc.WaypointDatabase.confirm) { + if (fmgc.WaypointDatabase.confirm[me.computer]) { me.R6 = ["CONFIRM DELETE ALL ", nil, "amb"]; me.arrowsColour[1][5] = "amb"; + canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); } else { me.R6 = ["DELETE ALL ", nil, "blu"]; me.arrowsColour[1][5] = "blu"; - fmgc.WaypointDatabase.delete(); + fmgc.WaypointDatabase.delete(me.computer); + me.scroll = fmgc.WaypointDatabase.getNonNilIndex(); + me._setupPageWithData(); + canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); } - me.scroll = fmgc.WaypointDatabase.getNonNilIndex(); - canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, }; \ No newline at end of file diff --git a/Nasal/MCDU/STATUS.nas b/Nasal/MCDU/STATUS.nas index 335a1d65..754cac62 100644 --- a/Nasal/MCDU/STATUS.nas +++ b/Nasal/MCDU/STATUS.nas @@ -6,11 +6,11 @@ var statusInput = func(key, i) { if (key == "L3") { fmgc.switchDatabase(); } elsif (key == "R5") { - if (fmgc.WaypointDatabase.confirm) { - fmgc.WaypointDatabase.delete(); - fmgc.WaypointDatabase.confirm = 0; + if (fmgc.WaypointDatabase.confirm[i]) { + fmgc.WaypointDatabase.delete(i); + fmgc.WaypointDatabase.confirm[i] = 0; } else { - fmgc.WaypointDatabase.confirm = 1; + fmgc.WaypointDatabase.confirm[i] = 1; } } }