Mercurial > wow > reagentmaker
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:eba26c900e99 |
|---|---|
| 1 local addonName, A = ... | |
| 2 | |
| 3 -- Create the menu frame | |
| 4 local MenuFrame = CreateFrame("Frame",nil,UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name | |
| 5 MenuFrame:Hide() | |
| 6 MenuFrame:SetBackdrop({ | |
| 7 bgFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Background", -- path to the background texture | |
| 8 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border", -- path to the border texture | |
| 9 tile = true, -- true to repeat the background texture to fill the frame, false to scale it | |
| 10 tileSize = 32, -- size (width or height) of the square repeating background tiles (in pixels) | |
| 11 edgeSize = 32, -- thickness of edge segments and square size of edge corners (in pixels) | |
| 12 insets = { -- distance from the edges of the frame to those of the background texture (in pixels) | |
| 13 left = 11, | |
| 14 right = 12, | |
| 15 top = 12, | |
| 16 bottom = 11 | |
| 17 } | |
| 18 }) | |
| 19 local numActiveEntries = 0 | |
| 20 local menuEntries = {} | |
| 21 | |
| 22 function A.menuOpen() | |
| 23 if not InCombatLockDown() and numActiveEntries>0 then | |
| 24 MenuFrame:Show() | |
| 25 end | |
| 26 end | |
| 27 function A.menuClose() | |
| 28 MenuFrame:Hide() | |
| 29 MenuFrame:ClearAllPoints() | |
| 30 | |
| 31 for i=1,numActiveEntries do | |
| 32 menuEntries[i]:Hide() | |
| 33 end | |
| 34 end | |
| 35 | |
| 36 function A.menuAddItem(text,action,itemID) | |
| 37 local btn | |
| 38 -- Create a button only if necessary | |
| 39 if numActiveEntries >= #menuEntries then | |
| 40 btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") | |
| 41 table.insert(menuEntries,btn) | |
| 42 | |
| 43 btn:SetHeight(12) | |
| 44 | |
| 45 -- Set its position | |
| 46 if #menuEntries==1 then | |
| 47 btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) | |
| 48 else | |
| 49 btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) | |
| 50 end | |
| 51 else | |
| 52 btn = menuEntries[numActiveEntries+1] | |
| 53 end | |
| 54 | |
| 55 -- Set its text | |
| 56 btn:SetText(text or " ") | |
| 57 | |
| 58 -- Set its action | |
| 59 if type(action)=="function" then | |
| 60 btn:SetScript("OnClick",action) | |
| 61 btn:SetAttribute("type", nil) | |
| 62 btn:SetAttribute("spell", nil) | |
| 63 btn:SetAttribute("target-item",nil) | |
| 64 elseif type(action)=="string" then | |
| 65 btn:SetScript("OnClick",nil) | |
| 66 btn:SetAttribute("type", "spell") | |
| 67 btn:SetAttribute("spell", action) | |
| 68 btn:SetAttribute("target-item",GetItemInfo(itemID)) | |
| 69 end -- if | |
| 70 | |
| 71 -- Reposition MenuFrame | |
| 72 MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) | |
| 73 | |
| 74 -- Increase she entry number | |
| 75 numActiveEntries = numActiveEntries + 1 | |
| 76 end -- function |
