annotate Libs/DF/normal_bar.lua @ 19:215f0dd37a6c

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