add overlay selector dialog class (similar to the livery selector)
This commit is contained in:
parent
37bba43061
commit
4341781968
2 changed files with 232 additions and 102 deletions
|
@ -398,6 +398,92 @@ settimer(func {
|
|||
}, 0);
|
||||
|
||||
|
||||
##
|
||||
# Overlay selector. Displays a list of overlay XML files and copies the
|
||||
# chosen one to the property tree. The given name property is saved to
|
||||
# autosave.xml and restored next time. The class allows to select liveries,
|
||||
# insignia, decals, variants, etc. Usually the overlay properties are
|
||||
# fed to "select" and "material" animations.
|
||||
#
|
||||
# SYNOPSIS:
|
||||
# OverlaySelector.new(<title>, <dir>, <nameprop>);
|
||||
#
|
||||
# title ... dialog title
|
||||
# dir ... directory where to find the XML overlay files,
|
||||
# relative to FG_ROOT
|
||||
# nameprop ... property in an overlay file that contains the name
|
||||
# The result is written to this property in the
|
||||
# property tree. You can attach a listener here to
|
||||
# get changes reported.
|
||||
#
|
||||
# EXAMPLE:
|
||||
# var pilots_dialog = gui.OverlaySelector.new("Pilots",
|
||||
# "Aircraft/foo/Models/Pilots",
|
||||
# "sim/model/pilot");
|
||||
#
|
||||
# pilots_dialog.open(); # or ... close(), or toggle()
|
||||
#
|
||||
#
|
||||
var OverlaySelector = {
|
||||
new: func(title, dir, nameprop) {
|
||||
var name = "overlay-select-";
|
||||
var data = props.globals.getNode("/sim/gui/dialogs/", 1);
|
||||
var i = nil;
|
||||
for (i = 1; 1; i += 1)
|
||||
if (data.getNode(name ~ i, 0) == nil)
|
||||
break;
|
||||
data = data.getNode(name ~= i, 1);
|
||||
|
||||
var m = Dialog.new(data.getNode("dialog", 1), "gui/dialogs/overlay-select.xml", name);
|
||||
m.parents = [OverlaySelector, Dialog];
|
||||
|
||||
m.dir = getprop("/sim/fg-root") ~ "/" ~ dir;
|
||||
m.nameprop = nameprop;
|
||||
m.result = data.getNode("result", 1);
|
||||
m.cblistener = setlistener(m.result, func m.set());
|
||||
aircraft.data.add(nameprop);
|
||||
|
||||
m.prop.getNode("group/text/label").setValue(title);
|
||||
m.list = m.prop.getNode("list");
|
||||
m.list.getNode("property").setValue(m.result.getPath());
|
||||
|
||||
m.rescan();
|
||||
m.set(getprop(m.nameprop));
|
||||
return m;
|
||||
},
|
||||
del: func {
|
||||
removelistener(me.cblistener);
|
||||
me.data.remove();
|
||||
},
|
||||
rescan: func {
|
||||
me.options = [];
|
||||
foreach (var file; directory(me.dir)) {
|
||||
if (substr(file, -4) != ".xml")
|
||||
continue;
|
||||
var n = io.read_properties(me.dir ~ "/" ~ file);
|
||||
var name = n.getNode(me.nameprop, 1).getValue() or "[NO NAME]";
|
||||
append(me.options, [name, n.getValues()]);
|
||||
me.options = sort(me.options, func(a, b) cmp(a[0], b[0]));
|
||||
}
|
||||
|
||||
me.list.removeChildren("value");
|
||||
forindex (var i; me.options)
|
||||
me.list.getChild("value", i, 1).setValue(me.options[i][0]);
|
||||
},
|
||||
set: func(which = nil) {
|
||||
if (!size(me.options))
|
||||
return;
|
||||
var choice = which or me.result.getValue() or me.options[0][0];
|
||||
foreach (var o; me.options) {
|
||||
if (o[0] == choice) {
|
||||
props.globals.setValues(o[1]);
|
||||
setprop(me.nameprop, choice);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
##
|
||||
# Apply whole dialog or list of widgets. This copies the widgets'
|
||||
# visible contents to the respective <property>.
|
||||
|
|
44
gui/dialogs/overlay-select.xml
Normal file
44
gui/dialogs/overlay-select.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<PropertyList>
|
||||
<name>overlay-select</name>
|
||||
<layout>vbox</layout>
|
||||
<x>-20</x>
|
||||
<pref-width>200</pref-width>
|
||||
|
||||
<group>
|
||||
<layout>hbox</layout>
|
||||
<empty><stretch>1</stretch></empty>
|
||||
|
||||
<text>
|
||||
<label>set by gui.OverlaySelector</label>
|
||||
</text>
|
||||
|
||||
<empty><stretch>1</stretch></empty>
|
||||
|
||||
<button>
|
||||
<pref-width>16</pref-width>
|
||||
<pref-height>16</pref-height>
|
||||
<legend></legend>
|
||||
<default>1</default>
|
||||
<keynum>27</keynum>
|
||||
<border>2</border>
|
||||
|
||||
<binding>
|
||||
<command>dialog-close</command>
|
||||
</binding>
|
||||
</button>
|
||||
</group>
|
||||
|
||||
<hrule/>
|
||||
|
||||
<list>
|
||||
<halign>fill</halign>
|
||||
<pref-height>200</pref-height>
|
||||
<property>set by gui.OverlaySelector</property>
|
||||
<binding>
|
||||
<command>dialog-apply</command>
|
||||
</binding>
|
||||
<value>set by gui.OverlaySelector</value>
|
||||
</list>
|
||||
</PropertyList>
|
Loading…
Add table
Reference in a new issue