Mercurial > wow > reagentmaker
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:5fc29ed07094 | 2:04c5b817eead |
---|---|
14 right = 12, | 14 right = 12, |
15 top = 12, | 15 top = 12, |
16 bottom = 11 | 16 bottom = 11 |
17 } | 17 } |
18 }) | 18 }) |
19 MenuFrame:SetWidth(70) | 19 MenuFrame:SetWidth(170) |
20 MenuFrame:SetFrameStrata("DIALOG") | |
21 | |
22 local MENU_ENTRY_HEIGHT = 12 | |
23 | |
20 local numActiveEntries = 0 | 24 local numActiveEntries = 0 |
21 local menuEntries = {} | 25 local menuEntries = {} |
26 local parentBtn -- The button it's associated with | |
22 | 27 |
28 function A.menuIsOpen(btn) | |
29 if btn then | |
30 return MenuFrame:IsShown() and (btn==parentBtn) | |
31 else | |
32 return MenuFrame:IsShown() | |
33 end | |
34 end | |
23 function A.menuOpen(parent) | 35 function A.menuOpen(parent) |
24 A.DEBUG("menuOpen") | 36 A.DEBUG("menuOpen") |
25 --if not InCombatLockDown() and numActiveEntries>0 then | 37 --if not InCombatLockDown() and numActiveEntries>0 then |
38 parentBtn = parent | |
26 MenuFrame:ClearAllPoints() | 39 MenuFrame:ClearAllPoints() |
27 MenuFrame:SetPoint("TOPLEFT",parent,"TOPRIGHT",0,0) | 40 MenuFrame:SetPoint("LEFT",parent,"RIGHT",0,0) |
28 | 41 |
29 MenuFrame:SetSize(50,50) | 42 MenuFrame:SetHeight(240) |
30 MenuFrame:SetParent(UIParent) | 43 --MenuFrame:SetParent(UIParent) |
31 | 44 |
32 MenuFrame:Show() | 45 MenuFrame:Show() |
33 --end | 46 --end |
34 end | 47 end |
35 function A.menuClose() | 48 function A.menuClose() |
36 MenuFrame:Hide() | 49 MenuFrame:Hide() |
37 MenuFrame:ClearAllPoints() | 50 MenuFrame:ClearAllPoints() |
38 | 51 |
52 parentBtn = nil | |
39 for i=1,numActiveEntries do | 53 for i=1,numActiveEntries do |
40 menuEntries[i]:Hide() | 54 menuEntries[i]:Hide() |
41 end | 55 end |
42 end | 56 end |
43 | 57 |
44 function A.menuAddItem(text,action,itemID) | 58 function A.menuAddItem(text,action,itemID) |
45 A.DEBUG("menuAddItem "..text) | 59 A.DEBUG("menuAddItem "..text) |
46 local btn | 60 local btn |
47 -- Create a button only if necessary | 61 -- Create a button only if necessary |
48 if numActiveEntries >= #menuEntries then | 62 if numActiveEntries >= #menuEntries then |
49 btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") | 63 btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame) --, "SecureActionButtonTemplate") |
50 table.insert(menuEntries,btn) | 64 table.insert(menuEntries,btn) |
51 | 65 |
52 btn:SetHeight(12) | 66 btn:SetHeight(MENU_ENTRY_HEIGHT) |
53 btn:SetWidth(70) | 67 btn:SetWidth(160) |
54 | 68 |
55 -- Set its position | 69 -- Set its position |
56 if #menuEntries==1 then | 70 if #menuEntries==0 then |
57 btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) | 71 btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) |
58 else | 72 else |
59 btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) | 73 btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) |
60 end | 74 end |
61 else | 75 else |
62 btn = menuEntries[numActiveEntries+1] | 76 btn = menuEntries[numActiveEntries+1] |
63 end | 77 end |
64 | 78 |
65 -- Set its text | 79 -- Set its text |
66 btn:SetText(text or " ") | 80 btn:SetText(text or "???") |
67 | 81 |
68 -- Set its action | 82 -- Set its action |
69 if type(action)=="function" then | 83 if type(action)=="function" then |
70 btn:SetScript("OnClick",action) | 84 btn:SetScript("OnClick",action) |
71 btn:SetAttribute("type", nil) | 85 btn:SetAttribute("type", nil) |
78 btn:SetAttribute("target-item",GetItemInfo(itemID)) | 92 btn:SetAttribute("target-item",GetItemInfo(itemID)) |
79 end -- if | 93 end -- if |
80 | 94 |
81 -- Reposition MenuFrame | 95 -- Reposition MenuFrame |
82 --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) | 96 --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) |
83 MenuFrame:SetHeight((numActiveEntries+1)*12) | 97 MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) |
84 | 98 |
85 -- Increase she entry number | 99 -- Increase the entry number |
86 numActiveEntries = numActiveEntries + 1 | 100 numActiveEntries = numActiveEntries + 1 |
101 A.DEBUG("Item added ") | |
87 end -- function | 102 end -- function |