diff --git a/Tukui/Modules/UnitFrames/Groups/Raid.lua b/Tukui/Modules/UnitFrames/Groups/Raid.lua index 8eefc820..1cbf55f5 100644 --- a/Tukui/Modules/UnitFrames/Groups/Raid.lua +++ b/Tukui/Modules/UnitFrames/Groups/Raid.lua @@ -1,30 +1,24 @@ 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 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) +-- Make raid widgets available for external edits. +UnitFrames.RaidWidgets = UnitFrames.newWidgetManager() +local RaidWidgets = UnitFrames.RaidWidgets - 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) - - local Health = CreateFrame("StatusBar", nil, self) +-- 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 +38,22 @@ function UnitFrames:Raid() Health.colorClass = true Health.colorReaction = true Health.isRaid = true + if C.UnitFrames.Smoothing then + Health.smoothing = true + end + + unitFrame.Health = Health + unitFrame.Health.bg = Health.Background + unitFrame:Tag(Health.Value, C.Raid.HealthTag.Value) +end +RaidWidgets:addOrReplace("Health", createHealth) - -- Power - local Power = CreateFrame("StatusBar", nil, self) +-- 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 +64,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 +RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("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 + RaidWidgets:addOrReplace("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 +195,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 +RaidWidgets:addOrReplace("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 + RaidWidgets:addOrReplace("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 + RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("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 +RaidWidgets:addOrReplace("Highlight", createHighlight) + + +--[[ Raid style function. ]] +function UnitFrames.Raid(self) + 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) + + 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..5fda310f --- /dev/null +++ b/Tukui/Modules/UnitFrames/WidgetManager.lua @@ -0,0 +1,103 @@ +local T, C, L = unpack((select(2, ...))) + +local UnitFrames = T["UnitFrames"] + +local WidgetManager = {} + +-- Add a widget to the index. +function WidgetManager:addToIndex(widget) + self.count = self.count + 1 + self.index[self.count] = widget +end + +-- 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 + self.addToIndex(self, widget) + self.addToIndex(self, _widget) + elseif _widget == widget then + -- deleted + else + self.addToIndex(self, _widget) + end + end +end + +-- 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 + +-- Returns the number of registered widgets. +function WidgetManager:getCount() + return self.count +end + +-- 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 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. +function WidgetManager:remove(name) + local widget = self:get(name) + if widget then + self.widgets[name] = nil + self.rebuildIndex(self, widget) + return true + else + return false + end +end + +--Calls all registered widgets in order. +function WidgetManager:createWidgets(unitFrame) + for _, widget in ipairs(self.index) do + widget(unitFrame) + end +end + +-- 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, + } +end + +UnitFrames.newWidgetManager = WidgetManager.new 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