Quantcast

preparing for 1.2

Steven Jackson [05-01-15 - 21:14]
preparing for 1.2
Filename
SVUI_!Core/system/dock.lua
SVUI_QuestTracker/components/quests.lua
diff --git a/SVUI_!Core/system/dock.lua b/SVUI_!Core/system/dock.lua
index 981d1f4..8c5c68e 100644
--- a/SVUI_!Core/system/dock.lua
+++ b/SVUI_!Core/system/dock.lua
@@ -79,9 +79,9 @@ local DOCK_LOCATIONS = {
 	["TopLeft"] = {1, "LEFT", false, "ANCHOR_BOTTOMLEFT"},
 	["TopRight"] = {-1, "RIGHT", false, "ANCHOR_BOTTOMLEFT"},
 };
-DOCK_DROPDOWN_OPTIONS["BottomLeft"] = { text = "To BottomLeft", func = function(button) MOD.BottomLeft.Bar:Add(button); end };
-DOCK_DROPDOWN_OPTIONS["BottomRight"] = { text = "To BottomRight", func = function(button) MOD.BottomRight.Bar:Add(button); end };
-DOCK_DROPDOWN_OPTIONS["TopLeft"] = { text = "To TopLeft", func = function(button) MOD.TopLeft.Bar:Add(button); end };
+DOCK_DROPDOWN_OPTIONS["BottomLeft"] = { text = "To BottomLeft", func = function(button) button:MoveTo("BottomLeft"); end };
+DOCK_DROPDOWN_OPTIONS["BottomRight"] = { text = "To BottomRight", func = function(button) button:MoveTo("BottomRight"); end };
+DOCK_DROPDOWN_OPTIONS["TopLeft"] = { text = "To TopLeft", func = function(button) button:MoveTo("TopLeft"); end };
 --DOCK_DROPDOWN_OPTIONS["TopRight"] = { text = "To TopRight", func = function(button) MOD.TopRight.Bar:Add(button) end };
 --[[
 ##########################################################
@@ -418,45 +418,51 @@ local function ActivateDockletButton(button)
 	end
 end

-local function ShowDockletWindow(holder, window)
-	if((not holder) or (not window)) then return end
-	holder.FrameLink = window;
-	holder:Show();
-	holder:FadeIn();
-	if(not InCombatLockdown()) then
-		window:SetFrameLevel(10)
-		window:Show()
+local function ShowDockletWindow(parent, window, button)
+	if((not parent) or (not window)) then return end
+	parent.Window.FrameLink = window;
+	parent.Window:Show();
+	parent.Window:FadeIn();
+	parent.backdrop:Show();
+	if(not window:IsShown()) then
+		if(not InCombatLockdown()) then
+			window:SetFrameLevel(10)
+			window:Show()
+		end
+		if(button and button.PostShowCallback) then
+			button:PostShowCallback()
+		end
 	end
 	window:FadeIn()
 end

-local function HideDockletWindow(window)
+local function HideDockletWindow(window, button)
 	if(not window) then return end
 	if(not InCombatLockdown()) then
 		window:SetFrameLevel(0)
 		window:Hide()
-	else
-		window:FadeOut(0.2, 1, 0, true)
 	end
-end
-
-local DockBar_ResetDocklets = function(self)
-	self.Parent.backdrop:Hide();
-	for name,window in pairs(self.Data.Windows) do
-		HideDockletWindow(window)
+	window:FadeOut(0.1, 1, 0, true)
+	if(button and button.PostHideCallback) then
+		button:PostHideCallback()
 	end
 end

-local DockBar_RefreshDocklets = function(self)
+local DockBar_ResetDocklets = function(self, button)
 	local location = self.Data.Location;
-	local ownerFrame = ""
-	local defaultButton = MOD.private.DefaultDocklets[location];
-	if(_G[defaultButton]) then
-		ownerFrame = _G[defaultButton]:GetAttribute("ownerFrame")
-	end
-	for name,window in pairs(self.Data.Windows) do
-		if(name ~= ownerFrame) then
-			HideDockletWindow(window)
+	local buttonList = self.Data.Buttons;
+	local currentButton = "";
+	if(button and button.GetName) then
+		currentButton = button:GetName()
+	end
+	self.Parent.backdrop:Hide();
+	for nextName,nextButton in pairs(buttonList) do
+		if(nextName ~= currentButton) then
+			local ownerFrame = nextButton:GetAttribute("ownerFrame");
+			local window = _G[ownerFrame]
+			if(window) then
+				HideDockletWindow(window, nextButton)
+			end
 		end
 	end
 end
@@ -483,8 +489,8 @@ local DockBar_SetDefault = function(self, button)
 	end

 	if(button and defaultFrame) then
-		DockBar_ResetDocklets(self);
-		ShowDockletWindow(self.Parent.Window, defaultFrame);
+		DockBar_ResetDocklets(self, button);
+		ShowDockletWindow(self.Parent, defaultFrame, button);
 		ActivateDockletButton(button);
 	end

@@ -498,8 +504,8 @@ local DockBar_NextDefault = function(self)
 		local ownerFrame = nextButton:GetAttribute("ownerFrame");
 		if(_G[ownerFrame]) then
 			MOD.private.DefaultDocklets[location] = nextName;
-			DockBar_ResetDocklets(self)
-			ShowDockletWindow(self.Parent.Window, _G[ownerFrame]);
+			DockBar_ResetDocklets(self, nextButton)
+			ShowDockletWindow(self.Parent, _G[ownerFrame], nextButton);
 			ActivateDockletButton(nextButton);
 			break;
 		end
@@ -742,13 +748,20 @@ local DockButton_OnClick = function(self, button)
 	MOD.ButtonSound()
 	if(button and button == "RightButton") then
 		self.Parent.Parent.backdrop:Hide()
-		self:Deactivate()
+		self:SetAttribute("isActive", false)
+		self:SetPanelColor("default")
+		if(self.Icon) then
+			self.Icon:SetGradient(unpack(SV.media.gradient.icon));
+		end
+		local ownerFrame = self:GetAttribute("ownerFrame")
+		local window = _G[ownerFrame]
+		HideDockletWindow(window, self)
 	else
 		if(IsAltKeyDown() and (not InCombatLockdown()) and self:GetAttribute("hasDropDown") and self.GetMenuList) then
 			local list = self:GetMenuList();
 			SV.Dropdown:Open(self, list, "Dock Options");
 		else
-			local thisIsShowing = DockBar_SetDefault(self, button)
+			local thisIsShowing = DockBar_SetDefault(self.Parent, self)
 			if(self.PostClickFunction and thisIsShowing) then
 				self:PostClickFunction(button)
 			end
@@ -811,6 +824,15 @@ local DockButton_SetDocked = function(self, attach)
 		self.Parent:Remove(self)
 	end
 end
+
+local DockButton_MoveTo = function(self, location)
+	if(not MOD[location]) then return end
+	MOD[location].Bar:Add(self);
+
+	if(self.PostMoveCallback) then
+		self:PostMoveCallback()
+	end
+end
 --[[
 ##########################################################
 REMAINING DOCKBAR FUNCTIONS
@@ -848,6 +870,7 @@ local DockBar_CreateButton = function(self, displayName, texture, onclick, globa

 	button.Parent 			= self;
   button.OrderIndex 	= 0;
+	button.MoveTo				= DockButton_MoveTo
 	button.GetMenuList 	= DockButton_GetMenuList
 	button.SetDocked 		= DockButton_SetDocked

@@ -889,7 +912,7 @@ MOD.BottomCenter = _G["SVUI_DockBottomCenter"];
 local DockBar_OnEvent = function(self, event)
     if(event == 'PLAYER_REGEN_ENABLED') then
         self:UnregisterEvent("PLAYER_REGEN_ENABLED")
-				DockBar_ResetDocklets(self)
+				DockBar_SetDefault(self)
     end
 end

@@ -1297,7 +1320,7 @@ function MOD:Load()

     dock.Window:ClearAllPoints()
     dock.Window:SetSize(width, height)
-    dock.Window:SetPoint(anchor, dock.Alert, reverse, 0, (4 * vertMod))
+    dock.Window:SetPoint(anchor, dock.Alert, reverse, 0, 4)
 		dock.backdrop = self.SetThemeDockStyle(dock.Window, isBottom)
 		dock.backdrop:Hide()
 		dock.Alert.backdrop = self.SetThemeDockStyle(dock.Alert, isBottom)
@@ -1328,10 +1351,10 @@ function MOD:Load()
 	self.BottomCenter:SetSize(centerWidth, dockHeight)
 	self.BottomCenter:SetPoint("BOTTOM", SV.Screen, "BOTTOM", 0, 0)

-	DockBar_ResetDocklets(self.BottomLeft.Bar)
-	DockBar_ResetDocklets(self.BottomRight.Bar)
-	DockBar_ResetDocklets(self.TopLeft.Bar)
-	DockBar_ResetDocklets(self.TopRight.Bar)
+	DockBar_SetDefault(self.BottomLeft.Bar)
+	DockBar_SetDefault(self.BottomRight.Bar)
+	DockBar_SetDefault(self.TopLeft.Bar)
+	DockBar_SetDefault(self.TopRight.Bar)

 	self:LoadProfessionTools();
 	self:LoadAllMiscTools();
diff --git a/SVUI_QuestTracker/components/quests.lua b/SVUI_QuestTracker/components/quests.lua
index b651cac..713476d 100644
--- a/SVUI_QuestTracker/components/quests.lua
+++ b/SVUI_QuestTracker/components/quests.lua
@@ -350,25 +350,44 @@ function ItemBar:Update()
 	local maxIndex = #self.Buttons;
 	local firstButton = self.Buttons[1];
 	local itemLink = firstButton.itemLink;
+
 	if(itemLink) then
 		ACTIVE_ITEMS[itemLink] = 1
 	end

+	local dockletLocation = MOD.Docklet.Parent.Bar.Data.Location;
+	local isHorizontal = (SV.db.QuestTracker.itemBarDirection == 'HORIZONTAL');
+	local anchor1 = isHorizontal and "LEFT" or "TOP";
+	local anchor2 = isHorizontal and "RIGHT" or "BOTTOM";
+	local xOff = isHorizontal and 2 or 0;
+	local yOff = isHorizontal and 0 or -2;
+
+	local itemScale = firstButton:GetHeight() + 2
+	local dockWidth,dockHeight = MOD.Docklet:GetSize()
+	local maxLength = isHorizontal and (dockWidth / itemScale) or (dockHeight / itemScale);
+
 	firstButton:ClearAllPoints();

-	local a1, a2, x, y = "BOTTOM", "TOP", 0, 2;
-	if(SV.db.QuestTracker.itemBarDirection == 'HORIZONTAL') then
-		a1, a2, x, y = "LEFT", "RIGHT", 2, 0;
-		firstButton:SetPoint("LEFT", self, "LEFT", 2, 0);
+	if(dockletLocation:find('Left')) then
+		anchor1 = isHorizontal and "RIGHT" or "TOP";
+		anchor2 = isHorizontal and "LEFT" or "BOTTOM";
+		xOff = isHorizontal and -2 or 0;
+	end
+
+	if(dockletLocation:find('Top') and (not isHorizontal)) then
+		anchor1 = "BOTTOM";
+		anchor2 = "TOP";
+		yOff = 2;
+	end
+
+	if(isHorizontal) then
+		firstButton:SetPoint(anchor1, self, anchor1, 0, 0);
 		if(SV.Tooltip and (not self.tipanchorchecked) and SV.Tooltip.Holder and SV.Tooltip.Holder.Grip and (not SV.Tooltip.Holder.Grip:HasMoved())) then
 			SV.Tooltip.DefaultPadding = 56
 			self.tipanchorchecked = true
 		end
-		-- if(SV.Tooltip and SV.Tooltip.Holder and SV.Tooltip.Holder.Grip) then
-		-- 	print(SV.Tooltip.Holder.Grip:GetPoint())
-		-- end
 	else
-		firstButton:SetPoint("TOP", self, "TOP", 0, -2);
+		firstButton:SetPoint(anchor2, self, anchor2, 0, 0);
 	end

 	local lastButton, totalShown, button = firstButton, 1;
@@ -380,16 +399,16 @@ function ItemBar:Update()
 		button:ClearAllPoints();
 		if(button:IsShown()) then
 			totalShown = totalShown + 1;
-			if(totalShown > 5) then
-				if(totalShown == 6) then
-					button:SetPoint(a1, firstButton, a2, x, y)
+			if(totalShown > maxLength) then
+				if(totalShown == (maxLength + 1)) then
+					button:SetPoint(anchor1, firstButton, anchor2, xOff, yOff)
 				else
-					button:SetPoint(a1, lastButton, a2, x, y)
+					button:SetPoint(anchor1, lastButton, anchor2, xOff, yOff)
 				end
 				button.___overflow = true;
 				button:FadeOut();
 			else
-				button:SetPoint(a2, lastButton, a1, x, -y)
+				button:SetPoint(anchor2, lastButton, anchor1, xOff, -yOff)
 				button.___overflow = false;
 				button:FadeIn();
 			end
@@ -1111,12 +1130,58 @@ local function UpdateQuestLocals(...)
 	QUEST_ROW_HEIGHT = ROW_HEIGHT + 2;
 end

-local _hook_QuestDock_OnShow = function(self)
+local function ReAnchorItemBar()
+	local dockletLocation = MOD.Docklet.Parent.Bar.Data.Location;
+	local isHorizontal = (SV.db.QuestTracker.itemBarDirection == 'HORIZONTAL');
+	local anchor1 = isHorizontal and "LEFT" or "RIGHT";
+	local anchor2 = "LEFT";
+	local xOff = isHorizontal and 0 or -4;
+	local yOff = isHorizontal and 4 or 0;
+
+	if(dockletLocation:find('Left')) then
+		anchor1 = isHorizontal and "RIGHT" or "LEFT";
+		anchor2 = "RIGHT";
+		xOff = isHorizontal and 0 or 4;
+	end
+
+	local prefix1 = isHorizontal and "BOTTOM" or "TOP";
+	local prefix2 = "TOP";
+
+	if(dockletLocation:find('Top')) then
+		prefix1 = isHorizontal and "TOP" or "BOTTOM";
+		prefix2 = "BOTTOM";
+		yOff = -4;
+	end
+
+	anchor1 = prefix1 .. anchor1;
+	anchor2 = prefix2 .. anchor2;
+
+	ItemBar:ClearAllPoints();
+	ItemBar:SetParent(SV.Screen);
+	ItemBar:SetPoint(anchor1, MOD.Docklet.Parent, anchor2, xOff, yOff);
+	if(isHorizontal) then
+		ItemBar:SetWidth(MOD.Docklet.Parent:GetWidth());
+		ItemBar:SetHeight(32);
+	else
+		ItemBar:SetWidth(32);
+		ItemBar:SetHeight(MOD.Docklet.Parent:GetHeight());
+	end
+end
+
+local function PostMoveCallback()
+	if(ItemBar.Grip and (not ItemBar.Grip:HasMoved())) then
+		ReAnchorItemBar()
+	end
+	MOD.QuestItemTimer = SV.Timers:ExecuteTimer(ShowItemBarButtons, 1.2);
+	ShowItemBarButtons();
+end
+
+local function PostShowCallback()
 	MOD.QuestItemTimer = SV.Timers:ExecuteTimer(ShowItemBarButtons, 1.2);
 	ShowItemBarButtons();
 end

-local _hook_QuestDock_OnHide = function(self)
+local function PostHideCallback()
 	if(MOD.QuestItemTimer) then
 		SV.Timers:RemoveTimer(MOD.QuestItemTimer)
 		MOD.QuestItemTimer = nil
@@ -1125,26 +1190,16 @@ local _hook_QuestDock_OnHide = function(self)
 end

 function MOD:InitializeQuests()
-	ItemBar:ClearAllPoints();
-	ItemBar:SetParent(SV.Screen);
-	if(SV.db.QuestTracker.itemBarDirection == 'HORIZONTAL') then
-		ItemBar:SetPoint("BOTTOMLEFT", SV.Dock.BottomRight, "TOPLEFT", 0, 4);
-		ItemBar:SetWidth(SV.Dock.BottomRight:GetWidth());
-		ItemBar:SetHeight(32);
-	else
-		ItemBar:SetPoint("TOPRIGHT", SV.Dock.BottomRight, "TOPLEFT", -4, 0);
-		ItemBar:SetWidth(32);
-		ItemBar:SetHeight(SV.Dock.BottomRight:GetHeight());
-	end
-
+	ReAnchorItemBar()
 	SV:NewAnchor(ItemBar, L["Quest Items"]);

 	for i = 1, 5 do
 		ItemBar.Buttons[i] = CreateQuestItemButton(i)
 	end

-	self.Docklet:FadeCallback(_hook_QuestDock_OnShow, false, true)
-	self.Docklet:FadeCallback(_hook_QuestDock_OnHide, true)
+	self.Docklet.DockButton.PostMoveCallback = PostMoveCallback;
+	self.Docklet.DockButton.PostShowCallback = PostShowCallback;
+	self.Docklet.DockButton.PostHideCallback = PostHideCallback;

 	local scrollChild = self.Docklet.ScrollFrame.ScrollChild;
 	local quests = CreateFrame("Frame", nil, scrollChild)