From 6903e1976cd16f77dc81a27609d61777f3db40a6 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Wed, 20 May 2020 18:50:09 +0100 Subject: [PATCH] Improvements --- Nasal/FMGC/flightplan-waypoints.nas | 10 ++++++++++ Nasal/MCDU/PILOTWAYPOINT.nas | 21 ++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Nasal/FMGC/flightplan-waypoints.nas b/Nasal/FMGC/flightplan-waypoints.nas index 73311e30..765a926e 100644 --- a/Nasal/FMGC/flightplan-waypoints.nas +++ b/Nasal/FMGC/flightplan-waypoints.nas @@ -76,6 +76,16 @@ var WaypointDatabase = { } return -1; }, + # getNonNilIndex - find the first non-nil + # post 2020.1 use dedicated function vecindex() + getNonNilIndex: func() { + for (var i = 0; i < me.getSize(); i = i + 1) { + if (me.waypointsVec[i] != nil) { + return i; + } + } + return -1; + }, # getCount - return size, neglecting "nil" getCount: func() { var count = 0; diff --git a/Nasal/MCDU/PILOTWAYPOINT.nas b/Nasal/MCDU/PILOTWAYPOINT.nas index fd122466..c323b2f1 100644 --- a/Nasal/MCDU/PILOTWAYPOINT.nas +++ b/Nasal/MCDU/PILOTWAYPOINT.nas @@ -23,7 +23,7 @@ var pilotWaypointPage = { R6: [nil, nil, "ack"], new: func(computer) { var ap = {parents:[pilotWaypointPage]}; - ap.scroll = 0; + ap.scroll = fmgc.WaypointDatabase.getNonNilIndex(); ap.computer = computer; ap._setupPageWithData(); return ap; @@ -48,14 +48,24 @@ var pilotWaypointPage = { translateLatitude: func(latitude) { var split = split(".", sprintf("%s", latitude)); var degree = split[0]; - var decimal = sprintf("%0.1f", split[1] * 60); - return degree ~ decimal; + 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]; - var decimal = sprintf("%0.1f", split[1] * 60); - return degree ~ decimal; + 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"; + } }, scrollLeft: func() { me.scroll -= 1; @@ -82,6 +92,7 @@ var pilotWaypointPage = { me.arrowsColour[1][5] = "blu"; fmgc.WaypointDatabase.delete(); } + me.scroll = fmgc.WaypointDatabase.getNonNilIndex(); canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, }; \ No newline at end of file