Quantcast

Fix accessibility so the correct interfaces

Eyal Shilony [10-19-14 - 20:33]
Fix accessibility so the correct interfaces
will open when clicking on the addon's broker display.

Filtered secured items out of the accessibility dropdowns.

Due to limitation in the game
some items cannot be opened securely from the menu during combat
so these items will be disabled once in combat.

When in combat the addon will change its text to "In Combat".
Filename
Core.lua
Menu.lua
Tooltip.lua
libs/EasyDisplay.lua
options/Accessibility.lua
options/Menu.lua
diff --git a/Core.lua b/Core.lua
index 724515b..26a5052 100644
--- a/Core.lua
+++ b/Core.lua
@@ -52,19 +52,19 @@ local defaults = {
 		accessibility = {
 			{
 				name = "bags",
-				modifier = 4
+				modifier = 1
 			},
 			{
-				name = "social",
+				name = "questlog",
 				modifier = 2
 			},
 			{
-				name = "lfd",
-				modifier = 1
+				name = "pvp",
+				modifier = 3
 			},
 			{
-				name = "questlog",
-				modifier = 3
+				name = "social",
+				modifier = 4
 			}
 		}
 	}
@@ -82,6 +82,19 @@ addon.modifiers = {
 	ALT_KEY
 }

+addon.secureItems = {
+	["spellbook"] = true,
+	["talents"] = true,
+	--["achievements"] = true,
+	--["questlog"] = true,
+	["lfd"] = true,
+	["collections"] = true,
+	["journal"] = true,
+	["guild"] = true,
+	--["help"] = true,
+	["interface"] = true
+}
+
 core:SetOnUpdate(function(self, elapsed)
 	if addon:IsMenuVisible() or not addon.tooltip then
 		return
@@ -99,6 +112,9 @@ core:SetOnUpdate(function(self, elapsed)
 end)

 function core:OnInitialize()
+	self:RegisterEvent("PLAYER_REGEN_ENABLED")
+	self:RegisterEvent("PLAYER_REGEN_DISABLED")
+
 	addon.db = LibStub("AceDB-3.0"):New("Broker_StartMenuDb", defaults, true)

 	addon.db.RegisterCallback(addon, "OnProfileChanged", function()
@@ -118,6 +134,7 @@ function core:OnInitialize()
 		icon = "Interface\\GroupFrame\\UI-Group-LeaderIcon",
 		text = addon.name,
 		OnClick = function(self, button)
+			addon:BuildMenu()
 			if not addon.db.profile.blockInCombat or not UnitAffectingCombat("player") then
 				addon:OpenMenu(self, button)
 			end
@@ -140,4 +157,14 @@ function core:OnInitialize()
 			addon.tooltip = nil
 		end
 	})
-end
\ No newline at end of file
+end
+
+function core:PLAYER_REGEN_ENABLED()
+	addon.dataobj.text = addon.name
+	addon:UpdateMenu()
+end
+
+function core:PLAYER_REGEN_DISABLED()
+	addon.dataobj.text = "|cffff0000In combat|r"
+	addon:UpdateMenu()
+end
diff --git a/Menu.lua b/Menu.lua
index 6a6d770..f2ee30d 100644
--- a/Menu.lua
+++ b/Menu.lua
@@ -22,14 +22,23 @@
 ]]

 local addonName, addon = ...
-local display = LibStub("EasyDisplay-1.0")
 local L = LibStub("AceLocale-3.0"):GetLocale(addonName)

 local menu = {}
-local disabledItems = { "talents" }
+
+local dropdown = LibStub("Libra"):CreateDropdown("Menu")
+dropdown.initialize = function(self, level)
+	for index = 1, #menu do
+		local value = menu[index]
+		if value.text then
+			value.index = index
+			UIDropDownMenu_AddButton(value, level)
+		end
+	end
+end

 local function insertItem(name, order)
-	local interface = display:GetInterface(name)
+	local interface = addon.display:GetInterface(name)
 	if interface and order > 0 then
 		local entry = {
 			order = order,
@@ -37,16 +46,15 @@ local function insertItem(name, order)
 			text = interface.title,
 			icon = interface.icon,
 			notCheckable = 1,
+			disabled = addon.secureItems[interface.name] and UnitAffectingCombat("player"),
 			attributes = {
 				["type"] = "click",
 				["clickbutton"] = interface.button,
 			}
 		}

-		if interface.button then
-			entry.button = interface.button
-		else
-			entry.func = function() display:DisplayInterface(name) end
+		if not addon.secureItems[interface.name] then
+			entry.func = function() addon.display:DisplayInterface(name) end
 		end

 		table.insert(menu, entry)
@@ -124,20 +132,9 @@ function addon:BuildMenu()
 	self.updateMenu = false
 end

-function addon:CreateMenu()
+function addon:UpdateMenu()
+	dropdown:Close()
 	addon.updateMenu = true
-	addon:BuildMenu()
-end
-
-local dropdown = LibStub("Libra"):CreateDropdown("Menu")
-dropdown.initialize = function(self, level)
-	for index = 1, #menu do
-		local value = menu[index]
-		if value.text then
-			value.index = index
-			UIDropDownMenu_AddButton(value, level)
-		end
-	end
 end

 function addon:OpenMenu(frame, button)
