forked from leo7044/CnC_TA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPvP_PvE_Player_Info_Mod.user.js
224 lines (206 loc) · 7.9 KB
/
PvP_PvE_Player_Info_Mod.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// ==UserScript==
// @name Tiberium Alliances PvP/PvE Player Info Mod
// @description Separates the number of bases destroyed into PvP and PvE in the Player Info window. Now also includes a tab showing all the POI the player is holding.
// @namespace player_info_mod
// @downloadURL https://raw.githubusercontent.com/leo7044/CnC_TA/master/PvP_PvE_Player_Info_Mod.user.js
// @updateURL https://raw.githubusercontent.com/leo7044/CnC_TA/master/PvP_PvE_Player_Info_Mod.user.js
// @include http*://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include http*://cncapp*.alliances.commandandconquer.com/*/index.aspx*
// @version 1.3.1
// @author KRS_L
// @contributor leo7044 (https://github.com/leo7044)
// ==/UserScript==
(function () {
var PlayerInfoMod_main = function () {
var playerInfoWindow = null;
var allianceInfoWindow = null;
var membersTable = null;
var general = null;
var pvpScoreLabel = null;
var pveScoreLabel = null;
var playerName = null;
var tabView = null;
var tableModel = null;
var baseCoords = null;
var rowData = null;
function createPlayerInfoMod() {
try {
console.log('Player Info Mod loaded');
var tr = qx.locale.Manager.tr;
playerInfoWindow = webfrontend.gui.info.PlayerInfoWindow.getInstance();
//allianceInfoWindow = webfrontend.gui.info.AllianceInfoWindow.getInstance();
//membersTable = allianceInfoWindow.getLayoutChildren()[1].getLayoutChildren()[0].getLayoutChildren()[1].getLayoutChildren()[1].getLayoutChildren()[0];
//membersTable.$$user_tableModel.setColumns
//membersTable.getTableColumnModel().setColumns
if (PerforceChangelist >= 436669) { // 15.3 patch
var eventType = "cellTap";
general = playerInfoWindow.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[1].getChildren()[0];
} else { //old
var eventType = "cellClick";
general = playerInfoWindow.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[1].getChildren()[0];
}
tabView = playerInfoWindow.getChildren()[0];
playerName = general.getChildren()[1];
var pvpLabel = new qx.ui.basic.Label("- PvP:");
pvpScoreLabel = new qx.ui.basic.Label("").set({
textColor: "text-value",
font: "font_size_13_bold"
});
general.add(pvpLabel, {
row: 3,
column: 3
});
general.add(pvpScoreLabel, {
row: 3,
column: 4
});
var pveLabel = new qx.ui.basic.Label("- PvE:");
pveScoreLabel = new qx.ui.basic.Label("").set({
textColor: "text-value",
font: "font_size_13_bold"
});
general.add(pveLabel, {
row: 4,
column: 3
});
general.add(pveScoreLabel, {
row: 4,
column: 4
});
var poiTab = new qx.ui.tabview.Page("POI");
poiTab.setLayout(new qx.ui.layout.Canvas());
poiTab.setPaddingTop(6);
poiTab.setPaddingLeft(8);
poiTab.setPaddingRight(10);
poiTab.setPaddingBottom(8);
tableModel = new webfrontend.data.SimpleColFormattingDataModel().set({
caseSensitiveSorting: false
});
tableModel.setColumns([tr("tnf:name"), tr("tnf:lvl"), tr("tnf:points"), tr("tnf:coordinates")], ["t", "l", "s", "c"]);
tableModel.setColFormat(3, "<div style=\"cursor:pointer;color:" + webfrontend.gui.util.BBCode.clrLink + "\">", "</div>");
var poiTable = new webfrontend.gui.widgets.CustomTable(tableModel);
poiTable.addListener(eventType, centerCoords, this);
var columnModel = poiTable.getTableColumnModel();
columnModel.setColumnWidth(0, 250);
columnModel.setColumnWidth(1, 80);
columnModel.setColumnWidth(2, 120);
columnModel.setColumnWidth(3, 120);
columnModel.setDataCellRenderer(3, new qx.ui.table.cellrenderer.Html());
columnModel.getDataCellRenderer(2).setUseAutoAlign(false);
poiTable.setStatusBarVisible(false);
poiTable.setColumnVisibilityButtonVisible(false);
poiTab.add(poiTable, {
left: 0,
top: 0,
right: 0,
bottom: 0
});
tabView.add(poiTab);
playerInfoWindow.addListener("close", onPlayerInfoWindowClose, this);
playerName.addListener("changeValue", onPlayerChanged, this);
} catch (e) {
console.log("createPlayerInfoMod: ", e);
}
}
function centerCoords(e) {
try {
var poiCoord = tableModel.getRowData(e.getRow())[3].split(":");
if (e.getColumn() == 3) webfrontend.gui.UtilView.centerCoordinatesOnRegionViewWindow(Number(poiCoord[0]), Number(poiCoord[1]));
} catch (e) {
console.log("centerCoords: ", e);
}
}
function onPlayerInfo(context, data) {
try {
pvpScoreLabel.setValue((data.bd - data.bde).toString());
pveScoreLabel.setValue(data.bde.toString());
var bases = data.c;
baseCoords = new Object;
for (var i in bases) {
var base = bases[i];
baseCoords[i] = new Object();
baseCoords[i]["x"] = base.x;
baseCoords[i]["y"] = base.y;
}
ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand("GetPublicAllianceInfo", {
id: data.a
}, phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, onAllianceInfo), null);
} catch (e) {
console.log("onPlayerInfo: ", e);
}
}
function onAllianceInfo(context, data) {
try {
rowData = [];
var pois = data.opois;
for (var i in pois) {
var poi = pois[i];
for (var j in baseCoords) {
var distanceX = Math.abs(baseCoords[j].x - poi.x);
var distanceY = Math.abs(baseCoords[j].y - poi.y);
if (distanceX > 2 || distanceY > 2) continue;
if (distanceX == 2 && distanceY == 2) continue;
var name = phe.cnc.gui.util.Text.getPoiInfosByType(poi.t).name;
var level = poi.l;
var score = ClientLib.Base.PointOfInterestTypes.GetScoreByLevel(poi.l);
var coords = phe.cnc.gui.util.Numbers.formatCoordinates(poi.x, poi.y);
rowData.push([name, level, score, coords]);
break;
}
}
tableModel.setData(rowData);
tableModel.sortByColumn(0, true);
} catch (e) {
console.log("onAllianceInfo: ", e);
}
}
function onPlayerChanged() {
try {
if (playerName.getValue().length > 0) {
ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand("GetPublicPlayerInfoByName", {
name: playerName.getValue()
}, phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, onPlayerInfo), null);
}
} catch (e) {
console.log("onPlayerChanged: ", e);
}
}
function onPlayerInfoWindowClose() {
try {
pvpScoreLabel.setValue("");
pveScoreLabel.setValue("");
tableModel.setData([]);
} catch (e) {
console.log("onPlayerInfoWindowClose: ", e);
}
}
function PlayerInfoMod_checkIfLoaded() {
try {
if (typeof qx !== 'undefined' && typeof qx.locale !== 'undefined' && typeof qx.locale.Manager !== 'undefined') {
if (ClientLib.Data.MainData.GetInstance().get_Alliance().get_FirstLeaders() !== null && ClientLib.Data.MainData.GetInstance().get_Alliance().get_FirstLeaders().l.length != 0) {
createPlayerInfoMod();
} else {
window.setTimeout(PlayerInfoMod_checkIfLoaded, 1000);
}
} else {
window.setTimeout(PlayerInfoMod_checkIfLoaded, 1000);
}
} catch (e) {
console.log("PlayerInfoMod_checkIfLoaded: ", e);
}
}
if (/commandandconquer\.com/i.test(document.domain)) {
window.setTimeout(PlayerInfoMod_checkIfLoaded, 1000);
}
}
try {
var PlayerInfoMod = document.createElement("script");
PlayerInfoMod.innerHTML = "(" + PlayerInfoMod_main.toString() + ")();";
PlayerInfoMod.type = "text/javascript";
if (/commandandconquer\.com/i.test(document.domain)) {
document.getElementsByTagName("head")[0].appendChild(PlayerInfoMod);
}
} catch (e) {
console.log("PlayerInfoMod: init error: ", e);
}
})();