annotate Core.lua @ 64:0bd50500561c

Added tag v0.1.14-BETA for changeset 533761fef07b
author Zerotorescue
date Wed, 22 Dec 2010 20:01:13 +0100
parents fee06221176f
children ac1189599769
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@61 5 --@debug@
Zerotorescue@61 6 local addonRevision = 1;
Zerotorescue@61 7 --@end-debug@
Zerotorescue@61 8 --[===[@non-debug@
Zerotorescue@61 9 local addonRevision = @project-revision@;
Zerotorescue@61 10 --@end-non-debug@]===]
Zerotorescue@61 11
Zerotorescue@62 12 local _G = _G;
Zerotorescue@62 13 local print, pairs, tonumber = _G.print, _G.pairs, _G.tonumber;
Zerotorescue@13 14
Zerotorescue@62 15 -- All modules must be able to retrieve our supported addons database, thus keep it a part of the addon object rather than local
Zerotorescue@13 16 addon.supportedAddons = {};
Zerotorescue@13 17 addon.supportedAddons.auctionPricing = {};
Zerotorescue@13 18 addon.supportedAddons.itemCount = {};
Zerotorescue@13 19 addon.supportedAddons.crafting = {};
Zerotorescue@0 20
Zerotorescue@0 21 function addon:OnInitialize()
Zerotorescue@0 22 self:Debug("OnInitialize");
Zerotorescue@0 23
Zerotorescue@0 24 -- SAVED VARIABLES
Zerotorescue@0 25
Zerotorescue@0 26 local defaults = {
Zerotorescue@0 27 global = {
Zerotorescue@61 28 version = nil,
Zerotorescue@61 29 },
Zerotorescue@61 30 profile = {
Zerotorescue@0 31 defaults = {
Zerotorescue@13 32 auctionPricingAddon = "Auctioneer",
Zerotorescue@13 33 itemCountAddon = "Altoholic",
Zerotorescue@13 34 craftingAddon = "AdvancedTradeSkillWindow",
Zerotorescue@61 35 minLocalStock = 20,
Zerotorescue@57 36 alertBelowLocalMinimum = true,
Zerotorescue@61 37 minGlobalStock = 60,
Zerotorescue@61 38 alertBelowGlobalMinimum = true,
Zerotorescue@0 39 summaryThresholdShow = 10,
Zerotorescue@0 40 restockTarget = 60,
Zerotorescue@0 41 minCraftingQueue = 0.05,
Zerotorescue@0 42 bonusQueue = 0.1,
Zerotorescue@0 43 priceThreshold = 0,
Zerotorescue@13 44 summaryHidePriceThreshold = false,
Zerotorescue@40 45 trackAtCharacters = {
Zerotorescue@40 46 },
Zerotorescue@31 47 localItemData = {
Zerotorescue@31 48 ["Bag"] = true,
Zerotorescue@31 49 ["Auction House"] = true,
Zerotorescue@31 50 },
Zerotorescue@13 51 summary = {
Zerotorescue@13 52 speed = 5,
Zerotorescue@13 53 width = 650,
Zerotorescue@13 54 height = 600,
Zerotorescue@13 55 },
Zerotorescue@0 56 colors = {
Zerotorescue@17 57 red = 0,
Zerotorescue@17 58 orange = 0.3,
Zerotorescue@17 59 yellow = 0.6,
Zerotorescue@17 60 green = 0.95,
Zerotorescue@0 61 },
Zerotorescue@0 62 },
Zerotorescue@61 63 groups = {
Zerotorescue@61 64 },
Zerotorescue@0 65 },
Zerotorescue@0 66 factionrealm = {
Zerotorescue@40 67 characters = {
Zerotorescue@40 68 },
Zerotorescue@0 69 },
Zerotorescue@0 70 };
Zerotorescue@0 71
Zerotorescue@0 72 -- Register our saved variables database
Zerotorescue@11 73 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
Zerotorescue@61 74
Zerotorescue@62 75 -- SLASH COMMANDS
Zerotorescue@62 76
Zerotorescue@62 77 -- Disable the AddonLoader slash commands
Zerotorescue@62 78 SLASH_INVENTORIUM1 = nil;
Zerotorescue@62 79 SLASH_IM1 = nil;
Zerotorescue@62 80
Zerotorescue@62 81 -- Register our own slash commands
Zerotorescue@62 82 SLASH_INVENTORIUM1 = "/inventorium";
Zerotorescue@62 83 SLASH_INVENTORIUM2 = "/im";
Zerotorescue@62 84 SlashCmdList["INVENTORIUM"] = function(msg)
Zerotorescue@62 85 addon:CommandHandler(msg);
Zerotorescue@62 86 end;
Zerotorescue@62 87
Zerotorescue@62 88 -- Debug command handling
Zerotorescue@62 89 self:RegisterSlash(function(this)
Zerotorescue@62 90 this.debugChannel = false;
Zerotorescue@62 91 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@62 92 local name = GetChatWindowInfo(i);
Zerotorescue@62 93
Zerotorescue@62 94 if name:upper() == "DEBUG" then
Zerotorescue@62 95 this.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@62 96
Zerotorescue@62 97 print("A debug channel already exists, used the old one. (" .. i .. ")");
Zerotorescue@62 98 return;
Zerotorescue@62 99 end
Zerotorescue@62 100 end
Zerotorescue@62 101
Zerotorescue@62 102 if not this.debugChannel then
Zerotorescue@62 103 -- Create a new debug channel
Zerotorescue@62 104 local chatFrame = FCF_OpenNewWindow('Debug');
Zerotorescue@62 105 ChatFrame_RemoveAllMessageGroups(chatFrame);
Zerotorescue@62 106 this.debugChannel = chatFrame;
Zerotorescue@62 107
Zerotorescue@62 108 print("New debug channel created.");
Zerotorescue@62 109 end
Zerotorescue@62 110 end, { "d", "debug" });
Zerotorescue@62 111
Zerotorescue@62 112 -- Remember this character is on this account
Zerotorescue@62 113 local playerName = UnitName("player");
Zerotorescue@62 114 if not self.db.factionrealm.characters[playerName] then
Zerotorescue@62 115 self.db.factionrealm.characters[playerName] = true;
Zerotorescue@62 116
Zerotorescue@62 117 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
Zerotorescue@62 118 self.db.profile.defaults.trackAtCharacters[playerName] = true;
Zerotorescue@62 119 end
Zerotorescue@62 120
Zerotorescue@62 121 self:PremadeGroupsCheck();
Zerotorescue@62 122 end
Zerotorescue@62 123
Zerotorescue@62 124 function addon:UpdateDatabase()
Zerotorescue@61 125 if not self.db.global.version or self.db.global.version < addonRevision then
Zerotorescue@61 126 -- Is our database outdated? Then patch it.
Zerotorescue@61 127
Zerotorescue@61 128 if not self.db.global.version then
Zerotorescue@61 129 -- Old version was before version was saved, many changes were done in that revision
Zerotorescue@61 130
Zerotorescue@61 131 print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
Zerotorescue@61 132
Zerotorescue@61 133 if self.db.global and self.db.global.defaults then
Zerotorescue@61 134 print("Moving all global data into your current profile...");
Zerotorescue@61 135
Zerotorescue@61 136 -- All data mustn't be global but profile-based
Zerotorescue@61 137 self.db.profile.defaults = CopyTable(self.db.global.defaults);
Zerotorescue@61 138 self.db.profile.groups = CopyTable(self.db.global.groups);
Zerotorescue@61 139
Zerotorescue@61 140 self.db.global.defaults = nil;
Zerotorescue@61 141 self.db.global.groups = nil;
Zerotorescue@61 142
Zerotorescue@62 143 self.CommandHandler = function()
Zerotorescue@62 144 message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA.");
Zerotorescue@61 145 end;
Zerotorescue@62 146 self:CommandHandler();
Zerotorescue@61 147 end
Zerotorescue@61 148
Zerotorescue@61 149 if self.db.profile.defaults.minimumStock then
Zerotorescue@61 150 print("Copying the minimum stock value into the minimum global stock...");
Zerotorescue@61 151
Zerotorescue@61 152 -- We added another stock option and renamed the old to be more obvious about what it means
Zerotorescue@61 153 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
Zerotorescue@61 154 self.db.profile.defaults.minimumStock = nil;
Zerotorescue@61 155 end
Zerotorescue@61 156
Zerotorescue@61 157 if self.db.profile.defaults.minimumLocalStock then
Zerotorescue@61 158 print("Renaming the minimum local stock property...");
Zerotorescue@61 159
Zerotorescue@61 160 -- We added another stock option and then renamed it
Zerotorescue@61 161 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
Zerotorescue@61 162 self.db.profile.defaults.minimumLocalStock = nil;
Zerotorescue@61 163 end
Zerotorescue@61 164
Zerotorescue@61 165 if self.db.profile.defaults.alertBelowMinimum then
Zerotorescue@61 166 print("Copying the alert below minimum value into the alert below global minimum value...");
Zerotorescue@61 167
Zerotorescue@61 168 -- We added another stock option and then renamed it
Zerotorescue@61 169 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
Zerotorescue@61 170 self.db.profile.defaults.alertBelowMinimum = nil;
Zerotorescue@61 171 end
Zerotorescue@61 172
Zerotorescue@61 173 -- Go through all groups to see if there's one with the above two renamed variables
Zerotorescue@61 174 for groupName, values in pairs(self.db.profile.groups) do
Zerotorescue@61 175 if values.minimumStock then
Zerotorescue@61 176 values.minGlobalStock = values.minimumStock;
Zerotorescue@61 177 values.minimumStock = nil;
Zerotorescue@61 178 end
Zerotorescue@61 179 end
Zerotorescue@61 180 end
Zerotorescue@61 181
Zerotorescue@61 182 -- Remember the version of our database
Zerotorescue@61 183 self.db.global.version = addonRevision;
Zerotorescue@61 184 end
Zerotorescue@46 185 end
Zerotorescue@46 186
Zerotorescue@23 187 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept)
Zerotorescue@23 188 -- Compare the current premade groups with those used, notify about changes
Zerotorescue@23 189 if addon.defaultGroups then
Zerotorescue@46 190 for premadeGroupName, groupInfo in pairs(addon.defaultGroups) do
Zerotorescue@23 191 -- Go through all default groups
Zerotorescue@23 192
Zerotorescue@61 193 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@23 194 -- Go through all groups to find those with this premade group
Zerotorescue@23 195
Zerotorescue@46 196 if values.premadeGroups and values.premadeGroups[premadeGroupName] and values.premadeGroups[premadeGroupName] < groupInfo.version then
Zerotorescue@23 197 -- Outdated group
Zerotorescue@23 198
Zerotorescue@23 199 if updateGroupName and updateKey then
Zerotorescue@23 200 -- This function was called after pressing yes or no in a confirm box
Zerotorescue@23 201
Zerotorescue@23 202 if accept then
Zerotorescue@23 203 -- Yes was clicked
Zerotorescue@23 204
Zerotorescue@23 205 for itemId, version in pairs(groupInfo.items) do
Zerotorescue@23 206 -- Go through all items in this premade group
Zerotorescue@23 207
Zerotorescue@46 208 if version > values.premadeGroups[premadeGroupName] then
Zerotorescue@23 209 -- This item was added in a more recent version than this group: Add item
Zerotorescue@23 210
Zerotorescue@62 211 if self:InGroup(itemId) then
Zerotorescue@62 212 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, self:InGroup(itemId)));
Zerotorescue@62 213 elseif self:AddItemToGroup(groupName, itemId) then
Zerotorescue@62 214 print(("|cff00ff00Added|r %s (#%d) found in the premade group |cfffed000%s|r to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, premadeGroupName, self:InGroup(itemId)));
Zerotorescue@46 215 end
Zerotorescue@46 216 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then
Zerotorescue@62 217 if self:InGroup(itemId) == groupName then
Zerotorescue@62 218 print(("|cffff0000Removed|r %s (#%d) from the group |cfffed000%s|r as it was removed from the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, self:InGroup(itemId), premadeGroupName));
Zerotorescue@62 219 self:RemoveItemFromGroup(groupName, itemId);
Zerotorescue@46 220 else
Zerotorescue@62 221 print(("Skipping the removal of %s (#%d) as it isn't in this group."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, self:InGroup(itemId)));
Zerotorescue@23 222 end
Zerotorescue@23 223 end
Zerotorescue@23 224 end
Zerotorescue@23 225
Zerotorescue@23 226 -- Remember the new version
Zerotorescue@46 227 values.premadeGroups[premadeGroupName] = groupInfo.version;
Zerotorescue@23 228 else
Zerotorescue@23 229 -- No was clicked
Zerotorescue@23 230
Zerotorescue@23 231 -- Let user know what was not added
Zerotorescue@23 232 for itemId, version in pairs(groupInfo.items) do
Zerotorescue@23 233 -- Go through all items in this premade group
Zerotorescue@23 234
Zerotorescue@46 235 if version > values.premadeGroups[premadeGroupName] then
Zerotorescue@23 236 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it
Zerotorescue@23 237
Zerotorescue@62 238 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, self:InGroup(itemId)));
Zerotorescue@23 239 end
Zerotorescue@23 240 end
Zerotorescue@23 241
Zerotorescue@23 242 -- Remember the new version
Zerotorescue@46 243 values.premadeGroups[premadeGroupName] = groupInfo.version;
Zerotorescue@23 244 end
Zerotorescue@23 245 else
Zerotorescue@23 246 StaticPopupDialogs["InventoriumConfirmUpdatePremadeGroup"] = {
Zerotorescue@23 247 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 248 button1 = YES,
Zerotorescue@23 249 button2 = NO,
Zerotorescue@23 250 OnAccept = function(self)
Zerotorescue@46 251 addon:PremadeGroupsCheck(groupName, premadeGroupName, true);
Zerotorescue@23 252 end,
Zerotorescue@23 253 OnCancel = function(self, _, reason)
Zerotorescue@23 254 if reason == "clicked" then
Zerotorescue@46 255 addon:PremadeGroupsCheck(groupName, premadeGroupName, false);
Zerotorescue@23 256 end
Zerotorescue@23 257 end,
Zerotorescue@23 258 timeout = 0,
Zerotorescue@23 259 whileDead = 1,
Zerotorescue@23 260 hideOnEscape = 1,
Zerotorescue@23 261 };
Zerotorescue@46 262 StaticPopup_Show("InventoriumConfirmUpdatePremadeGroup", premadeGroupName, groupName);
Zerotorescue@23 263
Zerotorescue@23 264 return;
Zerotorescue@23 265 end
Zerotorescue@23 266 end
Zerotorescue@23 267 end
Zerotorescue@23 268 end
Zerotorescue@23 269 end
Zerotorescue@23 270 end
Zerotorescue@23 271
Zerotorescue@0 272 function addon:GetItemId(itemLink)
Zerotorescue@13 273 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
Zerotorescue@0 274 itemLink = itemLink and tonumber(itemLink);
Zerotorescue@0 275
Zerotorescue@0 276 return itemLink;
Zerotorescue@0 277 end
Zerotorescue@0 278
Zerotorescue@62 279 function addon:GetOptionByKey(groupName, optionName, noDefault)
Zerotorescue@62 280 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
Zerotorescue@62 281 -- If this option exists within the settings of this group
Zerotorescue@62 282
Zerotorescue@62 283 return addon.db.profile.groups[groupName][optionName];
Zerotorescue@62 284 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
Zerotorescue@62 285 -- If a virtual group was selected
Zerotorescue@62 286
Zerotorescue@62 287 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
Zerotorescue@62 288 elseif addon.db.profile.defaults[optionName] and not noDefault then
Zerotorescue@62 289 return addon.db.profile.defaults[optionName];
Zerotorescue@62 290 else
Zerotorescue@62 291 return nil;
Zerotorescue@0 292 end
Zerotorescue@0 293 end
Zerotorescue@0 294
Zerotorescue@35 295 function addon:GetItemCountAddon(group)
Zerotorescue@35 296 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
Zerotorescue@35 297
Zerotorescue@35 298 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
Zerotorescue@35 299 -- Try to use the default item count addon
Zerotorescue@35 300
Zerotorescue@35 301 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
Zerotorescue@35 302 else
Zerotorescue@35 303 -- Default not available, get the first one then
Zerotorescue@35 304
Zerotorescue@35 305 for name, value in pairs(self.supportedAddons.itemCount) do
Zerotorescue@35 306 if value.IsEnabled() then
Zerotorescue@35 307 return value, name;
Zerotorescue@35 308 end
Zerotorescue@35 309 end
Zerotorescue@35 310 end
Zerotorescue@35 311
Zerotorescue@35 312 return;
Zerotorescue@35 313 end
Zerotorescue@35 314
Zerotorescue@23 315 function addon:GetItemCount(itemId, group)
Zerotorescue@13 316 itemId = tonumber(itemId);
Zerotorescue@13 317
Zerotorescue@13 318 if not itemId then return; end
Zerotorescue@13 319
Zerotorescue@35 320 local itemCountAddon = self:GetItemCountAddon(group);
Zerotorescue@23 321
Zerotorescue@35 322 return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1;
Zerotorescue@0 323 end
Zerotorescue@0 324
Zerotorescue@50 325 function addon:GetLocalItemCount(itemId, group)
Zerotorescue@50 326 itemId = tonumber(itemId);
Zerotorescue@50 327
Zerotorescue@50 328 if not itemId then return; end
Zerotorescue@50 329
Zerotorescue@50 330 local itemCountAddon = self:GetItemCountAddon(group);
Zerotorescue@50 331
Zerotorescue@50 332 local currentItemCount;
Zerotorescue@50 333
Zerotorescue@50 334 if itemCountAddon and itemCountAddon.GetCharacterCount then
Zerotorescue@50 335 local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId);
Zerotorescue@50 336
Zerotorescue@50 337 local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData");
Zerotorescue@50 338
Zerotorescue@50 339 currentItemCount = 0;
Zerotorescue@50 340 if selectedLocalItemCountSources["Bag"] then
Zerotorescue@50 341 currentItemCount = currentItemCount + bag;
Zerotorescue@50 342 end
Zerotorescue@50 343 if selectedLocalItemCountSources["Bank"] then
Zerotorescue@50 344 currentItemCount = currentItemCount + bank;
Zerotorescue@50 345 end
Zerotorescue@50 346 if selectedLocalItemCountSources["Auction House"] then
Zerotorescue@50 347 currentItemCount = currentItemCount + auctionHouse;
Zerotorescue@50 348 end
Zerotorescue@50 349 if selectedLocalItemCountSources["Mailbox"] then
Zerotorescue@50 350 currentItemCount = currentItemCount + mail;
Zerotorescue@50 351 end
Zerotorescue@50 352 end
Zerotorescue@50 353
Zerotorescue@50 354 return currentItemCount or -1;
Zerotorescue@50 355 end
Zerotorescue@50 356
Zerotorescue@23 357 function addon:GetAuctionValue(itemLink, group)
Zerotorescue@23 358 if not itemLink then return -5; end
Zerotorescue@13 359
Zerotorescue@23 360 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
Zerotorescue@23 361
Zerotorescue@23 362 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 363 -- Try to use the default auction pricing addon
Zerotorescue@1 364
Zerotorescue@23 365 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
Zerotorescue@13 366 else
Zerotorescue@13 367 -- Default not available, get the first one then
Zerotorescue@1 368
Zerotorescue@13 369 for name, value in pairs(self.supportedAddons.auctionPricing) do
Zerotorescue@13 370 if value.IsEnabled() then
Zerotorescue@13 371 return value.GetValue(itemLink);
Zerotorescue@13 372 end
Zerotorescue@1 373 end
Zerotorescue@1 374 end
Zerotorescue@7 375
Zerotorescue@7 376 return -2;
Zerotorescue@1 377 end
Zerotorescue@1 378
Zerotorescue@62 379 -- Slash commands
Zerotorescue@62 380
Zerotorescue@62 381 local slashArgs = {};
Zerotorescue@62 382 local slashError = "Wrong argument, the following arguments are available:";
Zerotorescue@62 383
Zerotorescue@62 384 function addon:CommandHandler(message)
Zerotorescue@62 385 local cmd, arg = string.split(" ", (message or ""), 2);
Zerotorescue@62 386 cmd = string.lower(cmd);
Zerotorescue@62 387
Zerotorescue@62 388 if slashArgs[cmd] then
Zerotorescue@62 389 -- Pass a reference to the addon (to be used as "self") and the provided arg
Zerotorescue@62 390 slashArgs[cmd](addon, arg);
Zerotorescue@62 391 else
Zerotorescue@62 392 print(slashError);
Zerotorescue@62 393 end
Zerotorescue@62 394 end
Zerotorescue@62 395
Zerotorescue@62 396 function addon:RegisterSlash(func, args, description)
Zerotorescue@62 397 for _, arg in pairs(args) do
Zerotorescue@62 398 slashArgs[arg] = func;
Zerotorescue@62 399 end
Zerotorescue@62 400
Zerotorescue@62 401 if description then
Zerotorescue@62 402 slashError = slashError .. "\n" .. description;
Zerotorescue@62 403 end
Zerotorescue@62 404 end
Zerotorescue@62 405
Zerotorescue@62 406 -- Group functions
Zerotorescue@62 407
Zerotorescue@62 408 function addon:InGroup(itemId)
Zerotorescue@62 409 -- Go through all groups to see if this item is already somewhere
Zerotorescue@62 410 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@62 411 if values.items and values.items[itemId] then
Zerotorescue@62 412 return groupName;
Zerotorescue@62 413 end
Zerotorescue@62 414 end
Zerotorescue@62 415
Zerotorescue@62 416 return;
Zerotorescue@62 417 end
Zerotorescue@62 418
Zerotorescue@62 419 function addon:AddItemToGroup(groupName, itemId)
Zerotorescue@62 420 if self:InGroup(itemId) then
Zerotorescue@62 421 return false;
Zerotorescue@62 422 end
Zerotorescue@62 423
Zerotorescue@62 424 if not addon.db.profile.groups[groupName].items then
Zerotorescue@62 425 addon.db.profile.groups[groupName].items = {};
Zerotorescue@62 426 end
Zerotorescue@62 427
Zerotorescue@62 428 -- Set this item
Zerotorescue@62 429 addon.db.profile.groups[groupName].items[itemId] = true;
Zerotorescue@62 430
Zerotorescue@62 431 if AceConfigRegistry then
Zerotorescue@62 432 -- Now rebuild the list
Zerotorescue@62 433 AceConfigRegistry:NotifyChange("InventoriumOptions");
Zerotorescue@62 434 end
Zerotorescue@62 435
Zerotorescue@62 436 return true;
Zerotorescue@62 437 end
Zerotorescue@62 438
Zerotorescue@62 439 function addon:RemoveItemFromGroup(groupName, itemId)
Zerotorescue@62 440 if self:InGroup(itemId) ~= groupName then
Zerotorescue@62 441 return false;
Zerotorescue@62 442 end
Zerotorescue@62 443
Zerotorescue@62 444 -- Unset this item
Zerotorescue@62 445 addon.db.profile.groups[groupName].items[itemId] = nil;
Zerotorescue@62 446
Zerotorescue@62 447 return true;
Zerotorescue@62 448 end
Zerotorescue@62 449
Zerotorescue@62 450 -- Readable money
Zerotorescue@62 451
Zerotorescue@62 452 local goldText = "%s%d|cffffd700g|r ";
Zerotorescue@62 453 local silverText = "%s%d|cffc7c7cfs|r ";
Zerotorescue@62 454 local copperText = "%s%d|cffeda55fc|r";
Zerotorescue@62 455
Zerotorescue@62 456 function addon:ReadableMoney(copper, clean)
Zerotorescue@62 457 local text = "";
Zerotorescue@62 458
Zerotorescue@62 459 local gold = floor( copper / COPPER_PER_GOLD );
Zerotorescue@62 460 if gold > 0 then
Zerotorescue@62 461 text = goldText:format(text, gold);
Zerotorescue@62 462 end
Zerotorescue@62 463
Zerotorescue@62 464 if not clean or (not gold or gold < 10) then
Zerotorescue@62 465 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
Zerotorescue@62 466 if silver > 0 then
Zerotorescue@62 467 text = silverText:format(text, silver);
Zerotorescue@62 468 end
Zerotorescue@62 469
Zerotorescue@62 470 if not clean or (not gold or gold < 1) then
Zerotorescue@62 471 local copper = floor( copper % COPPER_PER_SILVER );
Zerotorescue@62 472 if copper > 0 or text == "" then
Zerotorescue@62 473 text = copperText:format(text, copper);
Zerotorescue@62 474 end
Zerotorescue@62 475 end
Zerotorescue@62 476 end
Zerotorescue@62 477
Zerotorescue@62 478
Zerotorescue@62 479 return string.trim(text);
Zerotorescue@62 480 end
Zerotorescue@62 481
Zerotorescue@62 482 function addon:ReadableMoneyToCopper(value)
Zerotorescue@62 483 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 484 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 485 -- Thus we look for both
Zerotorescue@62 486 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@62 487 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@62 488 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@62 489
Zerotorescue@62 490 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
Zerotorescue@62 491 end
Zerotorescue@62 492
Zerotorescue@62 493 function addon:ValidateReadableMoney(info, value)
Zerotorescue@62 494 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 495 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 496 -- Thus we look for both
Zerotorescue@62 497 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@62 498 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@62 499 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@62 500
Zerotorescue@62 501 if not gold and not silver and not copper then
Zerotorescue@62 502 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
Zerotorescue@62 503 else
Zerotorescue@62 504 return true;
Zerotorescue@62 505 end
Zerotorescue@62 506 end
Zerotorescue@62 507
Zerotorescue@0 508
Zerotorescue@0 509
Zerotorescue@13 510 -- Public
Zerotorescue@13 511
Zerotorescue@36 512 function IMRegisterPricingAddon(name, get, enabled, onSelect)
Zerotorescue@13 513 addon.supportedAddons.auctionPricing[name] = {
Zerotorescue@13 514 GetValue = get,
Zerotorescue@13 515 IsEnabled = enabled,
Zerotorescue@36 516 OnSelect = onSelect,
Zerotorescue@13 517 };
Zerotorescue@13 518 end
Zerotorescue@13 519
Zerotorescue@50 520 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect)
Zerotorescue@13 521 addon.supportedAddons.itemCount[name] = {
Zerotorescue@17 522 GetTotalCount = getTotal,
Zerotorescue@17 523 GetCharacterCount = getCharacter,
Zerotorescue@13 524 IsEnabled = enabled,
Zerotorescue@50 525 OnSelect = onSelect,
Zerotorescue@13 526 };
Zerotorescue@13 527 end
Zerotorescue@13 528
Zerotorescue@50 529 function IMRegisterCraftingAddon(name, queue, enabled, onSelect)
Zerotorescue@13 530 addon.supportedAddons.crafting[name] = {
Zerotorescue@13 531 Queue = queue,
Zerotorescue@13 532 IsEnabled = enabled,
Zerotorescue@50 533 OnSelect = onSelect,
Zerotorescue@13 534 };
Zerotorescue@13 535 end
Zerotorescue@13 536
Zerotorescue@62 537 -- We need a global command handler for our chat-links
Zerotorescue@62 538 function InventoriumCommandHandler(msg)
Zerotorescue@62 539 addon:CommandHandler(msg);
Zerotorescue@62 540 end
Zerotorescue@62 541
Zerotorescue@13 542
Zerotorescue@13 543
Zerotorescue@13 544 -- Debug
Zerotorescue@0 545
Zerotorescue@0 546 function addon:Debug(t)
Zerotorescue@0 547 if not self.debugChannel and self.debugChannel ~= false then
Zerotorescue@0 548 -- 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 549 self.debugChannel = false;
Zerotorescue@0 550
Zerotorescue@0 551 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 552 local name = GetChatWindowInfo(i);
Zerotorescue@0 553
Zerotorescue@0 554 if name:upper() == "DEBUG" then
Zerotorescue@0 555 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 556 end
Zerotorescue@0 557 end
Zerotorescue@0 558 end
Zerotorescue@0 559
Zerotorescue@0 560 if self.debugChannel then
Zerotorescue@0 561 self.debugChannel:AddMessage(t);
Zerotorescue@0 562 end
Zerotorescue@0 563 end