-
Notifications
You must be signed in to change notification settings - Fork 2
/
WarChiefs_-_Tiberium_Alliances_Sector_HUD.user.js
160 lines (160 loc) · 6.12 KB
/
WarChiefs_-_Tiberium_Alliances_Sector_HUD.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// ==UserScript==
// @name WarChiefs - Tiberium Alliances Sector HUD
// @description Displays a tiny HUD with the Sector you are viewing.
// @author Eistee
// @version 13.12.18
// @namespace https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @icon http://eistee82.github.io/ta_simv2/icon.png
// @updateURL https://github.com/Eistee82/CNCTA/raw/master/WarChiefs_-_Tiberium_Alliances_Sector_HUD.user.js
// @downloadURL https://github.com/Eistee82/CNCTA/raw/master/WarChiefs_-_Tiberium_Alliances_Sector_HUD.user.js
// ==/UserScript==
/**
* License: CC-BY-NC-SA 3.0
*/
(function () {
var injectFunction = function () {
function createClasses() {
qx.Class.define("SectorHUD", {
type: "singleton",
extend: qx.core.Object,
construct: function () {
this.SectorText = new qx.ui.basic.Label("").set({
textColor : "#FFFFFF",
font : "font_size_11"
});
var HUD = new qx.ui.container.Composite(new qx.ui.layout.HBox()).set({
decorator : new qx.ui.decoration.Background().set({
backgroundRepeat : "no-repeat",
backgroundImage : "webfrontend/ui/menues/notifications/bgr_ticker_container.png",
backgroundPositionX : "center"
}),
padding : 2,
opacity: 0.8
});
HUD.add(this.SectorText);
HUD.addListener("click", function (e) {
if (e.getButton() == "left") this.paste_Coords();
if (e.getButton() == "right") this.jump_Coords();
}, this);
this.__refresh = false;
qx.core.Init.getApplication().getDesktop().add(HUD, {left: 128, top: 0});
phe.cnc.Util.attachNetEvent(ClientLib.Vis.VisMain.GetInstance().get_Region(), "PositionChange", ClientLib.Vis.PositionChange, this, this._update);
},
destruct: function () {},
members: {
__refresh: null,
SectorText: null,
get_SectorText: function (i) {
var qxApp = qx.core.Init.getApplication();
switch (i) {
case 0:
return qxApp.tr("tnf:south abbr");
case 1:
return qxApp.tr("tnf:southwest abbr");
case 2:
return qxApp.tr("tnf:west abbr");
case 3:
return qxApp.tr("tnf:northwest abbr");
case 4:
return qxApp.tr("tnf:north abbr");
case 5:
return qxApp.tr("tnf:northeast abbr");
case 6:
return qxApp.tr("tnf:east abbr");
case 7:
return qxApp.tr("tnf:southeast abbr");
}
},
get_SectorNo: function (x, y) {
var WorldX2 = Math.floor(ClientLib.Data.MainData.GetInstance().get_Server().get_WorldWidth() / 2),
WorldY2 = Math.floor(ClientLib.Data.MainData.GetInstance().get_Server().get_WorldHeight() / 2),
SectorCount = ClientLib.Data.MainData.GetInstance().get_Server().get_SectorCount(),
WorldCX = (WorldX2 - x),
WorldCY = (y - WorldY2),
WorldCa = ((Math.atan2(WorldCX, WorldCY) * SectorCount) / 6.2831853071795862) + (SectorCount + 0.5);
return (Math.floor(WorldCa) % SectorCount);
},
get_Coords: function () {
var Region = ClientLib.Vis.VisMain.GetInstance().get_Region();
GridWidth = Region.get_GridWidth(),
GridHeight = Region.get_GridHeight(),
RegionPosX = Region.get_PosX(),
RegionPosY = Region.get_PosY(),
ViewWidth = Region.get_ViewWidth(),
ViewHeight = Region.get_ViewHeight(),
ZoomFactor = Region.get_ZoomFactor(),
ViewCoordX = Math.floor((RegionPosX + ViewWidth / 2 / ZoomFactor) / GridWidth - 0.5),
ViewCoordY = Math.floor((RegionPosY + ViewHeight / 2 / ZoomFactor) / GridHeight - 0.5);
return {X: ViewCoordX, Y: ViewCoordY};
},
paste_Coords: function(){
var Coords = this.get_Coords(),
input = qx.core.Init.getApplication().getChat().getChatWidget().getEditable(),
inputDOM = input.getContentElement().getDomElement(),
text = [];
text.push(inputDOM.value.substring(0, inputDOM.selectionStart));
text.push("[coords]" + Coords.X + ':' + Coords.Y + "[/coords]");
text.push(inputDOM.value.substring(inputDOM.selectionEnd, inputDOM.value.length));
input.setValue(text.join(' '));
},
jump_Coords: function(){
var coords = prompt("Jump to Coords:");
if (coords) {
coords.replace(/(\[coords\])?([#])?(\d{1,4})\D(\d{1,4})(\D\w+)?(\[\/coords\])?/gi, function () {
if (arguments.length >= 5) {
ClientLib.Vis.VisMain.GetInstance().get_Region().CenterGridPosition(parseInt(arguments[3], 10), parseInt(arguments[4], 10));
}
});
}
},
_update: function () {
if (this.__refresh === false) {
this.__refresh = true;
setTimeout(this.__update.bind(this), 500);
}
},
__update: function () {
var Coords = this.get_Coords();
this.SectorText.setValue(Coords.X + ":" + Coords.Y + " [" + this.get_SectorText(this.get_SectorNo(Coords.X, Coords.Y)) + "]");
this.__refresh = false;
}
}
});
}
function waitForGame() {
try {
if (typeof qx !== "undefined" && typeof qx.core !== "undefined" && typeof qx.core.Init !== "undefined" && typeof ClientLib !== "undefined" && typeof phe !== "undefined") {
var app = qx.core.Init.getApplication();
if (app.initDone === true) {
try {
console.time("loaded in");
createClasses();
SectorHUD.getInstance();
console.group("WarChiefs - Sector HUD");
console.timeEnd("loaded in");
console.groupEnd();
} catch (e) {
console.group("WarChiefs - Sector HUD");
console.error("Error in waitForGame", e);
console.groupEnd();
}
} else
window.setTimeout(waitForGame, 1000);
} else {
window.setTimeout(waitForGame, 1000);
}
} catch (e) {
console.group("WarChiefs - Sector HUD");
console.error("Error in waitForGame", e);
console.groupEnd();
}
}
window.setTimeout(waitForGame, 1000);
};
var script = document.createElement("script");
var txt = injectFunction.toString();
script.innerHTML = "(" + txt + ")();";
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
})();