Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
misc/Legacy Worlds.wdgt/lib/LWWidget
77
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5.js
Normal file
77
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
LWWidget.Beta5 = LWWidget.Game.inherits({
|
||||
|
||||
constructor: function (path) {
|
||||
this.base(path);
|
||||
this.pageElement = 'b5Display';
|
||||
|
||||
this.pages[0] = new LWWidget.Beta5.Player(this);
|
||||
this.pages[1] = new LWWidget.Beta5.Planets(this);
|
||||
this.pages[2] = new LWWidget.Beta5.Fleets(this);
|
||||
this.pages[3] = new LWWidget.Beta5.Cash(this);
|
||||
this.pages[4] = new LWWidget.Beta5.Techs(this);
|
||||
this.pages[5] = new LWWidget.Beta5.Msg(this);
|
||||
this.pages[6] = new LWWidget.Beta5.Forums(this);
|
||||
this.pages[7] = new LWWidget.Beta5.Ticks(this);
|
||||
|
||||
this.setPage('player');
|
||||
|
||||
this.addSlot('updateServerTime');
|
||||
this.stUpdate = new Base.Timer(1000, true);
|
||||
this.stUpdate.bindEvent('Tick', 'updateServerTime', this);
|
||||
this.stUpdate.start();
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.stUpdate.destroy();
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
setData: function (data) {
|
||||
this.base(data);
|
||||
this.serverTime = parseInt(data.getAttribute('serverTime'), 10);
|
||||
this.drawServerTime();
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
var _e = document.getElementById('gDisplay');
|
||||
if (!_e) {
|
||||
return;
|
||||
}
|
||||
|
||||
var _e2 = document.getElementById('b5Display');
|
||||
if (!_e2) {
|
||||
_e.style.overflow = 'visible';
|
||||
_e.innerHTML = '<table style="width:98%;height:208px;margin:0% 1%;padding:0%;border:0">'
|
||||
+ '<tr><td style="font-size:13px;color:white;height:16px;text-align:center" id="serverTime"> </td></tr>'
|
||||
+ '<tr><td style="font-size:13px;color:white"><div id="b5Display" style="overflow:auto;height:192px;width:100%"> </div></td></tr>'
|
||||
+ '</table>';
|
||||
}
|
||||
this.drawServerTime();
|
||||
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
updateServerTime: function () {
|
||||
if (!this.serverTime) {
|
||||
return;
|
||||
}
|
||||
this.serverTime ++;
|
||||
this.drawServerTime();
|
||||
},
|
||||
|
||||
drawServerTime: function (u) {
|
||||
var _e = document.getElementById('serverTime');
|
||||
if (!_e || !this.serverTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
_e.innerHTML = LWWidget.Game.formatTime(this.serverTime);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Register the version
|
||||
LWWidget.Game.versions().put('beta5', LWWidget.Beta5);
|
17
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Cash.js
Normal file
17
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Cash.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
LWWidget.Beta5.Cash = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Empire')[0].getChildren('Budget')[0];
|
||||
|
||||
this.income = parseInt(_d.getAttribute('income'), 10);
|
||||
this.upkeep = parseInt(_d.getAttribute('upkeep'), 10);
|
||||
this.profit = parseInt(_d.getAttribute('profit'), 10);
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
_e.innerHTML = '<p style="text-align:center"><br/><br/>Planetary income: <b>€' + Base.Util.formatNumber(this.income)
|
||||
+ '</b><br/><br/>Fleet upkeep: <b>€' + Base.Util.formatNumber(this.upkeep)
|
||||
+ '</b><br/><br/>Daily profit: <b>€' + Base.Util.formatNumber(this.profit) + '</p>';
|
||||
}
|
||||
|
||||
});
|
55
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Fleets.js
Normal file
55
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Fleets.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
LWWidget.Beta5.Fleets = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Empire')[0].getChildren('Fleets')[0];
|
||||
|
||||
this.fleets = parseInt(_d.getAttribute('count'), 10);
|
||||
if (this.fleets) {
|
||||
// Fleets in battle
|
||||
this.inBattle = parseInt(_d.getAttribute('inBattle'), 10);
|
||||
// Total fleet power
|
||||
this.power = parseInt(_d.getAttribute('power'), 10);
|
||||
// Ships types
|
||||
this.gaships = parseInt(_d.getAttribute('gaships'), 10);
|
||||
this.fighters = parseInt(_d.getAttribute('fighters'), 10);
|
||||
this.cruisers = parseInt(_d.getAttribute('cruisers'), 10);
|
||||
this.bcruisers = parseInt(_d.getAttribute('bcruisers'), 10);
|
||||
// Upkeep
|
||||
_d = data.getChildren('Empire')[0].getChildren('Budget')[0];
|
||||
this.upkeep = parseInt(_d.getAttribute('upkeep'), 10);
|
||||
}
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
if (this.fleets == 0) {
|
||||
_e.innerHTML = '<p style="text-align:center">No fleets</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
var _s = '<p style="text-align:center"><b>' + Base.Util.formatNumber(this.fleets)
|
||||
+ '</b> fleet' + (this.fleets > 1 ? 's' : '');
|
||||
if (this.inBattle) {
|
||||
_s += ' (<b>' + Base.Util.formatNumber(this.inBattle) + '</b> engaged in battle!)';
|
||||
}
|
||||
_s += '<br/><br/>Total fleet power: <b>' + Base.Util.formatNumber(this.power)
|
||||
+ '</b><br/>Upkeep: <b>€' + Base.Util.formatNumber(this.upkeep)
|
||||
+ '</b><br/><br/><u>Ship types</u><br/>';
|
||||
|
||||
if (this.gaships) {
|
||||
_s += 'G.A. ships: <b>' + Base.Util.formatNumber(this.gaships) + '</b><br/>';
|
||||
}
|
||||
if (this.fighters) {
|
||||
_s += 'Fighters: <b>' + Base.Util.formatNumber(this.fighters) + '</b><br/>';
|
||||
}
|
||||
if (this.cruisers) {
|
||||
_s += 'Cruisers: <b>' + Base.Util.formatNumber(this.cruisers) + '</b><br/>';
|
||||
}
|
||||
if (this.bcruisers) {
|
||||
_s += 'Battle Cruisers: <b>' + Base.Util.formatNumber(this.bcruisers) + '</b><br/>';
|
||||
}
|
||||
_s += '</p>';
|
||||
|
||||
_e.innerHTML = _s;
|
||||
}
|
||||
|
||||
});
|
125
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Forums.js
Normal file
125
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Forums.js
Normal file
|
@ -0,0 +1,125 @@
|
|||
LWWidget.Beta5.Forums = LWWidget.Game.Page.inherits({
|
||||
|
||||
switchMode: function () {
|
||||
this.details = !this.details;
|
||||
this.game.draw();
|
||||
},
|
||||
|
||||
setData: function (data) {
|
||||
var _f = data.getChildren('Communications')[0].getChildren('Forums')[0];
|
||||
|
||||
// Read general forums
|
||||
var gf = _f.getChildren('GeneralForums'), gcats = new Base.Util.Hashtable();
|
||||
for (var i in gf) {
|
||||
var c = gf[i], desc = c.getChildren('Description')[0].getText(),
|
||||
cf = c.getChildren('Forum'), forums = new Array();
|
||||
for (var j in cf) {
|
||||
forums.push([cf[j].getText(), parseInt(cf[j].getAttribute('topics'), 10), parseInt(cf[j].getAttribute('unread'), 10)]);
|
||||
}
|
||||
gcats.put(desc, forums);
|
||||
}
|
||||
|
||||
// Read alliance forums
|
||||
var af = _f.getChildren('AllianceForums'), aForums = new Array();
|
||||
if (af.length) {
|
||||
af = af[0].getChildren('Forum');
|
||||
for (var i in af) {
|
||||
aForums.push([af[i].getText(), parseInt(af[i].getAttribute('topics'), 10), parseInt(af[i].getAttribute('unread'), 10)]);
|
||||
}
|
||||
}
|
||||
|
||||
// Store data
|
||||
this.general = gcats;
|
||||
this.alliance = aForums;
|
||||
},
|
||||
|
||||
|
||||
show: function () {
|
||||
this.details = false;
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
if (this.details) {
|
||||
_e.innerHTML = this.getDetailedHTML();
|
||||
} else {
|
||||
_e.innerHTML = this.getShortHTML();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getShortHTML: function () {
|
||||
var text = new Array(), gk = this.general.keys();
|
||||
for (var i in gk) {
|
||||
text.push(this.catSummary(gk[i], this.general.get(gk[i])));
|
||||
}
|
||||
|
||||
if (this.alliance.length) {
|
||||
text.push(this.catSummary('Alliance forums', this.alliance));
|
||||
}
|
||||
|
||||
return '<p style="text-align:center">' + text.join('<br/>') + '<br/><br/><a href="#" onclick="Base.Comp.get('
|
||||
+ this._cid + ').switchMode();return false">Show details</a>';
|
||||
},
|
||||
|
||||
catSummary: function (name, list) {
|
||||
var s = '<u>' + name + '</u>: ';
|
||||
|
||||
var unread = this.countUnread(list);
|
||||
if (unread > 0) {
|
||||
s += '<b>' + Base.Util.formatNumber(unread) + '</b> unread topic' + (unread > 1 ? 's' : '');
|
||||
} else {
|
||||
s += 'no unread topics';
|
||||
}
|
||||
return s;
|
||||
},
|
||||
|
||||
countUnread: function (forums) {
|
||||
var s = 0;
|
||||
for (var i in forums) {
|
||||
s += forums[i][2];
|
||||
}
|
||||
return s;
|
||||
},
|
||||
|
||||
|
||||
getDetailedHTML: function () {
|
||||
var text = new Array(), gk = this.general.keys();
|
||||
|
||||
for (var i in gk) {
|
||||
text.push(this.catDetailed(gk[i], this.general.get(gk[i])));
|
||||
}
|
||||
|
||||
if (this.alliance.length) {
|
||||
text.push(this.catDetailed('Alliance forums', this.alliance));
|
||||
}
|
||||
|
||||
return '<p style="text-align:center"><a href="#" onclick="Base.Comp.get('
|
||||
+ this._cid + ').switchMode();return false">Hide details</a><br/><br/>' + text.join('<br/><br/>');
|
||||
},
|
||||
|
||||
catDetailed: function (name, forums) {
|
||||
if (!forums.length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var text = new Array();
|
||||
|
||||
text.push('<b>' + name + '</b>');
|
||||
for (var i in forums) {
|
||||
var f = forums[i], s = '<u>' + f[0] + '</u>: ';
|
||||
|
||||
if (f[1]) {
|
||||
s += '<b>' + Base.Util.formatNumber(f[1]) + '</b> topic' + (f[1] > 1 ? 's' : '');
|
||||
if (f[2]) {
|
||||
s += ' (<b>' + Base.Util.formatNumber(f[2]) + '</b> unread)';
|
||||
}
|
||||
} else {
|
||||
s += 'empty forum';
|
||||
}
|
||||
text.push(s);
|
||||
}
|
||||
|
||||
return text.join('<br/>');
|
||||
}
|
||||
|
||||
});
|
71
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Msg.js
Normal file
71
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Msg.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
LWWidget.Beta5.Msg = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Communications')[0].getChildren('Messages')[0];
|
||||
|
||||
// Get default folders
|
||||
var _f = _d.getChildren('DefaultFolder');
|
||||
for (var i in _f) {
|
||||
var _a = [parseInt(_f[i].getAttribute('all'), 10), parseInt(_f[i].getAttribute('new'), 10)];
|
||||
switch (_f[i].getAttribute('id')) {
|
||||
case 'IN': this.inbox = _a; break;
|
||||
case 'INT': this.internal = _a; break;
|
||||
case 'OUT': this.outbox = _a; break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get custom folders
|
||||
this.custom = new Base.Util.Hashtable();
|
||||
_f = _d.getChildren('CustomFolder');
|
||||
for (var i in _f) {
|
||||
this.custom.put(_f[i].getAttribute('id'), [parseInt(_f[i].getAttribute('all'), 10), parseInt(_f[i].getAttribute('new'), 10), _f[i].getText()]);
|
||||
}
|
||||
},
|
||||
|
||||
show: function () {
|
||||
this.dCustom = false;
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
var _s = '<p style="text-align:center">';
|
||||
_s += this.folderCode('Inbox', this.inbox[0], this.inbox[1]) + '<br/>';
|
||||
_s += this.folderCode('Transmissions', this.internal[0], this.internal[1]) + '<br/>'
|
||||
_s += this.folderCode('Sent messages', this.outbox[0], this.outbox[1]) + '<br/><br/>';
|
||||
|
||||
if (this.custom.isEmpty()) {
|
||||
_s += 'No custom folders';
|
||||
} else if (this.dCustom) {
|
||||
_s += '<a href="#" onclick="Base.Comp.get(' + this._cid + ').switchCustom();return false">Hide custom folders</a><br/>';
|
||||
var cf = this.custom.values();
|
||||
for (var i in cf) {
|
||||
_s += this.folderCode(cf[i][2], cf[i][0], cf[i][1]) + '<br/>';
|
||||
}
|
||||
} else {
|
||||
_s += '<a href="#" onclick="Base.Comp.get(' + this._cid + ').switchCustom();return false">Display custom folders</a>';
|
||||
}
|
||||
|
||||
_s += '</p>';
|
||||
_e.innerHTML = _s;
|
||||
},
|
||||
|
||||
folderCode: function (name, a, n) {
|
||||
var _s = '<b>' + name + '</b>: ';
|
||||
if (a) {
|
||||
if (n) {
|
||||
_s += '<b>' + Base.Util.formatNumber(n) + '</b> new message' + (n > 1 ? 's' : '');
|
||||
} else {
|
||||
_s += 'no new messages';
|
||||
}
|
||||
_s += ' (<b>' + Base.Util.formatNumber(a) + '</b> total)';
|
||||
} else {
|
||||
_s += 'no messages';
|
||||
}
|
||||
return _s;
|
||||
},
|
||||
|
||||
switchCustom: function () {
|
||||
this.dCustom = !this.dCustom;
|
||||
this.game.draw();
|
||||
}
|
||||
|
||||
});
|
86
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Planets.js
Normal file
86
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Planets.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
LWWidget.Beta5.Planets = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Empire')[0].getChildren('Planets')[0];
|
||||
|
||||
this.planets = parseInt(_d.getAttribute('count'), 10);
|
||||
this.pList = new Array();
|
||||
if (this.planets) {
|
||||
// Planets under attack
|
||||
this.underAttack = parseInt(_d.getAttribute('siege'), 10);
|
||||
// Happiness / Corruption
|
||||
this.avgHappiness = parseInt(_d.getAttribute('avgHap'), 10);
|
||||
this.avgCorruption = parseInt(_d.getAttribute('avgCor'), 10);
|
||||
// Population
|
||||
this.totPopulation = parseInt(_d.getAttribute('totPop'), 10);
|
||||
this.avgPopulation = parseInt(_d.getAttribute('avgPop'), 10);
|
||||
// Factories
|
||||
this.totFactories = parseInt(_d.getAttribute('totFac'), 10);
|
||||
this.avgFactories = parseInt(_d.getAttribute('avgFac'), 10);
|
||||
// Factories
|
||||
this.totTurrets = parseInt(_d.getAttribute('totTur'), 10);
|
||||
this.avgTurrets = parseInt(_d.getAttribute('avgTur'), 10);
|
||||
|
||||
// Planet list
|
||||
var _l = _d.getChildren('List')[0].getChildren('Planet');
|
||||
for (var i in _l) {
|
||||
this.pList.push(_l[i].getText());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show: function () {
|
||||
this.mode = 0;
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
_e.innerHTML = (this.mode == 0 || !this.planets) ? this.getStats() : this.getList();
|
||||
},
|
||||
|
||||
setMode: function (m) {
|
||||
this.mode = m;
|
||||
if (this.game) {
|
||||
this.game.draw();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getStats: function () {
|
||||
if (this.planets == 0) {
|
||||
return '<p style="text-align:center">No planets.</p>';
|
||||
}
|
||||
|
||||
var _s = '<p style="text-align:center"><b>' + Base.Util.formatNumber(this.planets) + '</b> planet'
|
||||
+ (this.planets > 1 ? 's' : '') + '<br/>';
|
||||
if (this.underAttack) {
|
||||
_s += '<b>' + Base.Util.formatNumber(this.underAttack) + ' planet'
|
||||
+ (this.underAttack > 1 ? 's' : '') + ' under attack!</b>';
|
||||
} else {
|
||||
_s += 'No planets under attack';
|
||||
}
|
||||
|
||||
_s += '<br/><br/>Average happiness: <b>' + this.avgHappiness + '%</b><br/>Average corruption: <b>'
|
||||
+ this.avgCorruption + '%</b><br/>Population: <b>' + Base.Util.formatNumber(this.totPopulation) + '</b>';
|
||||
if (this.planets > 1) {
|
||||
_s += ' (<b>' + Base.Util.formatNumber(this.avgPopulation) + '</b> on average)';
|
||||
}
|
||||
_s += '<br/>Factories: <b>' + Base.Util.formatNumber(this.totFactories) + '</b>';
|
||||
if (this.planets > 1) {
|
||||
_s += ' (<b>' + Base.Util.formatNumber(this.avgFactories) + '</b> on average)';
|
||||
}
|
||||
_s += '<br/>Turrets: <b>' + Base.Util.formatNumber(this.totTurrets) + '</b>';
|
||||
if (this.planets > 1) {
|
||||
_s += ' (<b>' + Base.Util.formatNumber(this.avgTurrets) + '</b> on average)';
|
||||
}
|
||||
_s += '<br/><br/><a href="#" onclick="Base.Comp.get(' + this._cid + ').setMode(1);return false">View list</a></p>';
|
||||
|
||||
return _s;
|
||||
},
|
||||
|
||||
getList: function () {
|
||||
return '<p style="text-align:center"><a href="#" onclick="Base.Comp.get(' + this._cid
|
||||
+ ').setMode(0);return false"><<- Back</a><br/><br/><b>'
|
||||
+ this.pList.join('</b><br/><b>') + '</b></p>';
|
||||
}
|
||||
|
||||
});
|
82
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Player.js
Normal file
82
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Player.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
LWWidget.Beta5.Player = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Player')[0];
|
||||
|
||||
// Player name and cash
|
||||
this.playerName = _d.getAttribute('name');
|
||||
this.cash = _d.getAttribute('cash');
|
||||
|
||||
// Alliance status
|
||||
var _a = _d.getChildren('Alliance');
|
||||
if (_a.length) {
|
||||
_a = _a[0];
|
||||
this.alliance = { joined: (_a.getAttribute('inalliance') == '1'), tag: _a.getAttribute('tag') };
|
||||
} else {
|
||||
this.alliance = null;
|
||||
}
|
||||
|
||||
// General rankings
|
||||
_a = _d.getChildren('Rankings')[0];
|
||||
var _r = _a.getChildren('Ranking');
|
||||
for (var i in _r) {
|
||||
if (_r[i].getText() != 'General Ranking') {
|
||||
continue;
|
||||
}
|
||||
this.points = _r[i].getAttribute('points');
|
||||
this.rank = _r[i].getAttribute('rank');
|
||||
break;
|
||||
}
|
||||
|
||||
// Planets / planets under attack
|
||||
_d = data.getChildren('Empire')[0].getChildren('Planets')[0];
|
||||
this.planets = parseInt(_d.getAttribute('count'), 10);
|
||||
this.underAttack = parseInt(_d.getAttribute('siege'), 10);
|
||||
|
||||
// Fleets / fleets in battle
|
||||
_d = data.getChildren('Empire')[0].getChildren('Fleets')[0];
|
||||
this.fleets = parseInt(_d.getAttribute('count'), 10);
|
||||
this.inBattle = parseInt(_d.getAttribute('inBattle'), 10);
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
if (!this.playerName) {
|
||||
return;
|
||||
}
|
||||
|
||||
var str = '<p style="text-align:center">Player <b>' + this.playerName + '</b>';
|
||||
if (this.alliance && this.alliance.joined) {
|
||||
str += ' [<b>' + this.alliance.tag + '</b>]';
|
||||
} else if (this.alliance && !this.alliance.joined) {
|
||||
str += '<br/>Requesting to join alliance [<b>' + this.alliance.tag + '</b>]';
|
||||
}
|
||||
|
||||
str += '<br/><br/>Cash: <b>€' + Base.Util.formatNumber(this.cash) + '</b>'
|
||||
+ '<br/>General ranking: <b>#' + Base.Util.formatNumber(this.rank) + '</b> (<b>'
|
||||
+ Base.Util.formatNumber(this.points) + '</b> points)<br/><br/>';
|
||||
|
||||
if (this.planets == 0) {
|
||||
str += "No planets";
|
||||
} else {
|
||||
str += '<b>' + Base.Util.formatNumber(this.planets) + '</b> planet' + (this.planets > 1 ? 's' : '');
|
||||
if (this.underAttack > 0) {
|
||||
str += ' (<b>' + Base.Util.formatNumber(this.underAttack) + '</b> under attack!)';
|
||||
}
|
||||
}
|
||||
str += '<br/>';
|
||||
|
||||
if (this.fleets == 0) {
|
||||
str += "No fleets";
|
||||
} else {
|
||||
str += '<b>' + Base.Util.formatNumber(this.fleets) + '</b> fleet' + (this.fleets > 1 ? 's' : '');
|
||||
if (this.inBattle > 0) {
|
||||
str += ' (<b>' + Base.Util.formatNumber(this.inBattle) + '</b> in battle)';
|
||||
}
|
||||
}
|
||||
|
||||
str += '</p>';
|
||||
|
||||
_e.innerHTML = str;
|
||||
}
|
||||
|
||||
});
|
37
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Techs.js
Normal file
37
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Techs.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
LWWidget.Beta5.Techs = LWWidget.Game.Page.inherits({
|
||||
|
||||
setData: function (data) {
|
||||
var _d = data.getChildren('Empire')[0].getChildren('Research')[0];
|
||||
|
||||
this.points = parseInt(_d.getAttribute('points'), 10);
|
||||
this.newTechs = parseInt(_d.getAttribute('new'), 10);
|
||||
this.foreseen = parseInt(_d.getAttribute('foreseen'), 10);
|
||||
|
||||
_d = _d.getChildren('RBudget')[0];
|
||||
this.fundamental = parseInt(_d.getAttribute('fundamental'), 10);
|
||||
this.military = parseInt(_d.getAttribute('military'), 10);
|
||||
this.civilian = parseInt(_d.getAttribute('civilian'), 10);
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
var _s = '<p style="text-align:center">';
|
||||
if (this.newTechs == 0) {
|
||||
_s += 'No new technologies discovered.';
|
||||
} else {
|
||||
_s += '<b>' + this.newTechs + '</b> new technolog' + (this.newTechs > 1 ? 'ies' : 'y') + ' discovered.';
|
||||
}
|
||||
_s += '<br/>';
|
||||
if (this.foreseen == 0) {
|
||||
_s += 'No breakthroughs foreseen.';
|
||||
} else {
|
||||
_s += '<b>' + this.foreseen + '</b> breakthrough' + (this.foreseen > 1 ? 's' : '') + ' foreseen.';
|
||||
}
|
||||
_s += '<br/><br/><u>Research budget</u><br/><br/><b>' + Base.Util.formatNumber(this.points) + '</b> research points per day<br/><b>'
|
||||
+ this.fundamental + '%</b> allocated to Fundamental research<br/><b>'
|
||||
+ this.military + '%</b> allocated to Military research<br/><b>'
|
||||
+ this.civilian + '%</b> allocated to Civilian research</p>';
|
||||
|
||||
_e.innerHTML = _s;
|
||||
}
|
||||
|
||||
});
|
121
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Ticks.js
Normal file
121
misc/Legacy Worlds.wdgt/lib/LWWidget/Beta5/Ticks.js
Normal file
|
@ -0,0 +1,121 @@
|
|||
LWWidget.Beta5.Ticks = LWWidget.Game.Page.inherits({
|
||||
|
||||
constructor: function (game) {
|
||||
this.base(game);
|
||||
|
||||
this.addSlot('update');
|
||||
this.timer = new Base.Timer(1000, true);
|
||||
this.timer.bindEvent('Tick', 'update', this);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.timer.destroy();
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
setData: function (data) {
|
||||
var tList = data.getChildren('Ticks')[0].getChildren('Tick'), ticks = new Array();
|
||||
|
||||
for (var i in tList) {
|
||||
var tick = new Array();
|
||||
tick[0] = tList[i].getText();
|
||||
tick[1] = parseInt(tList[i].getAttribute('first'), 10);
|
||||
tick[2] = parseInt(tList[i].getAttribute('interval'), 10);
|
||||
|
||||
var l = tList[i].getAttribute('last');
|
||||
if (typeof l == 'string') {
|
||||
tick[3] = parseInt(l, 10);
|
||||
} else {
|
||||
tick[3] = null;
|
||||
}
|
||||
|
||||
ticks.push(tick);
|
||||
}
|
||||
|
||||
this.tDiff = (new Date()).getTime() - (parseInt(data.getAttribute('serverTime'), 10) * 1000);
|
||||
this.ticks = ticks;
|
||||
},
|
||||
|
||||
|
||||
show: function () {
|
||||
this.timer.start();
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.timer.stop();
|
||||
},
|
||||
|
||||
|
||||
draw: function (_e) {
|
||||
var text = new Array();
|
||||
|
||||
for (var i in this.ticks) {
|
||||
text.push('Next ' + this.ticks[i][0] + ': <span id="dtick' + i + '"> </span>');
|
||||
}
|
||||
|
||||
_e.innerHTML = '<p style="text-align:center">' + text.join('<br/>') + '</p>';
|
||||
this.update();
|
||||
},
|
||||
|
||||
|
||||
update: function () {
|
||||
this.computeNextTicks();
|
||||
|
||||
for (var i in this.ticks) {
|
||||
var t;
|
||||
|
||||
if (typeof this.ticks[i][5] == 'number') {
|
||||
var d, h, m, s;
|
||||
|
||||
h = this.ticks[i][5] % 86400; d = (this.ticks[i][5] - h) / 86400;
|
||||
m = h % 3600; h = (h - m) / 3600;
|
||||
s = m % 60; m = (m - s) / 60;
|
||||
|
||||
if (h < 10) { h = '0' + h; }
|
||||
if (m < 10) { m = '0' + m; }
|
||||
if (s < 10) { s = '0' + s; }
|
||||
|
||||
t = '<b>' + h + ':' + m + ':' + s + '</b>';
|
||||
if (d > 0) {
|
||||
t = '<b>' + d + '</b> day' + (d > 1 ? 's' : '') + ', ' + t;
|
||||
}
|
||||
} else {
|
||||
t = 'never';
|
||||
}
|
||||
|
||||
var e = document.getElementById('dtick' + i);
|
||||
if (!e) {
|
||||
break;
|
||||
}
|
||||
e.innerHTML = t;
|
||||
}
|
||||
},
|
||||
|
||||
computeNextTicks: function () {
|
||||
var now = Math.round(((new Date()).getTime() - this.tDiff) / 1000);
|
||||
for (var i in this.ticks) {
|
||||
if (this.ticks[i][3] && now > this.ticks[i][3]) {
|
||||
this.ticks[i][4] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now <= this.ticks[i][1]) {
|
||||
this.ticks[i][4] = this.ticks[i][1];
|
||||
continue;
|
||||
}
|
||||
|
||||
var d = now - this.ticks[i][1], m = (d - (d % this.ticks[i][2])) / this.ticks[i][2];
|
||||
this.ticks[i][4] = this.ticks[i][1] + (m + 1) * this.ticks[i][2];
|
||||
}
|
||||
|
||||
for (var i in this.ticks) {
|
||||
if (typeof this.ticks[i][4] != 'number') {
|
||||
this.ticks[i][5] = null;
|
||||
} else {
|
||||
this.ticks[i][5] = this.ticks[i][4] - now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
25
misc/Legacy Worlds.wdgt/lib/LWWidget/Data.js
Normal file
25
misc/Legacy Worlds.wdgt/lib/LWWidget/Data.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
LWWidget.Data = Base.inherits({
|
||||
|
||||
constructor: function (name) {
|
||||
this.base();
|
||||
this.name = name;
|
||||
this.attributes = new Base.Util.Hashtable();
|
||||
},
|
||||
|
||||
setAttribute: function (name, value) {
|
||||
this.attributes.put(name, value);
|
||||
},
|
||||
|
||||
getAttribute: function (name) {
|
||||
return (this.attributes.containsKey(name) ? this.attributes.get(name) : null);
|
||||
},
|
||||
|
||||
getChildren: function (name) {
|
||||
return new Array();
|
||||
},
|
||||
|
||||
getText: function () {
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
12
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Leaf.js
Normal file
12
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Leaf.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
LWWidget.Data.Leaf = LWWidget.Data.inherits({
|
||||
|
||||
constructor: function (name, text) {
|
||||
this.base(name);
|
||||
this.text = text;
|
||||
},
|
||||
|
||||
getText: function () {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
});
|
130
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Loader.js
Normal file
130
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Loader.js
Normal file
|
@ -0,0 +1,130 @@
|
|||
LWWidget.Data.Loader = Base.Comp.inherits({
|
||||
|
||||
constructor: function (login, password) {
|
||||
this.base();
|
||||
|
||||
this.addEvent('CommError');
|
||||
this.addEvent('FatalError');
|
||||
this.addEvent('Kick');
|
||||
this.addEvent('Load');
|
||||
this.addEvent('LoginFailure');
|
||||
this.addEvent('Maintenance');
|
||||
|
||||
this.addSlot('loaderDestroyed');
|
||||
this.addSlot('dataReceived');
|
||||
|
||||
this.loader = new Base.XMLLoader('', true);
|
||||
this.loader.bindEvent('Destroy', 'loaderDestroyed', this);
|
||||
this.loader.bindEvent('NetworkError', 'onCommError', this);
|
||||
this.loader.bindEvent('ServerError', 'onCommError', this);
|
||||
this.loader.bindEvent('Timeout', 'onCommError', this);
|
||||
this.loader.bindEvent('Unsupported', 'onCommError', this);
|
||||
this.loader.bindEvent('Aborted', 'onCommError', this);
|
||||
this.loader.bindEvent('Loaded', 'dataReceived', this);
|
||||
|
||||
this.params = new Base.Util.Hashtable();
|
||||
this.params.put('__s', '1');
|
||||
this.params.put('__l', login);
|
||||
this.params.put('__p', password);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
if (this.loader) {
|
||||
this.loader.destroy();
|
||||
}
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
load: function (from) {
|
||||
if (this.loader.isLoading) {
|
||||
return false;
|
||||
}
|
||||
this.loader.changeParameters(LWWidget.base + '/index.php/' + from + '.xml');
|
||||
this.loader.load(this.params);
|
||||
},
|
||||
|
||||
|
||||
loaderDestroyed: function () {
|
||||
this.loader = null;
|
||||
},
|
||||
|
||||
|
||||
dataReceived: function (data) {
|
||||
var _xml = Base.Util.parseXML(data);
|
||||
if (!_xml) {
|
||||
this.onCommError();
|
||||
return;
|
||||
}
|
||||
|
||||
var _doc = _xml.documentElement;
|
||||
if (_doc.nodeName == 'Maintenance') {
|
||||
var _r, _u, _c;
|
||||
_r = LWWidget.Data.Loader.getXMLText(_doc, 'Reason');
|
||||
_u = LWWidget.Data.Loader.getXMLText(_doc, 'Until');
|
||||
_c = LWWidget.Data.Loader.getXMLText(_doc, 'Current');
|
||||
this.onMaintenance(_r, _u, _c);
|
||||
} else if (_doc.nodeName == 'FatalError') {
|
||||
this.onFatalError(_doc.getAttribute('code'), LWWidget.Data.Loader.getXMLText(_doc, 'Text'));
|
||||
} else if (_doc.nodeName == 'Kicked') {
|
||||
this.onKick(LWWidget.Data.Loader.getXMLText(_doc, 'Reason'));
|
||||
} else if (_doc.nodeName == 'Failed') {
|
||||
this.onLoginFailure(_doc.getAttribute('code'));
|
||||
} else {
|
||||
var _data = LWWidget.Data.Loader.parse(_doc);
|
||||
if (_data) {
|
||||
this.onLoad(_data);
|
||||
} else {
|
||||
this.onCommError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, {
|
||||
|
||||
getXMLText: function (node, name) {
|
||||
var _t = '';
|
||||
for (var i=0;i<node.childNodes.length;i++) {
|
||||
var _c = node.childNodes[i];
|
||||
if (_c.nodeType == 1 && _c.nodeName == name) {
|
||||
_t += _c.childNodes[0].nodeValue;
|
||||
}
|
||||
}
|
||||
return _t;
|
||||
},
|
||||
|
||||
parse: function (xmlNode) {
|
||||
if (xmlNode.nodeType != 1 || xmlNode.nodeName != 'Node') {
|
||||
return null;
|
||||
}
|
||||
|
||||
var _in = (xmlNode.getAttribute('node') == '1'), _n;
|
||||
if (_in) {
|
||||
_n = new LWWidget.Data.Node(xmlNode.getAttribute('name'));
|
||||
} else {
|
||||
_n = new LWWidget.Data.Leaf(xmlNode.getAttribute('name'), LWWidget.Data.Loader.getXMLText(xmlNode, 'Text'));
|
||||
}
|
||||
|
||||
for (var i=0;i<xmlNode.childNodes.length;i++) {
|
||||
var _c = xmlNode.childNodes[i];
|
||||
if (_c.nodeType != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_c.nodeName == 'Attr') {
|
||||
var _t;
|
||||
if (_c.childNodes.length) {
|
||||
_t = _c.childNodes[0].nodeValue;
|
||||
} else {
|
||||
_t = '';
|
||||
}
|
||||
_n.setAttribute(_c.getAttribute('name'), _t);
|
||||
} else if (_c.nodeName == 'Node' && _in) {
|
||||
_n.addChild(this.parse(_c));
|
||||
}
|
||||
}
|
||||
|
||||
return _n;
|
||||
}
|
||||
|
||||
});
|
25
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Node.js
Normal file
25
misc/Legacy Worlds.wdgt/lib/LWWidget/Data/Node.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
LWWidget.Data.Node = LWWidget.Data.inherits({
|
||||
|
||||
constructor: function (name) {
|
||||
this.base(name);
|
||||
this.contents = new Array();
|
||||
},
|
||||
|
||||
addChild: function (child) {
|
||||
if (child instanceof LWWidget.Data.Node || child instanceof LWWidget.Data.Leaf) {
|
||||
this.contents.push(child);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getChildren: function (name) {
|
||||
var _c = new Array();
|
||||
for (var i in this.contents) {
|
||||
if (this.contents[i] && this.contents[i].name == name) {
|
||||
_c.push(this.contents[i]);
|
||||
}
|
||||
}
|
||||
return _c;
|
||||
}
|
||||
|
||||
});
|
67
misc/Legacy Worlds.wdgt/lib/LWWidget/Debug.js
Normal file
67
misc/Legacy Worlds.wdgt/lib/LWWidget/Debug.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
LWWidget.Debug = Base.Comp.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
this.addSlot('drawLog');
|
||||
|
||||
this.timer = new Base.Timer(1000, true);
|
||||
this.timer.bindEvent('Tick', 'drawLog', this);
|
||||
},
|
||||
|
||||
show: function () {
|
||||
document.getElementById('debugLink').style.display = 'none';
|
||||
document.getElementById('mainDiv').style.display = 'none';
|
||||
this.lastLength = -1;
|
||||
this.draw();
|
||||
document.getElementById('debugDiv').style.display = 'block';
|
||||
this.timer.start();
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.timer.stop();
|
||||
document.getElementById('debugDiv').style.display = 'none';
|
||||
document.getElementById('debugLink').style.display = 'block';
|
||||
document.getElementById('mainDiv').style.display = 'block';
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
var _str = '<table id="debugTable"><tr id="dbgHdr"><td><b>Debug mode</b></td>'
|
||||
+ '<td style="text-align:right"><a href="#" onclick="Base.Comp.get('
|
||||
+ this._cid + ').clear()">Flush log</a> - <a href="#" onclick="Base.Comp.get('
|
||||
+ this._cid + ').hide()">Hide</a></td></tr>'
|
||||
+ '<tr><td colspan="2"><div style="overflow:auto;height:260px;width:296px;color:white" id="dbgContents"> </div></td></tr></table>';
|
||||
document.getElementById('debugDiv').innerHTML = _str;
|
||||
this.drawLog();
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
Base.Log.flush();
|
||||
this.drawLog();
|
||||
},
|
||||
|
||||
drawLog: function () {
|
||||
var _e = document.getElementById('dbgContents');
|
||||
if (!_e) {
|
||||
return;
|
||||
}
|
||||
|
||||
var _l = Base.Log.get();
|
||||
if (_l.length == this.lastLength) {
|
||||
return;
|
||||
}
|
||||
this.lastLength = _l.length;
|
||||
|
||||
var _s;
|
||||
if (_l.length == 0) {
|
||||
_s = '<p style="text-align:center">The log is empty</p>';
|
||||
} else {
|
||||
_s = '<p>';
|
||||
for (var i=_l.length;i>0;i--) {
|
||||
_s += '[' + i + '] ' + _l[i-1] + '<br/>';
|
||||
}
|
||||
_s += '</p>';
|
||||
}
|
||||
_e.innerHTML = _s;
|
||||
}
|
||||
|
||||
});
|
168
misc/Legacy Worlds.wdgt/lib/LWWidget/Game.js
Normal file
168
misc/Legacy Worlds.wdgt/lib/LWWidget/Game.js
Normal file
|
@ -0,0 +1,168 @@
|
|||
LWWidget.Game = Base.Comp.inherits({
|
||||
|
||||
constructor: function (path) {
|
||||
this.base();
|
||||
this.path = path;
|
||||
|
||||
this.addEvent('RequestUpdate');
|
||||
this.addSlot('startDataUpdate');
|
||||
|
||||
this.pageElement = 'gDisplay';
|
||||
|
||||
this.autoUpdate = new Base.Timer(30000, true);
|
||||
this.autoUpdate.bindEvent('Tick', 'startDataUpdate', this);
|
||||
this.autoUpdate.start();
|
||||
|
||||
this.pages = [null, null, null, null, null, null, null, null];
|
||||
this.page = null;
|
||||
this.data = null;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.autoUpdate.destroy();
|
||||
if (this.page) {
|
||||
this.page.hide();
|
||||
this.page = null;
|
||||
}
|
||||
for (var i in this.pages) {
|
||||
if (this.pages[i]) {
|
||||
var _p = this.pages[i];
|
||||
this.pages[i] = null;
|
||||
_p.destroy();
|
||||
}
|
||||
}
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
startDataUpdate: function () {
|
||||
this.onRequestUpdate(this.path);
|
||||
},
|
||||
|
||||
setData: function (data) {
|
||||
this.data = data;
|
||||
for (var i in this.pages) {
|
||||
if (this.pages[i]) {
|
||||
this.pages[i].setData(data);
|
||||
}
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
|
||||
setPage: function (pName) {
|
||||
// Check for a valid page name
|
||||
if (!LWWidget.Game.pageMap().containsKey(pName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if something was changed
|
||||
var _p = this.pages[LWWidget.Game.pageMap().get(pName)];
|
||||
if (_p && this.page && _p._cid == this.page._cid || !(_p || this.page)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide current page and show new page
|
||||
if (this.page) {
|
||||
this.page.hide();
|
||||
}
|
||||
this.page = _p;
|
||||
if (_p) {
|
||||
this.page.show();
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
var _e = document.getElementById(this.pageElement);
|
||||
if (_e) {
|
||||
if (this.page) {
|
||||
this.page.draw(_e);
|
||||
} else {
|
||||
_e.innerHTML = '<p style="text-align:center">Page not implemented</p>';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show: function () {
|
||||
this.startDataUpdate();
|
||||
this.autoUpdate.start();
|
||||
if (this.page) {
|
||||
this.page.show();
|
||||
}
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.autoUpdate.stop();
|
||||
if (this.page) {
|
||||
this.page.hide();
|
||||
}
|
||||
}
|
||||
|
||||
}, {
|
||||
|
||||
pageMapInst: null,
|
||||
|
||||
versionsInst: null,
|
||||
|
||||
pageMap: function () {
|
||||
if (!LWWidget.Game.pageMapInst) {
|
||||
var _h = new Base.Util.Hashtable();
|
||||
_h.put('player', 0);
|
||||
_h.put('planets', 1);
|
||||
_h.put('fleets', 2);
|
||||
_h.put('budget', 3);
|
||||
_h.put('tech', 4);
|
||||
_h.put('msg', 5);
|
||||
_h.put('forums', 6);
|
||||
_h.put('ticks', 7);
|
||||
LWWidget.Game.pageMapInst = _h;
|
||||
}
|
||||
return LWWidget.Game.pageMapInst;
|
||||
},
|
||||
|
||||
versions: function () {
|
||||
if (!LWWidget.Game.versionsInst) {
|
||||
LWWidget.Game.versionsInst = new Base.Util.Hashtable();
|
||||
}
|
||||
return LWWidget.Game.versionsInst;
|
||||
},
|
||||
|
||||
formatTime: function (ts) {
|
||||
var d = new Date(ts * 1000);
|
||||
var str, s2;
|
||||
|
||||
s2 = d.getUTCHours().toString();
|
||||
if (s2.length == 1) {
|
||||
s2 = "0" + s2;
|
||||
}
|
||||
str = s2 + ':';
|
||||
|
||||
s2 = d.getUTCMinutes().toString();
|
||||
if (s2.length == 1) {
|
||||
s2 = "0" + s2;
|
||||
}
|
||||
str += s2 + ':';
|
||||
|
||||
s2 = d.getUTCSeconds().toString();
|
||||
if (s2.length == 1) {
|
||||
s2 = "0" + s2;
|
||||
}
|
||||
str += s2 + ' on ';
|
||||
|
||||
s2 = d.getUTCDate().toString();
|
||||
if (s2.length == 1) {
|
||||
s2 = "0" + s2;
|
||||
}
|
||||
str += s2 + '/';
|
||||
|
||||
s2 = (d.getUTCMonth() + 1).toString();
|
||||
if (s2.length == 1) {
|
||||
s2 = "0" + s2;
|
||||
}
|
||||
str += s2 + '/' + d.getUTCFullYear();
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
});
|
34
misc/Legacy Worlds.wdgt/lib/LWWidget/Game/Page.js
Normal file
34
misc/Legacy Worlds.wdgt/lib/LWWidget/Game/Page.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
LWWidget.Game.Page = Base.Comp.inherits({
|
||||
|
||||
constructor: function (game) {
|
||||
this.base();
|
||||
|
||||
this.addSlot('gameDestroyed');
|
||||
this.game = game;
|
||||
this.game.bindEvent('Destroy', 'gameDestroyed', this);
|
||||
},
|
||||
|
||||
writeContents: function (contents) {
|
||||
var e = document.getElementById('gDisplay');
|
||||
if (e) {
|
||||
e.innerHTML = contents;
|
||||
}
|
||||
},
|
||||
|
||||
gameDestroyed: function () {
|
||||
this.game = null;
|
||||
},
|
||||
|
||||
setData: function (data) {
|
||||
},
|
||||
|
||||
draw: function (_e) {
|
||||
},
|
||||
|
||||
show: function () {
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
}
|
||||
|
||||
});
|
73
misc/Legacy Worlds.wdgt/lib/LWWidget/GameDisplay.js
Normal file
73
misc/Legacy Worlds.wdgt/lib/LWWidget/GameDisplay.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
LWWidget.GameDisplay = LWWidget.Page.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
|
||||
this.addSlot('gameDestroyed');
|
||||
this.addEvent('Refresh');
|
||||
|
||||
this.gPath = '';
|
||||
this.game = null;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
if (this.game) {
|
||||
this.game.destroy();
|
||||
}
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
setGame: function (gClass, gPath) {
|
||||
if (this.game) {
|
||||
this.game.destroy();
|
||||
}
|
||||
this.game = new gClass(gPath);
|
||||
this.game.bindEvent('Destroy', 'gameDestroyed', this);
|
||||
this.game.bindEvent('RequestUpdate', 'onRefresh', this);
|
||||
},
|
||||
|
||||
gameDestroyed: function () {
|
||||
this.game = null;
|
||||
},
|
||||
|
||||
|
||||
handleData: function (data) {
|
||||
if (this.game) {
|
||||
this.game.setData(data);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
hide: function () {
|
||||
if (this.game) {
|
||||
this.game.hide();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
show: function () {
|
||||
if (this.game) {
|
||||
this.game.show();
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
|
||||
setPage: function (pName) {
|
||||
if (this.game) {
|
||||
this.game.setPage(pName);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
if (!document.getElementById('gDisplay')) {
|
||||
this.writeContents('<div id="gDisplay" style="overflow:auto;width:100%;height:100%"> </div>');
|
||||
}
|
||||
if (this.game) {
|
||||
this.game.draw();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
65
misc/Legacy Worlds.wdgt/lib/LWWidget/GameSelector.js
Normal file
65
misc/Legacy Worlds.wdgt/lib/LWWidget/GameSelector.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
LWWidget.GameSelector = LWWidget.Page.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
this.games = [];
|
||||
|
||||
this.addEvent('Select');
|
||||
},
|
||||
|
||||
|
||||
setGames: function (games) {
|
||||
if (games instanceof Array) {
|
||||
this.games = games;
|
||||
this.draw();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
var cc = '"return Base.Comp.get(' + this._cid + ').select()"',
|
||||
st = ' style="color:white;font-size:13px;background-color:#3f7fff;width:100%" ',
|
||||
st2 = ' style="color:white;font-size:13px;background-color:#3f7fff" ',
|
||||
str = '<form name="gsel" onsubmit=' + cc + '><table class="table">'
|
||||
+ '<tr><td colspan="2" style="text-align:center"><b>Game selection</b></td></tr>'
|
||||
+ '<tr><td colspan="2"> </td></tr>'
|
||||
+ '<tr><td><label for="gsel">Game:</label></td>'
|
||||
+ '<td><select name="gsel" id="gsel"' + st;
|
||||
|
||||
for (var i in this.games) {
|
||||
var g = this.games[i];
|
||||
str += '<option value="' + i + '">' + g.name + '</option>';
|
||||
}
|
||||
|
||||
str += '</select></td></tr><tr><td style="text-align:right">'
|
||||
+ '<input type="checkbox" name="grem" id="grem"' + st2 + '/></td>'
|
||||
+ '<td><label for="grem">Remember selection</label></td></tr>'
|
||||
+ '<tr><td colspan="2"> </td></tr>'
|
||||
+ '<tr><td colspan="2"><input type="submit" value="Select this game"'
|
||||
+ st + '</td></tr></table></form>';
|
||||
this.writeContents(str);
|
||||
|
||||
var _cb = document.getElementById('grem');
|
||||
if (_cb) {
|
||||
_cb.checked = (LWWidget.main.getPreference('lwRemGame') == '1');
|
||||
}
|
||||
},
|
||||
|
||||
select: function () {
|
||||
var _s = document.getElementById('gsel');
|
||||
if (!_s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sv = parseInt(_s.options[_s.selectedIndex].value, 10), rem = document.getElementById('grem').checked;
|
||||
LWWidget.main.setPreference('lwRemGame', rem ? '1' : '0');
|
||||
if (rem) {
|
||||
LWWidget.main.setPreference('lwGame', this.games[sv].path);
|
||||
}
|
||||
|
||||
this.onSelect(this.games[sv]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
77
misc/Legacy Worlds.wdgt/lib/LWWidget/Login.js
Normal file
77
misc/Legacy Worlds.wdgt/lib/LWWidget/Login.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
LWWidget.Login = LWWidget.Page.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
this.addEvent('Login');
|
||||
this.error = "";
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
var cc = '"return Base.Comp.get(' + this._cid + ').login()"',
|
||||
st = ' style="color:white;font-size:13px;background-color:#3f7fff;width:100%" ',
|
||||
st2 = ' style="color:white;font-size:13px;background-color:#3f7fff" ',
|
||||
str = '<form name="login" onsubmit=' + cc + '><table class="table">'
|
||||
+ '<tr><td><label for="lname">Username:</label></td><td>'
|
||||
+ '<input type="text" name="lname" id="lname" value=""'
|
||||
+ st + '/></td></tr>'
|
||||
+ '<tr><td><label for="lpass">Password:</label></td><td>'
|
||||
+ '<input type="password" name="lpass" id="lpass" value=""'
|
||||
+ st + '/></td></tr>'
|
||||
+ '<tr><td style="text-align:right"><input type="checkbox" '
|
||||
+ ' name="lrem" id="lrem"' + st2 + '/></td><td>'
|
||||
+ '<label for="lrem">Remember password</label></td></tr>'
|
||||
+ '<tr><td colspan="2"> </td></tr>'
|
||||
+ '<tr><td colspan="2" style="text-align:center" id="lerror"> </td></tr>'
|
||||
+ '<tr><td colspan="2"> </td></tr>'
|
||||
+ '<tr><td colspan="2"><input type="submit" value="Connect to Legacy Worlds!"'
|
||||
+ st + '</td></tr></table></form>';
|
||||
this.writeContents(str);
|
||||
this.fillForm();
|
||||
},
|
||||
|
||||
fillForm: function () {
|
||||
var l = LWWidget.main.getPreference('lwLogin'), p = LWWidget.main.getPreference('lwPassword'), r = LWWidget.main.getPreference('lwRemAuth');
|
||||
if (!document.getElementById('lname')) {
|
||||
return;
|
||||
}
|
||||
document.getElementById('lname').value = l;
|
||||
document.getElementById('lpass').value = p;
|
||||
document.getElementById('lrem').checked = (r == '1');
|
||||
document.getElementById("lerror").innerHTML = (this.error == "") ? ' ' : this.error;
|
||||
},
|
||||
|
||||
|
||||
setError: function (error) {
|
||||
this.error = error;
|
||||
var e = document.getElementById("lerror");
|
||||
if (e) {
|
||||
e.innerHTML = (error == "") ? ' ' : error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
login: function () {
|
||||
if (!document.getElementById('lname')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var l = document.getElementById('lname').value, p = document.getElementById('lpass').value,
|
||||
r = document.getElementById('lrem').checked ? '1' : '0';
|
||||
|
||||
if (l == '') {
|
||||
this.setError("Please type in your username");
|
||||
} else if (p == '') {
|
||||
this.setError("Please type in your password");
|
||||
} else {
|
||||
// Save the login as a preference and store the rest until we're sure
|
||||
LWWidget.main.setPreference('lwLogin', l);
|
||||
LWWidget.main.setPreference('lwRemAuth', r);
|
||||
LWWidget.main.password = p;
|
||||
|
||||
this.onLogin();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
392
misc/Legacy Worlds.wdgt/lib/LWWidget/Main.js
Normal file
392
misc/Legacy Worlds.wdgt/lib/LWWidget/Main.js
Normal file
|
@ -0,0 +1,392 @@
|
|||
LWWidget.Main = Base.Comp.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
|
||||
this.addEvent('Show');
|
||||
this.addEvent('Hide');
|
||||
this.addSlot('draw');
|
||||
this.bindEvent('Show', 'draw');
|
||||
|
||||
// Game-related slots
|
||||
this.addSlot('login');
|
||||
this.addSlot('loadGame');
|
||||
this.addSlot('loadData');
|
||||
|
||||
// Version management slots
|
||||
this.addSlot('versionError');
|
||||
this.addSlot('versionNewAvailable');
|
||||
this.addSlot('versionNewRequired');
|
||||
this.addSlot('versionOk');
|
||||
|
||||
// Generate the menu
|
||||
this.makeMenu();
|
||||
|
||||
// Version checker
|
||||
this.versionCheck = new LWWidget.VersionCheck();
|
||||
this.versionPage = new LWWidget.NewVersion();
|
||||
this.versionCheck.bindEvent('CommError', 'versionError', this);
|
||||
this.versionCheck.bindEvent('NewVersion', 'versionNewAvailable', this);
|
||||
this.versionCheck.bindEvent('RequiredVersion', 'versionNewRequired', this);
|
||||
this.versionCheck.bindEvent('VersionOk', 'versionOk', this);
|
||||
this.versionChecked = false;
|
||||
|
||||
// Login page
|
||||
this.loginPage = new LWWidget.Login();
|
||||
this.loginPage.bindEvent('Login', 'login', this);
|
||||
|
||||
// Game selection page
|
||||
this.gameSelector = new LWWidget.GameSelector();
|
||||
this.gameSelector.bindEvent('Select', 'loadGame', this);
|
||||
|
||||
// Game display
|
||||
this.gameDisplay = new LWWidget.GameDisplay(this);
|
||||
this.gameDisplay.bindEvent('Refresh', 'loadData', this);
|
||||
|
||||
// Generic text display
|
||||
this.textPage = new LWWidget.TextPage();
|
||||
|
||||
// FIXME: Set Dashboard-specific event handlers
|
||||
// this.initDashboard();
|
||||
|
||||
// FIXME: should use saved password if possible
|
||||
this.page = this.loginPage;
|
||||
this.menu.setMode('out');
|
||||
this.state = 0;
|
||||
|
||||
this.onShow(); // FIXME: use Dashboard events if possible
|
||||
},
|
||||
|
||||
|
||||
initDashboard: function () {
|
||||
if (window.widget) {
|
||||
var _cid = this._cid;
|
||||
widget.onshow = function () {
|
||||
if (Base) {
|
||||
Base.Comp.get(_cid).onShow();
|
||||
}
|
||||
};
|
||||
widget.onhide = function () {
|
||||
if (Base) {
|
||||
Base.Comp.get(_cid).onHide();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
makeMenu: function () {
|
||||
var _m;
|
||||
this.menu = new LWWidget.Menu();
|
||||
this.addSlot('menuCommand');
|
||||
this.menu.bindEvent('Click', 'menuCommand', this);
|
||||
|
||||
// Waiting
|
||||
_m = this.menu.newMode('wait');
|
||||
_m.addItem(new LWWidget.Menu.Text('Loading ... Please wait ...'));
|
||||
|
||||
// New version available
|
||||
_m = this.menu.newMode('nvAvail');
|
||||
_m.addItem(new LWWidget.Menu.Text('New version! '));
|
||||
_m.addItem(new LWWidget.Menu.Command('continue', 'Continue'));
|
||||
_m.addItem(new LWWidget.Menu.Command('logout', 'Log out'));
|
||||
|
||||
// New version required
|
||||
_m = this.menu.newMode('nvReq');
|
||||
_m.addItem(new LWWidget.Menu.Text('Update required '));
|
||||
_m.addItem(new LWWidget.Menu.Command('logout', 'Log out'));
|
||||
|
||||
// Logged out user
|
||||
_m = this.menu.newMode('out');
|
||||
_m.addItem(new LWWidget.Menu.Text('Please log in'));
|
||||
|
||||
// Game selection
|
||||
_m = this.menu.newMode('game');
|
||||
_m.addItem(new LWWidget.Menu.Entry('gamesel', 'Game selection'));
|
||||
_m.addItem(new LWWidget.Menu.Command('logout', 'Log out'));
|
||||
|
||||
// Error
|
||||
_m = this.menu.newMode('error');
|
||||
_m.addItem(new LWWidget.Menu.Text('Error! - '));
|
||||
_m.addItem(new LWWidget.Menu.Command('logout', 'Log out'));
|
||||
|
||||
// Standard
|
||||
_m = this.menu.newMode('std');
|
||||
_m.addItem(new LWWidget.Menu.Command('gamesel', 'Game selection'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('player', 'Player'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('planets', 'Planets'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('fleets', 'Fleets'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('budget', 'Budget'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('tech', 'Research'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('msg', 'Messages'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('forums', 'Forums'));
|
||||
_m.addItem(new LWWidget.Menu.Entry('ticks', 'Ticks'));
|
||||
_m.addItem(new LWWidget.Menu.Command('logout', 'Log out'));
|
||||
},
|
||||
|
||||
|
||||
initLoader: function (login, password) {
|
||||
this.loader = new LWWidget.Data.Loader(LWWidget.main.getPreference('lwLogin'), LWWidget.main.password);
|
||||
|
||||
var events = ['CommError', 'FatalError', 'Kick', 'Load', 'LoginFailure', 'Maintenance', 'Destroy'];
|
||||
var slots = ['commError', 'serverError', 'playerKicked', 'dataLoaded', 'loginFailed', 'serverMaintenance', 'loaderDestroyed'];
|
||||
for (var i=0;i<events.length;i++) {
|
||||
this.addSlot(slots[i]);
|
||||
this.loader.bindEvent(events[i], slots[i], this);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
var c = LWWidget.main.getPreference('lwColour');
|
||||
var str = '<img src="images/' + c + '.png" />'
|
||||
+ '<div id="mainDiv"><table id="mainTable">'
|
||||
+ '<tr><td id="mtTitle">Legacy Worlds</td></tr>'
|
||||
+ '<tr><td id="mtMenu"> </td></tr>'
|
||||
+ '<tr><td id="mtContents"> </td></tr>'
|
||||
+ '</table></div>';
|
||||
if (LWWidget.debug) {
|
||||
str += '<div id="debugDiv"> </div><div id="debugLink"><a href="#" onclick="LWWidget.main.showDebug();return false">Debug mode</a></div>';
|
||||
}
|
||||
Base.Browser.get().docBody.innerHTML = str;
|
||||
|
||||
this.menu.draw();
|
||||
this.page.draw();
|
||||
},
|
||||
|
||||
|
||||
setTextPage: function (mMode, text) {
|
||||
this.menu.setMode(mMode);
|
||||
this.page = this.textPage;
|
||||
this.page.setText(text);
|
||||
},
|
||||
|
||||
menuCommand: function (command) {
|
||||
if (command == 'logout') {
|
||||
if (this.loader) {
|
||||
this.loader.destroy();
|
||||
}
|
||||
if (this.versionCheck) {
|
||||
this.versionCheck.stop();
|
||||
}
|
||||
if (this.state == 3) {
|
||||
this.gameDisplay.hide();
|
||||
}
|
||||
this.state = 0;
|
||||
this.versionChecked = false;
|
||||
this.loginPage.setError('');
|
||||
this.page = this.loginPage;
|
||||
this.menu.setMode('out');
|
||||
this.page.draw();
|
||||
} else if (command == 'continue') {
|
||||
this.login();
|
||||
} else if (command == 'gamesel') {
|
||||
if (this.state == 3) {
|
||||
this.page.hide();
|
||||
}
|
||||
this.state = 1;
|
||||
this.setTextPage('wait', 'Connecting to the Legacy Worlds server<br/><br/>Please wait');
|
||||
this.loader.load('main/index');
|
||||
} else if (this.state == 3) {
|
||||
this.gameDisplay.setPage(command);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
versionError: function () {
|
||||
// Ignore the error if the version has already been checked
|
||||
if (!this.versionChecked) {
|
||||
this.commError();
|
||||
}
|
||||
},
|
||||
|
||||
versionNewAvailable: function (url) {
|
||||
// Ignore the new version unless it is the first time we check
|
||||
if (this.versionChecked) {
|
||||
return;
|
||||
}
|
||||
this.versionChecked = true;
|
||||
|
||||
this.versionPage.setData(url, false);
|
||||
this.page = this.versionPage;
|
||||
this.menu.setMode('nvAvail');
|
||||
this.page.draw();
|
||||
},
|
||||
|
||||
versionNewRequired: function (url) {
|
||||
if (this.state == 3) {
|
||||
this.gameDisplay.hide();
|
||||
}
|
||||
this.versionCheck.stop();
|
||||
this.versionPage.setData(url, true);
|
||||
this.page = this.versionPage;
|
||||
this.menu.setMode('nvReq');
|
||||
this.page.draw();
|
||||
},
|
||||
|
||||
versionOk: function () {
|
||||
if (!this.versionChecked) {
|
||||
// Continue login
|
||||
this.versionChecked = true;
|
||||
this.login();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
login: function () {
|
||||
this.setTextPage('wait', 'Connecting to the Legacy Worlds server<br/><br/>Please wait');
|
||||
|
||||
// If the version hasn't been checked, well, check it
|
||||
if (!this.versionChecked) {
|
||||
this.versionCheck.start();
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialise the loader and get the game list
|
||||
this.initLoader();
|
||||
this.loader.load('main/index');
|
||||
},
|
||||
|
||||
|
||||
handleGameList: function (data, force) {
|
||||
this.state = 1;
|
||||
|
||||
var games = new Array(), auto = null;
|
||||
|
||||
if (!force && LWWidget.main.getPreference('lwRemGame') == '1') {
|
||||
auto = LWWidget.main.getPreference('lwGame');
|
||||
}
|
||||
|
||||
for (var i in data.contents) {
|
||||
// Check if version is supported
|
||||
var _v = data.contents[i].getAttribute('version');
|
||||
if (!LWWidget.Game.versions().containsKey(_v)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var _g = {
|
||||
name: data.contents[i].getText(),
|
||||
path: data.contents[i].getAttribute('path'),
|
||||
version: LWWidget.Game.versions().get(_v)
|
||||
};
|
||||
if (auto && auto == _g.path) {
|
||||
this.loadGame(_g);
|
||||
return;
|
||||
}
|
||||
games.push(_g);
|
||||
}
|
||||
|
||||
if (games.length == 0) {
|
||||
this.setTextPage('error', 'It appears that you are not registered to any Legacy Worlds game.');
|
||||
} else if (!force && games.length == 1) {
|
||||
this.loadGame(games[0]);
|
||||
} else {
|
||||
this.page = this.gameSelector;
|
||||
this.menu.setMode('game');
|
||||
this.gameSelector.setGames(games);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
loadGame: function (game) {
|
||||
this.state = 2;
|
||||
this.currentGame = game;
|
||||
this.loader.load(game.path + '/play');
|
||||
},
|
||||
|
||||
loadData: function (path) {
|
||||
if (this.state == 3 && this.loader) {
|
||||
this.loader.load(path + '/play');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
commError: function () {
|
||||
this.setTextPage('error', '<b>Communications error</b><br/><br/>The server could not be reached or it sent an invalid reply.');
|
||||
},
|
||||
|
||||
serverError: function (code, text) {
|
||||
var str = '<b>Server error</b><br/><br/>The server encountered an internal error:<br/><i>'
|
||||
+ text + '</i><br/>(code: ' + code + ')';
|
||||
this.setTextPage('error', str);
|
||||
},
|
||||
|
||||
playerKicked: function (reason) {
|
||||
var str = (reason == '' ? 'No reason was specified' : ('<b>Reason:</b> ' + reason));
|
||||
if (this.state == 3) {
|
||||
this.gameDisplay.hide();
|
||||
}
|
||||
this.setTextPage('error', 'You have been <b>kicked</b> from the game!<br/><br/>' + str);
|
||||
},
|
||||
|
||||
loginFailed: function (code) {
|
||||
switch (code) {
|
||||
case '0':
|
||||
if (this.state == 0) {
|
||||
this.loader.destroy();
|
||||
LWWidget.main.password = '';
|
||||
this.loginPage.setError('Invalid username or password');
|
||||
this.page = this.loginPage;
|
||||
this.page.draw();
|
||||
} else {
|
||||
this.setTextPage('error', 'Your password has been changed.');
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
this.setTextPage('error', 'The server encountered an internal error while authenticating your account.');
|
||||
break;
|
||||
case '2':
|
||||
this.setTextPage('error', 'Your account has been closed!');
|
||||
break;
|
||||
case '3':
|
||||
this.setTextPage('error', 'Your account has not been validated yet, please check your e-mail.');
|
||||
break;
|
||||
case '4':
|
||||
if (this.state < 2) {
|
||||
this.setTextPage('error', 'The server just did something it\'s not supposed to do. Ever.');
|
||||
} else {
|
||||
this.gameDisplay.hide();
|
||||
this.setTextPage('errsel', 'You are no longer registered to this game!');
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
serverMaintenance: function (reason, until, now) {
|
||||
var str = '<b>The server is undergoing maintenance.</b><br/><br/>Reason: ' + reason
|
||||
+ '<br/><br/>It will be down until <b>' + until + '</b>.<br/>Current server time: ' + now;
|
||||
this.setTextPage('error', str);
|
||||
},
|
||||
|
||||
loaderDestroyed: function () {
|
||||
this.loader = null;
|
||||
},
|
||||
|
||||
dataLoaded: function (data) {
|
||||
if (this.state == 0) {
|
||||
// We were not loging in, save password if needed
|
||||
if (LWWidget.main.getPreference('lwRemAuth') == '1') {
|
||||
LWWidget.main.setPreference('lwPassword', LWWidget.main.password);
|
||||
}
|
||||
|
||||
this.handleGameList(data);
|
||||
} else if (this.state == 1) {
|
||||
// We were logged in but asked to select a game
|
||||
this.handleGameList(data, true);
|
||||
} else if (this.state == 2) {
|
||||
// We just received game data for the first time
|
||||
this.gameDisplay.setGame(this.currentGame.version, this.currentGame.path);
|
||||
this.gameDisplay.handleData(data);
|
||||
this.page = this.gameDisplay;
|
||||
this.menu.setMode('std');
|
||||
this.menu.setSelected('player');
|
||||
this.page.draw();
|
||||
this.state = 3;
|
||||
} else {
|
||||
// Update game contents
|
||||
this.gameDisplay.handleData(data);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
81
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu.js
Normal file
81
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
LWWidget.Menu = Base.Comp.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
|
||||
this.currentMode = null;
|
||||
this.modes = new Base.Util.Hashtable();
|
||||
|
||||
this.addSlot('modeDestroyed');
|
||||
this.addSlot('draw');
|
||||
this.addEvent('Click');
|
||||
this.bindEvent('Click', 'draw');
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
var modes = this.modes.values();
|
||||
for (var i in modes) {
|
||||
modes[i].destroy();
|
||||
}
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
newMode: function (name) {
|
||||
if (this.modes.containsKey(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var mode = new LWWidget.Menu.Mode(name);
|
||||
this.modes.put(name, mode);
|
||||
if (!this.currentMode) {
|
||||
this.currentMode = mode;
|
||||
}
|
||||
|
||||
mode.bindEvent('Destroy', 'modeDestroyed', this);
|
||||
mode.bindEvent('Click', 'onClick', this);
|
||||
|
||||
return mode;
|
||||
},
|
||||
|
||||
setMode: function (name) {
|
||||
if (!this.modes.containsKey(name) || this.currentMode && this.currentMode.name == name) {
|
||||
return;
|
||||
}
|
||||
this.currentMode = this.modes.get(name);
|
||||
this.draw();
|
||||
},
|
||||
|
||||
setSelected: function (name) {
|
||||
if (this.currentMode) {
|
||||
this.currentMode.setSelected(name);
|
||||
this.draw();
|
||||
}
|
||||
},
|
||||
|
||||
modeDestroyed: function (mode) {
|
||||
if (!(mode && mode._cid && mode.name && this.modes.containsKey(mode.name))) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modes.remove(mode.name);
|
||||
if (this.currentMode && this.currentMode._cid == mode._cid) {
|
||||
var _v = this.modes.values();
|
||||
if (_v.length) {
|
||||
this.currentMode = _v[0];
|
||||
} else {
|
||||
this.currentMode = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
var e = document.getElementById('mtMenu');
|
||||
if (!(e && this.currentMode)) {
|
||||
return;
|
||||
}
|
||||
e.innerHTML = this.currentMode.draw();
|
||||
}
|
||||
|
||||
});
|
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Command.js
Normal file
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Command.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
LWWidget.Menu.Command = LWWidget.Menu.Item.inherits({
|
||||
|
||||
constructor: function (name, text) {
|
||||
this.base(name, text, true, false, ' - ');
|
||||
}
|
||||
|
||||
});
|
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Entry.js
Normal file
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Entry.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
LWWidget.Menu.Entry = LWWidget.Menu.Item.inherits({
|
||||
|
||||
constructor: function (name, text) {
|
||||
this.base(name, text, true, true, ' - ');
|
||||
}
|
||||
|
||||
});
|
38
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Item.js
Normal file
38
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Item.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
LWWidget.Menu.Item = Base.Comp.inherits({
|
||||
|
||||
constructor: function (name, text, clickable, selectable, separator) {
|
||||
this.base();
|
||||
|
||||
this.name = name;
|
||||
this.text = text;
|
||||
this.clickable = !!clickable;
|
||||
this.selectable = this.clickable && !!selectable;
|
||||
this.separator = (typeof separator == 'string') ? separator : '';
|
||||
this.selected = false;
|
||||
|
||||
this.addEvent('Click');
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
var pfx, sfx;
|
||||
if (this.clickable && !this.selected) {
|
||||
pfx = '<a href="#" onclick="Base.Comp.get(' + this._cid + ').click();return false">';
|
||||
sfx = '</a>';
|
||||
} else if (this.selectable && this.selected) {
|
||||
pfx = '<b>';
|
||||
sfx = '</b>';
|
||||
} else {
|
||||
pfx = sfx = '';
|
||||
}
|
||||
|
||||
return pfx + this.text + sfx;
|
||||
},
|
||||
|
||||
click: function () {
|
||||
if (this.selectable) {
|
||||
this.selected = true;
|
||||
}
|
||||
this.onClick(this);
|
||||
}
|
||||
|
||||
});
|
109
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Mode.js
Normal file
109
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Mode.js
Normal file
|
@ -0,0 +1,109 @@
|
|||
LWWidget.Menu.Mode = Base.Comp.inherits({
|
||||
|
||||
constructor: function (name) {
|
||||
this.base();
|
||||
|
||||
this.name = name;
|
||||
this.items = new Base.Util.Hashtable();
|
||||
this.selected = null;
|
||||
|
||||
this.addSlot('itemDestroyed');
|
||||
this.addSlot('itemClicked');
|
||||
this.addEvent('Click');
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
var items = this.items.values();
|
||||
for (var i in items) {
|
||||
var _i = items[i];
|
||||
this.items.remove(items[i]._cid);
|
||||
items[i].destroy();
|
||||
}
|
||||
|
||||
this.base();
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
var str = '', items = this.items.values();
|
||||
|
||||
for (var i=0;i<items.length;i++) {
|
||||
str += items[i].draw();
|
||||
if (i < items.length - 1 && items[i].separator) {
|
||||
str += items[i].separator;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
},
|
||||
|
||||
|
||||
addItem: function (item) {
|
||||
if (!(item && item._cid) || this.items.containsKey(item._cid)) {
|
||||
return;
|
||||
}
|
||||
this.items.put(item._cid, item);
|
||||
if (item.selectable && !this.selected) {
|
||||
item.selected = true;
|
||||
this.selected = item;
|
||||
} else {
|
||||
item.selected = false;
|
||||
}
|
||||
|
||||
item.bindEvent('Destroy', 'itemDestroyed', this);
|
||||
item.bindEvent('Click', 'itemClicked', this);
|
||||
},
|
||||
|
||||
|
||||
setSelected: function (name) {
|
||||
var _k = this.items.values();
|
||||
for (var i in _k) {
|
||||
var item = _k[i];
|
||||
if (item.selectable && item.name == name) {
|
||||
if (this.selected) {
|
||||
if (this.selected._cid == item._cid) {
|
||||
return;
|
||||
}
|
||||
this.selected.selected = false;
|
||||
}
|
||||
item.selected = true;
|
||||
this.selected = item;
|
||||
return;
|
||||
} else if (item.name == name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
itemClicked: function (item) {
|
||||
if (item.selectable) {
|
||||
if (this.selected) {
|
||||
this.selected.selected = false;
|
||||
}
|
||||
item.selected = true;
|
||||
this.selected = item;
|
||||
}
|
||||
this.onClick(item.name);
|
||||
},
|
||||
|
||||
itemDestroyed: function (item) {
|
||||
if (!(item && item._cid && this.items.containsKey(item._cid))) {
|
||||
return;
|
||||
}
|
||||
this.items.remove(item._cid);
|
||||
|
||||
if (this.selected && this.selected._cid == item._cid) {
|
||||
var _v = this.items.values(), _s = null;
|
||||
for (var i in _v) {
|
||||
var _i = _v[i];
|
||||
if (_i.selectable) {
|
||||
_s = _i;
|
||||
_i.selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.selected = _s;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Text.js
Normal file
7
misc/Legacy Worlds.wdgt/lib/LWWidget/Menu/Text.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
LWWidget.Menu.Text = LWWidget.Menu.Item.inherits({
|
||||
|
||||
constructor: function (text) {
|
||||
this.base('', text);
|
||||
}
|
||||
|
||||
});
|
33
misc/Legacy Worlds.wdgt/lib/LWWidget/NewVersion.js
Normal file
33
misc/Legacy Worlds.wdgt/lib/LWWidget/NewVersion.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
LWWidget.NewVersion = LWWidget.Page.inherits({
|
||||
|
||||
setData: function (url, required) {
|
||||
this.url = url;
|
||||
this.required = required;
|
||||
},
|
||||
|
||||
|
||||
draw: function () {
|
||||
var _s;
|
||||
|
||||
if (this.required) {
|
||||
_s = 'Due to server updates, you are required to download a new version of this widget in order to keep using it.';
|
||||
} else {
|
||||
_s = 'A new version of the LegacyWorlds widget is available!<br/><br/>'
|
||||
+ 'Upgrading the widget is not mandatory; the new version only brings new features and bugfixes.';
|
||||
}
|
||||
|
||||
_s += '<br/><br/><a href="#" onclick="Base.Comp.get(' + this._cid + ').startDownload();return false">Download the new version</a>';
|
||||
|
||||
this.writeContents(_s);
|
||||
},
|
||||
|
||||
|
||||
startDownload: function () {
|
||||
if (window.widget) {
|
||||
widget.openURL(this.url);
|
||||
} else {
|
||||
window.open(this.url);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
17
misc/Legacy Worlds.wdgt/lib/LWWidget/Page.js
Normal file
17
misc/Legacy Worlds.wdgt/lib/LWWidget/Page.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
LWWidget.Page = Base.Comp.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
|
||||
this.addEvent('Show');
|
||||
this.addEvent('Hide');
|
||||
},
|
||||
|
||||
writeContents: function (contents) {
|
||||
var e = document.getElementById('mtContents');
|
||||
if (e) {
|
||||
e.innerHTML = contents;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
18
misc/Legacy Worlds.wdgt/lib/LWWidget/TextPage.js
Normal file
18
misc/Legacy Worlds.wdgt/lib/LWWidget/TextPage.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
LWWidget.TextPage = LWWidget.Page.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.text = "";
|
||||
},
|
||||
|
||||
setText: function (text) {
|
||||
if (this.text != text) {
|
||||
this.text = text;
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
this.writeContents(this.text == "" ? ' ' : this.text);
|
||||
}
|
||||
|
||||
});
|
101
misc/Legacy Worlds.wdgt/lib/LWWidget/VersionCheck.js
Normal file
101
misc/Legacy Worlds.wdgt/lib/LWWidget/VersionCheck.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
LWWidget.VersionCheck = Base.Comp.inherits({
|
||||
|
||||
constructor: function () {
|
||||
this.base();
|
||||
|
||||
this.addEvent('CommError');
|
||||
this.addEvent('NewVersion');
|
||||
this.addEvent('RequiredVersion');
|
||||
this.addEvent('VersionOk');
|
||||
|
||||
this.addSlot('dataReceived');
|
||||
this.addSlot('loaderDestroyed');
|
||||
this.addSlot('timerDestroyed');
|
||||
|
||||
this.loader = new Base.XMLLoader(LWWidget.base + '/index.php/main/macwidget.xml', false);
|
||||
this.loader.bindEvent('Destroy', 'loaderDestroyed', this);
|
||||
this.loader.bindEvent('NetworkError', 'onCommError', this);
|
||||
this.loader.bindEvent('ServerError', 'onCommError', this);
|
||||
this.loader.bindEvent('Timeout', 'onCommError', this);
|
||||
this.loader.bindEvent('Unsupported', 'onCommError', this);
|
||||
this.loader.bindEvent('Aborted', 'onCommError', this);
|
||||
this.loader.bindEvent('Loaded', 'dataReceived', this);
|
||||
|
||||
this.timer = new Base.Timer(300000, true);
|
||||
this.timer.bindEvent('Tick', 'load', this.loader);
|
||||
this.timer.bindEvent('Destroy', 'timerDestroyed', this);
|
||||
|
||||
this.knownVersion = LWWidget.version;
|
||||
},
|
||||
|
||||
|
||||
destroy: function () {
|
||||
if (this.loader) {
|
||||
this.loader.destroy();
|
||||
}
|
||||
if (this.timer) {
|
||||
this.timer.destroy();
|
||||
}
|
||||
this.base();
|
||||
},
|
||||
|
||||
|
||||
timerDestroyed: function () {
|
||||
this.timer = null;
|
||||
},
|
||||
|
||||
loaderDestroyed: function () {
|
||||
this.loader = null;
|
||||
},
|
||||
|
||||
|
||||
start: function () {
|
||||
if (typeof this.requiredVersion != 'undefined' && LWWidget.version < this.requiredVersion) {
|
||||
return;
|
||||
}
|
||||
this.timer.start();
|
||||
this.loader.load();
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
this.timer.stop();
|
||||
this.knownVersion = LWWidget.version;
|
||||
delete this.latestVersion;
|
||||
delete this.requiredVersion;
|
||||
},
|
||||
|
||||
|
||||
dataReceived: function (data) {
|
||||
var _xml = Base.Util.parseXML(data);
|
||||
if (!_xml) {
|
||||
this.onCommError();
|
||||
return;
|
||||
}
|
||||
|
||||
var _doc = _xml.documentElement;
|
||||
this.latestVersion = parseInt(_doc.getAttribute('latest'), 10);
|
||||
this.requiredVersion = parseInt(_doc.getAttribute('oldestOk'), 10);
|
||||
this.url = _doc.childNodes[0].nodeValue;
|
||||
|
||||
if (this.knownVersion == this.latestVersion && this.requiredVersion <= LWWidget.version) {
|
||||
this.onVersionOk();
|
||||
return;
|
||||
}
|
||||
|
||||
Base.Log.write('Version check: current version = ' + LWWidget.version);
|
||||
Base.Log.write('Version check: latest received version = ' + this.knownVersion);
|
||||
Base.Log.write('Version check: latest version = ' + this.latestVersion);
|
||||
Base.Log.write('Version check: oldest accepted version = ' + this.requiredVersion);
|
||||
|
||||
this.knownVersion = this.latestVersion;
|
||||
if (LWWidget.version < this.requiredVersion) {
|
||||
this.onRequiredVersion(this.url);
|
||||
this.timer.stop();
|
||||
} else if (LWWidget.version < this.latestVersion) {
|
||||
this.onNewVersion(this.url);
|
||||
} else {
|
||||
this.onVersionOk();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
2
misc/Legacy Worlds.wdgt/lib/LWWidget/Versions.js
Normal file
2
misc/Legacy Worlds.wdgt/lib/LWWidget/Versions.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
LWWidget.Versions = new Base.Util.Hashtable();
|
||||
LWWidget.Versions.put('beta5', LWWidget.Beta5);
|
Loading…
Add table
Add a link
Reference in a new issue