comparison Modules/Config.lua @ 98:252292b703ce

All print(...) function calls are now handled by addon:Print(text, color). The cursor will be cleared of any items/spells before moving as well as when aborting.
author Zerotorescue
date Sun, 09 Jan 2011 17:49:33 +0100
parents a12d22ef3f39
children 6ae44d372360
comparison
equal deleted inserted replaced
97:ae268e5c7825 98:252292b703ce
102 102
103 if itemData then 103 if itemData then
104 local groupName = groupIdToName[groupId]; 104 local groupName = groupIdToName[groupId];
105 105
106 if not itemData:AddToGroup(groupName) then 106 if not itemData:AddToGroup(groupName) then
107 print("|cffff0000Couldn't add the item with itemId (" .. itemData.id .. ") because it is already in a group.|r"); 107 addon:Print("Couldn't add the item with itemId (" .. itemData.id .. ") because it is already in a group.", addon.Colors.Red);
108 end 108 end
109 109
110 if AceConfigRegistry then 110 if AceConfigRegistry then
111 -- Now rebuild the list 111 -- Now rebuild the list
112 AceConfigRegistry:NotifyChange("InventoriumOptions"); 112 AceConfigRegistry:NotifyChange("InventoriumOptions");
891 local itemId = (addon:GetItemId(string.trim(value)) or tonumber(string.trim(value))); 891 local itemId = (addon:GetItemId(string.trim(value)) or tonumber(string.trim(value)));
892 892
893 local itemData = addon.ItemData:New(itemId); 893 local itemData = addon.ItemData:New(itemId);
894 894
895 if itemData:AddToGroup(groupName) then 895 if itemData:AddToGroup(groupName) then
896 addon.Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green); 896 addon:Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green);
897 897
898 if AceConfigRegistry then 898 if AceConfigRegistry then
899 -- Now rebuild the list 899 -- Now rebuild the list
900 AceConfigRegistry:NotifyChange("InventoriumOptions"); 900 AceConfigRegistry:NotifyChange("InventoriumOptions");
901 end 901 end
902 else 902 else
903 addon.Print(("%s is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red); 903 addon:Print(("%s is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red);
904 end 904 end
905 end 905 end
906 end, 906 end,
907 get = false, 907 get = false,
908 }, 908 },
921 921
922 if itemId then 922 if itemId then
923 local itemData = addon.ItemData:New(itemId); 923 local itemData = addon.ItemData:New(itemId);
924 924
925 if itemData:InGroup() then 925 if itemData:InGroup() then
926 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); 926 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);
927 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);
927 elseif itemData:AddToGroup(groupName) then 928 elseif itemData:AddToGroup(groupName) then
928 addon.Print(("Added %s to the group |cfffed000%s|r."):format(itemData.link or unknownItemName:format(itemId), groupName), addon.Colors.Green); 929 addon:Print(("Added %s to the group |cfffed000%s|r."):format(itemData.link or unknownItemName:format(itemId), groupName), addon.Colors.Green);
929 end 930 end
930 else 931 else
931 addon.Print(("\"%s\" is not a number."):format(value), addon.Colors.Red); 932 addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red);
932 end 933 end
933 end 934 end
934 935
935 if AceConfigRegistry then 936 if AceConfigRegistry then
936 -- Now rebuild the list 937 -- Now rebuild the list
953 return temp; 954 return temp;
954 end, 955 end,
955 set = function(info, value) 956 set = function(info, value)
956 local groupName = groupIdToName[info[2]]; 957 local groupName = groupIdToName[info[2]];
957 958
958 print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value)); 959 addon:Print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value));
959 960
960 -- Remember we imported this group and it's version so if it is ever changed, people can be notified 961 -- Remember we imported this group and it's version so if it is ever changed, people can be notified
961 if not addon.db.profile.groups[groupName].premadeGroups then 962 if not addon.db.profile.groups[groupName].premadeGroups then
962 addon.db.profile.groups[groupName].premadeGroups = {}; 963 addon.db.profile.groups[groupName].premadeGroups = {};
963 end 964 end
969 itemId = itemId and tonumber(itemId); 970 itemId = itemId and tonumber(itemId);
970 971
971 local itemData = addon.ItemData:New(itemId); 972 local itemData = addon.ItemData:New(itemId);
972 973
973 if not itemId then 974 if not itemId then
974 addon.Print(("\"|cfffed000%s|r\" is not a number."):format(value), addon.Colors.Red); 975 addon:Print(("\"|cfffed000%s|r\" is not a number."):format(value), addon.Colors.Red);
975 elseif itemData:InGroup() then 976 elseif itemData:InGroup() then
976 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); 977 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);
977 elseif itemData:AddToGroup(groupName) then 978 elseif itemData:AddToGroup(groupName) then
978 addon.Print(("Added %s to the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), groupName ), addon.Colors.Green); 979 addon:Print(("Added %s to the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), groupName ), addon.Colors.Green);
979 end 980 end
980 end 981 end
981 end 982 end
982 983
983 if AceConfigRegistry then 984 if AceConfigRegistry then
1018 if test then 1019 if test then
1019 local itemData = addon.ItemData:New(itemId); 1020 local itemData = addon.ItemData:New(itemId);
1020 1021
1021 if itemData.name:lower():find(value) then 1022 if itemData.name:lower():find(value) then
1022 if itemData:AddToGroup(groupName) then 1023 if itemData:AddToGroup(groupName) then
1023 addon.Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green); 1024 addon:Print(("Added %s to the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Green);
1024 else 1025 else
1025 addon.Print(("Couldn't add %s because it is already in a group."):format(itemData.link or unknownItemName:format(itemId)), addon.Colors.Red); 1026 addon:Print(("Couldn't add %s because it is already in a group."):format(itemData.link or unknownItemName:format(itemId)), addon.Colors.Red);
1026 end 1027 end
1027 end 1028 end
1028 end 1029 end
1029 end 1030 end
1030 1031
1118 local itemData = addon.ItemData:New(itemId); 1119 local itemData = addon.ItemData:New(itemId);
1119 1120
1120 if itemData.name:lower():find(value) then 1121 if itemData.name:lower():find(value) then
1121 itemData:RemoveFromGroup(groupName); 1122 itemData:RemoveFromGroup(groupName);
1122 1123
1123 addon.Print(("Removed %s from the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Red); 1124 addon:Print(("Removed %s from the selected group."):format( (itemData.link or unknownItemName:format(itemId)) ), addon.Colors.Red);
1124 end 1125 end
1125 end 1126 end
1126 end 1127 end
1127 1128
1128 if AceConfigRegistry then 1129 if AceConfigRegistry then
1155 -- Remove premade group from this group 1156 -- Remove premade group from this group
1156 local groupName = groupIdToName[info[2]]; 1157 local groupName = groupIdToName[info[2]];
1157 1158
1158 addon.db.profile.groups[groupName].premadeGroups[value] = nil; 1159 addon.db.profile.groups[groupName].premadeGroups[value] = nil;
1159 1160
1160 print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value)); 1161 addon:Print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value));
1161 end 1162 end
1162 end, 1163 end,
1163 get = false, 1164 get = false,
1164 disabled = function(info) 1165 disabled = function(info)
1165 local groupName = groupIdToName[info[2]]; 1166 local groupName = groupIdToName[info[2]];
1957 end 1958 end
1958 1959
1959 local result, temp = AceSerializer:Deserialize(current); 1960 local result, temp = AceSerializer:Deserialize(current);
1960 1961
1961 if not temp.name then 1962 if not temp.name then
1962 print("|cffff0000The provided data is not supported.|r"); 1963 addon:Print("The provided data is not supported.", addon.Colors.Red);
1963 elseif ValidateGroupName(nil, temp.name) ~= true then 1964 elseif ValidateGroupName(nil, temp.name) ~= true then
1964 print(("|cffff0000Aborting: A group named \"%s\" already exists.|r"):format(temp.name)); 1965 addon:Print(("Aborting: A group named \"%s\" already exists."):format(temp.name), addon.Colors.Red);
1965 else 1966 else
1966 local name = temp.name; 1967 local name = temp.name;
1967 temp.name = nil; 1968 temp.name = nil;
1968 print(("Importing %s..."):format(name)); 1969 addon:Print(("Importing %s..."):format(name));
1969 1970
1970 if temp.items then 1971 if temp.items then
1971 -- Remove items that are already in another group 1972 -- Remove items that are already in another group
1972 for value, _ in pairs(temp.items) do 1973 for value, _ in pairs(temp.items) do
1973 local itemId = tonumber(value); 1974 local itemId = tonumber(value);
1974 1975
1975 local itemData = addon.ItemData:New(itemId); 1976 local itemData = addon.ItemData:New(itemId);
1976 1977
1977 if not itemId then 1978 if not itemId then
1978 print(("\"%s\" is not a number."):format(value)); 1979 addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red);
1979 temp.items[value] = nil; 1980 temp.items[value] = nil;
1980 elseif itemData:InGroup() then 1981 elseif itemData:InGroup() then
1981 print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); 1982 addon:Print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ), addon.Colors.Red);
1982 temp.items[value] = nil; 1983 temp.items[value] = nil;
1983 else 1984 else
1984 -- Ensure the keys are numeric 1985 -- Ensure the keys are numeric
1985 temp.items[value] = nil; 1986 temp.items[value] = nil;
1986 temp.items[itemId] = true; 1987 temp.items[itemId] = true;
2064 2065
2065 if version > values.premadeGroups[premadeGroupName] then 2066 if version > values.premadeGroups[premadeGroupName] then
2066 -- This item was added in a more recent version than this group: Add item 2067 -- This item was added in a more recent version than this group: Add item
2067 2068
2068 if itemData:InGroup() then 2069 if itemData:InGroup() then
2069 print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); 2070 addon:Print(("Skipping %s as it is already in the group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ));
2070 elseif itemData:AddToGroup(groupName) then 2071 elseif itemData:AddToGroup(groupName) then
2071 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); 2072 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);
2072 end 2073 end
2073 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then 2074 elseif ( version * -1 ) > values.premadeGroups[premadeGroupName] then
2074 if itemData:InGroup() == groupName then 2075 if itemData:InGroup() == groupName then
2075 itemData:RemoveFromGroup(groupName); 2076 itemData:RemoveFromGroup(groupName);
2076 2077
2077 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); 2078 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);
2078 else 2079 else
2079 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() )); 2080 addon: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() ));
2080 end 2081 end
2081 end 2082 end
2082 end 2083 end
2083 2084
2084 if AceConfigRegistry then 2085 if AceConfigRegistry then
2098 local itemData = addon.ItemData:New(itemId); 2099 local itemData = addon.ItemData:New(itemId);
2099 2100
2100 if version > values.premadeGroups[premadeGroupName] then 2101 if version > values.premadeGroups[premadeGroupName] then
2101 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it 2102 -- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it
2102 2103
2103 print(("Skipping %s found in the premade group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() )); 2104 addon:Print(("Skipping %s found in the premade group |cfffed000%s|r."):format( (itemData.link or unknownItemName:format(itemId)), itemData:InGroup() ));
2104 end 2105 end
2105 end 2106 end
2106 2107
2107 -- Remember the new version 2108 -- Remember the new version
2108 values.premadeGroups[premadeGroupName] = groupInfo.version; 2109 values.premadeGroups[premadeGroupName] = groupInfo.version;