Zerotorescue@62
|
1 local addon = select(2, ...); -- Get a reference to the main addon object
|
Zerotorescue@205
|
2 local mod = addon:NewModule("Summary", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window
|
Zerotorescue@0
|
3
|
Zerotorescue@122
|
4 local _G = _G; -- prevent looking up of the global table
|
Zerotorescue@122
|
5 local sformat, sgsub, supper, mceil, mfloor, tinsert, twipe, tsort = _G.string.format, _G.string.gsub, _G.string.upper, _G.math.ceil, _G.math.floor, _G.table.insert, _G.table.wipe, _G.table.sort;
|
Zerotorescue@122
|
6 local pairs, type, select = _G.pairs, _G.type, _G.select;
|
Zerotorescue@122
|
7
|
Zerotorescue@23
|
8 local unknownItemName = "Unknown (#%d)";
|
Zerotorescue@23
|
9
|
Zerotorescue@62
|
10 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, itemsCache = 0, 0, {};
|
Zerotorescue@62
|
11 local AceGUI, cacheStart;
|
Zerotorescue@23
|
12
|
Zerotorescue@0
|
13 function mod:OnEnable()
|
Zerotorescue@62
|
14 -- Register the summary specific widget
|
Zerotorescue@62
|
15 addon:GetModule("Widgets"):InlineGroupWithButton();
|
Zerotorescue@62
|
16
|
Zerotorescue@62
|
17 AceGUI = LibStub("AceGUI-3.0");
|
Zerotorescue@0
|
18
|
Zerotorescue@1
|
19 -- Register our own slash commands
|
Zerotorescue@62
|
20 -- /im summary
|
Zerotorescue@1
|
21 addon:RegisterSlash(function()
|
Zerotorescue@205
|
22 if self:IsFrameOpen() then
|
Zerotorescue@205
|
23 self:CloseFrame();
|
Zerotorescue@205
|
24 else
|
Zerotorescue@205
|
25 self:Show();
|
Zerotorescue@205
|
26 end
|
Zerotorescue@36
|
27 end, { "s", "sum", "summary" }, "|Hfunction:InventoriumCommandHandler:summary|h|cff00fff7/im summary|r|h (or /im s) - Show the summary window containing an overview of all items within the groups tracked at this current character.");
|
Zerotorescue@62
|
28
|
Zerotorescue@62
|
29 -- /im reset
|
Zerotorescue@23
|
30 addon:RegisterSlash(function()
|
Zerotorescue@23
|
31 if mod.frame then
|
Zerotorescue@73
|
32 mod.frame:SetWidth(700);
|
Zerotorescue@23
|
33 mod.frame:SetHeight(600);
|
Zerotorescue@23
|
34
|
Zerotorescue@98
|
35 addon:Print("Resetting width and height of the summary frame.");
|
Zerotorescue@23
|
36 end
|
Zerotorescue@36
|
37 end, { "r", "reset" }, "|Hfunction:InventoriumCommandHandler:reset|h|cff00fff7/im reset|r|h (or /im r) - Reset the size of the summary frame.");
|
Zerotorescue@0
|
38 end
|
Zerotorescue@0
|
39
|
Zerotorescue@13
|
40 local function ShowTooltip(self)
|
Zerotorescue@13
|
41 -- If this function is called from a widget, self is the widget and self.frame the actual frame
|
Zerotorescue@13
|
42 local this = self.frame or self;
|
Zerotorescue@13
|
43
|
Zerotorescue@13
|
44 GameTooltip:SetOwner(this, "ANCHOR_NONE");
|
Zerotorescue@13
|
45 GameTooltip:SetPoint("BOTTOM", this, "TOP");
|
Zerotorescue@13
|
46 GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1);
|
Zerotorescue@13
|
47
|
Zerotorescue@13
|
48 if type(this.tooltip) == "string" then
|
Zerotorescue@13
|
49 GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1);
|
Zerotorescue@13
|
50 end
|
Zerotorescue@13
|
51
|
Zerotorescue@13
|
52 GameTooltip:Show();
|
Zerotorescue@13
|
53 end
|
Zerotorescue@13
|
54
|
Zerotorescue@13
|
55 local function HideTooltip()
|
Zerotorescue@13
|
56 GameTooltip:Hide();
|
Zerotorescue@13
|
57 end
|
Zerotorescue@13
|
58
|
Zerotorescue@0
|
59 function mod:BuildMain()
|
Zerotorescue@205
|
60 if not self.frame then
|
Zerotorescue@205
|
61 -- Main Window
|
Zerotorescue@205
|
62 self.frame = AceGUI:Create("Frame");
|
Zerotorescue@205
|
63 _G["InventoriumSummary"] = self.frame; -- name the global frame so it can be put in the UISpecialFrames
|
Zerotorescue@205
|
64 self.frame:SetTitle("Inventory Summary");
|
Zerotorescue@205
|
65 self.frame:SetLayout("Fill");
|
Zerotorescue@205
|
66 self.frame:SetCallback("OnClose", function(widget)
|
Zerotorescue@205
|
67 mod:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@205
|
68 mod:CloseFrame();
|
Zerotorescue@205
|
69 end);
|
Zerotorescue@205
|
70 self.frame:SetWidth(addon.db.profile.defaults.summary.width);
|
Zerotorescue@205
|
71 self.frame:SetHeight(addon.db.profile.defaults.summary.height);
|
Zerotorescue@205
|
72 self.frame.OnWidthSet = function(_, width)
|
Zerotorescue@205
|
73 addon.db.profile.defaults.summary.width = width;
|
Zerotorescue@205
|
74 end;
|
Zerotorescue@205
|
75 self.frame.OnHeightSet = function(_, height)
|
Zerotorescue@205
|
76 addon.db.profile.defaults.summary.height = height;
|
Zerotorescue@205
|
77 end;
|
Zerotorescue@205
|
78
|
Zerotorescue@205
|
79 -- Close on escape
|
Zerotorescue@205
|
80 tinsert(UISpecialFrames, "InventoriumSummary");
|
Zerotorescue@205
|
81
|
Zerotorescue@205
|
82 -- ScrollFrame child
|
Zerotorescue@205
|
83 self.scrollFrame = AceGUI:Create("ScrollFrame");
|
Zerotorescue@205
|
84 self.scrollFrame:SetLayout("Flow");
|
Zerotorescue@205
|
85
|
Zerotorescue@205
|
86 self.frame:AddChild(self.scrollFrame);
|
Zerotorescue@205
|
87
|
Zerotorescue@205
|
88 -- Reset items cache
|
Zerotorescue@205
|
89 twipe(itemsCache);
|
Zerotorescue@205
|
90 end
|
Zerotorescue@205
|
91 end
|
Zerotorescue@205
|
92
|
Zerotorescue@205
|
93 function mod:Show()
|
Zerotorescue@205
|
94 -- We don't want any other windows open at this time.
|
Zerotorescue@205
|
95 for name, module in addon:IterateModules() do
|
Zerotorescue@205
|
96 if module.CloseFrame then
|
Zerotorescue@205
|
97 module:CloseFrame();
|
Zerotorescue@205
|
98 end
|
Zerotorescue@205
|
99 end
|
Zerotorescue@0
|
100
|
Zerotorescue@205
|
101 self:BuildMain();
|
Zerotorescue@205
|
102 self:Build();
|
Zerotorescue@205
|
103 end
|
Zerotorescue@205
|
104
|
Zerotorescue@205
|
105 function mod:IsFrameOpen()
|
Zerotorescue@205
|
106 return (self.frame and self.frame:IsShown());
|
Zerotorescue@0
|
107 end
|
Zerotorescue@0
|
108
|
Zerotorescue@9
|
109 function mod:CloseFrame()
|
Zerotorescue@205
|
110 if self:IsFrameOpen() then
|
Zerotorescue@205
|
111 --self.scrollFrame:Release();
|
Zerotorescue@205
|
112 --self.scrollFrame = nil;
|
Zerotorescue@205
|
113
|
Zerotorescue@205
|
114 self.frame:Hide();
|
Zerotorescue@10
|
115
|
Zerotorescue@10
|
116 -- Stop caching
|
Zerotorescue@10
|
117
|
Zerotorescue@10
|
118 -- Stop timer
|
Zerotorescue@10
|
119 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@10
|
120
|
Zerotorescue@10
|
121 -- Reset trackers
|
Zerotorescue@10
|
122 CACHE_ITEMS_TOTAL = 0;
|
Zerotorescue@10
|
123 CACHE_ITEMS_CURRENT = 0;
|
Zerotorescue@9
|
124 end
|
Zerotorescue@9
|
125 end
|
Zerotorescue@9
|
126
|
Zerotorescue@0
|
127 local sortMethod = "item";
|
Zerotorescue@0
|
128 local sortDirectory = "ASC";
|
Zerotorescue@0
|
129 local function ReSort(subject)
|
Zerotorescue@0
|
130 if sortMethod == subject then
|
Zerotorescue@0
|
131 sortDirectory = (sortDirectory == "ASC" and "DESC") or "ASC";
|
Zerotorescue@0
|
132 else
|
Zerotorescue@0
|
133 sortDirectory = "ASC";
|
Zerotorescue@0
|
134 end
|
Zerotorescue@0
|
135 sortMethod = subject;
|
Zerotorescue@0
|
136
|
Zerotorescue@0
|
137 mod:Build();
|
Zerotorescue@0
|
138 end
|
Zerotorescue@57
|
139
|
Zerotorescue@10
|
140 -- From http://www.wowwiki.com/API_sort
|
Zerotorescue@10
|
141 local function pairsByKeys (t, f)
|
Zerotorescue@10
|
142 local a = {}
|
Zerotorescue@62
|
143 for n in pairs(t) do tinsert(a, n) end
|
Zerotorescue@122
|
144 tsort(a, f)
|
Zerotorescue@10
|
145 local i = 0 -- iterator variable
|
Zerotorescue@10
|
146 local iter = function () -- iterator function
|
Zerotorescue@10
|
147 i = i + 1
|
Zerotorescue@10
|
148 if a[i] == nil then return nil
|
Zerotorescue@10
|
149 else return a[i], t[a[i]]
|
Zerotorescue@10
|
150 end
|
Zerotorescue@10
|
151 end
|
Zerotorescue@10
|
152 return iter
|
Zerotorescue@10
|
153 end
|
Zerotorescue@0
|
154
|
Zerotorescue@0
|
155 function mod:Build()
|
Zerotorescue@10
|
156 local buildStartTime, times = GetTime(), {};
|
Zerotorescue@0
|
157
|
Zerotorescue@205
|
158 self.frame:Show();
|
Zerotorescue@205
|
159
|
Zerotorescue@1
|
160 -- 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
|
161 -- This appears to be required for each container we wish to pause, so also do this for the contents
|
Zerotorescue@1
|
162 mod.scrollFrame:PauseLayout();
|
Zerotorescue@1
|
163
|
Zerotorescue@10
|
164 mod.scrollFrame:ReleaseChildren();
|
Zerotorescue@10
|
165
|
Zerotorescue@10
|
166 -- Refresh button
|
Zerotorescue@10
|
167 local btnRefresh = AceGUI:Create("Button");
|
Zerotorescue@10
|
168 btnRefresh:SetText("Refresh");
|
Zerotorescue@10
|
169 btnRefresh:SetRelativeWidth(.2);
|
Zerotorescue@10
|
170 btnRefresh:SetCallback("OnClick", function()
|
Zerotorescue@10
|
171 -- Reset items cache
|
Zerotorescue@122
|
172 twipe(itemsCache);
|
Zerotorescue@10
|
173
|
Zerotorescue@10
|
174 -- Rebuild itemlist and start caching
|
Zerotorescue@10
|
175 mod:Build();
|
Zerotorescue@10
|
176 end);
|
Zerotorescue@13
|
177 btnRefresh:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
178 btnRefresh:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
179 btnRefresh.frame.tooltipTitle = "Refresh Cache";
|
Zerotorescue@13
|
180 btnRefresh.frame.tooltip = "Refresh the list and recache the item counts and auction values.";
|
Zerotorescue@10
|
181
|
Zerotorescue@10
|
182 mod.scrollFrame:AddChild(btnRefresh);
|
Zerotorescue@10
|
183
|
Zerotorescue@13
|
184 local lblSpacer = AceGUI:Create("Label");
|
Zerotorescue@13
|
185 lblSpacer:SetRelativeWidth(.03);
|
Zerotorescue@13
|
186
|
Zerotorescue@13
|
187 mod.scrollFrame:AddChild(lblSpacer);
|
Zerotorescue@13
|
188
|
Zerotorescue@10
|
189 -- Speed slider
|
Zerotorescue@13
|
190 local sdrSpeed = AceGUI:Create("Slider");
|
Zerotorescue@13
|
191 sdrSpeed:SetLabel("Processing speed");
|
Zerotorescue@62
|
192 sdrSpeed:SetSliderValues(0.01, 5, 0.01); -- min, max, interval
|
Zerotorescue@13
|
193 sdrSpeed:SetIsPercent(true);
|
Zerotorescue@13
|
194 sdrSpeed:SetRelativeWidth(.3);
|
Zerotorescue@13
|
195 sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
|
Zerotorescue@122
|
196 addon.db.profile.defaults.summary.speed = mceil( ( ( value * 100 ) / 5) - .5 );
|
Zerotorescue@10
|
197 end);
|
Zerotorescue@61
|
198 sdrSpeed:SetValue( addon.db.profile.defaults.summary.speed * 5 / 100 );
|
Zerotorescue@13
|
199 sdrSpeed:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
200 sdrSpeed:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
201 sdrSpeed.frame.tooltipTitle = "Caching Processing Speed";
|
Zerotorescue@13
|
202 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.";
|
Zerotorescue@10
|
203
|
Zerotorescue@13
|
204 mod.scrollFrame:AddChild(sdrSpeed);
|
Zerotorescue@13
|
205
|
Zerotorescue@13
|
206 local lblSpacer = AceGUI:Create("Label");
|
Zerotorescue@13
|
207 lblSpacer:SetRelativeWidth(.23);
|
Zerotorescue@13
|
208
|
Zerotorescue@13
|
209 mod.scrollFrame:AddChild(lblSpacer);
|
Zerotorescue@13
|
210
|
Zerotorescue@13
|
211 -- Config button
|
Zerotorescue@13
|
212 --[[local btnConfig = AceGUI:Create("Button");
|
Zerotorescue@13
|
213 btnConfig:SetText("Config");
|
Zerotorescue@13
|
214 btnConfig:SetRelativeWidth(.2);
|
Zerotorescue@13
|
215 btnConfig:SetCallback("OnClick", function()
|
Zerotorescue@13
|
216 --TODO: Tidy up
|
Zerotorescue@13
|
217 SlashCmdList["INVENTORIUM"]("config");
|
Zerotorescue@13
|
218 end);
|
Zerotorescue@13
|
219 btnConfig:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
220 btnConfig:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
221 btnConfig.frame.tooltipTitle = "Config";
|
Zerotorescue@13
|
222 btnConfig.frame.tooltip = "Click to open the config window. This will close the current window.";
|
Zerotorescue@13
|
223
|
Zerotorescue@13
|
224 mod.scrollFrame:AddChild(btnConfig);]]
|
Zerotorescue@13
|
225
|
Zerotorescue@13
|
226 local lblSpacer = AceGUI:Create("Label");
|
Zerotorescue@13
|
227 lblSpacer:SetRelativeWidth(.03);
|
Zerotorescue@13
|
228
|
Zerotorescue@13
|
229 mod.scrollFrame:AddChild(lblSpacer);
|
Zerotorescue@13
|
230
|
Zerotorescue@13
|
231 -- Queue all button
|
Zerotorescue@13
|
232 local btnQueueAll = AceGUI:Create("Button");
|
Zerotorescue@13
|
233 btnQueueAll:SetText("Queue All");
|
Zerotorescue@13
|
234 btnQueueAll:SetRelativeWidth(.2);
|
Zerotorescue@13
|
235 btnQueueAll:SetCallback("OnClick", function()
|
Zerotorescue@14
|
236 self:SendMessage("IM_QUEUE_ALL");
|
Zerotorescue@13
|
237 end);
|
Zerotorescue@13
|
238 btnQueueAll:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
239 btnQueueAll:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
240 btnQueueAll.frame.tooltipTitle = "Queue all";
|
Zerotorescue@13
|
241 btnQueueAll.frame.tooltip = "Queue everything that requires restocking within every single visible group.";
|
Zerotorescue@13
|
242
|
Zerotorescue@13
|
243 mod.scrollFrame:AddChild(btnQueueAll);
|
Zerotorescue@10
|
244
|
Zerotorescue@122
|
245 times.init = mceil( ( GetTime() - buildStartTime ) * 1000 );
|
Zerotorescue@10
|
246 addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
|
Zerotorescue@10
|
247
|
Zerotorescue@1
|
248 local playerName = UnitName("player");
|
Zerotorescue@1
|
249
|
Zerotorescue@1
|
250 -- Go through all our stored groups
|
Zerotorescue@61
|
251 for groupName, values in pairsByKeys(addon.db.profile.groups, function(a, b) return a:lower() < b:lower(); end) do
|
Zerotorescue@10
|
252 local groupStartTime, groupTimes = GetTime(), {};
|
Zerotorescue@10
|
253
|
Zerotorescue@50
|
254 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
|
Zerotorescue@50
|
255
|
Zerotorescue@1
|
256
|
Zerotorescue@1
|
257 -- Does this group have any items and do we want to track it at this char?
|
Zerotorescue@1
|
258 if values.items and trackAt[playerName] then
|
Zerotorescue@10
|
259
|
Zerotorescue@10
|
260
|
Zerotorescue@0
|
261 -- Get group settings
|
Zerotorescue@62
|
262 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
|
Zerotorescue@62
|
263 local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock");
|
Zerotorescue@50
|
264 local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow");
|
Zerotorescue@50
|
265 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
|
Zerotorescue@50
|
266 local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold");
|
Zerotorescue@50
|
267 local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue");
|
Zerotorescue@10
|
268
|
Zerotorescue@0
|
269 -- Make group container
|
Zerotorescue@0
|
270 local iGroup = AceGUI:Create("InlineGroupWithButton");
|
Zerotorescue@1
|
271 iGroup:PauseLayout();
|
Zerotorescue@0
|
272 iGroup:SetTitle(groupName);
|
Zerotorescue@0
|
273 iGroup:SetFullWidth(true);
|
Zerotorescue@0
|
274 iGroup:SetLayout("Flow");
|
Zerotorescue@0
|
275 iGroup:MakeButton({
|
Zerotorescue@0
|
276 name = "Queue",
|
Zerotorescue@0
|
277 desc = "Queue all items in this group.",
|
Zerotorescue@0
|
278 exec = function()
|
Zerotorescue@136
|
279 addon:Print(("Queuing all items within %s craftable by the currently open profession."):format(groupName));
|
Zerotorescue@14
|
280 self:SendMessage("IM_QUEUE_GROUP", groupName);
|
Zerotorescue@0
|
281 end,
|
Zerotorescue@0
|
282 });
|
Zerotorescue@0
|
283
|
Zerotorescue@10
|
284
|
Zerotorescue@10
|
285
|
Zerotorescue@0
|
286 -- Headers
|
Zerotorescue@1
|
287
|
Zerotorescue@0
|
288 -- Itemlink
|
Zerotorescue@0
|
289 local lblItem = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
290 lblItem:SetText("|cfffed000Item|r");
|
Zerotorescue@0
|
291 lblItem:SetFontObject(GameFontHighlight);
|
Zerotorescue@57
|
292 lblItem:SetRelativeWidth(.7);
|
Zerotorescue@0
|
293 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
|
Zerotorescue@13
|
294 lblItem:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
295 lblItem:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
296 lblItem.frame.tooltipTitle = "Item";
|
Zerotorescue@13
|
297 lblItem.frame.tooltip = "Sort on the item quality, then name.";
|
Zerotorescue@0
|
298
|
Zerotorescue@0
|
299 iGroup:AddChild(lblItem);
|
Zerotorescue@0
|
300
|
Zerotorescue@50
|
301 -- Local quantity
|
Zerotorescue@50
|
302 local lblLocal = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@50
|
303 lblLocal:SetText("|cfffed000Loc.|r");
|
Zerotorescue@50
|
304 lblLocal:SetFontObject(GameFontHighlight);
|
Zerotorescue@50
|
305 lblLocal:SetRelativeWidth(.099);
|
Zerotorescue@50
|
306 lblLocal:SetCallback("OnClick", function() ReSort("local"); end);
|
Zerotorescue@50
|
307 lblLocal:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@50
|
308 lblLocal:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@50
|
309 lblLocal.frame.tooltipTitle = "Local stock";
|
Zerotorescue@50
|
310 lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
|
Zerotorescue@50
|
311
|
Zerotorescue@50
|
312 iGroup:AddChild(lblLocal);
|
Zerotorescue@50
|
313
|
Zerotorescue@0
|
314 -- Current quantity
|
Zerotorescue@0
|
315 local lblQuantity = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@0
|
316 lblQuantity:SetText("|cfffed000Cur.|r");
|
Zerotorescue@0
|
317 lblQuantity:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
318 lblQuantity:SetRelativeWidth(.099);
|
Zerotorescue@0
|
319 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
|
Zerotorescue@13
|
320 lblQuantity:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
321 lblQuantity:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
322 lblQuantity.frame.tooltipTitle = "Current stock";
|
Zerotorescue@13
|
323 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock.";
|
Zerotorescue@0
|
324
|
Zerotorescue@0
|
325 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
326
|
Zerotorescue@1
|
327 -- Lowest value
|
Zerotorescue@1
|
328 local lblValue = AceGUI:Create("InteractiveLabel");
|
Zerotorescue@1
|
329 lblValue:SetText("|cfffed000Value|r");
|
Zerotorescue@1
|
330 lblValue:SetFontObject(GameFontHighlight);
|
Zerotorescue@10
|
331 lblValue:SetRelativeWidth(.099);
|
Zerotorescue@1
|
332 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
|
Zerotorescue@13
|
333 lblValue:SetCallback("OnEnter", ShowTooltip);
|
Zerotorescue@13
|
334 lblValue:SetCallback("OnLeave", HideTooltip);
|
Zerotorescue@13
|
335 lblValue.frame.tooltipTitle = "Value";
|
Zerotorescue@13
|
336 lblValue.frame.tooltip = "Sort on the item auction value.";
|
Zerotorescue@1
|
337
|
Zerotorescue@1
|
338 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
339
|
Zerotorescue@10
|
340
|
Zerotorescue@10
|
341 -- Retrieve items list
|
Zerotorescue@1
|
342 if not itemsCache[groupName] then
|
Zerotorescue@1
|
343 itemsCache[groupName] = {};
|
Zerotorescue@74
|
344 end
|
Zerotorescue@74
|
345
|
Zerotorescue@74
|
346 if #(itemsCache[groupName]) == 0 then
|
Zerotorescue@74
|
347 -- If the item cache is empty
|
Zerotorescue@12
|
348 for itemId, _ in pairs(values.items) do
|
Zerotorescue@74
|
349 local newItemData = addon.ItemData:New(itemId);
|
Zerotorescue@1
|
350
|
Zerotorescue@74
|
351 -- if no price threshold is set for this item and you don't want to always get the auction value, then don't look it up either
|
Zerotorescue@74
|
352 if priceThreshold == 0 and not alwaysGetAuctionValue then
|
Zerotorescue@74
|
353 newItemData.value = -4;
|
Zerotorescue@74
|
354 end
|
Zerotorescue@74
|
355
|
Zerotorescue@74
|
356 tinsert(itemsCache[groupName], newItemData);
|
Zerotorescue@74
|
357
|
Zerotorescue@1
|
358 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
|
Zerotorescue@1
|
359 end
|
Zerotorescue@0
|
360 end
|
Zerotorescue@0
|
361
|
Zerotorescue@122
|
362 groupTimes.init = mceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
363
|
Zerotorescue@10
|
364
|
Zerotorescue@10
|
365
|
Zerotorescue@10
|
366 -- Sort items
|
Zerotorescue@122
|
367 tsort(itemsCache[groupName], function(a, b)
|
Zerotorescue@73
|
368 local aRarity = a.rarity or 1;
|
Zerotorescue@73
|
369 local bRarity = b.rarity or 1;
|
Zerotorescue@73
|
370
|
Zerotorescue@73
|
371 if sortMethod == "item" and aRarity == bRarity then
|
Zerotorescue@1
|
372 -- Do a name-compare for items of the same rarity
|
Zerotorescue@1
|
373 -- Otherwise epics first, then junk
|
Zerotorescue@73
|
374
|
Zerotorescue@106
|
375 local aName = a.name or sformat(unknownItemName, a.id);
|
Zerotorescue@106
|
376 local bName = b.name or sformat(unknownItemName, b.id);
|
Zerotorescue@73
|
377
|
Zerotorescue@0
|
378 if sortDirectory == "ASC" then
|
Zerotorescue@73
|
379 return supper(aName) < supper(bName);
|
Zerotorescue@0
|
380 else
|
Zerotorescue@73
|
381 return supper(aName) > supper(bName);
|
Zerotorescue@1
|
382 end
|
Zerotorescue@1
|
383 elseif sortMethod == "item" then
|
Zerotorescue@1
|
384 if sortDirectory == "ASC" then
|
Zerotorescue@73
|
385 return aRarity > bRarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@1
|
386 else
|
Zerotorescue@73
|
387 return aRarity < bRarity; -- the comparers were reversed because we want epics first
|
Zerotorescue@0
|
388 end
|
Zerotorescue@0
|
389 elseif sortMethod == "current" then
|
Zerotorescue@0
|
390 if sortDirectory == "ASC" then
|
Zerotorescue@74
|
391 return a.globalCount < b.globalCount;
|
Zerotorescue@0
|
392 else
|
Zerotorescue@74
|
393 return a.globalCount > b.globalCount;
|
Zerotorescue@0
|
394 end
|
Zerotorescue@50
|
395 elseif sortMethod == "local" then
|
Zerotorescue@50
|
396 if sortDirectory == "ASC" then
|
Zerotorescue@50
|
397 return a.localCount < b.localCount;
|
Zerotorescue@50
|
398 else
|
Zerotorescue@50
|
399 return a.localCount > b.localCount;
|
Zerotorescue@50
|
400 end
|
Zerotorescue@1
|
401 elseif sortMethod == "value" then
|
Zerotorescue@1
|
402 if sortDirectory == "ASC" then
|
Zerotorescue@1
|
403 return a.value < b.value;
|
Zerotorescue@1
|
404 else
|
Zerotorescue@1
|
405 return a.value > b.value;
|
Zerotorescue@1
|
406 end
|
Zerotorescue@0
|
407 end
|
Zerotorescue@0
|
408 end);
|
Zerotorescue@0
|
409
|
Zerotorescue@122
|
410 groupTimes.sorting = mceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
411
|
Zerotorescue@10
|
412
|
Zerotorescue@10
|
413
|
Zerotorescue@10
|
414
|
Zerotorescue@10
|
415 -- Show itemslist
|
Zerotorescue@1
|
416 for i, item in pairs(itemsCache[groupName]) do
|
Zerotorescue@31
|
417 -- Go through all items for this group
|
Zerotorescue@31
|
418
|
Zerotorescue@74
|
419 if (( item.globalCount / minGlobalStock ) < showWhenBelow or ( item.localCount / minLocalStock ) < showWhenBelow) and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then
|
Zerotorescue@31
|
420 -- if the option "hide when below threshold" is disabled or no price threshold is set or the value is above the price threshold or the value could not be determined, proceed
|
Zerotorescue@62
|
421
|
Zerotorescue@0
|
422 local btnItemLink = AceGUI:Create("ItemLinkButton");
|
Zerotorescue@23
|
423 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
|
Zerotorescue@23
|
424 local itemName, itemLink = GetItemInfo(itemId);
|
Zerotorescue@23
|
425
|
Zerotorescue@23
|
426 if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then
|
Zerotorescue@23
|
427 ChatEdit_InsertLink(itemLink);
|
Zerotorescue@23
|
428 elseif buttonName == "LeftButton" and IsAltKeyDown() and itemName and AuctionFrame and AuctionFrame:IsShown() and AuctionFrameBrowse then
|
Zerotorescue@23
|
429 -- Start search at page 0
|
Zerotorescue@23
|
430 AuctionFrameBrowse.page = 0;
|
Zerotorescue@23
|
431
|
Zerotorescue@23
|
432 -- Set the search field (even though we could use "ChatEdit_InsertLink", this ensures the right field is updated)
|
Zerotorescue@23
|
433 BrowseName:SetText(itemName)
|
Zerotorescue@23
|
434
|
Zerotorescue@23
|
435 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
|
Zerotorescue@23
|
436 end
|
Zerotorescue@23
|
437 end);
|
Zerotorescue@57
|
438 btnItemLink:SetRelativeWidth(.7);
|
Zerotorescue@73
|
439 btnItemLink:SetItem(item);
|
Zerotorescue@0
|
440
|
Zerotorescue@0
|
441 iGroup:AddChild(btnItemLink);
|
Zerotorescue@0
|
442
|
Zerotorescue@50
|
443 -- Local quantity
|
Zerotorescue@50
|
444 local lblLocal = AceGUI:Create("Label");
|
Zerotorescue@106
|
445 lblLocal:SetText(addon:DisplayItemCount(item.localCount, minLocalStock));
|
Zerotorescue@50
|
446 lblLocal:SetRelativeWidth(.099);
|
Zerotorescue@50
|
447
|
Zerotorescue@50
|
448 iGroup:AddChild(lblLocal);
|
Zerotorescue@50
|
449
|
Zerotorescue@0
|
450 -- Current quantity
|
Zerotorescue@0
|
451 local lblQuantity = AceGUI:Create("Label");
|
Zerotorescue@106
|
452 lblQuantity:SetText(addon:DisplayItemCount(item.globalCount, minGlobalStock));
|
Zerotorescue@10
|
453 lblQuantity:SetRelativeWidth(.099);
|
Zerotorescue@0
|
454
|
Zerotorescue@0
|
455 iGroup:AddChild(lblQuantity);
|
Zerotorescue@0
|
456
|
Zerotorescue@1
|
457 -- Value
|
Zerotorescue@1
|
458 local lblValue = AceGUI:Create("Label");
|
Zerotorescue@1
|
459 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@10
|
460 lblValue:SetRelativeWidth(.099);
|
Zerotorescue@1
|
461
|
Zerotorescue@1
|
462 iGroup:AddChild(lblValue);
|
Zerotorescue@1
|
463
|
Zerotorescue@1
|
464 -- Remember references to the value and current fields so we can fill them later
|
Zerotorescue@74
|
465 item.set.value = lblValue;
|
Zerotorescue@74
|
466 item.set.globalCount = lblQuantity;
|
Zerotorescue@74
|
467 item.set.localCount = lblLocal;
|
Zerotorescue@0
|
468 end
|
Zerotorescue@0
|
469 end
|
Zerotorescue@0
|
470
|
Zerotorescue@122
|
471 groupTimes.preparing = mceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@10
|
472
|
Zerotorescue@1
|
473 iGroup:ResumeLayout();
|
Zerotorescue@1
|
474 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
|
Zerotorescue@10
|
475
|
Zerotorescue@122
|
476 groupTimes.building = mceil( ( GetTime() - groupStartTime ) * 1000 );
|
Zerotorescue@0
|
477 end
|
Zerotorescue@10
|
478
|
Zerotorescue@13
|
479 if groupStartTime and groupTimes then
|
Zerotorescue@122
|
480 addon:Debug("Building of %s took %d ms (%d / %d / %d / %d / %d).", groupName, mceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, mceil( ( GetTime() - buildStartTime ) * 1000 ));
|
Zerotorescue@13
|
481 end
|
Zerotorescue@0
|
482 end
|
Zerotorescue@1
|
483
|
Zerotorescue@1
|
484 mod.scrollFrame:ResumeLayout();
|
Zerotorescue@1
|
485 mod.scrollFrame:DoLayout();
|
Zerotorescue@1
|
486
|
Zerotorescue@122
|
487 addon:Debug("Done building summary after %d ms.", mceil( ( GetTime() - buildStartTime ) * 1000 ));
|
Zerotorescue@10
|
488
|
Zerotorescue@1
|
489 if CACHE_ITEMS_TOTAL > 0 then
|
Zerotorescue@1
|
490 cacheStart = GetTime();
|
Zerotorescue@7
|
491 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@1
|
492 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
|
493 end
|
Zerotorescue@1
|
494 end
|
Zerotorescue@1
|
495
|
Zerotorescue@1
|
496 function mod:UpdateNextItem()
|
Zerotorescue@1
|
497 local i = 0;
|
Zerotorescue@1
|
498
|
Zerotorescue@1
|
499 for groupName, items in pairs(itemsCache) do
|
Zerotorescue@61
|
500 local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock");
|
Zerotorescue@61
|
501 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
|
Zerotorescue@1
|
502 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
|
Zerotorescue@1
|
503
|
Zerotorescue@1
|
504 for _, item in pairs(items) do
|
Zerotorescue@74
|
505 if item.globalCount == -3 or item.localCount == -3 or item.value == -3 then
|
Zerotorescue@74
|
506 if item.globalCount == -3 then
|
Zerotorescue@10
|
507 -- Only if item count was queued, update it
|
Zerotorescue@74
|
508 item.globalCount = addon:GetItemCount(item.id, groupName);
|
Zerotorescue@74
|
509 if item.set.globalCount and item.set.globalCount.SetText then
|
Zerotorescue@106
|
510 item.set.globalCount:SetText(addon:DisplayItemCount(item.globalCount, minGlobalStock));
|
Zerotorescue@10
|
511 end
|
Zerotorescue@1
|
512 end
|
Zerotorescue@1
|
513
|
Zerotorescue@50
|
514 if item.localCount == -3 then
|
Zerotorescue@50
|
515 -- Only if item count was queued, update it
|
Zerotorescue@54
|
516 item.localCount = addon:GetLocalItemCount(item.id, groupName);
|
Zerotorescue@50
|
517 if item.set.localCount and item.set.localCount.SetText then
|
Zerotorescue@106
|
518 item.set.localCount:SetText(addon:DisplayItemCount(item.localCount, minLocalStock));
|
Zerotorescue@50
|
519 end
|
Zerotorescue@50
|
520 end
|
Zerotorescue@50
|
521
|
Zerotorescue@10
|
522 if item.value == -3 then
|
Zerotorescue@10
|
523 -- Only if item value was queued, update it
|
Zerotorescue@23
|
524
|
Zerotorescue@23
|
525 -- The itemlink might not have been loaded yet in which case we retry
|
Zerotorescue@23
|
526 item.link = item.link or select(2, GetItemInfo(item.id));
|
Zerotorescue@23
|
527
|
Zerotorescue@23
|
528 if item.link then
|
Zerotorescue@23
|
529 item.value = addon:GetAuctionValue(item.link, groupName);
|
Zerotorescue@23
|
530 if item.set.value and item.set.value.SetText then
|
Zerotorescue@23
|
531 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
|
Zerotorescue@23
|
532 end
|
Zerotorescue@10
|
533 end
|
Zerotorescue@1
|
534 end
|
Zerotorescue@1
|
535
|
Zerotorescue@1
|
536 i = i + 1;
|
Zerotorescue@1
|
537 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
|
Zerotorescue@1
|
538
|
Zerotorescue@9
|
539 if mod.frame then
|
Zerotorescue@122
|
540 mod.frame:SetStatusText(sformat("Caching auction values and item-counts... %d%% has already been processed.", mfloor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
|
Zerotorescue@9
|
541 end
|
Zerotorescue@1
|
542
|
Zerotorescue@61
|
543 if i >= addon.db.profile.defaults.summary.speed then
|
Zerotorescue@1
|
544 return;
|
Zerotorescue@1
|
545 end
|
Zerotorescue@1
|
546 end
|
Zerotorescue@1
|
547 end
|
Zerotorescue@1
|
548 end
|
Zerotorescue@1
|
549
|
Zerotorescue@1
|
550 -- Reset trackers
|
Zerotorescue@1
|
551 CACHE_ITEMS_TOTAL = 0;
|
Zerotorescue@1
|
552 CACHE_ITEMS_CURRENT = 0;
|
Zerotorescue@1
|
553
|
Zerotorescue@1
|
554 -- Stop timer
|
Zerotorescue@1
|
555 self:CancelTimer(self.tmrUpdater, true);
|
Zerotorescue@10
|
556
|
Zerotorescue@10
|
557 -- Rebuild list so hidden items due to too low prices get added
|
Zerotorescue@10
|
558 self:Build();
|
Zerotorescue@1
|
559
|
Zerotorescue@1
|
560 -- Announce
|
Zerotorescue@122
|
561 mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. mceil(GetTime() - cacheStart) .. " seconds.");
|
Zerotorescue@1
|
562
|
Zerotorescue@1
|
563 -- Forget time
|
Zerotorescue@1
|
564 cacheStart = nil;
|
Zerotorescue@0
|
565 end
|
Zerotorescue@0
|
566
|
Zerotorescue@1
|
567 function mod:DisplayMoney(value, priceThreshold)
|
Zerotorescue@7
|
568 if value == -1 then
|
Zerotorescue@7
|
569 return "|cff0000ffNone up|r";
|
Zerotorescue@7
|
570 elseif value == -2 then
|
Zerotorescue@7
|
571 return "|cff0000ffNo AH mod|r";
|
Zerotorescue@9
|
572 elseif value == -3 then
|
Zerotorescue@9
|
573 return "|cffffff00Unknown|r";
|
Zerotorescue@13
|
574 elseif value == -4 then
|
Zerotorescue@13
|
575 return "|cff00ff00-|r";
|
Zerotorescue@23
|
576 elseif value == -5 then
|
Zerotorescue@23
|
577 return "|cffff9933Error|r";
|
Zerotorescue@23
|
578 elseif priceThreshold and value < priceThreshold then
|
Zerotorescue@106
|
579 return sformat("|cffaaaaaa%s|r", sgsub(addon:ReadableMoney(value or 0, true), "|([a-fA-F0-9]+)([gsc]+)|r", "%2"));
|
Zerotorescue@1
|
580 else
|
Zerotorescue@1
|
581 return addon:ReadableMoney(value or 0, true);
|
Zerotorescue@1
|
582 end
|
Zerotorescue@1
|
583 end
|
Zerotorescue@1
|
584
|
Zerotorescue@0
|
585 function mod:NumberFormat(num)
|
Zerotorescue@62
|
586 local formatted = sgsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
|
Zerotorescue@122
|
587 local matches;
|
Zerotorescue@0
|
588
|
Zerotorescue@0
|
589 while true do
|
Zerotorescue@62
|
590 formatted, matches = sgsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);
|
Zerotorescue@0
|
591
|
Zerotorescue@0
|
592 if matches == 0 then
|
Zerotorescue@0
|
593 break;
|
Zerotorescue@0
|
594 end
|
Zerotorescue@0
|
595 end
|
Zerotorescue@0
|
596
|
Zerotorescue@0
|
597 return formatted;
|
Zerotorescue@1
|
598 end
|