8f4bc83 - Initial commit
[wowui.git] / RaidFrameIndicatorsConfig.lua
1 local Defaults = {}
2
3 function CreateDefaults()
4     Defaults.profile = {
5         indicatorFont = "Arial Narrow",
6         showIcons = true,
7         enabled = true,
8     };
9     for i = 1, 5 do
10         Defaults.profile["auras"..i] = "";
11         Defaults.profile["textSize"..i] = 10;
12         Defaults.profile["color"..i] = {r = 1, g = 1, b = 1, a = 1,};
13         Defaults.profile["mine"..i] = false;
14         Defaults.profile["stack"..i] = true;
15         Defaults.profile["debuffColor"..i] = false;
16         Defaults.profile["showText"..i] = true;
17         Defaults.profile["showIcon"..i] = true;
18         Defaults.profile["useDefaultIcon"..i] = true;
19         Defaults.profile["iconSize"..i] = 10;
20     end
21 end
22
23 local Options = {}
24 function CreateOptions ()
25     Options = {
26         type = 'group',
27         childGroups = 'tree',
28         get = function(item) return Indicators.db.profile[item[#item]] end,
29         set = function(item, value) Indicators.db.profile[item[#item]] = value; Indicators:RefreshConfig() end,
30         args  = {
31             indicatorFont = {
32                 type = 'select',
33                 dialogControl = "LSM30_Font",
34                 name = "Indicator Font",
35                 desc = "Adjust the font used for the indicators",
36                 values = AceGUIWidgetLSMlists.font,
37                 order = 17,
38             },
39             enabled = {
40                 type = "toggle",
41                 name = "Enabled",
42                 desc = "Enable/Disable indicators",
43                 order = 18,
44                 set = function(item, value)
45                     Indicators.db.profile[item[#item]] = value
46                     if value == true then
47                         Indicators:OnEnable()
48                     else
49                         Indicators:OnDisable()
50                     end
51                 end,
52             }
53         }
54     }
55
56     --- Add options for each indicator
57     local indicatorNames = {"Top Left", "Top Right", "Center", "Bottom Left", "Bottom Right"}
58     for i = 1, 5 do
59         Options.args["i"..i] = {}
60         Options.args["i"..i].type = 'group'
61         Options.args["i"..i].name = indicatorNames[i]
62         Options.args["i"..i].order = i*10+10
63         Options.args["i"..i].args = {}
64         Options.args["i"..i].args["auras"..i] = {
65             type = "input",
66             name = "Buffs/Debuffs",
67             desc = "The buffs/debuffs to show in this indicator. Put each buff/debuff on a separate line. You can use 'Magic/Poison/Curse/Disease' to show any debuff of that type.",
68             multiline = true,
69             order = 1,
70             width = "full",
71         }
72         Options.args["i"..i].args["mine"..i] = {
73             type = "toggle",
74             name = "Mine only",
75             desc = "Only show buffs/debuffs cast by me",
76             order = 10,
77         }
78         Options.args["i"..i].args.textHeader = {
79             type = "header",
80             name = "Text Counter",
81             order = 100,
82         }
83         Options.args["i"..i].args["showText"..i] = {
84             type = "toggle",
85             name = "Show text counter",
86             desc = "Show a text counter specifying the time left of the buff/debuff",
87             order = 110,
88         }
89         Options.args["i"..i].args["textSize"..i] = {
90             type = "range",
91             name = "Size",
92             desc = "Text size",
93             min = 1,
94             max = 30,
95             step = 1,
96             order = 120,
97             width = "full",
98         }
99         Options.args["i"..i].args.coloringHeader = {
100             type = "header",
101             name = "Color",
102             order = 150,
103         }
104         Options.args["i"..i].args["debuffColor"..i] = {
105             type = "toggle",
106             name = "Color by debuff type",
107             desc = "Color the text depending on the debuff type, will override any other coloring (poison = green, magic = blue etc)",
108             order = 165,
109         }
110         Options.args["i"..i].args["color"..i] = {
111             type = "color",
112             name = "Default color",
113             desc = "Default color of the indicator",
114             get = function(item)
115                 local t = Indicators.db.profile[item[#item]]
116                 return t.r, t.g, t.b, t.a
117             end,
118             set = function(item, r, g, b, a)
119                 local t = Indicators.db.profile[item[#item]]
120                 t.r, t.g, t.b, t.a = r, g, b, a
121                 Indicators:RefreshConfig()
122             end,
123             order = 170,
124         }
125         Options.args["i"..i].args.stackHeader = {
126             type = "header",
127             name = "Stack Size",
128             order = 200,
129         }
130         Options.args["i"..i].args["stack"..i] = {
131             type = "toggle",
132             name = "Show stack size",
133             desc = "Show stack size for buffs/debuffs that stack",
134             order = 210,
135         }
136         Options.args["i"..i].args.iconHeader = {
137             type = "header",
138             name = "Icon",
139             order = 300,
140         }
141         Options.args["i"..i].args["showIcon"..i] = {
142             type = "toggle",
143             name = "Show icon",
144             desc = "Show an icon if the buff/debuff are on the unit",
145             order = 310,
146         }
147         Options.args["i"..i].args["useDefaultIcon"..i] = {
148             type = "toggle",
149             name = "Use default icon",
150             desc = "Show default icon instead of the ability's.",
151             disabled = function () return not Indicators.db.profile["showIcon"..i] end,
152             order = 315,
153         }
154         Options.args["i"..i].args["iconSize"..i] = {
155             type = "range",
156             name = "Icon size",
157             desc = "Icon size",
158             min = 1,
159             max = 30,
160             step = 1,
161             order = 320,
162             width = "full",
163         }
164     end
165 end
166
167 local SlashCommands = {
168         type    = "group",
169     args  = {
170         enable = {
171             type = "execute",
172             name = "enable",
173             desc = "Enable indicators",
174             func = function() Indicators.db.profile.enabled = true; Indicators:OnEnable() end,
175         },
176         disable = {
177             type = "execute",
178             name = "disable",
179             desc = "Disable indicators",
180             func = function() Indicators.db.profile.enabled = false; Indicators:OnDisable() end,
181         },
182         config = {
183             type = "execute",
184             name = "config",
185             desc = "Show config",
186             func = function() Indicators:ShowConfig() end,
187         },
188     }
189 }
190
191 function Indicators:ShowConfig()
192     InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Profile)
193     InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Indicators)
194 end
195
196 function Indicators:SetupOptions()
197     -- Set up defaults
198     CreateDefaults()
199     self.db = LibStub("AceDB-3.0"):New("IndicatorsDB", Defaults)
200
201     -- Profile handling
202     local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
203
204     -- Get the config up
205     CreateOptions()
206     local config = LibStub("AceConfig-3.0")
207     config:RegisterOptionsTable("Raid Frame Indicators", Options)
208     config:RegisterOptionsTable("Raid Frame Indicators Profiles", profiles)
209
210     -- Register slash commands
211     config:RegisterOptionsTable("Raid Frame Indicators Options", SlashCommands, {"indicators", "raidframeindicators"})
212
213     -- Add to Blizz option pane
214     local dialog = LibStub("AceConfigDialog-3.0")
215     self.optionsFrames = {}
216     self.optionsFrames.Indicators = dialog:AddToBlizOptions("Raid Frame Indicators","Raid Frame Indicators")
217     self.optionsFrames.Profile = dialog:AddToBlizOptions("Raid Frame Indicators Profiles","Profiles", "Raid Frame Indicators")
218 end