Mercurial > wow > inventory
comparison Modules/Config.lua @ 152:311eb97cb983
Added mass export to the extra panel of the config. Next step is to support an easy way to backup settings. :)
author | Zerotorescue |
---|---|
date | Thu, 20 Jan 2011 20:13:00 +0100 |
parents | cd461a41723c |
children | 39df534c9856 |
comparison
equal
deleted
inserted
replaced
151:31d498e95512 | 152:311eb97cb983 |
---|---|
832 desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.", | 832 desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.", |
833 set = false, | 833 set = false, |
834 get = function(info) | 834 get = function(info) |
835 local groupName = groupIdToName[info[2]]; | 835 local groupName = groupIdToName[info[2]]; |
836 | 836 |
837 -- We want to include the group name, so we copy the table then set another value | 837 return mod:ExportGroup(groupName); |
838 local temp = CopyTable(addon.db.profile.groups[groupName]); | |
839 temp.name = groupName; | |
840 temp.trackAtCharacters = nil; | |
841 temp.overrideTrackAtCharacters = nil; | |
842 | |
843 if not AceSerializer then | |
844 AceSerializer = LibStub("AceSerializer-3.0"); | |
845 end | |
846 | |
847 return AceSerializer:Serialize(temp); | |
848 end, | 838 end, |
849 }, | 839 }, |
850 }, | 840 }, |
851 }, | 841 }, |
852 }, | 842 }, |
1262 local Widgets = addon:GetModule("Widgets"); | 1252 local Widgets = addon:GetModule("Widgets"); |
1263 Widgets:ItemLinkButton(); | 1253 Widgets:ItemLinkButton(); |
1264 Widgets:ConfigItemLinkButton(); | 1254 Widgets:ConfigItemLinkButton(); |
1265 end | 1255 end |
1266 | 1256 |
1257 function mod:ExportGroup(groupName) | |
1258 -- We want to include the group name, so we copy the table then set another value | |
1259 local temp = CopyTable(addon.db.profile.groups[groupName]); | |
1260 temp.name = groupName; | |
1261 temp.trackAtCharacters = nil; | |
1262 temp.overrideTrackAtCharacters = nil; | |
1263 | |
1264 if not AceSerializer then | |
1265 AceSerializer = LibStub("AceSerializer-3.0"); | |
1266 end | |
1267 | |
1268 return AceSerializer:Serialize(temp); | |
1269 end | |
1270 | |
1267 function mod:RefreshConfig() | 1271 function mod:RefreshConfig() |
1268 self:PremadeGroupsCheck(); | 1272 self:PremadeGroupsCheck(); |
1269 | 1273 |
1270 self:FillGroupOptions(); | 1274 self:FillGroupOptions(); |
1271 end | 1275 end |
1653 }, | 1657 }, |
1654 }; | 1658 }; |
1655 end | 1659 end |
1656 | 1660 |
1657 function mod:FillExtraOptions() | 1661 function mod:FillExtraOptions() |
1662 local selectedExportGroups = {}; | |
1658 options.args.extra = { | 1663 options.args.extra = { |
1659 order = 300, | 1664 order = 300, |
1660 type = "group", | 1665 type = "group", |
1661 name = "Extra", | 1666 name = "Extra", |
1662 desc = "Change additional (but completely optional) settings.", | 1667 desc = "Change additional (but completely optional) settings.", |
1713 if values.trackAtCharacters then | 1718 if values.trackAtCharacters then |
1714 values.trackAtCharacters[name] = nil; | 1719 values.trackAtCharacters[name] = nil; |
1715 end | 1720 end |
1716 end | 1721 end |
1717 end | 1722 end |
1723 end, | |
1724 }, | |
1725 }, | |
1726 }, | |
1727 export = { | |
1728 order = 30, | |
1729 type = "group", | |
1730 inline = true, | |
1731 name = "Export groups", | |
1732 args = { | |
1733 localItemData = { | |
1734 order = 0, | |
1735 type = "multiselect", | |
1736 name = "Select groups", | |
1737 desc = "Select which groups should be included in the export.", | |
1738 values = function() | |
1739 local temp = {}; | |
1740 | |
1741 if addon.db.profile.groups then | |
1742 temp["*InverseAll"] = "Inverse"; | |
1743 | |
1744 for groupName, _ in pairs(addon.db.profile.groups) do | |
1745 temp[groupName] = groupName; | |
1746 end | |
1747 end | |
1748 | |
1749 return temp; | |
1750 end, | |
1751 get = function(info, value) | |
1752 --local groupName = groupIdToName[info[2]]; | |
1753 --local optionName = info[#info]; | |
1754 | |
1755 return selectedExportGroups[value]; | |
1756 end, | |
1757 set = function(info, name, value) | |
1758 --local groupName = groupIdToName[info[2]]; | |
1759 --local optionName = info[#info]; | |
1760 | |
1761 if name == "*InverseAll" then | |
1762 for groupName, _ in pairs(addon.db.profile.groups) do | |
1763 if selectedExportGroups[groupName] then | |
1764 selectedExportGroups[groupName] = nil; | |
1765 else | |
1766 selectedExportGroups[groupName] = true; | |
1767 end | |
1768 end | |
1769 else | |
1770 if selectedExportGroups[name] then | |
1771 selectedExportGroups[name] = nil; | |
1772 else | |
1773 selectedExportGroups[name] = true; | |
1774 end | |
1775 end | |
1776 end, | |
1777 }, | |
1778 input = { | |
1779 order = 10, | |
1780 type = "input", | |
1781 multiline = true, | |
1782 width = "full", | |
1783 name = "Exported data", | |
1784 desc = "Export the group data for the currently selected group. Press CTRL-A to select all and CTRL-C to copy the text.", | |
1785 set = false, | |
1786 get = function(info) | |
1787 local result = ""; | |
1788 for groupName, v in pairs(selectedExportGroups) do | |
1789 if v then | |
1790 result = result .. mod:ExportGroup(groupName) .. "\n"; | |
1791 end | |
1792 end | |
1793 | |
1794 return result; | |
1718 end, | 1795 end, |
1719 }, | 1796 }, |
1720 }, | 1797 }, |
1721 }, | 1798 }, |
1722 colorCodes = { | 1799 colorCodes = { |
1998 desc = "Paste the group data as provided by a group export. If you are trying to import multiple groups at the same time, make sure to use newlines to seperate them.", | 2075 desc = "Paste the group data as provided by a group export. If you are trying to import multiple groups at the same time, make sure to use newlines to seperate them.", |
1999 set = function(info, value) | 2076 set = function(info, value) |
2000 local data = { string.split("\n", value or "") }; | 2077 local data = { string.split("\n", value or "") }; |
2001 | 2078 |
2002 for _, current in pairs(data) do | 2079 for _, current in pairs(data) do |
2003 if not AceSerializer then | 2080 if current and string.trim(current) ~= "" then |
2004 AceSerializer = LibStub("AceSerializer-3.0"); | 2081 if not AceSerializer then |
2005 end | 2082 AceSerializer = LibStub("AceSerializer-3.0"); |
2006 | 2083 end |
2007 local result, temp = AceSerializer:Deserialize(current); | |
2008 | |
2009 if not temp.name then | |
2010 addon:Print("The provided data is not supported.", addon.Colors.Red); | |
2011 elseif ValidateGroupName(nil, temp.name) ~= true then | |
2012 addon:Print(("Aborting: A group named \"%s\" already exists."):format(temp.name), addon.Colors.Red); | |
2013 else | |
2014 local name = temp.name; | |
2015 temp.name = nil; | |
2016 addon:Print(("Importing %s..."):format(name)); | |
2017 | 2084 |
2018 if temp.items then | 2085 local result, temp = AceSerializer:Deserialize(current); |
2019 -- Remove items that are already in another group | 2086 |
2020 for value, count in pairs(temp.items) do | 2087 if not temp.name then |
2021 local itemId = tonumber(value); | 2088 addon:Print("The provided data is not supported.", addon.Colors.Red); |
2022 | 2089 elseif ValidateGroupName(nil, temp.name) ~= true then |
2023 local itemData = addon.ItemData:New(itemId); | 2090 addon:Print(("Aborting: A group named \"%s\" already exists."):format(temp.name), addon.Colors.Red); |
2024 | 2091 else |
2025 if not itemId then | 2092 local name = temp.name; |
2026 addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red); | 2093 temp.name = nil; |
2027 temp.items[value] = nil; | 2094 addon:Print(("Importing %s..."):format(name)); |
2028 elseif itemData:InGroup() then | 2095 |
2029 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); | 2096 if temp.items then |
2030 temp.items[value] = nil; | 2097 -- Remove items that are already in another group |
2031 else | 2098 for value, count in pairs(temp.items) do |
2032 -- Ensure the keys are numeric | 2099 local itemId = tonumber(value); |
2033 temp.items[value] = nil; | 2100 |
2034 temp.items[itemId] = tonumber(count) or 0; | 2101 local itemData = addon.ItemData:New(itemId); |
2102 | |
2103 if not itemId then | |
2104 addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red); | |
2105 temp.items[value] = nil; | |
2106 elseif itemData:InGroup() then | |
2107 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); | |
2108 temp.items[value] = nil; | |
2109 else | |
2110 -- Ensure the keys are numeric | |
2111 temp.items[value] = nil; | |
2112 temp.items[itemId] = tonumber(count) or 0; | |
2113 end | |
2035 end | 2114 end |
2036 end | 2115 end |
2116 | |
2117 -- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this) | |
2118 temp.trackAtCharacters = nil; | |
2119 temp.overrideTrackAtCharacters = nil; | |
2120 | |
2121 addon.db.profile.groups[name] = temp; | |
2037 end | 2122 end |
2038 | |
2039 -- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this) | |
2040 temp.trackAtCharacters = nil; | |
2041 temp.overrideTrackAtCharacters = nil; | |
2042 | |
2043 addon.db.profile.groups[name] = temp; | |
2044 end | 2123 end |
2045 end | 2124 end |
2046 | 2125 |
2047 self:FillGroupOptions(); | 2126 self:FillGroupOptions(); |
2048 end, | 2127 end, |