comparison Summary.lua @ 9:3bac0bdd59e2

Close the summary frame when opening the config. Remove ?track at? data when exporting/importing a group. Don?t add items when importing a group that are already inside a group.
author Zerotorescue
date Sun, 10 Oct 2010 04:37:21 +0200
parents 1a815139e4c3
children c4d0e5d47e10
comparison
equal deleted inserted replaced
8:1f30a9ac9027 9:3bac0bdd59e2
70 -- Main Window 70 -- Main Window
71 mod.frame = AceGUI:Create("Frame"); 71 mod.frame = AceGUI:Create("Frame");
72 mod.frame:SetTitle("Inventory Summary"); 72 mod.frame:SetTitle("Inventory Summary");
73 mod.frame:SetLayout("Fill"); 73 mod.frame:SetLayout("Fill");
74 mod.frame:SetCallback("OnClose", function(widget) 74 mod.frame:SetCallback("OnClose", function(widget)
75 AceGUI:Release(widget);
76 mod:CancelTimer(self.tmrUpdater, true); 75 mod:CancelTimer(self.tmrUpdater, true);
76 mod:CloseFrame();
77 end); 77 end);
78 78
79 -- ScrollFrame child 79 -- ScrollFrame child
80 mod.scrollFrame = AceGUI:Create("ScrollFrame"); 80 mod.scrollFrame = AceGUI:Create("ScrollFrame");
81 mod.scrollFrame:SetLayout("Flow"); 81 mod.scrollFrame:SetLayout("Flow");
82 82
83 mod.frame:AddChild(mod.scrollFrame); 83 mod.frame:AddChild(mod.scrollFrame);
84 84
85 -- Reset items cache 85 -- Reset items cache
86 table.wipe(itemsCache); 86 table.wipe(itemsCache);
87 end
88
89 function mod:CloseFrame()
90 if mod.frame then
91 mod.frame:Release();
92 mod.frame = nil;
93 end
87 end 94 end
88 95
89 local sortMethod = "item"; 96 local sortMethod = "item";
90 local sortDirectory = "ASC"; 97 local sortDirectory = "ASC";
91 local function ReSort(subject) 98 local function ReSort(subject)
115 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters)); 122 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
116 123
117 -- Does this group have any items and do we want to track it at this char? 124 -- Does this group have any items and do we want to track it at this char?
118 if values.items and trackAt[playerName] then 125 if values.items and trackAt[playerName] then
119 -- Get group settings 126 -- Get group settings
120 local stockRequired = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock)); 127 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
121 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow)); 128 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
122 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold)); 129 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
123 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold)); 130 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
124 131
125 -- Make group container 132 -- Make group container
155 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end); 162 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
156 163
157 iGroup:AddChild(lblQuantity); 164 iGroup:AddChild(lblQuantity);
158 165
159 -- Required stock 166 -- Required stock
160 local lblStockRequired = AceGUI:Create("InteractiveLabel"); 167 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
161 lblStockRequired:SetText("|cfffed000Req.|r"); 168 lblMinimumStock:SetText("|cfffed000Req.|r");
162 lblStockRequired:SetFontObject(GameFontHighlight); 169 lblMinimumStock:SetFontObject(GameFontHighlight);
163 lblStockRequired:SetRelativeWidth(0.099); 170 lblMinimumStock:SetRelativeWidth(0.099);
164 lblStockRequired:SetCallback("OnClick", function() ReSort("percentage"); end); 171 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
165 172
166 iGroup:AddChild(lblStockRequired); 173 iGroup:AddChild(lblMinimumStock);
167 174
168 -- Lowest value 175 -- Lowest value
169 local lblValue = AceGUI:Create("InteractiveLabel"); 176 local lblValue = AceGUI:Create("InteractiveLabel");
170 lblValue:SetText("|cfffed000Value|r"); 177 lblValue:SetText("|cfffed000Value|r");
171 lblValue:SetFontObject(GameFontHighlight); 178 lblValue:SetFontObject(GameFontHighlight);
183 190
184 table.insert(itemsCache[groupName], { 191 table.insert(itemsCache[groupName], {
185 id = itemId, 192 id = itemId,
186 name = itemName, 193 name = itemName,
187 link = itemLink, 194 link = itemLink,
188 value = 0,--addon:GetAuctionValue(itemLink), 195 value = -3,--addon:GetAuctionValue(itemLink),
189 rarity = itemRarity, 196 rarity = itemRarity,
190 count = 0,--addon:GetItemCount(itemId), 197 count = -3,--addon:GetItemCount(itemId),
191 set = {}, 198 set = {},
192 }); 199 });
193 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; 200 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
194 end 201 end
195 end 202 end
215 else 222 else
216 return a.count > b.count; 223 return a.count > b.count;
217 end 224 end
218 elseif sortMethod == "percentage" then 225 elseif sortMethod == "percentage" then
219 if sortDirectory == "ASC" then 226 if sortDirectory == "ASC" then
220 return ( a.count / stockRequired ) < ( b.count / stockRequired ); 227 return ( a.count / lblMinimumStock ) < ( b.count / lblMinimumStock );
221 else 228 else
222 return ( a.count / stockRequired ) > ( b.count / stockRequired ); 229 return ( a.count / lblMinimumStock ) > ( b.count / lblMinimumStock );
223 end 230 end
224 elseif sortMethod == "value" then 231 elseif sortMethod == "value" then
225 if sortDirectory == "ASC" then 232 if sortDirectory == "ASC" then
226 return a.value < b.value; 233 return a.value < b.value;
227 else 234 else
230 end 237 end
231 end); 238 end);
232 239
233 -- Show stuff 240 -- Show stuff
234 for i, item in pairs(itemsCache[groupName]) do 241 for i, item in pairs(itemsCache[groupName]) do
235 if ( item.count / stockRequired ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then 242 if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
236 local btnItemLink = AceGUI:Create("ItemLinkButton"); 243 local btnItemLink = AceGUI:Create("ItemLinkButton");
237 btnItemLink:SetUserData("exec", function() 244 btnItemLink:SetUserData("exec", function()
238 print("Win."); 245 print("Win.");
239 end); 246 end);
240 btnItemLink:SetRelativeWidth(0.7); 247 btnItemLink:SetRelativeWidth(0.7);
242 249
243 iGroup:AddChild(btnItemLink); 250 iGroup:AddChild(btnItemLink);
244 251
245 -- Current quantity 252 -- Current quantity
246 local lblQuantity = AceGUI:Create("Label"); 253 local lblQuantity = AceGUI:Create("Label");
247 lblQuantity:SetText(self:ColorCode(item.count, stockRequired)); 254 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
248 lblQuantity:SetRelativeWidth(0.099); 255 lblQuantity:SetRelativeWidth(0.099);
249 256
250 iGroup:AddChild(lblQuantity); 257 iGroup:AddChild(lblQuantity);
251 258
252 -- Required stock 259 -- Required stock
253 local lblStockRequired = AceGUI:Create("Label"); 260 local lblMinimumStock = AceGUI:Create("Label");
254 lblStockRequired:SetText(stockRequired); 261 lblMinimumStock:SetText(minimumStock);
255 lblStockRequired:SetRelativeWidth(0.099); 262 lblMinimumStock:SetRelativeWidth(0.099);
256 263
257 iGroup:AddChild(lblStockRequired); 264 iGroup:AddChild(lblMinimumStock);
258 265
259 -- Value 266 -- Value
260 local lblValue = AceGUI:Create("Label"); 267 local lblValue = AceGUI:Create("Label");
261 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold)); 268 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
262 lblValue:SetRelativeWidth(0.099); 269 lblValue:SetRelativeWidth(0.099);
290 local i = 0; 297 local i = 0;
291 298
292 for groupName, items in pairs(itemsCache) do 299 for groupName, items in pairs(itemsCache) do
293 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock"); 300 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
294 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); 301 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
302 local groupUpdated;
295 303
296 for _, item in pairs(items) do 304 for _, item in pairs(items) do
297 if item.set then 305 if item.set then
298 item.count = addon:GetItemCount(item.id); 306 item.count = addon:GetItemCount(item.id);
299 if item.set.current then 307 if item.set.current and item.set.current.SetText then
300 item.set.current:SetText(self:ColorCode(item.count, minimumStock)); 308 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
301 end 309 end
302 310
303 item.value = addon:GetAuctionValue(item.link); 311 item.value = addon:GetAuctionValue(item.link);
304 if item.set.value then 312 if item.set.value and item.set.value.SetText then
305 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold)); 313 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
306 end 314 end
307 315
308 item.set = nil; 316 item.set = nil;
309 317
310 i = i + 1; 318 i = i + 1;
311 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1; 319 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
312 320 groupUpdated = true;
313 mod.frame:SetStatusText(("Caching auction values and item-counts... %d% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100))); 321
322 if mod.frame then
323 mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
324 end
314 325
315 if i >= CACHE_ITEMS_PER_UPDATE then 326 if i >= CACHE_ITEMS_PER_UPDATE then
316 return; 327 return;
317 end 328 end
318 end 329 end
330 end
331
332 if groupUpdated then
333 -- Rebuild list so hidden items due to too low prices get added
334 self:Build();
319 end 335 end
320 end 336 end
321 337
322 -- Reset trackers 338 -- Reset trackers
323 CACHE_ITEMS_TOTAL = 0; 339 CACHE_ITEMS_TOTAL = 0;
324 CACHE_ITEMS_CURRENT = 0; 340 CACHE_ITEMS_CURRENT = 0;
325
326 -- Rebuild list so hidden items due to too low prices get added
327 self:Build();
328 341
329 -- Stop timer 342 -- Stop timer
330 self:CancelTimer(self.tmrUpdater, true); 343 self:CancelTimer(self.tmrUpdater, true);
331 344
332 -- Announce 345 -- Announce
353 function mod:DisplayMoney(value, priceThreshold) 366 function mod:DisplayMoney(value, priceThreshold)
354 if value == -1 then 367 if value == -1 then
355 return "|cff0000ffNone up|r"; 368 return "|cff0000ffNone up|r";
356 elseif value == -2 then 369 elseif value == -2 then
357 return "|cff0000ffNo AH mod|r"; 370 return "|cff0000ffNo AH mod|r";
371 elseif value == -3 then
372 return "|cffffff00Unknown|r";
358 elseif value < priceThreshold then 373 elseif value < priceThreshold then
359 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true)); 374 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
360 else 375 else
361 return addon:ReadableMoney(value or 0, true); 376 return addon:ReadableMoney(value or 0, true);
377 end
378 end
379
380 function mod:DisplayItemCount(value, minimumStock)
381 if value == -3 then
382 return "|cffffff00Unknown|r";
383 else
384 return self:ColorCode(value, minimumStock);
362 end 385 end
363 end 386 end
364 387
365 function mod:NumberFormat(num) 388 function mod:NumberFormat(num)
366 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1); 389 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);