From 3407071c0085b595fcab1936f85c3b881d4d3017 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Thu, 12 Feb 2009 18:56:30 +0000 Subject: [PATCH] * Commiting some broken code that I plan to back out --- NinjaPanel.lua | 233 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 118 insertions(+), 115 deletions(-) diff --git a/NinjaPanel.lua b/NinjaPanel.lua index 01c56f3..d1fbf55 100644 --- a/NinjaPanel.lua +++ b/NinjaPanel.lua @@ -1,147 +1,148 @@ -NinjaPanel = {panels = {}, plugins = {}, pluginNames = {}} +NinjaPanel = {} -- Import Data Broker and bail if we can't find it for some reason local ldb = LibStub:GetLibrary("LibDataBroker-1.1") local jostle = LibStub:GetLibrary("LibJostle-3.0", true) local db +local options = { + panels = setmetatable({}, { __index = { + TOP = { + anchors = {"TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT"}, + sizes = {25, 2, 23, 23, 23, nil}, + offsets = {0, 0, 0, 0}, + gradient = {"VERTICAL", 0.2, 0.2, 0.2, 0, 0, 0}, + bgradient = {"HORIZONTAL", 203/255, 161/255, 53/255, 0, 0, 0}, + }, + RIGHT = { + anchors = {"TOPRIGHT", "BOTTOMRIGHT", "TOPLEFT", "BOTTOMLEFT"}, + sizes = {25, 2, 23, 23, 23, nil}, + offsets = {0, 0, 0, 0}, + gradient = {"HORIZONTAL", 0.2, 0.2, 0.2, 0, 0, 0}, + bgradient = {"VERTICAL", 0, 0, 0, 203/255, 161/255, 53/255}, + }, + BOTTOM = { + anchors = {"BOTTOMLEFT", "BOTTOMRIGHT", "TOPLEFT", "TOPRIGHT"}, + sizes = {25, 2, 23, 23, 23, nil}, + offsets = {0, 0, 0, 0}, + gradient = {"VERTICAL", 0, 0, 0, 0.2, 0.2, 0.2}, + bgradient = {"HORIZONTAL", 0, 0, 0, 203/255, 161/255, 53/255}, + }, + LEFT = { + anchors = {"TOPLEFT", "BOTTOMLEFT", "TOPRIGHT", "BOTTOMRIGHT"}, + sizes = {25, 2, 23, 23, 23, nil}, + offsets = {0, 0, 0, 0}, + gradient = {"HORIZONTAL", 0, 0, 0, 0.2, 0.2, 0.2}, + bgradient = {"VERTICAL", 203/255, 161/255, 53/255, 0, 0, 0}, + }, + }}) +} + local eventFrame = CreateFrame("Frame", "NinjaPanelEventFrame", UIParent) eventFrame:RegisterEvent("ADDON_LOADED") eventFrame:SetScript("OnEvent", function(self, event, arg1, ...) if arg1 == "NinjaPanel" and event == "ADDON_LOADED" then - -- Update addon options once they've been loaded - if not NinjaPanelDB then - NinjaPanelDB = {} - end - db = NinjaPanelDB - db.panels = db.panels or {} - db.plugins = db.plugins or {} - self:UnregisterEvent("ADDON_LOADED") - NinjaPanel:SpawnPanel("NinjaPanelTop", "TOP") - if db.DEVELOPMENT then - -- Spawn all four bars so we can test - NinjaPanel:SpawnPanel("NinjaPanelBottom", "BOTTOM") - NinjaPanel:SpawnPanel("NinjaPanelRight", "RIGHT") - NinjaPanel:SpawnPanel("NinjaPanelLeft", "LEFT") - - -- Create two plugins for each bar in order to test drag/drop - ldb:NewDataObject("TopOne", { type = "data source", text = "Top One" }) - ldb:NewDataObject("TopTwo", { type = "data source", text = "Top Two" }) - ldb:NewDataObject("BottomOne", { type = "data source", text = "Bottom One"}) - ldb:NewDataObject("BottomTwo", { type = "data source", text = "Bottom Two"}) - ldb:NewDataObject("LeftOne", { type = "launcher", icon = "Interface\\Icons\\Spell_Nature_StormReach"}) - ldb:NewDataObject("LeftTwo", { type = "launcher", icon = "Interface\\Icons\\Spell_Nature_StormReach"}) - ldb:NewDataObject("RightOne", { type = "launcher", icon = "Interface\\Icons\\Spell_Nature_StormReach"}) - ldb:NewDataObject("RightTwo", { type = "launcher", icon = "Interface\\Icons\\Spell_Nature_StormReach"}) - end - NinjaPanel:ScanForPlugins() + -- TODO: Set this to actually use the SV + NinjaPanel.db = options + NinjaPanel.panels = {} - if db.DEVELOPMENT then - db.plugins["TopOne"].panel = "NinjaPanelTop" - db.plugins["TopTwo"].panel = "NinjaPanelTop" - db.plugins["BottomOne"].panel = "NinjaPanelBottom" - db.plugins["BottomTwo"].panel = "NinjaPanelBottom" - NinjaPanel:UpdatePanels() - end + NinjaPanel:SpawnPanel("NinjaPanelTop", "TOP") + NinjaPanel:SpawnPanel("NinjaPanelBottom", "BOTTOM") + NinjaPanel:SpawnPanel("NinjaPanelRight", "RIGHT") + NinjaPanel:SpawnPanel("NinjaPanelLeft", "LEFT") - ldb.RegisterCallback(NinjaPanel, "LibDataBroker_DataObjectCreated", "ScanForPlugins") + --ldb.RegisterCallback(NinjaPanel, "LibDataBroker_DataObjectCreated", "ScanForPlugins") end end) --- Local functions that are defined below -local SortWeightName -local Button_OnEnter, Button_OnLeave -local Button_OnDragStart, Button_OnDragStop, Button_OnUpdateDragging -local Button_Tooltip_OnEnter, Button_Tooltip_OnLeave -local Panel_UpdateLayout - function NinjaPanel:SpawnPanel(name, position) local panel = CreateFrame("Frame", name, eventFrame) panel.bg = panel:CreateTexture(name .. "BG", "BACKGROUND") panel.border = panel:CreateTexture(name .. "Border", "BACKGROUND") + panel.boxes = {} + panel.left = CreateFrame("Button", nil, panel) + panel.center = CreateFrame("Button", nil, panel) + panel.right = CreateFrame("Button", nil, panel) + panel.left.bg = panel.left:CreateTexture(nil, "BACKGROUND") + panel.center.bg = panel.center:CreateTexture(nil, "BACKGROUND") + panel.right.bg = panel.right:CreateTexture(nil, "BACKGROUND") panel.name = name panel.position = position + local horizontal = (position == "TOP") or (position == "BOTTOM") + local opts = self.db.panels[position] + local anch = opts.anchors + + -- Anchor the panel in place panel:ClearAllPoints() - if position == "TOP" then - panel:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0) - panel:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0) - panel:SetHeight(16) - panel.bg:SetTexture(1, 1, 1, 0.8) - panel.bg:SetGradient("VERTICAL", 0.2, 0.2, 0.2, 0, 0, 0) - panel.bg:SetPoint("TOPLEFT") - panel.bg:SetPoint("TOPRIGHT") - panel.bg:SetHeight(15) - panel.border:SetTexture(1, 1, 1, 0.8) - panel.border:SetGradient("HORIZONTAL", 203 / 255, 161 / 255, 53 / 255, 0, 0, 0) - panel.border:SetPoint("TOPLEFT", panel.bg, "BOTTOMLEFT", 0, 0) - panel.border:SetPoint("TOPRIGHT", panel.bg, "BOTTOMRIGHT", 0, 0) - panel.border:SetHeight(1) - - if jostle then - jostle:RegisterTop(panel) - end - elseif position == "BOTTOM" then - panel:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0) - panel:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0) - panel:SetHeight(16) - panel.bg:SetTexture(1, 1, 1, 0.8) - panel.bg:SetGradient("VERTICAL", 0.2, 0.2, 0.2, 0, 0, 0) - panel.bg:SetPoint("BOTTOMLEFT") - panel.bg:SetPoint("BOTTOMRIGHT") - panel.bg:SetHeight(15) - panel.border:SetTexture(1, 1, 1, 0.8) - panel.border:SetGradient("HORIZONTAL", 203 / 255, 161 / 255, 53 / 255, 0, 0, 0) - panel.border:SetPoint("BOTTOMLEFT", panel.bg, "TOPLEFT", 0, 0) - panel.border:SetPoint("BOTTOMRIGHT", panel.bg, "TOPRIGHT", 0, 0) - panel.border:SetHeight(1) - - if jostle then - jostle:RegisterBottom(panel) - end - elseif position == "RIGHT" then - -- TODO: Fix the colors and gradients here - panel:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0) - panel:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0) - panel:SetWidth(16) - panel.bg:SetTexture(1, 1, 1, 0.8) - panel.bg:SetGradient("VERTICAL", 0.2, 0.2, 0.2, 0, 0, 0) - panel.bg:SetPoint("TOPRIGHT") - panel.bg:SetPoint("BOTTOMRIGHT") - panel.bg:SetWidth(15) - panel.border:SetTexture(1, 1, 1, 0.8) - panel.border:SetGradient("VERTICAL", 203 / 255, 161 / 255, 53 / 255, 0, 0, 0) - panel.border:SetPoint("TOPRIGHT", panel.bg, "TOPLEFT", 0, 0) - panel.border:SetPoint("BOTTOMRIGHT", panel.bg, "BOTTOMLEFT", 0, 0) - panel.border:SetWidth(1) - elseif position == "LEFT" then - -- TODO: Fix the colors and gradients here - panel:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0) - panel:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0) - panel:SetWidth(16) - panel.bg:SetTexture(1, 1, 1, 0.8) - panel.bg:SetGradient("HORIZONTAL", 0, 0, 0, 0.2, 0.2, 0.2) - panel.bg:SetPoint("TOPLEFT") - panel.bg:SetPoint("BOTTOMLEFT") - panel.bg:SetWidth(15) - panel.border:SetTexture(1, 1, 1, 0.8) - panel.border:SetGradient("VERTICAL", 203 / 255, 161 / 255, 53 / 255, 0, 0, 0) - panel.border:SetPoint("TOPLEFT", panel.bg, "TOPRIGHT", 0, 0) - panel.border:SetPoint("BOTTOMLEFT", panel.bg, "BOTTOMRIGHT", 0, 0) - panel.border:SetWidth(1) - end - - - -- TODO: Add the panel methods here - panel.plugins = {} - table.insert(self.panels, panel) - self.panels[panel.name] = panel + panel:SetPoint(anch[1], UIParent, anch[1], opts.offsets[1], opts.offsets[2]) + panel:SetPoint(anch[2], UIParent, anch[2], opts.offsets[3], opts.offsets[4]) + local size = opts.sizes[1] + opts.sizes[2] + if horizontal then panel:SetHeight(size) else panel:SetWidth(size) end + + -- Set the gradient/texture for the background + panel.bg:SetTexture(1, 1, 1, 0.8) + panel.bg:SetGradient(unpack(opts.gradient)) + if horizontal then panel.bg:SetHeight(size) else panel.bg:SetWidth(size) end + + -- Set the border gradient/texture + panel.border:SetTexture(1, 1, 1, 0.8) + panel.border:SetGradient(unpack(opts.bgradient)) + panel.border:SetPoint(anch[1], panel.bg, anch[3], opts.offsets[1], opts.offsets[2]) + panel.border:SetPoint(anch[2], panel.bg, anch[4], opts.offsets[3], opts.offsets[4]) + if horizontal then panel.border:SetHeight(opts.sizes[2]) else panel.border:SetWidth(opts.sizes[2]) end + + -- Anchor the drag receive boxes + panel.left:SetPoint(anch[1]) + panel.center:SetPoint("CENTER") + panel.right:SetPoint(anch[2]) + + -- Spawn a test button on the panel + local button = self:SpawnButton(name .. "Test") + button:SetHeight(opts.sizes[1]) + button.icon:SetPoint("LEFT", 2, 0) + button.icon:SetWidth(opts.sizes[3]) + button.icon:SetHeight(opts.sizes[4]) + --button.text:SetHeight(opts[5]) + --button.text:SetPoint("LEFT", button.icon, "RIGHT", 2) + button:SetWidth(button.icon:GetWidth() + 4) + button:SetPoint("LEFT", panel, "LEFT") + button:SetParent(panel) + table.insert(self.panels, panel) return panel end +function NinjaPanel:SpawnButton(name) + local button = CreateFrame("Button", "NinjaPanelButton_" .. name, eventFrame) + button.icon = button:CreateTexture(nil, "BACKGROUND") + button.text = button:CreateFontString(nil, "BACKGROUND", "GameFontHighlightSmall") + button.text:SetText("Test Button") + button.icon:SetTexture("Interface\\Icons\\INV_RoseBouquet01") + button:RegisterForClicks("AnyUp") + button:SetMovable(true) + + return button +end + +-- Local functions that are defined below +local SortWeightName +local Button_OnEnter, Button_OnLeave +local Button_OnDragStart, Button_OnDragStop, Button_OnUpdateDragging +local Button_Tooltip_OnEnter, Button_Tooltip_OnLeave +local Panel_UpdateLayout + +function NinjaPanel:ActivateDragBoxes() + for idx,panel in ipairs(self.panels) do + print("Updating drag boxes for panel: " .. panel.name) + panel.left.bg:SetTexture(1, 1, 1, 0.6) + panel.center.bg:SetTexture(1, 1, 1, 0.6) + panel.right.bg:SetTexture(1, 1, 1, 0.6) + end +end + function NinjaPanel:HasPlugin(name) return self.plugins[name] and true end @@ -327,6 +328,7 @@ function NinjaPanel:UpdatePanels() }) -- DEFAULT OPTIONS HERE + --[[ local height = opt.height local border_height = opt.border_height local gradient = opt.gradient @@ -339,6 +341,7 @@ function NinjaPanel:UpdatePanels() panel.border:SetHeight(border_height) panel.bg:SetGradientAlpha(gradient_dir, unpack(gradient)) panel.border:SetGradientAlpha(border_gradient_dir, unpack(border_gradient)) + --]] end -- Update the plugins on each panel -- 1.7.9.5