Mercurial > wow > inventory
comparison Config.lua @ 69:6329ee822172
Group functions moved to the config module, this should fix an issue with the item list not updating when adding items.
| author | Zerotorescue | 
|---|---|
| date | Thu, 23 Dec 2010 14:02:04 +0100 | 
| parents | 710f03653aaf | 
| children | 2127ab01ed4a | 
   comparison
  equal
  deleted
  inserted
  replaced
| 68:710f03653aaf | 69:6329ee822172 | 
|---|---|
| 99 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. | 99 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. | 
| 100 | 100 | 
| 101 if itemId then | 101 if itemId then | 
| 102 local groupName = groupIdToName[groupId]; | 102 local groupName = groupIdToName[groupId]; | 
| 103 | 103 | 
| 104 if not addon:AddItemToGroup(groupName, itemId) then | 104 if not mod:AddItemToGroup(groupName, itemId) then | 
| 105 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r"); | 105 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r"); | 
| 106 end | 106 end | 
| 107 end | 107 end | 
| 108 end, | 108 end, | 
| 109 width = "double", | 109 width = "double", | 
| 124 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. | 124 -- This is NOT a real "set", we pass the widget reference to this function which contains similar, but not the same, info. | 
| 125 | 125 | 
| 126 if itemId then | 126 if itemId then | 
| 127 local groupName = groupIdToName[groupId]; | 127 local groupName = groupIdToName[groupId]; | 
| 128 | 128 | 
| 129 addon:RemoveItemFromGroup(groupName, itemId); | 129 mod:RemoveItemFromGroup(groupName, itemId); | 
| 130 | 130 | 
| 131 -- Now rebuild the list | 131 -- Now rebuild the list | 
| 132 AceConfigRegistry:NotifyChange("InventoriumOptions"); | 132 AceConfigRegistry:NotifyChange("InventoriumOptions"); | 
| 133 end | 133 end | 
| 134 end, | 134 end, | 
| 851 | 851 | 
| 852 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); | 852 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); | 
| 853 | 853 | 
| 854 if not itemId then | 854 if not itemId then | 
| 855 return "This is not a valid item link."; | 855 return "This is not a valid item link."; | 
| 856 elseif addon:InGroup(itemId) then | 856 elseif mod:InGroup(itemId) then | 
| 857 return ("This item is already in the group \"%s\"."):format(addon:InGroup(itemId)); | 857 return ("This item is already in the group \"%s\"."):format(mod:InGroup(itemId)); | 
| 858 end | 858 end | 
| 859 | 859 | 
| 860 return true; | 860 return true; | 
| 861 end, | 861 end, | 
| 862 set = function(info, value) | 862 set = function(info, value) | 
| 863 if value and value ~= "" then | 863 if value and value ~= "" then | 
| 864 local groupName = groupIdToName[info[2]]; | 864 local groupName = groupIdToName[info[2]]; | 
| 865 | 865 | 
| 866 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); | 866 local itemId = addon:GetItemId(string.trim(value or "")) or tonumber(string.trim(value or "")); | 
| 867 | 867 | 
| 868 addon:AddItemToGroup(groupName, itemId); | 868 mod:AddItemToGroup(groupName, itemId); | 
| 869 | 869 | 
| 870 print(("Added %s"):format(select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId))); | 870 print(("Added %s"):format(select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId))); | 
| 871 end | 871 end | 
| 872 end, | 872 end, | 
| 873 get = false, | 873 get = false, | 
| 885 for _, value in pairs(allItemIds) do | 885 for _, value in pairs(allItemIds) do | 
| 886 local itemId = tonumber(value); | 886 local itemId = tonumber(value); | 
| 887 | 887 | 
| 888 if not itemId then | 888 if not itemId then | 
| 889 print(("\"%s\" is not a number."):format(value)); | 889 print(("\"%s\" is not a number."):format(value)); | 
| 890 elseif addon:InGroup(itemId) then | 890 elseif mod:InGroup(itemId) then | 
| 891 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, addon:InGroup(itemId))); | 891 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))); | 
| 892 else | 892 else | 
| 893 addon:AddItemToGroup(groupName, itemId); | 893 mod:AddItemToGroup(groupName, itemId); | 
| 894 end | 894 end | 
| 895 end | 895 end | 
| 896 end, | 896 end, | 
| 897 get = false, | 897 get = false, | 
| 898 }, | 898 }, | 
| 924 if version > 0 then | 924 if version > 0 then | 
| 925 itemId = itemId and tonumber(itemId); | 925 itemId = itemId and tonumber(itemId); | 
| 926 | 926 | 
| 927 if not itemId then | 927 if not itemId then | 
| 928 print(("\"|cfffed000%s|r\" is not a number."):format(value)); | 928 print(("\"|cfffed000%s|r\" is not a number."):format(value)); | 
| 929 elseif addon:InGroup(itemId) then | 929 elseif mod:InGroup(itemId) then | 
| 930 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, addon:InGroup(itemId))); | 930 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))); | 
| 931 else | 931 else | 
| 932 addon:AddItemToGroup(groupName, itemId); | 932 mod:AddItemToGroup(groupName, itemId); | 
| 933 print(("|cff00ff00Added|r |cfffed000%s|r (#%d) to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, groupName)); | 933 print(("|cff00ff00Added|r |cfffed000%s|r (#%d) to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, groupName)); | 
| 934 end | 934 end | 
| 935 end | 935 end | 
| 936 end | 936 end | 
| 937 end, | 937 end, | 
| 967 for itemId, test in pairs(ref) do | 967 for itemId, test in pairs(ref) do | 
| 968 if test then | 968 if test then | 
| 969 local itemName = GetItemInfo(itemId); | 969 local itemName = GetItemInfo(itemId); | 
| 970 | 970 | 
| 971 if itemName:lower():find(value) then | 971 if itemName:lower():find(value) then | 
| 972 if not addon:AddItemToGroup(groupName, itemId) then | 972 if not mod:AddItemToGroup(groupName, itemId) then | 
| 973 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r"); | 973 print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r"); | 
| 974 end | 974 end | 
| 975 end | 975 end | 
| 976 end | 976 end | 
| 977 end | 977 end | 
| 1059 for itemId, test in pairs(ref) do | 1059 for itemId, test in pairs(ref) do | 
| 1060 if test then | 1060 if test then | 
| 1061 local itemName = GetItemInfo(itemId); | 1061 local itemName = GetItemInfo(itemId); | 
| 1062 | 1062 | 
| 1063 if itemName:lower():find(value) then | 1063 if itemName:lower():find(value) then | 
| 1064 addon:RemoveItemFromGroup(groupName, itemId); | 1064 mod:RemoveItemFromGroup(groupName, itemId); | 
| 1065 print(("|cffff0000Removed|r %s (#%d)."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId)); | 1065 print(("|cffff0000Removed|r %s (#%d)."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId)); | 
| 1066 end | 1066 end | 
| 1067 end | 1067 end | 
| 1068 end | 1068 end | 
| 1069 | 1069 | 
| 1853 local itemId = tonumber(value); | 1853 local itemId = tonumber(value); | 
| 1854 | 1854 | 
| 1855 if not itemId then | 1855 if not itemId then | 
| 1856 print(("\"%s\" is not a number."):format(value)); | 1856 print(("\"%s\" is not a number."):format(value)); | 
| 1857 temp.items[value] = nil; | 1857 temp.items[value] = nil; | 
| 1858 elseif addon:InGroup(itemId) then | 1858 elseif mod:InGroup(itemId) then | 
| 1859 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, addon:InGroup(itemId))); | 1859 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))); | 
| 1860 temp.items[value] = nil; | 1860 temp.items[value] = nil; | 
| 1861 else | 1861 else | 
| 1862 -- Ensure the keys are numeric | 1862 -- Ensure the keys are numeric | 
| 1863 temp.items[value] = nil; | 1863 temp.items[value] = nil; | 
| 1864 temp.items[itemId] = true; | 1864 temp.items[itemId] = true; | 
| 1906 end | 1906 end | 
| 1907 | 1907 | 
| 1908 count = ( count + 1 ); | 1908 count = ( count + 1 ); | 
| 1909 end | 1909 end | 
| 1910 end | 1910 end | 
| 1911 end | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 -- Group functions | |
| 1918 | |
| 1919 function mod:InGroup(itemId) | |
| 1920 -- Go through all groups to see if this item is already somewhere | |
| 1921 for groupName, values in pairs(addon.db.profile.groups) do | |
| 1922 if values.items and values.items[itemId] then | |
| 1923 return groupName; | |
| 1924 end | |
| 1925 end | |
| 1926 | |
| 1927 return; | |
| 1928 end | |
| 1929 | |
| 1930 function mod:AddItemToGroup(groupName, itemId) | |
| 1931 if self:InGroup(itemId) then | |
| 1932 return false; | |
| 1933 end | |
| 1934 | |
| 1935 if not addon.db.profile.groups[groupName].items then | |
| 1936 addon.db.profile.groups[groupName].items = {}; | |
| 1937 end | |
| 1938 | |
| 1939 -- Set this item | |
| 1940 addon.db.profile.groups[groupName].items[itemId] = true; | |
| 1941 | |
| 1942 if AceConfigRegistry then | |
| 1943 -- Now rebuild the list | |
| 1944 AceConfigRegistry:NotifyChange("InventoriumOptions"); | |
| 1945 end | |
| 1946 | |
| 1947 return true; | |
| 1948 end | |
| 1949 | |
| 1950 function mod:RemoveItemFromGroup(groupName, itemId) | |
| 1951 if self:InGroup(itemId) ~= groupName then | |
| 1952 return false; | |
| 1953 end | |
| 1954 | |
| 1955 -- Unset this item | |
| 1956 addon.db.profile.groups[groupName].items[itemId] = nil; | |
| 1957 | |
| 1958 return true; | |
| 1911 end | 1959 end | 
| 1912 | 1960 | 
| 1913 | 1961 | 
| 1914 | 1962 | 
| 1915 | 1963 | 
| 1939 -- Go through all items in this premade group | 1987 -- Go through all items in this premade group | 
| 1940 | 1988 | 
| 1941 if version > values.premadeGroups[premadeGroupName] then | 1989 if version > values.premadeGroups[premadeGroupName] then | 
| 1942 -- This item was added in a more recent version than this group: Add item | 1990 -- This item was added in a more recent version than this group: Add item | 
| 1943 | 1991 | 
| 1944 if addon:InGroup(itemId) then | 1992 if mod:InGroup(itemId) then | 
| 1945 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, addon:InGroup(itemId))); | 1993 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))); | 
| 1946 elseif addon:AddItemToGroup(groupName, itemId) then | 1994 elseif mod:AddItemToGroup(groupName, itemId) then | 
| 1947 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, addon:InGroup(itemId))); | 1995 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))); | 
| 1948 end | 1996 end | 
| 1949 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then | 1997 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then | 
| 1950 if addon:InGroup(itemId) == groupName then | 1998 if mod:InGroup(itemId) == groupName then | 
| 1951 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, addon:InGroup(itemId), premadeGroupName)); | 1999 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)); | 
| 1952 addon:RemoveItemFromGroup(groupName, itemId); | 2000 mod:RemoveItemFromGroup(groupName, itemId); | 
| 1953 else | 2001 else | 
| 1954 print(("Skipping the removal of %s (#%d) as it isn't in this group."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, addon:InGroup(itemId))); | 2002 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))); | 
| 1955 end | 2003 end | 
| 1956 end | 2004 end | 
| 1957 end | 2005 end | 
| 1958 | 2006 | 
| 1959 -- Remember the new version | 2007 -- Remember the new version | 
| 1966 -- Go through all items in this premade group | 2014 -- Go through all items in this premade group | 
| 1967 | 2015 | 
| 1968 if version > values.premadeGroups[premadeGroupName] then | 2016 if version > values.premadeGroups[premadeGroupName] then | 
| 1969 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it | 2017 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it | 
| 1970 | 2018 | 
| 1971 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, addon:InGroup(itemId))); | 2019 print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, mod:InGroup(itemId))); | 
| 1972 end | 2020 end | 
| 1973 end | 2021 end | 
| 1974 | 2022 | 
| 1975 -- Remember the new version | 2023 -- Remember the new version | 
| 1976 values.premadeGroups[premadeGroupName] = groupInfo.version; | 2024 values.premadeGroups[premadeGroupName] = groupInfo.version; | 
