1
0
Fork 0

property_display: turn it into a regular class & lots of improvements

This commit is contained in:
mfranz 2008-05-15 15:42:31 +00:00
parent 0b4322736f
commit 54f8fc4370

View file

@ -59,8 +59,8 @@ var sanitize = func(s, newline = 0) {
var dialog_id = 0;
var theme_font = nil; var theme_font = nil;
var window_id = 0;
var window = { var window = {
new : func(x = nil, y = nil, maxlines = 10, autoscroll = 10) { new : func(x = nil, y = nil, maxlines = 10, autoscroll = 10) {
@ -78,7 +78,7 @@ var window = {
m.align = "center"; # "left", "right", "center" m.align = "center"; # "left", "right", "center"
# #
# "private" # "private"
m.name = "__screen_window_" ~ (dialog_id += 1) ~ "__"; m.name = "__screen_window_" ~ (window_id += 1) ~ "__";
m.lines = []; m.lines = [];
m.skiptimer = 0; m.skiptimer = 0;
m.dialog = nil; m.dialog = nil;
@ -171,48 +171,51 @@ var window = {
var property_display = { var display_id = 0;
init : func(x, y) {
me.listener = setlistener("/sim/gui/dialogs/property-browser/selected", func(n) { var display = {
var n = n.getValue(); new : func(x, y) {
if (n != "" and getprop("/devices/status/keyboard/shift")) { var m = { parents: [display] };
if (getprop("/devices/status/keyboard/ctrl")) #
return me.reset(); # "public"
n = props.globals.getNode(n); m.x = x;
if (!n.getAttribute("children")) m.y = y;
me.add(n); m.font = "HELVETICA_14";
} m.color = [1, 0.9, 0, 1];
}); m.interval = 0.1;
me.x = x; #
me.y = y; # "private"
me.font = "HELVETICA_14"; m.loopid = 0;
me.interval = 0; m.dialog = nil;
me.bg = [0, 0, 0, 0]; # background color m.name = "__screen_display_" ~ (display_id += 1) ~ "__";
me.fg = [1, 1, 1, 1]; # default foreground color m.base = props.globals.getNode("/sim/gui/dialogs/property-display-" ~ display_id, 1);
me.loopid = 0; m.namenode = props.Node.new({ "dialog-name" : m.name });
me.dialog = nil; m.reset();
me.base = props.globals.getNode("/sim/gui/dialogs/property-display", 1); return m;
me.namenode = props.Node.new({ "dialog-name" : "__property_display__" }); },
me.reset(); setcolor : func(r, g, b, a = 1) {
me.color = [r, g, b, a];
me.redraw();
me;
}, },
create : func { create : func {
me.dialog = gui.Widget.new(); me.dialog = gui.Widget.new();
me.dialog.set("name", "__property_display__"); me.dialog.set("name", me.name);
me.dialog.set("x", me.x); me.dialog.set("x", me.x);
me.dialog.set("y", me.y); me.dialog.set("y", me.y);
me.dialog.set("layout", "vbox"); me.dialog.set("layout", "vbox");
me.dialog.set("default-padding", 2); me.dialog.set("default-padding", 2);
me.dialog.setFont(me.font); me.dialog.setFont(me.font);
me.dialog.setColor(me.bg[0], me.bg[1], me.bg[2], me.bg[3]); me.dialog.setColor(0, 0, 0, 0);
foreach (var e; me.entries) { foreach (var e; me.entries) {
var w = me.dialog.addChild("text"); var w = me.dialog.addChild("text");
w.set("halign", "left"); w.set("halign", "left");
w.set("label", "XX"); # mouse-grab sensitive area w.set("label", "M"); # mouse-grab sensitive area
w.set("format", e[2] ~ " = %s"); w.set("format", e.tag ~ " = %s");
w.set("property", e[3].getPath()); w.set("property", e.target.getPath());
w.set("live", 1); w.set("live", 1);
w.setColor(me.fg[0], me.fg[1], me.fg[2], me.fg[3]); w.setColor(me.color[0], me.color[1], me.color[2], me.color[3]);
} }
fgcommand("dialog-new", me.dialog.prop()); fgcommand("dialog-new", me.dialog.prop());
}, },
@ -231,25 +234,31 @@ var property_display = {
me.loopid += 1; me.loopid += 1;
me.entries = []; me.entries = [];
}, },
add : func(n) { redraw : func {
if (!isa(n, props.Node)) me.close();
n = props.globals.getNode(n, 1); me.create();
me.open();
},
add : func(p...) {
foreach (PROP; var n; props.nodeList(p)) {
var path = n.getPath(); var path = n.getPath();
foreach (var e; me.entries) { foreach (var e; me.entries) {
if (e[0].getPath() == path) if (e.node.getPath() == path)
return; continue PROP;
e[1] = e[0]; e.parent = e.node;
e[2] = me.nameof(e[0]); 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) });
} }
append(me.entries, [n, n, me.nameof(n), me.base.getChild("entry", size(me.entries), 1)]);
# extend names to the left until they are unique # extend names to the left until they are unique
while (1) { while (1) {
var uniq = {}; var uniq = {};
foreach (var e; me.entries) { foreach (var e; me.entries) {
if (!contains(uniq, e[2])) if (!contains(uniq, e.tag))
uniq[e[2]] = []; uniq[e.tag] = [];
append(uniq[e[2]], e); append(uniq[e.tag], e);
} }
var finished = 1; var finished = 1;
@ -258,9 +267,9 @@ var property_display = {
continue; continue;
finished = 0; finished = 0;
foreach (var e; uniq[u]) { foreach (var e; uniq[u]) {
e[1] = e[1].getParent(); e.parent = e.parent.getParent();
if (e[1] != nil) if (e.parent != nil)
e[2] = me.nameof(e[1]) ~ '/' ~ e[2]; e.tag = me.nameof(e.parent) ~ '/' ~ e.tag;
} }
} }
if (finished) if (finished)
@ -270,12 +279,13 @@ var property_display = {
me.create(); me.create();
me.open(); me.open();
me._loop_(me.loopid += 1); me._loop_(me.loopid += 1);
me;
}, },
update : func { update : func {
foreach (var e; me.entries) { foreach (var e; me.entries) {
if ((var val = e[0].getValue()) == nil) if ((var val = e.node.getValue()) == nil)
val = "nil"; val = "nil";
e[3].setValue(sanitize(val, 1)); e.target.setValue(sanitize(val, 1));
} }
}, },
_loop_ : func(id) { _loop_ : func(id) {
@ -293,10 +303,25 @@ var property_display = {
var listener = {};
var log = nil; var log = nil;
var property_display = nil;
_setlistener("/sim/signals/nasal-dir-initialized", func { _setlistener("/sim/signals/nasal-dir-initialized", func {
property_display.init(5, -25); property_display = display.new(5, -25);
listener["display"] = setlistener("/sim/gui/dialogs/property-browser/selected", func(n) {
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());
}
});
setlistener("/sim/gui/current-style", func { setlistener("/sim/gui/current-style", func {
var theme = getprop("/sim/gui/current-style"); var theme = getprop("/sim/gui/current-style");
@ -307,14 +332,14 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
var b = "/sim/screen/"; var b = "/sim/screen/";
setlistener(b ~ "black", func(n) { log.write(n.getValue(), 0, 0, 0) }); 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 ~ "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 ~ "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 ~ "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 ~ "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 ~ "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 ~ "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) }); setlistener(b ~ "cyan", func(n) log.write(n.getValue(), 0, 0.6, 0.6));
}); });
@ -333,7 +358,7 @@ var msg_repeat = func {
return; return;
setprop("/sim/messages/pilot", "Say again ..."); setprop("/sim/messages/pilot", "Say again ...");
settimer(func { setprop("/sim/messages/copilot", last) }, 1.5); settimer(func setprop("/sim/messages/copilot", last), 1.5);
} else { } else {
var last = atc.getValue(); var last = atc.getValue();
@ -341,9 +366,7 @@ var msg_repeat = func {
return; return;
setprop("/sim/messages/pilot", "This is " ~ callsign.getValue() ~ ". Say again, over."); setprop("/sim/messages/pilot", "This is " ~ callsign.getValue() ~ ". Say again, over.");
settimer(func { settimer(func atc.setValue(atclast.getValue()), 6);
atc.setValue(atclast.getValue());
}, 6);
} }
} }
@ -351,7 +374,6 @@ var msg_repeat = func {
var atc = nil; var atc = nil;
var callsign = nil; var callsign = nil;
var atclast = nil; var atclast = nil;
var listener = {};
_setlistener("/sim/signals/nasal-dir-initialized", func { _setlistener("/sim/signals/nasal-dir-initialized", func {
# set /sim/screen/nomap=true to prevent default message mapping # set /sim/screen/nomap=true to prevent default message mapping
@ -413,18 +435,18 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
var m = "/sim/messages/"; var m = "/sim/messages/";
listener["atc"] = setlistener(m ~ "atc", listener["atc"] = setlistener(m ~ "atc",
func(n) { map("atc", n.getValue(), 0.7, 1.0, 0.7) }); func(n) map("atc", n.getValue(), 0.7, 1.0, 0.7));
listener["approach"] = setlistener(m ~ "approach", listener["approach"] = setlistener(m ~ "approach",
func(n) { map("approach", n.getValue(), 0.7, 1.0, 0.7) }); func(n) map("approach", n.getValue(), 0.7, 1.0, 0.7));
listener["ground"] = setlistener(m ~ "ground", listener["ground"] = setlistener(m ~ "ground",
func(n) { map("ground", n.getValue(), 0.7, 1.0, 0.7) }); func(n) map("ground", n.getValue(), 0.7, 1.0, 0.7));
listener["pilot"] = setlistener(m ~ "pilot", listener["pilot"] = setlistener(m ~ "pilot",
func(n) { map("pilot", n.getValue(), 1.0, 0.8, 0.0) }); func(n) map("pilot", n.getValue(), 1.0, 0.8, 0.0));
listener["copilot"] = setlistener(m ~ "copilot", listener["copilot"] = setlistener(m ~ "copilot",
func(n) { map("copilot", n.getValue(), 1.0, 1.0, 1.0) }); func(n) map("copilot", n.getValue(), 1.0, 1.0, 1.0));
listener["ai-plane"] = setlistener(m ~ "ai-plane", listener["ai-plane"] = setlistener(m ~ "ai-plane",
func(n) { map("ai-plane", n.getValue(), 0.9, 0.4, 0.2) }); func(n) map("ai-plane", n.getValue(), 0.9, 0.4, 0.2));
}); });