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@1
|
70 -- Main Window
|
Zerotorescue@1
|
71 mod.frame = AceGUI:Create("Frame");
|
Zerotorescue@1
|
72 mod.frame:SetTitle("Inventory Summary");
|
Zerotorescue@1
|
73 mod.frame:SetLayout("Fill");
|
Zerotorescue@1
|
74 mod.frame:SetCallback("OnClose", function(widget)
|
Zerotorescue@1
|
75 AceGUI:Release(widget);
|
Zerotorescue@7
|
76 mod:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@1
|
77 end);
|
Zerotorescue@0
|
78
|
Zerotorescue@1
|
79 -- ScrollFrame child
|
Zerotorescue@1
|
80 mod.scrollFrame = AceGUI:Create("ScrollFrame");
|
Zerotorescue@1
|
81 mod.scrollFrame:SetLayout("Flow");
|
Zerotorescue@0
|
82
|
Zerotorescue@1
|
83 mod.frame:AddChild(mod.scrollFrame);
|
Zerotorescue@1
|
84
|
Zerotorescue@1
|
85 -- Reset items cache
|
Zerotorescue@1
|
86 table.wipe(itemsCache);
|
Zerotorescue@0
|
87 end
|
Zerotorescue@0
|
88
|
Zerotorescue@0
|
89 local sortMethod = "item";
|
Zerotorescue@0
|
90 local sortDirectory = "ASC";
|
Zerotorescue@0
|
91 local function ReSort(subject)
|
Zerotorescue@0
|
92 if sortMethod == subject then
|
Zerotorescue@0
|
93 sortDirectory = (sortDirectory == "ASC" and "DESC") or "ASC";
|
Zerotorescue@0
|
94 else
|
Zerotorescue@0
|
95 sortDirectory = "ASC";
|
Zerotorescue@0
|
96 end
|
Zerotorescue@0
|
97 sortMethod = subject;
|
Zerotorescue@0
|
98
|
Zerotorescue@0
|
99 mod:Build();
|
Zerotorescue@0
|
100 end
|
Zerotorescue@0
|
101
|
Zerotorescue@0
|
102 function mod:Build()
|
Zerotorescue@1
|
103 local start = GetTime();
|
Zerotorescue@1
|
104
|
Zerotorescue@0
|
105 mod.scrollFrame:ReleaseChildren();
|
Zerotorescue@0
|
106
|
Zerotorescue@1
|
107 -- 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
|
108 -- This appears to be required for each container we wish to pause, so also do this for the contents
|
Zerotorescue@1
|
109 mod.scrollFrame:PauseLayout();
|
Zerotorescue@1
|
110
|
Zerotorescue@1
|
111 local playerName = UnitName("player");
|
Zerotorescue@1
|
112
|
Zerotorescue@1
|
113 -- Go through all our stored groups
|
Zerotorescue@0
|
114 for groupName, values in pairs(addon.db.global.groups) do
|
Zerotorescue@1
|
115 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
|
Zerotorescue@1
|
116
|
Zerotorescue@1
|
117 -- Does this group have any items and do we want to track it at this char?
|
Zerotorescue@1
|
118 if values.items and trackAt[playerName] then
|
Zerotorescue@0
|
119 -- Get group settings
|
Zerotorescue@1
|
120 local stockRequired = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
|
Zerotorescue@1
|
121 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
|
Zerotorescue@1
|
122 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
|
Zerotorescue@1
|
123 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
|
Zerotorescue@0
|
124
|
Zerotorescue@0
|
125 -- Make group container
|
Zerotorescue@0
|
126 local iGroup = AceGUI:Create("InlineGroupWithButton");
|
Zerotorescue@1
|
127 iGroup:PauseLayout();
|
Zerotorescue@0
|
128 iGroup:SetTitle(groupName);
|
Zerotorescue@0
|
129 iGroup:SetFullWidth(true);
|
Zerotorescue@0
|
130 iGroup:SetLayout("Flow");
|
Zerotorescue@0
|
131 iGroup:MakeButton({
|
Zerotorescue@0
|
132 name = "Queue",
|
Zerotorescue@0
|
133 desc = "Queue all items in this group.",
|
Zerotorescue@0
|
134 exec = function()
|
Zerotorescue@0
|
135 print(groupName);
|
Zerotorescue@0
|
136 end,
|
Zerotorescue@0
|
137 });
|
Zerotorescue@0
|
138
|
Zerotorescue@0
|
139 -- Headers
|
Zerotorescue@1
|
140
|
Zerotorescue@0
|
141 -- Itemlink
|
Zerotorescue@0
|
142 local lblItem = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
143 lblItem:SetText("|cfffed000Item|r");
|
Zerotorescue@0
|
144 lblItem:SetFontObject(GameFontHighlight);
|
Zerotorescue@0
|
145 lblItem:SetRelativeWidth(0.7);
|
Zerotorescue@0
|
146 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
|
Zerotorescue@0
|
147
|
Zerotorescue@0
|
148 iGroup:AddChild(lblItem);
|
Zerotorescue@0
|
149
|
Zerotorescue@0
|
150 -- Current quantity
|
Zerotorescue@0
|
151 local lblQuantity = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
152 lblQuantity:SetText("|cfffed000Cur.|r");
|
Zerotorescue@0
|
153 lblQuantity:SetFontObject(GameFontHighlight);
|
Zerotorescue@1
|
154 lblQuantity:SetRelativeWidth(0.099);
|
Zerotorescue@0
|
155 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
|
Zerotorescue@0
|
156
|
Zerotorescue@0
|
157 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
158
|
Zerotorescue@0
|
159 -- Required stock
|
Zerotorescue@0
|
160 local lblStockRequired = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
161 lblStockRequired:SetText("|cfffed000Req.|r");
|
Zerotorescue@0
|
162 lblStockRequired:SetFontObject(GameFontHighlight);
|
Zerotorescue@1
|
163 lblStockRequired:SetRelativeWidth(0.099);
|
Zerotorescue@0
|
164 lblStockRequired:SetCallback("OnClick", function() ReSort("percentage"); end);
|
Zerotorescue@0
|
165
|
Zerotorescue@0
|
166 iGroup:AddChild(lblStockRequired);
|
Zerotorescue@0
|
167
|
Zerotorescue@1
|
168 -- Lowest value
|
Zerotorescue@1
|
169 local lblValue = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@1
|
170 lblValue:SetText("|cfffed000Value|r");
|
Zerotorescue@1
|
171 lblValue:SetFontObject(GameFontHighlight);
|
Zerotorescue@1
|
172 lblValue:SetRelativeWidth(0.099);
|
Zerotorescue@1
|
173 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
|
Zerotorescue@1
|
174
|
Zerotorescue@1
|
175 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
176
|
Zerotorescue@1
|
177 if not itemsCache[groupName] then
|
Zerotorescue@1
|
178 itemsCache[groupName] = {};
|
Zerotorescue@0
|
179
|
Zerotorescue@1
|
180 -- Sort item list
|
Zerotorescue@1
|
181 for itemId in pairs(values.items) do
|
Zerotorescue@1
|
182 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
|
Zerotorescue@1
|
183
|
Zerotorescue@1
|
184 table.insert(itemsCache[groupName], {
|
Zerotorescue@1
|
185 id = itemId,
|
Zerotorescue@1
|
186 name = itemName,
|
Zerotorescue@1
|
187 link = itemLink,
|
Zerotorescue@1
|
188 value = 0,--addon:GetAuctionValue(itemLink),
|
Zerotorescue@1
|
189 rarity = itemRarity,
|
Zerotorescue@1
|
190 count = 0,--addon:GetItemCount(itemId),
|
Zerotorescue@1
|
191 set = {},
|
Zerotorescue@1
|
192 });
|
Zerotorescue@1
|
193 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
|
Zerotorescue@1
|
194 end
|
Zerotorescue@0
|
195 end
|
Zerotorescue@0
|
196
|
Zerotorescue@1
|
197 table.sort(itemsCache[groupName], function(a, b)
|
Zerotorescue@1
|
198 if sortMethod == "item" and a.rarity == b.rarity then
|
Zerotorescue@1
|
199 -- Do a name-compare for items of the same rarity
|
Zerotorescue@1
|
200 -- Otherwise epics first, then junk
|
Zerotorescue@0
|
201 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
202 return a.name:upper() < b.name:upper();
|
Zerotorescue@0
|
203 else
|
Zerotorescue@1
|
204 return a.name:upper() > b.name:upper();
|
Zerotorescue@1
|
205 end
|
Zerotorescue@1
|
206 elseif sortMethod == "item" then
|
Zerotorescue@1
|
207 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
208 return a.rarity > b.rarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@1
|
209 else
|
Zerotorescue@1
|
210 return a.rarity < b.rarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@0
|
211 end
|
Zerotorescue@0
|
212 elseif sortMethod == "current" then
|
Zerotorescue@0
|
213 if sortDirectory == "ASC" then
|
Zerotorescue@0
|
214 return a.count < b.count;
|
Zerotorescue@0
|
215 else
|
Zerotorescue@0
|
216 return a.count > b.count;
|
Zerotorescue@0
|
217 end
|
Zerotorescue@0
|
218 elseif sortMethod == "percentage" then
|
Zerotorescue@0
|
219 if sortDirectory == "ASC" then
|
Zerotorescue@0
|
220 return ( a.count / stockRequired ) < ( b.count / stockRequired );
|
Zerotorescue@0
|
221 else
|
Zerotorescue@0
|
222 return ( a.count / stockRequired ) > ( b.count / stockRequired );
|
Zerotorescue@0
|
223 end
|
Zerotorescue@1
|
224 elseif sortMethod == "value" then
|
Zerotorescue@1
|
225 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
226 return a.value < b.value;
|
Zerotorescue@1
|
227 else
|
Zerotorescue@1
|
228 return a.value > b.value;
|
Zerotorescue@1
|
229 end
|
Zerotorescue@0
|
230 end
|
Zerotorescue@0
|
231 end);
|
Zerotorescue@0
|
232
|
Zerotorescue@0
|
233 -- Show stuff
|
Zerotorescue@1
|
234 for i, item in pairs(itemsCache[groupName]) do
|
Zerotorescue@1
|
235 if ( item.count / stockRequired ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
|
Zerotorescue@0
|
236 local btnItemLink = AceGUI:Create("ItemLinkButton");
|
Zerotorescue@1
|
237 btnItemLink:SetUserData("exec", function()
|
Zerotorescue@1
|
238 print("Win.");
|
Zerotorescue@1
|
239 end);
|
Zerotorescue@0
|
240 btnItemLink:SetRelativeWidth(0.7);
|
Zerotorescue@1
|
241 btnItemLink:SetItemId(item.id);
|
Zerotorescue@0
|
242
|
Zerotorescue@0
|
243 iGroup:AddChild(btnItemLink);
|
Zerotorescue@0
|
244
|
Zerotorescue@0
|
245 -- Current quantity
|
Zerotorescue@0
|
246 local lblQuantity = AceGUI:Create("Label");
|
Zerotorescue@0
|
247 lblQuantity:SetText(self:ColorCode(item.count, stockRequired));
|
Zerotorescue@1
|
248 lblQuantity:SetRelativeWidth(0.099);
|
Zerotorescue@0
|
249
|
Zerotorescue@0
|
250 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
251
|
Zerotorescue@0
|
252 -- Required stock
|
Zerotorescue@0
|
253 local lblStockRequired = AceGUI:Create("Label");
|
Zerotorescue@0
|
254 lblStockRequired:SetText(stockRequired);
|
Zerotorescue@1
|
255 lblStockRequired:SetRelativeWidth(0.099);
|
Zerotorescue@0
|
256
|
Zerotorescue@0
|
257 iGroup:AddChild(lblStockRequired);
|
Zerotorescue@1
|
258
|
Zerotorescue@1
|
259 -- Value
|
Zerotorescue@1
|
260 local lblValue = AceGUI:Create("Label");
|
Zerotorescue@1
|
261 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@1
|
262 lblValue:SetRelativeWidth(0.099);
|
Zerotorescue@1
|
263
|
Zerotorescue@1
|
264 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
265
|
Zerotorescue@1
|
266 -- Remember references to the value and current fields so we can fill them later
|
Zerotorescue@1
|
267 if item.set then
|
Zerotorescue@1
|
268 item.set.value = lblValue;
|
Zerotorescue@1
|
269 item.set.current = lblQuantity;
|
Zerotorescue@1
|
270 end
|
Zerotorescue@0
|
271 end
|
Zerotorescue@0
|
272 end
|
Zerotorescue@0
|
273
|
Zerotorescue@1
|
274 iGroup:ResumeLayout();
|
Zerotorescue@1
|
275 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
|
Zerotorescue@0
|
276 end
|
Zerotorescue@0
|
277 end
|
Zerotorescue@1
|
278
|
Zerotorescue@1
|
279 mod.scrollFrame:ResumeLayout();
|
Zerotorescue@1
|
280 mod.scrollFrame:DoLayout();
|
Zerotorescue@1
|
281
|
Zerotorescue@1
|
282 if CACHE_ITEMS_TOTAL > 0 then
|
Zerotorescue@1
|
283 cacheStart = GetTime();
|
Zerotorescue@7
|
284 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@1
|
285 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
|
286 end
|
Zerotorescue@1
|
287 end
|
Zerotorescue@1
|
288
|
Zerotorescue@1
|
289 function mod:UpdateNextItem()
|
Zerotorescue@1
|
290 local i = 0;
|
Zerotorescue@1
|
291
|
Zerotorescue@1
|
292 for groupName, items in pairs(itemsCache) do
|
Zerotorescue@1
|
293 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
|
Zerotorescue@1
|
294 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
|
Zerotorescue@1
|
295
|
Zerotorescue@1
|
296 for _, item in pairs(items) do
|
Zerotorescue@1
|
297 if item.set then
|
Zerotorescue@1
|
298 item.count = addon:GetItemCount(item.id);
|
Zerotorescue@1
|
299 if item.set.current then
|
Zerotorescue@1
|
300 item.set.current:SetText(self:ColorCode(item.count, minimumStock));
|
Zerotorescue@1
|
301 end
|
Zerotorescue@1
|
302
|
Zerotorescue@1
|
303 item.value = addon:GetAuctionValue(item.link);
|
Zerotorescue@1
|
304 if item.set.value then
|
Zerotorescue@1
|
305 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@1
|
306 end
|
Zerotorescue@1
|
307
|
Zerotorescue@1
|
308 item.set = nil;
|
Zerotorescue@1
|
309
|
Zerotorescue@1
|
310 i = i + 1;
|
Zerotorescue@1
|
311 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
|
Zerotorescue@1
|
312
|
Zerotorescue@7
|
313 mod.frame:SetStatusText(("Caching auction values and item-counts... %d% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
|
Zerotorescue@1
|
314
|
Zerotorescue@1
|
315 if i >= CACHE_ITEMS_PER_UPDATE then
|
Zerotorescue@1
|
316 return;
|
Zerotorescue@1
|
317 end
|
Zerotorescue@1
|
318 end
|
Zerotorescue@1
|
319 end
|
Zerotorescue@1
|
320 end
|
Zerotorescue@1
|
321
|
Zerotorescue@1
|
322 -- Reset trackers
|
Zerotorescue@1
|
323 CACHE_ITEMS_TOTAL = 0;
|
Zerotorescue@1
|
324 CACHE_ITEMS_CURRENT = 0;
|
Zerotorescue@1
|
325
|
Zerotorescue@1
|
326 -- Rebuild list so hidden items due to too low prices get added
|
Zerotorescue@1
|
327 self:Build();
|
Zerotorescue@1
|
328
|
Zerotorescue@1
|
329 -- Stop timer
|
Zerotorescue@1
|
330 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@1
|
331
|
Zerotorescue@1
|
332 -- Announce
|
Zerotorescue@1
|
333 mod.frame:SetStatusText("All prices and itemcounts have been cached. This process took " .. ceil(GetTime() - cacheStart) .. " seconds.");
|
Zerotorescue@1
|
334
|
Zerotorescue@1
|
335 -- Forget time
|
Zerotorescue@1
|
336 cacheStart = nil;
|
Zerotorescue@0
|
337 end
|
Zerotorescue@0
|
338
|
Zerotorescue@0
|
339 function mod:ColorCode(num, required)
|
Zerotorescue@0
|
340 local percentage = ( num / required );
|
Zerotorescue@0
|
341
|
Zerotorescue@0
|
342 if percentage >= addon.db.global.defaults.colors.green then
|
Zerotorescue@0
|
343 return ("|cff00ff00%d|r"):format(num);
|
Zerotorescue@0
|
344 elseif percentage >= addon.db.global.defaults.colors.yellow then
|
Zerotorescue@0
|
345 return ("|cffffff00%d|r"):format(num);
|
Zerotorescue@0
|
346 elseif percentage >= addon.db.global.defaults.colors.orange then
|
Zerotorescue@0
|
347 return ("|cffff9933%d|r"):format(num);
|
Zerotorescue@0
|
348 elseif percentage >= addon.db.global.defaults.colors.red then
|
Zerotorescue@0
|
349 return ("|cffff0000%d|r"):format(num);
|
Zerotorescue@0
|
350 end
|
Zerotorescue@0
|
351 end
|
Zerotorescue@0
|
352
|
Zerotorescue@1
|
353 function mod:DisplayMoney(value, priceThreshold)
|
Zerotorescue@7
|
354 if value == -1 then
|
Zerotorescue@7
|
355 return "|cff0000ffNone up|r";
|
Zerotorescue@7
|
356 elseif value == -2 then
|
Zerotorescue@7
|
357 return "|cff0000ffNo AH mod|r";
|
Zerotorescue@7
|
358 elseif value < priceThreshold then
|
Zerotorescue@1
|
359 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
|
Zerotorescue@1
|
360 else
|
Zerotorescue@1
|
361 return addon:ReadableMoney(value or 0, true);
|
Zerotorescue@1
|
362 end
|
Zerotorescue@1
|
363 end
|
Zerotorescue@1
|
364
|
Zerotorescue@0
|
365 function mod:NumberFormat(num)
|
Zerotorescue@0
|
366 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
|
Zerotorescue@0
|
367
|
Zerotorescue@0
|
368 while true do
|
Zerotorescue@0
|
369 formatted, matches = string.gsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);
|
Zerotorescue@0
|
370
|
Zerotorescue@0
|
371 if matches == 0 then
|
Zerotorescue@0
|
372 break;
|
Zerotorescue@0
|
373 end
|
Zerotorescue@0
|
374 end
|
Zerotorescue@0
|
375
|
Zerotorescue@0
|
376 return formatted;
|
Zerotorescue@1
|
377 end
|
Zerotorescue@1
|
378
|
Zerotorescue@1
|
379 --[[
|
Zerotorescue@1
|
380 No longer used, we're now caching complete item data instead of just AH values.
|
Zerotorescue@1
|
381 local AuctionValueCache = {};
|
Zerotorescue@1
|
382 function mod:GetAuctionValue(link)
|
Zerotorescue@1
|
383 local itemId = addon:GetItemId(link);
|
Zerotorescue@1
|
384
|
Zerotorescue@1
|
385 if AuctionValueCache[itemId] then
|
Zerotorescue@1
|
386 return AuctionValueCache[itemId];
|
Zerotorescue@1
|
387 else
|
Zerotorescue@1
|
388 local value = addon:GetAuctionValue(link);
|
Zerotorescue@1
|
389
|
Zerotorescue@1
|
390 AuctionValueCache[itemId] = value;
|
Zerotorescue@1
|
391
|
Zerotorescue@1
|
392 -- Reset the cache 1 minute after last updating it
|
Zerotorescue@1
|
393 self:CancelTimer(self.tmrResetCache, true);
|
Zerotorescue@1
|
394 self.tmrResetCache = self:ScheduleTimer(function()
|
Zerotorescue@1
|
395 table.wipe(AuctionValueCache);
|
Zerotorescue@1
|
396
|
Zerotorescue@1
|
397 mod.frame:SetStatusText("The auction item value cache has been reset.");
|
Zerotorescue@1
|
398 end, 60);
|
Zerotorescue@1
|
399 mod.frame:SetStatusText("");
|
Zerotorescue@1
|
400
|
Zerotorescue@1
|
401 return value;
|
Zerotorescue@1
|
402 end
|
Zerotorescue@1
|
403 end
|
Zerotorescue@1
|
404 ]] |