From ff485ffa38be2c616a31864b261eda078fab435d Mon Sep 17 00:00:00 2001 From: Matt Emborsky Date: Sat, 10 Dec 2011 03:16:32 -0500 Subject: [PATCH] [caelUI - modules] We can now create a backdrop on modules via :CreateBackdrop(). Use locals over globals. Change the way :GetMedia() is referenced. --- caelUI/core/modules.lua | 44 ++++++++++++++++++--- caelUI/modules/blizzard/skin/timer_bars.lua | 8 +--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/caelUI/core/modules.lua b/caelUI/core/modules.lua index 3abea75..42fce27 100644 --- a/caelUI/core/modules.lua +++ b/caelUI/core/modules.lua @@ -2,6 +2,7 @@ local private = unpack(select(2, ...)) -- Localized variables local PixelScale = private.PixelScale +local media = private.media -- We use this to reference a blank frame for calling frame related functions when we modify them. local reference_frame = CreateFrame("Frame") @@ -34,10 +35,6 @@ module_metatable.__index.IsEventRegistered = private.events.IsEventRegistered -- Format money output module_metatable.__index.FormatMoney = private.format_money -function module_metatable.__index:GetMedia() - return private.media -end - -- Rewrite the SetPoint on our frame so we can use PixelScale here instead of in the actual module. function module_metatable.__index:SetPoint(...) local argument_count = #(...) @@ -54,8 +51,35 @@ function module_metatable.__index:SetPoint(...) reference_frame.SetPoint(self, ...) end end + + self:Print("Hello from SetPoint.") end +function module_metatable.__index:CreateBackdrop() + local name + + if self.name then + name = self.name .. "Backdrop" + elseif self.GetParent and self:GetParent():GetName() then + name = self:GetParent():GetName() .. "Backdrop" + else + name = nil + end + + self.backdrop = CreateFrame("Frame", name, self) + self.SetPoint(self.backdrop, "TOPLEFT", self, "TOPLEFT", -2, 2) + self.SetPoint(self.backdrop, "BOTTOMRIGHT", self, "BOTTOMRIGHT", 2, -2) + self.backdrop:SetFrameLevel(self:GetFrameLevel() - 1 > 0 and self:GetFrameLevel() - 1 or 0) + self.backdrop:SetBackdrop(media.backdrop_table) + self.backdrop:SetBackdropColor(0, 0, 0, 0.4) + self.backdrop:SetBackdropBorderColor(0, 0, 0, 1) + self.backdrop:SetFrameStrata("BACKGROUND") +end + +-- If the module doesn't pass in a name and we are creating a frame, we need to assign it a name so we can +-- have better global management of it. +local system_count = 0 + function CreateModule(name, create_frame) -- Make a black table if we aren't to be create a frame local self = {} @@ -63,7 +87,12 @@ function CreateModule(name, create_frame) -- If we are creating this module as a frame, we need to create the frame and overwrite some of the -- frame functions to be managed our way and to make the code a in the module look a lot cleaner. if create_frame then - self = CreateFrame("Frame", "caelUI_" .. name, UIParent) + self = CreateFrame("Frame", "caelUI_" .. name and name or "SystemGenerated" .. system_count, UIParent) + + -- Increase the system counter if we had no named passed in. + if not name then + system_count = system_count + 1 + end end -- Set our modules metatable to our returned self. @@ -74,7 +103,10 @@ function CreateModule(name, create_frame) -- We pass the PixelScale function with the table/frame we create because we occasionally still need -- it on frame modifications that are not created with this function. - self.PixelScale = private.PixelScale + self.PixelScale = PixelScale + + -- Return the media table so we don't have to include private in our modules. + self.GetMedia = function() return media end -- Return the data. return self diff --git a/caelUI/modules/blizzard/skin/timer_bars.lua b/caelUI/modules/blizzard/skin/timer_bars.lua index c110b85..44ef4ee 100644 --- a/caelUI/modules/blizzard/skin/timer_bars.lua +++ b/caelUI/modules/blizzard/skin/timer_bars.lua @@ -51,13 +51,7 @@ do statusbar:SetAllPoints(bar) end - bar.backdrop = CreateFrame("Frame", nil, bar) - bar.backdrop:SetFrameLevel(bar:GetFrameLevel() - 1) - bar.backdrop:SetPoint("TOPLEFT", bar, "TOPLEFT", PixelScale(-2), PixelScale(2)) - bar.backdrop:SetPoint("BOTTOMRIGHT", bar, "BOTTOMRIGHT", PixelScale(2), PixelScale(-2)) - bar.backdrop:SetBackdrop(media.backdrop_table) - bar.backdrop:SetBackdropBorderColor(0, 0, 0) - bar.backdrop:SetBackdropColor(0, 0, 0, 0.4) + TimerBars.CreateBackdrop(bar) bar.skinned = true end