vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Enchantrix Addon for World of Warcraft(tm).
3 Version: 3.6.1 (Platypus)
4 Revision: $Id: EnxConfig.lua 881 2006-05-28 18:31:04Z aradan $
5  
6 Configuration functions.
7  
8 License:
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13  
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18  
19 You should have received a copy of the GNU General Public License
20 along with this program(see GLP.txt); if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ]]
23  
24 -- Global functions
25 local addonLoaded -- Enchantrix.Config.AddonLoaded()
26 local getFilterDefaults -- Enchantrix.Config.GetFilterDefaults()
27 local setFilter -- Enchantrix.Config.SetFilter()
28 local getFilter -- Enchantrix.Config.GetFilter()
29 local setFrame -- Enchantrix.Config.SetFrame()
30 local getFrameNames -- Enchantrix.Config.GetFrameNames()
31 local getFrameIndex -- Enchantrix.Config.GetFrameIndex()
32 local setLocale -- Enchantrix.Config.SetLocale()
33 local getLocale -- Enchantrix.Config.GetLocale()
34  
35 -- Local functions
36 local isValidLocale
37  
38 -- Default filter configuration
39 local filterDefaults = {
40 ['all'] = true,
41 ['barker'] = true,
42 ['embed'] = false,
43 ['counts'] = false,
44 ['terse'] = false,
45 ['valuate'] = true,
46 ['valuate-hsp'] = true,
47 ['valuate-median'] = true,
48 ['valuate-baseline'] = true,
49 ['locale'] = 'default',
50 ['printframe'] = 1,
51 }
52  
53 -- True if this filter value should be saved per character
54 local perCharacterFilter = {
55 ['embed'] = true,
56 ['counts'] = true,
57 ['terse'] = true,
58 ['printframe'] = true,
59 }
60  
61 function addonLoaded()
62 -- Remove unused/unknown filter values
63 for key in EnchantConfig.filters do
64 if getFilterDefaults(key) == nil then
65 setFilter(key, nil)
66 else
67 setFilter(key, getFilter(key))
68 end
69 end
70 end
71  
72 function getFilterDefaults(key)
73 return filterDefaults[key]
74 end
75  
76 function getFilter(filter)
77 local val = EnchantConfigChar.filters[filter]
78 if val == nil then
79 val = EnchantConfig.filters[filter]
80 end
81 if val == nil then
82 val = getFilterDefaults(filter)
83 end
84 return val
85 end
86  
87 function setFilter(key, value)
88 if (value == 'default') or (value == getFilterDefaults(key)) then
89 -- Don't save default values
90 value = nil
91 elseif value == 'on' then
92 value = true
93 elseif value == 'off' then
94 value = false
95 end
96 if perCharacterFilter[key] then
97 EnchantConfigChar.filters[key] = value
98 else
99 EnchantConfigChar.filters[key] = nil
100 end
101 EnchantConfig.filters[key] = value
102 end
103  
104 -- The following three functions were added by MentalPower to implement the /enx print-in command
105 function getFrameNames(index)
106  
107 local frames = {}
108 local frameName
109  
110 for i = 1, NUM_CHAT_WINDOWS do
111 -- name, fontSize, r, g, b, a, shown, locked, docked = GetChatWindowInfo(i)
112 local name = GetChatWindowInfo(i)
113  
114 if ( name == "" ) then
115 if (i == 1) then
116 name = _ENCH('TextGeneral')
117 elseif (i == 2) then
118 name = _ENCH('TextCombat')
119 end
120 end
121 frames[name] = i
122  
123 if i == index then
124 frameName = name
125 end
126 end
127  
128 return frames, frameName or ""
129 end
130  
131 function getFrameIndex()
132 return Enchantrix.Config.GetFilter('printframe')
133 end
134  
135 function setFrame(frame, chatprint)
136  
137 local frameNumber
138 local frameVal
139 frameVal = tonumber(frame)
140  
141 -- If no arguments are passed, then set it to the default frame.
142 if not (frame) then
143 frameNumber = 1;
144  
145 -- If the frame argument is a number then set our chatframe to that number.
146 elseif ((frameVal) ~= nil) then
147 frameNumber = frameVal;
148  
149 -- If the frame argument is a string, find out if there's a chatframe with that name, and set our chatframe to that index. If not set it to the default frame.
150 elseif (type(frame) == "string") then
151 allFrames = Enchantrix.Config.GetFrameNames();
152  
153 if (allFrames[frame]) then
154 frameNumber = allFrames[frame];
155  
156 else
157 frameNumber = 1;
158 end
159  
160 -- If the argument is something else, set our chatframe to it's default value.
161 else
162 frameNumber = 1;
163 end
164  
165 local _, frameName
166  
167 if (chatprint == true) then
168 _, frameName = Enchantrix.Config.GetFrameNames(frameNumber);
169  
170 if (Enchantrix.Config.GetFrameIndex() ~= frameNumber) then
171 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtPrintin'), frameName));
172 end
173 end
174  
175 Enchantrix.Config.SetFilter("printframe", frameNumber);
176  
177 if (chatprint == true) then
178 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtPrintin'), frameName));
179 Enchantrix.Command.SetKhaosSetKeyValue("printframe", frameNumber);
180 end
181 end
182  
183 function isValidLocale(param)
184 return (EnchantrixLocalizations and EnchantrixLocalizations[param])
185 end
186  
187 function setLocale(param, chatprint)
188 param = Enchantrix.Locale.DelocalizeFilterVal(param)
189  
190 if (param == 'default') or (param == 'off') then
191 Babylonian.SetOrder('')
192 validLocale = true
193 elseif (isValidLocale(param)) then
194 Babylonian.SetOrder(param)
195 validLocale = true
196 else
197 validLocale = false
198 end
199  
200 if chatprint then
201 if validLocale then
202 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActSet'), _ENCH('CmdLocale'), param))
203 Enchantrix.Command.SetKhaosSetKeyValue('locale', param)
204 else
205 Enchantrix.Util.ChatPrint(string.format(_ENCH("FrmtActUnknownLocale"), param))
206 local locales = " "
207 for locale, data in pairs(EnchantrixLocalizations) do
208 locales = locales .. " '" .. locale .. "' "
209 end
210 Enchantrix.Util.ChatPrint(locales)
211 end
212 end
213  
214 if (Enchantrix.State.Khaos_Registered) then
215 Khaos.refresh(nil, nil, true)
216 end
217  
218 Enchantrix.State.Locale_Changed = true
219 end
220  
221 function getLocale()
222 local locale = Enchantrix.Config.GetFilter('locale')
223 if locale ~= 'default' then
224 return locale
225 end
226 return GetLocale()
227 end
228  
229 Enchantrix.Config = {
230 Revision = "$Revision: 881 $",
231 AddonLoaded = addonLoaded,
232  
233 GetFilterDefaults = getFilterDefaults,
234 GetFilter = getFilter,
235 SetFilter = setFilter,
236  
237 GetFrameNames = getFrameNames,
238 GetFrameIndex = getFrameIndex,
239 SetFrame = setFrame,
240  
241 SetLocale = setLocale,
242 GetLocale = getLocale,
243 }