1
0
Fork 0

Use new multiplayer commands in gui

This commit is contained in:
Torsten Dreyer 2015-03-12 09:50:16 +01:00
parent 419ae89ae2
commit 6ae95ea10a
3 changed files with 50 additions and 62 deletions

View file

@ -76,16 +76,10 @@
gui.dialog_update("multiplayer", "host");
}
# listen for results arriving
# listen for results arriving
setlistener("/sim/multiplay/got-servers", updateServers);
setlistener("/sim/multiplay/get-servers-failure", updateServersFailed);
fgcommand("xmlhttprequest", props.Node.new({
"url" : "http://liveries.flightgear.org/mpstatus/mpservers.xml",
"targetnode" : "/sim/multiplay/server-list",
"complete" : "/sim/multiplay/got-servers",
"failure" : "/sim/multiplay/get-servers-failure"
}));
fgcommand("multiplayer-refreshserverlist");
]]>
</open>
@ -235,21 +229,11 @@
<binding>
<command>nasal</command>
<script>
var server = getprop("/sim/multiplay/selected-server");
# Get the server name by splitting on the space between
# the hostname and the comment.
server = split(" ", server)[0];
setprop("/sim/multiplay/txhost", server);
# Standard port is 5000
setprop("/sim/multiplay/txport", 5000);
setprop("/sim/multiplay/rxport", 5000);
fgcommand("multiplayer-connect", props.Node.new({
"servername": getprop("/sim/multiplay/selected-server")
}));
</script>
</binding>
<binding>
<command>reinit</command>
<subsystem>mp</subsystem>
</binding>
</button>
<button>
@ -262,13 +246,7 @@
<command>dialog-apply</command>
</binding>
<binding>
<command>nasal</command>
<script>
setprop("/sim/multiplay/txhost", "");
</script>
</binding>
<binding>
<command>reinit</command>
<command>multiplayer-disconnect</command>
<subsystem>mp</subsystem>
</binding>
</button>

View file

@ -2,11 +2,14 @@
*
*/
(function(factory) {
if (typeof define === "function" && define.amd)// AMD. Register as an anonymous module.
define([
'jquery'
], factory); else // Browser globals
factory(jQuery);
if (typeof define === "function" && define.amd)// AMD. Register as an
// anonymous module.
define([
'jquery'
], factory);
else
// Browser globals
factory(jQuery);
}(function(jquery) {
fgCommand = {
@ -79,11 +82,13 @@
name : '',
children : []
};
if (typeof (subsys) === 'string')arg.children.push({
name : 'subsystem',
index : 0,
value : subsys
});else
if (typeof (subsys) === 'string')
arg.children.push({
name : 'subsystem',
index : 0,
value : subsys
});
else
subsys.forEach(function(s, i) {
arg.children.push({
name : 'subsystem',
@ -114,34 +119,39 @@
this.sendCommand("request-metar", this.twoArgs("station", id, "path", path));
},
multiplayer : function(cmd) {
multiplayerConnect : function(cmd) {
cmd = cmd || {};
var arg = {
'name' : '',
'children' : [
{
'name' : 'command',
'value' : '',
'index' : 0,
}
],
'children' : [],
};
if (cmd.connect) {
arg.children[0].value = 'connect';
arg.children.push({
'name' : 'servername',
'value' : cmd.servername
});
if (cmd.rxport)
arg.children.push({
'name' : 'servername',
'value' : cmd.connect.servername
});
if (cmd.connect.rxport)arg.children.push({
'name' : 'rxport',
'value' : Number(cmd.connect.rxport)
'value' : Number(cmd.rxport)
});
if (cmd.connect.txport)arg.children.push({
if (cmd.txport)
arg.children.push({
'name' : 'txport',
'value' : Number(cmd.connect.txport)
'value' : Number(cmd.txport)
});
} else if (cmd.disconnect)arg.children[0].value = 'disconnect';else if (cmd.refreshserverlist)arg.children[0].value = 'refreshserverlist';
this.sendCommand("multiplayer", arg);
this.sendCommand("multiplayer-connect", arg);
},
multiplayerDisconnect : function() {
var arg = {
'name' : '',
'children' : [],
};
this.sendCommand("multiplayer-disconnect");
},
multiplayerRefreshserverlist : function() {
this.sendCommand('multiplayer-refreshserverlist');
},
clearMetar : function(path) {

View file

@ -57,17 +57,17 @@ define([
self.toggleConnect = function() {
if( self.online() ) {
fgCommand.multiplayer({ disconnect: {} });
fgCommand.multiplayerDisconnect();
} else {
fgCommand.multiplayer({ connect: {
'servername': self.selectedServer(),
} });
fgCommand.multiplayerConnect({
'servername': self.selectedServer(),
});
}
}
self.serverListVisible = ko.observable(true);
fgCommand.multiplayer({ refreshserverlist: {} });
fgCommand.multiplayerRefreshserverlist();
}
// Return component definition