# HG changeset patch # User Zerotorescue # Date 1293224111 -3600 # Node ID 8d11fc88ecab6f6222e6912c25359daee9bc5e5e # Parent 6216b754350d854b6685814df5a28c0d73a3fcbe Default summary width is now 700 pixels (up from 650). Changed the item data table into a class which is now also used at the custom widgets. diff -r 6216b754350d -r 8d11fc88ecab Core.lua --- a/Core.lua Fri Dec 24 16:10:20 2010 +0100 +++ b/Core.lua Fri Dec 24 21:55:11 2010 +0100 @@ -50,7 +50,7 @@ }, summary = { speed = 5, - width = 650, + width = 700, height = 600, }, colors = { diff -r 6216b754350d -r 8d11fc88ecab Inventorium.toc --- a/Inventorium.toc Fri Dec 24 16:10:20 2010 +0100 +++ b/Inventorium.toc Fri Dec 24 21:55:11 2010 +0100 @@ -19,6 +19,7 @@ # Stuff Widgets.lua +ItemData.class.lua # Data Data\PremadeGroups.lua diff -r 6216b754350d -r 8d11fc88ecab ItemData.class.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ItemData.class.lua Fri Dec 24 21:55:11 2010 +0100 @@ -0,0 +1,30 @@ +local addon = select(2, ...); + +-- Define the class + +addon.ItemData = {}; +addon.ItemData.__index = addon.ItemData; + +-- Construct +function addon.ItemData:New(itemId) + local self = {}; + + setmetatable(self, addon.ItemData); + + local itemName, itemLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemId); + + -- Standard info everything needs + self.id = itemId; + self.name = itemName; + self.link = itemLink; + self.rarity = itemRarity; + self.icon = itemTexture; + + -- Detailed stuff + self.value = -3; + self.globalCount = -3; + self.localCount = -3; + self.set = {}; + + return self; +end diff -r 6216b754350d -r 8d11fc88ecab Summary.lua --- a/Summary.lua Fri Dec 24 16:10:20 2010 +0100 +++ b/Summary.lua Fri Dec 24 21:55:11 2010 +0100 @@ -321,21 +321,20 @@ -- Retrieve items list if not itemsCache[groupName] then itemsCache[groupName] = {}; - - -- Sort item list + end + + if #(itemsCache[groupName]) == 0 then + -- If the item cache is empty for itemId, _ in pairs(values.items) do - local itemName, itemLink, itemRarity = GetItemInfo(itemId); + local newItemData = addon.ItemData:New(itemId); - tinsert(itemsCache[groupName], { - id = itemId, - name = itemName, -- may be nil - link = itemLink, -- may be nil - 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, -- may be nil - count = -3,--addon:GetItemCount(itemId, groupName), - localCount = -3, - set = {}, - }); + -- 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 + if priceThreshold == 0 and not alwaysGetAuctionValue then + newItemData.value = -4; + end + + tinsert(itemsCache[groupName], newItemData); + CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; end end @@ -369,9 +368,9 @@ end elseif sortMethod == "current" then if sortDirectory == "ASC" then - return a.count < b.count; + return a.globalCount < b.globalCount; else - return a.count > b.count; + return a.globalCount > b.globalCount; end elseif sortMethod == "local" then if sortDirectory == "ASC" then @@ -397,7 +396,7 @@ for i, item in pairs(itemsCache[groupName]) do -- Go through all items for this group - if (( item.count / minGlobalStock ) < showWhenBelow or ( item.localCount / minLocalStock ) < showWhenBelow) and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then + 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 -- 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"); @@ -430,7 +429,7 @@ -- Current quantity local lblQuantity = AceGUI:Create("Label"); - lblQuantity:SetText(self:DisplayItemCount(item.count, minGlobalStock)); + lblQuantity:SetText(self:DisplayItemCount(item.globalCount, minGlobalStock)); lblQuantity:SetRelativeWidth(.099); iGroup:AddChild(lblQuantity); @@ -443,23 +442,9 @@ iGroup:AddChild(lblValue); -- Remember references to the value and current fields so we can fill them later - if item.set then - -- -3 means the price is unknown, queue look up - if item.value == -3 then - item.set.value = lblValue; - end - 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 and item.localCount ~= -3 then - item.set = nil; - end - end + item.set.value = lblValue; + item.set.globalCount = lblQuantity; + item.set.localCount = lblLocal; end end @@ -497,12 +482,12 @@ local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); for _, item in pairs(items) do - if item.set then - if item.count == -3 then + if item.globalCount == -3 or item.localCount == -3 or item.value == -3 then + if item.globalCount == -3 then -- Only if item count was queued, update it - item.count = addon:GetItemCount(item.id, groupName); - if item.set.current and item.set.current.SetText then - item.set.current:SetText(self:DisplayItemCount(item.count, minGlobalStock)); + item.globalCount = addon:GetItemCount(item.id, groupName); + if item.set.globalCount and item.set.globalCount.SetText then + item.set.globalCount:SetText(self:DisplayItemCount(item.globalCount, minGlobalStock)); end end @@ -528,8 +513,6 @@ end end - item.set = nil; - i = i + 1; CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1; diff -r 6216b754350d -r 8d11fc88ecab Widgets.lua --- a/Widgets.lua Fri Dec 24 16:10:20 2010 +0100 +++ b/Widgets.lua Fri Dec 24 21:55:11 2010 +0100 @@ -55,11 +55,11 @@ -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions self:SetCallback("CustomOnEnter", function(this) - local itemId = this:GetUserData("itemId"); + local itemData = this:GetUserData("ItemData"); - if itemId then + if itemData then GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT"); - GameTooltip:SetHyperlink(("item:%d"):format(itemId)); + GameTooltip:SetHyperlink(("item:%d"):format(itemData.id)); GameTooltip:Show(); end end); @@ -73,14 +73,14 @@ end local func = this:GetUserData("exec"); - local itemId = this:GetUserData("itemId"); + local itemData = this:GetUserData("ItemData"); if func then -- If this is a config option we will need the group id local path = this:GetUserData("path"); local groupId = (path and path[2]) or nil; - func(groupId, itemId, ...); + func(groupId, itemData, ...); end end); @@ -93,27 +93,11 @@ -- Remember the original SetText as this might get overwritten by the config-widget widget.originalSetText = widget.SetText; - widget.SetItemId = function(self, itemId) - self:SetUserData("itemId", itemId); + widget.SetItem = function(self, item) + self:SetUserData("ItemData", item); -- Put the icon in front of it - self:SetImage(GetItemIcon(itemId)); - -- Standardize the size - self:SetImageSize(16, 16); - - -- Make readable font - self:SetFontObject(GameFontHighlight); - - -- We don't want to set the itemId as text, but rather the item link, so get that. - local itemLink = select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId); - - self:originalSetText(itemLink); - end; - widget.SetItem = function(self, item) - self:SetUserData("itemId", item.id); - - -- Put the icon in front of it - self:SetImage(GetItemIcon(item.id)); + self:SetImage(item.icon); -- Standardize the size self:SetImageSize(16, 16); @@ -132,7 +116,7 @@ end -- We don't want to set the itemId as text, but rather the item link, so get that. - local itemLink = item.link or ("Unknown (#%d)"):format(itemId); + local itemLink = item.link or ("Unknown (#%d)"):format(item.id); self:originalSetText(itemLink); end; @@ -166,7 +150,9 @@ -- Forward that itemId to the ItemLinkButton widget.SetText = function(self, value, ...) if value and tonumber(value) then - self:SetItemId(tonumber(value)); + local newItemData = addon.ItemData:New(tonumber(value)); + + self:SetItem(newItemData); end end;