forked from fs86/LFG_MatchMaker_TBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLFGMM_PopupWindow.lua
393 lines (299 loc) · 11.2 KB
/
LFGMM_PopupWindow.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
--[[
LFG MatchMaker - Addon for World of Warcraft.
Version: 1.0.9
URL: https://github.com/AvilanHauxen/LFG_MatchMaker
Copyright (C) 2019-2020 L.I.R.
This file is part of 'LFG MatchMaker' addon for World of Warcraft.
'LFG MatchMaker' is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
'LFG MatchMaker' is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 'LFG MatchMaker'. If not, see <https://www.gnu.org/licenses/>.
]]--
------------------------------------------------------------------------------------------------------------------------
-- POPUP WINDOW
------------------------------------------------------------------------------------------------------------------------
function LFGMM_PopupWindow_Initialize()
LFGMM_PopupWindow:RegisterForDrag("LeftButton");
LFGMM_PopupWindow:SetScript("OnDragStart", LFGMM_PopupWindow.StartMoving);
LFGMM_PopupWindow:SetScript("OnDragStop", LFGMM_PopupWindow.StopMovingOrSizing);
LFGMM_PopupWindow:SetScript("OnShow", function() PlaySound(SOUNDKIT.IG_PLAYER_INVITE); end);
LFGMM_PopupWindow_WhisperButton:SetScript("OnClick", LFGMM_PopupWindow_WhisperButton_OnClick);
LFGMM_PopupWindow_IgnoreButton:SetScript("OnClick", LFGMM_PopupWindow_IgnoreButton_OnClick);
LFGMM_PopupWindow_WhoButton:SetScript("OnClick", LFGMM_PopupWindow_WhoButton_OnClick);
LFGMM_PopupWindow_InviteButton:SetScript("OnClick", LFGMM_PopupWindow_InviteButton_OnClick);
LFGMM_PopupWindow_RequestInviteButton:SetScript("OnClick", LFGMM_PopupWindow_RequestInviteButton_OnClick);
LFGMM_PopupWindow_SkipWaitButton:SetScript("OnClick", LFGMM_PopupWindow_SkipWaitButton_OnClick);
LFGMM_PopupWindow_CloseButton:SetScript("OnClick", LFGMM_PopupWindow_CloseButton_OnClick);
LFGMM_PopupWindow.UpdateAgeTimerLock = false;
LFGMM_PopupWindow.UpdateWaitCountdownLock = false;
end
function LFGMM_PopupWindow_ShowForMatch(message)
if (LFGMM_PopupWindow:IsVisible()) then
return;
end
LFGMM_PopupWindow.Type = "MATCH";
LFGMM_PopupWindow.Message = message;
-- Title and buttons
if (message.Type == "LFG") then
LFGMM_PopupWindow_Title:SetText("Player found!");
LFGMM_PopupWindow_RequestInviteButton:Hide();
LFGMM_PopupWindow_InviteButton:Show();
elseif (message.Type == "LFM") then
LFGMM_PopupWindow_Title:SetText("Group found!");
LFGMM_PopupWindow_RequestInviteButton:Show();
LFGMM_PopupWindow_InviteButton:Hide();
else
LFGMM_PopupWindow_Title:SetText("Possible match found!");
if (LFGMM_DB.SEARCH.LFM.Running) then
LFGMM_PopupWindow_RequestInviteButton:Hide();
LFGMM_PopupWindow_InviteButton:Show();
else
LFGMM_PopupWindow_RequestInviteButton:Show();
LFGMM_PopupWindow_InviteButton:Hide();
end
end
-- Show
LFGMM_PopupWindow_IgnoreButton:Show();
LFGMM_PopupWindow_WhoButton:Show();
LFGMM_PopupWindow_WhisperButton:Show();
-- Hide
LFGMM_PopupWindow_WaitText:Hide();
LFGMM_PopupWindow_WaitCountdownText:Hide();
LFGMM_PopupWindow_SkipWaitButton:Hide();
-- Disable
LFGMM_PopupWindow_CloseButton:Disable();
-- Show and refresh
LFGMM_PopupWindow:Show();
LFGMM_PopupWindow_Refresh();
-- Age
LFGMM_PopupWindow_StartUpdateAge();
end
function LFGMM_PopupWindow_ShowForInviteRequested(message)
LFGMM_PopupWindow.Type = "REQUEST";
LFGMM_PopupWindow.Message = message;
-- Title
LFGMM_PopupWindow_Title:SetText("Invite requested");
-- Show
LFGMM_PopupWindow_WaitText:Show();
LFGMM_PopupWindow_WaitCountdownText:Show();
LFGMM_PopupWindow_SkipWaitButton:Show();
-- Hide
LFGMM_PopupWindow_IgnoreButton:Hide();
LFGMM_PopupWindow_WhoButton:Hide();
LFGMM_PopupWindow_WhisperButton:Hide();
LFGMM_PopupWindow_RequestInviteButton:Hide();
LFGMM_PopupWindow_InviteButton:Hide();
-- Disable
LFGMM_PopupWindow_CloseButton:Disable();
-- Show and refresh
LFGMM_PopupWindow:Show();
LFGMM_PopupWindow_Refresh();
-- Age
LFGMM_PopupWindow_StartUpdateAge();
-- Countdown
LFGMM_PopupWindow_StartWaitCountdown();
end
function LFGMM_PopupWindow_ShowForInvited(message)
LFGMM_PopupWindow.Type = "INVITE";
LFGMM_PopupWindow.Message = message;
-- Title
LFGMM_PopupWindow_Title:SetText("Invite received!");
-- Show
LFGMM_PopupWindow_WhoButton:Show();
LFGMM_PopupWindow_WhisperButton:Show();
-- Enable
LFGMM_PopupWindow_CloseButton:Enable();
-- Hide
LFGMM_PopupWindow_IgnoreButton:Hide();
LFGMM_PopupWindow_RequestInviteButton:Hide();
LFGMM_PopupWindow_InviteButton:Hide();
LFGMM_PopupWindow_WaitText:Hide();
LFGMM_PopupWindow_WaitCountdownText:Hide();
LFGMM_PopupWindow_SkipWaitButton:Hide();
-- Show and refresh
LFGMM_PopupWindow:Show();
LFGMM_PopupWindow_Refresh();
-- Age
LFGMM_PopupWindow_StartUpdateAge();
end
function LFGMM_PopupWindow_Hide()
-- Reset popup
LFGMM_PopupWindow.Type = nil;
LFGMM_PopupWindow.Message = nil;
LFGMM_PopupWindow.WaitTimer = 0;
-- Hide
LFGMM_PopupWindow:Hide();
-- Search again
if (LFGMM_DB.SEARCH.LFG.Running or LFGMM_DB.SEARCH.LFM.Running) then
C_Timer.After(2, LFGMM_Core_FindSearchMatch);
end
-- Release lock
if (LFGMM_GLOBAL.SEARCH_LOCK) then
LFGMM_GLOBAL.SEARCH_LOCK = false;
end
-- Refresh
LFGMM_ListTab_MessageInfoWindow_Refresh();
end
function LFGMM_PopupWindow_HideForInvited()
if (LFGMM_PopupWindow:IsVisible() and LFGMM_PopupWindow.Type == "INVITE") then
LFGMM_PopupWindow_Hide();
end
end
function LFGMM_PopupWindow_Refresh()
-- Return if window has been hidden
if (not LFGMM_PopupWindow:IsVisible()) then
return;
end
local message = LFGMM_PopupWindow.Message;
local guildName = "";
if (message.GuildName ~= nil and message.GuildName ~= "") then
guildName = " " .. message.GuildName;
end
-- Class
LFGMM_PopupWindow_ClassIcon:SetTexCoord(unpack(message.PlayerClass.IconCoordinates));
LFGMM_PopupWindow_ClassText:SetText(message.PlayerClass.Color .. message.PlayerClass.LocalizedName);
-- Level
LFGMM_PopupWindow_LevelText:SetText(message.PlayerClass.Color .. (message.PlayerLevel or "?"));
-- Player
LFGMM_PopupWindow_PlayerText:SetText(message.PlayerClass.Color .. "[" .. message.Player .. "]" .. guildName .. ":");
-- Message
LFGMM_PopupWindow_MessageText:SetText(message.Message);
-- Window size
LFGMM_PopupWindow:SetHeight(LFGMM_PopupWindow_MessageText:GetHeight() + 115);
-- Who button
if (LFGMM_PopupWindow.Type ~= "REQUEST") then
if (message.PlayerLevel ~= nil) then
LFGMM_PopupWindow_WhoButton:Hide();
else
LFGMM_PopupWindow_WhoButton:Show();
if (LFGMM_GLOBAL.WHO_COOLDOWN > 0) then
LFGMM_PopupWindow_WhoButton:SetText("Who? (" .. LFGMM_GLOBAL.WHO_COOLDOWN .. ")");
LFGMM_PopupWindow_WhoButton:Disable();
else
LFGMM_PopupWindow_WhoButton:SetText("Who?");
LFGMM_PopupWindow_WhoButton:Enable();
end
end
end
-- Refresh info window
LFGMM_ListTab_MessageInfoWindow_Refresh();
end
function LFGMM_PopupWindow_WhisperButton_OnClick()
LFGMM_Core_OpenWhisper(LFGMM_PopupWindow.Message);
end
function LFGMM_PopupWindow_WhoButton_OnClick()
LFGMM_Core_WhoRequest(LFGMM_PopupWindow.Message);
end
function LFGMM_PopupWindow_IgnoreButton_OnClick()
LFGMM_Core_Ignore(LFGMM_PopupWindow.Message);
LFGMM_PopupWindow_Hide();
end
function LFGMM_PopupWindow_InviteButton_OnClick()
LFGMM_Core_Invite(LFGMM_PopupWindow.Message);
LFGMM_PopupWindow_Hide();
end
function LFGMM_PopupWindow_RequestInviteButton_OnClick()
LFGMM_Core_RequestInvite(LFGMM_PopupWindow.Message);
LFGMM_PopupWindow_ShowForInviteRequested(LFGMM_PopupWindow.Message);
-- Refresh
LFGMM_ListTab_MessageInfoWindow_Refresh();
end
function LFGMM_PopupWindow_SkipWaitButton_OnClick()
LFGMM_PopupWindow_Hide();
end
function LFGMM_PopupWindow_CloseButton_OnClick()
LFGMM_PopupWindow_Hide();
end
function LFGMM_PopupWindow_StartUpdateAge()
-- Set age text
local ageText = LFGMM_Utility_GetAgeText(LFGMM_PopupWindow.Message.Timestamp);
LFGMM_PopupWindow_TimeText:SetText("Announced " .. ageText);
-- Start timer
if (not LFGMM_PopupWindow.UpdateAgeTimerLock) then
LFGMM_PopupWindow.UpdateAgeTimerLock = true;
LFGMM_PopupWindow_UpdateAge();
end
end
function LFGMM_PopupWindow_UpdateAge()
-- Return if hidden
if (not LFGMM_PopupWindow:IsVisible()) then
LFGMM_PopupWindow.UpdateAgeTimerLock = false;
return;
end
-- Update age text
local ageText = LFGMM_Utility_GetAgeText(LFGMM_PopupWindow.Message.Timestamp);
LFGMM_PopupWindow_TimeText:SetText("Announced " .. ageText);
C_Timer.After(1, LFGMM_PopupWindow_UpdateAge);
end
function LFGMM_PopupWindow_StartWaitCountdown()
-- Set wait countdown
LFGMM_PopupWindow.WaitTimer = 60;
LFGMM_PopupWindow_WaitCountdownText:SetText(60);
-- Start countdown
if (not LFGMM_PopupWindow.UpdateWaitCountdownLock) then
LFGMM_PopupWindow.UpdateWaitCountdownLock = true;
LFGMM_PopupWindow_UpdateWaitCountdown();
end
end
function LFGMM_PopupWindow_UpdateWaitCountdown()
-- Return if hidden
if (not LFGMM_PopupWindow:IsVisible() or not LFGMM_PopupWindow_WaitCountdownText:IsVisible()) then
LFGMM_PopupWindow.UpdateWaitCountdownLock = false;
return;
end
-- Hide if countdown reached zero
if (LFGMM_PopupWindow.WaitTimer == 0) then
LFGMM_PopupWindow.UpdateWaitCountdownLock = false;
LFGMM_PopupWindow_Hide();
else
-- Hide if group has been joined
if (table.getn(LFGMM_GLOBAL.GROUP_MEMBERS) > 1) then
LFGMM_PopupWindow.UpdateWaitCountdownLock = false;
LFGMM_PopupWindow_Hide();
-- Update wait countdown
else
LFGMM_PopupWindow_WaitCountdownText:SetText(LFGMM_PopupWindow.WaitTimer);
LFGMM_PopupWindow.WaitTimer = LFGMM_PopupWindow.WaitTimer - 1;
C_Timer.After(1, LFGMM_PopupWindow_UpdateWaitCountdown);
end
end
end
function LFGMM_PopupWindow_MoveToPartyInviteDialog()
for index = 1, STATICPOPUP_NUMDIALOGS, 1 do
local frameName = "StaticPopup" .. index;
if (_G[frameName].which == "PARTY_INVITE") then
LFGMM_PopupWindow_SavePosition();
LFGMM_PopupWindow:ClearAllPoints();
LFGMM_PopupWindow:SetPoint("TOP", frameName, "BOTTOM", 0, -25);
break;
end
end
end
function LFGMM_PopupWindow_SavePosition()
local point, relativeTo, relativePoint, x, y = LFGMM_PopupWindow:GetPoint();
LFGMM_PopupWindow.SavedPosition = {
Point = point,
RelativeTo = relativeTo,
RelativePoint = relativePoint,
X = x,
Y = y
};
end
function LFGMM_PopupWindow_RestorePosition()
if (LFGMM_PopupWindow.SavedPosition ~= nil) then
LFGMM_PopupWindow:ClearAllPoints();
LFGMM_PopupWindow:SetPoint(
LFGMM_PopupWindow.SavedPosition.Point,
LFGMM_PopupWindow.SavedPosition.RelativeTo,
LFGMM_PopupWindow.SavedPosition.RelativePoint,
LFGMM_PopupWindow.SavedPosition.X,
LFGMM_PopupWindow.SavedPosition.Y
);
end
end