diff Frames.lua @ 106:d3fbb5676a5e

Added tooltips to the item refill window headers. Now color coding the availibility of items at the item refill window. Added a hide help text option (which is off by default). Renamed all premade groups to a new naming pattern; ?Profession - Category - Detail?, e.g. ?Inscription - Glyphs by class - Death Knight?. To continue getting notified about updates to a selected premade group, you must re-add them. Repositioned elements of the item refill frame to fit better. No longer using colorsargs to remember the index of a queued move, but instead providing a reference to the move itself in the new ?rowData? property of each row. Added tooltips to the headers of the sort table. Merged missing and available columns together (showing available / missing) and sorting on available now sorts on percentage of how many of the missing items are available. Moving and available columns are now aligned to the right. Added an ?extra? config group which contains the additional (but completely optional) settings. Moved color codes adjustments, forget character, auto refill skip confirm and hide help info options to this group.
author Zerotorescue
date Wed, 12 Jan 2011 19:58:39 +0100
parents 8502f02bf543
children 67bd5057ecb7
line wrap: on
line diff
--- a/Frames.lua	Wed Jan 12 14:15:50 2011 +0100
+++ b/Frames.lua	Wed Jan 12 19:58:39 2011 +0100
@@ -4,6 +4,8 @@
 	-- If this function is called from a widget, self is the widget and self.frame the actual frame
 	local this = self.frame or self;
 	
+	if not this.tooltipTitle then return; end
+	
 	GameTooltip:SetOwner(this, "ANCHOR_NONE");
 	if this.tooltipLocation and this.tooltipLocation == "BOTTOM" then
 		GameTooltip:SetPoint("TOP", this, "BOTTOM");
@@ -120,7 +122,7 @@
 	
 	-- Description
 		local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
-		lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -25);
+		lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27);
 		lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right
 		lblDescription:SetJustifyH("LEFT");
 		lblDescription:SetJustifyV("TOP");
@@ -138,8 +140,8 @@
 			btnMove:SetScript("OnClick", onAccept);
 			btnMove:SetScript("OnEnter", ShowTooltip);
 			btnMove:SetScript("OnLeave", HideTooltip);
-			btnMove.tooltipTitle = "Move Items";
-			btnMove.tooltip = "Start moving these items from the bank.";
+			btnMove.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items");
+			btnMove.tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank.");
 			
 			frame.btnMove = btnMove;
 			
@@ -152,29 +154,29 @@
 			btnCancel:SetScript("OnClick", onCancel);
 			btnCancel:SetScript("OnEnter", ShowTooltip);
 			btnCancel:SetScript("OnLeave", HideTooltip);
-			btnCancel.tooltipTitle = "Cancel";
-			btnCancel.tooltip = "Do not move anything and close the window.";
+			btnCancel.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel");
+			btnCancel.tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window.");
 			
 			frame.btnCancel = btnCancel;
 		
 	-- Because the scrolling table code-behind will change this element's height, we can't rely on that. Make a dummy frame which we can measure
 		local frmMeasureDummy = CreateFrame("Frame", nil, frame);
-		frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20);
-		frmMeasureDummy:SetPoint("LEFT", frame.lblDescription, "LEFT", 15, 0);
+		frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
+		frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0);
 		frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
 		
 		frame.frmMeasureDummy = frmMeasureDummy;
 		
 	-- Scrolling table with a list of items to be moved
-		local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 20 ); -- adjust width by the scrollbar size
+		local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
 		local headers = {
 			{
 				["name"] = "Item",
-				["width"] = (scrollTableWidth * .5),
+				["width"] = (scrollTableWidth * .60),
 				["defaultsort"] = "asc",
 				["comparesort"] = function(this, aRow, bRow, column)
-					local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).colorargs[2]);
-					local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).colorargs[2]);
+					local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.id);
+					local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.id);
 					local template = "%d%s";
 					aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
 					bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
@@ -186,55 +188,86 @@
 					end
 				end,
 				["sort"] = "asc", -- when the data is set, use this column so sort the default data
+				["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
+				["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."),
 			},
 			{
 				["name"] = "Moving",
 				["width"] = (scrollTableWidth * .15),
+				["align"] = "RIGHT",
 				["defaultsort"] = "dsc",
-			},
-			{
-				["name"] = "Missing",
-				["width"] = (scrollTableWidth * .15), 
-				["defaultsort"] = "dsc",
+				["sortnext"] = 1,
+				["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"),
+				["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."),
 			},
 			{
 				["name"] = "Available",
-				["width"] = (scrollTableWidth * .2),
+				["width"] = (scrollTableWidth * .25),
+				["align"] = "RIGHT",
 				["defaultsort"] = "dsc",
+				["sortnext"] = 1,
+				["comparesort"] = function(this, aRow, bRow, column)
+					local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing);
+					local bAvailablePercent = (this:GetRow(bRow).rowData.available / this:GetRow(bRow).rowData.missing);
+					
+					if this.cols[column].sort == "dsc" then
+						return aAvailablePercent > bAvailablePercent;
+					else
+						return aAvailablePercent < bAvailablePercent;
+					end
+				end,
+				["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
+				["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."),
 			},
 		};
 		
 		local ScrollingTable = LibStub("ScrollingTable");
 		local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame);
+		-- When moving over a row, provide a tooltip for the item
 		table:RegisterEvents({
 			["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
-				if row and realrow and data[realrow] and data[realrow].colorargs and data[realrow].colorargs[2] then
-			    	GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
-					GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
-			    	GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].colorargs[2]));
-					GameTooltip:Show();
+				if row and realrow then
+					-- Data row
+					
+					if data[realrow] and data[realrow].rowData and data[realrow].rowData.id then
+						GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
+						GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
+						GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.id));
+						GameTooltip:Show();
+					end
+				else
+					-- Header row
+					
+					if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
+						cellFrame.tooltipTitle = cols[column].tooltipTitle;
+						if cols[column].tooltip then
+							cellFrame.tooltip = cols[column].tooltip; -- Optional
+						else
+							cellFrame.tooltip = nil;
+						end
+						
+						ShowTooltip(cellFrame);
+					end
 				end
 			end,
 			["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
-				if row and realrow then
-					HideTooltip();
-				end
+				HideTooltip();
 			end,
 		});
 		
 		frame.scrollTable = table;
-		table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20);
+		table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
 		table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
 		table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
 		
-		-- Change the amount of displayed rows based on the size of the frame
-			frame.AdjustScrollTableRows = function(this)
-				local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
-				newRows = (newRows < 3 and 3) or newRows;
-				
-				this.scrollTable:SetDisplayRows(newRows, 15);
-			end;
-			frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
+	-- Change the amount of displayed rows based on the size of the frame
+		frame.AdjustScrollTableRows = function(this)
+			local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
+			newRows = (newRows < 3 and 3) or newRows;
+			
+			this.scrollTable:SetDisplayRows(newRows, 15);
+		end;
+		frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
 end
 
 function addon:SetMoverFrameData(data)