Quantcast

optimizing codebase (stage 1)

failcoder [08-24-15 - 22:27]
optimizing codebase (stage 1)
Filename
SVUI_Inventory/SVUI_Inventory.lua
diff --git a/SVUI_Inventory/SVUI_Inventory.lua b/SVUI_Inventory/SVUI_Inventory.lua
index cadeb35..71ca6e0 100644
--- a/SVUI_Inventory/SVUI_Inventory.lua
+++ b/SVUI_Inventory/SVUI_Inventory.lua
@@ -59,6 +59,7 @@ local CreateFrame = _G.CreateFrame;
 local hooksecurefunc = _G.hooksecurefunc;
 local numBagFrame = NUM_BAG_FRAMES + 1;
 local MULTI_BAG_LAYOUT = false;
+local MULTI_BAG_HEIGHT_OFFSET = 0;
 local LOOT_CACHE, GEAR_CACHE, GEARSET_LISTING = {}, {}, {};
 local internalTimer;
 local RefProfessionColors = {
@@ -314,7 +315,6 @@ local ContainerFrame_UpdateLayout = function(self)
 	local containerName = self:GetName()
 	local buttonSpacing = 8;
 	local containerWidth, numContainerColumns, buttonSize
-
 	local precount = 0;
 	for i, bagID in ipairs(self.BagIDs) do
 		if((not MULTI_BAG_LAYOUT) or (isBank or (bagID > 0))) then
@@ -347,13 +347,19 @@ local ContainerFrame_UpdateLayout = function(self)
 	end

 	local numContainerRows = ceil(precount / numContainerColumns)
-	local containerHeight = (((buttonSize + buttonSpacing) * numContainerRows) - buttonSpacing) + self.topOffset + self.bottomOffset
+	local containerHeight = (((buttonSize + buttonSpacing) * numContainerRows) - buttonSpacing) + self.topOffset + self.bottomOffset;
 	local holderWidth = ((buttonSize + buttonSpacing) * numContainerColumns) - buttonSpacing;
 	local bottomPadding = (containerWidth - holderWidth) * 0.5;
 	local lastButton, lastRowButton, globalName;
 	local numContainerSlots, fullContainerSlots = GetNumBankSlots();
 	local totalSlots = 0;

+	if(MULTI_BAG_LAYOUT) then
+		local bpCount = GetContainerNumSlots(0);
+		local bpRows = ceil(bpCount / numContainerColumns);
+		containerHeight = (((buttonSize + buttonSpacing) * bpRows) - buttonSpacing) + self.topOffset + self.bottomOffset;
+	end
+
 	self.ButtonSize = buttonSize;
 	self.holderFrame:SetWidth(holderWidth);

@@ -443,12 +449,19 @@ local ContainerFrame_UpdateLayout = function(self)
 				self.Bags[bagID].SlotUpdate = SlotUpdate;
 				self.Bags[bagID].RefreshSlots = ContainerFrame_RefreshSlots;
 			end
+
 			local bagAnchor = self.holderFrame;
+			local numCols = numContainerColumns;
+			local rowCount = 0;
+
 			if(self.Bags[bagID].holderFrame) then
 				bagAnchor = self.Bags[bagID].holderFrame;
 				lastButton = false;
 				lastRowButton = false;
 				totalSlots = 0;
+				numCols = ceil(numSlots * 0.2);
+				local multiSize = (((buttonSize + buttonSpacing) * numCols) - buttonSpacing) + 16
+				self.Bags[bagID]:SetSize(multiSize,multiSize)
 			end

 			self.Bags[bagID].numSlots = numSlots;
@@ -542,21 +555,29 @@ local ContainerFrame_UpdateLayout = function(self)
 				end

 				if lastButton then
-					if((totalSlots - 1) % numContainerColumns == 0) then
+					if((totalSlots - 1) % numCols == 0) then
 						self.Bags[bagID][slotID]:SetPoint("TOP", lastRowButton, "BOTTOM", 0, -buttonSpacing);
 						lastRowButton = self.Bags[bagID][slotID];
+						rowCount = rowCount + 1;
 					else
 						self.Bags[bagID][slotID]:SetPoint("LEFT", lastButton, "RIGHT", buttonSpacing, 0);
 					end
 				else
-					self.Bags[bagID][slotID]:SetPoint("TOPLEFT", self.holderFrame, "TOPLEFT");
+					self.Bags[bagID][slotID]:SetPoint("TOPLEFT", bagAnchor, "TOPLEFT");
 					lastRowButton = self.Bags[bagID][slotID];
+					rowCount = rowCount + 1;
 				end

 				lastButton = self.Bags[bagID][slotID];

 				self.Bags[bagID]:SlotUpdate(slotID);
 			end
+
+			if(self.Bags[bagID].holderFrame) then
+				local multiWidth = (((buttonSize + buttonSpacing) * numCols) - buttonSpacing) + 16;
+				local multiHeight = (((buttonSize + buttonSpacing) * rowCount) - buttonSpacing) + 50;
+				self.Bags[bagID]:SetSize(multiWidth,multiHeight)
+			end
 		else
 			if(self.Bags[bagID]) then
 				self.Bags[bagID].numSlots = numSlots;
@@ -742,10 +763,23 @@ end
 function MOD:ModifyBags()
 	local docked = SV.db.Inventory.alignToChat
 	local anchor, x, y
+
+	MULTI_BAG_HEIGHT_OFFSET = 0;
+
+	if(MULTI_BAG_LAYOUT) then
+		MULTI_BAG_HEIGHT_OFFSET = self.MasterFrame:GetHeight()
+		for bagID,bag in pairs(self.MasterFrame.Bags) do
+			if(bagID == 1 or bagID == 3) then
+				local bagHeight = bag:GetHeight()
+				MULTI_BAG_HEIGHT_OFFSET = MULTI_BAG_HEIGHT_OFFSET + (bagHeight + 4);
+			end
+		end
+	end
+
 	if(docked) then
 		if self.MasterFrame then
 			self.MasterFrame:ClearAllPoints()
-			self.MasterFrame:SetPoint("BOTTOMRIGHT", SV.Dock.BottomRight, "BOTTOMRIGHT", 0, 0)
+			self.MasterFrame:SetPoint("TOPRIGHT", SV.Dock.BottomRight, "BOTTOMRIGHT", 0, MULTI_BAG_HEIGHT_OFFSET)
 		end
 		if self.BankFrame then
 			self.BankFrame:ClearAllPoints()
@@ -755,7 +789,7 @@ function MOD:ModifyBags()
 		if self.MasterFrame then
 			local anchor, x, y = SV.db.Inventory.bags.point, SV.db.Inventory.bags.xOffset, SV.db.Inventory.bags.yOffset
 			self.MasterFrame:ClearAllPoints()
-			self.MasterFrame:SetPoint(anchor, SV.Screen, anchor, x, y)
+			self.MasterFrame:SetPoint(anchor, SV.Screen, anchor, x, y + MULTI_BAG_HEIGHT_OFFSET)
 		end
 		if self.BankFrame then
 			local anchor, x, y = SV.db.Inventory.bank.point, SV.db.Inventory.bank.xOffset, SV.db.Inventory.bank.yOffset
@@ -1066,6 +1100,11 @@ do
 	local Container_OnShow = function(self)
 		NEXT_ACTION_ALLOWED = true
 		MOD:PositionBagBar()
+		if(MULTI_BAG_LAYOUT) then
+			for bagID, bagFrame in ipairs(MOD.MasterFrame.Bags) do
+				bagFrame:Show()
+			end
+		end
 	end

 	local Container_OnHide = function(self)
@@ -1262,9 +1301,19 @@ do
 			for i, bagID in ipairs(frame.BagIDs) do
 				if(bagID > 0) then
 					local singleBagFrameName = "SVUI_ContainerFrameBag" .. bagID;
-					local singleBagFrame = CreateFrame("Button", singleBagFrameName, SV.Screen);
+					local singleBagFrame = CreateFrame("Button", singleBagFrameName, frame);
 					tinsert(UISpecialFrames, singleBagFrameName);

+					if(bagID == 1) then
+						singleBagFrame:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", 0, -4)
+					elseif(bagID == 2) then
+						singleBagFrame:SetPoint("TOPRIGHT", _G['SVUI_ContainerFrameBag1'], "TOPLEFT", -4, 0)
+					elseif(bagID == 3) then
+						singleBagFrame:SetPoint("TOPRIGHT", _G['SVUI_ContainerFrameBag1'], "BOTTOMRIGHT", 0, -4)
+					else
+						singleBagFrame:SetPoint("TOPRIGHT", _G['SVUI_ContainerFrameBag3'], "TOPLEFT", -4, 0)
+					end
+
 					singleBagFrame:SetStyle("Frame", "Pattern")
 					singleBagFrame:SetFrameStrata("HIGH")
 					singleBagFrame:SetMovable(true)
@@ -1278,12 +1327,12 @@ do
 					singleBagFrame.closeButton:SetPoint("TOPRIGHT", -4, -4)
 					SV.API:Set("CloseButton", singleBagFrame.closeButton);
 					singleBagFrame.closeButton:SetScript("PostClick", function()
-						if(not InCombatLockdown()) then CloseBag(0) end
+						if(not InCombatLockdown()) then CloseBag(bagID) end
 					end)

 					singleBagFrame.holderFrame = CreateFrame("Frame", nil, singleBagFrame)
-					singleBagFrame.holderFrame:SetPoint("TOP", singleBagFrame, "TOP", 0, -8)
-					singleBagFrame.holderFrame:SetPoint("BOTTOM", singleBagFrame, "BOTTOM", 0, 8)
+					singleBagFrame.holderFrame:SetPoint("TOPLEFT", singleBagFrame, "TOPLEFT", 8, -42)
+					singleBagFrame.holderFrame:SetPoint("BOTTOMRIGHT", singleBagFrame, "BOTTOMRIGHT", -8, 8)

 					singleBagFrame:SetScript("OnDragStart", Container_OnDragStart)
 					singleBagFrame:SetScript("OnDragStop", Container_OnDragStop)
@@ -1828,8 +1877,8 @@ function MOD:Load()

 	self:ModifyBagBar()
 	self:CreateMasterFrame()
-	self:ModifyBags()
 	self.MasterFrame:UpdateLayout()
+	self:ModifyBags()

 	self:InitializeMenus()