annotate Summary.lua @ 17:8f5c02113c5c

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