-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleCraft_SafeQueue.lua
61 lines (54 loc) · 2.1 KB
/
BattleCraft_SafeQueue.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
local SafeQueue = CreateFrame("Frame", "SafeQueue", UIParent)
local queueTime
local queue = 0
local remaining = 0
SafeQueueDB = SafeQueueDB or { announce = "self" }
SafeQueue:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
SafeQueue:SetScript("OnUpdate", function(self) self:Timer() end)
SafeQueue:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].button2 = nil
StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].hideOnEscape = false
function SafeQueue:UPDATE_BATTLEFIELD_STATUS()
local queued
for i = 1, MAX_BATTLEFIELD_QUEUES do
local status = GetBattlefieldStatus(i)
if status == "queued" then
queued = true
if not queueTime then queueTime = GetTime() end
elseif status == "confirm" then
if queueTime then
self:TimeWaited()
queueTime = nil
remaining = 0
queue = i
end
end
end
if not queued and queueTime then queueTime = nil end
end
function SafeQueue:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff3c78d8[SafeQueue]|r " .. msg)
end
function SafeQueue:TimeWaited()
if SafeQueueDB.announce == "off" then return end
local secs = floor(GetTime() - queueTime)
local str = "Queue popped " .. (secs < 1 and "instantly!" or "after " .. SecondsToTime(secs))
-- Only announce to self
if SafeQueueDB.announce == "self" then
self:Print(str)
end
end
function SafeQueue:Timer()
local secs = GetBattlefieldPortExpiration(queue)
if secs > 0 then
local p = StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY")
if p and remaining ~= secs then
remaining = secs
local color = secs > 20 and "ff20ff20" or secs > 10 and "ffffff00" or "ffff0000"
_G[p .. "Text"]:SetText(string.gsub(
_G[p .. "Text"]:GetText(),
".+ to enter",
"You have |c"..color..SecondsToTime(secs).."|r to enter"))
end
end
end