view Modules/Options.lua @ 94:4ec8611d9466

Fixed Enchanting. I was not getting the ItemID correctly, so enchants could not be mapped to the scrolls they were to created Changed snatch to only add each item once and to only add a snatch for items you don't have API: Added haveMaterials to the item and need to the reagents that get passed to queue destinations. This is in preparation for building a shopping list module.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 11 Aug 2010 23:48:23 -0700
parents 2d65db19d3ce
children c59d22fac6d1
line wrap: on
line source
local ItemAuditor = select(2, ...)
local Options = ItemAuditor:NewModule("Options")

local currentFaction = UnitFactionGroup("player")
local AHFactions = { currentFaction, 'Neutral' }

local windowIndex = nil
function Options.GetChatWindowList()
	local windows = {}
	for i=1, NUM_CHAT_WINDOWS do
		local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i)
		if (name ~= "") and (docked or shown) then
			windows[i] = name
		end
	end
	return windows
end

function Options:GetChatWindowIndex()
	local cf = ItemAuditor.db.char.output_chat_frame
	if not windowIndex then
		for i=1, NUM_CHAT_WINDOWS do
			local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i)
			if name ~= "" and cf ~= nil and cf == name then
				Options.SetChatWindow(nil, i)
			end
		end
	end
	return windowIndex 
end


local selectedWindow = nil

function Options.SetChatWindow(info, index)
	windowIndex = index
	local name = GetChatWindowInfo(windowIndex)
	
	ItemAuditor.db.char.output_chat_frame = name
	selectedWindow = nil
end

function Options.GetSelectedChatWindow()
	if not selectedWindow then
		local index = Options.GetChatWindowIndex()
		if index then
			selectedWindow = _G["ChatFrame"..index]
		end
	end
	if (selectedWindow) then
		return selectedWindow
	end
	return DEFAULT_CHAT_FRAME
end


function ItemAuditor:SetEnabled(info, enable)
	self.db.profile.addon_enabled = enable
	if enable == self:IsEnabled() then
		-- do nothing
	elseif enable then
		self:Enable()
		self:Print('ItemAuditor is enabled.')
	else
		self:Disable()
		self:Print('ItemAuditor is supended and will not watch for any events. Use "/ia suspend" to turn it back on.')
	end
end

local function pairsByKeys (t, f)
	local a = {}
		for n in pairs(t) do table.insert(a, n) end
		table.sort(a, f)
		local i = 0      -- iterator variable
		local iter = function ()   -- iterator function
			i = i + 1
			if a[i] == nil then return nil
			else return a[i], t[a[i]]
			end
		end
	return iter
end



function ItemAuditor:GetAuctionThreshold()
	return ItemAuditor.db.char.auction_threshold
end

function ItemAuditor:GetAH()
	return ItemAuditor.db.char.ah
end

function ItemAuditor:SetAH(info, value)
	ItemAuditor.db.char.ah = value
end

function ItemAuditor:GetAHCut()
	if ItemAuditor.db.char.ah == 1 then
		return 0.05
	end
	return 0.15
end

function ItemAuditor:GetAHFaction()
	return AHFactions[ItemAuditor.db.char.ah]
end

function ItemAuditor:ShowOptionsGUI()
	InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
end


ItemAuditor.Options.args.messages = {
	name = "Messages",
	desc = "Control which messages display in your chat window.",
	type = 'group',
	args = {
		
		item_cost = {
			type = "toggle",
			name = "Item Cost",
			desc = "Shows a message every time an item's cost changes",
			get = function() return ItemAuditor.db.profile.messages.cost_updates end,
			set = function(info, value) ItemAuditor.db.profile.messages.cost_updates = value end,
			order = 0,
		},
		queue_skip = {
			type = "toggle",
			name = "Queue Skip",
			desc = "Displays a message when an item is excluded from the queue.",
			get = function() return ItemAuditor.db.profile.messages.queue_skip end,
			set = function(info, value) ItemAuditor.db.profile.messages.queue_skip = value end,
			disabled = 'IsQADisabled',
			order = 1,
		},
		output = {
			type = "select",
			name = "Output",
			desc = "",
			values = Options.GetChatWindowList,
			get = Options.GetChatWindowIndex,
			set = Options.SetChatWindow,
		},
	},
}

ItemAuditor.Options.args.prices = {
	name = "Prices",
	desc = "Control how your minimum price is calculated.",
	type = 'group',
	args = {
		auction_house = {
			type = "select",
			name = "Auction House",
			desc = "",
			values = { currentFaction, 'Neutral' },
			get = 'GetAH',
			set = 'SetAH',
		},
	},
}