It works
This commit is contained in:
parent
6903e1976c
commit
10bf4c5cb8
6 changed files with 170 additions and 30 deletions
|
@ -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 ~ " "));
|
||||
|
||||
|
|
|
@ -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; }
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
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);
|
|
@ -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 {
|
||||
|
|
83
Nasal/MCDU/NEWWAYPOINT.nas
Normal file
83
Nasal/MCDU/NEWWAYPOINT.nas
Normal file
|
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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);
|
||||
},
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue