Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
JerichoR committed Oct 3, 2024
1 parent 0866812 commit b58475d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 96 deletions.
28 changes: 14 additions & 14 deletions Tukui/Modules/UnitFrames/Groups/Raid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ local PowerTexture
local Font
local HealthFont

--[[ Make raid widgets available for external edits. ]]
-- Make raid widgets available for external edits.
UnitFrames.RaidWidgets = UnitFrames.newWidgetManager()
local RaidWidgets = UnitFrames.RaidWidgets

-- oUF base elements
--[[ Configures oUF element Health. ]]
-- Configures oUF element Health.
local function createHealth(unitFrame)
local Health = CreateFrame("StatusBar", nil, unitFrame)
Health:SetPoint("TOPLEFT")
Expand Down Expand Up @@ -48,7 +48,7 @@ local function createHealth(unitFrame)
end
RaidWidgets:addOrReplace("Health", createHealth)

--[[ Configures oUF element Power. ]]
-- Configures oUF element Power.
local function createPower(unitFrame)
local Power = CreateFrame("StatusBar", nil, unitFrame)
Power:SetHeight(3)
Expand All @@ -73,7 +73,7 @@ local function createPower(unitFrame)
end
RaidWidgets:addOrReplace("Power", createPower)

--[[ Configures oUF element RaidTargetIndicator. ]]
-- Configures oUF element RaidTargetIndicator.
local function createRaidTargetIndicator(unitFrame)
local RaidIcon = unitFrame.Health:CreateTexture(nil, "OVERLAY")
RaidIcon:SetSize(C.UnitFrames.RaidIconSize, C.UnitFrames.RaidIconSize)
Expand All @@ -84,7 +84,7 @@ local function createRaidTargetIndicator(unitFrame)
end
RaidWidgets:addOrReplace("RaidTargetIndicator", createRaidTargetIndicator)

--[[ Configures oUF element ReadyCheckIndicator. ]]
-- Configures oUF element ReadyCheckIndicator.
local function createReadyCheckIndicator(unitFrame)
local ReadyCheck = unitFrame.Power:CreateTexture(nil, "OVERLAY", nil, 2)
ReadyCheck:SetSize(12, 12)
Expand All @@ -94,7 +94,7 @@ local function createReadyCheckIndicator(unitFrame)
end
RaidWidgets:addOrReplace("ReadyCheckIndicator", createReadyCheckIndicator)

--[[ Configures oUF element ResurrectIndicator. ]]
-- Configures oUF element ResurrectIndicator.
local function createResurrectIndicator(unitFrame)
local Health = unitFrame.Health
local ResurrectIndicator = Health:CreateTexture(nil, "OVERLAY")
Expand All @@ -105,7 +105,7 @@ local function createResurrectIndicator(unitFrame)
end
RaidWidgets:addOrReplace("ResurrectIndicator", createResurrectIndicator)

