Mercurial > wow > inventory
changeset 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 | 51d85a84b40c |
children | 55515004032b |
files | Core.lua ItemCountAddons/Altoholic.lua ItemCountAddons/ItemCount.lua Summary.lua |
diffstat | 4 files changed, 141 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Fri Dec 17 00:51:00 2010 +0100 +++ b/Core.lua Sat Dec 18 00:22:06 2010 +0100 @@ -649,7 +649,13 @@ return temp; end, get = function() return self.db.global.defaults.itemCountAddon; end, - set = function(i, v) self.db.global.defaults.itemCountAddon = v; end, + set = function(i, v) + self.db.global.defaults.itemCountAddon = v; + + if self.supportedAddons.itemCount[v].OnSelect then + self.supportedAddons.itemCount[v].OnSelect(); + end + end, }, craftingAddon = { order = 30, @@ -665,9 +671,15 @@ return temp; end, get = function() return self.db.global.defaults.craftingAddon; end, - set = function(i, v) self.db.global.defaults.craftingAddon = v; end, + set = function(i, v) + self.db.global.defaults.craftingAddon = v; + + if self.supportedAddons.crafting[v].OnSelect then + self.supportedAddons.crafting[v].OnSelect(); + end + end, }, - --[[localItemData = { + localItemData = { order = 40, type = "multiselect", name = "Include in local item data", @@ -681,7 +693,7 @@ get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end, set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end, --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. - },]] + }, }, }, minimumStock = { @@ -716,8 +728,8 @@ order = 20, type = "range", min = 0, - max = 100, - softMax = 10, + max = 10, + softMax = 100, step = 0.05, isPercent = true, name = "Show in summary when below", @@ -1280,6 +1292,16 @@ return temp; end, + set = function(info, value) + local groupName = groupIdToName[info[2]]; + local optionName = info[#info]; + + addon.db.global.groups[groupName][optionName] = value ~= "" and value; + + if addon.supportedAddons.itemCount[value].OnSelect then + addon.supportedAddons.itemCount[value].OnSelect(); + end + end, arg = "overrideItemCountAddon", }, overrideCraftingAddon = { @@ -1302,9 +1324,19 @@ return temp; end, + set = function(info, value) + local groupName = groupIdToName[info[2]]; + local optionName = info[#info]; + + addon.db.global.groups[groupName][optionName] = value ~= "" and value; + + if addon.supportedAddons.crafting[value].OnSelect then + addon.supportedAddons.crafting[value].OnSelect(); + end + end, arg = "overrideCraftingAddon", }, - --[[overrideLocalItemData = { + overrideLocalItemData = { order = 39, type = "toggle", name = "Override local item data", @@ -1325,7 +1357,7 @@ get = GetMultiOption, --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. arg = "overrideLocalItemData", - },]] + }, virtualGroup = { order = 50, type = "select", @@ -1403,8 +1435,8 @@ order = 20, type = "range", min = 0, - max = 100, - softMax = 10, + max = 10, + softMax = 100, step = 0.05, isPercent = true, name = "Show in summary when below", @@ -2192,6 +2224,38 @@ return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1; end +function addon:GetLocalItemCount(itemId, group) + itemId = tonumber(itemId); + + if not itemId then return; end + + local itemCountAddon = self:GetItemCountAddon(group); + + local currentItemCount; + + if itemCountAddon and itemCountAddon.GetCharacterCount then + local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId); + + local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData"); + + currentItemCount = 0; + if selectedLocalItemCountSources["Bag"] then + currentItemCount = currentItemCount + bag; + end + if selectedLocalItemCountSources["Bank"] then + currentItemCount = currentItemCount + bank; + end + if selectedLocalItemCountSources["Auction House"] then + currentItemCount = currentItemCount + auctionHouse; + end + if selectedLocalItemCountSources["Mailbox"] then + currentItemCount = currentItemCount + mail; + end + end + + return currentItemCount or -1; +end + function addon:GetAuctionValue(itemLink, group) if not itemLink then return -5; end @@ -2226,18 +2290,20 @@ }; end -function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled) +function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect) addon.supportedAddons.itemCount[name] = { GetTotalCount = getTotal, GetCharacterCount = getCharacter, IsEnabled = enabled, + OnSelect = onSelect, }; end -function IMRegisterCraftingAddon(name, queue, enabled) +function IMRegisterCraftingAddon(name, queue, enabled, onSelect) addon.supportedAddons.crafting[name] = { Queue = queue, IsEnabled = enabled, + OnSelect = onSelect, }; end
--- a/ItemCountAddons/Altoholic.lua Fri Dec 17 00:51:00 2010 +0100 +++ b/ItemCountAddons/Altoholic.lua Sat Dec 18 00:22:06 2010 +0100 @@ -8,6 +8,12 @@ return (Altoholic and Altoholic.GetItemCount); end + local function OnSelect() + local addonName = "|r|cfffed000Altoholic|r|cffff6600"; + + print("|cffff6600Note: " .. addonName .. " can not provide local item data.|r"); + end + IMRegisterItemCountAddon("Altoholic", GetTotalCount, nil, IsEnabled); end
--- a/ItemCountAddons/ItemCount.lua Fri Dec 17 00:51:00 2010 +0100 +++ b/ItemCountAddons/ItemCount.lua Sat Dec 18 00:22:06 2010 +0100 @@ -12,6 +12,12 @@ return (ICGetItemCountTotal and ICGetItemCountCharacter); end - IMRegisterItemCountAddon("ItemCount", GetTotalCount, GetCharacterCount, IsEnabled); + local function OnSelect() + local addonName = "|r|cfffed000ItemCount|r|cffff6600"; + + print("|cffff6600Note: " .. addonName .. " can't record mailbox item data and thus this will not be included in any item counts.|r"); + end + + IMRegisterItemCountAddon("ItemCount", GetTotalCount, GetCharacterCount, IsEnabled, OnSelect); end
--- a/Summary.lua Fri Dec 17 00:51:00 2010 +0100 +++ b/Summary.lua Sat Dec 18 00:22:06 2010 +0100 @@ -268,18 +268,19 @@ for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do local groupStartTime, groupTimes = GetTime(), {}; - local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters)); + local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters"); + -- Does this group have any items and do we want to track it at this char? if values.items and trackAt[playerName] then -- Get group settings - local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock)); - local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow)); - local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold)); - local hideWhenBelowPriceThreshold = (values.summaryHidePriceThreshold or (values.summaryHidePriceThreshold == nil and addon.db.global.defaults.summaryHidePriceThreshold)); - local alwaysGetAuctionValue = (values.alwaysGetAuctionValue or (values.alwaysGetAuctionValue == nil and addon.db.global.defaults.alwaysGetAuctionValue)); + local minimumStock = addon:GetOptionByKey(groupName, "minimumStock"); + local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow"); + local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); + local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold"); + local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue"); -- Make group container local iGroup = AceGUI:Create("InlineGroupWithButton"); @@ -304,7 +305,7 @@ local lblItem = AceGUI:Create("InteractiveLabel"); lblItem:SetText("|cfffed000Item|r"); lblItem:SetFontObject(GameFontHighlight); - lblItem:SetRelativeWidth(.7); + lblItem:SetRelativeWidth(.6); lblItem:SetCallback("OnClick", function() ReSort("item"); end); lblItem:SetCallback("OnEnter", ShowTooltip); lblItem:SetCallback("OnLeave", HideTooltip); @@ -313,6 +314,19 @@ iGroup:AddChild(lblItem); + -- Local quantity + local lblLocal = AceGUI:Create("InteractiveLabel"); + lblLocal:SetText("|cfffed000Loc.|r"); + lblLocal:SetFontObject(GameFontHighlight); + lblLocal:SetRelativeWidth(.099); + lblLocal:SetCallback("OnClick", function() ReSort("local"); end); + lblLocal:SetCallback("OnEnter", ShowTooltip); + lblLocal:SetCallback("OnLeave", HideTooltip); + lblLocal.frame.tooltipTitle = "Local stock"; + lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock."; + + iGroup:AddChild(lblLocal); + -- Current quantity local lblQuantity = AceGUI:Create("InteractiveLabel"); lblQuantity:SetText("|cfffed000Cur.|r"); @@ -326,19 +340,6 @@ iGroup:AddChild(lblQuantity); - -- Local quantity - --[[local lblLocal = AceGUI:Create("InteractiveLabel"); - lblLocal:SetText("|cfffed000Loc.|r"); - lblLocal:SetFontObject(GameFontHighlight); - lblLocal:SetRelativeWidth(.099); - lblLocal:SetCallback("OnClick", function() ReSort("current"); end); - lblLocal:SetCallback("OnEnter", ShowTooltip); - lblLocal:SetCallback("OnLeave", HideTooltip); - lblLocal.frame.tooltipTitle = "Local stock"; - lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock."; - - iGroup:AddChild(lblLocal);]] - -- Required stock local lblMinimumStock = AceGUI:Create("InteractiveLabel"); lblMinimumStock:SetText("|cfffed000Min.|r"); @@ -381,7 +382,7 @@ 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), rarity = itemRarity or 1, count = -3,--addon:GetItemCount(itemId, groupName), - --localCount = -3, + localCount = -3, set = {}, }); CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; @@ -414,6 +415,12 @@ else return a.count > b.count; end + elseif sortMethod == "local" then + if sortDirectory == "ASC" then + return a.localCount < b.localCount; + else + return a.localCount > b.localCount; + end elseif sortMethod == "percentage" then if sortDirectory == "ASC" then return ( a.count / minimumStock ) < ( b.count / minimumStock ); @@ -438,8 +445,9 @@ for i, item in pairs(itemsCache[groupName]) do -- Go through all items for this group - if ( item.count / minimumStock ) < showWhenBelow and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then + 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 -- 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 + local btnItemLink = AceGUI:Create("ItemLinkButton"); btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName) local itemName, itemLink = GetItemInfo(itemId); @@ -456,11 +464,18 @@ QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0); end end); - btnItemLink:SetRelativeWidth(.7); + btnItemLink:SetRelativeWidth(.6); btnItemLink:SetItemId(item.id); iGroup:AddChild(btnItemLink); + -- Local quantity + local lblLocal = AceGUI:Create("Label"); + lblLocal:SetText(self:DisplayItemCount(item.localCount, minimumStock)); + lblLocal:SetRelativeWidth(.099); + + iGroup:AddChild(lblLocal); + -- Current quantity local lblQuantity = AceGUI:Create("Label"); lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock)); @@ -468,13 +483,6 @@ iGroup:AddChild(lblQuantity); - -- Local quantity - --[[local lblLocal = AceGUI:Create("Label"); - lblLocal:SetText(self:DisplayItemCount(item.count, minimumStock)); - lblLocal:SetRelativeWidth(.099); - - iGroup:AddChild(lblLocal);]] - -- Required stock local lblMinimumStock = AceGUI:Create("Label"); lblMinimumStock:SetText(minimumStock); @@ -498,9 +506,12 @@ if item.count == -3 then item.set.current = lblQuantity; end + if item.localCount == -3 then + item.set.localCount = lblLocal; + end -- Don't queue if we already know everything we want to know - if item.value ~= -3 and item.count ~= -3 then + if item.value ~= -3 and item.count ~= -3 and item.localCount ~= -3 then item.set = nil; end end @@ -549,6 +560,14 @@ end end + if item.localCount == -3 then + -- Only if item count was queued, update it + item.localCount = addon:GetItemCount(item.id, groupName); + if item.set.localCount and item.set.localCount.SetText then + item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minimumStock)); + end + end + if item.value == -3 then -- Only if item value was queued, update it