annotate Libs/DF/normal_bar.lua @ 25:6bb668a41455

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