comparison 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
comparison
equal deleted inserted replaced
105:4efbaf069ddb 106:d3fbb5676a5e
1 local addon = select(2, ...); 1 local addon = select(2, ...);
2 2
3 local function ShowTooltip(self) 3 local function ShowTooltip(self)
4 -- If this function is called from a widget, self is the widget and self.frame the actual frame 4 -- If this function is called from a widget, self is the widget and self.frame the actual frame
5 local this = self.frame or self; 5 local this = self.frame or self;
6
7 if not this.tooltipTitle then return; end
6 8
7 GameTooltip:SetOwner(this, "ANCHOR_NONE"); 9 GameTooltip:SetOwner(this, "ANCHOR_NONE");
8 if this.tooltipLocation and this.tooltipLocation == "BOTTOM" then 10 if this.tooltipLocation and this.tooltipLocation == "BOTTOM" then
9 GameTooltip:SetPoint("TOP", this, "BOTTOM"); 11 GameTooltip:SetPoint("TOP", this, "BOTTOM");
10 else 12 else
118 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end); 120 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end);
119 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); 121 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
120 122
121 -- Description 123 -- Description
122 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); 124 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
123 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -25); 125 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27);
124 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right 126 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right
125 lblDescription:SetJustifyH("LEFT"); 127 lblDescription:SetJustifyH("LEFT");
126 lblDescription:SetJustifyV("TOP"); 128 lblDescription:SetJustifyV("TOP");
127 lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?"); 129 lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?");
128 130
136 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11); 138 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11);
137 btnMove:SetText("Move Items"); 139 btnMove:SetText("Move Items");
138 btnMove:SetScript("OnClick", onAccept); 140 btnMove:SetScript("OnClick", onAccept);
139 btnMove:SetScript("OnEnter", ShowTooltip); 141 btnMove:SetScript("OnEnter", ShowTooltip);
140 btnMove:SetScript("OnLeave", HideTooltip); 142 btnMove:SetScript("OnLeave", HideTooltip);
141 btnMove.tooltipTitle = "Move Items"; 143 btnMove.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items");
142 btnMove.tooltip = "Start moving these items from the bank."; 144 btnMove.tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank.");
143 145
144 frame.btnMove = btnMove; 146 frame.btnMove = btnMove;
145 147
146 -- Cancel 148 -- Cancel
147 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); 149 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate");
150 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11); 152 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11);
151 btnCancel:SetText("Cancel"); 153 btnCancel:SetText("Cancel");
152 btnCancel:SetScript("OnClick", onCancel); 154 btnCancel:SetScript("OnClick", onCancel);
153 btnCancel:SetScript("OnEnter", ShowTooltip); 155 btnCancel:SetScript("OnEnter", ShowTooltip);
154 btnCancel:SetScript("OnLeave", HideTooltip); 156 btnCancel:SetScript("OnLeave", HideTooltip);
155 btnCancel.tooltipTitle = "Cancel"; 157 btnCancel.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel");
156 btnCancel.tooltip = "Do not move anything and close the window."; 158 btnCancel.tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window.");
157 159
158 frame.btnCancel = btnCancel; 160 frame.btnCancel = btnCancel;
159 161
160 -- 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 162 -- 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
161 local frmMeasureDummy = CreateFrame("Frame", nil, frame); 163 local frmMeasureDummy = CreateFrame("Frame", nil, frame);
162 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); 164 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
163 frmMeasureDummy:SetPoint("LEFT", frame.lblDescription, "LEFT", 15, 0); 165 frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0);
164 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); 166 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
165 167
166 frame.frmMeasureDummy = frmMeasureDummy; 168 frame.frmMeasureDummy = frmMeasureDummy;
167 169
168 -- Scrolling table with a list of items to be moved 170 -- Scrolling table with a list of items to be moved
169 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 20 ); -- adjust width by the scrollbar size 171 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
170 local headers = { 172 local headers = {
171 { 173 {
172 ["name"] = "Item", 174 ["name"] = "Item",
173 ["width"] = (scrollTableWidth * .5), 175 ["width"] = (scrollTableWidth * .60),
174 ["defaultsort"] = "asc", 176 ["defaultsort"] = "asc",
175 ["comparesort"] = function(this, aRow, bRow, column) 177 ["comparesort"] = function(this, aRow, bRow, column)
176 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).colorargs[2]); 178 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.id);
177 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).colorargs[2]); 179 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.id);
178 local template = "%d%s"; 180 local template = "%d%s";
179 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower()); 181 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
180 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower()); 182 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
181 183
182 if this.cols[column].sort == "dsc" then 184 if this.cols[column].sort == "dsc" then
184 else 186 else
185 return aName < bName; 187 return aName < bName;
186 end 188 end
187 end, 189 end,
188 ["sort"] = "asc", -- when the data is set, use this column so sort the default data 190 ["sort"] = "asc", -- when the data is set, use this column so sort the default data
191 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
192 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."),
189 }, 193 },
190 { 194 {
191 ["name"] = "Moving", 195 ["name"] = "Moving",
192 ["width"] = (scrollTableWidth * .15), 196 ["width"] = (scrollTableWidth * .15),
197 ["align"] = "RIGHT",
193 ["defaultsort"] = "dsc", 198 ["defaultsort"] = "dsc",
194 }, 199 ["sortnext"] = 1,
195 { 200 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"),
196 ["name"] = "Missing", 201 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."),
197 ["width"] = (scrollTableWidth * .15),
198 ["defaultsort"] = "dsc",
199 }, 202 },
200 { 203 {
201 ["name"] = "Available", 204 ["name"] = "Available",
202 ["width"] = (scrollTableWidth * .2), 205 ["width"] = (scrollTableWidth * .25),
206 ["align"] = "RIGHT",
203 ["defaultsort"] = "dsc", 207 ["defaultsort"] = "dsc",
208 ["sortnext"] = 1,
209 ["comparesort"] = function(this, aRow, bRow, column)
210 local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing);
211 local bAvailablePercent = (this:GetRow(bRow).rowData.available / this:GetRow(bRow).rowData.missing);
212
213 if this.cols[column].sort == "dsc" then
214 return aAvailablePercent > bAvailablePercent;
215 else
216 return aAvailablePercent < bAvailablePercent;
217 end
218 end,
219 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
220 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."),
204 }, 221 },
205 }; 222 };
206 223
207 local ScrollingTable = LibStub("ScrollingTable"); 224 local ScrollingTable = LibStub("ScrollingTable");
208 local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame); 225 local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame);
226 -- When moving over a row, provide a tooltip for the item
209 table:RegisterEvents({ 227 table:RegisterEvents({
210 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 228 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
211 if row and realrow and data[realrow] and data[realrow].colorargs and data[realrow].colorargs[2] then 229 if row and realrow then
212 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE"); 230 -- Data row
213 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT"); 231
214 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].colorargs[2])); 232 if data[realrow] and data[realrow].rowData and data[realrow].rowData.id then
215 GameTooltip:Show(); 233 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
234 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
235 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.id));
236 GameTooltip:Show();
237 end
238 else
239 -- Header row
240
241 if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
242 cellFrame.tooltipTitle = cols[column].tooltipTitle;
243 if cols[column].tooltip then
244 cellFrame.tooltip = cols[column].tooltip; -- Optional
245 else
246 cellFrame.tooltip = nil;
247 end
248
249 ShowTooltip(cellFrame);
250 end
216 end 251 end
217 end, 252 end,
218 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 253 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
219 if row and realrow then 254 HideTooltip();
220 HideTooltip();
221 end
222 end, 255 end,
223 }); 256 });
224 257
225 frame.scrollTable = table; 258 frame.scrollTable = table;
226 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); 259 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
227 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0); 260 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
228 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); 261 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
229 262
230 -- Change the amount of displayed rows based on the size of the frame 263 -- Change the amount of displayed rows based on the size of the frame
231 frame.AdjustScrollTableRows = function(this) 264 frame.AdjustScrollTableRows = function(this)
232 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); 265 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
233 newRows = (newRows < 3 and 3) or newRows; 266 newRows = (newRows < 3 and 3) or newRows;
234 267
235 this.scrollTable:SetDisplayRows(newRows, 15); 268 this.scrollTable:SetDisplayRows(newRows, 15);
236 end; 269 end;
237 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); 270 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
238 end 271 end
239 272
240 function addon:SetMoverFrameData(data) 273 function addon:SetMoverFrameData(data)
241 InventoriumItemMover.scrollTable:SetData(data); 274 InventoriumItemMover.scrollTable:SetData(data);
242 275