Quantcast

-Redesigned the profiles window to look a lot cleaner.

Safturento [11-10-11 - 04:05]
-Redesigned the profiles window to look a lot cleaner.
-Added a tooltip when mousing over the enable/disable button for an addon.
Filename
stAddonManager.lua
diff --git a/stAddonManager.lua b/stAddonManager.lua
index b45b6c1..c37c9ae 100644
--- a/stAddonManager.lua
+++ b/stAddonManager.lua
@@ -1,4 +1,5 @@
-local addonName = select(1, ...)
+local ADDON_NAME = ...
+
 ------------------------------------------------------
 -- MEDIA & CONFIG ------------------------------------
 ------------------------------------------------------
@@ -100,6 +101,30 @@ local function SkinScrollBar(frame, thumbTrim)
 	end
 end

+local function CreateMenuButton(parent, width, height, text, ...)
+	local button = CreateFrame("Button", nil, parent)
+	button:SetFrameLevel(parent:GetFrameLevel()+1)
+	button:SetSize(width, height)
+	SkinFrame(button)
+	if ... then button:SetPoint(...) end
+
+	button.text = button:CreateFontString(nil, "OVERLAY")
+	button.text:SetFont(unpack(font))
+	button.text:SetPoint("CENTER", 1, 0)
+	if text then button.text:SetText(text) end
+
+	button:SetScript("OnEnter", function(self)
+		self.text:SetTextColor(0/255, 170/255, 255/255)
+		self:SetBackdropColor(.1, .1, .1)
+	end)
+	button:SetScript("OnLeave", function(self)
+		self.text:SetTextColor(255/255, 255/255, 255/255)
+		self:SetBackdropColor(unpack(backdropcolor))
+	end)
+
+	return button
+end
+
 function stAddonManager:UpdateAddonList(queryString)
 	local addons = {}
 	for i=1, GetNumAddOns() do
@@ -111,6 +136,15 @@ function stAddonManager:UpdateAddonList(queryString)
 			addons[i].title = title
 			addons[i].notes = notes
 			addons[i].enabled = enabled
+			if GetAddOnMetadata(i, "version") then
+				addons[i].version = GetAddOnMetadata(i, "version")
+			end
+			if GetAddOnDependencies(i) then
+				addons[i].dependencies = {GetAddOnDependencies(i)}
+			end
+			if GetAddOnOptionalDependencies(i) then
+				addons[i].optionaldependencies = {GetAddOnOptionalDependencies(i)}
+			end
 		end
 	end
 	return addons
@@ -127,58 +161,23 @@ local function GetEnabledAddons()
 	return EnabledAddons
 end

-local function LoadProfileWindow()
+function stAddonManager:LoadProfileWindow()
 	local self = stAddonManager
 	if self.ProfileWindow then ToggleFrame(self.ProfileWindow) return end
-
 	local window = CreateFrame("Frame", "stAddonManager_ProfileWindow", self)
 	window:SetPoint("TOPLEFT", self, "TOPRIGHT", 5, 0)
-	window:SetSize(200, 300)
+	window:SetSize(150, 20)
 	SkinFrame(window, true)
-
-	local header = CreateFrame("Frame", "stAddonmanager_ProfileWindow_Header", window)
-	header:SetPoint("TOP", window, "TOP", 0, 0)
-	SkinFrame(header)
-	header:SetSize(window:GetWidth(), 20)
+	CreateBackdrop(window, true)

-	local hTitle = header:CreateFontString(nil, "OVERLAY")
+
+	local hTitle = window:CreateFontString(nil, "OVERLAY")
 	hTitle:SetFont(unpack(font))
 	hTitle:SetPoint("CENTER")
 	hTitle:SetText("Profiles")
-	header.title = hTitle
-	window.header = header
-
-	--Create scroll frame (God damn these things are a pain)
-	local scrollBG = CreateFrame("Frame", window:GetName().."_ScrollBackground", window)
-	scrollBG:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 5, -55)
-	scrollBG:SetWidth(window:GetWidth()-10)
-	scrollBG:SetHeight(window:GetHeight()-80)
-	SkinFrame(scrollBG)
-
-	local scrollFrame = CreateFrame("ScrollFrame", window:GetName().."_ScrollFrame", window, "UIPanelScrollFrameTemplate")
-	scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 0, -2)
-	scrollFrame:SetWidth(scrollBG:GetWidth()-25)
-	scrollFrame:SetHeight(scrollBG:GetHeight()-5)
-	SkinScrollBar(_G[window:GetName().."_ScrollFrameScrollBar"])
-	scrollFrame:SetFrameLevel(window:GetFrameLevel()+1)
+	window.title = hTitle

