1
0
Fork 0

Merge branch 'master' of git://gitorious.org/fg/fgdata

This commit is contained in:
BARANGER Emmanuel 2012-03-24 20:03:46 +01:00
commit ce21ba73d9
10 changed files with 118 additions and 122 deletions

View file

@ -1,9 +1,8 @@
###############################################################################
## $Id$
##
## Nasal for copilot for dual control over the multiplayer network.
##
## Copyright (C) 2007 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
## Copyright (C) 2007 - 2012 Anders Gidenstam (anders(at)gidenstam.org)
## This file is licensed under the GPL license version 2 or later.
##
###############################################################################
@ -123,7 +122,8 @@ var connect = func (pilot) {
] ~ ADC.copilot_connect_pilot(pilot);
print("Dual control ... connected to pilot.");
setprop("/sim/messages/copilot", "Welcome aboard.");
setprop("/sim/messages/copilot", "Welcome aboard. I'm " ~
pilot.getNode("callsign").getValue() ~ ".");
}
var disconnect = func {
@ -168,12 +168,16 @@ var disconnect = func {
######################################################################
# Main loop singleton class.
var main = {
_initialized : 0,
init : func {
me.loopid = 0;
if (!me._initialized) {
me.loopid = 0;
setlistener("/ai/models/model-added", func {
settimer(func { me.activate(); }, 2);
});
me._initialized = 1;
}
me.active = 0;
setlistener("/ai/models/model-added", func {
settimer(func { me.activate(); }, 2);
});
print("Copilot dual control ... initialized");
settimer(func { me.activate(); }, 5);
},

View file

@ -1,9 +1,8 @@
###############################################################################
## $Id$
##
## Nasal for main pilot for dual control over the multiplayer network.
##
## Copyright (C) 2007 - 2010 Anders Gidenstam (anders(at)gidenstam.org)
## Copyright (C) 2007 - 2012 Anders Gidenstam (anders(at)gidenstam.org)
## This file is licensed under the GPL license version 2 or later.
##
###############################################################################
@ -30,18 +29,23 @@ var connect = func (copilot) {
process_data = ADC.pilot_connect_copilot(copilot);
print("Dual control ... copilot connected.");
setprop("/sim/messages/copilot", "Hi.");
setprop("/sim/messages/copilot", "Hi. I'm your copilot " ~
copilot.getNode("callsign").getValue() ~ ".");
}
######################################################################
# Main loop singleton class.
var main = {
_initialized : 0,
init : func {
me.loopid = 0;
if (!me._initialized) {
me.loopid = 0;
setlistener("/ai/models/model-added", func {
settimer(func { me.activate(); }, 2);
});
me._initialized = 1;
}
me.active = 0;
setlistener("/ai/models/model-added", func {
settimer(func { me.activate(); }, 2);
});
settimer(func { me.activate(); }, 5);
print("Pilot dual control ... initialized");
},

View file

@ -133,7 +133,7 @@ var door = {
#
var light = {
new: func {
m = { parents: [light] };
var m = { parents: [light] };
m.node = makeNode(arg[0]);
var stretch = 1.0;
var c = 1;

View file

@ -39,8 +39,8 @@ var menuEnable = func(searchname, state) {
menu.getNode("enabled").setBoolValue(state);
}
}
foreach (item; menu.getChildren("item")) {
foreach (name; item.getChildren("name")) {
foreach (var item; menu.getChildren("item")) {
foreach (var name; item.getChildren("name")) {
if (name.getValue() == searchname) {
item.getNode("enabled").setBoolValue(state);
}
@ -55,8 +55,8 @@ var menuEnable = func(searchname, state) {
#
var menuBind = func(searchname, command) {
foreach (var menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
foreach (item; menu.getChildren("item")) {
foreach (name; item.getChildren("name")) {
foreach (var item; menu.getChildren("item")) {
foreach (var name; item.getChildren("name")) {
if (name.getValue() == searchname) {
item.getNode("binding", 1).getNode("command", 1).setValue("nasal");
item.getNode("binding", 1).getNode("script", 1).setValue(command);
@ -89,11 +89,31 @@ var setCursor = func(x = nil, y = nil, cursor = nil) {
fgcommand("set-cursor", args);
return args.getNode("cursor").getValue();
}
##
# Supported mouse cursor types.
#
var cursor_types = { none: 0, pointer: 1, wait: 2, crosshair: 3, leftright: 4,
topside: 5, bottomside: 6, leftside: 7, rightside: 8,
topleft: 9, topright: 10, bottomleft: 11, bottomright: 12,
};
##
# Find a GUI element by given name.
# dialog: dialog root property.
# name: name of GUI element to be searched.
# Returns GUI element when found, nil otherwise.
#
var findElementByName = func(dialog,name) {
foreach( var child; dialog.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = findElementByName(child, name);
if( f != nil ) return f;
}
return nil;
};
########################################################################
@ -240,10 +260,10 @@ var Widget = {
prop : func { return me.node; },
new : func { return { parents : [Widget], node : props.Node.new() } },
addChild : func {
type = arg[0];
idx = size(me.node.getChildren(type));
name = type ~ "[" ~ idx ~ "]";
newnode = me.node.getNode(name, 1);
var type = arg[0];
var idx = size(me.node.getChildren(type));
var name = type ~ "[" ~ idx ~ "]";
var newnode = me.node.getNode(name, 1);
return { parents : [Widget], node : newnode };
},
setColor : func(r, g, b, a = 1) {
@ -295,6 +315,7 @@ var Dialog = {
new: func(prop, path = nil, name = nil) {
var m = { parents: [Dialog] };
m.state = 0;
m.listener = nil;
if (path == nil) { # global dialog in $FG_ROOT/gui/dialogs/
m.name = prop;
m.prop = props.Node.new({ "dialog-name" : prop });
@ -309,6 +330,11 @@ var Dialog = {
}
return Dialog.instance[m.name] = m;
},
del: func
{
if (me.listener != nil)
removelistener(me.listener);
},
# doesn't need to be called explicitly, but can be used to force a reload
load: func {
var state = me.state;
@ -433,6 +459,9 @@ var OverlaySelector = {
del: func {
removelistener(me.listener);
removelistener(me.reinit_listener);
# call inherited 'del'
me.parents = subvec(me.parents,1);
me.del();
},
rescan: func {
me.data = [];
@ -548,6 +577,9 @@ var FileSelector = {
delete(me.instance, me.name);
removelistener(me.cblistener);
me.data.remove();
# call inherited 'del'
me.parents = subvec(me.parents,1);
me.del();
},
};
@ -556,7 +588,7 @@ var FileSelector = {
#
var DirSelector = {
new: func(callback, title, button, dir = "") {
return FileSelector.new(callback, title, button, nil, dir, "", 0, show_files=0);
return FileSelector.new(callback, title, button, nil, dir, "", 0, 0);
}
};
@ -728,10 +760,10 @@ var setWeight = func(wgt, opt) {
# appropriate weights therefrom.
var setWeightOpts = func {
var tankchange = 0;
foreach(w; props.globals.getNode("sim").getChildren("weight")) {
foreach(var w; props.globals.getNode("sim").getChildren("weight")) {
var selected = w.getNode("selected");
if(selected != nil) {
foreach(opt; w.getChildren("opt")) {
foreach(var opt; w.getChildren("opt")) {
if(opt.getNode("name", 1).getValue() == selected.getValue()) {
if(setWeight(w, opt)) { tankchange = 1; }
break;
@ -901,7 +933,7 @@ var showWeightDialog = func {
tcell(fuelTable, "text", 0, 4).set("label", "Gallons");
var tanks = props.globals.getNode("/consumables/fuel").getChildren("tank");
for(i=0; i<size(tanks); i+=1) {
for(var i=0; i<size(tanks); i+=1) {
var t = tanks[i];
var tname = i ~ "";
@ -965,7 +997,7 @@ var showWeightDialog = func {
var wgts = payload_base.getChildren("weight");
else
var wgts = [];
for(i=0; i<size(wgts); i+=1) {
for(var i=0; i<size(wgts); i+=1) {
var w = wgts[i];
var wname = w.getNode("name", 1).getValue();
var wprop = fdmdata.payload ~ "/weight[" ~ i ~ "]";
@ -981,8 +1013,8 @@ var showWeightDialog = func {
# 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());
# var ent = combo.addChild("value");
# ent.prop().setValue(opt.getNode("name", 1).getValue());
#}
# More complicated workaround to move the "current" item
@ -1065,20 +1097,20 @@ var showWeightDialog = func {
# </text>
# </help>
#
showHelpDialog = func {
node = props.globals.getNode(arg[0]);
var showHelpDialog = func {
var node = props.globals.getNode(arg[0]);
if (arg[0] == "/sim/help" and size(node.getChildren()) < 4) {
node = node.getChild("common");
}
name = node.getNode("title", 1).getValue();
var name = node.getNode("title", 1).getValue();
if (name == nil) {
name = getprop("/sim/description");
if (name == nil) {
name = getprop("/sim/aircraft");
}
}
toggle = size(arg) > 1 and arg[1] != nil and arg[1] > 0;
var toggle = size(arg) > 1 and arg[1] != nil and arg[1] > 0;
if (toggle and contains(dialog, name)) {
fgcommand("dialog-close", props.Node.new({ "dialog-name": name }));
delete(dialog, name);
@ -1091,13 +1123,13 @@ showHelpDialog = func {
dialog[name].set("name", name);
# title bar
titlebar = dialog[name].addChild("group");
var titlebar = dialog[name].addChild("group");
titlebar.set("layout", "hbox");
titlebar.addChild("empty").set("stretch", 1);
titlebar.addChild("text").set("label", name);
titlebar.addChild("empty").set("stretch", 1);
w = titlebar.addChild("button");
var w = titlebar.addChild("button");
w.set("pref-width", 16);
w.set("pref-height", 16);
w.set("legend", "");
@ -1109,19 +1141,19 @@ showHelpDialog = func {
dialog[name].addChild("hrule");
# key list
keylist = dialog[name].addChild("group");
var keylist = dialog[name].addChild("group");
keylist.set("layout", "table");
keylist.set("default-padding", 2);
keydefs = node.getChildren("key");
n = size(keydefs);
row = col = 0;
foreach (key; keydefs) {
var keydefs = node.getChildren("key");
var n = size(keydefs);
var row = var col = 0;
foreach (var key; keydefs) {
if (n >= 60 and row >= n / 3 or n >= 16 and row >= n / 2) {
col += 1;
row = 0;
}
w = keylist.addChild("text");
var w = keylist.addChild("text");
w.set("row", row);
w.set("col", 2 * col);
w.set("halign", "right");
@ -1136,7 +1168,7 @@ showHelpDialog = func {
}
# separate lines
lines = node.getChildren("line");
var lines = node.getChildren("line");
if (size(lines)) {
if (size(keydefs)) {
dialog[name].addChild("empty").set("pref-height", 4);
@ -1144,12 +1176,12 @@ showHelpDialog = func {
dialog[name].addChild("empty").set("pref-height", 4);
}
g = dialog[name].addChild("group");
var g = dialog[name].addChild("group");
g.set("layout", "vbox");
g.set("default-padding", 1);
foreach (var lin; lines) {
foreach (var l; split("\n", lin.getValue())) {
w = g.addChild("text");
var w = g.addChild("text");
w.set("halign", "left");
w.set("label", " " ~ l ~ " ");
}
@ -1161,13 +1193,13 @@ showHelpDialog = func {
dialog[name].set("resizable", 1);
dialog[name].addChild("empty").set("pref-height", 10);
width = [640, 800, 1152][col];
height = screenHProp.getValue() - (100 + (size(keydefs) / (col + 1) + size(lines)) * 28);
var width = [640, 800, 1152][col];
var height = screenHProp.getValue() - (100 + (size(keydefs) / (col + 1) + size(lines)) * 28);
if (height < 200) {
height = 200;
}
w = dialog[name].addChild("textbox");
var w = dialog[name].addChild("textbox");
w.set("padding", 4);
w.set("halign", "fill");
w.set("valign", "fill");
@ -1335,7 +1367,7 @@ var update_shader_settings = func() {
setprop("/sim/rendering/shaders/urban",qualityLvl);
setprop("/sim/rendering/shaders/water",qualityLvl);
if (qualityLvl >= 3.0){
qualityLvl = 3.0;
qualityLvl = 3.0;
}
setprop("/sim/rendering/shaders/model",qualityLvl);
if (qualityLvl >= 1.0){

View file

@ -202,7 +202,7 @@ var wrap = func(node) {
} elsif(argtype == "vector") {
var v = node;
var n = size(v);
for(i=0; i<n; i+=1) { v[i] = wrapNode(v[i]); }
for(var i=0; i<n; i+=1) { v[i] = wrapNode(v[i]); }
return v;
}
return node;
@ -235,7 +235,7 @@ var setAll = func(base, child, value) {
node = node.getParent();
if(node == nil) return;
var children = node.getChildren();
foreach(c; children)
foreach(var c; children)
if(c.getName() == name)
c.getNode(child, 1).setValue(value);
}

View file

@ -26,7 +26,7 @@
# Populate the view combo box with a list of the available views
initViews : func(update) {
var combo = me.findElementByName( me.dlgRoot, "view-selector" );
var combo = gui.findElementByName( me.dlgRoot, "view-selector" );
if (update)
combo.removeChildren("value");
@ -35,21 +35,21 @@
foreach (var v; view.views) {
var name = "Unnamed view " ~ v.getIndex();
if (v.getNode("name") != nil) {
name = v.getNode("name").getValue();
name = v.getNode("name").getValue();
}
# Pre-populate the combo box selected value
if (i == current_view) {
setprop("/sim/replay/view-name", name);
setprop("/sim/replay/view-name", name);
}
if (update)
combo.getNode("value[" ~ i ~ "]", 1).setValue(name);
i = i + 1;
i += 1;
}
},
open : func {
var replaySlider = me.findElementByName( me.dlgRoot, "replay-time-slider" );
var replaySlider = gui.findElementByName( me.dlgRoot, "replay-time-slider" );
me.maxProp = replaySlider.getChild("max");
me.minProp = replaySlider.getChild("min");
me.speedUpListenerId = setlistener( "/sim/speed-up", func(n) { me.updateListener(n); }, 1, 1 );
@ -72,24 +72,13 @@
}
setprop("/sim/gui/dialogs/replay/time-factor","" ~ SpeedUp ~ "x");
me.initViews(0);
},
},
close : func {
removelistener( me.speedUpListenerId );
removelistener( me.viewListenerId );
},
findElementByName : func(base,name) {
foreach( var child; base.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = me.findElementByName(child,name);
if( f != nil ) return f;
}
return nil;
},
};
var controller = ReplayDialogController.new( cmdarg() );
@ -147,7 +136,7 @@
<object-name>replay-looped</object-name>
</binding>
</checkbox>
<input>
<input>
<name>replay-duration</name>
<pref-width>40</pref-width>
<color>
@ -161,7 +150,7 @@
<command>dialog-apply</command>
<object-name>replay-duration</object-name>
</binding>
</input>
</input>
<empty><pref-width>40</pref-width></empty>
@ -214,8 +203,8 @@
<alpha type="float">0.8</alpha>
</color>
<binding>
<command>nasal</command>
<script>controls.speedup(-1);</script>
<command>nasal</command>
<script>controls.speedup(-1);</script>
</binding>
</button>
<text>
@ -242,12 +231,12 @@
<alpha type="float">0.8</alpha>
</color>
<binding>
<command>nasal</command>
<script>controls.speedup(1);</script>
<command>nasal</command>
<script>controls.speedup(1);</script>
</binding>
</button>
<empty><stretch>1</stretch></empty>
<empty><stretch>1</stretch></empty>
<button>
<legend>Hide</legend>
@ -260,10 +249,10 @@
</color>
<pref-width>40</pref-width>
<binding>
<command>nasal</command>
<script><![CDATA[
<command>nasal</command>
<script><![CDATA[
setprop("/sim/messages/copilot", "Replay active. 'Esc' to stop. 'Ctrl-R' to show replay controls.");
]]></script>
]]></script>
</binding>
<binding>
<command>dialog-close</command>
@ -286,8 +275,8 @@
<alpha type="float">0.8</alpha>
</color>
<binding>
<command>nasal</command>
<script>controls.replaySkip(-30);</script>
<command>nasal</command>
<script>controls.replaySkip(-30);</script>
</binding>
</button>
@ -302,8 +291,8 @@
<alpha type="float">0.8</alpha>
</color>
<binding>
<command>nasal</command>
<script>controls.replaySkip(-5);</script>
<command>nasal</command>
<script>controls.replaySkip(-5);</script>
</binding>
</button>
@ -335,7 +324,7 @@
<min>0</min><!-- property is updated on "dialog open" -->
<max>1.0</max><!-- property is updated on "dialog open" -->
<property>/sim/replay/time</property>
<live>true</live>
<live>true</live>
<binding>
<command>dialog-apply</command>
<object-name>replay-time-slider</object-name>
@ -367,8 +356,8 @@
<alpha type="float">0.8</alpha>
</color>
<binding>
<command>nasal</command>
<script>controls.replaySkip(5);</script>
<command>nasal</command>
<script>controls.replaySkip(5);</script>
</binding>
</button>

View file

@ -108,17 +108,6 @@
<open><![CDATA[
var dlg_root = cmdarg();
var findElementByName = func(rootN, name) {
foreach( var child; rootN.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = findElementByName(child,name);
if( f != nil ) return f;
}
return nil;
};
var isEnabledScenario = func(scenario) {
foreach( var n; props.globals.getNode("sim/ai",1).getChildren("scenario") )
if( n.getValue() == scenario )
@ -138,7 +127,7 @@
propertyRoot.getNode("selected",1).setBoolValue(isEnabledScenario(file));
propertyRoot.getNode("name",1).setValue(file);
var group = 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");
var cb = group.getNode("checkbox",1);
cb.getNode("property",1).setValue(propertyRoot.getNode("selected").getPath());

View file

@ -329,19 +329,8 @@
<open><![CDATA[
var dlg_root = cmdarg();
var findElementByName = func(rootN, name) {
foreach( var child; rootN.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = findElementByName(child,name);
if( f != nil ) return f;
}
return nil;
};
# Fill the sound device combo box
var combo = findElementByName( dlg_root, "source-selection" );
var combo = gui.findElementByName( dlg_root, "source-selection" );
var wsn = props.globals.getNode( "sim/sound/devices" );
if( wsn != nil ) {
var devices = wsn.getChildren("device");

View file

@ -1961,7 +1961,7 @@
# fill the METAR source combo box
var combo = me.findElementByName( me.dlgRoot, "source-selection" );
var combo = gui.findElementByName( me.dlgRoot, "source-selection" );
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
if( wsn != nil ) {
var scenarios = wsn.getChildren("scenario");
@ -2020,17 +2020,6 @@
return nil;
},
findElementByName : func(base,name) {
foreach( var child; base.getChildren() ) {
var n = child.getNode( "name" );
if( n != nil and n.getValue() == name )
return child;
var f = me.findElementByName(child,name);
if( f != nil ) return f;
}
return nil;
},
scenarioListener : func( n ) {
description = "";
metar = "nil";

View file

@ -225,7 +225,7 @@ Started September 2000 by David Megginson, david@megginson.com
<sound>
<volume type="float"
userarchive="y">0.8</volume>
<enabled type="bool">true</enabled>
<enabled type="bool" userarchive="y">true</enabled>
<atc>
<enabled type="bool"
userarchive="y">true</enabled>