Gladdy-TBC/Modules/Highlight.lua

271 lines
9.8 KiB
Lua
Raw Permalink Normal View History

2021-05-17 16:49:54 +02:00
local CreateFrame, UnitIsUnit = CreateFrame, UnitIsUnit
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
local Highlight = Gladdy:NewModule("Highlight", nil, {
2021-05-22 13:41:31 +02:00
highlightBorderSize = 1,
highlightInset = false,
2021-05-17 16:49:54 +02:00
targetBorderColor = { r = 1, g = 0.8, b = 0, a = 1 },
focusBorderColor = { r = 1, g = 0, b = 0, a = 1 },
leaderBorderColor = { r = 0, g = 1, b = 0, a = 1 },
2021-05-22 13:41:31 +02:00
highlightBorderStyle = "Square Full White",
2021-05-17 16:49:54 +02:00
highlight = true,
targetBorder = true,
focusBorder = true,
leaderBorder = true,
})
function Highlight:Initialize()
self:RegisterMessage("JOINED_ARENA")
end
function Highlight:JOINED_ARENA()
self:RegisterEvent("PLAYER_FOCUS_CHANGED")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:SetScript("OnEvent", function(self, event, ...)
if self[event] then
self[event](self, ...)
end
end)
end
function Highlight:Reset()
self:UnregisterAllEvents()
self:SetScript("OnEvent", nil)
end
function Highlight:PLAYER_TARGET_CHANGED()
for i=1, Gladdy.curBracket do
self:Toggle("arena" .. i, "target", UnitIsUnit("target", "arena" .. i))
end
end
function Highlight:PLAYER_FOCUS_CHANGED()
for i=1, Gladdy.curBracket do
self:Toggle("arena" .. i, "focus", UnitIsUnit("focus", "arena" .. i))
end
end
function Highlight:CreateFrame(unit)
local button = Gladdy.buttons[unit]
if (not button) then
return
end
2021-05-24 12:41:21 +02:00
local healthBar = Gladdy.modules["Health Bar"].frames[unit]
2021-05-17 16:49:54 +02:00
local targetBorder = CreateFrame("Frame", nil, button, BackdropTemplateMixin and "BackdropTemplate")
2021-05-22 13:41:31 +02:00
targetBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = Gladdy.db.highlightBorderSize })
2021-05-19 19:30:54 +02:00
--targetBorder:SetFrameStrata("MEDIUM")
2021-05-17 16:49:54 +02:00
targetBorder:Hide()
local focusBorder = CreateFrame("Frame", nil, button, BackdropTemplateMixin and "BackdropTemplate")
2021-05-22 13:41:31 +02:00
focusBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = Gladdy.db.highlightBorderSize })
2021-05-19 19:30:54 +02:00
--focusBorder:SetFrameStrata("MEDIUM")
2021-05-17 16:49:54 +02:00
focusBorder:Hide()
local leaderBorder = CreateFrame("Frame", nil, button, BackdropTemplateMixin and "BackdropTemplate")
2021-05-22 13:41:31 +02:00
leaderBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = Gladdy.db.highlightBorderSize })
2021-05-19 19:30:54 +02:00
--leaderBorder:SetFrameStrata("MEDIUM")
2021-05-17 16:49:54 +02:00
leaderBorder:Hide()
local highlight = healthBar:CreateTexture(nil, "OVERLAY")
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
highlight:SetBlendMode("ADD")
highlight:SetAlpha(0.5)
highlight:ClearAllPoints()
highlight:SetAllPoints(healthBar)
highlight:Hide()
button.targetBorder = targetBorder
button.focusBorder = focusBorder
button.leaderBorder = leaderBorder
button.highlight = highlight
end
function Highlight:UpdateFrame(unit)
local button = Gladdy.buttons[unit]
if (not button) then
return
end
local borderSize = Gladdy.db.highlightBorderSize
2021-05-22 13:41:31 +02:00
local borderOffset = borderSize
2021-05-17 16:49:54 +02:00
local iconSize = Gladdy.db.healthBarHeight + Gladdy.db.powerBarHeight + 1
2021-05-22 13:41:31 +02:00
local width = Gladdy.db.barWidth + (Gladdy.db.highlightInset and 0 or borderSize * 2)
local height = iconSize + (Gladdy.db.highlightInset and 0 or borderSize * 2)
2021-05-17 16:49:54 +02:00
button.targetBorder:SetWidth(width)
button.targetBorder:SetHeight(height)
button.targetBorder:ClearAllPoints()
2021-05-22 13:41:31 +02:00
if Gladdy.db.highlightInset then
button.targetBorder:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT", -(borderOffset/Gladdy.db.statusbarBorderOffset), (borderOffset/Gladdy.db.statusbarBorderOffset))
button.targetBorder:SetPoint("BOTTOMRIGHT", button.powerBar, "BOTTOMRIGHT", (borderOffset/Gladdy.db.statusbarBorderOffset), -(borderOffset/Gladdy.db.statusbarBorderOffset))
else
button.targetBorder:SetPoint("TOP", button.healthBar, "TOP", 0, (Gladdy.db.highlightInset and 0 or borderSize))
end
button.targetBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = borderSize })
2021-05-17 16:49:54 +02:00
button.targetBorder:SetBackdropBorderColor(Gladdy.db.targetBorderColor.r, Gladdy.db.targetBorderColor.g, Gladdy.db.targetBorderColor.b, Gladdy.db.targetBorderColor.a)
button.focusBorder:SetWidth(width)
button.focusBorder:SetHeight(height)
button.focusBorder:ClearAllPoints()
2021-05-22 13:41:31 +02:00
if Gladdy.db.highlightInset then
button.focusBorder:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT", -(borderOffset/Gladdy.db.statusbarBorderOffset), (borderOffset/Gladdy.db.statusbarBorderOffset))
button.focusBorder:SetPoint("BOTTOMRIGHT", button.powerBar, "BOTTOMRIGHT", (borderOffset/Gladdy.db.statusbarBorderOffset), -(borderOffset/Gladdy.db.statusbarBorderOffset))
else
button.focusBorder:SetPoint("TOP", button.healthBar, "TOP", 0, (Gladdy.db.highlightInset and 0 or borderSize))
end
button.focusBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = borderSize })
2021-05-17 16:49:54 +02:00
button.focusBorder:SetBackdropBorderColor(Gladdy.db.focusBorderColor.r, Gladdy.db.focusBorderColor.g, Gladdy.db.focusBorderColor.b, Gladdy.db.focusBorderColor.a)
button.leaderBorder:SetWidth(width)
button.leaderBorder:SetHeight(height)
button.leaderBorder:ClearAllPoints()
2021-05-22 13:41:31 +02:00
if Gladdy.db.highlightInset then
button.leaderBorder:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT", -(borderOffset/Gladdy.db.statusbarBorderOffset), (borderOffset/Gladdy.db.statusbarBorderOffset))
button.leaderBorder:SetPoint("BOTTOMRIGHT", button.powerBar, "BOTTOMRIGHT", (borderOffset/Gladdy.db.statusbarBorderOffset), -(borderOffset/Gladdy.db.statusbarBorderOffset))
else
button.leaderBorder:SetPoint("TOP", button.healthBar, "TOP", 0, (Gladdy.db.highlightInset and 0 or borderSize))
end
button.leaderBorder:SetBackdrop({ edgeFile = Gladdy.LSM:Fetch("border", Gladdy.db.highlightBorderStyle), edgeSize = borderSize })
2021-05-17 16:49:54 +02:00
button.leaderBorder:SetBackdropBorderColor(Gladdy.db.leaderBorderColor.r, Gladdy.db.leaderBorderColor.g, Gladdy.db.leaderBorderColor.b, Gladdy.db.leaderBorderColor.a)
if Gladdy.frame.testing then
Highlight:Test(unit)
end
end
function Highlight:ResetUnit(unit)
local button = Gladdy.buttons[unit]
if (not button) then
return
end
button.targetBorder:Hide()
button.focusBorder:Hide()
button.leaderBorder:Hide()
button.highlight:Hide()
end
function Highlight:Test(unit)
if (unit == "arena1") then
self:Toggle(unit, "focus", true)
elseif (unit == "arena2") then
self:Toggle(unit, "target", true)
elseif (unit == "arena3") then
self:Toggle(unit, "leader", true)
end
end
function Highlight:Toggle(unit, frame, show)
local button = Gladdy.buttons[unit]
if (not button) then
return
end
if (frame == "target") then
if (Gladdy.db.targetBorder and show) then
button.targetBorder:Show()
else
button.targetBorder:Hide()
end
if (Gladdy.db.highlight and show) then
button.highlight:Show()
else
button.highlight:Hide()
end
elseif (frame == "focus") then
if (Gladdy.db.focusBorder and show) then
button.focusBorder:Show()
else
button.focusBorder:Hide()
end
elseif (frame == "leader") then
if (Gladdy.db.leaderBorder and show) then
button.leaderBorder:Show()
else
button.leaderBorder:Hide()
end
end
end
function Highlight:GetOptions()
return {
headerHighlight = {
type = "header",
name = L["Highlight"],
order = 2,
},
2021-05-22 13:41:31 +02:00
highlightInset = Gladdy:option({
type = "toggle",
name = L["Show Inside"],
desc = L["Show Highlight border inside of frame"],
order = 3,
}),
highlightBorderSize = Gladdy:option({
2021-05-17 16:49:54 +02:00
type = "range",
name = L["Border size"],
desc = L["Border size"],
2021-05-22 13:41:31 +02:00
order = 4,
2021-05-17 16:49:54 +02:00
min = 1,
2021-05-22 13:41:31 +02:00
max = 20,
2021-05-17 16:49:54 +02:00
step = 1,
2021-05-22 13:41:31 +02:00
}),
highlightBorderStyle = Gladdy:option({
type = "select",
name = L["Border style"],
order = 5,
dialogControl = "LSM30_Border",
values = AceGUIWidgetLSMlists.border,
}),
headerColor = {
type = "header",
name = L["Colors"],
order = 6,
2021-05-17 16:49:54 +02:00
},
targetBorderColor = Gladdy:colorOption({
type = "color",
name = L["Target border color"],
desc = L["Color of the selected targets border"],
2021-05-22 13:41:31 +02:00
order = 7,
2021-05-17 16:49:54 +02:00
hasAlpha = true,
}),
focusBorderColor = Gladdy:colorOption({
type = "color",
name = L["Focus border color"],
desc = L["Color of the focus border"],
2021-05-22 13:41:31 +02:00
order = 8,
2021-05-17 16:49:54 +02:00
hasAlpha = true,
}),
headerEnable = {
type = "header",
2021-05-24 12:41:21 +02:00
name = L["Enabled"],
2021-05-17 16:49:54 +02:00
order = 10,
},
highlight = Gladdy:option({
type = "toggle",
name = L["Highlight target"],
desc = L["Toggle if the selected target should be highlighted"],
order = 11,
2021-05-24 12:41:21 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
targetBorder = Gladdy:option({
type = "toggle",
name = L["Show border around target"],
desc = L["Toggle if a border should be shown around the selected target"],
order = 12,
2021-05-24 12:41:21 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
focusBorder = Gladdy:option({
type = "toggle",
name = L["Show border around focus"],
desc = L["Toggle of a border should be shown around the current focus"],
order = 13,
2021-05-24 12:41:21 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
}
end