vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 TODO;
3 HonorBar at lvl 60.
4 Experience from mob text.
5 Figure out profile deletion
6 Element offsets
7 for 1.9 Dissable dissable
8 Vertical bars.
9 Circular bars.
10 Time to.... text...
11 More text bars.
12 Titan/DAB optional dependencies for frame attachment.
13 Help tooltips for config
14 Identify and fix position label wierdness
15 Custom texture addons
16 Element defaults
17 OnMousover for bar/elements
18 ]]
19  
20 function BEB.OnLoad()
21 SlashCmdList["BEB"] = BEB.Slash_Handler
22 SLASH_BEB1 = "/beb"
23 SLASH_BEB2 = "/basicexperiencebar"
24 this:RegisterEvent("PLAYER_ENTERING_WORLD")
25 this:RegisterEvent("VARIABLES_LOADED")
26 BEBCurrentVersion = 0.81
27 end
28  
29 function BEB.OnEvent(event)
30 if (event == "VARIABLES_LOADED") then
31 BEB.VARIABLES_LOADED = true
32 if ( BEB.ENTERING_WORLD ) then
33 BEB.Initialize()
34 end
35 elseif (event == "PLAYER_ENTERING_WORLD") then
36 BEB.ENTERING_WORLD = true
37 if ( BEB.VARIABLES_LOADED ) then
38 BEB.Initialize()
39 end
40 elseif (event == "PLAYER_LEVEL_UP") then
41 BEB.XpThisSession = BEB.XpThisSession + (UnitXPMax("player") - BEB.OldXp)
42 BEB.OldXp = 0
43 elseif (event == "PLAYER_UPDATE_RESTING") then
44 BEB.UpdateFlashers()
45 BEB.SetColors("force")
46 elseif ((event == "PLAYER_XP_UPDATE") or (event == "CHAT_MSG_COMBAT_XP_GAIN")) then
47 BEB.XpThisSession = BEB.XpThisSession + (UnitXP("player") - BEB.OldXp)
48 BEB.OldXp = UnitXP("player")
49 BEB.UpdateElement("BEBXpBar")
50 BEB.UpdateElement("BEBRestedXpBar")
51 BEB.UpdateElement("BEBRestedXpTick")
52 elseif (event == "UPDATE_EXHAUSTION") then
53 BEB.UpdateElement("BEBRestedXpBar")
54 BEB.UpdateElement("BEBRestedXpTick")
55 BEB.UpdateElement("BEBRestedXpTickGlow")
56 BEB.SetColors()
57 elseif (event == "PLAYER_LOGOUT") then
58 if (BEBCharSettings.BEBProfile) then
59 BEB.SaveProfile(BEBCharSettings.BEBProfile)
60 end
61 end
62 end
63  
64 function BEB.Initialize()
65 BEB.INDEX = UnitName("player").." of "..GetCVar("realmName")
66 if (BEBCharSettings) then
67 if (BEBCharSettings.BEBMain.BEBProfile) then
68 BEB.LoadProfile(BEBCharSettings.BEBProfile)
69 if (not BEBCharSettings.BEBMain.enabled) then
70 BEBINITIALIZED = true
71 BEB.DisableAddon()
72 return
73 end
74 end
75 end
76 if BEBINITIALIZED then
77 return
78 end
79 BEBMain:RegisterEvent("PLAYER_LOGOUT")
80 BEBMain:RegisterEvent("PLAYER_LEVEL_UP")
81 BEBMain:RegisterEvent("PLAYER_UPDATE_RESTING")
82 BEBMain:RegisterEvent("PLAYER_XP_UPDATE")
83 BEBMain:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
84 BEBMain:RegisterEvent("UPDATE_EXHAUSTION")
85 BEBMain:RegisterForClicks("LeftButtonUp","RightButtonUp")
86 BEB.XpThisSession = 0
87 BEB.RateThisSession = 0
88 BEB.TTLThisSession = 0
89 BEB.StartTime = GetTime() - 1
90 BEB.OldXp = UnitXP("player")
91 BEB.flashers = {}
92 BEB.UpdateFrequency = 5
93 BEB.TimeFromLastUpdate = 0
94 BEB.StringOnUpdate = 0
95 BEBXpPerLvl = {400,900,1400,2100,2800,3600,4500,5400,6500,7600,8800,10100,11400,12900,14400,16000,17700,19400,21300,23200,25200,27300,29400,31700,34000,36400,38900,41400,44300,47400,50800,54500,58600,62800,67100,71600,76100,80800,85700,90700,95800,101000,106300,111800,117500,123200,129100,135100,141200,147500,153900,160400,167100,173900,180800,187900,195000,202300,209800,217400}
96 BEBRestedXpTickGlow.flashtime = .5
97 if (not BEBGlobal) then
98 BEBGlobal = {}
99 BEBGlobal.profiles = {}
100 BEBGlobal.Chars = {}
101 BEB.DefaultSettings()
102 end
103 local numprofiles = 0
104 for _,_ in BEBGlobal.profiles do
105 numprofiles = numprofiles + 1
106 end
107 table.setn(BEBGlobal.profiles,numprofiles)
108 if (not BEBCharSettings) then
109 BEB.DefaultSettings()
110 end
111 if (BEBCharSettings.Version < BEBCurrentVersion) then
112 BEB.DefaultSettings()
113 end
114 if (BEBCharSettings.BEBProfile) then
115 BEB.SaveProfile(BEBCharSettings.BEBProfile)
116 end
117 BEBGlobal.Chars[BEB.INDEX] = {Profile = BEBCharSettings.BEBProfile, Version = BEBCharSettings.Version}
118 BEB.SetupBars()
119 BEBINITIALIZED = true
120 BEB.OnEvent("PLAYER_UPDATE_RESTING")
121 end
122  
123 function BEB.Slash_Handler(msg)
124 local command, param
125 local index = string.find(msg, " ")
126 if(index) then
127 command = string.sub(msg, 1, (index - 1))
128 param = string.sub(msg, (index + 1) )
129 else
130 command = msg
131 end
132 if (command == "" or command == "defaults" or command == "enable") then
133 if (IsAddOnLoaded("BEBOptions")) then
134 else
135 local loaded,reason = LoadAddOn("BEBOptions")
136 if (not loaded) then
137 if (reason == "DISABLED") then
138 BEB.Feedback(BEB.TEXT.optionsdisabled)
139 elseif (reason == "MISSING") then
140 BEB.Feedback(BEB.TEXT.optionsmissing)
141 elseif (reason == "CORRUPT") then
142 BEB.Feedback(BEB.TEXT.optionscorrupt)
143 end
144 return
145 end
146 end
147 if (command == "") then
148 if (BEBConfigFrame:IsVisible() or BEBEnableFrame:IsVisible()) then
149 BEBConfigFrame:Hide()
150 BEBEnableFrame:Hide()
151 else
152 BEBConfigFrame:Show()
153 end
154 elseif (command == "defaults") then
155 BEBOPTIONS.LoadDefaults()
156 elseif (command == "enable") then
157 if (not BEBCharSettings.BEBMain.enabled) then
158 BEBOPTIONS.EnableAddon()
159 else
160 BEB.Feedback(BEB.TEXT.alreadyenabled)
161 end
162 end
163 else
164 if (command == "disable") then
165 if (not BEBCharSettings.BEBMain.enabled) then
166 BEB.Feedback(BEB.TEXT.alreadydisabled)
167 else
168 BEB.DisableAddon()
169 end
170 elseif (command == "help") then
171 BEB.Feedback(BEB.TEXT.validcommands)
172 else
173 BEB.Feedback(BEB.TEXT.invalidcommand)
174 end
175 end
176 end
177 function BEB.DefaultSettings()
178 if (not BEBCharSettings) then
179 BEBCharSettings = {}
180 BEBCharSettings.Version = 0
181 end
182 if (BEBCharSettings.Version < 0.7) then
183 BEBCharSettings = {
184 BEBBackground = {
185 maxrestcolor = {0, 0, 0, .25},
186 restcolor = {0, 0, 0, .25},
187 shown = true,
188 texture = "PlainBackdrop",
189 unrestcolor = {0, 0, 0, .25}
190 },
191 BEBBarText = {
192 clicktext = true,
193 location = {
194 point = "CENTER",
195 relpoint = "CENTER",
196 x = 0,
197 y = 0
198 },
199 maxrestcolor = {1, 1, 1, 1},
200 mouseover = false,
201 restcolor = {1, 1, 1, 1},
202 shown = true,
203 size = {y=10},
204 text = {string = "Lvl $plv, XP $cxp/$mxp, $pdl% , $rxp Rested Xp."},
205 unrestcolor = {1, 1, 1, 1}
206 },
207 BEBMain = {
208 dragable = true,
209 enabled = true,
210 location = {
211 point = "CENTER",
212 relpoint = "CENTER",
213 relto = "UIParent",
214 x = 0,
215 y = -337
216 },
217 size = {x=1024,y=12}
218 },
219 BEBMarkers = {
220 maxrestcolor = {1, 1, 1, 1},
221 restcolor = {1, 1, 1, 1},
222 shown = true,
223 texture = "BEB-ExperienceBarMarkers",
224 unrestcolor = {1, 1, 1, 1}
225 },
226 BEBProfile = false,
227 BEBRestedXpBar = {
228 maxrestcolor = {0.2, 0.3, 0.65, 1},
229 restcolor = {0.2, 0.3, 0.65, 1},
230 shown = true,
231 texture = "BEB-BarFill-RoundedLight"
232 },
233 BEBRestedXpTick = {
234 location = {x=0,y=0},
235 maxrestcolor = {1, 0, 0, 1},
236 restcolor = {1, 1, 1, 1},
237 shown = true,
238 size = {x=27,y=26},
239 texture = "BEB-ExhaustionTicks"
240 },
241 BEBRestedXpTickGlow = {
242 flashing = true,
243 maxrestcolor = {1, 0.8, 0.8, 1},
244 restcolor = {1, 1, 1, 1},
245 shown = true,
246 texture = "BEB-ExhaustionTicksGlow"
247 },
248 BEBXpBar = {
249 maxrestcolor = {0.4, 0, 0.7, 1},
250 restcolor = {0.4, 0, 0.7, 1},
251 texture = "BEB-BarFill-RoundedLight",
252 unrestcolor = {0.6, 0, 0.5, 1}
253 },
254 BEBXpTick = {
255 location = {x=0,y=0},
256 maxrestcolor = {1, 1, 1, 1},
257 restcolor = {1, 1, 1, 1},
258 shown = true,
259 size = {x=27,y=26},
260 texture = "BEB-ExhaustionTicks",
261 unrestcolor = {1, 1, 1, 1}
262 },
263 Version = 0.7,
264 }
265 end
266 if (BEBCharSettings.Version < 0.71) then
267 BEBCharSettings.BEBBackground.flashing = false
268 BEBCharSettings.BEBXpBar.flashing = false
269 BEBCharSettings.BEBRestedXpBar.flashing = false
270 BEBCharSettings.BEBMarkers.flashing = false
271 BEBCharSettings.BEBXpTick.flashing = false
272 BEBCharSettings.BEBRestedXpTick.flashing = false
273 BEBCharSettings.BEBBarText.flashing = false
274 BEBCharSettings.Version = 0.71
275 end
276 if (BEBCharSettings.Version < BEBCurrentVersion) then
277 BEBCharSettings.Version = BEBCurrentVersion
278 end
279 end
280  
281  
282  
283 function BEB.OnDragStart()
284 if(not BEBCharSettings.BEBMain.dragable) then
285 BEB.Feedback(BEB.TEXT.framelocked)
286 else
287 BEBMain:StartMoving()
288 end
289 end
290  
291 function BEB.OnDragStop()
292 BEBMain:StopMovingOrSizing()
293 BEB.GetPosition()
294 BEBMain:SetUserPlaced(false)
295 end
296  
297 function BEB.OnClick(arg1)
298 if (arg1 == "RightButton") then
299 BEB.Slash_Handler("")
300 elseif (arg1 == "LeftButton") then
301 if (BEBCharSettings.BEBBarText.shown and BEBCharSettings.BEBBarText.clicktext) then
302 ChatFrameEditBox:Insert(BEBBarText.textframe:GetText())
303 end
304 end
305 end
306  
307 function BEB.OnEnter()
308 if (BEBCharSettings.BEBBarText.shown and BEBCharSettings.BEBBarText.mouseover) then
309 BEBBarText:Show()
310 end
311 end
312 function BEB.OnLeave()
313 if (BEBCharSettings.BEBBarText.shown and BEBCharSettings.BEBBarText.mouseover) then
314 BEBBarText:Hide()
315 end
316 end
317  
318 function BEB.GetPosition()
319 local BEBPoint = {}
320 local BEBRelPoint = {}
321 local point = BEBCharSettings.BEBMain.location.point
322 local relpoint = BEBCharSettings.BEBMain.location.relpoint
323 local relto = getglobal(BEBCharSettings.BEBMain.location.relto)
324 if (point == "CENTER") then
325 BEBPoint.x, BEBPoint.y = BEBMain:GetCenter()
326 elseif (point == "TOPRIGHT") then
327 BEBPoint.x, BEBPoint.y = BEBMain:GetRight(), BEBMain:GetTop()
328 elseif (point == "TOPLEFT") then
329 BEBPoint.x, BEBPoint.y = BEBMain:GetLeft(), BEBMain:GetTop()
330 elseif (point == "BOTTOMRIGHT") then
331 BEBPoint.x, BEBPoint.y = BEBMain:GetRight(), BEBMain:GetBottom()
332 elseif (point == "BOTTOMLEFT") then
333 BEBPoint.x, BEBPoint.y = BEBMain:GetLeft(), BEBMain:GetBottom()
334 elseif (point == "TOP") then
335 BEBPoint.x, _, BEBPoint.y = BEBMain:GetCenter(), BEBMain:GetTop()
336 elseif (point == "BOTTOM") then
337 BEBPoint.x, _, BEBPoint.y = BEBMain:GetCenter(), BEBMain:GetBottom()
338 elseif (point == "LEFT") then
339 BEBPoint.x, _, BEBPoint.y = BEBMain:GetLeft(), BEBMain:GetCenter()
340 elseif (point == "RIGHT") then
341 BEBPoint.x, _, BEBPoint.y = BEBMain:GetRight(), BEBMain:GetCenter()
342 end
343 if (relpoint == "CENTER") then
344 BEBRelPoint.x, BEBRelPoint.y = relto:GetCenter()
345 elseif (relpoint == "TOPRIGHT") then
346 BEBRelPoint.x, BEBRelPoint.y = relto:GetRight(), relto:GetTop()
347 elseif (relpoint == "TOPLEFT") then
348 BEBRelPoint.x, BEBRelPoint.y = relto:GetLeft(), relto:GetTop()
349 elseif (relpoint == "BOTTOMRIGHT") then
350 BEBRelPoint.x, BEBRelPoint.y = relto:GetRight(), relto:GetBottom()
351 elseif (relpoint == "BOTTOMLEFT") then
352 BEBRelPoint.x, BEBRelPoint.y = relto:GetLeft(), relto:GetBottom()
353 elseif (relpoint == "TOP") then
354 BEBRelPoint.x, _, BEBRelPoint.y = relto:GetCenter(), relto:GetTop()
355 elseif (relpoint == "BOTTOM") then
356 BEBRelPoint.x, _, BEBRelPoint.y = relto:GetCenter(), relto:GetBottom()
357 elseif (relpoint == "LEFT") then
358 BEBRelPoint.x, _, BEBRelPoint.y = relto:GetLeft(), relto:GetCenter()
359 elseif (relpoint == "RIGHT") then
360 BEBRelPoint.x, _, BEBRelPoint.y = relto:GetRight(), relto:GetCenter()
361 end
362 BEBCharSettings.BEBMain.location.x, BEBCharSettings.BEBMain.location.y = BEBPoint.x - BEBRelPoint.x, BEBPoint.y - BEBRelPoint.y
363 end
364  
365 function BEB.IsFrame(frameName)
366 if (getglobal(frameName)) then
367 local var = getglobal(frameName)
368 return ((type(var) == "table") and (type(var[0]) == "userdata") and (type(var.GetName) == "function") and (var:GetName() == frameName))
369 else
370 return false
371 end
372 end
373  
374 function BEB.CompileString(instring)
375 local outstring = {events = {}}
376 local count = 0
377 local i = 1
378 while i<=string.len(instring) do
379 count = count +1
380 outstring[count] = {}
381 a,_ = string.find(instring,"%$",i)
382 if (a == i) then
383 local substring = string.sub(instring, i, i+3)
384 outstring[count].string = substring
385 if (BEB.VARIABLE_FUNCTIONS[substring]) then
386 outstring[count].func = BEB.VARIABLE_FUNCTIONS[substring].func
387 outstring[count].text = outstring[count].func()
388 for _,v in BEB.VARIABLE_FUNCTIONS[substring].events do
389 if (outstring.events[v]) then
390 table.insert(outstring.events[v],count)
391 else
392 outstring.events[v] = {count}
393 end
394 end
395 end
396 i = i+4
397 elseif (not a) then
398 outstring[count].string = string.sub(instring, i, string.len(instring))
399 outstring[count].text = outstring[count].string
400 i = string.len(instring) +1
401 else
402 outstring[count].string = string.sub(instring, i, a-1)
403 outstring[count].text = outstring[count].string
404 i = a
405 end
406 end
407 outstring.count = count
408 return outstring
409 end
410  
411 function BEB.TexturePath(var)
412 if (string.find(var, "Interface\\")) then
413 return var
414 else
415 return "Interface\\AddOns\\BEB\\Textures\\"..var
416 end
417 end
418  
419 function BEB.DisableAddon()
420 if ( not BEBINITIALIZED ) then
421 this:GetParent():Hide()
422 return
423 end
424 BEBMain:UnregisterEvent("PLAYER_LEVEL_UP")
425 BEBMain:UnregisterEvent("PLAYER_UPDATE_RESTING")
426 BEBMain:UnregisterEvent("PLAYER_XP_UPDATE")
427 BEBMain:UnregisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
428 BEBMain:UnregisterEvent("UPDATE_EXHAUSTION")
429 if (BEBBarText.texttable and BEBBarText.texttable.events) then
430 for k,_ in BEBBarText.texttable.events do
431 BEBBarText:UnregisterEvent(k)
432 end
433 end
434 BEBMain:Hide()
435 BEBDisabled = true -- check
436 BEBCharSettings.BEBMain.enabled = false
437 if (BEBConfigFrame and BEBConfigFrame:IsShown()) then
438 BEBConfigFrame:Hide()
439 BEBEnableFrame:Show()
440 end
441 end
442  
443 function BEB.LoadProfile(bebprofile)
444 if (BEBGlobal.profiles[bebprofile]) then
445 if (BEBCharSettings.BEBProfile == bebprofile) then
446 BEBCharSettings = BEB.TableCopy(BEBGlobal.profiles[bebprofile])
447 BEBCharSettings.BEBProfile = bebprofile
448 else
449 BEBCharSettings = BEB.TableCopy(BEBGlobal.profiles[bebprofile])
450 end
451 else
452 BEB.FeedBack(BEB.TEXT.profilemissing)
453 BEBCharSettings.BEBProfile = false
454 end
455 end
456  
457 function BEB.SaveProfile(bebprofile)
458 BEBGlobal.profiles[bebprofile] = BEB.TableCopy(BEBCharSettings)
459 BEBGlobal.profiles[bebprofile].BEBProfile = false
460 end
461  
462 function BEB.TableCopy(a)
463 local b={}
464 for k,v in a do
465 if type(v) == "table" then
466 b[k] = BEB.TableCopy(v)
467 else
468 b[k]=v
469 end
470 end
471 return b
472 end
473  
474 function BEB.SetupBars()
475 if (not BEBCharSettings.BEBMain.enabled) then
476 return
477 else
478 BEBMain:Show()
479 end
480 local elements = {"BEBMain","BEBBackground","BEBXpBar","BEBRestedXpBar","BEBMarkers","BEBXpTick","BEBRestedXpTick","BEBRestedXpTickGlow","BEBBarText"}
481 for _,v in ipairs(elements) do
482 BEB.SetupElement(v)
483 end
484 BEB.SetColors("force")
485 end
486 function BEB.SetupElement(element)
487 if (element == "BEBProfile") then
488 return
489 end
490 local Element = getglobal(element)
491 if (BEBCharSettings[element].flashing) then
492 BEB.flashers[element] = true
493 if ((IsResting() == 1) and (not Element.flashing)) then
494 BEB.StartFlashing(element,0.7,0.2,1)
495 end
496 else
497 BEB.flashers[element] = nil
498 if ((IsResting() == 1) and Element.flashing) then
499 BEB.StopFlashing(element)
500 end
501 end
502  
503 if (element == "BEBMain") then
504 if (BEB.IsFrame(BEBCharSettings.BEBMain.location.relto)) then
505 BEBMain:ClearAllPoints()
506 local Location = BEBCharSettings.BEBMain.location
507 BEBMain:SetPoint(Location.point, Location.relto, Location.relpoint, Location.x, Location.y)
508 else
509 BEB.Feedback(BEB.TEXT.framewasinvalid)
510 BEBMain:SetPoint("CENTER","UIParent","CENTER",0,0)
511 end
512 BEBMain:SetWidth(BEBCharSettings.BEBMain.size.x)
513 BEBMain:SetHeight(BEBCharSettings.BEBMain.size.y)
514 if (BEBCharSettings.BEBMain.dragable == true) then
515 BEBMain:RegisterForDrag("LeftButton")
516 else
517 BEBMain:RegisterForDrag()
518 end
519 BEBBarText:SetHeight(BEBCharSettings.BEBMain.size.y)
520 BEBXpBar:SetHeight(BEBCharSettings.BEBMain.size.y)
521 BEBRestedXpBar:SetHeight(BEBCharSettings.BEBMain.size.y)
522 BEBMainWidth = BEBMain:GetWidth()
523 elseif (element == "BEBBackground") then
524 if (BEBCharSettings.BEBBackground.shown) then
525 BEBBackground:ClearAllPoints()
526 BEBBackground:SetPoint("TOPLEFT", BEBMain, "TOPLEFT", 0, 0)
527 BEBBackground:SetPoint("BOTTOMRIGHT", BEBMain, "BOTTOMRIGHT", 0, 0)
528 BEBBackground.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBBackground.texture))
529 BEBBackground:Show()
530 else
531 BEBBackground:Hide()
532 end
533 elseif (element == "BEBXpBar") then
534 BEBXpBar:ClearAllPoints()
535 BEBXpBar:SetPoint("LEFT", BEBMain, "LEFT", 0, 0)
536 BEBXpBar.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBXpBar.texture))
537 elseif (element == "BEBRestedXpBar") then
538 if (BEBCharSettings.BEBRestedXpBar.shown) then
539 BEBRestedXpBar:ClearAllPoints()
540 BEBRestedXpBar:SetPoint("LEFT", BEBXpBar, "RIGHT", 0, 0)
541 BEBRestedXpBar.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBRestedXpBar.texture))
542 BEBRestedXpBar:Show()
543 else
544 BEBRestedXpBar:Hide()
545 end
546 elseif (element == "BEBMarkers") then
547 if (BEBCharSettings.BEBMarkers.shown) then
548 BEBMarkers:ClearAllPoints()
549 BEBMarkers:SetPoint("TOPLEFT", BEBMain, "TOPLEFT", 0, 0)
550 BEBMarkers:SetPoint("BOTTOMRIGHT", BEBMain, "BOTTOMRIGHT", 0, 0)
551 BEBMarkers.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBMarkers.texture))
552 BEBMarkers:Show()
553 else
554 BEBMarkers:Hide()
555 end
556 elseif (element == "BEBXpTick") then
557 if (BEBCharSettings.BEBXpTick.shown) then
558 BEBXpTick:ClearAllPoints()
559 BEBXpTick:SetPoint("CENTER", "BEBXpBar", "RIGHT", BEBCharSettings.BEBXpTick.location.x, BEBCharSettings.BEBXpTick.location.y)
560 BEBXpTick.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBXpTick.texture))
561 BEBXpTick.texture:SetTexCoord(0,0.5,0,0.5)
562 BEBXpTick:Show()
563 else
564 BEBXpTick:Hide()
565 end
566 BEBXpTick:SetWidth(BEBCharSettings.BEBXpTick.size.x)
567 BEBXpTick:SetHeight(BEBCharSettings.BEBXpTick.size.y)
568 elseif (element == "BEBRestedXpTick") then
569 if (BEBCharSettings.BEBRestedXpTick.shown) then
570 BEBRestedXpTick.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBRestedXpTick.texture))
571 BEBRestedXpTick:SetWidth(BEBCharSettings.BEBRestedXpTick.size.x)
572 BEBRestedXpTick:SetHeight(BEBCharSettings.BEBRestedXpTick.size.y)
573 BEBRestedXpTick:Show()
574 else
575 BEBRestedXpTick:Hide()
576 end
577 elseif (element == "BEBRestedXpTickGlow") then
578 if (BEBCharSettings.BEBRestedXpTickGlow.shown) then
579 BEBRestedXpTickGlow.texture:SetTexture(BEB.TexturePath(BEBCharSettings.BEBRestedXpTickGlow.texture))
580 BEBRestedXpTickGlow:ClearAllPoints()
581 BEBRestedXpTickGlow:SetPoint("TOPLEFT", "BEBRestedXpTick", "TOPLEFT", 0, 0)
582 BEBRestedXpTickGlow:SetPoint("BOTTOMRIGHT", "BEBRestedXpTick", "BOTTOMRIGHT", 0, 0)
583 end
584 elseif (element == "BEBBarText") then
585 BEBBarText.texttable = BEB.CompileString(BEBCharSettings.BEBBarText.text.string)
586 if (BEBCharSettings.BEBBarText.shown) then
587 BEBBarText:ClearAllPoints()
588 BEBBarText:SetPoint(BEBCharSettings.BEBBarText.location.point, "BEBMain", BEBCharSettings.BEBBarText.location.relpoint, BEBCharSettings.BEBBarText.location.x, BEBCharSettings.BEBBarText.location.y)
589 for k,_ in BEBBarText.texttable.events do
590 BEBBarText:RegisterEvent(k)
591 end
592 BEB.StringEvent("PLAYER_LEVEL_UP")
593 if (BEBCharSettings.BEBBarText.mouseover) then
594 BEBBarText:Hide()
595 else
596 BEBBarText:Show()
597 end
598 else
599 BEBBarText:Hide()
600 end
601 BEBBarText.textframe:SetTextHeight(BEBCharSettings.BEBBarText.size.y)
602 local scale = BEBMain:GetScale()
603 BEBMain:SetScale(scale + 0.1)
604 BEBMain:SetScale(scale)
605 end
606 BEB.UpdateElement(element)
607 end
608  
609 function BEB.SetColors(force)
610 if (BEB.RestState) then
611 BEB.OldRestState = BEB.RestState
612 else
613 BEB.OldRestState = -1
614 end
615 if (GetRestState() == 1) then
616 if (GetXPExhaustion() == (UnitXPMax("player")*1.5)) then
617 BEB.RestState = 2
618 else
619 BEB.RestState = 1
620 end
621 else
622 BEB.RestState = 0
623 end
624 if ((BEB.RestState ~= BEB.OldRestState) or force) then
625 if (BEB.RestState == 0) then
626 BEBBarText.textframe:SetVertexColor(unpack(BEBCharSettings.BEBBarText.unrestcolor))
627 BEBXpTick.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpTick.unrestcolor))
628 BEBMarkers.texture:SetVertexColor(unpack(BEBCharSettings.BEBMarkers.unrestcolor))
629 BEBXpBar.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpBar.unrestcolor))
630 BEBBackground.texture:SetVertexColor(unpack(BEBCharSettings.BEBBackground.unrestcolor))
631 elseif (BEB.RestState == 1) then
632 BEBRestedXpTickGlow.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpTickGlow.restcolor))
633 BEBBarText.textframe:SetVertexColor(unpack(BEBCharSettings.BEBBarText.restcolor))
634 BEBRestedXpTick.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpTick.restcolor))
635 BEBXpTick.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpTick.restcolor))
636 BEBMarkers.texture:SetVertexColor(unpack(BEBCharSettings.BEBMarkers.restcolor))
637 BEBXpBar.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpBar.restcolor))
638 BEBRestedXpBar.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpBar.restcolor))
639 BEBBackground.texture:SetVertexColor(unpack(BEBCharSettings.BEBBackground.restcolor))
640 elseif (BEB.RestState == 2) then
641 BEBRestedXpTickGlow.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpTickGlow.maxrestcolor))
642 BEBBarText.textframe:SetVertexColor(unpack(BEBCharSettings.BEBBarText.maxrestcolor))
643 BEBRestedXpTick.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpTick.maxrestcolor))
644 BEBXpTick.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpTick.maxrestcolor))
645 BEBMarkers.texture:SetVertexColor(unpack(BEBCharSettings.BEBMarkers.maxrestcolor))
646 BEBXpBar.texture:SetVertexColor(unpack(BEBCharSettings.BEBXpBar.maxrestcolor))
647 BEBRestedXpBar.texture:SetVertexColor(unpack(BEBCharSettings.BEBRestedXpBar.maxrestcolor))
648 BEBBackground.texture:SetVertexColor(unpack(BEBCharSettings.BEBBackground.maxrestcolor))
649 end
650 end
651 end
652  
653 function BEB.UpdateElement(element)
654 if (element == "BEBXpBar") then
655 BEBScale = BEBMainWidth / UnitXPMax("player")
656 if ((not UnitXP("player")) or (UnitXP("player") == 0)) then
657 BEBXpWidth = 1
658 else
659 BEBXpWidth = BEBScale * UnitXP("player")
660 end
661 BEBXpBar:SetWidth(BEBXpWidth)
662 BEBXpBar.texture:SetTexCoord(0,(BEBXpWidth/BEBMainWidth),0,1)
663 elseif (element == "BEBRestedXpBar") then
664 if ((GetRestState() == 1) and BEBCharSettings.BEBRestedXpBar.shown) then
665 if ((UnitXP("player")+GetXPExhaustion()) > UnitXPMax("player")) then
666 BEBRestedXpBar:SetWidth(BEBMainWidth - BEBXpWidth)
667 BEBRestedXpBar.texture:SetTexCoord((BEBXpWidth/BEBMainWidth),1,0,1)
668 else
669 local BEBRestedXpWidth = (UnitXP("player")+GetXPExhaustion())*BEBScale
670 BEBRestedXpBar:SetWidth(BEBRestedXpWidth - BEBXpWidth)
671 BEBRestedXpBar.texture:SetTexCoord((BEBXpWidth/BEBMainWidth),(BEBRestedXpWidth/BEBMainWidth),0,1)
672 end
673 else
674 BEBRestedXpBar:Hide()
675 end
676 elseif (element == "BEBRestedXpTick") then
677 if ((GetRestState() == 1) and BEBCharSettings.BEBRestedXpTick.shown) then
678 local position
679 local xp, rest, xpmax, level = UnitXP("player"), GetXPExhaustion(), UnitXPMax("player"), UnitLevel("player")
680 if (level < 59) then
681 if ((xp + rest - xpmax) > BEBXpPerLvl[level+1]) then
682 position = ((xp + rest - xpmax - BEBXpPerLvl[level+1])/BEBXpPerLvl[level+2]) * BEBMainWidth
683 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0.5, 1)
684 BEBRestState = 3
685 elseif ((xp + rest) > xpmax) then
686 position = ((xp + rest - xpmax)/BEBXpPerLvl[level+1]) * BEBMainWidth
687 BEBRestedXpTick.texture:SetTexCoord(0.5, 1, 0, 0.5)
688 BEBRestState = 2
689 else
690 position = (xp + rest)*BEBScale
691 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0, 0.5)
692 BEBRestState = 1
693 end
694 elseif (level == 59) then
695 if ((xp + rest - xpmax) > BEBXpPerLvl[level+1]) then
696 position = BEBMainWidth
697 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0.5, 1)
698 BEBRestState = 3
699 elseif ((xp + rest) > xpmax) then
700 position = ((xp + rest - xpmax)/BEBXpPerLvl[level+1]) * BEBMainWidth
701 BEBRestedXpTick.texture:SetTexCoord(0.5, 1, 0, 0.5)
702 BEBRestState = 2
703 else
704 position = (xp + rest)*BEBScale
705 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0, 0.5)
706 BEBRestState = 1
707 end
708 elseif (level == 60) then
709 if ((xp + rest - xpmax) > BEBXpPerLvl[level+1]) then
710 position = BEBMainWidth
711 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0.5, 1)
712 BEBRestState = 3
713 elseif ((xp + rest) > xpmax) then
714 position = BEBMainWidth
715 BEBRestedXpTick.texture:SetTexCoord(0.5, 1, 0, 0.5)
716 BEBRestState = 2
717 else
718 position = (xp + rest)*BEBScale
719 BEBRestedXpTick.texture:SetTexCoord(0, 0.5, 0, 0.5)
720 BEBRestState = 1
721 end
722 end
723 local offsets = BEBCharSettings.BEBRestedXpTick.location
724 BEBRestedXpTick:SetPoint("CENTER" ,"BEBMain" ,"LEFT", (position + offsets.x), offsets.y)
725 BEBRestedXpTick:Show()
726 else
727 BEBRestedXpTick:Hide()
728 BEBRestState = 0
729 end
730 elseif (element == "BEBRestedXpTickGlow") then
731 if (BEBCharSettings.BEBRestedXpTickGlow.shown and (BEBRestState ~= 0) and (IsResting() == 1)) then
732 if (BEBRestState == 1) then
733 BEBRestedXpTickGlow.texture:SetTexCoord(0, 0.5, 0, 0.5)
734 BEBRestedXpTickGlow:Show()
735 elseif (BEBRestState == 2) then
736 BEBRestedXpTickGlow.texture:SetTexCoord(0.5, 1, 0, 0.5)
737 BEBRestedXpTickGlow:Show()
738 elseif (BEBRestState == 3) then
739 BEBRestedXpTickGlow.texture:SetTexCoord(0, 0.5, 0.5, 1)
740 BEBRestedXpTickGlow:Show()
741 end
742 else
743 BEBRestedXpTickGlow:Hide()
744 end
745 end
746 end
747  
748 function BEB.OnUpdate(elapsed)
749 if (BEBINITIALIZED and BEBCharSettings.BEBMain.enabled) then
750 if (BEBTextTimeToHide) then
751 if (BEBTextTimeToHide > 0) then
752 BEBTextTimeToHide = BEBTextTimeToHide - elapsed
753 else
754 BEBTextTimeToHide = nil
755 BEBBarText:Hide()
756 end
757 end
758 BEB.StringOnUpdate = BEB.StringOnUpdate +elapsed
759 if (BEB.StringOnUpdate > 0.5) then
760 BEB.StringEvent("ON_UPDATE")
761 BEB.StringOnUpdate = 0
762 end
763 BEB.TimeThisSession = GetTime() - BEB.StartTime
764 BEB.RateThisSession = BEB.XpThisSession/BEB.TimeThisSession
765 BEB.TimeFromLastUpdate = BEB.TimeFromLastUpdate + elapsed
766 if (BEB.TimeFromLastUpdate > BEB.UpdateFrequency) then
767 BEB.UpdateElement("BEBXpBar")
768 BEB.UpdateElement("BEBRestedXpBar")
769 BEB.UpdateElement("BEBRestedXpTick")
770 BEB.UpdateElement("BEBRestedXpTickGlow")
771 BEB.SetColors()
772 BEB.TimeFromLastUpdate = 0
773 end
774 end
775 end
776  
777 function BEB.StringEvent(event)
778 if (BEBBarText.texttable.events[event]) then
779 local text = ""
780 for _,n in BEBBarText.texttable.events[event] do
781 BEBBarText.texttable[n].text = BEBBarText.texttable[n].func()
782 end
783 for i=1,BEBBarText.texttable.count do
784 text = text..BEBBarText.texttable[i].text
785 end
786 BEBBarText.textframe:SetText(text)
787 BEBBarText:SetWidth(BEBBarText.textframe:GetWidth())
788 end
789 end
790  
791 function BEB.Feedback(msg)
792 DEFAULT_CHAT_FRAME:AddMessage( msg, 1.0, 1.0, 0.0 );
793 end
794  
795 function BEB.StartFlashing(element,rate,min,max)
796 local Element = getglobal(element)
797 if (not Element.flashing) then
798 Element.flashing = true
799 Element.rate = rate
800 Element.min = min
801 Element.max = max
802 Element.scale = (max-min)/rate
803 Element.time = rate
804 if (Element.textframe) then
805 Element.textframe:SetAlpha(max)
806 elseif (Element.texture) then
807 Element.texture:SetAlpha(max)
808 end
809 Element:SetScript("OnUpdate",BEB.ElementFlashing)
810 end
811 end
812  
813 function BEB.StopFlashing(element)
814 local Element = getglobal(element)
815 Element.flashing = nil
816 Element.rate = nil
817 Element.min = nil
818 Element.max = nil
819 Element.scale = nil
820 Element.time = nil
821 Element.reversed = nil
822 Element:SetScript("OnUpdate",nil)
823 end
824  
825 function BEB.UpdateFlashers()
826 if (IsResting() == 1) then
827 for v,_ in BEB.flashers do
828 BEB.StartFlashing(v,0.7,0.2,1)
829 end
830 else
831 for v,_ in BEB.flashers do
832 BEB.StopFlashing(v)
833 end
834 end
835 end
836  
837 function BEB.ElementFlashing()
838 this.time = this.time - arg1
839 while (this.time < 0) do
840 this.time = this.rate + this.time
841 if (this.reversed) then
842 this.reversed = nil
843 else
844 this.reversed = true
845 end
846 end
847 if (this.reversed) then
848 if (this.textframe) then
849 this.textframe:SetAlpha(this.max-(this.scale*this.time))
850 elseif (this.texture) then
851 this.texture:SetAlpha(this.max-(this.scale*this.time))
852 end
853 else
854 if (this.textframe) then
855 this.textframe:SetAlpha(this.min+(this.scale*this.time))
856 elseif (this.texture) then
857 this.texture:SetAlpha(this.min+(this.scale*this.time))
858 end
859 end
860 end
861  
862 function BEB.SecondsToTime(seconds)
863 if (seconds < 60) then
864 return math.floor(seconds).."s"
865 elseif (seconds < 3600) then
866 return math.floor(seconds/60).."m"..math.floor(math.mod(seconds,60)).."s"
867 elseif (seconds < 86400) then
868 return math.floor(seconds/3600).."h"..math.floor(math.mod(seconds,3600)/60).."m"
869 else
870 return math.floor(seconds/86400).."d"..math.floor(math.mod(seconds,86400)/3600).."h"
871 end
872 end
873  
874 function BEB.round(num, idp)
875 local mult = 10^(idp or 0)
876 return math.floor(num * mult + 0.5) / mult
877 end