-
Notifications
You must be signed in to change notification settings - Fork 4
/
WinFrame.lua
411 lines (354 loc) · 14.7 KB
/
WinFrame.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
local addonVer = "1.0.3.2"
local me = UnitName('player')
local xmog = false
function wfprint(a)
DEFAULT_CHAT_FRAME:AddMessage("|cff69ccf0[TWLC2c] |cffffffff" .. a)
end
function wfdebug(a)
if me == 'Er' or me == 'Kzktst' then --dev
wfprint('|cff0070de[Winframe :' .. time() .. '] |cffffffff[' .. a .. ']')
end
end
local WinAnimFrame = CreateFrame("Frame")
WinAnimFrame:RegisterEvent("CHAT_MSG_ADDON")
WinAnimFrame:RegisterEvent("CHAT_MSG_LOOT")
WinAnimFrame:RegisterEvent("ADDON_LOADED")
WinAnimFrame:Hide()
WinAnimFrame.wonItems = {}
WinAnimFrame:SetScript("OnEvent", function()
if (event) then
if (event == "ADDON_LOADED" and arg1 == 'TWLC2c') then
WinAnimFrame:HideAnchor()
if not TWLC_LOOT_THRESHOLD then TWLC_LOOT_THRESHOLD = 3 end
if TWLC_LOOT_ENABLE_SOUND == nil then TWLC_LOOT_ENABLE_SOUND = true end
if not TWLC_WIN_VOLUME then TWLC_WIN_VOLUME = 'high' end
local text = ''
local qualities = {
[0] = 'Poor',
[1] = 'Common',
[2] = 'Uncommon',
[3] = 'Rare',
[4] = 'Epic',
[5] = 'Legendary'
}
for i = TWLC_LOOT_THRESHOLD, 5 do
local _, _, _, color = GetItemQualityColor(i)
text = text .. color .. qualities[i] .. ' '
end
wfprint('TWLC2c WinFrame (v' .. addonVer .. ') Loaded. Type |cfffff569/tw|cff69ccf0win |cffffffffto show the Anchor window.')
wfprint('Type |cfffff569/tw|cff69ccf0win <0-5> |cffffffffto change loot window threshold '
.. '( current threshhold set at ' .. TWLC_LOOT_THRESHOLD .. ' : ' .. text .. '|cffffffff).')
if TWLC_LOOT_ENABLE_SOUND then
wfprint('Win Sound is Enabled(' .. TWLC_WIN_VOLUME .. '). Type |cfffff569/tw|cff69ccf0win|cfffff569sound |cffffffffto toggle win sound on or off.')
else
wfprint('Win Sound is Disabled. Type |cfffff569/tw|cff69ccf0win|cfffff569sound |cffffffffto toggle win sound on or off.')
end
end
if (event == "CHAT_MSG_LOOT") then
--receive
--eng
if (string.find(arg1, 'You receive loot', 1, true)) then
local recEx = string.split(arg1, 'loot: ')
if (recEx[1]) then
addWonItem(recEx[2], recEx[1] .. 'loot:')
end
end
--ger
if (string.find(arg1, 'Ihr erhaltet Beute:', 1, true)) then
local recEx = string.split(arg1, 'Beute: ')
if (recEx[1]) then
addWonItem(recEx[2], recEx[1] .. 'Beute:')
end
end
--create
--eng
if (string.find(arg1, 'You create', 1, true)) then
local recEx = string.split(arg1, 'create: ')
if (recEx[1]) then
addWonItem(recEx[2], recEx[1] .. 'create:')
end
end
--ger
if (string.find(arg1, 'Ihr stellt her', 1, true)) then
local recEx = string.split(arg1, 'stellt her: ')
if (recEx[1]) then
addWonItem(recEx[2], recEx[1] .. 'stellt her:')
end
end
end
if (event == "CHAT_MSG_ADDON") then
if (arg1 == "TWLCNF") then
--disabled in TWLC2
if (string.find(arg2, 'youWon=')) then
local winEx = string.split(arg2, '=')
if (winEx[1] and winEx[2] and winEx[3]) then
if (winEx[2] == UnitName('player')) then
addWonItem(winEx[3], 'You Won!')
end
end
end
end
if arg1 == 'TWLC2' then
if string.find(arg2, 'playerWon#') then
local wonData = string.split(arg2, "#")
if wonData[5] then
if wonData[5] == 'xmog' and wonData[2] == me then
xmog = true
else
xmog = false
end
end
end
end
end
end
end)
local delayAddWonItem = CreateFrame("Frame")
delayAddWonItem:Hide()
delayAddWonItem.data = {}
delayAddWonItem:SetScript("OnShow", function()
this.startTime = GetTime()
end)
delayAddWonItem:SetScript("OnUpdate", function()
local plus = 0.2
local gt = GetTime() * 1000 --22.123 -> 22123
local st = (this.startTime + plus) * 1000 -- (22.123 + 0.1) * 1000 = 22.223 * 1000 = 22223
if gt >= st then
local atLeastOne = false
for id, data in next, delayAddWonItem.data do
if delayAddWonItem.data[id] then
atLeastOne = true
addWonItem(id, data)
delayAddWonItem.data[id] = nil
end
end
if not atLeastOne then
delayAddWonItem:Hide()
end
end
end)
function addWonItem(linkString, winText)
local _, _, itemLink = string.find(linkString, "(item:%d+:%d+:%d+:%d+)");
GameTooltip:SetHyperlink(itemLink)
GameTooltip:Hide()
local name, _, quality, _, _, _, _, _, tex = GetItemInfo(itemLink)
if (not name or not quality) then
delayAddWonItem.data[linkString] = winText
delayAddWonItem:Show()
return false
end
if quality < TWLC_LOOT_THRESHOLD then
return false
end
local _, _, _, color = GetItemQualityColor(quality)
local wonIndex = 0
for i = 1, table.getn(WinAnimFrame.wonItems), 1 do
if (not WinAnimFrame.wonItems[i].active) then
wonIndex = i
break
end
end
if wonIndex == 0 then
wonIndex = table.getn(WinAnimFrame.wonItems) + 1
end
if (not WinAnimFrame.wonItems[wonIndex]) then
WinAnimFrame.wonItems[wonIndex] = CreateFrame("Frame", "WinFrame" .. wonIndex, getglobal("WinFrame"), "WonItemTemplate")
end
WinAnimFrame.wonItems[wonIndex]:SetPoint("TOP", getglobal("WinFrame"), "TOP", 0, (20 + 100 * wonIndex))
WinAnimFrame.wonItems[wonIndex].active = true
WinAnimFrame.wonItems[wonIndex].quality = quality
WinAnimFrame.wonItems[wonIndex].frameIndex = 0
WinAnimFrame.wonItems[wonIndex].doAnim = true
WinAnimFrame.wonItems[wonIndex].xmog = xmog
xmog = false
WinAnimFrame.wonItems[wonIndex]:SetAlpha(0)
WinAnimFrame.wonItems[wonIndex]:Show()
getglobal('WinFrame' .. wonIndex .. 'Icon'):SetNormalTexture(tex)
getglobal('WinFrame' .. wonIndex .. 'Icon'):SetPushedTexture(tex)
getglobal('WinFrame' .. wonIndex .. 'ItemName'):SetText(color .. name)
getglobal('WinFrame' .. wonIndex .. 'Title'):SetText(winText)
local ex = string.split(linkString, "|")
if ex[3] then
getglobal('WinFrame' .. wonIndex .. 'Icon'):SetScript("OnEnter", function(self)
LCTooltipWinFrame:SetOwner(this, "ANCHOR_RIGHT", 0, 0);
LCTooltipWinFrame:SetHyperlink(string.sub(ex[3], 2, string.len(ex[3])));
LCTooltipWinFrame:Show();
end)
getglobal('WinFrame' .. wonIndex .. 'Icon'):SetScript("OnLeave", function(self)
LCTooltipWinFrame:Hide();
end)
else
wfdebug('wrong itemlink ?')
end
start_anim()
end
function test_win_frame()
-- addWonItem('|cffff8000|Hitem:12583:0:0:0:::::|h[Thunderfury, Blessed Blade of the Windseeker]|h|r', 'You Won ! (test message)')
addWonItem('|cffa335ee|Hitem:19364:0:0:0:0:0:0:0:0|h[Ashkandi, Greatsword of the Brotherhood]|h|r', 'You Won ! (test message)')
end
function start_anim()
if TWLC_LOOT_ENABLE_SOUND then
PlaySoundFile("Interface\\AddOns\\TWLC2c\\sound\\win_" .. TWLC_WIN_VOLUME .. ".ogg");
end
if (table.getn(WinAnimFrame.wonItems) > 0) then
WinAnimFrame.showLootWindow = true
end
if (not WinAnimFrame:IsVisible()) then
WinAnimFrame:Show()
end
end
WinAnimFrame.showLootWindow = false
WinAnimFrame:SetScript("OnShow", function()
this.startTime = GetTime()
end)
WinAnimFrame:SetScript("OnUpdate", function()
if (WinAnimFrame.showLootWindow) then
if ((GetTime()) >= (this.startTime) + 0.03) then
this.startTime = GetTime()
for i, d in next, WinAnimFrame.wonItems do
if (WinAnimFrame.wonItems[i].active) then
local frame = getglobal('WinFrame' .. i)
local quality = WinAnimFrame.wonItems[i].quality
local image = 'loot_frame_' .. quality .. '_'
if (quality < 3) then
image = 'loot_frame_012_'
end
if (quality >= 3) then
image = 'loot_frame_345_'
end
if WinAnimFrame.wonItems[i].xmog then
image = 'loot_frame_xmog_'
getglobal('WinFrame' .. i .. 'Title'):Hide()
getglobal('WinFrame' .. i .. 'QualityBorder'):Hide()
getglobal('WinFrame' .. i .. 'Icon'):SetPoint('LEFT', 160, -9)
getglobal('WinFrame' .. i .. 'Icon'):SetWidth(36)
getglobal('WinFrame' .. i .. 'IconNormalTexture'):SetWidth(36)
getglobal('WinFrame' .. i .. 'Icon'):SetHeight(36)
getglobal('WinFrame' .. i .. 'IconNormalTexture'):SetHeight(36)
else
getglobal('WinFrame' .. i .. 'Title'):Show()
getglobal('WinFrame' .. i .. 'QualityBorder'):Show()
getglobal('WinFrame' .. i .. 'Icon'):SetPoint('LEFT', 148, 0)
getglobal('WinFrame' .. i .. 'Icon'):SetWidth(46)
getglobal('WinFrame' .. i .. 'IconNormalTexture'):SetWidth(46)
getglobal('WinFrame' .. i .. 'Icon'):SetHeight(46)
getglobal('WinFrame' .. i .. 'IconNormalTexture'):SetHeight(46)
end
if WinAnimFrame.wonItems[i].frameIndex < 10 then
image = image .. '0' .. WinAnimFrame.wonItems[i].frameIndex
else
image = image .. WinAnimFrame.wonItems[i].frameIndex;
end
WinAnimFrame.wonItems[i].frameIndex = WinAnimFrame.wonItems[i].frameIndex + 1
getglobal('WinFrame' .. i .. 'QualityBorder'):SetTexture('Interface\\addons\\TWLC2c\\images\\loot\\' .. quality .. '_large')
if (WinAnimFrame.wonItems[i].doAnim) then
local backdrop = {
bgFile = 'Interface\\AddOns\\TWLC2c\\images\\loot\\' .. image,
tile = false
};
if (WinAnimFrame.wonItems[i].frameIndex <= 30) then
frame:SetBackdrop(backdrop)
end
frame:SetAlpha(frame:GetAlpha() + 0.03)
getglobal('WinFrame' .. i .. 'Icon'):SetAlpha(frame:GetAlpha() + 0.03)
end
if (WinAnimFrame.wonItems[i].frameIndex == 35) then --stop and hold last frame
WinAnimFrame.wonItems[i].doAnim = false
end
if (WinAnimFrame.wonItems[i].frameIndex > 119) then
frame:SetAlpha(frame:GetAlpha() - 0.03)
getglobal('WinFrame' .. i .. 'Icon'):SetAlpha(frame:GetAlpha() + 0.03)
end
if (WinAnimFrame.wonItems[i].frameIndex == 150) then
WinAnimFrame.wonItems[i].frameIndex = 0
frame:Hide()
WinAnimFrame.wonItems[i].active = false
xmog = false
end
end
end
end
end
end)
function close_placement()
wfprint('Anchor window closed. Type |cfffff569/tw|cff69ccf0win |cffffffffto show the Anchor window.')
WinAnimFrame:HideAnchor()
end
function WinAnimFrame:ShowAnchor()
getglobal('WinFrame'):SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
tile = true,
})
getglobal('WinFrame'):EnableMouse(true)
getglobal('WinFrameTitle'):Show()
getglobal('WinFrameTestPlacement'):Show()
getglobal('WinFrameClosePlacement'):Show()
end
function WinAnimFrame:HideAnchor()
getglobal('WinFrame'):SetBackdrop({
bgFile = "",
tile = true,
})
getglobal('WinFrame'):EnableMouse(false)
getglobal('WinFrameTitle'):Hide()
getglobal('WinFrameTestPlacement'):Hide()
getglobal('WinFrameClosePlacement'):Hide()
end
SLASH_TWWIN1 = "/twwin"
SLASH_TWWIN2 = "/twwinthreshold"
SlashCmdList["TWWIN"] = function(cmd)
if (cmd) then
if (tonumber(cmd)) then
local newT = tonumber(cmd)
if (newT >= 0 and newT <= 5) then
TWLC_LOOT_THRESHOLD = newT
local text = ''
local qualities = {
[0] = 'Poor',
[1] = 'Common',
[2] = 'Uncommon',
[3] = 'Rare',
[4] = 'Epic',
[5] = 'Legendary'
}
for i = newT, 5 do
local _, _, _, color = GetItemQualityColor(i)
text = text .. color .. qualities[i] .. ' '
end
wfprint('Loot threshold changed to ' .. TWLC_LOOT_THRESHOLD .. ', ' .. text)
else
wfprint('Accepted range is |cfffff5690-5') -- |cffffffffto show the Anchor window.')
end
else
WinAnimFrame:ShowAnchor()
end
end
end
SLASH_TWWINSOUND1 = "/twwinsound"
SlashCmdList["TWWINSOUND"] = function(cmd)
if cmd then
if cmd == 'high' or cmd == 'low' then
TWLC_WIN_VOLUME = cmd
wfprint('Win Sound Volume set to |cfffff569' .. TWLC_WIN_VOLUME)
return true
end
TWLC_LOOT_ENABLE_SOUND = not TWLC_LOOT_ENABLE_SOUND
if TWLC_LOOT_ENABLE_SOUND then
wfprint('Win Sound Enabled')
else
wfprint('Win Sound Disabled')
end
end
end
function string:split(delimiter)
local result = {}
local from = 1
local delim_from, delim_to = string.find(self, delimiter, from)
while delim_from do
table.insert(result, string.sub(self, from, delim_from - 1))
from = delim_to + 1
delim_from, delim_to = string.find(self, delimiter, from)
end
table.insert(result, string.sub(self, from))
return result
end