--[[ Copyright (c) 2014 Eyal Shilony <Lynxium> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] local addonName, addon = ... local dropdown = CreateFrame("Frame", "StartMenuFrame", nil, "UIDropDownMenuTemplate") local display = LibStub("EasyDisplay-1.0") local L = LibStub("AceLocale-3.0"):GetLocale(addonName) dropdown:Hide() local menu = { } local disabledItems = { "talents" } local function insertItem(name, order) local interface = display:GetInterface(name) if interface and order > 0 then local entry = { order = order, name = name, text = interface.title, icon = interface.icon, notCheckable = 1, func = function() display:DisplayInterface(name) end, attributes = { ["type"] = "click", ["clickbutton"] = interface.button, } } if interface.button then entry.button = interface.button end table.insert(menu, entry) end end local function insertSimpleItem(text, func) table.insert(menu, { text = text, notCheckable = 1, func = func, }) end local function insertSeparator() if #menu > 0 then table.insert(menu, { text = "", notCheckable = 1, disabled = true, }) end end local function comp(a, b) return a.order < b.order end function addon:BuildMenu(brokerDisplayButton) if not self.updateMenu then return end wipe(menu) for name, order in pairs(self.db.profile.menu) do insertItem(name, order) end table.sort(menu, comp) if not self.db.profile.hideLogoutButtons then insertSeparator() insertSimpleItem(LOGOUT, function() Logout() HideUIPanel(GameMenuFrame) end) end if not self.db.profile.hideLogoutButtons then insertSimpleItem(EXIT_GAME, function() Quit() HideUIPanel(GameMenuFrame) end) end if not self.db.profile.hideReloadUIButton then insertSeparator() insertSimpleItem(L["Reload UI"], function() ReloadUI() end) end if not self.db.profile.hideOptionsButton then insertSeparator() insertSimpleItem(L["Options"], function() if not InterfaceOptionsFrame:IsVisible() then HideUIPanel(GameMenuFrame) InterfaceOptionsFrame_OpenToCategory(addon.name) InterfaceOptionsFrame_OpenToCategory(addon.name) else HideUIPanel(InterfaceOptionsFrame) end end) end self.updateMenu = false end function addon:OpenMenu(frame, button) local name local isLeftButton = self.db.profile.mouseButton == 1 and button == "LeftButton" local isRightButton = self.db.profile.mouseButton == 2 and button == "RightButton" for _, v in pairs(self.db.profile.accessibility) do if not IsModifierKeyDown() and v.modifier == 4 or IsAltKeyDown() and v.modifier == 1 or IsControlKeyDown() and v.modifier == 2 or IsShiftKeyDown() and v.modifier == 3 then name = v.name break end end if isLeftButton or isRightButton then display:DisplayInterface(name) else EasyMenu(menu, dropdown, frame, 0, 0, "MENU") end end function addon:IsMenuVisible() local current = UIDropDownMenu_GetCurrentDropDown() if current and current == dropdown and DropDownList1:IsShown() then return true else return false end end