comparison Summary.lua @ 13:5006cb0e97c6

Removed sound media registrations since we don?t use them. Added an option to include tadeskill items above a certain item level threshold in the add items config tab. Renamed the variable for toggling hiding from summary when below price threshold-option. You will have to re-set it. Summary size and processing speed will now be remembered. Processing speed slider can now go up to 500% (up from 100%). Silver will be hidden from money when it includes more than 10 gold (down from 100g) and copper will be hidden if it includes more than 1 gold (down from 10g). Auction addons, crafting addons and itemcount addons can now register themselves through a few global functions. The most used addons have been included in the addon folder. You can now select the prefered default pricing, item count and crafting addons. Temporarily removed the ?dialogControl = ?DropDown?? from the track at select boxes. This functionality is broken within the Ace3 library and until it is fixed I wish to keep these options somewhat functional. The item list will now be truncated before rebuilding. Previously items disappearing from your inventory would still appear in this list. Mass add is now functional. All buttons and sliders that were meant to receive a tooltip (including the sort-headers), now have one. Added spacers between all buttons and sliders of the summary window. Added a ?queue all? button to the summary window. This button is not yet functional. If the value of an item is not retrieved from the auction prices database, it will appear as a dash (-) rather than ?0c?. If no item count is enabled, item counts will appear as ?Unknown? instead of breaking (or defaulting to 0).
author Zerotorescue
date Mon, 18 Oct 2010 15:26:42 +0200
parents 417c3cfb9623
children 0fc8a54516d7
comparison
equal deleted inserted replaced
12:417c3cfb9623 13:5006cb0e97c6
9 -- Register our own slash commands 9 -- Register our own slash commands
10 addon:RegisterSlash(function() 10 addon:RegisterSlash(function()
11 mod:BuildMain(); 11 mod:BuildMain();
12 mod:Build(); 12 mod:Build();
13 end, "s", "sum", "summary"); 13 end, "s", "sum", "summary");
14 end
15
16 local function ShowTooltip(self)
17 -- If this function is called from a widget, self is the widget and self.frame the actual frame
18 local this = self.frame or self;
19
20 GameTooltip:SetOwner(this, "ANCHOR_NONE");
21 GameTooltip:SetPoint("BOTTOM", this, "TOP");
22 GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1);
23
24 if type(this.tooltip) == "string" then
25 GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1);
26 end
27
28 GameTooltip:Show();
29 end
30
31 local function HideTooltip()
32 GameTooltip:Hide();
14 end 33 end
15 34
16 function mod:RegisterWidgets() 35 function mod:RegisterWidgets()
17 -- Register InlineGroupWithButton-widget 36 -- Register InlineGroupWithButton-widget
18 -- This widget adds a button next to the header of an inline group 37 -- This widget adds a button next to the header of an inline group
33 button:SetWidth(120); 52 button:SetWidth(120);
34 button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5); 53 button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
35 button:SetScript("OnClick", buttonSettings.exec); 54 button:SetScript("OnClick", buttonSettings.exec);
36 button.tooltipTitle = buttonSettings.name; 55 button.tooltipTitle = buttonSettings.name;
37 button.tooltip = buttonSettings.desc or ""; 56 button.tooltip = buttonSettings.desc or "";
38 button:SetScript("OnEnter", function(self) 57 button:SetScript("OnEnter", ShowTooltip);
39 GameTooltip:SetOwner(self, "ANCHOR_NONE") 58 button:SetScript("OnLeave", HideTooltip);
40 GameTooltip:SetPoint("BOTTOM", self, "TOP")
41 GameTooltip:SetText(self.tooltipTitle, 1, .82, 0, 1)
42
43 if type(self.tooltip) == "string" then
44 GameTooltip:AddLine(self.tooltip, 1, 1, 1, 1);
45 end
46
47 GameTooltip:Show();
48 end);
49 button:SetScript("OnLeave", function(self)
50 GameTooltip:Hide();
51 end);
52 else 59 else
53 error("settings must be a table - usage: MakeButton(table);"); 60 error("settings must be a table - usage: MakeButton(table);");
54 end 61 end
55 end 62 end
56 63
59 66
60 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion); 67 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
61 end 68 end
62 69
63 local itemsCache = {}; 70 local itemsCache = {};
64 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, CACHE_ITEMS_PER_UPDATE = 0, 0, 5; 71
72 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
65 local cacheStart; 73 local cacheStart;
66 74
67 function mod:BuildMain() 75 function mod:BuildMain()
68 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions"); 76 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
69 77
70 self:CloseFrame(); 78 self:CloseFrame();
71 79
72 -- Main Window 80 -- Main Window
73 mod.frame = AceGUI:Create("Frame"); 81 mod.frame = AceGUI:Create("Frame");
74 mod.frame:SetTitle("Inventorium Summary"); 82 mod.frame:SetTitle("Summary");
75 mod.frame:SetLayout("Fill"); 83 mod.frame:SetLayout("Fill");
76 mod.frame:SetCallback("OnClose", function(widget) 84 mod.frame:SetCallback("OnClose", function(widget)
77 mod:CancelTimer(self.tmrUpdater, true); 85 mod:CancelTimer(self.tmrUpdater, true);
78 mod:CloseFrame(); 86 mod:CloseFrame();
79 end); 87 end);
88 mod.frame:SetWidth(addon.db.global.defaults.summary.width);
89 mod.frame:SetHeight(addon.db.global.defaults.summary.height);
90 mod.frame.OnWidthSet = function(_, width)
91 addon.db.global.defaults.summary.width = width;
92 end;
93 mod.frame.OnHeightSet = function(_, height)
94 addon.db.global.defaults.summary.height = height;
95 end;
80 96
81 -- ScrollFrame child 97 -- ScrollFrame child
82 mod.scrollFrame = AceGUI:Create("ScrollFrame"); 98 mod.scrollFrame = AceGUI:Create("ScrollFrame");
83 mod.scrollFrame:SetLayout("Flow"); 99 mod.scrollFrame:SetLayout("Flow");
84 100
142 mod.scrollFrame:ReleaseChildren(); 158 mod.scrollFrame:ReleaseChildren();
143 159
144 -- Refresh button 160 -- Refresh button
145 local btnRefresh = AceGUI:Create("Button"); 161 local btnRefresh = AceGUI:Create("Button");
146 btnRefresh:SetText("Refresh"); 162 btnRefresh:SetText("Refresh");
147 -- SetTooltip: Reload all item counts and auction values.
148 btnRefresh:SetRelativeWidth(.2); 163 btnRefresh:SetRelativeWidth(.2);
149 btnRefresh:SetCallback("OnClick", function() 164 btnRefresh:SetCallback("OnClick", function()
150 -- Reset items cache 165 -- Reset items cache
151 table.wipe(itemsCache); 166 table.wipe(itemsCache);
152 167
153 -- Rebuild itemlist and start caching 168 -- Rebuild itemlist and start caching
154 mod:Build(); 169 mod:Build();
155 end); 170 end);
171 btnRefresh:SetCallback("OnEnter", ShowTooltip);
172 btnRefresh:SetCallback("OnLeave", HideTooltip);
173 btnRefresh.frame.tooltipTitle = "Refresh Cache";
174 btnRefresh.frame.tooltip = "Refresh the list and recache the item counts and auction values.";
156 175
157 mod.scrollFrame:AddChild(btnRefresh); 176 mod.scrollFrame:AddChild(btnRefresh);
158 177
178 local lblSpacer = AceGUI:Create("Label");
179 lblSpacer:SetRelativeWidth(.03);
180
181 mod.scrollFrame:AddChild(lblSpacer);
182
159 -- Speed slider 183 -- Speed slider
160 local btnRefresh = AceGUI:Create("Slider"); 184 local sdrSpeed = AceGUI:Create("Slider");
161 btnRefresh:SetLabel("Processing speed"); 185 sdrSpeed:SetLabel("Processing speed");
162 btnRefresh:SetSliderValues(0.01, 1, 0.01); 186 sdrSpeed:SetSliderValues(0.01, 5, 0.01);
163 btnRefresh:SetIsPercent(true); 187 sdrSpeed:SetIsPercent(true);
164 -- SetTooltip: Change the speed at which item counts and auction values are being cached. Higher is faster but may drastically reduce your FPS while caching. 188 sdrSpeed:SetRelativeWidth(.3);
165 btnRefresh:SetRelativeWidth(.3); 189 sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
166 btnRefresh:SetCallback("OnMouseUp", function(self, event, value) 190 addon.db.global.defaults.summary.speed = ceil( value * 100 / 5 );
167 CACHE_ITEMS_PER_UPDATE = ceil( value * 100 / 5 ); -- max = 20, min = 1 191
192 CACHE_ITEMS_PER_UPDATE = addon.db.global.defaults.summary.speed; -- max = 20, min = 1
168 end); 193 end);
169 btnRefresh:SetValue( CACHE_ITEMS_PER_UPDATE * 5 / 100 ); 194 sdrSpeed:SetValue( addon.db.global.defaults.summary.speed * 5 / 100 );
170 195 sdrSpeed:SetCallback("OnEnter", ShowTooltip);
171 mod.scrollFrame:AddChild(btnRefresh); 196 sdrSpeed:SetCallback("OnLeave", HideTooltip);
197 sdrSpeed.frame.tooltipTitle = "Caching Processing Speed";
198 sdrSpeed.frame.tooltip = "Change the speed at which item counts and auction values are being cached. Higher is faster but may drastically reduce your FPS while caching.\n\nAnything above 100% will probably become uncomfortable.";
199
200 mod.scrollFrame:AddChild(sdrSpeed);
201
202 local lblSpacer = AceGUI:Create("Label");
203 lblSpacer:SetRelativeWidth(.23);
204
205 mod.scrollFrame:AddChild(lblSpacer);
206
207 -- Config button
208 --[[local btnConfig = AceGUI:Create("Button");
209 btnConfig:SetText("Config");
210 btnConfig:SetRelativeWidth(.2);
211 btnConfig:SetCallback("OnClick", function()
212 --TODO: Tidy up
213 SlashCmdList["INVENTORIUM"]("config");
214 end);
215 btnConfig:SetCallback("OnEnter", ShowTooltip);
216 btnConfig:SetCallback("OnLeave", HideTooltip);
217 btnConfig.frame.tooltipTitle = "Config";
218 btnConfig.frame.tooltip = "Click to open the config window. This will close the current window.";
219
220 mod.scrollFrame:AddChild(btnConfig);]]
221
222 local lblSpacer = AceGUI:Create("Label");
223 lblSpacer:SetRelativeWidth(.03);
224
225 mod.scrollFrame:AddChild(lblSpacer);
226
227 -- Queue all button
228 local btnQueueAll = AceGUI:Create("Button");
229 btnQueueAll:SetText("Queue All");
230 btnQueueAll:SetRelativeWidth(.2);
231 btnQueueAll:SetCallback("OnClick", function()
232
233 end);
234 btnQueueAll:SetCallback("OnEnter", ShowTooltip);
235 btnQueueAll:SetCallback("OnLeave", HideTooltip);
236 btnQueueAll.frame.tooltipTitle = "Queue all";
237 btnQueueAll.frame.tooltip = "Queue everything that requires restocking within every single visible group.";
238
239 mod.scrollFrame:AddChild(btnQueueAll);
172 240
173 times.init = ceil( ( GetTime() - buildStartTime ) * 1000 ); 241 times.init = ceil( ( GetTime() - buildStartTime ) * 1000 );
174 addon:Debug("Time spent legend: (init / sorting / preparing / building / all)."); 242 addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
175 243
176 local playerName = UnitName("player"); 244 local playerName = UnitName("player");
214 local lblItem = AceGUI:Create("InteractiveLabel"); 282 local lblItem = AceGUI:Create("InteractiveLabel");
215 lblItem:SetText("|cfffed000Item|r"); 283 lblItem:SetText("|cfffed000Item|r");
216 lblItem:SetFontObject(GameFontHighlight); 284 lblItem:SetFontObject(GameFontHighlight);
217 lblItem:SetRelativeWidth(.7); 285 lblItem:SetRelativeWidth(.7);
218 lblItem:SetCallback("OnClick", function() ReSort("item"); end); 286 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
287 lblItem:SetCallback("OnEnter", ShowTooltip);
288 lblItem:SetCallback("OnLeave", HideTooltip);
289 lblItem.frame.tooltipTitle = "Item";
290 lblItem.frame.tooltip = "Sort on the item quality, then name.";
219 291
220 iGroup:AddChild(lblItem); 292 iGroup:AddChild(lblItem);
221 293
222 -- Current quantity 294 -- Current quantity
223 local lblQuantity = AceGUI:Create("InteractiveLabel"); 295 local lblQuantity = AceGUI:Create("InteractiveLabel");
224 lblQuantity:SetText("|cfffed000Cur.|r"); 296 lblQuantity:SetText("|cfffed000Cur.|r");
225 lblQuantity:SetFontObject(GameFontHighlight); 297 lblQuantity:SetFontObject(GameFontHighlight);
226 lblQuantity:SetRelativeWidth(.099); 298 lblQuantity:SetRelativeWidth(.099);
227 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end); 299 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
300 lblQuantity:SetCallback("OnEnter", ShowTooltip);
301 lblQuantity:SetCallback("OnLeave", HideTooltip);
302 lblQuantity.frame.tooltipTitle = "Current stock";
303 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock.";
228 304
229 iGroup:AddChild(lblQuantity); 305 iGroup:AddChild(lblQuantity);
230 306
231 -- Required stock 307 -- Required stock
232 local lblMinimumStock = AceGUI:Create("InteractiveLabel"); 308 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
233 lblMinimumStock:SetText("|cfffed000Req.|r"); 309 lblMinimumStock:SetText("|cfffed000Min.|r");
234 lblMinimumStock:SetFontObject(GameFontHighlight); 310 lblMinimumStock:SetFontObject(GameFontHighlight);
235 lblMinimumStock:SetRelativeWidth(.099); 311 lblMinimumStock:SetRelativeWidth(.099);
236 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end); 312 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
313 lblMinimumStock:SetCallback("OnEnter", ShowTooltip);
314 lblMinimumStock:SetCallback("OnLeave", HideTooltip);
315 lblMinimumStock.frame.tooltipTitle = "Minimum stock";
316 lblMinimumStock.frame.tooltip = "Sort on the minimum amount of items you wish to keep in stock.";
237 317
238 iGroup:AddChild(lblMinimumStock); 318 iGroup:AddChild(lblMinimumStock);
239 319
240 -- Lowest value 320 -- Lowest value
241 local lblValue = AceGUI:Create("InteractiveLabel"); 321 local lblValue = AceGUI:Create("InteractiveLabel");
242 lblValue:SetText("|cfffed000Value|r"); 322 lblValue:SetText("|cfffed000Value|r");
243 lblValue:SetFontObject(GameFontHighlight); 323 lblValue:SetFontObject(GameFontHighlight);
244 lblValue:SetRelativeWidth(.099); 324 lblValue:SetRelativeWidth(.099);
245 lblValue:SetCallback("OnClick", function() ReSort("value"); end); 325 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
326 lblValue:SetCallback("OnEnter", ShowTooltip);
327 lblValue:SetCallback("OnLeave", HideTooltip);
328 lblValue.frame.tooltipTitle = "Value";
329 lblValue.frame.tooltip = "Sort on the item auction value.";
246 330
247 iGroup:AddChild(lblValue); 331 iGroup:AddChild(lblValue);
248 332
249 333
250 -- Retrieve items list 334 -- Retrieve items list
254 local unknownItemName = "Unknown (#%d)"; 338 local unknownItemName = "Unknown (#%d)";
255 339
256 -- Sort item list 340 -- Sort item list
257 for itemId, _ in pairs(values.items) do 341 for itemId, _ in pairs(values.items) do
258 local itemName, itemLink, itemRarity = GetItemInfo(itemId); 342 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
259
260 if not itemRarity then
261 print(itemId .. ": " .. itemName .. " - " .. itemLink);
262 end
263 343
264 table.insert(itemsCache[groupName], { 344 table.insert(itemsCache[groupName], {
265 id = itemId, 345 id = itemId,
266 name = itemName or unknownItemName:format(itemId), 346 name = itemName or unknownItemName:format(itemId),
267 link = itemLink or unknownItemName:format(itemId), 347 link = itemLink or unknownItemName:format(itemId),
268 value = ((priceThreshold == 0) and 0) or -3,-- if no price threshold is set for this item, then don't look it up either --addon:GetAuctionValue(itemLink), 348 value = ((priceThreshold == 0) and -4) or -3,-- if no price threshold is set for this item, then don't look it up either --addon:GetAuctionValue(itemLink),
269 rarity = itemRarity or 1, 349 rarity = itemRarity or 1,
270 count = -3,--addon:GetItemCount(itemId), 350 count = -3,--addon:GetItemCount(itemId),
271 set = {}, 351 set = {},
272 }); 352 });
273 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; 353 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
377 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time 457 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
378 458
379 groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 ); 459 groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 );
380 end 460 end
381 461
382 addon:Debug(("Building of %s took %d ms (%d / %d / %d / %d / %d)."):format(groupName, ceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init, groupTimes.sorting, groupTimes.preparing, groupTimes.building, ceil( ( GetTime() - buildStartTime ) * 1000 ))); 462 if groupStartTime and groupTimes then
463 addon:Debug(("Building of %s took %d ms (%d / %d / %d / %d / %d)."):format(groupName, ceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, ceil( ( GetTime() - buildStartTime ) * 1000 )));
464 end
383 end 465 end
384 466
385 mod.scrollFrame:ResumeLayout(); 467 mod.scrollFrame:ResumeLayout();
386 mod.scrollFrame:DoLayout(); 468 mod.scrollFrame:DoLayout();
387 469
426 508
427 if mod.frame then 509 if mod.frame then
428 mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100))); 510 mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
429 end 511 end
430 512
431 if i >= CACHE_ITEMS_PER_UPDATE then 513 if i >= addon.db.global.defaults.summary.speed then
432 return; 514 return;
433 end 515 end
434 end 516 end
435 end 517 end
436 end 518 end
471 return "|cff0000ffNone up|r"; 553 return "|cff0000ffNone up|r";
472 elseif value == -2 then 554 elseif value == -2 then
473 return "|cff0000ffNo AH mod|r"; 555 return "|cff0000ffNo AH mod|r";
474 elseif value == -3 then 556 elseif value == -3 then
475 return "|cffffff00Unknown|r"; 557 return "|cffffff00Unknown|r";
558 elseif value == -4 then
559 return "|cff00ff00-|r";
476 elseif value < priceThreshold then 560 elseif value < priceThreshold then
477 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true)); 561 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
478 else 562 else
479 return addon:ReadableMoney(value or 0, true); 563 return addon:ReadableMoney(value or 0, true);
480 end 564 end
481 end 565 end
482 566
483 function mod:DisplayItemCount(value, minimumStock) 567 function mod:DisplayItemCount(value, minimumStock)
484 if value == -3 then 568 if value == -1 then
569 return "|cffffff00Unknown|r";
570 elseif value == -3 then
485 return "|cffffff00Unknown|r"; 571 return "|cffffff00Unknown|r";
486 else 572 else
487 return self:ColorCode(value, minimumStock); 573 return self:ColorCode(value, minimumStock);
488 end 574 end
489 end 575 end
499 end 585 end
500 end 586 end
501 587
502 return formatted; 588 return formatted;
503 end 589 end
504
505 --[[
506 No longer used, we're now caching complete item data instead of just AH values.
507 local AuctionValueCache = {};
508 function mod:GetAuctionValue(link)
509 local itemId = addon:GetItemId(link);
510
511 if AuctionValueCache[itemId] then
512 return AuctionValueCache[itemId];
513 else
514 local value = addon:GetAuctionValue(link);
515
516 AuctionValueCache[itemId] = value;
517
518 -- Reset the cache 1 minute after last updating it
519 self:CancelTimer(self.tmrResetCache, true);
520 self.tmrResetCache = self:ScheduleTimer(function()
521 table.wipe(AuctionValueCache);
522
523 mod.frame:SetStatusText("The auction item value cache has been reset.");
524 end, 60);
525 mod.frame:SetStatusText("");
526
527 return value;
528 end
529 end
530 ]]