Gladdy-TBC/Modules/Trinket.lua

563 lines
21 KiB
Lua
Raw Permalink Normal View History

local ceil, str_gsub = ceil, string.gsub
local C_PvP = C_PvP
2021-05-17 16:49:54 +02:00
local CreateFrame = CreateFrame
local GetTime = GetTime
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
2022-01-11 00:29:17 +01:00
local Trinket = Gladdy:NewModule("Trinket", 80, {
2021-05-17 16:49:54 +02:00
trinketFont = "DorisPP",
trinketFontScale = 1,
2022-01-12 20:57:53 +01:00
trinketFontEnabled = true,
2021-05-17 16:49:54 +02:00
trinketEnabled = true,
trinketSize = 60 + 20 + 1,
trinketWidthFactor = 0.9,
trinketBorderStyle = "Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp",
trinketBorderColor = { r = 0, g = 0, b = 0, a = 1 },
trinketDisableCircle = false,
trinketCooldownAlpha = 1,
2021-09-18 15:00:34 +02:00
trinketCooldownNumberAlpha = 1,
2022-01-11 00:29:17 +01:00
trinketXOffset = 0,
trinketYOffset = 0,
trinketFrameStrata = "MEDIUM",
trinketFrameLevel = 5,
2022-01-12 20:57:53 +01:00
trinketColored = false,
2022-01-12 22:39:06 +01:00
trinketColoredCd = { r = 1, g = 0, b = 0, a = 1 },
trinketColoredNoCd = { r = 0, g = 1, b = 0, a = 1 },
trinketGroup = false,
trinketGroupDirection = "DOWN",
2021-05-17 16:49:54 +02:00
})
function Trinket:Initialize()
self.frames = {}
if Gladdy.db.trinketEnabled then
self:RegisterMessage("JOINED_ARENA")
end
end
2021-05-17 16:49:54 +02:00
function Trinket:UpdateFrameOnce()
if Gladdy.db.trinketEnabled then
self:RegisterMessage("JOINED_ARENA")
else
self:UnregisterAllMessages()
end
2021-05-17 16:49:54 +02:00
end
local function iconTimer(self, elapsed)
if (self.active) then
if (self.timeLeft <= 0) then
self.active = false
self.cooldown:Clear()
Gladdy:SendMessage("TRINKET_READY", self.unit)
2022-01-12 20:57:53 +01:00
if Gladdy.db.trinketColored then
2022-01-12 22:39:06 +01:00
self:SetBackdropColor(Gladdy:SetColor(Gladdy.db.trinketColoredNoCd))
2022-01-12 20:57:53 +01:00
end
else
self.timeLeft = self.timeLeft - elapsed
end
local timeLeft = ceil(self.timeLeft)
if timeLeft >= 60 then
2021-09-18 15:00:34 +02:00
self.cooldownFont:SetTextColor(1, 1, 0, Gladdy.db.trinketCooldownNumberAlpha)
2021-09-14 23:55:17 +02:00
self.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), (self:GetWidth()/2 - 0.15*self:GetWidth()) * Gladdy.db.trinketFontScale, "OUTLINE")
elseif timeLeft < 60 and timeLeft >= 30 then
2021-09-18 15:00:34 +02:00
self.cooldownFont:SetTextColor(1, 1, 0, Gladdy.db.trinketCooldownNumberAlpha)
2021-09-14 23:55:17 +02:00
self.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), (self:GetWidth()/2 - 1) * Gladdy.db.trinketFontScale, "OUTLINE")
elseif timeLeft < 30 and timeLeft >= 11 then
2021-09-18 15:00:34 +02:00
self.cooldownFont:SetTextColor(1, 0.7, 0, Gladdy.db.trinketCooldownNumberAlpha)
2021-09-14 23:55:17 +02:00
self.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), (self:GetWidth()/2 - 1) * Gladdy.db.trinketFontScale, "OUTLINE")
elseif timeLeft <= 10 and timeLeft >= 5 then
2021-09-18 15:00:34 +02:00
self.cooldownFont:SetTextColor(1, 0.7, 0, Gladdy.db.trinketCooldownNumberAlpha)
2021-09-14 23:55:17 +02:00
self.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), (self:GetWidth()/2 - 1) * Gladdy.db.trinketFontScale, "OUTLINE")
elseif timeLeft < 5 and timeLeft > 0 then
2021-09-18 15:00:34 +02:00
self.cooldownFont:SetTextColor(1, 0, 0, Gladdy.db.trinketCooldownNumberAlpha)
2021-09-14 23:55:17 +02:00
self.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), (self:GetWidth()/2 - 1) * Gladdy.db.trinketFontScale, "OUTLINE")
end
2022-01-12 20:57:53 +01:00
if Gladdy.db.trinketFontEnabled then
Gladdy:FormatTimer(self.cooldownFont, self.timeLeft, self.timeLeft < 10, true)
else
self.cooldownFont:SetText("")
end
end
end
2021-05-17 16:49:54 +02:00
function Trinket:CreateFrame(unit)
2022-01-12 20:57:53 +01:00
local trinket = CreateFrame("Button", "GladdyTrinketButton" .. unit, Gladdy.buttons[unit], BackdropTemplateMixin and "BackdropTemplate")
trinket:SetBackdrop({bgFile = "Interface\\AddOns\\Gladdy\\Images\\trinket" })
2021-05-19 19:30:32 +02:00
trinket:EnableMouse(false)
trinket:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket:SetFrameLevel(Gladdy.db.trinketFrameLevel)
2021-05-17 16:49:54 +02:00
trinket.texture = trinket:CreateTexture(nil, "BACKGROUND")
trinket.texture:SetAllPoints(trinket)
trinket.texture:SetTexture("Interface\\Icons\\INV_Jewelry_TrinketPVP_02")
2021-05-19 14:57:29 +02:00
trinket.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask")
2021-05-17 16:49:54 +02:00
trinket.cooldown = CreateFrame("Cooldown", nil, trinket, "CooldownFrameTemplate")
trinket.cooldown.noCooldownCount = true --Gladdy.db.trinketDisableOmniCC
trinket.cooldown:SetHideCountdownNumbers(true)
trinket.cooldown:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.cooldown:SetFrameLevel(Gladdy.db.trinketFrameLevel + 1)
2021-05-17 16:49:54 +02:00
trinket.cooldownFrame = CreateFrame("Frame", nil, trinket)
trinket.cooldownFrame:ClearAllPoints()
trinket.cooldownFrame:SetPoint("TOPLEFT", trinket, "TOPLEFT")
trinket.cooldownFrame:SetPoint("BOTTOMRIGHT", trinket, "BOTTOMRIGHT")
trinket.cooldownFrame:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.cooldownFrame:SetFrameLevel(Gladdy.db.trinketFrameLevel + 2)
2021-05-17 16:49:54 +02:00
trinket.cooldownFont = trinket.cooldownFrame:CreateFontString(nil, "OVERLAY")
2021-09-14 23:55:17 +02:00
trinket.cooldownFont:SetFont(Gladdy:SMFetch("font", "trinketFont"), 20, "OUTLINE")
2021-05-17 16:49:54 +02:00
--trinket.cooldownFont:SetAllPoints(trinket.cooldown)
trinket.cooldownFont:SetJustifyH("CENTER")
trinket.cooldownFont:SetPoint("CENTER")
trinket.borderFrame = CreateFrame("Frame", nil, trinket)
trinket.borderFrame:SetAllPoints(trinket)
trinket.borderFrame:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.borderFrame:SetFrameLevel(Gladdy.db.trinketFrameLevel + 3)
2021-05-17 16:49:54 +02:00
trinket.texture.overlay = trinket.borderFrame:CreateTexture(nil, "OVERLAY")
trinket.texture.overlay:SetAllPoints(trinket)
trinket.texture.overlay:SetTexture(Gladdy.db.trinketBorderStyle)
trinket.unit = unit
2021-05-17 16:49:54 +02:00
trinket:SetScript("OnUpdate", iconTimer)
2021-05-17 16:49:54 +02:00
self.frames[unit] = trinket
Gladdy.buttons[unit].trinket = trinket
2021-05-17 16:49:54 +02:00
end
function Trinket:UpdateFrame(unit)
local trinket = self.frames[unit]
if (not trinket) then
return
end
2022-01-12 20:57:53 +01:00
if Gladdy.db.trinketColored then
if trinket.active then
2022-01-12 22:39:06 +01:00
trinket:SetBackdropColor(Gladdy:SetColor(Gladdy.db.trinketColoredCd))
2022-01-12 20:57:53 +01:00
else
2022-01-12 22:39:06 +01:00
trinket:SetBackdropColor(Gladdy:SetColor(Gladdy.db.trinketColoredNoCd))
2022-01-12 20:57:53 +01:00
end
trinket.texture:SetTexture()
else
2022-01-12 23:17:35 +01:00
trinket:SetBackdropColor(0,0,0,0)
2022-01-12 20:57:53 +01:00
trinket.texture:SetTexture("Interface\\Icons\\INV_Jewelry_TrinketPVP_02")
end
2021-05-17 16:49:54 +02:00
local width, height = Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor, Gladdy.db.trinketSize
trinket:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket:SetFrameLevel(Gladdy.db.trinketFrameLevel)
trinket.cooldown:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.cooldown:SetFrameLevel(Gladdy.db.trinketFrameLevel + 1)
trinket.cooldownFrame:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.cooldownFrame:SetFrameLevel(Gladdy.db.trinketFrameLevel + 2)
trinket.borderFrame:SetFrameStrata(Gladdy.db.trinketFrameStrata)
trinket.borderFrame:SetFrameLevel(Gladdy.db.trinketFrameLevel + 3)
2021-05-17 16:49:54 +02:00
trinket:SetWidth(width)
trinket:SetHeight(height)
trinket.cooldown:SetWidth(width - width/16)
trinket.cooldown:SetHeight(height - height/16)
trinket.cooldown:ClearAllPoints()
trinket.cooldown:SetPoint("CENTER", trinket, "CENTER")
trinket.cooldown.noCooldownCount = true -- Gladdy.db.trinketDisableOmniCC
trinket.cooldown:SetAlpha(Gladdy.db.trinketCooldownAlpha)
trinket.texture:ClearAllPoints()
trinket.texture:SetAllPoints(trinket)
trinket.texture.overlay:SetTexture(Gladdy.db.trinketBorderStyle)
2022-01-12 22:39:06 +01:00
trinket.texture.overlay:SetVertexColor(Gladdy:SetColor(Gladdy.db.trinketBorderColor))
2021-05-17 16:49:54 +02:00
2022-01-11 00:29:17 +01:00
Gladdy:SetPosition(trinket, unit, "trinketXOffset", "trinketYOffset", Trinket:LegacySetPosition(trinket, unit), Trinket)
if (Gladdy.db.trinketGroup) then
if (unit ~= "arena1") then
local previousUnit = "arena" .. str_gsub(unit, "arena", "") - 1
self.frames[unit]:ClearAllPoints()
if Gladdy.db.trinketGroupDirection == "RIGHT" then
self.frames[unit]:SetPoint("LEFT", self.frames[previousUnit], "RIGHT", 0, 0)
elseif Gladdy.db.trinketGroupDirection == "LEFT" then
self.frames[unit]:SetPoint("RIGHT", self.frames[previousUnit], "LEFT", 0, 0)
elseif Gladdy.db.trinketGroupDirection == "UP" then
self.frames[unit]:SetPoint("BOTTOM", self.frames[previousUnit], "TOP", 0, 0)
elseif Gladdy.db.trinketGroupDirection == "DOWN" then
self.frames[unit]:SetPoint("TOP", self.frames[previousUnit], "BOTTOM", 0, 0)
end
end
end
2022-01-11 00:29:17 +01:00
if (unit == "arena1") then
Gladdy:CreateMover(trinket,"trinketXOffset", "trinketYOffset", L["Trinket"],
{"TOPLEFT", "TOPLEFT"},
Gladdy.db.trinketSize * Gladdy.db.trinketWidthFactor,
Gladdy.db.trinketSize,
0,
2022-01-13 23:11:33 +01:00
0, "trinketEnabled")
2021-05-17 16:49:54 +02:00
end
2022-01-12 20:57:53 +01:00
trinket.cooldown:SetAlpha(Gladdy.db.trinketCooldownAlpha)
if Gladdy.db.trinketDisableCircle then
trinket.cooldown:Hide()
else
trinket.cooldown:Show()
end
if (not Gladdy.db.trinketEnabled) then
2021-05-17 16:49:54 +02:00
trinket:Hide()
else
trinket:Show()
end
end
function Trinket:Reset()
self:UnregisterEvent("ARENA_COOLDOWNS_UPDATE")
self:SetScript("OnEvent", nil)
end
function Trinket:ResetUnit(unit)
local trinket = self.frames[unit]
if (not trinket) then
return
end
trinket.timeLeft = nil
trinket.active = false
trinket.cooldown:Clear()
trinket.cooldownFont:SetText("")
end
function Trinket:Test(unit)
local trinket = self.frames[unit]
if (not trinket) then
return
end
if (unit == "arena2" or unit == "arena3") then
self:Used(unit, GetTime() * 1000, 120000)
end
end
function Trinket:JOINED_ARENA()
self:RegisterEvent("ARENA_COOLDOWNS_UPDATE")
self:SetScript("OnEvent", function(self, event, ...)
if self[event] then
self[event](self, ...)
end
end)
end
function Trinket:ARENA_COOLDOWNS_UPDATE()
for i=1, Gladdy.curBracket do
local unit = "arena" .. i
local spellID, itemID, startTime, duration = C_PvP.GetArenaCrowdControlInfo(unit);
if (spellID) then
if (startTime ~= 0 and duration ~= 0) then
self:Used(unit, startTime, duration)
end
end
end
end
function Trinket:Used(unit, startTime, duration)
local trinket = self.frames[unit]
if (not trinket) then
return
end
if not trinket.active then
trinket.timeLeft = (startTime/1000.0 + duration/1000.0) - GetTime()
if not Gladdy.db.trinketDisableCircle then trinket.cooldown:SetCooldown(startTime/1000.0, duration/1000.0) end
trinket.active = true
2022-01-12 20:57:53 +01:00
if Gladdy.db.trinketColored then
2022-01-12 22:39:06 +01:00
trinket:SetBackdropColor(Gladdy:SetColor(Gladdy.db.trinketColoredCd))
2022-01-12 20:57:53 +01:00
end
2021-05-17 16:49:54 +02:00
Gladdy:SendMessage("TRINKET_USED", unit)
end
end
function Trinket:GetOptions()
return {
headerTrinket = {
type = "header",
name = L["Trinket"],
order = 2,
},
trinketEnabled = Gladdy:option({
type = "toggle",
name = L["Enabled"],
desc = L["Enable trinket icon"],
order = 3,
}),
2022-01-12 20:57:53 +01:00
trinketColored = Gladdy:option({
type = "toggle",
2022-01-12 23:04:23 +01:00
name = L["Colored trinket"],
desc = L["Shows a solid colored icon when off/off CD."],
2022-01-12 20:57:53 +01:00
order = 4,
disabled = function() return not Gladdy.db.trinketEnabled end,
2022-01-12 20:57:53 +01:00
}),
2022-01-12 22:39:06 +01:00
trinketColoredCd = Gladdy:colorOption({
type = "color",
name = L["Colored trinket CD"],
desc = L["Color of the border"],
order = 5,
hasAlpha = true,
disabled = function() return not Gladdy.db.trinketEnabled end,
2022-01-12 22:39:06 +01:00
}),
trinketColoredNoCd = Gladdy:colorOption({
type = "color",
name = L["Colored trinket No CD"],
desc = L["Color of the border"],
order = 6,
hasAlpha = true,
disabled = function() return not Gladdy.db.trinketEnabled end,
2022-01-12 22:39:06 +01:00
}),
trinketGroup = Gladdy:option({
type = "toggle",
name = L["Group Class Icons"],
order = 7,
disabled = function() return not Gladdy.db.trinketEnabled end,
}),
trinketGroupDirection = Gladdy:option({
type = "select",
name = L["Group direction"],
order = 8,
values = {
["RIGHT"] = L["Right"],
["LEFT"] = L["Left"],
["UP"] = L["Up"],
["DOWN"] = L["Down"],
},
disabled = function()
return not Gladdy.db.trinketGroup or not Gladdy.db.trinketEnabled
end,
}),
2021-05-17 16:49:54 +02:00
group = {
type = "group",
childGroups = "tree",
2021-05-24 12:41:21 +02:00
name = L["Frame"],
2022-01-12 20:57:53 +01:00
order = 5,
disabled = function() return not Gladdy.db.trinketEnabled end,
2021-05-17 16:49:54 +02:00
args = {
general = {
type = "group",
name = L["Size"],
order = 1,
args = {
header = {
type = "header",
name = L["Size"],
2021-05-24 12:41:21 +02:00
order = 1,
2021-05-17 16:49:54 +02:00
},
trinketSize = Gladdy:option({
type = "range",
2021-05-24 12:41:21 +02:00
name = L["Size"],
2021-05-17 16:49:54 +02:00
min = 5,
max = 100,
step = 1,
order = 4,
2021-06-15 09:06:50 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
trinketWidthFactor = Gladdy:option({
type = "range",
name = L["Icon width factor"],
min = 0.5,
max = 2,
step = 0.05,
order = 6,
2021-06-15 09:06:50 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
},
},
cooldown = {
type = "group",
name = L["Cooldown"],
order = 2,
args = {
header = {
type = "header",
name = L["Cooldown"],
order = 4,
},
trinketDisableCircle = Gladdy:option({
type = "toggle",
name = L["No Cooldown Circle"],
order = 7,
2021-05-24 12:41:21 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
trinketCooldownAlpha = Gladdy:option({
type = "range",
name = L["Cooldown circle alpha"],
min = 0,
max = 1,
step = 0.1,
order = 8,
2021-06-15 09:06:50 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
2021-09-18 15:00:34 +02:00
trinketCooldownNumberAlpha = Gladdy:option({
type = "range",
name = L["Cooldown number alpha"],
min = 0,
max = 1,
step = 0.1,
order = 9,
width = "full",
}),
2021-05-17 16:49:54 +02:00
},
},
font = {
type = "group",
name = L["Font"],
order = 3,
args = {
header = {
type = "header",
name = L["Font"],
2022-01-12 20:57:53 +01:00
order = 1,
2021-05-17 16:49:54 +02:00
},
2022-01-12 20:57:53 +01:00
trinketFontEnabled = Gladdy:option({
type = "toggle",
name = L["Font Enabled"],
order = 2,
width = "full",
}),
2021-05-17 16:49:54 +02:00
trinketFont = Gladdy:option({
type = "select",
name = L["Font"],
desc = L["Font of the cooldown"],
2022-01-12 20:57:53 +01:00
order = 3,
2021-05-17 16:49:54 +02:00
dialogControl = "LSM30_Font",
values = AceGUIWidgetLSMlists.font,
}),
trinketFontScale = Gladdy:option({
type = "range",
name = L["Font scale"],
desc = L["Scale of the font"],
2022-01-12 20:57:53 +01:00
order = 4,
2021-05-17 16:49:54 +02:00
min = 0.1,
max = 2,
step = 0.1,
2021-06-15 09:06:50 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
},
},
position = {
type = "group",
name = L["Position"],
order = 5,
2021-05-17 16:49:54 +02:00
args = {
header = {
type = "header",
2021-05-24 12:41:21 +02:00
name = L["Icon position"],
2021-05-17 16:49:54 +02:00
order = 4,
},
trinketXOffset = Gladdy:option({
type = "range",
name = L["Horizontal offset"],
order = 23,
min = -800,
max = 800,
step = 0.1,
width = "full",
}),
trinketYOffset = Gladdy:option({
type = "range",
name = L["Vertical offset"],
order = 24,
min = -800,
max = 800,
step = 0.1,
width = "full",
2021-05-17 16:49:54 +02:00
}),
},
},
border = {
type = "group",
name = L["Border"],
order = 4,
args = {
header = {
type = "header",
name = L["Border"],
order = 4,
},
trinketBorderStyle = Gladdy:option({
type = "select",
name = L["Border style"],
order = 31,
values = Gladdy:GetIconStyles()
}),
trinketBorderColor = Gladdy:colorOption({
type = "color",
name = L["Border color"],
desc = L["Color of the border"],
order = 32,
hasAlpha = true,
}),
},
},
frameStrata = {
type = "group",
name = L["Frame Strata and Level"],
order = 6,
args = {
headerAuraLevel = {
type = "header",
name = L["Frame Strata and Level"],
order = 1,
},
trinketFrameStrata = Gladdy:option({
type = "select",
name = L["Frame Strata"],
order = 2,
values = Gladdy.frameStrata,
sorting = Gladdy.frameStrataSorting,
width = "full",
}),
trinketFrameLevel = Gladdy:option({
type = "range",
name = L["Frame Level"],
min = 0,
max = 500,
step = 1,
order = 3,
width = "full",
}),
},
2021-05-17 16:49:54 +02:00
},
},
},
}
2022-01-11 00:29:17 +01:00
end
---------------------------
-- LAGACY HANDLER
---------------------------
function Trinket:LegacySetPosition(trinket, unit)
if Gladdy.db.newLayout then
return Gladdy.db.newLayout
end
trinket:ClearAllPoints()
local margin = (Gladdy.db.highlightInset and 0 or Gladdy.db.highlightBorderSize) + Gladdy.db.padding
if (Gladdy.db.classIconPos == "LEFT") then
if (Gladdy.db.trinketPos == "RIGHT") then
trinket:SetPoint("TOPLEFT", Gladdy.buttons[unit].healthBar, "TOPRIGHT", margin, 0)
else
trinket:SetPoint("TOPRIGHT", Gladdy.buttons[unit].classIcon, "TOPLEFT", -Gladdy.db.padding, 0)
end
else
if (Gladdy.db.trinketPos == "RIGHT") then
trinket:SetPoint("TOPLEFT", Gladdy.buttons[unit].classIcon, "TOPRIGHT", Gladdy.db.padding, 0)
else
trinket:SetPoint("TOPRIGHT", Gladdy.buttons[unit].healthBar, "TOPLEFT", -margin, 0)
end
end
2021-05-17 16:49:54 +02:00
end