Gladdy-TBC/Modules/Classicon.lua

350 lines
13 KiB
Lua
Raw Normal View History

local select = select
2021-05-17 16:49:54 +02:00
local Gladdy = LibStub("Gladdy")
local CreateFrame = CreateFrame
local GetSpellInfo = GetSpellInfo
2021-05-17 16:49:54 +02:00
local L = Gladdy.L
2022-01-11 00:29:17 +01:00
local Classicon = Gladdy:NewModule("Class Icon", 81, {
2022-01-12 02:25:11 +01:00
classIconEnabled = true,
2021-05-17 16:49:54 +02:00
classIconSize = 60 + 20 + 1,
classIconWidthFactor = 0.9,
classIconBorderStyle = "Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp",
classIconBorderColor = { r = 0, g = 0, b = 0, a = 1 },
classIconSpecIcon = false,
2022-01-11 00:29:17 +01:00
classIconXOffset = 0,
classIconYOffset = 0,
classIconFrameStrata = "MEDIUM",
classIconFrameLevel = 5,
2021-05-17 16:49:54 +02:00
})
local classIconPath = "Interface\\Addons\\Gladdy\\Images\\Classes\\"
local classIcons = {
["DRUID"] = classIconPath .. "inv_misc_monsterclaw_04",
["HUNTER"] = classIconPath .. "inv_weapon_bow_07",
["MAGE"] = classIconPath .. "inv_staff_13",
["PALADIN"] = classIconPath .. "inv_hammer_01",
["PRIEST"] = classIconPath .. "inv_staff_30",
["ROGUE"] = classIconPath .. "inv_throwingknife_04",
["SHAMAN"] = classIconPath .. "inv_jewelry_talisman_04",
["WARLOCK"] = classIconPath .. "spell_nature_drowsy",
["WARRIOR"] = classIconPath .. "inv_sword_27",
}
local specIcons = {
--DRUID
["DRUID"] = {
[L["Balance"]] = select(3, GetSpellInfo(8921)), -- Moonfire
[L["Feral"]] = select(3, GetSpellInfo(27545)), -- Cat Form
[L["Restoration"]] = select(3, GetSpellInfo(5185)), -- Healing Touch
},
["HUNTER"] = {
[L["Beast Mastery"]] = select(3, GetSpellInfo(1515)), -- Tame Beast
[L["Marksmanship"]] = select(3, GetSpellInfo(42243)), -- Volley
[L["Survival"]] = select(3, GetSpellInfo(1495)), -- Mongoose Bite
},
["MAGE"] = {
[L["Arcane"]] = select(3, GetSpellInfo(1459)), -- Arcane Intellect
[L["Fire"]] = select(3, GetSpellInfo(133)), -- Fireball
[L["Frost"]] = select(3, GetSpellInfo(116)), -- Frostbolt
},
["PALADIN"] = {
[L["Holy"]] = select(3, GetSpellInfo(635)), -- Holy Light
[L["Retribution"]] = select(3, GetSpellInfo(7294)), -- Retribution Aura
[L["Protection"]] = select(3, GetSpellInfo(32828)), -- Protection Aura
},
["PRIEST"] = {
[L["Discipline"]] = select(3, GetSpellInfo(1243)), -- Power Word: Fortitude
[L["Shadow"]] = select(3, GetSpellInfo(589)), -- Shadow Word: Pain
[L["Holy"]] = select(3, GetSpellInfo(635)), -- Holy Light
},
["ROGUE"] = {
[L["Assassination"]] = select(3, GetSpellInfo(1329)), -- Mutilate (Eviscerate? 2098)
[L["Combat"]] = select(3, GetSpellInfo(53)), -- Backstab
[L["Subtlety"]] = select(3, GetSpellInfo(1784)), -- Stealth
},
["SHAMAN"] = {
[L["Elemental"]] = select(3, GetSpellInfo(403)), -- Lightning Bolt
[L["Enhancement"]] = select(3, GetSpellInfo(324)), -- Lightning Shield
[L["Restoration"]] = select(3, GetSpellInfo(331)), -- Healing Wave
},
["WARLOCK"] = {
[L["Affliction"]] = select(3, GetSpellInfo(6789)), -- Affliction
[L["Demonology"]] = select(3, GetSpellInfo(5500)), -- Sense Demons
[L["Destruction"]] = select(3, GetSpellInfo(5740)), -- Rain of Fire
},
["WARRIOR"] = {
[L["Arms"]] = select(3, GetSpellInfo(12294)), -- Mortal Strike
[L["Fury"]] = select(3, GetSpellInfo(12325)), -- Inner Rage
[L["Protection"]] = select(3, GetSpellInfo(71)), -- Defensive Stance
},
}
2021-05-17 16:49:54 +02:00
function Classicon:Initialize()
self.frames = {}
self:RegisterMessage("ENEMY_SPOTTED")
self:RegisterMessage("UNIT_DEATH")
self:RegisterMessage("UNIT_SPEC")
2021-05-17 16:49:54 +02:00
end
function Classicon:CreateFrame(unit)
local classIcon = CreateFrame("Frame", nil, Gladdy.buttons[unit])
classIcon:EnableMouse(false)
2021-05-17 16:49:54 +02:00
classIcon:SetFrameStrata("MEDIUM")
classIcon:SetFrameLevel(1)
classIcon.texture = classIcon:CreateTexture(nil, "BACKGROUND")
classIcon.texture:SetAllPoints(classIcon)
classIcon.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask")
2021-05-17 16:49:54 +02:00
classIcon.texture.overlay = classIcon:CreateTexture(nil, "BORDER")
classIcon.texture.overlay:SetAllPoints(classIcon)
classIcon.texture.overlay:SetTexture(Gladdy.db.classIconBorderStyle)
classIcon:SetFrameStrata("MEDIUM")
classIcon:SetFrameLevel(2)
Gladdy.buttons[unit].classIcon = classIcon
self.frames[unit] = classIcon
end
function Classicon:UpdateFrame(unit)
local classIcon = self.frames[unit]
if (not classIcon) then
return
end
classIcon:SetFrameStrata(Gladdy.db.classIconFrameStrata)
classIcon:SetFrameLevel(Gladdy.db.classIconFrameLevel)
2021-05-17 16:49:54 +02:00
classIcon:SetWidth(Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor)
classIcon:SetHeight(Gladdy.db.classIconSize)
2022-01-11 00:29:17 +01:00
Gladdy:SetPosition(classIcon, unit, "classIconXOffset", "classIconYOffset", Classicon:LegacySetPosition(classIcon, unit), Classicon)
if (unit == "arena1") then
Gladdy:CreateMover(classIcon, "classIconXOffset", "classIconYOffset", L["Class Icon"],
{"TOPLEFT", "TOPLEFT"},
Gladdy.db.classIconSize * Gladdy.db.classIconWidthFactor,
Gladdy.db.classIconSize,
0,
2022-01-13 23:11:33 +01:00
0, "classIconEnabled")
2021-05-17 16:49:54 +02:00
end
classIcon.texture:ClearAllPoints()
classIcon.texture:SetAllPoints(classIcon)
classIcon.texture.overlay:SetTexture(Gladdy.db.classIconBorderStyle)
classIcon.texture.overlay:SetVertexColor(Gladdy:SetColor(Gladdy.db.classIconBorderColor))
2022-01-12 02:25:11 +01:00
if Gladdy.db.classIconEnabled then
classIcon:Show()
else
classIcon:Hide()
end
2021-05-17 16:49:54 +02:00
end
function Classicon:ENEMY_SPOTTED(unit)
local classIcon = self.frames[unit]
if (not classIcon) then
return
end
classIcon.texture:SetTexture(classIcons[Gladdy.buttons[unit].class])
--classIcon.texture:SetTexCoord(unpack(CLASS_BUTTONS[Gladdy.buttons[unit].class]))
classIcon.texture:SetAllPoints(classIcon)
end
function Classicon:UNIT_SPEC(unit, spec)
local classIcon = self.frames[unit]
if (not Gladdy.db.classIconSpecIcon or not classIcon) then
return
end
classIcon.texture:SetTexture(specIcons[Gladdy.buttons[unit].class][spec])
end
2021-05-17 16:49:54 +02:00
function Classicon:Test(unit)
self:ENEMY_SPOTTED(unit)
end
function Classicon:ResetUnit(unit)
local classIcon = self.frames[unit]
if (not classIcon) then
return
end
classIcon.texture:SetTexture("")
end
function Classicon:GetOptions()
return {
headerClassicon = {
type = "header",
name = L["Class Icon"],
order = 2,
},
2022-01-12 02:25:11 +01:00
classIconEnabled = Gladdy:option({
type = "toggle",
name = L["Class Icon Enabled"],
order = 3,
}),
classIconSpecIcon = {
type = "toggle",
name = L["Show Spec Icon"],
desc = L["Shows Spec Icon once spec is detected"],
2022-01-12 02:25:11 +01:00
order = 4,
2021-07-29 15:53:34 +02:00
get = function() return Gladdy.db.classIconSpecIcon end,
set = function(_, value)
Gladdy.db.classIconSpecIcon = value
if Gladdy.curBracket and Gladdy.curBracket > 0 then
for i=1,Gladdy.curBracket do
local unit = "arena" .. i
if (Gladdy.buttons[unit] and Gladdy.buttons[unit].spec) then
self:ENEMY_SPOTTED(unit)
self:UNIT_SPEC(unit, Gladdy.buttons[unit].spec)
end
end
end
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"],
order = 4,
2021-05-17 16:49:54 +02:00
args = {
size = {
type = "group",
name = L["Icon size"],
order = 1,
args = {
2021-05-22 13:42:47 +02:00
header = {
type = "header",
name = L["Icon size"],
order = 1,
},
2021-05-17 16:49:54 +02:00
classIconSize = Gladdy:option({
type = "range",
name = L["Icon size"],
2022-01-12 02:25:11 +01:00
min = 3,
2021-05-17 16:49:54 +02:00
max = 100,
2022-01-12 02:25:11 +01:00
step = .1,
2021-05-17 16:49:54 +02:00
order = 3,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
classIconWidthFactor = Gladdy:option({
type = "range",
name = L["Icon width factor"],
min = 0.5,
max = 2,
step = 0.05,
order = 4,
2021-06-15 09:06:05 +02:00
width = "full",
2021-05-17 16:49:54 +02:00
}),
},
},
position = {
type = "group",
name = L["Position"],
order = 3,
2021-05-17 16:49:54 +02:00
args = {
headerPosition = {
type = "header",
name = L["Position"],
order = 5,
},
classIconXOffset = Gladdy:option({
type = "range",
name = L["Horizontal offset"],
order = 11,
min = -800,
max = 800,
step = 0.1,
width = "full",
}),
classIconYOffset = Gladdy:option({
type = "range",
name = L["Vertical offset"],
order = 12,
min = -800,
max = 800,
step = 0.1,
width = "full",
2021-05-17 16:49:54 +02:00
}),
},
},
border = {
type = "group",
name = L["Border"],
order = 2,
2021-05-17 16:49:54 +02:00
args = {
headerBorder = {
type = "header",
name = L["Border"],
order = 10,
},
classIconBorderStyle = Gladdy:option({
type = "select",
name = L["Border style"],
order = 11,
values = Gladdy:GetIconStyles()
}),
classIconBorderColor = Gladdy:colorOption({
type = "color",
name = L["Border color"],
desc = L["Color of the border"],
order = 12,
hasAlpha = true,
}),
},
},
frameStrata = {
type = "group",
name = L["Frame Strata and Level"],
order = 4,
args = {
headerAuraLevel = {
type = "header",
name = L["Frame Strata and Level"],
order = 1,
},
classIconFrameStrata = Gladdy:option({
type = "select",
name = L["Frame Strata"],
order = 2,
values = Gladdy.frameStrata,
sorting = Gladdy.frameStrataSorting,
width = "full",
}),
classIconFrameLevel = 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 Classicon:LegacySetPosition(classIcon, unit)
if Gladdy.db.newLayout then
return Gladdy.db.newLayout
end
classIcon:ClearAllPoints()
local margin = (Gladdy.db.highlightInset and 0 or Gladdy.db.highlightBorderSize) + Gladdy.db.padding
if (Gladdy.db.classIconPos == "LEFT") then
classIcon:SetPoint("TOPRIGHT", Gladdy.buttons[unit].healthBar, "TOPLEFT", -margin, 0)
else
classIcon:SetPoint("TOPLEFT", Gladdy.buttons[unit], "TOPRIGHT", margin, 0)
end
2021-05-17 16:49:54 +02:00
end