comparison Modules/Config.lua @ 31:90d58723ac0a

- Removed all BeanCounter checks in files. + Added a new module: BeanCounter Support. This module will now take care of preventing mail opening while BeanCounter is scanning. + Added AceHook library for the BeanCounter Support module. ~ Sorted the Core.lua OnInitialize to properly toggle modules before doing time consuming things. ~ All module comments are now a property of the modules themselves and can be retrieved with (string)?.moduleDescription? and (bool)?.moduleRequired?. ~ All module references are now called ?mod?. ! Added a new config group: Modules. This group will show the module statuses and descriptions and it will contain all optional modules (with their settings) as subgroups. - Removed all libraries from the repository.
author Zerotorescue
date Fri, 10 Sep 2010 18:59:58 +0200
parents 2dd6005d41f3
children b79bb7b449c3
comparison
equal deleted inserted replaced
30:4ab03ed958ed 31:90d58723ac0a
1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
2 local Config = MailOpener:NewModule("Config", "AceEvent-3.0", "AceTimer-3.0"); 2 local mod = MailOpener:NewModule("Config", "AceEvent-3.0", "AceTimer-3.0");
3 3
4 --[[ 4 mod.moduleDescription = "Builds and loads the config frame(s) and handles the slash commands. Automatically loaded when needed.";
5 Module name: Config 5 mod.moduleRequired = false;
6 Description: Builds and loads the config frame(s) and handles the slash commands.
7 Required: No (default off).
8 ]]
9 6
10 local Media = LibStub("LibSharedMedia-3.0"); 7 local Media = LibStub("LibSharedMedia-3.0");
11 Media:Register("sound", "Cartoon FX", [[Sound\Doodad\Goblin_Lottery_Open03.wav]]); 8 Media:Register("sound", "Cartoon FX", [[Sound\Doodad\Goblin_Lottery_Open03.wav]]);
12 Media:Register("sound", "Cheer", [[Sound\Event Sounds\OgreEventCheerUnique.wav]]); 9 Media:Register("sound", "Cheer", [[Sound\Event Sounds\OgreEventCheerUnique.wav]]);
13 Media:Register("sound", "Explosion", [[Sound\Doodad\Hellfire_Raid_FX_Explosion05.wav]]); 10 Media:Register("sound", "Explosion", [[Sound\Doodad\Hellfire_Raid_FX_Explosion05.wav]]);
24 Media:Register("sound", "Whisper Ping", [[Sound\interface\iTellMessage.wav]]); 21 Media:Register("sound", "Whisper Ping", [[Sound\interface\iTellMessage.wav]]);
25 Media:Register("sound", "You Will Die!", [[Sound\Creature\CThun\CThunYouWillDIe.wav]]); 22 Media:Register("sound", "You Will Die!", [[Sound\Creature\CThun\CThunYouWillDIe.wav]]);
26 23
27 local AceConfigDialog; 24 local AceConfigDialog;
28 25
29 function Config:OnEnable() 26 function mod:OnEnable()
30 MailOpener:Debug("Enabling |cff00ffffConfig|r module."); 27 MailOpener:Debug("Enabling |cff00ffffConfig|r module.");
31 end 28 end
32 29
33 function Config:CommandHandler(message) 30 function mod:CommandHandler(message)
34 local cmd, arg = string.split(" ", (message or ""), 2); 31 local cmd, arg = string.split(" ", (message or ""), 2);
35 cmd = string.lower(cmd); 32 cmd = string.lower(cmd);
36 33
37 if cmd == "c" or cmd == "config" or cmd == "conf" or cmd == "option" or cmd == "options" or cmd == "opt" or cmd == "setting" or cmd == "settings" then 34 if cmd == "c" or cmd == "config" or cmd == "conf" or cmd == "option" or cmd == "options" or cmd == "opt" or cmd == "setting" or cmd == "settings" then
38 self:Show(); 35 self:Show();
60 else 57 else
61 print("Wrong command, available: /mo config (or /mo c)"); 58 print("Wrong command, available: /mo config (or /mo c)");
62 end 59 end
63 end 60 end
64 61
65 function Config:Load() 62 function mod:Load()
66 if not AceConfigDialog then 63 if not AceConfigDialog then
67 local options = self:GetOptions(); 64 local options = self:GetOptions();
68 65
69 -- Build options dialog 66 -- Build options dialog
70 AceConfigDialog = LibStub("AceConfigDialog-3.0"); 67 AceConfigDialog = LibStub("AceConfigDialog-3.0");
81 -- Add to the blizzard addons options thing 78 -- Add to the blizzard addons options thing
82 AceConfigDialog:AddToBlizOptions("Mail Opener"); 79 AceConfigDialog:AddToBlizOptions("Mail Opener");
83 end 80 end
84 end 81 end
85 82
86 function Config:Show() 83 function mod:Show()
87 self:Load(); 84 self:Load();
88 85
89 AceConfigDialog:Open("Mail Opener"); 86 AceConfigDialog:Open("Mail Opener");
90 end 87 end
91 88
92 function Config:GetOptions() 89 function mod:GetOptions()
93 local options = { 90 local options = {
94 type = "group", 91 type = "group",
95 name = "Mail Opener", 92 name = "Mail Opener",
96 childGroups = "tree", 93 childGroups = "tree",
97 args = { 94 args = {
108 options.args.profiles.order = 1000; -- we want this as last group 105 options.args.profiles.order = 1000; -- we want this as last group
109 106
110 return options; 107 return options;
111 end 108 end
112 109
113 function Config:GetModuleOptions(options) 110 -- Get the options group for every one of our modules
111 function mod:GetModuleOptions(options)
112 -- Go through all our modules
114 for name, module in MailOpener:IterateModules() do 113 for name, module in MailOpener:IterateModules() do
114 -- Look if they even have an options group
115 if module.GetOptionsGroup then 115 if module.GetOptionsGroup then
116 options.args[name] = module:GetOptionsGroup(); 116 -- Get that options group
117 local moduleGroup = module:GetOptionsGroup();
118
119 -- If it's set to be a subgroup of the modules group, put it there
120 if moduleGroup['type'] == "modulesSubGroup" then
121 moduleGroup['type'] = "group";
122
123 -- If the modules group doesn't exist yet, make it
124 if options.args.Modules == nil then
125 options.args.Modules = self:GetModuleGroupsContainer();
126 end
127
128 -- Add to the modules sub group
129 options.args.Modules.args[name] = moduleGroup;
130 else
131 options.args[name] = moduleGroup;
132 end
133
117 end 134 end
118 end 135 end
119 136
120 return options; 137 return options;
121 end 138 end
122 139
123 function Config:GetGeneralOptions() 140 function mod:GetModuleGroupsContainer()
141 local modulesConfigGroup = {
142 order = 400,
143 type = "group",
144 childGroups = "tree",
145 name = "Modules",
146 desc = "Change settings for modules or toggle them on or off.",
147 args = {
148 General = {
149 order = 10,
150 type = "group",
151 inline = true,
152 name = "Modules Status",
153 args = {
154 headerName = {
155 order = 0,
156 width = "normal",
157 type = "description",
158 fontSize = "medium",
159 name = "|cfffed000Module Name|r",
160 },
161 headerStatus = {
162 order = 1,
163 width = "half",
164 type = "description",
165 fontSize = "medium",
166 name = "|cfffed000Status|r",
167 },
168 headerDefault = {
169 order = 2,
170 width = "normal",
171 type = "description",
172 fontSize = "medium",
173 name = "|cfffed000Default Status|r",
174 },
175 headerseperator = {
176 order = 3,
177 type = "description",
178 name = "",
179 },
180 },
181 },
182 },
183 };
184
185 -- Make a list of modules and their statuses
186 local orderNo = 5;
187 for moduleName, module in MailOpener:IterateModules() do
188 -- Display each module as NAME CURRENT STATUS DEFAULT STATUS
189
190 -- Name
191 modulesConfigGroup.args.General.args[moduleName .. "name"] = {
192 order = orderNo,
193 width = "normal",
194 type = "description",
195 fontSize = "medium",
196 name = function()
197 return moduleName;
198 end,
199 };
200 -- Current status
201 modulesConfigGroup.args.General.args[moduleName .. "status"] = {
202 order = ( orderNo + 1 ),
203 width = "half",
204 type = "description",
205 fontSize = "medium",
206 name = function()
207 if module:IsEnabled() then
208 return "|cff00ff00Enabled|r";
209 else
210 return "|cffff0000Disabled|r";
211 end
212 end,
213 };
214 -- Default status
215 modulesConfigGroup.args.General.args[moduleName .. "default"] = {
216 order = ( orderNo + 2 ),
217 width = "normal",
218 type = "description",
219 fontSize = "medium",
220 name = function()
221 local desc = "";
222 if MailOpener.db.profile.modules[moduleName] == nil or MailOpener.db.profile.modules[moduleName] == true then
223 desc = "|cff00ff00Enabled|r";
224 else
225 desc = "|cffff0000Disabled|r";
226 end
227
228 if module.moduleRequired then
229 desc = desc .. " (Required module)";
230 end
231
232 return desc;
233 end,
234 };
235
236 -- Seperator
237 modulesConfigGroup.args.General.args[moduleName .. "seperator"] = {
238 order = ( orderNo + 3 ),
239 type = "description",
240 name = "",
241 };
242
243 if module.moduleDescription then
244 -- Description
245 modulesConfigGroup.args.General.args[moduleName .. "description"] = {
246 order = ( orderNo + 4 ),
247 type = "description",
248 name = function()
249 return "|cfffed000" .. module.moduleDescription .. "|r";
250 end,
251 };
252 end
253
254 orderNo = orderNo + 5;
255 end
256
257 return modulesConfigGroup;
258 end
259
260 function mod:GetGeneralOptions()
124 local generalConfigGroup = { 261 local generalConfigGroup = {
125 order = 100, 262 order = 100,
126 type = "group", 263 type = "group",
127 name = "General", 264 name = "General",
128 desc = "Change general Mail Opener settings.", 265 desc = "Change general Mail Opener settings.",
237 }; 374 };
238 375
239 return generalConfigGroup; 376 return generalConfigGroup;
240 end 377 end
241 378
242 function Config:GetNotificationsOptions() 379 function mod:GetNotificationsOptions()
243 local notificationsConfigGroup = { 380 local notificationsConfigGroup = {
244 order = 200, 381 order = 200,
245 type = "group", 382 type = "group",
246 name = "Notifications", 383 name = "Notifications",
247 desc = "Toggle notifications.", 384 desc = "Toggle notifications.",