annotate Libs/DF/normal_bar.lua @ 58:0682d738499b v8.0.1.058

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