// ==UserScript==
// @name C&C Tiberium Alliances Map (Eistee)
// @description Shows you the region map
// @author Eistee
// @version 13.08.25
// @namespace http*://*.alliances.commandandconquer.com/*
// @include http*://*.alliances.commandandconquer.com/*
// @icon http://s3.amazonaws.com/uso_ss/icon/176516/large.png
// @grant GM_getValue
// @grant GM_log
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
/*
Bugfix for DR01 Script: C&C: Tiberium Alliances Map
Version: 1.6.9
http://userscripts.org/scripts/show/152801
__________________________________________________
based on Tiberium Alliances Map (Nolana Kane) v1.8
https://userscripts.org/scripts/show/135955
contributors:
KSX https://userscripts.org/scripts/show/149093
777lexa777 https://userscripts.org/scripts/show/149350
*/
(function () {
var TAMap_mainFunction = function () {
function createMapTweak() {
var TAMap = {};
qx.Class.define("TAMap", {
type : "singleton",
extend : qx.core.Object,
members : {
version : "13.08.25",
alliances : null,
alliancesAreLoaded : false,
buttonMap : null,
blurInterval : null,
drawingNow : false,
initZoom : null,
isInitialized : false,
mapBox : null,
mapCanvas : null,
canvasElement : null,
canvasWidth : null,
canvasHeight : null,
mapMouseCanvas : null,
mapMouseWidget : null,
scroll : null,
scrollWidget : null,
settingsWnd : null,
mapUpdateTimer : null,
relations : {
enemies : null,
enemiesById : null,
enemyCoords : [],
allies : null,
nap : null
},
swObj : {
isLoaded : false,
refreshIcon : null,
allianceSelect : null,
allianceListItem : {},
poiSelect : null,
obfSectorName : null,
obfAllianceList : null,
obfAllianceId : null,
obfAllianceName : null,
settingFields : {},
labels : {},
chkBoxFields : {},
coordButtons : {}
},
line : {
1 : {
x : null,
y : null
},
2 : {
x : null,
y : null
}
},
visOptions : null,
visOpt_DEFAULTS : {
selectedAllianceId : -1,
selectedAllianceName : "<< None >>",
poi : -2,
vpWidth : null,
vpHeight : null,
showEnemies : true,
showEnemyRange : true,
mapBoxBounds : {
height : 500,
top : 33,
left : 129,
width : 500
},
settingsWndBounds : {
height : 646,
top : 48,
left : 615,
width : 524
},
chk : {
showAlliancePois : false,
showOwnCities : true,
showSectionFrame : true,
showBorderLine1 : false,
showBorderLine2 : false,
fadeMap : true
},
settingsPanel : {
playerColor : "#7F0", // type = 1
baseColor : "#550", // type = 2
campColor : "midnightblue", // type = 3, CampType=2
outpostColor : "royalblue", // type = 3, CampType=3
poiColor : "orange", // type = 4, POIType != 0
tunnelColor : "forestgreen", // type = 4, POIType = 0
enemyBaseColor : "red",
allianceTerrainColor : "rgba(255,255,255,0.5)",
ownBaseColor : "rgba(0,255,0,0.5)",
highlightColor : "rgba(200,255,200,1)",
line1start : "800:796",
line1end : "1387:921",
line1color : "rgba(0,255,0,0.3)",
line2start : "800:796",
line2end : "1410:830",
line2color : "rgba(255,255,0,0.3)",
zoomFactor : 3
}
},
initialize : function () {
console.log("\nTAMap v" + this.version + ": Loaded");
this.init_vars();
this.init_menuButton();
this.init_mapBox();
this.init_scroll();
this.init_settingsWnd();
this.init_settingsButton();
this.init_mapBox_listeners();
this.isInitialized = true;
},
init_vars : function () {
// cloning
var vTemp = JSON.parse(JSON.stringify(this.visOpt_DEFAULTS));
if (localStorage) {
var sto = localStorage.getItem("TAMapStorage");
if (sto != null) {
// check visOptions integrity against DEFAULTS
this.visOptions = JSON.parse(sto);
for (var i in vTemp) {
if (typeof this.visOptions[i] == "object") {
for (var j in vTemp[i]) {
if (typeof this.visOptions[i][j] == "undefined") {
console.log("\nSolving inconsistency with visOptions." + i + "." + j + "\n");
this.visOptions[i][j] = vTemp[i][j];
}
}
} else if (typeof this.visOptions[i] == "undefined") {
console.log("Solving inconsistency with visOptions." + i);
this.visOptions[i] = vTemp[i];
}
}
} else {
this.visOptions = vTemp;
}
}
this.initZoom = this.visOptions.settingsPanel.zoomFactor;
this.worldHeight = ClientLib.Data.MainData.GetInstance().get_World().get_WorldHeight();
this.worldWidth = ClientLib.Data.MainData.GetInstance().get_World().get_WorldWidth();
this.canvasHeight = this.worldHeight * this.initZoom;
this.canvasWidth = this.worldWidth * this.initZoom;
},
init_menuButton : function () {
this.buttonMap = new qx.ui.menu.Button("Map");
this.buttonMap.addListener("click", this.toggleMap, this);
var submenu = new qx.ui.menu.Menu();
submenu.add(this.buttonMap);
var bntScript = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_MENU).getScriptsButton();
bntScript.Add("Map", null, submenu);
},
init_mapBox : function () {
// The Map window
this.mapBox = new qx.ui.window.Window("Mini-Map [v" + this.version + "]");
this.mapBox.setPadding(1);
this.mapBox.setLayout(new qx.ui.layout.Grow());
// this.mapBox.setLayout(new qx.ui.layout.VBox());
this.mapBox.setShowMaximize(false);
this.mapBox.setShowMinimize(false);
this.mapBox.moveTo(this.visOptions.mapBoxBounds.left, this.visOptions.mapBoxBounds.top);
this.mapBox.setHeight(this.visOptions.mapBoxBounds.height);
this.mapBox.setWidth(this.visOptions.mapBoxBounds.width);
this.mapBox.setMinWidth(10);
this.mapBox.setMinHeight(10);
this.mapBox.setBackgroundColor("black");
},
init_scroll : function () {
var cw = this.canvasWidth;
var ch = this.canvasHeight;
this.scroll = new qx.ui.container.Scroll();
//this.scroll.removeListener("mousewheel", this.scroll._onMouseWheel, this.scroll);
this.scroll.addListener("mousewheel", function (evt) {
console.log(evt.getWheelDelta());
}, this);
this.mapBox.add(this.scroll);
this.scrollWidget = new qx.ui.core.Widget();
this.scrollWidget.setMinHeight(ch);
this.scrollWidget.setMinWidth(cw);
this.scrollWidget.setHeight(ch);
this.scrollWidget.setWidth(cw);
this.scroll.add(this.scrollWidget);
this.canvasElement = new qx.html.Element("canvas", null, {
id : "map",
width : cw,
height : ch
});
this.canvasElement.addListener("appear", function () {
//console.log("appeared:" + this.canvasElement.getDomElement());
this.createMapCanvas();
}, this);
this.scrollWidget.getContentElement().add(this.canvasElement);
},
init_settingsWnd : function () {
try {
/* select box for alliances */
var selectBox = new qx.ui.form.SelectBox();
var _this = this;
selectBox.addListener("changeSelection", function (e) {
try {
if (e != null && e.getData() && e.getData().length > 0) {
var mod = e.getData()[0].getModel();
console.log("Alliance selected: ");
console.log(mod);
console.log("e.getData()[0]: ");
console.log(e.getData()[0]);
this.visOptions.selectedAllianceId = mod; // alliance ID or -1 for none
console.log("saved: " + mod);
this.visOptions.selectedAllianceName = this.swObj.allianceListItem[mod].getLabel();
if (this.visOptions.selectedAllianceId != -1) {
this.swObj.chkBoxFields.showAlliancePois.setEnabled(true);
}
this.saveOptions();
this.updateMap();
}
} catch (err) {
console.log("alliance changeSelection error:");
console.log(err);
}
}, this);
this.swObj.allianceSelect = selectBox;
// this.mapBox.add(selectBox);
/* Select box for POI Type */
selectBox = new qx.ui.form.SelectBox();
var currentSelection = this.visOptions.poi || -2;
var makePoiItem = function (model, name) {
var item = new qx.ui.form.ListItem(name, null, model);
selectBox.add(item);
if (currentSelection == model) {
selectBox.setSelection([item]);
}
}
FPOI = ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType;
makePoiItem(-2, "<< All >>");
makePoiItem(-1, "<< None >>");
makePoiItem(FPOI.TiberiumMine, "Tiberium");
makePoiItem(FPOI.CrystalMine, "Crystal");
makePoiItem(FPOI.PowerVortex, "Reactor");
makePoiItem(FPOI.Infantery, "Tungsten INF");
makePoiItem(FPOI.Vehicle, "Uranium VEH");
makePoiItem(FPOI.Air, "Aircraft");
makePoiItem(FPOI.Defense, "Resonator DEF");
//makePoiItem(FPOI.TunnelExit,"Tunnel Exit");
/* ClientLib.Base.EPOIType is not consistent with ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType
makePoiItem(ClientLib.Base.EPOIType.AirBonus, "Aircraft GNT (Off Air)");
makePoiItem(ClientLib.Base.EPOIType.CrystalBonus, "Crystal CNH");
makePoiItem(ClientLib.Base.EPOIType.DefenseBonus, "Resonator NT (Def)");
makePoiItem(ClientLib.Base.EPOIType.InfanteryBonus, "Tungsten C (Off Inf)");
makePoiItem(ClientLib.Base.EPOIType.PowerBonus, "Reactor (Power Bonus)");
makePoiItem(ClientLib.Base.EPOIType.TiberiumBonus, "Tiberium CN");
makePoiItem(ClientLib.Base.EPOIType.VehicleBonus, "Uranium C (Off Vehicles)");
*/
selectBox.addListener("changeSelection", function (e) {
try {
if (e != null && e.getData() && e.getData().length > 0) {
console.log("POI selected " + e.getData()[0].getModel());
_this.visOptions.poi = e.getData()[0].getModel(); // POI ID or -2 for all
this.saveOptions();
this.updateMap();
}
} catch (err) {
console.log(err);
}
}, this);
this.swObj.poiSelect = selectBox;
/* Settings Window */
this.settingsWnd = new qx.ui.window.Window("Map Settings");
this.settingsWnd.setPadding(10);
//this.mapBox.setLayout(new qx.ui.layout.Grow());
var layout = new qx.ui.layout.Grid();
layout.setSpacing(5);
layout.setColumnAlign(0, "right", "center");
layout.setColumnAlign(1, "left", "center");
layout.setColumnAlign(2, "left", "center");
layout.setColumnAlign(3, "right", "center");
layout.setColumnAlign(4, "left", "center");
this.settingsWnd.setLayout(layout);
this.settingsWnd.setShowMaximize(false);
this.settingsWnd.setShowMinimize(false);
this.settingsWnd.moveTo(this.visOptions.settingsWndBounds.left, this.visOptions.settingsWndBounds.top);
this.settingsWnd.setHeight(this.visOptions.settingsWndBounds.height);
this.settingsWnd.setWidth(this.visOptions.settingsWndBounds.width);
this.settingsWnd.setMinWidth(10);
this.settingsWnd.setMinHeight(10);
this.settingsWnd.addListener("close", function () {
this.visOptions.settingsWndBounds = this.settingsWnd.getBounds();
this.saveOptions();
}, this);
/* Reset Button */
var resetAllOptions = new qx.ui.form.Button("Full Reset");
resetAllOptions.set({
appearance : "button-text-small",
toolTipText : '<div style="color:#F22">Reset All options to default</div>',
});
resetAllOptions.addListener("click", function () {
if (confirm("Are you sure? This will return all settings to default.")) {
if (isNaN(this.visOptions.settingsPanel.zoomFactor)) this.visOptions.settingsPanel.zoomFactor = 3;
this.visOptions = JSON.parse(JSON.stringify(this.visOpt_DEFAULTS));
this.saveOptions();
for (var option in this.visOptions.chk) {
//console.log("this.visOptions.chk." + option + " == " + this.visOptions.chk[option]);
if (this.swObj.chkBoxFields[option]) {
this.swObj.chkBoxFields[option].setValue(this.visOptions.chk[option]);
} else {
console.log(option + " ::: chkBoxFields does not exist.")
}
}
for (var option in this.visOptions.settingsPanel) {
if (option == "chk") {
//do nothing
} else if (this.swObj.settingFields[option]) {
this.swObj.settingFields[option].setValue(String(this.visOptions.settingsPanel[option]));
} else {
console.log(option + " :: settingFields does not exist.")
}
}
this.updateMap();
this.scrollMapBox(false);
}
}, this);
this.settingsWnd.add(resetAllOptions, {
row : 14,
column : 4
});
this.makeLbl("- Highlight -", 0, 0);
this.makeLbl("Alliance POIs:", 1, 0);
this.settingsWnd.add(this.swObj.allianceSelect, { row : 1, column : 1 });
this.refreshIcon = new qx.ui.basic.Image("FactionUI/icons/icon_refresh_funds.png");
this.settingsWnd.add(this.refreshIcon, { row : 1,column : 2 });
this.refreshIcon.addListener("click", function () {
this.populateAllianceSelect();
}, this);
this.makeLbl("POIs:", 2, 0);
this.settingsWnd.add(this.swObj.poiSelect, {
row : 2,
column : 1
});
this.makeLbl("Alliance POIs:", 3, 0);
/* Checkbox for alliance POIs */
this.makeCheckbox("showAlliancePois",3,1);
if (this.visOptions.selectedAllianceId == -1) {
this.swObj.chkBoxFields.showAlliancePois.setEnabled(false);
}
this.makeLbl("Own Cities:", 4, 0);
/* Checkbox for own bases */
this.makeCheckbox("showOwnCities",4,1);
this.makeLbl("Viewport Frame:", 5, 0);
/* Checkbox for showSectionFrame */
this.makeCheckbox("showSectionFrame",5,1);
bt = new qx.ui.basic.Label("- Colors -").set({
value : '<a href="http://www.w3schools.com/html/html_colornames.asp" style="font-size:16px;font-weight:bold;color:orange" target="_blank">- Colors -</a>',
rich : true,
selectable : true
});
this.settingsWnd.add(bt, {
row : 6,
column : 1,
});
// bt.addListener("click", function() { window.open("http://www.w3schools.com/html/html_colornames.asp") });
this.makeLbl("Alliance Terrain:", 7, 0);
this.makeTxt("allianceTerrainColor", 7, 1);
this.makeLbl("Forg. Base:", 8, 0);
this.makeTxt("baseColor", 8, 1);
this.makeLbl("Camp:", 9, 0);
this.makeTxt("campColor", 9, 1);
this.makeLbl("Player:", 10, 0);
this.makeTxt("playerColor", 10, 1);
this.makeLbl("Enemy:", 11, 0);
this.makeTxt("enemyBaseColor", 11, 1);
//this.swObj.settingFields.enemyBaseColor.setEnabled(false);
this.makeLbl("Outpost:", 12, 0);
this.makeTxt("outpostColor", 12, 1);
this.makeLbl("POI:", 13, 0);
this.makeTxt("poiColor", 13, 1);
this.makeLbl("Tunnel:", 14, 0);
this.makeTxt("tunnelColor", 14, 1);
this.makeLbl("Own Base:", 15, 0);
this.makeTxt("ownBaseColor", 15, 1);
//this.swObj.settingFields.ownBaseColor.setEnabled(false);
this.makeLbl("Highlight:", 16, 0);
this.makeTxt("highlightColor", 16, 1);
//this.swObj.settingFields.highlightColor.setEnabled(false);
/* Line Options */
this.makeLbl(",.-^-.,", 0, 2, "'-.,.-'", "green");
this.makeLbl("- Line -", 0, 3);
this.makeLbl("Show Line", 1, 3);
/* Checkbox for showBorderLine1 */
this.makeCheckbox("showBorderLine1",1,4);
this.makeLbl("Line Start:", 2, 3);
this.makeTxt("line1start", 2, 4);
this.makeCoordsSelectionButton("line1start", 2, 5, "\u2607");
this.makeLbl("Line End:", 3, 3);
this.makeTxt("line1end", 3, 4);
this.makeCoordsSelectionButton("line1end", 3, 5, "\u2613");
this.makeLbl("Line 1 Color:", 4, 3);
this.makeTxt("line1color", 4, 4);
this.makeLbl("Show Line 2", 5, 3);
/* Checkbox for showBorderLine2 */
this.makeCheckbox("showBorderLine2",5,4);
this.makeLbl("Line Start:", 6, 3);
this.makeTxt("line2start", 6, 4);
this.makeCoordsSelectionButton("line2start", 6, 5, "\u2607");
this.makeLbl("Line End:", 7, 3);
this.makeTxt("line2end", 7, 4);
this.makeCoordsSelectionButton("line2end", 7,