From 623c47c922f0fc1a5720bf7db5f1aee7c2da06f8 Mon Sep 17 00:00:00 2001 From: Xinhuan Date: Mon, 2 Mar 2009 11:38:27 +0800 Subject: [PATCH] Upvalue Omen's menu and quick menu functions. --- Omen.lua | 67 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/Omen.lua b/Omen.lua index 02d89cb..a40d1bd 100644 --- a/Omen.lua +++ b/Omen.lua @@ -222,6 +222,25 @@ for i = 1, 40 do end +---------------------------------------------------------------------------------------- +-- Use a common frame and setup some common functions for the Omen dropdown menus +local Omen_DropDownMenu = CreateFrame("Frame", "Omen_DropDownMenu") +Omen_DropDownMenu.displayMode = "MENU" +Omen_DropDownMenu.info = {} +Omen_DropDownMenu.HideMenu = function() + if UIDROPDOWNMENU_OPEN_MENU == Omen_DropDownMenu then + CloseDropDownMenus() + end +end +Omen_DropDownMenu.OnClick = function(frame, button, down) + if Omen_DropDownMenu.initialize ~= frame.initMenuFunc then + CloseDropDownMenus() + Omen_DropDownMenu.initialize = frame.initMenuFunc + end + ToggleDropDownMenu(1, nil, Omen_DropDownMenu, frame, 0, 0) +end + + ----------------------------------------------------------------------------- -- Table Pool for recycling tables local tablePool = {} @@ -339,11 +358,8 @@ function Omen:CreateFrames() self.Title:EnableMouse(true) self.Title:SetScript("OnMouseDown", startmoving) self.Title:SetScript("OnMouseUp", stopmoving) - self.Title:SetScript("OnClick", function(self, button, down) - if button == "RightButton" then - ToggleDropDownMenu(1, nil, Omen_TitleDropDownMenu, self:GetName(), 0, 0) - end - end) + self.Title:SetScript("OnClick", Omen_DropDownMenu.OnClick) + self.Title.initMenuFunc = self.TitleQuickMenu self.Title:RegisterForClicks("RightButtonUp") -- Create Title text @@ -1717,11 +1733,24 @@ end -- Title Right Click menu do - local info = {} - local Omen_TitleDropDownMenu = CreateFrame("Frame", "Omen_TitleDropDownMenu") - Omen_TitleDropDownMenu.displayMode = "MENU" - Omen_TitleDropDownMenu.initialize = function(self, level) + -- Upvalue the functions in the menu + local function updateGrip() + db.Locked = not db.Locked + Omen:UpdateGrips() + LibStub("AceConfigRegistry-3.0"):NotifyChange("Omen") + end + local function toggleFocus() Omen:ToggleFocus() end + local function toggleTestMode() + testMode = not testMode + Omen:UpdateBars() + LibStub("AceConfigRegistry-3.0"):NotifyChange("Omen") + end + local function showConfig() Omen:ShowConfig() end + local function toggle() Omen:Toggle() end + + function Omen.TitleQuickMenu(self, level) if not level then return end + local info = self.info wipe(info) if level == 1 then -- Create the title of the menu @@ -1735,50 +1764,42 @@ do info.notCheckable = nil info.text = L["Lock Omen"] - info.func = function() - db.Locked = not db.Locked - Omen:UpdateGrips() - LibStub("AceConfigRegistry-3.0"):NotifyChange("Omen") - end + info.func = updateGrip info.checked = db.Locked info.tooltipTitle = L["Lock Omen"] info.tooltipText = L["Locks Omen in place and prevents it from being dragged or resized."] UIDropDownMenu_AddButton(info, level) info.text = L["Use Focus Target"] - info.func = function() Omen:ToggleFocus() end + info.func = toggleFocus info.checked = db.UseFocus info.tooltipTitle = L["Use Focus Target"] info.tooltipText = L["Tells Omen to additionally check your 'focus' and 'focustarget' before your 'target' and 'targettarget' in that order for threat display."] UIDropDownMenu_AddButton(info, level) info.text = L["Test Mode"] - info.func = function() - testMode = not testMode - Omen:UpdateBars() - LibStub("AceConfigRegistry-3.0"):NotifyChange("Omen") - end + info.func = toggleTestMode info.checked = testMode info.tooltipTitle = L["Test Mode"] info.tooltipText = L["Tells Omen to enter Test Mode so that you can configure Omen's display much more easily."] UIDropDownMenu_AddButton(info, level) info.text = L["Open Config"] - info.func = function() Omen:ShowConfig() end + info.func = showConfig info.checked = nil info.tooltipTitle = L["Open Config"] info.tooltipText = L["Open Omen's configuration panel"] UIDropDownMenu_AddButton(info, level) info.text = L["Hide Omen"] - info.func = function() Omen:Toggle() end + info.func = toggle info.tooltipTitle = L["Hide Omen"] info.tooltipText = nil UIDropDownMenu_AddButton(info, level) -- Close menu item info.text = CLOSE - info.func = function() CloseDropDownMenus() end + info.func = self.HideMenu info.checked = nil info.arg1 = nil info.notCheckable = 1