annotate 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
rev   line source
Zerotorescue@62 1 local addon = select(2, ...); -- Get a reference to the main addon object
Zerotorescue@62 2 local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window
Zerotorescue@0 3
Zerotorescue@23 4 local unknownItemName = "Unknown (#%d)";
Zerotorescue@23 5
Zerotorescue@62 6 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, itemsCache = 0, 0, {};
Zerotorescue@62 7 local AceGUI, cacheStart;
Zerotorescue@23 8
Zerotorescue@62 9 local _G = _G; -- prevent looking up of the global table
Zerotorescue@62 10 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
Zerotorescue@23 11
Zerotorescue@0 12 function mod:OnEnable()
Zerotorescue@62 13 -- Register the summary specific widget
Zerotorescue@62 14 addon:GetModule("Widgets"):InlineGroupWithButton();
Zerotorescue@62 15
Zerotorescue@62 16 AceGUI = LibStub("AceGUI-3.0");
Zerotorescue@0 17
Zerotorescue@1 18 -- Register our own slash commands
Zerotorescue@62 19 -- /im summary
Zerotorescue@1 20 addon:RegisterSlash(function()
Zerotorescue@1 21 mod:BuildMain();
Zerotorescue@1 22 mod:Build();
Zerotorescue@36 23 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.");
Zerotorescue@62 24
Zerotorescue@62 25 -- /im reset
Zerotorescue@23 26 addon:RegisterSlash(function()
Zerotorescue@23 27 if mod.frame then
Zerotorescue@23 28 mod.frame:SetWidth(650);
Zerotorescue@23 29 mod.frame:SetHeight(600);
Zerotorescue@23 30
Zerotorescue@23 31 print("Resetting width and height of the summary frame.");
Zerotorescue@23 32 end
Zerotorescue@36 33 end, { "r", "reset" }, "|Hfunction:InventoriumCommandHandler:reset|h|cff00fff7/im reset|r|h (or /im r) - Reset the size of the summary frame.");
Zerotorescue@0 34 end
Zerotorescue@0 35
Zerotorescue@13 36 local function ShowTooltip(self)
Zerotorescue@13 37 -- If this function is called from a widget, self is the widget and self.frame the actual frame
Zerotorescue@13 38 local this = self.frame or self;
Zerotorescue@13 39
Zerotorescue@13 40 GameTooltip:SetOwner(this, "ANCHOR_NONE");
Zerotorescue@13 41 GameTooltip:SetPoint("BOTTOM", this, "TOP");
Zerotorescue@13 42 GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1);
Zerotorescue@13 43
Zerotorescue@13 44 if type(this.tooltip) == "string" then
Zerotorescue@13 45 GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1);
Zerotorescue@13 46 end
Zerotorescue@13 47
Zerotorescue@13 48 GameTooltip:Show();
Zerotorescue@13 49 end
Zerotorescue@13 50
Zerotorescue@13 51 local function HideTooltip()
Zerotorescue@13 52 GameTooltip:Hide();
Zerotorescue@13 53 end
Zerotorescue@13 54
Zerotorescue@0 55 function mod:BuildMain()
Zerotorescue@11 56 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
Zerotorescue@0 57
Zerotorescue@10 58 self:CloseFrame();
Zerotorescue@10 59
Zerotorescue@1 60 -- Main Window
Zerotorescue@1 61 mod.frame = AceGUI:Create("Frame");
Zerotorescue@23 62 _G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames
Zerotorescue@57 63 mod.frame:SetTitle("Inventory Summary");
Zerotorescue@1 64 mod.frame:SetLayout("Fill");
Zerotorescue@1 65 mod.frame:SetCallback("OnClose", function(widget)
Zerotorescue@7 66 mod:CancelTimer(self.tmrUpdater, true);
Zerotorescue@9 67 mod:CloseFrame();
Zerotorescue@1 68 end);
Zerotorescue@61 69 mod.frame:SetWidth(addon.db.profile.defaults.summary.width);
Zerotorescue@61 70 mod.frame:SetHeight(addon.db.profile.defaults.summary.height);
Zerotorescue@13 71 mod.frame.OnWidthSet = function(_, width)
Zerotorescue@61 72 addon.db.profile.defaults.summary.width = width;
Zerotorescue@13 73 end;
Zerotorescue@13 74 mod.frame.OnHeightSet = function(_, height)
Zerotorescue@61 75 addon.db.profile.defaults.summary.height = height;
Zerotorescue@13 76 end;
Zerotorescue@0 77
Zerotorescue@23 78 -- Close on escape
Zerotorescue@23 79 tinsert(UISpecialFrames, "InventoriumSummary");
Zerotorescue@23 80
Zerotorescue@1 81 -- ScrollFrame child
Zerotorescue@1 82 mod.scrollFrame = AceGUI:Create("ScrollFrame");
Zerotorescue@1 83 mod.scrollFrame:SetLayout("Flow");
Zerotorescue@0 84
Zerotorescue@1 85 mod.frame:AddChild(mod.scrollFrame);
Zerotorescue@1 86
Zerotorescue@1 87 -- Reset items cache
Zerotorescue@1 88 table.wipe(itemsCache);
Zerotorescue@0 89 end
Zerotorescue@0 90
Zerotorescue@9 91 function mod:CloseFrame()
Zerotorescue@9 92 if mod.frame then
Zerotorescue@9 93 mod.frame:Release();
Zerotorescue@9 94 mod.frame = nil;
Zerotorescue@10 95
Zerotorescue@10 96 -- Stop caching
Zerotorescue@10 97
Zerotorescue@10 98 -- Stop timer
Zerotorescue@10 99 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@10 100
Zerotorescue@10 101 -- Reset trackers
Zerotorescue@10 102 CACHE_ITEMS_TOTAL = 0;
Zerotorescue@10 103 CACHE_ITEMS_CURRENT = 0;
Zerotorescue@9 104 end
Zerotorescue@9 105 end
Zerotorescue@9 106
Zerotorescue@0 107 local sortMethod = "item";
Zerotorescue@0 108 local sortDirectory = "ASC";
Zerotorescue@0 109 local function ReSort(subject)
Zerotorescue@0 110 if sortMethod == subject then
Zerotorescue@0 111 sortDirectory = (sortDirectory == "ASC" and "DESC") or "ASC";
Zerotorescue@0 112 else
Zerotorescue@0 113 sortDirectory = "ASC";
Zerotorescue@0 114 end
Zerotorescue@0 115 sortMethod = subject;
Zerotorescue@0 116
Zerotorescue@0 117 mod:Build();
Zerotorescue@0 118 end
Zerotorescue@57 119
Zerotorescue@10 120 -- From http://www.wowwiki.com/API_sort
Zerotorescue@10 121 local function pairsByKeys (t, f)
Zerotorescue@10 122 local a = {}
Zerotorescue@62 123 for n in pairs(t) do tinsert(a, n) end
Zerotorescue@10 124 table.sort(a, f)
Zerotorescue@10 125 local i = 0 -- iterator variable
Zerotorescue@10 126 local iter = function () -- iterator function
Zerotorescue@10 127 i = i + 1
Zerotorescue@10 128 if a[i] == nil then return nil
Zerotorescue@10 129 else return a[i], t[a[i]]
Zerotorescue@10 130 end
Zerotorescue@10 131 end
Zerotorescue@10 132 return iter
Zerotorescue@10 133 end
Zerotorescue@0 134
Zerotorescue@0 135 function mod:Build()
Zerotorescue@10 136 local buildStartTime, times = GetTime(), {};
Zerotorescue@0 137
Zerotorescue@1 138 -- We are going to add hunderds of widgets to this container, but don't want it to also cause hunderds of reflows, thus pause reflowing and just do it once when everything is prepared
Zerotorescue@1 139 -- This appears to be required for each container we wish to pause, so also do this for the contents
Zerotorescue@1 140 mod.scrollFrame:PauseLayout();
Zerotorescue@1 141
Zerotorescue@10 142 mod.scrollFrame:ReleaseChildren();
Zerotorescue@10 143
Zerotorescue@10 144 -- Refresh button
Zerotorescue@10 145 local btnRefresh = AceGUI:Create("Button");
Zerotorescue@10 146 btnRefresh:SetText("Refresh");
Zerotorescue@10 147 btnRefresh:SetRelativeWidth(.2);
Zerotorescue@10 148 btnRefresh:SetCallback("OnClick", function()
Zerotorescue@10 149 -- Reset items cache
Zerotorescue@10 150 table.wipe(itemsCache);
Zerotorescue@10 151
Zerotorescue@10 152 -- Rebuild itemlist and start caching
Zerotorescue@10 153 mod:Build();
Zerotorescue@10 154 end);
Zerotorescue@13 155 btnRefresh:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 156 btnRefresh:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 157 btnRefresh.frame.tooltipTitle = "Refresh Cache";
Zerotorescue@13 158 btnRefresh.frame.tooltip = "Refresh the list and recache the item counts and auction values.";
Zerotorescue@10 159
Zerotorescue@10 160 mod.scrollFrame:AddChild(btnRefresh);
Zerotorescue@10 161
Zerotorescue@13 162 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 163 lblSpacer:SetRelativeWidth(.03);
Zerotorescue@13 164
Zerotorescue@13 165 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 166
Zerotorescue@10 167 -- Speed slider
Zerotorescue@13 168 local sdrSpeed = AceGUI:Create("Slider");
Zerotorescue@13 169 sdrSpeed:SetLabel("Processing speed");
Zerotorescue@62 170 sdrSpeed:SetSliderValues(0.01, 5, 0.01); -- min, max, interval
Zerotorescue@13 171 sdrSpeed:SetIsPercent(true);
Zerotorescue@13 172 sdrSpeed:SetRelativeWidth(.3);
Zerotorescue@13 173 sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
Zerotorescue@62 174 addon.db.profile.defaults.summary.speed = ceil( ( ( value * 100 ) / 5) - .5 );
Zerotorescue@13 175
Zerotorescue@61 176 CACHE_ITEMS_PER_UPDATE = addon.db.profile.defaults.summary.speed; -- max = 20, min = 1
Zerotorescue@10 177 end);
Zerotorescue@61 178 sdrSpeed:SetValue( addon.db.profile.defaults.summary.speed * 5 / 100 );
Zerotorescue@13 179 sdrSpeed:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 180 sdrSpeed:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 181 sdrSpeed.frame.tooltipTitle = "Caching Processing Speed";
Zerotorescue@13 182 sdrSpeed.frame.tooltip = "Change the speed at which item counts and auction values are being cached. Higher is faster but may drastically reduce your FPS while caching.\n\nAnything above 100% will probably become uncomfortable.";
Zerotorescue@10 183
Zerotorescue@13 184 mod.scrollFrame:AddChild(sdrSpeed);
Zerotorescue@13 185
Zerotorescue@13 186 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 187 lblSpacer:SetRelativeWidth(.23);
Zerotorescue@13 188
Zerotorescue@13 189 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 190
Zerotorescue@13 191 -- Config button
Zerotorescue@13 192 --[[local btnConfig = AceGUI:Create("Button");
Zerotorescue@13 193 btnConfig:SetText("Config");
Zerotorescue@13 194 btnConfig:SetRelativeWidth(.2);
Zerotorescue@13 195 btnConfig:SetCallback("OnClick", function()
Zerotorescue@13 196 --TODO: Tidy up
Zerotorescue@13 197 SlashCmdList["INVENTORIUM"]("config");
Zerotorescue@13 198 end);
Zerotorescue@13 199 btnConfig:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 200 btnConfig:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 201 btnConfig.frame.tooltipTitle = "Config";
Zerotorescue@13 202 btnConfig.frame.tooltip = "Click to open the config window. This will close the current window.";
Zerotorescue@13 203
Zerotorescue@13 204 mod.scrollFrame:AddChild(btnConfig);]]
Zerotorescue@13 205
Zerotorescue@13 206 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 207 lblSpacer:SetRelativeWidth(.03);
Zerotorescue@13 208
Zerotorescue@13 209 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 210
Zerotorescue@13 211 -- Queue all button
Zerotorescue@13 212 local btnQueueAll = AceGUI:Create("Button");
Zerotorescue@13 213 btnQueueAll:SetText("Queue All");
Zerotorescue@13 214 btnQueueAll:SetRelativeWidth(.2);
Zerotorescue@13 215 btnQueueAll:SetCallback("OnClick", function()
Zerotorescue@14 216 self:SendMessage("IM_QUEUE_ALL");
Zerotorescue@13 217 end);
Zerotorescue@13 218 btnQueueAll:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 219 btnQueueAll:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 220 btnQueueAll.frame.tooltipTitle = "Queue all";
Zerotorescue@13 221 btnQueueAll.frame.tooltip = "Queue everything that requires restocking within every single visible group.";
Zerotorescue@13 222
Zerotorescue@13 223 mod.scrollFrame:AddChild(btnQueueAll);
Zerotorescue@10 224
Zerotorescue@10 225 times.init = ceil( ( GetTime() - buildStartTime ) * 1000 );
Zerotorescue@10 226 addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
Zerotorescue@10 227
Zerotorescue@1 228 local playerName = UnitName("player");
Zerotorescue@1 229
Zerotorescue@1 230 -- Go through all our stored groups
Zerotorescue@61 231 for groupName, values in pairsByKeys(addon.db.profile.groups, function(a, b) return a:lower() < b:lower(); end) do
Zerotorescue@10 232 local groupStartTime, groupTimes = GetTime(), {};
Zerotorescue@10 233
Zerotorescue@50 234 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
Zerotorescue@50 235
Zerotorescue@1 236
Zerotorescue@1 237 -- Does this group have any items and do we want to track it at this char?
Zerotorescue@1 238 if values.items and trackAt[playerName] then
Zerotorescue@10 239
Zerotorescue@10 240
Zerotorescue@0 241 -- Get group settings
Zerotorescue@62 242 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
Zerotorescue@62 243 local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock");
Zerotorescue@50 244 local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow");
Zerotorescue@50 245 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@50 246 local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold");
Zerotorescue@50 247 local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue");
Zerotorescue@10 248
Zerotorescue@0 249 -- Make group container
Zerotorescue@0 250 local iGroup = AceGUI:Create("InlineGroupWithButton");
Zerotorescue@1 251 iGroup:PauseLayout();
Zerotorescue@0 252 iGroup:SetTitle(groupName);
Zerotorescue@0 253 iGroup:SetFullWidth(true);
Zerotorescue@0 254 iGroup:SetLayout("Flow");
Zerotorescue@0 255 iGroup:MakeButton({
Zerotorescue@0 256 name = "Queue",
Zerotorescue@0 257 desc = "Queue all items in this group.",
Zerotorescue@0 258 exec = function()
Zerotorescue@14 259 print("Queueing all items within " .. groupName .. " craftable by the currently open profession.");
Zerotorescue@14 260 self:SendMessage("IM_QUEUE_GROUP", groupName);
Zerotorescue@0 261 end,
Zerotorescue@0 262 });
Zerotorescue@0 263
Zerotorescue@10 264
Zerotorescue@10 265
Zerotorescue@0 266 -- Headers
Zerotorescue@1 267
Zerotorescue@0 268 -- Itemlink
Zerotorescue@0 269 local lblItem = AceGUI:Create("InteractiveLabel");
Zerotorescue@0 270 lblItem:SetText("|cfffed000Item|r");
Zerotorescue@0 271 lblItem:SetFontObject(GameFontHighlight);
Zerotorescue@57 272 lblItem:SetRelativeWidth(.7);
Zerotorescue@0 273 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
Zerotorescue@13 274 lblItem:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 275 lblItem:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 276 lblItem.frame.tooltipTitle = "Item";
Zerotorescue@13 277 lblItem.frame.tooltip = "Sort on the item quality, then name.";
Zerotorescue@0 278
Zerotorescue@0 279 iGroup:AddChild(lblItem);
Zerotorescue@0 280
Zerotorescue@50 281 -- Local quantity
Zerotorescue@50 282 local lblLocal = AceGUI:Create("InteractiveLabel");
Zerotorescue@50 283 lblLocal:SetText("|cfffed000Loc.|r");
Zerotorescue@50 284 lblLocal:SetFontObject(GameFontHighlight);
Zerotorescue@50 285 lblLocal:SetRelativeWidth(.099);
Zerotorescue@50 286 lblLocal:SetCallback("OnClick", function() ReSort("local"); end);
Zerotorescue@50 287 lblLocal:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@50 288 lblLocal:SetCallback("OnLeave", HideTooltip);
Zerotorescue@50 289 lblLocal.frame.tooltipTitle = "Local stock";
Zerotorescue@50 290 lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
Zerotorescue@50 291
Zerotorescue@50 292 iGroup:AddChild(lblLocal);
Zerotorescue@50 293
Zerotorescue@0 294 -- Current quantity
Zerotorescue@0 295 local lblQuantity = AceGUI:Create("InteractiveLabel");
Zerotorescue@0 296 lblQuantity:SetText("|cfffed000Cur.|r");
Zerotorescue@0 297 lblQuantity:SetFontObject(GameFontHighlight);
Zerotorescue@10 298 lblQuantity:SetRelativeWidth(.099);
Zerotorescue@0 299 lblQuantity:SetCallback("OnClick", function() ReSort("current"); end);
Zerotorescue@13 300 lblQuantity:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 301 lblQuantity:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 302 lblQuantity.frame.tooltipTitle = "Current stock";
Zerotorescue@13 303 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock.";
Zerotorescue@0 304
Zerotorescue@0 305 iGroup:AddChild(lblQuantity);
Zerotorescue@0 306
Zerotorescue@1 307 -- Lowest value
Zerotorescue@1 308 local lblValue = AceGUI:Create("InteractiveLabel");
Zerotorescue@1 309 lblValue:SetText("|cfffed000Value|r");
Zerotorescue@1 310 lblValue:SetFontObject(GameFontHighlight);
Zerotorescue@10 311 lblValue:SetRelativeWidth(.099);
Zerotorescue@1 312 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
Zerotorescue@13 313 lblValue:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 314 lblValue:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 315 lblValue.frame.tooltipTitle = "Value";
Zerotorescue@13 316 lblValue.frame.tooltip = "Sort on the item auction value.";
Zerotorescue@1 317
Zerotorescue@1 318 iGroup:AddChild(lblValue);
Zerotorescue@1 319
Zerotorescue@10 320
Zerotorescue@10 321 -- Retrieve items list
Zerotorescue@1 322 if not itemsCache[groupName] then
Zerotorescue@1 323 itemsCache[groupName] = {};
Zerotorescue@0 324
Zerotorescue@1 325 -- Sort item list
Zerotorescue@12 326 for itemId, _ in pairs(values.items) do
Zerotorescue@1 327 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
Zerotorescue@1 328
Zerotorescue@62 329 tinsert(itemsCache[groupName], {
Zerotorescue@1 330 id = itemId,
Zerotorescue@62 331 name = itemName or printf(unknownItemName, itemId),
Zerotorescue@23 332 link = itemLink,
Zerotorescue@23 333 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),
Zerotorescue@12 334 rarity = itemRarity or 1,
Zerotorescue@23 335 count = -3,--addon:GetItemCount(itemId, groupName),
Zerotorescue@50 336 localCount = -3,
Zerotorescue@1 337 set = {},
Zerotorescue@1 338 });
Zerotorescue@1 339 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
Zerotorescue@1 340 end
Zerotorescue@0 341 end
Zerotorescue@0 342
Zerotorescue@10 343 groupTimes.init = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 344
Zerotorescue@10 345
Zerotorescue@10 346
Zerotorescue@10 347 -- Sort items
Zerotorescue@1 348 table.sort(itemsCache[groupName], function(a, b)
Zerotorescue@1 349 if sortMethod == "item" and a.rarity == b.rarity then
Zerotorescue@1 350 -- Do a name-compare for items of the same rarity
Zerotorescue@1 351 -- Otherwise epics first, then junk
Zerotorescue@0 352 if sortDirectory == "ASC" then
Zerotorescue@62 353 return supper(a.name) < supper(b.name);
Zerotorescue@0 354 else
Zerotorescue@62 355 return supper(a.name) > supper(b.name);
Zerotorescue@1 356 end
Zerotorescue@1 357 elseif sortMethod == "item" then
Zerotorescue@1 358 if sortDirectory == "ASC" then
Zerotorescue@1 359 return a.rarity > b.rarity; -- the comparers were reversed because we want epics first
Zerotorescue@1 360 else
Zerotorescue@1 361 return a.rarity < b.rarity; -- the comparers were reversed because we want epics first
Zerotorescue@0 362 end
Zerotorescue@0 363 elseif sortMethod == "current" then
Zerotorescue@0 364 if sortDirectory == "ASC" then
Zerotorescue@0 365 return a.count < b.count;
Zerotorescue@0 366 else
Zerotorescue@0 367 return a.count > b.count;
Zerotorescue@0 368 end
Zerotorescue@50 369 elseif sortMethod == "local" then
Zerotorescue@50 370 if sortDirectory == "ASC" then
Zerotorescue@50 371 return a.localCount < b.localCount;
Zerotorescue@50 372 else
Zerotorescue@50 373 return a.localCount > b.localCount;
Zerotorescue@50 374 end
Zerotorescue@1 375 elseif sortMethod == "value" then
Zerotorescue@1 376 if sortDirectory == "ASC" then
Zerotorescue@1 377 return a.value < b.value;
Zerotorescue@1 378 else
Zerotorescue@1 379 return a.value > b.value;
Zerotorescue@1 380 end
Zerotorescue@0 381 end
Zerotorescue@0 382 end);
Zerotorescue@0 383
Zerotorescue@10 384 groupTimes.sorting = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 385
Zerotorescue@10 386
Zerotorescue@10 387
Zerotorescue@10 388
Zerotorescue@10 389 -- Show itemslist
Zerotorescue@1 390 for i, item in pairs(itemsCache[groupName]) do
Zerotorescue@31 391 -- Go through all items for this group
Zerotorescue@31 392
Zerotorescue@57 393 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
Zerotorescue@31 394 -- 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
Zerotorescue@62 395
Zerotorescue@0 396 local btnItemLink = AceGUI:Create("ItemLinkButton");
Zerotorescue@23 397 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
Zerotorescue@23 398 local itemName, itemLink = GetItemInfo(itemId);
Zerotorescue@23 399
Zerotorescue@23 400 if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then
Zerotorescue@23 401 ChatEdit_InsertLink(itemLink);
Zerotorescue@23 402 elseif buttonName == "LeftButton" and IsAltKeyDown() and itemName and AuctionFrame and AuctionFrame:IsShown() and AuctionFrameBrowse then
Zerotorescue@23 403 -- Start search at page 0
Zerotorescue@23 404 AuctionFrameBrowse.page = 0;
Zerotorescue@23 405
Zerotorescue@23 406 -- Set the search field (even though we could use "ChatEdit_InsertLink", this ensures the right field is updated)
Zerotorescue@23 407 BrowseName:SetText(itemName)
Zerotorescue@23 408
Zerotorescue@23 409 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
Zerotorescue@23 410 end
Zerotorescue@23 411 end);
Zerotorescue@57 412 btnItemLink:SetRelativeWidth(.7);
Zerotorescue@1 413 btnItemLink:SetItemId(item.id);
Zerotorescue@0 414
Zerotorescue@0 415 iGroup:AddChild(btnItemLink);
Zerotorescue@0 416
Zerotorescue@50 417 -- Local quantity
Zerotorescue@50 418 local lblLocal = AceGUI:Create("Label");
Zerotorescue@57 419 lblLocal:SetText(self:DisplayItemCount(item.localCount, minLocalStock));
Zerotorescue@50 420 lblLocal:SetRelativeWidth(.099);
Zerotorescue@50 421
Zerotorescue@50 422 iGroup:AddChild(lblLocal);
Zerotorescue@50 423
Zerotorescue@0 424 -- Current quantity
Zerotorescue@0 425 local lblQuantity = AceGUI:Create("Label");
Zerotorescue@57 426 lblQuantity:SetText(self:DisplayItemCount(item.count, minGlobalStock));
Zerotorescue@10 427 lblQuantity:SetRelativeWidth(.099);
Zerotorescue@0 428
Zerotorescue@0 429 iGroup:AddChild(lblQuantity);
Zerotorescue@0 430
Zerotorescue@1 431 -- Value
Zerotorescue@1 432 local lblValue = AceGUI:Create("Label");
Zerotorescue@1 433 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
Zerotorescue@10 434 lblValue:SetRelativeWidth(.099);
Zerotorescue@1 435
Zerotorescue@1 436 iGroup:AddChild(lblValue);
Zerotorescue@1 437
Zerotorescue@1 438 -- Remember references to the value and current fields so we can fill them later
Zerotorescue@1 439 if item.set then
Zerotorescue@10 440 -- -3 means the price is unknown, queue look up
Zerotorescue@10 441 if item.value == -3 then
Zerotorescue@10 442 item.set.value = lblValue;
Zerotorescue@10 443 end
Zerotorescue@10 444 if item.count == -3 then
Zerotorescue@10 445 item.set.current = lblQuantity;
Zerotorescue@10 446 end
Zerotorescue@50 447 if item.localCount == -3 then
Zerotorescue@50 448 item.set.localCount = lblLocal;
Zerotorescue@50 449 end
Zerotorescue@10 450
Zerotorescue@10 451 -- Don't queue if we already know everything we want to know
Zerotorescue@50 452 if item.value ~= -3 and item.count ~= -3 and item.localCount ~= -3 then
Zerotorescue@10 453 item.set = nil;
Zerotorescue@10 454 end
Zerotorescue@1 455 end
Zerotorescue@0 456 end
Zerotorescue@0 457 end
Zerotorescue@0 458
Zerotorescue@10 459 groupTimes.preparing = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 460
Zerotorescue@1 461 iGroup:ResumeLayout();
Zerotorescue@1 462 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
Zerotorescue@10 463
Zerotorescue@10 464 groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@0 465 end
Zerotorescue@10 466
Zerotorescue@13 467 if groupStartTime and groupTimes then
Zerotorescue@62 468 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 )));
Zerotorescue@13 469 end
Zerotorescue@0 470 end
Zerotorescue@1 471
Zerotorescue@1 472 mod.scrollFrame:ResumeLayout();
Zerotorescue@1 473 mod.scrollFrame:DoLayout();
Zerotorescue@1 474
Zerotorescue@62 475 addon:Debug(printf("Done building summary after %d ms.", ceil( ( GetTime() - buildStartTime ) * 1000 )));
Zerotorescue@10 476
Zerotorescue@1 477 if CACHE_ITEMS_TOTAL > 0 then
Zerotorescue@1 478 cacheStart = GetTime();
Zerotorescue@7 479 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@1 480 self.tmrUpdater = self:ScheduleRepeatingTimer("UpdateNextItem", .01); -- Once every 100 frames (or once every x frames if you have less than 100 FPS, basically, once every frame)
Zerotorescue@1 481 end
Zerotorescue@1 482 end
Zerotorescue@1 483
Zerotorescue@1 484 function mod:UpdateNextItem()
Zerotorescue@1 485 local i = 0;
Zerotorescue@1 486
Zerotorescue@1 487 for groupName, items in pairs(itemsCache) do
Zerotorescue@61 488 local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock");
Zerotorescue@61 489 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
Zerotorescue@1 490 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@1 491
Zerotorescue@1 492 for _, item in pairs(items) do
Zerotorescue@1 493 if item.set then
Zerotorescue@10 494 if item.count == -3 then
Zerotorescue@10 495 -- Only if item count was queued, update it
Zerotorescue@23 496 item.count = addon:GetItemCount(item.id, groupName);
Zerotorescue@10 497 if item.set.current and item.set.current.SetText then
Zerotorescue@57 498 item.set.current:SetText(self:DisplayItemCount(item.count, minGlobalStock));
Zerotorescue@10 499 end
Zerotorescue@1 500 end
Zerotorescue@1 501
Zerotorescue@50 502 if item.localCount == -3 then
Zerotorescue@50 503 -- Only if item count was queued, update it
Zerotorescue@54 504 item.localCount = addon:GetLocalItemCount(item.id, groupName);
Zerotorescue@50 505 if item.set.localCount and item.set.localCount.SetText then
Zerotorescue@57 506 item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minLocalStock));
Zerotorescue@50 507 end
Zerotorescue@50 508 end
Zerotorescue@50 509
Zerotorescue@10 510 if item.value == -3 then
Zerotorescue@10 511 -- Only if item value was queued, update it
Zerotorescue@23 512
Zerotorescue@23 513 -- The itemlink might not have been loaded yet in which case we retry
Zerotorescue@23 514 item.link = item.link or select(2, GetItemInfo(item.id));
Zerotorescue@23 515
Zerotorescue@23 516 if item.link then
Zerotorescue@23 517 item.value = addon:GetAuctionValue(item.link, groupName);
Zerotorescue@23 518 if item.set.value and item.set.value.SetText then
Zerotorescue@23 519 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
Zerotorescue@23 520 end
Zerotorescue@10 521 end
Zerotorescue@1 522 end
Zerotorescue@1 523
Zerotorescue@1 524 item.set = nil;
Zerotorescue@1 525
Zerotorescue@1 526 i = i + 1;
Zerotorescue@1 527 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
Zerotorescue@1 528
Zerotorescue@9 529 if mod.frame then
Zerotorescue@62 530 mod.frame:SetStatusText(printf("Caching auction values and item-counts... %d%% has already been processed.", floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
Zerotorescue@9 531 end
Zerotorescue@1 532
Zerotorescue@61 533 if i >= addon.db.profile.defaults.summary.speed then
Zerotorescue@1 534 return;
Zerotorescue@1 535 end
Zerotorescue@1 536 end
Zerotorescue@1 537 end
Zerotorescue@1 538 end
Zerotorescue@1 539
Zerotorescue@1 540 -- Reset trackers
Zerotorescue@1 541 CACHE_ITEMS_TOTAL = 0;
Zerotorescue@1 542 CACHE_ITEMS_CURRENT = 0;
Zerotorescue@1 543
Zerotorescue@1 544 -- Stop timer
Zerotorescue@1 545 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@10 546
Zerotorescue@10 547 -- Rebuild list so hidden items due to too low prices get added
Zerotorescue@10 548 self:Build();
Zerotorescue@1 549
Zerotorescue@1 550 -- Announce
Zerotorescue@10 551 mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. ceil(GetTime() - cacheStart) .. " seconds.");
Zerotorescue@1 552
Zerotorescue@1 553 -- Forget time
Zerotorescue@1 554 cacheStart = nil;
Zerotorescue@0 555 end
Zerotorescue@0 556
Zerotorescue@0 557 function mod:ColorCode(num, required)
Zerotorescue@0 558 local percentage = ( num / required );
Zerotorescue@0 559
Zerotorescue@61 560 if percentage >= addon.db.profile.defaults.colors.green then
Zerotorescue@62 561 return printf("|cff00ff00%d|r", num);
Zerotorescue@61 562 elseif percentage >= addon.db.profile.defaults.colors.yellow then
Zerotorescue@62 563 return printf("|cffffff00%d|r", num);
Zerotorescue@61 564 elseif percentage >= addon.db.profile.defaults.colors.orange then
Zerotorescue@62 565 return printf("|cffff9933%d|r", num);
Zerotorescue@61 566 elseif percentage >= addon.db.profile.defaults.colors.red then
Zerotorescue@62 567 return printf("|cffff0000%d|r", num);
Zerotorescue@0 568 end
Zerotorescue@0 569 end
Zerotorescue@0 570
Zerotorescue@1 571 function mod:DisplayMoney(value, priceThreshold)
Zerotorescue@7 572 if value == -1 then
Zerotorescue@7 573 return "|cff0000ffNone up|r";
Zerotorescue@7 574 elseif value == -2 then
Zerotorescue@7 575 return "|cff0000ffNo AH mod|r";
Zerotorescue@9 576 elseif value == -3 then
Zerotorescue@9 577 return "|cffffff00Unknown|r";
Zerotorescue@13 578 elseif value == -4 then
Zerotorescue@13 579 return "|cff00ff00-|r";
Zerotorescue@23 580 elseif value == -5 then
Zerotorescue@23 581 return "|cffff9933Error|r";
Zerotorescue@23 582 elseif priceThreshold and value < priceThreshold then
Zerotorescue@62 583 return printf("|cffaaaaaa%s|r", sgsub(addon:ReadableMoney(value or 0, true), "|([a-fA-F0-9]+)([gsc]+)|r", "%2"));
Zerotorescue@1 584 else
Zerotorescue@1 585 return addon:ReadableMoney(value or 0, true);
Zerotorescue@1 586 end
Zerotorescue@1 587 end
Zerotorescue@1 588
Zerotorescue@9 589 function mod:DisplayItemCount(value, minimumStock)
Zerotorescue@13 590 if value == -1 then
Zerotorescue@13 591 return "|cffffff00Unknown|r";
Zerotorescue@13 592 elseif value == -3 then
Zerotorescue@9 593 return "|cffffff00Unknown|r";
Zerotorescue@9 594 else
Zerotorescue@62 595 return printf("%s / %d", self:ColorCode(value, minimumStock), minimumStock);
Zerotorescue@9 596 end
Zerotorescue@9 597 end
Zerotorescue@9 598
Zerotorescue@0 599 function mod:NumberFormat(num)
Zerotorescue@62 600 local formatted = sgsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
Zerotorescue@0 601
Zerotorescue@0 602 while true do
Zerotorescue@62 603 formatted, matches = sgsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);
Zerotorescue@0 604
Zerotorescue@0 605 if matches == 0 then
Zerotorescue@0 606 break;
Zerotorescue@0 607 end
Zerotorescue@0 608 end
Zerotorescue@0 609
Zerotorescue@0 610 return formatted;
Zerotorescue@1 611 end