2015-03-10 20:48:11 +00:00
|
|
|
define([
|
2015-03-11 21:37:48 +00:00
|
|
|
'jquery', 'knockout', 'text!./Config.html', 'fgcommand', 'props', 'kojqui/button', 'kojqui/buttonset', 'kojqui/selectmenu',
|
|
|
|
], function(jquery, ko, htmlString, fgCommand, SGPropertyNode) {
|
2015-03-10 20:48:11 +00:00
|
|
|
function ViewModel(params) {
|
|
|
|
var self = this;
|
2015-03-11 21:37:48 +00:00
|
|
|
|
|
|
|
self.asa = ko.observable('');
|
2015-03-10 20:48:11 +00:00
|
|
|
|
2015-03-11 21:37:48 +00:00
|
|
|
self.aiEnabled = ko.observable().extend({
|
|
|
|
fgPropertyGetSet : "/sim/traffic-manager/enabled"
|
|
|
|
});
|
|
|
|
self.multiplayerHideReplay = ko.observable().extend({
|
|
|
|
fgPropertyGetSet : "/sim/traffic-manager/enabled"
|
|
|
|
});
|
|
|
|
|
|
|
|
self.callsign = ko.observable().extend({
|
|
|
|
fgPropertyGetSet : "/sim/multiplay/callsign"
|
|
|
|
});
|
|
|
|
|
|
|
|
self.online = ko.observable().extend({
|
|
|
|
fgprop : "/sim/multiplay/online"
|
|
|
|
});
|
|
|
|
|
|
|
|
self.offline = ko.pureComputed(function() {
|
|
|
|
return !self.online();
|
|
|
|
});
|
|
|
|
|
|
|
|
self.selectedServer = ko.observable().extend({
|
|
|
|
fgPropertyGetSet : "/sim/multiplay/selected-server"
|
|
|
|
});
|
|
|
|
|
|
|
|
self.gotServers = ko.observable().extend({
|
|
|
|
fgprop: "/sim/multiplay/got-servers"
|
|
|
|
}).subscribe(function(newValue) {
|
|
|
|
if( newValue ) {
|
|
|
|
self.serverList.removeAll();
|
|
|
|
jquery.get('/json/sim/multiplay/server-list?d=3', null, function(data) {
|
|
|
|
var root = new SGPropertyNode(data);
|
|
|
|
root.getChildren('server').forEach(function(server){
|
|
|
|
if( !server.getNode('online').getValue() )
|
|
|
|
return;
|
|
|
|
self.serverList.push( {
|
|
|
|
name: server.getNode('name').getValue(),
|
|
|
|
host: server.getNode('hostname').getValue(),
|
|
|
|
location: server.getNode('location').getValue(),
|
|
|
|
port: server.getNode('port').getValue(),
|
|
|
|
longname: server.getNode('hostname').getValue() + ' - ' + server.getNode('location').getValue(),
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.serverList = ko.observableArray([]);
|
|
|
|
|
|
|
|
self.toggleConnect = function() {
|
|
|
|
if( self.online() ) {
|
2015-03-12 08:50:16 +00:00
|
|
|
fgCommand.multiplayerDisconnect();
|
2015-03-11 21:37:48 +00:00
|
|
|
} else {
|
2015-03-12 08:50:16 +00:00
|
|
|
fgCommand.multiplayerConnect({
|
|
|
|
'servername': self.selectedServer(),
|
2015-03-26 15:10:46 +00:00
|
|
|
'rxport': 5000,
|
|
|
|
'txport': 5000
|
2015-03-12 08:50:16 +00:00
|
|
|
});
|
2015-03-11 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.serverListVisible = ko.observable(true);
|
|
|
|
|
2015-03-12 08:50:16 +00:00
|
|
|
fgCommand.multiplayerRefreshserverlist();
|
2015-03-10 20:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return component definition
|
|
|
|
return {
|
|
|
|
viewModel : ViewModel,
|
|
|
|
template : htmlString
|
|
|
|
};
|
|
|
|
});
|