Mercurial > wow > inventory
diff Config.lua @ 76:958aba5f3297
Moved the group functions to the item data class.
Added a new subgroup under the general config group called ?extra? which will provide features such as database character removal and perhaps guild selecting.
Added a new custom .Print function to the addon object which takes two parameters: (string)text, (Color)color. The latter can be retrieved from the addon.Colors var (e.g. addon.Colors.Red).
The ItemId parameter of the ItemData class constructor is now optional.
author | Zerotorescue |
---|---|
date | Sat, 25 Dec 2010 22:07:07 +0100 |
parents | 2127ab01ed4a |
children | f885805da5d6 |
line wrap: on
line diff
--- a/Config.lua Sat Dec 25 15:33:40 2010 +0100 +++ b/Config.lua Sat Dec 25 22:07:07 2010 +0100 @@ -4,6 +4,8 @@ local options, groupIdToName, groupIsVirtual, temp, count, includeTradeSkillItems, currentGroupType = {}, {}, {}, {}, 0, 500, "Normal"; local AceConfigDialog, AceConfigRegistry, AceSerializer; +local unknownItemName = "Unknown (#%d)"; + -- Private functions and tables local function SetOption(info, value, multiSelectEnabled) @@ -98,12 +100,17 @@ set = function(groupId, itemData) -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. - if itemData and itemData.id then - local groupName = groupIdToName[groupId]; - - if not mod:AddItemToGroup(groupName, itemData.id) then - print("|cffff0000Couldn't add the item with itemId (" .. itemData.id .. ") because it is already in a group.|r"); - end + if itemData then + local groupName = groupIdToName[groupId]; + + if not itemData:AddToGroup(groupName) then + print("|cffff0000Couldn't add the item with itemId (" .. itemData.id .. ") because it is already in a group.|r"); + end + + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end end, width = "double", @@ -123,13 +130,15 @@ set = function(groupId, itemData) -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. - if itemData and itemData.id then + if itemData then local groupName = groupIdToName[groupId]; - mod:RemoveItemFromGroup(groupName, itemData.id); + itemData:RemoveFromGroup(groupName); - -- Now rebuild the list - AceConfigRegistry:NotifyChange("InventoriumOptions"); + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end end, width = "double", @@ -849,12 +858,14 @@ local groupName = groupIdToName[info[2]]; - local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); + local itemId = (addon:GetItemId(string.trim(value)) or tonumber(string.trim(value))); + + local itemData = addon.ItemData:New(itemId); if not itemId then - return "This is not a valid item link."; - elseif mod:InGroup(itemId) then - return ("This item is already in the group \"%s\"."):format(mod:InGroup(itemId)); + return "This is not a valid item link or id."; + elseif itemData:InGroup() then + return ("This item is already in the group |cfffed000%s|r."):format(itemData:InGroup()); end return true; @@ -863,11 +874,20 @@ if value and value ~= "" then local groupName = groupIdToName[info[2]]; - local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); + local itemId = (addon:GetItemId(string.trim(value)) or tonumber(string.trim(value))); - mod:AddItemToGroup(groupName, itemId); - - print(("Added %s"):format(select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId))); + local itemData = addon.ItemData:New(itemId); + + if itemData:AddToGroup(groupName) then + addon.Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green); + + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end + else + addon.Print(("%s is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red); + end end end, get = false, @@ -885,14 +905,23 @@ for _, value in pairs(allItemIds) do local itemId = tonumber(value); - if not itemId then - print(("\"%s\" is not a number."):format(value)); - elseif mod:InGroup(itemId) then - print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); + if itemId then + local itemData = addon.ItemData:New(itemId); + + if itemData:InGroup() then + addon.Print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(itemData.link or "Unknown", itemId, itemData:InGroup()), addon.Colors.Red); + elseif itemData:AddToGroup(groupName) then + addon.Print(("Added %s to the group |cfffed000%s|r."):format(itemData.link or unknownItemName:format(itemId), groupName), addon.Colors.Green); + end else - mod:AddItemToGroup(groupName, itemId); + addon.Print(("\"%s\" is not a number."):format(value), addon.Colors.Red); end end + + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end, get = false, }, @@ -922,18 +951,25 @@ for itemId, version in pairs(addon.defaultGroups[value].items) do if version > 0 then + -- Sanity check itemId = itemId and tonumber(itemId); + local itemData = addon.ItemData:New(itemId); + if not itemId then - print(("\"|cfffed000%s|r\" is not a number."):format(value)); - elseif mod:InGroup(itemId) then - print(("|cffff0000Skipping|r |cfffed000%s|r (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); - else - mod:AddItemToGroup(groupName, itemId); - print(("|cff00ff00Added|r |cfffed000%s|r (#%d) to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, groupName)); + addon.Print(("\"|cfffed000%s|r\" is not a number."):format(value), addon.Colors.Red); + elseif itemData:InGroup() then + addon.Print(("Skipping |cfffed000%s|r as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red); + elseif itemData:AddToGroup(groupName) then + addon.Print(("Added %s to the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), groupName ), addon.Colors.Green); end end end + + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end, get = false, }, @@ -966,15 +1002,22 @@ for itemId, test in pairs(ref) do if test then - local itemName = GetItemInfo(itemId); + local itemData = addon.ItemData:New(itemId); - if itemName:lower():find(value) then - if not mod:AddItemToGroup(groupName, itemId) then - print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r"); + if itemData.name:lower():find(value) then + if itemData:AddToGroup(groupName) then + addon.Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green); + else + addon.Print(("Couldn't add %s because it is already in a group."):format(itemData.link or unknownItemName:format(itemId)), addon.Colors.Red); end end end end + + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end, get = false, }, @@ -1058,17 +1101,20 @@ for itemId, test in pairs(ref) do if test then - local itemName = GetItemInfo(itemId); + local itemData = addon.ItemData:New(itemId); - if itemName:lower():find(value) then - mod:RemoveItemFromGroup(groupName, itemId); - print(("|cffff0000Removed|r %s (#%d)."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId)); + if itemData.name:lower():find(value) then + itemData:RemoveFromGroup(groupName); + + addon.Print(("Removed %s from the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Red); end end end - -- Now rebuild the list - AceConfigRegistry:NotifyChange("InventoriumOptions"); + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end end, get = false, }, @@ -1081,6 +1127,7 @@ local groupName = groupIdToName[info[2]]; local temp = {}; + temp[""] = ""; if addon.db.profile.groups[groupName].premadeGroups then for name, version in pairs(addon.db.profile.groups[groupName].premadeGroups) do temp[name] = name; @@ -1090,12 +1137,14 @@ return temp; end, set = function(info, value) - -- Remove premade group from this group - local groupName = groupIdToName[info[2]]; - - addon.db.profile.groups[groupName].premadeGroups[value] = nil; - - print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value)); + if value and value ~= "" then + -- Remove premade group from this group + local groupName = groupIdToName[info[2]]; + + addon.db.profile.groups[groupName].premadeGroups[value] = nil; + + print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value)); + end end, get = false, disabled = function(info) @@ -1621,6 +1670,55 @@ }, }, }, + extra = { + order = 40, + type = "group", + inline = true, + name = "Extra", + args = { + description = { + order = 0, + type = "description", + name = "Additional optional settings.", + }, + header = { + order = 5, + type = "header", + name = "", + }, + removeCharacter = { + order = 40, + type = "select", + name = "Forget character", + desc = "Select a character to remove all traces of it from Inventorium's memory.\n\nYour current character can not be removed, you must login to a different character to do so.", + values = function() + local temp = {}; + + temp[""] = ""; + + local playerName = UnitName("player"); + for charName in pairs(addon.db.factionrealm.characters) do + if playerName ~= charName then + temp[charName] = charName; + end + end + + return temp; + end, + set = function(i, value) + if value and value ~= "" then + addon.db.factionrealm.characters[value] = nil; + addon.db.profile.defaults.trackAtCharacters[value] = nil; + for name, values in pairs(addon.db.profile.groups) do + if values.trackAtCharacters then + values.trackAtCharacters[name] = nil; + end + end + end + end, + }, + }, + }, }, }; end @@ -1852,11 +1950,13 @@ for value, _ in pairs(temp.items) do local itemId = tonumber(value); + local itemData = addon.ItemData:New(itemId); + if not itemId then print(("\"%s\" is not a number."):format(value)); temp.items[value] = nil; - elseif mod:InGroup(itemId) then - print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); + elseif itemData:InGroup() then + print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); temp.items[value] = nil; else -- Ensure the keys are numeric @@ -1914,54 +2014,6 @@ --- Group functions - -function mod:InGroup(itemId) - -- Go through all groups to see if this item is already somewhere - for groupName, values in pairs(addon.db.profile.groups) do - if values.items and values.items[itemId] then - return groupName; - end - end - - return; -end - -function mod:AddItemToGroup(groupName, itemId) - if self:InGroup(itemId) then - return false; - end - - if not addon.db.profile.groups[groupName].items then - addon.db.profile.groups[groupName].items = {}; - end - - -- Set this item - addon.db.profile.groups[groupName].items[itemId] = true; - - if AceConfigRegistry then - -- Now rebuild the list - AceConfigRegistry:NotifyChange("InventoriumOptions"); - end - - return true; -end - -function mod:RemoveItemFromGroup(groupName, itemId) - if self:InGroup(itemId) ~= groupName then - return false; - end - - -- Unset this item - addon.db.profile.groups[groupName].items[itemId] = nil; - - return true; -end - - - - - -- Verify premade groups @@ -1986,24 +2038,32 @@ for itemId, version in pairs(groupInfo.items) do -- Go through all items in this premade group + local itemData = addon.ItemData:New(itemId); + if version > values.premadeGroups[premadeGroupName] then -- This item was added in a more recent version than this group: Add item - if mod:InGroup(itemId) then - print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); - elseif mod:AddItemToGroup(groupName, itemId) then - 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, mod:InGroup(itemId))); + if itemData:InGroup() then + print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); + elseif itemData:AddToGroup(groupName) then + addon.Print(("Added %s found in the premade group |cfffed000%s|r to the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), premadeGroupName, itemData:InGroup() ), addon.Colors.Green); end elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then - if mod:InGroup(itemId) == groupName then - 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, mod:InGroup(itemId), premadeGroupName)); - mod:RemoveItemFromGroup(groupName, itemId); + if itemData:InGroup() == groupName then + itemData:RemoveFromGroup(groupName); + + addon.Print(("Removed %s from the group |cfffed000%s|r as it was removed from the premade group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup(), premadeGroupName ), addon.Colors.Red); else - print(("Skipping the removal of %s (#%d) as it isn't in this group."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); + print(("Skipping the removal of %s as it isn't in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); end end end + if AceConfigRegistry then + -- Now rebuild the list + AceConfigRegistry:NotifyChange("InventoriumOptions"); + end + -- Remember the new version values.premadeGroups[premadeGroupName] = groupInfo.version; else @@ -2013,10 +2073,12 @@ for itemId, version in pairs(groupInfo.items) do -- Go through all items in this premade group + local itemData = addon.ItemData:New(itemId); + if version > values.premadeGroups[premadeGroupName] then -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it - print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); + print(("Skipping %s found in the premade group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); end end