Gladdy-TBC/Modules/CombatIndicator.lua

283 lines
9.6 KiB
Lua
Raw Permalink Normal View History

2021-05-19 16:35:26 +02:00
local select = select
local UnitExists, UnitAffectingCombat, GetSpellInfo = UnitExists, UnitAffectingCombat, GetSpellInfo
local CreateFrame = CreateFrame
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
2021-05-24 12:41:21 +02:00
local CombatIndicator = Gladdy:NewModule("Combat Indicator", nil, {
2021-05-19 16:35:26 +02:00
ciEnabled = true,
ciSize = 20,
ciAlpha = 1,
ciWidthFactor = 1,
ciXOffset = 0,
ciYOffset = -31,
ciBorderStyle = "Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp",
ciBorderColor = { r = 0, g = 0, b = 0, a = 1 },
ciFrameStrata = "HIGH",
ciFrameLevel = 5,
2021-05-19 16:35:26 +02:00
})
function CombatIndicator:Initialize()
self.frames = {}
self:RegisterMessage("JOINED_ARENA")
self.updateInterval = 0.05
self.combatIndicatorIcon = select(3, GetSpellInfo(674))
end
function CombatIndicator:JOINED_ARENA()
self:SetScript("OnUpdate", CombatIndicator.OnEvent)
self.lastTimeUpdated = 0
end
function CombatIndicator:CreateFrame(unit)
local button = Gladdy.buttons[unit]
if not button then
return
end
local ciFrame = CreateFrame("Frame", "GladdyCombatindicator" .. unit, button)
ciFrame:EnableMouse(false)
2021-09-24 15:51:24 +02:00
ciFrame:SetMovable(true)
ciFrame:SetFrameStrata(Gladdy.db.ciFrameStrata)
ciFrame:SetFrameLevel(Gladdy.db.ciFrameLevel)
2021-05-19 16:35:26 +02:00
ciFrame:SetHeight(Gladdy.db.ciSize)
ciFrame:SetWidth(Gladdy.db.ciSize * Gladdy.db.ciWidthFactor)
ciFrame.texture = ciFrame:CreateTexture(nil, "OVERLAY")
ciFrame.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask")
ciFrame.texture:SetTexture(self.combatIndicatorIcon)
ciFrame.texture:SetAllPoints(ciFrame)
ciFrame.border = ciFrame:CreateTexture(nil, "OVERLAY")
ciFrame.border:SetAllPoints(ciFrame)
ciFrame.border:SetTexture(Gladdy.db.ciBorderStyle)
ciFrame.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.ciBorderColor))
2021-05-19 16:35:26 +02:00
self.frames[unit] = ciFrame
button.ciFrame = ciFrame
end
function CombatIndicator:UpdateFrame(unit)
local button = Gladdy.buttons[unit]
local ciFrame = self.frames[unit]
if (not button or not ciFrame) then
return
end
ciFrame:SetFrameStrata(Gladdy.db.ciFrameStrata)
ciFrame:SetFrameLevel(Gladdy.db.ciFrameLevel)
2021-05-19 16:35:26 +02:00
ciFrame:SetHeight(Gladdy.db.ciSize)
ciFrame:SetWidth(Gladdy.db.ciSize * Gladdy.db.ciWidthFactor)
2021-05-22 13:28:27 +02:00
ciFrame.border:SetTexture(Gladdy.db.ciBorderStyle)
ciFrame.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.ciBorderColor))
2021-05-19 16:35:26 +02:00
2022-01-11 00:29:17 +01:00
Gladdy:SetPosition(ciFrame, unit, "ciXOffset", "ciYOffset", CombatIndicator:LegacySetPosition(ciFrame, unit), CombatIndicator)
2021-05-19 19:30:40 +02:00
2021-05-19 16:35:26 +02:00
ciFrame:SetAlpha(Gladdy.db.ciAlpha)
if (Gladdy.db.ciEnabled == false) then
ciFrame:Hide()
else
ciFrame:Show()
end
2021-09-24 15:51:24 +02:00
if (unit == "arena1") then
2022-01-13 23:11:33 +01:00
Gladdy:CreateMover(ciFrame, "ciXOffset", "ciYOffset", L["Combat Indicator"],
{"TOPLEFT", "TOPLEFT"},
Gladdy.db.ciSize * Gladdy.db.ciWidthFactor, Gladdy.db.ciSize,
0, 0, "ciEnabled")
2021-09-24 15:51:24 +02:00
end
2021-05-19 16:35:26 +02:00
end
function CombatIndicator:Test()
self.test = true
self:JOINED_ARENA()
end
function CombatIndicator:Reset()
self:SetScript("OnUpdate", nil)
self.test = false
end
function CombatIndicator.OnEvent(self, elapsed)
self.lastTimeUpdated = self.lastTimeUpdated + elapsed
if (self.lastTimeUpdated > self.updateInterval) then
for i=1,Gladdy.curBracket do
local unit = "arena" .. i
2021-06-22 12:18:45 +02:00
if Gladdy.db.ciEnabled and (CombatIndicator.test or (UnitExists(unit) and UnitAffectingCombat(unit))) then
2021-05-19 16:35:26 +02:00
CombatIndicator.frames[unit]:Show()
else
CombatIndicator.frames[unit]:Hide()
end
end
self.lastTimeUpdated = 0
end
end
function CombatIndicator:GetOptions()
return {
2021-05-24 12:41:21 +02:00
header = {
2021-05-19 16:35:26 +02:00
type = "header",
2021-05-24 12:41:21 +02:00
name = L["Combat Indicator"],
2021-05-19 16:35:26 +02:00
order = 2,
},
ciEnabled = Gladdy:option({
type = "toggle",
name = L["Enabled"],
2021-05-24 12:41:21 +02:00
desc = L["Enable Combat Indicator icon"],
2021-05-19 16:35:26 +02:00
order = 3,
}),
group = {
type = "group",
childGroups = "tree",
2021-05-24 12:41:21 +02:00
name = L["Frame"],
2021-05-19 16:35:26 +02:00
order = 4,
args = {
general = {
type = "group",
name = L["Frame"],
order = 1,
args = {
header = {
type = "header",
name = L["Frame"],
order = 1,
},
ciSize = Gladdy:option({
type = "range",
name = L["Icon size"],
min = 5,
max = 100,
step = 1,
order = 2,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-19 16:35:26 +02:00
}),
ciWidthFactor = Gladdy:option({
type = "range",
name = L["Icon width factor"],
min = 0.5,
max = 2,
step = 0.05,
order = 3,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-19 16:35:26 +02:00
}),
ciAlpha = Gladdy:option({
type = "range",
name = L["Alpha"],
min = 0,
max = 1,
step = 0.05,
order = 4,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-19 16:35:26 +02:00
}),
},
},
position = {
type = "group",
name = L["Position"],
order = 3,
2021-05-19 16:35:26 +02:00
args = {
header = {
type = "header",
name = L["Position"],
order = 4,
},
ciXOffset = Gladdy:option({
type = "range",
name = L["Horizontal offset"],
order = 23,
min = -400,
max = 400,
step = 0.1,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-19 16:35:26 +02:00
}),
ciYOffset = Gladdy:option({
type = "range",
name = L["Vertical offset"],
order = 24,
min = -400,
max = 400,
step = 0.1,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-19 16:35:26 +02:00
}),
},
},
border = {
type = "group",
name = L["Border"],
order = 2,
2021-05-19 16:35:26 +02:00
args = {
header = {
type = "header",
name = L["Border"],
order = 4,
},
ciBorderStyle = Gladdy:option({
type = "select",
name = L["Border style"],
order = 31,
values = Gladdy:GetIconStyles()
}),
ciBorderColor = 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 = 5,
args = {
headerAuraLevel = {
type = "header",
name = L["Frame Strata and Level"],
order = 1,
},
ciFrameStrata = Gladdy:option({
type = "select",
name = L["Frame Strata"],
order = 2,
values = Gladdy.frameStrata,
sorting = Gladdy.frameStrataSorting,
width = "full",
}),
ciFrameLevel = Gladdy:option({
type = "range",
name = L["Frame Level"],
min = 0,
max = 500,
step = 1,
order = 3,
width = "full",
}),
},
},
2021-05-19 16:35:26 +02:00
},
},
}
2022-01-11 00:29:17 +01:00
end
---------------------------
-- LAGACY HANDLER
---------------------------
function CombatIndicator:LegacySetPosition(ciFrame, unit)
if Gladdy.db.newLayout then
return Gladdy.db.newLayout
end
-- LEGACY options
local ANCHORS = { ["LEFT"] = "RIGHT", ["RIGHT"] = "LEFT", ["BOTTOM"] = "TOP", ["TOP"] = "BOTTOM"}
local ciAnchor = Gladdy.db.ciAnchor or Gladdy.legacy.ciAnchor
local ciPos = Gladdy.db.ciPos
ciFrame:ClearAllPoints()
ciFrame:SetPoint(ANCHORS[ciPos], Gladdy.buttons[unit][ciAnchor], ciPos, Gladdy.db.ciXOffset, Gladdy.db.ciYOffset)
return Gladdy.db.newLayout
2021-05-19 16:35:26 +02:00
end