annotate Libs/DF/panel.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents
children f635adb94909
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 --> lua locals
Tercio@11 8 local _rawset = rawset --> lua local
Tercio@11 9 local _rawget = rawget --> lua local
Tercio@11 10 local _setmetatable = setmetatable --> lua local
Tercio@11 11 local _unpack = unpack --> lua local
Tercio@11 12 local _type = type --> lua local
Tercio@11 13 local _math_floor = math.floor --> lua local
Tercio@11 14 local loadstring = loadstring --> lua local
Tercio@11 15
Tercio@11 16 local cleanfunction = function() end
Tercio@11 17 local PanelMetaFunctions = {}
Tercio@11 18 local APIFrameFunctions
Tercio@11 19
Tercio@11 20 local simple_panel_counter = 1
Tercio@11 21
Tercio@11 22 ------------------------------------------------------------------------------------------------------------
Tercio@11 23 --> metatables
Tercio@11 24
Tercio@11 25 PanelMetaFunctions.__call = function (_table, value)
Tercio@11 26 --> nothing to do
Tercio@11 27 return true
Tercio@11 28 end
Tercio@11 29
Tercio@11 30 ------------------------------------------------------------------------------------------------------------
Tercio@11 31 --> members
Tercio@11 32
Tercio@11 33 --> tooltip
Tercio@11 34 local gmember_tooltip = function (_object)
Tercio@11 35 return _object:GetTooltip()
Tercio@11 36 end
Tercio@11 37 --> shown
Tercio@11 38 local gmember_shown = function (_object)
Tercio@11 39 return _object:IsShown()
Tercio@11 40 end
Tercio@11 41 --> backdrop color
Tercio@11 42 local gmember_color = function (_object)
Tercio@11 43 return _object.frame:GetBackdropColor()
Tercio@11 44 end
Tercio@11 45 --> backdrop table
Tercio@11 46 local gmember_backdrop = function (_object)
Tercio@11 47 return _object.frame:GetBackdrop()
Tercio@11 48 end
Tercio@11 49 --> frame width
Tercio@11 50 local gmember_width = function (_object)
Tercio@11 51 return _object.frame:GetWidth()
Tercio@11 52 end
Tercio@11 53 --> frame height
Tercio@11 54 local gmember_height = function (_object)
Tercio@11 55 return _object.frame:GetHeight()
Tercio@11 56 end
Tercio@11 57 --> locked
Tercio@11 58 local gmember_locked = function (_object)
Tercio@11 59 return _rawget (_object, "is_locked")
Tercio@11 60 end
Tercio@11 61
Tercio@11 62 local get_members_function_index = {
Tercio@11 63 ["tooltip"] = gmember_tooltip,
Tercio@11 64 ["shown"] = gmember_shown,
Tercio@11 65 ["color"] = gmember_color,
Tercio@11 66 ["backdrop"] = gmember_backdrop,
Tercio@11 67 ["width"] = gmember_width,
Tercio@11 68 ["height"] = gmember_height,
Tercio@11 69 ["locked"] = gmember_locked,
Tercio@11 70 }
Tercio@11 71
Tercio@11 72 PanelMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 73
Tercio@11 74 local func = get_members_function_index [_member_requested]
Tercio@11 75 if (func) then
Tercio@11 76 return func (_table, _member_requested)
Tercio@11 77 end
Tercio@11 78
Tercio@11 79 local fromMe = _rawget (_table, _member_requested)
Tercio@11 80 if (fromMe) then
Tercio@11 81 return fromMe
Tercio@11 82 end
Tercio@11 83
Tercio@11 84 return PanelMetaFunctions [_member_requested]
Tercio@11 85 end
Tercio@11 86
Tercio@11 87
Tercio@11 88 --> tooltip
Tercio@11 89 local smember_tooltip = function (_object, _value)
Tercio@11 90 return _object:SetTooltip (_value)
Tercio@11 91 end
Tercio@11 92 --> show
Tercio@11 93 local smember_show = function (_object, _value)
Tercio@11 94 if (_value) then
Tercio@11 95 return _object:Show()
Tercio@11 96 else
Tercio@11 97 return _object:Hide()
Tercio@11 98 end
Tercio@11 99 end
Tercio@11 100 --> hide
Tercio@11 101 local smember_hide = function (_object, _value)
Tercio@11 102 if (not _value) then
Tercio@11 103 return _object:Show()
Tercio@11 104 else
Tercio@11 105 return _object:Hide()
Tercio@11 106 end
Tercio@11 107 end
Tercio@11 108 --> backdrop color
Tercio@11 109 local smember_color = function (_object, _value)
Tercio@11 110 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 111 return _object:SetBackdropColor (_value1, _value2, _value3, _value4)
Tercio@11 112 end
Tercio@11 113 --> frame width
Tercio@11 114 local smember_width = function (_object, _value)
Tercio@11 115 return _object.frame:SetWidth (_value)
Tercio@11 116 end
Tercio@11 117 --> frame height
Tercio@11 118 local smember_height = function (_object, _value)
Tercio@11 119 return _object.frame:SetHeight (_value)
Tercio@11 120 end
Tercio@11 121
Tercio@11 122 --> locked
Tercio@11 123 local smember_locked = function (_object, _value)
Tercio@11 124 if (_value) then
Tercio@11 125 _object.frame:SetMovable (false)
Tercio@11 126 return _rawset (_object, "is_locked", true)
Tercio@11 127 else
Tercio@11 128 _object.frame:SetMovable (true)
Tercio@11 129 _rawset (_object, "is_locked", false)
Tercio@11 130 return
Tercio@11 131 end
Tercio@11 132 end
Tercio@11 133
Tercio@11 134 --> backdrop
Tercio@11 135 local smember_backdrop = function (_object, _value)
Tercio@11 136 return _object.frame:SetBackdrop (_value)
Tercio@11 137 end
Tercio@11 138
Tercio@11 139 --> close with right button
Tercio@11 140 local smember_right_close = function (_object, _value)
Tercio@11 141 return _rawset (_object, "rightButtonClose", _value)
Tercio@11 142 end
Tercio@11 143
Tercio@11 144 local set_members_function_index = {
Tercio@11 145 ["tooltip"] = smember_tooltip,
Tercio@11 146 ["show"] = smember_show,
Tercio@11 147 ["hide"] = smember_hide,
Tercio@11 148 ["color"] = smember_color,
Tercio@11 149 ["backdrop"] = smember_backdrop,
Tercio@11 150 ["width"] = smember_width,
Tercio@11 151 ["height"] = smember_height,
Tercio@11 152 ["locked"] = smember_locked,
Tercio@11 153 ["close_with_right"] = smember_right_close,
Tercio@11 154 }
Tercio@11 155
Tercio@11 156 PanelMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 157 local func = set_members_function_index [_key]
Tercio@11 158 if (func) then
Tercio@11 159 return func (_table, _value)
Tercio@11 160 else
Tercio@11 161 return _rawset (_table, _key, _value)
Tercio@11 162 end
Tercio@11 163 end
Tercio@11 164
Tercio@11 165 ------------------------------------------------------------------------------------------------------------
Tercio@11 166 --> methods
Tercio@11 167
Tercio@11 168 --> right click to close
Tercio@11 169 function PanelMetaFunctions:CreateRightClickLabel (textType, w, h, close_text)
Tercio@11 170 local text
Tercio@11 171 w = w or 20
Tercio@11 172 h = h or 20
Tercio@11 173
Tercio@11 174 if (close_text) then
Tercio@11 175 text = close_text
Tercio@11 176 else
Tercio@11 177 if (textType) then
Tercio@11 178 textType = string.lower (textType)
Tercio@11 179 if (textType == "short") then
Tercio@11 180 text = "close window"
Tercio@11 181 elseif (textType == "medium") then
Tercio@11 182 text = "close window"
Tercio@11 183 elseif (textType == "large") then
Tercio@11 184 text = "close window"
Tercio@11 185 end
Tercio@11 186 else
Tercio@11 187 text = "close window"
Tercio@11 188 end
Tercio@11 189 end
Tercio@11 190
Tercio@11 191 return DF:NewLabel (self, _, "$parentRightMouseToClose", nil, "|TInterface\\TUTORIALFRAME\\UI-TUTORIAL-FRAME:"..w..":"..h..":0:1:512:512:8:70:328:409|t " .. text)
Tercio@11 192 end
Tercio@11 193
Tercio@11 194 --> show & hide
Tercio@11 195 function PanelMetaFunctions:Show()
Tercio@11 196 self.frame:Show()
Tercio@11 197
Tercio@11 198 end
Tercio@11 199 function PanelMetaFunctions:Hide()
Tercio@11 200 self.frame:Hide()
Tercio@11 201
Tercio@11 202 end
Tercio@11 203
Tercio@11 204 -- setpoint
Tercio@11 205 function PanelMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 206 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 207 if (not v1) then
Tercio@11 208 print ("Invalid parameter for SetPoint")
Tercio@11 209 return
Tercio@11 210 end
Tercio@11 211 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 212 end
Tercio@11 213
Tercio@11 214 -- sizes
Tercio@11 215 function PanelMetaFunctions:SetSize (w, h)
Tercio@11 216 if (w) then
Tercio@11 217 self.frame:SetWidth (w)
Tercio@11 218 end
Tercio@11 219 if (h) then
Tercio@11 220 self.frame:SetHeight (h)
Tercio@11 221 end
Tercio@11 222 end
Tercio@11 223
Tercio@11 224 -- clear
Tercio@11 225 function PanelMetaFunctions:HideWidgets()
Tercio@11 226 for widgetName, widgetSelf in pairs (self) do
Tercio@11 227 if (type (widgetSelf) == "table" and widgetSelf.dframework) then
Tercio@11 228 widgetSelf:Hide()
Tercio@11 229 end
Tercio@11 230 end
Tercio@11 231 end
Tercio@11 232
Tercio@11 233 -- backdrop
Tercio@11 234 function PanelMetaFunctions:SetBackdrop (background, edge, tilesize, edgesize, tile, left, right, top, bottom)
Tercio@11 235
Tercio@11 236 if (_type (background) == "boolean" and not background) then
Tercio@11 237 return self.frame:SetBackdrop (nil)
Tercio@11 238
Tercio@11 239 elseif (_type (background) == "table") then
Tercio@11 240 self.frame:SetBackdrop (background)
Tercio@11 241
Tercio@11 242 else
Tercio@11 243 local currentBackdrop = self.frame:GetBackdrop() or {edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", tile=true, tileSize=16, edgeSize=16, insets={left=1, right=0, top=0, bottom=0}}
Tercio@11 244 currentBackdrop.bgFile = background or currentBackdrop.bgFile
Tercio@11 245 currentBackdrop.edgeFile = edgeFile or currentBackdrop.edgeFile
Tercio@11 246 currentBackdrop.tileSize = tilesize or currentBackdrop.tileSize
Tercio@11 247 currentBackdrop.edgeSize = edgesize or currentBackdrop.edgeSize
Tercio@11 248 currentBackdrop.tile = tile or currentBackdrop.tile
Tercio@11 249 currentBackdrop.insets.left = left or currentBackdrop.insets.left
Tercio@11 250 currentBackdrop.insets.right = left or currentBackdrop.insets.right
Tercio@11 251 currentBackdrop.insets.top = left or currentBackdrop.insets.top
Tercio@11 252 currentBackdrop.insets.bottom = left or currentBackdrop.insets.bottom
Tercio@11 253 self.frame:SetBackdrop (currentBackdrop)
Tercio@11 254 end
Tercio@11 255 end
Tercio@11 256
Tercio@11 257 -- backdropcolor
Tercio@11 258 function PanelMetaFunctions:SetBackdropColor (color, arg2, arg3, arg4)
Tercio@11 259 if (arg2) then
Tercio@11 260 self.frame:SetBackdropColor (color, arg2, arg3, arg4 or 1)
Tercio@11 261 self.frame.Gradient.OnLeave = {color, arg2, arg3, arg4 or 1}
Tercio@11 262 else
Tercio@11 263 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 264 self.frame:SetBackdropColor (_value1, _value2, _value3, _value4)
Tercio@11 265 self.frame.Gradient.OnLeave = {_value1, _value2, _value3, _value4}
Tercio@11 266 end
Tercio@11 267 end
Tercio@11 268
Tercio@11 269 -- border color
Tercio@11 270 function PanelMetaFunctions:SetBackdropBorderColor (color, arg2, arg3, arg4)
Tercio@11 271 if (arg2) then
Tercio@11 272 return self.frame:SetBackdropBorderColor (color, arg2, arg3, arg4)
Tercio@11 273 end
Tercio@11 274 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 275 self.frame:SetBackdropBorderColor (_value1, _value2, _value3, _value4)
Tercio@11 276 end
Tercio@11 277
Tercio@11 278 -- gradient colors
Tercio@11 279 function PanelMetaFunctions:SetGradient (FadeType, color)
Tercio@11 280 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 281 if (FadeType == "OnEnter") then
Tercio@11 282 self.frame.Gradient.OnEnter = {_value1, _value2, _value3, _value4}
Tercio@11 283 elseif (FadeType == "OnLeave") then
Tercio@11 284 self.frame.Gradient.OnLeave = {_value1, _value2, _value3, _value4}
Tercio@11 285 end
Tercio@11 286 end
Tercio@11 287
Tercio@11 288 -- tooltip
Tercio@11 289 function PanelMetaFunctions:SetTooltip (tooltip)
Tercio@11 290 if (tooltip) then
Tercio@11 291 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 292 else
Tercio@11 293 return _rawset (self, "have_tooltip", nil)
Tercio@11 294 end
Tercio@11 295 end
Tercio@11 296 function PanelMetaFunctions:GetTooltip()
Tercio@11 297 return _rawget (self, "have_tooltip")
Tercio@11 298 end
Tercio@11 299
Tercio@11 300 -- frame levels
Tercio@11 301 function PanelMetaFunctions:GetFrameLevel()
Tercio@11 302 return self.widget:GetFrameLevel()
Tercio@11 303 end
Tercio@11 304 function PanelMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 305 if (not frame) then
Tercio@11 306 return self.widget:SetFrameLevel (level)
Tercio@11 307 else
Tercio@11 308 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 309 return self.widget:SetFrameLevel (framelevel)
Tercio@11 310 end
Tercio@11 311 end
Tercio@11 312
Tercio@11 313 -- frame stratas
Tercio@11 314 function PanelMetaFunctions:SetFrameStrata()
Tercio@11 315 return self.widget:GetFrameStrata()
Tercio@11 316 end
Tercio@11 317 function PanelMetaFunctions:SetFrameStrata (strata)
Tercio@11 318 if (_type (strata) == "table") then
Tercio@11 319 self.widget:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 320 else
Tercio@11 321 self.widget:SetFrameStrata (strata)
Tercio@11 322 end
Tercio@11 323 end
Tercio@11 324
Tercio@11 325 -- enable and disable gradients
Tercio@11 326 function PanelMetaFunctions:DisableGradient()
Tercio@11 327 self.GradientEnabled = false
Tercio@11 328 end
Tercio@11 329 function PanelMetaFunctions:EnableGradient()
Tercio@11 330 self.GradientEnabled = true
Tercio@11 331 end
Tercio@11 332
Tercio@11 333 --> hooks
Tercio@11 334 function PanelMetaFunctions:SetHook (hookType, func)
Tercio@11 335 if (func) then
Tercio@11 336 _rawset (self, hookType.."Hook", func)
Tercio@11 337 else
Tercio@11 338 _rawset (self, hookType.."Hook", nil)
Tercio@11 339 end
Tercio@11 340 end
Tercio@11 341
Tercio@11 342 ------------------------------------------------------------------------------------------------------------
Tercio@11 343 --> scripts
Tercio@11 344
Tercio@11 345 local OnEnter = function (frame)
Tercio@11 346 if (frame.MyObject.OnEnterHook) then
Tercio@11 347 local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject)
Tercio@11 348 if (interrupt) then
Tercio@11 349 return
Tercio@11 350 end
Tercio@11 351 end
Tercio@11 352
Tercio@11 353 if (frame.MyObject.have_tooltip) then
Tercio@11 354 GameCooltip2:Reset()
Tercio@11 355 GameCooltip2:SetType ("tooltip")
Tercio@11 356 GameCooltip2:SetColor ("main", "transparent")
Tercio@11 357 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 358 GameCooltip2:SetOwner (frame)
Tercio@11 359 GameCooltip2:ShowCooltip()
Tercio@11 360 end
Tercio@11 361 end
Tercio@11 362
Tercio@11 363 local OnLeave = function (frame)
Tercio@11 364 if (frame.MyObject.OnLeaveHook) then
Tercio@11 365 local interrupt = frame.MyObject.OnLeaveHook (frame, frame.MyObject)
Tercio@11 366 if (interrupt) then
Tercio@11 367 return
Tercio@11 368 end
Tercio@11 369 end
Tercio@11 370
Tercio@11 371 if (frame.MyObject.have_tooltip) then
Tercio@11 372 GameCooltip2:ShowMe (false)
Tercio@11 373 end
Tercio@11 374
Tercio@11 375 end
Tercio@11 376
Tercio@11 377 local OnHide = function (frame)
Tercio@11 378 if (frame.MyObject.OnHideHook) then
Tercio@11 379 local interrupt = frame.MyObject.OnHideHook (frame, frame.MyObject)
Tercio@11 380 if (interrupt) then
Tercio@11 381 return
Tercio@11 382 end
Tercio@11 383 end
Tercio@11 384 end
Tercio@11 385
Tercio@11 386 local OnShow = function (frame)
Tercio@11 387 if (frame.MyObject.OnShowHook) then
Tercio@11 388 local interrupt = frame.MyObject.OnShowHook (frame, frame.MyObject)
Tercio@11 389 if (interrupt) then
Tercio@11 390 return
Tercio@11 391 end
Tercio@11 392 end
Tercio@11 393 end
Tercio@11 394
Tercio@11 395 local OnMouseDown = function (frame, button)
Tercio@11 396 if (frame.MyObject.OnMouseDownHook) then
Tercio@11 397 local interrupt = frame.MyObject.OnMouseDownHook (frame, button, frame.MyObject)
Tercio@11 398 if (interrupt) then
Tercio@11 399 return
Tercio@11 400 end
Tercio@11 401 end
Tercio@11 402
Tercio@11 403 if (frame.MyObject.container == UIParent) then
Tercio@11 404 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 405 frame.isMoving = true
Tercio@11 406 frame:StartMoving()
Tercio@11 407 end
Tercio@11 408
Tercio@11 409 elseif (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 410 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 411 frame.MyObject.container.isMoving = true
Tercio@11 412 frame.MyObject.container:StartMoving()
Tercio@11 413 end
Tercio@11 414 end
Tercio@11 415
Tercio@11 416
Tercio@11 417 end
Tercio@11 418
Tercio@11 419 local OnMouseUp = function (frame, button)
Tercio@11 420 if (frame.MyObject.OnMouseUpHook) then
Tercio@11 421 local interrupt = frame.MyObject.OnMouseUpHook (frame, button, frame.MyObject)
Tercio@11 422 if (interrupt) then
Tercio@11 423 return
Tercio@11 424 end
Tercio@11 425 end
Tercio@11 426
Tercio@11 427 if (button == "RightButton" and frame.MyObject.rightButtonClose) then
Tercio@11 428 frame.MyObject:Hide()
Tercio@11 429 end
Tercio@11 430
Tercio@11 431 if (frame.MyObject.container == UIParent) then
Tercio@11 432 if (frame.isMoving) then
Tercio@11 433 frame:StopMovingOrSizing()
Tercio@11 434 frame.isMoving = false
Tercio@11 435 end
Tercio@11 436 else
Tercio@11 437 if (frame.MyObject.container.isMoving) then
Tercio@11 438 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 439 frame.MyObject.container.isMoving = false
Tercio@11 440 end
Tercio@11 441 end
Tercio@11 442 end
Tercio@11 443
Tercio@11 444 ------------------------------------------------------------------------------------------------------------
Tercio@11 445 --> object constructor
Tercio@11 446 function DF:CreatePanel (parent, w, h, backdrop, backdropcolor, bordercolor, member, name)
Tercio@11 447 return DF:NewPanel (parent, parent, name, member, w, h, backdrop, backdropcolor, bordercolor)
Tercio@11 448 end
Tercio@11 449
Tercio@11 450 function DF:NewPanel (parent, container, name, member, w, h, backdrop, backdropcolor, bordercolor)
Tercio@11 451
Tercio@11 452 if (not name) then
Tercio@11 453 name = "DetailsFrameworkPanelNumber" .. DF.PanelCounter
Tercio@11 454 DF.PanelCounter = DF.PanelCounter + 1
Tercio@11 455
Tercio@11 456 elseif (not parent) then
Tercio@11 457 parent = UIParent
Tercio@11 458 end
Tercio@11 459 if (not container) then
Tercio@11 460 container = parent
Tercio@11 461 end
Tercio@11 462
Tercio@11 463 if (name:find ("$parent")) then
Tercio@11 464 name = name:gsub ("$parent", parent:GetName())
Tercio@11 465 end
Tercio@11 466
Tercio@11 467 local PanelObject = {type = "panel", dframework = true}
Tercio@11 468
Tercio@11 469 if (member) then
Tercio@11 470 parent [member] = PanelObject
Tercio@11 471 end
Tercio@11 472
Tercio@11 473 if (parent.dframework) then
Tercio@11 474 parent = parent.widget
Tercio@11 475 end
Tercio@11 476 if (container.dframework) then
Tercio@11 477 container = container.widget
Tercio@11 478 end
Tercio@11 479
Tercio@11 480
Tercio@11 481 --> default members:
Tercio@11 482 --> hooks
Tercio@11 483 PanelObject.OnEnterHook = nil
Tercio@11 484 PanelObject.OnLeaveHook = nil
Tercio@11 485 PanelObject.OnHideHook = nil
Tercio@11 486 PanelObject.OnShowHook = nil
Tercio@11 487 PanelObject.OnMouseDownHook = nil
Tercio@11 488 PanelObject.OnMouseUpHook = nil
Tercio@11 489 --> misc
Tercio@11 490 PanelObject.is_locked = true
Tercio@11 491 PanelObject.GradientEnabled = true
Tercio@11 492 PanelObject.container = container
Tercio@11 493 PanelObject.rightButtonClose = false
Tercio@11 494
Tercio@11 495 PanelObject.frame = CreateFrame ("frame", name, parent, "DetailsFrameworkPanelTemplate")
Tercio@11 496 PanelObject.widget = PanelObject.frame
Tercio@11 497
Tercio@11 498 if (not APIFrameFunctions) then
Tercio@11 499 APIFrameFunctions = {}
Tercio@11 500 local idx = getmetatable (PanelObject.frame).__index
Tercio@11 501 for funcName, funcAddress in pairs (idx) do
Tercio@11 502 if (not PanelMetaFunctions [funcName]) then
Tercio@11 503 PanelMetaFunctions [funcName] = function (object, ...)
Tercio@11 504 local x = loadstring ( "return _G."..object.frame:GetName()..":"..funcName.."(...)")
Tercio@11 505 return x (...)
Tercio@11 506 end
Tercio@11 507 end
Tercio@11 508 end
Tercio@11 509 end
Tercio@11 510
Tercio@11 511 PanelObject.frame:SetWidth (w or 100)
Tercio@11 512 PanelObject.frame:SetHeight (h or 100)
Tercio@11 513
Tercio@11 514 PanelObject.frame.MyObject = PanelObject
Tercio@11 515
Tercio@11 516 --> hooks
Tercio@11 517 PanelObject.frame:SetScript ("OnEnter", OnEnter)
Tercio@11 518 PanelObject.frame:SetScript ("OnLeave", OnLeave)
Tercio@11 519 PanelObject.frame:SetScript ("OnHide", OnHide)
Tercio@11 520 PanelObject.frame:SetScript ("OnShow", OnShow)
Tercio@11 521 PanelObject.frame:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 522 PanelObject.frame:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 523
Tercio@11 524 _setmetatable (PanelObject, PanelMetaFunctions)
Tercio@11 525
Tercio@11 526 if (backdrop) then
Tercio@11 527 PanelObject:SetBackdrop (backdrop)
Tercio@11 528 elseif (_type (backdrop) == "boolean") then
Tercio@11 529 PanelObject.frame:SetBackdrop (nil)
Tercio@11 530 end
Tercio@11 531
Tercio@11 532 if (backdropcolor) then
Tercio@11 533 PanelObject:SetBackdropColor (backdropcolor)
Tercio@11 534 end
Tercio@11 535
Tercio@11 536 if (bordercolor) then
Tercio@11 537 PanelObject:SetBackdropBorderColor (bordercolor)
Tercio@11 538 end
Tercio@11 539
Tercio@11 540 return PanelObject
Tercio@11 541 end
Tercio@11 542
Tercio@11 543 ------------fill panel
Tercio@11 544
Tercio@11 545 local button_on_enter = function (self)
Tercio@11 546 self.MyObject._icon:SetBlendMode ("ADD")
Tercio@11 547 end
Tercio@11 548 local button_on_leave = function (self)
Tercio@11 549 self.MyObject._icon:SetBlendMode ("BLEND")
Tercio@11 550 end
Tercio@11 551
Tercio@11 552 function DF:CreateFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options)
Tercio@11 553 return DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options)
Tercio@11 554 end
Tercio@11 555
Tercio@11 556 function DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options)
Tercio@11 557
Tercio@11 558 local panel = DF:NewPanel (parent, parent, name, member, w, h)
Tercio@11 559 panel.backdrop = nil
Tercio@11 560
Tercio@11 561 options = options or {rowheight = 20}
Tercio@11 562 panel.rows = {}
Tercio@11 563
Tercio@11 564 for index, t in ipairs (rows) do
Tercio@11 565 local thisrow = DF:NewPanel (panel, panel, "$parentHeader_" .. name .. index, nil, 1, 20)
Tercio@11 566 thisrow.backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]}
Tercio@11 567 thisrow.color = "silver"
Tercio@11 568 thisrow.type = t.type
Tercio@11 569 thisrow.func = t.func
Tercio@11 570 thisrow.name = t.name
Tercio@11 571 thisrow.notext = t.notext
Tercio@11 572 thisrow.icon = t.icon
Tercio@11 573 thisrow.iconalign = t.iconalign
Tercio@11 574
Tercio@11 575 local text = DF:NewLabel (thisrow, nil, name .. "$parentLabel", "text")
Tercio@11 576 text:SetPoint ("left", thisrow, "left", 2, 0)
Tercio@11 577 text:SetText (t.name)
Tercio@11 578
Tercio@11 579 tinsert (panel.rows, thisrow)
Tercio@11 580 end
Tercio@11 581
Tercio@11 582 local cur_width = 0
Tercio@11 583 local row_width = w / #rows
Tercio@11 584
Tercio@11 585 local anchors = {}
Tercio@11 586
Tercio@11 587 for index, row in ipairs (panel.rows) do
Tercio@11 588 if (autowidth) then
Tercio@11 589 row:SetWidth (row_width)
Tercio@11 590 row:SetPoint ("topleft", panel, "topleft", cur_width, 0)
Tercio@11 591 tinsert (anchors, cur_width)
Tercio@11 592 cur_width = cur_width + row_width + 1
Tercio@11 593 else
Tercio@11 594 row:SetPoint ("topleft", panel, "topleft", cur_width, 0)
Tercio@11 595 row.width = rows [index].width
Tercio@11 596 tinsert (anchors, cur_width)
Tercio@11 597 cur_width = cur_width + rows [index].width + 1
Tercio@11 598 end
Tercio@11 599 end
Tercio@11 600
Tercio@11 601 if (autowidth) then
Tercio@11 602 panel.rows [#panel.rows]:SetWidth (row_width - #rows + 1)
Tercio@11 603 else
Tercio@11 604 panel.rows [#panel.rows]:SetWidth (rows [#rows].width - #rows + 1)
Tercio@11 605 end
Tercio@11 606
Tercio@11 607 local refresh_fillbox = function (self)
Tercio@11 608 local offset = FauxScrollFrame_GetOffset (self)
Tercio@11 609 local filled_lines = total_lines()
Tercio@11 610
Tercio@11 611 for index = 1, #self.lines do
Tercio@11 612
Tercio@11 613 local row = self.lines [index]
Tercio@11 614 if (index <= filled_lines) then
Tercio@11 615
Tercio@11 616 local real_index = index + offset
Tercio@11 617
Tercio@11 618 local results = fill_row (real_index)
Tercio@11 619
Tercio@11 620 if (results [1]) then
Tercio@11 621
Tercio@11 622 row:Show()
Tercio@11 623
Tercio@11 624 for i = 1, #row.row_widgets do
Tercio@11 625
Tercio@11 626 row.row_widgets [i].index = real_index
Tercio@11 627
Tercio@11 628 if (panel.rows [i].type == "icon") then
Tercio@11 629
Tercio@11 630 local result = results [i]:gsub (".-%\\", "")
Tercio@11 631 row.row_widgets [i]._icon.texture = results [i]
Tercio@11 632
Tercio@11 633 elseif (panel.rows [i].type == "button") then
Tercio@11 634
Tercio@11 635 if (type (results [i]) == "table") then
Tercio@11 636
Tercio@11 637 if (results [i].text) then
Tercio@11 638 row.row_widgets [i]:SetText (results [i].text)
Tercio@11 639 end
Tercio@11 640
Tercio@11 641 if (results [i].icon) then
Tercio@11 642 row.row_widgets [i]._icon:SetTexture (results [i].icon)
Tercio@11 643 end
Tercio@11 644
Tercio@11 645 if (results [i].func) then
Tercio@11 646 row.row_widgets [i]:SetClickFunction (results [i].func, real_index, results [i].value)
Tercio@11 647 end
Tercio@11 648
Tercio@11 649 else
Tercio@11 650 row.row_widgets [i]:SetText (results [i])
Tercio@11 651 end
Tercio@11 652
Tercio@11 653 else
Tercio@11 654 --< text
Tercio@11 655 row.row_widgets [i]:SetText (results [i])
Tercio@11 656
Tercio@11 657 end
Tercio@11 658 end
Tercio@11 659
Tercio@11 660 else
Tercio@11 661 row:Hide()
Tercio@11 662 for i = 1, #row.row_widgets do
Tercio@11 663 row.row_widgets [i]:SetText ("")
Tercio@11 664 if (panel.rows [i].type == "icon") then
Tercio@11 665 row.row_widgets [i]._icon.texture = ""
Tercio@11 666 end
Tercio@11 667 end
Tercio@11 668 end
Tercio@11 669 else
Tercio@11 670 row:Hide()
Tercio@11 671 for i = 1, #row.row_widgets do
Tercio@11 672 row.row_widgets [i]:SetText ("")
Tercio@11 673 if (panel.rows [i].type == "icon") then
Tercio@11 674 row.row_widgets [i]._icon.texture = ""
Tercio@11 675 end
Tercio@11 676 end
Tercio@11 677 end
Tercio@11 678 end
Tercio@11 679 end
Tercio@11 680
Tercio@11 681 function panel:Refresh()
Tercio@11 682 local filled_lines = total_lines()
Tercio@11 683 local scroll_total_lines = #panel.scrollframe
Tercio@11 684 local line_height = options.rowheight
Tercio@11 685
Tercio@11 686 FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height)
Tercio@11 687 refresh_fillbox (panel.scrollframe)
Tercio@11 688 end
Tercio@11 689
Tercio@11 690 local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate")
Tercio@11 691 scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end)
Tercio@11 692 scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21)
Tercio@11 693 scrollframe:SetPoint ("topright", panel.widget, "topright", -23, -21)
Tercio@11 694 scrollframe:SetPoint ("bottomleft", panel.widget, "bottomleft")
Tercio@11 695 scrollframe:SetPoint ("bottomright", panel.widget, "bottomright", -23, 0)
Tercio@11 696 scrollframe:SetSize (w, h)
Tercio@11 697 panel.scrollframe = scrollframe
Tercio@11 698 scrollframe.lines = {}
Tercio@11 699
Tercio@11 700 --create lines
Tercio@11 701 local size = options.rowheight
Tercio@11 702 local amount = math.floor (((h-21) / size))
Tercio@11 703
Tercio@11 704
Tercio@11 705 for i = 1, amount do
Tercio@11 706
Tercio@11 707 local row = DF:NewPanel (parent, nil, "$parentRow_" .. i, nil, 1, size)
Tercio@11 708 row.backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]]}
Tercio@11 709 row.color = {1, 1, 1, .2}
Tercio@11 710 row:SetPoint ("topleft", scrollframe, "topleft", 0, (i-1) * size * -1)
Tercio@11 711 row:SetPoint ("topright", scrollframe, "topright", 0, (i-1) * size * -1)
Tercio@11 712 tinsert (scrollframe.lines, row)
Tercio@11 713
Tercio@11 714 row.row_widgets = {}
Tercio@11 715
Tercio@11 716 for o = 1, #rows do
Tercio@11 717
Tercio@11 718 local _type = panel.rows [o].type
Tercio@11 719
Tercio@11 720 if (_type == "text") then
Tercio@11 721
Tercio@11 722 --> create text
Tercio@11 723 local text = DF:NewLabel (row, nil, name .. "$parentLabel" .. o, "text" .. o)
Tercio@11 724 text:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 725
Tercio@11 726 --> insert in the table
Tercio@11 727 tinsert (row.row_widgets, text)
Tercio@11 728
Tercio@11 729 elseif (_type == "entry") then
Tercio@11 730
Tercio@11 731 --> create editbox
Tercio@11 732 local editbox = DF:NewTextEntry (row, nil, "$parentEntry" .. o, "entry", panel.rows [o].width, 20, panel.rows [o].func, i, o)
Tercio@11 733 editbox.align = "left"
Tercio@11 734 editbox:SetHook ("OnEnterPressed", function()
Tercio@11 735 editbox.widget.focuslost = true
Tercio@11 736 editbox:ClearFocus()
Tercio@11 737 editbox.func (editbox.index, editbox.text)
Tercio@11 738 return true
Tercio@11 739 end)
Tercio@11 740 editbox:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 741 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1})
Tercio@11 742 editbox:SetBackdropColor (1, 1, 1, 0.1)
Tercio@11 743 editbox:SetBackdropBorderColor (1, 1, 1, 0.1)
Tercio@11 744 editbox.editbox.current_bordercolor = {1, 1, 1, 0.1}
Tercio@11 745
Tercio@11 746 --> insert in the table
Tercio@11 747 tinsert (row.row_widgets, editbox)
Tercio@11 748
Tercio@11 749 elseif (_type == "button") then
Tercio@11 750
Tercio@11 751 --> create button
Tercio@11 752 local button = DF:NewButton (row, nil, "$parentButton" .. o, "button", panel.rows [o].width, 20)
Tercio@11 753
Tercio@11 754 local func = function()
Tercio@11 755 panel.rows [o].func (button.index, o)
Tercio@11 756 panel:Refresh()
Tercio@11 757 end
Tercio@11 758 button:SetClickFunction (func)
Tercio@11 759
Tercio@11 760 button:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 761
Tercio@11 762 --> create icon and the text
Tercio@11 763 local icon = DF:NewImage (button, nil, 20, 20)
Tercio@11 764 local text = DF:NewLabel (button)
Tercio@11 765
Tercio@11 766 button._icon = icon
Tercio@11 767 button._text = text
Tercio@11 768
Tercio@11 769 button:SetHook ("OnEnter", button_on_enter)
Tercio@11 770 button:SetHook ("OnLeave", button_on_leave)
Tercio@11 771
Tercio@11 772 if (panel.rows [o].icon) then
Tercio@11 773 icon.texture = panel.rows [o].icon
Tercio@11 774 if (panel.rows [o].iconalign) then
Tercio@11 775 if (panel.rows [o].iconalign == "center") then
Tercio@11 776 icon:SetPoint ("center", button, "center")
Tercio@11 777 elseif (panel.rows [o].iconalign == "right") then
Tercio@11 778 icon:SetPoint ("right", button, "right")
Tercio@11 779 end
Tercio@11 780 else
Tercio@11 781 icon:SetPoint ("left", button, "left")
Tercio@11 782 end
Tercio@11 783 end
Tercio@11 784
Tercio@11 785 if (panel.rows [o].name and not panel.rows [o].notext) then
Tercio@11 786 text:SetPoint ("left", icon, "right", 2, 0)
Tercio@11 787 text.text = panel.rows [o].name
Tercio@11 788 end
Tercio@11 789
Tercio@11 790 --> inser in the table
Tercio@11 791 tinsert (row.row_widgets, button)
Tercio@11 792
Tercio@11 793 elseif (_type == "icon") then
Tercio@11 794
Tercio@11 795 --> create button and icon
Tercio@11 796 local iconbutton = DF:NewButton (row, nil, "$parentIconButton" .. o, "iconbutton", 22, 20)
Tercio@11 797 iconbutton:InstallCustomTexture()
Tercio@11 798
Tercio@11 799 iconbutton:SetHook ("OnEnter", button_on_enter)
Tercio@11 800 iconbutton:SetHook ("OnLeave", button_on_leave)
Tercio@11 801
Tercio@11 802 --iconbutton:InstallCustomTexture()
Tercio@11 803 local icon = DF:NewImage (iconbutton, nil, 20, 20, "artwork", nil, "_icon", "$parentIcon" .. o)
Tercio@11 804 iconbutton._icon = icon
Tercio@11 805
Tercio@11 806 iconbutton:SetPoint ("left", row, "left", anchors [o] + ( (panel.rows [o].width - 22) / 2), 0)
Tercio@11 807 icon:SetPoint ("center", iconbutton, "center", 0, 0)
Tercio@11 808
Tercio@11 809 --> set functions
Tercio@11 810 local function iconcallback (texture)
Tercio@11 811 iconbutton._icon.texture = texture
Tercio@11 812 panel.rows [o].func (iconbutton.index, texture)
Tercio@11 813 end
Tercio@11 814
Tercio@11 815 iconbutton:SetClickFunction (function()
Tercio@11 816 DF:IconPick (iconcallback, true)
Tercio@11 817 return true
Tercio@11 818 end)
Tercio@11 819
Tercio@11 820 --> insert in the table
Tercio@11 821 tinsert (row.row_widgets, iconbutton)
Tercio@11 822
Tercio@11 823 end
Tercio@11 824
Tercio@11 825 end
Tercio@11 826 end
Tercio@11 827
Tercio@11 828 return panel
Tercio@11 829 end
Tercio@11 830
Tercio@11 831
Tercio@11 832 ------------color pick
Tercio@11 833 local color_pick_func = function()
Tercio@11 834 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 835 local a = OpacitySliderFrame:GetValue()
Tercio@11 836 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 837 end
Tercio@11 838 local color_pick_func_cancel = function()
Tercio@11 839 ColorPickerFrame:SetColorRGB (unpack (ColorPickerFrame.previousValues))
Tercio@11 840 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 841 local a = OpacitySliderFrame:GetValue()
Tercio@11 842 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 843 end
Tercio@11 844
Tercio@11 845 function DF:ColorPick (frame, r, g, b, alpha, callback)
Tercio@11 846
Tercio@11 847 ColorPickerFrame:ClearAllPoints()
Tercio@11 848 ColorPickerFrame:SetPoint ("bottomleft", frame, "topright", 0, 0)
Tercio@11 849
Tercio@11 850 ColorPickerFrame.dcallback = callback
Tercio@11 851 ColorPickerFrame.dframe = frame
Tercio@11 852
Tercio@11 853 ColorPickerFrame.func = color_pick_func
Tercio@11 854 ColorPickerFrame.opacityFunc = color_pick_func
Tercio@11 855 ColorPickerFrame.cancelFunc = color_pick_func_cancel
Tercio@11 856
Tercio@11 857 ColorPickerFrame.opacity = alpha
Tercio@11 858 ColorPickerFrame.hasOpacity = alpha and true
Tercio@11 859
Tercio@11 860 ColorPickerFrame.previousValues = {r, g, b}
Tercio@11 861 ColorPickerFrame:SetParent (UIParent)
Tercio@11 862 ColorPickerFrame:SetFrameStrata ("tooltip")
Tercio@11 863 ColorPickerFrame:SetColorRGB (r, g, b)
Tercio@11 864 ColorPickerFrame:Show()
Tercio@11 865
Tercio@11 866 end
Tercio@11 867
Tercio@11 868 ------------icon pick
Tercio@11 869 function DF:IconPick (callback, close_when_select)
Tercio@11 870
Tercio@11 871 if (not DF.IconPickFrame) then
Tercio@11 872
Tercio@11 873 local string_lower = string.lower
Tercio@11 874
Tercio@11 875 DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent)
Tercio@11 876 tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame")
Tercio@11 877 DF.IconPickFrame:SetFrameStrata ("DIALOG")
Tercio@11 878
Tercio@11 879 DF.IconPickFrame:SetPoint ("center", UIParent, "center")
Tercio@11 880 DF.IconPickFrame:SetWidth (350)
Tercio@11 881 DF.IconPickFrame:SetHeight (227)
Tercio@11 882 DF.IconPickFrame:EnableMouse (true)
Tercio@11 883 DF.IconPickFrame:SetMovable (true)
Tercio@11 884 DF.IconPickFrame:SetBackdrop ({bgFile = DF.folder .. "background", edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Tercio@11 885 tile = true, tileSize = 32, edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}})
Tercio@11 886
Tercio@11 887 DF.IconPickFrame:SetBackdropBorderColor (170/255, 170/255, 170/255)
Tercio@11 888 DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8)
Tercio@11 889 DF.IconPickFrame:SetFrameLevel (1)
Tercio@11 890
Tercio@11 891 DF.IconPickFrame.emptyFunction = function() end
Tercio@11 892 DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction
Tercio@11 893
Tercio@11 894 DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent)
Tercio@11 895 DF.IconPickFrame.preview:SetFrameStrata ("tooltip")
Tercio@11 896 DF.IconPickFrame.preview:SetSize (76, 76)
Tercio@11 897 local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
Tercio@11 898 preview_image:SetAllPoints (DF.IconPickFrame.preview)
Tercio@11 899 DF.IconPickFrame.preview.icon = preview_image
Tercio@11 900 DF.IconPickFrame.preview:Hide()
Tercio@11 901
Tercio@11 902 DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color)
Tercio@11 903 DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -20)
Tercio@11 904 DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20)
Tercio@11 905 DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0)
Tercio@11 906 DF.IconPickFrame.search:SetHook ("OnTextChanged", function()
Tercio@11 907 DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText()
Tercio@11 908 if (DF.IconPickFrame.searching == "") then
Tercio@11 909 DF.IconPickFrameScroll:Show()
Tercio@11 910 DF.IconPickFrame.searching = nil
Tercio@11 911 DF.IconPickFrame.updateFunc()
Tercio@11 912 else
Tercio@11 913 DF.IconPickFrameScroll:Hide()
Tercio@11 914 FauxScrollFrame_SetOffset (DF.IconPickFrame, 1)
Tercio@11 915 DF.IconPickFrame.last_filter_index = 1
Tercio@11 916 DF.IconPickFrame.updateFunc()
Tercio@11 917 end
Tercio@11 918 end)
Tercio@11 919
Tercio@11 920 --> close button
Tercio@11 921 local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton")
Tercio@11 922 close_button:SetWidth (32)
Tercio@11 923 close_button:SetHeight (32)
Tercio@11 924 close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7)
Tercio@11 925 close_button:SetFrameLevel (close_button:GetFrameLevel()+2)
Tercio@11 926
Tercio@11 927 local MACRO_ICON_FILENAMES = {}
Tercio@11 928 DF.IconPickFrame:SetScript ("OnShow", function()
Tercio@11 929
Tercio@11 930 MACRO_ICON_FILENAMES = {};
Tercio@11 931 MACRO_ICON_FILENAMES[1] = "INV_MISC_QUESTIONMARK";
Tercio@11 932 local index = 2;
Tercio@11 933
Tercio@11 934 for i = 1, GetNumSpellTabs() do
Tercio@11 935 local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo(i);
Tercio@11 936 offset = offset + 1;
Tercio@11 937 local tabEnd = offset + numSpells;
Tercio@11 938 for j = offset, tabEnd - 1 do
Tercio@11 939 --to get spell info by slot, you have to pass in a pet argument
Tercio@11 940 local spellType, ID = GetSpellBookItemInfo(j, "player");
Tercio@11 941 if (spellType ~= "FUTURESPELL") then
Tercio@11 942 local spellTexture = strupper(GetSpellBookItemTexture(j, "player"));
Tercio@11 943 if ( not string.match( spellTexture, "INTERFACE\\BUTTONS\\") ) then
Tercio@11 944 MACRO_ICON_FILENAMES[index] = gsub( spellTexture, "INTERFACE\\ICONS\\", "");
Tercio@11 945 index = index + 1;
Tercio@11 946 end
Tercio@11 947 end
Tercio@11 948 if (spellType == "FLYOUT") then
Tercio@11 949 local _, _, numSlots, isKnown = GetFlyoutInfo(ID);
Tercio@11 950 if (isKnown and numSlots > 0) then
Tercio@11 951 for k = 1, numSlots do
Tercio@11 952 local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo(ID, k)
Tercio@11 953 if (isKnown) then
Tercio@11 954 MACRO_ICON_FILENAMES[index] = gsub( strupper(GetSpellTexture(spellID)), "INTERFACE\\ICONS\\", "");
Tercio@11 955 index = index + 1;
Tercio@11 956 end
Tercio@11 957 end
Tercio@11 958 end
Tercio@11 959 end
Tercio@11 960 end
Tercio@11 961 end
Tercio@11 962
Tercio@11 963 GetLooseMacroItemIcons (MACRO_ICON_FILENAMES)
Tercio@11 964 GetLooseMacroIcons (MACRO_ICON_FILENAMES)
Tercio@11 965 GetMacroIcons (MACRO_ICON_FILENAMES)
Tercio@11 966 GetMacroItemIcons (MACRO_ICON_FILENAMES )
Tercio@11 967
Tercio@11 968 end)
Tercio@11 969
Tercio@11 970 DF.IconPickFrame:SetScript ("OnHide", function()
Tercio@11 971 MACRO_ICON_FILENAMES = nil;
Tercio@11 972 collectgarbage()
Tercio@11 973 end)
Tercio@11 974
Tercio@11 975 DF.IconPickFrame.buttons = {}
Tercio@11 976
Tercio@11 977 local OnClickFunction = function (self)
Tercio@11 978 DF.IconPickFrame.callback (self.icon:GetTexture())
Tercio@11 979 if (DF.IconPickFrame.click_close) then
Tercio@11 980 close_button:Click()
Tercio@11 981 end
Tercio@11 982 end
Tercio@11 983
Tercio@11 984 local onenter = function (self)
Tercio@11 985 DF.IconPickFrame.preview:SetPoint ("bottom", self, "top", 0, 2)
Tercio@11 986 DF.IconPickFrame.preview.icon:SetTexture (self.icon:GetTexture())
Tercio@11 987 DF.IconPickFrame.preview:Show()
Tercio@11 988 self.icon:SetBlendMode ("ADD")
Tercio@11 989 end
Tercio@11 990 local onleave = function (self)
Tercio@11 991 DF.IconPickFrame.preview:Hide()
Tercio@11 992 self.icon:SetBlendMode ("BLEND")
Tercio@11 993 end
Tercio@11 994
Tercio@11 995 local backdrop = {bgFile = DF.folder .. "background", tile = true, tileSize = 16,
Tercio@11 996 insets = {left = 0, right = 0, top = 0, bottom = 0}, edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 10}
Tercio@11 997
Tercio@11 998 for i = 0, 9 do
Tercio@11 999 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..(i+1), DF.IconPickFrame)
Tercio@11 1000 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..(i+1).."Icon", "overlay")
Tercio@11 1001 newcheck.icon = image
Tercio@11 1002 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1003 newcheck:SetSize (30, 28)
Tercio@11 1004 newcheck:SetBackdrop (backdrop)
Tercio@11 1005
Tercio@11 1006 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1007 newcheck.param1 = i+1
Tercio@11 1008
Tercio@11 1009 newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -40)
Tercio@11 1010 newcheck:SetID (i+1)
Tercio@11 1011 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1012 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1013 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1014 end
Tercio@11 1015 for i = 11, 20 do
Tercio@11 1016 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1017 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1018 newcheck.icon = image
Tercio@11 1019 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1020 newcheck:SetSize (30, 28)
Tercio@11 1021 newcheck:SetBackdrop (backdrop)
Tercio@11 1022
Tercio@11 1023 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1024 newcheck.param1 = i
Tercio@11 1025
Tercio@11 1026 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1027 newcheck:SetID (i)
Tercio@11 1028 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1029 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1030 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1031 end
Tercio@11 1032 for i = 21, 30 do
Tercio@11 1033 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1034 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1035 newcheck.icon = image
Tercio@11 1036 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1037 newcheck:SetSize (30, 28)
Tercio@11 1038 newcheck:SetBackdrop (backdrop)
Tercio@11 1039
Tercio@11 1040 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1041 newcheck.param1 = i
Tercio@11 1042
Tercio@11 1043 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1044 newcheck:SetID (i)
Tercio@11 1045 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1046 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1047 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1048 end
Tercio@11 1049 for i = 31, 40 do
Tercio@11 1050 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1051 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1052 newcheck.icon = image
Tercio@11 1053 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1054 newcheck:SetSize (30, 28)
Tercio@11 1055 newcheck:SetBackdrop (backdrop)
Tercio@11 1056
Tercio@11 1057 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1058 newcheck.param1 = i
Tercio@11 1059
Tercio@11 1060 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1061 newcheck:SetID (i)
Tercio@11 1062 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1063 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1064 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1065 end
Tercio@11 1066 for i = 41, 50 do
Tercio@11 1067 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1068 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1069 newcheck.icon = image
Tercio@11 1070 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1071 newcheck:SetSize (30, 28)
Tercio@11 1072 newcheck:SetBackdrop (backdrop)
Tercio@11 1073
Tercio@11 1074 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1075 newcheck.param1 = i
Tercio@11 1076
Tercio@11 1077 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1078 newcheck:SetID (i)
Tercio@11 1079 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1080 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1081 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1082 end
Tercio@11 1083 for i = 51, 60 do
Tercio@11 1084 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1085 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1086 newcheck.icon = image
Tercio@11 1087 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1088 newcheck:SetSize (30, 28)
Tercio@11 1089 newcheck:SetBackdrop (backdrop)
Tercio@11 1090
Tercio@11 1091 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1092 newcheck.param1 = i
Tercio@11 1093
Tercio@11 1094 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1095 newcheck:SetID (i)
Tercio@11 1096 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1097 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1098 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1099 end
Tercio@11 1100
Tercio@11 1101 local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate")
Tercio@11 1102
Tercio@11 1103 local ChecksFrame_Update = function (self)
Tercio@11 1104
Tercio@11 1105 local numMacroIcons = #MACRO_ICON_FILENAMES
Tercio@11 1106 local macroPopupIcon, macroPopupButton
Tercio@11 1107 local macroPopupOffset = FauxScrollFrame_GetOffset (scroll)
Tercio@11 1108 local index
Tercio@11 1109
Tercio@11 1110 local texture
Tercio@11 1111 local filter
Tercio@11 1112 if (DF.IconPickFrame.searching) then
Tercio@11 1113 filter = string_lower (DF.IconPickFrame.searching)
Tercio@11 1114 end
Tercio@11 1115
Tercio@11 1116 if (filter and filter ~= "") then
Tercio@11 1117
Tercio@11 1118 local ignored = 0
Tercio@11 1119 local tryed = 0
Tercio@11 1120 local found = 0
Tercio@11 1121 local type = type
Tercio@11 1122 local buttons = DF.IconPickFrame.buttons
Tercio@11 1123 index = 1
Tercio@11 1124
Tercio@11 1125 for i = 1, 60 do
Tercio@11 1126
Tercio@11 1127 macroPopupIcon = buttons[i].icon
Tercio@11 1128 macroPopupButton = buttons[i]
Tercio@11 1129
Tercio@11 1130 for o = index, numMacroIcons do
Tercio@11 1131
Tercio@11 1132 tryed = tryed + 1
Tercio@11 1133
Tercio@11 1134 texture = MACRO_ICON_FILENAMES [o]
Tercio@11 1135 if (type (texture) == "number") then
Tercio@11 1136 macroPopupIcon:SetToFileData (texture)
Tercio@11 1137 texture = macroPopupIcon:GetTexture()
Tercio@11 1138 macroPopupIcon:SetTexture (nil)
Tercio@11 1139 else
Tercio@11 1140 texture = "INTERFACE\\ICONS\\" .. texture
Tercio@11 1141 end
Tercio@11 1142
Tercio@11 1143 if (texture and texture:find (filter)) then
Tercio@11 1144 macroPopupIcon:SetTexture (texture)
Tercio@11 1145 macroPopupButton:Show()
Tercio@11 1146 found = found + 1
Tercio@11 1147 DF.IconPickFrame.last_filter_index = o
Tercio@11 1148 index = o+1
Tercio@11 1149 break
Tercio@11 1150 else
Tercio@11 1151 ignored = ignored + 1
Tercio@11 1152 end
Tercio@11 1153
Tercio@11 1154 end
Tercio@11 1155 end
Tercio@11 1156
Tercio@11 1157 for o = found+1, 60 do
Tercio@11 1158 macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..o]
Tercio@11 1159 macroPopupButton:Hide()
Tercio@11 1160 end
Tercio@11 1161 else
Tercio@11 1162 for i = 1, 60 do
Tercio@11 1163 macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"]
Tercio@11 1164 macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i]
Tercio@11 1165 index = (macroPopupOffset * 10) + i
Tercio@11 1166 texture = MACRO_ICON_FILENAMES [index]
Tercio@11 1167 if ( index <= numMacroIcons and texture ) then
Tercio@11 1168
Tercio@11 1169 if (type (texture) == "number") then
Tercio@11 1170 macroPopupIcon:SetToFileData (texture)
Tercio@11 1171 else
Tercio@11 1172 macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture)
Tercio@11 1173 end
Tercio@11 1174
Tercio@11 1175 macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64)
Tercio@11 1176 macroPopupButton.IconID = index
Tercio@11 1177 macroPopupButton:Show()
Tercio@11 1178 else
Tercio@11 1179 macroPopupButton:Hide()
Tercio@11 1180 end
Tercio@11 1181 end
Tercio@11 1182 end
Tercio@11 1183
Tercio@11 1184 -- Scrollbar stuff
Tercio@11 1185 FauxScrollFrame_Update (scroll, ceil (numMacroIcons / 10) , 5, 20 )
Tercio@11 1186 end
Tercio@11 1187
Tercio@11 1188 DF.IconPickFrame.updateFunc = ChecksFrame_Update
Tercio@11 1189
Tercio@11 1190 scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -37)
Tercio@11 1191 scroll:SetWidth (330)
Tercio@11 1192 scroll:SetHeight (178)
Tercio@11 1193 scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end)
Tercio@11 1194 scroll.update = ChecksFrame_Update
Tercio@11 1195 DF.IconPickFrameScroll = scroll
Tercio@11 1196 DF.IconPickFrame:Hide()
Tercio@11 1197
Tercio@11 1198 end
Tercio@11 1199
Tercio@11 1200 DF.IconPickFrame:Show()
Tercio@11 1201 DF.IconPickFrameScroll.update (DF.IconPickFrameScroll)
Tercio@11 1202 DF.IconPickFrame.callback = callback or DF.IconPickFrame.emptyFunction
Tercio@11 1203 DF.IconPickFrame.click_close = close_when_select
Tercio@11 1204
Tercio@11 1205 end
Tercio@11 1206
Tercio@11 1207 local simple_panel_counter = 1
Tercio@11 1208 local simple_panel_mouse_down = function (self, button)
Tercio@11 1209 if (button == "RightButton") then
Tercio@11 1210 if (self.IsMoving) then
Tercio@11 1211 self.IsMoving = false
Tercio@11 1212 self:StopMovingOrSizing()
Tercio@11 1213 if (self.db and self.db.position) then
Tercio@11 1214 DF:SavePositionOnScreen (self)
Tercio@11 1215 end
Tercio@11 1216 end
Tercio@11 1217 self:Hide()
Tercio@11 1218 return
Tercio@11 1219 end
Tercio@11 1220 if (not self.IsMoving and not self.IsLocked) then
Tercio@11 1221 self.IsMoving = true
Tercio@11 1222 self:StartMoving()
Tercio@11 1223 end
Tercio@11 1224 end
Tercio@11 1225 local simple_panel_mouse_up = function (self, button)
Tercio@11 1226 if (self.IsMoving) then
Tercio@11 1227 self.IsMoving = false
Tercio@11 1228 self:StopMovingOrSizing()
Tercio@11 1229 if (self.db and self.db.position) then
Tercio@11 1230 DF:SavePositionOnScreen (self)
Tercio@11 1231 end
Tercio@11 1232 end
Tercio@11 1233 end
Tercio@11 1234 local simple_panel_settitle = function (self, title)
Tercio@11 1235 self.title:SetText (title)
Tercio@11 1236 end
Tercio@11 1237
Tercio@11 1238 function DF:CreateSimplePanel (parent, w, h, title, name)
Tercio@11 1239
Tercio@11 1240 if (not name) then
Tercio@11 1241 name = "DetailsFrameworkSimplePanel" .. simple_panel_counter
Tercio@11 1242 simple_panel_counter = simple_panel_counter + 1
Tercio@11 1243 end
Tercio@11 1244 if (not parent) then
Tercio@11 1245 parent = UIParent
Tercio@11 1246 end
Tercio@11 1247
Tercio@11 1248 local f = CreateFrame ("frame", name, UIParent)
Tercio@11 1249 f:SetSize (w or 400, h or 250)
Tercio@11 1250 f:SetPoint ("center", UIParent, "center", 0, 0)
Tercio@11 1251 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 1252 f:EnableMouse()
Tercio@11 1253 f:SetMovable (true)
Tercio@11 1254 tinsert (UISpecialFrames, name)
Tercio@11 1255
Tercio@11 1256 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1257 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1258
Tercio@11 1259 local bg = f:CreateTexture (nil, "background")
Tercio@11 1260 bg:SetAllPoints (f)
Tercio@11 1261 bg:SetTexture (DF.folder .. "background")
Tercio@11 1262
Tercio@11 1263 local close = CreateFrame ("button", name .. "Close", f, "UIPanelCloseButton")
Tercio@11 1264 close:SetSize (32, 32)
Tercio@11 1265 close:SetPoint ("topright", f, "topright", 0, -12)
Tercio@11 1266
Tercio@11 1267 f.title = DF:CreateLabel (f, title or "", 12, nil, "GameFontNormal")
Tercio@11 1268 f.title:SetPoint ("top", f, "top", 0, -22)
Tercio@11 1269
Tercio@11 1270 f.SetTitle = simple_panel_settitle
Tercio@11 1271
Tercio@11 1272 simple_panel_counter = simple_panel_counter + 1
Tercio@11 1273
Tercio@11 1274 return f
Tercio@11 1275 end
Tercio@11 1276
Tercio@11 1277 local Panel1PxBackdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 64,
Tercio@11 1278 edgeFile = DF.folder .. "border_3", edgeSize = 9, insets = {left = 2, right = 2, top = 3, bottom = 3}}
Tercio@11 1279
Tercio@11 1280 local Panel1PxOnClickClose = function (self)
Tercio@11 1281 self:GetParent():Hide()
Tercio@11 1282 end
Tercio@11 1283 local Panel1PxOnToggleLock = function (self)
Tercio@11 1284 if (self.IsLocked) then
Tercio@11 1285 self.IsLocked = false
Tercio@11 1286 self:SetMovable (true)
Tercio@11 1287 self:EnableMouse (true)
Tercio@11 1288 self.Lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1289 self.Lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1290 self.Lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1291 else
Tercio@11 1292 self.IsLocked = true
Tercio@11 1293 self:SetMovable (false)
Tercio@11 1294 self:EnableMouse (false)
Tercio@11 1295 self.Lock:GetNormalTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1296 self.Lock:GetHighlightTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1297 self.Lock:GetPushedTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1298 end
Tercio@11 1299 end
Tercio@11 1300 local Panel1PxOnClickLock = function (self)
Tercio@11 1301 local f = self:GetParent()
Tercio@11 1302 Panel1PxOnToggleLock (f)
Tercio@11 1303 end
Tercio@11 1304 local Panel1PxSetTitle = function (self, text)
Tercio@11 1305 self.Title:SetText (text or "")
Tercio@11 1306 end
Tercio@11 1307
Tercio@11 1308 local Panel1PxReadConfig = function (self)
Tercio@11 1309 local db = self.db
Tercio@11 1310 if (db) then
Tercio@11 1311 db.IsLocked = db.IsLocked or false
Tercio@11 1312 self.IsLocked = db.IsLocked
Tercio@11 1313 db.position = db.position or {x = 0, y = 0}
Tercio@11 1314 DF:RestoreFramePosition (self)
Tercio@11 1315 end
Tercio@11 1316 end
Tercio@11 1317
Tercio@11 1318 function DF:SavePositionOnScreen (frame)
Tercio@11 1319 if (frame.db and frame.db.position) then
Tercio@11 1320 local x, y = DF:GetPositionOnScreen (frame)
Tercio@11 1321 frame.db.position.x, frame.db.position.y = x, y
Tercio@11 1322 end
Tercio@11 1323 end
Tercio@11 1324
Tercio@11 1325 function DF:GetPositionOnScreen (frame)
Tercio@11 1326 local xOfs, yOfs = frame:GetCenter()
Tercio@11 1327 if (not xOfs) then
Tercio@11 1328 return
Tercio@11 1329 end
Tercio@11 1330 local scale = frame:GetEffectiveScale()
Tercio@11 1331 local UIscale = UIParent:GetScale()
Tercio@11 1332 xOfs = xOfs*scale - GetScreenWidth()*UIscale/2
Tercio@11 1333 yOfs = yOfs*scale - GetScreenHeight()*UIscale/2
Tercio@11 1334 return xOfs/UIscale, yOfs/UIscale
Tercio@11 1335 end
Tercio@11 1336
Tercio@11 1337 function DF:RestoreFramePosition (frame)
Tercio@11 1338 if (frame.db and frame.db.position) then
Tercio@11 1339 local scale, UIscale = frame:GetEffectiveScale(), UIParent:GetScale()
Tercio@11 1340 frame:ClearAllPoints()
Tercio@11 1341 frame:SetPoint ("center", UIParent, "center", frame.db.position.x * UIscale / scale, frame.db.position.y * UIscale / scale)
Tercio@11 1342 end
Tercio@11 1343 end
Tercio@11 1344
Tercio@11 1345 function DF:Create1PxPanel (parent, w, h, title, name, config, title_anchor)
Tercio@11 1346 local f = CreateFrame ("frame", name, parent or UIParent)
Tercio@11 1347 f:SetSize (w or 100, h or 75)
Tercio@11 1348 f:SetPoint ("center", UIParent, "center")
Tercio@11 1349
Tercio@11 1350 if (name) then
Tercio@11 1351 tinsert (UISpecialFrames, name)
Tercio@11 1352 end
Tercio@11 1353
Tercio@11 1354 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1355 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1356
Tercio@11 1357 f:SetBackdrop (Panel1PxBackdrop)
Tercio@11 1358 f:SetBackdropColor (0, 0, 0, 0.5)
Tercio@11 1359
Tercio@11 1360 f.IsLocked = false
Tercio@11 1361 f:SetMovable (true)
Tercio@11 1362 f:EnableMouse (true)
Tercio@11 1363 f:SetUserPlaced (true)
Tercio@11 1364
Tercio@11 1365 f.db = config
Tercio@11 1366 Panel1PxReadConfig (f)
Tercio@11 1367
Tercio@11 1368 local close = CreateFrame ("button", name and name .. "CloseButton", f)
Tercio@11 1369 close:SetSize (16, 16)
Tercio@11 1370 close:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1371 close:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1372 close:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1373 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1374 close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1375 close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1376 close:SetAlpha (0.7)
Tercio@11 1377
Tercio@11 1378 local lock = CreateFrame ("button", name and name .. "LockButton", f)
Tercio@11 1379 lock:SetSize (16, 16)
Tercio@11 1380 lock:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1381 lock:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1382 lock:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1383 lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1384 lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1385 lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1386 lock:SetAlpha (0.7)
Tercio@11 1387
Tercio@11 1388 close:SetPoint ("topright", f, "topright", -3, -3)
Tercio@11 1389 lock:SetPoint ("right", close, "left", 3, 0)
Tercio@11 1390
Tercio@11 1391 close:SetScript ("OnClick", Panel1PxOnClickClose)
Tercio@11 1392 lock:SetScript ("OnClick", Panel1PxOnClickLock)
Tercio@11 1393
Tercio@11 1394 local title_string = f:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal")
Tercio@11 1395 title_string:SetPoint ("topleft", f, "topleft", 5, -5)
Tercio@11 1396 title_string:SetText (title or "")
Tercio@11 1397
Tercio@11 1398 if (title_anchor) then
Tercio@11 1399 if (title_anchor == "top") then
Tercio@11 1400 title_string:ClearAllPoints()
Tercio@11 1401 title_string:SetPoint ("bottomleft", f, "topleft", 0, 0)
Tercio@11 1402 close:ClearAllPoints()
Tercio@11 1403 close:SetPoint ("bottomright", f, "topright", 0, 0)
Tercio@11 1404 end
Tercio@11 1405 f.title_anchor = title_anchor
Tercio@11 1406 end
Tercio@11 1407
Tercio@11 1408 f.SetTitle = Panel1PxSetTitle
Tercio@11 1409 f.Title = title_string
Tercio@11 1410 f.Lock = lock
Tercio@11 1411 f.Close = close
Tercio@11 1412
Tercio@11 1413 return f
Tercio@11 1414 end
Tercio@11 1415
Tercio@11 1416 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1417 --> options button -- ~options
Tercio@11 1418 function DF:CreateOptionsButton (parent, callback, name)
Tercio@11 1419
Tercio@11 1420 local b = CreateFrame ("button", name, parent)
Tercio@11 1421 b:SetSize (14, 14)
Tercio@11 1422 b:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1423 b:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1424 b:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1425 b:GetNormalTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1426 b:GetHighlightTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1427 b:GetPushedTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1428 b:SetAlpha (0.7)
Tercio@11 1429
Tercio@11 1430 b:SetScript ("OnClick", callback)
Tercio@11 1431 b:SetScript ("OnEnter", function (self)
Tercio@11 1432 GameCooltip2:Reset()
Tercio@11 1433 GameCooltip2:AddLine ("Options")
Tercio@11 1434 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1435 end)
Tercio@11 1436 b:SetScript ("OnLeave", function (self)
Tercio@11 1437 GameCooltip2:Hide()
Tercio@11 1438 end)
Tercio@11 1439
Tercio@11 1440 return b
Tercio@11 1441
Tercio@11 1442 end
Tercio@11 1443
Tercio@11 1444 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1445 --> feedback panel -- ~feedback
Tercio@11 1446
Tercio@11 1447 function DF:CreateFeedbackButton (parent, callback, name)
Tercio@11 1448 local b = CreateFrame ("button", name, parent)
Tercio@11 1449 b:SetSize (12, 13)
Tercio@11 1450 b:SetNormalTexture (DF.folder .. "mail")
Tercio@11 1451 b:SetPushedTexture (DF.folder .. "mail")
Tercio@11 1452 b:SetHighlightTexture (DF.folder .. "mail")
Tercio@11 1453
Tercio@11 1454 b:SetScript ("OnClick", callback)
Tercio@11 1455 b:SetScript ("OnEnter", function (self)
Tercio@11 1456 GameCooltip2:Reset()
Tercio@11 1457 GameCooltip2:AddLine ("Send Feedback")
Tercio@11 1458 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1459 end)
Tercio@11 1460 b:SetScript ("OnLeave", function (self)
Tercio@11 1461 GameCooltip2:Hide()
Tercio@11 1462 end)
Tercio@11 1463
Tercio@11 1464 return b
Tercio@11 1465 end
Tercio@11 1466
Tercio@11 1467 local backdrop_fb_line = {bgFile = DF.folder .. "background", edgeFile = DF.folder .. "border_3",
Tercio@11 1468 tile = true, tileSize = 64, edgeSize = 8, insets = {left = 2, right = 2, top = 2, bottom = 2}}
Tercio@11 1469
Tercio@11 1470 local on_enter_feedback = function (self)
Tercio@11 1471 self:SetBackdropColor (1, 1, 0, 0.5)
Tercio@11 1472 end
Tercio@11 1473 local on_leave_feedback = function (self)
Tercio@11 1474 self:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 1475 end
Tercio@11 1476
Tercio@11 1477 local on_click_feedback = function (self)
Tercio@11 1478
Tercio@11 1479 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 1480
Tercio@11 1481 if (not feedback_link_textbox) then
Tercio@11 1482 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 1483 editbox:SetAutoFocus (false)
Tercio@11 1484 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1485 editbox.text = editbox.link
Tercio@11 1486 editbox:HighlightText()
Tercio@11 1487 end)
Tercio@11 1488 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1489 editbox:Hide()
Tercio@11 1490 end)
Tercio@11 1491 editbox:SetHook ("OnChar", function()
Tercio@11 1492 editbox.text = editbox.link
Tercio@11 1493 editbox:HighlightText()
Tercio@11 1494 end)
Tercio@11 1495 editbox.text = ""
Tercio@11 1496
Tercio@11 1497 DF.feedback_link_textbox = editbox
Tercio@11 1498 feedback_link_textbox = editbox
Tercio@11 1499 end
Tercio@11 1500
Tercio@11 1501 feedback_link_textbox.link = self.link
Tercio@11 1502 feedback_link_textbox.text = self.link
Tercio@11 1503 feedback_link_textbox:Show()
Tercio@11 1504
Tercio@11 1505 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 1506
Tercio@11 1507 feedback_link_textbox:HighlightText()
Tercio@11 1508
Tercio@11 1509 feedback_link_textbox:SetFocus()
Tercio@11 1510 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1511 end
Tercio@11 1512
Tercio@11 1513 local feedback_get_fb_line = function (self)
Tercio@11 1514
Tercio@11 1515 local line = self.feedback_lines [self.next_feedback]
Tercio@11 1516 if (not line) then
Tercio@11 1517 line = CreateFrame ("frame", "AddonFeedbackPanelFB" .. self.next_feedback, self)
Tercio@11 1518 line:SetBackdrop (backdrop_fb_line)
Tercio@11 1519 line:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 1520 line:SetSize (390, 42)
Tercio@11 1521 line:SetPoint ("topleft", self.feedback_anchor, "bottomleft", 0, -5 + ((self.next_feedback-1) * 46 * -1))
Tercio@11 1522 line:SetScript ("OnEnter", on_enter_feedback)
Tercio@11 1523 line:SetScript ("OnLeave", on_leave_feedback)
Tercio@11 1524 line:SetScript ("OnMouseUp", on_click_feedback)
Tercio@11 1525
Tercio@11 1526 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 1527 line.icon:SetSize (90, 36)
Tercio@11 1528
Tercio@11 1529 line.desc = line:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 1530
Tercio@11 1531 line.icon:SetPoint ("left", line, "left", 5, 0)
Tercio@11 1532 line.desc:SetPoint ("left", line.icon, "right", 5, 0)
Tercio@11 1533
Tercio@11 1534 local arrow = line:CreateTexture (nil, "overlay")
Tercio@11 1535 arrow:SetTexture ([[Interface\Buttons\JumpUpArrow]])
Tercio@11 1536 arrow:SetRotation (-1.55)
Tercio@11 1537 arrow:SetPoint ("right", line, "right", -5, 0)
Tercio@11 1538
Tercio@11 1539 self.feedback_lines [self.next_feedback] = line
Tercio@11 1540 end
Tercio@11 1541
Tercio@11 1542 self.next_feedback = self.next_feedback + 1
Tercio@11 1543
Tercio@11 1544 return line
Tercio@11 1545 end
Tercio@11 1546
Tercio@11 1547 local on_click_feedback = function (self)
Tercio@11 1548
Tercio@11 1549 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 1550
Tercio@11 1551 if (not feedback_link_textbox) then
Tercio@11 1552 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 1553 editbox:SetAutoFocus (false)
Tercio@11 1554 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1555 editbox.text = editbox.link
Tercio@11 1556 editbox:HighlightText()
Tercio@11 1557 end)
Tercio@11 1558 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1559 editbox:Hide()
Tercio@11 1560 end)
Tercio@11 1561 editbox:SetHook ("OnChar", function()
Tercio@11 1562 editbox.text = editbox.link
Tercio@11 1563 editbox:HighlightText()
Tercio@11 1564 end)
Tercio@11 1565 editbox.text = ""
Tercio@11 1566
Tercio@11 1567 DF.feedback_link_textbox = editbox
Tercio@11 1568 feedback_link_textbox = editbox
Tercio@11 1569 end
Tercio@11 1570
Tercio@11 1571 feedback_link_textbox.link = self.link
Tercio@11 1572 feedback_link_textbox.text = self.link
Tercio@11 1573 feedback_link_textbox:Show()
Tercio@11 1574
Tercio@11 1575 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 1576
Tercio@11 1577 feedback_link_textbox:HighlightText()
Tercio@11 1578
Tercio@11 1579 feedback_link_textbox:SetFocus()
Tercio@11 1580 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1581 end
Tercio@11 1582
Tercio@11 1583 local on_enter_addon = function (self)
Tercio@11 1584 if (self.tooltip) then
Tercio@11 1585 GameCooltip2:Preset (2)
Tercio@11 1586 GameCooltip2:AddLine ("|cFFFFFF00" .. self.name .. "|r")
Tercio@11 1587 GameCooltip2:AddLine ("")
Tercio@11 1588 GameCooltip2:AddLine (self.tooltip)
Tercio@11 1589 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1590 end
Tercio@11 1591 self.icon:SetBlendMode ("ADD")
Tercio@11 1592 end
Tercio@11 1593 local on_leave_addon = function (self)
Tercio@11 1594 if (self.tooltip) then
Tercio@11 1595 GameCooltip2:Hide()
Tercio@11 1596 end
Tercio@11 1597 self.icon:SetBlendMode ("BLEND")
Tercio@11 1598 end
Tercio@11 1599 local on_click_addon = function (self)
Tercio@11 1600 local addon_link_textbox = DF.addon_link_textbox
Tercio@11 1601
Tercio@11 1602 if (not addon_link_textbox) then
Tercio@11 1603 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 128, 64)
Tercio@11 1604 editbox:SetAutoFocus (false)
Tercio@11 1605 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1606 editbox.text = editbox.link
Tercio@11 1607 editbox:HighlightText()
Tercio@11 1608 end)
Tercio@11 1609 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1610 editbox:Hide()
Tercio@11 1611 end)
Tercio@11 1612 editbox:SetHook ("OnChar", function()
Tercio@11 1613 editbox.text = editbox.link
Tercio@11 1614 editbox:HighlightText()
Tercio@11 1615 end)
Tercio@11 1616 editbox.text = ""
Tercio@11 1617
Tercio@11 1618 DF.addon_link_textbox = editbox
Tercio@11 1619 addon_link_textbox = editbox
Tercio@11 1620 end
Tercio@11 1621
Tercio@11 1622 addon_link_textbox.link = self.link
Tercio@11 1623 addon_link_textbox.text = self.link
Tercio@11 1624 addon_link_textbox:Show()
Tercio@11 1625
Tercio@11 1626 addon_link_textbox:SetPoint ("topleft", self.icon, "topleft", 0, 0)
Tercio@11 1627
Tercio@11 1628 addon_link_textbox:HighlightText()
Tercio@11 1629
Tercio@11 1630 addon_link_textbox:SetFocus()
Tercio@11 1631 addon_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1632 end
Tercio@11 1633
Tercio@11 1634 local feedback_get_addons_line = function (self)
Tercio@11 1635 local line = self.addons_lines [self.next_addons]
Tercio@11 1636 if (not line) then
Tercio@11 1637
Tercio@11 1638 line = CreateFrame ("frame", "AddonFeedbackPanelSA" .. self.next_addons, self)
Tercio@11 1639 line:SetSize (128, 64)
Tercio@11 1640
Tercio@11 1641 if (self.next_addons == 1) then
Tercio@11 1642 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5)
Tercio@11 1643 elseif (self.next_addons_line_break == self.next_addons) then
Tercio@11 1644 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5 + floor (self.next_addons_line_break/3) * 66 * -1)
Tercio@11 1645 self.next_addons_line_break = self.next_addons_line_break + 3
Tercio@11 1646 else
Tercio@11 1647 local previous = self.addons_lines [self.next_addons - 1]
Tercio@11 1648 line:SetPoint ("topleft", previous, "topright", 2, 0)
Tercio@11 1649 end
Tercio@11 1650
Tercio@11 1651 line:SetScript ("OnEnter", on_enter_addon)
Tercio@11 1652 line:SetScript ("OnLeave", on_leave_addon)
Tercio@11 1653 line:SetScript ("OnMouseUp", on_click_addon)
Tercio@11 1654
Tercio@11 1655 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 1656 line.icon:SetSize (128, 64)
Tercio@11 1657
Tercio@11 1658 line.icon:SetPoint ("topleft", line, "topleft", 0, 0)
Tercio@11 1659
Tercio@11 1660 self.addons_lines [self.next_addons] = line
Tercio@11 1661 end
Tercio@11 1662
Tercio@11 1663 self.next_addons = self.next_addons + 1
Tercio@11 1664
Tercio@11 1665 return line
Tercio@11 1666 end
Tercio@11 1667
Tercio@11 1668 local default_coords = {0, 1, 0, 1}
Tercio@11 1669 local feedback_add_fb = function (self, table)
Tercio@11 1670 local line = self:GetFeedbackLine()
Tercio@11 1671 line.icon:SetTexture (table.icon)
Tercio@11 1672 line.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 1673 line.desc:SetText (table.desc)
Tercio@11 1674 line.link = table.link
Tercio@11 1675 line:Show()
Tercio@11 1676 end
Tercio@11 1677
Tercio@11 1678 local feedback_add_addon = function (self, table)
Tercio@11 1679 local block = self:GetAddonsLine()
Tercio@11 1680 block.icon:SetTexture (table.icon)
Tercio@11 1681 block.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 1682 block.link = table.link
Tercio@11 1683 block.tooltip = table.desc
Tercio@11 1684 block.name = table.name
Tercio@11 1685 block:Show()
Tercio@11 1686 end
Tercio@11 1687
Tercio@11 1688 local feedback_hide_all = function (self)
Tercio@11 1689 self.next_feedback = 1
Tercio@11 1690 self.next_addons = 1
Tercio@11 1691
Tercio@11 1692 for index, line in ipairs (self.feedback_lines) do
Tercio@11 1693 line:Hide()
Tercio@11 1694 end
Tercio@11 1695
Tercio@11 1696 for index, line in ipairs (self.addons_lines) do
Tercio@11 1697 line:Hide()
Tercio@11 1698 end
Tercio@11 1699 end
Tercio@11 1700
Tercio@11 1701 -- feedback_methods = { { icon = icon path, desc = description, link = url}}
Tercio@11 1702 function DF:ShowFeedbackPanel (addon_name, version, feedback_methods, more_addons)
Tercio@11 1703
Tercio@11 1704 local f = _G.AddonFeedbackPanel
Tercio@11 1705
Tercio@11 1706 if (not f) then
Tercio@11 1707 f = DF:Create1PxPanel (UIParent, 400, 100, addon_name .. " Feedback", "AddonFeedbackPanel", nil)
Tercio@11 1708 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 1709 f:SetPoint ("center", UIParent, "center")
Tercio@11 1710 f:SetBackdropColor (0, 0, 0, 0.8)
Tercio@11 1711 f.feedback_lines = {}
Tercio@11 1712 f.addons_lines = {}
Tercio@11 1713 f.next_feedback = 1
Tercio@11 1714 f.next_addons = 1
Tercio@11 1715 f.next_addons_line_break = 4
Tercio@11 1716
Tercio@11 1717 local feedback_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1718 feedback_anchor:SetText ("Feedback:")
Tercio@11 1719 feedback_anchor:SetPoint ("topleft", f, "topleft", 5, -30)
Tercio@11 1720 f.feedback_anchor = feedback_anchor
Tercio@11 1721 local excla_text = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1722 excla_text:SetText ("click and copy the link")
Tercio@11 1723 excla_text:SetPoint ("topright", f, "topright", -5, -30)
Tercio@11 1724 excla_text:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 1725
Tercio@11 1726 local addons_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1727 addons_anchor:SetText ("AddOns From the Same Author:")
Tercio@11 1728 f.addons_anchor = addons_anchor
Tercio@11 1729 local excla_text2 = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1730 excla_text2:SetText ("click and copy the link")
Tercio@11 1731 excla_text2:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 1732 f.excla_text2 = excla_text2
Tercio@11 1733
Tercio@11 1734 f.GetFeedbackLine = feedback_get_fb_line
Tercio@11 1735 f.GetAddonsLine = feedback_get_addons_line
Tercio@11 1736 f.AddFeedbackMethod = feedback_add_fb
Tercio@11 1737 f.AddOtherAddon = feedback_add_addon
Tercio@11 1738 f.HideAll = feedback_hide_all
Tercio@11 1739
Tercio@11 1740 DF:SetFontSize (f.Title, 14)
Tercio@11 1741
Tercio@11 1742 end
Tercio@11 1743
Tercio@11 1744 f:HideAll()
Tercio@11 1745 f:SetTitle (addon_name)
Tercio@11 1746
Tercio@11 1747 for index, feedback in ipairs (feedback_methods) do
Tercio@11 1748 f:AddFeedbackMethod (feedback)
Tercio@11 1749 end
Tercio@11 1750
Tercio@11 1751 f.addons_anchor:SetPoint ("topleft", f, "topleft", 5, f.next_feedback * 50 * -1)
Tercio@11 1752 f.excla_text2:SetPoint ("topright", f, "topright", -5, f.next_feedback * 50 * -1)
Tercio@11 1753
Tercio@11 1754 for index, addon in ipairs (more_addons) do
Tercio@11 1755 f:AddOtherAddon (addon)
Tercio@11 1756 end
Tercio@11 1757
Tercio@11 1758 f:SetHeight (80 + ((f.next_feedback-1) * 50) + (ceil ((f.next_addons-1)/3) * 66))
Tercio@11 1759
Tercio@11 1760 f:Show()
Tercio@11 1761
Tercio@11 1762 return true
Tercio@11 1763 end
Tercio@11 1764
Tercio@11 1765
Tercio@11 1766 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1767 --> chart panel -- ~chart
Tercio@11 1768
Tercio@11 1769 local chart_panel_backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
Tercio@11 1770 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}}
Tercio@11 1771
Tercio@11 1772 local chart_panel_align_timelabels = function (self, elapsed_time)
Tercio@11 1773
Tercio@11 1774 self.TimeScale = elapsed_time
Tercio@11 1775
Tercio@11 1776 local linha = self.TimeLabels [17]
Tercio@11 1777 local minutos, segundos = math.floor (elapsed_time / 60), math.floor (elapsed_time % 60)
Tercio@11 1778 if (segundos < 10) then
Tercio@11 1779 segundos = "0" .. segundos
Tercio@11 1780 end
Tercio@11 1781
Tercio@11 1782 if (minutos > 0) then
Tercio@11 1783 if (minutos < 10) then
Tercio@11 1784 minutos = "0" .. minutos
Tercio@11 1785 end
Tercio@11 1786 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 1787 else
Tercio@11 1788 linha:SetText ("00:" .. segundos)
Tercio@11 1789 end
Tercio@11 1790
Tercio@11 1791 local time_div = elapsed_time / 16 --786 -- 49.125
Tercio@11 1792
Tercio@11 1793 for i = 2, 16 do
Tercio@11 1794
Tercio@11 1795 local linha = self.TimeLabels [i]
Tercio@11 1796
Tercio@11 1797 local this_time = time_div * (i-1)
Tercio@11 1798 local minutos, segundos = math.floor (this_time / 60), math.floor (this_time % 60)
Tercio@11 1799
Tercio@11 1800 if (segundos < 10) then
Tercio@11 1801 segundos = "0" .. segundos
Tercio@11 1802 end
Tercio@11 1803
Tercio@11 1804 if (minutos > 0) then
Tercio@11 1805 if (minutos < 10) then
Tercio@11 1806 minutos = "0" .. minutos
Tercio@11 1807 end
Tercio@11 1808 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 1809 else
Tercio@11 1810 linha:SetText ("00:" .. segundos)
Tercio@11 1811 end
Tercio@11 1812
Tercio@11 1813 end
Tercio@11 1814
Tercio@11 1815 end
Tercio@11 1816
Tercio@11 1817 local chart_panel_set_scale = function (self, amt, func, text)
Tercio@11 1818 if (type (amt) ~= "number") then
Tercio@11 1819 return
Tercio@11 1820 end
Tercio@11 1821
Tercio@11 1822 local piece = amt / 1000 / 8
Tercio@11 1823
Tercio@11 1824 for i = 1, 8 do
Tercio@11 1825 if (func) then
Tercio@11 1826 self ["dpsamt" .. math.abs (i-9)]:SetText ( func (piece*i) .. (text or ""))
Tercio@11 1827 else
Tercio@11 1828 if (piece*i > 1) then
Tercio@11 1829 self ["dpsamt" .. math.abs (i-9)]:SetText ( floor (piece*i) .. (text or ""))
Tercio@11 1830 else
Tercio@11 1831 self ["dpsamt" .. math.abs (i-9)]:SetText ( format ("%.3f", piece*i) .. (text or ""))
Tercio@11 1832 end
Tercio@11 1833 end
Tercio@11 1834 end
Tercio@11 1835 end
Tercio@11 1836
Tercio@11 1837 local chart_panel_can_move = function (self, can)
Tercio@11 1838 self.can_move = can
Tercio@11 1839 end
Tercio@11 1840
Tercio@11 1841 local chart_panel_overlay_reset = function (self)
Tercio@11 1842 self.OverlaysAmount = 1
Tercio@11 1843 for index, pack in ipairs (self.Overlays) do
Tercio@11 1844 for index2, texture in ipairs (pack) do
Tercio@11 1845 texture:Hide()
Tercio@11 1846 end
Tercio@11 1847 end
Tercio@11 1848 end
Tercio@11 1849
Tercio@11 1850 local chart_panel_reset = function (self)
Tercio@11 1851
Tercio@11 1852 self.Graphic:ResetData()
Tercio@11 1853 self.Graphic.max_value = 0
Tercio@11 1854
Tercio@11 1855 self.TimeScale = nil
Tercio@11 1856 self.BoxLabelsAmount = 1
Tercio@11 1857 table.wipe (self.GData)
Tercio@11 1858 table.wipe (self.OData)
Tercio@11 1859
Tercio@11 1860 for index, box in ipairs (self.BoxLabels) do
Tercio@11 1861 box.check:Hide()
Tercio@11 1862 box.button:Hide()
Tercio@11 1863 box.box:Hide()
Tercio@11 1864 box.text:Hide()
Tercio@11 1865 box.border:Hide()
Tercio@11 1866 box.showing = false
Tercio@11 1867 end
Tercio@11 1868
Tercio@11 1869 chart_panel_overlay_reset (self)
Tercio@11 1870 end
Tercio@11 1871
Tercio@11 1872 local chart_panel_enable_line = function (f, thisbox)
Tercio@11 1873
Tercio@11 1874 local index = thisbox.index
Tercio@11 1875 local type = thisbox.type
Tercio@11 1876
Tercio@11 1877 if (thisbox.enabled) then
Tercio@11 1878 --disable
Tercio@11 1879 thisbox.check:Hide()
Tercio@11 1880 thisbox.enabled = false
Tercio@11 1881 else
Tercio@11 1882 --enable
Tercio@11 1883 thisbox.check:Show()
Tercio@11 1884 thisbox.enabled = true
Tercio@11 1885 end
Tercio@11 1886
Tercio@11 1887 if (type == "graphic") then
Tercio@11 1888
Tercio@11 1889 f.Graphic:ResetData()
Tercio@11 1890 f.Graphic.max_value = 0
Tercio@11 1891
Tercio@11 1892 local max = 0
Tercio@11 1893 local max_time = 0
Tercio@11 1894
Tercio@11 1895 for index, box in ipairs (f.BoxLabels) do
Tercio@11 1896 if (box.type == type and box.showing and box.enabled) then
Tercio@11 1897 local data = f.GData [index]
Tercio@11 1898
Tercio@11 1899 f.Graphic:AddDataSeries (data[1], data[2], nil, data[3])
Tercio@11 1900
Tercio@11 1901 if (data[4] > max) then
Tercio@11 1902 max = data[4]
Tercio@11 1903 end
Tercio@11 1904 if (data [5] > max_time) then
Tercio@11 1905 max_time = data [5]
Tercio@11 1906 end
Tercio@11 1907 end
Tercio@11 1908 end
Tercio@11 1909
Tercio@11 1910 f:SetScale (max)
Tercio@11 1911 f:SetTime (max_time)
Tercio@11 1912
Tercio@11 1913 elseif (type == "overlay") then
Tercio@11 1914
Tercio@11 1915 chart_panel_overlay_reset (f)
Tercio@11 1916
Tercio@11 1917 for index, box in ipairs (f.BoxLabels) do
Tercio@11 1918 if (box.type == type and box.showing and box.enabled) then
Tercio@11 1919
Tercio@11 1920 f:AddOverlay (box.index)
Tercio@11 1921
Tercio@11 1922 end
Tercio@11 1923 end
Tercio@11 1924
Tercio@11 1925 end
Tercio@11 1926 end
Tercio@11 1927
Tercio@11 1928 local create_box = function (self, next_box)
Tercio@11 1929
Tercio@11 1930 local thisbox = {}
Tercio@11 1931 self.BoxLabels [next_box] = thisbox
Tercio@11 1932
Tercio@11 1933 local box = DF:NewImage (self.Graphic, nil, 16, 16, "border")
Tercio@11 1934
Tercio@11 1935 local text = DF:NewLabel (self.Graphic)
Tercio@11 1936
Tercio@11 1937 local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork")
Tercio@11 1938 border:SetPoint ("center", box, "center", -3, -4)
Tercio@11 1939 border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]])
Tercio@11 1940
Tercio@11 1941 local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay")
Tercio@11 1942 checktexture:SetPoint ("center", box, "center", -1, -1)
Tercio@11 1943 checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
Tercio@11 1944
Tercio@11 1945 thisbox.box = box
Tercio@11 1946 thisbox.text = text
Tercio@11 1947 thisbox.border = border
Tercio@11 1948 thisbox.check = checktexture
Tercio@11 1949 thisbox.enabled = true
Tercio@11 1950
Tercio@11 1951 local button = CreateFrame ("button", nil, self.Graphic)
Tercio@11 1952 button:SetSize (20, 20)
Tercio@11 1953 button:SetScript ("OnClick", function()
Tercio@11 1954 chart_panel_enable_line (self, thisbox)
Tercio@11 1955 end)
Tercio@11 1956 button:SetPoint ("center", box, "center")
Tercio@11 1957
Tercio@11 1958 thisbox.button = button
Tercio@11 1959
Tercio@11 1960 thisbox.box:SetPoint ("right", text, "left", -4, 0)
Tercio@11 1961
Tercio@11 1962 if (next_box == 1) then
Tercio@11 1963 thisbox.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 1964 else
Tercio@11 1965 thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -7, 0)
Tercio@11 1966 end
Tercio@11 1967
Tercio@11 1968 return thisbox
Tercio@11 1969
Tercio@11 1970 end
Tercio@11 1971
Tercio@11 1972 local realign_labels = function (self)
Tercio@11 1973
Tercio@11 1974 local width = self:GetWidth() - 108
Tercio@11 1975
Tercio@11 1976 local first_box = self.BoxLabels [1]
Tercio@11 1977 first_box.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 1978
Tercio@11 1979 local line_width = first_box.text:GetStringWidth() + 26
Tercio@11 1980
Tercio@11 1981 for i = 2, #self.BoxLabels do
Tercio@11 1982
Tercio@11 1983 local box = self.BoxLabels [i]
Tercio@11 1984
Tercio@11 1985 if (box.box:IsShown()) then
Tercio@11 1986
Tercio@11 1987 line_width = line_width + box.text:GetStringWidth() + 26
Tercio@11 1988
Tercio@11 1989 if (line_width > width) then
Tercio@11 1990 line_width = box.text:GetStringWidth() + 26
Tercio@11 1991 box.text:SetPoint ("topright", self, "topright", -35, -40)
Tercio@11 1992 else
Tercio@11 1993 box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -7, 0)
Tercio@11 1994 end
Tercio@11 1995 else
Tercio@11 1996 break
Tercio@11 1997 end
Tercio@11 1998 end
Tercio@11 1999
Tercio@11 2000 end
Tercio@11 2001
Tercio@11 2002 local chart_panel_add_label = function (self, color, name, type, number)
Tercio@11 2003
Tercio@11 2004 local next_box = self.BoxLabelsAmount
Tercio@11 2005 local thisbox = self.BoxLabels [next_box]
Tercio@11 2006
Tercio@11 2007 if (not thisbox) then
Tercio@11 2008 thisbox = create_box (self, next_box)
Tercio@11 2009 end
Tercio@11 2010
Tercio@11 2011 self.BoxLabelsAmount = self.BoxLabelsAmount + 1
Tercio@11 2012
Tercio@11 2013 thisbox.type = type
Tercio@11 2014 thisbox.index = number
Tercio@11 2015
Tercio@11 2016 thisbox.box:SetTexture (unpack (color))
Tercio@11 2017 thisbox.text:SetText (name)
Tercio@11 2018
Tercio@11 2019 thisbox.check:Show()
Tercio@11 2020 thisbox.button:Show()
Tercio@11 2021 thisbox.border:Show()
Tercio@11 2022 thisbox.box:Show()
Tercio@11 2023 thisbox.text:Show()
Tercio@11 2024
Tercio@11 2025 thisbox.showing = true
Tercio@11 2026 thisbox.enabled = true
Tercio@11 2027
Tercio@11 2028 realign_labels (self)
Tercio@11 2029
Tercio@11 2030 end
Tercio@11 2031
Tercio@11 2032 local line_default_color = {1, 1, 1}
Tercio@11 2033 local draw_overlay = function (self, this_overlay, overlayData, color)
Tercio@11 2034
Tercio@11 2035 local pixel = self.Graphic:GetWidth() / self.TimeScale
Tercio@11 2036 local index = 1
Tercio@11 2037 local r, g, b = unpack (color)
Tercio@11 2038
Tercio@11 2039 for i = 1, #overlayData, 2 do
Tercio@11 2040 local aura_start = overlayData [i]
Tercio@11 2041 local aura_end = overlayData [i+1]
Tercio@11 2042
Tercio@11 2043 local this_block = this_overlay [index]
Tercio@11 2044 if (not this_block) then
Tercio@11 2045 this_block = self.Graphic:CreateTexture (nil, "border")
Tercio@11 2046 tinsert (this_overlay, this_block)
Tercio@11 2047 end
Tercio@11 2048 this_block:SetHeight (self.Graphic:GetHeight())
Tercio@11 2049
Tercio@11 2050 this_block:SetPoint ("left", self.Graphic, "left", pixel * aura_start, 0)
Tercio@11 2051 if (aura_end) then
Tercio@11 2052 this_block:SetWidth ((aura_end-aura_start)*pixel)
Tercio@11 2053 else
Tercio@11 2054 --malformed table
Tercio@11 2055 this_block:SetWidth (pixel*5)
Tercio@11 2056 end
Tercio@11 2057
Tercio@11 2058 this_block:SetTexture (r, g, b, 0.25)
Tercio@11 2059 this_block:Show()
Tercio@11 2060
Tercio@11 2061 index = index + 1
Tercio@11 2062 end
Tercio@11 2063
Tercio@11 2064 end
Tercio@11 2065
Tercio@11 2066 local chart_panel_add_overlay = function (self, overlayData, color, name, icon)
Tercio@11 2067
Tercio@11 2068 if (not self.TimeScale) then
Tercio@11 2069 error ("Use SetTime (time) before adding an overlay.")
Tercio@11 2070 end
Tercio@11 2071
Tercio@11 2072 if (type (overlayData) == "number") then
Tercio@11 2073 local overlay_index = overlayData
Tercio@11 2074 draw_overlay (self, self.Overlays [self.OverlaysAmount], self.OData [overlay_index][1], self.OData [overlay_index][2])
Tercio@11 2075 else
Tercio@11 2076 local this_overlay = self.Overlays [self.OverlaysAmount]
Tercio@11 2077 if (not this_overlay) then
Tercio@11 2078 this_overlay = {}
Tercio@11 2079 tinsert (self.Overlays, this_overlay)
Tercio@11 2080 end
Tercio@11 2081
Tercio@11 2082 draw_overlay (self, this_overlay, overlayData, color)
Tercio@11 2083
Tercio@11 2084 tinsert (self.OData, {overlayData, color or line_default_color})
Tercio@11 2085 if (name) then
Tercio@11 2086 self:AddLabel (color or line_default_color, name, "overlay", #self.OData)
Tercio@11 2087 end
Tercio@11 2088 end
Tercio@11 2089
Tercio@11 2090 self.OverlaysAmount = self.OverlaysAmount + 1
Tercio@11 2091 end
Tercio@11 2092
Tercio@11 2093 local SMA_table = {}
Tercio@11 2094 local SMA_max = 0
Tercio@11 2095 local reset_SMA = function()
Tercio@11 2096 table.wipe (SMA_table)
Tercio@11 2097 SMA_max = 0
Tercio@11 2098 end
Tercio@11 2099
Tercio@11 2100 local calc_SMA
Tercio@11 2101 calc_SMA = function (a, b, ...)
Tercio@11 2102 if (b) then
Tercio@11 2103 return calc_SMA (a + b, ...)
Tercio@11 2104 else
Tercio@11 2105 return a
Tercio@11 2106 end
Tercio@11 2107 end
Tercio@11 2108
Tercio@11 2109 local do_SMA = function (value, max_value)
Tercio@11 2110
Tercio@11 2111 if (#SMA_table == 10) then
Tercio@11 2112 tremove (SMA_table, 1)
Tercio@11 2113 end
Tercio@11 2114
Tercio@11 2115 SMA_table [#SMA_table + 1] = value
Tercio@11 2116
Tercio@11 2117 local new_value = calc_SMA (unpack (SMA_table)) / #SMA_table
Tercio@11 2118
Tercio@11 2119 if (new_value > SMA_max) then
Tercio@11 2120 SMA_max = new_value
Tercio@11 2121 return new_value, SMA_max
Tercio@11 2122 else
Tercio@11 2123 return new_value
Tercio@11 2124 end
Tercio@11 2125
Tercio@11 2126 end
Tercio@11 2127
Tercio@11 2128 local chart_panel_add_data = function (self, graphicData, color, name, elapsed_time, lineTexture, smoothLevel, firstIndex)
Tercio@11 2129
Tercio@11 2130 local f = self
Tercio@11 2131 self = self.Graphic
Tercio@11 2132
Tercio@11 2133 local _data = {}
Tercio@11 2134 local max_value = graphicData.max_value
Tercio@11 2135 local amount = #graphicData
Tercio@11 2136
Tercio@11 2137 local scaleW = 1/self:GetWidth()
Tercio@11 2138
Tercio@11 2139 local content = graphicData
Tercio@11 2140 tinsert (content, 1, 0)
Tercio@11 2141 tinsert (content, 1, 0)
Tercio@11 2142 tinsert (content, #content+1, 0)
Tercio@11 2143 tinsert (content, #content+1, 0)
Tercio@11 2144
Tercio@11 2145 local _i = 3
Tercio@11 2146
Tercio@11 2147 local graphMaxDps = math.max (self.max_value, max_value)
Tercio@11 2148
Tercio@11 2149 if (not smoothLevel) then
Tercio@11 2150 while (_i <= #content-2) do
Tercio@11 2151 local v = (content[_i-2]+content[_i-1]+content[_i]+content[_i+1]+content[_i+2])/5 --> normalize
Tercio@11 2152 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 2153 _i = _i + 1
Tercio@11 2154 end
Tercio@11 2155
Tercio@11 2156 elseif (smoothLevel == "SHORT") then
Tercio@11 2157 while (_i <= #content-2) do
Tercio@11 2158 local value = (content[_i] + content[_i+1]) / 2
Tercio@11 2159 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2160 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2161 _i = _i + 2
Tercio@11 2162 end
Tercio@11 2163
Tercio@11 2164 elseif (smoothLevel == "SMA") then
Tercio@11 2165 reset_SMA()
Tercio@11 2166 while (_i <= #content-2) do
Tercio@11 2167 local value, is_new_max_value = do_SMA (content[_i], max_value)
Tercio@11 2168 if (is_new_max_value) then
Tercio@11 2169 max_value = is_new_max_value
Tercio@11 2170 end
Tercio@11 2171 _data [#_data+1] = {scaleW*(_i-2), value} --> x and y coords
Tercio@11 2172 _i = _i + 1
Tercio@11 2173 end
Tercio@11 2174
Tercio@11 2175 elseif (smoothLevel == -1) then
Tercio@11 2176 while (_i <= #content-2) do
Tercio@11 2177 local current = content[_i]
Tercio@11 2178
Tercio@11 2179 local minus_2 = content[_i-2] * 0.6
Tercio@11 2180 local minus_1 = content[_i-1] * 0.8
Tercio@11 2181 local plus_1 = content[_i+1] * 0.8
Tercio@11 2182 local plus_2 = content[_i+2] * 0.6
Tercio@11 2183
Tercio@11 2184 local v = (current + minus_2 + minus_1 + plus_1 + plus_2)/5 --> normalize
Tercio@11 2185 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 2186 _i = _i + 1
Tercio@11 2187 end
Tercio@11 2188
Tercio@11 2189 elseif (smoothLevel == 1) then
Tercio@11 2190 _i = 2
Tercio@11 2191 while (_i <= #content-1) do
Tercio@11 2192 local v = (content[_i-1]+content[_i]+content[_i+1])/3 --> normalize
Tercio@11 2193 _data [#_data+1] = {scaleW*(_i-1), v/graphMaxDps} --> x and y coords
Tercio@11 2194 _i = _i + 1
Tercio@11 2195 end
Tercio@11 2196
Tercio@11 2197 elseif (smoothLevel == 2) then
Tercio@11 2198 _i = 1
Tercio@11 2199 while (_i <= #content) do
Tercio@11 2200 local v = content[_i] --> do not normalize
Tercio@11 2201 _data [#_data+1] = {scaleW*(_i), v/graphMaxDps} --> x and y coords
Tercio@11 2202 _i = _i + 1
Tercio@11 2203 end
Tercio@11 2204
Tercio@11 2205 end
Tercio@11 2206
Tercio@11 2207 tremove (content, 1)
Tercio@11 2208 tremove (content, 1)
Tercio@11 2209 tremove (content, #graphicData)
Tercio@11 2210 tremove (content, #graphicData)
Tercio@11 2211
Tercio@11 2212 if (max_value > self.max_value) then
Tercio@11 2213 --> normalize previous data
Tercio@11 2214 if (self.max_value > 0) then
Tercio@11 2215 local normalizePercent = self.max_value / max_value
Tercio@11 2216 for dataIndex, Data in ipairs (self.Data) do
Tercio@11 2217 local Points = Data.Points
Tercio@11 2218 for i = 1, #Points do
Tercio@11 2219 Points[i][2] = Points[i][2]*normalizePercent
Tercio@11 2220 end
Tercio@11 2221 end
Tercio@11 2222 end
Tercio@11 2223
Tercio@11 2224 self.max_value = max_value
Tercio@11 2225 f:SetScale (max_value)
Tercio@11 2226
Tercio@11 2227 end
Tercio@11 2228
Tercio@11 2229 tinsert (f.GData, {_data, color or line_default_color, lineTexture, max_value, elapsed_time})
Tercio@11 2230 if (name) then
Tercio@11 2231 f:AddLabel (color or line_default_color, name, "graphic", #f.GData)
Tercio@11 2232 end
Tercio@11 2233
Tercio@11 2234 if (firstIndex) then
Tercio@11 2235 if (lineTexture) then
Tercio@11 2236 if (not lineTexture:find ("\\") and not lineTexture:find ("//")) then
Tercio@11 2237 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)LibGraph%-2%.0%.lua")
Tercio@11 2238 if path then
Tercio@11 2239 lineTexture = "Interface\\AddOns\\" .. path .. lineTexture
Tercio@11 2240 else
Tercio@11 2241 lineTexture = nil
Tercio@11 2242 end
Tercio@11 2243 end
Tercio@11 2244 end
Tercio@11 2245
Tercio@11 2246 table.insert (self.Data, 1, {Points = _data, Color = color or line_default_color, lineTexture = lineTexture, ElapsedTime = elapsed_time})
Tercio@11 2247 self.NeedsUpdate = true
Tercio@11 2248 else
Tercio@11 2249 self:AddDataSeries (_data, color or line_default_color, nil, lineTexture)
Tercio@11 2250 self.Data [#self.Data].ElapsedTime = elapsed_time
Tercio@11 2251 end
Tercio@11 2252
Tercio@11 2253 local max_time = 0
Tercio@11 2254 for _, data in ipairs (self.Data) do
Tercio@11 2255 if (data.ElapsedTime > max_time) then
Tercio@11 2256 max_time = data.ElapsedTime
Tercio@11 2257 end
Tercio@11 2258 end
Tercio@11 2259
Tercio@11 2260 f:SetTime (max_time)
Tercio@11 2261
Tercio@11 2262 end
Tercio@11 2263
Tercio@11 2264 local chart_panel_onresize = function (self)
Tercio@11 2265 local width, height = self:GetSize()
Tercio@11 2266 local spacement = width - 78 - 60
Tercio@11 2267 spacement = spacement / 16
Tercio@11 2268
Tercio@11 2269 for i = 1, 17 do
Tercio@11 2270 local label = self.TimeLabels [i]
Tercio@11 2271 label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), 13)
Tercio@11 2272 label.line:SetHeight (height - 45)
Tercio@11 2273 end
Tercio@11 2274
Tercio@11 2275 local spacement = (self.Graphic:GetHeight()) / 8
Tercio@11 2276 for i = 1, 8 do
Tercio@11 2277 self ["dpsamt"..i]:SetPoint ("TOPLEFT", self, "TOPLEFT", 27, -25 + (-(spacement* (i-1))) )
Tercio@11 2278 self ["dpsamt"..i].line:SetWidth (width-20)
Tercio@11 2279 end
Tercio@11 2280
Tercio@11 2281 self.Graphic:SetSize (width - 135, height - 67)
Tercio@11 2282 self.Graphic:SetPoint ("topleft", self, "topleft", 108, -35)
Tercio@11 2283 end
Tercio@11 2284
Tercio@11 2285 local chart_panel_vlines_on = function (self)
Tercio@11 2286 for i = 1, 17 do
Tercio@11 2287 local label = self.TimeLabels [i]
Tercio@11 2288 label.line:Show()
Tercio@11 2289 end
Tercio@11 2290 end
Tercio@11 2291
Tercio@11 2292 local chart_panel_vlines_off = function (self)
Tercio@11 2293 for i = 1, 17 do
Tercio@11 2294 local label = self.TimeLabels [i]
Tercio@11 2295 label.line:Hide()
Tercio@11 2296 end
Tercio@11 2297 end
Tercio@11 2298
Tercio@11 2299 local chart_panel_set_title = function (self, title)
Tercio@11 2300 self.chart_title.text = title
Tercio@11 2301 end
Tercio@11 2302
Tercio@11 2303 local chart_panel_mousedown = function (self, button)
Tercio@11 2304 if (button == "LeftButton" and self.can_move) then
Tercio@11 2305 if (not self.isMoving) then
Tercio@11 2306 self:StartMoving()
Tercio@11 2307 self.isMoving = true
Tercio@11 2308 end
Tercio@11 2309 elseif (button == "RightButton" and not self.no_right_click_close) then
Tercio@11 2310 if (not self.isMoving) then
Tercio@11 2311 self:Hide()
Tercio@11 2312 end
Tercio@11 2313 end
Tercio@11 2314 end
Tercio@11 2315 local chart_panel_mouseup = function (self, button)
Tercio@11 2316 if (button == "LeftButton" and self.isMoving) then
Tercio@11 2317 self:StopMovingOrSizing()
Tercio@11 2318 self.isMoving = nil
Tercio@11 2319 end
Tercio@11 2320 end
Tercio@11 2321
Tercio@11 2322 local chart_panel_hide_close_button = function (self)
Tercio@11 2323 self.CloseButton:Hide()
Tercio@11 2324 end
Tercio@11 2325
Tercio@11 2326 local chart_panel_right_click_close = function (self, value)
Tercio@11 2327 if (type (value) == "boolean") then
Tercio@11 2328 if (value) then
Tercio@11 2329 self.no_right_click_close = nil
Tercio@11 2330 else
Tercio@11 2331 self.no_right_click_close = true
Tercio@11 2332 end
Tercio@11 2333 end
Tercio@11 2334 end
Tercio@11 2335
Tercio@11 2336 function DF:CreateChartPanel (parent, w, h, name)
Tercio@11 2337
Tercio@11 2338 if (not name) then
Tercio@11 2339 name = "DFPanel" .. DF.PanelCounter
Tercio@11 2340 DF.PanelCounter = DF.PanelCounter + 1
Tercio@11 2341 end
Tercio@11 2342
Tercio@11 2343 parent = parent or UIParent
Tercio@11 2344 w = w or 800
Tercio@11 2345 h = h or 500
Tercio@11 2346
Tercio@11 2347 local f = CreateFrame ("frame", name, parent)
Tercio@11 2348 f:SetSize (w or 500, h or 400)
Tercio@11 2349 f:EnableMouse (true)
Tercio@11 2350 f:SetMovable (true)
Tercio@11 2351
Tercio@11 2352 f:SetScript ("OnMouseDown", chart_panel_mousedown)
Tercio@11 2353 f:SetScript ("OnMouseUp", chart_panel_mouseup)
Tercio@11 2354
Tercio@11 2355 f:SetBackdrop (chart_panel_backdrop)
Tercio@11 2356 f:SetBackdropColor (.3, .3, .3, .3)
Tercio@11 2357
Tercio@11 2358 local c = CreateFrame ("Button", nil, f, "UIPanelCloseButton")
Tercio@11 2359 c:SetWidth (32)
Tercio@11 2360 c:SetHeight (32)
Tercio@11 2361 c:SetPoint ("TOPRIGHT", f, "TOPRIGHT", -3, -7)
Tercio@11 2362 c:SetFrameLevel (f:GetFrameLevel()+1)
Tercio@11 2363 c:SetAlpha (0.9)
Tercio@11 2364 f.CloseButton = c
Tercio@11 2365
Tercio@11 2366 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0})
Tercio@11 2367 title:SetPoint ("topleft", f, "topleft", 110, -13)
Tercio@11 2368
Tercio@11 2369 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
Tercio@11 2370 bottom_texture:SetTexture (0, 0, 0, .6)
Tercio@11 2371 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7)
Tercio@11 2372 bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7)
Tercio@11 2373
Tercio@11 2374 f.Overlays = {}
Tercio@11 2375 f.OverlaysAmount = 1
Tercio@11 2376
Tercio@11 2377 f.BoxLabels = {}
Tercio@11 2378 f.BoxLabelsAmount = 1
Tercio@11 2379
Tercio@11 2380 f.TimeLabels = {}
Tercio@11 2381 for i = 1, 17 do
Tercio@11 2382 local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 2383 time:SetText ("00:00")
Tercio@11 2384 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), 13)
Tercio@11 2385 f.TimeLabels [i] = time
Tercio@11 2386
Tercio@11 2387 local line = f:CreateTexture (nil, "border")
Tercio@11 2388 line:SetSize (1, h-45)
Tercio@11 2389 line:SetTexture (1, 1, 1, .1)
Tercio@11 2390 line:SetPoint ("bottomleft", time, "topright", 0, -10)
Tercio@11 2391 line:Hide()
Tercio@11 2392 time.line = line
Tercio@11 2393 end
Tercio@11 2394
Tercio@11 2395 --graphic
Tercio@11 2396 local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67)
Tercio@11 2397 g:SetXAxis (-1,1)
Tercio@11 2398 g:SetYAxis (-1,1)
Tercio@11 2399 g:SetGridSpacing (false, false)
Tercio@11 2400 g:SetGridColor ({0.5,0.5,0.5,0.3})
Tercio@11 2401 g:SetAxisDrawing (false,false)
Tercio@11 2402 g:SetAxisColor({1.0,1.0,1.0,1.0})
Tercio@11 2403 g:SetAutoScale (true)
Tercio@11 2404 g:SetLineTexture ("smallline")
Tercio@11 2405 g:SetBorderSize ("right", 0.001)
Tercio@11 2406 g:SetBorderSize ("left", 0.000)
Tercio@11 2407 g:SetBorderSize ("top", 0.002)
Tercio@11 2408 g:SetBorderSize ("bottom", 0.001)
Tercio@11 2409 g.VerticalLines = {}
Tercio@11 2410 g.max_value = 0
Tercio@11 2411
Tercio@11 2412 g:SetLineTexture ("line")
Tercio@11 2413
Tercio@11 2414 f.Graphic = g
Tercio@11 2415 f.GData = {}
Tercio@11 2416 f.OData = {}
Tercio@11 2417
Tercio@11 2418 --div lines
Tercio@11 2419 for i = 1, 8, 1 do
Tercio@11 2420 local line = g:CreateTexture (nil, "overlay")
Tercio@11 2421 line:SetTexture (1, 1, 1, .2)
Tercio@11 2422 line:SetWidth (670)
Tercio@11 2423 line:SetHeight (1.1)
Tercio@11 2424
Tercio@11 2425 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 2426 f ["dpsamt"..i] = s
Tercio@11 2427 s:SetText ("100k")
Tercio@11 2428 s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i)))
Tercio@11 2429
Tercio@11 2430 line:SetPoint ("topleft", s, "bottom", -27, 0)
Tercio@11 2431 s.line = line
Tercio@11 2432 end
Tercio@11 2433
Tercio@11 2434 f.SetTime = chart_panel_align_timelabels
Tercio@11 2435 f.EnableVerticalLines = chart_panel_vlines_on
Tercio@11 2436 f.DisableVerticalLines = chart_panel_vlines_off
Tercio@11 2437 f.SetTitle = chart_panel_set_title
Tercio@11 2438 f.SetScale = chart_panel_set_scale
Tercio@11 2439 f.Reset = chart_panel_reset
Tercio@11 2440 f.AddLine = chart_panel_add_data
Tercio@11 2441 f.CanMove = chart_panel_can_move
Tercio@11 2442 f.AddLabel = chart_panel_add_label
Tercio@11 2443 f.AddOverlay = chart_panel_add_overlay
Tercio@11 2444 f.HideCloseButton = chart_panel_hide_close_button
Tercio@11 2445 f.RightClickClose = chart_panel_right_click_close
Tercio@11 2446
Tercio@11 2447 f:SetScript ("OnSizeChanged", chart_panel_onresize)
Tercio@11 2448 chart_panel_onresize (f)
Tercio@11 2449
Tercio@11 2450 return f
Tercio@11 2451 end