shadowsight:
- reset timer when shadowsight buff is active - add a second timer - show one or two timers option added
This commit is contained in:
parent
65daef4cd4
commit
c3a7c6cbc8
@ -1,6 +1,12 @@
|
||||
local floor, str_find, pairs = math.floor, string.find, pairs
|
||||
local CreateFrame = CreateFrame
|
||||
|
||||
---------------------------
|
||||
|
||||
-- CORE
|
||||
|
||||
---------------------------
|
||||
|
||||
local Gladdy = LibStub("Gladdy")
|
||||
local L = Gladdy.L
|
||||
local ShadowsightTimer = Gladdy:NewModule("Shadowsight Timer", nil, {
|
||||
@ -12,8 +18,14 @@ local ShadowsightTimer = Gladdy:NewModule("Shadowsight Timer", nil, {
|
||||
shadowsightTimerX = 0,
|
||||
shadowsightTimerY = 0,
|
||||
shadowsightAnnounce = true,
|
||||
shadowsightTimerStartTime = 91,
|
||||
shadowsightTimerResetTime = 120,
|
||||
shadowsightTimerShowTwoTimer = false,
|
||||
})
|
||||
|
||||
-- /run LibStub("Gladdy").modules["Shadowsight Timer"]:AURA_GAIN(nil, nil, 34709)
|
||||
-- /run LibStub("Gladdy").modules["Shadowsight Timer"].timerFrame1:SetAlpha(0)
|
||||
|
||||
function ShadowsightTimer:OnEvent(event, ...)
|
||||
self[event](self, ...)
|
||||
end
|
||||
@ -22,20 +34,120 @@ function ShadowsightTimer:Initialize()
|
||||
self.locale = Gladdy:GetArenaTimer()
|
||||
self:RegisterMessage("JOINED_ARENA")
|
||||
self:RegisterMessage("AURA_GAIN")
|
||||
self:CreateTimerFrame()
|
||||
self:CreateAnchor()
|
||||
end
|
||||
|
||||
function ShadowsightTimer:Reset()
|
||||
self.anchor:Hide()
|
||||
for i=1,2 do
|
||||
self["timerFrame" .. i].active = false
|
||||
self["timerFrame" .. i]:SetScript("OnUpdate", nil)
|
||||
self["timerFrame" .. i].font:SetTextColor(1, 0.8, 0)
|
||||
end
|
||||
self:UnregisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
||||
self:SetScript("OnEvent", nil)
|
||||
end
|
||||
|
||||
---------------------------
|
||||
|
||||
-- FRAME SETUP
|
||||
|
||||
---------------------------
|
||||
|
||||
function ShadowsightTimer:CreateTimerFrame(anchor, name, points)
|
||||
local backdrop = {
|
||||
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||
edgeFile = "",
|
||||
tile = true, tileSize = 16, edgeSize = 10,
|
||||
insets = {left = 0, right = 0, top = 0, bottom = 0}
|
||||
}
|
||||
self[name] = CreateFrame("Frame", nil, anchor, BackdropTemplateMixin and "BackdropTemplate")
|
||||
self[name]:SetPoint(points[1], anchor, points[2])
|
||||
self[name]:SetBackdrop(backdrop)
|
||||
self[name]:SetBackdropColor(0,0,0,0.8)
|
||||
self[name]:SetHeight(17)
|
||||
self[name]:SetWidth(35)
|
||||
|
||||
self[name].texture = self[name]:CreateTexture(nil,"OVERLAY")
|
||||
self[name].texture:SetWidth(16)
|
||||
self[name].texture:SetHeight(16)
|
||||
self[name].texture:SetTexture("Interface\\Icons\\Spell_Shadow_EvilEye")
|
||||
self[name].texture:SetTexCoord(0.125,0.875,0.125,0.875)
|
||||
self[name].texture:SetPoint("RIGHT", self[name], "LEFT")
|
||||
|
||||
self[name].font = self[name]:CreateFontString(nil,"OVERLAY","GameFontNormal")
|
||||
self[name].font:SetPoint("LEFT", 5, 0)
|
||||
self[name].font:SetJustifyH("LEFT")
|
||||
self[name].font:SetTextColor(1, 0.8, 0)
|
||||
end
|
||||
|
||||
function ShadowsightTimer:CreateAnchor()
|
||||
self.anchor = CreateFrame("Frame")
|
||||
self.anchor:SetMovable(true)
|
||||
self.anchor:EnableMouse(true)
|
||||
self.anchor:SetWidth(35)
|
||||
self.anchor:SetHeight(17)
|
||||
self.anchor:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
self.anchor:SetScript("OnMouseDown",function(self) self:StartMoving() end)
|
||||
self.anchor:SetScript("OnMouseUp",function(self)
|
||||
self:StopMovingOrSizing()
|
||||
Gladdy.db.shadowsightTimerRelPoint1,_,Gladdy.db.shadowsightTimerRelPoint2,Gladdy.db.shadowsightTimerX,Gladdy.db.shadowsightTimerY = self:GetPoint()
|
||||
end)
|
||||
self.anchor:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.anchor:Hide()
|
||||
|
||||
self:CreateTimerFrame(self.anchor, "timerFrame1", {"TOP", "TOP"})
|
||||
local show = Gladdy.db.shadowsightTimerShowTwoTimer
|
||||
self:CreateTimerFrame(show and self.timerFrame1 or self.anchor, "timerFrame2", show and {"TOP", "BOTTOM"} or {"TOP", "TOP"})
|
||||
end
|
||||
|
||||
function ShadowsightTimer:UpdateFrameOnce()
|
||||
self.anchor:EnableMouse(not Gladdy.db.shadowsightTimerLocked)
|
||||
if Gladdy.db.shadowsightTimerEnabled then
|
||||
self.anchor:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.anchor:ClearAllPoints()
|
||||
self.anchor:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint2, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
if Gladdy.frame.testing or Gladdy.curBracket then
|
||||
self.anchor:Show()
|
||||
end
|
||||
if Gladdy.db.shadowsightTimerShowTwoTimer then
|
||||
self.anchor:SetHeight(34)
|
||||
self.timerFrame2:ClearAllPoints()
|
||||
self.timerFrame2:SetPoint("TOP", self.timerFrame1, "BOTTOM")
|
||||
ShadowsightTimer:NotifyStart()
|
||||
else
|
||||
self.anchor:SetHeight(17)
|
||||
self.timerFrame2:ClearAllPoints()
|
||||
self.timerFrame2:SetPoint("TOP", self.anchor, "TOP")
|
||||
ShadowsightTimer:NotifyStart()
|
||||
end
|
||||
else
|
||||
self.anchor:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.anchor:ClearAllPoints()
|
||||
self.anchor:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint2, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
self.anchor:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------
|
||||
|
||||
-- EVENT HANDLING
|
||||
|
||||
---------------------------
|
||||
|
||||
function ShadowsightTimer:JOINED_ARENA()
|
||||
self:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
||||
self:SetScript("OnEvent", ShadowsightTimer.OnEvent)
|
||||
self.timerFrame.font:SetText("1:30")
|
||||
self.timerFrame.font:SetTextColor(1, 0.8, 0)
|
||||
self.timerFrame:Show()
|
||||
for i=1,2 do
|
||||
self["timerFrame" .. i].font:SetText("1:30")
|
||||
self["timerFrame" .. i].font:SetTextColor(1, 0.8, 0)
|
||||
end
|
||||
self.anchor:Show()
|
||||
end
|
||||
|
||||
function ShadowsightTimer:AURA_GAIN(unit, auraType, spellID)
|
||||
if (spellID == 34709) then
|
||||
--TODO reset timer after 15s
|
||||
self:Start(Gladdy.db.shadowsightTimerResetTime, self:GetHiddenTimer())
|
||||
end
|
||||
end
|
||||
|
||||
@ -43,96 +155,53 @@ function ShadowsightTimer:CHAT_MSG_BG_SYSTEM_NEUTRAL(msg)
|
||||
for k,v in pairs(self.locale) do
|
||||
if str_find(msg, v) then
|
||||
if k == 0 then
|
||||
self:Start()
|
||||
self:Start(nil, self.timerFrame1)
|
||||
self:Start(nil, self.timerFrame2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------
|
||||
|
||||
-- TEST
|
||||
|
||||
---------------------------
|
||||
|
||||
function ShadowsightTimer:Test()
|
||||
if Gladdy.db.shadowsightTimerEnabled then
|
||||
self.timerFrame:Show()
|
||||
self:Start()
|
||||
self.anchor:Show()
|
||||
ShadowsightTimer:JOINED_ARENA()
|
||||
self:Start(20, self.timerFrame1)
|
||||
self:Start(25, self.timerFrame2)
|
||||
end
|
||||
end
|
||||
|
||||
function ShadowsightTimer:Reset()
|
||||
self.timerFrame:Hide()
|
||||
self.timerFrame:SetScript("OnUpdate", nil)
|
||||
self.timerFrame.font:SetTextColor(1, 0.8, 0)
|
||||
end
|
||||
---------------------------
|
||||
|
||||
function ShadowsightTimer:CreateTimerFrame()
|
||||
self.timerFrame = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
|
||||
self.timerFrame:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
-- TIMER
|
||||
|
||||
local backdrop = {
|
||||
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||
edgeFile = "",
|
||||
tile = true, tileSize = 16, edgeSize = 10,
|
||||
insets = {left = 0, right = 0, top = 0, bottom = 0}
|
||||
}
|
||||
---------------------------
|
||||
|
||||
self.timerFrame:SetBackdrop(backdrop)
|
||||
self.timerFrame:SetBackdropColor(0,0,0,0.8)
|
||||
self.timerFrame:SetHeight(17)
|
||||
self.timerFrame:SetWidth(35)
|
||||
|
||||
self.timerFrame:SetMovable(true)
|
||||
self.timerFrame:EnableMouse(true)
|
||||
|
||||
self.timerFrame.texture = self.timerFrame:CreateTexture(nil,"OVERLAY")
|
||||
self.timerFrame.texture:SetWidth(16)
|
||||
self.timerFrame.texture:SetHeight(16)
|
||||
self.timerFrame.texture:SetTexture("Interface\\Icons\\Spell_Shadow_EvilEye")
|
||||
self.timerFrame.texture:SetTexCoord(0.125,0.875,0.125,0.875)
|
||||
self.timerFrame.texture:SetPoint("RIGHT", self.timerFrame, "LEFT")
|
||||
|
||||
self.timerFrame.font = self.timerFrame:CreateFontString(nil,"OVERLAY","GameFontNormal")
|
||||
self.timerFrame.font:SetPoint("LEFT", 5, 0)
|
||||
self.timerFrame.font:SetJustifyH("LEFT")
|
||||
self.timerFrame.font:SetTextColor(1, 0.8, 0)
|
||||
|
||||
self.timerFrame:SetScript("OnMouseDown",function(self) self:StartMoving() end)
|
||||
self.timerFrame:SetScript("OnMouseUp",function(self)
|
||||
self:StopMovingOrSizing()
|
||||
Gladdy.db.shadowsightTimerRelPoint1,_,Gladdy.db.shadowsightTimerRelPoint2,Gladdy.db.shadowsightTimerX,Gladdy.db.shadowsightTimerY = self:GetPoint()
|
||||
end)
|
||||
self.timerFrame:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.timerFrame:Hide()
|
||||
end
|
||||
|
||||
function ShadowsightTimer:UpdateFrameOnce()
|
||||
self.timerFrame:EnableMouse(not Gladdy.db.shadowsightTimerLocked)
|
||||
if Gladdy.db.shadowsightTimerEnabled then
|
||||
self.timerFrame:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.timerFrame:ClearAllPoints()
|
||||
self.timerFrame:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint2, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
if Gladdy.frame.testing or Gladdy.curBracket then
|
||||
self.timerFrame:Show()
|
||||
end
|
||||
else
|
||||
self.timerFrame:SetScale(Gladdy.db.shadowsightTimerScale)
|
||||
self.timerFrame:ClearAllPoints()
|
||||
self.timerFrame:SetPoint(Gladdy.db.shadowsightTimerRelPoint1, nil, Gladdy.db.shadowsightTimerRelPoint2, Gladdy.db.shadowsightTimerX, Gladdy.db.shadowsightTimerY)
|
||||
self.timerFrame:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function ShadowsightTimer:Start()
|
||||
self.timerFrame.endTime = 91
|
||||
self.timerFrame.timeSinceLastUpdate = 0
|
||||
self.timerFrame:SetScript("OnUpdate", ShadowsightTimer.OnUpdate)
|
||||
function ShadowsightTimer:Start(time, frame)
|
||||
frame.endTime = time or Gladdy.db.shadowsightTimerStartTime
|
||||
frame.active = true
|
||||
ShadowsightTimer:NotifyStart()
|
||||
frame.announced = nil
|
||||
frame.timeSinceLastUpdate = 0
|
||||
frame.font:SetTextColor(1, 0.8, 0)
|
||||
frame:SetScript("OnUpdate", ShadowsightTimer.OnUpdate)
|
||||
end
|
||||
|
||||
function ShadowsightTimer.OnUpdate(self, elapsed)
|
||||
self.timeSinceLastUpdate = self.timeSinceLastUpdate + elapsed;
|
||||
self.endTime = self.endTime - elapsed
|
||||
|
||||
if (self.timeSinceLastUpdate > 0.1) then
|
||||
if (self.timeSinceLastUpdate > 0.01) then
|
||||
self.font:SetFormattedText(floor(self.endTime / 60) .. ":" .. "%02d", self.endTime - floor(self.endTime / 60) * 60)
|
||||
self.timeSinceLastUpdate = 0;
|
||||
if floor(self.endTime) == 15 and Gladdy.db.shadowsightAnnounce then
|
||||
if floor(self.endTime) == 15 and Gladdy.db.shadowsightAnnounce and not self.announced then
|
||||
self.announced = true
|
||||
Gladdy:SendMessage("SHADOWSIGHT", L["Shadowsight up in %ds"]:format(15))
|
||||
end
|
||||
end
|
||||
@ -143,9 +212,61 @@ function ShadowsightTimer.OnUpdate(self, elapsed)
|
||||
self:SetScript("OnUpdate", nil)
|
||||
self.font:SetText("0:00")
|
||||
self.font:SetTextColor(0, 1, 0)
|
||||
self.active = false
|
||||
ShadowsightTimer:NotifyEnd()
|
||||
end
|
||||
end
|
||||
|
||||
function ShadowsightTimer:NotifyStart()
|
||||
local show = Gladdy.db.shadowsightTimerShowTwoTimer
|
||||
if self.timerFrame1.active and self.timerFrame2.active then
|
||||
if self.timerFrame1.endTime < self.timerFrame2.endTime then
|
||||
self.timerFrame1:SetAlpha(1)
|
||||
self.timerFrame2:SetAlpha(show and 1 or 0)
|
||||
else
|
||||
self.timerFrame1:SetAlpha(show and 1 or 0)
|
||||
self.timerFrame2:SetAlpha(1)
|
||||
end
|
||||
else
|
||||
if self.timerFrame1.active then
|
||||
self.timerFrame1:SetAlpha(1)
|
||||
self.timerFrame2:SetAlpha(show and 1 or 0)
|
||||
elseif self.timerFrame2.active then
|
||||
self.timerFrame1:SetAlpha(show and 1 or 0)
|
||||
self.timerFrame2:SetAlpha(1)
|
||||
else
|
||||
self.timerFrame1:SetAlpha(1)
|
||||
self.timerFrame2:SetAlpha(show and 1 or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
function ShadowsightTimer:NotifyEnd()
|
||||
local show = Gladdy.db.shadowsightTimerShowTwoTimer
|
||||
if self.timerFrame1.active then
|
||||
self.timerFrame1:SetAlpha(1)
|
||||
self.timerFrame2:SetAlpha(show and 1 or 0)
|
||||
elseif self.timerFrame2.active then
|
||||
self.timerFrame1:SetAlpha(show and 1 or 0)
|
||||
self.timerFrame2:SetAlpha(1)
|
||||
else
|
||||
self.timerFrame1:SetAlpha(1)
|
||||
self.timerFrame2:SetAlpha(show and 1 or 0)
|
||||
end
|
||||
end
|
||||
function ShadowsightTimer:GetHiddenTimer()
|
||||
if self.timerFrame1.active and self.timerFrame2.active then
|
||||
return self.timerFrame1.endTime < self.timerFrame2.endTime and self.timerFrame1 or self.timerFrame2
|
||||
else
|
||||
return self.timerFrame1.active and self.timerFrame2 or self.timerFrame1
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------
|
||||
|
||||
-- OPTIONS
|
||||
|
||||
---------------------------
|
||||
|
||||
function ShadowsightTimer:GetOptions()
|
||||
return {
|
||||
headerArenaCountdown = {
|
||||
@ -167,21 +288,52 @@ function ShadowsightTimer:GetOptions()
|
||||
order = 4,
|
||||
width = "full",
|
||||
}),
|
||||
shadowsightTimerShowTwoTimer = Gladdy:option({
|
||||
type = "toggle",
|
||||
name = L["Show two timers"],
|
||||
order = 5,
|
||||
width = "full",
|
||||
}),
|
||||
shadowsightAnnounce = Gladdy:option({
|
||||
type = "toggle",
|
||||
name = L["Announce"],
|
||||
--desc = L["Turns countdown before the start of an arena match on/off."],
|
||||
order = 5,
|
||||
order = 6,
|
||||
width = "full",
|
||||
}),
|
||||
shadowsightTimerScale = Gladdy:option({
|
||||
type = "range",
|
||||
name = L["Scale"],
|
||||
order = 6,
|
||||
order = 7,
|
||||
min = 0.1,
|
||||
max = 5,
|
||||
step = 0.1,
|
||||
width = "full",
|
||||
}),
|
||||
headerTimer = {
|
||||
type = "header",
|
||||
name = L["Shadowsight CDs"],
|
||||
order = 10,
|
||||
},
|
||||
shadowsightTimerStartTime = Gladdy:option({
|
||||
type = "range",
|
||||
name = L["Start Time"],
|
||||
desc = L["Start time in seconds"],
|
||||
min = 80,
|
||||
max = 100,
|
||||
order = 11,
|
||||
step = 0.1,
|
||||
width = "full",
|
||||
}),
|
||||
shadowsightTimerResetTime = Gladdy:option({
|
||||
type = "range",
|
||||
name = L["Reset Time"],
|
||||
desc = L["Reset time in seconds"],
|
||||
min = 110,
|
||||
max = 130,
|
||||
order = 12,
|
||||
step = 0.1,
|
||||
width = "full",
|
||||
}),
|
||||
}
|
||||
end
|
Loading…
Reference in New Issue
Block a user