-	scrollFrame.Anchor = CreateFrame("Frame", window:GetName().."_ScrollAnchor", scrollFrame)
-	scrollFrame.Anchor:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, -3)
-	scrollFrame.Anchor:SetWidth(window:GetWidth()-40)
-	scrollFrame.Anchor:SetHeight(scrollFrame:GetHeight()-4)
-	scrollFrame.Anchor:SetFrameLevel(scrollFrame:GetFrameLevel()+1)
-	scrollFrame:SetScrollChild(scrollFrame.Anchor)
-
-	local EnableAll = CreateFrame("Button", window:GetName().."_EnableAllButton", window)
-	SkinFrame(EnableAll)
-	EnableAll:SetSize((window:GetWidth()-15)/2, 20)
-	EnableAll:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 5, -5)
-	EnableAll.text = EnableAll:CreateFontString(nil, "OVERLAY")
-	EnableAll.text:SetFont(unpack(font))
-	EnableAll.text:SetText("Enable All")
-	EnableAll.text:SetPoint("CENTER")
-	EnableAll:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	EnableAll:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	local EnableAll = CreateMenuButton(window, (window:GetWidth()-15)/2, 20, "Enable All", "TOPLEFT", window, "BOTTOMLEFT", 5, -5)
 	EnableAll:SetScript("OnClick", function(self)
 		for i, addon in pairs(stAddonManager.AllAddons) do
 			EnableAddOn(addon.name)
@@ -187,19 +186,10 @@ local function LoadProfileWindow()
 		end
 	end)

-	local DisableAll = CreateFrame("Button", window:GetName().."_DisableAllButton", window)
-	SkinFrame(DisableAll)
-	DisableAll:SetSize(EnableAll:GetSize())
-	DisableAll:SetPoint("TOPRIGHT", header, "BOTTOMRIGHT", -5, -5)
-	DisableAll.text = DisableAll:CreateFontString(nil, "OVERLAY")
-	DisableAll.text:SetFont(unpack(font))
-	DisableAll.text:SetText("Disable All")
-	DisableAll.text:SetPoint("CENTER")
-	DisableAll:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	DisableAll:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	local DisableAll = CreateMenuButton(window, EnableAll:GetWidth(), EnableAll:GetHeight(), "DisableAll", "TOPRIGHT", window, "BOTTOMRIGHT", -5, -5)
 	DisableAll:SetScript("OnClick", function(self)
 		for i, addon in pairs(stAddonManager.AllAddons) do
-			if addon.name ~= addonName then
+			if addon.name ~= ADDON_NAME then
 				DisableAddOn(addon.name)
 				stAddonManager.Buttons[i]:SetBackdropColor(unpack(backdropcolor))
 				addon.enabled = false
@@ -211,17 +201,7 @@ local function LoadProfileWindow()
 		stAddonProfiles = {}
 	end

-	local SaveProfile = CreateFrame("Button", window:GetName().."_SaveProfileButton", window)
-	SkinFrame(SaveProfile)
-	SaveProfile:SetHeight(20)
-	SaveProfile:SetPoint("TOPLEFT", EnableAll, "BOTTOMLEFT", 0, -5)
-	SaveProfile:SetPoint("TOPRIGHT", DisableAll, "BOTTOMRIGHT", 0, -5)
-	SaveProfile.text = SaveProfile:CreateFontString(nil, "OVERLAY")
-	SaveProfile.text:SetFont(unpack(font))
-	SaveProfile.text:SetText("New Profile")
-	SaveProfile.text:SetPoint("CENTER")
-	SaveProfile:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	SaveProfile:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	local SaveProfile = CreateMenuButton(window, window:GetWidth()-10, 20, "New Profile", "TOPLEFT", EnableAll, "BOTTOMLEFT", 0, -5)
 	SaveProfile:SetScript("OnClick", function(self)
 		if not self.editbox then
 			local ebox = CreateFrame("EditBox", nil, self)
@@ -260,24 +240,6 @@ local function LoadProfileWindow()
 		self.profileButton.text:SetText(">")
 	end)

-	local function CreateMenuButton(parent, width, height, text, ...)
-		local button = CreateFrame("Button", nil, parent)
-		button:SetFrameLevel(parent:GetFrameLevel()+1)
-		button:SetSize(width, height)
-		SkinFrame(button)
-		if ... then button:SetPoint(...) end
-
-		button.text = button:CreateFontString(nil, "OVERLAY")
-		button.text:SetFont(unpack(font))
-		button.text:SetPoint("CENTER")
-		if text then button.text:SetText(text) end
-
-		button:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-		button:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
-
-		return button
-	end
-
 	local buttons = {}
 	function stAddonManager:UpdateProfileList()
 		local i = 1
@@ -312,22 +274,22 @@ local function LoadProfileWindow()

 		for profileName, addonList in sort(stAddonProfiles, function(a, b) return strlower(b) > strlower(a) end) do
 			if not buttons[i] then
-				local button = CreateMenuButton(scrollFrame.Anchor, scrollFrame:GetWidth()-4, 20, "<Profile Name>")
+				local button = CreateMenuButton(window, window:GetWidth()-10, 20, "<Profile Name>")
 				button.text:ClearAllPoints()
 				button.text:SetPoint("CENTER", button, "TOP", 0, -10)

 				local overlay = CreateFrame("Frame", nil, button)
 				overlay:EnableMouse(true) --just to stop the mouseover highlight when your mouse goes between the buttons
 				overlay:SetPoint("BOTTOM", button, "BOTTOM", 0, 3)
-				overlay:SetPoint("TOP", button, "TOP", 0, -20)
+				overlay:SetPoint("TOP", button, "TOP", 0, -18)
 				overlay:SetWidth(button:GetWidth()-10)
 				overlay:SetFrameLevel(button:GetFrameLevel()+1)
 				overlay:Hide()
-
-				overlay.set = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Set to..", "TOP", overlay, "TOP", 0, 0)
-				overlay.add = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Add to..", "TOP", overlay.set, "BOTTOM", 0, -3)
-				overlay.remove = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Remove from..", "TOP", overlay.add, "BOTTOM", 0, -3)
-				overlay.delete = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Delete Profile", "TOP", overlay.remove, "BOTTOM", 0, -3)
+
+				overlay.set = CreateMenuButton(overlay, overlay:GetWidth(), 20, "Set to..", "TOP", overlay, "TOP", 0, 0)
+				overlay.add = CreateMenuButton(overlay, overlay:GetWidth(), 20, "Add to..", "TOP", overlay.set, "BOTTOM", 0, 1)
+				overlay.remove = CreateMenuButton(overlay, overlay:GetWidth(), 20, "Remove from..", "TOP", overlay.add, "BOTTOM", 0, 1)
+				overlay.delete = CreateMenuButton(overlay, overlay:GetWidth(), 20, "Delete Profile", "TOP", overlay.remove, "BOTTOM", 0, 1)

 				button.overlay = overlay

@@ -344,7 +306,7 @@ local function LoadProfileWindow()
 						end

 						self.overlay:Show()
-						self:SetHeight(25+(18*4)+(3*3))
+						self:SetHeight(20*5)
 					end
 				end)

