Mercurial > wow > reagentmaker
diff SecureMenu.lua @ 0:eba26c900e99
Initial commit, save state before using secure menus
author | contrebasse |
---|---|
date | Mon, 28 Mar 2011 22:32:26 +0200 |
parents | |
children | 5fc29ed07094 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SecureMenu.lua Mon Mar 28 22:32:26 2011 +0200 @@ -0,0 +1,76 @@ +local addonName, A = ... + +-- Create the menu frame +local MenuFrame = CreateFrame("Frame",nil,UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name +MenuFrame:Hide() +MenuFrame:SetBackdrop({ + bgFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Background", -- path to the background texture + edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border", -- path to the border texture + tile = true, -- true to repeat the background texture to fill the frame, false to scale it + tileSize = 32, -- size (width or height) of the square repeating background tiles (in pixels) + edgeSize = 32, -- thickness of edge segments and square size of edge corners (in pixels) + insets = { -- distance from the edges of the frame to those of the background texture (in pixels) + left = 11, + right = 12, + top = 12, + bottom = 11 + } +}) +local numActiveEntries = 0 +local menuEntries = {} + +function A.menuOpen() + if not InCombatLockDown() and numActiveEntries>0 then + MenuFrame:Show() + end +end +function A.menuClose() + MenuFrame:Hide() + MenuFrame:ClearAllPoints() + + for i=1,numActiveEntries do + menuEntries[i]:Hide() + end +end + +function A.menuAddItem(text,action,itemID) + local btn + -- Create a button only if necessary + if numActiveEntries >= #menuEntries then + btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") + table.insert(menuEntries,btn) + + btn:SetHeight(12) + + -- Set its position + if #menuEntries==1 then + btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) + else + btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) + end + else + btn = menuEntries[numActiveEntries+1] + end + + -- Set its text + btn:SetText(text or " ") + + -- Set its action + if type(action)=="function" then + btn:SetScript("OnClick",action) + btn:SetAttribute("type", nil) + btn:SetAttribute("spell", nil) + btn:SetAttribute("target-item",nil) + elseif type(action)=="string" then + btn:SetScript("OnClick",nil) + btn:SetAttribute("type", "spell") + btn:SetAttribute("spell", action) + btn:SetAttribute("target-item",GetItemInfo(itemID)) + end -- if + + -- Reposition MenuFrame + MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) + + -- Increase she entry number + numActiveEntries = numActiveEntries + 1 +end -- function