--[[ Configures oUF element Range. ]]
-- Configures oUF element Range.
local function createRange(unitFrame)
local Range = {
insideAlpha = 1,
Expand All @@ -116,7 +116,7 @@ local function createRange(unitFrame)
end
RaidWidgets:addOrReplace("Range", createRange)

--[[ Configures oUF element Buffs (part of Auras). ]]
-- Configures oUF element Buffs (part of Auras).
local function createBuffs(unitFrame)
local Buffs = CreateFrame("Frame", unitFrame:GetName().."Buffs", unitFrame.Health)
local onlyShowPlayer = C.Raid.RaidBuffs.Value == "Self"
Expand Down Expand Up @@ -146,7 +146,7 @@ if C.Raid.RaidBuffsStyle.Value == "Standard" then
RaidWidgets:addOrReplace("Buffs", createBuffs)
end

--[[ Configures oUF element HealthPrediction. ]]
-- Configures oUF element HealthPrediction.
local function createHealComm(unitframe)
if C.UnitFrames.HealComm then
local Health = unitframe.Health
Expand Down Expand Up @@ -212,7 +212,7 @@ RaidWidgets:addOrReplace("HealComm", createHealComm)


-- oUF Plugins
--[[ Configures oUF_AuraTrack. ]]
-- Configures oUF_AuraTrack.
local function createAuraTrack(unitFrame)
local AuraTrack = CreateFrame("Frame", nil, unitFrame.Health)
AuraTrack:SetAllPoints()
Expand All @@ -228,7 +228,7 @@ if C.Raid.RaidBuffsStyle.Value == "Aura Track" then
RaidWidgets:addOrReplace("AuraTrack", createAuraTrack)
end

--[[ Configures oUF_RaidDebuffs. ]]
-- Configures oUF_RaidDebuffs.
local function createRaidDebuffs(unitFrame)
local Health = unitFrame.Health
local RaidDebuffs = CreateFrame("Frame", nil, Health)
Expand Down Expand Up @@ -262,7 +262,7 @@ end


-- additional plugins
--[[ Creates a panel for the unit name. ]]
-- Creates a panel for the unit name.
local function createNamePanel(unitFrame)
local Panel = CreateFrame("Frame", nil, unitFrame)
Panel:SetPoint("TOPLEFT", unitFrame.Power, "BOTTOMLEFT", 0, -1)
Expand All @@ -286,7 +286,7 @@ local function createNamePanel(unitFrame)
end
RaidWidgets:addOrReplace("NamePanel", createNamePanel)

--[[ Highlights the currently selected unit. ]]
-- Highlights the currently selected unit.
local function createHighlight(unitFrame)
local Highlight = CreateFrame("Frame", nil, unitFrame, "BackdropTemplate")
Highlight:SetBackdrop({edgeFile = C.Medias.Glow, edgeSize = C.Raid.HighlightSize})
Expand All @@ -301,7 +301,7 @@ RaidWidgets:addOrReplace("Highlight", createHighlight)


--[[ Raid style function. ]]
function UnitFrames:Raid()
function UnitFrames.Raid(self)
HealthTexture = T.GetTexture(C["Textures"].UFRaidHealthTexture)
PowerTexture = T.GetTexture(C["Textures"].UFRaidPowerTexture)
Font = T.GetFont(C["Raid"].Font)
Expand Down
133 changes: 51 additions & 82 deletions Tukui/Modules/UnitFrames/WidgetManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,131 +4,100 @@ local UnitFrames = T["UnitFrames"]

local WidgetManager = {}

--[[ Internal: Add a widget to the index. ]]
local function addToIndex(self, widget)
-- Add a widget to the index.
function WidgetManager:addToIndex(widget)
self.count = self.count + 1
self.index[self.count] = widget
end

--[[ Internal: Rebuild the index for insert or remove. ]]
local function rebuildIndex(self, widget, atIndex)
-- Rebuild the index for insert or remove.
function WidgetManager:rebuildIndex(widget, atIndex)
local oldIndex = self.index

self.index = {}
self.count = 0

for i, _widget in ipairs(oldIndex) do
if i == atIndex then
addToIndex(self, widget)
addToIndex(self, _widget)
self.addToIndex(self, widget)
self.addToIndex(self, _widget)
elseif _widget == widget then
-- deleted
else
addToIndex(self, _widget)
self.addToIndex(self, _widget)
end
end
end

--[[ Add a new widget create function.
* self - RaidWidgets object
* name - Name of the new widget
* widget - The new widget
* returns - True
]]
WidgetManager.addOrReplace = function(self, name, widget)
if self.widgets[name] then
self.widgets[name] = widget
else
addToIndex(self, widget)
self.widgets[name] = widget
end
return true
-- Add a new or replace an existing widget create function.
function WidgetManager:addOrReplace(name, widget)
if self.widgets[name] then
self.widgets[name] = widget
else
self.addToIndex(self, widget)
self.widgets[name] = widget
end
return true
end

--[[ Gets the number of registered widgets.
* self - RaidWidgets object
* returns - Number of registered widgets
]]
WidgetManager.getCount = function(self)
-- Returns the number of registered widgets.
function WidgetManager:getCount()
return self.count
end

--[[ Returns the registered widget by its name or index.
* self - RaidWidgets object
* nameOrIndex - The name or index of the widget to retrieve
* returns - The registered widget or nil
]]
WidgetManager.get = function(self, nameOrIndex)
-- Returns the registered widget by its name or index.
function WidgetManager:get(nameOrIndex)
if type(nameOrIndex) == "string" then
return self.widgets[nameOrIndex]
elseif type(nameOrIndex) == "number" then
return self.index[nameOrIndex]
end
end

--[[ Insert a new widget at a specific position.
Other widgets will be shifted if needed.
* self - RaidWidgets object
* atIndex - The index where to insert it
* name - Name of the new widget
* widget - The new widget
* returns - True if successful, false otherwise
]]
WidgetManager.insert = function(self, atIndex, name, widget)
if not self.widgets[name] and atIndex <= self.count then
self.widgets[name] = widget
rebuildIndex(self, widget, atIndex)
return true
else
return false
end
-- Insert a new widget at position "atIndex".
-- Other widgets will be shifted if needed.
function WidgetManager:insert(atIndex, name, widget)
if not self.widgets[name] and atIndex <= self.count then
self.widgets[name] = widget
self.rebuildIndex(self, widget, atIndex)
return true
else
return false
end
end

--[[ Remove a registered widget.
* self - RaidWidgets object
* name - Name of the widget to be removed
* returns - True if successful, false otherwise
]]
WidgetManager.remove = function(self, name)
-- Remove a registered widget.
function WidgetManager:remove(name)
local widget = self:get(name)
if widget then
self.widgets[name] = nil
rebuildIndex(self, widget)
return true
else
return false
self.rebuildIndex(self, widget)
return true
else
return false
end
end

--[[ Calls all registered widgets in order.
* self - RaidWidgets object
* unitFrame - The unitFrame these widgets belong to
]]
WidgetManager.createWidgets = function(self, unitFrame)
--Calls all registered widgets in order.
function WidgetManager:createWidgets(unitFrame)
for _, widget in ipairs(self.index) do
widget(unitFrame)
end
end

--[[ Create a new widget manager. ]]
-- Creates a new widget manager.
WidgetManager.new = function()
return {
index = {},
count = 0,
widgets = {},
addOrReplace = WidgetManager.addOrReplace,
get = WidgetManager.get,
insert = WidgetManager.insert,
remove = WidgetManager.remove,
getCount = WidgetManager.getCount,
createWidgets = WidgetManager.createWidgets,
}
return {
index = {},
count = 0,
widgets = {},
addOrReplace = WidgetManager.addOrReplace,
get = WidgetManager.get,
insert = WidgetManager.insert,
remove = WidgetManager.remove,
getCount = WidgetManager.getCount,
createWidgets = WidgetManager.createWidgets,
}
end

UnitFrames.newWidgetManager = WidgetManager.new
UnitFrames.newWidgetManager = WidgetManager.new

0 comments on commit b58475d

Please sign in to comment.