Livery: Apply custom texture selector
This commit is contained in:
parent
e39bc384f8
commit
477ab17188
|
@ -5,12 +5,10 @@
|
|||
|
||||
<nasal>
|
||||
<load>
|
||||
var livery_update = aircraft.livery_update.new("Aircraft/followme_e-tron/Models/Messages", 1, nil);
|
||||
var liveryFuse_update = followme.liveryFuse_update.new("Aircraft/followme_e-tron/Models/Texture", 1, nil);
|
||||
var livery_update = aircraft.livery_update.new("Aircraft/followme_e-tron/Models/Messages", 1, nil);
|
||||
</load>
|
||||
<unload>
|
||||
livery_update.stop();
|
||||
liveryFuse_update.stop();
|
||||
livery_update.stop();
|
||||
</unload>
|
||||
</nasal>
|
||||
|
||||
|
@ -67,8 +65,10 @@
|
|||
<object-name>door.rr</object-name>
|
||||
<object-name>rdoor</object-name>
|
||||
<object-name>ldoor</object-name>
|
||||
<property-base>sim/model/livery</property-base>
|
||||
<texture-prop>texture-fuse</texture-prop>
|
||||
<!--<property-base>sim/model/livery</property-base>
|
||||
<texture-prop>texture-fuse</texture-prop>-->
|
||||
<property-base>sim/multiplay/generic</property-base>
|
||||
<texture-prop>string[19]</texture-prop>
|
||||
<texture>followmeoutside.png</texture>
|
||||
</animation>
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#//Follow Me Library by Sidi Liang
|
||||
#//Contact: sidi.liang@gmail.com
|
||||
|
||||
io.include("texture-selector.nas");
|
||||
|
||||
var isInternalView = func(){ #// return 1 if is in internal view, otherwise return 0.
|
||||
return props.getNode("sim/current-view/internal", 1).getValue();
|
||||
}
|
||||
|
@ -53,22 +55,3 @@ var runCode = func(url, addition = nil){
|
|||
print("Code loaded");
|
||||
});
|
||||
}
|
||||
|
||||
var liveryFuse = {
|
||||
init: func(dir, nameprop = "sim/model/livery/name", sortprop = nil) {
|
||||
me.parents = [gui.OverlaySelector.new("Select Livery", dir, nameprop,
|
||||
sortprop, "sim/model/livery/file")];
|
||||
me.dialog = me.parents[0];
|
||||
},
|
||||
};
|
||||
var liveryFuse_update = {
|
||||
new: func(liveriesdir, interval = 10.01, callback = nil) {
|
||||
var m = { parents: [liveryFuse_update, aircraft.overlay_update.new()] };
|
||||
m.parents[1].add(liveriesdir, "sim/model/livery/file", callback);
|
||||
m.parents[1].interval = interval;
|
||||
return m;
|
||||
},
|
||||
stop: func {
|
||||
me.parents[1].stop();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,41 +6,9 @@
|
|||
#To add an plate, just place the new plate texture file (must be .png
|
||||
#format) to that folder and it will show up in the dialog.
|
||||
|
||||
|
||||
var Scanner = {
|
||||
new: func(path, fileType) {
|
||||
return { parents:[Scanner], path: path, fileType: fileType};
|
||||
},
|
||||
path: "",
|
||||
fileType: "",
|
||||
scan: func(){
|
||||
var data = [];
|
||||
var files = directory(me.path);
|
||||
if (size(files)) {
|
||||
foreach (var file; files) {
|
||||
if (substr(file, 0 - size(me.fileType)) != me.fileType)
|
||||
continue;
|
||||
var n = io.read_properties(me.path ~ file);
|
||||
append(data, [substr(file, 0, size(file) - size(me.fileType)), me.path ~ file]);
|
||||
}
|
||||
#me.data = sort(me.data, func(a, b) num(a[1]) == nil or num(b[1]) == nil
|
||||
# ? cmp(a[1], b[1]) : a[1] - b[1]);
|
||||
}
|
||||
return data;
|
||||
},
|
||||
};
|
||||
var path = props.getNode("/",1).getValue("sim/aircraft-dir") ~ '/Models/plate/texture';
|
||||
var plateScanner = Scanner.new(path, ".png");
|
||||
var plateSelector = TextureSelector.new(path, ".png", 1, 1, "sim/gui/dialogs/vehicle_config/dialog", "group[4]/combo/"); #Using the scanner in library.nas
|
||||
|
||||
var updateList = func(){
|
||||
var allPlates = plateScanner.scan();
|
||||
var data = props.globals.getNode("/sim/gui/dialogs/vehicle_config/dialog/group[4]/combo/", 1);
|
||||
data.removeChildren("value");
|
||||
data.getChild("value", 0, 1).setValue("NONE");
|
||||
forindex(var i; allPlates){
|
||||
data.getChild("value", i+1, 1).setValue(allPlates[i][0]);
|
||||
}
|
||||
}
|
||||
var Plate = {
|
||||
new: func() {
|
||||
return { parents:[Plate]};
|
||||
|
|
|
@ -8,8 +8,9 @@ props.getNode("/sim/gui/dialogs/vehicle_config/dialog",1);
|
|||
var configDialog = gui.Dialog.new("/sim/gui/dialogs/vehicle_config/dialog", "Aircraft/followme_e-tron/gui/dialogs/config-dialog.xml");
|
||||
|
||||
aircraft.livery.init("Aircraft/followme_e-tron/Models/Messages");
|
||||
liveryFuse.init("Aircraft/followme_e-tron/Models/Texture");
|
||||
|
||||
var liveryPath = props.getNode("sim/aircraft-dir").getValue()~"/Models/Liveries/";
|
||||
var liverySelector = followme.TextureSelector.new(path: liveryPath, fileType: ".xml", textureProp: "texture-fuse", defaultValue: "Yellow(Default)");
|
||||
liverySelector.scanXML();
|
||||
aircraft.livery.select("Blanco");
|
||||
|
||||
var tyreSmoke_0 = aircraft.tyresmoke.new(0, auto = 1, diff_norm = 0.4, check_vspeed = 0);
|
||||
|
@ -476,7 +477,7 @@ var resetOnPosition = func(){
|
|||
setprop("/fdm/jsbsim/simulation/pause", 1);
|
||||
setprop("/fdm/jsbsim/simulation/reset", 1);
|
||||
var groundAlt = props.getNode("/position/ground-elev-ft").getValue();
|
||||
props.getNode("/position/altitude-ft").setValue(groundAlt+5);
|
||||
props.getNode("/position/altitude-ft").setValue(groundAlt+7);
|
||||
latProp.setValue(lat);
|
||||
lonProp.setValue(lon);
|
||||
setprop("/fdm/jsbsim/simulation/pause", 0);
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
#//Sidi Liang, 2020
|
||||
#//Docs to be done
|
||||
|
||||
var TextureSelector = { #//Tmp Note: path MUST end with "/"
|
||||
new: func(path, fileType = nil, enableNone = 0, customDialog = 0, customDialogBase = "",
|
||||
customDialogPosition = "", texturePropertyBase = "sim/model/livery/", textureProp = "livery", textureNameProp = "name",
|
||||
textureDataNode = nil, defaultValue = ""){
|
||||
|
||||
var m = {parents:[TextureSelector]};
|
||||
if(customDialog == 1){
|
||||
m.dialogNode = props.getNode(customDialogBase, 1);
|
||||
}else{
|
||||
m.dialog = TextureSelectorDialog.new(defaultV: defaultValue);
|
||||
}
|
||||
if(textureDataNode == nil) textureDataNode = props.getNode("/TextureSelector/liveries/", 1);
|
||||
|
||||
m.path = path;
|
||||
m.fileType = fileType;
|
||||
m.enableNone = enableNone;
|
||||
m.customDialog = customDialog;
|
||||
m.dialogCustom = customDialogPosition;
|
||||
m.texturePropertyBase = texturePropertyBase;
|
||||
m.textureProp = textureProp;
|
||||
m.textureNameProp = textureNameProp;
|
||||
m.textureDataNode = textureDataNode;
|
||||
m.defaultValue = defaultValue;
|
||||
if(defaultValue) m.setTextureByNameXML(defaultValue);
|
||||
return m;
|
||||
},
|
||||
path: "", #//path containing texture file
|
||||
fileType: "",
|
||||
enableNone: 0,
|
||||
customDialog: 0,
|
||||
dialogCustom:"list/",
|
||||
texturePropertyBase: "sim/model/livery/",
|
||||
textureProp:"livery",
|
||||
textureNameProp:"name",
|
||||
defaultValue:"",
|
||||
dialogNode:nil,
|
||||
dialog:nil,
|
||||
textureDataNode:props.getNode("/TextureSelector/liveries/", 1),
|
||||
scan: func(path = nil, fileType = nil){
|
||||
if(path == nil and me.path) path = me.path;
|
||||
else return 1;
|
||||
if(fileType == nil and me.fileType) fileType = me.fileType;
|
||||
else return 1;
|
||||
var data = [];
|
||||
var files = directory(path);
|
||||
if (size(files)) {
|
||||
foreach (var file; files) {
|
||||
if (substr(file, 0 - size(fileType)) != fileType)
|
||||
continue;
|
||||
append(data, [substr(file, 0, size(file) - size(fileType)), path ~ file]);
|
||||
}
|
||||
#me.data = sort(me.data, func(a, b) num(a[1]) == nil or num(b[1]) == nil
|
||||
# ? cmp(a[1], b[1]) : a[1] - b[1]);
|
||||
}
|
||||
return data;
|
||||
},
|
||||
scanXML: func(path = nil){
|
||||
if(path == nil and me.path) path = me.path;
|
||||
else return 1;
|
||||
var fileType = ".xml";
|
||||
var names = [];
|
||||
var files = directory(path);
|
||||
if (size(files)) {
|
||||
var i = 0;
|
||||
foreach (var file; files) {
|
||||
if (substr(file, 0 - size(fileType)) != fileType)
|
||||
continue;
|
||||
var node = me.textureDataNode.getChild(me.textureProp, i, 1); #//Temporary solution, to be improved
|
||||
n = io.read_properties(me.path ~ file, node);
|
||||
var data = [];
|
||||
append(data, n.getNode(me.texturePropertyBase ~ me.textureNameProp).getValue());
|
||||
append(names, data);
|
||||
i+=1;
|
||||
}
|
||||
}
|
||||
return names;
|
||||
},
|
||||
updateList: func(){
|
||||
var allItems = nil;
|
||||
if(me.fileType != ".xml") allItems = me.scan();
|
||||
else allItems = me.scanXML();
|
||||
var data = nil;
|
||||
if(me.customDialog) data = me.dialogNode.getNode(me.dialogCustom, 1); #//Pass the custom dialog if used
|
||||
else data = me.dialog.list;
|
||||
data.removeChildren("value");
|
||||
if(me.enableNone){
|
||||
data.getChild("value", 0, 1).setValue("NONE");
|
||||
forindex(var i; allItems){
|
||||
data.getChild("value", i+1, 1).setValue(allItems[i][0]);
|
||||
}
|
||||
}else{
|
||||
forindex(var i; allItems){
|
||||
data.getChild("value", i, 1).setValue(allItems[i][0]);
|
||||
}
|
||||
}
|
||||
},
|
||||
setTextureByNameXML: func(name){
|
||||
allTextures = me.textureDataNode.getChildren(me.textureProp);
|
||||
foreach(var texture; allTextures){
|
||||
var tmp = texture.getNode(me.texturePropertyBase);
|
||||
if(tmp.getNode(me.textureNameProp).getValue() == name){
|
||||
print(tmp.getNode(me.textureProp).getValue());
|
||||
props.copy(tmp, props.getNode(me.texturePropertyBase));
|
||||
props.getNode("/sim/multiplay/generic/string[19]", 1).setValue(texture.getNode(me.texturePropertyBase).getNode(me.textureProp).getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var TextureSelectorDialog = {
|
||||
new: func(dialogBase = "/sim/gui/dialogs/TextureSelector/dialog", dialogFile = "Aircraft/followme_e-tron/gui/dialogs/livery-select.xml", defaultV = ""){
|
||||
var m = gui.Dialog.new(dialogBase, dialogFile);
|
||||
m.parents = [TextureSelectorDialog, gui.Dialog];
|
||||
var dNode = props.getNode(dialogBase, 1);
|
||||
m.dialogNode = dNode;
|
||||
m.dialogFile = dialogFile;
|
||||
m.title = "Livery Selection";
|
||||
m.list = m.dialogNode.getNode("list", 1);
|
||||
m.result = props.getNode(m.list.getPath() ~ "/result", 1);
|
||||
m.defaultValue = defaultV;
|
||||
m.nasal = m.dialogNode.getNode("nasal", 1);
|
||||
m.openScript = m.nasal.getNode("open", 1);
|
||||
m.closeScript = m.nasal.getNode("close", 1);
|
||||
m.openScript.setValue('print("livery-select dialog opened");
|
||||
followme.liverySelector.updateList();
|
||||
#print(cmdarg().getPath());
|
||||
var lis = setlistener(followme.liverySelector.dialog.result, func(){
|
||||
var selected = followme.liverySelector.dialog.result.getValue();
|
||||
if(selected != "none"){
|
||||
followme.liverySelector.setTextureByNameXML(selected);
|
||||
}else{
|
||||
#fileNode.setValue(nameNode.getValue());
|
||||
}
|
||||
});');
|
||||
m.closeScript.setValue('\n followme.playAudio("repair.wav");');
|
||||
m.reload();
|
||||
#Reload when the GUI is reloaded
|
||||
m.reload_listener = setlistener("/sim/signals/reinit-gui", func(n) m.reload());
|
||||
|
||||
return m;
|
||||
},
|
||||
reload: func(){
|
||||
me.list.getNode("property").setValue(me.result.getPath());
|
||||
me.result.setValue(me.result.getValue() or me.defaultValue);
|
||||
me.openScript.setValue('print("livery-select dialog opened");
|
||||
followme.liverySelector.updateList();
|
||||
#print(cmdarg().getPath());
|
||||
var lis = setlistener(followme.liverySelector.dialog.result, func(){
|
||||
var selected = followme.liverySelector.dialog.result.getValue();
|
||||
if(selected != "none"){
|
||||
followme.liverySelector.setTextureByNameXML(selected);
|
||||
}else{
|
||||
#fileNode.setValue(nameNode.getValue());
|
||||
}
|
||||
});');
|
||||
me.closeScript.setValue('followme.playAudio("repair.wav");');
|
||||
me.dialogNode.getNode("group/text/label").setValue(me.title);
|
||||
me.dialogNode.getNode("group/button/binding/script").setValue('gui.Dialog.instance["' ~ me.dialogNode.getNode("name").getValue() ~ '"].close()');
|
||||
}
|
||||
};
|
|
@ -235,8 +235,8 @@
|
|||
<!-- Splah ends here -->
|
||||
<rating>
|
||||
<FDM type="int">4</FDM>
|
||||
<systems type="int">2</systems>
|
||||
<cockpit type="int">3</cockpit>
|
||||
<systems type="int">3</systems>
|
||||
<cockpit type="int">4</cockpit>
|
||||
<model type="int">4</model>
|
||||
</rating>
|
||||
|
||||
|
@ -431,7 +431,7 @@
|
|||
</systems>
|
||||
<!-- Start tutorials -->
|
||||
<tutorials>
|
||||
<tutorial include="Tutorials/followme-cockpit-overview-dashboard.xml"/>
|
||||
<tutorial include="Tutorials/followme-cockpit-overview-dashboard.xml"/>
|
||||
<tutorial include="Tutorials/followme-cockpit-overview-dashboard-zh.xml"/>
|
||||
<tutorial include="Tutorials/followme-cockpit-overview-center-console.xml"/>
|
||||
<tutorial include="Tutorials/followme-keyboard.xml"/>
|
||||
|
@ -463,11 +463,11 @@
|
|||
<script>followme.configDialog.open();</script>
|
||||
</binding>
|
||||
</item>
|
||||
<item>
|
||||
<item>
|
||||
<label>Select Livery</label>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>followme.liveryFuse.dialog.toggle()</script>
|
||||
<script>followme.liverySelector.dialog.open()</script>
|
||||
</binding>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<nasal>
|
||||
<open>
|
||||
followme.updateList();
|
||||
followme.plateSelector.updateList();
|
||||
#print(cmdarg().getPath());
|
||||
var nameNode = props.getNode("systems/plate/name", 1);
|
||||
var fileNode = props.getNode("systems/plate/file", 1);
|
||||
|
@ -196,7 +196,7 @@
|
|||
<pref-height>28</pref-height>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>followme.liveryFuse.dialog.toggle()</script>
|
||||
<script>followme.liverySelector.dialog.open()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<button>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<PropertyList>
|
||||
|
||||
<name>livery-select</name>
|
||||
<layout>vbox</layout>
|
||||
<resizable>true</resizable>
|
||||
<x>-20</x>
|
||||
<pref-width>300</pref-width>
|
||||
<modal>false</modal>
|
||||
<draggable>true</draggable>
|
||||
|
||||
<group>
|
||||
<layout>hbox</layout>
|
||||
<empty><stretch>1</stretch></empty>
|
||||
|
||||
<text>
|
||||
<label>$name</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>nasal</command>
|
||||
<script>$close</script>
|
||||
</binding>
|
||||
</button>
|
||||
</group>
|
||||
|
||||
<hrule/>
|
||||
|
||||
<list>
|
||||
<halign>fill</halign>
|
||||
<valign>fill</valign>
|
||||
<stretch>true</stretch>
|
||||
<pref-height>500</pref-height>
|
||||
<property>$result</property>
|
||||
<binding>
|
||||
<command>dialog-apply</command>
|
||||
</binding>
|
||||
<value>$value</value>
|
||||
</list>
|
||||
|
||||
</PropertyList>
|
Binary file not shown.
Before Width: | Height: | Size: 662 KiB After Width: | Height: | Size: 1.4 MiB |
|
@ -1,2 +1 @@
|
|||
202003
|
||||
425
|
||||
20200606
|
||||
|
|
Loading…
Reference in New Issue