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:
BIN
media/textures/pixel_edge.tga
Normal file
BIN
media/textures/pixel_edge.tga
Normal file
Binary file not shown.
BIN
media/textures/square_white.tga
Normal file
BIN
media/textures/square_white.tga
Normal file
Binary file not shown.
@@ -17,6 +17,8 @@
|
|||||||
local omi = select(2, ...)
|
local omi = select(2, ...)
|
||||||
local types = omi.GetModule("types")
|
local types = omi.GetModule("types")
|
||||||
|
|
||||||
|
local squarePool = CreateFramePool("Frame", nil, "BackdropTemplate")
|
||||||
|
|
||||||
---SquareIndicator is an indicator that displays a colored square texture
|
---SquareIndicator is an indicator that displays a colored square texture
|
||||||
---@class SquareIndicator: Indicator
|
---@class SquareIndicator: Indicator
|
||||||
local SquareIndicator = types.CreateClass("SquareIndicator", Indicator)
|
local SquareIndicator = types.CreateClass("SquareIndicator", Indicator)
|
||||||
@@ -36,33 +38,90 @@ end
|
|||||||
-- point Attachment point to the unitframe's overlay frame
|
-- point Attachment point to the unitframe's overlay frame
|
||||||
-- x, y x and y offset for the attachment point
|
-- x, y x and y offset for the attachment point
|
||||||
-- color Color of the square
|
-- color Color of the square
|
||||||
function SquareIndicator:Init(unitframe, size, point, x, y, color)
|
---@param unitframe UnitFrame
|
||||||
local frame = unitframe.overlays
|
---@param size number
|
||||||
|
---@param point string
|
||||||
local texture = frame:CreateTexture(nil, "ARTWORK")
|
---@param x number
|
||||||
self.texture = texture
|
---@param y number
|
||||||
texture:Hide()
|
---@param color number[]
|
||||||
texture:SetTexture("Interface\\Addons\\OmicronFrames\\media\\textures\\square_b")
|
---@param showStacks boolean
|
||||||
texture:SetSize(size, size)
|
function SquareIndicator:Init(unitframe, size, point, x, y, color, showStacks)
|
||||||
texture:SetPoint(point, x, y)
|
self.unitframe = unitframe
|
||||||
self:SetColor(color)
|
self.frameParent = unitframe.overlays
|
||||||
texture:SetVertexColor(unpack(color))
|
self.size = size
|
||||||
texture:SetDrawLayer("ARTWORK")
|
self.point = point
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.color = color
|
||||||
|
self.showStacks = showStacks
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the color of the Square Indicator
|
--- Set the color of the Square Indicator
|
||||||
-- color: a sequence table with 3 color channels {r, g, b}
|
-- color: a sequence table with 3 color channels {r, g, b}
|
||||||
function SquareIndicator:SetColor(color)
|
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
|
end
|
||||||
|
|
||||||
--- Show the square indicator.
|
--- Show the square indicator.
|
||||||
---@param data table|nil
|
---@param data table
|
||||||
function SquareIndicator:Show(data)
|
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
|
end
|
||||||
|
|
||||||
--- Hide the square indicator.
|
--- Hide the square indicator.
|
||||||
function SquareIndicator:Hide()
|
function SquareIndicator:Hide()
|
||||||
self.texture:Hide()
|
local frame = self.frame
|
||||||
|
self.stacks:Hide()
|
||||||
|
self.frame = nil
|
||||||
|
self.stacks = nil
|
||||||
|
squarePool:Release(frame)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user