comparison Core.lua @ 13:5006cb0e97c6

Removed sound media registrations since we don?t use them. Added an option to include tadeskill items above a certain item level threshold in the add items config tab. Renamed the variable for toggling hiding from summary when below price threshold-option. You will have to re-set it. Summary size and processing speed will now be remembered. Processing speed slider can now go up to 500% (up from 100%). Silver will be hidden from money when it includes more than 10 gold (down from 100g) and copper will be hidden if it includes more than 1 gold (down from 10g). Auction addons, crafting addons and itemcount addons can now register themselves through a few global functions. The most used addons have been included in the addon folder. You can now select the prefered default pricing, item count and crafting addons. Temporarily removed the ?dialogControl = ?DropDown?? from the track at select boxes. This functionality is broken within the Ace3 library and until it is fixed I wish to keep these options somewhat functional. The item list will now be truncated before rebuilding. Previously items disappearing from your inventory would still appear in this list. Mass add is now functional. All buttons and sliders that were meant to receive a tooltip (including the sort-headers), now have one. Added spacers between all buttons and sliders of the summary window. Added a ?queue all? button to the summary window. This button is not yet functional. If the value of an item is not retrieved from the auction prices database, it will appear as a dash (-) rather than ?0c?. If no item count is enabled, item counts will appear as ?Unknown? instead of breaking (or defaulting to 0).
author Zerotorescue
date Mon, 18 Oct 2010 15:26:42 +0200
parents 10a2244f7ff0
children 8f5c02113c5c
comparison
equal deleted inserted replaced
12:417c3cfb9623 13:5006cb0e97c6
1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium") 1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium")
2 local addon = LibStub("AceAddon-3.0"):NewAddon("Inventorium", "AceEvent-3.0"); 2 local addon = LibStub("AceAddon-3.0"):NewAddon("Inventorium", "AceEvent-3.0");
3 3
4 local AceGUI = LibStub("AceGUI-3.0"); 4 local AceGUI = LibStub("AceGUI-3.0");
5
6 local Media = LibStub("LibSharedMedia-3.0");
7 Media:Register("sound", "Cartoon FX", [[Sound\Doodad\Goblin_Lottery_Open03.wav]]);
8 Media:Register("sound", "Cheer", [[Sound\Event Sounds\OgreEventCheerUnique.wav]]);
9 Media:Register("sound", "Explosion", [[Sound\Doodad\Hellfire_Raid_FX_Explosion05.wav]]);
10 Media:Register("sound", "Fel Nova", [[Sound\Spells\SeepingGaseous_Fel_Nova.wav]]);
11 Media:Register("sound", "Fel Portal", [[Sound\Spells\Sunwell_Fel_PortalStand.wav]]);
12 Media:Register("sound", "Magic Click", [[Sound\interface\MagicClick.wav]]);
13 Media:Register("sound", "Rubber Ducky", [[Sound\Doodad\Goblin_Lottery_Open01.wav]]);
14 Media:Register("sound", "Shing!", [[Sound\Doodad\PortcullisActive_Closed.wav]]);
15 Media:Register("sound", "Simon Chime", [[Sound\Doodad\SimonGame_LargeBlueTree.wav]]);
16 Media:Register("sound", "Simon Error", [[Sound\Spells\SimonGame_Visual_BadPress.wav]]);
17 Media:Register("sound", "Simon Start", [[Sound\Spells\SimonGame_Visual_GameStart.wav]]);
18 Media:Register("sound", "War Drums", [[Sound\Event Sounds\Event_wardrum_ogre.wav]]);
19 Media:Register("sound", "Wham!", [[Sound\Doodad\PVP_Lordaeron_Door_Open.wav]]);
20 Media:Register("sound", "Whisper Ping", [[Sound\interface\iTellMessage.wav]]);
21 Media:Register("sound", "You Will Die!", [[Sound\Creature\CThun\CThunYouWillDIe.wav]]);
22 5
23 local AceConfigDialog, AceConfigRegistry, AceSerializer; 6 local AceConfigDialog, AceConfigRegistry, AceSerializer;
24 local groupIdToName = {}; 7 local groupIdToName = {};
25 local options = {}; 8 local options = {};
9 local includeTradeSkillItems = 500;
10
11 -- All modules must be able to retrieve our supported addons database, thus keep it public
12 addon.supportedAddons = {};
13 addon.supportedAddons.auctionPricing = {};
14 addon.supportedAddons.itemCount = {};
15 addon.supportedAddons.crafting = {};
26 16
27 function addon:OnInitialize() 17 function addon:OnInitialize()
28 self:Debug("OnInitialize"); 18 self:Debug("OnInitialize");
29 19
30 -- SAVED VARIABLES 20 -- SAVED VARIABLES
31 21
32 local defaults = { 22 local defaults = {
33 global = { 23 global = {
34 groups = {}, 24 groups = {},
35 defaults = { 25 defaults = {
26 auctionPricingAddon = "Auctioneer",
27 itemCountAddon = "Altoholic",
28 craftingAddon = "AdvancedTradeSkillWindow",
36 minimumStock = 60, 29 minimumStock = 60,
37 alertBelowMinimum = true, 30 alertBelowMinimum = true,
38 summaryThresholdShow = 10, 31 summaryThresholdShow = 10,
39 restockTarget = 60, 32 restockTarget = 60,
40 minCraftingQueue = 0.05, 33 minCraftingQueue = 0.05,
41 bonusQueue = 0.1, 34 bonusQueue = 0.1,
42 priceThreshold = 0, 35 priceThreshold = 0,
43 hideFromSummaryWhenBelowPriceThreshold = false, 36 summaryHidePriceThreshold = false,
44 trackAtCharacters = {}, 37 trackAtCharacters = {},
38 summary = {
39 speed = 5,
40 width = 650,
41 height = 600,
42 },
45 colors = { 43 colors = {
46 red = 0; 44 red = 0;
47 orange = 0.3; 45 orange = 0.3;
48 yellow = 0.6; 46 yellow = 0.6;
49 green = 0.95; 47 green = 0.95;
359 local gold = floor( copper / COPPER_PER_GOLD ); 357 local gold = floor( copper / COPPER_PER_GOLD );
360 if gold > 0 then 358 if gold > 0 then
361 text = goldText:format(text, gold); 359 text = goldText:format(text, gold);
362 end 360 end
363 361
364 if not clean or (not gold or gold < 100) then 362 if not clean or (not gold or gold < 10) then
365 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER ); 363 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
366 if silver > 0 then 364 if silver > 0 then
367 text = silverText:format(text, silver); 365 text = silverText:format(text, silver);
368 end 366 end
369 367
370 if not clean or (not gold or gold < 10) then 368 if not clean or (not gold or gold < 1) then
371 local copper = floor( copper % COPPER_PER_SILVER ); 369 local copper = floor( copper % COPPER_PER_SILVER );
372 if copper > 0 or text == "" then 370 if copper > 0 or text == "" then
373 text = copperText:format(text, copper); 371 text = copperText:format(text, copper);
374 end 372 end
375 end 373 end
426 header = { 424 header = {
427 order = 5, 425 order = 5,
428 type = "header", 426 type = "header",
429 name = "", 427 name = "",
430 }, 428 },
431 auctionAddon = { 429 auctionPricingAddon = {
432 order = 10, 430 order = 10,
433 type = "select", 431 type = "select",
434 name = "Prefered pricing addon", 432 name = "Prefered pricing addon",
435 values = { 433 desc = "Select the addon you prefer data to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
436 Auctioneer = "Auctioneer", 434 values = function()
437 Auctionator = "Auctionator", 435 local temp = {};
438 }, 436 for name, value in pairs(self.supportedAddons.auctionPricing) do
439 get = function() end, 437 temp[name] = name;
440 set = function(i, v) end, 438 end
439
440 return temp;
441 end,
442 get = function() return self.db.global.defaults.auctionPricingAddon; end,
443 set = function(i, v) self.db.global.defaults.auctionPricingAddon = v; end,
441 }, 444 },
442 itemCountAddon = { 445 itemCountAddon = {
443 order = 20, 446 order = 20,
444 type = "select", 447 type = "select",
445 name = "Prefered item count addon", 448 name = "Prefered item count addon",
446 values = { 449 desc = "Select the addon you prefer data to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
447 Altoholic = "Altoholic", 450 values = function()
448 DataStore = "DataStore", 451 local temp = {};
449 ItemCount = "ItemCount", 452 for name, value in pairs(self.supportedAddons.itemCount) do
450 }, 453 temp[name] = name;
451 get = function() end, 454 end
452 set = function(i, v) end, 455
456 return temp;
457 end,
458 get = function() return self.db.global.defaults.itemCountAddon; end,
459 set = function(i, v) self.db.global.defaults.itemCountAddon = v; end,
460 },
461 craftingAddon = {
462 order = 20,
463 type = "select",
464 name = "Prefered crafting addon",
465 desc = "Select the addon you prefer data to be queued into. A random supported addon will be used if the selected addon can not be found.",
466 values = function()
467 local temp = {};
468 for name, value in pairs(self.supportedAddons.crafting) do
469 temp[name] = name;
470 end
471
472 return temp;
473 end,
474 get = function() return self.db.global.defaults.craftingAddon; end,
475 set = function(i, v) self.db.global.defaults.craftingAddon = v; end,
453 }, 476 },
454 }, 477 },
455 }, 478 },
456 minimumStock = { 479 minimumStock = {
457 order = 10, 480 order = 10,
525 if _G['AceGUI30Pullout' .. i] then 548 if _G['AceGUI30Pullout' .. i] then
526 _G['AceGUI30Pullout' .. i]:Hide(); 549 _G['AceGUI30Pullout' .. i]:Hide();
527 end 550 end
528 end 551 end
529 end, 552 end,
530 confirm = true, 553 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
531 dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
532 }, 554 },
533 }, 555 },
534 }, 556 },
535 refill = { 557 refill = {
536 order = 20, 558 order = 20,
597 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.", 619 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.",
598 validate = function(info, value) return self:ValidateReadableMoney(info, value); end, 620 validate = function(info, value) return self:ValidateReadableMoney(info, value); end,
599 get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end, 621 get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end,
600 set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end, 622 set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end,
601 }, 623 },
602 hideFromSummaryWhenBelowPriceThreshold = { -- I wish this var could be a little bit shorter... 624 summaryHidePriceThreshold = {
603 order = 50, 625 order = 50,
604 type = "toggle", 626 type = "toggle",
605 name = "Hide when below threshold", 627 name = "Hide when below threshold",
606 desc = "Hide items from the summary when their value is below the set price threshold.", 628 desc = "Hide items from the summary when their value is below the set price threshold.",
607 get = function() return self.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold; end, 629 get = function() return self.db.global.defaults.summaryHidePriceThreshold; end,
608 set = function(i, v) self.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold = v; end, 630 set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end,
609 }, 631 },
610 }, 632 },
611 }, 633 },
612 colorCodes = { 634 colorCodes = {
613 order = 30, 635 order = 30,
857 end 879 end
858 end 880 end
859 881
860 local ref = options.args.groups.args[info[2]].args.add.args.list.args; 882 local ref = options.args.groups.args[info[2]].args.add.args.list.args;
861 883
884 -- Remaking the list, so out with the old, in with the new
885 table.wipe(ref);
886
862 -- Parse bags and show these 887 -- Parse bags and show these
863 for bagID = 4, 0, -1 do 888 for bagID = 4, 0, -1 do
864 for slot = 1, GetContainerNumSlots(bagID) do 889 for slot = 1, GetContainerNumSlots(bagID) do
865 local itemId = addon:GetItemId(GetContainerItemLink(bagID, slot)); 890 local itemId = addon:GetItemId(GetContainerItemLink(bagID, slot));
866 891
873 ref[itemId] = nil; 898 ref[itemId] = nil;
874 end 899 end
875 end 900 end
876 end 901 end
877 end 902 end
903
904 if includeTradeSkillItems ~= 500 then
905 -- Include tradeskill items
906
907 -- Go through all trade skills for the profession
908 for i = 1, GetNumTradeSkills() do
909 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
910 local itemLink = GetTradeSkillItemLink(i);
911
912 if itemLink then
913 local itemId = addon:GetItemId(itemLink);
914 if not itemId then
915 -- If this isn't an item, it can only be an enchant instead
916 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
917
918 itemId = scrollIds[itemId]; -- change enchantIds into scrollIds
919 end
920
921 local itemLevel = select(4, GetItemInfo(itemId)) or 0;
922
923 if includeTradeSkillItems == 0 or itemLevel >= includeTradeSkillItems then
924 if not items[itemId] then
925 -- If this item isn't used in any group yet
926 ref[itemId] = tblAddItemTemplate;
927 else
928 -- It's already used in a group, don't show it
929 ref[itemId] = nil;
930 end
931 end
932 end
933 end
934 end
878 end 935 end
879 936
880 local function UpdateRemoveItemList(info) 937 local function UpdateRemoveItemList(info)
881 local groupName = groupIdToName[info[2]]; 938 local groupName = groupIdToName[info[2]];
882 939
896 ref[itemId] = tblRemoveItemTemplate; 953 ref[itemId] = tblRemoveItemTemplate;
897 end 954 end
898 end 955 end
899 956
900 function addon:GetItemId(itemLink) 957 function addon:GetItemId(itemLink)
901 itemLink = itemLink and select(3, string.find(itemLink, "|Hitem:([-0-9]+):")); -- if itemLink is nil, it won't execute the second part 958 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
902 itemLink = itemLink and tonumber(itemLink); 959 itemLink = itemLink and tonumber(itemLink);
903 960
904 return itemLink; 961 return itemLink;
905 end 962 end
906 963
1016 end 1073 end
1017 1074
1018 return temp; 1075 return temp;
1019 end, 1076 end,
1020 get = GetMultiOption, 1077 get = GetMultiOption,
1021 confirm = true, 1078 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
1022 dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
1023 arg = "overrideTrackAtCharacters", 1079 arg = "overrideTrackAtCharacters",
1024 }, 1080 },
1025 }, 1081 },
1026 }, 1082 },
1027 refill = { 1083 refill = {
1119 validate = function(info, value) return addon:ValidateReadableMoney(info, value); end, 1175 validate = function(info, value) return addon:ValidateReadableMoney(info, value); end,
1120 get = function(i) return addon:ReadableMoney(GetOption(i)); end, 1176 get = function(i) return addon:ReadableMoney(GetOption(i)); end,
1121 set = function(i, v) SetOption(i, addon:ReadableMoneyToCopper(v)); end, 1177 set = function(i, v) SetOption(i, addon:ReadableMoneyToCopper(v)); end,
1122 arg = "overridePriceThreshold", 1178 arg = "overridePriceThreshold",
1123 }, 1179 },
1124 overrideHideFromSummaryWhenBelowPriceThreshold = { 1180 overrideSummaryHidePriceThreshold = {
1125 order = 49, 1181 order = 49,
1126 type = "toggle", 1182 type = "toggle",
1127 name = "Override summary showing", 1183 name = "Override summary showing",
1128 desc = "Allows you to override if items in this group should be hidden from the summary while their value is below the price threshold.", 1184 desc = "Allows you to override if items in this group should be hidden from the summary while their value is below the price threshold.",
1129 arg = "hideFromSummaryWhenBelowPriceThreshold", 1185 arg = "summaryHidePriceThreshold",
1130 }, 1186 },
1131 hideFromSummaryWhenBelowPriceThreshold = { -- I wish this var could be a little bit shorter... 1187 summaryHidePriceThreshold = {
1132 order = 50, 1188 order = 50,
1133 type = "toggle", 1189 type = "toggle",
1134 name = "Hide when below threshold", 1190 name = "Hide when below threshold",
1135 desc = "Hide items from the summary when their value is below the set price threshold.", 1191 desc = "Hide items from the summary when their value is below the set price threshold.",
1136 arg = "overrideHideFromSummaryWhenBelowPriceThreshold", 1192 arg = "overrideSummaryHidePriceThreshold",
1137 }, 1193 },
1138 }, 1194 },
1139 }, 1195 },
1140 }, 1196 },
1141 }, 1197 },
1332 massAdd = { 1388 massAdd = {
1333 order = 20, 1389 order = 20,
1334 type = "input", 1390 type = "input",
1335 name = "Add all items matching...", 1391 name = "Add all items matching...",
1336 desc = "Add every item in your inventory matching the name entered in this field. If you enter \"Glyph\" as a filter, any items in your inventory containing this in their name will be added to this group.", 1392 desc = "Add every item in your inventory matching the name entered in this field. If you enter \"Glyph\" as a filter, any items in your inventory containing this in their name will be added to this group.",
1337 --set = massAddItems, 1393 set = function(info, value)
1394 if not value then return; end
1395
1396 value = value:lower();
1397
1398 local ref = options.args.groups.args[info[2]].args.add.args.list.args;
1399
1400 for itemId, test in pairs(ref) do
1401 if test then
1402 local itemName = GetItemInfo(itemId);
1403
1404 if itemName:lower():find(value) then
1405 local groupName = groupIdToName[info[2]];
1406
1407 if not AddToGroup(groupName, itemId) then
1408 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r");
1409 end
1410 end
1411 end
1412 end
1413 end,
1338 get = false, 1414 get = false,
1415 },
1416 minItemLevel = {
1417 order = 40,
1418 type = "select",
1419 values = function()
1420 local temp = {};
1421
1422 temp[0] = "Include everything";
1423
1424 local itemLevelTemplate = "Itemlevel >= %d";
1425
1426 for i = 1, 49 do
1427 temp[( i * 10 )] = itemLevelTemplate:format(( i * 10 ));
1428 end
1429
1430 temp[500] = "Include nothing";
1431
1432 return temp;
1433 end,
1434 name = "Include tradeskill items",
1435 desc = "Include all items above this item level from the currently opened tradeskill window in the below item list.\n\nSetting this very low this might considerably slow down this config window.\n\nSet to 500 to disable showing of items completely.",
1436 set = function(i, v) includeTradeSkillItems = v; end,
1437 get = function() return includeTradeSkillItems; end,
1438 disabled = function()
1439 if GetTradeSkillLine() == "UNKNOWN" then
1440 includeTradeSkillItems = 500;
1441 return true; -- disabled
1442 else
1443 return false;
1444 end
1445 end,
1339 }, 1446 },
1340 }, 1447 },
1341 }, 1448 },
1342 list = { 1449 list = {
1343 order = 30, 1450 order = 30,
1531 count = ( count + 1 ); 1638 count = ( count + 1 );
1532 end 1639 end
1533 end 1640 end
1534 end 1641 end
1535 1642
1643
1644
1645 -- General functions used addon-wide
1646
1536 function addon:GetItemCount(itemId) 1647 function addon:GetItemCount(itemId)
1537 return Altoholic:GetItemCount(itemId); 1648 itemId = tonumber(itemId);
1538 end 1649
1539 1650 if not itemId then return; end
1540 function addon:GetAuctionValue(link) 1651
1541 if GetAuctionBuyout then 1652 if self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon] then
1542 -- Auctionator support 1653 -- Try to use the default item count addon
1543 1654
1544 local lowBuy = GetAuctionBuyout(link); 1655 return self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon].GetCount(itemId);
1656 else
1657 -- Default not available, get the first one then
1545 1658
1546 if lowBuy == nil then 1659 for name, value in pairs(self.supportedAddons.itemCount) do
1547 -- No auctions up at this time 1660 if value.IsEnabled() then
1548 return -1; 1661 return value.GetCount(itemId);
1662 end
1549 end 1663 end
1664 end
1665
1666 return -1;
1667 end
1668
1669 function addon:GetAuctionValue(itemLink)
1670 if not itemLink then return; end
1671
1672 if self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon] then
1673 -- Try to use the default auction pricing addon
1550 1674
1551 return lowBuy; 1675 return self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon].GetValue(itemLink);
1552 elseif AucAdvanced ~= nil and AucAdvanced.Modules.Util.SimpleAuction ~= nil and AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems ~= nil then 1676 else
1553 -- Auctioneer support 1677 -- Default not available, get the first one then
1554 1678
1555 local imgSeen, _, _, _, _, lowBuy, _, _ = AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(link); 1679 for name, value in pairs(self.supportedAddons.auctionPricing) do
1556 --local imgseen, image, matchBid, matchBuy, lowBid, lowBuy, aveBuy, aSeen 1680 if value.IsEnabled() then
1557 1681 return value.GetValue(itemLink);
1558 if imgSeen <= 0 then 1682 end
1559 -- No auctions up at this time
1560 return -1;
1561 end 1683 end
1562
1563 return lowBuy;
1564 end 1684 end
1565 1685
1566 return -2; 1686 return -2;
1567 end 1687 end
1568 1688
1569 1689
1570 1690
1691 -- Public
1692
1693 function IMRegisterPricingAddon(name, get, enabled)
1694 addon.supportedAddons.auctionPricing[name] = {
1695 GetValue = get,
1696 IsEnabled = enabled,
1697 };
1698 end
1699
1700 function IMRegisterItemCountAddon(name, get, enabled)
1701 addon.supportedAddons.itemCount[name] = {
1702 GetCount = get,
1703 IsEnabled = enabled,
1704 };
1705 end
1706
1707 function IMRegisterCraftingAddon(name, queue, enabled)
1708 addon.supportedAddons.crafting[name] = {
1709 Queue = queue,
1710 IsEnabled = enabled,
1711 };
1712 end
1713
1714
1715
1716 -- Debug
1571 1717
1572 function addon:Debug(t) 1718 function addon:Debug(t)
1573 if not self.debugChannel and self.debugChannel ~= false then 1719 if not self.debugChannel and self.debugChannel ~= false then
1574 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources) 1720 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources)
1575 self.debugChannel = false; 1721 self.debugChannel = false;