comparison Summary.lua @ 50:9607b3251655

Added OnSelect event support to both item count as crafting addons. Added basic local item count data support. Fixed "Show in summary when below" option to allow a value of up to 10.000%. Summary should now respect virtual groups.
author Zerotorescue
date Sat, 18 Dec 2010 00:22:06 +0100
parents 58fb38f0b447
children 06fee4208bf2
comparison
equal deleted inserted replaced
49:51d85a84b40c 50:9607b3251655
266 266
267 -- Go through all our stored groups 267 -- Go through all our stored groups
268 for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do 268 for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do
269 local groupStartTime, groupTimes = GetTime(), {}; 269 local groupStartTime, groupTimes = GetTime(), {};
270 270
271 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters)); 271 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
272
272 273
273 -- Does this group have any items and do we want to track it at this char? 274 -- Does this group have any items and do we want to track it at this char?
274 if values.items and trackAt[playerName] then 275 if values.items and trackAt[playerName] then
275 276
276 277
277 -- Get group settings 278 -- Get group settings
278 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock)); 279 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
279 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow)); 280 local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow");
280 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold)); 281 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
281 local hideWhenBelowPriceThreshold = (values.summaryHidePriceThreshold or (values.summaryHidePriceThreshold == nil and addon.db.global.defaults.summaryHidePriceThreshold)); 282 local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold");
282 local alwaysGetAuctionValue = (values.alwaysGetAuctionValue or (values.alwaysGetAuctionValue == nil and addon.db.global.defaults.alwaysGetAuctionValue)); 283 local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue");
283 284
284 -- Make group container 285 -- Make group container
285 local iGroup = AceGUI:Create("InlineGroupWithButton"); 286 local iGroup = AceGUI:Create("InlineGroupWithButton");
286 iGroup:PauseLayout(); 287 iGroup:PauseLayout();
287 iGroup:SetTitle(groupName); 288 iGroup:SetTitle(groupName);
302 303
303 -- Itemlink 304 -- Itemlink
304 local lblItem = AceGUI:Create("InteractiveLabel"); 305 local lblItem = AceGUI:Create("InteractiveLabel");
305 lblItem:SetText("|cfffed000Item|r"); 306 lblItem:SetText("|cfffed000Item|r");
306 lblItem:SetFontObject(GameFontHighlight); 307 lblItem:SetFontObject(GameFontHighlight);
307 lblItem:SetRelativeWidth(.7); 308 lblItem:SetRelativeWidth(.6);
308 lblItem:SetCallback("OnClick", function() ReSort("item"); end); 309 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
309 lblItem:SetCallback("OnEnter", ShowTooltip); 310 lblItem:SetCallback("OnEnter", ShowTooltip);
310 lblItem:SetCallback("OnLeave", HideTooltip); 311 lblItem:SetCallback("OnLeave", HideTooltip);
311 lblItem.frame.tooltipTitle = "Item"; 312 lblItem.frame.tooltipTitle = "Item";
312 lblItem.frame.tooltip = "Sort on the item quality, then name."; 313 lblItem.frame.tooltip = "Sort on the item quality, then name.";
313 314
314 iGroup:AddChild(lblItem); 315 iGroup:AddChild(lblItem);
316
317 -- Local quantity
318 local lblLocal = AceGUI:Create("InteractiveLabel");
319 lblLocal:SetText("|cfffed000Loc.|r");
320 lblLocal:SetFontObject(GameFontHighlight);
321 lblLocal:SetRelativeWidth(.099);
322 lblLocal:SetCallback("OnClick", function() ReSort("local"); end);
323 lblLocal:SetCallback("OnEnter", ShowTooltip);
324 lblLocal:SetCallback("OnLeave", HideTooltip);
325 lblLocal.frame.tooltipTitle = "Local stock";
326 lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
327
328 iGroup:AddChild(lblLocal);
315 329
316 -- Current quantity 330 -- Current quantity
317 local lblQuantity = AceGUI:Create("InteractiveLabel"); 331 local lblQuantity = AceGUI:Create("InteractiveLabel");
318 lblQuantity:SetText("|cfffed000Cur.|r"); 332 lblQuantity:SetText("|cfffed000Cur.|r");
319 lblQuantity:SetFontObject(GameFontHighlight); 333 lblQuantity:SetFontObject(GameFontHighlight);
324 lblQuantity.frame.tooltipTitle = "Current stock"; 338 lblQuantity.frame.tooltipTitle = "Current stock";
325 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock."; 339 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock.";
326 340
327 iGroup:AddChild(lblQuantity); 341 iGroup:AddChild(lblQuantity);
328 342
329 -- Local quantity
330 --[[local lblLocal = AceGUI:Create("InteractiveLabel");
331 lblLocal:SetText("|cfffed000Loc.|r");
332 lblLocal:SetFontObject(GameFontHighlight);
333 lblLocal:SetRelativeWidth(.099);
334 lblLocal:SetCallback("OnClick", function() ReSort("current"); end);
335 lblLocal:SetCallback("OnEnter", ShowTooltip);
336 lblLocal:SetCallback("OnLeave", HideTooltip);
337 lblLocal.frame.tooltipTitle = "Local stock";
338 lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
339
340 iGroup:AddChild(lblLocal);]]
341
342 -- Required stock 343 -- Required stock
343 local lblMinimumStock = AceGUI:Create("InteractiveLabel"); 344 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
344 lblMinimumStock:SetText("|cfffed000Min.|r"); 345 lblMinimumStock:SetText("|cfffed000Min.|r");
345 lblMinimumStock:SetFontObject(GameFontHighlight); 346 lblMinimumStock:SetFontObject(GameFontHighlight);
346 lblMinimumStock:SetRelativeWidth(.099); 347 lblMinimumStock:SetRelativeWidth(.099);
379 name = itemName or unknownItemName:format(itemId), 380 name = itemName or unknownItemName:format(itemId),
380 link = itemLink, 381 link = itemLink,
381 value = ((priceThreshold == 0 and not alwaysGetAuctionValue) and -4) or -3,-- if (no price threshold is set for this item and you don't want to always get auction value), then don't look it up either --addon:GetAuctionValue(itemLink), 382 value = ((priceThreshold == 0 and not alwaysGetAuctionValue) and -4) or -3,-- if (no price threshold is set for this item and you don't want to always get auction value), then don't look it up either --addon:GetAuctionValue(itemLink),
382 rarity = itemRarity or 1, 383 rarity = itemRarity or 1,
383 count = -3,--addon:GetItemCount(itemId, groupName), 384 count = -3,--addon:GetItemCount(itemId, groupName),
384 --localCount = -3, 385 localCount = -3,
385 set = {}, 386 set = {},
386 }); 387 });
387 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; 388 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
388 end 389 end
389 end 390 end
412 if sortDirectory == "ASC" then 413 if sortDirectory == "ASC" then
413 return a.count < b.count; 414 return a.count < b.count;
414 else 415 else
415 return a.count > b.count; 416 return a.count > b.count;
416 end 417 end
418 elseif sortMethod == "local" then
419 if sortDirectory == "ASC" then
420 return a.localCount < b.localCount;
421 else
422 return a.localCount > b.localCount;
423 end
417 elseif sortMethod == "percentage" then 424 elseif sortMethod == "percentage" then
418 if sortDirectory == "ASC" then 425 if sortDirectory == "ASC" then
419 return ( a.count / minimumStock ) < ( b.count / minimumStock ); 426 return ( a.count / minimumStock ) < ( b.count / minimumStock );
420 else 427 else
421 return ( a.count / minimumStock ) > ( b.count / minimumStock ); 428 return ( a.count / minimumStock ) > ( b.count / minimumStock );
436 443
437 -- Show itemslist 444 -- Show itemslist
438 for i, item in pairs(itemsCache[groupName]) do 445 for i, item in pairs(itemsCache[groupName]) do
439 -- Go through all items for this group 446 -- Go through all items for this group
440 447
441 if ( item.count / minimumStock ) < showWhenBelow and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then 448 if (( item.count / minimumStock ) < showWhenBelow or ( item.localCount / minimumStock ) < showWhenBelow) and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then
442 -- 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 449 -- 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
450
443 local btnItemLink = AceGUI:Create("ItemLinkButton"); 451 local btnItemLink = AceGUI:Create("ItemLinkButton");
444 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName) 452 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
445 local itemName, itemLink = GetItemInfo(itemId); 453 local itemName, itemLink = GetItemInfo(itemId);
446 454
447 if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then 455 if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then
454 BrowseName:SetText(itemName) 462 BrowseName:SetText(itemName)
455 463
456 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0); 464 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
457 end 465 end
458 end); 466 end);
459 btnItemLink:SetRelativeWidth(.7); 467 btnItemLink:SetRelativeWidth(.6);
460 btnItemLink:SetItemId(item.id); 468 btnItemLink:SetItemId(item.id);
461 469
462 iGroup:AddChild(btnItemLink); 470 iGroup:AddChild(btnItemLink);
471
472 -- Local quantity
473 local lblLocal = AceGUI:Create("Label");
474 lblLocal:SetText(self:DisplayItemCount(item.localCount, minimumStock));
475 lblLocal:SetRelativeWidth(.099);
476
477 iGroup:AddChild(lblLocal);
463 478
464 -- Current quantity 479 -- Current quantity
465 local lblQuantity = AceGUI:Create("Label"); 480 local lblQuantity = AceGUI:Create("Label");
466 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock)); 481 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
467 lblQuantity:SetRelativeWidth(.099); 482 lblQuantity:SetRelativeWidth(.099);
468 483
469 iGroup:AddChild(lblQuantity); 484 iGroup:AddChild(lblQuantity);
470
471 -- Local quantity
472 --[[local lblLocal = AceGUI:Create("Label");
473 lblLocal:SetText(self:DisplayItemCount(item.count, minimumStock));
474 lblLocal:SetRelativeWidth(.099);
475
476 iGroup:AddChild(lblLocal);]]
477 485
478 -- Required stock 486 -- Required stock
479 local lblMinimumStock = AceGUI:Create("Label"); 487 local lblMinimumStock = AceGUI:Create("Label");
480 lblMinimumStock:SetText(minimumStock); 488 lblMinimumStock:SetText(minimumStock);
481 lblMinimumStock:SetRelativeWidth(.099); 489 lblMinimumStock:SetRelativeWidth(.099);
496 item.set.value = lblValue; 504 item.set.value = lblValue;
497 end 505 end
498 if item.count == -3 then 506 if item.count == -3 then
499 item.set.current = lblQuantity; 507 item.set.current = lblQuantity;
500 end 508 end
509 if item.localCount == -3 then
510 item.set.localCount = lblLocal;
511 end
501 512
502 -- Don't queue if we already know everything we want to know 513 -- Don't queue if we already know everything we want to know
503 if item.value ~= -3 and item.count ~= -3 then 514 if item.value ~= -3 and item.count ~= -3 and item.localCount ~= -3 then
504 item.set = nil; 515 item.set = nil;
505 end 516 end
506 end 517 end
507 end 518 end
508 end 519 end
544 if item.count == -3 then 555 if item.count == -3 then
545 -- Only if item count was queued, update it 556 -- Only if item count was queued, update it
546 item.count = addon:GetItemCount(item.id, groupName); 557 item.count = addon:GetItemCount(item.id, groupName);
547 if item.set.current and item.set.current.SetText then 558 if item.set.current and item.set.current.SetText then
548 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock)); 559 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
560 end
561 end
562
563 if item.localCount == -3 then
564 -- Only if item count was queued, update it
565 item.localCount = addon:GetItemCount(item.id, groupName);
566 if item.set.localCount and item.set.localCount.SetText then
567 item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minimumStock));
549 end 568 end
550 end 569 end
551 570
552 if item.value == -3 then 571 if item.value == -3 then
553 -- Only if item value was queued, update it 572 -- Only if item value was queued, update it