annotate Core.lua @ 24:db57cd9273f1

Fixed premade item data update check.
author Zerotorescue
date Thu, 28 Oct 2010 19:20:33 +0200
parents 7d7aaa3fbe94
children 8177b5bcb883
rev   line source
Zerotorescue@11 1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium")
Zerotorescue@17 2 local addon = select(2, ...);
Zerotorescue@17 3 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0");
Zerotorescue@1 4
Zerotorescue@1 5 local AceGUI = LibStub("AceGUI-3.0");
Zerotorescue@0 6
Zerotorescue@0 7 local AceConfigDialog, AceConfigRegistry, AceSerializer;
Zerotorescue@0 8 local groupIdToName = {};
Zerotorescue@0 9 local options = {};
Zerotorescue@13 10 local includeTradeSkillItems = 500;
Zerotorescue@13 11
Zerotorescue@13 12 -- All modules must be able to retrieve our supported addons database, thus keep it public
Zerotorescue@13 13 addon.supportedAddons = {};
Zerotorescue@13 14 addon.supportedAddons.auctionPricing = {};
Zerotorescue@13 15 addon.supportedAddons.itemCount = {};
Zerotorescue@13 16 addon.supportedAddons.crafting = {};
Zerotorescue@0 17
Zerotorescue@0 18 function addon:OnInitialize()
Zerotorescue@0 19 self:Debug("OnInitialize");
Zerotorescue@0 20
Zerotorescue@0 21 -- SAVED VARIABLES
Zerotorescue@0 22
Zerotorescue@0 23 local defaults = {
Zerotorescue@0 24 global = {
Zerotorescue@0 25 groups = {},
Zerotorescue@0 26 defaults = {
Zerotorescue@13 27 auctionPricingAddon = "Auctioneer",
Zerotorescue@13 28 itemCountAddon = "Altoholic",
Zerotorescue@13 29 craftingAddon = "AdvancedTradeSkillWindow",
Zerotorescue@0 30 minimumStock = 60,
Zerotorescue@0 31 alertBelowMinimum = true,
Zerotorescue@0 32 summaryThresholdShow = 10,
Zerotorescue@0 33 restockTarget = 60,
Zerotorescue@0 34 minCraftingQueue = 0.05,
Zerotorescue@0 35 bonusQueue = 0.1,
Zerotorescue@0 36 priceThreshold = 0,
Zerotorescue@13 37 summaryHidePriceThreshold = false,
Zerotorescue@0 38 trackAtCharacters = {},
Zerotorescue@13 39 summary = {
Zerotorescue@13 40 speed = 5,
Zerotorescue@13 41 width = 650,
Zerotorescue@13 42 height = 600,
Zerotorescue@13 43 },
Zerotorescue@0 44 colors = {
Zerotorescue@17 45 red = 0,
Zerotorescue@17 46 orange = 0.3,
Zerotorescue@17 47 yellow = 0.6,
Zerotorescue@17 48 green = 0.95,
Zerotorescue@0 49 },
Zerotorescue@0 50 },
Zerotorescue@0 51 },
Zerotorescue@0 52 factionrealm = {
Zerotorescue@0 53 characters = {},
Zerotorescue@0 54 },
Zerotorescue@0 55 };
Zerotorescue@0 56
Zerotorescue@0 57 -- Register our saved variables database
Zerotorescue@11 58 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
Zerotorescue@0 59
Zerotorescue@0 60 -- SLASH COMMANDS
Zerotorescue@0 61
Zerotorescue@0 62 -- Disable the AddonLoader slash commands
Zerotorescue@11 63 SLASH_INVENTORIUM1 = nil;
Zerotorescue@0 64 SLASH_IY1 = nil;
Zerotorescue@0 65
Zerotorescue@0 66 -- Register our own slash commands
Zerotorescue@11 67 SLASH_INVENTORIUM1 = "/inventorium";
Zerotorescue@11 68 SLASH_INVENTORIUM2 = "/im";
Zerotorescue@11 69 SlashCmdList["INVENTORIUM"] = function(msg)
Zerotorescue@0 70 self:CommandHandler(msg);
Zerotorescue@0 71 end
Zerotorescue@0 72
Zerotorescue@0 73 -- INTERFACE OPTIONS
Zerotorescue@0 74
Zerotorescue@0 75 -- Attempt to remove the interface options added by AddonLoader (if enabled)
Zerotorescue@0 76 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
Zerotorescue@11 77 AddonLoader:RemoveInterfaceOptions("Inventorium");
Zerotorescue@0 78 end
Zerotorescue@0 79
Zerotorescue@0 80 -- Now create our own options frame
Zerotorescue@0 81 local frame = CreateFrame("Frame", nil, UIParent);
Zerotorescue@0 82 frame:Hide();
Zerotorescue@11 83 frame.name = "Inventorium";
Zerotorescue@0 84 frame:HookScript("OnShow", function(self)
Zerotorescue@0 85 -- Refresh the frame to instantly show the right options
Zerotorescue@0 86 InterfaceOptionsFrame_OpenToCategory(self.name)
Zerotorescue@0 87 end);
Zerotorescue@0 88 -- And add it to the interface options
Zerotorescue@0 89 InterfaceOptions_AddCategory(frame);
Zerotorescue@0 90
Zerotorescue@1 91 self:MakeItemLinkButtonWidget();
Zerotorescue@1 92 self:MakeConfigItemLinkButtonWidget();
Zerotorescue@0 93
Zerotorescue@0 94 -- Remember this character is mine
Zerotorescue@0 95 local playerName = UnitName("player");
Zerotorescue@0 96 if not self.db.factionrealm.characters[playerName] then
Zerotorescue@0 97 self.db.factionrealm.characters[playerName] = true;
Zerotorescue@0 98
Zerotorescue@0 99 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
Zerotorescue@0 100 self.db.global.defaults.trackAtCharacters[playerName] = true;
Zerotorescue@0 101 end
Zerotorescue@23 102
Zerotorescue@23 103 self:PremadeGroupsCheck();
Zerotorescue@0 104 end
Zerotorescue@0 105
Zerotorescue@24 106 local function InGroup(itemId)
Zerotorescue@24 107 -- Go through all groups to see if this item is already somewhere
Zerotorescue@24 108 for groupName, values in pairs(addon.db.global.groups) do
Zerotorescue@24 109 if values.items and values.items[itemId] then
Zerotorescue@24 110 return groupName;
Zerotorescue@24 111 end
Zerotorescue@24 112 end
Zerotorescue@24 113
Zerotorescue@24 114 return;
Zerotorescue@24 115 end
Zerotorescue@24 116
Zerotorescue@23 117 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept)
Zerotorescue@23 118 -- Compare the current premade groups with those used, notify about changes
Zerotorescue@23 119 if addon.defaultGroups then
Zerotorescue@23 120 for key, groupInfo in pairs(addon.defaultGroups) do
Zerotorescue@23 121 -- Go through all default groups
Zerotorescue@23 122
Zerotorescue@23 123 for groupName, values in pairs(addon.db.global.groups) do
Zerotorescue@23 124 -- Go through all groups to find those with this premade group
Zerotorescue@23 125
Zerotorescue@23 126 if values.premadeGroups and values.premadeGroups[key] and values.premadeGroups[key] < groupInfo.version then
Zerotorescue@23 127 -- Outdated group
Zerotorescue@23 128
Zerotorescue@23 129 if updateGroupName and updateKey then
Zerotorescue@23 130 -- This function was called after pressing yes or no in a confirm box
Zerotorescue@23 131
Zerotorescue@23 132 if accept then
Zerotorescue@23 133 -- Yes was clicked
Zerotorescue@23 134
Zerotorescue@23 135 for itemId, version in pairs(groupInfo.items) do
Zerotorescue@23 136 -- Go through all items in this premade group
Zerotorescue@23 137
Zerotorescue@23 138 if version > values.premadeGroups[key] then
Zerotorescue@23 139 -- This item was added in a more recent version than this group: Add item
Zerotorescue@23 140
Zerotorescue@23 141 if InGroup(itemId) then
Zerotorescue@23 142 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@23 143 elseif AddToGroup(groupName, itemId) then
Zerotorescue@23 144 print(("Added %s (#%d) found in the premade group |cfffed000%s|r to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@23 145 end
Zerotorescue@23 146 end
Zerotorescue@23 147 end
Zerotorescue@23 148
Zerotorescue@23 149 -- Remember the new version
Zerotorescue@23 150 values.premadeGroups[key] = groupInfo.version;
Zerotorescue@23 151 else
Zerotorescue@23 152 -- No was clicked
Zerotorescue@23 153
Zerotorescue@23 154 -- Let user know what was not added
Zerotorescue@23 155 for itemId, version in pairs(groupInfo.items) do
Zerotorescue@23 156 -- Go through all items in this premade group
Zerotorescue@23 157
Zerotorescue@23 158 if version > values.premadeGroups[key] then
Zerotorescue@23 159 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it
Zerotorescue@23 160
Zerotorescue@23 161 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@23 162 end
Zerotorescue@23 163 end
Zerotorescue@23 164
Zerotorescue@23 165 -- Remember the new version
Zerotorescue@23 166 values.premadeGroups[key] = groupInfo.version;
Zerotorescue@23 167 end
Zerotorescue@23 168 else
Zerotorescue@23 169 StaticPopupDialogs["InventoriumConfirmUpdatePremadeGroup"] = {
Zerotorescue@23 170 text = "The premade group |cfffed000%s|r used in the group |cfffed000%s|r has been changed. Do you wish to copy these changes?",
Zerotorescue@23 171 button1 = YES,
Zerotorescue@23 172 button2 = NO,
Zerotorescue@23 173 OnAccept = function(self)
Zerotorescue@23 174 addon:PremadeGroupsCheck(groupName, key, true);
Zerotorescue@23 175 end,
Zerotorescue@23 176 OnCancel = function(self, _, reason)
Zerotorescue@23 177 if reason == "clicked" then
Zerotorescue@23 178 addon:PremadeGroupsCheck(groupName, key, false);
Zerotorescue@23 179 end
Zerotorescue@23 180 end,
Zerotorescue@23 181 timeout = 0,
Zerotorescue@23 182 whileDead = 1,
Zerotorescue@23 183 hideOnEscape = 1,
Zerotorescue@23 184 };
Zerotorescue@23 185 StaticPopup_Show("InventoriumConfirmUpdatePremadeGroup", key, groupName);
Zerotorescue@23 186
Zerotorescue@23 187 return;
Zerotorescue@23 188 end
Zerotorescue@23 189 end
Zerotorescue@23 190 end
Zerotorescue@23 191 end
Zerotorescue@23 192 end
Zerotorescue@23 193 end
Zerotorescue@23 194
Zerotorescue@23 195
Zerotorescue@1 196 local slashArgs = {};
Zerotorescue@1 197 function addon:RegisterSlash(func, ...)
Zerotorescue@1 198 for _, arg in pairs({ ... }) do
Zerotorescue@1 199 slashArgs[arg] = func;
Zerotorescue@1 200 end
Zerotorescue@1 201 end
Zerotorescue@1 202
Zerotorescue@1 203 function addon:MakeItemLinkButtonWidget()
Zerotorescue@0 204 --[[
Zerotorescue@0 205 [ ItemLinkButton ]
Zerotorescue@1 206 This custom widget has to show an icon with the item link next to it.
Zerotorescue@1 207 Upon hover it must show the item tooltip.
Zerotorescue@1 208 Upon click it must execute the function provided through user data.
Zerotorescue@1 209
Zerotorescue@1 210 UserData: itemId, onClickEvent
Zerotorescue@1 211
Zerotorescue@0 212 OnEnter: tooltip show
Zerotorescue@1 213 OnLeave: tooltip hide
Zerotorescue@1 214 OnClick: UserData.onClickEvent
Zerotorescue@0 215 ]]
Zerotorescue@0 216
Zerotorescue@0 217 local widgetType = "ItemLinkButton";
Zerotorescue@0 218 local widgetVersion = 1;
Zerotorescue@0 219
Zerotorescue@1 220 local function Constructor()
Zerotorescue@1 221 local widget = AceGUI:Create("InteractiveLabel");
Zerotorescue@1 222 widget.type = widgetType;
Zerotorescue@1 223
Zerotorescue@1 224 -- We overwrite the OnAcquire as we want to set our callbacks even
Zerotorescue@1 225 -- when the widget is re-used from the widget pool
Zerotorescue@1 226 widget.originalOnAcquire = widget.OnAcquire;
Zerotorescue@1 227 widget.OnAcquire = function(self, ...)
Zerotorescue@1 228
Zerotorescue@1 229
Zerotorescue@1 230 -- We overwrite the setcallback because we don't want anything else
Zerotorescue@1 231 -- to overwrite our OnEnter, OnLeave and OnClick events
Zerotorescue@1 232 -- which would be done by the AceConfigDialog after a widget gets re-used
Zerotorescue@1 233 if not self.originalSetCallBack then
Zerotorescue@1 234 self.originalSetCallBack = self.SetCallback;
Zerotorescue@1 235 self.SetCallback = function(this, event, func, ...)
Zerotorescue@1 236 if event == "OnEnter" or event == "OnLeave" or event == "OnClick" then
Zerotorescue@1 237 -- Don't allow overwriting of these events
Zerotorescue@1 238 return;
Zerotorescue@1 239 elseif event == "CustomOnEnter" then
Zerotorescue@1 240 return this.originalSetCallBack(this, "OnEnter", func, ...);
Zerotorescue@1 241 elseif event == "CustomOnLeave" then
Zerotorescue@1 242 return this.originalSetCallBack(this, "OnLeave", func, ...);
Zerotorescue@1 243 elseif event == "CustomOnClick" then
Zerotorescue@1 244 return this.originalSetCallBack(this, "OnClick", func, ...);
Zerotorescue@1 245 else
Zerotorescue@1 246 return this.originalSetCallBack(this, event, func, ...);
Zerotorescue@1 247 end
Zerotorescue@1 248 end;
Zerotorescue@1 249 end
Zerotorescue@1 250
Zerotorescue@1 251
Zerotorescue@1 252 -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions
Zerotorescue@1 253 self:SetCallback("CustomOnEnter", function(this)
Zerotorescue@1 254 local itemId = this:GetUserData("itemId");
Zerotorescue@1 255
Zerotorescue@1 256 if itemId then
Zerotorescue@1 257 GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT");
Zerotorescue@1 258 GameTooltip:SetHyperlink(("item:%d"):format(itemId));
Zerotorescue@1 259 GameTooltip:Show();
Zerotorescue@1 260 end
Zerotorescue@1 261 end);
Zerotorescue@1 262 self:SetCallback("CustomOnLeave", function(this)
Zerotorescue@1 263 GameTooltip:Hide();
Zerotorescue@1 264 end);
Zerotorescue@23 265 self:SetCallback("CustomOnClick", function(this, ...)
Zerotorescue@23 266 -- Below is used in child widgets to prepare for onclick
Zerotorescue@1 267 if this.OnClick then
Zerotorescue@23 268 this.OnClick(this, ...);
Zerotorescue@1 269 end
Zerotorescue@1 270
Zerotorescue@1 271 local func = this:GetUserData("exec");
Zerotorescue@1 272 local itemId = this:GetUserData("itemId");
Zerotorescue@1 273
Zerotorescue@1 274 if func then
Zerotorescue@1 275 -- If this is a config option we will need the group id
Zerotorescue@1 276 local path = this:GetUserData("path");
Zerotorescue@1 277 local groupId = (path and path[2]) or nil;
Zerotorescue@1 278
Zerotorescue@23 279 func(groupId, itemId, ...);
Zerotorescue@1 280 end
Zerotorescue@1 281 end);
Zerotorescue@1 282
Zerotorescue@1 283
Zerotorescue@1 284
Zerotorescue@1 285 -- Then also do whatever it wanted to do
Zerotorescue@1 286 self.originalOnAcquire(self, ...);
Zerotorescue@1 287 end;
Zerotorescue@1 288
Zerotorescue@1 289 -- Remember the original SetText as this might get overwritten by the config-widget
Zerotorescue@1 290 widget.originalSetText = widget.SetText;
Zerotorescue@1 291
Zerotorescue@1 292 widget.SetItemId = function(self, itemId)
Zerotorescue@1 293 self:SetUserData("itemId", itemId);
Zerotorescue@1 294
Zerotorescue@1 295 -- Put the icon in front of it
Zerotorescue@1 296 self:SetImage(GetItemIcon(itemId));
Zerotorescue@0 297 -- Standardize the size
Zerotorescue@0 298 self:SetImageSize(16, 16);
Zerotorescue@0 299
Zerotorescue@0 300 -- Make readable font
Zerotorescue@0 301 self:SetFontObject(GameFontHighlight);
Zerotorescue@0 302
Zerotorescue@0 303 -- We don't want to set the itemId as text, but rather the item link, so get that.
Zerotorescue@1 304 local itemLink = select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId);
Zerotorescue@0 305
Zerotorescue@1 306 self:originalSetText(itemLink);
Zerotorescue@1 307 end;
Zerotorescue@1 308
Zerotorescue@1 309 return widget;
Zerotorescue@0 310 end
Zerotorescue@1 311
Zerotorescue@1 312 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
Zerotorescue@1 313 end
Zerotorescue@1 314
Zerotorescue@1 315 function addon:MakeConfigItemLinkButtonWidget()
Zerotorescue@1 316 -- Define out custom item link button widget
Zerotorescue@1 317 -- This will be called as if it's an input element, we overwrite some of the related functions which are called for default input fields
Zerotorescue@0 318
Zerotorescue@1 319 local widgetType = "ConfigItemLinkButton";
Zerotorescue@1 320 local widgetVersion = 1;
Zerotorescue@0 321
Zerotorescue@1 322 -- Empty function for disabling functions
Zerotorescue@1 323 local function Dummy() end
Zerotorescue@0 324
Zerotorescue@0 325 -- Makes an instance of our ItemLinkButton widget
Zerotorescue@0 326 local function GetItemLinkButton()
Zerotorescue@1 327 local widget = AceGUI:Create("ItemLinkButton");
Zerotorescue@0 328 widget.type = widgetType;
Zerotorescue@0 329
Zerotorescue@0 330 -- We can only provide custom widgets for input, select and multiselect fields
Zerotorescue@0 331 -- Input being the simplest, we use that - however, it provides two parameters: label and text. We only need one, disable the other.
Zerotorescue@0 332 widget.SetLabel = Dummy;
Zerotorescue@0 333
Zerotorescue@1 334 -- SetText is called when this button is being created and contains the itemId
Zerotorescue@1 335 -- Forward that itemId to the ItemLinkButton
Zerotorescue@1 336 widget.SetText = function(self, value, ...)
Zerotorescue@1 337 if value and tonumber(value) then
Zerotorescue@1 338 self:SetItemId(tonumber(value));
Zerotorescue@1 339 end
Zerotorescue@1 340 end;
Zerotorescue@1 341
Zerotorescue@1 342 widget.OnClick = function(self, ...)
Zerotorescue@1 343 local option = self:GetUserData("option");
Zerotorescue@1 344
Zerotorescue@1 345 if option and option.set then
Zerotorescue@1 346 self:SetUserData("exec", option.set);
Zerotorescue@1 347 end
Zerotorescue@1 348 end;
Zerotorescue@0 349
Zerotorescue@0 350 return widget;
Zerotorescue@0 351 end
Zerotorescue@0 352
Zerotorescue@0 353 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion);
Zerotorescue@0 354 end
Zerotorescue@0 355
Zerotorescue@0 356 function addon:CommandHandler(message)
Zerotorescue@0 357 local cmd, arg = string.split(" ", (message or ""), 2);
Zerotorescue@0 358 cmd = string.lower(cmd);
Zerotorescue@0 359
Zerotorescue@0 360 if cmd == "c" or cmd == "config" or cmd == "conf" or cmd == "option" or cmd == "options" or cmd == "opt" or cmd == "setting" or cmd == "settings" then
Zerotorescue@9 361 -- We don't want any other windows open at this time.
Zerotorescue@9 362 for name, module in self:IterateModules() do
Zerotorescue@9 363 if module.CloseFrame then
Zerotorescue@9 364 module:CloseFrame();
Zerotorescue@9 365 end
Zerotorescue@9 366 end
Zerotorescue@9 367
Zerotorescue@0 368 self:Show();
Zerotorescue@0 369 elseif cmd == "d" or cmd == "debug" then
Zerotorescue@0 370 self.debugChannel = false;
Zerotorescue@0 371 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 372 local name = GetChatWindowInfo(i);
Zerotorescue@0 373
Zerotorescue@0 374 if name:upper() == "DEBUG" then
Zerotorescue@0 375 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 376
Zerotorescue@0 377 print("A debug channel already exists, used the old one. (" .. i .. ")");
Zerotorescue@0 378 return;
Zerotorescue@0 379 end
Zerotorescue@0 380 end
Zerotorescue@0 381
Zerotorescue@0 382 if not self.debugChannel then
Zerotorescue@0 383 -- Create a new debug channel
Zerotorescue@0 384 local chatFrame = FCF_OpenNewWindow('Debug');
Zerotorescue@0 385 ChatFrame_RemoveAllMessageGroups(chatFrame);
Zerotorescue@0 386 self.debugChannel = chatFrame;
Zerotorescue@0 387
Zerotorescue@0 388 print("New debug channel created.");
Zerotorescue@0 389 end
Zerotorescue@1 390 elseif slashArgs[cmd] then
Zerotorescue@1 391 slashArgs[cmd]();
Zerotorescue@0 392 else
Zerotorescue@11 393 print("Wrong command, available: /inventorium config (or /im c) and /inventorium summary (or /im s)");
Zerotorescue@0 394 end
Zerotorescue@0 395 end
Zerotorescue@0 396
Zerotorescue@0 397 function addon:Load()
Zerotorescue@0 398 if not AceConfigDialog and not AceConfigRegistry then
Zerotorescue@0 399 self:FillOptions();
Zerotorescue@0 400
Zerotorescue@0 401 -- Build options dialog
Zerotorescue@0 402 AceConfigDialog = LibStub("AceConfigDialog-3.0");
Zerotorescue@0 403 AceConfigRegistry = LibStub("AceConfigRegistry-3.0");
Zerotorescue@0 404 -- Register options table
Zerotorescue@11 405 LibStub("AceConfig-3.0"):RegisterOptionsTable("InventoriumOptions", options);
Zerotorescue@0 406 -- Set a nice default size (so that 4 normal sized elements fit next to eachother)
Zerotorescue@11 407 AceConfigDialog:SetDefaultSize("InventoriumOptions", 975, 600);
Zerotorescue@0 408
Zerotorescue@0 409 -- In case the addon is loaded from another condition, always call the remove interface options
Zerotorescue@0 410 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
Zerotorescue@11 411 AddonLoader:RemoveInterfaceOptions("Inventorium");
Zerotorescue@0 412 end
Zerotorescue@0 413
Zerotorescue@0 414 -- Add to the blizzard addons options thing
Zerotorescue@11 415 --AceConfigDialog:AddToBlizOptions("InventoriumOptions");
Zerotorescue@0 416 end
Zerotorescue@0 417 end
Zerotorescue@0 418
Zerotorescue@0 419 function addon:Show()
Zerotorescue@0 420 self:Load();
Zerotorescue@0 421
Zerotorescue@11 422 AceConfigDialog:Open("InventoriumOptions");
Zerotorescue@0 423 end
Zerotorescue@0 424
Zerotorescue@0 425 function addon:FillOptions()
Zerotorescue@0 426 options = {
Zerotorescue@0 427 type = "group",
Zerotorescue@11 428 name = "Inventorium",
Zerotorescue@0 429 childGroups = "tree",
Zerotorescue@0 430 args = {
Zerotorescue@0 431 },
Zerotorescue@0 432 };
Zerotorescue@0 433
Zerotorescue@0 434 self:FillGeneralOptions();
Zerotorescue@0 435
Zerotorescue@0 436 options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db, true);
Zerotorescue@0 437 options.args.profiles.order = 200;
Zerotorescue@0 438
Zerotorescue@0 439 self:MakeGroupOptions();
Zerotorescue@0 440
Zerotorescue@0 441 self:FillGroupOptions();
Zerotorescue@0 442 end
Zerotorescue@0 443
Zerotorescue@1 444 local goldText = "%s%d|cffffd700g|r ";
Zerotorescue@1 445 local silverText = "%s%d|cffc7c7cfs|r ";
Zerotorescue@1 446 local copperText = "%s%d|cffeda55fc|r";
Zerotorescue@1 447
Zerotorescue@1 448 function addon:ReadableMoney(copper, clean)
Zerotorescue@1 449 local text = "";
Zerotorescue@1 450
Zerotorescue@1 451 local gold = floor( copper / COPPER_PER_GOLD );
Zerotorescue@1 452 if gold > 0 then
Zerotorescue@1 453 text = goldText:format(text, gold);
Zerotorescue@1 454 end
Zerotorescue@1 455
Zerotorescue@13 456 if not clean or (not gold or gold < 10) then
Zerotorescue@1 457 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
Zerotorescue@1 458 if silver > 0 then
Zerotorescue@1 459 text = silverText:format(text, silver);
Zerotorescue@1 460 end
Zerotorescue@1 461
Zerotorescue@13 462 if not clean or (not gold or gold < 1) then
Zerotorescue@1 463 local copper = floor( copper % COPPER_PER_SILVER );
Zerotorescue@1 464 if copper > 0 or text == "" then
Zerotorescue@1 465 text = copperText:format(text, copper);
Zerotorescue@1 466 end
Zerotorescue@1 467 end
Zerotorescue@1 468 end
Zerotorescue@1 469
Zerotorescue@1 470
Zerotorescue@1 471 return string.trim(text);
Zerotorescue@1 472 end
Zerotorescue@1 473
Zerotorescue@1 474 function addon:ReadableMoneyToCopper(value)
Zerotorescue@1 475 -- If a player enters a value it will be filled without color codes
Zerotorescue@1 476 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@1 477 -- Thus we look for both
Zerotorescue@1 478 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@1 479 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@1 480 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@1 481
Zerotorescue@1 482 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
Zerotorescue@1 483 end
Zerotorescue@1 484
Zerotorescue@1 485 function addon:ValidateReadableMoney(info, value)
Zerotorescue@1 486 -- If a player enters a value it will be filled without color codes
Zerotorescue@1 487 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@1 488 -- Thus we look for both
Zerotorescue@1 489 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@1 490 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@1 491 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@1 492
Zerotorescue@1 493 if not gold and not silver and not copper then
Zerotorescue@1 494 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
Zerotorescue@1 495 else
Zerotorescue@1 496 return true;
Zerotorescue@1 497 end
Zerotorescue@1 498 end
Zerotorescue@1 499
Zerotorescue@0 500 function addon:FillGeneralOptions()
Zerotorescue@0 501 options.args.general = {
Zerotorescue@0 502 order = 100,
Zerotorescue@0 503 type = "group",
Zerotorescue@0 504 name = "General",
Zerotorescue@11 505 desc = "Change general Inventorium settings.",
Zerotorescue@0 506 args = {
Zerotorescue@0 507 general = {
Zerotorescue@0 508 order = 0,
Zerotorescue@0 509 type = "group",
Zerotorescue@0 510 inline = true,
Zerotorescue@0 511 name = "General",
Zerotorescue@0 512 args = {
Zerotorescue@0 513 description = {
Zerotorescue@0 514 order = 0,
Zerotorescue@0 515 type = "description",
Zerotorescue@23 516 name = "Here you can set general settings. The settings entered here will be used when you choose not to override the settings within an individual group.",
Zerotorescue@0 517 },
Zerotorescue@0 518 header = {
Zerotorescue@0 519 order = 5,
Zerotorescue@0 520 type = "header",
Zerotorescue@0 521 name = "",
Zerotorescue@0 522 },
Zerotorescue@13 523 auctionPricingAddon = {
Zerotorescue@0 524 order = 10,
Zerotorescue@0 525 type = "select",
Zerotorescue@0 526 name = "Prefered pricing addon",
Zerotorescue@13 527 desc = "Select the addon you prefer data to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@13 528 values = function()
Zerotorescue@13 529 local temp = {};
Zerotorescue@13 530 for name, value in pairs(self.supportedAddons.auctionPricing) do
Zerotorescue@13 531 temp[name] = name;
Zerotorescue@13 532 end
Zerotorescue@13 533
Zerotorescue@13 534 return temp;
Zerotorescue@13 535 end,
Zerotorescue@13 536 get = function() return self.db.global.defaults.auctionPricingAddon; end,
Zerotorescue@13 537 set = function(i, v) self.db.global.defaults.auctionPricingAddon = v; end,
Zerotorescue@0 538 },
Zerotorescue@0 539 itemCountAddon = {
Zerotorescue@0 540 order = 20,
Zerotorescue@0 541 type = "select",
Zerotorescue@0 542 name = "Prefered item count addon",
Zerotorescue@13 543 desc = "Select the addon you prefer data to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@13 544 values = function()
Zerotorescue@13 545 local temp = {};
Zerotorescue@13 546 for name, value in pairs(self.supportedAddons.itemCount) do
Zerotorescue@13 547 temp[name] = name;
Zerotorescue@13 548 end
Zerotorescue@13 549
Zerotorescue@13 550 return temp;
Zerotorescue@13 551 end,
Zerotorescue@13 552 get = function() return self.db.global.defaults.itemCountAddon; end,
Zerotorescue@13 553 set = function(i, v) self.db.global.defaults.itemCountAddon = v; end,
Zerotorescue@13 554 },
Zerotorescue@13 555 craftingAddon = {
Zerotorescue@23 556 order = 30,
Zerotorescue@13 557 type = "select",
Zerotorescue@13 558 name = "Prefered crafting addon",
Zerotorescue@13 559 desc = "Select the addon you prefer data to be queued into. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@13 560 values = function()
Zerotorescue@13 561 local temp = {};
Zerotorescue@13 562 for name, value in pairs(self.supportedAddons.crafting) do
Zerotorescue@13 563 temp[name] = name;
Zerotorescue@13 564 end
Zerotorescue@13 565
Zerotorescue@13 566 return temp;
Zerotorescue@13 567 end,
Zerotorescue@13 568 get = function() return self.db.global.defaults.craftingAddon; end,
Zerotorescue@13 569 set = function(i, v) self.db.global.defaults.craftingAddon = v; end,
Zerotorescue@0 570 },
Zerotorescue@23 571 localItemData = {
Zerotorescue@23 572 order = 40,
Zerotorescue@23 573 type = "multiselect",
Zerotorescue@23 574 name = "Include in local item data NYI | PH",
Zerotorescue@23 575 desc = "Select which data should be included in the local item data.",
Zerotorescue@23 576 values = {
Zerotorescue@23 577 ["Bag"] = "Bag",
Zerotorescue@23 578 ["Bank"] = "Bank",
Zerotorescue@23 579 ["Auction House"] = "Auction House",
Zerotorescue@23 580 ["Mailbox"] = "Mailbox",
Zerotorescue@23 581 },
Zerotorescue@23 582 get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end,
Zerotorescue@23 583 set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end,
Zerotorescue@23 584 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
Zerotorescue@23 585 },
Zerotorescue@0 586 },
Zerotorescue@0 587 },
Zerotorescue@0 588 minimumStock = {
Zerotorescue@0 589 order = 10,
Zerotorescue@0 590 type = "group",
Zerotorescue@0 591 inline = true,
Zerotorescue@0 592 name = "Minimum stock",
Zerotorescue@0 593 args = {
Zerotorescue@0 594 description = {
Zerotorescue@0 595 order = 0,
Zerotorescue@0 596 type = "description",
Zerotorescue@0 597 name = "Here you can specify the default minimum amount of items you wish to keep in stock and related settings. The settings entered here will be used when you choose not to override the settings within an individual group.",
Zerotorescue@0 598 },
Zerotorescue@0 599 header = {
Zerotorescue@0 600 order = 5,
Zerotorescue@0 601 type = "header",
Zerotorescue@0 602 name = "",
Zerotorescue@0 603 },
Zerotorescue@0 604 minimumStock = {
Zerotorescue@0 605 order = 10,
Zerotorescue@0 606 type = "range",
Zerotorescue@0 607 min = 0,
Zerotorescue@0 608 max = 100000,
Zerotorescue@17 609 softMax = 100,
Zerotorescue@0 610 step = 1,
Zerotorescue@0 611 name = "Minimum stock",
Zerotorescue@17 612 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.",
Zerotorescue@0 613 get = function() return self.db.global.defaults.minimumStock; end,
Zerotorescue@0 614 set = function(i, v) self.db.global.defaults.minimumStock = v; end,
Zerotorescue@0 615 },
Zerotorescue@0 616 summaryThresholdShow = {
Zerotorescue@0 617 order = 20,
Zerotorescue@0 618 type = "range",
Zerotorescue@0 619 min = 0,
Zerotorescue@0 620 max = 100,
Zerotorescue@0 621 softMax = 10,
Zerotorescue@0 622 step = 0.05,
Zerotorescue@0 623 isPercent = true,
Zerotorescue@0 624 name = "Show in summary when below",
Zerotorescue@0 625 desc = "Show items in the summary when below this percentage of the minimum stock.\n\nYou can manually enter a value between 1.000% and 10.000% in the edit box if the provided range is insufficient.",
Zerotorescue@0 626 get = function() return self.db.global.defaults.summaryThresholdShow; end,
Zerotorescue@0 627 set = function(i, v) self.db.global.defaults.summaryThresholdShow = v; end,
Zerotorescue@0 628 },
Zerotorescue@0 629 alertBelowMinimum = {
Zerotorescue@0 630 order = 30,
Zerotorescue@0 631 type = "toggle",
Zerotorescue@0 632 name = "Alert when below minimum",
Zerotorescue@0 633 desc = "Show an alert when this item gets below this threshold.",
Zerotorescue@0 634 get = function() return self.db.global.defaults.alertBelowMinimum; end,
Zerotorescue@0 635 set = function(i, v) self.db.global.defaults.alertBelowMinimum = v; end,
Zerotorescue@0 636 },
Zerotorescue@0 637 trackAtCharacters = {
Zerotorescue@0 638 order = 40,
Zerotorescue@0 639 type = "multiselect",
Zerotorescue@0 640 name = "Track at",
Zerotorescue@0 641 desc = "Select at which characters this should appear in the summary and generate alerts.",
Zerotorescue@0 642 values = function()
Zerotorescue@0 643 local temp = {};
Zerotorescue@0 644 for charName in pairs(self.db.factionrealm.characters) do
Zerotorescue@0 645 temp[charName] = charName;
Zerotorescue@0 646 end
Zerotorescue@0 647
Zerotorescue@0 648 return temp;
Zerotorescue@0 649 end,
Zerotorescue@1 650 get = function(i, v) return self.db.global.defaults.trackAtCharacters[v]; end,
Zerotorescue@23 651 set = function(i, v, e) self.db.global.defaults.trackAtCharacters[v] = e or nil; end,
Zerotorescue@13 652 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
Zerotorescue@0 653 },
Zerotorescue@0 654 },
Zerotorescue@0 655 },
Zerotorescue@0 656 refill = {
Zerotorescue@0 657 order = 20,
Zerotorescue@0 658 type = "group",
Zerotorescue@0 659 inline = true,
Zerotorescue@0 660 name = "Replenishing stock",
Zerotorescue@0 661 args = {
Zerotorescue@0 662 description = {
Zerotorescue@0 663 order = 0,
Zerotorescue@0 664 type = "description",
Zerotorescue@0 665 name = function()
Zerotorescue@0 666 local r = "Here you can specify the default amount of items to which you wish to restock when you are collecting new items. This may be higher than the minimum stock. The settings entered here will be used when you choose not to override the settings within an individual group.\n\n";
Zerotorescue@0 667
Zerotorescue@0 668 r = r .. "When restocking the target amount is |cfffed000" .. self.db.global.defaults.restockTarget .. "|r of every item. Not queueing craftable items when only missing |cfffed000" .. floor( self.db.global.defaults.minCraftingQueue * self.db.global.defaults.restockTarget ) .. "|r (|cfffed000" .. ( self.db.global.defaults.minCraftingQueue * 100 ) .. "%|r) of the restock target.";
Zerotorescue@0 669
Zerotorescue@0 670 return r;
Zerotorescue@0 671 end,
Zerotorescue@0 672 },
Zerotorescue@0 673 header = {
Zerotorescue@0 674 order = 5,
Zerotorescue@0 675 type = "header",
Zerotorescue@0 676 name = "",
Zerotorescue@0 677 },
Zerotorescue@0 678 restockTarget = {
Zerotorescue@0 679 order = 10,
Zerotorescue@0 680 type = "range",
Zerotorescue@0 681 min = 0,
Zerotorescue@0 682 max = 100000,
Zerotorescue@0 683 softMax = 1000,
Zerotorescue@0 684 step = 1,
Zerotorescue@0 685 name = "Restock target",
Zerotorescue@0 686 desc = "You can manually enter a value between 1.000 and 100.000 in the edit box if the provided range is insufficient.",
Zerotorescue@0 687 get = function() return self.db.global.defaults.restockTarget; end,
Zerotorescue@0 688 set = function(i, v) self.db.global.defaults.restockTarget = v; end,
Zerotorescue@0 689 },
Zerotorescue@0 690 minCraftingQueue = {
Zerotorescue@0 691 order = 20,
Zerotorescue@0 692 type = "range",
Zerotorescue@0 693 min = 0,
Zerotorescue@0 694 max = 1,
Zerotorescue@0 695 step = 0.01, -- 1%
Zerotorescue@0 696 isPercent = true,
Zerotorescue@0 697 name = "Don't queue if I only miss",
Zerotorescue@0 698 desc = "Don't add a craftable item to the queue if I only miss this much or less of the restock target.\n\nExample: if your restock target is set to 60 and this is set to 5%, an item won't be queued unless you are missing more than 3 of it.",
Zerotorescue@0 699 get = function() return self.db.global.defaults.minCraftingQueue; end,
Zerotorescue@0 700 set = function(i, v) self.db.global.defaults.minCraftingQueue = v; end,
Zerotorescue@0 701 },
Zerotorescue@0 702 bonusQueue = {
Zerotorescue@0 703 order = 30,
Zerotorescue@0 704 type = "range",
Zerotorescue@0 705 min = 0,
Zerotorescue@0 706 max = 10, -- 1000%
Zerotorescue@0 707 step = 0.01, -- 1%
Zerotorescue@0 708 isPercent = true,
Zerotorescue@0 709 name = "Bonus queue",
Zerotorescue@1 710 desc = "Get additional items when there are none left.\n\nExample: if your restock target is set to 60 and this is set to 10%, you will get 66 items instead of just 60 if you end up with none left while queueing.",
Zerotorescue@0 711 get = function() return self.db.global.defaults.bonusQueue; end,
Zerotorescue@0 712 set = function(i, v) self.db.global.defaults.bonusQueue = v; end,
Zerotorescue@0 713 },
Zerotorescue@0 714 priceThreshold = {
Zerotorescue@0 715 order = 40,
Zerotorescue@0 716 type = "input",
Zerotorescue@0 717 name = "Price threshold",
Zerotorescue@1 718 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.",
Zerotorescue@1 719 validate = function(info, value) return self:ValidateReadableMoney(info, value); end,
Zerotorescue@1 720 get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end,
Zerotorescue@1 721 set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end,
Zerotorescue@0 722 },
Zerotorescue@13 723 summaryHidePriceThreshold = {
Zerotorescue@0 724 order = 50,
Zerotorescue@0 725 type = "toggle",
Zerotorescue@1 726 name = "Hide when below threshold",
Zerotorescue@0 727 desc = "Hide items from the summary when their value is below the set price threshold.",
Zerotorescue@13 728 get = function() return self.db.global.defaults.summaryHidePriceThreshold; end,
Zerotorescue@13 729 set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end,
Zerotorescue@0 730 },
Zerotorescue@23 731 alwaysGetAuctionValue = {
Zerotorescue@23 732 order = 60,
Zerotorescue@23 733 type = "toggle",
Zerotorescue@23 734 name = "Always show auction value",
Zerotorescue@23 735 desc = "Always cache and show the auction value of items, even if the price threshold is set to 0.",
Zerotorescue@23 736 get = function() return self.db.global.defaults.alwaysGetAuctionValue; end,
Zerotorescue@23 737 set = function(i, v) self.db.global.defaults.alwaysGetAuctionValue = v; end,
Zerotorescue@23 738 },
Zerotorescue@0 739 },
Zerotorescue@0 740 },
Zerotorescue@0 741 colorCodes = {
Zerotorescue@0 742 order = 30,
Zerotorescue@0 743 type = "group",
Zerotorescue@0 744 inline = true,
Zerotorescue@0 745 name = "Color codes",
Zerotorescue@0 746 args = {
Zerotorescue@0 747 description = {
Zerotorescue@0 748 order = 0,
Zerotorescue@0 749 type = "description",
Zerotorescue@0 750 name = "Change the color code thresholds based on the current stock remaining of the required minimum stock.",
Zerotorescue@0 751 },
Zerotorescue@0 752 header = {
Zerotorescue@0 753 order = 5,
Zerotorescue@0 754 type = "header",
Zerotorescue@0 755 name = "",
Zerotorescue@0 756 },
Zerotorescue@0 757 green = {
Zerotorescue@0 758 order = 10,
Zerotorescue@0 759 type = "range",
Zerotorescue@0 760 min = 0,
Zerotorescue@0 761 max = 1,
Zerotorescue@0 762 step = 0.01,
Zerotorescue@0 763 isPercent = true,
Zerotorescue@0 764 name = "|cff00ff00Green|r",
Zerotorescue@0 765 desc = "Show quantity in green when at least this much of the minimum stock is available.",
Zerotorescue@0 766 get = function() return self.db.global.defaults.colors.green; end,
Zerotorescue@0 767 set = function(i, v) self.db.global.defaults.colors.green = v; end,
Zerotorescue@0 768 },
Zerotorescue@0 769 yellow = {
Zerotorescue@0 770 order = 20,
Zerotorescue@0 771 type = "range",
Zerotorescue@0 772 min = 0,
Zerotorescue@0 773 max = 1,
Zerotorescue@0 774 step = 0.01,
Zerotorescue@0 775 isPercent = true,
Zerotorescue@0 776 name = "|cffffff00Yellow|r",
Zerotorescue@0 777 desc = "Show quantity in yellow when at least this much of the minimum stock is available.",
Zerotorescue@0 778 get = function() return self.db.global.defaults.colors.yellow; end,
Zerotorescue@0 779 set = function(i, v) self.db.global.defaults.colors.yellow = v; end,
Zerotorescue@0 780 },
Zerotorescue@0 781 orange = {
Zerotorescue@0 782 order = 30,
Zerotorescue@0 783 type = "range",
Zerotorescue@0 784 min = 0,
Zerotorescue@0 785 max = 1,
Zerotorescue@0 786 step = 0.01,
Zerotorescue@0 787 isPercent = true,
Zerotorescue@0 788 name = "|cffff9933Orange|r",
Zerotorescue@0 789 desc = "Show quantity in orange when at least this much of the minimum stock is available.",
Zerotorescue@0 790 get = function() return self.db.global.defaults.colors.orange; end,
Zerotorescue@0 791 set = function(i, v) self.db.global.defaults.colors.orange = v; end,
Zerotorescue@0 792 },
Zerotorescue@0 793 red = {
Zerotorescue@0 794 order = 40,
Zerotorescue@0 795 type = "range",
Zerotorescue@0 796 min = 0,
Zerotorescue@0 797 max = 1,
Zerotorescue@0 798 step = 0.01,
Zerotorescue@0 799 isPercent = true,
Zerotorescue@0 800 name = "|cffff0000Red|r",
Zerotorescue@0 801 desc = "Show quantity in red when at least this much of the minimum stock is available.",
Zerotorescue@0 802 get = function() return self.db.global.defaults.colors.red; end,
Zerotorescue@0 803 set = function(i, v) self.db.global.defaults.colors.red = v; end,
Zerotorescue@0 804 },
Zerotorescue@0 805 },
Zerotorescue@0 806 },
Zerotorescue@0 807 },
Zerotorescue@0 808 };
Zerotorescue@0 809 end
Zerotorescue@0 810
Zerotorescue@0 811 local count = 0;
Zerotorescue@0 812 local temp = {};
Zerotorescue@0 813
Zerotorescue@1 814 local function SetOption(info, value, multiSelectEnabled)
Zerotorescue@0 815 local groupName = groupIdToName[info[2]];
Zerotorescue@0 816 local optionName = info[#info];
Zerotorescue@0 817
Zerotorescue@23 818 -- Special treatment for override toggle boxes
Zerotorescue@23 819 if not info.arg:find("override") then
Zerotorescue@23 820 if not value and info.arg then
Zerotorescue@23 821 -- If this override was disabled and a saved variable name was provided, set it to nil rather than false
Zerotorescue@23 822
Zerotorescue@23 823 value = nil;
Zerotorescue@23 824
Zerotorescue@23 825 -- If this is an override toggler then also set the related field to nil
Zerotorescue@23 826 addon.db.global.groups[groupName][info.arg] = nil;
Zerotorescue@23 827 elseif value and info.arg then
Zerotorescue@23 828 -- If this override is now enabled, we need to copy the default into this field (unless it is not nil (which is supposed to be impossible), in which case we'll use the already selected value)
Zerotorescue@23 829
Zerotorescue@23 830 addon.db.global.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg);
Zerotorescue@23 831 end
Zerotorescue@0 832 end
Zerotorescue@0 833
Zerotorescue@1 834 if multiSelectEnabled ~= nil then
Zerotorescue@1 835 -- The saved vars for a multiselect will always be an array, it may not yet exist in which case it must be created.
Zerotorescue@1 836 if not addon.db.global.groups[groupName][optionName] then
Zerotorescue@1 837 addon.db.global.groups[groupName][optionName] = {};
Zerotorescue@1 838 end
Zerotorescue@1 839
Zerotorescue@1 840 addon.db.global.groups[groupName][optionName][value] = multiSelectEnabled or nil;
Zerotorescue@1 841 else
Zerotorescue@1 842 addon.db.global.groups[groupName][optionName] = value;
Zerotorescue@1 843 end
Zerotorescue@0 844 end
Zerotorescue@0 845
Zerotorescue@1 846 function addon:GetOptionByKey(groupName, optionName, noDefault)
Zerotorescue@23 847 if groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName][optionName] ~= nil then
Zerotorescue@23 848 return self.db.global.groups[groupName][optionName];
Zerotorescue@23 849 elseif self.db.global.defaults[optionName] and not noDefault then
Zerotorescue@23 850 return self.db.global.defaults[optionName];
Zerotorescue@0 851 else
Zerotorescue@0 852 return nil;
Zerotorescue@0 853 end
Zerotorescue@0 854 end
Zerotorescue@0 855
Zerotorescue@0 856 local function GetOption(info)
Zerotorescue@0 857 local groupName = groupIdToName[info[2]];
Zerotorescue@0 858 local optionName = info[#info];
Zerotorescue@0 859
Zerotorescue@1 860 return addon:GetOptionByKey(groupName, optionName);
Zerotorescue@1 861 end
Zerotorescue@1 862
Zerotorescue@1 863 local function GetMultiOption(info, value)
Zerotorescue@1 864 local groupName = groupIdToName[info[2]];
Zerotorescue@1 865 local optionName = info[#info];
Zerotorescue@1 866
Zerotorescue@1 867 if addon.db.global.groups[groupName][optionName] ~= nil then
Zerotorescue@1 868 return addon.db.global.groups[groupName][optionName][value];
Zerotorescue@1 869 elseif addon.db.global.defaults[optionName] then
Zerotorescue@1 870 return addon.db.global.defaults[optionName][value];
Zerotorescue@1 871 else
Zerotorescue@1 872 return nil;
Zerotorescue@1 873 end
Zerotorescue@0 874 end
Zerotorescue@0 875
Zerotorescue@0 876 local function GetDisabled(info)
Zerotorescue@0 877 if not info.arg or not info.arg:find("override") then
Zerotorescue@0 878 return false;
Zerotorescue@0 879 end
Zerotorescue@0 880
Zerotorescue@0 881 local groupName = groupIdToName[info[2]];
Zerotorescue@0 882 local optionName = info[#info];
Zerotorescue@0 883
Zerotorescue@1 884 return (addon:GetOptionByKey(groupName, info.arg, true) == nil);
Zerotorescue@0 885 end
Zerotorescue@0 886
Zerotorescue@0 887 local function ValidateGroupName(_, value)
Zerotorescue@0 888 value = string.lower(string.trim(value or ""));
Zerotorescue@0 889
Zerotorescue@0 890 for name, _ in pairs(addon.db.global.groups) do
Zerotorescue@0 891 if string.lower(name) == value then
Zerotorescue@0 892 return ("A group named \"%s\" already exists."):format(name);
Zerotorescue@0 893 end
Zerotorescue@0 894 end
Zerotorescue@0 895
Zerotorescue@0 896 return true;
Zerotorescue@0 897 end
Zerotorescue@0 898
Zerotorescue@0 899 local function AddToGroup(groupName, itemId)
Zerotorescue@0 900 if InGroup(itemId) then
Zerotorescue@0 901 return false;
Zerotorescue@0 902 end
Zerotorescue@0 903
Zerotorescue@0 904 if not addon.db.global.groups[groupName].items then
Zerotorescue@0 905 addon.db.global.groups[groupName].items = {};
Zerotorescue@0 906 end
Zerotorescue@0 907
Zerotorescue@0 908 -- Set this item
Zerotorescue@0 909 addon.db.global.groups[groupName].items[itemId] = true;
Zerotorescue@0 910
Zerotorescue@0 911 -- Now rebuild the list
Zerotorescue@11 912 AceConfigRegistry:NotifyChange("InventoriumOptions");
Zerotorescue@0 913
Zerotorescue@0 914 return true;
Zerotorescue@0 915 end
Zerotorescue@0 916
Zerotorescue@0 917 local tblAddItemTemplate = {
Zerotorescue@0 918 order = 0,
Zerotorescue@0 919 type = "input",
Zerotorescue@0 920 name = function(info)
Zerotorescue@0 921 local itemName, _, itemRarity = GetItemInfo(info[#info]);
Zerotorescue@0 922 return tostring( 7 - (itemRarity or 0) ) .. (itemName or "");
Zerotorescue@0 923 end,
Zerotorescue@0 924 get = function(info)
Zerotorescue@0 925 return tostring(info[#info]); -- Ace is going to be anal about this if it's a numeric value, so we transmute it into a string here then back to a number on the other side
Zerotorescue@0 926 end,
Zerotorescue@1 927 set = function(groupId, itemId)
Zerotorescue@0 928 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info.
Zerotorescue@0 929
Zerotorescue@1 930 if itemId then
Zerotorescue@1 931 local groupName = groupIdToName[groupId];
Zerotorescue@0 932
Zerotorescue@1 933 if not AddToGroup(groupName, itemId) then
Zerotorescue@1 934 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r");
Zerotorescue@0 935 end
Zerotorescue@0 936 end
Zerotorescue@0 937 end,
Zerotorescue@0 938 width = "double",
Zerotorescue@1 939 dialogControl = "ConfigItemLinkButton",
Zerotorescue@0 940 };
Zerotorescue@0 941
Zerotorescue@0 942 local tblRemoveItemTemplate = {
Zerotorescue@0 943 order = 0,
Zerotorescue@0 944 type = "input",
Zerotorescue@0 945 name = function(info)
Zerotorescue@0 946 local itemName, _, itemRarity = GetItemInfo(info[#info]);
Zerotorescue@0 947 return tostring( 7 - (itemRarity or 0) ) .. (itemName or "");
Zerotorescue@0 948 end,
Zerotorescue@0 949 get = function(info)
Zerotorescue@0 950 return tostring(info[#info]); -- Ace is going to be anal about this if it's a numeric value, so we transmute it into a string here then back to a number on the other side
Zerotorescue@0 951 end,
Zerotorescue@1 952 set = function(groupId, itemId)
Zerotorescue@0 953 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info.
Zerotorescue@0 954
Zerotorescue@1 955 if itemId then
Zerotorescue@1 956 local groupName = groupIdToName[groupId];
Zerotorescue@0 957
Zerotorescue@0 958 -- Unset this item
Zerotorescue@1 959 addon.db.global.groups[groupName].items[itemId] = nil;
Zerotorescue@0 960
Zerotorescue@0 961 -- Now rebuild the list
Zerotorescue@11 962 AceConfigRegistry:NotifyChange("InventoriumOptions");
Zerotorescue@0 963 end
Zerotorescue@0 964 end,
Zerotorescue@0 965 width = "double",
Zerotorescue@1 966 dialogControl = "ConfigItemLinkButton",
Zerotorescue@0 967 };
Zerotorescue@0 968
Zerotorescue@0 969 local function UpdateAddItemList(info)
Zerotorescue@0 970 local groupName = groupIdToName[info[2]];
Zerotorescue@0 971
Zerotorescue@0 972 if not addon.db.global.groups[groupName].items then
Zerotorescue@0 973 addon.db.global.groups[groupName].items = {};
Zerotorescue@0 974 end
Zerotorescue@0 975
Zerotorescue@0 976 -- Merge all items from all groups together
Zerotorescue@0 977 local items = {};
Zerotorescue@0 978 for groupName, values in pairs(addon.db.global.groups) do
Zerotorescue@0 979 if values.items then
Zerotorescue@0 980 for itemId, _ in pairs(values.items) do
Zerotorescue@0 981 items[itemId] = true;
Zerotorescue@0 982 end
Zerotorescue@0 983 end
Zerotorescue@0 984 end
Zerotorescue@0 985
Zerotorescue@0 986 local ref = options.args.groups.args[info[2]].args.add.args.list.args;
Zerotorescue@0 987
Zerotorescue@13 988 -- Remaking the list, so out with the old, in with the new
Zerotorescue@13 989 table.wipe(ref);
Zerotorescue@13 990
Zerotorescue@0 991 -- Parse bags and show these
Zerotorescue@0 992 for bagID = 4, 0, -1 do
Zerotorescue@0 993 for slot = 1, GetContainerNumSlots(bagID) do
Zerotorescue@0 994 local itemId = addon:GetItemId(GetContainerItemLink(bagID, slot));
Zerotorescue@0 995
Zerotorescue@0 996 if itemId then
Zerotorescue@0 997 if not items[itemId] then
Zerotorescue@0 998 -- If this item isn't used in any group yet
Zerotorescue@0 999 ref[itemId] = tblAddItemTemplate;
Zerotorescue@0 1000 else
Zerotorescue@0 1001 -- It's already used in a group, don't show it
Zerotorescue@0 1002 ref[itemId] = nil;
Zerotorescue@0 1003 end
Zerotorescue@0 1004 end
Zerotorescue@0 1005 end
Zerotorescue@0 1006 end
Zerotorescue@13 1007
Zerotorescue@13 1008 if includeTradeSkillItems ~= 500 then
Zerotorescue@13 1009 -- Include tradeskill items
Zerotorescue@13 1010
Zerotorescue@13 1011 -- Go through all trade skills for the profession
Zerotorescue@13 1012 for i = 1, GetNumTradeSkills() do
Zerotorescue@13 1013 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 1014 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 1015
Zerotorescue@13 1016 if itemLink then
Zerotorescue@13 1017 local itemId = addon:GetItemId(itemLink);
Zerotorescue@13 1018 if not itemId then
Zerotorescue@13 1019 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 1020 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 1021
Zerotorescue@17 1022 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 1023 end
Zerotorescue@13 1024
Zerotorescue@17 1025 if itemId then
Zerotorescue@17 1026 local itemLevel = select(4, GetItemInfo(itemId)) or 0;
Zerotorescue@17 1027
Zerotorescue@17 1028 if includeTradeSkillItems == 0 or itemLevel >= includeTradeSkillItems then
Zerotorescue@17 1029 if not items[itemId] then
Zerotorescue@17 1030 -- If this item isn't used in any group yet
Zerotorescue@17 1031 ref[itemId] = tblAddItemTemplate;
Zerotorescue@17 1032 else
Zerotorescue@17 1033 -- It's already used in a group, don't show it
Zerotorescue@17 1034 ref[itemId] = nil;
Zerotorescue@17 1035 end
Zerotorescue@13 1036 end
Zerotorescue@17 1037 else
Zerotorescue@17 1038 addon:Debug("|cffff0000ERROR|r: Couldn't find proper item id for " .. itemLink);
Zerotorescue@13 1039 end
Zerotorescue@13 1040 end
Zerotorescue@13 1041 end
Zerotorescue@13 1042 end
Zerotorescue@0 1043 end
Zerotorescue@0 1044
Zerotorescue@0 1045 local function UpdateRemoveItemList(info)
Zerotorescue@0 1046 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1047
Zerotorescue@0 1048 if not addon.db.global.groups[groupName].items then
Zerotorescue@0 1049 addon.db.global.groups[groupName].items = {};
Zerotorescue@0 1050 end
Zerotorescue@0 1051
Zerotorescue@0 1052 local ref = options.args.groups.args[info[2]].args.remove.args.list.args;
Zerotorescue@0 1053
Zerotorescue@0 1054 -- Unset all
Zerotorescue@0 1055 for itemId, _ in pairs(ref) do
Zerotorescue@0 1056 ref[itemId] = nil;
Zerotorescue@0 1057 end
Zerotorescue@0 1058
Zerotorescue@0 1059 -- Parse items in group and show these
Zerotorescue@0 1060 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
Zerotorescue@0 1061 ref[itemId] = tblRemoveItemTemplate;
Zerotorescue@0 1062 end
Zerotorescue@0 1063 end
Zerotorescue@0 1064
Zerotorescue@0 1065 function addon:GetItemId(itemLink)
Zerotorescue@13 1066 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
Zerotorescue@0 1067 itemLink = itemLink and tonumber(itemLink);
Zerotorescue@0 1068
Zerotorescue@0 1069 return itemLink;
Zerotorescue@0 1070 end
Zerotorescue@0 1071
Zerotorescue@0 1072 -- Default group
Zerotorescue@0 1073 local defaultGroup = {
Zerotorescue@0 1074 order = 0,
Zerotorescue@0 1075 type = "group",
Zerotorescue@0 1076 childGroups = "tab",
Zerotorescue@0 1077 name = function(info)
Zerotorescue@0 1078 return groupIdToName[info[#info]];
Zerotorescue@0 1079 end,
Zerotorescue@0 1080 args = {
Zerotorescue@0 1081 general = {
Zerotorescue@0 1082 order = 10,
Zerotorescue@0 1083 type = "group",
Zerotorescue@23 1084 name = "General",
Zerotorescue@23 1085 desc = "Change the general settings for just this group.",
Zerotorescue@0 1086 args = {
Zerotorescue@23 1087 general = {
Zerotorescue@23 1088 order = 0,
Zerotorescue@23 1089 type = "group",
Zerotorescue@23 1090 inline = true,
Zerotorescue@23 1091 name = "General",
Zerotorescue@23 1092 set = SetOption,
Zerotorescue@23 1093 get = GetOption,
Zerotorescue@23 1094 disabled = GetDisabled,
Zerotorescue@23 1095 args = {
Zerotorescue@23 1096 description = {
Zerotorescue@23 1097 order = 0,
Zerotorescue@23 1098 type = "description",
Zerotorescue@23 1099 name = "Here you can set general settings for the currently selected group. If you do not wish to override a setting, the default setting specified in the general group will be used.",
Zerotorescue@23 1100 },
Zerotorescue@23 1101 header = {
Zerotorescue@23 1102 order = 5,
Zerotorescue@23 1103 type = "header",
Zerotorescue@23 1104 name = "",
Zerotorescue@23 1105 },
Zerotorescue@23 1106 overrideAuctionPricingAddon = {
Zerotorescue@23 1107 order = 9,
Zerotorescue@23 1108 type = "toggle",
Zerotorescue@23 1109 name = "Override pricing addon",
Zerotorescue@23 1110 desc = "Allows you to override the pricing addon setting for this group.",
Zerotorescue@23 1111 arg = "auctionPricingAddon",
Zerotorescue@23 1112 },
Zerotorescue@23 1113 auctionPricingAddon = {
Zerotorescue@23 1114 order = 10,
Zerotorescue@23 1115 type = "select",
Zerotorescue@23 1116 name = "Prefered pricing addon",
Zerotorescue@23 1117 desc = "Select the addon you prefer data for this group to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@23 1118 values = function()
Zerotorescue@23 1119 local temp = {};
Zerotorescue@23 1120 for name, value in pairs(addon.supportedAddons.auctionPricing) do
Zerotorescue@23 1121 temp[name] = name;
Zerotorescue@23 1122 end
Zerotorescue@23 1123
Zerotorescue@23 1124 return temp;
Zerotorescue@23 1125 end,
Zerotorescue@23 1126 arg = "overrideAuctionPricingAddon",
Zerotorescue@23 1127 },
Zerotorescue@23 1128 overrideItemCountAddon = {
Zerotorescue@23 1129 order = 19,
Zerotorescue@23 1130 type = "toggle",
Zerotorescue@23 1131 name = "Override item count addon",
Zerotorescue@23 1132 desc = "Allows you to override the item count addon setting for this group.",
Zerotorescue@23 1133 arg = "itemCountAddon",
Zerotorescue@23 1134 },
Zerotorescue@23 1135 itemCountAddon = {
Zerotorescue@23 1136 order = 20,
Zerotorescue@23 1137 type = "select",
Zerotorescue@23 1138 name = "Prefered item count addon",
Zerotorescue@23 1139 desc = "Select the addon you prefer data for this group to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@23 1140 values = function()
Zerotorescue@23 1141 local temp = {};
Zerotorescue@23 1142 for name, value in pairs(addon.supportedAddons.itemCount) do
Zerotorescue@23 1143 temp[name] = name;
Zerotorescue@23 1144 end
Zerotorescue@23 1145
Zerotorescue@23 1146 return temp;
Zerotorescue@23 1147 end,
Zerotorescue@23 1148 arg = "overrideItemCountAddon",
Zerotorescue@23 1149 },
Zerotorescue@23 1150 overrideCraftingAddon = {
Zerotorescue@23 1151 order = 29,
Zerotorescue@23 1152 type = "toggle",
Zerotorescue@23 1153 name = "Override crafting addon",
Zerotorescue@23 1154 desc = "Allows you to override the crafting addon setting for this group.",
Zerotorescue@23 1155 arg = "craftingAddon",
Zerotorescue@23 1156 },
Zerotorescue@23 1157 craftingAddon = {
Zerotorescue@23 1158 order = 30,
Zerotorescue@23 1159 type = "select",
Zerotorescue@23 1160 name = "Prefered crafting addon",
Zerotorescue@23 1161 desc = "Select the addon you prefer data from this group to be queued into. A random supported addon will be used if the selected addon can not be found.",
Zerotorescue@23 1162 values = function()
Zerotorescue@23 1163 local temp = {};
Zerotorescue@23 1164 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@23 1165 temp[name] = name;
Zerotorescue@23 1166 end
Zerotorescue@23 1167
Zerotorescue@23 1168 return temp;
Zerotorescue@23 1169 end,
Zerotorescue@23 1170 arg = "overrideCraftingAddon",
Zerotorescue@23 1171 },
Zerotorescue@23 1172 },
Zerotorescue@23 1173 },
Zerotorescue@0 1174 minimumStock = {
Zerotorescue@0 1175 order = 10,
Zerotorescue@0 1176 type = "group",
Zerotorescue@0 1177 inline = true,
Zerotorescue@0 1178 name = "Minimum stock",
Zerotorescue@0 1179 set = SetOption,
Zerotorescue@0 1180 get = GetOption,
Zerotorescue@0 1181 disabled = GetDisabled,
Zerotorescue@0 1182 args = {
Zerotorescue@0 1183 description = {
Zerotorescue@0 1184 order = 0,
Zerotorescue@0 1185 type = "description",
Zerotorescue@0 1186 name = "Here you can specify the minimum amount of items you wish to keep in stock and related settings for the currently selected group.",
Zerotorescue@0 1187 },
Zerotorescue@0 1188 header = {
Zerotorescue@0 1189 order = 5,
Zerotorescue@0 1190 type = "header",
Zerotorescue@0 1191 name = "",
Zerotorescue@0 1192 },
Zerotorescue@0 1193 overrideMinimumStock = {
Zerotorescue@0 1194 order = 9,
Zerotorescue@0 1195 type = "toggle",
Zerotorescue@0 1196 name = "Override min stock",
Zerotorescue@0 1197 desc = "Allows you to override the minimum stock setting for this group.",
Zerotorescue@0 1198 arg = "minimumStock",
Zerotorescue@0 1199 },
Zerotorescue@0 1200 minimumStock = {
Zerotorescue@0 1201 order = 10,
Zerotorescue@0 1202 type = "range",
Zerotorescue@0 1203 min = 0,
Zerotorescue@0 1204 max = 100000,
Zerotorescue@17 1205 softMax = 100,
Zerotorescue@0 1206 step = 1,
Zerotorescue@0 1207 name = "Minimum stock",
Zerotorescue@17 1208 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.",
Zerotorescue@0 1209 arg = "overrideMinimumStock",
Zerotorescue@0 1210 },
Zerotorescue@0 1211 overrideSummaryThresholdShow = {
Zerotorescue@0 1212 order = 19,
Zerotorescue@0 1213 type = "toggle",
Zerotorescue@0 1214 name = "Override summary showing",
Zerotorescue@0 1215 desc = "Allows you to override when this group should appear in the summary.",
Zerotorescue@0 1216 arg = "summaryThresholdShow",
Zerotorescue@0 1217 },
Zerotorescue@0 1218 summaryThresholdShow = {
Zerotorescue@0 1219 order = 20,
Zerotorescue@0 1220 type = "range",
Zerotorescue@0 1221 min = 0,
Zerotorescue@0 1222 max = 100,
Zerotorescue@0 1223 softMax = 10,
Zerotorescue@0 1224 step = 0.05,
Zerotorescue@0 1225 isPercent = true,
Zerotorescue@0 1226 name = "Show in summary when below",
Zerotorescue@0 1227 desc = "Show items in the summary when below the specified percentage of the minimum stock.\n\nYou can manually enter a value between 1.000% and 10.000% in the edit box if the provided range is insufficient.",
Zerotorescue@0 1228 arg = "overrideSummaryThresholdShow",
Zerotorescue@0 1229 },
Zerotorescue@0 1230 overrideAlertBelowMinimum = {
Zerotorescue@0 1231 order = 29,
Zerotorescue@0 1232 type = "toggle",
Zerotorescue@0 1233 name = "Override minimum alert",
Zerotorescue@0 1234 desc = "Allows you to override wether an alert should be shown when an item in this group gets below the minimum stock threshold.",
Zerotorescue@0 1235 arg = "alertBelowMinimum",
Zerotorescue@0 1236 },
Zerotorescue@0 1237 alertBelowMinimum = {
Zerotorescue@0 1238 order = 30,
Zerotorescue@0 1239 type = "toggle",
Zerotorescue@0 1240 name = "Alert when below minimum",
Zerotorescue@0 1241 desc = "Show an alert when an item in this group gets below the minimum stock threshold.",
Zerotorescue@0 1242 arg = "overrideAlertBelowMinimum",
Zerotorescue@0 1243 },
Zerotorescue@1 1244 overrideTrackAtCharacters = {
Zerotorescue@1 1245 order = 39,
Zerotorescue@1 1246 type = "toggle",
Zerotorescue@1 1247 name = "Override track at",
Zerotorescue@1 1248 desc = "Allows you to override at which characters items in this group should appear in the summary and generate alerts.",
Zerotorescue@1 1249 arg = "trackAtCharacters",
Zerotorescue@1 1250 },
Zerotorescue@1 1251 trackAtCharacters = {
Zerotorescue@1 1252 order = 40,
Zerotorescue@1 1253 type = "multiselect",
Zerotorescue@1 1254 name = "Track at",
Zerotorescue@1 1255 desc = "Select at which characters this should appear in the summary and generate alerts.",
Zerotorescue@1 1256 values = function()
Zerotorescue@1 1257 local temp = {};
Zerotorescue@1 1258 for charName in pairs(addon.db.factionrealm.characters) do
Zerotorescue@1 1259 temp[charName] = charName;
Zerotorescue@1 1260 end
Zerotorescue@1 1261
Zerotorescue@1 1262 return temp;
Zerotorescue@1 1263 end,
Zerotorescue@1 1264 get = GetMultiOption,
Zerotorescue@13 1265 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
Zerotorescue@1 1266 arg = "overrideTrackAtCharacters",
Zerotorescue@1 1267 },
Zerotorescue@0 1268 },
Zerotorescue@0 1269 },
Zerotorescue@0 1270 refill = {
Zerotorescue@0 1271 order = 20,
Zerotorescue@0 1272 type = "group",
Zerotorescue@0 1273 inline = true,
Zerotorescue@0 1274 name = "Replenishing stock",
Zerotorescue@0 1275 set = SetOption,
Zerotorescue@0 1276 get = GetOption,
Zerotorescue@0 1277 disabled = GetDisabled,
Zerotorescue@0 1278 args = {
Zerotorescue@0 1279 description = {
Zerotorescue@0 1280 order = 0,
Zerotorescue@0 1281 type = "description",
Zerotorescue@0 1282 name = function(info)
Zerotorescue@0 1283 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1284 local r = "Here you can specify the amount of items to which you wish to restock when you are collecting new items for the currently selected group. This may be higher than the minimum stock.\n\n";
Zerotorescue@0 1285
Zerotorescue@17 1286 r = r .. "When restocking the target amount is |cfffed000" .. addon:GetOptionByKey(groupName, "restockTarget") .. "|r of every item. Not queueing craftable items when only missing |cfffed000" .. floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * addon:GetOptionByKey(groupName, "restockTarget") ) .. "|r (|cfffed000" .. ( addon:GetOptionByKey(groupName, "minCraftingQueue") * 100 ) .. "%|r) of the restock target and making |cfffed000" .. floor( ( addon:GetOptionByKey(groupName, "bonusQueue") * addon:GetOptionByKey(groupName, "restockTarget") ) + .5 ) .. "|r (|cfffed000" .. ( addon:GetOptionByKey(groupName, "bonusQueue") * 100 ) .. "%|r) extra items when you completely ran out.";
Zerotorescue@0 1287
Zerotorescue@0 1288 return r;
Zerotorescue@0 1289 end,
Zerotorescue@0 1290 },
Zerotorescue@0 1291 header = {
Zerotorescue@0 1292 order = 5,
Zerotorescue@0 1293 type = "header",
Zerotorescue@0 1294 name = "",
Zerotorescue@0 1295 },
Zerotorescue@0 1296 overrideRestockTarget = {
Zerotorescue@0 1297 order = 9,
Zerotorescue@0 1298 type = "toggle",
Zerotorescue@0 1299 name = "Override restock target",
Zerotorescue@0 1300 desc = "Allows you to override the restock target setting for this group.",
Zerotorescue@0 1301 arg = "restockTarget",
Zerotorescue@0 1302 },
Zerotorescue@0 1303 restockTarget = {
Zerotorescue@0 1304 order = 10,
Zerotorescue@0 1305 type = "range",
Zerotorescue@0 1306 min = 0,
Zerotorescue@0 1307 max = 100000,
Zerotorescue@0 1308 softMax = 1000,
Zerotorescue@0 1309 step = 1,
Zerotorescue@0 1310 name = "Restock target",
Zerotorescue@0 1311 desc = "You can manually enter a value between 1.000 and 100.000 in the edit box if the provided range is insufficient.",
Zerotorescue@0 1312 arg = "overrideRestockTarget",
Zerotorescue@0 1313 },
Zerotorescue@0 1314 overrideMinCraftingQueue = {
Zerotorescue@0 1315 order = 19,
Zerotorescue@0 1316 type = "toggle",
Zerotorescue@0 1317 name = "Override min queue",
Zerotorescue@0 1318 desc = "Allows you to override the minimum craftable items queue setting for this group.",
Zerotorescue@0 1319 arg = "minCraftingQueue",
Zerotorescue@0 1320 },
Zerotorescue@0 1321 minCraftingQueue = {
Zerotorescue@0 1322 order = 20,
Zerotorescue@0 1323 type = "range",
Zerotorescue@0 1324 min = 0,
Zerotorescue@0 1325 max = 1,
Zerotorescue@0 1326 step = 0.01,
Zerotorescue@0 1327 isPercent = true,
Zerotorescue@0 1328 name = "Don't queue if I only miss",
Zerotorescue@0 1329 desc = "Don't add a craftable item to the queue if I only miss this much or less of the restock target.\n\nExample: if your restock target is set to 60 and this is set to 5%, an item won't be queued unless you are missing more than 3 of it.",
Zerotorescue@0 1330 arg = "overrideMinCraftingQueue",
Zerotorescue@0 1331 },
Zerotorescue@1 1332 overrideBonusQueue = {
Zerotorescue@1 1333 order = 29,
Zerotorescue@1 1334 type = "toggle",
Zerotorescue@1 1335 name = "Override bonus queue",
Zerotorescue@1 1336 desc = "Allows you to override the bonus craftable items queue setting for this group.",
Zerotorescue@1 1337 arg = "bonusQueue",
Zerotorescue@1 1338 },
Zerotorescue@1 1339 bonusQueue = {
Zerotorescue@1 1340 order = 30,
Zerotorescue@1 1341 type = "range",
Zerotorescue@1 1342 min = 0,
Zerotorescue@1 1343 max = 10, -- 1000%
Zerotorescue@1 1344 step = 0.01, -- 1%
Zerotorescue@1 1345 isPercent = true,
Zerotorescue@1 1346 name = "Bonus queue",
Zerotorescue@1 1347 desc = "Get additional items when there are none left.\n\nExample: if your restock target is set to 60 and this is set to 10%, you will get 66 items instead of just 60 if you end up with none left while queueing.",
Zerotorescue@1 1348 arg = "overrideBonusQueue",
Zerotorescue@1 1349 },
Zerotorescue@1 1350 overridePriceThreshold = {
Zerotorescue@1 1351 order = 39,
Zerotorescue@1 1352 type = "toggle",
Zerotorescue@1 1353 name = "Override price threshold",
Zerotorescue@1 1354 desc = "Allows you to override the price threshold setting for this group.",
Zerotorescue@1 1355 arg = "priceThreshold",
Zerotorescue@1 1356 },
Zerotorescue@1 1357 priceThreshold = {
Zerotorescue@1 1358 order = 40,
Zerotorescue@1 1359 type = "input",
Zerotorescue@1 1360 name = "Price threshold",
Zerotorescue@1 1361 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.",
Zerotorescue@1 1362 validate = function(info, value) return addon:ValidateReadableMoney(info, value); end,
Zerotorescue@1 1363 get = function(i) return addon:ReadableMoney(GetOption(i)); end,
Zerotorescue@1 1364 set = function(i, v) SetOption(i, addon:ReadableMoneyToCopper(v)); end,
Zerotorescue@1 1365 arg = "overridePriceThreshold",
Zerotorescue@1 1366 },
Zerotorescue@13 1367 overrideSummaryHidePriceThreshold = {
Zerotorescue@1 1368 order = 49,
Zerotorescue@1 1369 type = "toggle",
Zerotorescue@1 1370 name = "Override summary showing",
Zerotorescue@1 1371 desc = "Allows you to override if items in this group should be hidden from the summary while their value is below the price threshold.",
Zerotorescue@13 1372 arg = "summaryHidePriceThreshold",
Zerotorescue@1 1373 },
Zerotorescue@13 1374 summaryHidePriceThreshold = {
Zerotorescue@1 1375 order = 50,
Zerotorescue@1 1376 type = "toggle",
Zerotorescue@1 1377 name = "Hide when below threshold",
Zerotorescue@1 1378 desc = "Hide items from the summary when their value is below the set price threshold.",
Zerotorescue@13 1379 arg = "overrideSummaryHidePriceThreshold",
Zerotorescue@1 1380 },
Zerotorescue@23 1381 overrideAlwaysGetAuctionValue = {
Zerotorescue@23 1382 order = 59,
Zerotorescue@23 1383 type = "toggle",
Zerotorescue@23 1384 name = "Override auction value showing",
Zerotorescue@23 1385 desc = "Allows you to override if the auction value of items in this group should be cached and displayed even when the price threshold is set to 0.",
Zerotorescue@23 1386 arg = "alwaysGetAuctionValue",
Zerotorescue@23 1387 },
Zerotorescue@23 1388 alwaysGetAuctionValue = {
Zerotorescue@23 1389 order = 60,
Zerotorescue@23 1390 type = "toggle",
Zerotorescue@23 1391 name = "Always show auction value",
Zerotorescue@23 1392 desc = "Always cache and show the auction value of items in this group, even if the price threshold is set to 0.",
Zerotorescue@23 1393 arg = "overrideAlwaysGetAuctionValue",
Zerotorescue@23 1394 },
Zerotorescue@0 1395 },
Zerotorescue@0 1396 },
Zerotorescue@0 1397 },
Zerotorescue@0 1398 },
Zerotorescue@0 1399 group = {
Zerotorescue@0 1400 order = 20,
Zerotorescue@0 1401 type = "group",
Zerotorescue@23 1402 name = "Management",
Zerotorescue@23 1403 desc = "Rename, delete, duplicate or export this group.",
Zerotorescue@0 1404 args = {
Zerotorescue@10 1405 actions = {
Zerotorescue@0 1406 order = 10,
Zerotorescue@0 1407 type = "group",
Zerotorescue@10 1408 name = "Actions",
Zerotorescue@0 1409 inline = true,
Zerotorescue@0 1410 args = {
Zerotorescue@0 1411 rename = {
Zerotorescue@0 1412 order = 10,
Zerotorescue@0 1413 type = "input",
Zerotorescue@10 1414 name = "Rename group - New name",
Zerotorescue@0 1415 desc = "Change the name of this group to something else. You can also use item links here as you wish.",
Zerotorescue@0 1416 validate = ValidateGroupName,
Zerotorescue@0 1417 set = function(info, value)
Zerotorescue@0 1418 local oldGroupName = groupIdToName[info[2]];
Zerotorescue@0 1419
Zerotorescue@0 1420 addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]);
Zerotorescue@0 1421 addon.db.global.groups[oldGroupName] = nil;
Zerotorescue@0 1422
Zerotorescue@0 1423 groupIdToName[info[2]] = value;
Zerotorescue@0 1424 groupIdToName[value] = true;
Zerotorescue@0 1425 groupIdToName[oldGroupName] = nil;
Zerotorescue@0 1426
Zerotorescue@0 1427 addon:FillGroupOptions();
Zerotorescue@0 1428 end,
Zerotorescue@0 1429 get = function(info)
Zerotorescue@0 1430 return groupIdToName[info[2]];
Zerotorescue@0 1431 end,
Zerotorescue@0 1432 },
Zerotorescue@10 1433 duplicate = {
Zerotorescue@10 1434 order = 20,
Zerotorescue@10 1435 type = "input",
Zerotorescue@10 1436 name = "Duplicate group - New name",
Zerotorescue@10 1437 desc = "Duplicate this group. You can also use item links here as you wish.\n\nAll item data will be erased.",
Zerotorescue@10 1438 validate = ValidateGroupName,
Zerotorescue@10 1439 set = function(info, value)
Zerotorescue@10 1440 local oldGroupName = groupIdToName[info[2]];
Zerotorescue@10 1441
Zerotorescue@10 1442 addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]);
Zerotorescue@10 1443
Zerotorescue@10 1444 -- Reset item data (duplicate items me no want)
Zerotorescue@10 1445 addon.db.global.groups[value].items = nil;
Zerotorescue@10 1446
Zerotorescue@10 1447 addon:FillGroupOptions();
Zerotorescue@10 1448 end,
Zerotorescue@10 1449 get = false,
Zerotorescue@10 1450 },
Zerotorescue@0 1451 delete = {
Zerotorescue@10 1452 order = 30,
Zerotorescue@0 1453 type = "execute",
Zerotorescue@0 1454 name = "Delete group",
Zerotorescue@0 1455 desc = "Delete the currently selected group.",
Zerotorescue@0 1456 confirm = true,
Zerotorescue@0 1457 confirmText = "Are you sure you wish to |cffff0000DELETE|r this group? This action is not reversable!",
Zerotorescue@0 1458 func = function(info)
Zerotorescue@0 1459 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1460
Zerotorescue@0 1461 addon.db.global.groups[groupName] = nil;
Zerotorescue@0 1462
Zerotorescue@0 1463 addon:FillGroupOptions();
Zerotorescue@0 1464 end,
Zerotorescue@0 1465 },
Zerotorescue@0 1466 },
Zerotorescue@0 1467 },
Zerotorescue@0 1468 export = {
Zerotorescue@10 1469 order = 40,
Zerotorescue@0 1470 type = "group",
Zerotorescue@0 1471 name = "Export",
Zerotorescue@0 1472 inline = true,
Zerotorescue@0 1473 args = {
Zerotorescue@0 1474 input = {
Zerotorescue@0 1475 order = 10,
Zerotorescue@0 1476 type = "input",
Zerotorescue@0 1477 multiline = true,
Zerotorescue@0 1478 name = "Group data",
Zerotorescue@0 1479 width = "full",
Zerotorescue@0 1480 desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.",
Zerotorescue@0 1481 set = false,
Zerotorescue@0 1482 get = function(info)
Zerotorescue@0 1483 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1484
Zerotorescue@0 1485 -- We want to include the group name, so we copy the table then set another value
Zerotorescue@0 1486 local temp = CopyTable(addon.db.global.groups[groupName]);
Zerotorescue@0 1487 temp.name = groupName;
Zerotorescue@9 1488 temp.trackAtCharacters = nil;
Zerotorescue@9 1489 temp.overrideTrackAtCharacters = nil;
Zerotorescue@0 1490
Zerotorescue@0 1491 if not AceSerializer then
Zerotorescue@0 1492 AceSerializer = LibStub("AceSerializer-3.0");
Zerotorescue@0 1493 end
Zerotorescue@0 1494
Zerotorescue@0 1495 return AceSerializer:Serialize(temp);
Zerotorescue@0 1496 end,
Zerotorescue@0 1497 },
Zerotorescue@0 1498 },
Zerotorescue@0 1499 },
Zerotorescue@0 1500 },
Zerotorescue@0 1501 },
Zerotorescue@0 1502 add = {
Zerotorescue@0 1503 order = 30,
Zerotorescue@0 1504 type = "group",
Zerotorescue@0 1505 name = "Add items",
Zerotorescue@23 1506 desc = "Add new items to this group.",
Zerotorescue@0 1507 args = {
Zerotorescue@0 1508 singleAdd = {
Zerotorescue@0 1509 order = 10,
Zerotorescue@0 1510 type = "group",
Zerotorescue@0 1511 inline = true,
Zerotorescue@0 1512 name = "Add items",
Zerotorescue@0 1513 args = {
Zerotorescue@0 1514 help = {
Zerotorescue@0 1515 order = 10,
Zerotorescue@0 1516 type = "description",
Zerotorescue@0 1517 name = "You can add a single item to this group at a time by pasting the item-id or an item-link in the field to the left or you can also import multiple items at once by pasting exported item data in the field to the right. Scroll further down to add items based on your inventory contents.",
Zerotorescue@0 1518 },
Zerotorescue@0 1519 itemLink = {
Zerotorescue@0 1520 order = 20,
Zerotorescue@0 1521 type = "input",
Zerotorescue@0 1522 name = "Single item add (item-link or item-id)",
Zerotorescue@0 1523 desc = "Shift-click an item-link or enter an item-id to add the related item to this group. You can only add one item link or item id at a time.",
Zerotorescue@0 1524 validate = function(info, value)
Zerotorescue@0 1525 -- If the value is empty we'll allow passing to clear the carret
Zerotorescue@0 1526 if value == "" then return true; end
Zerotorescue@0 1527
Zerotorescue@0 1528 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1529
Zerotorescue@0 1530 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or ""));
Zerotorescue@0 1531
Zerotorescue@0 1532 if not itemId then
Zerotorescue@0 1533 return "This is not a valid item link.";
Zerotorescue@0 1534 elseif InGroup(itemId) then
Zerotorescue@0 1535 return ("This item is already in the group \"%s\"."):format(InGroup(itemId));
Zerotorescue@0 1536 end
Zerotorescue@0 1537
Zerotorescue@0 1538 return true;
Zerotorescue@0 1539 end,
Zerotorescue@0 1540 set = function(info, value)
Zerotorescue@0 1541 if value and value ~= "" then
Zerotorescue@0 1542 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1543
Zerotorescue@0 1544 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or ""));
Zerotorescue@0 1545
Zerotorescue@0 1546 AddToGroup(groupName, itemId);
Zerotorescue@0 1547
Zerotorescue@0 1548 print(("Added %s"):format(select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId)));
Zerotorescue@0 1549 end
Zerotorescue@0 1550 end,
Zerotorescue@0 1551 get = false,
Zerotorescue@0 1552 },
Zerotorescue@17 1553 importItemData = {
Zerotorescue@17 1554 order = 30,
Zerotorescue@0 1555 type = "input",
Zerotorescue@0 1556 name = "Import item data",
Zerotorescue@0 1557 desc = "Import item data from an exported item data-string. Any items already grouped will be skipped.",
Zerotorescue@0 1558 set = function(info, value)
Zerotorescue@0 1559 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1560
Zerotorescue@0 1561 local allItemIds = { string.split(";", value or "") };
Zerotorescue@0 1562
Zerotorescue@0 1563 for _, value in pairs(allItemIds) do
Zerotorescue@0 1564 local itemId = tonumber(value);
Zerotorescue@0 1565
Zerotorescue@0 1566 if not itemId then
Zerotorescue@0 1567 print(("\"%s\" is not a number."):format(value));
Zerotorescue@0 1568 elseif InGroup(itemId) then
Zerotorescue@0 1569 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@0 1570 else
Zerotorescue@0 1571 AddToGroup(groupName, itemId);
Zerotorescue@0 1572 end
Zerotorescue@0 1573 end
Zerotorescue@0 1574 end,
Zerotorescue@0 1575 get = false,
Zerotorescue@0 1576 },
Zerotorescue@17 1577 importPremadeData = {
Zerotorescue@17 1578 order = 40,
Zerotorescue@17 1579 type = "select",
Zerotorescue@17 1580 name = "Import premade data",
Zerotorescue@17 1581 desc = "Import item data from a premade item-group. Any items already grouped will be skipped.",
Zerotorescue@17 1582 values = function()
Zerotorescue@17 1583 local temp = {};
Zerotorescue@17 1584 for key, group in pairs(addon.defaultGroups) do
Zerotorescue@17 1585 temp[key] = key;
Zerotorescue@17 1586 end
Zerotorescue@17 1587
Zerotorescue@17 1588 return temp;
Zerotorescue@17 1589 end,
Zerotorescue@17 1590 set = function(info, value)
Zerotorescue@17 1591 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1592
Zerotorescue@17 1593 print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value));
Zerotorescue@17 1594
Zerotorescue@17 1595 -- Remember we imported this group and it's version so if it is ever changed, people can be notified
Zerotorescue@17 1596 if not addon.db.global.groups[groupName].premadeGroups then
Zerotorescue@17 1597 addon.db.global.groups[groupName].premadeGroups = {};
Zerotorescue@17 1598 end
Zerotorescue@17 1599 addon.db.global.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version;
Zerotorescue@17 1600
Zerotorescue@17 1601 for itemId, _ in pairs(addon.defaultGroups[value].items) do
Zerotorescue@17 1602 itemId = itemId and tonumber(itemId);
Zerotorescue@17 1603
Zerotorescue@17 1604 if not itemId then
Zerotorescue@17 1605 print(("\"|cfffed000%s|r\" is not a number."):format(value));
Zerotorescue@17 1606 elseif InGroup(itemId) then
Zerotorescue@17 1607 print(("Skipping |cfffed000%s|r (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@17 1608 else
Zerotorescue@17 1609 AddToGroup(groupName, itemId);
Zerotorescue@17 1610 end
Zerotorescue@17 1611 end
Zerotorescue@17 1612 end,
Zerotorescue@17 1613 get = false,
Zerotorescue@17 1614 },
Zerotorescue@0 1615 },
Zerotorescue@0 1616 },
Zerotorescue@0 1617 massAdd = {
Zerotorescue@0 1618 order = 20,
Zerotorescue@0 1619 type = "group",
Zerotorescue@0 1620 inline = true,
Zerotorescue@0 1621 name = "Mass add",
Zerotorescue@0 1622 args = {
Zerotorescue@0 1623 help = {
Zerotorescue@0 1624 order = 10,
Zerotorescue@0 1625 type = "description",
Zerotorescue@0 1626 name = "Click the items you wish to add to this group or add multiple of these items at once by providing a name filter in the field below.",
Zerotorescue@0 1627 },
Zerotorescue@0 1628 massAdd = {
Zerotorescue@0 1629 order = 20,
Zerotorescue@0 1630 type = "input",
Zerotorescue@0 1631 name = "Add all items matching...",
Zerotorescue@0 1632 desc = "Add every item in your inventory matching the name entered in this field. If you enter \"Glyph\" as a filter, any items in your inventory containing this in their name will be added to this group.",
Zerotorescue@13 1633 set = function(info, value)
Zerotorescue@17 1634 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1635
Zerotorescue@13 1636 if not value then return; end
Zerotorescue@13 1637
Zerotorescue@13 1638 value = value:lower();
Zerotorescue@13 1639
Zerotorescue@13 1640 local ref = options.args.groups.args[info[2]].args.add.args.list.args;
Zerotorescue@13 1641
Zerotorescue@13 1642 for itemId, test in pairs(ref) do
Zerotorescue@13 1643 if test then
Zerotorescue@13 1644 local itemName = GetItemInfo(itemId);
Zerotorescue@13 1645
Zerotorescue@13 1646 if itemName:lower():find(value) then
Zerotorescue@13 1647 if not AddToGroup(groupName, itemId) then
Zerotorescue@13 1648 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r");
Zerotorescue@13 1649 end
Zerotorescue@13 1650 end
Zerotorescue@13 1651 end
Zerotorescue@13 1652 end
Zerotorescue@13 1653 end,
Zerotorescue@0 1654 get = false,
Zerotorescue@0 1655 },
Zerotorescue@13 1656 minItemLevel = {
Zerotorescue@13 1657 order = 40,
Zerotorescue@13 1658 type = "select",
Zerotorescue@13 1659 values = function()
Zerotorescue@13 1660 local temp = {};
Zerotorescue@13 1661
Zerotorescue@13 1662 temp[0] = "Include everything";
Zerotorescue@13 1663
Zerotorescue@13 1664 local itemLevelTemplate = "Itemlevel >= %d";
Zerotorescue@13 1665
Zerotorescue@13 1666 for i = 1, 49 do
Zerotorescue@13 1667 temp[( i * 10 )] = itemLevelTemplate:format(( i * 10 ));
Zerotorescue@13 1668 end
Zerotorescue@13 1669
Zerotorescue@13 1670 temp[500] = "Include nothing";
Zerotorescue@13 1671
Zerotorescue@13 1672 return temp;
Zerotorescue@13 1673 end,
Zerotorescue@13 1674 name = "Include tradeskill items",
Zerotorescue@13 1675 desc = "Include all items above this item level from the currently opened tradeskill window in the below item list.\n\nSetting this very low this might considerably slow down this config window.\n\nSet to 500 to disable showing of items completely.",
Zerotorescue@13 1676 set = function(i, v) includeTradeSkillItems = v; end,
Zerotorescue@13 1677 get = function() return includeTradeSkillItems; end,
Zerotorescue@13 1678 disabled = function()
Zerotorescue@13 1679 if GetTradeSkillLine() == "UNKNOWN" then
Zerotorescue@13 1680 includeTradeSkillItems = 500;
Zerotorescue@13 1681 return true; -- disabled
Zerotorescue@13 1682 else
Zerotorescue@13 1683 return false;
Zerotorescue@13 1684 end
Zerotorescue@13 1685 end,
Zerotorescue@13 1686 },
Zerotorescue@0 1687 },
Zerotorescue@0 1688 },
Zerotorescue@0 1689 list = {
Zerotorescue@0 1690 order = 30,
Zerotorescue@0 1691 type = "group",
Zerotorescue@0 1692 inline = true,
Zerotorescue@0 1693 name = "Item list",
Zerotorescue@0 1694 hidden = UpdateAddItemList,
Zerotorescue@0 1695 args = {
Zerotorescue@0 1696
Zerotorescue@0 1697 },
Zerotorescue@0 1698 },
Zerotorescue@0 1699 },
Zerotorescue@0 1700 },
Zerotorescue@0 1701 remove = {
Zerotorescue@0 1702 order = 40,
Zerotorescue@0 1703 type = "group",
Zerotorescue@0 1704 name = "Current items",
Zerotorescue@23 1705 desc = "View, export or remove items from this group.",
Zerotorescue@0 1706 args = {
Zerotorescue@0 1707 help = {
Zerotorescue@0 1708 order = 10,
Zerotorescue@0 1709 type = "group",
Zerotorescue@0 1710 inline = true,
Zerotorescue@0 1711 name = "Help",
Zerotorescue@0 1712 hidden = false,
Zerotorescue@0 1713 args = {
Zerotorescue@0 1714 help = {
Zerotorescue@0 1715 order = 10,
Zerotorescue@0 1716 type = "description",
Zerotorescue@0 1717 name = "Click the items you wish to remove from this group.",
Zerotorescue@0 1718 },
Zerotorescue@17 1719 massRemove = {
Zerotorescue@17 1720 order = 20,
Zerotorescue@17 1721 type = "input",
Zerotorescue@17 1722 name = "Remove all items matching...",
Zerotorescue@17 1723 desc = "Remove every item in this group matching the name entered in this field. If you enter \"Glyph\" as a filter, any items in this group containing this in their name will be removed from this group.",
Zerotorescue@17 1724 set = function(info, value)
Zerotorescue@17 1725 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1726
Zerotorescue@17 1727 if not value then return; end
Zerotorescue@17 1728
Zerotorescue@17 1729 value = value:lower();
Zerotorescue@17 1730
Zerotorescue@17 1731 local ref = options.args.groups.args[info[2]].args.remove.args.list.args;
Zerotorescue@17 1732
Zerotorescue@17 1733 for itemId, test in pairs(ref) do
Zerotorescue@17 1734 if test then
Zerotorescue@17 1735 local itemName = GetItemInfo(itemId);
Zerotorescue@17 1736
Zerotorescue@17 1737 if itemName:lower():find(value) then
Zerotorescue@17 1738 -- Unset this item
Zerotorescue@17 1739 addon.db.global.groups[groupName].items[itemId] = nil;
Zerotorescue@17 1740 end
Zerotorescue@17 1741 end
Zerotorescue@17 1742 end
Zerotorescue@17 1743 end,
Zerotorescue@17 1744 get = false,
Zerotorescue@17 1745 },
Zerotorescue@17 1746 premadeGroups = {
Zerotorescue@17 1747 order = 30,
Zerotorescue@17 1748 type = "select",
Zerotorescue@17 1749 name = "Imported premade groups",
Zerotorescue@23 1750 desc = "This is a list of all premade groups that were imported into this group. You will be notified when any of these premade groups have changed and you will be able to import these changes.\n\nSelect a group to stop reminding you of changes to the premade group (the item list will be unaffected). Doing so will require you to manually update this when new items are added to the game.",
Zerotorescue@17 1751 values = function(info)
Zerotorescue@17 1752 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1753
Zerotorescue@17 1754 local temp = {};
Zerotorescue@17 1755 if addon.db.global.groups[groupName].premadeGroups then
Zerotorescue@17 1756 for name, version in pairs(addon.db.global.groups[groupName].premadeGroups) do
Zerotorescue@17 1757 temp[name] = name;
Zerotorescue@17 1758 end
Zerotorescue@17 1759 end
Zerotorescue@17 1760
Zerotorescue@17 1761 return temp;
Zerotorescue@17 1762 end,
Zerotorescue@17 1763 set = function(info, value)
Zerotorescue@17 1764 -- Remove premade group from this group
Zerotorescue@17 1765 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1766
Zerotorescue@17 1767 addon.db.global.groups[groupName].premadeGroups[value] = nil;
Zerotorescue@17 1768
Zerotorescue@17 1769 print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value));
Zerotorescue@17 1770 end,
Zerotorescue@17 1771 get = false,
Zerotorescue@17 1772 disabled = function(info)
Zerotorescue@17 1773 local groupName = groupIdToName[info[2]];
Zerotorescue@17 1774
Zerotorescue@17 1775 return (not addon.db.global.groups[groupName].premadeGroups);
Zerotorescue@17 1776 end,
Zerotorescue@17 1777 },
Zerotorescue@0 1778 },
Zerotorescue@0 1779 },
Zerotorescue@0 1780 list = {
Zerotorescue@0 1781 order = 20,
Zerotorescue@0 1782 type = "group",
Zerotorescue@0 1783 inline = true,
Zerotorescue@0 1784 name = "Item list",
Zerotorescue@0 1785 hidden = UpdateRemoveItemList,
Zerotorescue@0 1786 args = {
Zerotorescue@0 1787
Zerotorescue@0 1788 },
Zerotorescue@0 1789 },
Zerotorescue@0 1790 export = {
Zerotorescue@0 1791 order = 30,
Zerotorescue@0 1792 type = "group",
Zerotorescue@0 1793 name = "Export",
Zerotorescue@0 1794 inline = true,
Zerotorescue@0 1795 args = {
Zerotorescue@0 1796 input = {
Zerotorescue@0 1797 order = 10,
Zerotorescue@0 1798 type = "input",
Zerotorescue@0 1799 name = "Item data",
Zerotorescue@0 1800 width = "full",
Zerotorescue@0 1801 desc = "Export the item data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.",
Zerotorescue@0 1802 set = false,
Zerotorescue@0 1803 get = function(info)
Zerotorescue@0 1804 local groupName = groupIdToName[info[2]];
Zerotorescue@0 1805
Zerotorescue@0 1806 local combinedItemIds;
Zerotorescue@0 1807 -- Parse items in group and show these
Zerotorescue@0 1808 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
Zerotorescue@0 1809 if not combinedItemIds then
Zerotorescue@0 1810 combinedItemIds = tostring(itemId);
Zerotorescue@0 1811 else
Zerotorescue@0 1812 combinedItemIds = combinedItemIds .. (";%d"):format(itemId);
Zerotorescue@0 1813 end
Zerotorescue@0 1814 end
Zerotorescue@0 1815
Zerotorescue@0 1816 return combinedItemIds; -- We don't serialize this because we actually DO want people to be able to manually modify it - besides, parsing it isn't going to be hard
Zerotorescue@0 1817 end,
Zerotorescue@0 1818 },
Zerotorescue@0 1819 },
Zerotorescue@0 1820 },
Zerotorescue@0 1821 },
Zerotorescue@0 1822 },
Zerotorescue@0 1823 },
Zerotorescue@0 1824 };
Zerotorescue@0 1825
Zerotorescue@0 1826 function addon:MakeGroupOptions()
Zerotorescue@0 1827 options.args.groups = {
Zerotorescue@0 1828 order = 1100,
Zerotorescue@0 1829 type = "group",
Zerotorescue@0 1830 name = "Groups",
Zerotorescue@0 1831 desc = "Change a group.",
Zerotorescue@0 1832 args = {
Zerotorescue@0 1833 create = {
Zerotorescue@0 1834 order = 10,
Zerotorescue@0 1835 type = "group",
Zerotorescue@0 1836 inline = true,
Zerotorescue@0 1837 name = "Create a brand new group",
Zerotorescue@0 1838 args = {
Zerotorescue@0 1839 name = {
Zerotorescue@0 1840 order = 10,
Zerotorescue@0 1841 type = "input",
Zerotorescue@0 1842 name = "Group name",
Zerotorescue@0 1843 desc = "The name of the group. You can also use item links as you wish.",
Zerotorescue@0 1844 validate = ValidateGroupName,
Zerotorescue@0 1845 set = function(_, value)
Zerotorescue@0 1846 self.db.global.groups[value] = {};
Zerotorescue@0 1847
Zerotorescue@0 1848 addon:FillGroupOptions();
Zerotorescue@0 1849 end,
Zerotorescue@0 1850 get = false,
Zerotorescue@0 1851 width = "double",
Zerotorescue@0 1852 },
Zerotorescue@0 1853 },
Zerotorescue@0 1854 },
Zerotorescue@0 1855 import = {
Zerotorescue@0 1856 order = 20,
Zerotorescue@0 1857 type = "group",
Zerotorescue@0 1858 inline = true,
Zerotorescue@0 1859 name = "Import a group",
Zerotorescue@0 1860 args = {
Zerotorescue@0 1861 input = {
Zerotorescue@0 1862 order = 10,
Zerotorescue@0 1863 type = "input",
Zerotorescue@0 1864 multiline = true,
Zerotorescue@0 1865 name = "Group data",
Zerotorescue@0 1866 desc = "Paste the group data as provided by a group export. If you are trying to import multiple groups at the same time, make sure to use newlines to seperate them.",
Zerotorescue@0 1867 set = function(info, value)
Zerotorescue@9 1868 local data = { string.split("\n", value or "") };
Zerotorescue@0 1869
Zerotorescue@9 1870 for _, current in pairs(data) do
Zerotorescue@0 1871 if not AceSerializer then
Zerotorescue@0 1872 AceSerializer = LibStub("AceSerializer-3.0");
Zerotorescue@0 1873 end
Zerotorescue@0 1874
Zerotorescue@0 1875 local result, temp = AceSerializer:Deserialize(current);
Zerotorescue@0 1876
Zerotorescue@0 1877 if not temp.name then
Zerotorescue@0 1878 print("|cffff0000The provided data is not supported.|r");
Zerotorescue@10 1879 elseif ValidateGroupName(nil, temp.name) ~= true then
Zerotorescue@10 1880 print(("|cffff0000Aborting: A group named \"%s\" already exists.|r"):format(temp.name));
Zerotorescue@0 1881 else
Zerotorescue@10 1882 local name = temp.name;
Zerotorescue@0 1883 temp.name = nil;
Zerotorescue@9 1884 print(("Importing %s..."):format(name));
Zerotorescue@10 1885
Zerotorescue@10 1886 -- Remove items that are already in another group
Zerotorescue@10 1887 for value, _ in pairs(temp.items) do
Zerotorescue@17 1888 local itemId = tonumber(value);
Zerotorescue@10 1889
Zerotorescue@10 1890 if not itemId then
Zerotorescue@10 1891 print(("\"%s\" is not a number."):format(value));
Zerotorescue@10 1892 temp.items[value] = nil;
Zerotorescue@10 1893 elseif InGroup(itemId) then
Zerotorescue@10 1894 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
Zerotorescue@10 1895 temp.items[value] = nil;
Zerotorescue@10 1896 else
Zerotorescue@10 1897 -- Ensure the keys are numeric
Zerotorescue@10 1898 temp.items[value] = nil;
Zerotorescue@10 1899 temp.items[itemId] = true;
Zerotorescue@10 1900 end
Zerotorescue@10 1901 end
Zerotorescue@10 1902
Zerotorescue@23 1903 -- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this)
Zerotorescue@10 1904 temp.trackAtCharacters = nil;
Zerotorescue@10 1905 temp.overrideTrackAtCharacters = nil;
Zerotorescue@10 1906
Zerotorescue@10 1907 self.db.global.groups[name] = temp;
Zerotorescue@0 1908 end
Zerotorescue@0 1909 end
Zerotorescue@10 1910
Zerotorescue@10 1911 self:FillGroupOptions();
Zerotorescue@0 1912 end,
Zerotorescue@0 1913 get = false,
Zerotorescue@0 1914 width = "full",
Zerotorescue@0 1915 },
Zerotorescue@0 1916 },
Zerotorescue@0 1917 },
Zerotorescue@0 1918 },
Zerotorescue@0 1919 };
Zerotorescue@0 1920 end
Zerotorescue@0 1921
Zerotorescue@0 1922 function addon:FillGroupOptions()
Zerotorescue@0 1923 for id, name in pairs(groupIdToName) do
Zerotorescue@0 1924 if type(name) == "string" and not self.db.global.groups[name] then
Zerotorescue@0 1925 options.args.groups.args[id] = nil;
Zerotorescue@0 1926 groupIdToName[id] = nil;
Zerotorescue@0 1927 groupIdToName[name] = nil;
Zerotorescue@0 1928 end
Zerotorescue@0 1929 end
Zerotorescue@0 1930
Zerotorescue@0 1931 for name, values in pairs(self.db.global.groups) do
Zerotorescue@0 1932 if not groupIdToName[name] then
Zerotorescue@23 1933 options.args.groups.args[tostring(count)] = defaultGroup;
Zerotorescue@0 1934
Zerotorescue@0 1935 groupIdToName[tostring(count)] = name;
Zerotorescue@0 1936 groupIdToName[name] = true;
Zerotorescue@0 1937
Zerotorescue@0 1938 count = ( count + 1 );
Zerotorescue@0 1939 end
Zerotorescue@0 1940 end
Zerotorescue@0 1941 end
Zerotorescue@0 1942
Zerotorescue@13 1943
Zerotorescue@13 1944
Zerotorescue@13 1945 -- General functions used addon-wide
Zerotorescue@13 1946
Zerotorescue@23 1947 function addon:GetItemCount(itemId, group)
Zerotorescue@13 1948 itemId = tonumber(itemId);
Zerotorescue@13 1949
Zerotorescue@13 1950 if not itemId then return; end
Zerotorescue@13 1951
Zerotorescue@23 1952 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
Zerotorescue@23 1953
Zerotorescue@23 1954 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 1955 -- Try to use the default item count addon
Zerotorescue@13 1956
Zerotorescue@23 1957 return self.supportedAddons.itemCount[selectedExternalAddon].GetTotalCount(itemId);
Zerotorescue@13 1958 else
Zerotorescue@13 1959 -- Default not available, get the first one then
Zerotorescue@13 1960
Zerotorescue@13 1961 for name, value in pairs(self.supportedAddons.itemCount) do
Zerotorescue@13 1962 if value.IsEnabled() then
Zerotorescue@17 1963 return value.GetTotalCount(itemId);
Zerotorescue@13 1964 end
Zerotorescue@13 1965 end
Zerotorescue@13 1966 end
Zerotorescue@13 1967
Zerotorescue@13 1968 return -1;
Zerotorescue@0 1969 end
Zerotorescue@0 1970
Zerotorescue@23 1971 function addon:GetAuctionValue(itemLink, group)
Zerotorescue@23 1972 if not itemLink then return -5; end
Zerotorescue@13 1973
Zerotorescue@23 1974 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
Zerotorescue@23 1975
Zerotorescue@23 1976 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 1977 -- Try to use the default auction pricing addon
Zerotorescue@1 1978
Zerotorescue@23 1979 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
Zerotorescue@13 1980 else
Zerotorescue@13 1981 -- Default not available, get the first one then
Zerotorescue@1 1982
Zerotorescue@13 1983 for name, value in pairs(self.supportedAddons.auctionPricing) do
Zerotorescue@13 1984 if value.IsEnabled() then
Zerotorescue@13 1985 return value.GetValue(itemLink);
Zerotorescue@13 1986 end
Zerotorescue@1 1987 end
Zerotorescue@1 1988 end
Zerotorescue@7 1989
Zerotorescue@7 1990 return -2;
Zerotorescue@1 1991 end
Zerotorescue@1 1992
Zerotorescue@0 1993
Zerotorescue@0 1994
Zerotorescue@13 1995 -- Public
Zerotorescue@13 1996
Zerotorescue@13 1997 function IMRegisterPricingAddon(name, get, enabled)
Zerotorescue@13 1998 addon.supportedAddons.auctionPricing[name] = {
Zerotorescue@13 1999 GetValue = get,
Zerotorescue@13 2000 IsEnabled = enabled,
Zerotorescue@13 2001 };
Zerotorescue@13 2002 end
Zerotorescue@13 2003
Zerotorescue@17 2004 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled)
Zerotorescue@13 2005 addon.supportedAddons.itemCount[name] = {
Zerotorescue@17 2006 GetTotalCount = getTotal,
Zerotorescue@17 2007 GetCharacterCount = getCharacter,
Zerotorescue@13 2008 IsEnabled = enabled,
Zerotorescue@13 2009 };
Zerotorescue@13 2010 end
Zerotorescue@13 2011
Zerotorescue@13 2012 function IMRegisterCraftingAddon(name, queue, enabled)
Zerotorescue@13 2013 addon.supportedAddons.crafting[name] = {
Zerotorescue@13 2014 Queue = queue,
Zerotorescue@13 2015 IsEnabled = enabled,
Zerotorescue@13 2016 };
Zerotorescue@13 2017 end
Zerotorescue@13 2018
Zerotorescue@13 2019
Zerotorescue@13 2020
Zerotorescue@13 2021 -- Debug
Zerotorescue@0 2022
Zerotorescue@0 2023 function addon:Debug(t)
Zerotorescue@0 2024 if not self.debugChannel and self.debugChannel ~= false then
Zerotorescue@0 2025 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources)
Zerotorescue@0 2026 self.debugChannel = false;
Zerotorescue@0 2027
Zerotorescue@0 2028 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 2029 local name = GetChatWindowInfo(i);
Zerotorescue@0 2030
Zerotorescue@0 2031 if name:upper() == "DEBUG" then
Zerotorescue@0 2032 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 2033 end
Zerotorescue@0 2034 end
Zerotorescue@0 2035 end
Zerotorescue@0 2036
Zerotorescue@0 2037 if self.debugChannel then
Zerotorescue@0 2038 self.debugChannel:AddMessage(t);
Zerotorescue@0 2039 end
Zerotorescue@0 2040 end