forked from funkydude/LegionInvasionTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegionInvasionTimer.lua
215 lines (200 loc) · 7 KB
/
LegionInvasionTimer.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
local name, mod = ...
local L = mod.L
local candy = LibStub("LibCandyBar-3.0")
local media = LibStub("LibSharedMedia-3.0")
local Timer = C_Timer.After
mod.c = {r=1,g=1,b=1}
local frame = CreateFrame("Frame", name, UIParent)
mod.f = frame
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetWidth(180)
frame:SetHeight(15)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetClampedToScreen(true)
frame:Hide()
frame:RegisterEvent("PLAYER_LOGIN")
local function startBar(text, timeLeft, rewardQuestID, icon, first, pause)
local bar
if first then
if frame.bar1 then frame.bar1:Stop(true) end
frame.bar1 = candy:New(media:Fetch("statusbar", legionTimerDB.barTexture), legionTimerDB.width, legionTimerDB.height)
bar = frame.bar1
if legionTimerDB.growUp then
bar:SetPoint("BOTTOM", name, "TOP")
else
bar:SetPoint("TOP", name, "BOTTOM")
end
else
if frame.bar2 then frame.bar2:Stop() end
frame.bar2 = candy:New(media:Fetch("statusbar", legionTimerDB.barTexture), legionTimerDB.width, legionTimerDB.height)
bar = frame.bar2
if legionTimerDB.growUp then
frame.bar2:SetPoint("BOTTOMLEFT", frame.bar1, "TOPLEFT", 0, legionTimerDB.spacing)
frame.bar2:SetPoint("BOTTOMRIGHT", frame.bar1, "TOPRIGHT", 0, legionTimerDB.spacing)
else
frame.bar2:SetPoint("TOPLEFT", frame.bar1, "BOTTOMLEFT", 0, -legionTimerDB.spacing)
frame.bar2:SetPoint("TOPRIGHT", frame.bar1, "BOTTOMRIGHT", 0, -legionTimerDB.spacing)
end
end
bar:SetLabel(text:match("[^%:]+:(.+)") or text)
bar.candyBarLabel:SetJustifyH(legionTimerDB.alignZone)
bar.candyBarDuration:SetJustifyH(legionTimerDB.alignTime)
bar:SetDuration(timeLeft)
if rewardQuestID > 0 then
if IsQuestFlaggedCompleted(rewardQuestID) then
bar:SetColor(unpack(legionTimerDB.colorComplete))
bar:Set("LegionInvasionTimer:complete", 1)
else
bar:SetColor(unpack(legionTimerDB.colorIncomplete))
bar:Set("LegionInvasionTimer:complete", 0)
end
end
bar:SetTextColor(unpack(legionTimerDB.colorText))
if legionTimerDB.icon then
bar:SetIcon(icon)
end
bar:SetTimeVisibility(legionTimerDB.timeText)
bar:SetFill(legionTimerDB.fill)
local flags = nil
if legionTimerDB.monochrome and legionTimerDB.outline ~= "NONE" then
flags = "MONOCHROME," .. legionTimerDB.outline
elseif legionTimerDB.monochrome then
flags = "MONOCHROME"
elseif legionTimerDB.outline ~= "NONE" then
flags = legionTimerDB.outline
end
bar.candyBarLabel:SetFont(media:Fetch("font", legionTimerDB.font), legionTimerDB.fontSize, flags)
bar.candyBarDuration:SetFont(media:Fetch("font", legionTimerDB.font), legionTimerDB.fontSize, flags)
if pause then -- Searching bars
bar:Start()
bar:Pause()
bar:SetTimeVisibility(false)
elseif rewardQuestID > 0 then -- Zone bars
bar:Start(14400) -- 4hrs = 60*4 = 240min = 240*60 = 14,400sec
else
bar:Start() -- Boss bars
end
end
local hasPausedBars, justLoggedIn = false, true
local function findTimer()
-- 3 Legion Invasion: Northern Barrens 0 43282
-- 4 Legion Invasion: Westfall 0 43245
-- 5 Legion Invasion: Tanaris 0 43244
-- 6 Legion Invasion: Dun Morogh 0 43284
-- 7 Legion Invasion: Hillsbrad 0 43285
-- 8 Legion Invasion: Azshara 0 43301
local first = true
for i = 3, 8 do
local zone, timeLeftMinutes, rewardQuestID = GetInvasionInfo(i)
if timeLeftMinutes and timeLeftMinutes > 1 and timeLeftMinutes < 241 then -- On some realms timeLeftMinutes can return massive values during the initialization of a new event
startBar(zone, timeLeftMinutes * 60, rewardQuestID, 236292, first) -- 236292 = Interface\\Icons\\Ability_Warlock_DemonicEmpowerment
if not first then break end -- I'm assuming it's always 2 events
first = false
if hasPausedBars and not justLoggedIn then
hasPausedBars = false
Timer(30, findTimer) -- Sometimes Blizz doesn't reset the quest ID very quickly, do another check to fix colors if so
FlashClientIcon()
print("|cFF33FF99LegionInvasionTimer|r:", L.invasionsAvailable)
RaidNotice_AddMessage(RaidBossEmoteFrame, L.invasionsAvailable, mod.c)
PlaySound("RaidWarning", "Master")
end
justLoggedIn = false
end
end
if first then
if not hasPausedBars then
hasPausedBars = true
startBar("Searching..", 7200, 0, 132177, true, true) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
startBar("Searching...", 7200, 0, 132177, false, true)
end
Timer(3, findTimer) -- Start hunting for the next event
end
end
frame:SetScript("OnEvent", function(f)
f:UnregisterEvent("PLAYER_LOGIN")
local weekday, month, day, year = CalendarGetDate()
if month ~= 8 or year ~= 2016 then
f:SetScript("OnEvent", nil)
return -- Good times come to an end
end
if type(legionTimerDB) ~= "table" or not legionTimerDB.colorText then
legionTimerDB = {
fontSize = 10,
barTexture = "Blizzard Raid Bar",
outline = "NONE",
font = media:GetDefault("font"),
width = 200,
height = 20,
icon = true,
timeText = true,
spacing = 0,
alignZone = "LEFT",
alignTime = "RIGHT",
colorText = {1,1,1,1},
colorComplete = {0,1,0,1},
colorIncomplete = {1,0,0,1},
}
end
if legionTimerDB.texture then -- Cleanup old texture DB entry
if legionTimerDB.texture == "BantoBar" then
legionTimerDB.barTexture = "Blizzard Raid Bar"
else
legionTimerDB.barTexture = legionTimerDB.texture
end
legionTimerDB.texture = nil
end
f:Show()
f:SetScript("OnDragStart", function(f) f:StartMoving() end)
f:SetScript("OnDragStop", function(f) f:StopMovingOrSizing() end)
SlashCmdList[name] = function() LoadAddOn("LegionInvasionTimer_Options") LibStub("AceConfigDialog-3.0"):Open(name) end
SLASH_LegionInvasionTimer1 = "/lit"
SLASH_LegionInvasionTimer2 = "/legioninvasiontimer"
f:SetScript("OnMouseUp", function(f, btn)
if btn == "RightButton" then
SlashCmdList[name]()
end
end)
f:SetScript("OnEnter", function(f)
GameTooltip:SetOwner(f, "ANCHOR_NONE")
GameTooltip:SetPoint("BOTTOM", f, "TOP")
GameTooltip:AddLine(L.tooltipClick, 0.2, 1, 0.2, 1)
GameTooltip:AddLine(L.tooltipClickOptions, 0.2, 1, 0.2, 1)
GameTooltip:Show()
end)
f:SetScript("OnLeave", GameTooltip_Hide)
local bg = f:CreateTexture(nil, "PARENT")
bg:SetAllPoints(f)
bg:SetColorTexture(0, 1, 0, 0.3)
f.bg = bg
local header = f:CreateFontString(nil, "OVERLAY", "TextStatusBarText")
header:SetAllPoints(f)
header:SetText(name)
f.header = header
f.startBar = startBar
f.db = legionTimerDB
if legionTimerDB.lock then
f:EnableMouse(false)
f.bg:Hide()
f.header:Hide()
end
candy.RegisterCallback(name, "LibCandyBar_Stop", function(_, bar, dontScan)
if not dontScan and bar == frame.bar1 and bar:Get("LegionInvasionTimer:complete") then
Timer(1, findTimer) -- Event over, start hunting for the next event
end
if bar == frame.bar1 then
frame.bar1 = nil
elseif bar == frame.bar2 then
frame.bar2 = nil
end
end)
findTimer()
f:RegisterEvent("SCENARIO_COMPLETED")
f:SetScript("OnEvent", function()
local _,_,_,_,_,_,_,_,_,scenarioType = C_Scenario.GetInfo()
if scenarioType == 4 then -- LE_SCENARIO_TYPE_LEGION_INVASION = 4
Timer(8, findTimer) -- Update bar color
end
end)
end)