From 37a570a44acad65d5659bc770dfd4e7ffa772ea6 Mon Sep 17 00:00:00 2001 From: JerichoR Date: Sun, 29 Sep 2024 16:11:40 +0200 Subject: [PATCH 1/3] Refactored the raid style function into individual element functions. Enabled add/replace/remove of individual elements for external edits. --- Tukui/Modules/UnitFrames/Groups/Raid.lua | 374 +++++++++++++++-------- 1 file changed, 242 insertions(+), 132 deletions(-) diff --git a/Tukui/Modules/UnitFrames/Groups/Raid.lua b/Tukui/Modules/UnitFrames/Groups/Raid.lua index 8eefc820..d2286982 100644 --- a/Tukui/Modules/UnitFrames/Groups/Raid.lua +++ b/Tukui/Modules/UnitFrames/Groups/Raid.lua @@ -1,30 +1,53 @@ local T, C, L = unpack((select(2, ...))) local UnitFrames = T["UnitFrames"] -local Class = select(2, UnitClass("player")) +local CreateFrame = _G.CreateFrame -function UnitFrames:Raid() - local HealthTexture = T.GetTexture(C["Textures"].UFRaidHealthTexture) - local PowerTexture = T.GetTexture(C["Textures"].UFRaidPowerTexture) - local Font = T.GetFont(C["Raid"].Font) - local HealthFont = T.GetFont(C["Raid"].HealthFont) +local subWidgets = {} +local HealthTexture +local PowerTexture +local Font +local HealthFont - self:RegisterForClicks("AnyUp") - self:SetScript("OnEnter", UnitFrame_OnEnter) - self:SetScript("OnLeave", UnitFrame_OnLeave) - self:CreateShadow() - self.Shadow:SetFrameLevel(2) +--[[ Add a widget to the Raid style. - self.Backdrop = CreateFrame("Frame", nil, self, "BackdropTemplate") - self.Backdrop:SetAllPoints() - self.Backdrop:SetFrameLevel(self:GetFrameLevel()) - self.Backdrop:SetBackdrop(UnitFrames.Backdrop) - self.Backdrop:SetBackdropColor(0, 0, 0) +Default widgets are already registered, Health and Power will be created first and are available to other widgets. After that all other widgets in random order. - local Health = CreateFrame("StatusBar", nil, self) +Add or replace a widget: AddRaidWidget(widgetName, yourCreateFunction, true)\ +Remove a widget: AddRaidWidget(widgetName, nil, true) + +* name - Name of the widget +* createFunction - Function to be called to setup the widget +* replace - true to replace an already existing entry +]] +UnitFrames.AddRaidWidget = function(name, createFunction, replace) + if replace or not subWidgets[name] then + subWidgets[name] = createFunction + end +end +local addWidget = UnitFrames.AddRaidWidget + +--[[ Calls the create function of all registered widgets. ]] +local function createWidgets(unitFrame) + -- process Health and Power first as other widgets depend on them + subWidgets["Health"](unitFrame) + subWidgets["Power"](unitFrame) + + for name, func in pairs(subWidgets) do + if name ~= "Health" and name ~= "Power" then + func(unitFrame) + end + end +end + + +-- oUF base elements +--[[ Configures oUF element Health. ]] +local function createHealth(unitFrame) + local Health = CreateFrame("StatusBar", nil, unitFrame) Health:SetPoint("TOPLEFT") Health:SetPoint("TOPRIGHT") - Health:SetHeight(self:GetHeight() - 3 - 19) + Health:SetHeight(unitFrame:GetHeight() - 3 - 19) Health:SetStatusBarTexture(HealthTexture) if C.Raid.VerticalHealth then @@ -44,12 +67,22 @@ function UnitFrames:Raid() Health.colorClass = true Health.colorReaction = true Health.isRaid = true + if C.UnitFrames.Smoothing then + Health.smoothing = true + end - -- Power - local Power = CreateFrame("StatusBar", nil, self) + unitFrame.Health = Health + unitFrame.Health.bg = Health.Background + unitFrame:Tag(Health.Value, C.Raid.HealthTag.Value) +end +addWidget("Health", createHealth) + +--[[ Configures oUF element Power. ]] +local function createPower(unitFrame) + local Power = CreateFrame("StatusBar", nil, unitFrame) Power:SetHeight(3) - Power:SetPoint("TOPLEFT", Health, "BOTTOMLEFT", 0, -1) - Power:SetPoint("TOPRIGHT", Health, "BOTTOMRIGHT", 0, -1) + Power:SetPoint("TOPLEFT", unitFrame.Health, "BOTTOMLEFT", 0, -1) + Power:SetPoint("TOPRIGHT", unitFrame.Health, "BOTTOMRIGHT", 0, -1) Power.Background = Power:CreateTexture(nil, "BORDER") Power.Background:SetTexture(PowerTexture) @@ -60,102 +93,96 @@ function UnitFrames:Raid() Power.colorPower = true Power.isRaid = true + if C.UnitFrames.Smoothing then + Power.smoothing = true + end - local Panel = CreateFrame("Frame", nil, self) - Panel:SetPoint("TOPLEFT", Power, "BOTTOMLEFT", 0, -1) - Panel:SetPoint("TOPRIGHT", Power, "BOTTOMRIGHT", 0, -1) - Panel:SetPoint("BOTTOM", 0, 0) - Panel:CreateBackdrop() - Panel.Backdrop:SetBorderColor(0, 0, 0, 0) + unitFrame.Power = Power + unitFrame.Power.bg = Power.Background +end +addWidget("Power", createPower) - local Name = Panel:CreateFontString(nil, "OVERLAY") - Name:SetPoint("CENTER") - Name:SetFontObject(Font) +--[[ Configures oUF element RaidTargetIndicator. ]] +local function createRaidTargetIndicator(unitFrame) + local RaidIcon = unitFrame.Health:CreateTexture(nil, "OVERLAY") + RaidIcon:SetSize(C.UnitFrames.RaidIconSize, C.UnitFrames.RaidIconSize) + RaidIcon:SetPoint("TOP", unitFrame, 0, C.UnitFrames.RaidIconSize / 2) + RaidIcon:SetTexture([[Interface\AddOns\Tukui\Medias\Textures\Others\RaidIcons]]) - local ReadyCheck = Power:CreateTexture(nil, "OVERLAY", nil, 2) - ReadyCheck:SetHeight(12) - ReadyCheck:SetWidth(12) + unitFrame.RaidTargetIndicator = RaidIcon +end +addWidget("RaidTargetIndicator", createRaidTargetIndicator) + +--[[ Configures oUF element ReadyCheckIndicator. ]] +local function createReadyCheckIndicator(unitFrame) + local ReadyCheck = unitFrame.Power:CreateTexture(nil, "OVERLAY", nil, 2) + ReadyCheck:SetSize(12, 12) ReadyCheck:SetPoint("CENTER") - local RaidIcon = Health:CreateTexture(nil, "OVERLAY") - RaidIcon:SetSize(C.UnitFrames.RaidIconSize, C.UnitFrames.RaidIconSize) - RaidIcon:SetPoint("TOP", self, 0, C.UnitFrames.RaidIconSize / 2) - RaidIcon:SetTexture([[Interface\AddOns\Tukui\Medias\Textures\Others\RaidIcons]]) + unitFrame.ReadyCheckIndicator = ReadyCheck +end +addWidget("ReadyCheckIndicator", createReadyCheckIndicator) +--[[ Configures oUF element ResurrectIndicator. ]] +local function createResurrectIndicator(unitFrame) + local Health = unitFrame.Health + local ResurrectIndicator = Health:CreateTexture(nil, "OVERLAY") + ResurrectIndicator:SetSize(24, 24) + ResurrectIndicator:SetPoint("CENTER", Health) + + unitFrame.ResurrectIndicator = ResurrectIndicator +end +addWidget("ResurrectIndicator", createResurrectIndicator) + +--[[ Configures oUF element Range. ]] +local function createRange(unitFrame) local Range = { insideAlpha = 1, outsideAlpha = C["Raid"].RangeAlpha, } - if C.Raid.RaidBuffsStyle.Value == "Aura Track" then - local AuraTrack = CreateFrame("Frame", nil, Health) - AuraTrack:SetAllPoints() - AuraTrack.Texture = C.Medias.Normal - AuraTrack.Icons = C.Raid.AuraTrackIcons - AuraTrack.SpellTextures = C.Raid.AuraTrackSpellTextures - AuraTrack.Thickness = C.Raid.AuraTrackThickness - AuraTrack.Font = C.Medias.Font - - self.AuraTrack = AuraTrack - elseif C.Raid.RaidBuffsStyle.Value == "Standard" then - local Buffs = CreateFrame("Frame", self:GetName().."Buffs", Health) - local onlyShowPlayer = C.Raid.RaidBuffs.Value == "Self" - local filter = C.Raid.RaidBuffs.Value == "All" and "HELPFUL" or "HELPFUL|RAID" - - Buffs:SetPoint("TOPLEFT", Health, "TOPLEFT", 0, 0) - Buffs:SetHeight(16) - Buffs:SetWidth(79) - Buffs.size = 16 - Buffs.num = 5 - Buffs.numRow = 1 - Buffs.spacing = 0 - Buffs.initialAnchor = "TOPLEFT" - Buffs.disableCooldown = true - Buffs.disableMouse = true - Buffs.onlyShowPlayer = onlyShowPlayer - Buffs.filter = filter - Buffs.IsRaid = true - Buffs.PostCreateIcon = UnitFrames.PostCreateAura - Buffs.PostUpdateIcon = UnitFrames.DesaturateBuffs - Buffs.PostCreateButton = UnitFrames.PostCreateAura - Buffs.PostUpdateButton = UnitFrames.DesaturateBuffs - - self.Buffs = Buffs - end - - if C.Raid.DebuffWatch then - local RaidDebuffs = CreateFrame("Frame", nil, Health) - local Height = Health:GetHeight() - local DebuffSize = Height >= 32 and Height - 16 or Height - - RaidDebuffs:SetHeight(DebuffSize) - RaidDebuffs:SetWidth(DebuffSize) - RaidDebuffs:SetPoint("CENTER", Health) - RaidDebuffs:SetFrameLevel(Health:GetFrameLevel() + 10) - RaidDebuffs.icon = RaidDebuffs:CreateTexture(nil, "ARTWORK") - RaidDebuffs.icon:SetTexCoord(.1, .9, .1, .9) - RaidDebuffs.icon:SetInside(RaidDebuffs) - RaidDebuffs.cd = CreateFrame("Cooldown", nil, RaidDebuffs, "CooldownFrameTemplate") - RaidDebuffs.cd:SetInside(RaidDebuffs, 1, 0) - RaidDebuffs.cd:SetReverse(true) - RaidDebuffs.cd:SetHideCountdownNumbers(true) - RaidDebuffs.cd:SetAlpha(.7) - RaidDebuffs.timer = RaidDebuffs:CreateFontString(nil, "OVERLAY") - RaidDebuffs.timer:SetFont(C.Medias.Font, 12, "OUTLINE") - RaidDebuffs.timer:SetPoint("CENTER", RaidDebuffs, 1, 0) - RaidDebuffs.count = RaidDebuffs:CreateFontString(nil, "OVERLAY") - RaidDebuffs.count:SetFont(C.Medias.Font, 12, "OUTLINE") - RaidDebuffs.count:SetPoint("BOTTOMRIGHT", RaidDebuffs, "BOTTOMRIGHT", 2, 0) - RaidDebuffs.count:SetTextColor(1, .9, 0) - - self.RaidDebuffs = RaidDebuffs - end + unitFrame.Range = Range +end +addWidget("Range", createRange) + +--[[ 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" + local filter = C.Raid.RaidBuffs.Value == "All" and "HELPFUL" or "HELPFUL|RAID" + + Buffs:SetPoint("TOPLEFT", unitFrame.Health, "TOPLEFT", 0, 0) + Buffs:SetHeight(16) + Buffs:SetWidth(79) + Buffs.size = 16 + Buffs.num = 5 + Buffs.numRow = 1 + Buffs.spacing = 0 + Buffs.initialAnchor = "TOPLEFT" + Buffs.disableCooldown = true + Buffs.disableMouse = true + Buffs.onlyShowPlayer = onlyShowPlayer + Buffs.filter = filter + Buffs.IsRaid = true + Buffs.PostCreateIcon = UnitFrames.PostCreateAura + Buffs.PostUpdateIcon = UnitFrames.DesaturateBuffs + Buffs.PostCreateButton = UnitFrames.PostCreateAura + Buffs.PostUpdateButton = UnitFrames.DesaturateBuffs + + unitFrame.Buffs = Buffs +end +if C.Raid.RaidBuffsStyle.Value == "Standard" then + addWidget("Buffs", createBuffs) +end +--[[ Configures oUF element HealthPrediction. ]] +local function createHealComm(unitframe) if C.UnitFrames.HealComm then + local Health = unitframe.Health local myBar = CreateFrame("StatusBar", nil, Health) local otherBar = CreateFrame("StatusBar", nil, Health) local absorbBar = CreateFrame("StatusBar", nil, Health) - local Vertical = Health:GetOrientation("VERTICAL") == "VERTICAL" and true or false + local Vertical = Health:GetOrientation() == "VERTICAL" and true or false myBar:SetOrientation(Vertical and "VERTICAL" or "HORIZONTAL") myBar:SetFrameLevel(Health:GetFrameLevel()) @@ -197,48 +224,131 @@ function UnitFrames:Raid() maxOverflow = 1, } - self.HealthPrediction = HealthPrediction + unitframe.HealthPrediction = HealthPrediction end - local ResurrectIndicator = Health:CreateTexture(nil, "OVERLAY") - ResurrectIndicator:SetSize(24, 24) - ResurrectIndicator:SetPoint("CENTER", Health) - - local Highlight = CreateFrame("Frame", nil, self, "BackdropTemplate") - Highlight:SetBackdrop({edgeFile = C.Medias.Glow, edgeSize = C.Raid.HighlightSize}) - Highlight:SetOutside(self, C.Raid.HighlightSize, C.Raid.HighlightSize) - Highlight:SetBackdropBorderColor(unpack(C.Raid.HighlightColor)) - Highlight:SetFrameLevel(0) - Highlight:Hide() - -- Enable smoothing bars animation? if C.UnitFrames.Smoothing then - Health.smoothing = true - Power.smoothing = true + unitframe.Health.smoothing = true + unitframe.Power.smoothing = true - if self.HealthPrediction then - self.HealthPrediction.smoothing = true + if unitframe.HealthPrediction then + unitframe.HealthPrediction.smoothing = true end end +end +addWidget("HealComm", createHealComm) + + +-- oUF Plugins +--[[ Configures oUF_AuraTrack. ]] +local function createAuraTrack(unitFrame) + local AuraTrack = CreateFrame("Frame", nil, unitFrame.Health) + AuraTrack:SetAllPoints() + AuraTrack.Texture = C.Medias.Normal + AuraTrack.Icons = C.Raid.AuraTrackIcons + AuraTrack.SpellTextures = C.Raid.AuraTrackSpellTextures + AuraTrack.Thickness = C.Raid.AuraTrackThickness + AuraTrack.Font = C.Medias.Font + + unitFrame.AuraTrack = AuraTrack +end +if C.Raid.RaidBuffsStyle.Value == "Aura Track" then + addWidget("AuraTrack", createAuraTrack) +end + +--[[ Configures oUF_RaidDebuffs. ]] +local function createRaidDebuffs(unitFrame) + local Health = unitFrame.Health + local RaidDebuffs = CreateFrame("Frame", nil, Health) + local Height = Health:GetHeight() + local DebuffSize = Height >= 32 and Height - 16 or Height + + RaidDebuffs:SetSize(DebuffSize, DebuffSize) + RaidDebuffs:SetPoint("CENTER", Health) + RaidDebuffs:SetFrameLevel(Health:GetFrameLevel() + 10) + RaidDebuffs.icon = RaidDebuffs:CreateTexture(nil, "ARTWORK") + RaidDebuffs.icon:SetTexCoord(.1, .9, .1, .9) + RaidDebuffs.icon:SetInside(RaidDebuffs) + RaidDebuffs.cd = CreateFrame("Cooldown", nil, RaidDebuffs, "CooldownFrameTemplate") + RaidDebuffs.cd:SetInside(RaidDebuffs, 1, 0) + RaidDebuffs.cd:SetReverse(true) + RaidDebuffs.cd:SetHideCountdownNumbers(true) + RaidDebuffs.cd:SetAlpha(.7) + RaidDebuffs.timer = RaidDebuffs:CreateFontString(nil, "OVERLAY") + RaidDebuffs.timer:SetFont(C.Medias.Font, 12, "OUTLINE") + RaidDebuffs.timer:SetPoint("CENTER", RaidDebuffs, 1, 0) + RaidDebuffs.count = RaidDebuffs:CreateFontString(nil, "OVERLAY") + RaidDebuffs.count:SetFont(C.Medias.Font, 12, "OUTLINE") + RaidDebuffs.count:SetPoint("BOTTOMRIGHT", RaidDebuffs, "BOTTOMRIGHT", 2, 0) + RaidDebuffs.count:SetTextColor(1, .9, 0) + + unitFrame.RaidDebuffs = RaidDebuffs +end +if C.Raid.DebuffWatch then + addWidget("RaidDebuffs", createRaidDebuffs) +end + + +-- additional plugins +--[[ 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) + Panel:SetPoint("TOPRIGHT", unitFrame.Power, "BOTTOMRIGHT", 0, -1) + Panel:SetPoint("BOTTOM", 0, 0) + Panel:CreateBackdrop() + Panel.Backdrop:SetBorderColor(0, 0, 0, 0) + + local Name = Panel:CreateFontString(nil, "OVERLAY") + Name:SetPoint("CENTER") + Name:SetFontObject(Font) - self:Tag(Health.Value, C.Raid.HealthTag.Value) - self.Health = Health - self.Health.bg = Health.Background - self.Power = Power - self.Power.bg = Power.Background - self.Panel = Panel - self.Name = Name - self.ReadyCheckIndicator = ReadyCheck - self.Range = Range - self.RaidTargetIndicator = RaidIcon - self.Highlight = Highlight - self.ResurrectIndicator = ResurrectIndicator + unitFrame.Panel = Panel + unitFrame.Name = Name if T.Retail then - self:Tag(Name, "[Tukui:GetRaidNameColor][Tukui:NameShort]") + unitFrame:Tag(Name, "[Tukui:GetRaidNameColor][Tukui:NameShort]") else - self:Tag(Name, "[Tukui:NameShort]") + unitFrame:Tag(Name, "[Tukui:NameShort]") end +end +addWidget("NamePanel", createNamePanel) + +--[[ 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}) + Highlight:SetOutside(unitFrame, C.Raid.HighlightSize, C.Raid.HighlightSize) + Highlight:SetBackdropBorderColor(unpack(C.Raid.HighlightColor)) + Highlight:SetFrameLevel(0) + Highlight:Hide() + + unitFrame.Highlight = Highlight +end +addWidget("Highlight", createHighlight) + + +--[[ Raid style function. ]] +function UnitFrames:Raid() + HealthTexture = T.GetTexture(C["Textures"].UFRaidHealthTexture) + PowerTexture = T.GetTexture(C["Textures"].UFRaidPowerTexture) + Font = T.GetFont(C["Raid"].Font) + HealthFont = T.GetFont(C["Raid"].HealthFont) + + self:RegisterForClicks("AnyUp") + self:SetScript("OnEnter", UnitFrame_OnEnter) + self:SetScript("OnLeave", UnitFrame_OnLeave) + self:CreateShadow() + self.Shadow:SetFrameLevel(2) + + self.Backdrop = CreateFrame("Frame", nil, self, "BackdropTemplate") + self.Backdrop:SetAllPoints() + self.Backdrop:SetFrameLevel(self:GetFrameLevel()) + self.Backdrop:SetBackdrop(UnitFrames.Backdrop) + self.Backdrop:SetBackdropColor(0, 0, 0) + + createWidgets(self) self:RegisterEvent("PLAYER_TARGET_CHANGED", UnitFrames.Highlight, true) self:RegisterEvent("RAID_ROSTER_UPDATE", UnitFrames.Highlight, true) From 0866812be0bdb8d21d5afff52fc410ed31599153 Mon Sep 17 00:00:00 2001 From: JerichoR Date: Wed, 2 Oct 2024 22:03:14 +0200 Subject: [PATCH 2/3] Moved the widget registry to own file and preserve internal order --- Tukui/Modules/UnitFrames/Groups/Raid.lua | 61 +++------- Tukui/Modules/UnitFrames/WidgetManager.lua | 134 +++++++++++++++++++++ Tukui/Tukui-Cata.toc | 3 +- Tukui/Tukui-Classic.toc | 1 + Tukui/Tukui-Mainline.toc | 1 + 5 files changed, 154 insertions(+), 46 deletions(-) create mode 100644 Tukui/Modules/UnitFrames/WidgetManager.lua diff --git a/Tukui/Modules/UnitFrames/Groups/Raid.lua b/Tukui/Modules/UnitFrames/Groups/Raid.lua index d2286982..5be5f1a4 100644 --- a/Tukui/Modules/UnitFrames/Groups/Raid.lua +++ b/Tukui/Modules/UnitFrames/Groups/Raid.lua @@ -3,43 +3,14 @@ local T, C, L = unpack((select(2, ...))) local UnitFrames = T["UnitFrames"] local CreateFrame = _G.CreateFrame -local subWidgets = {} local HealthTexture local PowerTexture local Font local HealthFont ---[[ Add a widget to the Raid style. - -Default widgets are already registered, Health and Power will be created first and are available to other widgets. After that all other widgets in random order. - -Add or replace a widget: AddRaidWidget(widgetName, yourCreateFunction, true)\ -Remove a widget: AddRaidWidget(widgetName, nil, true) - -* name - Name of the widget -* createFunction - Function to be called to setup the widget -* replace - true to replace an already existing entry -]] -UnitFrames.AddRaidWidget = function(name, createFunction, replace) - if replace or not subWidgets[name] then - subWidgets[name] = createFunction - end -end -local addWidget = UnitFrames.AddRaidWidget - ---[[ Calls the create function of all registered widgets. ]] -local function createWidgets(unitFrame) - -- process Health and Power first as other widgets depend on them - subWidgets["Health"](unitFrame) - subWidgets["Power"](unitFrame) - - for name, func in pairs(subWidgets) do - if name ~= "Health" and name ~= "Power" then - func(unitFrame) - end - end -end - +--[[ Make raid widgets available for external edits. ]] +UnitFrames.RaidWidgets = UnitFrames.newWidgetManager() +local RaidWidgets = UnitFrames.RaidWidgets -- oUF base elements --[[ Configures oUF element Health. ]] @@ -75,7 +46,7 @@ local function createHealth(unitFrame) unitFrame.Health.bg = Health.Background unitFrame:Tag(Health.Value, C.Raid.HealthTag.Value) end -addWidget("Health", createHealth) +RaidWidgets:addOrReplace("Health", createHealth) --[[ Configures oUF element Power. ]] local function createPower(unitFrame) @@ -100,7 +71,7 @@ local function createPower(unitFrame) unitFrame.Power = Power unitFrame.Power.bg = Power.Background end -addWidget("Power", createPower) +RaidWidgets:addOrReplace("Power", createPower) --[[ Configures oUF element RaidTargetIndicator. ]] local function createRaidTargetIndicator(unitFrame) @@ -111,7 +82,7 @@ local function createRaidTargetIndicator(unitFrame) unitFrame.RaidTargetIndicator = RaidIcon end -addWidget("RaidTargetIndicator", createRaidTargetIndicator) +RaidWidgets:addOrReplace("RaidTargetIndicator", createRaidTargetIndicator) --[[ Configures oUF element ReadyCheckIndicator. ]] local function createReadyCheckIndicator(unitFrame) @@ -121,7 +92,7 @@ local function createReadyCheckIndicator(unitFrame) unitFrame.ReadyCheckIndicator = ReadyCheck end -addWidget("ReadyCheckIndicator", createReadyCheckIndicator) +RaidWidgets:addOrReplace("ReadyCheckIndicator", createReadyCheckIndicator) --[[ Configures oUF element ResurrectIndicator. ]] local function createResurrectIndicator(unitFrame) @@ -132,7 +103,7 @@ local function createResurrectIndicator(unitFrame) unitFrame.ResurrectIndicator = ResurrectIndicator end -addWidget("ResurrectIndicator", createResurrectIndicator) +RaidWidgets:addOrReplace("ResurrectIndicator", createResurrectIndicator) --[[ Configures oUF element Range. ]] local function createRange(unitFrame) @@ -143,7 +114,7 @@ local function createRange(unitFrame) unitFrame.Range = Range end -addWidget("Range", createRange) +RaidWidgets:addOrReplace("Range", createRange) --[[ Configures oUF element Buffs (part of Auras). ]] local function createBuffs(unitFrame) @@ -172,7 +143,7 @@ local function createBuffs(unitFrame) unitFrame.Buffs = Buffs end if C.Raid.RaidBuffsStyle.Value == "Standard" then - addWidget("Buffs", createBuffs) + RaidWidgets:addOrReplace("Buffs", createBuffs) end --[[ Configures oUF element HealthPrediction. ]] @@ -237,7 +208,7 @@ local function createHealComm(unitframe) end end end -addWidget("HealComm", createHealComm) +RaidWidgets:addOrReplace("HealComm", createHealComm) -- oUF Plugins @@ -254,7 +225,7 @@ local function createAuraTrack(unitFrame) unitFrame.AuraTrack = AuraTrack end if C.Raid.RaidBuffsStyle.Value == "Aura Track" then - addWidget("AuraTrack", createAuraTrack) + RaidWidgets:addOrReplace("AuraTrack", createAuraTrack) end --[[ Configures oUF_RaidDebuffs. ]] @@ -286,7 +257,7 @@ local function createRaidDebuffs(unitFrame) unitFrame.RaidDebuffs = RaidDebuffs end if C.Raid.DebuffWatch then - addWidget("RaidDebuffs", createRaidDebuffs) + RaidWidgets:addOrReplace("RaidDebuffs", createRaidDebuffs) end @@ -313,7 +284,7 @@ local function createNamePanel(unitFrame) unitFrame:Tag(Name, "[Tukui:NameShort]") end end -addWidget("NamePanel", createNamePanel) +RaidWidgets:addOrReplace("NamePanel", createNamePanel) --[[ Highlights the currently selected unit. ]] local function createHighlight(unitFrame) @@ -326,7 +297,7 @@ local function createHighlight(unitFrame) unitFrame.Highlight = Highlight end -addWidget("Highlight", createHighlight) +RaidWidgets:addOrReplace("Highlight", createHighlight) --[[ Raid style function. ]] @@ -348,7 +319,7 @@ function UnitFrames:Raid() self.Backdrop:SetBackdrop(UnitFrames.Backdrop) self.Backdrop:SetBackdropColor(0, 0, 0) - createWidgets(self) + RaidWidgets:createWidgets(self) self:RegisterEvent("PLAYER_TARGET_CHANGED", UnitFrames.Highlight, true) self:RegisterEvent("RAID_ROSTER_UPDATE", UnitFrames.Highlight, true) diff --git a/Tukui/Modules/UnitFrames/WidgetManager.lua b/Tukui/Modules/UnitFrames/WidgetManager.lua new file mode 100644 index 00000000..57cc91b9 --- /dev/null +++ b/Tukui/Modules/UnitFrames/WidgetManager.lua @@ -0,0 +1,134 @@ +local T, C, L = unpack((select(2, ...))) + +local UnitFrames = T["UnitFrames"] + +local WidgetManager = {} + +--[[ Internal: Add a widget to the index. ]] +local function addToIndex(self, 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) + 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) + elseif _widget == widget then + -- deleted + else + 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 +end + +--[[ Gets the number of registered widgets. + +* self - RaidWidgets object +* returns - Number of registered widgets +]] +WidgetManager.getCount = function(self) + 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) + 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 +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) + local widget = self:get(name) + if widget then + self.widgets[name] = nil + 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) + for _, widget in ipairs(self.index) do + widget(unitFrame) + end +end + +--[[ Create 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, + } +end + +UnitFrames.newWidgetManager = WidgetManager.new \ No newline at end of file diff --git a/Tukui/Tukui-Cata.toc b/Tukui/Tukui-Cata.toc index 00991018..c0412662 100644 --- a/Tukui/Tukui-Cata.toc +++ b/Tukui/Tukui-Cata.toc @@ -9,7 +9,7 @@ ## X-Website: http://www.tukui.org ## X-Tukui-ProjectID: 1 ## X-Tukui-ProjectFolders: Tukui - + ## Init Core\Init.lua @@ -184,6 +184,7 @@ Modules\UnitFrames\Core.lua Modules\UnitFrames\Debuffs.lua Modules\UnitFrames\Tracking.lua Modules\UnitFrames\Tags.lua +Modules\UnitFrames\WidgetManager.lua Modules\UnitFrames\Classes\Warrior.lua Modules\UnitFrames\Classes\Paladin.lua Modules\UnitFrames\Classes\Hunter.lua diff --git a/Tukui/Tukui-Classic.toc b/Tukui/Tukui-Classic.toc index e3caa588..9d101ab7 100644 --- a/Tukui/Tukui-Classic.toc +++ b/Tukui/Tukui-Classic.toc @@ -181,6 +181,7 @@ Modules\UnitFrames\Core.lua Modules\UnitFrames\Debuffs.lua Modules\UnitFrames\Tracking.lua Modules\UnitFrames\Tags.lua +Modules\UnitFrames\WidgetManager.lua Modules\UnitFrames\Classes\Warrior.lua Modules\UnitFrames\Classes\Paladin.lua Modules\UnitFrames\Classes\Hunter.lua diff --git a/Tukui/Tukui-Mainline.toc b/Tukui/Tukui-Mainline.toc index 1a859266..dba2af62 100644 --- a/Tukui/Tukui-Mainline.toc +++ b/Tukui/Tukui-Mainline.toc @@ -201,6 +201,7 @@ Modules\UnitFrames\Core.lua Modules\UnitFrames\Debuffs.lua Modules\UnitFrames\Tracking.lua Modules\UnitFrames\Tags.lua +Modules\UnitFrames\WidgetManager.lua Modules\UnitFrames\Classes\Warrior.lua Modules\UnitFrames\Classes\Paladin.lua Modules\UnitFrames\Classes\Hunter.lua From b58475dee7ab2b9895a2786eaadc251755b43a77 Mon Sep 17 00:00:00 2001 From: JerichoR Date: Thu, 3 Oct 2024 12:26:45 +0200 Subject: [PATCH 3/3] Update doc --- Tukui/Modules/UnitFrames/Groups/Raid.lua | 28 ++--- Tukui/Modules/UnitFrames/WidgetManager.lua | 133 ++++++++------------- 2 files changed, 65 insertions(+), 96 deletions(-) diff --git a/Tukui/Modules/UnitFrames/Groups/Raid.lua b/Tukui/Modules/UnitFrames/Groups/Raid.lua index 5be5f1a4..1cbf55f5 100644 --- a/Tukui/Modules/UnitFrames/Groups/Raid.lua +++ b/Tukui/Modules/UnitFrames/Groups/Raid.lua @@ -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") @@ -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) @@ -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) @@ -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) @@ -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") @@ -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, @@ -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" @@ -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 @@ -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() @@ -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) @@ -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) @@ -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}) @@ -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) diff --git a/Tukui/Modules/UnitFrames/WidgetManager.lua b/Tukui/Modules/UnitFrames/WidgetManager.lua index 57cc91b9..5fda310f 100644 --- a/Tukui/Modules/UnitFrames/WidgetManager.lua +++ b/Tukui/Modules/UnitFrames/WidgetManager.lua @@ -4,14 +4,14 @@ 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 = {} @@ -19,49 +19,34 @@ local function rebuildIndex(self, widget, atIndex) 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 @@ -69,66 +54,50 @@ WidgetManager.get = function(self, 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 \ No newline at end of file +UnitFrames.newWidgetManager = WidgetManager.new