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