Mercurial > wow > inventory
diff Summary.lua @ 62:fee06221176f
Seperated the config from Core.lua.
Many other code cleaning up for readability.
Added local references for much used globals.
Moved widgets to a different file for readability.
Re-added global function for slash command handling since we do need it for our chat-hyperlinks.
Fixed queueing to properly use the track at property of virtual groups.
Fixed queueing to display the item id instead of the item link if the item link could not be loaded.
Speed slider at the summary now has an interval of 1% down from 5% and rounds rather than ceils it?s value so 101% will become 100% rather than 105%.
Now using the right stock properties at the summary.
Added a help group to the config.
author | Zerotorescue |
---|---|
date | Wed, 22 Dec 2010 19:56:55 +0100 |
parents | d903b0a151d3 |
children | 7ca83ad9d67a |
line wrap: on
line diff
--- a/Summary.lua Wed Dec 22 15:04:09 2010 +0100 +++ b/Summary.lua Wed Dec 22 19:56:55 2010 +0100 @@ -1,23 +1,28 @@ -local addon = select(2, ...); -local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0"); - -local AceGUI = LibStub("AceGUI-3.0"); +local addon = select(2, ...); -- Get a reference to the main addon object +local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window local unknownItemName = "Unknown (#%d)"; -local itemsCache = {}; +local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, itemsCache = 0, 0, {}; +local AceGUI, cacheStart; -local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0; -local cacheStart; +local _G = _G; -- prevent looking up of the global table +local printf, sgsub, supper, tinsert, pairs, ceil, GetItemInfo = _G.string.format, _G.string.gsub, _G.string.upper, _G.table.insert, _G.pairs, _G.ceil, _G.GetItemInfo; -- prevent looking up of the most used globals all the time function mod:OnEnable() - self:RegisterWidgets(); + -- Register the summary specific widget + addon:GetModule("Widgets"):InlineGroupWithButton(); + + AceGUI = LibStub("AceGUI-3.0"); -- Register our own slash commands + -- /im summary addon:RegisterSlash(function() mod:BuildMain(); mod:Build(); end, { "s", "sum", "summary" }, "|Hfunction:InventoriumCommandHandler:summary|h|cff00fff7/im summary|r|h (or /im s) - Show the summary window containing an overview of all items within the groups tracked at this current character."); + + -- /im reset addon:RegisterSlash(function() if mod.frame then mod.frame:SetWidth(650); @@ -47,48 +52,6 @@ GameTooltip:Hide(); end -function mod:RegisterWidgets() - -- Register InlineGroupWithButton-widget - -- This widget adds a button next to the header of an inline group - -- SetPoint doesn't seem usable within AceGUI. - - local widgetType = "InlineGroupWithButton"; - local widgetVersion = 1; - - local function Constructor() - local widget = AceGUI:Create("InlineGroup"); - widget.type = widgetType; - - widget.MakeButton = function(self, buttonSettings) - if type(buttonSettings) == "table" then - if not self.btnQueue then - -- Because widgets are re-used, we don't want to recreate this button - self.btnQueue = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate"); - self.btnQueue:SetHeight(22); - self.btnQueue:SetWidth(120); - end - self.btnQueue:SetText(buttonSettings.name); - self.btnQueue:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5); - - -- Triggers - self.btnQueue:SetScript("OnClick", buttonSettings.exec); - - -- Tooltip - self.btnQueue.tooltipTitle = buttonSettings.name; - self.btnQueue.tooltip = buttonSettings.desc or ""; - self.btnQueue:SetScript("OnEnter", ShowTooltip); - self.btnQueue:SetScript("OnLeave", HideTooltip); - else - error("settings must be a table - usage: MakeButton(table);"); - end - end; - - return widget; - end - - AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion); -end - function mod:BuildMain() LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions"); @@ -157,7 +120,7 @@ -- From http://www.wowwiki.com/API_sort local function pairsByKeys (t, f) local a = {} - for n in pairs(t) do table.insert(a, n) end + for n in pairs(t) do tinsert(a, n) end table.sort(a, f) local i = 0 -- iterator variable local iter = function () -- iterator function @@ -204,11 +167,11 @@ -- Speed slider local sdrSpeed = AceGUI:Create("Slider"); sdrSpeed:SetLabel("Processing speed"); - sdrSpeed:SetSliderValues(0.01, 5, 0.05); + sdrSpeed:SetSliderValues(0.01, 5, 0.01); -- min, max, interval sdrSpeed:SetIsPercent(true); sdrSpeed:SetRelativeWidth(.3); sdrSpeed:SetCallback("OnMouseUp", function(self, event, value) - addon.db.profile.defaults.summary.speed = ceil( value * 100 / 5 ); + addon.db.profile.defaults.summary.speed = ceil( ( ( value * 100 ) / 5) - .5 ); CACHE_ITEMS_PER_UPDATE = addon.db.profile.defaults.summary.speed; -- max = 20, min = 1 end); @@ -276,8 +239,8 @@ -- Get group settings - local minGlobalStock = addon:GetOptionByKey(groupName, "minimumStock"); - local minLocalStock = addon:GetOptionByKey(groupName, "minimumLocalStock"); + local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock"); + local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock"); local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow"); local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold"); @@ -363,9 +326,9 @@ for itemId, _ in pairs(values.items) do local itemName, itemLink, itemRarity = GetItemInfo(itemId); - table.insert(itemsCache[groupName], { + tinsert(itemsCache[groupName], { id = itemId, - name = itemName or unknownItemName:format(itemId), + name = itemName or printf(unknownItemName, itemId), link = itemLink, 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, @@ -387,9 +350,9 @@ -- Do a name-compare for items of the same rarity -- Otherwise epics first, then junk if sortDirectory == "ASC" then - return a.name:upper() < b.name:upper(); + return supper(a.name) < supper(b.name); else - return a.name:upper() > b.name:upper(); + return supper(a.name) > supper(b.name); end elseif sortMethod == "item" then if sortDirectory == "ASC" then @@ -429,7 +392,7 @@ 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 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); @@ -465,15 +428,6 @@ iGroup:AddChild(lblQuantity); - --[[ - -- Required stock - local lblMinimumStock = AceGUI:Create("Label"); - lblMinimumStock:SetText(minGlobalStock); - lblMinimumStock:SetRelativeWidth(.099); - - iGroup:AddChild(lblMinimumStock); - ]] - -- Value local lblValue = AceGUI:Create("Label"); lblValue:SetText(self:DisplayMoney(item.value, priceThreshold)); @@ -511,14 +465,14 @@ end if groupStartTime and groupTimes then - addon:Debug(("Building of %s took %d ms (%d / %d / %d / %d / %d)."):format(groupName, ceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, ceil( ( GetTime() - buildStartTime ) * 1000 ))); + addon:Debug(printf("Building of %s took %d ms (%d / %d / %d / %d / %d).", groupName, ceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, ceil( ( GetTime() - buildStartTime ) * 1000 ))); end end mod.scrollFrame:ResumeLayout(); mod.scrollFrame:DoLayout(); - addon:Debug(("Done building summary after %d ms."):format(ceil( ( GetTime() - buildStartTime ) * 1000 ))); + addon:Debug(printf("Done building summary after %d ms.", ceil( ( GetTime() - buildStartTime ) * 1000 ))); if CACHE_ITEMS_TOTAL > 0 then cacheStart = GetTime(); @@ -573,7 +527,7 @@ CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1; if mod.frame then - mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100))); + mod.frame:SetStatusText(printf("Caching auction values and item-counts... %d%% has already been processed.", floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100))); end if i >= addon.db.profile.defaults.summary.speed then @@ -604,13 +558,13 @@ local percentage = ( num / required ); if percentage >= addon.db.profile.defaults.colors.green then - return ("|cff00ff00%d|r"):format(num); + return printf("|cff00ff00%d|r", num); elseif percentage >= addon.db.profile.defaults.colors.yellow then - return ("|cffffff00%d|r"):format(num); + return printf("|cffffff00%d|r", num); elseif percentage >= addon.db.profile.defaults.colors.orange then - return ("|cffff9933%d|r"):format(num); + return printf("|cffff9933%d|r", num); elseif percentage >= addon.db.profile.defaults.colors.red then - return ("|cffff0000%d|r"):format(num); + return printf("|cffff0000%d|r", num); end end @@ -626,7 +580,7 @@ elseif value == -5 then return "|cffff9933Error|r"; elseif priceThreshold and value < priceThreshold then - return ("|cffaaaaaa%s|r"):format(addon:ReadableMoney(value or 0, true):gsub("|([a-fA-F0-9]+)([gsc]+)|r", "%2")); + return printf("|cffaaaaaa%s|r", sgsub(addon:ReadableMoney(value or 0, true), "|([a-fA-F0-9]+)([gsc]+)|r", "%2")); else return addon:ReadableMoney(value or 0, true); end @@ -638,15 +592,15 @@ elseif value == -3 then return "|cffffff00Unknown|r"; else - return ("%s / %d"):format(self:ColorCode(value, minimumStock), minimumStock); + return printf("%s / %d", self:ColorCode(value, minimumStock), minimumStock); end end function mod:NumberFormat(num) - local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1); + local formatted = sgsub(num, "(%d)(%d%d%d)$", "%1,%2", 1); while true do - formatted, matches = string.gsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1); + formatted, matches = sgsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1); if matches == 0 then break;