Zerotorescue@0
|
1 local addon = LibStub("AceAddon-3.0"):GetAddon("Inventory");
|
Zerotorescue@1
|
2 local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0");
|
Zerotorescue@0
|
3
|
Zerotorescue@0
|
4 local AceGUI = LibStub("AceGUI-3.0");
|
Zerotorescue@0
|
5
|
Zerotorescue@0
|
6 function mod:OnEnable()
|
Zerotorescue@0
|
7 self:RegisterWidgets();
|
Zerotorescue@0
|
8
|
Zerotorescue@1
|
9 -- Register our own slash commands
|
Zerotorescue@1
|
10 addon:RegisterSlash(function()
|
Zerotorescue@1
|
11 mod:BuildMain();
|
Zerotorescue@1
|
12 mod:Build();
|
Zerotorescue@1
|
13 end, "s", "sum", "summary");
|
Zerotorescue@0
|
14 end
|
Zerotorescue@0
|
15
|
Zerotorescue@0
|
16 function mod:RegisterWidgets()
|
Zerotorescue@0
|
17 -- Register InlineGroupWithButton-widget
|
Zerotorescue@0
|
18 -- This widget adds a button next to the header of an inline group
|
Zerotorescue@0
|
19 -- SetPoint doesn't seem usable within AceGUI.
|
Zerotorescue@0
|
20
|
Zerotorescue@0
|
21 local widgetType = "InlineGroupWithButton";
|
Zerotorescue@0
|
22 local widgetVersion = 1;
|
Zerotorescue@0
|
23
|
Zerotorescue@0
|
24 local function Constructor()
|
Zerotorescue@0
|
25 local widget = AceGUI:Create("InlineGroup");
|
Zerotorescue@0
|
26 widget.type = widgetType;
|
Zerotorescue@0
|
27
|
Zerotorescue@0
|
28 widget.MakeButton = function(self, buttonSettings)
|
Zerotorescue@0
|
29 if type(buttonSettings) == "table" then
|
Zerotorescue@0
|
30 local button = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate");
|
Zerotorescue@0
|
31 button:SetText(buttonSettings.name);
|
Zerotorescue@0
|
32 button:SetHeight(22);
|
Zerotorescue@0
|
33 button:SetWidth(120);
|
Zerotorescue@0
|
34 button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
|
Zerotorescue@0
|
35 button:SetScript("OnClick", buttonSettings.exec);
|
Zerotorescue@0
|
36 button.tooltipTitle = buttonSettings.name;
|
Zerotorescue@0
|
37 button.tooltip = buttonSettings.desc or "";
|
Zerotorescue@0
|
38 button:SetScript("OnEnter", function(self)
|
Zerotorescue@0
|
39 GameTooltip:SetOwner(self, "ANCHOR_NONE")
|
Zerotorescue@0
|
40 GameTooltip:SetPoint("BOTTOM", self, "TOP")
|
Zerotorescue@0
|
41 GameTooltip:SetText(self.tooltipTitle, 1, .82, 0, 1)
|
Zerotorescue@0
|
42
|
Zerotorescue@0
|
43 if type(self.tooltip) == "string" then
|
Zerotorescue@0
|
44 GameTooltip:AddLine(self.tooltip, 1, 1, 1, 1);
|
Zerotorescue@0
|
45 end
|
Zerotorescue@0
|
46
|
Zerotorescue@0
|
47 GameTooltip:Show();
|
Zerotorescue@0
|
48 end);
|
Zerotorescue@0
|
49 button:SetScript("OnLeave", function(self)
|
Zerotorescue@0
|
50 GameTooltip:Hide();
|
Zerotorescue@0
|
51 end);
|
Zerotorescue@0
|
52 else
|
Zerotorescue@0
|
53 error("settings must be a table - usage: MakeButton(table);");
|
Zerotorescue@0
|
54 end
|
Zerotorescue@0
|
55 end
|
Zerotorescue@0
|
56
|
Zerotorescue@0
|
57 return widget;
|
Zerotorescue@0
|
58 end
|
Zerotorescue@0
|
59
|
Zerotorescue@0
|
60 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
|
Zerotorescue@0
|
61 end
|
Zerotorescue@0
|
62
|
Zerotorescue@1
|
63 local itemsCache = {};
|
Zerotorescue@1
|
64 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, CACHE_ITEMS_PER_UPDATE = 0, 0, 5;
|
Zerotorescue@1
|
65 local cacheStart;
|
Zerotorescue@1
|
66
|
Zerotorescue@0
|
67 function mod:BuildMain()
|
Zerotorescue@1
|
68 LibStub("AceConfigDialog-3.0"):Close("InventoryOptions");
|
Zerotorescue@0
|
69
|
Zerotorescue@10
|
70 self:CloseFrame();
|
Zerotorescue@10
|
71
|
Zerotorescue@1
|
72 -- Main Window
|
Zerotorescue@1
|
73 mod.frame = AceGUI:Create("Frame");
|
Zerotorescue@1
|
74 mod.frame:SetTitle("Inventory Summary");
|
Zerotorescue@1
|
75 mod.frame:SetLayout("Fill");
|
Zerotorescue@1
|
76 mod.frame:SetCallback("OnClose", function(widget)
|
Zerotorescue@7
|
77 mod:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@9
|
78 mod:CloseFrame();
|
Zerotorescue@1
|
79 end);
|
Zerotorescue@0
|
80
|
Zerotorescue@1
|
81 -- ScrollFrame child
|
Zerotorescue@1
|
82 mod.scrollFrame = AceGUI:Create("ScrollFrame");
|
Zerotorescue@1
|
83 mod.scrollFrame:SetLayout("Flow");
|
Zerotorescue@0
|
84
|
Zerotorescue@1
|
85 mod.frame:AddChild(mod.scrollFrame);
|
Zerotorescue@1
|
86
|
Zerotorescue@1
|
87 -- Reset items cache
|
Zerotorescue@1
|
88 table.wipe(itemsCache);
|
Zerotorescue@0
|
89 end
|
Zerotorescue@0
|
90
|
Zerotorescue@9
|
91 function mod:CloseFrame()
|
Zerotorescue@9
|
92 if mod.frame then
|
Zerotorescue@9
|
93 mod.frame:Release();
|
Zerotorescue@9
|
94 mod.frame = nil;
|
Zerotorescue@10
|
95
|
Zerotorescue@10
|
96 -- Stop caching
|
Zerotorescue@10
|
97
|
Zerotorescue@10
|
98 -- Stop timer
|
Zerotorescue@10
|
99 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@10
|
100
|
Zerotorescue@10
|
101 -- Reset trackers
|
Zerotorescue@10
|
102 CACHE_ITEMS_TOTAL = 0;
|
Zerotorescue@10
|
103 CACHE_ITEMS_CURRENT = 0;
|
Zerotorescue@9
|
104 end
|
Zerotorescue@9
|
105 end
|
Zerotorescue@9
|
106
|
Zerotorescue@0
|
107 local sortMethod = "item";
|
Zerotorescue@0
|
108 local sortDirectory = "ASC";
|
Zerotorescue@0
|
109 local function ReSort(subject)
|
Zerotorescue@0
|
110 if sortMethod == subject then
|
Zerotorescue@0
|
111 sortDirectory = (sortDirectory == "ASC" and "DESC") or "ASC";
|
Zerotorescue@0
|
112 else
|
Zerotorescue@0
|
113 sortDirectory = "ASC";
|
Zerotorescue@0
|
114 end
|
Zerotorescue@0
|
115 sortMethod = subject;
|
Zerotorescue@0
|
116
|
Zerotorescue@0
|
117 mod:Build();
|
Zerotorescue@0
|
118 end
|
Zerotorescue@10
|
119
|
Zerotorescue@10
|
120 -- From http://www.wowwiki.com/API_sort
|
Zerotorescue@10
|
121 local function pairsByKeys (t, f)
|
Zerotorescue@10
|
122 local a = {}
|
Zerotorescue@10
|
123 for n in pairs(t) do table.insert(a, n) end
|
Zerotorescue@10
|
124 table.sort(a, f)
|
Zerotorescue@10
|
125 local i = 0 -- iterator variable
|
Zerotorescue@10
|
126 local iter = function () -- iterator function
|
Zerotorescue@10
|
127 i = i + 1
|
Zerotorescue@10
|
128 if a[i] == nil then return nil
|
Zerotorescue@10
|
129 else return a[i], t[a[i]]
|
Zerotorescue@10
|
130 end
|
Zerotorescue@10
|
131 end
|
Zerotorescue@10
|
132 return iter
|
Zerotorescue@10
|
133 end
|
Zerotorescue@0
|
134
|
Zerotorescue@0
|
135 function mod:Build()
|
Zerotorescue@10
|
136 local buildStartTime, times = GetTime(), {};
|
Zerotorescue@0
|
137
|
Zerotorescue@1
|
138 -- We are going to add hunderds of widgets to this container, but don't want it to also cause hunderds of reflows, thus pause reflowing and just do it once when everything is prepared
|
Zerotorescue@1
|
139 -- This appears to be required for each container we wish to pause, so also do this for the contents
|
Zerotorescue@1
|
140 mod.scrollFrame:PauseLayout();
|
Zerotorescue@1
|
141
|
Zerotorescue@10
|
142 mod.scrollFrame:ReleaseChildren();
|
Zerotorescue@10
|
143
|
Zerotorescue@10
|
144 -- Refresh button
|
Zerotorescue@10
|
145 local btnRefresh = AceGUI:Create("Button");
|
Zerotorescue@10
|
146 btnRefresh:SetText("Refresh");
|
Zerotorescue@10
|
147 -- SetTooltip: Reload all item counts and auction values.
|
Zerotorescue@10
|
148 btnRefresh:SetRelativeWidth(.2);
|
Zerotorescue@10
|
149 btnRefresh:SetCallback("OnClick", function()
|
Zerotorescue@10
|
150 -- Reset items cache
|
Zerotorescue@10
|
151 table.wipe(itemsCache);
|
Zerotorescue@10
|
152
|
Zerotorescue@10
|
153 -- Rebuild itemlist and start caching
|
Zerotorescue@10
|
154 mod:Build();
|
Zerotorescue@10
|
155 end);
|
Zerotorescue@10
|
156
|
Zerotorescue@10
|
157 mod.scrollFrame:AddChild(btnRefresh);
|
Zerotorescue@10
|
158
|
Zerotorescue@10
|
159 -- Speed slider
|
Zerotorescue@10
|
160 local btnRefresh = AceGUI:Create("Slider");
|
Zerotorescue@10
|
161 btnRefresh:SetLabel("Processing speed");
|
Zerotorescue@10
|
162 btnRefresh:SetSliderValues(0.01, 1, 0.01);
|
Zerotorescue@10
|
163 btnRefresh:SetIsPercent(true);
|
Zerotorescue@10
|
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.
|
Zerotorescue@10
|
165 btnRefresh:SetRelativeWidth(.3);
|
Zerotorescue@10
|
166 btnRefresh:SetCallback("OnMouseUp", function(self, event, value)
|
Zerotorescue@10
|
167 CACHE_ITEMS_PER_UPDATE = ceil( value * 100 / 5 ); -- max = 20, min = 1
|
Zerotorescue@10
|
168 end);
|
Zerotorescue@10
|
169 btnRefresh:SetValue( CACHE_ITEMS_PER_UPDATE * 5 / 100 );
|
Zerotorescue@10
|
170
|
Zerotorescue@10
|
171 mod.scrollFrame:AddChild(btnRefresh);
|
Zerotorescue@10
|
172
|
Zerotorescue@10
|
173 times.init = ceil( ( GetTime() - buildStartTime ) * 1000 );
|
Zerotorescue@10
|
174 addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
|
Zerotorescue@10
|
175
|
Zerotorescue@1
|
176 local playerName = UnitName("player");
|
Zerotorescue@1
|
177
|
Zerotorescue@1
|
178 -- Go through all our stored groups
|
Zerotorescue@10
|
179 for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do
|
Zerotorescue@10
|
180 local groupStartTime, groupTimes = GetTime(), {};
|
Zerotorescue@10
|
181
|
Zerotorescue@1
|
182 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
|
Zerotorescue@1
|
183
|
Zerotorescue@1
|
184 -- Does this group have any items and do we want to track it at this char?
|
Zerotorescue@1
|
185 if values.items and trackAt[playerName] then
|
Zerotorescue@10
|
186
|
Zerotorescue@10
|
187
|
Zerotorescue@0
|
188 -- Get group settings
|
Zerotorescue@9
|
189 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
|
Zerotorescue@1
|
190 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
|
Zerotorescue@1
|
191 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
|
Zerotorescue@1
|
192 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
|
Zerotorescue@0
|
193
|
Zerotorescue@10
|
194
|
Zerotorescue@0
|
195 -- Make group container
|
Zerotorescue@0
|
196 local iGroup = AceGUI:Create("InlineGroupWithButton");
|
Zerotorescue@1
|
197 iGroup:PauseLayout();
|
Zerotorescue@0
|
198 iGroup:SetTitle(groupName);
|
Zerotorescue@0
|
199 iGroup:SetFullWidth(true);
|
Zerotorescue@0
|
200 iGroup:SetLayout("Flow");
|
Zerotorescue@0
|
201 iGroup:MakeButton({
|
Zerotorescue@0
|
202 name = "Queue",
|
Zerotorescue@0
|
203 desc = "Queue all items in this group.",
|
Zerotorescue@0
|
204 exec = function()
|
Zerotorescue@0
|
205 print(groupName);
|
Zerotorescue@0
|
206 end,
|
Zerotorescue@0
|
207 });
|
Zerotorescue@0
|
208
|
Zerotorescue@10
|
209
|
Zerotorescue@10
|
210
|
Zerotorescue@0
|
211 -- Headers
|
Zerotorescue@1
|
212
|
Zerotorescue@0
|
213 -- Itemlink
|
Zerotorescue@0
|
214 local lblItem = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
215 lblItem:SetText("|cfffed000Item|r");
|
Zerotorescue@0
|
216 lblItem:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
217 lblItem:SetRelativeWidth(.7);
|
Zerotorescue@0
|
218 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
|
Zerotorescue@0
|
219
|
Zerotorescue@0
|
220 iGroup:AddChild(lblItem);
|
Zerotorescue@0
|
221
|
Zerotorescue@0
|
222 -- Current quantity
|
Zerotorescue@0
|
223 local lblQuantity = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
224 lblQuantity:SetText("|cfffed000Cur.|r");
|
Zerotorescue@0
|
225 lblQuantity:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
226 lblQuantity:SetRelativeWidth(.099);
|
Zerotorescue@0
|
227 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
|
Zerotorescue@0
|
228
|
Zerotorescue@0
|
229 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
230
|
Zerotorescue@0
|
231 -- Required stock
|
Zerotorescue@9
|
232 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@9
|
233 lblMinimumStock:SetText("|cfffed000Req.|r");
|
Zerotorescue@9
|
234 lblMinimumStock:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
235 lblMinimumStock:SetRelativeWidth(.099);
|
Zerotorescue@9
|
236 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
|
Zerotorescue@0
|
237
|
Zerotorescue@9
|
238 iGroup:AddChild(lblMinimumStock);
|
Zerotorescue@0
|
239
|
Zerotorescue@1
|
240 -- Lowest value
|
Zerotorescue@1
|
241 local lblValue = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@1
|
242 lblValue:SetText("|cfffed000Value|r");
|
Zerotorescue@1
|
243 lblValue:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
244 lblValue:SetRelativeWidth(.099);
|
Zerotorescue@1
|
245 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
|
Zerotorescue@1
|
246
|
Zerotorescue@1
|
247 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
248
|
Zerotorescue@10
|
249
|
Zerotorescue@10
|
250 -- Retrieve items list
|
Zerotorescue@1
|
251 if not itemsCache[groupName] then
|
Zerotorescue@1
|
252 itemsCache[groupName] = {};
|
Zerotorescue@0
|
253
|
Zerotorescue@1
|
254 -- Sort item list
|
Zerotorescue@1
|
255 for itemId in pairs(values.items) do
|
Zerotorescue@1
|
256 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
|
Zerotorescue@1
|
257
|
Zerotorescue@1
|
258 table.insert(itemsCache[groupName], {
|
Zerotorescue@1
|
259 id = itemId,
|
Zerotorescue@1
|
260 name = itemName,
|
Zerotorescue@1
|
261 link = itemLink,
|
Zerotorescue@10
|
262 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),
|
Zerotorescue@1
|
263 rarity = itemRarity,
|
Zerotorescue@9
|
264 count = -3,--addon:GetItemCount(itemId),
|
Zerotorescue@1
|
265 set = {},
|
Zerotorescue@1
|
266 });
|
Zerotorescue@1
|
267 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
|
Zerotorescue@1
|
268 end
|
Zerotorescue@0
|
269 end
|
Zerotorescue@0
|
270
|
Zerotorescue@10
|
271 groupTimes.init = ceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
272
|
Zerotorescue@10
|
273
|
Zerotorescue@10
|
274
|
Zerotorescue@10
|
275 -- Sort items
|
Zerotorescue@1
|
276 table.sort(itemsCache[groupName], function(a, b)
|
Zerotorescue@1
|
277 if sortMethod == "item" and a.rarity == b.rarity then
|
Zerotorescue@1
|
278 -- Do a name-compare for items of the same rarity
|
Zerotorescue@1
|
279 -- Otherwise epics first, then junk
|
Zerotorescue@0
|
280 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
281 return a.name:upper() < b.name:upper();
|
Zerotorescue@0
|
282 else
|
Zerotorescue@1
|
283 return a.name:upper() > b.name:upper();
|
Zerotorescue@1
|
284 end
|
Zerotorescue@1
|
285 elseif sortMethod == "item" then
|
Zerotorescue@1
|
286 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
287 return a.rarity > b.rarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@1
|
288 else
|
Zerotorescue@1
|
289 return a.rarity < b.rarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@0
|
290 end
|
Zerotorescue@0
|
291 elseif sortMethod == "current" then
|
Zerotorescue@0
|
292 if sortDirectory == "ASC" then
|
Zerotorescue@0
|
293 return a.count < b.count;
|
Zerotorescue@0
|
294 else
|
Zerotorescue@0
|
295 return a.count > b.count;
|
Zerotorescue@0
|
296 end
|
Zerotorescue@0
|
297 elseif sortMethod == "percentage" then
|
Zerotorescue@0
|
298 if sortDirectory == "ASC" then
|
Zerotorescue@10
|
299 return ( a.count / minimumStock ) < ( b.count / minimumStock );
|
Zerotorescue@0
|
300 else
|
Zerotorescue@10
|
301 return ( a.count / minimumStock ) > ( b.count / minimumStock );
|
Zerotorescue@0
|
302 end
|
Zerotorescue@1
|
303 elseif sortMethod == "value" then
|
Zerotorescue@1
|
304 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
305 return a.value < b.value;
|
Zerotorescue@1
|
306 else
|
Zerotorescue@1
|
307 return a.value > b.value;
|
Zerotorescue@1
|
308 end
|
Zerotorescue@0
|
309 end
|
Zerotorescue@0
|
310 end);
|
Zerotorescue@0
|
311
|
Zerotorescue@10
|
312 groupTimes.sorting = ceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
313
|
Zerotorescue@10
|
314
|
Zerotorescue@10
|
315
|
Zerotorescue@10
|
316
|
Zerotorescue@10
|
317 -- Show itemslist
|
Zerotorescue@1
|
318 for i, item in pairs(itemsCache[groupName]) do
|
Zerotorescue@9
|
319 if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
|
Zerotorescue@0
|
320 local btnItemLink = AceGUI:Create("ItemLinkButton");
|
Zerotorescue@10
|
321 --btnItemLink:SetUserData("exec", function()
|
Zerotorescue@10
|
322 -- print("Nothing happening yet.");
|
Zerotorescue@10
|
323 --end);
|
Zerotorescue@10
|
324 btnItemLink:SetRelativeWidth(.7);
|
Zerotorescue@1
|
325 btnItemLink:SetItemId(item.id);
|
Zerotorescue@0
|
326
|
Zerotorescue@0
|
327 iGroup:AddChild(btnItemLink);
|
Zerotorescue@0
|
328
|
Zerotorescue@0
|
329 -- Current quantity
|
Zerotorescue@0
|
330 local lblQuantity = AceGUI:Create("Label");
|
Zerotorescue@9
|
331 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
|
Zerotorescue@10
|
332 lblQuantity:SetRelativeWidth(.099);
|
Zerotorescue@0
|
333
|
Zerotorescue@0
|
334 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
335
|
Zerotorescue@0
|
336 -- Required stock
|
Zerotorescue@9
|
337 local lblMinimumStock = AceGUI:Create("Label");
|
Zerotorescue@9
|
338 lblMinimumStock:SetText(minimumStock);
|
Zerotorescue@10
|
339 lblMinimumStock:SetRelativeWidth(.099);
|
Zerotorescue@0
|
340
|
Zerotorescue@9
|
341 iGroup:AddChild(lblMinimumStock);
|
Zerotorescue@1
|
342
|
Zerotorescue@1
|
343 -- Value
|
Zerotorescue@1
|
344 local lblValue = AceGUI:Create("Label");
|
Zerotorescue@1
|
345 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@10
|
346 lblValue:SetRelativeWidth(.099);
|
Zerotorescue@1
|
347
|
Zerotorescue@1
|
348 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
349
|
Zerotorescue@1
|
350 -- Remember references to the value and current fields so we can fill them later
|
Zerotorescue@1
|
351 if item.set then
|
Zerotorescue@10
|
352 -- -3 means the price is unknown, queue look up
|
Zerotorescue@10
|
353 if item.value == -3 then
|
Zerotorescue@10
|
354 item.set.value = lblValue;
|
Zerotorescue@10
|
355 end
|
Zerotorescue@10
|
356 if item.count == -3 then
|
Zerotorescue@10
|
357 item.set.current = lblQuantity;
|
Zerotorescue@10
|
358 end
|
Zerotorescue@10
|
359
|
Zerotorescue@10
|
360 -- Don't queue if we already know everything we want to know
|
Zerotorescue@10
|
361 if item.value ~= -3 and item.count ~= -3 then
|
Zerotorescue@10
|
362 item.set = nil;
|
Zerotorescue@10
|
363 end
|
Zerotorescue@1
|
364 end
|
Zerotorescue@0
|
365 end
|
Zerotorescue@0
|
366 end
|
Zerotorescue@0
|
367
|
Zerotorescue@10
|
368 groupTimes.preparing = ceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
369
|
Zerotorescue@1
|
370 iGroup:ResumeLayout();
|
Zerotorescue@1
|
371 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
|
Zerotorescue@10
|
372
|
Zerotorescue@10
|
373 groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@0
|
374 end
|
Zerotorescue@10
|
375
|
Zerotorescue@10
|
376 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 )));
|
Zerotorescue@0
|
377 end
|
Zerotorescue@1
|
378
|
Zerotorescue@1
|
379 mod.scrollFrame:ResumeLayout();
|
Zerotorescue@1
|
380 mod.scrollFrame:DoLayout();
|
Zerotorescue@1
|
381
|
Zerotorescue@10
|
382 addon:Debug(("Done building summary after %d ms."):format(ceil( ( GetTime() - buildStartTime ) * 1000 )));
|
Zerotorescue@10
|
383
|
Zerotorescue@1
|
384 if CACHE_ITEMS_TOTAL > 0 then
|
Zerotorescue@1
|
385 cacheStart = GetTime();
|
Zerotorescue@7
|
386 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@1
|
387 self.tmrUpdater = self:ScheduleRepeatingTimer("UpdateNextItem", .01); -- Once every 100 frames (or once every x frames if you have less than 100 FPS, basically, once every frame)
|
Zerotorescue@1
|
388 end
|
Zerotorescue@1
|
389 end
|
Zerotorescue@1
|
390
|
Zerotorescue@1
|
391 function mod:UpdateNextItem()
|
Zerotorescue@1
|
392 local i = 0;
|
Zerotorescue@1
|
393
|
Zerotorescue@1
|
394 for groupName, items in pairs(itemsCache) do
|
Zerotorescue@1
|
395 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
|
Zerotorescue@1
|
396 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
|
Zerotorescue@1
|
397
|
Zerotorescue@1
|
398 for _, item in pairs(items) do
|
Zerotorescue@1
|
399 if item.set then
|
Zerotorescue@10
|
400 if item.count == -3 then
|
Zerotorescue@10
|
401 -- Only if item count was queued, update it
|
Zerotorescue@10
|
402 item.count = addon:GetItemCount(item.id);
|
Zerotorescue@10
|
403 if item.set.current and item.set.current.SetText then
|
Zerotorescue@10
|
404 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
|
Zerotorescue@10
|
405 end
|
Zerotorescue@1
|
406 end
|
Zerotorescue@1
|
407
|
Zerotorescue@10
|
408 if item.value == -3 then
|
Zerotorescue@10
|
409 -- Only if item value was queued, update it
|
Zerotorescue@10
|
410 item.value = addon:GetAuctionValue(item.link);
|
Zerotorescue@10
|
411 if item.set.value and item.set.value.SetText then
|
Zerotorescue@10
|
412 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@10
|
413 end
|
Zerotorescue@1
|
414 end
|
Zerotorescue@1
|
415
|
Zerotorescue@1
|
416 item.set = nil;
|
Zerotorescue@1
|
417
|
Zerotorescue@1
|
418 i = i + 1;
|
Zerotorescue@1
|
419 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
|
Zerotorescue@1
|
420
|
Zerotorescue@9
|
421 if mod.frame then
|
Zerotorescue@9
|
422 mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
|
Zerotorescue@9
|
423 end
|
Zerotorescue@1
|
424
|
Zerotorescue@1
|
425 if i >= CACHE_ITEMS_PER_UPDATE then
|
Zerotorescue@1
|
426 return;
|
Zerotorescue@1
|
427 end
|
Zerotorescue@1
|
428 end
|
Zerotorescue@1
|
429 end
|
Zerotorescue@1
|
430 end
|
Zerotorescue@1
|
431
|
Zerotorescue@1
|
432 -- Reset trackers
|
Zerotorescue@1
|
433 CACHE_ITEMS_TOTAL = 0;
|
Zerotorescue@1
|
434 CACHE_ITEMS_CURRENT = 0;
|
Zerotorescue@1
|
435
|
Zerotorescue@1
|
436 -- Stop timer
|
Zerotorescue@1
|
437 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@10
|
438
|
Zerotorescue@10
|
439 -- Rebuild list so hidden items due to too low prices get added
|
Zerotorescue@10
|
440 self:Build();
|
Zerotorescue@1
|
441
|
Zerotorescue@1
|
442 -- Announce
|
Zerotorescue@10
|
443 mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. ceil(GetTime() - cacheStart) .. " seconds.");
|
Zerotorescue@1
|
444
|
Zerotorescue@1
|
445 -- Forget time
|
Zerotorescue@1
|
446 cacheStart = nil;
|
Zerotorescue@0
|
447 end
|
Zerotorescue@0
|
448
|
Zerotorescue@0
|
449 function mod:ColorCode(num, required)
|
Zerotorescue@0
|
450 local percentage = ( num / required );
|
Zerotorescue@0
|
451
|
Zerotorescue@0
|
452 if percentage >= addon.db.global.defaults.colors.green then
|
Zerotorescue@0
|
453 return ("|cff00ff00%d|r"):format(num);
|
Zerotorescue@0
|
454 elseif percentage >= addon.db.global.defaults.colors.yellow then
|
Zerotorescue@0
|
455 return ("|cffffff00%d|r"):format(num);
|
Zerotorescue@0
|
456 elseif percentage >= addon.db.global.defaults.colors.orange then
|
Zerotorescue@0
|
457 return ("|cffff9933%d|r"):format(num);
|
Zerotorescue@0
|
458 elseif percentage >= addon.db.global.defaults.colors.red then
|
Zerotorescue@0
|
459 return ("|cffff0000%d|r"):format(num);
|
Zerotorescue@0
|
460 end
|
Zerotorescue@0
|
461 end
|
Zerotorescue@0
|
462
|
Zerotorescue@1
|
463 function mod:DisplayMoney(value, priceThreshold)
|
Zerotorescue@7
|
464 if value == -1 then
|
Zerotorescue@7
|
465 return "|cff0000ffNone up|r";
|
Zerotorescue@7
|
466 elseif value == -2 then
|
Zerotorescue@7
|
467 return "|cff0000ffNo AH mod|r";
|
Zerotorescue@9
|
468 elseif value == -3 then
|
Zerotorescue@9
|
469 return "|cffffff00Unknown|r";
|
Zerotorescue@7
|
470 elseif value < priceThreshold then
|
Zerotorescue@1
|
471 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
|
Zerotorescue@1
|
472 else
|
Zerotorescue@1
|
473 return addon:ReadableMoney(value or 0, true);
|
Zerotorescue@1
|
474 end
|
Zerotorescue@1
|
475 end
|
Zerotorescue@1
|
476
|
Zerotorescue@9
|
477 function mod:DisplayItemCount(value, minimumStock)
|
Zerotorescue@9
|
478 if value == -3 then
|
Zerotorescue@9
|
479 return "|cffffff00Unknown|r";
|
Zerotorescue@9
|
480 else
|
Zerotorescue@9
|
481 return self:ColorCode(value, minimumStock);
|
Zerotorescue@9
|
482 end
|
Zerotorescue@9
|
483 end
|
Zerotorescue@9
|
484
|
Zerotorescue@0
|
485 function mod:NumberFormat(num)
|
Zerotorescue@0
|
486 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
|
Zerotorescue@0
|
487
|
Zerotorescue@0
|
488 while true do
|
Zerotorescue@0
|
489 formatted, matches = string.gsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);
|
Zerotorescue@0
|
490
|
Zerotorescue@0
|
491 if matches == 0 then
|
Zerotorescue@0
|
492 break;
|
Zerotorescue@0
|
493 end
|
Zerotorescue@0
|
494 end
|
Zerotorescue@0
|
495
|
Zerotorescue@0
|
496 return formatted;
|
Zerotorescue@1
|
497 end
|
Zerotorescue@1
|
498
|
Zerotorescue@1
|
499 --[[
|
Zerotorescue@1
|
500 No longer used, we're now caching complete item data instead of just AH values.
|
Zerotorescue@1
|
501 local AuctionValueCache = {};
|
Zerotorescue@1
|
502 function mod:GetAuctionValue(link)
|
Zerotorescue@1
|
503 local itemId = addon:GetItemId(link);
|
Zerotorescue@1
|
504
|
Zerotorescue@1
|
505 if AuctionValueCache[itemId] then
|
Zerotorescue@1
|
506 return AuctionValueCache[itemId];
|
Zerotorescue@1
|
507 else
|
Zerotorescue@1
|
508 local value = addon:GetAuctionValue(link);
|
Zerotorescue@1
|
509
|
Zerotorescue@1
|
510 AuctionValueCache[itemId] = value;
|
Zerotorescue@1
|
511
|
Zerotorescue@1
|
512 -- Reset the cache 1 minute after last updating it
|
Zerotorescue@1
|
513 self:CancelTimer(self.tmrResetCache, true);
|
Zerotorescue@1
|
514 self.tmrResetCache = self:ScheduleTimer(function()
|
Zerotorescue@1
|
515 table.wipe(AuctionValueCache);
|
Zerotorescue@1
|
516
|
Zerotorescue@1
|
517 mod.frame:SetStatusText("The auction item value cache has been reset.");
|
Zerotorescue@1
|
518 end, 60);
|
Zerotorescue@1
|
519 mod.frame:SetStatusText("");
|
Zerotorescue@1
|
520
|
Zerotorescue@1
|
521 return value;
|
Zerotorescue@1
|
522 end
|
Zerotorescue@1
|
523 end
|
Zerotorescue@1
|
524 ]] |