@@ -356,48 +318,72 @@ local function LoadProfileWindow()
 			local overlay = buttons[i].overlay
 			overlay.set:SetScript("OnClick", function(self)
 				DisableAllAddOns()
+				EnableAddOn(ADDON_NAME)
 				for i, name in pairs(addonList) do EnableAddOn(name) end
 				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
 				stAddonManager:UpdateList(stAddonManager.AllAddons)
+				for i=1, #buttons do
+					buttons[i].overlay:Hide()
+					buttons[i]:SetHeight(20)
+				end
 			end)
 			overlay.add:SetScript("OnClick", function(self)
 				for i, name in pairs(addonList) do EnableAddOn(name) end
 				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
 				stAddonManager:UpdateList(stAddonManager.AllAddons)
+				for i=1, #buttons do
+					buttons[i].overlay:Hide()
+					buttons[i]:SetHeight(20)
+				end
 			end)
 			overlay.remove:SetScript("OnClick", function(self)
-				for i, name in pairs(addonList) do if name ~= addonName then DisableAddOn(name) end end
+				for i, name in pairs(addonList) do if name ~= ADDON_NAME then DisableAddOn(name) end end
 				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
 				stAddonManager:UpdateList(stAddonManager.AllAddons)
+				for i=1, #buttons do
+					buttons[i].overlay:Hide()
+					buttons[i]:SetHeight(20)
+				end
 			end)
 			overlay.delete:SetScript("OnClick", function(self)
 				if IsShiftKeyDown() then
 					stAddonProfiles[profileName] = nil
 					stAddonManager:UpdateProfileList()
+					for i=1, #buttons do
+						buttons[i].overlay:Hide()
+						buttons[i]:SetHeight(20)
+					end
 				else
 					print("|cff00aaffst|rAddonManager: Are you sure you want to delete this profile? Hold down shift and click again if you are.")
 				end
+
 			end)

 			i = i + 1
 		end
