vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | -- CVar Keywords |
||
3 | CSM_CVARNAME = "cvarname"; |
||
4 | CSM_CVARVALUE= "cvarval"; |
||
5 | CSM_CVARCALLBACK = "callback"; |
||
6 | UUI_LAST_PLAYER = "uui_last_player"; |
||
7 | UUI_LAST_REALM = "uui_last_realm"; |
||
8 | |||
9 | |||
10 | UltimateUIMaster_CVars = { }; |
||
11 | UltimateUIMaster_CVarsToRegister = { }; |
||
12 | UltimateUIMaster_CVarsToSet = { }; |
||
13 | UltimateUIMaster_Callbacks = { }; |
||
14 | -- RegisterForSave('UltimateUIMaster_CVars'); |
||
15 | |||
16 | -- Debug tools |
||
17 | ULTIMATEUIMASTER_DEBUG_CVAR = 0; |
||
18 | CSM_DEBUG_CVAR = "ULTIMATEUIMASTER_DEBUG_CVAR"; |
||
19 | |||
20 | --[[ |
||
21 | UltimateUIMaster_RegisterCVar |
||
22 | |||
23 | Usage: |
||
24 | UltimateUIMaster_RegisterCVar(uui_cvar, [uui_defvalue, uui_callback ]) |
||
25 | |||
26 | uui_cvar is the "UUI_CVAR_NAME" you used to use. |
||
27 | uui_defvalue is the default value you're storing. |
||
28 | uui_callback will be called when the cvars are loaded |
||
29 | |||
30 | |||
31 | ]] |
||
32 | function UltimateUI_RegisterCVar (uui_cvar, uui_defvalue, uui_callback) |
||
33 | -- Sea.io.dprint( CSM_DEBUG_CVAR, "REGISTER: "..uui_cvar); |
||
34 | |||
35 | if ( uui_cvar == nil ) then return false; end |
||
36 | if ( uui_defvalue == nil) then uui_defvalue = 0; end |
||
37 | if ( uui_callback ) then |
||
38 | UltimateUIMaster_Callbacks[this:GetName()] = uui_callback; |
||
39 | end |
||
40 | |||
41 | playername = UnitName("player"); |
||
42 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then |
||
43 | if (UltimateUIMaster_CVarsToRegister[uui_cvar] == nil) then |
||
44 | UltimateUIMaster_CVarsToRegister[uui_cvar] = uui_defvalue; |
||
45 | end |
||
46 | return false; |
||
47 | end |
||
48 | |||
49 | local realmname = GetCVar("realmName"); |
||
50 | if ( UltimateUIMaster_CVars[realmname] == nil ) then |
||
51 | UltimateUIMaster_CVars[realmname]={}; |
||
52 | end |
||
53 | if ( UltimateUIMaster_CVars[realmname][playername] == nil ) then |
||
54 | UltimateUIMaster_CVars[realmname][playername]={}; |
||
55 | end |
||
56 | local var = UltimateUI_GetCVar(uui_cvar); |
||
57 | if (var) then |
||
58 | UltimateUIMaster_CVars[realmname][playername][uui_cvar] = var; |
||
59 | else |
||
60 | UltimateUIMaster_CVars[realmname][playername][uui_cvar] = uui_defvalue; |
||
61 | end |
||
62 | |||
63 | return true; |
||
64 | end |
||
65 | |||
66 | -- The UltimateUI own |
||
67 | function UltimateUI_SetCVar ( uui_cvar, uui_value) |
||
68 | if ( uui_cvar == nil ) then return false; end |
||
69 | if(not uui_value) then |
||
70 | uui_value = "0"; |
||
71 | end |
||
72 | if (isTable(uui_value)) then |
||
73 | -- Sea.io.dprint( CSM_DEBUG_CVAR, "SET: ",uui_cvar," table"); |
||
74 | else |
||
75 | -- Sea.io.dprint( CSM_DEBUG_CVAR, "SET: ",uui_cvar,' ',uui_value); |
||
76 | end |
||
77 | |||
78 | playername = UnitName("player"); |
||
79 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then |
||
80 | UltimateUIMaster_CVarsToSet[uui_cvar] = uui_value; |
||
81 | return false; |
||
82 | end |
||
83 | |||
84 | local realmname = GetCVar("realmName"); |
||
85 | if ( UltimateUIMaster_CVars[realmname] == nil ) then |
||
86 | UltimateUIMaster_CVars[realmname]={}; |
||
87 | end |
||
88 | if ( UltimateUIMaster_CVars[realmname][playername] == nil ) then |
||
89 | UltimateUIMaster_CVars[realmname][playername]={}; |
||
90 | end |
||
91 | UltimateUIMaster_CVars[realmname][playername][uui_cvar] = uui_value; |
||
92 | end |
||
93 | |||
94 | -- Fakes the GetCVar command |
||
95 | function UltimateUI_GetCVar ( uui_cvar ) |
||
96 | -- Sea.io.dprint( CSM_DEBUG_CVAR,"GET:", uui_cvar); |
||
97 | if ( uui_cvar == nil ) then return nil; end |
||
98 | |||
99 | playername = UnitName("player"); |
||
100 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then return nil; end |
||
101 | |||
102 | -- Sea.io.dprint( CSM_DEBUG_CVAR, "GET: VALUE "..UltimateUIMaster_CVars[uui_cvar] ); |
||
103 | |||
104 | local realmname = GetCVar("realmName"); |
||
105 | --Check if variable exists on current realm/player |
||
106 | if (isTable(UltimateUIMaster_CVars[realmname]) and isTable(UltimateUIMaster_CVars[realmname][playername]) and UltimateUIMaster_CVars[realmname][playername][uui_cvar]) then |
||
107 | return UltimateUIMaster_CVars[realmname][playername][uui_cvar]; |
||
108 | end |
||
109 | --Check if variable exists on last realm, current player |
||
110 | if (UltimateUIMaster_LastRealm and isTable(UltimateUIMaster_CVars[UltimateUIMaster_LastRealm]) and isTable(UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][playername]) and UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][playername][uui_cvar]) then |
||
111 | return UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][playername][uui_cvar]; |
||
112 | end |
||
113 | --Check if variable exists on any realm, current player |
||
114 | for curRealm in UltimateUIMaster_CVars do |
||
115 | if (isTable(UltimateUIMaster_CVars[curRealm]) and isTable(UltimateUIMaster_CVars[curRealm][playername]) and UltimateUIMaster_CVars[curRealm][playername][uui_cvar]) then |
||
116 | return UltimateUIMaster_CVars[curRealm][playername][uui_cvar]; |
||
117 | end |
||
118 | end |
||
119 | --Check if current player exists in old format |
||
120 | if (isTable(UltimateUIMaster_CVars[playername]) and UltimateUIMaster_CVars[playername][uui_cvar]) then |
||
121 | return UltimateUIMaster_CVars[playername][uui_cvar]; |
||
122 | end |
||
123 | --Check if variable exists on last realm, last player |
||
124 | if (UltimateUIMaster_LastRealm and UltimateUIMaster_LastPlayer and isTable(UltimateUIMaster_CVars[UltimateUIMaster_LastRealm]) and isTable(UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][UltimateUIMaster_LastPlayer]) and UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][UltimateUIMaster_LastPlayer][uui_cvar]) then |
||
125 | return UltimateUIMaster_CVars[UltimateUIMaster_LastRealm][UltimateUIMaster_LastPlayer][uui_cvar]; |
||
126 | end |
||
127 | --Check if variable exists on cur realm, any player |
||
128 | if (isTable(UltimateUIMaster_CVars[realmname])) then |
||
129 | for curPlayer in UltimateUIMaster_CVars[realmname] do |
||
130 | if (isTable(UltimateUIMaster_CVars[realmname][curPlayer]) and UltimateUIMaster_CVars[realmname][curPlayer][uui_cvar]) then |
||
131 | return UltimateUIMaster_CVars[realmname][curPlayer][uui_cvar]; |
||
132 | end |
||
133 | end |
||
134 | end |
||
135 | --Check if variable exists on any realm, any player |
||
136 | for curRealm in UltimateUIMaster_CVars do |
||
137 | if (isTable(UltimateUIMaster_CVars[curRealm])) then |
||
138 | for curPlayer in UltimateUIMaster_CVars[curRealm] do |
||
139 | if (isTable(UltimateUIMaster_CVars[curRealm][curPlayer]) and UltimateUIMaster_CVars[curRealm][curPlayer][uui_cvar]) then |
||
140 | return UltimateUIMaster_CVars[curRealm][curPlayer][uui_cvar]; |
||
141 | end |
||
142 | end |
||
143 | end |
||
144 | end |
||
145 | --Check if previous player exists in old format |
||
146 | if (UltimateUIMaster_LastPlayer and isTable(UltimateUIMaster_CVars[UltimateUIMaster_LastPlayer]) and UltimateUIMaster_CVars[UltimateUIMaster_LastPlayer][uui_cvar]) then |
||
147 | return UltimateUIMaster_CVars[UltimateUIMaster_LastPlayer][uui_cvar]; |
||
148 | end |
||
149 | --Check if var exists on any player in old format |
||
150 | for curPlayer in UltimateUIMaster_CVars do |
||
151 | if (isTable(UltimateUIMaster_CVars[curPlayer]) and UltimateUIMaster_CVars[curPlayer][uui_cvar]) then |
||
152 | return UltimateUIMaster_CVars[curPlayer][uui_cvar]; |
||
153 | end |
||
154 | end |
||
155 | --Check if var exists in really old format |
||
156 | if (UltimateUIMaster_CVars[uui_cvar]) then |
||
157 | return UltimateUIMaster_CVars[uui_cvar]; |
||
158 | end |
||
159 | --Give up |
||
160 | return nil; |
||
161 | end |
||
162 | |||
163 | function UltimateUI_RegisterMissed () |
||
164 | playername = UnitName("player"); |
||
165 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then return false; end |
||
166 | |||
167 | for uui_cvar, uui_defvalue in UltimateUIMaster_CVarsToRegister do |
||
168 | UltimateUI_RegisterCVar(uui_cvar, uui_defvalue); |
||
169 | UltimateUIMaster_CVarsToRegister[uui_cvar] = nil; |
||
170 | end |
||
171 | |||
172 | return true; |
||
173 | end |
||
174 | |||
175 | function UltimateUI_SetMissed () |
||
176 | playername = UnitName("player"); |
||
177 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then return false; end |
||
178 | |||
179 | for uui_cvar, uui_value in UltimateUIMaster_CVarsToSet do |
||
180 | UltimateUI_SetCVar(uui_cvar, uui_value); |
||
181 | UltimateUIMaster_CVarsToSet[uui_cvar] = nil; |
||
182 | end |
||
183 | |||
184 | return true; |
||
185 | end |
||
186 | |||
187 | function UltimateUI_RegisterVarsLoaded (uui_callback) |
||
188 | if ( uui_callback ) then |
||
189 | UltimateUIMaster_Callbacks[this:GetName()] = uui_callback; |
||
190 | end |
||
191 | end |
||
192 | |||
193 | function UltimateUI_CallVarsLoaded () |
||
194 | playername = UnitName("player"); |
||
195 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT )) then return false; end |
||
196 | |||
197 | for uui_mod, uui_func in UltimateUIMaster_Callbacks do |
||
198 | if (uui_func) then |
||
199 | ----------------------------------------------------------------------- |
||
200 | --WARNING WARNING WARNING we are chaning this so that the called------- |
||
201 | --function will behave normalish, but this could be dangerous---------- |
||
202 | ----------------------------------------------------------------------- |
||
203 | --Store old this |
||
204 | local curThis = this; |
||
205 | --If we got a good something to set this to, then do it |
||
206 | if (getglobal(uui_mod)) then |
||
207 | this = getglobal(uui_mod); |
||
208 | end |
||
209 | --Call the function |
||
210 | uui_func(); |
||
211 | --Reset this |
||
212 | this = curThis; |
||
213 | end |
||
214 | end |
||
215 | |||
216 | return true; |
||
217 | end |
||
218 | |||
219 | ULTIMATEUI_SETTINGS_CLASS_PREFIX = "CLASS_DEFAULT_SETTING_"; |
||
220 | |||
221 | -- this saves default settings for a certain class |
||
222 | -- it is recommended that UltimateUIMaster_StoreVariables() is called prior to |
||
223 | -- this function so that the CVars contain the latest info, but... |
||
224 | function UltimateUI_SaveDefaultSettingsForClass(className) |
||
225 | if ( not className ) then |
||
226 | className = UnitClass("player"); |
||
227 | end |
||
228 | local playername = UnitName("player"); |
||
229 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT ) or ( not className ) ) then |
||
230 | return false; |
||
231 | end |
||
232 | |||
233 | if ( UltimateUIMaster_CVars[playername] == nil ) then |
||
234 | UltimateUIMaster_CVars[playername]={}; |
||
235 | end |
||
236 | |||
237 | local cvarIndex = ULTIMATEUI_SETTINGS_CLASS_PREFIX..className; |
||
238 | |||
239 | if ( UltimateUIMaster_CVars[cvarIndex] == nil ) then |
||
240 | UltimateUIMaster_CVars[cvarIndex]={}; |
||
241 | end |
||
242 | |||
243 | for k, v in UltimateUIMaster_CVars[playername] do |
||
244 | UltimateUIMaster_CVars[cvarIndex][k] = v; |
||
245 | end |
||
246 | return true; |
||
247 | end |
||
248 | |||
249 | -- this loads default settings for a certain class |
||
250 | -- it is recommended that UltimateUIMaster_LoadVariables() is called after this |
||
251 | -- function so that the system contains the latest info, but... |
||
252 | function UltimateUI_LoadDefaultSettingsForClass(className) |
||
253 | if ( not className ) then |
||
254 | className = UnitClass("player"); |
||
255 | end |
||
256 | local playername = UnitName("player"); |
||
257 | if (( playername == nil ) or ( playername == UKNOWNBEING ) or ( playername == UNKNOWNOBJECT ) or ( not className ) ) then |
||
258 | return false; |
||
259 | end |
||
260 | |||
261 | if ( UltimateUIMaster_CVars[playername] == nil ) then |
||
262 | UltimateUIMaster_CVars[playername]={}; |
||
263 | end |
||
264 | |||
265 | local cvarIndex = ULTIMATEUI_SETTINGS_CLASS_PREFIX..className; |
||
266 | |||
267 | if ( UltimateUIMaster_CVars[cvarIndex] == nil ) then |
||
268 | UltimateUIMaster_CVars[cvarIndex]={}; |
||
269 | end |
||
270 | |||
271 | for k, v in UltimateUIMaster_CVars[cvarIndex] do |
||
272 | UltimateUIMaster_CVars[playername][k] = v; |
||
273 | end |
||
274 | return true; |
||
275 | end |
||
276 | |||
277 | --[[ |
||
278 | |||
279 | Everything below this point is a helper function. |
||
280 | |||
281 | You shouldn't have to call any of these. |
||
282 | |||
283 | ]]-- |
||
284 | |||
285 | function PrintCvars() |
||
286 | PrintTable(UltimateUIMaster_CVars, "UltimateUIMaster_CVars"); |
||
287 | end |
||
288 | |||
289 | function pcv () |
||
290 | DEFAULT_CHAT_FRAME=ChatFrame1; |
||
291 | PrintCvars(); |
||
292 | end |