1
0
Fork 0

Adapt scenarios dialog for revised AIManager

AIManager now takes care of finding scenarios which can be loaded, so
the work here is much simpler.
This commit is contained in:
James Turner 2019-02-03 11:36:56 +00:00
parent 801512bb8c
commit 867d898b68

View file

@ -188,38 +188,32 @@
}; };
var columns = [ "left-column", "right-column" ]; var columns = [ "left-column", "right-column" ];
var processScenario = func(nr,file, rootN) {
var scenarioN = rootN.getNode("scenario"); var processScenario = func(nr, rootN) {
if( scenarioN == nil ) return;
var descriptionN = rootN.getNode("description"); var descriptionN = rootN.getNode("description");
var nameN = rootN.getNode("name"); var nameN = rootN.getNode("name");
if( (descriptionN == nil)and(nameN == nil) )
{
descriptionN = scenarioN.getNode("description");
nameN = scenarioN.getNode("name");
}
var description = descriptionN != nil ? descriptionN.getValue() : ""; var description = descriptionN != nil ? descriptionN.getValue() : "";
var scenarioId = rootN.getNode("id").getValue();
var propertyRoot = props.globals.getNode("sim/gui/dialogs/scenario",1).getChild( "scenario", nr, 1 ); var propertyRoot = props.globals.getNode("sim/gui/dialogs/scenario",1).getChild( "scenario", nr, 1 );
propertyRoot.getNode("selected",1).setBoolValue(isEnabledScenario(file)); propertyRoot.getNode("selected",1).setBoolValue(isEnabledScenario(scenarioId));
propertyRoot.getNode("name",1).setValue(file); propertyRoot.getNode("name",1).setValue(scenarioId);
var group = gui.findElementByName( dlg_root, columns[math.mod(nr,2)] ).getChild("group", nr, 1 ); var group = gui.findElementByName( dlg_root, columns[math.mod(nr,2)] ).getChild("group", nr, 1 );
group.getNode("layout",1).setValue("hbox"); group.getNode("layout",1).setValue("hbox");
var cb = group.getNode("checkbox",1); var cb = group.getNode("checkbox",1);
cb.getNode("property",1).setValue(propertyRoot.getNode("selected").getPath()); cb.getNode("property",1).setValue(propertyRoot.getNode("selected").getPath());
var label = string.replace(file, "_", " "); var label = nameN.getValue();
if (nameN != nil)
label = nameN.getValue();
cb.getNode("label",1).setValue(label); cb.getNode("label",1).setValue(label);
cb.getNode("name",1).setValue(file); cb.getNode("name",1).setValue(scenarioId);
var applyBind = cb.addChild("binding", 0); var applyBind = cb.addChild("binding", 0);
applyBind.getNode("command", 1).setValue("dialog-apply"); applyBind.getNode("command", 1).setValue("dialog-apply");
var bind = cb.addChild("binding", 1); var bind = cb.addChild("binding", 1);
bind.getNode("command", 1).setValue("load-scenario"); bind.getNode("command", 1).setValue("load-scenario");
bind.getNode("name", 1).setValue(file); bind.getNode("name", 1).setValue(scenarioId);
bind.getNode("load-property", 1).setValue(propertyRoot.getNode("selected").getPath()); bind.getNode("load-property", 1).setValue(propertyRoot.getNode("selected").getPath());
#cb.getNode("enable/property",1).setValue("/sim/ai/scenarios-enabled"); #cb.getNode("enable/property",1).setValue("/sim/ai/scenarios-enabled");
@ -229,9 +223,8 @@
var path = getprop("/sim/fg-root") ~ "/AI"; var path = getprop("/sim/fg-root") ~ "/AI";
var i = -1; var i = -1;
foreach(var file; sort(directory(path), cmp)) foreach(var s; props.globals.getNode("sim/ai/scenarios",1).getChildren("scenario"))
if(size(file) > 4 and substr(file, -4) == ".xml") processScenario( i+=1, s );
processScenario( i+=1, substr(file,0,size(file)-4), io.read_properties(path ~ "/" ~ file) );
]]></open> ]]></open>