-
+
 		local prevButton
+		local lastButton
 		for i,button in pairs(buttons) do
 			if i == 1 then
-				button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 4, -2)
+				button:SetPoint("TOP", SaveProfile, "BOTTOM", 0, -5)
 			else
-				button:SetPoint("TOP", prevButton, "BOTTOM", 0, -3)
+				button:SetPoint("TOP", prevButton, "BOTTOM", 0, 1)
 			end
 			prevButton = button
 		end
+
+		window.backdrop:ClearAllPoints()
+		window.backdrop:SetPoint("TOPLEFT", window, "TOPLEFT", 0, 0)
+		window.backdrop:SetPoint("TOPRIGHT", window, "TOPRIGHT", 0, 0)
+		window.backdrop:SetPoint("BOTTOM", prevButton, "BOTTOM", 0, -5)
 	end
 	stAddonManager:UpdateProfileList()

 	self.ProfileWindow = window
 end

-local function LoadWindow()
+function stAddonManager:LoadWindow()
 	if stAddonManager.Loaded then stAddonManager:Show(); return  end
 	local window = stAddonManager
 	local header = window.header
@@ -421,16 +407,10 @@ local function LoadWindow()
 	hTitle:SetText("|cff00aaffst|rAddonManager")
 	header.title = hTitle

-	local close = CreateFrame("Button", nil, header)
-	close:SetPoint("RIGHT", header, "RIGHT", 0, 0)
-	close:SetFrameLevel(header:GetFrameLevel()+2)
-	close:SetSize(20, 20)
-	close.text = close:CreateFontString(nil, "OVERLAY")
-	close.text:SetFont(unpack(font))
-	close.text:SetText("x")
-	close.text:SetPoint("CENTER", close, "CENTER", 0, 0)
-	close:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	close:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	local close = CreateMenuButton(header, 20, 20, "x", "RIGHT", header, "RIGHT", 0, 0)
+	close:SetBackdrop(nil)
+	close:HookScript("OnEnter", function(self) self:SetBackdrop(nil) end)
+	close:HookScript("OnLeave", function(self) self:SetBackdrop(nil) end)
 	close:SetScript("OnClick", function() window:Hide() end)
 	header.close = close

@@ -463,13 +443,6 @@ local function LoadWindow()

 	stAddonManager.Buttons = {}

-	-- local lockedAddons = {}
-	-- if not stLockedAddons then
-		-- stLockedAddons = {}
-	-- else
-		-- lockedAddons = {}
-	-- end
-
 	--Create initial list
 	for i, addon in pairs(stAddonManager.AllAddons) do
 		local button = CreateFrame("Frame", nil, scrollFrame.Anchor)
@@ -477,13 +450,13 @@ local function LoadWindow()
 		button:SetSize(16, 16)
 		SkinFrame(button)
 		if addon.enabled then
-		button:SetBackdropColor(0/255, 170/255, 255/255)
+			button:SetBackdropColor(0/255, 170/255, 255/255)
 		end

 		if i == 1 then
-		button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 5, -5)
+			button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 5, -5)
 		else
-		button:SetPoint("TOP", stAddonManager.Buttons[i-1], "BOTTOM", 0, -5)
+			button:SetPoint("TOP", stAddonManager.Buttons[i-1], "BOTTOM", 0, -3)
 		end
 		button.text = button:CreateFontString(nil, "OVERLAY")
 		button.text:SetFont(unpack(font))
@@ -493,8 +466,18 @@ local function LoadWindow()
 		button.text:SetText(addon.title)

 		button:SetScript("OnEnter", function(self)
-		--tooltip stuff
+			GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", -3, self:GetHeight())
+			GameTooltip:ClearLines()
+
+			if addon.version then GameTooltip:AddDoubleLine(addon.title, addon.version)
+			else GameTooltip:AddLine(addon.title) end
+			if addon.notes then	GameTooltip:AddLine(addon.notes, nil, nil, nil, true) end
+			if addon.dependencies then GameTooltip:AddLine("Dependencies: "..unpack(addon.dependencies), 1, .5, 0, true) end
+			if addon.optionaldependencies then GameTooltip:AddLine("Optional Dependencies: "..unpack(addon.optionaldependencies), 1, .5, 0, true) end
+
+			GameTooltip:Show()
 		end)
