annotate Summary.lua @ 13:5006cb0e97c6

Removed sound media registrations since we don?t use them. Added an option to include tadeskill items above a certain item level threshold in the add items config tab. Renamed the variable for toggling hiding from summary when below price threshold-option. You will have to re-set it. Summary size and processing speed will now be remembered. Processing speed slider can now go up to 500% (up from 100%). Silver will be hidden from money when it includes more than 10 gold (down from 100g) and copper will be hidden if it includes more than 1 gold (down from 10g). Auction addons, crafting addons and itemcount addons can now register themselves through a few global functions. The most used addons have been included in the addon folder. You can now select the prefered default pricing, item count and crafting addons. Temporarily removed the ?dialogControl = ?DropDown?? from the track at select boxes. This functionality is broken within the Ace3 library and until it is fixed I wish to keep these options somewhat functional. The item list will now be truncated before rebuilding. Previously items disappearing from your inventory would still appear in this list. Mass add is now functional. All buttons and sliders that were meant to receive a tooltip (including the sort-headers), now have one. Added spacers between all buttons and sliders of the summary window. Added a ?queue all? button to the summary window. This button is not yet functional. If the value of an item is not retrieved from the auction prices database, it will appear as a dash (-) rather than ?0c?. If no item count is enabled, item counts will appear as ?Unknown? instead of breaking (or defaulting to 0).
author Zerotorescue
date Mon, 18 Oct 2010 15:26:42 +0200
parents 417c3cfb9623
children 0fc8a54516d7
rev   line source
Zerotorescue@11 1 local addon = LibStub("AceAddon-3.0"):GetAddon("Inventorium");
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@0 49 local button = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate");
Zerotorescue@0 50 button:SetText(buttonSettings.name);
Zerotorescue@0 51 button:SetHeight(22);
Zerotorescue@0 52 button:SetWidth(120);
Zerotorescue@0 53 button:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
Zerotorescue@0 54 button:SetScript("OnClick", buttonSettings.exec);
Zerotorescue@0 55 button.tooltipTitle = buttonSettings.name;
Zerotorescue@0 56 button.tooltip = buttonSettings.desc or "";
Zerotorescue@13 57 button:SetScript("OnEnter", ShowTooltip);
Zerotorescue@13 58 button:SetScript("OnLeave", HideTooltip);
Zerotorescue@0 59 else
Zerotorescue@0 60 error("settings must be a table - usage: MakeButton(table);");
Zerotorescue@0 61 end
Zerotorescue@0 62 end
Zerotorescue@0 63
Zerotorescue@0 64 return widget;
Zerotorescue@0 65 end
Zerotorescue@0 66
Zerotorescue@0 67 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
Zerotorescue@0 68 end
Zerotorescue@0 69
Zerotorescue@1 70 local itemsCache = {};
Zerotorescue@13 71
Zerotorescue@13 72 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
Zerotorescue@1 73 local cacheStart;
Zerotorescue@1 74
Zerotorescue@0 75 function mod:BuildMain()
Zerotorescue@11 76 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
Zerotorescue@0 77
Zerotorescue@10 78 self:CloseFrame();
Zerotorescue@10 79
Zerotorescue@1 80 -- Main Window
Zerotorescue@1 81 mod.frame = AceGUI:Create("Frame");
Zerotorescue@13 82 mod.frame:SetTitle("Summary");
Zerotorescue@1 83 mod.frame:SetLayout("Fill");
Zerotorescue@1 84 mod.frame:SetCallback("OnClose", function(widget)
Zerotorescue@7 85 mod:CancelTimer(self.tmrUpdater, true);
Zerotorescue@9 86 mod:CloseFrame();
Zerotorescue@1 87 end);
Zerotorescue@13 88 mod.frame:SetWidth(addon.db.global.defaults.summary.width);
Zerotorescue@13 89 mod.frame:SetHeight(addon.db.global.defaults.summary.height);
Zerotorescue@13 90 mod.frame.OnWidthSet = function(_, width)
Zerotorescue@13 91 addon.db.global.defaults.summary.width = width;
Zerotorescue@13 92 end;
Zerotorescue@13 93 mod.frame.OnHeightSet = function(_, height)
Zerotorescue@13 94 addon.db.global.defaults.summary.height = height;
Zerotorescue@13 95 end;
Zerotorescue@0 96
Zerotorescue@1 97 -- ScrollFrame child
Zerotorescue@1 98 mod.scrollFrame = AceGUI:Create("ScrollFrame");
Zerotorescue@1 99 mod.scrollFrame:SetLayout("Flow");
Zerotorescue@0 100
Zerotorescue@1 101 mod.frame:AddChild(mod.scrollFrame);
Zerotorescue@1 102
Zerotorescue@1 103 -- Reset items cache
Zerotorescue@1 104 table.wipe(itemsCache);
Zerotorescue@0 105 end
Zerotorescue@0 106
Zerotorescue@9 107 function mod:CloseFrame()
Zerotorescue@9 108 if mod.frame then
Zerotorescue@9 109 mod.frame:Release();
Zerotorescue@9 110 mod.frame = nil;
Zerotorescue@10 111
Zerotorescue@10 112 -- Stop caching
Zerotorescue@10 113
Zerotorescue@10 114 -- Stop timer
Zerotorescue@10 115 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@10 116
Zerotorescue@10 117 -- Reset trackers
Zerotorescue@10 118 CACHE_ITEMS_TOTAL = 0;
Zerotorescue@10 119 CACHE_ITEMS_CURRENT = 0;
Zerotorescue@9 120 end
Zerotorescue@9 121 end
Zerotorescue@9 122
Zerotorescue@0 123 local sortMethod = "item";
Zerotorescue@0 124 local sortDirectory = "ASC";
Zerotorescue@0 125 local function ReSort(subject)
Zerotorescue@0 126 if sortMethod == subject then
Zerotorescue@0 127 sortDirectory = (sortDirectory == "ASC" and "DESC") or "ASC";
Zerotorescue@0 128 else
Zerotorescue@0 129 sortDirectory = "ASC";
Zerotorescue@0 130 end
Zerotorescue@0 131 sortMethod = subject;
Zerotorescue@0 132
Zerotorescue@0 133 mod:Build();
Zerotorescue@0 134 end
Zerotorescue@10 135
Zerotorescue@10 136 -- From http://www.wowwiki.com/API_sort
Zerotorescue@10 137 local function pairsByKeys (t, f)
Zerotorescue@10 138 local a = {}
Zerotorescue@10 139 for n in pairs(t) do table.insert(a, n) end
Zerotorescue@10 140 table.sort(a, f)
Zerotorescue@10 141 local i = 0 -- iterator variable
Zerotorescue@10 142 local iter = function () -- iterator function
Zerotorescue@10 143 i = i + 1
Zerotorescue@10 144 if a[i] == nil then return nil
Zerotorescue@10 145 else return a[i], t[a[i]]
Zerotorescue@10 146 end
Zerotorescue@10 147 end
Zerotorescue@10 148 return iter
Zerotorescue@10 149 end
Zerotorescue@0 150
Zerotorescue@0 151 function mod:Build()
Zerotorescue@10 152 local buildStartTime, times = GetTime(), {};
Zerotorescue@0 153
Zerotorescue@1 154 -- 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 155 -- This appears to be required for each container we wish to pause, so also do this for the contents
Zerotorescue@1 156 mod.scrollFrame:PauseLayout();
Zerotorescue@1 157
Zerotorescue@10 158 mod.scrollFrame:ReleaseChildren();
Zerotorescue@10 159
Zerotorescue@10 160 -- Refresh button
Zerotorescue@10 161 local btnRefresh = AceGUI:Create("Button");
Zerotorescue@10 162 btnRefresh:SetText("Refresh");
Zerotorescue@10 163 btnRefresh:SetRelativeWidth(.2);
Zerotorescue@10 164 btnRefresh:SetCallback("OnClick", function()
Zerotorescue@10 165 -- Reset items cache
Zerotorescue@10 166 table.wipe(itemsCache);
Zerotorescue@10 167
Zerotorescue@10 168 -- Rebuild itemlist and start caching
Zerotorescue@10 169 mod:Build();
Zerotorescue@10 170 end);
Zerotorescue@13 171 btnRefresh:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 172 btnRefresh:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 173 btnRefresh.frame.tooltipTitle = "Refresh Cache";
Zerotorescue@13 174 btnRefresh.frame.tooltip = "Refresh the list and recache the item counts and auction values.";
Zerotorescue@10 175
Zerotorescue@10 176 mod.scrollFrame:AddChild(btnRefresh);
Zerotorescue@10 177
Zerotorescue@13 178 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 179 lblSpacer:SetRelativeWidth(.03);
Zerotorescue@13 180
Zerotorescue@13 181 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 182
Zerotorescue@10 183 -- Speed slider
Zerotorescue@13 184 local sdrSpeed = AceGUI:Create("Slider");
Zerotorescue@13 185 sdrSpeed:SetLabel("Processing speed");
Zerotorescue@13 186 sdrSpeed:SetSliderValues(0.01, 5, 0.01);
Zerotorescue@13 187 sdrSpeed:SetIsPercent(true);
Zerotorescue@13 188 sdrSpeed:SetRelativeWidth(.3);
Zerotorescue@13 189 sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
Zerotorescue@13 190 addon.db.global.defaults.summary.speed = ceil( value * 100 / 5 );
Zerotorescue@13 191
Zerotorescue@13 192 CACHE_ITEMS_PER_UPDATE = addon.db.global.defaults.summary.speed; -- max = 20, min = 1
Zerotorescue@10 193 end);
Zerotorescue@13 194 sdrSpeed:SetValue( addon.db.global.defaults.summary.speed * 5 / 100 );
Zerotorescue@13 195 sdrSpeed:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 196 sdrSpeed:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 197 sdrSpeed.frame.tooltipTitle = "Caching Processing Speed";
Zerotorescue@13 198 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 199
Zerotorescue@13 200 mod.scrollFrame:AddChild(sdrSpeed);
Zerotorescue@13 201
Zerotorescue@13 202 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 203 lblSpacer:SetRelativeWidth(.23);
Zerotorescue@13 204
Zerotorescue@13 205 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 206
Zerotorescue@13 207 -- Config button
Zerotorescue@13 208 --[[local btnConfig = AceGUI:Create("Button");
Zerotorescue@13 209 btnConfig:SetText("Config");
Zerotorescue@13 210 btnConfig:SetRelativeWidth(.2);
Zerotorescue@13 211 btnConfig:SetCallback("OnClick", function()
Zerotorescue@13 212 --TODO: Tidy up
Zerotorescue@13 213 SlashCmdList["INVENTORIUM"]("config");
Zerotorescue@13 214 end);
Zerotorescue@13 215 btnConfig:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 216 btnConfig:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 217 btnConfig.frame.tooltipTitle = "Config";
Zerotorescue@13 218 btnConfig.frame.tooltip = "Click to open the config window. This will close the current window.";
Zerotorescue@13 219
Zerotorescue@13 220 mod.scrollFrame:AddChild(btnConfig);]]
Zerotorescue@13 221
Zerotorescue@13 222 local lblSpacer = AceGUI:Create("Label");
Zerotorescue@13 223 lblSpacer:SetRelativeWidth(.03);
Zerotorescue@13 224
Zerotorescue@13 225 mod.scrollFrame:AddChild(lblSpacer);
Zerotorescue@13 226
Zerotorescue@13 227 -- Queue all button
Zerotorescue@13 228 local btnQueueAll = AceGUI:Create("Button");
Zerotorescue@13 229 btnQueueAll:SetText("Queue All");
Zerotorescue@13 230 btnQueueAll:SetRelativeWidth(.2);
Zerotorescue@13 231 btnQueueAll:SetCallback("OnClick", function()
Zerotorescue@13 232
Zerotorescue@13 233 end);
Zerotorescue@13 234 btnQueueAll:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 235 btnQueueAll:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 236 btnQueueAll.frame.tooltipTitle = "Queue all";
Zerotorescue@13 237 btnQueueAll.frame.tooltip = "Queue everything that requires restocking within every single visible group.";
Zerotorescue@13 238
Zerotorescue@13 239 mod.scrollFrame:AddChild(btnQueueAll);
Zerotorescue@10 240
Zerotorescue@10 241 times.init = ceil( ( GetTime() - buildStartTime ) * 1000 );
Zerotorescue@10 242 addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
Zerotorescue@10 243
Zerotorescue@1 244 local playerName = UnitName("player");
Zerotorescue@1 245
Zerotorescue@1 246 -- Go through all our stored groups
Zerotorescue@10 247 for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do
Zerotorescue@10 248 local groupStartTime, groupTimes = GetTime(), {};
Zerotorescue@10 249
Zerotorescue@1 250 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
Zerotorescue@1 251
Zerotorescue@1 252 -- Does this group have any items and do we want to track it at this char?
Zerotorescue@1 253 if values.items and trackAt[playerName] then
Zerotorescue@10 254
Zerotorescue@10 255
Zerotorescue@0 256 -- Get group settings
Zerotorescue@9 257 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
Zerotorescue@1 258 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
Zerotorescue@1 259 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
Zerotorescue@1 260 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
Zerotorescue@0 261
Zerotorescue@10 262
Zerotorescue@0 263 -- Make group container
Zerotorescue@0 264 local iGroup = AceGUI:Create("InlineGroupWithButton");
Zerotorescue@1 265 iGroup:PauseLayout();
Zerotorescue@0 266 iGroup:SetTitle(groupName);
Zerotorescue@0 267 iGroup:SetFullWidth(true);
Zerotorescue@0 268 iGroup:SetLayout("Flow");
Zerotorescue@0 269 iGroup:MakeButton({
Zerotorescue@0 270 name = "Queue",
Zerotorescue@0 271 desc = "Queue all items in this group.",
Zerotorescue@0 272 exec = function()
Zerotorescue@0 273 print(groupName);
Zerotorescue@0 274 end,
Zerotorescue@0 275 });
Zerotorescue@0 276
Zerotorescue@10 277
Zerotorescue@10 278
Zerotorescue@0 279 -- Headers
Zerotorescue@1 280
Zerotorescue@0 281 -- Itemlink
Zerotorescue@0 282 local lblItem = AceGUI:Create("InteractiveLabel");
Zerotorescue@0 283 lblItem:SetText("|cfffed000Item|r");
Zerotorescue@0 284 lblItem:SetFontObject(GameFontHighlight);
Zerotorescue@10 285 lblItem:SetRelativeWidth(.7);
Zerotorescue@0 286 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
Zerotorescue@13 287 lblItem:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 288 lblItem:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 289 lblItem.frame.tooltipTitle = "Item";
Zerotorescue@13 290 lblItem.frame.tooltip = "Sort on the item quality, then name.";
Zerotorescue@0 291
Zerotorescue@0 292 iGroup:AddChild(lblItem);
Zerotorescue@0 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@0 307 -- Required stock
Zerotorescue@9 308 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
Zerotorescue@13 309 lblMinimumStock:SetText("|cfffed000Min.|r");
Zerotorescue@9 310 lblMinimumStock:SetFontObject(GameFontHighlight);
Zerotorescue@10 311 lblMinimumStock:SetRelativeWidth(.099);
Zerotorescue@9 312 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
Zerotorescue@13 313 lblMinimumStock:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 314 lblMinimumStock:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 315 lblMinimumStock.frame.tooltipTitle = "Minimum stock";
Zerotorescue@13 316 lblMinimumStock.frame.tooltip = "Sort on the minimum amount of items you wish to keep in stock.";
Zerotorescue@0 317
Zerotorescue@9 318 iGroup:AddChild(lblMinimumStock);
Zerotorescue@0 319
Zerotorescue@1 320 -- Lowest value
Zerotorescue@1 321 local lblValue = AceGUI:Create("InteractiveLabel");
Zerotorescue@1 322 lblValue:SetText("|cfffed000Value|r");
Zerotorescue@1 323 lblValue:SetFontObject(GameFontHighlight);
Zerotorescue@10 324 lblValue:SetRelativeWidth(.099);
Zerotorescue@1 325 lblValue:SetCallback("OnClick", function() ReSort("value"); end);
Zerotorescue@13 326 lblValue:SetCallback("OnEnter", ShowTooltip);
Zerotorescue@13 327 lblValue:SetCallback("OnLeave", HideTooltip);
Zerotorescue@13 328 lblValue.frame.tooltipTitle = "Value";
Zerotorescue@13 329 lblValue.frame.tooltip = "Sort on the item auction value.";
Zerotorescue@1 330
Zerotorescue@1 331 iGroup:AddChild(lblValue);
Zerotorescue@1 332
Zerotorescue@10 333
Zerotorescue@10 334 -- Retrieve items list
Zerotorescue@1 335 if not itemsCache[groupName] then
Zerotorescue@1 336 itemsCache[groupName] = {};
Zerotorescue@0 337
Zerotorescue@12 338 local unknownItemName = "Unknown (#%d)";
Zerotorescue@12 339
Zerotorescue@1 340 -- Sort item list
Zerotorescue@12 341 for itemId, _ in pairs(values.items) do
Zerotorescue@1 342 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
Zerotorescue@1 343
Zerotorescue@1 344 table.insert(itemsCache[groupName], {
Zerotorescue@1 345 id = itemId,
Zerotorescue@12 346 name = itemName or unknownItemName:format(itemId),
Zerotorescue@12 347 link = itemLink or unknownItemName:format(itemId),
Zerotorescue@13 348 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 349 rarity = itemRarity or 1,
Zerotorescue@9 350 count = -3,--addon:GetItemCount(itemId),
Zerotorescue@1 351 set = {},
Zerotorescue@1 352 });
Zerotorescue@1 353 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
Zerotorescue@1 354 end
Zerotorescue@0 355 end
Zerotorescue@0 356
Zerotorescue@10 357 groupTimes.init = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 358
Zerotorescue@10 359
Zerotorescue@10 360
Zerotorescue@10 361 -- Sort items
Zerotorescue@1 362 table.sort(itemsCache[groupName], function(a, b)
Zerotorescue@1 363 if sortMethod == "item" and a.rarity == b.rarity then
Zerotorescue@1 364 -- Do a name-compare for items of the same rarity
Zerotorescue@1 365 -- Otherwise epics first, then junk
Zerotorescue@0 366 if sortDirectory == "ASC" then
Zerotorescue@1 367 return a.name:upper() < b.name:upper();
Zerotorescue@0 368 else
Zerotorescue@1 369 return a.name:upper() > b.name:upper();
Zerotorescue@1 370 end
Zerotorescue@1 371 elseif sortMethod == "item" then
Zerotorescue@1 372 if sortDirectory == "ASC" then
Zerotorescue@1 373 return a.rarity > b.rarity; -- the comparers were reversed because we want epics first
Zerotorescue@1 374 else
Zerotorescue@1 375 return a.rarity < b.rarity; -- the comparers were reversed because we want epics first
Zerotorescue@0 376 end
Zerotorescue@0 377 elseif sortMethod == "current" then
Zerotorescue@0 378 if sortDirectory == "ASC" then
Zerotorescue@0 379 return a.count < b.count;
Zerotorescue@0 380 else
Zerotorescue@0 381 return a.count > b.count;
Zerotorescue@0 382 end
Zerotorescue@0 383 elseif sortMethod == "percentage" then
Zerotorescue@0 384 if sortDirectory == "ASC" then
Zerotorescue@10 385 return ( a.count / minimumStock ) < ( b.count / minimumStock );
Zerotorescue@0 386 else
Zerotorescue@10 387 return ( a.count / minimumStock ) > ( b.count / minimumStock );
Zerotorescue@0 388 end
Zerotorescue@1 389 elseif sortMethod == "value" then
Zerotorescue@1 390 if sortDirectory == "ASC" then
Zerotorescue@1 391 return a.value < b.value;
Zerotorescue@1 392 else
Zerotorescue@1 393 return a.value > b.value;
Zerotorescue@1 394 end
Zerotorescue@0 395 end
Zerotorescue@0 396 end);
Zerotorescue@0 397
Zerotorescue@10 398 groupTimes.sorting = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 399
Zerotorescue@10 400
Zerotorescue@10 401
Zerotorescue@10 402
Zerotorescue@10 403 -- Show itemslist
Zerotorescue@1 404 for i, item in pairs(itemsCache[groupName]) do
Zerotorescue@9 405 if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
Zerotorescue@0 406 local btnItemLink = AceGUI:Create("ItemLinkButton");
Zerotorescue@10 407 --btnItemLink:SetUserData("exec", function()
Zerotorescue@10 408 -- print("Nothing happening yet.");
Zerotorescue@10 409 --end);
Zerotorescue@10 410 btnItemLink:SetRelativeWidth(.7);
Zerotorescue@1 411 btnItemLink:SetItemId(item.id);
Zerotorescue@0 412
Zerotorescue@0 413 iGroup:AddChild(btnItemLink);
Zerotorescue@0 414
Zerotorescue@0 415 -- Current quantity
Zerotorescue@0 416 local lblQuantity = AceGUI:Create("Label");
Zerotorescue@9 417 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
Zerotorescue@10 418 lblQuantity:SetRelativeWidth(.099);
Zerotorescue@0 419
Zerotorescue@0 420 iGroup:AddChild(lblQuantity);
Zerotorescue@0 421
Zerotorescue@0 422 -- Required stock
Zerotorescue@9 423 local lblMinimumStock = AceGUI:Create("Label");
Zerotorescue@9 424 lblMinimumStock:SetText(minimumStock);
Zerotorescue@10 425 lblMinimumStock:SetRelativeWidth(.099);
Zerotorescue@0 426
Zerotorescue@9 427 iGroup:AddChild(lblMinimumStock);
Zerotorescue@1 428
Zerotorescue@1 429 -- Value
Zerotorescue@1 430 local lblValue = AceGUI:Create("Label");
Zerotorescue@1 431 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
Zerotorescue@10 432 lblValue:SetRelativeWidth(.099);
Zerotorescue@1 433
Zerotorescue@1 434 iGroup:AddChild(lblValue);
Zerotorescue@1 435
Zerotorescue@1 436 -- Remember references to the value and current fields so we can fill them later
Zerotorescue@1 437 if item.set then
Zerotorescue@10 438 -- -3 means the price is unknown, queue look up
Zerotorescue@10 439 if item.value == -3 then
Zerotorescue@10 440 item.set.value = lblValue;
Zerotorescue@10 441 end
Zerotorescue@10 442 if item.count == -3 then
Zerotorescue@10 443 item.set.current = lblQuantity;
Zerotorescue@10 444 end
Zerotorescue@10 445
Zerotorescue@10 446 -- Don't queue if we already know everything we want to know
Zerotorescue@10 447 if item.value ~= -3 and item.count ~= -3 then
Zerotorescue@10 448 item.set = nil;
Zerotorescue@10 449 end
Zerotorescue@1 450 end
Zerotorescue@0 451 end
Zerotorescue@0 452 end
Zerotorescue@0 453
Zerotorescue@10 454 groupTimes.preparing = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@10 455
Zerotorescue@1 456 iGroup:ResumeLayout();
Zerotorescue@1 457 mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
Zerotorescue@10 458
Zerotorescue@10 459 groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 );
Zerotorescue@0 460 end
Zerotorescue@10 461
Zerotorescue@13 462 if groupStartTime and groupTimes then
Zerotorescue@13 463 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 464 end
Zerotorescue@0 465 end
Zerotorescue@1 466
Zerotorescue@1 467 mod.scrollFrame:ResumeLayout();
Zerotorescue@1 468 mod.scrollFrame:DoLayout();
Zerotorescue@1 469
Zerotorescue@10 470 addon:Debug(("Done building summary after %d ms."):format(ceil( ( GetTime() - buildStartTime ) * 1000 )));
Zerotorescue@10 471
Zerotorescue@1 472 if CACHE_ITEMS_TOTAL > 0 then
Zerotorescue@1 473 cacheStart = GetTime();
Zerotorescue@7 474 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@1 475 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 476 end
Zerotorescue@1 477 end
Zerotorescue@1 478
Zerotorescue@1 479 function mod:UpdateNextItem()
Zerotorescue@1 480 local i = 0;
Zerotorescue@1 481
Zerotorescue@1 482 for groupName, items in pairs(itemsCache) do
Zerotorescue@1 483 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
Zerotorescue@1 484 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@1 485
Zerotorescue@1 486 for _, item in pairs(items) do
Zerotorescue@1 487 if item.set then
Zerotorescue@10 488 if item.count == -3 then
Zerotorescue@10 489 -- Only if item count was queued, update it
Zerotorescue@10 490 item.count = addon:GetItemCount(item.id);
Zerotorescue@10 491 if item.set.current and item.set.current.SetText then
Zerotorescue@10 492 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
Zerotorescue@10 493 end
Zerotorescue@1 494 end
Zerotorescue@1 495
Zerotorescue@10 496 if item.value == -3 then
Zerotorescue@10 497 -- Only if item value was queued, update it
Zerotorescue@10 498 item.value = addon:GetAuctionValue(item.link);
Zerotorescue@10 499 if item.set.value and item.set.value.SetText then
Zerotorescue@10 500 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
Zerotorescue@10 501 end
Zerotorescue@1 502 end
Zerotorescue@1 503
Zerotorescue@1 504 item.set = nil;
Zerotorescue@1 505
Zerotorescue@1 506 i = i + 1;
Zerotorescue@1 507 CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
Zerotorescue@1 508
Zerotorescue@9 509 if mod.frame then
Zerotorescue@9 510 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 511 end
Zerotorescue@1 512
Zerotorescue@13 513 if i >= addon.db.global.defaults.summary.speed then
Zerotorescue@1 514 return;
Zerotorescue@1 515 end
Zerotorescue@1 516 end
Zerotorescue@1 517 end
Zerotorescue@1 518 end
Zerotorescue@1 519
Zerotorescue@1 520 -- Reset trackers
Zerotorescue@1 521 CACHE_ITEMS_TOTAL = 0;
Zerotorescue@1 522 CACHE_ITEMS_CURRENT = 0;
Zerotorescue@1 523
Zerotorescue@1 524 -- Stop timer
Zerotorescue@1 525 self:CancelTimer(self.tmrUpdater, true);
Zerotorescue@10 526
Zerotorescue@10 527 -- Rebuild list so hidden items due to too low prices get added
Zerotorescue@10 528 self:Build();
Zerotorescue@1 529
Zerotorescue@1 530 -- Announce
Zerotorescue@10 531 mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. ceil(GetTime() - cacheStart) .. " seconds.");
Zerotorescue@1 532
Zerotorescue@1 533 -- Forget time
Zerotorescue@1 534 cacheStart = nil;
Zerotorescue@0 535 end
Zerotorescue@0 536
Zerotorescue@0 537 function mod:ColorCode(num, required)
Zerotorescue@0 538 local percentage = ( num / required );
Zerotorescue@0 539
Zerotorescue@0 540 if percentage >= addon.db.global.defaults.colors.green then
Zerotorescue@0 541 return ("|cff00ff00%d|r"):format(num);
Zerotorescue@0 542 elseif percentage >= addon.db.global.defaults.colors.yellow then
Zerotorescue@0 543 return ("|cffffff00%d|r"):format(num);
Zerotorescue@0 544 elseif percentage >= addon.db.global.defaults.colors.orange then
Zerotorescue@0 545 return ("|cffff9933%d|r"):format(num);
Zerotorescue@0 546 elseif percentage >= addon.db.global.defaults.colors.red then
Zerotorescue@0 547 return ("|cffff0000%d|r"):format(num);
Zerotorescue@0 548 end
Zerotorescue@0 549 end
Zerotorescue@0 550
Zerotorescue@1 551 function mod:DisplayMoney(value, priceThreshold)
Zerotorescue@7 552 if value == -1 then
Zerotorescue@7 553 return "|cff0000ffNone up|r";
Zerotorescue@7 554 elseif value == -2 then
Zerotorescue@7 555 return "|cff0000ffNo AH mod|r";
Zerotorescue@9 556 elseif value == -3 then
Zerotorescue@9 557 return "|cffffff00Unknown|r";
Zerotorescue@13 558 elseif value == -4 then
Zerotorescue@13 559 return "|cff00ff00-|r";
Zerotorescue@7 560 elseif value < priceThreshold then
Zerotorescue@1 561 return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
Zerotorescue@1 562 else
Zerotorescue@1 563 return addon:ReadableMoney(value or 0, true);
Zerotorescue@1 564 end
Zerotorescue@1 565 end
Zerotorescue@1 566
Zerotorescue@9 567 function mod:DisplayItemCount(value, minimumStock)
Zerotorescue@13 568 if value == -1 then
Zerotorescue@13 569 return "|cffffff00Unknown|r";
Zerotorescue@13 570 elseif value == -3 then
Zerotorescue@9 571 return "|cffffff00Unknown|r";
Zerotorescue@9 572 else
Zerotorescue@9 573 return self:ColorCode(value, minimumStock);
Zerotorescue@9 574 end
Zerotorescue@9 575 end
Zerotorescue@9 576
Zerotorescue@0 577 function mod:NumberFormat(num)
Zerotorescue@0 578 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
Zerotorescue@0 579
Zerotorescue@0 580 while true do
Zerotorescue@0 581 formatted, matches = string.gsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);
Zerotorescue@0 582
Zerotorescue@0 583 if matches == 0 then
Zerotorescue@0 584 break;
Zerotorescue@0 585 end
Zerotorescue@0 586 end
Zerotorescue@0 587
Zerotorescue@0 588 return formatted;
Zerotorescue@1 589 end