annotate Modules/Options.lua @ 63:e7d287cc3b02

Replaced all instances of addon with ItemAuditor and I moved ItemAuditor out of the global namespace. The conversion was mostly a search/replace offering no new functionality. That will come in a later commit.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Tue, 27 Jul 2010 17:58:33 -0700
parents 4ec321eb0dfe
children 32d53abee666
rev   line source
Asa@63 1 local ItemAuditor = select(2, ...)
Asa@63 2 local Options = ItemAuditor:NewModule("Options")
Asa@3 3
Asa@13 4 local currentFaction = UnitFactionGroup("player")
Asa@13 5 local AHFactions = { currentFaction, 'Neutral' }
Asa@13 6
Asa@20 7 local craftingThresholds = {5000, 10000, 50000}
Asa@20 8 local craftingThresholdsDisplay = {}
Asa@20 9
Asa@57 10 local currentVersion = "@project-version@"
Asa@57 11
Asa@20 12 for key, value in pairs(craftingThresholds) do
Asa@63 13 craftingThresholdsDisplay[key] = ItemAuditor:FormatMoney(value, '', true)
Asa@20 14 -- craftingThresholdsDisplay[key] = value
Asa@20 15 end
Asa@20 16
Asa@55 17 local windowIndex = nil
Asa@63 18 function ItemAuditor:GetChatWindowList()
Asa@55 19 local windows = {}
Asa@55 20 for i=1, NUM_CHAT_WINDOWS do
Asa@55 21 local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i)
Asa@55 22 if (name ~= "") and (docked or shown) then
Asa@55 23 windows[i] = name
Asa@55 24 end
Asa@55 25 end
Asa@55 26 return windows
Asa@55 27 end
Asa@55 28
Asa@63 29 function ItemAuditor:GetChatWindowIndex()
Asa@55 30 local cf = self.db.char.output_chat_frame
Asa@55 31 if not windowIndex then
Asa@55 32 for i=1, NUM_CHAT_WINDOWS do
Asa@55 33 local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i)
Asa@55 34 if name ~= "" and cf ~= nil and cf == name then
Asa@55 35 self:SetChatWindow(nil, i)
Asa@55 36 end
Asa@55 37 end
Asa@55 38 end
Asa@55 39 return windowIndex
Asa@55 40 end
Asa@55 41
Asa@55 42
Asa@55 43 local selectedWindow = nil
Asa@55 44
Asa@63 45 function ItemAuditor:SetChatWindow(info, index)
Asa@55 46 windowIndex = index
Asa@55 47 local name = GetChatWindowInfo(windowIndex)
Asa@55 48
Asa@55 49 self.db.char.output_chat_frame = name
Asa@55 50 selectedWindow = nil
Asa@55 51 end
Asa@55 52
Asa@63 53 function ItemAuditor:GetSelectedChatWindow()
Asa@55 54 if not selectedWindow then
Asa@56 55 local index = self:GetChatWindowIndex()
Asa@56 56 if index then
Asa@56 57 selectedWindow = _G["ChatFrame"..index]
Asa@56 58 end
Asa@55 59 end
Asa@55 60 if (selectedWindow) then
Asa@55 61 return selectedWindow
Asa@55 62 end
Asa@55 63 return DEFAULT_CHAT_FRAME
Asa@55 64 end
Asa@55 65
Asa@63 66 local optionsTable = {
Asa@63 67 handler = ItemAuditor,
Asa@57 68 name = "ItemAuditor "..currentVersion,
Asa@3 69 type = 'group',
Asa@3 70 args = {
Asa@13 71 prices = {
Asa@13 72 name = "Prices",
Asa@13 73 desc = "Control how your minimum price is calculated.",
Asa@13 74 type = 'group',
Asa@13 75 args = {
Asa@13 76 auction_house = {
Asa@13 77 type = "select",
Asa@13 78 name = "Auction House",
Asa@13 79 desc = "",
Asa@13 80 values = { currentFaction, 'Neutral' },
Asa@13 81 get = 'GetAH',
Asa@13 82 set = 'SetAH',
Asa@13 83 },
Asa@13 84 },
Asa@3 85 },
Asa@13 86
Asa@13 87
Asa@13 88 messages = {
Asa@13 89 name = "Messages",
Asa@13 90 desc = "Control which messages display in your chat window.",
Asa@13 91 type = 'group',
Asa@13 92 args = {
Asa@20 93
Asa@20 94 item_cost = {
Asa@20 95 type = "toggle",
Asa@20 96 name = "Item Cost",
Asa@20 97 desc = "Shows a message every time an item's cost changes",
Asa@20 98 get = function() return ItemAuditor.db.profile.messages.cost_updates end,
Asa@20 99 set = function(info, value) ItemAuditor.db.profile.messages.cost_updates = value end,
Asa@20 100 order = 0,
Asa@20 101 },
Asa@20 102 queue_skip = {
Asa@20 103 type = "toggle",
Asa@20 104 name = "Queue Skip",
Asa@20 105 desc = "Displays a message when an item is excluded from the queue.",
Asa@20 106 get = function() return ItemAuditor.db.profile.messages.queue_skip end,
Asa@20 107 set = function(info, value) ItemAuditor.db.profile.messages.queue_skip = value end,
Asa@20 108 disabled = 'IsQADisabled',
Asa@20 109 order = 1,
Asa@20 110 },
Asa@55 111 output = {
Asa@55 112 type = "select",
Asa@55 113 name = "Output",
Asa@55 114 desc = "",
Asa@55 115 values = 'GetChatWindowList',
Asa@55 116 get = 'GetChatWindowIndex',
Asa@55 117 set = 'SetChatWindow',
Asa@55 118 },
Asa@13 119 },
Asa@3 120 },
Asa@13 121
Asa@13 122 qa_options = {
Asa@13 123 name = "QA Options",
Asa@13 124 desc = "Control how ItemAuditor integrates with QuickAuctions",
Asa@13 125 type = 'group',
Asa@13 126 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@13 127 args = {
Asa@13 128 toggle_qa = {
Asa@13 129 type = "toggle",
Asa@13 130 name = "Enable Quick Auctions",
Asa@13 131 desc = "This will enable or disable Quick Auctions integration",
Asa@13 132 get = "IsQAEnabled",
Asa@13 133 set = "SetQAEnabled",
Asa@13 134 order = 0,
Asa@13 135 },
Asa@13 136 --[[
Asa@13 137 add_mail = {
Asa@13 138 type = "toggle",
Asa@13 139 name = "Add mail cost to QA Threshold",
Asa@13 140 get = "IsQAEnabled",
Asa@13 141 set = "SetQAEnabled",
Asa@13 142 order = 1,
Asa@13 143 },
Asa@13 144 ]]
Asa@20 145 auction_threshold = {
Asa@20 146 type = "range",
Asa@20 147 name = "Auction Threshold",
Asa@20 148 desc = "Don't create items that will make less than this amount of profit",
Asa@20 149 min = 0.0,
Asa@20 150 max = 1.0,
Asa@20 151 isPercent = true,
Asa@20 152 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@21 153 set = function(info, value)
Asa@21 154 ItemAuditor.db.char.auction_threshold = value
Asa@21 155 ItemAuditor:RefreshQAGroups()
Asa@21 156 end,
Asa@20 157 disabled = 'IsQADisabled',
Asa@20 158 order = 1,
Asa@20 159 },
Asa@13 160 refresh_qa = {
Asa@13 161 type = "execute",
Asa@13 162 name = "Refresh QA Thresholds",
Asa@13 163 desc = "Resets all Quick Auctions thresholds",
Asa@13 164 func = "RefreshQAGroups",
Asa@13 165 disabled = 'IsQADisabled',
Asa@20 166 order = 9,
Asa@13 167 },
Asa@21 168 }
Asa@21 169 },
Asa@21 170 crafting_options = {
Asa@21 171 name = "Crafting with Skillet",
Asa@21 172 desc = "/ia queue",
Asa@21 173 type = 'group',
Asa@21 174 disabled = function() return Skillet == nil end,
Asa@21 175 args = {
Asa@20 176 crafting_threshold = {
Asa@20 177 type = "select",
Asa@20 178 name = "Crafting Threshold",
Asa@20 179 desc = "Don't create items that will make less than this amount of profit",
Asa@20 180 values = craftingThresholdsDisplay,
Asa@20 181 get = function() return ItemAuditor.db.char.crafting_threshold end,
Asa@20 182 set = function(info, value) ItemAuditor.db.char.crafting_threshold = value end,
Asa@20 183 order = 11,
Asa@20 184 },
Asa@21 185 },
Asa@12 186 },
Asa@3 187 options = {
Asa@3 188 type = "execute",
Asa@3 189 name = "options",
Asa@3 190 desc = "Show Blizzard's options GUI",
Asa@3 191 func = "ShowOptionsGUI",
Asa@3 192 guiHidden = true,
Asa@3 193 },
Asa@18 194 queue = {
Asa@18 195 type = "execute",
Asa@18 196 name = "queue",
Asa@18 197 desc = "Queue",
Asa@18 198 func = "Queue",
Asa@18 199 guiHidden = true,
Asa@18 200 },
Asa@22 201 debug = {
Asa@22 202 type = "execute",
Asa@22 203 name = "debug",
Asa@22 204 desc = "Shows the debug frame",
Asa@22 205 func = function() ItemAuditor_DebugFrame:Show() end,
Asa@22 206 guiHidden = true,
Asa@28 207 },
Asa@28 208 invested = {
Asa@28 209 type = "execute",
Asa@28 210 name = "invested",
Asa@28 211 desc = "Shows what you have invested in",
Asa@58 212 func = "DisplayInvested",
Asa@28 213 guiHidden = false,
Asa@28 214 },
Asa@59 215 crafting = {
Asa@59 216 type = "execute",
Asa@59 217 name = "crafting",
Asa@59 218 desc = "<description goes here>",
Asa@59 219 func = "DisplayCrafting",
Asa@59 220 guiHidden = false,
Asa@59 221 },
Asa@59 222
Asa@38 223 suspend = {
Asa@38 224 type = "toggle",
Asa@38 225 name = "suspend",
Asa@38 226 desc = "Suspends ItemAuditor",
Asa@38 227 get = "IsEnabled",
Asa@38 228 set = "SetEnabled",
Asa@38 229 guiHidden = true,
Asa@38 230 },
Asa@3 231 },
Asa@3 232 }
Asa@3 233
Asa@63 234 function ItemAuditor:SetEnabled(info, enable)
Asa@38 235 self.db.profile.addon_enabled = enable
Asa@38 236 if enable == self:IsEnabled() then
Asa@38 237 -- do nothing
Asa@38 238 elseif enable then
Asa@38 239 self:Enable()
Asa@38 240 self:Print('ItemAuditor is enabled.')
Asa@38 241 else
Asa@38 242 self:Disable()
Asa@38 243 self:Print('ItemAuditor is supended and will not watch for any events. Use "/ia suspend" to turn it back on.')
Asa@38 244 end
Asa@38 245 end
Asa@38 246
Asa@63 247 function ItemAuditor:RegisterOptions()
Asa@3 248 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor")
Asa@63 249 LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", optionsTable, {"ia"})
Asa@3 250 end
Asa@3 251
Asa@7 252 local function pairsByKeys (t, f)
Asa@7 253 local a = {}
Asa@7 254 for n in pairs(t) do table.insert(a, n) end
Asa@7 255 table.sort(a, f)
Asa@7 256 local i = 0 -- iterator variable
Asa@7 257 local iter = function () -- iterator function
Asa@7 258 i = i + 1
Asa@7 259 if a[i] == nil then return nil
Asa@7 260 else return a[i], t[a[i]]
Asa@7 261 end
Asa@7 262 end
Asa@7 263 return iter
Asa@7 264 end
Asa@7 265
Asa@63 266 function ItemAuditor:GetCraftingThreshold()
Asa@20 267 local key = ItemAuditor.db.char.crafting_threshold
Asa@20 268 return craftingThresholds[key]
Asa@20 269 end
Asa@20 270
Asa@63 271 function ItemAuditor:GetAuctionThreshold()
Asa@20 272 return ItemAuditor.db.char.auction_threshold
Asa@20 273 end
Asa@20 274
Asa@63 275 function ItemAuditor:GetAH()
Asa@13 276 return ItemAuditor.db.char.ah
Asa@13 277 end
Asa@13 278
Asa@63 279 function ItemAuditor:SetAH(info, value)
Asa@13 280 ItemAuditor.db.char.ah = value
Asa@13 281 end
Asa@13 282
Asa@63 283 function ItemAuditor:GetAHCut()
Asa@13 284 if ItemAuditor.db.char.ah == 1 then
Asa@13 285 return 0.05
Asa@13 286 end
Asa@13 287 return 0.15
Asa@13 288 end
Asa@13 289
Asa@63 290 function ItemAuditor:GetAHFaction()
Asa@13 291 return AHFactions[ItemAuditor.db.char.ah]
Asa@13 292 end
Asa@13 293
Asa@63 294 function ItemAuditor:ShowOptionsGUI()
Asa@3 295 InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
Asa@3 296 end
Asa@3 297
Asa@3 298