Mercurial > wow > reagentmaker
view SecureMenu.lua @ 2:04c5b817eead
The try to build my own secure menu continues...
author | contrebasse |
---|---|
date | Tue, 29 Mar 2011 22:06:36 +0200 |
parents | 5fc29ed07094 |
children | ed0582126cae |
line wrap: on
line source
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 } }) MenuFrame:SetWidth(170) MenuFrame:SetFrameStrata("DIALOG") local MENU_ENTRY_HEIGHT = 12 local numActiveEntries = 0 local menuEntries = {} local parentBtn -- The button it's associated with function A.menuIsOpen(btn) if btn then return MenuFrame:IsShown() and (btn==parentBtn) else return MenuFrame:IsShown() end end function A.menuOpen(parent) A.DEBUG("menuOpen") --if not InCombatLockDown() and numActiveEntries>0 then parentBtn = parent MenuFrame:ClearAllPoints() MenuFrame:SetPoint("LEFT",parent,"RIGHT",0,0) MenuFrame:SetHeight(240) --MenuFrame:SetParent(UIParent) MenuFrame:Show() --end end function A.menuClose() MenuFrame:Hide() MenuFrame:ClearAllPoints() parentBtn = nil for i=1,numActiveEntries do menuEntries[i]:Hide() end end function A.menuAddItem(text,action,itemID) A.DEBUG("menuAddItem "..text) local btn -- Create a button only if necessary if numActiveEntries >= #menuEntries then btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame) --, "SecureActionButtonTemplate") table.insert(menuEntries,btn) btn:SetHeight(MENU_ENTRY_HEIGHT) btn:SetWidth(160) -- Set its position if #menuEntries==0 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",itemID) 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) MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) -- Increase the entry number numActiveEntries = numActiveEntries + 1 A.DEBUG("Item added ") end -- function