vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Global variables |
2 | TitanSettings = nil; |
||
3 | TitanPlayerSettings = nil; |
||
4 | TitanPluginSettings = nil; |
||
5 | TitanPanelSettings = nil; |
||
6 | TitanOldSettings = nil; |
||
7 | |||
8 | TITAN_LAST_UPDATED = "April 27th, 2006" |
||
9 | TITAN_VERSION = "2.18.11000"; |
||
10 | TITAN_FIRST_LOAD = nil; |
||
11 | |||
12 | -- Constants |
||
13 | TITAN_NIL = "Titan Nil"; |
||
14 | |||
15 | function TitanVariables_InitTitanSettings() |
||
16 | if (not TitanSettings) then |
||
17 | TitanSettings = {}; |
||
18 | end |
||
19 | |||
20 | -- Backup Settings from old version that doesn't support settings per char |
||
21 | if ( not TitanSettings.Version ) then |
||
22 | TitanVariables_BackupOldSettings(); |
||
23 | end |
||
24 | |||
25 | -- Settings migration from version to version |
||
26 | if ( TitanVariables_CompareVersion(TitanSettings.Version, "1.22.1300") < 0 ) then |
||
27 | TitanVariables_MigrateTo_1_22_1300(); |
||
28 | end |
||
29 | |||
30 | TitanOldSettings = TitanSettings.OldSettings; |
||
31 | TitanSettings.Version = TITAN_VERSION; |
||
32 | TITAN_PANEL_SELECTED = "Main"; |
||
33 | end |
||
34 | |||
35 | function TitanVariables_InitDetailedSettings() |
||
36 | if (not TitanPlayerSettings) then |
||
37 | TitanVariables_InitPlayerSettings(); |
||
38 | if (TitanPlayerSettings) then |
||
39 | -- Migrate old settings |
||
40 | if (TITAN_FIRST_LOAD) then |
||
41 | TitanVariables_MigrateOldSettings(); |
||
42 | end |
||
43 | |||
44 | -- Syncronize Plugins/Panel settings |
||
45 | TitanVariables_SyncPluginSettings(); |
||
46 | TitanVariables_SyncPanelSettings(); |
||
47 | end |
||
48 | end |
||
49 | end |
||
50 | |||
51 | function TitanVariables_InitPlayerSettings() |
||
52 | -- Titan should not be nil |
||
53 | if (not TitanSettings) then |
||
54 | return; |
||
55 | end |
||
56 | |||
57 | -- Init TitanSettings.Players |
||
58 | if (not TitanSettings.Players ) then |
||
59 | TitanSettings.Players = {}; |
||
60 | end |
||
61 | |||
62 | local playerName = UnitName("player"); |
||
63 | local serverName = GetCVar("realmName"); |
||
64 | -- Do nothing if player name is not available |
||
65 | if (playerName == nil or playerName == UNKNOWNOBJECT or playerName == UKNOWNBEING) then |
||
66 | return; |
||
67 | end |
||
68 | |||
69 | if (TitanSettings.Players[playerName] and not TitanSettings[playerName .. "@" .. serverName]) then |
||
70 | TitanSettings.Players[playerName.."@"..serverName] = TitanSettings.Players[playerName]; |
||
71 | TitanSettings.Players[playerName]=nil; |
||
72 | end |
||
73 | |||
74 | -- Init TitanPlayerSettings |
||
75 | if (not TitanSettings.Players[playerName.."@"..serverName]) then |
||
76 | TitanSettings.Players[playerName.."@"..serverName] = {}; |
||
77 | TitanSettings.Players[playerName.."@"..serverName].Plugins = {}; |
||
78 | TitanSettings.Players[playerName.."@"..serverName].Panel = {}; |
||
79 | TITAN_FIRST_LOAD = 1; |
||
80 | end |
||
81 | |||
82 | -- Set global variables |
||
83 | TitanPlayerSettings = TitanSettings.Players[playerName.."@"..serverName]; |
||
84 | TitanPluginSettings = TitanPlayerSettings["Plugins"]; |
||
85 | TitanPanelSettings = TitanPlayerSettings["Panel"]; |
||
86 | end |
||
87 | |||
88 | function TitanVariables_SyncPluginSettings() |
||
89 | -- Init each and every plugin |
||
90 | for id, plugin in TitanPlugins do |
||
91 | if (plugin and plugin.savedVariables) then |
||
92 | -- Init savedVariables table |
||
93 | if (not TitanPluginSettings[id]) then |
||
94 | TitanPluginSettings[id] = {}; |
||
95 | end |
||
96 | |||
97 | -- Synchronize registered and saved variables |
||
98 | TitanVariables_SyncRegisterSavedVariables(plugin.savedVariables, TitanPluginSettings[id]); |
||
99 | else |
||
100 | -- Remove plugin savedVariables table if there's one |
||
101 | if (TitanPluginSettings[id]) then |
||
102 | TitanPluginSettings[id] = nil; |
||
103 | end |
||
104 | end |
||
105 | end |
||
106 | end |
||
107 | |||
108 | function TitanVariables_SyncPanelSettings() |
||
109 | -- Synchronize registered and saved variables |
||
110 | TitanVariables_SyncRegisterSavedVariables(TITAN_PANEL_SAVED_VARIABLES, TitanPanelSettings); |
||
111 | end |
||
112 | |||
113 | function TitanVariables_SyncRegisterSavedVariables(registeredVariables, savedVariables) |
||
114 | if (registeredVariables and savedVariables) then |
||
115 | -- Init registeredVariables |
||
116 | for index, value in registeredVariables do |
||
117 | if (not TitanUtils_TableContainsIndex(savedVariables, index)) then |
||
118 | savedVariables[index] = value; |
||
119 | end |
||
120 | end |
||
121 | |||
122 | -- Remove out-of-date savedVariables |
||
123 | for index, value in savedVariables do |
||
124 | if (not TitanUtils_TableContainsIndex(registeredVariables, index)) then |
||
125 | savedVariables[index] = nil; |
||
126 | end |
||
127 | end |
||
128 | end |
||
129 | end |
||
130 | |||
131 | function TitanGetVar(id, var) |
||
132 | if (id and var and TitanPluginSettings and TitanPluginSettings[id]) then |
||
133 | return TitanUtils_Ternary(TitanPluginSettings[id][var] == TITAN_NIL, nil, TitanPluginSettings[id][var]); |
||
134 | end |
||
135 | end |
||
136 | |||
137 | function TitanSetVar(id, var, value) |
||
138 | if (id and var and TitanPluginSettings and TitanPluginSettings[id]) then |
||
139 | TitanPluginSettings[id][var] = TitanUtils_Ternary(value, value, TITAN_NIL); |
||
140 | end |
||
141 | end |
||
142 | |||
143 | function TitanGetVarTable(id, var, position) |
||
144 | if (id and var and TitanPluginSettings and TitanPluginSettings[id]) then |
||
145 | return TitanUtils_Ternary(TitanPluginSettings[id][var][position] == TITAN_NIL, nil, TitanPluginSettings[id][var][position]); |
||
146 | end |
||
147 | end |
||
148 | |||
149 | function TitanSetVarTable(id, var, position, value) |
||
150 | if (id and var and TitanPluginSettings and TitanPluginSettings[id]) then |
||
151 | TitanPluginSettings[id][var][position] = TitanUtils_Ternary(value, value, TITAN_NIL); |
||
152 | end |
||
153 | end |
||
154 | |||
155 | function TitanToggleVar(id, var) |
||
156 | if (id and var and TitanPluginSettings and TitanPluginSettings[id]) then |
||
157 | TitanSetVar(id, var, TitanUtils_Toggle(TitanGetVar(id, var))); |
||
158 | end |
||
159 | end |
||
160 | |||
161 | function TitanPanelGetVar(var) |
||
162 | if (var and TitanPanelSettings) then |
||
163 | return TitanUtils_Ternary(TitanPanelSettings[var] == TITAN_NIL, nil, TitanPanelSettings[var]); |
||
164 | end |
||
165 | end |
||
166 | |||
167 | function TitanPanelSetVar(var, value) |
||
168 | if (var and TitanPanelSettings) then |
||
169 | TitanPanelSettings[var] = TitanUtils_Ternary(value, value, TITAN_NIL); |
||
170 | end |
||
171 | end |
||
172 | |||
173 | function TitanPanelToggleVar(var) |
||
174 | if (var and TitanPanelSettings) then |
||
175 | TitanPanelSetVar(var, TitanUtils_Toggle(TitanPanelGetVar(var))); |
||
176 | end |
||
177 | end |
||
178 | |||
179 | function TitanVariables_BackupOldSettings() |
||
180 | if (TitanSettings.Players) then |
||
181 | -- New OldSettings and copy over the existing settings |
||
182 | TitanSettings.OldSettings = {}; |
||
183 | TitanSettings.OldSettings.Players = TitanSettings.Players; |
||
184 | TitanSettings.OldSettings.Panel = TitanSettings.Panel; |
||
185 | |||
186 | -- Clear the existing settings |
||
187 | TitanSettings.Players = nil; |
||
188 | TitanSettings.Panel = nil; |
||
189 | TitanSettings.Volume = nil; |
||
190 | TitanSettings.UIScale = nil; |
||
191 | TitanSettings.Tooltip = nil; |
||
192 | end |
||
193 | end |
||
194 | |||
195 | function TitanVariables_MigrateOldSettings() |
||
196 | local playerName = UnitName("player"); |
||
197 | if (TITAN_FIRST_LOAD and TitanOldSettings) then |
||
198 | -- Old player settings migration |
||
199 | if (TitanOldSettings.Players[playerName]) then |
||
200 | TitanPluginSettings.Clock = TitanOldSettings.Players[playerName].Clock; |
||
201 | end |
||
202 | |||
203 | -- Old panel settings migration |
||
204 | if (TitanOldSettings.Panel) then |
||
205 | -- Transparency |
||
206 | TitanPanelSettings.Transparency = TitanOldSettings.Panel.Transparency; |
||
207 | |||
208 | -- AutoHide |
||
209 | TitanPanelSettings.AutoHide = TitanMigrate(TitanOldSettings.Panel.AutoHide); |
||
210 | |||
211 | -- Buttons |
||
212 | TitanPanelSettings.Buttons = TitanVariables_AppendNonMovableButtons(TitanOldSettings.Panel.Buttons); |
||
213 | |||
214 | -- Bag |
||
215 | if (TitanPluginSettings.Bag and TitanOldSettings.Panel.Bag) then |
||
216 | TitanPluginSettings.Bag.CountAmmoPouchSlots = TitanMigrate(TitanOldSettings.Panel.Bag.CountAmmoPouchSlots); |
||
217 | TitanPluginSettings.Bag.ShowUsedSlots = TitanMigrate(TitanOldSettings.Panel.Bag.ShowUsedSlots); |
||
218 | end |
||
219 | |||
220 | -- Coords |
||
221 | if (TitanPluginSettings.Coords and TitanOldSettings.Panel.Location) then |
||
222 | TitanPluginSettings.Coords.ShowColoredText = TitanMigrate(TitanOldSettings.Panel.Location.ShowColoredText); |
||
223 | TitanPluginSettings.Coords.ShowCoordsOnMap = TitanMigrate(TitanOldSettings.Panel.Location.ShowCoordsOnMap); |
||
224 | TitanPluginSettings.Coords.ShowZoneText = TitanMigrate(TitanOldSettings.Panel.Location.ShowZoneText); |
||
225 | end |
||
226 | |||
227 | -- FPS |
||
228 | if (TitanPluginSettings.FPS and TitanOldSettings.Panel.FPS) then |
||
229 | TitanPluginSettings.FPS.ShowColoredText = TitanMigrate(TitanOldSettings.Panel.FPS.ShowColoredText); |
||
230 | end |
||
231 | |||
232 | -- Latency |
||
233 | if (TitanPluginSettings.Latency and TitanOldSettings.Panel.Latency) then |
||
234 | TitanPluginSettings.Latency.ShowColoredText = TitanMigrate(TitanOldSettings.Panel.Latency.ShowColoredText); |
||
235 | end |
||
236 | |||
237 | -- XP |
||
238 | if (TitanPluginSettings.XP and TitanOldSettings.Panel.XP) then |
||
239 | TitanPluginSettings.XP.ShowXPPerHourSession = TitanMigrate(TitanOldSettings.Panel.XP.ShowXPPerHourSession); |
||
240 | end |
||
241 | end |
||
242 | end |
||
243 | end |
||
244 | |||
245 | function TitanMigrate(value) |
||
246 | return TitanUtils_Ternary(value, value, TITAN_NIL); |
||
247 | end |
||
248 | |||
249 | function TitanVariables_MigrateTo_1_22_1300() |
||
250 | if ( TitanSettings and TitanSettings.Players and type(TitanSettings.Players) == "table" ) then |
||
251 | for index, value in TitanSettings.Players do |
||
252 | if ( value and value.Panel and value.Panel.Buttons ) then |
||
253 | value.Panel.Buttons = TitanVariables_AppendNonMovableButtons(value.Panel.Buttons); |
||
254 | end |
||
255 | end |
||
256 | end |
||
257 | end |
||
258 | |||
259 | function TitanVariables_AppendNonMovableButtons(buttons) |
||
260 | if ( buttons and type(buttons) == "table" ) then |
||
261 | for index, id in TITAN_PANEL_NONMOVABLE_PLUGINS do |
||
262 | if ( not TitanUtils_TableContainsValue(buttons, id) ) then |
||
263 | table.insert(buttons, id); |
||
264 | end |
||
265 | end |
||
266 | end |
||
267 | return buttons; |
||
268 | end |
||
269 | |||
270 | function TitanVariables_CompareVersion(version1, version2) |
||
271 | local mainVer1, subVer1, uiVer1, betaVer1 = TitanVariables_ParseVersion(version1); |
||
272 | local mainVer2, subVer2, uiVer2, betaVer2 = TitanVariables_ParseVersion(version2); |
||
273 | |||
274 | if ( mainVer1 == mainVer2 ) then |
||
275 | if ( subVer1 == subVer2 ) then |
||
276 | if ( uiVer1 == uiVer2 ) then |
||
277 | return (betaVer1 - betaVer2); |
||
278 | else |
||
279 | return (uiVer1 - uiVer2); |
||
280 | end |
||
281 | else |
||
282 | return (subVer1 - subVer2); |
||
283 | end |
||
284 | else |
||
285 | return (mainVer1 - mainVer2); |
||
286 | end |
||
287 | end |
||
288 | |||
289 | function TitanVariables_ParseVersion(version) |
||
290 | if ( version ) then |
||
291 | local verInfo = {}; |
||
292 | for w in string.gfind(version, "%w+") do |
||
293 | table.insert(verInfo, w); |
||
294 | end |
||
295 | |||
296 | local mainVer, subVer, uiVer, betaVer; |
||
297 | mainVer = tonumber(verInfo[1]); |
||
298 | subVer = tonumber(verInfo[2]); |
||
299 | uiVer = tonumber(verInfo[3]); |
||
300 | if ( not verInfo[4] ) then |
||
301 | betaVer = 100; |
||
302 | else |
||
303 | betaVer = tonumber(string.sub(verInfo[4], 5, -1)); |
||
304 | end |
||
305 | return mainVer, subVer, uiVer, betaVer; |
||
306 | else |
||
307 | return 0, 0, 0, 0; |
||
308 | end |
||
309 | end |
||
310 | |||
311 | function TitanVariables_UseSettings() |
||
312 | TitanCopyPlayerSettings = TitanSettings.Players[this.value]; |
||
313 | TitanCopyPluginSettings = TitanCopyPlayerSettings["Plugins"]; |
||
314 | TitanCopyPanelSettings = TitanCopyPlayerSettings["Panel"]; |
||
315 | |||
316 | for index, id in TitanPanelSettings["Buttons"] do |
||
317 | local currentButton = TitanUtils_GetButton(TitanPanelSettings["Buttons"][index]); |
||
318 | currentButton:Hide(); |
||
319 | end |
||
320 | |||
321 | for index, id in TitanCopyPanelSettings do |
||
322 | TitanPanelSetVar(index, TitanCopyPanelSettings[index]); |
||
323 | end |
||
324 | |||
325 | for index, id in TitanCopyPluginSettings do |
||
326 | for var, id in TitanCopyPluginSettings[index] do |
||
327 | TitanSetVar(index, var, TitanCopyPluginSettings[index][var]) |
||
328 | end |
||
329 | end |
||
330 | |||
331 | TitanPanel_InitPanelBarButton(); |
||
332 | TitanPanel_InitPanelButtons(); |
||
333 | |||
334 | if (TitanPanelGetVar("AutoHide")) then |
||
335 | TitanPanelBarButton_Hide("TitanPanelBarButton", TitanPanelGetVar("Position")); |
||
336 | end |
||
337 | if (TitanPanelGetVar("AuxAutoHide")) then |
||
338 | TitanPanelBarButton_Hide("TitanPanelAuxBarButton", TITAN_PANEL_PLACE_BOTTOM); |
||
339 | end |
||
340 | TitanPanelRightClickMenu_Close(); |
||
341 | end |