annotate Libs/DF/normal_bar.lua @ 20:dc1c77254f80

- added close button to users panel. - framework update.
author Tercio
date Tue, 11 Aug 2015 12:46:46 -0300
parents 2f09fe4be15c
children dbd417f413a8
rev   line source
Tercio@11 1
Tercio@11 2 local DF = _G ["DetailsFramework"]
Tercio@20 3 if (not DF or not DetailsFrameworkCanLoad) then
Tercio@20 4 return
Tercio@20 5 end
Tercio@20 6
Tercio@11 7 local _
Tercio@11 8 local _rawset = rawset --> lua locals
Tercio@11 9 local _rawget = rawget --> lua locals
Tercio@11 10 local _setmetatable = setmetatable --> lua locals
Tercio@11 11 local _unpack = unpack --> lua locals
Tercio@11 12 local _type = type --> lua locals
Tercio@11 13 local _math_floor = math.floor --> lua locals
Tercio@11 14
Tercio@11 15 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
Tercio@11 16
Tercio@11 17 local cleanfunction = function() end
Tercio@11 18 local BarMetaFunctions = {}
Tercio@11 19 local APIBarFunctions
Tercio@11 20
Tercio@11 21 ------------------------------------------------------------------------------------------------------------
Tercio@11 22 --> metatables
Tercio@11 23
Tercio@11 24 BarMetaFunctions.__call = function (_table, value)
Tercio@11 25 if (not value) then
Tercio@11 26 return _table.statusbar:GetValue()
Tercio@11 27 else
Tercio@11 28 return _table.statusbar:SetValue (value)
Tercio@11 29 end
Tercio@11 30 end
Tercio@11 31
Tercio@11 32 BarMetaFunctions.__add = function (v1, v2)
Tercio@11 33 if (_type (v1) == "table") then
Tercio@11 34 local v = v1.statusbar:GetValue()
Tercio@11 35 v = v + v2
Tercio@11 36 v1.statusbar:SetValue (v)
Tercio@11 37 else
Tercio@11 38 local v = v2.statusbar:GetValue()
Tercio@11 39 v = v + v1
Tercio@11 40 v2.statusbar:SetValue (v)
Tercio@11 41 end
Tercio@11 42 end
Tercio@11 43
Tercio@11 44 BarMetaFunctions.__sub = function (v1, v2)
Tercio@11 45 if (_type (v1) == "table") then
Tercio@11 46 local v = v1.statusbar:GetValue()
Tercio@11 47 v = v - v2
Tercio@11 48 v1.statusbar:SetValue (v)
Tercio@11 49 else
Tercio@11 50 local v = v2.statusbar:GetValue()
Tercio@11 51 v = v - v1
Tercio@11 52 v2.statusbar:SetValue (v)
Tercio@11 53 end
Tercio@11 54 end
Tercio@11 55
Tercio@11 56 ------------------------------------------------------------------------------------------------------------
Tercio@11 57 --> members
Tercio@11 58
Tercio@11 59 --> tooltip
Tercio@11 60 local function gmember_tooltip (_object)
Tercio@11 61 return _object:GetTooltip()
Tercio@11 62 end
Tercio@11 63 --> shown
Tercio@11 64 local gmember_shown = function (_object)
Tercio@11 65 return _object.statusbar:IsShown()
Tercio@11 66 end
Tercio@11 67 --> frame width
Tercio@11 68 local gmember_width = function (_object)
Tercio@11 69 return _object.statusbar:GetWidth()
Tercio@11 70 end
Tercio@11 71 --> frame height
Tercio@11 72 local gmember_height = function (_object)
Tercio@11 73 return _object.statusbar:GetHeight()
Tercio@11 74 end
Tercio@11 75 --> value
Tercio@11 76 local gmember_value = function (_object)
Tercio@11 77 return _object.statusbar:GetValue()
Tercio@11 78 end
Tercio@11 79 --> right text
Tercio@11 80 local gmember_rtext = function (_object)
Tercio@11 81 return _object.textright:GetText()
Tercio@11 82 end
Tercio@11 83 --> left text
Tercio@11 84 local gmember_ltext = function (_object)
Tercio@11 85 return _object.textleft:GetText()
Tercio@11 86 end
Tercio@11 87 --> left color
Tercio@11 88 local gmember_color = function (_object)
Tercio@11 89 return _object._texture.original_colors
Tercio@11 90 end
Tercio@11 91 --> icon
Tercio@11 92 local gmember_icon = function (_object)
Tercio@11 93 return _object._icon:GetTexture()
Tercio@11 94 end
Tercio@11 95 --> texture
Tercio@11 96 local gmember_texture = function (_object)
Tercio@11 97 return _object._texture:GetTexture()
Tercio@11 98 end
Tercio@11 99 --> font size
Tercio@11 100 local gmember_textsize = function (_object)
Tercio@11 101 local _, fontsize = _object.textleft:GetFont()
Tercio@11 102 return fontsize
Tercio@11 103 end
Tercio@11 104 --> font face
Tercio@11 105 local gmember_textfont = function (_object)
Tercio@11 106 local fontface = _object.textleft:GetFont()
Tercio@11 107 return fontface
Tercio@11 108 end
Tercio@11 109 --> font color
Tercio@11 110 local gmember_textcolor = function (_object)
Tercio@11 111 return _object.textleft:GetTextColor()
Tercio@11 112 end
Tercio@11 113
Tercio@11 114 local get_members_function_index = {
Tercio@11 115 ["tooltip"] = gmember_tooltip,
Tercio@11 116 ["shown"] = gmember_shown,
Tercio@11 117 ["width"] = gmember_width,
Tercio@11 118 ["height"] = gmember_height,
Tercio@11 119 ["value"] = gmember_value,
Tercio@11 120 ["lefttext"] = gmember_ltext,
Tercio@11 121 ["righttext"] = gmember_rtext,
Tercio@11 122 ["color"] = gmember_color,
Tercio@11 123 ["icon"] = gmember_icon,
Tercio@11 124 ["texture"] = gmember_texture,
Tercio@11 125 ["fontsize"] = gmember_textsize,
Tercio@11 126 ["fontface"] = gmember_textfont,
Tercio@11 127 ["fontcolor"] = gmember_textcolor,
Tercio@11 128 ["textsize"] = gmember_textsize, --alias
Tercio@11 129 ["textfont"] = gmember_textfont, --alias
Tercio@11 130 ["textcolor"] = gmember_textcolor --alias
Tercio@11 131 }
Tercio@11 132
Tercio@11 133 BarMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 134
Tercio@11 135 local func = get_members_function_index [_member_requested]
Tercio@11 136 if (func) then
Tercio@11 137 return func (_table, _member_requested)
Tercio@11 138 end
Tercio@11 139
Tercio@11 140 local fromMe = _rawget (_table, _member_requested)
Tercio@11 141 if (fromMe) then
Tercio@11 142 return fromMe
Tercio@11 143 end
Tercio@11 144
Tercio@11 145 return BarMetaFunctions [_member_requested]
Tercio@11 146 end
Tercio@11 147
Tercio@11 148
Tercio@11 149 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 150
Tercio@11 151
Tercio@11 152 --> tooltip
Tercio@11 153 local smember_tooltip = function (_object, _value)
Tercio@11 154 return _object:SetTooltip (_value)
Tercio@11 155 end
Tercio@11 156 --> show
Tercio@11 157 local smember_shown = function (_object, _value)
Tercio@11 158 if (_value) then
Tercio@11 159 return _object:Show()
Tercio@11 160 else
Tercio@11 161 return _object:Hide()
Tercio@11 162 end
Tercio@11 163 end
Tercio@11 164 --> hide
Tercio@11 165 local smember_hide = function (_object, _value)
Tercio@11 166 if (_value) then
Tercio@11 167 return _object:Hide()
Tercio@11 168 else
Tercio@11 169 return _object:Show()
Tercio@11 170 end
Tercio@11 171 end
Tercio@11 172 --> width
Tercio@11 173 local smember_width = function (_object, _value)
Tercio@11 174 return _object.statusbar:SetWidth (_value)
Tercio@11 175 end
Tercio@11 176 --> height
Tercio@11 177 local smember_height = function (_object, _value)
Tercio@11 178 return _object.statusbar:SetHeight (_value)
Tercio@11 179 end
Tercio@11 180 --> statusbar value
Tercio@11 181 local smember_value = function (_object, _value)
Tercio@11 182 _object.statusbar:SetValue (_value)
Tercio@11 183 return _object.div:SetPoint ("left", _object.statusbar, "left", _value * (_object.statusbar:GetWidth()/100) - 16, 0)
Tercio@11 184 end
Tercio@11 185 --> right text
Tercio@11 186 local smember_rtext = function (_object, _value)
Tercio@11 187 return _object.textright:SetText (_value)
Tercio@11 188 end
Tercio@11 189 --> left text
Tercio@11 190 local smember_ltext = function (_object, _value)
Tercio@11 191 return _object.textleft:SetText (_value)
Tercio@11 192 end
Tercio@11 193 --> color
Tercio@11 194 local smember_color = function (_object, _value)
Tercio@11 195 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 196
Tercio@11 197 _object.statusbar:SetStatusBarColor (_value1, _value2, _value3, _value4)
Tercio@11 198 _object._texture.original_colors = {_value1, _value2, _value3, _value4}
Tercio@11 199 return _object._texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 200 end
Tercio@11 201 --> icon
Tercio@11 202 local smember_icon = function (_object, _value)
Tercio@11 203 if (type (_value) == "table") then
Tercio@11 204 local _value1, _value2 = _unpack (_value)
Tercio@11 205 _object._icon:SetTexture (_value1)
Tercio@11 206 if (_value2) then
Tercio@11 207 _object._icon:SetTexCoord (_unpack (_value2))
Tercio@11 208 end
Tercio@11 209 else
Tercio@11 210 _object._icon:SetTexture (_value)
Tercio@11 211 end
Tercio@11 212 return
Tercio@11 213 end
Tercio@11 214 --> texture
Tercio@11 215 local smember_texture = function (_object, _value)
Tercio@11 216 if (type (_value) == "table") then
Tercio@11 217 local _value1, _value2 = _unpack (_value)
Tercio@11 218 _object._texture:SetTexture (_value1)
Tercio@11 219 if (_value2) then
Tercio@11 220 _object._texture:SetTexCoord (_unpack (_value2))
Tercio@11 221 end
Tercio@11 222 else
Tercio@11 223 if (_value:find ("\\")) then
Tercio@11 224 _object._texture:SetTexture (_value)
Tercio@11 225 else
Tercio@11 226 local file = SharedMedia:Fetch ("statusbar", _value)
Tercio@11 227 if (file) then
Tercio@11 228 _object._texture:SetTexture (file)
Tercio@11 229 else
Tercio@11 230 _object._texture:SetTexture (_value)
Tercio@11 231 end
Tercio@11 232 end
Tercio@11 233 end
Tercio@11 234 return
Tercio@11 235 end
Tercio@11 236 --> font face
Tercio@11 237 local smember_textfont = function (_object, _value)
Tercio@11 238 DF:SetFontFace (_object.textleft, _value)
Tercio@11 239 return DF:SetFontFace (_object.textright, _value)
Tercio@11 240 end
Tercio@11 241 --> font size
Tercio@11 242 local smember_textsize = function (_object, _value)
Tercio@11 243 DF:SetFontSize (_object.textleft, _value)
Tercio@11 244 return DF:SetFontSize (_object.textright, _value)
Tercio@11 245 end
Tercio@11 246 --> font color
Tercio@11 247 local smember_textcolor = function (_object, _value)
Tercio@11 248 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 249 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 250 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 251 end
Tercio@11 252 --> outline (shadow)
Tercio@11 253 local smember_outline = function (_object, _value)
Tercio@11 254 DF:SetFontOutline (_object.textleft, _value)
Tercio@11 255 return DF:SetFontOutline (_object.textright, _value)
Tercio@11 256 end
Tercio@11 257
Tercio@11 258 local set_members_function_index = {
Tercio@11 259 ["tooltip"] = smember_tooltip,
Tercio@11 260 ["shown"] = smember_shown,
Tercio@11 261 ["width"] = smember_width,
Tercio@11 262 ["height"] = smember_height,
Tercio@11 263 ["value"] = smember_value,
Tercio@11 264 ["righttext"] = smember_rtext,
Tercio@11 265 ["lefttext"] = smember_ltext,
Tercio@11 266 ["color"] = smember_color,
Tercio@11 267 ["icon"] = smember_icon,
Tercio@11 268 ["texture"] = smember_texture,
Tercio@11 269 ["fontsize"] = smember_textsize,
Tercio@11 270 ["fontface"] = smember_textfont,
Tercio@11 271 ["fontcolor"] = smember_textcolor,
Tercio@11 272 ["textsize"] = smember_textsize, --alias
Tercio@11 273 ["textfont"] = smember_textfont, --alias
Tercio@11 274 ["textcolor"] = smember_textcolor, --alias
Tercio@11 275 ["shadow"] = smember_outline,
Tercio@11 276 ["outline"] = smember_outline, --alias
Tercio@11 277 }
Tercio@11 278
Tercio@11 279 BarMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 280
Tercio@11 281 local func = set_members_function_index [_key]
Tercio@11 282 if (func) then
Tercio@11 283 return func (_table, _value)
Tercio@11 284 else
Tercio@11 285 return _rawset (_table, _key, _value)
Tercio@11 286 end
Tercio@11 287 end
Tercio@11 288
Tercio@11 289 ------------------------------------------------------------------------------------------------------------
Tercio@11 290 --> methods
Tercio@11 291
Tercio@11 292 --> show & hide
Tercio@11 293 function BarMetaFunctions:Show()
Tercio@11 294 self.statusbar:Show()
Tercio@11 295 end
Tercio@11 296 function BarMetaFunctions:Hide()
Tercio@11 297 self.statusbar:Hide()
Tercio@11 298 end
Tercio@11 299
Tercio@11 300 --> set value (status bar)
Tercio@11 301 function BarMetaFunctions:SetValue (value)
Tercio@11 302 if (not value) then
Tercio@11 303 value = 0
Tercio@11 304 end
Tercio@11 305 self.statusbar:SetValue (value)
Tercio@11 306 self.div:SetPoint ("left", self.statusbar, "left", value * (self.statusbar:GetWidth()/100) - 16, 0)
Tercio@11 307 end
Tercio@11 308
Tercio@11 309 --> set point
Tercio@11 310 function BarMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 311 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 312 if (not v1) then
Tercio@11 313 print ("Invalid parameter for SetPoint")
Tercio@11 314 return
Tercio@11 315 end
Tercio@11 316 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 317 end
Tercio@11 318
Tercio@11 319 --> set sizes
Tercio@11 320 function BarMetaFunctions:SetSize (w, h)
Tercio@11 321 if (w) then
Tercio@11 322 self.statusbar:SetWidth (w)
Tercio@11 323 end
Tercio@11 324 if (h) then
Tercio@11 325 self.statusbar:SetHeight (h)
Tercio@11 326 end
Tercio@11 327 end
Tercio@11 328
Tercio@11 329 --> set texture
Tercio@11 330 function BarMetaFunctions:SetTexture (texture)
Tercio@11 331 self._texture:SetTexture (texture)
Tercio@11 332 end
Tercio@11 333
Tercio@11 334 --> set texts
Tercio@11 335 function BarMetaFunctions:SetLeftText (text)
Tercio@11 336 self.textleft:SetText (text)
Tercio@11 337 end
Tercio@11 338 function BarMetaFunctions:SetRightText (text)
Tercio@11 339 self.textright:SetText (text)
Tercio@11 340 end
Tercio@11 341
Tercio@11 342 --> set color
Tercio@11 343 function BarMetaFunctions:SetColor (r, g, b, a)
Tercio@11 344 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 345
Tercio@11 346 self._texture:SetVertexColor (r, g, b, a)
Tercio@11 347 self.statusbar:SetStatusBarColor (r, g, b, a)
Tercio@11 348 self._texture.original_colors = {r, g, b, a}
Tercio@11 349 end
Tercio@11 350
Tercio@11 351 --> set icons
Tercio@11 352 function BarMetaFunctions:SetIcon (texture, ...)
Tercio@11 353 self._icon:SetTexture (texture)
Tercio@11 354 if (...) then
Tercio@11 355 local L, R, U, D = _unpack (...)
Tercio@11 356 self._icon:SetTexCoord (L, R, U, D)
Tercio@11 357 end
Tercio@11 358 end
Tercio@11 359
Tercio@11 360 --> show div
Tercio@11 361 function BarMetaFunctions:ShowDiv (bool)
Tercio@11 362 if (bool) then
Tercio@11 363 self.div:Show()
Tercio@11 364 else
Tercio@11 365 self.div:Hide()
Tercio@11 366 end
Tercio@11 367 end
Tercio@11 368
Tercio@11 369 -- tooltip
Tercio@11 370 function BarMetaFunctions:SetTooltip (tooltip)
Tercio@11 371 if (tooltip) then
Tercio@11 372 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 373 else
Tercio@11 374 return _rawset (self, "have_tooltip", nil)
Tercio@11 375 end
Tercio@11 376 end
Tercio@11 377 function BarMetaFunctions:GetTooltip()
Tercio@11 378 return _rawget (self, "have_tooltip")
Tercio@11 379 end
Tercio@11 380
Tercio@11 381 -- frame levels
Tercio@11 382 function BarMetaFunctions:GetFrameLevel()
Tercio@11 383 return self.statusbar:GetFrameLevel()
Tercio@11 384 end
Tercio@11 385 function BarMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 386 if (not frame) then
Tercio@11 387 return self.statusbar:SetFrameLevel (level)
Tercio@11 388 else
Tercio@11 389 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 390 return self.statusbar:SetFrameLevel (framelevel)
Tercio@11 391 end
Tercio@11 392 end
Tercio@11 393
Tercio@11 394 -- frame stratas
Tercio@11 395 function BarMetaFunctions:SetFrameStrata()
Tercio@11 396 return self.statusbar:GetFrameStrata()
Tercio@11 397 end
Tercio@11 398 function BarMetaFunctions:SetFrameStrata (strata)
Tercio@11 399 if (_type (strata) == "table") then
Tercio@11 400 self.statusbar:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 401 else
Tercio@11 402 self.statusbar:SetFrameStrata (strata)
Tercio@11 403 end
Tercio@11 404 end
Tercio@11 405
Tercio@11 406 --> container
Tercio@11 407 function BarMetaFunctions:SetContainer (container)
Tercio@11 408 self.container = container
Tercio@11 409 end
Tercio@11 410
Tercio@11 411 --> hooks
Tercio@11 412 function BarMetaFunctions:SetHook (hookType, func)
Tercio@11 413 if (func) then
Tercio@11 414 _rawset (self, hookType.."Hook", func)
Tercio@11 415 else
Tercio@11 416 _rawset (self, hookType.."Hook", nil)
Tercio@11 417 end
Tercio@11 418 end
Tercio@11 419
Tercio@11 420 ------------------------------------------------------------------------------------------------------------
Tercio@11 421 --> scripts
Tercio@11 422
Tercio@11 423 local OnEnter = function (frame)
Tercio@11 424 if (frame.MyObject.OnEnterHook) then
Tercio@11 425 local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject)
Tercio@11 426 if (interrupt) then
Tercio@11 427 return
Tercio@11 428 end
Tercio@11 429 end
Tercio@11 430
Tercio@11 431 frame.MyObject.background:Show()
Tercio@11 432
Tercio@11 433 if (frame.MyObject.have_tooltip) then
Tercio@11 434 GameCooltip2:Reset()
Tercio@11 435 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 436 GameCooltip2:ShowCooltip (frame, "tooltip")
Tercio@11 437 end
Tercio@11 438
Tercio@11 439 end
Tercio@11 440
Tercio@11 441 local OnLeave = function (frame)
Tercio@11 442 if (frame.MyObject.OnLeaveHook) then
Tercio@11 443 local interrupt = frame.MyObject.OnLeaveHook (frame)
Tercio@11 444 if (interrupt) then
Tercio@11 445 return
Tercio@11 446 end
Tercio@11 447 end
Tercio@11 448
Tercio@11 449 if (frame.MyObject.have_tooltip) then
Tercio@11 450 GameCooltip2:ShowMe (false)
Tercio@11 451 end
Tercio@11 452 end
Tercio@11 453
Tercio@11 454 local OnHide = function (frame)
Tercio@11 455 if (frame.MyObject.OnHideHook) then
Tercio@11 456 local interrupt = frame.MyObject.OnHideHook (frame)
Tercio@11 457 if (interrupt) then
Tercio@11 458 return
Tercio@11 459 end
Tercio@11 460 end
Tercio@11 461 end
Tercio@11 462
Tercio@11 463 local OnShow = function (frame)
Tercio@11 464 if (frame.MyObject.OnShowHook) then
Tercio@11 465 local interrupt = frame.MyObject.OnShowHook (frame)
Tercio@11 466 if (interrupt) then
Tercio@11 467 return
Tercio@11 468 end
Tercio@11 469 end
Tercio@11 470 end
Tercio@11 471
Tercio@11 472 local OnMouseDown = function (frame, button)
Tercio@11 473 if (frame.MyObject.OnMouseDownHook) then
Tercio@11 474 local interrupt = frame.MyObject.OnMouseDownHook (frame, button)
Tercio@11 475 if (interrupt) then
Tercio@11 476 return
Tercio@11 477 end
Tercio@11 478 end
Tercio@11 479
Tercio@11 480 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 481 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 482 frame.MyObject.container.isMoving = true
Tercio@11 483 frame.MyObject.container:StartMoving()
Tercio@11 484 end
Tercio@11 485 end
Tercio@11 486 end
Tercio@11 487
Tercio@11 488 local OnMouseUp = function (frame, button)
Tercio@11 489 if (frame.MyObject.OnMouseUpHook) then
Tercio@11 490 local interrupt = frame.MyObject.OnMouseUpHook (frame, button)
Tercio@11 491 if (interrupt) then
Tercio@11 492 return
Tercio@11 493 end
Tercio@11 494 end
Tercio@11 495
Tercio@11 496 if (frame.MyObject.container.isMoving) then
Tercio@11 497 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 498 frame.MyObject.container.isMoving = false
Tercio@11 499 end
Tercio@11 500 end
Tercio@11 501
Tercio@11 502 ------------------------------------------------------------------------------------------------------------
Tercio@11 503 --> timer
Tercio@11 504
Tercio@11 505 function BarMetaFunctions:OnTimerEnd()
Tercio@11 506 if (self.OnTimerEndHook) then
Tercio@11 507 local interrupt = self.OnTimerEndHook()
Tercio@11 508 if (interrupt) then
Tercio@11 509 return
Tercio@11 510 end
Tercio@11 511 end
Tercio@11 512 self.timer_texture:Hide()
Tercio@11 513 self.div_timer:Hide()
Tercio@11 514 self:Hide()
Tercio@11 515 self.timer = false
Tercio@11 516 end
Tercio@11 517
Tercio@11 518 local OnUpdate = function (self, elapsed)
Tercio@11 519 local timepct = (elapsed / self.tempo) * 100
Tercio@11 520 self.c = self.c - (timepct*self.width/100)
Tercio@11 521 self.remaining = self.remaining - elapsed
Tercio@11 522 self.righttext:SetText (_math_floor (self.remaining))
Tercio@11 523 self.timertexture:SetWidth (self.c)
Tercio@11 524 if (self.c < 1) then
Tercio@11 525 self:SetScript ("OnUpdate", nil)
Tercio@11 526 self.MyObject:OnTimerEnd()
Tercio@11 527 end
Tercio@11 528 end
Tercio@11 529
Tercio@11 530 function BarMetaFunctions:SetTimer (tempo)
Tercio@11 531
Tercio@11 532 self.statusbar.width = self.statusbar:GetWidth()
Tercio@11 533 self.statusbar.tempo = tempo
Tercio@11 534 self.statusbar.remaining = tempo
Tercio@11 535 self.statusbar.c = self.statusbar.width
Tercio@11 536
Tercio@11 537 self.timer_texture:Show()
Tercio@11 538 self.timer_texture:SetWidth (self.statusbar.width)
Tercio@11 539 self.statusbar.t = self.timer_texture
Tercio@11 540 self (1)
Tercio@11 541
Tercio@11 542 self.div_timer:Show()
Tercio@11 543 self.background:Show()
Tercio@11 544
Tercio@11 545 self.timer = true
Tercio@11 546
Tercio@11 547 self.statusbar:SetScript ("OnUpdate", OnUpdate)
Tercio@11 548 end
Tercio@11 549
Tercio@11 550 ------------------------------------------------------------------------------------------------------------
Tercio@11 551 --> object constructor
Tercio@11 552
Tercio@11 553 function DetailsFrameworkNormalBar_OnCreate (self)
Tercio@11 554 self.texture.original_colors = {1, 1, 1, 1}
Tercio@11 555 self.background.original_colors = {.3, .3, .3, .3}
Tercio@11 556 self.timertexture.original_colors = {.3, .3, .3, .3}
Tercio@11 557 return true
Tercio@11 558 end
Tercio@11 559
Tercio@11 560 function DF:CreateBar (parent, texture, w, h, value, member, name)
Tercio@11 561 return DF:NewBar (parent, parent, name, member, w, h, value, texture)
Tercio@11 562 end
Tercio@11 563
Tercio@11 564 function DF:NewBar (parent, container, name, member, w, h, value, texture_name)
Tercio@11 565
Tercio@11 566 if (not name) then
Tercio@11 567 name = "DetailsFrameworkBarNumber" .. DF.BarNameCounter
Tercio@11 568 DF.BarNameCounter = DF.BarNameCounter + 1
Tercio@11 569
Tercio@11 570 elseif (not parent) then
Tercio@11 571 return nil
Tercio@11 572 elseif (not container) then
Tercio@11 573 container = parent
Tercio@11 574 end
Tercio@11 575
Tercio@11 576 if (name:find ("$parent")) then
Tercio@11 577 name = name:gsub ("$parent", parent:GetName())
Tercio@11 578 end
Tercio@11 579
Tercio@11 580 local BarObject = {type = "bar", dframework = true}
Tercio@11 581
Tercio@11 582 if (member) then
Tercio@11 583 parent [member] = BarObject
Tercio@11 584 end
Tercio@11 585
Tercio@11 586 if (parent.dframework) then
Tercio@11 587 parent = parent.widget
Tercio@11 588 end
Tercio@11 589 if (container.dframework) then
Tercio@11 590 container = container.widget
Tercio@11 591 end
Tercio@11 592
Tercio@11 593 value = value or 0
Tercio@11 594 w = w or 150
Tercio@11 595 h = h or 14
Tercio@11 596
Tercio@11 597 --> default members:
Tercio@11 598 --> hooks
Tercio@11 599 BarObject.OnEnterHook = nil
Tercio@11 600 BarObject.OnLeaveHook = nil
Tercio@11 601 BarObject.OnHideHook = nil
Tercio@11 602 BarObject.OnShowHook = nil
Tercio@11 603 BarObject.OnMouseDownHook = nil
Tercio@11 604 BarObject.OnMouseUpHook = nil
Tercio@11 605 BarObject.OnTimerEndHook = nil
Tercio@11 606 --> misc
Tercio@11 607 BarObject.tooltip = nil
Tercio@11 608 BarObject.locked = false
Tercio@11 609 BarObject.have_tooltip = nil
Tercio@11 610
Tercio@11 611 BarObject.container = container
Tercio@11 612
Tercio@11 613 --> create widgets
Tercio@11 614 BarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkNormalBarTemplate")
Tercio@11 615 BarObject.widget = BarObject.statusbar
Tercio@11 616
Tercio@11 617 if (not APIBarFunctions) then
Tercio@11 618 APIBarFunctions = true
Tercio@11 619 local idx = getmetatable (BarObject.statusbar).__index
Tercio@11 620 for funcName, funcAddress in pairs (idx) do
Tercio@11 621 if (not BarMetaFunctions [funcName]) then
Tercio@11 622 BarMetaFunctions [funcName] = function (object, ...)
Tercio@20 623 local x = loadstring ( "return _G['"..object.statusbar:GetName().."']:"..funcName.."(...)")
Tercio@11 624 return x (...)
Tercio@11 625 end
Tercio@11 626 end
Tercio@11 627 end
Tercio@11 628 end
Tercio@11 629
Tercio@11 630 BarObject.statusbar:SetHeight (h)
Tercio@11 631 BarObject.statusbar:SetWidth (w)
Tercio@11 632 BarObject.statusbar:SetFrameLevel (parent:GetFrameLevel()+1)
Tercio@11 633 BarObject.statusbar:SetMinMaxValues (0, 100)
Tercio@11 634 BarObject.statusbar:SetValue (value or 50)
Tercio@11 635 BarObject.statusbar.MyObject = BarObject
Tercio@11 636
Tercio@11 637 BarObject.timer_texture = _G [name .. "_timerTexture"]
Tercio@11 638 BarObject.timer_texture:SetWidth (w)
Tercio@11 639 BarObject.timer_texture:SetHeight (h)
Tercio@11 640
Tercio@11 641 BarObject._texture = _G [name .. "_statusbarTexture"]
Tercio@11 642 BarObject.background = _G [name .. "_background"]
Tercio@11 643 BarObject._icon = _G [name .. "_icon"]
Tercio@11 644 BarObject.textleft = _G [name .. "_TextLeft"]
Tercio@11 645 BarObject.textright = _G [name .. "_TextRight"]
Tercio@11 646 BarObject.div = _G [name .. "_sparkMouseover"]
Tercio@11 647 BarObject.div_timer = _G [name .. "_sparkTimer"]
Tercio@11 648
Tercio@11 649 --> hooks
Tercio@11 650 BarObject.statusbar:SetScript ("OnEnter", OnEnter)
Tercio@11 651 BarObject.statusbar:SetScript ("OnLeave", OnLeave)
Tercio@11 652 BarObject.statusbar:SetScript ("OnHide", OnHide)
Tercio@11 653 BarObject.statusbar:SetScript ("OnShow", OnShow)
Tercio@11 654 BarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 655 BarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 656
Tercio@11 657 --> set class
Tercio@11 658 _setmetatable (BarObject, BarMetaFunctions)
Tercio@11 659
Tercio@11 660 --> set texture
Tercio@11 661 if (texture_name) then
Tercio@11 662 smember_texture (BarObject, texture_name)
Tercio@11 663 end
Tercio@11 664
Tercio@11 665 return BarObject
Tercio@11 666 end