annotate Modules/Options.lua @ 59:4ec321eb0dfe

Adding a crafing tab to the ItemAuditor window.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sun, 25 Jul 2010 15:51:13 -0700
parents bdf3aba93aa9
children e7d287cc3b02
rev   line source
Asa@28 1 local addonName, addonTable = ...;
Asa@3 2 local addon = _G[addonName]
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@20 13 craftingThresholdsDisplay[key] = addon:FormatMoney(value, '', true)
Asa@20 14 -- craftingThresholdsDisplay[key] = value
Asa@20 15 end
Asa@20 16
Asa@55 17 local windowIndex = nil
Asa@55 18 function addon: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@55 29 function addon: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@55 45 function addon: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@55 53 function addon: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@3 66 local options = {
Asa@13 67 handler = addon,
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 = (not addon.QA_compatibile),
Asa@13 127 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@13 128 args = {
Asa@13 129 toggle_qa = {
Asa@13 130 type = "toggle",
Asa@13 131 name = "Enable Quick Auctions",
Asa@13 132 desc = "This will enable or disable Quick Auctions integration",
Asa@13 133 get = "IsQAEnabled",
Asa@13 134 set = "SetQAEnabled",
Asa@13 135 order = 0,
Asa@13 136 },
Asa@13 137 --[[
Asa@13 138 add_mail = {
Asa@13 139 type = "toggle",
Asa@13 140 name = "Add mail cost to QA Threshold",
Asa@13 141 get = "IsQAEnabled",
Asa@13 142 set = "SetQAEnabled",
Asa@13 143 order = 1,
Asa@13 144 },
Asa@13 145 ]]
Asa@20 146 auction_threshold = {
Asa@20 147 type = "range",
Asa@20 148 name = "Auction Threshold",
Asa@20 149 desc = "Don't create items that will make less than this amount of profit",
Asa@20 150 min = 0.0,
Asa@20 151 max = 1.0,
Asa@20 152 isPercent = true,
Asa@20 153 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@21 154 set = function(info, value)
Asa@21 155 ItemAuditor.db.char.auction_threshold = value
Asa@21 156 ItemAuditor:RefreshQAGroups()
Asa@21 157 end,
Asa@20 158 disabled = 'IsQADisabled',
Asa@20 159 order = 1,
Asa@20 160 },
Asa@13 161 refresh_qa = {
Asa@13 162 type = "execute",
Asa@13 163 name = "Refresh QA Thresholds",
Asa@13 164 desc = "Resets all Quick Auctions thresholds",
Asa@13 165 func = "RefreshQAGroups",
Asa@13 166 disabled = 'IsQADisabled',
Asa@20 167 order = 9,
Asa@13 168 },
Asa@21 169 }
Asa@21 170 },
Asa@21 171 crafting_options = {
Asa@21 172 name = "Crafting with Skillet",
Asa@21 173 desc = "/ia queue",
Asa@21 174 type = 'group',
Asa@21 175 disabled = function() return Skillet == nil end,
Asa@21 176 args = {
Asa@20 177 crafting_threshold = {
Asa@20 178 type = "select",
Asa@20 179 name = "Crafting Threshold",
Asa@20 180 desc = "Don't create items that will make less than this amount of profit",
Asa@20 181 values = craftingThresholdsDisplay,
Asa@20 182 get = function() return ItemAuditor.db.char.crafting_threshold end,
Asa@20 183 set = function(info, value) ItemAuditor.db.char.crafting_threshold = value end,
Asa@20 184 order = 11,
Asa@20 185 },
Asa@21 186 },
Asa@12 187 },
Asa@3 188 options = {
Asa@3 189 type = "execute",
Asa@3 190 name = "options",
Asa@3 191 desc = "Show Blizzard's options GUI",
Asa@3 192 func = "ShowOptionsGUI",
Asa@3 193 guiHidden = true,
Asa@3 194 },
Asa@18 195 queue = {
Asa@18 196 type = "execute",
Asa@18 197 name = "queue",
Asa@18 198 desc = "Queue",
Asa@18 199 func = "Queue",
Asa@18 200 guiHidden = true,
Asa@18 201 },
Asa@22 202 debug = {
Asa@22 203 type = "execute",
Asa@22 204 name = "debug",
Asa@22 205 desc = "Shows the debug frame",
Asa@22 206 func = function() ItemAuditor_DebugFrame:Show() end,
Asa@22 207 guiHidden = true,
Asa@28 208 },
Asa@28 209 invested = {
Asa@28 210 type = "execute",
Asa@28 211 name = "invested",
Asa@28 212 desc = "Shows what you have invested in",
Asa@58 213 func = "DisplayInvested",
Asa@28 214 guiHidden = false,
Asa@28 215 },
Asa@59 216 crafting = {
Asa@59 217 type = "execute",
Asa@59 218 name = "crafting",
Asa@59 219 desc = "<description goes here>",
Asa@59 220 func = "DisplayCrafting",
Asa@59 221 guiHidden = false,
Asa@59 222 },
Asa@59 223
Asa@38 224 suspend = {
Asa@38 225 type = "toggle",
Asa@38 226 name = "suspend",
Asa@38 227 desc = "Suspends ItemAuditor",
Asa@38 228 get = "IsEnabled",
Asa@38 229 set = "SetEnabled",
Asa@38 230 guiHidden = true,
Asa@38 231 },
Asa@3 232 },
Asa@3 233 }
Asa@3 234
Asa@38 235 function addon:SetEnabled(info, enable)
Asa@38 236 self.db.profile.addon_enabled = enable
Asa@38 237 if enable == self:IsEnabled() then
Asa@38 238 -- do nothing
Asa@38 239 elseif enable then
Asa@38 240 self:Enable()
Asa@38 241 self:Print('ItemAuditor is enabled.')
Asa@38 242 else
Asa@38 243 self:Disable()
Asa@38 244 self:Print('ItemAuditor is supended and will not watch for any events. Use "/ia suspend" to turn it back on.')
Asa@38 245 end
Asa@38 246 end
Asa@38 247
Asa@3 248 function addon:RegisterOptions()
Asa@3 249 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor")
Asa@3 250 LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", options, {"ia"})
Asa@3 251 end
Asa@3 252
Asa@7 253 local function pairsByKeys (t, f)
Asa@7 254 local a = {}
Asa@7 255 for n in pairs(t) do table.insert(a, n) end
Asa@7 256 table.sort(a, f)
Asa@7 257 local i = 0 -- iterator variable
Asa@7 258 local iter = function () -- iterator function
Asa@7 259 i = i + 1
Asa@7 260 if a[i] == nil then return nil
Asa@7 261 else return a[i], t[a[i]]
Asa@7 262 end
Asa@7 263 end
Asa@7 264 return iter
Asa@7 265 end
Asa@7 266
Asa@20 267 function addon:GetCraftingThreshold()
Asa@20 268 local key = ItemAuditor.db.char.crafting_threshold
Asa@20 269 return craftingThresholds[key]
Asa@20 270 end
Asa@20 271
Asa@20 272 function addon:GetAuctionThreshold()
Asa@20 273 return ItemAuditor.db.char.auction_threshold
Asa@20 274 end
Asa@20 275
Asa@13 276 function addon:GetAH()
Asa@13 277 return ItemAuditor.db.char.ah
Asa@13 278 end
Asa@13 279
Asa@13 280 function addon:SetAH(info, value)
Asa@13 281 ItemAuditor.db.char.ah = value
Asa@13 282 end
Asa@13 283
Asa@13 284 function addon:GetAHCut()
Asa@13 285 if ItemAuditor.db.char.ah == 1 then
Asa@13 286 return 0.05
Asa@13 287 end
Asa@13 288 return 0.15
Asa@13 289 end
Asa@13 290
Asa@13 291 function addon:GetAHFaction()
Asa@13 292 return AHFactions[ItemAuditor.db.char.ah]
Asa@13 293 end
Asa@13 294
Asa@3 295 function addon:ShowOptionsGUI()
Asa@3 296 InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
Asa@3 297 end
Asa@3 298
Asa@3 299