annotate Modules/Options.lua @ 49:9ff6a3b02332 ticket7

I have changed my mind, price distribution will always be based on the AH price, unless none is available, then all items have the same weight which is what was being done before.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 21 Jul 2010 01:00:14 -0700
parents 003de902ae64
children 234896be4087
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@20 10 for key, value in pairs(craftingThresholds) do
Asa@20 11 craftingThresholdsDisplay[key] = addon:FormatMoney(value, '', true)
Asa@20 12 -- craftingThresholdsDisplay[key] = value
Asa@20 13 end
Asa@20 14
Asa@3 15 local options = {
Asa@13 16 handler = addon,
Asa@3 17 name = "ItemAuditor",
Asa@3 18 type = 'group',
Asa@3 19 args = {
Asa@13 20 prices = {
Asa@13 21 name = "Prices",
Asa@13 22 desc = "Control how your minimum price is calculated.",
Asa@13 23 type = 'group',
Asa@13 24 args = {
Asa@13 25 auction_house = {
Asa@13 26 type = "select",
Asa@13 27 name = "Auction House",
Asa@13 28 desc = "",
Asa@13 29 values = { currentFaction, 'Neutral' },
Asa@13 30 get = 'GetAH',
Asa@13 31 set = 'SetAH',
Asa@13 32 },
Asa@13 33 },
Asa@3 34 },
Asa@13 35
Asa@13 36
Asa@13 37 messages = {
Asa@13 38 name = "Messages",
Asa@13 39 desc = "Control which messages display in your chat window.",
Asa@13 40 type = 'group',
Asa@13 41 args = {
Asa@20 42
Asa@20 43 item_cost = {
Asa@20 44 type = "toggle",
Asa@20 45 name = "Item Cost",
Asa@20 46 desc = "Shows a message every time an item's cost changes",
Asa@20 47 get = function() return ItemAuditor.db.profile.messages.cost_updates end,
Asa@20 48 set = function(info, value) ItemAuditor.db.profile.messages.cost_updates = value end,
Asa@20 49 order = 0,
Asa@20 50 },
Asa@20 51 queue_skip = {
Asa@20 52 type = "toggle",
Asa@20 53 name = "Queue Skip",
Asa@20 54 desc = "Displays a message when an item is excluded from the queue.",
Asa@20 55 get = function() return ItemAuditor.db.profile.messages.queue_skip end,
Asa@20 56 set = function(info, value) ItemAuditor.db.profile.messages.queue_skip = value end,
Asa@20 57 disabled = 'IsQADisabled',
Asa@20 58 order = 1,
Asa@20 59 },
Asa@13 60 },
Asa@3 61 },
Asa@13 62
Asa@13 63 qa_options = {
Asa@13 64 name = "QA Options",
Asa@13 65 desc = "Control how ItemAuditor integrates with QuickAuctions",
Asa@13 66 type = 'group',
Asa@13 67 -- disabled = (not addon.QA_compatibile),
Asa@13 68 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@13 69 args = {
Asa@13 70 toggle_qa = {
Asa@13 71 type = "toggle",
Asa@13 72 name = "Enable Quick Auctions",
Asa@13 73 desc = "This will enable or disable Quick Auctions integration",
Asa@13 74 get = "IsQAEnabled",
Asa@13 75 set = "SetQAEnabled",
Asa@13 76 order = 0,
Asa@13 77 },
Asa@13 78 --[[
Asa@13 79 add_mail = {
Asa@13 80 type = "toggle",
Asa@13 81 name = "Add mail cost to QA Threshold",
Asa@13 82 get = "IsQAEnabled",
Asa@13 83 set = "SetQAEnabled",
Asa@13 84 order = 1,
Asa@13 85 },
Asa@13 86 ]]
Asa@20 87 auction_threshold = {
Asa@20 88 type = "range",
Asa@20 89 name = "Auction Threshold",
Asa@20 90 desc = "Don't create items that will make less than this amount of profit",
Asa@20 91 min = 0.0,
Asa@20 92 max = 1.0,
Asa@20 93 isPercent = true,
Asa@20 94 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@21 95 set = function(info, value)
Asa@21 96 ItemAuditor.db.char.auction_threshold = value
Asa@21 97 ItemAuditor:RefreshQAGroups()
Asa@21 98 end,
Asa@20 99 disabled = 'IsQADisabled',
Asa@20 100 order = 1,
Asa@20 101 },
Asa@13 102 refresh_qa = {
Asa@13 103 type = "execute",
Asa@13 104 name = "Refresh QA Thresholds",
Asa@13 105 desc = "Resets all Quick Auctions thresholds",
Asa@13 106 func = "RefreshQAGroups",
Asa@13 107 disabled = 'IsQADisabled',
Asa@20 108 order = 9,
Asa@13 109 },
Asa@21 110 }
Asa@21 111 },
Asa@21 112 crafting_options = {
Asa@21 113 name = "Crafting with Skillet",
Asa@21 114 desc = "/ia queue",
Asa@21 115 type = 'group',
Asa@21 116 disabled = function() return Skillet == nil end,
Asa@21 117 args = {
Asa@20 118 crafting_threshold = {
Asa@20 119 type = "select",
Asa@20 120 name = "Crafting Threshold",
Asa@20 121 desc = "Don't create items that will make less than this amount of profit",
Asa@20 122 values = craftingThresholdsDisplay,
Asa@20 123 get = function() return ItemAuditor.db.char.crafting_threshold end,
Asa@20 124 set = function(info, value) ItemAuditor.db.char.crafting_threshold = value end,
Asa@20 125 order = 11,
Asa@20 126 },
Asa@21 127 },
Asa@12 128 },
Asa@3 129 options = {
Asa@3 130 type = "execute",
Asa@3 131 name = "options",
Asa@3 132 desc = "Show Blizzard's options GUI",
Asa@3 133 func = "ShowOptionsGUI",
Asa@3 134 guiHidden = true,
Asa@3 135 },
Asa@18 136 queue = {
Asa@18 137 type = "execute",
Asa@18 138 name = "queue",
Asa@18 139 desc = "Queue",
Asa@18 140 func = "Queue",
Asa@18 141 guiHidden = true,
Asa@18 142 },
Asa@22 143 debug = {
Asa@22 144 type = "execute",
Asa@22 145 name = "debug",
Asa@22 146 desc = "Shows the debug frame",
Asa@22 147 func = function() ItemAuditor_DebugFrame:Show() end,
Asa@22 148 guiHidden = true,
Asa@28 149 },
Asa@28 150 invested = {
Asa@28 151 type = "execute",
Asa@28 152 name = "invested",
Asa@28 153 desc = "Shows what you have invested in",
Asa@28 154 func = "CreateFrames",
Asa@28 155 guiHidden = false,
Asa@28 156 },
Asa@38 157 suspend = {
Asa@38 158 type = "toggle",
Asa@38 159 name = "suspend",
Asa@38 160 desc = "Suspends ItemAuditor",
Asa@38 161 get = "IsEnabled",
Asa@38 162 set = "SetEnabled",
Asa@38 163 guiHidden = true,
Asa@38 164 },
Asa@3 165 },
Asa@3 166 }
Asa@3 167
Asa@38 168 function addon:SetEnabled(info, enable)
Asa@38 169 self.db.profile.addon_enabled = enable
Asa@38 170 if enable == self:IsEnabled() then
Asa@38 171 -- do nothing
Asa@38 172 elseif enable then
Asa@38 173 self:Enable()
Asa@38 174 self:Print('ItemAuditor is enabled.')
Asa@38 175 else
Asa@38 176 self:Disable()
Asa@38 177 self:Print('ItemAuditor is supended and will not watch for any events. Use "/ia suspend" to turn it back on.')
Asa@38 178 end
Asa@38 179 end
Asa@38 180
Asa@3 181 function addon:RegisterOptions()
Asa@3 182 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor")
Asa@3 183 LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", options, {"ia"})
Asa@3 184 end
Asa@3 185
Asa@7 186 local function pairsByKeys (t, f)
Asa@7 187 local a = {}
Asa@7 188 for n in pairs(t) do table.insert(a, n) end
Asa@7 189 table.sort(a, f)
Asa@7 190 local i = 0 -- iterator variable
Asa@7 191 local iter = function () -- iterator function
Asa@7 192 i = i + 1
Asa@7 193 if a[i] == nil then return nil
Asa@7 194 else return a[i], t[a[i]]
Asa@7 195 end
Asa@7 196 end
Asa@7 197 return iter
Asa@7 198 end
Asa@7 199
Asa@20 200 function addon:GetCraftingThreshold()
Asa@20 201 local key = ItemAuditor.db.char.crafting_threshold
Asa@20 202 return craftingThresholds[key]
Asa@20 203 end
Asa@20 204
Asa@20 205 function addon:GetAuctionThreshold()
Asa@20 206 return ItemAuditor.db.char.auction_threshold
Asa@20 207 end
Asa@20 208
Asa@13 209 function addon:GetAH()
Asa@13 210 return ItemAuditor.db.char.ah
Asa@13 211 end
Asa@13 212
Asa@13 213 function addon:SetAH(info, value)
Asa@13 214 ItemAuditor.db.char.ah = value
Asa@13 215 end
Asa@13 216
Asa@13 217 function addon:GetAHCut()
Asa@13 218 if ItemAuditor.db.char.ah == 1 then
Asa@13 219 return 0.05
Asa@13 220 end
Asa@13 221 return 0.15
Asa@13 222 end
Asa@13 223
Asa@13 224 function addon:GetAHFaction()
Asa@13 225 return AHFactions[ItemAuditor.db.char.ah]
Asa@13 226 end
Asa@13 227
Asa@3 228 function addon:ShowOptionsGUI()
Asa@3 229 InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
Asa@3 230 end
Asa@3 231
Asa@3 232