# HG changeset patch # User contrebasse # Date 1301429196 -7200 # Node ID 04c5b817eead1694b0e003c29a727e2350352dd0 # Parent 5fc29ed07094c014ddf55342651853036605b8e6 The try to build my own secure menu continues... diff -r 5fc29ed07094 -r 04c5b817eead ReagentMaker.lua --- a/ReagentMaker.lua Mon Mar 28 22:59:20 2011 +0200 +++ b/ReagentMaker.lua Tue Mar 29 22:06:36 2011 +0200 @@ -46,7 +46,7 @@ -- Register clics on reagent's buttons for i=1,7 do local button = _G["TradeSkillReagent"..i]; - button:HookScript("OnClick", function() self:ToggleMenu(button, i) end); + button:HookScript("OnClick", function(btn) A.ToggleMenu(btn, i) end); --button:HookScript("OnEnter", function() self:Entered(button, i) end) --button:HookScript("OnLeave", function() self:Left(button, i) end) end -- for @@ -142,17 +142,24 @@ local IsModifierKeyDown = IsModifierKeyDown local GetTradeSkillReagentItemLink = GetTradeSkillReagentItemLink local GetTradeSkillSelectionIndex = GetTradeSkillSelectionIndex - local ToggleDropDownMenu = ToggleDropDownMenu -- Toggles the reagent's menu - function A:ToggleMenu(button, index) + function A.ToggleMenu(button, index) -- We want no modifiers if IsModifierKeyDown() then return end - local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index)) - if itemID and A.data[itemID] then - A.FillMenu(itemID) - A.menuOpen(button) + if A.menuIsOpen(button) then + A.menuClose() + else + local itemID = A.link2ID(GetTradeSkillReagentItemLink(GetTradeSkillSelectionIndex(), index)) + if itemID and A.data[itemID] then + A.FillMenu(itemID) + A.menuOpen(button) + else + if A.menuIsOpen() then + A.menuClose() + end + end -- if end -- if end -- function end -- do diff -r 5fc29ed07094 -r 04c5b817eead SecureMenu.lua --- a/SecureMenu.lua Mon Mar 28 22:59:20 2011 +0200 +++ b/SecureMenu.lua Tue Mar 29 22:06:36 2011 +0200 @@ -16,18 +16,31 @@ bottom = 11 } }) -MenuFrame:SetWidth(70) +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("TOPLEFT",parent,"TOPRIGHT",0,0) + MenuFrame:SetPoint("LEFT",parent,"RIGHT",0,0) - MenuFrame:SetSize(50,50) - MenuFrame:SetParent(UIParent) + MenuFrame:SetHeight(240) + --MenuFrame:SetParent(UIParent) MenuFrame:Show() --end @@ -36,6 +49,7 @@ MenuFrame:Hide() MenuFrame:ClearAllPoints() + parentBtn = nil for i=1,numActiveEntries do menuEntries[i]:Hide() end @@ -46,14 +60,14 @@ local btn -- Create a button only if necessary if numActiveEntries >= #menuEntries then - btn = CreateFrame("Button", nil, MenuFrame, "SecureActionButtonTemplate") + btn = CreateFrame("Button", "ReagentMakerMenuButton"..(#menuEntries+1), MenuFrame) --, "SecureActionButtonTemplate") table.insert(menuEntries,btn) - btn:SetHeight(12) - btn:SetWidth(70) + btn:SetHeight(MENU_ENTRY_HEIGHT) + btn:SetWidth(160) -- Set its position - if #menuEntries==1 then + if #menuEntries==0 then btn:SetPoint("TOPLEFT",MenuFrame,"TOPLEFT",0,0) else btn:SetPoint("TOPLEFT",menuEntries[#menuEntries-1],"BOTTOMLEFT",0,0) @@ -63,7 +77,7 @@ end -- Set its text - btn:SetText(text or " ") + btn:SetText(text or "???") -- Set its action if type(action)=="function" then @@ -80,8 +94,9 @@ -- Reposition MenuFrame --MenuFrame:SetPoint("BOTTOMRIGHT",btn,"BOTTOMRIGHT",0,0) - MenuFrame:SetHeight((numActiveEntries+1)*12) + MenuFrame:SetHeight((numActiveEntries+1)*MENU_ENTRY_HEIGHT) - -- Increase she entry number + -- Increase the entry number numActiveEntries = numActiveEntries + 1 + A.DEBUG("Item added ") end -- function