Hébergeur de fichiers indépendant

world map IG.user.js

À propos

Type de fichier
Fichier JS de 41 Ko (text/plain)
Confidentialité
Fichier public, envoyé le 21 mai 2014 à 07:43, depuis l'adresse IP 31.34.x.x (France)
Sécurité
Ne contient aucun Virus ou Malware connus - Dernière vérification: 2 jours
Statistiques
La présente page de téléchargement a été vue 437 fois depuis l'envoi du fichier
Page de téléchargement

Aperçu du fichier


// ==UserScript==
// @name Command & Conquer TA World Map
// @description Creates a detailed map of bases and pois of the alliance and enemies.
// @namespace https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @version 1.0.0
// @grant none
// @author zdoom
// @updateURL https://userscripts.org/scripts/source/173330.meta.js
// @downloadURL https://userscripts.org/scripts/source/173330.user.js
// ==/UserScript==

(function(){

function create_ccta_map_class()
{
qx.Class.define("ccta_map",
{
type: "singleton",
extend: qx.core.Object,

construct: function()
{
try
{	
var root = this;

var mapButton = new qx.ui.form.Button('Map').set({ enabled: false });
var app = qx.core.Init.getApplication();
var optionsBar = app.getOptionsBar().getLayoutParent();
this.__mapButton = mapButton;

optionsBar.getChildren()[0].getChildren()[2].addAt(mapButton,1);

var onReady = function()
{
console.log('checking if data is ready');
var alliance = ClientLib.Data.MainData.GetInstance().get_Alliance().get_Relationships;
var world = ClientLib.Data.MainData.GetInstance().get_World();
var endGame = ClientLib.Data.MainData.GetInstance().get_EndGame().get_Hubs().d;
var command = ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand;
var delegate = phe.cnc.Util.createEventDelegate;

if(!!alliance && !!world && !!command && !!delegate && !!endGame)
{
var worldWidth = world.get_WorldWidth();
if(!worldWidth) return;

var factor = 500 / worldWidth;
var hubs = [], fortress = [];

for (var index in endGame)
{
var currentHub = endGame[index];
if (currentHub.get_Type() == 1) hubs.push([(currentHub.get_X() + 2) * factor, (currentHub.get_Y() + 2) * factor]);
if (currentHub.get_Type() == 3) fortress = [(currentHub.get_X() + 2) * factor, (currentHub.get_Y() + 2) * factor];
}

if (hubs.length > 0)
{
timer.stop();
root.__factor = factor;
root.__endGame['hubs'] = hubs;
root.__endGame['fortress'] = fortress;
root.__init();
}
console.log(hubs);
}
console.log(!!alliance, !!world, !!command, !!delegate, !!endGame);
};

var timer = new qx.event.Timer(1000);
timer.addListener('interval', onReady, this);
timer.start();
}
catch(e)
{
console.log(e.toString());
}
console.log('ccta_map initialization completed');
},
destruct: function(){},
members:
{
__mapButton: null,
__allianceExist: null,
__allianceName: null,
__allianceId: null,
__allianceHasRelations: false,
__defaultAlliances: null,
__selectedAlliances: null,
__data: null,
__totalProcesses: null,
__completedProcesses: 0,
__endGame: {},
__isLoading: false,
__factor: null,

__init: function()
{
try
{
var root = this;
var data = ClientLib.Data.MainData.GetInstance();
var alliance_data = data.get_Alliance();
var alliance_exists = alliance_data.get_Exists();

if(alliance_exists)
{
var alliance_name = alliance_data.get_Name();
var alliance_id = alliance_data.get_Id();
var alliance_relations = alliance_data.get_Relationships();

this.__allianceExist = true;
this.__allianceId = alliance_id;
this.__allianceName = alliance_name;

var selectedAlliancesList = [];
selectedAlliancesList[0] = [alliance_id, 'alliance', alliance_name, 0];

if (alliance_relations != null)
{
this.__allianceHasRelations = true;
alliance_relations.map(function(x)
{
var type = x.Relationship, id = x.OtherAllianceId, name = x.OtherAllianceName;
if ((type == 3) && (selectedAlliancesList.length < 9)) selectedAlliancesList.push([id, 'enemy', name, 0]);
});
}
this.__defaultAlliances = selectedAlliancesList;
}
else
{
this.__allianceExist = false;
}

if (typeof(Storage) !== 'undefined' && typeof(localStorage.ccta_map_settings) !== 'undefined')
{
this.__selectedAlliances = JSON.parse(localStorage.ccta_map_settings);
}

this.__mapButton.setEnabled(true);
this.__mapButton.addListener('execute', function()
{
root.getData();
ccta_map.container.getInstance().open(1);
}, this);
}
catch(e)
{
console.log(e.toString());
}
},

getData: function()
{
if (this.__isLoading === true) return;
this.__isLoading = true;
var arr = (this.__selectedAlliances == null) ? this.__defaultAlliances : this.__selectedAlliances;

if(arr != null)
{
this.__data = [];
this.__totalProcesses = arr.length;
for(var i = 0; i < arr.length; i++)
{
this.__getAlliance(arr[i][0], arr[i][1], arr[i][3]);
}
}
},

__getAlliance: function(aid, type, color)
{
try
{
var alliance = {}, root = this, factor = this.__factor;
alliance.id = aid;
alliance.players = {};
var totalProcesses = this.__totalProcesses;

var getBases = function(pid, pn, p, tp)
{
ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand("GetPublicPlayerInfo", { id: pid },
phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, function(context, data)
{
if (data.c != null)
{
var totalBases = data.c.length;
var player = {};
var bases = [];

for (var b = 0; b < data.c.length; b++)
{
var id = data.c[b].i;
var name = data.c[b].n;
var x = data.c[b].x * factor;
var y = data.c[b].y * factor;
bases.push([x, y, name, id]);
if((p == tp - 1) && (b == totalBases - 1))
{
root.__completedProcesses++;
var loader = ccta_map.container.getInstance().loader;
loader.setValue('Loading: ' + root.__completedProcesses + "/" + totalProcesses);
}
if(root.__completedProcesses == totalProcesses) root.__onProcessComplete();
}
player.id = pid;
player.name = pn;
player.bases = bases;
alliance.players[pn] = player;
}
}), null);
};

ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand("GetPublicAllianceInfo", { id: aid },
phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, function(context, data)
{
if (data == null) return;
if (data.opois != null)
{
var pois = [];
data.opois.map(function(poi)
{
pois.push({'i': poi.i, 'l': poi.l, 't': poi.t, 'x': poi.x * factor, 'y': poi.y * factor});
});
alliance.pois = pois;
}
if (data.n != null) alliance.name = data.n;
if (data.m != null)
{

for (var p = 0; p < data.m.length; p++)
{
var playerName = data.m[p].n;
var playerId = data.m[p].i;
getBases(playerId, playerName, p, data.m.length);	
}
root.__data.push([alliance, type, color]);
}
}), null);
}
catch(e)
{
console.log(e.toString());
}
},

__onProcessComplete: function()
{
console.log('process completed - alliances data has been generated', this.__data);
this.__isLoading = false;
var win = ccta_map.container.getInstance();
win.receivedData = this.__data;
win.__updateList();
win.drawCanvas();
win.loader.setValue('Completed');
this.__totalProcess = null;
this.__completedProcesses = 0;
setTimeout(function(){
win.loader.setValue('');
}, 3000);
}

}

});

qx.Class.define("ccta_map.container",
{
type: "singleton",
extend: qx.ui.container.Composite,

construct: function()
{
try
{
this.base(arguments);
var layout = new qx.ui.layout.Canvas();
this._setLayout(layout);

var worldWidth = ClientLib.Data.MainData.GetInstance().get_World().get_WorldWidth();
var factor = 500 / worldWidth;
this.__factor = factor;

var zoomIn = new qx.ui.form.Button('+').set({ width: 30 });
var zoomOut = new qx.ui.form.Button('-').set({ width: 30, enabled: false });
var zoomReset = new qx.ui.form.Button('R').set({ width: 30, enabled: false });
var grid = new qx.ui.container.Composite(new qx.ui.layout.Grid(3,1));
var info = new qx.ui.container.Composite(new qx.ui.layout.VBox()).set({ minHeight: 300, padding: 10 });
var canvasContainer = new qx.ui.container.Composite(new qx.ui.layout.VBox());
var rightBar = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
var leftBar = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
var widget = new qx.ui.core.Widget().set({ width: 500, height: 500 });
var div = new qx.html.Element('div', null, {id: 'canvasContainer'});


var li1 = new qx.ui.form.ListItem('All', null, "all");
var li2 = new qx.ui.form.ListItem('My Bases', null, "bases");
var li3 = new qx.ui.form.ListItem('My Alliance', null, "alliance");
var li4 = new qx.ui.form.ListItem('Selected', null, "selected");
var displayMode = new qx.ui.form.SelectBox().set({ height: 28 });
displayMode.add(li1);
displayMode.add(li2);
displayMode.add(li3);
displayMode.add(li4);

var zoomBar = new qx.ui.container.Composite(new qx.ui.layout.HBox(15));

var bothOpt = new qx.ui.form.RadioButton('Both').set({ model: "both" });
var basesOpt = new qx.ui.form.RadioButton('Base').set({ model: "bases" });;
var poisOpt = new qx.ui.form.RadioButton('Poi').set({ model: "pois" });
var displayOptions = new qx.ui.form.RadioButtonGroup().set({ layout: new qx.ui.layout.HBox(), font :'font_size_11' });
displayOptions.add(bothOpt);
displayOptions.add(basesOpt);
displayOptions.add(poisOpt);

var allianceList = new qx.ui.form.List().set({ font :'font_size_11', height: 215 });
var editAlliance = new qx.ui.form.Button('Edit Alliances');
var label = new qx.ui.basic.Label('Transparency');
var slider = new qx.ui.form.Slider().set({ minimum: 30, maximum: 100, value: 100 });
var coordsField = new qx.ui.form.TextField().set({maxWidth: 100, textAlign: 'center', readOnly: 'true', alignX: 'center'});
var loader = new qx.ui.basic.Label().set({ marginTop: 100 });

grid.set({ minWidth: 780, backgroundColor: '#8e979b', minHeight: 524, margin: 3, paddingTop: 10 });
rightBar.set({ maxWidth: 130, minWidth: 130, paddingTop: 30, paddingRight: 10 });
leftBar.set({ maxWidth: 130, minWidth: 130, paddingTop: 30, paddingLeft: 10 });

var hints = [[zoomIn,'Zoom in'], [zoomOut,'Zoom out'], [zoomReset,'Restet zoom'], [basesOpt,'Show bases only'] , [poisOpt,'Show POIs only'], [bothOpt,'Show bases and POIs']]
for(var i = 0; i < hints.length; i++)
{
var tooltip = new qx.ui.tooltip.ToolTip(hints[i][1]);
hints[i][0].setToolTip(tooltip);
}

zoomBar.add(zoomIn);
zoomBar.add(zoomOut);
zoomBar.add(zoomReset);

rightBar.add(zoomBar);
rightBar.add(displayMode);
rightBar.add(displayOptions);
rightBar.add(allianceList);
rightBar.add(editAlliance);
rightBar.add(label);
rightBar.add(slider);

leftBar.add(coordsField);
leftBar.add(info);
leftBar.add(loader);

canvasContainer.add(widget);
widget.getContentElement().add(div);
grid.add(leftBar, {row: 1, column: 1});
grid.add(rightBar, {row: 1, column: 3});
grid.add(canvasContainer, {row: 1, column: 2});

this.info = info;
this.coordsField = coordsField;
this.allianceList = allianceList;
this.panel = [zoomOut, zoomReset, zoomIn, displayOptions, displayMode, allianceList, editAlliance];
this.loader = loader;
this.zoomIn = zoomIn;
this.zoomOut = zoomOut;
this.zoomReset = zoomReset;

//canvas
var cont = document.createElement('div'),
mask = document.createElement('div'),
canvas = document.createElement('canvas'),
ctx = canvas.getContext("2d"),
root = this;

cont.style.width = '500px';
cont.style.height = '500px';
cont.style.position = 'absolute';
cont.style.overflow = 'hidden';
cont.style.backgroundColor = '#0b2833';

canvas.style.position = 'absolute';
canvas.style.backgroundColor = '#0b2833';

mask.style.position = 'absolute';
mask.style.width = '500px';
mask.style.height = '500px';
mask.style.background = 'url("http://archeikhmeri.co.uk/images/map_mask.png") center center no-repeat';

this.canvas = canvas;
this.mask = mask;
this.ctx = ctx;	

var __zoomIn = function(){ if (root.scale < 12) root.__scaleMap('up') };
var __zoomOut = function(){if (root.scale > 1) root.__scaleMap('down') };
var __zoomReset = function()
{
canvas.width = 500;
canvas.height = 500;
canvas.style.left = 0;
canvas.style.top = 0;
root.scale = 1;
root.drawCanvas();
zoomIn.setEnabled(true);
zoomOut.setEnabled(false);
zoomReset.setEnabled(false);
};

cont.appendChild(canvas);
cont.appendChild(mask);	
root.__draggable(mask);
root.resetMap();

slider.addListener('changeValue', function(e)
{
if (e.getData())
{
var val = e.getData() / 100;
this.setOpacity(val);
slider.setToolTipText(" " + val * 100 + "% ");
}
}, this);

allianceList.addListener('changeSelection', function(e)
{
if ((root.__displayM == "bases") || (root.__displayM == "alliance") || !e.getData()[0]) return;
var aid = e.getData()[0].getModel();
root.__selectedA = aid;
root.drawCanvas();
}, this);

displayMode.addListener('changeSelection', function(e)
{
var dm = e.getData()[0].getModel();
root.__displayM = dm;
root.__updateList();

if(dm == "bases")
{
displayOptions.setSelection([basesOpt]);
poisOpt.setEnabled(false);
bothOpt.setEnabled(false);
root.__displayO = "bases";
}
else
{
if(!poisOpt.isEnabled()) poisOpt.setEnabled(true);
if(!bothOpt.isEnabled()) bothOpt.setEnabled(true);
displayOptions.setSelection([bothOpt]);
root.__displayO = "both";
}
root.drawCanvas();
}, this);

displayOptions.addListener('changeSelection', function(e)
{
if (!e.getData()[0]) return;
var dop = e.getData()[0].getModel();
root.__displayO = dop;
root.drawCanvas();
}, this);

editAlliance.addListener('execute', function()
{
ccta_map.options.getInstance().open();
}, this);

var desktop = qx.core.Init.getApplication().getDesktop();
desktop.addListener('resize', this._onResize, this);

zoomIn.addListener('execute', __zoomIn, this);
zoomOut.addListener('execute', __zoomOut, this);
zoomReset.addListener('execute', __zoomReset, this);

this.add(grid);

this.wdgAnchor = new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_tl1.png").set({ width: 3, height: 32 });
this.__imgTopRightCorner = new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_tr.png").set({ width: 34, height: 35 });	
this._add(this.__imgTopRightCorner, { right: 0, top: 0, bottom: 28 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_r.png").set({ width: 3, height: 1, allowGrowY: true, scale: true }), { right: 0, top: 35, bottom: 29 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_br.png").set({ width: 5, height: 28, allowGrowY: true, scale: true }), { right: 0, bottom: 0 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_b.png").set({ width: 1, height: 3, allowGrowX: true, scale: true }), { right: 5, bottom: 0, left: 5 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_bl.png").set({ width: 5, height: 29 }), { left: 0, bottom: 0 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_l.png").set({ width: 3, height: 1, allowGrowY: true, scale: true }), { left: 0, bottom: 29, top: 32 });
this._add(this.wdgAnchor, { left: 0, top: 0 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_tl2.png").set({ width: 25, height: 5 }), { left: 3, top: 0 });
this._add(new qx.ui.basic.Image("webfrontend/ui/common/frame_basewin/frame_basewindow_t.png").set({ width: 1, height: 3, allowGrowX: true, scale: true }), { left: 28, right: 34, top: 0 });

this.__btnClose = new webfrontend.ui.SoundButton(null, "FactionUI/icons/icon_close_button.png").set({ appearance: "button-close", width: 23, height: 23, toolTipText: this.tr("tnf:close base view") });
this.__btnClose.addListener("execute", this._onClose, this);
this._add(this.__btnClose, { top: 6, right: 5 });

var onLoaded = function()
{
var counter = 0;
var check = function()
{
if(counter > 60) return;
var htmlDiv = document.getElementById('canvasContainer');
(htmlDiv) ? htmlDiv.appendChild(cont) : setTimeout(check, 1000);
console.log('retrying check for canvasContainer is loaded');
counter++;
};
check();
};
onLoaded();

}
catch(e)
{
console.log(e.toString());
}
console.log('container creation completed');
},
destruct: function(){},
members:
{
info: null,
coordsField: null,
panel: null,
loader: null,
canvas: null,
mask: null,
ctx: null,
receivedData: null,
allianceList: null,
circles: [53, 85, 113, 145, 242],
scale: 1,
selectedBase: false,
elements: [],
locations: [],
inProgress: false,
isRadarVisible: false,
__interval: null,
__pointerX: null,
__pointerY: null,
__selectedA: null,
__selectedB: null,
__displayM: "all",
__displayO: "both",
__factor: null,

__setInfo: function(base)
{
try
{
// console.log(base);
var info = this.info;
info.removeAll();
if(!base) return;
for ( var i = 0; i < base.length; i++)
{
var title = new qx.ui.basic.Label(base[i][0]).set({font: 'font_size_13_bold', textColor: '#375773'});
var value = new qx.ui.basic.Label(base[i][1]).set({font: 'font_size_11', textColor: '#333333', marginBottom: 5});
info.add(title);
info.add(value);
}
}
catch(e)
{
console.log(e.toString());
}
},

__createLayout: function()
{
var s = this.scale, circles = this.circles, ctx = this.ctx;
for (var i = 0; i < circles.length; i++) {
var r = circles[i];
ctx.beginPath();
ctx.arc(250, 250, r, 0, Math.PI * 2, true);
ctx.lineWidth = (i == 4) ? 1/s : 0.3/s;
ctx.strokeStyle = '#8ce9ef';
ctx.stroke();
ctx.closePath();
}

for(var i = 0; i < 8; i++){
var r = circles[4], a = (Math.PI * i / 4) - Math.PI / 8;
ctx.beginPath();
ctx.moveTo(250,250);
ctx.lineTo((r * Math.cos(a)) + 250, (r * Math.sin(a)) + 250);
ctx.lineWidth = 0.3/s;
ctx.strokeStyle = '#8ce9ef';
ctx.stroke();
ctx.closePath();
}

var endGame = ccta_map.getInstance().__endGame, hubs = endGame.hubs, fortress = endGame.fortress;
var fortressX = fortress[0];
var fortressY = fortress[1];

var grd = ctx.createLinearGradient(fortressX, fortressY - 0.5, fortressX, fortressY + 0.5);
grd.addColorStop(0, 'rgba(200, 228, 228, 0.5)');
grd.addColorStop(1, 'rgba(170, 214, 118, 0.5)');
ctx.beginPath();
ctx.arc(fortressX - 0.2, fortressY - 0.2, 1, 0, Math.PI * 2, true);
ctx.fillStyle = grd;
ctx.lineWidth = 0.1;
ctx.strokeStyle = '#a5fe6a';
ctx.fill();
ctx.stroke();	
ctx.closePath();

for(var i = 0; i < hubs.length; i++)
{
var c = 'rgba(200, 228, 228, 0.5)', d = 'rgba(170, 214, 118, 0.5)', l = 1.3, b = 0.1;
var x = hubs[i][0];
var y = hubs[i][1];
var grd = ctx.createLinearGradient(x, y, x, y+l);
grd.addColorStop(0, c);
grd.addColorStop(1, d);
ctx.beginPath();
ctx.rect(x-b, y-b, l, l);
ctx.fillStyle = grd;
ctx.fill();
ctx.strokeStyle = '#a5fe6a';
ctx.lineWidth = b;
ctx.stroke();
ctx.closePath();
}

},

__createAlliance: function(name, data, type, color)
{
try
{
this.inProgress = true;
var colors = {
"bases": {"alliance":[["#86d3fb","#75b7d9"]], "owner":[["#ffc48b","#d5a677"]], "enemy":[["#ff8e8b","#dc7a78"],['#e25050','#cc2d2d'],['#93b7f8','#527ef2'],['#d389aa','#b14e69']], "nap":[["#ffffff","#cccccc"]], "selected":[["#ffe50e", "#d7c109"]], "ally":[["#6ce272", "#5fc664"],['#d4e17e','#b3ca47'],['#92f8f2','#52f2e8'],['#1cba1c','#108510']]},
"pois": [["#add2a8","#6db064"], ["#75b9da","#4282bd"], ["#abd2d6","#6bafb7"], ["#e2e0b7","#ccc880"], ["#e5c998","#d09e53"], ["#d4a297","#b35a54"], ["#afa3b1","#755f79"]]
};

var owner = ClientLib.Data.MainData.GetInstance().get_Player().name, ctx = this.ctx, factor = this.__factor;
var dop = this.__displayO, dmd = this.__displayM, root = this, s = this.scale;

var r = (s < 3) ? 0.65 : (s > 3) ? 0.35 : 0.5;

var createBase = function (x, y, bt, clr)
{
var c = colors.bases[bt][clr][0], d = colors.bases[bt][clr][1];
var grd=ctx.createLinearGradient(x, y-r, x, y+r);
grd.addColorStop(0, c);
grd.addColorStop(1, d);
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = grd;
ctx.fill();
ctx.lineWidth = 0.1;
ctx.strokeStyle = '#000000';
ctx.stroke();
ctx.closePath();
};

var createPoi = function(x, y, t)
{
var c = colors.pois[t][0], d = colors.pois[t][1];
var grd = ctx.createLinearGradient(x, y-r, x, y+r);
grd.addColorStop(0, c);
grd.addColorStop(1, d);
ctx.beginPath();
ctx.rect(x-r, y-r, r*2, r*2);
ctx.fillStyle = grd;
ctx.fill();
ctx.strokeStyle = "#000000";
ctx.lineWidth = 0.1;
ctx.stroke();
ctx.closePath();
};

if (dop != "pois")
{
for (var player in data.players) {
for (var i = 0; i < data.players[player].bases.length; i++){
var b = data.players[player].bases[i], pid = data.players[player].id;
if(dmd == "bases")
{
if (player == owner)
{
this.elements.push({"x":b[0],"y":b[1],"an":name,"pn":player,"bn":b[2],"bi":b[3],"ai":data.id,"pi":pid,"type":"base"});
this.locations.push([b[0]/factor, b[1]/factor]);
createBase(b[0], b[1], 'owner', 0);
}
}
else
{
this.elements.push({"x":b[0],"y":b[1],"an":name,"pn":player,"bn":b[2],"bi":b[3],"ai":data.id,"pi":pid,"type":"base"});
this.locations.push([b[0]/factor, b[1]/factor]);
(player == owner) ? createBase(b[0], b[1], 'owner', 0) : createBase(b[0], b[1], type, color);
}
}
}
}

if (dop != "bases")
{
for (var i = 0; i < data.pois.length; i++){
var x = data.pois[i].x, y = data.pois[i].y, t = data.pois[i].t, l = data.pois[i].l;
createPoi(x, y, t - 2);
this.elements.push({"x": x, "y": y, "an": name, "ai": data.id, "t": t, "l": l});
this.locations.push([x/factor, y/factor]);
}
}
this.inProgress = false;
}
catch(e)
{
console.log(e.toString());
}
},

__draggable: function(mask)
{
try
{
var start, end, initCoords = [], selectedBase = false, root = this, canvas = this.canvas, c = 0;
var factor = root.__factor;	

var displayBaseInfo = function()
{
try
{
if (!selectedBase || root.inProgress) return;
var base = [];
var pois = ['Tiberium', 'Crystal', 'Reactor', 'Tungesten', 'Uranium', 'Aircraft Guidance', 'Resonater'];
for ( var i in selectedBase)
{
var txt = "", val = "";
switch(i)
{
case "an": txt = "Alliance: "; val = selectedBase[i]; break;
case "bn": txt = "Base : "; val = selectedBase[i]; break;
case "pn": txt = "Player : "; val = selectedBase[i]; break;
case "l" : txt = "Level : "; val = selectedBase[i]; break;
case "t" : txt = "Type : "; val = pois[selectedBase[i] - 2]; break;
default : txt = false;
}
if(txt)
{
base.push([txt, val]);
}
root.__setInfo(base);
}
}
catch(e)
{
console.log(e.toString());
}
};

var onMapHover = function(event)
{
var loc = root.locations, elements = root.elements, coordsField = root.coordsField;
var getCoords = function()
{
var canvasRect = canvas.getBoundingClientRect();
var x = (event.pageX - canvasRect.left), y = (event.pageY - canvasRect.top);
return [x, y];
};

var coords = getCoords();
var x = coords[0] + canvas.offsetLeft, y = coords[1] + canvas.offsetTop;

if(Math.sqrt(Math.pow(x - 250, 2) + Math.pow(y - 250, 2)) > 242)
{
coordsField.setValue("");
return;
}

x = Math.round(coords[0] / (root.scale * factor)); root.__pointerX = x;
y = Math.round(coords[1] / (root.scale * factor)); root.__pointerY = y;

coordsField.setValue(x + ":" + y);

if (root.scale < 2 || root.inProgress) return;

for(var i = 0; i < loc.length; i++)
{
var elmX = loc[i][0], elmY = loc[i][1];
if ((x == elmX) && (y == elmY))
{
selectedBase = elements[i];
displayBaseInfo();
break;
}
else
{
selectedBase = false;
root.__setInfo(false);
}
}
};

var onMapDrag = function(event)
{
if (root.scale == 1 || root.inProgress) return;
var cx = canvas.offsetLeft, cy = canvas.offsetTop, mx = event.pageX, my = event.pageY;
var newX = cx + mx - initCoords[0], newY = cy + my - initCoords[1];
initCoords[0] = mx;
initCoords[1] = my;
canvas.style.top = newY + 'px';
canvas.style.left = newX + 'px';
};

var onMapWheel = function(event)
{
if (root.inProgress) return;
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
if((delta < 0 && root.scale <= 1) || (delta > 0 && root.scale >= 12)) return;
c += delta;
var str = ( Math.abs(c) % 3 == 0 ) ? ((delta < 0) ? 'down' : 'up') : false;
if(str) root.__scaleMap(str);
};

var onMapDown = function(event){
var x = event.pageX, y = event.pageY, t = new Date();
initCoords = [x,y];
start = t.getTime();
mask.removeEventListener('mousemove', onMapHover, false);
mask.addEventListener('mousemove', onMapDrag, false);
};

var onMapUp = function(event){
var x = event.pageX, y = event.pageY, t = new Date();
end = t.getTime();
initCoords = [x,y];
mask.removeEventListener('mousemove', onMapDrag, false);
mask.addEventListener('mousemove', onMapHover, false);
if (end - start < 150) webfrontend.gui.UtilView.centerCoordinatesOnRegionViewWindow(root.__pointerX, root.__pointerY);
};

var onMapOut = function(event){
mask.removeEventListener('mousemove', onMapDrag, false);
mask.addEventListener('mousemove', onMapHover, false);
};

mask.addEventListener('mouseup', onMapUp, false);
mask.addEventListener('mousedown', onMapDown, false);
mask.addEventListener('mousemove', onMapHover, false);
mask.addEventListener('mouseout', onMapOut, false);
mask.addEventListener('mousewheel', onMapWheel, false);
mask.addEventListener('DOMMouseScroll', onMapWheel, false);
}
catch(e)
{
console.log(e.toString());
}
},

__startRadarScan: function()
{
this.isRadarVisible = true;
var FRAMES_PER_CYCLE = 20, FRAMERATE = 20, RINGS = 6;
var canvas = this.canvas, ctx = this.ctx, canvassize = 400, animationframe = 0, root = this;
var ringsize = canvassize / (2 * RINGS + 1);
var radiusmax = ringsize / 2 + ringsize + (RINGS - 1) * ringsize;

function animateRadarFrame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
root.__createLayout();
var radius, alpha;
for (var ringno = 0; ringno < RINGS; ringno++)
{
radius = ringsize / 2 + (animationframe / FRAMES_PER_CYCLE) * ringsize + ringno * ringsize;
alpha = (radiusmax - radius) / radiusmax;
ctx.beginPath();
ctx.fillStyle = "rgba(92,178,112," + alpha + ")";
ctx.arc(250, 250, radius, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();
}

ctx.beginPath();
ctx.fillStyle = "rgb(100,194,122)";
ctx.arc(250, 250, ringsize / 2, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();

animationframe = (animationframe >= (FRAMES_PER_CYCLE - 1)) ? 0 : animationframe + 1;
}
this.__interval = setInterval(animateRadarFrame, 1000 / FRAMERATE);
},

__stopRadarScan: function()
{
if(!this.isRadarVisible) return;
clearInterval(this.__interval);
this.isRadarVisible = false;
this.__enablePanel();
},

__disablePanel: function()
{
this.inProgress = true;
for (var i = 0; i < this.panel.length; i++) this.panel[i].setEnabled(false);
},

__enablePanel: function()
{
for (var i = 0; i < this.panel.length; i++) if(i>1) this.panel[i].setEnabled(true);
},

__createIcon: function(color, width, height)
{
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;

var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.rect(0, 0, width, height);
ctx.fillStyle = color;
ctx.fill();
ctx.closePath();

var data = canvas.toDataURL("image/png");
return data;
},

__updateList: function()
{
var dm = this.__displayM;
this.__selectedA = null;
this.allianceList.removeAll();
var d = this.receivedData, root = this;
var colors = {"enemy":["#ff807d", "#a93939", "#739bf5", "#c26b89"], "ally": ["#3bbe5d", "#c4d663", "#73f5ed", "#169f16"], "nap": ["#ffffff"], "selected": ["#ffe50e"], "alliance": ["#75b7d9"], "owner": ["#ffc48b"]};
for (var i = 0; i < d.length; i++)
{
var name = d[i][0].name, type = d[i][1], aid = d[i][0].id, clr = d[i][2];
if((dm == "all") || (dm == "selected"))
{
var color = colors[type][clr];
var li = new qx.ui.form.ListItem(name, root.__createIcon(color, 10, 10), aid);
var tooltip = new qx.ui.tooltip.ToolTip(name + " - " + type, root.__createIcon(color, 15, 15));
li.setToolTip(tooltip);
this.allianceList.add(li);
}
else
{
if(type == "alliance")
{
var li = new qx.ui.form.ListItem(name, null, aid);
var tooltip = new qx.ui.tooltip.ToolTip(name + " - " + type, root.__createIcon(color, 15, 15));
li.setToolTip(tooltip);
this.allianceList.add(li);
break;
}
}
}
},

drawCanvas: function()
{
var dmd = this.__displayM, b = this.receivedData, list = this.allianceList;
var selected = (this.__selectedA != null && typeof this.__selectedA == 'number') ? this.__selectedA : false;
var mask = this.mask, n = this.scale, canvas = this.canvas, ctx = this.ctx;

this.elements = [];
this.locations = [];
this.__stopRadarScan();
canvas.width = n * 500;
canvas.height = n * 500;
ctx = canvas.getContext("2d");
ctx.scale(n, n);

this.__createLayout();

for (var i = 0; i < b.length; i++)
{
var name = b[i][0].name, data = b[i][0], type = b[i][1], aid = b[i][0].id, color = b[i][2];
if(((dmd == "alliance") || (dmd == "bases")) && (type == "alliance"))
{
this.__createAlliance(name, data, type, 0);
break;
}
if(dmd == "all")
{
if(selected && (aid == selected))
{
type = 'selected';
color = 0;
}
this.__createAlliance(name, data, type, color);
}
if((dmd == "selected") && selected && (aid == selected))
{
this.__createAlliance(name, data, type, color);
break;
}
}
},

__scaleMap: function(str)
{
try
{
var newScale = (str == 'up') ? this.scale + 2 : this.scale - 2;
if (newScale > 12 || newScale < 1 || this.inProgress) return;
var canvas = this.canvas, ctx = this.ctx;
var x = ((canvas.offsetLeft - 250) * newScale/this.scale) + 250,
y = ((canvas.offsetTop - 250) * newScale/this.scale) + 250;


Partager le fichier


Télécharger world map IG.user.js


Télécharger world map IG.user.js