Mercurial > wow > inventory
comparison Core.lua @ 46:87d68ccf0a8f
The premade group update processor should now properly add items when they were added to a premade group.
Items can now be indicated as removed in premade groups by setting the version number to a negative value of the latest version.
Removed Enchanted Spellthread from the Cataclysm enchants premade group.
| author | Zerotorescue |
|---|---|
| date | Sun, 12 Dec 2010 17:18:19 +0100 |
| parents | abc824800387 |
| children | 9607b3251655 |
comparison
equal
deleted
inserted
replaced
| 45:0d1f8282a43e | 46:87d68ccf0a8f |
|---|---|
| 152 end | 152 end |
| 153 | 153 |
| 154 return; | 154 return; |
| 155 end | 155 end |
| 156 | 156 |
| 157 local function AddToGroup(groupName, itemId) | |
| 158 if InGroup(itemId) then | |
| 159 return false; | |
| 160 end | |
| 161 | |
| 162 if not addon.db.global.groups[groupName].items then | |
| 163 addon.db.global.groups[groupName].items = {}; | |
| 164 end | |
| 165 | |
| 166 -- Set this item | |
| 167 addon.db.global.groups[groupName].items[itemId] = true; | |
| 168 | |
| 169 if AceConfigRegistry then | |
| 170 -- Now rebuild the list | |
| 171 AceConfigRegistry:NotifyChange("InventoriumOptions"); | |
| 172 end | |
| 173 | |
| 174 return true; | |
| 175 end | |
| 176 | |
| 177 local function RemoveFromGroup(groupName, itemId) | |
| 178 if InGroup(itemId) ~= groupName then | |
| 179 return false; | |
| 180 end | |
| 181 | |
| 182 -- Unset this item | |
| 183 addon.db.global.groups[groupName].items[itemId] = nil; | |
| 184 | |
| 185 return true; | |
| 186 end | |
| 187 | |
| 157 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept) | 188 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept) |
| 158 -- Compare the current premade groups with those used, notify about changes | 189 -- Compare the current premade groups with those used, notify about changes |
| 159 if addon.defaultGroups then | 190 if addon.defaultGroups then |
| 160 for key, groupInfo in pairs(addon.defaultGroups) do | 191 for premadeGroupName, groupInfo in pairs(addon.defaultGroups) do |
| 161 -- Go through all default groups | 192 -- Go through all default groups |
| 162 | 193 |
| 163 for groupName, values in pairs(addon.db.global.groups) do | 194 for groupName, values in pairs(addon.db.global.groups) do |
| 164 -- Go through all groups to find those with this premade group | 195 -- Go through all groups to find those with this premade group |
| 165 | 196 |
| 166 if values.premadeGroups and values.premadeGroups[key] and values.premadeGroups[key] < groupInfo.version then | 197 if values.premadeGroups and values.premadeGroups[premadeGroupName] and values.premadeGroups[premadeGroupName] < groupInfo.version then |
| 167 -- Outdated group | 198 -- Outdated group |
| 168 | 199 |
| 169 if updateGroupName and updateKey then | 200 if updateGroupName and updateKey then |
| 170 -- This function was called after pressing yes or no in a confirm box | 201 -- This function was called after pressing yes or no in a confirm box |
| 171 | 202 |
| 173 -- Yes was clicked | 204 -- Yes was clicked |
| 174 | 205 |
| 175 for itemId, version in pairs(groupInfo.items) do | 206 for itemId, version in pairs(groupInfo.items) do |
| 176 -- Go through all items in this premade group | 207 -- Go through all items in this premade group |
| 177 | 208 |
| 178 if version > values.premadeGroups[key] then | 209 if version > values.premadeGroups[premadeGroupName] then |
| 179 -- This item was added in a more recent version than this group: Add item | 210 -- This item was added in a more recent version than this group: Add item |
| 180 | 211 |
| 181 if InGroup(itemId) then | 212 if InGroup(itemId) then |
| 182 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); | 213 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); |
| 183 elseif AddToGroup(groupName, itemId) then | 214 elseif AddToGroup(groupName, itemId) then |
| 184 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))); | 215 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, InGroup(itemId))); |
| 216 end | |
| 217 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then | |
| 218 if InGroup(itemId) == groupName then | |
| 219 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, InGroup(itemId), premadeGroupName)); | |
| 220 RemoveFromGroup(groupName, itemId); | |
| 221 else | |
| 222 print(("Skipping the removal of %s (#%d) as it isn't in this group."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); | |
| 185 end | 223 end |
| 186 end | 224 end |
| 187 end | 225 end |
| 188 | 226 |
| 189 -- Remember the new version | 227 -- Remember the new version |
| 190 values.premadeGroups[key] = groupInfo.version; | 228 values.premadeGroups[premadeGroupName] = groupInfo.version; |
| 191 else | 229 else |
| 192 -- No was clicked | 230 -- No was clicked |
| 193 | 231 |
| 194 -- Let user know what was not added | 232 -- Let user know what was not added |
| 195 for itemId, version in pairs(groupInfo.items) do | 233 for itemId, version in pairs(groupInfo.items) do |
| 196 -- Go through all items in this premade group | 234 -- Go through all items in this premade group |
| 197 | 235 |
| 198 if version > values.premadeGroups[key] then | 236 if version > values.premadeGroups[premadeGroupName] then |
| 199 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it | 237 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it |
| 200 | 238 |
| 201 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); | 239 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); |
| 202 end | 240 end |
| 203 end | 241 end |
| 204 | 242 |
| 205 -- Remember the new version | 243 -- Remember the new version |
| 206 values.premadeGroups[key] = groupInfo.version; | 244 values.premadeGroups[premadeGroupName] = groupInfo.version; |
| 207 end | 245 end |
| 208 else | 246 else |
| 209 StaticPopupDialogs["InventoriumConfirmUpdatePremadeGroup"] = { | 247 StaticPopupDialogs["InventoriumConfirmUpdatePremadeGroup"] = { |
| 210 text = "The premade group |cfffed000%s|r used in the group |cfffed000%s|r has been changed. Do you wish to copy these changes?", | 248 text = "The premade group |cfffed000%s|r used in the group |cfffed000%s|r has been changed. Do you wish to copy these changes?", |
| 211 button1 = YES, | 249 button1 = YES, |
| 212 button2 = NO, | 250 button2 = NO, |
| 213 OnAccept = function(self) | 251 OnAccept = function(self) |
| 214 addon:PremadeGroupsCheck(groupName, key, true); | 252 addon:PremadeGroupsCheck(groupName, premadeGroupName, true); |
| 215 end, | 253 end, |
| 216 OnCancel = function(self, _, reason) | 254 OnCancel = function(self, _, reason) |
| 217 if reason == "clicked" then | 255 if reason == "clicked" then |
| 218 addon:PremadeGroupsCheck(groupName, key, false); | 256 addon:PremadeGroupsCheck(groupName, premadeGroupName, false); |
| 219 end | 257 end |
| 220 end, | 258 end, |
| 221 timeout = 0, | 259 timeout = 0, |
| 222 whileDead = 1, | 260 whileDead = 1, |
| 223 hideOnEscape = 1, | 261 hideOnEscape = 1, |
| 224 }; | 262 }; |
| 225 StaticPopup_Show("InventoriumConfirmUpdatePremadeGroup", key, groupName); | 263 StaticPopup_Show("InventoriumConfirmUpdatePremadeGroup", premadeGroupName, groupName); |
| 226 | 264 |
| 227 return; | 265 return; |
| 228 end | 266 end |
| 229 end | 267 end |
| 230 end | 268 end |
| 967 end | 1005 end |
| 968 | 1006 |
| 969 return true; | 1007 return true; |
| 970 end | 1008 end |
| 971 | 1009 |
| 972 local function AddToGroup(groupName, itemId) | |
| 973 if InGroup(itemId) then | |
| 974 return false; | |
| 975 end | |
| 976 | |
| 977 if not addon.db.global.groups[groupName].items then | |
| 978 addon.db.global.groups[groupName].items = {}; | |
| 979 end | |
| 980 | |
| 981 -- Set this item | |
| 982 addon.db.global.groups[groupName].items[itemId] = true; | |
| 983 | |
| 984 -- Now rebuild the list | |
| 985 AceConfigRegistry:NotifyChange("InventoriumOptions"); | |
| 986 | |
| 987 return true; | |
| 988 end | |
| 989 | |
| 990 local tblAddItemTemplate = { | 1010 local tblAddItemTemplate = { |
| 991 order = 0, | 1011 order = 0, |
| 992 type = "input", | 1012 type = "input", |
| 993 name = function(info) | 1013 name = function(info) |
| 994 local itemName, _, itemRarity = GetItemInfo(info[#info]); | 1014 local itemName, _, itemRarity = GetItemInfo(info[#info]); |
| 1026 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. | 1046 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. |
| 1027 | 1047 |
| 1028 if itemId then | 1048 if itemId then |
| 1029 local groupName = groupIdToName[groupId]; | 1049 local groupName = groupIdToName[groupId]; |
| 1030 | 1050 |
| 1031 -- Unset this item | 1051 RemoveFromGroup(groupName, itemId); |
| 1032 addon.db.global.groups[groupName].items[itemId] = nil; | 1052 |
| 1033 | 1053 -- Now rebuild the list |
| 1034 -- Now rebuild the list | 1054 AceConfigRegistry:NotifyChange("InventoriumOptions"); |
| 1035 AceConfigRegistry:NotifyChange("InventoriumOptions"); | |
| 1036 end | 1055 end |
| 1037 end, | 1056 end, |
| 1038 width = "double", | 1057 width = "double", |
| 1039 dialogControl = "ConfigItemLinkButton", | 1058 dialogControl = "ConfigItemLinkButton", |
| 1040 }; | 1059 }; |
| 1768 if not addon.db.global.groups[groupName].premadeGroups then | 1787 if not addon.db.global.groups[groupName].premadeGroups then |
| 1769 addon.db.global.groups[groupName].premadeGroups = {}; | 1788 addon.db.global.groups[groupName].premadeGroups = {}; |
| 1770 end | 1789 end |
| 1771 addon.db.global.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version; | 1790 addon.db.global.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version; |
| 1772 | 1791 |
| 1773 for itemId, _ in pairs(addon.defaultGroups[value].items) do | 1792 for itemId, version in pairs(addon.defaultGroups[value].items) do |
| 1774 itemId = itemId and tonumber(itemId); | 1793 if version > 0 then |
| 1775 | 1794 itemId = itemId and tonumber(itemId); |
| 1776 if not itemId then | 1795 |
| 1777 print(("\"|cfffed000%s|r\" is not a number."):format(value)); | 1796 if not itemId then |
| 1778 elseif InGroup(itemId) then | 1797 print(("\"|cfffed000%s|r\" is not a number."):format(value)); |
| 1779 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))); | 1798 elseif InGroup(itemId) then |
| 1780 else | 1799 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, InGroup(itemId))); |
| 1781 AddToGroup(groupName, itemId); | 1800 else |
| 1801 AddToGroup(groupName, itemId); | |
| 1802 print(("|cff00ff00Added|r |cfffed000%s|r (#%d) to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, groupName)); | |
| 1803 end | |
| 1782 end | 1804 end |
| 1783 end | 1805 end |
| 1784 end, | 1806 end, |
| 1785 get = false, | 1807 get = false, |
| 1786 }, | 1808 }, |
| 1906 for itemId, test in pairs(ref) do | 1928 for itemId, test in pairs(ref) do |
| 1907 if test then | 1929 if test then |
| 1908 local itemName = GetItemInfo(itemId); | 1930 local itemName = GetItemInfo(itemId); |
| 1909 | 1931 |
| 1910 if itemName:lower():find(value) then | 1932 if itemName:lower():find(value) then |
| 1911 -- Unset this item | 1933 RemoveFromGroup(groupName, itemId); |
| 1912 addon.db.global.groups[groupName].items[itemId] = nil; | 1934 print(("|cffff0000Removed|r %s (#%d)."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId)); |
| 1913 end | 1935 end |
| 1914 end | 1936 end |
| 1915 end | 1937 end |
| 1938 | |
| 1939 -- Now rebuild the list | |
| 1940 AceConfigRegistry:NotifyChange("InventoriumOptions"); | |
| 1916 end, | 1941 end, |
| 1917 get = false, | 1942 get = false, |
| 1918 }, | 1943 }, |
| 1919 premadeGroups = { | 1944 premadeGroups = { |
| 1920 order = 30, | 1945 order = 30, |
