[Yes, Andy's writing code again. The world is ending.]
An IRC discussion about shavlir's (really nice) harrier model showed that it had its own version of something like the Fuel & Weight dialog, developed because the existing subsystem only supported sliders and not "combo box" style selection for specific external stores. That seemed sub-optimal, so I spent a few hours extending the F&W dialog to do this and forward-ported the harrier to use it. Check the harrier-set.xml file for an example. Basically, the weight dialog reads a list of options for each weight listed under /sim/weight[n] and manages a "selected" proprty telling us which one is in use. The FDM code can then read out the weight-lb property as before, and the model animations can use the selected option to predicate drawing the appropriate 3D content. It seems to work pretty well.
This commit is contained in:
parent
e85c8708ce
commit
3e268e394c
1 changed files with 65 additions and 15 deletions
|
@ -421,6 +421,22 @@ showTutorialDialog = func {
|
||||||
showDialog(name);
|
showDialog(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Checks the /sim/weight[n]/{selected|opt} values and sets the
|
||||||
|
# appropriate weights therefrom. Called from the F&W dialog.
|
||||||
|
var setWeightOpts = func {
|
||||||
|
foreach(w; props.globals.getNode("sim").getChildren("weight")) {
|
||||||
|
var selected = w.getNode("selected");
|
||||||
|
if(selected != nil) {
|
||||||
|
foreach(opt; w.getChildren("opt")) {
|
||||||
|
if(opt.getNode("name", 1).getValue() == selected.getValue()) {
|
||||||
|
var lbs = opt.getNode("lbs", 1).getValue();
|
||||||
|
w.getNode("weight-lb", 1).setValue(lbs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# Dynamically generates a weight & fuel configuration dialog specific to
|
# Dynamically generates a weight & fuel configuration dialog specific to
|
||||||
|
@ -482,10 +498,10 @@ showWeightDialog = func {
|
||||||
ok.setBinding("dialog-close");
|
ok.setBinding("dialog-close");
|
||||||
|
|
||||||
# Temporary helper function
|
# Temporary helper function
|
||||||
tcell = func {
|
tcell = func(parent, type, row, col) {
|
||||||
cell = arg[0].addChild(arg[1]);
|
cell = parent.addChild(type);
|
||||||
cell.set("row", arg[2]);
|
cell.set("row", row);
|
||||||
cell.set("col", arg[3]);
|
cell.set("col", col);
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,23 +577,58 @@ showWeightDialog = func {
|
||||||
|
|
||||||
wgts = props.globals.getNode("/sim").getChildren("weight");
|
wgts = props.globals.getNode("/sim").getChildren("weight");
|
||||||
for(i=0; i<size(wgts); i+=1) {
|
for(i=0; i<size(wgts); i+=1) {
|
||||||
w = wgts[i];
|
var w = wgts[i];
|
||||||
wname = w.getNode("name", 1).getValue();
|
var wname = w.getNode("name", 1).getValue();
|
||||||
max = w.getNode("max-lb", 1).getValue();
|
var wprop = "/sim/weight[" ~ i ~ "]";
|
||||||
wprop = "/sim/weight[" ~ i ~ "]/weight-lb";
|
|
||||||
|
|
||||||
title = tcell(weightTable, "text", i+1, 0);
|
title = tcell(weightTable, "text", i+1, 0);
|
||||||
title.set("label", wname);
|
title.set("label", wname);
|
||||||
title.set("halign", "right");
|
title.set("halign", "right");
|
||||||
|
|
||||||
slider = tcell(weightTable, "slider", i+1, 1);
|
if(w.getNode("opt") != nil) {
|
||||||
slider.set("property", wprop);
|
var combo = tcell(weightTable, "combo", i+1, 1);
|
||||||
slider.set("min", 0);
|
combo.set("property", wprop ~ "/selected");
|
||||||
slider.set("max", max);
|
combo.set("pref-width", 300);
|
||||||
slider.setBinding("dialog-apply");
|
|
||||||
|
# Simple code we'd like to use:
|
||||||
|
#foreach(opt; w.getChildren("opt")) {
|
||||||
|
# var ent = combo.addChild("value");
|
||||||
|
# ent.prop().setValue(opt.getNode("name", 1).getValue());
|
||||||
|
#}
|
||||||
|
|
||||||
|
# More complicated workaround to move the "current" item
|
||||||
|
# into the first slow, because dialog.cxx doesn't set the
|
||||||
|
# selected item in the combo box.
|
||||||
|
var opts = [];
|
||||||
|
var curr = w.getNode("selected");
|
||||||
|
curr = curr == nil ? "" : curr.getValue();
|
||||||
|
foreach(opt; w.getChildren("opt")) {
|
||||||
|
append(opts, opt.getNode("name", 1).getValue());
|
||||||
|
}
|
||||||
|
forindex(oi; opts) {
|
||||||
|
if(opts[oi] == curr) {
|
||||||
|
var tmp = opts[0];
|
||||||
|
opts[0] = opts[oi];
|
||||||
|
opts[oi] = tmp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(opt; opts) {
|
||||||
|
combo.addChild("value").prop().setValue(opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
combo.setBinding("dialog-apply");
|
||||||
|
combo.setBinding("nasal", "gui.setWeightOpts()");
|
||||||
|
} else {
|
||||||
|
var slider = tcell(weightTable, "slider", i+1, 1);
|
||||||
|
slider.set("property", wprop ~ "/weight-lb");
|
||||||
|
slider.set("min", w.getNode("min-lb", 1).getValue());
|
||||||
|
slider.set("max", w.getNode("max-lb", 1).getValue());
|
||||||
|
slider.setBinding("dialog-apply");
|
||||||
|
}
|
||||||
|
|
||||||
lbs = tcell(weightTable, "text", i+1, 2);
|
lbs = tcell(weightTable, "text", i+1, 2);
|
||||||
lbs.set("property", wprop);
|
lbs.set("property", wprop ~ "/weight-lb");
|
||||||
lbs.set("label", "0123456");
|
lbs.set("label", "0123456");
|
||||||
lbs.set("format", "%.0f");
|
lbs.set("format", "%.0f");
|
||||||
lbs.set("live", 1);
|
lbs.set("live", 1);
|
||||||
|
@ -830,4 +881,3 @@ common_aircraft_keys = {
|
||||||
{ name : "Shift-F8", desc : "scroll 2D panel right" },
|
{ name : "Shift-F8", desc : "scroll 2D panel right" },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue