-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRealmList.lua
369 lines (334 loc) · 11 KB
/
RealmList.lua
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
REALM_BUTTON_HEIGHT = 16;
MAX_REALMS_DISPLAYED = 18;
MAX_REALM_CATEGORY_TABS = 8;
function RealmList_OnLoad(self)
self:RegisterEvent("OPEN_REALM_LIST");
self.currentRealm = 0;
self.offset = 0;
end
function RealmList_OnEvent(self, event)
if ( event == "OPEN_REALM_LIST" ) then
if ( self:IsShown() ) then
RealmListUpdate();
else
self:Show();
end
end
end
function RealmListUpdate()
-- Just for the first time the frame is loaded
if ( not RealmList.selectedCategory ) then
RealmList.selectedCategory = 1;
end
-- Set the refresh timer
RealmList.refreshTime = RealmListUpdateRate();
-- Set up the category tabs
RealmList_UpdateTabs(GetRealmCategories());
local numRealms = GetNumRealms(RealmList.selectedCategory);
local name, numCharacters, invalidRealm, currentRealm, pvp, rp, load, locked;
local realmIndex;
local pvpText, loadText, isFull;
local major, minor, revision, build, type;
RealmListOkButton:Disable();
RealmListHighlight:Hide();
for i=1, MAX_REALMS_DISPLAYED, 1 do
realmIndex = RealmList.offset + i;
local button = _G["RealmListRealmButton"..i];
if ( realmIndex > numRealms ) then
button:Hide();
else
name, numCharacters, invalidRealm, realmDown, currentRealm, pvp, rp, load, locked, major, minor, revision, build, type = GetRealmInfo(RealmList.selectedCategory, realmIndex);
if ( not name ) then
button:Hide();
else
pvpText = _G["RealmListRealmButton"..i.."PVP"];
if ( pvp and rp ) then
pvpText:SetText(RPPVP_PARENTHESES);
pvpText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
elseif ( rp ) then
pvpText:SetText(RP_PARENTHESES);
pvpText:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
elseif ( pvp ) then
pvpText:SetText(PVP_PARENTHESES);
pvpText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
else
pvpText:SetText(GAMETYPE_NORMAL);
pvpText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
end
isFull = nil;
loadText = _G["RealmListRealmButton"..i.."Load"];
if ( realmDown ) then
loadText:SetText(REALM_DOWN);
loadText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
elseif ( locked ) then
loadText:SetText(REALM_LOCKED);
loadText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
elseif ( load == -3.0 ) then
loadText:SetText(LOAD_RECOMMENDED);
loadText:SetTextColor(BLUE_FONT_COLOR.r, BLUE_FONT_COLOR.g, BLUE_FONT_COLOR.b);
elseif ( load == -2.0 ) then
loadText:SetText(LOAD_NEW);
loadText:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
elseif ( load == 2.0 ) then
loadText:SetText(LOAD_FULL);
loadText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
isFull = 1;
elseif ( load > 0 ) then
loadText:SetText(LOAD_HIGH);
loadText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
elseif ( load < 0 ) then
loadText:SetText(LOAD_LOW);
loadText:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
else
loadText:SetText(LOAD_MEDIUM);
loadText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
end
if (major) then
button.major = major;
button.minor = minor;
button.revision = revision;
button.build = build;
button.type = type;
button:SetText(name.." ("..major.."."..minor.."."..revision..")");
else
button:SetText(name);
end
players = _G["RealmListRealmButton"..i.."Players"];
if ( numCharacters > 0 ) then
players:SetText("("..numCharacters..")");
else
players:SetText("");
end
if ( realmDown ) then
button:SetNormalFontObject(RealmDownNormal);
button:SetHighlightFontObject(RealmDownHighlight);
else
if ( invalidRealm ) then
button:SetNormalFontObject(RealmInvalidNormal);
button:SetHighlightFontObject(RealmInvalidHighlight);
else
if ( numCharacters > 0 ) then
button:SetNormalFontObject(RealmCharactersNormal);
button:SetHighlightFontObject(GlueFontHighlightLeft);
else
button:SetNormalFontObject(RealmNoCharactersNormal);
button:SetHighlightFontObject(GlueFontHighlightLeft);
end
end
end
button:Show();
button:SetID(realmIndex);
button.name = name;
if ( realmDown ) then
button:Disable();
else
button:Enable();
end
if ( RealmList.selectedName ) then
if ( name == RealmList.selectedName ) then
RealmList.currentRealm = realmIndex;
button:LockHighlight();
RealmListOkButton:Enable();
RealmListHighlight:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
-- If realm is full and the player has no chars on that server show a dialog
if ( isFull and numCharacters == 0 ) then
RealmList.showRealmIsFullDialog = 1;
else
RealmList.showRealmIsFullDialog = nil;
end
if ( realmDown ) then
RealmListHighlight:Hide();
RealmListOkButton:Disable();
else
RealmListHighlight:Show();
pvpText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
loadText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
RealmListOkButton:Enable();
if ( invalidRealm ) then
RealmListHighlightTexture:SetVertexColor(1.0, 0.1, 0.1);
else
if ( numCharacters > 0 ) then
RealmListHighlightTexture:SetVertexColor(0.1, 1.0, 0.1);
else
RealmListHighlightTexture:SetVertexColor(1.0, 0.78, 0.0);
end
end
end
else
button:UnlockHighlight();
end
else
if ( currentRealm == 1 ) then
RealmList.currentRealm = realmIndex;
button:LockHighlight();
RealmListHighlight:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
if ( realmDown ) then
RealmListHighlight:Hide();
RealmListOkButton:Disable();
else
RealmListHighlight:Show();
pvpText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
loadText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
RealmListOkButton:Enable();
if ( invalidRealm ) then
RealmListHighlightTexture:SetVertexColor(1.0, 0.1, 0.1);
else
if ( numCharacters > 0 ) then
RealmListHighlightTexture:SetVertexColor(0.1, 1.0, 0.1);
else
RealmListHighlightTexture:SetVertexColor(1.0, 0.78, 0.0);
end
end
end
else
button:UnlockHighlight();
end
end
end
end
end
RealmList.selectedName = nil;
-- ScrollFrame stuff
GlueScrollFrame_Update(RealmListScrollFrame, numRealms, MAX_REALMS_DISPLAYED, REALM_BUTTON_HEIGHT, RealmListHighlight, 557, 587);
end
function RealmList_UpdateTabs(...)
local numTabs = select("#", ...);
local tab;
for i=1, MAX_REALM_CATEGORY_TABS do
tab = _G["RealmListTab"..i];
if ( not tab ) then
tab = CreateFrame("Button", "RealmListTab"..i, RealmListBackground, "RealmListTabButtonTemplate");
tab:SetID(i);
tab:SetPoint("LEFT", "RealmListTab"..(i-1), "RIGHT", -15, 0);
end
tab.disabled = nil;
if ( numTabs == 1 ) then
tab:Hide();
elseif ( i <= numTabs ) then
tab:SetText(select(i, ...));
GlueTemplates_TabResize(0, tab);
tab:Show();
if (IsInvalidTournamentRealmCategory(i)) then
tab:SetDisabledFontObject("GlueFontDisableSmall");
tab.disabled = true;
else
tab:SetDisabledFontObject("GlueFontHighlightSmall");
end
else
tab:Hide();
end
end
GlueTemplates_SetNumTabs(RealmList, numTabs);
if ( not GlueTemplates_GetSelectedTab(RealmList) ) then
GlueTemplates_SetTab(RealmList, 1);
end
end
function RealmList_OnKeyDown(key)
if ( key == "ESCAPE" ) then
RealmList_OnCancel();
elseif ( key == "ENTER" ) then
RealmList_OnOk();
elseif ( key == "PRINTSCREEN" ) then
Screenshot();
end
end
function RealmList_OnOk()
RealmList:Hide();
-- If trying to join a Full realm then popup a dialog
if ( RealmList.showRealmIsFullDialog ) then
GlueDialog_Show("REALM_IS_FULL");
return;
end
if ( RealmList.currentRealm > 0 ) then
ChangeRealm(RealmList.selectedCategory , RealmList.currentRealm);
end
end
function RealmList_OnCancel()
RealmList:Hide();
RealmListDialogCancelled();
local serverName, isPVP, isRP, isDown = GetServerName();
if ( (GetNumRealms(RealmList.selectedCategory) == 0) or (isDown) ) then
SetGlueScreen("realmwizard");
end
end
function RealmSelectButton_OnClick(self, id)
if ( IsInvalidLocale( RealmList.selectedCategory ) ) then
--Display popup explaining locale specific realms
GlueDialog_Show("REALM_LOCALE_WARNING");
else
RealmList.refreshTime = RealmListUpdateRate();
RealmList.currentRealm = id;
RealmList.selectedName = self.name;
RealmListUpdate();
end
end
function RealmSelectButton_OnDoubleClick(self, id)
if ( IsInvalidLocale( RealmList.selectedCategory ) ) then
--Display popup explaining locale specific realms
GlueDialog_Show("REALM_LOCALE_WARNING");
else
RealmList.currentRealm = id;
RealmList.selectedName = self.name;
RealmList_OnOk();
end
end
function RealmListScrollFrame_OnVerticalScroll(self, offset)
RealmList.refreshTime = RealmListUpdateRate();
local scrollbar = _G[self:GetName().."ScrollBar"];
scrollbar:SetValue(offset);
RealmList.offset = floor((offset / REALM_BUTTON_HEIGHT) + 0.5);
RealmListUpdate();
end
function RealmList_OnShow(self)
RealmListUpdate();
self.refreshTime = RealmListUpdateRate();
local selectedCategory = GetSelectedCategory();
if ( selectedCategory == 0 ) then
selectedCategory = 1;
end
local button = _G["RealmListTab"..selectedCategory];
if ( button ) then
RealmListTab_OnClick(button);
GlueTemplates_SetTab(RealmList, selectedCategory);
end
end
function RealmList_OnHide()
CancelRealmListQuery();
end
function RealmList_OnUpdate(self, elapsed)
if ( self.refreshTime ) then
self.refreshTime = self.refreshTime - elapsed;
if ( self.refreshTime <= 0 ) then
self.refreshTime = nil;
RequestRealmList();
end
end
-- Account Msg stuff
if ( (ACCOUNT_MSG_NUM_AVAILABLE > 0) and not GlueDialog:IsShown() ) then
if ( ACCOUNT_MSG_HEADERS_LOADED ) then
if ( ACCOUNT_MSG_BODY_LOADED ) then
local dialogString = AccountMsg_GetHeaderSubject( ACCOUNT_MSG_CURRENT_INDEX ).."\n\n"..AccountMsg_GetBody();
GlueDialog_Show("ACCOUNT_MSG", dialogString);
end
end
end
end
function RealmListTab_OnClick(tab)
if ( tab.disabled ) then
if ( IsTournamentRealmCategory(tab:GetID()) ) then
--Display popup explaining tournament realms
-- RealmHelpFrame:Show();
GlueDialog_Show("REALM_TOURNAMENT_WARNING");
end
local button = _G["RealmListTab"..RealmList.selectedCategory];
if ( button ) then
button:Click();
end
return;
end
RealmList.selectedCategory = tab:GetID();
RealmListUpdate();
end
function RealmHelpText_OnShow(self)
self:SetText("<html><body><p>" .. string.format(REALM_HELP_FRAME_TEXT, REALM_HELP_FRAME_URL) .. "</p></body></html>");
end