annotate Libs/DF/normal_bar.lua @ 23:52973d00a183

- framework update.
author Tercio
date Tue, 08 Sep 2015 13:23:31 -0300
parents dbd417f413a8
children 7a285d98b95f
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@22 199 _object.timer_texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 200 return _object._texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 201 end
Tercio@11 202 --> icon
Tercio@11 203 local smember_icon = function (_object, _value)
Tercio@11 204 if (type (_value) == "table") then
Tercio@11 205 local _value1, _value2 = _unpack (_value)
Tercio@11 206 _object._icon:SetTexture (_value1)
Tercio@11 207 if (_value2) then
Tercio@11 208 _object._icon:SetTexCoord (_unpack (_value2))
Tercio@11 209 end
Tercio@11 210 else
Tercio@11 211 _object._icon:SetTexture (_value)
Tercio@11 212 end
Tercio@11 213 return
Tercio@11 214 end
Tercio@11 215 --> texture
Tercio@11 216 local smember_texture = function (_object, _value)
Tercio@11 217 if (type (_value) == "table") then
Tercio@11 218 local _value1, _value2 = _unpack (_value)
Tercio@11 219 _object._texture:SetTexture (_value1)
Tercio@22 220 _object.timer_texture:SetTexture (_value1)
Tercio@11 221 if (_value2) then
Tercio@11 222 _object._texture:SetTexCoord (_unpack (_value2))
Tercio@22 223 _object.timer_texture:SetTexCoord (_unpack (_value2))
Tercio@11 224 end
Tercio@11 225 else
Tercio@11 226 if (_value:find ("\\")) then
Tercio@11 227 _object._texture:SetTexture (_value)
Tercio@11 228 else
Tercio@11 229 local file = SharedMedia:Fetch ("statusbar", _value)
Tercio@11 230 if (file) then
Tercio@11 231 _object._texture:SetTexture (file)
Tercio@22 232 _object.timer_texture:SetTexture (file)
Tercio@11 233 else
Tercio@11 234 _object._texture:SetTexture (_value)
Tercio@22 235 _object.timer_texture:SetTexture (_value)
Tercio@11 236 end
Tercio@11 237 end
Tercio@11 238 end
Tercio@11 239 return
Tercio@11 240 end
Tercio@11 241 --> font face
Tercio@11 242 local smember_textfont = function (_object, _value)
Tercio@11 243 DF:SetFontFace (_object.textleft, _value)
Tercio@11 244 return DF:SetFontFace (_object.textright, _value)
Tercio@11 245 end
Tercio@11 246 --> font size
Tercio@11 247 local smember_textsize = function (_object, _value)
Tercio@11 248 DF:SetFontSize (_object.textleft, _value)
Tercio@11 249 return DF:SetFontSize (_object.textright, _value)
Tercio@11 250 end
Tercio@11 251 --> font color
Tercio@11 252 local smember_textcolor = function (_object, _value)
Tercio@11 253 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 254 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 255 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 256 end
Tercio@11 257 --> outline (shadow)
Tercio@11 258 local smember_outline = function (_object, _value)
Tercio@11 259 DF:SetFontOutline (_object.textleft, _value)
Tercio@11 260 return DF:SetFontOutline (_object.textright, _value)
Tercio@11 261 end
Tercio@11 262
Tercio@11 263 local set_members_function_index = {
Tercio@11 264 ["tooltip"] = smember_tooltip,
Tercio@11 265 ["shown"] = smember_shown,
Tercio@11 266 ["width"] = smember_width,
Tercio@11 267 ["height"] = smember_height,
Tercio@11 268 ["value"] = smember_value,
Tercio@11 269 ["righttext"] = smember_rtext,
Tercio@11 270 ["lefttext"] = smember_ltext,
Tercio@11 271 ["color"] = smember_color,
Tercio@11 272 ["icon"] = smember_icon,
Tercio@11 273 ["texture"] = smember_texture,
Tercio@11 274 ["fontsize"] = smember_textsize,
Tercio@11 275 ["fontface"] = smember_textfont,
Tercio@11 276 ["fontcolor"] = smember_textcolor,
Tercio@11 277 ["textsize"] = smember_textsize, --alias
Tercio@11 278 ["textfont"] = smember_textfont, --alias
Tercio@11 279 ["textcolor"] = smember_textcolor, --alias
Tercio@11 280 ["shadow"] = smember_outline,
Tercio@11 281 ["outline"] = smember_outline, --alias
Tercio@11 282 }
Tercio@11 283
Tercio@11 284 BarMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 285
Tercio@11 286 local func = set_members_function_index [_key]
Tercio@11 287 if (func) then
Tercio@11 288 return func (_table, _value)
Tercio@11 289 else
Tercio@11 290 return _rawset (_table, _key, _value)
Tercio@11 291 end
Tercio@11 292 end
Tercio@11 293
Tercio@11 294 ------------------------------------------------------------------------------------------------------------
Tercio@11 295 --> methods
Tercio@11 296
Tercio@11 297 --> show & hide
Tercio@11 298 function BarMetaFunctions:Show()
Tercio@11 299 self.statusbar:Show()
Tercio@11 300 end
Tercio@11 301 function BarMetaFunctions:Hide()
Tercio@11 302 self.statusbar:Hide()
Tercio@11 303 end
Tercio@11 304
Tercio@11 305 --> set value (status bar)
Tercio@11 306 function BarMetaFunctions:SetValue (value)
Tercio@11 307 if (not value) then
Tercio@11 308 value = 0
Tercio@11 309 end
Tercio@11 310 self.statusbar:SetValue (value)
Tercio@11 311 self.div:SetPoint ("left", self.statusbar, "left", value * (self.statusbar:GetWidth()/100) - 16, 0)
Tercio@11 312 end
Tercio@11 313
Tercio@11 314 --> set point
Tercio@11 315 function BarMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 316 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 317 if (not v1) then
Tercio@11 318 print ("Invalid parameter for SetPoint")
Tercio@11 319 return
Tercio@11 320 end
Tercio@11 321 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 322 end
Tercio@11 323
Tercio@11 324 --> set sizes
Tercio@11 325 function BarMetaFunctions:SetSize (w, h)
Tercio@11 326 if (w) then
Tercio@11 327 self.statusbar:SetWidth (w)
Tercio@11 328 end
Tercio@11 329 if (h) then
Tercio@11 330 self.statusbar:SetHeight (h)
Tercio@11 331 end
Tercio@11 332 end
Tercio@11 333
Tercio@11 334 --> set texture
Tercio@11 335 function BarMetaFunctions:SetTexture (texture)
Tercio@11 336 self._texture:SetTexture (texture)
Tercio@11 337 end
Tercio@11 338
Tercio@11 339 --> set texts
Tercio@11 340 function BarMetaFunctions:SetLeftText (text)
Tercio@11 341 self.textleft:SetText (text)
Tercio@11 342 end
Tercio@11 343 function BarMetaFunctions:SetRightText (text)
Tercio@11 344 self.textright:SetText (text)
Tercio@11 345 end
Tercio@11 346
Tercio@11 347 --> set color
Tercio@11 348 function BarMetaFunctions:SetColor (r, g, b, a)
Tercio@11 349 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 350
Tercio@11 351 self._texture:SetVertexColor (r, g, b, a)
Tercio@11 352 self.statusbar:SetStatusBarColor (r, g, b, a)
Tercio@11 353 self._texture.original_colors = {r, g, b, a}
Tercio@11 354 end
Tercio@11 355
Tercio@11 356 --> set icons
Tercio@11 357 function BarMetaFunctions:SetIcon (texture, ...)
Tercio@11 358 self._icon:SetTexture (texture)
Tercio@11 359 if (...) then
Tercio@11 360 local L, R, U, D = _unpack (...)
Tercio@11 361 self._icon:SetTexCoord (L, R, U, D)
Tercio@11 362 end
Tercio@11 363 end
Tercio@11 364
Tercio@11 365 --> show div
Tercio@11 366 function BarMetaFunctions:ShowDiv (bool)
Tercio@11 367 if (bool) then
Tercio@11 368 self.div:Show()
Tercio@11 369 else
Tercio@11 370 self.div:Hide()
Tercio@11 371 end
Tercio@11 372 end
Tercio@11 373
Tercio@11 374 -- tooltip
Tercio@11 375 function BarMetaFunctions:SetTooltip (tooltip)
Tercio@11 376 if (tooltip) then
Tercio@11 377 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 378 else
Tercio@11 379 return _rawset (self, "have_tooltip", nil)
Tercio@11 380 end
Tercio@11 381 end
Tercio@11 382 function BarMetaFunctions:GetTooltip()
Tercio@11 383 return _rawget (self, "have_tooltip")
Tercio@11 384 end
Tercio@11 385
Tercio@11 386 -- frame levels
Tercio@11 387 function BarMetaFunctions:GetFrameLevel()
Tercio@11 388 return self.statusbar:GetFrameLevel()
Tercio@11 389 end
Tercio@11 390 function BarMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 391 if (not frame) then
Tercio@11 392 return self.statusbar:SetFrameLevel (level)
Tercio@11 393 else
Tercio@11 394 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 395 return self.statusbar:SetFrameLevel (framelevel)
Tercio@11 396 end
Tercio@11 397 end
Tercio@11 398
Tercio@11 399 -- frame stratas
Tercio@11 400 function BarMetaFunctions:SetFrameStrata()
Tercio@11 401 return self.statusbar:GetFrameStrata()
Tercio@11 402 end
Tercio@11 403 function BarMetaFunctions:SetFrameStrata (strata)
Tercio@11 404 if (_type (strata) == "table") then
Tercio@11 405 self.statusbar:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 406 else
Tercio@11 407 self.statusbar:SetFrameStrata (strata)
Tercio@11 408 end
Tercio@11 409 end
Tercio@11 410
Tercio@11 411 --> container
Tercio@11 412 function BarMetaFunctions:SetContainer (container)
Tercio@11 413 self.container = container
Tercio@11 414 end
Tercio@11 415
Tercio@11 416 --> hooks
Tercio@11 417 function BarMetaFunctions:SetHook (hookType, func)
Tercio@11 418 if (func) then
Tercio@11 419 _rawset (self, hookType.."Hook", func)
Tercio@11 420 else
Tercio@11 421 _rawset (self, hookType.."Hook", nil)
Tercio@11 422 end
Tercio@11 423 end
Tercio@11 424
Tercio@11 425 ------------------------------------------------------------------------------------------------------------
Tercio@11 426 --> scripts
Tercio@11 427
Tercio@11 428 local OnEnter = function (frame)
Tercio@11 429 if (frame.MyObject.OnEnterHook) then
Tercio@11 430 local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject)
Tercio@11 431 if (interrupt) then
Tercio@11 432 return
Tercio@11 433 end
Tercio@11 434 end
Tercio@11 435
Tercio@11 436 frame.MyObject.background:Show()
Tercio@11 437
Tercio@11 438 if (frame.MyObject.have_tooltip) then
Tercio@11 439 GameCooltip2:Reset()
Tercio@11 440 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 441 GameCooltip2:ShowCooltip (frame, "tooltip")
Tercio@11 442 end
Tercio@11 443
Tercio@11 444 end
Tercio@11 445
Tercio@11 446 local OnLeave = function (frame)
Tercio@11 447 if (frame.MyObject.OnLeaveHook) then
Tercio@11 448 local interrupt = frame.MyObject.OnLeaveHook (frame)
Tercio@11 449 if (interrupt) then
Tercio@11 450 return
Tercio@11 451 end
Tercio@11 452 end
Tercio@11 453
Tercio@11 454 if (frame.MyObject.have_tooltip) then
Tercio@11 455 GameCooltip2:ShowMe (false)
Tercio@11 456 end
Tercio@11 457 end
Tercio@11 458
Tercio@11 459 local OnHide = function (frame)
Tercio@11 460 if (frame.MyObject.OnHideHook) then
Tercio@11 461 local interrupt = frame.MyObject.OnHideHook (frame)
Tercio@11 462 if (interrupt) then
Tercio@11 463 return
Tercio@11 464 end
Tercio@11 465 end
Tercio@11 466 end
Tercio@11 467
Tercio@11 468 local OnShow = function (frame)
Tercio@11 469 if (frame.MyObject.OnShowHook) then
Tercio@11 470 local interrupt = frame.MyObject.OnShowHook (frame)
Tercio@11 471 if (interrupt) then
Tercio@11 472 return
Tercio@11 473 end
Tercio@11 474 end
Tercio@11 475 end
Tercio@11 476
Tercio@11 477 local OnMouseDown = function (frame, button)
Tercio@11 478 if (frame.MyObject.OnMouseDownHook) then
Tercio@11 479 local interrupt = frame.MyObject.OnMouseDownHook (frame, button)
Tercio@11 480 if (interrupt) then
Tercio@11 481 return
Tercio@11 482 end
Tercio@11 483 end
Tercio@11 484
Tercio@11 485 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 486 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 487 frame.MyObject.container.isMoving = true
Tercio@11 488 frame.MyObject.container:StartMoving()
Tercio@11 489 end
Tercio@11 490 end
Tercio@11 491 end
Tercio@11 492
Tercio@11 493 local OnMouseUp = function (frame, button)
Tercio@11 494 if (frame.MyObject.OnMouseUpHook) then
Tercio@11 495 local interrupt = frame.MyObject.OnMouseUpHook (frame, button)
Tercio@11 496 if (interrupt) then
Tercio@11 497 return
Tercio@11 498 end
Tercio@11 499 end
Tercio@11 500
Tercio@11 501 if (frame.MyObject.container.isMoving) then
Tercio@11 502 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 503 frame.MyObject.container.isMoving = false
Tercio@11 504 end
Tercio@11 505 end
Tercio@11 506
Tercio@11 507 ------------------------------------------------------------------------------------------------------------
Tercio@11 508 --> timer
Tercio@11 509
Tercio@11 510 function BarMetaFunctions:OnTimerEnd()
Tercio@11 511 if (self.OnTimerEndHook) then
Tercio@11 512 local interrupt = self.OnTimerEndHook()
Tercio@11 513 if (interrupt) then
Tercio@11 514 return
Tercio@11 515 end
Tercio@11 516 end
Tercio@11 517 self.timer_texture:Hide()
Tercio@11 518 self.div_timer:Hide()
Tercio@11 519 self:Hide()
Tercio@11 520 self.timer = false
Tercio@11 521 end
Tercio@11 522
Tercio@11 523 local OnUpdate = function (self, elapsed)
Tercio@11 524 local timepct = (elapsed / self.tempo) * 100
Tercio@11 525 self.c = self.c - (timepct*self.width/100)
Tercio@11 526 self.remaining = self.remaining - elapsed
Tercio@11 527 self.righttext:SetText (_math_floor (self.remaining))
Tercio@11 528 self.timertexture:SetWidth (self.c)
Tercio@11 529 if (self.c < 1) then
Tercio@11 530 self:SetScript ("OnUpdate", nil)
Tercio@11 531 self.MyObject:OnTimerEnd()
Tercio@11 532 end
Tercio@11 533 end
Tercio@11 534
Tercio@11 535 function BarMetaFunctions:SetTimer (tempo)
Tercio@11 536
Tercio@11 537 self.statusbar.width = self.statusbar:GetWidth()
Tercio@11 538 self.statusbar.tempo = tempo
Tercio@11 539 self.statusbar.remaining = tempo
Tercio@11 540 self.statusbar.c = self.statusbar.width
Tercio@11 541
Tercio@11 542 self.timer_texture:Show()
Tercio@11 543 self.timer_texture:SetWidth (self.statusbar.width)
Tercio@11 544 self.statusbar.t = self.timer_texture
Tercio@11 545 self (1)
Tercio@11 546
Tercio@11 547 self.div_timer:Show()
Tercio@11 548 self.background:Show()
Tercio@22 549 self:Show()
Tercio@11 550
Tercio@11 551 self.timer = true
Tercio@11 552
Tercio@11 553 self.statusbar:SetScript ("OnUpdate", OnUpdate)
Tercio@11 554 end
Tercio@11 555
Tercio@11 556 ------------------------------------------------------------------------------------------------------------
Tercio@11 557 --> object constructor
Tercio@11 558
Tercio@11 559 function DetailsFrameworkNormalBar_OnCreate (self)
Tercio@11 560 self.texture.original_colors = {1, 1, 1, 1}
Tercio@11 561 self.background.original_colors = {.3, .3, .3, .3}
Tercio@11 562 self.timertexture.original_colors = {.3, .3, .3, .3}
Tercio@11 563 return true
Tercio@11 564 end
Tercio@11 565
Tercio@11 566 function DF:CreateBar (parent, texture, w, h, value, member, name)
Tercio@11 567 return DF:NewBar (parent, parent, name, member, w, h, value, texture)
Tercio@11 568 end
Tercio@11 569
Tercio@11 570 function DF:NewBar (parent, container, name, member, w, h, value, texture_name)
Tercio@11 571
Tercio@11 572 if (not name) then
Tercio@11 573 name = "DetailsFrameworkBarNumber" .. DF.BarNameCounter
Tercio@11 574 DF.BarNameCounter = DF.BarNameCounter + 1
Tercio@11 575
Tercio@11 576 elseif (not parent) then
Tercio@11 577 return nil
Tercio@11 578 elseif (not container) then
Tercio@11 579 container = parent
Tercio@11 580 end
Tercio@11 581
Tercio@11 582 if (name:find ("$parent")) then
Tercio@11 583 name = name:gsub ("$parent", parent:GetName())
Tercio@11 584 end
Tercio@11 585
Tercio@11 586 local BarObject = {type = "bar", dframework = true}
Tercio@11 587
Tercio@11 588 if (member) then
Tercio@11 589 parent [member] = BarObject
Tercio@11 590 end
Tercio@11 591
Tercio@11 592 if (parent.dframework) then
Tercio@11 593 parent = parent.widget
Tercio@11 594 end
Tercio@11 595 if (container.dframework) then
Tercio@11 596 container = container.widget
Tercio@11 597 end
Tercio@11 598
Tercio@11 599 value = value or 0
Tercio@11 600 w = w or 150
Tercio@11 601 h = h or 14
Tercio@11 602
Tercio@11 603 --> default members:
Tercio@11 604 --> hooks
Tercio@11 605 BarObject.OnEnterHook = nil
Tercio@11 606 BarObject.OnLeaveHook = nil
Tercio@11 607 BarObject.OnHideHook = nil
Tercio@11 608 BarObject.OnShowHook = nil
Tercio@11 609 BarObject.OnMouseDownHook = nil
Tercio@11 610 BarObject.OnMouseUpHook = nil
Tercio@11 611 BarObject.OnTimerEndHook = nil
Tercio@11 612 --> misc
Tercio@11 613 BarObject.tooltip = nil
Tercio@11 614 BarObject.locked = false
Tercio@11 615 BarObject.have_tooltip = nil
Tercio@11 616
Tercio@11 617 BarObject.container = container
Tercio@11 618
Tercio@11 619 --> create widgets
Tercio@11 620 BarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkNormalBarTemplate")
Tercio@11 621 BarObject.widget = BarObject.statusbar
Tercio@11 622
Tercio@11 623 if (not APIBarFunctions) then
Tercio@11 624 APIBarFunctions = true
Tercio@11 625 local idx = getmetatable (BarObject.statusbar).__index
Tercio@11 626 for funcName, funcAddress in pairs (idx) do
Tercio@11 627 if (not BarMetaFunctions [funcName]) then
Tercio@11 628 BarMetaFunctions [funcName] = function (object, ...)
Tercio@20 629 local x = loadstring ( "return _G['"..object.statusbar:GetName().."']:"..funcName.."(...)")
Tercio@11 630 return x (...)
Tercio@11 631 end
Tercio@11 632 end
Tercio@11 633 end
Tercio@11 634 end
Tercio@11 635
Tercio@11 636 BarObject.statusbar:SetHeight (h)
Tercio@11 637 BarObject.statusbar:SetWidth (w)
Tercio@11 638 BarObject.statusbar:SetFrameLevel (parent:GetFrameLevel()+1)
Tercio@11 639 BarObject.statusbar:SetMinMaxValues (0, 100)
Tercio@11 640 BarObject.statusbar:SetValue (value or 50)
Tercio@11 641 BarObject.statusbar.MyObject = BarObject
Tercio@11 642
Tercio@11 643 BarObject.timer_texture = _G [name .. "_timerTexture"]
Tercio@11 644 BarObject.timer_texture:SetWidth (w)
Tercio@11 645 BarObject.timer_texture:SetHeight (h)
Tercio@11 646
Tercio@11 647 BarObject._texture = _G [name .. "_statusbarTexture"]
Tercio@11 648 BarObject.background = _G [name .. "_background"]
Tercio@11 649 BarObject._icon = _G [name .. "_icon"]
Tercio@11 650 BarObject.textleft = _G [name .. "_TextLeft"]
Tercio@11 651 BarObject.textright = _G [name .. "_TextRight"]
Tercio@11 652 BarObject.div = _G [name .. "_sparkMouseover"]
Tercio@11 653 BarObject.div_timer = _G [name .. "_sparkTimer"]
Tercio@11 654
Tercio@11 655 --> hooks
Tercio@11 656 BarObject.statusbar:SetScript ("OnEnter", OnEnter)
Tercio@11 657 BarObject.statusbar:SetScript ("OnLeave", OnLeave)
Tercio@11 658 BarObject.statusbar:SetScript ("OnHide", OnHide)
Tercio@11 659 BarObject.statusbar:SetScript ("OnShow", OnShow)
Tercio@11 660 BarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 661 BarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 662
Tercio@11 663 --> set class
Tercio@11 664 _setmetatable (BarObject, BarMetaFunctions)
Tercio@11 665
Tercio@11 666 --> set texture
Tercio@11 667 if (texture_name) then
Tercio@11 668 smember_texture (BarObject, texture_name)
Tercio@11 669 end
Tercio@11 670
Tercio@11 671 return BarObject
Tercio@11 672 end