@@ -146,17 +143,17 @@ function addon:OpenMenu(frame, button)
 	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
+		if not IsModifierKeyDown() and v.modifier == 1
+		or IsAltKeyDown() and v.modifier == 4
+		or IsControlKeyDown() and v.modifier == 3
+		or IsShiftKeyDown() and v.modifier == 2 then
 			name = v.name
 			break
 		end
 	end

 	if isLeftButton or isRightButton then
-		display:DisplayInterface(name)
+		addon.display:DisplayInterface(name)
 	else
 		dropdown:Toggle(nil, frame)
 	end
diff --git a/Tooltip.lua b/Tooltip.lua
index 4d836a8..afc78e9 100644
--- a/Tooltip.lua
+++ b/Tooltip.lua
@@ -188,7 +188,7 @@ function addon:UpdateTooltip()

 		for i, v in ipairs(db.accessibility) do
 			local mouseButton = addon.buttons[db.mouseButton]
-			if v.modifier == 4 then
+			if v.modifier == 1 then
 				text = ": |cffffffff" .. mouseButton .. "|r"
 			else
 				text = ": |cffffffff" .. mouseButton .. " + " .. addon.modifiers[v.modifier] .. "|r"
diff --git a/libs/EasyDisplay.lua b/libs/EasyDisplay.lua
index 1d979f5..61382b2 100644
--- a/libs/EasyDisplay.lua
+++ b/libs/EasyDisplay.lua
@@ -25,7 +25,7 @@

 assert(LibStub, "EasyDisplay-1.0 requires LibStub")

-local lib, minor = LibStub:NewLibrary("EasyDisplay-1.0", 8)
+local lib, minor = LibStub:NewLibrary("EasyDisplay-1.0", 9)
 if not lib then return end
 minor = minor or 0

@@ -38,7 +38,7 @@ local UIPanelWindows = UIPanelWindows

 local BAGS = "Bags"
 local CALENDAR = "Calendar"
-local CHARACTER_MSG = "|cffFFFF00Cannot display frame '%s' because the character level is too low.|r"
+local CHARACTER_MSG = "|cffFFFF00Cannot display interface '%s' because the character level is too low.|r"

 --[[ MANAGED FRAMES ]]

@@ -102,7 +102,6 @@ local interfaces = {
 		frameName = "SpellBookFrame",
 		button = SpellbookMicroButton,
 		func = function() ToggleFrame(SpellBookFrame) end,
-		secure = true,
 	},
 	{
 		name = "talents",
@@ -112,7 +111,6 @@ local interfaces = {
 		level = SHOW_TALENT_LEVEL,
 		button = TalentMicroButton,
 		func = ToggleTalentFrame,
-		secure = true,
 	},
 	{
 		name = "achievements",
@@ -351,17 +349,6 @@ table.sort(interfaces, comp)

 local count = #interfaces

--- Due to a reason unknown to me yet the SpellBookFrame cannot be opened in combat, at least on my own machines,
--- probably because some variables and frames aren't fully set prior to combat so it taints and throws this error 'Interface action failed because of an AddOn'
--- the following hack seems to solve it by opening and closing it immediately at login.
-local frame = CreateFrame("Frame")
-frame:RegisterEvent("PLAYER_LOGIN")
-local function onEvent(self, event, ...)
-	ShowUIPanel(SpellBookFrame)
-	HideUIPanel(SpellBookFrame)
-end
-frame:SetScript('OnEvent', onEvent)
-
 -- Hides the GameMenuFrame and resets the hideMenu flag.
 -- The hideMenu flag dictates whether the GameMenuFrame should be hidden rather than opened when the interface is closed.
 local function hideUIPanel(self)
diff --git a/options/Accessibility.lua b/options/Accessibility.lua
index af5f10b..f9d3aed 100644
--- a/options/Accessibility.lua
+++ b/options/Accessibility.lua
@@ -31,9 +31,9 @@ function options:OnInitialize()
 	accessibility:SetDescription(L["Bind up to four menu items to the mouse which you can use to open them quickly by clicking on the broker display."])

 	local titles = {}
-	for _, v in addon.display:Interfaces() do
-		if not v.secure then
-			table.insert(titles, v.title)
+	for _, interface in addon.display:Interfaces() do
+		if not addon.secureItems[interface.name] then
+			table.insert(titles, interface.title)
 		end
 	end

diff --git a/options/Menu.lua b/options/Menu.lua
index 7b3e863..b4958ea 100644
--- a/options/Menu.lua
+++ b/options/Menu.lua
@@ -53,7 +53,7 @@ local function updateMenuDb(visibleItems)
 		end
 	end
 	addon.db.profile.menu = menu
-	addon:CreateMenu()
+	addon:UpdateMenu()
 end

 local function addAvailableItems(availableItems)
@@ -86,7 +86,7 @@ local function reset(availableItems, visibleItems)
 	availableItems:Clear()
 	addAvailableItems(availableItems)

-	addon:CreateMenu()
+	addon:UpdateMenu()
 end

 function options:OnInitialize()