Gladdy-TBC/Frame.lua

362 lines
13 KiB
Lua
Raw Permalink Normal View History

2021-05-17 16:49:54 +02:00
local CreateFrame = CreateFrame
local UIParent = UIParent
local InCombatLockdown = InCombatLockdown
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
Gladdy.BUTTON_DEFAULTS = {
name = "",
guid = "",
raceLoc = "",
classLoc = "",
class = "",
health = "",
healthMax = 0,
power = 0,
powerMax = 0,
powerType = 0,
spec = "",
testSpec = "",
spells = {},
ns = false,
nf = false,
pom = false,
fd = false,
damaged = 0,
click = false,
stealthed = false,
2021-06-16 14:10:49 +02:00
classColors = {},
lastState = 0,
2021-05-17 16:49:54 +02:00
}
function Gladdy:CreateFrame()
self.frame = CreateFrame("Frame", "GladdyFrame", UIParent)
2021-05-22 13:41:31 +02:00
--self.frame.texture = self.frame:CreateTexture(nil, "OVERLAY")
--self.frame.texture:SetAllPoints(self.frame)
--self.frame.texture:SetTexture("Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp")
2021-05-17 16:49:54 +02:00
self.frame:SetClampedToScreen(true)
2021-05-19 19:30:32 +02:00
self.frame:EnableMouse(false)
2021-05-17 16:49:54 +02:00
self.frame:SetMovable(true)
self.frame:RegisterForDrag("LeftButton")
self.frame:SetScript("OnDragStart", function(f)
if (not InCombatLockdown() and not self.db.locked) then
f:StartMoving()
end
end)
self.frame:SetScript("OnDragStop", function(f)
if (not InCombatLockdown()) then
f:StopMovingOrSizing()
local scale = f:GetEffectiveScale()
self.db.x = f:GetLeft() * scale
self.db.y = (self.db.growUp and f:GetBottom() or f:GetTop()) * scale
end
end)
self.anchor = CreateFrame("Button", "GladdyAnchor", self.frame, BackdropTemplateMixin and "BackdropTemplate")
self.anchor:SetHeight(20)
self.anchor:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16 })
self.anchor:SetBackdropColor(0, 0, 0, 1)
self.anchor:SetClampedToScreen(true)
self.anchor:EnableMouse(true)
self.anchor:SetMovable(true)
self.anchor:RegisterForDrag("LeftButton")
self.anchor:RegisterForClicks("RightButtonUp")
self.anchor:SetScript("OnDragStart", function()
if (not InCombatLockdown() and not self.db.locked) then
self.frame:StartMoving()
end
end)
self.anchor:SetScript("OnDragStop", function()
if (not InCombatLockdown()) then
self.frame:StopMovingOrSizing()
local scale = self.frame:GetEffectiveScale()
self.db.x = self.frame:GetLeft() * scale
self.db.y = (self.db.growUp and self.frame:GetBottom() or self.frame:GetTop()) * scale
end
end)
self.anchor:SetScript("OnClick", function()
if (not InCombatLockdown()) then
self:ShowOptions()
end
end)
self.anchor.text = self.anchor:CreateFontString("GladdyAnchorText", "ARTWORK", "GameFontHighlightSmall")
self.anchor.text:SetText(L["Gladdy - drag to move"])
self.anchor.text:SetPoint("CENTER")
self.anchor.button = CreateFrame("Button", "GladdyAnchorButton", self.anchor, "UIPanelCloseButton")
self.anchor.button:SetWidth(20)
self.anchor.button:SetHeight(20)
self.anchor.button:SetPoint("RIGHT", self.anchor, "RIGHT", 2, 0)
self.anchor.button:SetScript("OnClick", function(_, _, down)
if (not down) then
self.db.locked = true
self:UpdateFrame()
end
end)
if (self.db.locked) then
self.anchor:Hide()
end
self.frame:Hide()
end
function Gladdy:UpdateFrame()
2021-06-20 02:27:27 +02:00
if (InCombatLockdown()) then
return
end
2021-05-17 16:49:54 +02:00
if (not self.frame) then
self:CreateFrame()
end
local teamSize = self.curBracket or 0
2021-05-22 13:41:31 +02:00
local highlightBorderSize = (self.db.highlightInset and 0 or self.db.highlightBorderSize * 2)
2021-06-15 09:06:05 +02:00
local powerBarHeight = self.db.powerBarEnabled and (self.db.powerBarHeight + 1) or 0
2021-05-22 13:41:31 +02:00
local leftSize = 0
local rightSize = 0
--Trinket + Racial
if self.db.trinketEnabled and self.db.trinketPos == "LEFT" then
leftSize = leftSize + self.db.trinketSize * self.db.trinketWidthFactor + self.db.padding
if self.db.racialEnabled and self.db.racialAnchor == "trinket" and self.db.racialPos == "LEFT" then
leftSize = leftSize + self.db.racialSize * self.db.racialWidthFactor + self.db.padding
end
end
if self.db.trinketEnabled and self.db.trinketPos == "RIGHT" then
rightSize = rightSize + self.db.trinketSize * self.db.trinketWidthFactor + self.db.padding
if self.db.racialEnabled and self.db.racialAnchor == "trinket" and self.db.racialPos == "RIGHT" then
rightSize = rightSize + self.db.racialSize * self.db.racialWidthFactor + self.db.padding
end
end
--ClassIcon
if self.db.classIconPos == "LEFT" then
leftSize = leftSize + self.db.classIconSize * self.db.classIconWidthFactor + self.db.padding
else
rightSize = rightSize + self.db.classIconSize * self.db.classIconWidthFactor + self.db.padding
end
--Highlight
if not self.db.highlightInset then
leftSize = leftSize + self.db.highlightBorderSize
rightSize = rightSize + self.db.highlightBorderSize
end
2021-05-17 16:49:54 +02:00
2021-06-15 09:06:05 +02:00
local margin = powerBarHeight
2021-05-22 13:41:31 +02:00
local width = self.db.barWidth + leftSize + rightSize
2021-06-15 09:06:05 +02:00
local height = (self.db.healthBarHeight + powerBarHeight) * teamSize
2021-05-22 13:41:31 +02:00
+ (self.db.highlightInset and 0 or self.db.highlightBorderSize * 2 * teamSize)
+ self.db.bottomMargin * (teamSize - 1)
2021-05-17 16:49:54 +02:00
2021-05-22 13:41:31 +02:00
-- Highlight
margin = margin + highlightBorderSize
2021-05-17 16:49:54 +02:00
if (self.db.cooldownYPos == "TOP" or self.db.cooldownYPos == "BOTTOM") and self.db.cooldown then
margin = margin + self.db.cooldownSize
2021-05-22 13:41:31 +02:00
height = height + self.db.cooldownSize * (teamSize - 1)
2021-05-17 16:49:54 +02:00
end
if (self.db.buffsCooldownPos == "TOP" or self.db.buffsCooldownPos == "BOTTOM") and self.db.buffsEnabled then
margin = margin + self.db.buffsIconSize
2021-05-22 13:41:31 +02:00
height = height + self.db.buffsIconSize * (teamSize - 1)
2021-05-17 16:49:54 +02:00
end
if (self.db.buffsBuffsCooldownPos == "TOP" or self.db.buffsBuffsCooldownPos == "BOTTOM") and self.db.buffsEnabled then
margin = margin + self.db.buffsBuffsIconSize
2021-05-22 13:41:31 +02:00
height = height + self.db.buffsBuffsIconSize * (teamSize - 1)
2021-05-17 16:49:54 +02:00
end
if self.db.buffsCooldownPos == "TOP" and self.db.cooldownYPos == "TOP" and self.db.cooldown and self.db.buffsEnabled then
margin = margin + 1
2021-05-22 13:41:31 +02:00
height = height + (teamSize - 1)
2021-05-17 16:49:54 +02:00
end
if self.db.buffsCooldownPos == "BOTTOM" and self.db.cooldownYPos == "BOTTOM" and self.db.cooldown and self.db.buffsEnabled then
margin = margin + 1
2021-05-22 13:41:31 +02:00
height = height + (teamSize - 1)
2021-05-17 16:49:54 +02:00
end
2021-05-22 13:41:31 +02:00
-- GrowDirection
if (self.db.growDirection == "LEFT" or self.db.growDirection == "RIGHT") then
width = self.db.barWidth * teamSize + (leftSize + rightSize) * teamSize + self.db.bottomMargin * (teamSize - 1)
2021-06-15 09:06:05 +02:00
height = self.db.healthBarHeight + powerBarHeight
2021-05-22 13:41:31 +02:00
end
2021-05-17 16:49:54 +02:00
self.frame:SetScale(self.db.frameScale)
self.frame:SetWidth(width)
self.frame:SetHeight(height)
--self.frame:SetBackdropColor(self.db.frameColor.r, self.db.frameColor.g, self.db.frameColor.b, self.db.frameColor.a)
self.frame:ClearAllPoints()
if (self.db.x == 0 and self.db.y == 0) then
self.frame:SetPoint("CENTER")
else
local scale = self.frame:GetEffectiveScale()
2021-05-22 13:41:31 +02:00
if (self.db.growDirection == "TOP") then
2021-05-17 16:49:54 +02:00
self.frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
else
self.frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
end
end
2021-05-22 13:41:31 +02:00
--Anchor
2021-05-17 16:49:54 +02:00
self.anchor:SetWidth(width)
self.anchor:ClearAllPoints()
2021-05-22 13:41:31 +02:00
if (self.db.growDirection == "TOP") then
2021-05-17 16:49:54 +02:00
self.anchor:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
2021-05-22 13:41:31 +02:00
elseif self.growDirection == "BOTTOM" or self.growDirection == "RIGHT" then
2021-05-17 16:49:54 +02:00
self.anchor:SetPoint("BOTTOMLEFT", self.frame, "TOPLEFT")
2021-05-22 13:41:31 +02:00
else
self.anchor:SetPoint("BOTTOMRIGHT", self.frame, "TOPRIGHT")
2021-05-17 16:49:54 +02:00
end
if (self.db.locked) then
self.anchor:Hide()
else
self.anchor:Show()
end
for i = 1, teamSize do
local button = self.buttons["arena" .. i]
2021-05-22 13:41:31 +02:00
button:SetWidth(self.db.barWidth)
2021-05-17 16:49:54 +02:00
button:SetHeight(self.db.healthBarHeight)
2021-05-19 19:30:32 +02:00
button.secure:SetWidth(self.db.barWidth)
2021-06-15 09:06:05 +02:00
button.secure:SetHeight(self.db.healthBarHeight + powerBarHeight)
2021-05-17 16:49:54 +02:00
button:ClearAllPoints()
button.secure:ClearAllPoints()
2021-05-22 13:41:31 +02:00
if (self.db.growDirection == "TOP") then
2021-05-17 16:49:54 +02:00
if (i == 1) then
2021-06-15 09:06:05 +02:00
button:SetPoint("BOTTOMLEFT", self.frame, "BOTTOMLEFT", leftSize, powerBarHeight)
2021-06-20 13:15:27 +02:00
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
2021-05-17 16:49:54 +02:00
else
button:SetPoint("BOTTOMLEFT", self.buttons["arena" .. (i - 1)], "TOPLEFT", 0, margin + self.db.bottomMargin)
2021-06-20 13:15:27 +02:00
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
2021-05-17 16:49:54 +02:00
end
2021-05-22 13:41:31 +02:00
elseif (self.db.growDirection == "BOTTOM") then
2021-05-17 16:49:54 +02:00
if (i == 1) then
2021-05-22 13:41:31 +02:00
button:SetPoint("TOPLEFT", self.frame, "TOPLEFT", leftSize, 0)
2021-05-19 19:30:32 +02:00
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
2021-05-17 16:49:54 +02:00
else
button:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "BOTTOMLEFT", 0, -margin - self.db.bottomMargin)
2021-05-19 19:30:32 +02:00
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
2021-05-17 16:49:54 +02:00
end
2021-05-22 13:41:31 +02:00
elseif (self.db.growDirection == "LEFT") then
if (i == 1) then
button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -rightSize, 0)
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
else
button:SetPoint("TOPRIGHT", self.buttons["arena" .. (i - 1)], "TOPLEFT", -rightSize - leftSize - self.db.bottomMargin, 0)
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
end
elseif (self.db.growDirection == "RIGHT") then
if (i == 1) then
button:SetPoint("TOPLEFT", self.frame, "TOPLEFT", leftSize, 0)
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
else
button:SetPoint("TOPLEFT", self.buttons["arena" .. (i - 1)], "TOPRIGHT", leftSize + rightSize + self.db.bottomMargin, 0)
button.secure:SetPoint("TOPLEFT", button.healthBar, "TOPLEFT")
end
2021-05-17 16:49:54 +02:00
end
2021-05-19 19:33:22 +02:00
for _, v in self:IterModules() do
2021-06-16 01:14:11 +02:00
self:Call(v, "UpdateFrame", "arena" .. i)
2021-05-17 16:49:54 +02:00
end
end
2021-05-19 19:33:22 +02:00
for _, v in self:IterModules() do
2021-05-17 16:49:54 +02:00
self:Call(v, "UpdateFrameOnce")
end
end
function Gladdy:HideFrame()
if (self.frame) then
self.frame:Hide()
self.frame.testing = nil
end
end
function Gladdy:ToggleFrame(i)
self:Reset()
if (self.frame and self.frame:IsShown() and i == self.curBracket) then
self:HideFrame()
else
self.curBracket = i
if (not self.frame) then
self:CreateFrame()
end
for o = 1, self.curBracket do
local unit = "arena" .. o
if (not self.buttons[unit]) then
self:CreateButton(o)
end
end
2021-06-16 14:10:49 +02:00
self:Reset()
self.curBracket = i
2021-05-17 16:49:54 +02:00
self:UpdateFrame()
self:Test()
self.frame:Show()
end
end
function Gladdy:CreateButton(i)
if (not self.frame) then
self:CreateFrame()
end
local button = CreateFrame("Frame", "GladdyButtonFrame" .. i, self.frame)
2021-05-19 19:30:32 +02:00
button:EnableMouse(false)
2021-05-22 13:41:31 +02:00
--button:SetAlpha(0)
--button.texture = button:CreateTexture(nil, "OVERLAY")
--button.texture:SetAllPoints(button)
--button.texture:SetTexture("Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp")
2021-05-17 16:49:54 +02:00
2021-06-15 17:10:31 +02:00
local secure = CreateFrame("Button", "GladdyButton" .. i, button, "SecureActionButtonTemplate, SecureHandlerEnterLeaveTemplate")
2021-05-17 16:49:54 +02:00
secure:RegisterForClicks("AnyUp")
2021-06-20 00:55:06 +02:00
secure:RegisterForClicks("AnyDown")
2021-06-20 02:27:27 +02:00
secure:SetAttribute("target", "arena" .. i)
secure:SetAttribute("focus", "arena" .. i)
2021-05-17 16:49:54 +02:00
secure:SetAttribute("unit", "arena" .. i)
2021-06-20 02:27:27 +02:00
--[[
secure:SetAttribute("target", i == 1 and "player" or "focus")
secure:SetAttribute("focus", i == 1 and "player" or "focus")
secure:SetAttribute("unit", i == 1 and "player" or "focus")
--]]
2021-05-19 19:30:32 +02:00
--secure.texture = secure:CreateTexture(nil, "OVERLAY")
--secure.texture:SetAllPoints(secure)
--secure.texture:SetTexture("Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp")
2021-05-17 16:49:54 +02:00
button.id = i
2021-06-20 00:55:06 +02:00
--button.unit = i == 1 and "player" or "focus"
2021-05-17 16:49:54 +02:00
button.unit = "arena" .. i
button.secure = secure
2021-06-16 01:14:11 +02:00
self:ResetButton("arena" .. i)
2021-05-17 16:49:54 +02:00
2021-06-16 01:14:11 +02:00
self.buttons["arena" .. i] = button
2021-05-17 16:49:54 +02:00
2021-05-19 19:33:22 +02:00
for _, v in self:IterModules() do
2021-06-16 01:14:11 +02:00
self:Call(v, "CreateFrame", "arena" .. i)
2021-05-17 16:49:54 +02:00
end
2021-06-17 16:43:28 +02:00
self:ResetButton("arena" .. i)
2021-05-18 16:39:43 +02:00
end
function Gladdy:GetAnchor(unit, position)
local anchor = "healthBar"
if Gladdy.db.classIconPos == position then
anchor = "classIcon"
end
if Gladdy.db.trinketPos == position then
anchor = "trinket"
end
if anchor == Gladdy.db.racialAnchor and Gladdy.db.racialPos == position then
anchor = "racial"
end
return Gladdy.buttons[unit][anchor]
2021-05-17 16:49:54 +02:00
end