Add BorderIndicator
This commit is contained in:
@@ -16,6 +16,7 @@ types/statusbar.lua
|
|||||||
types/auralist.lua
|
types/auralist.lua
|
||||||
types/indicators/indicator.lua
|
types/indicators/indicator.lua
|
||||||
types/indicators/squareindicator.lua
|
types/indicators/squareindicator.lua
|
||||||
|
types/indicators/borderindicator.lua
|
||||||
types/unitgroup.lua
|
types/unitgroup.lua
|
||||||
types/unitframe.lua
|
types/unitframe.lua
|
||||||
|
|
||||||
|
102
src/types/indicators/borderindicator.lua
Normal file
102
src/types/indicators/borderindicator.lua
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
-- Copyright 2023 <omicron.me@protonmail.com>
|
||||||
|
--
|
||||||
|
-- This file is part of Omicron Frames
|
||||||
|
--
|
||||||
|
-- Omicron Frames is free software: you can redistribute it and/or modify it
|
||||||
|
-- under the terms of the GNU General Public License as published by the Free
|
||||||
|
-- Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
-- any later version.
|
||||||
|
--
|
||||||
|
-- Omicron Frames is distributed in the hope that it will be useful, but
|
||||||
|
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
-- more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License along with
|
||||||
|
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
local omi = select(2, ...)
|
||||||
|
local types = omi.GetModule("types")
|
||||||
|
|
||||||
|
---@class Indicator
|
||||||
|
local Indicator = types.Indicator
|
||||||
|
|
||||||
|
local borderPool = CreateFramePool("Frame", nil, "BackdropTemplate")
|
||||||
|
|
||||||
|
---BorderIndicator is an indicator that displays a colored square texture
|
||||||
|
---@class BorderIndicator: Indicator
|
||||||
|
local BorderIndicator = types.CreateClass("BorderIndicator", Indicator)
|
||||||
|
types.BorderIndicator = BorderIndicator
|
||||||
|
|
||||||
|
---@return BorderIndicator
|
||||||
|
function BorderIndicator.new(cls, ...)
|
||||||
|
--- I really dislike duplicating this everywhere but it makes
|
||||||
|
--lua-language-server able to deduce the type of Object:new calls and that
|
||||||
|
--is honestly worth it
|
||||||
|
return types.Object.new(cls, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Initialize a new BorderIndicator
|
||||||
|
---@param unitframe UnitFrame
|
||||||
|
---@param size number
|
||||||
|
---@param color number[]
|
||||||
|
function BorderIndicator:Init(unitframe, thickness, color)
|
||||||
|
self.unitframe = unitframe
|
||||||
|
self.frameParent = unitframe.overlays
|
||||||
|
self.thickness = thickness
|
||||||
|
self.color = color
|
||||||
|
end
|
||||||
|
|
||||||
|
---Set the color of the Square Indicator
|
||||||
|
---@param color number[]
|
||||||
|
function BorderIndicator:SetColor(color)
|
||||||
|
self.color = color
|
||||||
|
local frame = self.frame
|
||||||
|
if frame then
|
||||||
|
frame:SetBackdropBorderColor(unpack(color))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Set Border thickness
|
||||||
|
---@param thickness number
|
||||||
|
function BorderIndicator:SetThickness(thickness)
|
||||||
|
self.thickness = thickness
|
||||||
|
local frame = self.frame
|
||||||
|
if frame and frame.backdropInfo.edgeSize ~= thickness then
|
||||||
|
frame.backdropInfo.edgeSize = thickness
|
||||||
|
frame:ApplyBackdrop()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Show the square indicator.
|
||||||
|
---@param data table
|
||||||
|
function BorderIndicator:Show(data)
|
||||||
|
local frame, stacks = self:GetFrame()
|
||||||
|
frame:Show()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BorderIndicator:GetFrame()
|
||||||
|
local frame, new = borderPool:Acquire()
|
||||||
|
if new then
|
||||||
|
frame.backdropInfo = {
|
||||||
|
edgeFile = "Interface\\Addons\\OmicronFrames\\media\\textures\\pixel_edge",
|
||||||
|
edgeSize = 1,
|
||||||
|
insets = {left=0, right=0, top=0, bottom=0},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
frame.backdropInfo.edgeSize = self.thickness
|
||||||
|
frame:ApplyBackdrop()
|
||||||
|
frame:SetParent(self.frameParent)
|
||||||
|
frame:SetAllPoints()
|
||||||
|
frame:SetBackdropBorderColor(unpack(self.color))
|
||||||
|
self.frame = frame
|
||||||
|
return frame
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Hide the square indicator.
|
||||||
|
function BorderIndicator:Hide()
|
||||||
|
local frame = self.frame
|
||||||
|
self.frame = nil
|
||||||
|
borderPool:Release(frame)
|
||||||
|
end
|
||||||
|
|
@@ -26,6 +26,9 @@ local AuraList = types.AuraList
|
|||||||
---@class SquareIndicator
|
---@class SquareIndicator
|
||||||
local SquareIndicator = types.SquareIndicator
|
local SquareIndicator = types.SquareIndicator
|
||||||
|
|
||||||
|
---@class SquareIndicator
|
||||||
|
local BorderIndicator = types.BorderIndicator
|
||||||
|
|
||||||
---@class AuraTrigger
|
---@class AuraTrigger
|
||||||
local AuraTrigger = types.AuraTrigger
|
local AuraTrigger = types.AuraTrigger
|
||||||
|
|
||||||
@@ -124,6 +127,13 @@ function UnitFrame:CreateIndicator(indicator)
|
|||||||
indicator.point,
|
indicator.point,
|
||||||
indicator.x,
|
indicator.x,
|
||||||
indicator.y,
|
indicator.y,
|
||||||
|
indicator.color,
|
||||||
|
indicator.showStacks
|
||||||
|
)
|
||||||
|
elseif kind == "BorderIndicator" then
|
||||||
|
return BorderIndicator:new(
|
||||||
|
self,
|
||||||
|
indicator.thickness,
|
||||||
indicator.color
|
indicator.color
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user