# HG changeset patch # User Zerotorescue # Date 1298125606 -3600 # Node ID 03cd9d95e9807cd582fd271f8666c6d2b7c94611 # Parent 65a9ef84d18fe79a6073d97a6bd2dc9633660ddb Added ZeroAuctions group import. diff -r 65a9ef84d18f -r 03cd9d95e980 Modules/Config.lua --- a/Modules/Config.lua Sat Feb 12 20:15:40 2011 +0100 +++ b/Modules/Config.lua Sat Feb 19 15:26:46 2011 +0100 @@ -2072,7 +2072,7 @@ name = "", hidden = function() return addon.db.profile.defaults.hideHelp; end, }, - localItemData = { + selectExportGroups = { order = 9, type = "multiselect", name = "Select groups", @@ -2363,6 +2363,7 @@ end function mod:MakeGroupOptions() + local selectedImportGroups; options.args.groups = { order = 1100, type = "group", @@ -2406,17 +2407,23 @@ }, }, }, - import = { + importExport = { order = 20, type = "group", inline = true, - name = "Import a group", + name = "Import a group export", args = { + help = { + order = 5, + type = "description", + name = "If you have exported one or more groups (which can be done by clicking a group and opening the management tab or at the middle of the extra tab) you can instantly import them here. These groups will be added if no groups with the same name already exist.", + hidden = function() return addon.db.profile.defaults.hideHelp; end, + }, input = { order = 10, type = "input", multiline = true, - name = "Group data", + name = "Exported group data", 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.", set = function(info, value) local data = { string.split("\n", value or "") }; @@ -2477,6 +2484,159 @@ }, }, }, + importFromOtherAddons = { + order = 30, + type = "group", + inline = true, + name = "Import groups from other addons", + args = { + selectImportGroups = { + order = 10, + type = "multiselect", + name = "Select groups", + desc = "Select which groups should be imported.", + values = function() + local temp = {}; + temp["*InverseAll"] = "Inverse"; + + local Ace = LibStub("AceAddon-3.0", true); + if Ace then + local ZA = Ace:GetAddon("ZeroAuctions", true); + + if ZA then + for groupName, contents in pairs(ZA.db.global.groups) do + temp["ZeroAuctions$" .. groupName] = string.format("ZA: %s", groupName); + end + end + + local APM = Ace:GetAddon("AuctionProfitMaster", true); + + if APM then + for groupName, contents in pairs(APM.db.global.groups) do + temp["AuctionProfitMaster$" .. groupName] = string.format("APM: %s", groupName); + end + end + end + + return temp; + end, + get = function(info, value) + --local groupName = groupIdToName[info[2]]; + --local optionName = info[#info]; + + return selectedImportGroups and selectedImportGroups[value]; + end, + set = function(info, name, value) + --local groupName = groupIdToName[info[2]]; + --local optionName = info[#info]; + + if not selectedImportGroups then + selectedImportGroups = {}; + end + + if name == "*InverseAll" then + for groupName, _ in pairs(info.option.values()) do + if selectedImportGroups and selectedImportGroups[groupName] then + selectedImportGroups[groupName] = nil; + else + selectedImportGroups[groupName] = true; + end + end + else + if selectedImportGroups and selectedImportGroups[name] then + selectedImportGroups[name] = nil; + else + selectedImportGroups[name] = true; + end + end + end, + }, + import = { + order = 20, + type = "execute", + name = "Import selected groups", + desc = "Import the groups selected above.", + func = function(info) + -- Go through all selected groups + for selection in pairs(selectedImportGroups) do + local sourceAddon, groupName = string.match(selection, "^(%a+)\$(.+)$"); + + if sourceAddon == "ZeroAuctions" or sourceAddon == "AuctionProfitMaster" then + -- ZeroAuctions/AuctionProfitMaster-group + + local ZA = LibStub("AceAddon-3.0"):GetAddon(sourceAddon); -- If it was in the list, we're sure the addon is enabled + + local temp = {}; + + do-- Set settings region + local currentProfile = ZA.db.profile; + if currentProfile then + -- Set price threshold + local threshold = currentProfile.threshold and currentProfile.threshold[groupName]; + if threshold then + -- Set price threshold + temp.overridePriceThreshold = true; + temp.priceThreshold = threshold; + end + + -- Set minimum global stock, minimum local stock and restock target + local postCap = currentProfile.postCap and currentProfile.postCap[groupName]; + local perAuction = currentProfile.perAuction and currentProfile.perAuction[groupName]; + if postCap and perAuction then + -- Restock target + temp.overrideRestockTarget = true; + temp.restockTarget = (postCap * perAuction); + + -- Minimum global stock + temp.overrideMinGlobalStock = true; + temp.minGlobalStock = (postCap * perAuction); + + -- Minimum local stock + temp.overrideMinLocalStock = true; + temp.minLocalStock = perAuction; + end + end + end + + local items = ZA.db.global.groups[groupName]; + + if not groupName or not items then + addon:Print("The provided data is not supported.", addon.Colors.Red); + elseif ValidateGroupName(nil, groupName) ~= true then + addon:Print(("Aborting: A group named \"%s\" already exists."):format(groupName), addon.Colors.Red); + else + addon:Print(("Importing %s..."):format(groupName)); + + temp.items = {}; + + if items then + -- Remove items that are already in another group + for value, _ in pairs(items) do + local textItemId = string.match(value, "^item:(%d+)$"); + local itemId = tonumber(textItemId or ""); + + local itemData = addon.ItemData:New(itemId); + + if not itemId then + addon:Print(("\"%s\" is not a number."):format(value), addon.Colors.Red); + elseif itemData:InGroup() then + 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); + else + temp.items[itemId] = 0; + end + end + end + + addon.db.profile.groups[groupName] = temp; + end + end + end + + mod:FillGroupOptions(); + end, + }, + }, + }, }, }; end