Quantcast

Fix profiles.

Eyal Shilony [10-16-14 - 00:06]
Fix profiles.

Update the default menu so it will match the default MicroMenu,

Remove interfaces that no longer exist in the game.

Add new interfaces like Shops and Addons.
Filename
Core.lua
Menu.lua
libs/EasyDisplay.lua
options/Menu.lua
options/UI.lua
diff --git a/Core.lua b/Core.lua
index 69f65d5..37d10bf 100644
--- a/Core.lua
+++ b/Core.lua
@@ -30,7 +30,7 @@ addon.name = addonName:gsub("Broker_", "")
 local defaults = {
 	profile = {
 		mouseButton = 1,
-		numAddOns = 5,
+		numAddOns = 10,
 		hideTooltip = false,
 		hideTooltipAccessibilityBindings = false,
 		hideLogoutButtons = true,
@@ -43,12 +43,11 @@ local defaults = {
 			achievements = 4,
 			questlog = 5,
 			guild = 6,
-			pvp = 7,
-			lfd = 8,
-			companions = 9,
-			journal = 10,
-			mainmenu = 11,
-			help = 12
+			lfd = 7,
+			companions = 8,
+			journal = 9,
+			social = 10,
+			mainmenu = 11
 		},
 		accessibility = {
 			{
@@ -103,16 +102,12 @@ function core:OnInitialize()
 	addon.updateMenu = true

 	addon.db = LibStub("AceDB-3.0"):New("Broker_StartMenuDb", defaults, true)
-	addon.db.RegisterCallback(addon, "OnProfileChanged", "BuildMenu")
-	addon.db.RegisterCallback(addon, "OnProfileCopied", "BuildMenu")
-	addon.db.RegisterCallback(addon, "OnProfileReset", "BuildMenu")

 	addon.dataobj = LibStub("LibDataBroker-1.1"):NewDataObject(addon.name, {
 		type = "data source",
 		icon = "Interface\\GroupFrame\\UI-Group-LeaderIcon",
 		text = addon.name,
 		OnClick = function(self, button)
-			addon:BuildMenu(self)
 			if not addon.db.profile.blockInCombat or not UnitAffectingCombat("player") then
 				addon:OpenMenu(self, button)
 			end
diff --git a/Menu.lua b/Menu.lua
index e7c0e86..17ed3b1 100644
--- a/Menu.lua
+++ b/Menu.lua
@@ -27,7 +27,7 @@ local display = LibStub("EasyDisplay-1.0")
 local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
 dropdown:Hide()

-local menu = { }
+local menu = {}
 local disabledItems = { "talents" }

 local function insertItem(name, order)
@@ -76,7 +76,7 @@ local function comp(a, b)
 	return a.order < b.order
 end

-function addon:BuildMenu(brokerDisplayButton)
+function addon:BuildMenu()
 	if not self.updateMenu then
 		return
 	end
@@ -125,6 +125,11 @@ function addon:BuildMenu(brokerDisplayButton)
 	self.updateMenu = false
 end

+function addon:CreateMenu()
+	addon.updateMenu = true
+	addon:BuildMenu()
+end
+
 function addon:OpenMenu(frame, button)
 	local name
 	local isLeftButton = self.db.profile.mouseButton == 1 and button == "LeftButton"
diff --git a/libs/EasyDisplay.lua b/libs/EasyDisplay.lua
index 7188cb7..6ae8c50 100644
--- a/libs/EasyDisplay.lua
+++ b/libs/EasyDisplay.lua
@@ -76,6 +76,18 @@ LoD_AddonFrames = {
 ]]
 local interfaces = {
 	{
+		name = "addons",
+		title = ADDONS,
+		func = function()
+			if not AddonList:IsVisible() then
+				ShowUIPanel(AddonList)
+				AddonList.hideMenu = true
+			else
+				HideUIPanel(AddonList)
+			end
+		end,
+	},
+	{
 		name = "character",
 		title = CHARACTER_BUTTON,
 		alias = "char",
@@ -121,7 +133,7 @@ local interfaces = {
 		alias = "ql",
 		frameName = "QuestLogFrame",
 		button = QuestLogMicroButton,
-		func = function() ToggleFrame(QuestLogFrame) end,
+		func = function() ToggleQuestLog() end,
 	},
 	{
 		name = "social",
@@ -195,13 +207,6 @@ local interfaces = {
 		end,
 	},
 	{
-		name = "keyring",
-		title = KEYRING,
-		func = function()
-			ToggleKeyRing()
-		end,
-	},
-	{
 		name = "time",
 		title = TIMEMANAGER_TITLE,
 		frameName = "TimeManagerFrame",
@@ -305,6 +310,20 @@ local interfaces = {
 				HideUIPanel(GameMenuFrame)
 			end
 		end,
+	},
+	{
+		name = "whatsnew",
+		title = GAMEMENU_NEW_BUTTON,
+		func = function()
+			SplashFrame_Open()
+		end,
+	},
+	{
+		name = "shops",
+		title = BLIZZARD_STORE,
+		func = function()
+			ToggleStoreUI()
+		end,
 	}
 }

@@ -318,6 +337,16 @@ if IsMacClient() ~= 1 then
 	end
 end

+-- We need to show addons only when we have more than one addon available.
+if GetNumAddOns() > 0 then
+	for i, v in ipairs(interfaces) do
+		if v.name == "addons" then
+			table.remove(interfaces, i)
+			break
+		end
+	end
+end
+
 local function comp(a, b)
 	return a.title:lower() < b.title:lower()
 end
diff --git a/options/Menu.lua b/options/Menu.lua
index f25a76a..d2c11c0 100644
--- a/options/Menu.lua
+++ b/options/Menu.lua
@@ -38,14 +38,55 @@ local function menuItems()
 	end
 end

-local function updateMenu(list)
+local function updateMenuDb(visibleItems)
 	local menu = {}
-	for i, item in list:Items() do
+	for i, item in visibleItems:Items() do
 		local interface = addon.display:GetInterface(item:GetText())
 		menu[interface.name] = i
 	end
+	-- Sets items that are not visible with zero so when the list of visible items is empty
+	--	AceDB won't change back to the default profile and everything will reset.
+	for _, interface in addon.display:Interfaces() do
+		local exists = menu[interface.name]
+		if not exists then
+			menu[interface.name] = 0
+		end
+	end
 	addon.db.profile.menu = menu
-	addon.updateMenu = true
+	addon:CreateMenu()
+end
+
+local function addAvailableItems(availableItems)
+	for _, interface in addon.display:Interfaces() do
+		local order = addon.db.profile.menu[interface.name]
+		if order == 0 then
+			local item = ui:CreateListItem()
+			item:SetText(interface.title)
+			availableItems:AddItem(item)
+		end
+	end
+end
+
+local function addVisibleItems(visibleItems)
+	for name in menuItems() do
+		local interface = addon.display:GetInterface(name)
+		if interface and interface.title then
+			local item = ui:CreateListItem()
+			item:SetText(interface.title)
+			visibleItems:AddItem(item)
+		end
+	end
+end
+
+local function reset(availableItems, visibleItems)
+	visibleItems:Clear()
+	addVisibleItems(visibleItems)
+	updateMenuDb(visibleItems)
+
+	availableItems:Clear()
+	addAvailableItems(availableItems)
+
+	addon:CreateMenu()
 end

 function options:OnInitialize()
@@ -56,26 +97,12 @@ function options:OnInitialize()
 	availableItems:SetPoint("TOPLEFT", 10, -120)
 	availableItems:SetSize(220, 400)

-	for i, interface in addon.display:Interfaces() do
-		local exists = addon.db.profile.menu[interface.name]
-		if not exists then
-			local item = ui:CreateListItem()
-			item:SetText(interface.title)
-			availableItems:AddItem(item)
-		end
-	end
-
 	local visibleItems = ui:CreateList(order)
 	visibleItems:SetTitle("Visible Menu Items")
 	visibleItems:SetPoint("TOPLEFT", availableItems, "TOPRIGHT", 23, 0)
 	visibleItems:SetSize(220, 400)

-	for name in menuItems() do
-		local interface = addon.display:GetInterface(name)
-		local item = ui:CreateListItem()
-		item:SetText(interface.title)
-		visibleItems:AddItem(item)
-	end
+	reset(availableItems, visibleItems)

 	local addToButton = ui:CreateButton(availableItems)
 	addToButton:SetSize(24, 24)
@@ -84,7 +111,7 @@ function options:OnInitialize()
 	addToButton:SetPushedTexture([[Interface\Buttons\UI-SpellbookIcon-NextPage-Down]])
 	addToButton:OnClick(function()
 		availableItems:MoveSelectedTo(visibleItems)
-		updateMenu(visibleItems)
+		updateMenuDb(visibleItems)
 	end)

 	local removeFromButton = ui:CreateButton(availableItems)
@@ -94,7 +121,7 @@ function options:OnInitialize()
 	removeFromButton:SetPushedTexture([[Interface\Buttons\UI-SpellbookIcon-PrevPage-Down]])
 	removeFromButton:OnClick(function()
 		visibleItems:MoveSelectedTo(availableItems)
-		updateMenu(visibleItems)
+		updateMenuDb(visibleItems)
 	end)

 	local moveUpButton = ui:CreateButton(visibleItems)
@@ -104,7 +131,7 @@ function options:OnInitialize()
 	moveUpButton:SetPushedTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollUp-Down]])
 	moveUpButton:OnClick(function()
 		visibleItems:MoveSelectedUp()
-		updateMenu(visibleItems)
+		updateMenuDb(visibleItems)
 	end)

 	local moveDownButton = ui:CreateButton(visibleItems)
@@ -114,6 +141,18 @@ function options:OnInitialize()
 	moveDownButton:SetPushedTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Down]])
 	moveDownButton:OnClick(function()
 		visibleItems:MoveSelectedDown()
-		updateMenu(visibleItems)
+		updateMenuDb(visibleItems)
+	end)
+
+	addon.db.RegisterCallback(addon, "OnProfileChanged", function()
+		reset(availableItems, visibleItems)
+	end)
+
+	addon.db.RegisterCallback(addon, "OnProfileCopied", function()
+		reset(availableItems, visibleItems)
+	end)
+
+	addon.db.RegisterCallback(addon, "OnProfileReset", function()
+		reset(availableItems, visibleItems)
 	end)
 end
diff --git a/options/UI.lua b/options/UI.lua
index 2388f45..6119b05 100644
--- a/options/UI.lua
+++ b/options/UI.lua
@@ -286,6 +286,12 @@ function ui:CreateList(parent)
 		self:Update()
 	end

+	function list:Clear()
+		for i in reverse() do
+			self:RemoveItem(i)
+		end
+	end
+
 	list.frame = frame

 	return list