2008-05-16 16:26:15 +00:00
|
|
|
# on-screen displays
|
|
|
|
#==============================================================================
|
2006-02-02 23:34:16 +00:00
|
|
|
|
2007-03-20 16:25:11 +00:00
|
|
|
|
|
|
|
##
|
2007-03-23 15:56:34 +00:00
|
|
|
# convert string for output; replaces tabs by spaces, and skips
|
2007-06-22 18:49:38 +00:00
|
|
|
# delimiters and the voice part in "{text|voice}" constructions
|
2007-03-20 16:25:11 +00:00
|
|
|
#
|
2008-05-14 12:04:54 +00:00
|
|
|
var sanitize = func(s, newline = 0) {
|
2007-03-20 16:25:11 +00:00
|
|
|
var r = "";
|
2007-03-23 15:56:34 +00:00
|
|
|
var skip = 0;
|
2008-05-14 12:04:54 +00:00
|
|
|
s ~= "";
|
2007-03-20 16:25:11 +00:00
|
|
|
for (var i = 0; i < size(s); i += 1) {
|
|
|
|
var c = s[i];
|
2007-10-07 11:34:53 +00:00
|
|
|
if (c == `\t`)
|
2007-03-20 16:25:11 +00:00
|
|
|
r ~= ' ';
|
2007-10-07 11:34:53 +00:00
|
|
|
elsif (c == `{`)
|
|
|
|
nil;
|
|
|
|
elsif (c == `|`)
|
2007-03-23 15:56:34 +00:00
|
|
|
skip = 1;
|
2007-10-07 11:34:53 +00:00
|
|
|
elsif (c == `}`)
|
2007-03-23 15:56:34 +00:00
|
|
|
skip = 0;
|
2008-05-14 12:04:54 +00:00
|
|
|
elsif (c == `\n` and newline)
|
|
|
|
r ~= "\\n";
|
2007-10-07 11:34:53 +00:00
|
|
|
elsif (!skip)
|
2007-03-20 16:25:11 +00:00
|
|
|
r ~= chr(c);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var theme_font = nil;
|
2006-02-02 23:34:16 +00:00
|
|
|
|
2008-05-16 16:26:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
# screen.window
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Class that manages a dialog with fixed number of lines, where you can push in
|
|
|
|
# text at the bottom, which then (optionally) scrolls up after some time.
|
|
|
|
#
|
|
|
|
# simple use:
|
|
|
|
#
|
|
|
|
# var window = screen.window.new();
|
|
|
|
# window.write("message in the middle of the screen");
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# advanced use:
|
|
|
|
#
|
|
|
|
# var window = screen.window.new(nil, -100, 3, 10);
|
|
|
|
# window.fg = [1, 1, 1, 1]; # choose white default color
|
|
|
|
# window.align = "left";
|
|
|
|
#
|
|
|
|
# window.write("first line");
|
|
|
|
# window.write("second line (red)", 1, 0, 0);
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# arguments:
|
|
|
|
# x ... x coordinate
|
|
|
|
# y ... y coordinate
|
|
|
|
# positive coords position relative to the left/lower corner,
|
|
|
|
# negative coords from the right/upper corner, nil centers
|
|
|
|
# maxlines ... max number of displayed lines; if more are pushed into the
|
|
|
|
# screen, then the ones on top fall off
|
|
|
|
# autoscroll ... seconds that each line should be shown; can be less if
|
|
|
|
# a message falls off; if 0 then don't scroll at all
|
|
|
|
#
|
2007-06-22 14:13:30 +00:00
|
|
|
var window = {
|
2008-05-16 16:26:15 +00:00
|
|
|
id : 0,
|
2006-02-02 23:34:16 +00:00
|
|
|
new : func(x = nil, y = nil, maxlines = 10, autoscroll = 10) {
|
2008-05-15 20:31:35 +00:00
|
|
|
var m = { parents: [window] };
|
2006-02-02 23:34:16 +00:00
|
|
|
#
|
|
|
|
# "public"
|
|
|
|
m.x = x;
|
|
|
|
m.y = y;
|
|
|
|
m.maxlines = maxlines;
|
|
|
|
m.autoscroll = autoscroll; # display time in seconds
|
2006-02-22 17:26:06 +00:00
|
|
|
m.sticky = 0; # reopens on old place
|
2006-02-04 13:31:16 +00:00
|
|
|
m.font = nil;
|
2006-02-02 23:34:16 +00:00
|
|
|
m.bg = [0, 0, 0, 0]; # background color
|
2006-02-04 13:31:16 +00:00
|
|
|
m.fg = [0.9, 0.4, 0.2, 1]; # default foreground color
|
2006-02-03 00:02:26 +00:00
|
|
|
m.align = "center"; # "left", "right", "center"
|
2006-02-02 23:34:16 +00:00
|
|
|
#
|
|
|
|
# "private"
|
2008-05-16 16:26:15 +00:00
|
|
|
m.name = "__screen_window_" ~ (window.id += 1) ~ "__";
|
2006-02-02 23:34:16 +00:00
|
|
|
m.lines = [];
|
|
|
|
m.skiptimer = 0;
|
|
|
|
m.dialog = nil;
|
2008-05-15 20:31:35 +00:00
|
|
|
m.namenode = props.Node.new({ "dialog-name": m.name });
|
2008-05-19 09:48:41 +00:00
|
|
|
setlistener("/sim/startup/xsize", func m._redraw_());
|
|
|
|
setlistener("/sim/startup/ysize", func m._redraw_());
|
2006-02-02 23:34:16 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
write : func(msg, r = nil, g = nil, b = nil, a = nil) {
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.namenode == nil)
|
|
|
|
return;
|
|
|
|
if (r == nil)
|
|
|
|
r = me.fg[0];
|
|
|
|
if (g == nil)
|
|
|
|
g = me.fg[1];
|
|
|
|
if (b == nil)
|
|
|
|
b = me.fg[2];
|
|
|
|
if (a == nil)
|
|
|
|
a = me.fg[3];
|
2009-03-15 15:23:00 +00:00
|
|
|
foreach (var line; split("\n", string.trim(msg ~ ""))) {
|
2007-06-22 14:13:30 +00:00
|
|
|
line = sanitize(string.trim(line));
|
2006-02-21 21:38:59 +00:00
|
|
|
append(me.lines, [line, r, g, b, a]);
|
2006-02-21 21:26:49 +00:00
|
|
|
if (size(me.lines) > me.maxlines) {
|
|
|
|
me.lines = subvec(me.lines, 1);
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.autoscroll)
|
2006-02-21 21:26:49 +00:00
|
|
|
me.skiptimer += 1;
|
|
|
|
}
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.autoscroll)
|
2008-05-16 16:26:15 +00:00
|
|
|
settimer(func me._timeout_(), me.autoscroll, 1);
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
},
|
2006-02-05 20:43:14 +00:00
|
|
|
show : func {
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.dialog != nil)
|
2006-02-05 20:43:14 +00:00
|
|
|
me.close();
|
2006-02-02 23:34:16 +00:00
|
|
|
|
|
|
|
me.dialog = gui.Widget.new();
|
|
|
|
me.dialog.set("name", me.name);
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.x != nil)
|
|
|
|
me.dialog.set("x", me.x);
|
|
|
|
if (me.y != nil)
|
|
|
|
me.dialog.set("y", me.y);
|
2006-02-02 23:34:16 +00:00
|
|
|
me.dialog.set("layout", "vbox");
|
|
|
|
me.dialog.set("default-padding", 2);
|
2007-10-07 11:34:53 +00:00
|
|
|
if (me.font != nil)
|
2006-02-04 13:31:16 +00:00
|
|
|
me.dialog.setFont(me.font);
|
2007-10-07 11:34:53 +00:00
|
|
|
elsif (theme_font != nil)
|
2006-02-04 13:31:16 +00:00
|
|
|
me.dialog.setFont(theme_font);
|
2007-10-07 11:34:53 +00:00
|
|
|
|
2006-02-02 23:34:16 +00:00
|
|
|
me.dialog.setColor(me.bg[0], me.bg[1], me.bg[2], me.bg[3]);
|
|
|
|
|
2007-03-20 16:25:11 +00:00
|
|
|
foreach (var line; me.lines) {
|
2006-02-02 23:34:16 +00:00
|
|
|
var w = me.dialog.addChild("text");
|
2006-02-05 20:43:14 +00:00
|
|
|
w.set("halign", me.align);
|
|
|
|
w.set("label", line[0]);
|
|
|
|
w.setColor(line[1], line[2], line[3], line[4]);
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fgcommand("dialog-new", me.dialog.prop());
|
|
|
|
fgcommand("dialog-show", me.namenode);
|
|
|
|
},
|
2006-02-04 13:31:16 +00:00
|
|
|
close : func {
|
|
|
|
fgcommand("dialog-close", me.namenode);
|
2006-02-22 17:26:06 +00:00
|
|
|
if (me.dialog != nil and me.sticky) {
|
|
|
|
me.x = me.dialog.prop().getNode("lastx").getValue();
|
|
|
|
me.y = me.dialog.prop().getNode("lasty").getValue();
|
2006-02-04 13:31:16 +00:00
|
|
|
}
|
|
|
|
},
|
2006-02-02 23:34:16 +00:00
|
|
|
_timeout_ : func {
|
|
|
|
if (me.skiptimer > 0) {
|
|
|
|
me.skiptimer -= 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (size(me.lines) > 1) {
|
|
|
|
me.lines = subvec(me.lines, 1);
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
} else {
|
2006-02-04 13:31:16 +00:00
|
|
|
me.close();
|
2006-02-02 23:34:16 +00:00
|
|
|
dialog = nil;
|
|
|
|
me.lines = [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_redraw_ : func {
|
|
|
|
if (me.dialog != nil) {
|
2006-02-04 13:31:16 +00:00
|
|
|
me.close();
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-16 16:26:15 +00:00
|
|
|
# screen.display
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Class that manages a dialog, which displays an arbitrary number of properties
|
|
|
|
# periodically updating the values. Property names are abbreviated to the
|
|
|
|
# shortest possible unique part.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# var dpy = screen.display.new(20, 10); # x/y coordinate
|
|
|
|
# dpy.setcolor(1, 0, 1); # magenta (default: white)
|
2008-05-19 09:48:41 +00:00
|
|
|
# dpy.setfont("SANS_12B"); # see $FG_ROOT/gui/styles/*.xml
|
2008-05-16 16:26:15 +00:00
|
|
|
#
|
|
|
|
# dpy.add("/position/latitude-deg", "/position/longitude-deg");
|
|
|
|
# dpy.add(props.globals.getNode("/orientation").getChildren());
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# The add() method takes one or more property paths or props.Nodes, or a vector
|
|
|
|
# containing those, or a hash with properties, or vectors with properties, etc.
|
|
|
|
# Internal "public" parameters may be set directly:
|
|
|
|
#
|
|
|
|
# dpy.interval = 0; # update every frame
|
|
|
|
# dpy.format = "%.3g"; # max. 3 digits fractional part
|
|
|
|
# dpy.redraw(); # pick up new settings
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# The open() method should only be used to undo a close() call. In all other
|
|
|
|
# cases this is done implicitly. redraw() is automatically called by an add(),
|
|
|
|
# but can be used to let the dialog pick up new settings of internal variables.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Methods add(), setfont() and setcolor() can be appended to the new()
|
|
|
|
# constructor (-> show big yellow frame rate counter in upper right corner):
|
|
|
|
#
|
|
|
|
# screen.display.new(-15, -5, 0).setfont("TIMES_24").setcolor(1, 0.9, 0).add("/sim/frame-rate");
|
|
|
|
#
|
2008-05-15 15:42:31 +00:00
|
|
|
var display = {
|
2008-05-16 16:26:15 +00:00
|
|
|
id : 0,
|
|
|
|
new : func(x, y, show_tags = 1) {
|
2008-05-15 15:42:31 +00:00
|
|
|
var m = { parents: [display] };
|
|
|
|
#
|
|
|
|
# "public"
|
|
|
|
m.x = x;
|
|
|
|
m.y = y;
|
2008-05-16 16:26:15 +00:00
|
|
|
m.tags = show_tags;
|
2008-05-15 15:42:31 +00:00
|
|
|
m.font = "HELVETICA_14";
|
2008-05-15 16:11:50 +00:00
|
|
|
m.color = [1, 1, 1, 1];
|
2008-05-15 20:31:35 +00:00
|
|
|
m.format = "%.12g";
|
2008-05-15 15:42:31 +00:00
|
|
|
m.interval = 0.1;
|
|
|
|
#
|
|
|
|
# "private"
|
|
|
|
m.loopid = 0;
|
|
|
|
m.dialog = nil;
|
2008-05-16 16:26:15 +00:00
|
|
|
m.name = "__screen_display_" ~ (display.id += 1) ~ "__";
|
|
|
|
m.base = props.globals.getNode("/sim/gui/dialogs/property-display-" ~ display.id, 1);
|
2008-05-15 20:31:35 +00:00
|
|
|
m.namenode = props.Node.new({ "dialog-name": m.name });
|
2008-05-19 09:48:41 +00:00
|
|
|
setlistener("/sim/startup/xsize", func m.redraw());
|
|
|
|
setlistener("/sim/startup/ysize", func m.redraw());
|
2008-05-15 15:42:31 +00:00
|
|
|
m.reset();
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
setcolor : func(r, g, b, a = 1) {
|
|
|
|
me.color = [r, g, b, a];
|
|
|
|
me.redraw();
|
|
|
|
me;
|
2008-05-14 10:23:47 +00:00
|
|
|
},
|
2008-05-16 16:26:15 +00:00
|
|
|
setfont : func(font) {
|
|
|
|
me.font = font;
|
|
|
|
me.redraw();
|
|
|
|
me;
|
|
|
|
},
|
|
|
|
_create_ : func {
|
2008-05-14 20:06:50 +00:00
|
|
|
me.dialog = gui.Widget.new();
|
2008-05-15 15:42:31 +00:00
|
|
|
me.dialog.set("name", me.name);
|
2008-05-14 20:06:50 +00:00
|
|
|
me.dialog.set("x", me.x);
|
|
|
|
me.dialog.set("y", me.y);
|
|
|
|
me.dialog.set("layout", "vbox");
|
|
|
|
me.dialog.set("default-padding", 2);
|
|
|
|
me.dialog.setFont(me.font);
|
2008-05-15 15:42:31 +00:00
|
|
|
me.dialog.setColor(0, 0, 0, 0);
|
2008-05-14 20:06:50 +00:00
|
|
|
|
|
|
|
foreach (var e; me.entries) {
|
|
|
|
var w = me.dialog.addChild("text");
|
|
|
|
w.set("halign", "left");
|
2008-05-15 15:42:31 +00:00
|
|
|
w.set("label", "M"); # mouse-grab sensitive area
|
|
|
|
w.set("property", e.target.getPath());
|
2008-05-16 16:26:15 +00:00
|
|
|
w.set("format", me.tags ? e.tag ~ " = %s" : "%s");
|
2008-05-14 20:06:50 +00:00
|
|
|
w.set("live", 1);
|
2008-05-15 15:42:31 +00:00
|
|
|
w.setColor(me.color[0], me.color[1], me.color[2], me.color[3]);
|
2008-05-14 20:06:50 +00:00
|
|
|
}
|
|
|
|
fgcommand("dialog-new", me.dialog.prop());
|
|
|
|
},
|
2008-05-16 16:26:15 +00:00
|
|
|
# add() opens already, so call open() explicitly only after close()!
|
2008-05-14 20:06:50 +00:00
|
|
|
open : func {
|
2008-05-16 16:26:15 +00:00
|
|
|
if (me.dialog != nil) {
|
2008-05-14 20:06:50 +00:00
|
|
|
fgcommand("dialog-show", me.namenode);
|
2008-05-16 16:26:15 +00:00
|
|
|
me._loop_(me.loopid += 1);
|
|
|
|
}
|
2008-05-14 20:06:50 +00:00
|
|
|
},
|
|
|
|
close : func {
|
|
|
|
if (me.dialog != nil) {
|
|
|
|
fgcommand("dialog-close", me.namenode);
|
2008-05-16 16:26:15 +00:00
|
|
|
me.loopid += 1;
|
2008-05-14 20:06:50 +00:00
|
|
|
me.dialog = nil;
|
|
|
|
}
|
|
|
|
},
|
2008-05-16 16:26:15 +00:00
|
|
|
toggle : func {
|
|
|
|
me.dialog == nil ? me.redraw() : me.close();
|
|
|
|
},
|
2008-05-14 10:23:47 +00:00
|
|
|
reset : func {
|
2008-05-14 20:06:50 +00:00
|
|
|
me.close();
|
2008-05-14 10:23:47 +00:00
|
|
|
me.loopid += 1;
|
2008-05-14 15:40:00 +00:00
|
|
|
me.entries = [];
|
|
|
|
},
|
2008-05-15 15:42:31 +00:00
|
|
|
redraw : func {
|
|
|
|
me.close();
|
2008-05-16 16:26:15 +00:00
|
|
|
me._create_();
|
2008-05-15 15:42:31 +00:00
|
|
|
me.open();
|
|
|
|
},
|
|
|
|
add : func(p...) {
|
2008-05-19 09:48:41 +00:00
|
|
|
foreach (nextprop; var n; props.nodeList(p)) {
|
2008-05-15 15:42:31 +00:00
|
|
|
var path = n.getPath();
|
|
|
|
foreach (var e; me.entries) {
|
|
|
|
if (e.node.getPath() == path)
|
2008-05-19 09:48:41 +00:00
|
|
|
continue nextprop;
|
2008-05-15 15:42:31 +00:00
|
|
|
e.parent = e.node;
|
|
|
|
e.tag = me.nameof(e.node);
|
|
|
|
}
|
|
|
|
append(me.entries, { node: n, parent: n, tag: me.nameof(n),
|
|
|
|
target: me.base.getChild("entry", size(me.entries), 1) });
|
2008-05-14 15:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# extend names to the left until they are unique
|
2008-05-16 16:26:15 +00:00
|
|
|
while (me.tags) {
|
2008-05-14 15:40:00 +00:00
|
|
|
var uniq = {};
|
|
|
|
foreach (var e; me.entries) {
|
2008-05-16 16:26:15 +00:00
|
|
|
if (contains(uniq, e.tag))
|
|
|
|
append(uniq[e.tag], e);
|
|
|
|
else
|
|
|
|
uniq[e.tag] = [e];
|
2008-05-14 15:40:00 +00:00
|
|
|
}
|
|
|
|
|
2008-05-16 16:26:15 +00:00
|
|
|
var done = 1;
|
2008-05-14 15:40:00 +00:00
|
|
|
foreach (var u; keys(uniq)) {
|
|
|
|
if (size(uniq[u]) == 1)
|
|
|
|
continue;
|
2008-05-16 16:26:15 +00:00
|
|
|
done = 0;
|
2008-05-14 15:40:00 +00:00
|
|
|
foreach (var e; uniq[u]) {
|
2008-05-15 15:42:31 +00:00
|
|
|
e.parent = e.parent.getParent();
|
|
|
|
if (e.parent != nil)
|
|
|
|
e.tag = me.nameof(e.parent) ~ '/' ~ e.tag;
|
2008-05-14 15:40:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-16 16:26:15 +00:00
|
|
|
if (done)
|
2008-05-14 15:40:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-16 16:26:15 +00:00
|
|
|
me.redraw();
|
2008-05-15 15:42:31 +00:00
|
|
|
me;
|
2008-05-14 10:23:47 +00:00
|
|
|
},
|
|
|
|
update : func {
|
2008-05-14 15:40:00 +00:00
|
|
|
foreach (var e; me.entries) {
|
2008-05-15 20:31:35 +00:00
|
|
|
var type = e.node.getType();
|
|
|
|
if (type == "NONE")
|
|
|
|
var val = "nil";
|
|
|
|
elsif (type == "BOOL")
|
|
|
|
var val = e.node.getValue() ? "true" : "false";
|
|
|
|
elsif (type == "STRING" or type == "UNSPECIFIED")
|
|
|
|
var val = "'" ~ sanitize(e.node.getValue(), 1) ~ "'";
|
|
|
|
else
|
|
|
|
var val = sprintf(me.format, e.node.getValue());
|
|
|
|
e.target.setValue(val);
|
2008-05-14 10:57:02 +00:00
|
|
|
}
|
2008-05-14 10:23:47 +00:00
|
|
|
},
|
|
|
|
_loop_ : func(id) {
|
|
|
|
id != me.loopid and return;
|
|
|
|
me.update();
|
2008-05-16 16:26:15 +00:00
|
|
|
settimer(func me._loop_(id), me.interval);
|
2008-05-14 10:23:47 +00:00
|
|
|
},
|
2008-05-14 20:06:50 +00:00
|
|
|
nameof : func(n) {
|
|
|
|
var name = n.getName();
|
|
|
|
if (var i = n.getIndex())
|
|
|
|
name ~= '[' ~ i ~ ']';
|
|
|
|
return name;
|
|
|
|
},
|
2008-05-14 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-15 15:42:31 +00:00
|
|
|
|
|
|
|
var listener = {};
|
2007-03-20 16:25:11 +00:00
|
|
|
var log = nil;
|
2008-05-15 15:42:31 +00:00
|
|
|
var property_display = nil;
|
2008-05-19 09:48:41 +00:00
|
|
|
var controls = nil;
|
2006-02-02 23:34:16 +00:00
|
|
|
|
2008-12-23 10:03:26 +00:00
|
|
|
|
|
|
|
# Shift-click in the property browser adds the selected property to the property display
|
|
|
|
# Shift-Alt-click adds all children of the selected property to the property display
|
|
|
|
# Shift-Ctrl-click removes all properties from the display
|
|
|
|
#
|
2007-06-12 16:20:55 +00:00
|
|
|
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
2008-05-15 15:42:31 +00:00
|
|
|
property_display = display.new(5, -25);
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.display = setlistener("/sim/gui/dialogs/property-browser/selected", func(n) {
|
2008-05-15 15:42:31 +00:00
|
|
|
var n = n.getValue();
|
|
|
|
if (n != "" and getprop("/devices/status/keyboard/shift")) {
|
|
|
|
if (getprop("/devices/status/keyboard/ctrl"))
|
|
|
|
return property_display.reset();
|
|
|
|
n = props.globals.getNode(n);
|
|
|
|
if (!n.getAttribute("children"))
|
|
|
|
property_display.add(n);
|
|
|
|
elsif (getprop("/devices/status/keyboard/alt"))
|
|
|
|
property_display.add(n.getChildren());
|
|
|
|
}
|
|
|
|
});
|
2008-05-14 10:23:47 +00:00
|
|
|
|
2006-03-09 23:05:08 +00:00
|
|
|
setlistener("/sim/gui/current-style", func {
|
|
|
|
var theme = getprop("/sim/gui/current-style");
|
|
|
|
theme_font = getprop("/sim/gui/style[" ~ theme ~ "]/fonts/message-display/name");
|
2006-02-04 13:31:16 +00:00
|
|
|
}, 1);
|
|
|
|
|
2006-02-21 21:26:49 +00:00
|
|
|
log = window.new(nil, -30, 10, 10);
|
2007-03-27 18:02:12 +00:00
|
|
|
log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
|
2006-02-03 00:02:26 +00:00
|
|
|
|
|
|
|
var b = "/sim/screen/";
|
2008-05-15 15:42:31 +00:00
|
|
|
setlistener(b ~ "black", func(n) log.write(n.getValue(), 0, 0, 0));
|
|
|
|
setlistener(b ~ "white", func(n) log.write(n.getValue(), 1, 1, 1));
|
|
|
|
setlistener(b ~ "red", func(n) log.write(n.getValue(), 0.8, 0, 0));
|
|
|
|
setlistener(b ~ "green", func(n) log.write(n.getValue(), 0, 0.6, 0));
|
|
|
|
setlistener(b ~ "blue", func(n) log.write(n.getValue(), 0, 0, 0.8));
|
|
|
|
setlistener(b ~ "yellow", func(n) log.write(n.getValue(), 0.8, 0.8, 0));
|
|
|
|
setlistener(b ~ "magenta", func(n) log.write(n.getValue(), 0.7, 0, 0.7));
|
|
|
|
setlistener(b ~ "cyan", func(n) log.write(n.getValue(), 0, 0.6, 0.6));
|
2007-01-21 20:56:25 +00:00
|
|
|
});
|
2006-02-11 12:05:50 +00:00
|
|
|
|
|
|
|
|
2008-12-23 10:03:26 +00:00
|
|
|
|
2008-12-23 10:15:12 +00:00
|
|
|
# --prop:display=sim/frame-rate ... adds this property to the property display
|
|
|
|
# --prop:display=position/ ... adds all properties under /position/ (ends with slash!)
|
|
|
|
# --prop:display=position/,orientation/ ... separate multiple properties with comma
|
2008-12-23 10:03:26 +00:00
|
|
|
#
|
2008-08-05 12:35:01 +00:00
|
|
|
_setlistener("/sim/signals/fdm-initialized", func {
|
|
|
|
foreach (var n; props.globals.getChildren("display")) {
|
2008-12-23 10:15:12 +00:00
|
|
|
foreach (var p; split(",", n.getValue())) {
|
|
|
|
if (!size(p))
|
|
|
|
continue;
|
2009-01-25 00:27:12 +00:00
|
|
|
if (find('%', p) >= 0)
|
|
|
|
property_display.format = p;
|
|
|
|
elsif (p[-1] == `/`)
|
2008-12-23 10:15:12 +00:00
|
|
|
property_display.add(props.globals.getNode(p, 1).getChildren());
|
|
|
|
else
|
|
|
|
property_display.add(p);
|
|
|
|
}
|
2008-08-05 12:35:01 +00:00
|
|
|
}
|
|
|
|
props.globals.removeChildren("display");
|
|
|
|
});
|
|
|
|
|
2006-02-11 12:05:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# functions that make use of the window class (and don't belong anywhere else)
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
2007-06-22 14:13:30 +00:00
|
|
|
var msg_repeat = func {
|
2007-03-24 13:32:15 +00:00
|
|
|
if (getprop("/sim/tutorials/running")) {
|
|
|
|
var last = getprop("/sim/tutorials/last-message");
|
2007-10-07 11:34:53 +00:00
|
|
|
if (last == nil)
|
2006-02-24 11:05:13 +00:00
|
|
|
return;
|
2007-10-07 11:34:53 +00:00
|
|
|
|
2006-02-24 11:05:13 +00:00
|
|
|
setprop("/sim/messages/pilot", "Say again ...");
|
2008-05-15 15:42:31 +00:00
|
|
|
settimer(func setprop("/sim/messages/copilot", last), 1.5);
|
2006-02-24 11:05:13 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
var last = atc.getValue();
|
2007-10-07 11:34:53 +00:00
|
|
|
if (last == nil)
|
2006-02-24 11:05:13 +00:00
|
|
|
return;
|
2007-10-07 11:34:53 +00:00
|
|
|
|
2006-10-31 12:19:42 +00:00
|
|
|
setprop("/sim/messages/pilot", "This is " ~ callsign.getValue() ~ ". Say again, over.");
|
2008-05-15 15:42:31 +00:00
|
|
|
settimer(func atc.setValue(atclast.getValue()), 6);
|
2006-02-11 12:05:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-31 12:19:42 +00:00
|
|
|
|
|
|
|
var atc = nil;
|
|
|
|
var callsign = nil;
|
|
|
|
var atclast = nil;
|
2006-02-11 12:05:50 +00:00
|
|
|
|
2007-06-12 16:20:55 +00:00
|
|
|
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
2006-02-13 19:52:45 +00:00
|
|
|
# set /sim/screen/nomap=true to prevent default message mapping
|
|
|
|
var nomap = getprop("/sim/screen/nomap");
|
2007-10-07 11:34:53 +00:00
|
|
|
if (nomap != nil and nomap)
|
2006-02-13 19:52:45 +00:00
|
|
|
return;
|
2006-10-31 12:19:42 +00:00
|
|
|
|
|
|
|
callsign = props.globals.getNode("/sim/user/callsign", 1);
|
|
|
|
atc = props.globals.getNode("/sim/messages/atc", 1);
|
|
|
|
atclast = props.globals.getNode("/sim/messages/atc-last", 1);
|
|
|
|
atclast.setValue("");
|
|
|
|
|
2007-10-07 11:34:53 +00:00
|
|
|
# let ATC tell which runway was automatically chosen after startup/teleportation
|
|
|
|
settimer(func {
|
2007-10-15 18:27:42 +00:00
|
|
|
setlistener("/sim/atc/runway", func(n) { # set in src/Main/fg_init.cxx
|
|
|
|
var rwy = n.getValue();
|
2007-10-07 11:34:53 +00:00
|
|
|
if (rwy == nil)
|
|
|
|
return;
|
|
|
|
if (getprop("/sim/presets/airport-id") == "KSFO" and rwy == "28R")
|
|
|
|
return;
|
2007-10-07 17:09:13 +00:00
|
|
|
if ((var agl = getprop("/position/altitude-agl-ft")) != nil and agl > 100)
|
2007-10-07 11:34:53 +00:00
|
|
|
return;
|
2007-10-10 09:58:22 +00:00
|
|
|
screen.log.write("You are on runway " ~ rwy, 0.7, 1.0, 0.7);
|
2007-10-07 11:34:53 +00:00
|
|
|
}, 1);
|
|
|
|
}, 5);
|
|
|
|
|
2007-10-15 18:27:42 +00:00
|
|
|
setlistener("/gear/launchbar/state", func(n) {
|
|
|
|
if (n.getValue() == "Engaged")
|
2007-10-12 17:25:54 +00:00
|
|
|
setprop("/sim/messages/copilot", "Engaged!");
|
2007-10-15 18:27:42 +00:00
|
|
|
}, 0, 0);
|
2007-10-09 14:48:44 +00:00
|
|
|
|
2006-02-11 12:05:50 +00:00
|
|
|
# map ATC messages to the screen log and to the voice subsystem
|
2009-02-15 15:10:47 +00:00
|
|
|
var map = func(type, msg, r, g, b, cond = nil) {
|
2006-10-31 13:59:50 +00:00
|
|
|
printlog("info", "{", type, "} ", msg);
|
2009-02-15 15:10:47 +00:00
|
|
|
setprop("/sim/sound/voices/" ~ type, msg);
|
|
|
|
|
|
|
|
if (cond == nil or cond())
|
|
|
|
screen.log.write(msg, r, g, b);
|
2006-10-31 12:19:42 +00:00
|
|
|
|
|
|
|
# save last ATC message for user callsign, unless this was already
|
|
|
|
# a repetition; insert "I say again" appropriately
|
|
|
|
if (type == "atc") {
|
|
|
|
var cs = callsign.getValue();
|
|
|
|
if (find(", I say again: ", atc.getValue()) < 0
|
|
|
|
and (var pos = find(cs, msg)) >= 0) {
|
|
|
|
var m = substr(msg, 0, pos + size(cs));
|
|
|
|
msg = substr(msg, pos + size(cs));
|
|
|
|
|
2006-10-31 13:59:50 +00:00
|
|
|
if ((pos = find("Tower, ", msg)) >= 0) {
|
|
|
|
m ~= substr(msg, 0, pos + 7);
|
|
|
|
msg = substr(msg, pos + 7);
|
2006-10-31 12:19:42 +00:00
|
|
|
} else {
|
|
|
|
m ~= ", ";
|
|
|
|
}
|
2006-10-31 13:59:50 +00:00
|
|
|
m ~= "I say again: " ~ msg;
|
2006-10-31 12:19:42 +00:00
|
|
|
atclast.setValue(m);
|
2006-10-31 13:59:50 +00:00
|
|
|
printlog("debug", "ATC_LAST_MESSAGE: ", m);
|
2006-10-31 12:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-11 12:05:50 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 19:52:45 +00:00
|
|
|
var m = "/sim/messages/";
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.atc = setlistener(m ~ "atc",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("atc", n.getValue(), 0.7, 1.0, 0.7));
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.approach = setlistener(m ~ "approach",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("approach", n.getValue(), 0.7, 1.0, 0.7));
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.ground = setlistener(m ~ "ground",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("ground", n.getValue(), 0.7, 1.0, 0.7));
|
2006-02-28 15:25:26 +00:00
|
|
|
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.pilot = setlistener(m ~ "pilot",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("pilot", n.getValue(), 1.0, 0.8, 0.0));
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.copilot = setlistener(m ~ "copilot",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("copilot", n.getValue(), 1.0, 1.0, 1.0));
|
2008-05-19 09:48:41 +00:00
|
|
|
listener.ai_plane = setlistener(m ~ "ai-plane",
|
2008-05-15 15:42:31 +00:00
|
|
|
func(n) map("ai-plane", n.getValue(), 0.9, 0.4, 0.2));
|
2009-02-15 15:10:47 +00:00
|
|
|
listener.mp_plane = setlistener(m ~ "mp-plane",
|
2009-02-15 15:48:38 +00:00
|
|
|
func(n) map("ai-plane", n.getValue(), 0.5, 0.0, 0.8,
|
2009-02-15 15:10:47 +00:00
|
|
|
func getprop("/sim/multiplay/chat-display")));
|
2007-01-21 20:56:25 +00:00
|
|
|
});
|
2006-02-11 12:05:50 +00:00
|
|
|
|
|
|
|
|