Rework square indicators
- The indicator will grab a frame from a pool - Having a frame, it now uses a real border/edge - There is a stacks number that can optionally be enabled
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
local omi = select(2, ...)
|
||||
local types = omi.GetModule("types")
|
||||
|
||||
local squarePool = CreateFramePool("Frame", nil, "BackdropTemplate")
|
||||
|
||||
---SquareIndicator is an indicator that displays a colored square texture
|
||||
---@class SquareIndicator: Indicator
|
||||
local SquareIndicator = types.CreateClass("SquareIndicator", Indicator)
|
||||
@@ -36,33 +38,90 @@ end
|
||||
-- point Attachment point to the unitframe's overlay frame
|
||||
-- x, y x and y offset for the attachment point
|
||||
-- color Color of the square
|
||||
function SquareIndicator:Init(unitframe, size, point, x, y, color)
|
||||
local frame = unitframe.overlays
|
||||
|
||||
local texture = frame:CreateTexture(nil, "ARTWORK")
|
||||
self.texture = texture
|
||||
texture:Hide()
|
||||
texture:SetTexture("Interface\\Addons\\OmicronFrames\\media\\textures\\square_b")
|
||||
texture:SetSize(size, size)
|
||||
texture:SetPoint(point, x, y)
|
||||
self:SetColor(color)
|
||||
texture:SetVertexColor(unpack(color))
|
||||
texture:SetDrawLayer("ARTWORK")
|
||||
---@param unitframe UnitFrame
|
||||
---@param size number
|
||||
---@param point string
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param color number[]
|
||||
---@param showStacks boolean
|
||||
function SquareIndicator:Init(unitframe, size, point, x, y, color, showStacks)
|
||||
self.unitframe = unitframe
|
||||
self.frameParent = unitframe.overlays
|
||||
self.size = size
|
||||
self.point = point
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.color = color
|
||||
self.showStacks = showStacks
|
||||
end
|
||||
|
||||
--- Set the color of the Square Indicator
|
||||
-- color: a sequence table with 3 color channels {r, g, b}
|
||||
function SquareIndicator:SetColor(color)
|
||||
self.texture:SetVertexColor(unpack(color))
|
||||
self.color = color
|
||||
local frame = self.frame
|
||||
if frame then
|
||||
frame:SetBackdropColor(unpack(color))
|
||||
end
|
||||
end
|
||||
|
||||
--- Show the square indicator.
|
||||
---@param data table|nil
|
||||
---@param data table
|
||||
function SquareIndicator:Show(data)
|
||||
self.texture:Show()
|
||||
local frame, stacks = self:GetFrame()
|
||||
local numStacks = data.stacks or 0
|
||||
self.frame = frame
|
||||
self.stacks = stacks
|
||||
if self.showStacks and numStacks > 0 then
|
||||
stacks:SetText(numStacks)
|
||||
stacks:Show()
|
||||
end
|
||||
frame:SetBackdropColor(unpack(self.color))
|
||||
frame:Show()
|
||||
end
|
||||
|
||||
function SquareIndicator:GetFrame()
|
||||
local frame, new = squarePool:Acquire()
|
||||
local stacks
|
||||
if new then
|
||||
frame.backdropInfo = {
|
||||
bgFile = "Interface\\Addons\\OmicronFrames\\media\\textures\\square_white",
|
||||
edgeFile = "Interface\\Addons\\OmicronFrames\\media\\textures\\pixel_edge",
|
||||
edgeSize = 2,
|
||||
insets = {left=0, right=0, top=0, bottom=0},
|
||||
}
|
||||
frame:ApplyBackdrop()
|
||||
|
||||
stacks = frame:CreateFontString(nil, "OVERLAY")
|
||||
frame.stacks = stacks
|
||||
stacks:SetFont("Interface\\AddOns\\OmicronFrames\\media\\fonts\\roboto\\Roboto-Medium.ttf", 12, "OUTLINE")
|
||||
stacks:SetPoint("CENTER")
|
||||
stacks:SetTextColor(1, 1, 1)
|
||||
end
|
||||
|
||||
frame:SetSize(self.size, self.size)
|
||||
frame:SetParent(self.frameParent)
|
||||
frame:SetPoint(self.point, self.x, self.y)
|
||||
frame:SetBackdropBorderColor(0, 0, 0, 1)
|
||||
stacks = frame.stacks
|
||||
return frame, stacks
|
||||
end
|
||||
|
||||
---@param data table
|
||||
function SquareIndicator:Update(data)
|
||||
local numStacks = data.stacks or 0
|
||||
if numStacks > 0 then
|
||||
self.stacks:SetText(numStacks)
|
||||
self.stacks:Show()
|
||||
end
|
||||
end
|
||||
|
||||
--- Hide the square indicator.
|
||||
function SquareIndicator:Hide()
|
||||
self.texture:Hide()
|
||||
local frame = self.frame
|
||||
self.stacks:Hide()
|
||||
self.frame = nil
|
||||
self.stacks = nil
|
||||
squarePool:Release(frame)
|
||||
end
|
||||
|
Reference in New Issue
Block a user