+		button:SetScript("OnLeave", function(self) GameTooltip:Hide() end)

 		button:SetScript("OnMouseDown", function(self)
 			if addon.enabled then
@@ -511,13 +494,12 @@ local function LoadWindow()
 		stAddonManager.Buttons[i] = button
 	end

-	 function stAddonManager:UpdateList(AddonsTable)
+	function stAddonManager:UpdateList(AddonsTable)
 		--Start off by hiding all of the buttons
 		for _, b in pairs(stAddonManager.Buttons) do b:Hide() end
-
-		local bIndex = 1
-		for i, addon in pairs(AddonsTable) do
-			local button = stAddonManager.Buttons[bIndex]
+		local i = 1
+		for _, addon in pairs(AddonsTable) do
+			local button = stAddonManager.Buttons[i]
 			button:Show()
 			if addon.enabled then
 				button:SetBackdropColor(0/255, 170/255, 255/255)
@@ -538,7 +520,7 @@ local function LoadWindow()
 			end)

 			button.text:SetText(addon.title)
-			bIndex = bIndex+1
+			i = i+1
 		end
 	end

@@ -577,18 +559,9 @@ local function LoadWindow()
 	searchBar.clear = sbClear
 	stAddonManager.searchBar = searchBar

-	local profileButton = CreateFrame("Button", window:GetName().."_ProfileWindowButton", window)
-	profileButton:SetPoint("TOPRIGHT", header, "BOTTOMRIGHT", -10, -5)
-	profileButton:SetSize(20, 20)
-	SkinFrame(profileButton)
-	profileButton.text = profileButton:CreateFontString(nil, "OVERLAY")
-	profileButton.text:SetFont(unpack(font))
-	profileButton.text:SetText(">")
-	profileButton.text:SetPoint("CENTER", profileButton, "CENTER", 0, 0)
-	profileButton:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	profileButton:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	local profileButton = CreateMenuButton(window, 20, 20, ">", "TOPRIGHT", header, "BOTTOMRIGHT", -10, -5)
 	profileButton:SetScript("OnClick", function(self)
-		LoadProfileWindow()
+		stAddonManager:LoadProfileWindow()
 		if stAddonManager.ProfileWindow:IsShown() then
 			self.text:SetText("<")
 		else
@@ -597,28 +570,19 @@ local function LoadWindow()
 	end)
 	stAddonManager.profileButton = profileButton

-	local reloadButton = CreateFrame("Button", window:GetName().."_ReloadUIButton", window)
-	reloadButton:SetPoint("LEFT", searchBar, "RIGHT", 5, 0)
+	local reloadButton = CreateMenuButton(window, 1, searchBar:GetHeight(), "Reload UI", "LEFT", searchBar, "RIGHT", 5, 0)
 	reloadButton:SetPoint("RIGHT", profileButton, "LEFT", -5, 0)
-	reloadButton:SetHeight(searchBar:GetHeight())
-	reloadButton.text = reloadButton:CreateFontString(nil, "OVERLAY")
-	reloadButton.text:SetPoint("CENTER")
-	reloadButton.text:SetFont(unpack(font))
-	reloadButton.text:SetText("ReloadUI")
-	reloadButton:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-	reloadButton:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
 	reloadButton:SetScript("OnClick", function(self)
 		if InCombatLockdown() then return end
 		ReloadUI()
 	end)
-	SkinFrame(reloadButton)
 	stAddonManager.reloadButton = reloadButton

 	stAddonManager.Loaded = true
 end

 SLASH_STADDONMANAGER1, SLASH_STADDONMANAGER2, SLASH_STADDONMANAGER3 = "/staddonmanager", "/stam", "/staddon"
-SlashCmdList["STADDONMANAGER"] = LoadWindow
+SlashCmdList["STADDONMANAGER"] = function() stAddonManager:LoadWindow() end

 local function CheckForAddon(event, addon, addonName)
 	return ((event == "PLAYER_ENTERING_WORLD" and IsAddOnLoaded(addonName)) or (event == "ADDON_LOADED" and addon == addonName))
@@ -632,7 +596,7 @@ gmbAddOns:SetPoint("TOP", GameMenuButtonMacros, "BOTTOM", 0, -1)
 gmbAddOns:SetText("|cff00aaffst|rAddonManager")
 gmbAddOns:SetScript("OnClick", function()
 	HideUIPanel(GameMenuFrame);
-	LoadWindow()
+	stAddonManager:LoadWindow()
 end)

 gmbAddOns:RegisterEvent("ADDON_LOADED")