From 0a35f72e081e1ae36a93217481d53920a1ffb5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=3Abear=3A=E2=80=82?= Date: Thu, 30 Aug 2012 18:20:47 -0600 Subject: [PATCH] New tekPanelAuction --- Panda.lua | 2 +- tekPanelAuction.lua | 192 ++++++++++++++++++++++++++++++-------------- 2 files changed, 131 insertions(+), 63 deletions(-) diff --git a/Panda.lua b/Panda.lua index 059e51c..d0012c4 100755 --- a/Panda.lua +++ b/Panda.lua @@ -60,7 +60,7 @@ local L = setmetatable(locale == "deDE" and { -- Addon Namespace -- ------------------------------- -local panel = LibStub("tekPanel-Auction").new("PandaPanel", "Panda", true) +local panel = ns.tekPanelAuction("PandaPanel", "Panda", true) Panda = {panel = panel, locale = L} local butts, lastbutt = {} diff --git a/tekPanelAuction.lua b/tekPanelAuction.lua index 3d8c0e4..a0972aa 100644 --- a/tekPanelAuction.lua +++ b/tekPanelAuction.lua @@ -1,81 +1,77 @@ +--[[ +tekPanelAuction v11 -local lib, oldminor = LibStub:NewLibrary("tekPanel-Auction", 9) -if not lib then return end -oldminor = oldminor or 0 +Creates a frame using the Auction House textures. Also generates a panel +inside this frame. Additional panels can be created. Panels can be +completely blank, like the Bids tab or split with a side frame like the +Browse tab. When using the split panel, sub-panels can be registered that +will create a menu item on the left that opens the subpanel in the space on +the right. Switching between main panels is not automatically provided, +you must create tabs or some other interface to do this. +Make sure you use ShowUIPanel(...) to show your frame, this ensure it is +positioned by the game's engine, and closes with the ESC key. -local function createtex(parent, layer, w, h, ...) - local tex = parent:CreateTexture(nil, layer) - tex:SetWidth(w) tex:SetHeight(h) - tex:SetPoint(...) - return tex -end +name - A string defining the name to assign the frame in the global. + namespace, use nil for no name. Passed to CreateFrame. +titletext - A string containing the text to display in the frame's titlebar. + Nil can be passed if no title is desired, but one is recommended +splitstyle - A boolean to trigger using split style in the default panel. +Examples + ns.tekPanelAuction("rawr", "Imma bear", true) + -- Creates a frame nameed rawr, with title "Imma bear", and a split panel. -function lib.new(name, titletext, splitstyle) - local frame = CreateFrame("Frame", name, UIParent) - frame:CreateTitleRegion() - frame:SetToplevel(true) - frame:SetFrameLevel(100) -- Force frame to a high level so it shows on top the first time it's displayed - frame:SetWidth(832) frame:SetHeight(447) - frame:SetPoint("TOPLEFT", 0, -104) - frame:EnableMouse() -- To avoid click-thru + ns.tekPanelAuction() + -- Create an anonymous frame, with no title and a blank panel. - frame:Hide() +Returns the frame and the automatically generated panel. - frame:SetAttribute("UIPanelLayout-defined", true) - frame:SetAttribute("UIPanelLayout-enabled", true) - frame:SetAttribute("UIPanelLayout-area", "doublewide") - frame:SetAttribute("UIPanelLayout-whileDead", true) - table.insert(UISpecialFrames, name) - local title = frame:GetTitleRegion() - title:SetWidth(757) title:SetHeight(20) - title:SetPoint("TOPLEFT", 75, -15) +Additional panels can be generated with the NewPanel method on the frame. +The panel is inserted into the frame's panel list, but you must provide +means of toggling its visibility. - local portrait = createtex(frame, "OVERLAY", 57, 57, "TOPLEFT", 9, -7) - SetPortraitTexture(portrait, "player") - frame:SetScript("OnEvent", function(self, event, unit) if unit == "player" then SetPortraitTexture(portrait, "player") end end) - frame:RegisterEvent("UNIT_PORTRAIT_UPDATE") +splitstyle - A boolean to trigger using split style. - local title = frame:CreateFontString(nil, "OVERLAY") - title:SetFontObject(GameFontNormal) - title:SetPoint("TOP", 0, -18) - title:SetText(titletext) +Example - local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton") - close:SetPoint("TOPRIGHT", 3, -8) - close:SetScript("OnClick", function() HideUIPanel(frame) end) + local f = ns.tekPanelAuction(nil, "") + local panel = f:NewPanel(true) - frame.topleft = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", 0, 0) - frame.top = createtex(frame, "ARTWORK", 320, 256, "TOPLEFT", 256, 0) - frame.topright = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", frame.top, "TOPRIGHT") - frame.bottomleft = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", 0, -256) - frame.bottom = createtex(frame, "ARTWORK", 320, 256, "TOPLEFT", 256, -256) - frame.bottomright = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", frame.bottom, "TOPRIGHT") +Returns the newly generated panel. - frame.panels = {} - frame.NewPanel = lib.newpanel - local panel = frame:NewPanel(splitstyle) - if splitstyle then - function frame:RegisterFrame(...) - panel:RegisterFrame(...) - end - end +When using the split style, you can register new subpanels by calling the +panel's RegisterFrame method. You do not need to parent or anchor the frame +passed in, it will be automatically positioned in the right side of the +panel when it is displayed. - local voyeur = CreateFrame("Frame", nil, frame) - voyeur:SetScript("OnShow", function() - local vis - for i,panel in pairs(frame.panels) do vis = vis or panel:IsShown() end - if not vis then frame.panels[1]:Show() end - end) +name - A string containing the name to display in the list on the left. +frame - The frame to display for the subpanel. - return frame, panel +Example + + local subpanel = CreateFrame("Frame", nil, UIParent) + local f = ns.tekPanelAuction(nil, "") + local panel = f:NewPanel(true) + panel:RegisterFrame("Help", subpanel) + +Returns nothing. +]] + +local myname, ns = ... + + +local function createtex(parent, layer, w, h, ...) + local tex = parent:CreateTexture(nil, layer) + tex:SetWidth(w) tex:SetHeight(h) + tex:SetPoint(...) + return tex end -function lib.newpanel(base, splitstyle) +local function newpanel(base, splitstyle) local frame = CreateFrame("Frame", nil, base) frame:SetAllPoints() frame:Hide() @@ -193,11 +189,18 @@ function lib.newpanel(base, splitstyle) end) else frame:SetScript("OnShow", function(self) + -- AuctionFrameTopLeft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-TopLeft"); + -- AuctionFrameTop:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Top"); + -- AuctionFrameTopRight:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-TopRight"); + -- AuctionFrameBotLeft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotLeft"); + -- AuctionFrameBot:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Bot"); + -- AuctionFrameBotRight:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotRight"); + self.base.topleft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-TopLeft") - self.base.top:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-Top") - self.base.topright:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-TopRight") + self.base.top:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Top") + self.base.topright:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-TopRight") self.base.bottomleft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotLeft") - self.base.bottom:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-Bot") + self.base.bottom:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Bot") self.base.bottomright:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotRight") end) end @@ -205,3 +208,68 @@ function lib.newpanel(base, splitstyle) return frame end + +function ns.tekPanelAuction(name, titletext, splitstyle) + local frame = CreateFrame("Frame", name, UIParent) + -- frame:CreateTitleRegion() + frame:SetToplevel(true) + frame:SetFrameLevel(100) -- Force frame to a high level so it shows on top the first time it's displayed + frame:SetWidth(832) frame:SetHeight(447) + frame:SetPoint("TOPLEFT", 0, -104) + frame:EnableMouse() -- To avoid click-thru + -- frame:SetMovable(false) + + frame:Hide() + + frame:SetAttribute("UIPanelLayout-defined", true) + frame:SetAttribute("UIPanelLayout-enabled", true) + frame:SetAttribute("UIPanelLayout-area", "doublewide") + frame:SetAttribute("UIPanelLayout-whileDead", true) + table.insert(UISpecialFrames, name) + + -- local title = frame:GetTitleRegion() + -- title:SetWidth(757) title:SetHeight(20) + -- title:SetPoint("TOPLEFT", 75, -15) + + local portrait = createtex(frame, "OVERLAY", 57, 57, "TOPLEFT", 9, -7) + SetPortraitTexture(portrait, "player") + frame:SetScript("OnEvent", function(self, event, unit) if unit == "player" then SetPortraitTexture(portrait, "player") end end) + frame:RegisterEvent("UNIT_PORTRAIT_UPDATE") + + local title = frame:CreateFontString(nil, "OVERLAY") + title:SetFontObject(GameFontNormal) + title:SetPoint("TOP", 0, -18) + title:SetText(titletext) + + local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton") + close:SetPoint("TOPRIGHT", 3, -8) + close:SetScript("OnClick", function() HideUIPanel(frame) end) + + frame.topleft = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", 0, 0) + frame.top = createtex(frame, "ARTWORK", 320, 256, "TOPLEFT", 256, 0) + frame.topright = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", frame.top, "TOPRIGHT") + frame.bottomleft = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", 0, -256) + frame.bottom = createtex(frame, "ARTWORK", 320, 256, "TOPLEFT", 256, -256) + frame.bottomright = createtex(frame, "ARTWORK", 256, 256, "TOPLEFT", frame.bottom, "TOPRIGHT") + + frame.panels = {} + frame.NewPanel = newpanel + + local panel = frame:NewPanel(splitstyle) + if splitstyle then + function frame:RegisterFrame(...) + panel:RegisterFrame(...) + end + end + + local voyeur = CreateFrame("Frame", nil, frame) + voyeur:SetScript("OnShow", function() + local vis + for i,panel in pairs(frame.panels) do vis = vis or panel:IsShown() end + if not vis then frame.panels[1]:Show() end + end) + + return frame, panel +end + +