annotate Libs/DF/panel.lua @ 17:0c160948ac5e

- ToC Update.
author Tercio
date Tue, 23 Jun 2015 14:16:13 -0300
parents f635adb94909
children 680465749fc7
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@17 654 --> text
Tercio@11 655 row.row_widgets [i]:SetText (results [i])
Tercio@17 656 if (panel.rows [i].type == "entry") then
Tercio@17 657 row.row_widgets [i]:SetCursorPosition (0)
Tercio@17 658 end
Tercio@11 659
Tercio@11 660 end
Tercio@11 661 end
Tercio@11 662
Tercio@11 663 else
Tercio@11 664 row:Hide()
Tercio@11 665 for i = 1, #row.row_widgets do
Tercio@11 666 row.row_widgets [i]:SetText ("")
Tercio@11 667 if (panel.rows [i].type == "icon") then
Tercio@11 668 row.row_widgets [i]._icon.texture = ""
Tercio@11 669 end
Tercio@11 670 end
Tercio@11 671 end
Tercio@11 672 else
Tercio@11 673 row:Hide()
Tercio@11 674 for i = 1, #row.row_widgets do
Tercio@11 675 row.row_widgets [i]:SetText ("")
Tercio@11 676 if (panel.rows [i].type == "icon") then
Tercio@11 677 row.row_widgets [i]._icon.texture = ""
Tercio@11 678 end
Tercio@11 679 end
Tercio@11 680 end
Tercio@11 681 end
Tercio@11 682 end
Tercio@11 683
Tercio@11 684 function panel:Refresh()
Tercio@11 685 local filled_lines = total_lines()
Tercio@17 686 local scroll_total_lines = #panel.scrollframe.lines
Tercio@11 687 local line_height = options.rowheight
Tercio@11 688
Tercio@11 689 FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height)
Tercio@11 690 refresh_fillbox (panel.scrollframe)
Tercio@11 691 end
Tercio@11 692
Tercio@11 693 local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate")
Tercio@11 694 scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end)
Tercio@11 695 scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21)
Tercio@11 696 scrollframe:SetPoint ("topright", panel.widget, "topright", -23, -21)
Tercio@11 697 scrollframe:SetPoint ("bottomleft", panel.widget, "bottomleft")
Tercio@11 698 scrollframe:SetPoint ("bottomright", panel.widget, "bottomright", -23, 0)
Tercio@11 699 scrollframe:SetSize (w, h)
Tercio@11 700 panel.scrollframe = scrollframe
Tercio@11 701 scrollframe.lines = {}
Tercio@11 702
Tercio@11 703 --create lines
Tercio@11 704 local size = options.rowheight
Tercio@11 705 local amount = math.floor (((h-21) / size))
Tercio@11 706
Tercio@11 707
Tercio@11 708 for i = 1, amount do
Tercio@11 709
Tercio@17 710 local row = DF:NewPanel (panel, nil, "$parentRow_" .. i, nil, 1, size)
Tercio@11 711 row.backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]]}
Tercio@11 712 row.color = {1, 1, 1, .2}
Tercio@11 713 row:SetPoint ("topleft", scrollframe, "topleft", 0, (i-1) * size * -1)
Tercio@11 714 row:SetPoint ("topright", scrollframe, "topright", 0, (i-1) * size * -1)
Tercio@11 715 tinsert (scrollframe.lines, row)
Tercio@11 716
Tercio@11 717 row.row_widgets = {}
Tercio@11 718
Tercio@11 719 for o = 1, #rows do
Tercio@11 720
Tercio@11 721 local _type = panel.rows [o].type
Tercio@11 722
Tercio@11 723 if (_type == "text") then
Tercio@11 724
Tercio@11 725 --> create text
Tercio@11 726 local text = DF:NewLabel (row, nil, name .. "$parentLabel" .. o, "text" .. o)
Tercio@11 727 text:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 728
Tercio@11 729 --> insert in the table
Tercio@11 730 tinsert (row.row_widgets, text)
Tercio@11 731
Tercio@11 732 elseif (_type == "entry") then
Tercio@11 733
Tercio@11 734 --> create editbox
Tercio@11 735 local editbox = DF:NewTextEntry (row, nil, "$parentEntry" .. o, "entry", panel.rows [o].width, 20, panel.rows [o].func, i, o)
Tercio@11 736 editbox.align = "left"
Tercio@11 737 editbox:SetHook ("OnEnterPressed", function()
Tercio@11 738 editbox.widget.focuslost = true
Tercio@11 739 editbox:ClearFocus()
Tercio@11 740 editbox.func (editbox.index, editbox.text)
Tercio@11 741 return true
Tercio@11 742 end)
Tercio@11 743 editbox:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 744 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1})
Tercio@11 745 editbox:SetBackdropColor (1, 1, 1, 0.1)
Tercio@11 746 editbox:SetBackdropBorderColor (1, 1, 1, 0.1)
Tercio@11 747 editbox.editbox.current_bordercolor = {1, 1, 1, 0.1}
Tercio@11 748
Tercio@11 749 --> insert in the table
Tercio@11 750 tinsert (row.row_widgets, editbox)
Tercio@11 751
Tercio@11 752 elseif (_type == "button") then
Tercio@11 753
Tercio@11 754 --> create button
Tercio@11 755 local button = DF:NewButton (row, nil, "$parentButton" .. o, "button", panel.rows [o].width, 20)
Tercio@11 756
Tercio@11 757 local func = function()
Tercio@11 758 panel.rows [o].func (button.index, o)
Tercio@11 759 panel:Refresh()
Tercio@11 760 end
Tercio@11 761 button:SetClickFunction (func)
Tercio@11 762
Tercio@11 763 button:SetPoint ("left", row, "left", anchors [o], 0)
Tercio@11 764
Tercio@11 765 --> create icon and the text
Tercio@11 766 local icon = DF:NewImage (button, nil, 20, 20)
Tercio@11 767 local text = DF:NewLabel (button)
Tercio@11 768
Tercio@11 769 button._icon = icon
Tercio@11 770 button._text = text
Tercio@11 771
Tercio@11 772 button:SetHook ("OnEnter", button_on_enter)
Tercio@11 773 button:SetHook ("OnLeave", button_on_leave)
Tercio@11 774
Tercio@11 775 if (panel.rows [o].icon) then
Tercio@11 776 icon.texture = panel.rows [o].icon
Tercio@11 777 if (panel.rows [o].iconalign) then
Tercio@11 778 if (panel.rows [o].iconalign == "center") then
Tercio@11 779 icon:SetPoint ("center", button, "center")
Tercio@11 780 elseif (panel.rows [o].iconalign == "right") then
Tercio@11 781 icon:SetPoint ("right", button, "right")
Tercio@11 782 end
Tercio@11 783 else
Tercio@11 784 icon:SetPoint ("left", button, "left")
Tercio@11 785 end
Tercio@11 786 end
Tercio@11 787
Tercio@11 788 if (panel.rows [o].name and not panel.rows [o].notext) then
Tercio@11 789 text:SetPoint ("left", icon, "right", 2, 0)
Tercio@11 790 text.text = panel.rows [o].name
Tercio@11 791 end
Tercio@11 792
Tercio@11 793 --> inser in the table
Tercio@11 794 tinsert (row.row_widgets, button)
Tercio@11 795
Tercio@11 796 elseif (_type == "icon") then
Tercio@11 797
Tercio@11 798 --> create button and icon
Tercio@11 799 local iconbutton = DF:NewButton (row, nil, "$parentIconButton" .. o, "iconbutton", 22, 20)
Tercio@11 800 iconbutton:InstallCustomTexture()
Tercio@11 801
Tercio@11 802 iconbutton:SetHook ("OnEnter", button_on_enter)
Tercio@11 803 iconbutton:SetHook ("OnLeave", button_on_leave)
Tercio@11 804
Tercio@11 805 --iconbutton:InstallCustomTexture()
Tercio@11 806 local icon = DF:NewImage (iconbutton, nil, 20, 20, "artwork", nil, "_icon", "$parentIcon" .. o)
Tercio@11 807 iconbutton._icon = icon
Tercio@11 808
Tercio@11 809 iconbutton:SetPoint ("left", row, "left", anchors [o] + ( (panel.rows [o].width - 22) / 2), 0)
Tercio@11 810 icon:SetPoint ("center", iconbutton, "center", 0, 0)
Tercio@11 811
Tercio@11 812 --> set functions
Tercio@11 813 local function iconcallback (texture)
Tercio@11 814 iconbutton._icon.texture = texture
Tercio@11 815 panel.rows [o].func (iconbutton.index, texture)
Tercio@11 816 end
Tercio@11 817
Tercio@11 818 iconbutton:SetClickFunction (function()
Tercio@11 819 DF:IconPick (iconcallback, true)
Tercio@11 820 return true
Tercio@11 821 end)
Tercio@11 822
Tercio@11 823 --> insert in the table
Tercio@11 824 tinsert (row.row_widgets, iconbutton)
Tercio@11 825
Tercio@11 826 end
Tercio@11 827
Tercio@11 828 end
Tercio@11 829 end
Tercio@11 830
Tercio@11 831 return panel
Tercio@11 832 end
Tercio@11 833
Tercio@11 834
Tercio@11 835 ------------color pick
Tercio@11 836 local color_pick_func = function()
Tercio@11 837 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 838 local a = OpacitySliderFrame:GetValue()
Tercio@11 839 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 840 end
Tercio@11 841 local color_pick_func_cancel = function()
Tercio@11 842 ColorPickerFrame:SetColorRGB (unpack (ColorPickerFrame.previousValues))
Tercio@11 843 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 844 local a = OpacitySliderFrame:GetValue()
Tercio@11 845 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 846 end
Tercio@11 847
Tercio@11 848 function DF:ColorPick (frame, r, g, b, alpha, callback)
Tercio@11 849
Tercio@11 850 ColorPickerFrame:ClearAllPoints()
Tercio@11 851 ColorPickerFrame:SetPoint ("bottomleft", frame, "topright", 0, 0)
Tercio@11 852
Tercio@11 853 ColorPickerFrame.dcallback = callback
Tercio@11 854 ColorPickerFrame.dframe = frame
Tercio@11 855
Tercio@11 856 ColorPickerFrame.func = color_pick_func
Tercio@11 857 ColorPickerFrame.opacityFunc = color_pick_func
Tercio@11 858 ColorPickerFrame.cancelFunc = color_pick_func_cancel
Tercio@11 859
Tercio@11 860 ColorPickerFrame.opacity = alpha
Tercio@11 861 ColorPickerFrame.hasOpacity = alpha and true
Tercio@11 862
Tercio@11 863 ColorPickerFrame.previousValues = {r, g, b}
Tercio@11 864 ColorPickerFrame:SetParent (UIParent)
Tercio@11 865 ColorPickerFrame:SetFrameStrata ("tooltip")
Tercio@11 866 ColorPickerFrame:SetColorRGB (r, g, b)
Tercio@11 867 ColorPickerFrame:Show()
Tercio@11 868
Tercio@11 869 end
Tercio@11 870
Tercio@11 871 ------------icon pick
Tercio@11 872 function DF:IconPick (callback, close_when_select)
Tercio@11 873
Tercio@11 874 if (not DF.IconPickFrame) then
Tercio@11 875
Tercio@11 876 local string_lower = string.lower
Tercio@11 877
Tercio@11 878 DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent)
Tercio@11 879 tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame")
Tercio@11 880 DF.IconPickFrame:SetFrameStrata ("DIALOG")
Tercio@11 881
Tercio@11 882 DF.IconPickFrame:SetPoint ("center", UIParent, "center")
Tercio@11 883 DF.IconPickFrame:SetWidth (350)
Tercio@11 884 DF.IconPickFrame:SetHeight (227)
Tercio@11 885 DF.IconPickFrame:EnableMouse (true)
Tercio@11 886 DF.IconPickFrame:SetMovable (true)
Tercio@11 887 DF.IconPickFrame:SetBackdrop ({bgFile = DF.folder .. "background", edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Tercio@11 888 tile = true, tileSize = 32, edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}})
Tercio@11 889
Tercio@11 890 DF.IconPickFrame:SetBackdropBorderColor (170/255, 170/255, 170/255)
Tercio@11 891 DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8)
Tercio@11 892 DF.IconPickFrame:SetFrameLevel (1)
Tercio@11 893
Tercio@11 894 DF.IconPickFrame.emptyFunction = function() end
Tercio@11 895 DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction
Tercio@11 896
Tercio@11 897 DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent)
Tercio@11 898 DF.IconPickFrame.preview:SetFrameStrata ("tooltip")
Tercio@11 899 DF.IconPickFrame.preview:SetSize (76, 76)
Tercio@11 900 local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
Tercio@11 901 preview_image:SetAllPoints (DF.IconPickFrame.preview)
Tercio@11 902 DF.IconPickFrame.preview.icon = preview_image
Tercio@11 903 DF.IconPickFrame.preview:Hide()
Tercio@11 904
Tercio@11 905 DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color)
Tercio@11 906 DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -20)
Tercio@11 907 DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20)
Tercio@11 908 DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0)
Tercio@11 909 DF.IconPickFrame.search:SetHook ("OnTextChanged", function()
Tercio@11 910 DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText()
Tercio@11 911 if (DF.IconPickFrame.searching == "") then
Tercio@11 912 DF.IconPickFrameScroll:Show()
Tercio@11 913 DF.IconPickFrame.searching = nil
Tercio@11 914 DF.IconPickFrame.updateFunc()
Tercio@11 915 else
Tercio@11 916 DF.IconPickFrameScroll:Hide()
Tercio@11 917 FauxScrollFrame_SetOffset (DF.IconPickFrame, 1)
Tercio@11 918 DF.IconPickFrame.last_filter_index = 1
Tercio@11 919 DF.IconPickFrame.updateFunc()
Tercio@11 920 end
Tercio@11 921 end)
Tercio@11 922
Tercio@11 923 --> close button
Tercio@11 924 local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton")
Tercio@11 925 close_button:SetWidth (32)
Tercio@11 926 close_button:SetHeight (32)
Tercio@11 927 close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7)
Tercio@11 928 close_button:SetFrameLevel (close_button:GetFrameLevel()+2)
Tercio@11 929
Tercio@11 930 local MACRO_ICON_FILENAMES = {}
Tercio@11 931 DF.IconPickFrame:SetScript ("OnShow", function()
Tercio@11 932
Tercio@11 933 MACRO_ICON_FILENAMES = {};
Tercio@11 934 MACRO_ICON_FILENAMES[1] = "INV_MISC_QUESTIONMARK";
Tercio@11 935 local index = 2;
Tercio@11 936
Tercio@11 937 for i = 1, GetNumSpellTabs() do
Tercio@11 938 local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo(i);
Tercio@11 939 offset = offset + 1;
Tercio@11 940 local tabEnd = offset + numSpells;
Tercio@11 941 for j = offset, tabEnd - 1 do
Tercio@11 942 --to get spell info by slot, you have to pass in a pet argument
Tercio@11 943 local spellType, ID = GetSpellBookItemInfo(j, "player");
Tercio@11 944 if (spellType ~= "FUTURESPELL") then
Tercio@11 945 local spellTexture = strupper(GetSpellBookItemTexture(j, "player"));
Tercio@11 946 if ( not string.match( spellTexture, "INTERFACE\\BUTTONS\\") ) then
Tercio@11 947 MACRO_ICON_FILENAMES[index] = gsub( spellTexture, "INTERFACE\\ICONS\\", "");
Tercio@11 948 index = index + 1;
Tercio@11 949 end
Tercio@11 950 end
Tercio@11 951 if (spellType == "FLYOUT") then
Tercio@11 952 local _, _, numSlots, isKnown = GetFlyoutInfo(ID);
Tercio@11 953 if (isKnown and numSlots > 0) then
Tercio@11 954 for k = 1, numSlots do
Tercio@11 955 local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo(ID, k)
Tercio@11 956 if (isKnown) then
Tercio@11 957 MACRO_ICON_FILENAMES[index] = gsub( strupper(GetSpellTexture(spellID)), "INTERFACE\\ICONS\\", "");
Tercio@11 958 index = index + 1;
Tercio@11 959 end
Tercio@11 960 end
Tercio@11 961 end
Tercio@11 962 end
Tercio@11 963 end
Tercio@11 964 end
Tercio@11 965
Tercio@11 966 GetLooseMacroItemIcons (MACRO_ICON_FILENAMES)
Tercio@11 967 GetLooseMacroIcons (MACRO_ICON_FILENAMES)
Tercio@11 968 GetMacroIcons (MACRO_ICON_FILENAMES)
Tercio@11 969 GetMacroItemIcons (MACRO_ICON_FILENAMES )
Tercio@11 970
Tercio@11 971 end)
Tercio@11 972
Tercio@11 973 DF.IconPickFrame:SetScript ("OnHide", function()
Tercio@11 974 MACRO_ICON_FILENAMES = nil;
Tercio@11 975 collectgarbage()
Tercio@11 976 end)
Tercio@11 977
Tercio@11 978 DF.IconPickFrame.buttons = {}
Tercio@11 979
Tercio@11 980 local OnClickFunction = function (self)
Tercio@11 981 DF.IconPickFrame.callback (self.icon:GetTexture())
Tercio@11 982 if (DF.IconPickFrame.click_close) then
Tercio@11 983 close_button:Click()
Tercio@11 984 end
Tercio@11 985 end
Tercio@11 986
Tercio@11 987 local onenter = function (self)
Tercio@11 988 DF.IconPickFrame.preview:SetPoint ("bottom", self, "top", 0, 2)
Tercio@11 989 DF.IconPickFrame.preview.icon:SetTexture (self.icon:GetTexture())
Tercio@11 990 DF.IconPickFrame.preview:Show()
Tercio@11 991 self.icon:SetBlendMode ("ADD")
Tercio@11 992 end
Tercio@11 993 local onleave = function (self)
Tercio@11 994 DF.IconPickFrame.preview:Hide()
Tercio@11 995 self.icon:SetBlendMode ("BLEND")
Tercio@11 996 end
Tercio@11 997
Tercio@11 998 local backdrop = {bgFile = DF.folder .. "background", tile = true, tileSize = 16,
Tercio@11 999 insets = {left = 0, right = 0, top = 0, bottom = 0}, edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 10}
Tercio@11 1000
Tercio@11 1001 for i = 0, 9 do
Tercio@11 1002 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..(i+1), DF.IconPickFrame)
Tercio@11 1003 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..(i+1).."Icon", "overlay")
Tercio@11 1004 newcheck.icon = image
Tercio@11 1005 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1006 newcheck:SetSize (30, 28)
Tercio@11 1007 newcheck:SetBackdrop (backdrop)
Tercio@11 1008
Tercio@11 1009 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1010 newcheck.param1 = i+1
Tercio@11 1011
Tercio@11 1012 newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -40)
Tercio@11 1013 newcheck:SetID (i+1)
Tercio@11 1014 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1015 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1016 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1017 end
Tercio@11 1018 for i = 11, 20 do
Tercio@11 1019 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1020 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1021 newcheck.icon = image
Tercio@11 1022 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1023 newcheck:SetSize (30, 28)
Tercio@11 1024 newcheck:SetBackdrop (backdrop)
Tercio@11 1025
Tercio@11 1026 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1027 newcheck.param1 = i
Tercio@11 1028
Tercio@11 1029 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1030 newcheck:SetID (i)
Tercio@11 1031 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1032 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1033 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1034 end
Tercio@11 1035 for i = 21, 30 do
Tercio@11 1036 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1037 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1038 newcheck.icon = image
Tercio@11 1039 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1040 newcheck:SetSize (30, 28)
Tercio@11 1041 newcheck:SetBackdrop (backdrop)
Tercio@11 1042
Tercio@11 1043 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1044 newcheck.param1 = i
Tercio@11 1045
Tercio@11 1046 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1047 newcheck:SetID (i)
Tercio@11 1048 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1049 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1050 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1051 end
Tercio@11 1052 for i = 31, 40 do
Tercio@11 1053 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1054 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1055 newcheck.icon = image
Tercio@11 1056 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1057 newcheck:SetSize (30, 28)
Tercio@11 1058 newcheck:SetBackdrop (backdrop)
Tercio@11 1059
Tercio@11 1060 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1061 newcheck.param1 = i
Tercio@11 1062
Tercio@11 1063 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1064 newcheck:SetID (i)
Tercio@11 1065 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1066 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1067 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1068 end
Tercio@11 1069 for i = 41, 50 do
Tercio@11 1070 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1071 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1072 newcheck.icon = image
Tercio@11 1073 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1074 newcheck:SetSize (30, 28)
Tercio@11 1075 newcheck:SetBackdrop (backdrop)
Tercio@11 1076
Tercio@11 1077 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1078 newcheck.param1 = i
Tercio@11 1079
Tercio@11 1080 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1081 newcheck:SetID (i)
Tercio@11 1082 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1083 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1084 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1085 end
Tercio@11 1086 for i = 51, 60 do
Tercio@11 1087 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1088 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1089 newcheck.icon = image
Tercio@11 1090 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1091 newcheck:SetSize (30, 28)
Tercio@11 1092 newcheck:SetBackdrop (backdrop)
Tercio@11 1093
Tercio@11 1094 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1095 newcheck.param1 = i
Tercio@11 1096
Tercio@11 1097 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1098 newcheck:SetID (i)
Tercio@11 1099 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1100 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1101 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1102 end
Tercio@11 1103
Tercio@11 1104 local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate")
Tercio@11 1105
Tercio@11 1106 local ChecksFrame_Update = function (self)
Tercio@11 1107
Tercio@11 1108 local numMacroIcons = #MACRO_ICON_FILENAMES
Tercio@11 1109 local macroPopupIcon, macroPopupButton
Tercio@11 1110 local macroPopupOffset = FauxScrollFrame_GetOffset (scroll)
Tercio@11 1111 local index
Tercio@11 1112
Tercio@11 1113 local texture
Tercio@11 1114 local filter
Tercio@11 1115 if (DF.IconPickFrame.searching) then
Tercio@11 1116 filter = string_lower (DF.IconPickFrame.searching)
Tercio@11 1117 end
Tercio@11 1118
Tercio@11 1119 if (filter and filter ~= "") then
Tercio@11 1120
Tercio@11 1121 local ignored = 0
Tercio@11 1122 local tryed = 0
Tercio@11 1123 local found = 0
Tercio@11 1124 local type = type
Tercio@11 1125 local buttons = DF.IconPickFrame.buttons
Tercio@11 1126 index = 1
Tercio@11 1127
Tercio@11 1128 for i = 1, 60 do
Tercio@11 1129
Tercio@11 1130 macroPopupIcon = buttons[i].icon
Tercio@11 1131 macroPopupButton = buttons[i]
Tercio@11 1132
Tercio@11 1133 for o = index, numMacroIcons do
Tercio@11 1134
Tercio@11 1135 tryed = tryed + 1
Tercio@11 1136
Tercio@11 1137 texture = MACRO_ICON_FILENAMES [o]
Tercio@11 1138 if (type (texture) == "number") then
Tercio@11 1139 macroPopupIcon:SetToFileData (texture)
Tercio@11 1140 texture = macroPopupIcon:GetTexture()
Tercio@11 1141 macroPopupIcon:SetTexture (nil)
Tercio@11 1142 else
Tercio@11 1143 texture = "INTERFACE\\ICONS\\" .. texture
Tercio@11 1144 end
Tercio@11 1145
Tercio@11 1146 if (texture and texture:find (filter)) then
Tercio@11 1147 macroPopupIcon:SetTexture (texture)
Tercio@11 1148 macroPopupButton:Show()
Tercio@11 1149 found = found + 1
Tercio@11 1150 DF.IconPickFrame.last_filter_index = o
Tercio@11 1151 index = o+1
Tercio@11 1152 break
Tercio@11 1153 else
Tercio@11 1154 ignored = ignored + 1
Tercio@11 1155 end
Tercio@11 1156
Tercio@11 1157 end
Tercio@11 1158 end
Tercio@11 1159
Tercio@11 1160 for o = found+1, 60 do
Tercio@11 1161 macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..o]
Tercio@11 1162 macroPopupButton:Hide()
Tercio@11 1163 end
Tercio@11 1164 else
Tercio@11 1165 for i = 1, 60 do
Tercio@11 1166 macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"]
Tercio@11 1167 macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i]
Tercio@11 1168 index = (macroPopupOffset * 10) + i
Tercio@11 1169 texture = MACRO_ICON_FILENAMES [index]
Tercio@11 1170 if ( index <= numMacroIcons and texture ) then
Tercio@11 1171
Tercio@11 1172 if (type (texture) == "number") then
Tercio@11 1173 macroPopupIcon:SetToFileData (texture)
Tercio@11 1174 else
Tercio@11 1175 macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture)
Tercio@11 1176 end
Tercio@11 1177
Tercio@11 1178 macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64)
Tercio@11 1179 macroPopupButton.IconID = index
Tercio@11 1180 macroPopupButton:Show()
Tercio@11 1181 else
Tercio@11 1182 macroPopupButton:Hide()
Tercio@11 1183 end
Tercio@11 1184 end
Tercio@11 1185 end
Tercio@11 1186
Tercio@11 1187 -- Scrollbar stuff
Tercio@11 1188 FauxScrollFrame_Update (scroll, ceil (numMacroIcons / 10) , 5, 20 )
Tercio@11 1189 end
Tercio@11 1190
Tercio@11 1191 DF.IconPickFrame.updateFunc = ChecksFrame_Update
Tercio@11 1192
Tercio@11 1193 scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -37)
Tercio@11 1194 scroll:SetWidth (330)
Tercio@11 1195 scroll:SetHeight (178)
Tercio@11 1196 scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end)
Tercio@11 1197 scroll.update = ChecksFrame_Update
Tercio@11 1198 DF.IconPickFrameScroll = scroll
Tercio@11 1199 DF.IconPickFrame:Hide()
Tercio@11 1200
Tercio@11 1201 end
Tercio@11 1202
Tercio@11 1203 DF.IconPickFrame:Show()
Tercio@11 1204 DF.IconPickFrameScroll.update (DF.IconPickFrameScroll)
Tercio@11 1205 DF.IconPickFrame.callback = callback or DF.IconPickFrame.emptyFunction
Tercio@11 1206 DF.IconPickFrame.click_close = close_when_select
Tercio@11 1207
Tercio@11 1208 end
Tercio@11 1209
Tercio@11 1210 local simple_panel_counter = 1
Tercio@11 1211 local simple_panel_mouse_down = function (self, button)
Tercio@11 1212 if (button == "RightButton") then
Tercio@11 1213 if (self.IsMoving) then
Tercio@11 1214 self.IsMoving = false
Tercio@11 1215 self:StopMovingOrSizing()
Tercio@11 1216 if (self.db and self.db.position) then
Tercio@11 1217 DF:SavePositionOnScreen (self)
Tercio@11 1218 end
Tercio@11 1219 end
Tercio@17 1220 if (not self.DontRightClickClose) then
Tercio@17 1221 self:Hide()
Tercio@17 1222 end
Tercio@11 1223 return
Tercio@11 1224 end
Tercio@11 1225 if (not self.IsMoving and not self.IsLocked) then
Tercio@11 1226 self.IsMoving = true
Tercio@11 1227 self:StartMoving()
Tercio@11 1228 end
Tercio@11 1229 end
Tercio@11 1230 local simple_panel_mouse_up = function (self, button)
Tercio@11 1231 if (self.IsMoving) then
Tercio@11 1232 self.IsMoving = false
Tercio@11 1233 self:StopMovingOrSizing()
Tercio@11 1234 if (self.db and self.db.position) then
Tercio@11 1235 DF:SavePositionOnScreen (self)
Tercio@11 1236 end
Tercio@11 1237 end
Tercio@11 1238 end
Tercio@11 1239 local simple_panel_settitle = function (self, title)
Tercio@11 1240 self.title:SetText (title)
Tercio@11 1241 end
Tercio@11 1242
Tercio@11 1243 function DF:CreateSimplePanel (parent, w, h, title, name)
Tercio@11 1244
Tercio@11 1245 if (not name) then
Tercio@11 1246 name = "DetailsFrameworkSimplePanel" .. simple_panel_counter
Tercio@11 1247 simple_panel_counter = simple_panel_counter + 1
Tercio@11 1248 end
Tercio@11 1249 if (not parent) then
Tercio@11 1250 parent = UIParent
Tercio@11 1251 end
Tercio@11 1252
Tercio@11 1253 local f = CreateFrame ("frame", name, UIParent)
Tercio@11 1254 f:SetSize (w or 400, h or 250)
Tercio@11 1255 f:SetPoint ("center", UIParent, "center", 0, 0)
Tercio@11 1256 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 1257 f:EnableMouse()
Tercio@11 1258 f:SetMovable (true)
Tercio@11 1259 tinsert (UISpecialFrames, name)
Tercio@11 1260
Tercio@11 1261 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1262 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1263
Tercio@11 1264 local bg = f:CreateTexture (nil, "background")
Tercio@11 1265 bg:SetAllPoints (f)
Tercio@11 1266 bg:SetTexture (DF.folder .. "background")
Tercio@11 1267
Tercio@11 1268 local close = CreateFrame ("button", name .. "Close", f, "UIPanelCloseButton")
Tercio@11 1269 close:SetSize (32, 32)
Tercio@11 1270 close:SetPoint ("topright", f, "topright", 0, -12)
Tercio@11 1271
Tercio@11 1272 f.title = DF:CreateLabel (f, title or "", 12, nil, "GameFontNormal")
Tercio@11 1273 f.title:SetPoint ("top", f, "top", 0, -22)
Tercio@11 1274
Tercio@11 1275 f.SetTitle = simple_panel_settitle
Tercio@11 1276
Tercio@11 1277 simple_panel_counter = simple_panel_counter + 1
Tercio@11 1278
Tercio@11 1279 return f
Tercio@11 1280 end
Tercio@11 1281
Tercio@11 1282 local Panel1PxBackdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 64,
Tercio@11 1283 edgeFile = DF.folder .. "border_3", edgeSize = 9, insets = {left = 2, right = 2, top = 3, bottom = 3}}
Tercio@11 1284
Tercio@11 1285 local Panel1PxOnClickClose = function (self)
Tercio@11 1286 self:GetParent():Hide()
Tercio@11 1287 end
Tercio@11 1288 local Panel1PxOnToggleLock = function (self)
Tercio@11 1289 if (self.IsLocked) then
Tercio@11 1290 self.IsLocked = false
Tercio@11 1291 self:SetMovable (true)
Tercio@11 1292 self:EnableMouse (true)
Tercio@11 1293 self.Lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1294 self.Lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1295 self.Lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@17 1296 if (self.OnUnlock) then
Tercio@17 1297 self:OnUnlock()
Tercio@17 1298 end
Tercio@17 1299 if (self.db) then
Tercio@17 1300 self.db.IsLocked = self.IsLocked
Tercio@17 1301 end
Tercio@11 1302 else
Tercio@11 1303 self.IsLocked = true
Tercio@11 1304 self:SetMovable (false)
Tercio@11 1305 self:EnableMouse (false)
Tercio@11 1306 self.Lock:GetNormalTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1307 self.Lock:GetHighlightTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1308 self.Lock:GetPushedTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@17 1309 if (self.OnLock) then
Tercio@17 1310 self:OnLock()
Tercio@17 1311 end
Tercio@17 1312 if (self.db) then
Tercio@17 1313 self.db.IsLocked = self.IsLocked
Tercio@17 1314 end
Tercio@11 1315 end
Tercio@11 1316 end
Tercio@11 1317 local Panel1PxOnClickLock = function (self)
Tercio@11 1318 local f = self:GetParent()
Tercio@11 1319 Panel1PxOnToggleLock (f)
Tercio@11 1320 end
Tercio@11 1321 local Panel1PxSetTitle = function (self, text)
Tercio@11 1322 self.Title:SetText (text or "")
Tercio@11 1323 end
Tercio@11 1324
Tercio@11 1325 local Panel1PxReadConfig = function (self)
Tercio@11 1326 local db = self.db
Tercio@11 1327 if (db) then
Tercio@11 1328 db.IsLocked = db.IsLocked or false
Tercio@11 1329 self.IsLocked = db.IsLocked
Tercio@11 1330 db.position = db.position or {x = 0, y = 0}
Tercio@11 1331 DF:RestoreFramePosition (self)
Tercio@11 1332 end
Tercio@11 1333 end
Tercio@11 1334
Tercio@11 1335 function DF:SavePositionOnScreen (frame)
Tercio@11 1336 if (frame.db and frame.db.position) then
Tercio@11 1337 local x, y = DF:GetPositionOnScreen (frame)
Tercio@11 1338 frame.db.position.x, frame.db.position.y = x, y
Tercio@11 1339 end
Tercio@11 1340 end
Tercio@11 1341
Tercio@11 1342 function DF:GetPositionOnScreen (frame)
Tercio@11 1343 local xOfs, yOfs = frame:GetCenter()
Tercio@11 1344 if (not xOfs) then
Tercio@11 1345 return
Tercio@11 1346 end
Tercio@11 1347 local scale = frame:GetEffectiveScale()
Tercio@11 1348 local UIscale = UIParent:GetScale()
Tercio@11 1349 xOfs = xOfs*scale - GetScreenWidth()*UIscale/2
Tercio@11 1350 yOfs = yOfs*scale - GetScreenHeight()*UIscale/2
Tercio@11 1351 return xOfs/UIscale, yOfs/UIscale
Tercio@11 1352 end
Tercio@11 1353
Tercio@11 1354 function DF:RestoreFramePosition (frame)
Tercio@11 1355 if (frame.db and frame.db.position) then
Tercio@11 1356 local scale, UIscale = frame:GetEffectiveScale(), UIParent:GetScale()
Tercio@11 1357 frame:ClearAllPoints()
Tercio@11 1358 frame:SetPoint ("center", UIParent, "center", frame.db.position.x * UIscale / scale, frame.db.position.y * UIscale / scale)
Tercio@11 1359 end
Tercio@11 1360 end
Tercio@11 1361
Tercio@13 1362 function DF:Create1PxPanel (parent, w, h, title, name, config, title_anchor, no_special_frame)
Tercio@11 1363 local f = CreateFrame ("frame", name, parent or UIParent)
Tercio@11 1364 f:SetSize (w or 100, h or 75)
Tercio@11 1365 f:SetPoint ("center", UIParent, "center")
Tercio@11 1366
Tercio@13 1367 if (name and not no_special_frame) then
Tercio@11 1368 tinsert (UISpecialFrames, name)
Tercio@11 1369 end
Tercio@11 1370
Tercio@11 1371 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1372 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1373
Tercio@11 1374 f:SetBackdrop (Panel1PxBackdrop)
Tercio@11 1375 f:SetBackdropColor (0, 0, 0, 0.5)
Tercio@11 1376
Tercio@17 1377 f.IsLocked = (config and config.IsLocked ~= nil and config.IsLocked) or false
Tercio@11 1378 f:SetMovable (true)
Tercio@11 1379 f:EnableMouse (true)
Tercio@11 1380 f:SetUserPlaced (true)
Tercio@11 1381
Tercio@11 1382 f.db = config
Tercio@11 1383 Panel1PxReadConfig (f)
Tercio@11 1384
Tercio@11 1385 local close = CreateFrame ("button", name and name .. "CloseButton", f)
Tercio@11 1386 close:SetSize (16, 16)
Tercio@11 1387 close:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1388 close:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1389 close:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1390 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1391 close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1392 close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1393 close:SetAlpha (0.7)
Tercio@11 1394
Tercio@11 1395 local lock = CreateFrame ("button", name and name .. "LockButton", f)
Tercio@11 1396 lock:SetSize (16, 16)
Tercio@11 1397 lock:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1398 lock:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1399 lock:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1400 lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1401 lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1402 lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1403 lock:SetAlpha (0.7)
Tercio@11 1404
Tercio@11 1405 close:SetPoint ("topright", f, "topright", -3, -3)
Tercio@11 1406 lock:SetPoint ("right", close, "left", 3, 0)
Tercio@11 1407
Tercio@11 1408 close:SetScript ("OnClick", Panel1PxOnClickClose)
Tercio@11 1409 lock:SetScript ("OnClick", Panel1PxOnClickLock)
Tercio@11 1410
Tercio@11 1411 local title_string = f:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal")
Tercio@11 1412 title_string:SetPoint ("topleft", f, "topleft", 5, -5)
Tercio@11 1413 title_string:SetText (title or "")
Tercio@11 1414
Tercio@11 1415 if (title_anchor) then
Tercio@11 1416 if (title_anchor == "top") then
Tercio@11 1417 title_string:ClearAllPoints()
Tercio@11 1418 title_string:SetPoint ("bottomleft", f, "topleft", 0, 0)
Tercio@11 1419 close:ClearAllPoints()
Tercio@11 1420 close:SetPoint ("bottomright", f, "topright", 0, 0)
Tercio@11 1421 end
Tercio@11 1422 f.title_anchor = title_anchor
Tercio@11 1423 end
Tercio@11 1424
Tercio@11 1425 f.SetTitle = Panel1PxSetTitle
Tercio@11 1426 f.Title = title_string
Tercio@11 1427 f.Lock = lock
Tercio@11 1428 f.Close = close
Tercio@11 1429
Tercio@17 1430 f.IsLocked = not f.IsLocked
Tercio@17 1431 Panel1PxOnToggleLock (f)
Tercio@17 1432
Tercio@11 1433 return f
Tercio@11 1434 end
Tercio@11 1435
Tercio@11 1436 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1437 --> options button -- ~options
Tercio@11 1438 function DF:CreateOptionsButton (parent, callback, name)
Tercio@11 1439
Tercio@11 1440 local b = CreateFrame ("button", name, parent)
Tercio@11 1441 b:SetSize (14, 14)
Tercio@11 1442 b:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1443 b:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1444 b:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1445 b:GetNormalTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1446 b:GetHighlightTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1447 b:GetPushedTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 1448 b:SetAlpha (0.7)
Tercio@11 1449
Tercio@11 1450 b:SetScript ("OnClick", callback)
Tercio@11 1451 b:SetScript ("OnEnter", function (self)
Tercio@11 1452 GameCooltip2:Reset()
Tercio@11 1453 GameCooltip2:AddLine ("Options")
Tercio@11 1454 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1455 end)
Tercio@11 1456 b:SetScript ("OnLeave", function (self)
Tercio@11 1457 GameCooltip2:Hide()
Tercio@11 1458 end)
Tercio@11 1459
Tercio@11 1460 return b
Tercio@11 1461
Tercio@11 1462 end
Tercio@11 1463
Tercio@11 1464 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1465 --> feedback panel -- ~feedback
Tercio@11 1466
Tercio@11 1467 function DF:CreateFeedbackButton (parent, callback, name)
Tercio@11 1468 local b = CreateFrame ("button", name, parent)
Tercio@11 1469 b:SetSize (12, 13)
Tercio@11 1470 b:SetNormalTexture (DF.folder .. "mail")
Tercio@11 1471 b:SetPushedTexture (DF.folder .. "mail")
Tercio@11 1472 b:SetHighlightTexture (DF.folder .. "mail")
Tercio@11 1473
Tercio@11 1474 b:SetScript ("OnClick", callback)
Tercio@11 1475 b:SetScript ("OnEnter", function (self)
Tercio@11 1476 GameCooltip2:Reset()
Tercio@11 1477 GameCooltip2:AddLine ("Send Feedback")
Tercio@11 1478 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1479 end)
Tercio@11 1480 b:SetScript ("OnLeave", function (self)
Tercio@11 1481 GameCooltip2:Hide()
Tercio@11 1482 end)
Tercio@11 1483
Tercio@11 1484 return b
Tercio@11 1485 end
Tercio@11 1486
Tercio@11 1487 local backdrop_fb_line = {bgFile = DF.folder .. "background", edgeFile = DF.folder .. "border_3",
Tercio@11 1488 tile = true, tileSize = 64, edgeSize = 8, insets = {left = 2, right = 2, top = 2, bottom = 2}}
Tercio@11 1489
Tercio@11 1490 local on_enter_feedback = function (self)
Tercio@11 1491 self:SetBackdropColor (1, 1, 0, 0.5)
Tercio@11 1492 end
Tercio@11 1493 local on_leave_feedback = function (self)
Tercio@11 1494 self:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 1495 end
Tercio@11 1496
Tercio@11 1497 local on_click_feedback = function (self)
Tercio@11 1498
Tercio@11 1499 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 1500
Tercio@11 1501 if (not feedback_link_textbox) then
Tercio@11 1502 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 1503 editbox:SetAutoFocus (false)
Tercio@11 1504 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1505 editbox.text = editbox.link
Tercio@11 1506 editbox:HighlightText()
Tercio@11 1507 end)
Tercio@11 1508 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1509 editbox:Hide()
Tercio@11 1510 end)
Tercio@11 1511 editbox:SetHook ("OnChar", function()
Tercio@11 1512 editbox.text = editbox.link
Tercio@11 1513 editbox:HighlightText()
Tercio@11 1514 end)
Tercio@11 1515 editbox.text = ""
Tercio@11 1516
Tercio@11 1517 DF.feedback_link_textbox = editbox
Tercio@11 1518 feedback_link_textbox = editbox
Tercio@11 1519 end
Tercio@11 1520
Tercio@11 1521 feedback_link_textbox.link = self.link
Tercio@11 1522 feedback_link_textbox.text = self.link
Tercio@11 1523 feedback_link_textbox:Show()
Tercio@11 1524
Tercio@11 1525 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 1526
Tercio@11 1527 feedback_link_textbox:HighlightText()
Tercio@11 1528
Tercio@11 1529 feedback_link_textbox:SetFocus()
Tercio@11 1530 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1531 end
Tercio@11 1532
Tercio@11 1533 local feedback_get_fb_line = function (self)
Tercio@11 1534
Tercio@11 1535 local line = self.feedback_lines [self.next_feedback]
Tercio@11 1536 if (not line) then
Tercio@11 1537 line = CreateFrame ("frame", "AddonFeedbackPanelFB" .. self.next_feedback, self)
Tercio@11 1538 line:SetBackdrop (backdrop_fb_line)
Tercio@11 1539 line:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 1540 line:SetSize (390, 42)
Tercio@11 1541 line:SetPoint ("topleft", self.feedback_anchor, "bottomleft", 0, -5 + ((self.next_feedback-1) * 46 * -1))
Tercio@11 1542 line:SetScript ("OnEnter", on_enter_feedback)
Tercio@11 1543 line:SetScript ("OnLeave", on_leave_feedback)
Tercio@11 1544 line:SetScript ("OnMouseUp", on_click_feedback)
Tercio@11 1545
Tercio@11 1546 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 1547 line.icon:SetSize (90, 36)
Tercio@11 1548
Tercio@11 1549 line.desc = line:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 1550
Tercio@11 1551 line.icon:SetPoint ("left", line, "left", 5, 0)
Tercio@11 1552 line.desc:SetPoint ("left", line.icon, "right", 5, 0)
Tercio@11 1553
Tercio@11 1554 local arrow = line:CreateTexture (nil, "overlay")
Tercio@11 1555 arrow:SetTexture ([[Interface\Buttons\JumpUpArrow]])
Tercio@11 1556 arrow:SetRotation (-1.55)
Tercio@11 1557 arrow:SetPoint ("right", line, "right", -5, 0)
Tercio@11 1558
Tercio@11 1559 self.feedback_lines [self.next_feedback] = line
Tercio@11 1560 end
Tercio@11 1561
Tercio@11 1562 self.next_feedback = self.next_feedback + 1
Tercio@11 1563
Tercio@11 1564 return line
Tercio@11 1565 end
Tercio@11 1566
Tercio@11 1567 local on_click_feedback = function (self)
Tercio@11 1568
Tercio@11 1569 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 1570
Tercio@11 1571 if (not feedback_link_textbox) then
Tercio@11 1572 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 1573 editbox:SetAutoFocus (false)
Tercio@11 1574 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1575 editbox.text = editbox.link
Tercio@11 1576 editbox:HighlightText()
Tercio@11 1577 end)
Tercio@11 1578 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1579 editbox:Hide()
Tercio@11 1580 end)
Tercio@11 1581 editbox:SetHook ("OnChar", function()
Tercio@11 1582 editbox.text = editbox.link
Tercio@11 1583 editbox:HighlightText()
Tercio@11 1584 end)
Tercio@11 1585 editbox.text = ""
Tercio@11 1586
Tercio@11 1587 DF.feedback_link_textbox = editbox
Tercio@11 1588 feedback_link_textbox = editbox
Tercio@11 1589 end
Tercio@11 1590
Tercio@11 1591 feedback_link_textbox.link = self.link
Tercio@11 1592 feedback_link_textbox.text = self.link
Tercio@11 1593 feedback_link_textbox:Show()
Tercio@11 1594
Tercio@11 1595 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 1596
Tercio@11 1597 feedback_link_textbox:HighlightText()
Tercio@11 1598
Tercio@11 1599 feedback_link_textbox:SetFocus()
Tercio@11 1600 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1601 end
Tercio@11 1602
Tercio@11 1603 local on_enter_addon = function (self)
Tercio@11 1604 if (self.tooltip) then
Tercio@11 1605 GameCooltip2:Preset (2)
Tercio@11 1606 GameCooltip2:AddLine ("|cFFFFFF00" .. self.name .. "|r")
Tercio@11 1607 GameCooltip2:AddLine ("")
Tercio@11 1608 GameCooltip2:AddLine (self.tooltip)
Tercio@11 1609 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 1610 end
Tercio@11 1611 self.icon:SetBlendMode ("ADD")
Tercio@11 1612 end
Tercio@11 1613 local on_leave_addon = function (self)
Tercio@11 1614 if (self.tooltip) then
Tercio@11 1615 GameCooltip2:Hide()
Tercio@11 1616 end
Tercio@11 1617 self.icon:SetBlendMode ("BLEND")
Tercio@11 1618 end
Tercio@11 1619 local on_click_addon = function (self)
Tercio@11 1620 local addon_link_textbox = DF.addon_link_textbox
Tercio@11 1621
Tercio@11 1622 if (not addon_link_textbox) then
Tercio@11 1623 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 128, 64)
Tercio@11 1624 editbox:SetAutoFocus (false)
Tercio@11 1625 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 1626 editbox.text = editbox.link
Tercio@11 1627 editbox:HighlightText()
Tercio@11 1628 end)
Tercio@11 1629 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 1630 editbox:Hide()
Tercio@11 1631 end)
Tercio@11 1632 editbox:SetHook ("OnChar", function()
Tercio@11 1633 editbox.text = editbox.link
Tercio@11 1634 editbox:HighlightText()
Tercio@11 1635 end)
Tercio@11 1636 editbox.text = ""
Tercio@11 1637
Tercio@11 1638 DF.addon_link_textbox = editbox
Tercio@11 1639 addon_link_textbox = editbox
Tercio@11 1640 end
Tercio@11 1641
Tercio@11 1642 addon_link_textbox.link = self.link
Tercio@11 1643 addon_link_textbox.text = self.link
Tercio@11 1644 addon_link_textbox:Show()
Tercio@11 1645
Tercio@11 1646 addon_link_textbox:SetPoint ("topleft", self.icon, "topleft", 0, 0)
Tercio@11 1647
Tercio@11 1648 addon_link_textbox:HighlightText()
Tercio@11 1649
Tercio@11 1650 addon_link_textbox:SetFocus()
Tercio@11 1651 addon_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 1652 end
Tercio@11 1653
Tercio@11 1654 local feedback_get_addons_line = function (self)
Tercio@11 1655 local line = self.addons_lines [self.next_addons]
Tercio@11 1656 if (not line) then
Tercio@11 1657
Tercio@11 1658 line = CreateFrame ("frame", "AddonFeedbackPanelSA" .. self.next_addons, self)
Tercio@11 1659 line:SetSize (128, 64)
Tercio@11 1660
Tercio@11 1661 if (self.next_addons == 1) then
Tercio@11 1662 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5)
Tercio@11 1663 elseif (self.next_addons_line_break == self.next_addons) then
Tercio@11 1664 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5 + floor (self.next_addons_line_break/3) * 66 * -1)
Tercio@11 1665 self.next_addons_line_break = self.next_addons_line_break + 3
Tercio@11 1666 else
Tercio@11 1667 local previous = self.addons_lines [self.next_addons - 1]
Tercio@11 1668 line:SetPoint ("topleft", previous, "topright", 2, 0)
Tercio@11 1669 end
Tercio@11 1670
Tercio@11 1671 line:SetScript ("OnEnter", on_enter_addon)
Tercio@11 1672 line:SetScript ("OnLeave", on_leave_addon)
Tercio@11 1673 line:SetScript ("OnMouseUp", on_click_addon)
Tercio@11 1674
Tercio@11 1675 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 1676 line.icon:SetSize (128, 64)
Tercio@11 1677
Tercio@11 1678 line.icon:SetPoint ("topleft", line, "topleft", 0, 0)
Tercio@11 1679
Tercio@11 1680 self.addons_lines [self.next_addons] = line
Tercio@11 1681 end
Tercio@11 1682
Tercio@11 1683 self.next_addons = self.next_addons + 1
Tercio@11 1684
Tercio@11 1685 return line
Tercio@11 1686 end
Tercio@11 1687
Tercio@11 1688 local default_coords = {0, 1, 0, 1}
Tercio@11 1689 local feedback_add_fb = function (self, table)
Tercio@11 1690 local line = self:GetFeedbackLine()
Tercio@11 1691 line.icon:SetTexture (table.icon)
Tercio@11 1692 line.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 1693 line.desc:SetText (table.desc)
Tercio@11 1694 line.link = table.link
Tercio@11 1695 line:Show()
Tercio@11 1696 end
Tercio@11 1697
Tercio@11 1698 local feedback_add_addon = function (self, table)
Tercio@11 1699 local block = self:GetAddonsLine()
Tercio@11 1700 block.icon:SetTexture (table.icon)
Tercio@11 1701 block.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 1702 block.link = table.link
Tercio@11 1703 block.tooltip = table.desc
Tercio@11 1704 block.name = table.name
Tercio@11 1705 block:Show()
Tercio@11 1706 end
Tercio@11 1707
Tercio@11 1708 local feedback_hide_all = function (self)
Tercio@11 1709 self.next_feedback = 1
Tercio@11 1710 self.next_addons = 1
Tercio@11 1711
Tercio@11 1712 for index, line in ipairs (self.feedback_lines) do
Tercio@11 1713 line:Hide()
Tercio@11 1714 end
Tercio@11 1715
Tercio@11 1716 for index, line in ipairs (self.addons_lines) do
Tercio@11 1717 line:Hide()
Tercio@11 1718 end
Tercio@11 1719 end
Tercio@11 1720
Tercio@11 1721 -- feedback_methods = { { icon = icon path, desc = description, link = url}}
Tercio@11 1722 function DF:ShowFeedbackPanel (addon_name, version, feedback_methods, more_addons)
Tercio@11 1723
Tercio@11 1724 local f = _G.AddonFeedbackPanel
Tercio@11 1725
Tercio@11 1726 if (not f) then
Tercio@11 1727 f = DF:Create1PxPanel (UIParent, 400, 100, addon_name .. " Feedback", "AddonFeedbackPanel", nil)
Tercio@11 1728 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 1729 f:SetPoint ("center", UIParent, "center")
Tercio@11 1730 f:SetBackdropColor (0, 0, 0, 0.8)
Tercio@11 1731 f.feedback_lines = {}
Tercio@11 1732 f.addons_lines = {}
Tercio@11 1733 f.next_feedback = 1
Tercio@11 1734 f.next_addons = 1
Tercio@11 1735 f.next_addons_line_break = 4
Tercio@11 1736
Tercio@11 1737 local feedback_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1738 feedback_anchor:SetText ("Feedback:")
Tercio@11 1739 feedback_anchor:SetPoint ("topleft", f, "topleft", 5, -30)
Tercio@11 1740 f.feedback_anchor = feedback_anchor
Tercio@11 1741 local excla_text = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1742 excla_text:SetText ("click and copy the link")
Tercio@11 1743 excla_text:SetPoint ("topright", f, "topright", -5, -30)
Tercio@11 1744 excla_text:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 1745
Tercio@11 1746 local addons_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1747 addons_anchor:SetText ("AddOns From the Same Author:")
Tercio@11 1748 f.addons_anchor = addons_anchor
Tercio@11 1749 local excla_text2 = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 1750 excla_text2:SetText ("click and copy the link")
Tercio@11 1751 excla_text2:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 1752 f.excla_text2 = excla_text2
Tercio@11 1753
Tercio@11 1754 f.GetFeedbackLine = feedback_get_fb_line
Tercio@11 1755 f.GetAddonsLine = feedback_get_addons_line
Tercio@11 1756 f.AddFeedbackMethod = feedback_add_fb
Tercio@11 1757 f.AddOtherAddon = feedback_add_addon
Tercio@11 1758 f.HideAll = feedback_hide_all
Tercio@11 1759
Tercio@11 1760 DF:SetFontSize (f.Title, 14)
Tercio@11 1761
Tercio@11 1762 end
Tercio@11 1763
Tercio@11 1764 f:HideAll()
Tercio@11 1765 f:SetTitle (addon_name)
Tercio@11 1766
Tercio@11 1767 for index, feedback in ipairs (feedback_methods) do
Tercio@11 1768 f:AddFeedbackMethod (feedback)
Tercio@11 1769 end
Tercio@11 1770
Tercio@11 1771 f.addons_anchor:SetPoint ("topleft", f, "topleft", 5, f.next_feedback * 50 * -1)
Tercio@11 1772 f.excla_text2:SetPoint ("topright", f, "topright", -5, f.next_feedback * 50 * -1)
Tercio@11 1773
Tercio@11 1774 for index, addon in ipairs (more_addons) do
Tercio@11 1775 f:AddOtherAddon (addon)
Tercio@11 1776 end
Tercio@11 1777
Tercio@11 1778 f:SetHeight (80 + ((f.next_feedback-1) * 50) + (ceil ((f.next_addons-1)/3) * 66))
Tercio@11 1779
Tercio@11 1780 f:Show()
Tercio@11 1781
Tercio@11 1782 return true
Tercio@11 1783 end
Tercio@11 1784
Tercio@11 1785
Tercio@11 1786 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 1787 --> chart panel -- ~chart
Tercio@11 1788
Tercio@11 1789 local chart_panel_backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
Tercio@11 1790 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}}
Tercio@11 1791
Tercio@11 1792 local chart_panel_align_timelabels = function (self, elapsed_time)
Tercio@11 1793
Tercio@11 1794 self.TimeScale = elapsed_time
Tercio@11 1795
Tercio@11 1796 local linha = self.TimeLabels [17]
Tercio@11 1797 local minutos, segundos = math.floor (elapsed_time / 60), math.floor (elapsed_time % 60)
Tercio@11 1798 if (segundos < 10) then
Tercio@11 1799 segundos = "0" .. segundos
Tercio@11 1800 end
Tercio@11 1801
Tercio@11 1802 if (minutos > 0) then
Tercio@11 1803 if (minutos < 10) then
Tercio@11 1804 minutos = "0" .. minutos
Tercio@11 1805 end
Tercio@11 1806 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 1807 else
Tercio@11 1808 linha:SetText ("00:" .. segundos)
Tercio@11 1809 end
Tercio@11 1810
Tercio@11 1811 local time_div = elapsed_time / 16 --786 -- 49.125
Tercio@11 1812
Tercio@11 1813 for i = 2, 16 do
Tercio@11 1814
Tercio@11 1815 local linha = self.TimeLabels [i]
Tercio@11 1816
Tercio@11 1817 local this_time = time_div * (i-1)
Tercio@11 1818 local minutos, segundos = math.floor (this_time / 60), math.floor (this_time % 60)
Tercio@11 1819
Tercio@11 1820 if (segundos < 10) then
Tercio@11 1821 segundos = "0" .. segundos
Tercio@11 1822 end
Tercio@11 1823
Tercio@11 1824 if (minutos > 0) then
Tercio@11 1825 if (minutos < 10) then
Tercio@11 1826 minutos = "0" .. minutos
Tercio@11 1827 end
Tercio@11 1828 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 1829 else
Tercio@11 1830 linha:SetText ("00:" .. segundos)
Tercio@11 1831 end
Tercio@11 1832
Tercio@11 1833 end
Tercio@11 1834
Tercio@11 1835 end
Tercio@11 1836
Tercio@11 1837 local chart_panel_set_scale = function (self, amt, func, text)
Tercio@11 1838 if (type (amt) ~= "number") then
Tercio@11 1839 return
Tercio@11 1840 end
Tercio@11 1841
Tercio@11 1842 local piece = amt / 1000 / 8
Tercio@11 1843
Tercio@11 1844 for i = 1, 8 do
Tercio@11 1845 if (func) then
Tercio@11 1846 self ["dpsamt" .. math.abs (i-9)]:SetText ( func (piece*i) .. (text or ""))
Tercio@11 1847 else
Tercio@11 1848 if (piece*i > 1) then
Tercio@11 1849 self ["dpsamt" .. math.abs (i-9)]:SetText ( floor (piece*i) .. (text or ""))
Tercio@11 1850 else
Tercio@11 1851 self ["dpsamt" .. math.abs (i-9)]:SetText ( format ("%.3f", piece*i) .. (text or ""))
Tercio@11 1852 end
Tercio@11 1853 end
Tercio@11 1854 end
Tercio@11 1855 end
Tercio@11 1856
Tercio@11 1857 local chart_panel_can_move = function (self, can)
Tercio@11 1858 self.can_move = can
Tercio@11 1859 end
Tercio@11 1860
Tercio@11 1861 local chart_panel_overlay_reset = function (self)
Tercio@11 1862 self.OverlaysAmount = 1
Tercio@11 1863 for index, pack in ipairs (self.Overlays) do
Tercio@11 1864 for index2, texture in ipairs (pack) do
Tercio@11 1865 texture:Hide()
Tercio@11 1866 end
Tercio@11 1867 end
Tercio@11 1868 end
Tercio@11 1869
Tercio@11 1870 local chart_panel_reset = function (self)
Tercio@11 1871
Tercio@11 1872 self.Graphic:ResetData()
Tercio@11 1873 self.Graphic.max_value = 0
Tercio@11 1874
Tercio@11 1875 self.TimeScale = nil
Tercio@11 1876 self.BoxLabelsAmount = 1
Tercio@11 1877 table.wipe (self.GData)
Tercio@11 1878 table.wipe (self.OData)
Tercio@11 1879
Tercio@11 1880 for index, box in ipairs (self.BoxLabels) do
Tercio@11 1881 box.check:Hide()
Tercio@11 1882 box.button:Hide()
Tercio@11 1883 box.box:Hide()
Tercio@11 1884 box.text:Hide()
Tercio@11 1885 box.border:Hide()
Tercio@11 1886 box.showing = false
Tercio@11 1887 end
Tercio@11 1888
Tercio@11 1889 chart_panel_overlay_reset (self)
Tercio@11 1890 end
Tercio@11 1891
Tercio@11 1892 local chart_panel_enable_line = function (f, thisbox)
Tercio@11 1893
Tercio@11 1894 local index = thisbox.index
Tercio@11 1895 local type = thisbox.type
Tercio@11 1896
Tercio@11 1897 if (thisbox.enabled) then
Tercio@11 1898 --disable
Tercio@11 1899 thisbox.check:Hide()
Tercio@11 1900 thisbox.enabled = false
Tercio@11 1901 else
Tercio@11 1902 --enable
Tercio@11 1903 thisbox.check:Show()
Tercio@11 1904 thisbox.enabled = true
Tercio@11 1905 end
Tercio@11 1906
Tercio@11 1907 if (type == "graphic") then
Tercio@11 1908
Tercio@11 1909 f.Graphic:ResetData()
Tercio@11 1910 f.Graphic.max_value = 0
Tercio@11 1911
Tercio@11 1912 local max = 0
Tercio@11 1913 local max_time = 0
Tercio@11 1914
Tercio@11 1915 for index, box in ipairs (f.BoxLabels) do
Tercio@11 1916 if (box.type == type and box.showing and box.enabled) then
Tercio@11 1917 local data = f.GData [index]
Tercio@11 1918
Tercio@11 1919 f.Graphic:AddDataSeries (data[1], data[2], nil, data[3])
Tercio@11 1920
Tercio@11 1921 if (data[4] > max) then
Tercio@11 1922 max = data[4]
Tercio@11 1923 end
Tercio@11 1924 if (data [5] > max_time) then
Tercio@11 1925 max_time = data [5]
Tercio@11 1926 end
Tercio@11 1927 end
Tercio@11 1928 end
Tercio@11 1929
Tercio@11 1930 f:SetScale (max)
Tercio@11 1931 f:SetTime (max_time)
Tercio@11 1932
Tercio@11 1933 elseif (type == "overlay") then
Tercio@11 1934
Tercio@11 1935 chart_panel_overlay_reset (f)
Tercio@11 1936
Tercio@11 1937 for index, box in ipairs (f.BoxLabels) do
Tercio@11 1938 if (box.type == type and box.showing and box.enabled) then
Tercio@11 1939
Tercio@11 1940 f:AddOverlay (box.index)
Tercio@11 1941
Tercio@11 1942 end
Tercio@11 1943 end
Tercio@11 1944
Tercio@11 1945 end
Tercio@11 1946 end
Tercio@11 1947
Tercio@11 1948 local create_box = function (self, next_box)
Tercio@11 1949
Tercio@11 1950 local thisbox = {}
Tercio@11 1951 self.BoxLabels [next_box] = thisbox
Tercio@11 1952
Tercio@11 1953 local box = DF:NewImage (self.Graphic, nil, 16, 16, "border")
Tercio@11 1954
Tercio@11 1955 local text = DF:NewLabel (self.Graphic)
Tercio@11 1956
Tercio@11 1957 local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork")
Tercio@11 1958 border:SetPoint ("center", box, "center", -3, -4)
Tercio@11 1959 border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]])
Tercio@11 1960
Tercio@11 1961 local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay")
Tercio@11 1962 checktexture:SetPoint ("center", box, "center", -1, -1)
Tercio@11 1963 checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
Tercio@11 1964
Tercio@11 1965 thisbox.box = box
Tercio@11 1966 thisbox.text = text
Tercio@11 1967 thisbox.border = border
Tercio@11 1968 thisbox.check = checktexture
Tercio@11 1969 thisbox.enabled = true
Tercio@11 1970
Tercio@11 1971 local button = CreateFrame ("button", nil, self.Graphic)
Tercio@11 1972 button:SetSize (20, 20)
Tercio@11 1973 button:SetScript ("OnClick", function()
Tercio@11 1974 chart_panel_enable_line (self, thisbox)
Tercio@11 1975 end)
Tercio@11 1976 button:SetPoint ("center", box, "center")
Tercio@11 1977
Tercio@11 1978 thisbox.button = button
Tercio@11 1979
Tercio@11 1980 thisbox.box:SetPoint ("right", text, "left", -4, 0)
Tercio@11 1981
Tercio@11 1982 if (next_box == 1) then
Tercio@11 1983 thisbox.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 1984 else
Tercio@11 1985 thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -7, 0)
Tercio@11 1986 end
Tercio@11 1987
Tercio@11 1988 return thisbox
Tercio@11 1989
Tercio@11 1990 end
Tercio@11 1991
Tercio@11 1992 local realign_labels = function (self)
Tercio@11 1993
Tercio@11 1994 local width = self:GetWidth() - 108
Tercio@11 1995
Tercio@11 1996 local first_box = self.BoxLabels [1]
Tercio@11 1997 first_box.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 1998
Tercio@11 1999 local line_width = first_box.text:GetStringWidth() + 26
Tercio@11 2000
Tercio@11 2001 for i = 2, #self.BoxLabels do
Tercio@11 2002
Tercio@11 2003 local box = self.BoxLabels [i]
Tercio@11 2004
Tercio@11 2005 if (box.box:IsShown()) then
Tercio@11 2006
Tercio@11 2007 line_width = line_width + box.text:GetStringWidth() + 26
Tercio@11 2008
Tercio@11 2009 if (line_width > width) then
Tercio@11 2010 line_width = box.text:GetStringWidth() + 26
Tercio@11 2011 box.text:SetPoint ("topright", self, "topright", -35, -40)
Tercio@11 2012 else
Tercio@11 2013 box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -7, 0)
Tercio@11 2014 end
Tercio@11 2015 else
Tercio@11 2016 break
Tercio@11 2017 end
Tercio@11 2018 end
Tercio@11 2019
Tercio@11 2020 end
Tercio@11 2021
Tercio@11 2022 local chart_panel_add_label = function (self, color, name, type, number)
Tercio@11 2023
Tercio@11 2024 local next_box = self.BoxLabelsAmount
Tercio@11 2025 local thisbox = self.BoxLabels [next_box]
Tercio@11 2026
Tercio@11 2027 if (not thisbox) then
Tercio@11 2028 thisbox = create_box (self, next_box)
Tercio@11 2029 end
Tercio@11 2030
Tercio@11 2031 self.BoxLabelsAmount = self.BoxLabelsAmount + 1
Tercio@11 2032
Tercio@11 2033 thisbox.type = type
Tercio@11 2034 thisbox.index = number
Tercio@11 2035
Tercio@11 2036 thisbox.box:SetTexture (unpack (color))
Tercio@11 2037 thisbox.text:SetText (name)
Tercio@11 2038
Tercio@11 2039 thisbox.check:Show()
Tercio@11 2040 thisbox.button:Show()
Tercio@11 2041 thisbox.border:Show()
Tercio@11 2042 thisbox.box:Show()
Tercio@11 2043 thisbox.text:Show()
Tercio@11 2044
Tercio@11 2045 thisbox.showing = true
Tercio@11 2046 thisbox.enabled = true
Tercio@11 2047
Tercio@11 2048 realign_labels (self)
Tercio@11 2049
Tercio@11 2050 end
Tercio@11 2051
Tercio@11 2052 local line_default_color = {1, 1, 1}
Tercio@11 2053 local draw_overlay = function (self, this_overlay, overlayData, color)
Tercio@11 2054
Tercio@11 2055 local pixel = self.Graphic:GetWidth() / self.TimeScale
Tercio@11 2056 local index = 1
Tercio@11 2057 local r, g, b = unpack (color)
Tercio@11 2058
Tercio@11 2059 for i = 1, #overlayData, 2 do
Tercio@11 2060 local aura_start = overlayData [i]
Tercio@11 2061 local aura_end = overlayData [i+1]
Tercio@11 2062
Tercio@11 2063 local this_block = this_overlay [index]
Tercio@11 2064 if (not this_block) then
Tercio@11 2065 this_block = self.Graphic:CreateTexture (nil, "border")
Tercio@11 2066 tinsert (this_overlay, this_block)
Tercio@11 2067 end
Tercio@11 2068 this_block:SetHeight (self.Graphic:GetHeight())
Tercio@11 2069
Tercio@11 2070 this_block:SetPoint ("left", self.Graphic, "left", pixel * aura_start, 0)
Tercio@11 2071 if (aura_end) then
Tercio@11 2072 this_block:SetWidth ((aura_end-aura_start)*pixel)
Tercio@11 2073 else
Tercio@11 2074 --malformed table
Tercio@11 2075 this_block:SetWidth (pixel*5)
Tercio@11 2076 end
Tercio@11 2077
Tercio@11 2078 this_block:SetTexture (r, g, b, 0.25)
Tercio@11 2079 this_block:Show()
Tercio@11 2080
Tercio@11 2081 index = index + 1
Tercio@11 2082 end
Tercio@11 2083
Tercio@11 2084 end
Tercio@11 2085
Tercio@11 2086 local chart_panel_add_overlay = function (self, overlayData, color, name, icon)
Tercio@11 2087
Tercio@11 2088 if (not self.TimeScale) then
Tercio@11 2089 error ("Use SetTime (time) before adding an overlay.")
Tercio@11 2090 end
Tercio@11 2091
Tercio@11 2092 if (type (overlayData) == "number") then
Tercio@11 2093 local overlay_index = overlayData
Tercio@11 2094 draw_overlay (self, self.Overlays [self.OverlaysAmount], self.OData [overlay_index][1], self.OData [overlay_index][2])
Tercio@11 2095 else
Tercio@11 2096 local this_overlay = self.Overlays [self.OverlaysAmount]
Tercio@11 2097 if (not this_overlay) then
Tercio@11 2098 this_overlay = {}
Tercio@11 2099 tinsert (self.Overlays, this_overlay)
Tercio@11 2100 end
Tercio@11 2101
Tercio@11 2102 draw_overlay (self, this_overlay, overlayData, color)
Tercio@11 2103
Tercio@11 2104 tinsert (self.OData, {overlayData, color or line_default_color})
Tercio@11 2105 if (name) then
Tercio@11 2106 self:AddLabel (color or line_default_color, name, "overlay", #self.OData)
Tercio@11 2107 end
Tercio@11 2108 end
Tercio@11 2109
Tercio@11 2110 self.OverlaysAmount = self.OverlaysAmount + 1
Tercio@11 2111 end
Tercio@11 2112
Tercio@11 2113 local SMA_table = {}
Tercio@11 2114 local SMA_max = 0
Tercio@11 2115 local reset_SMA = function()
Tercio@11 2116 table.wipe (SMA_table)
Tercio@11 2117 SMA_max = 0
Tercio@11 2118 end
Tercio@11 2119
Tercio@11 2120 local calc_SMA
Tercio@11 2121 calc_SMA = function (a, b, ...)
Tercio@11 2122 if (b) then
Tercio@11 2123 return calc_SMA (a + b, ...)
Tercio@11 2124 else
Tercio@11 2125 return a
Tercio@11 2126 end
Tercio@11 2127 end
Tercio@11 2128
Tercio@11 2129 local do_SMA = function (value, max_value)
Tercio@11 2130
Tercio@11 2131 if (#SMA_table == 10) then
Tercio@11 2132 tremove (SMA_table, 1)
Tercio@11 2133 end
Tercio@11 2134
Tercio@11 2135 SMA_table [#SMA_table + 1] = value
Tercio@11 2136
Tercio@11 2137 local new_value = calc_SMA (unpack (SMA_table)) / #SMA_table
Tercio@11 2138
Tercio@11 2139 if (new_value > SMA_max) then
Tercio@11 2140 SMA_max = new_value
Tercio@11 2141 return new_value, SMA_max
Tercio@11 2142 else
Tercio@11 2143 return new_value
Tercio@11 2144 end
Tercio@11 2145
Tercio@11 2146 end
Tercio@11 2147
Tercio@11 2148 local chart_panel_add_data = function (self, graphicData, color, name, elapsed_time, lineTexture, smoothLevel, firstIndex)
Tercio@11 2149
Tercio@11 2150 local f = self
Tercio@11 2151 self = self.Graphic
Tercio@11 2152
Tercio@11 2153 local _data = {}
Tercio@11 2154 local max_value = graphicData.max_value
Tercio@11 2155 local amount = #graphicData
Tercio@11 2156
Tercio@11 2157 local scaleW = 1/self:GetWidth()
Tercio@11 2158
Tercio@11 2159 local content = graphicData
Tercio@11 2160 tinsert (content, 1, 0)
Tercio@11 2161 tinsert (content, 1, 0)
Tercio@11 2162 tinsert (content, #content+1, 0)
Tercio@11 2163 tinsert (content, #content+1, 0)
Tercio@11 2164
Tercio@11 2165 local _i = 3
Tercio@11 2166
Tercio@11 2167 local graphMaxDps = math.max (self.max_value, max_value)
Tercio@11 2168
Tercio@11 2169 if (not smoothLevel) then
Tercio@11 2170 while (_i <= #content-2) do
Tercio@11 2171 local v = (content[_i-2]+content[_i-1]+content[_i]+content[_i+1]+content[_i+2])/5 --> normalize
Tercio@11 2172 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 2173 _i = _i + 1
Tercio@11 2174 end
Tercio@11 2175
Tercio@11 2176 elseif (smoothLevel == "SHORT") then
Tercio@11 2177 while (_i <= #content-2) do
Tercio@11 2178 local value = (content[_i] + content[_i+1]) / 2
Tercio@11 2179 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2180 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2181 _i = _i + 2
Tercio@11 2182 end
Tercio@11 2183
Tercio@11 2184 elseif (smoothLevel == "SMA") then
Tercio@11 2185 reset_SMA()
Tercio@11 2186 while (_i <= #content-2) do
Tercio@11 2187 local value, is_new_max_value = do_SMA (content[_i], max_value)
Tercio@11 2188 if (is_new_max_value) then
Tercio@11 2189 max_value = is_new_max_value
Tercio@11 2190 end
Tercio@11 2191 _data [#_data+1] = {scaleW*(_i-2), value} --> x and y coords
Tercio@11 2192 _i = _i + 1
Tercio@11 2193 end
Tercio@11 2194
Tercio@11 2195 elseif (smoothLevel == -1) then
Tercio@11 2196 while (_i <= #content-2) do
Tercio@11 2197 local current = content[_i]
Tercio@11 2198
Tercio@11 2199 local minus_2 = content[_i-2] * 0.6
Tercio@11 2200 local minus_1 = content[_i-1] * 0.8
Tercio@11 2201 local plus_1 = content[_i+1] * 0.8
Tercio@11 2202 local plus_2 = content[_i+2] * 0.6
Tercio@11 2203
Tercio@11 2204 local v = (current + minus_2 + minus_1 + plus_1 + plus_2)/5 --> normalize
Tercio@11 2205 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 2206 _i = _i + 1
Tercio@11 2207 end
Tercio@11 2208
Tercio@11 2209 elseif (smoothLevel == 1) then
Tercio@11 2210 _i = 2
Tercio@11 2211 while (_i <= #content-1) do
Tercio@11 2212 local v = (content[_i-1]+content[_i]+content[_i+1])/3 --> normalize
Tercio@11 2213 _data [#_data+1] = {scaleW*(_i-1), v/graphMaxDps} --> x and y coords
Tercio@11 2214 _i = _i + 1
Tercio@11 2215 end
Tercio@11 2216
Tercio@11 2217 elseif (smoothLevel == 2) then
Tercio@11 2218 _i = 1
Tercio@11 2219 while (_i <= #content) do
Tercio@11 2220 local v = content[_i] --> do not normalize
Tercio@11 2221 _data [#_data+1] = {scaleW*(_i), v/graphMaxDps} --> x and y coords
Tercio@11 2222 _i = _i + 1
Tercio@11 2223 end
Tercio@11 2224
Tercio@11 2225 end
Tercio@11 2226
Tercio@11 2227 tremove (content, 1)
Tercio@11 2228 tremove (content, 1)
Tercio@11 2229 tremove (content, #graphicData)
Tercio@11 2230 tremove (content, #graphicData)
Tercio@11 2231
Tercio@11 2232 if (max_value > self.max_value) then
Tercio@11 2233 --> normalize previous data
Tercio@11 2234 if (self.max_value > 0) then
Tercio@11 2235 local normalizePercent = self.max_value / max_value
Tercio@11 2236 for dataIndex, Data in ipairs (self.Data) do
Tercio@11 2237 local Points = Data.Points
Tercio@11 2238 for i = 1, #Points do
Tercio@11 2239 Points[i][2] = Points[i][2]*normalizePercent
Tercio@11 2240 end
Tercio@11 2241 end
Tercio@11 2242 end
Tercio@11 2243
Tercio@11 2244 self.max_value = max_value
Tercio@11 2245 f:SetScale (max_value)
Tercio@11 2246
Tercio@11 2247 end
Tercio@11 2248
Tercio@11 2249 tinsert (f.GData, {_data, color or line_default_color, lineTexture, max_value, elapsed_time})
Tercio@11 2250 if (name) then
Tercio@11 2251 f:AddLabel (color or line_default_color, name, "graphic", #f.GData)
Tercio@11 2252 end
Tercio@11 2253
Tercio@11 2254 if (firstIndex) then
Tercio@11 2255 if (lineTexture) then
Tercio@11 2256 if (not lineTexture:find ("\\") and not lineTexture:find ("//")) then
Tercio@11 2257 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)LibGraph%-2%.0%.lua")
Tercio@11 2258 if path then
Tercio@11 2259 lineTexture = "Interface\\AddOns\\" .. path .. lineTexture
Tercio@11 2260 else
Tercio@11 2261 lineTexture = nil
Tercio@11 2262 end
Tercio@11 2263 end
Tercio@11 2264 end
Tercio@11 2265
Tercio@11 2266 table.insert (self.Data, 1, {Points = _data, Color = color or line_default_color, lineTexture = lineTexture, ElapsedTime = elapsed_time})
Tercio@11 2267 self.NeedsUpdate = true
Tercio@11 2268 else
Tercio@11 2269 self:AddDataSeries (_data, color or line_default_color, nil, lineTexture)
Tercio@11 2270 self.Data [#self.Data].ElapsedTime = elapsed_time
Tercio@11 2271 end
Tercio@11 2272
Tercio@11 2273 local max_time = 0
Tercio@11 2274 for _, data in ipairs (self.Data) do
Tercio@11 2275 if (data.ElapsedTime > max_time) then
Tercio@11 2276 max_time = data.ElapsedTime
Tercio@11 2277 end
Tercio@11 2278 end
Tercio@11 2279
Tercio@11 2280 f:SetTime (max_time)
Tercio@11 2281
Tercio@11 2282 end
Tercio@11 2283
Tercio@11 2284 local chart_panel_onresize = function (self)
Tercio@11 2285 local width, height = self:GetSize()
Tercio@11 2286 local spacement = width - 78 - 60
Tercio@11 2287 spacement = spacement / 16
Tercio@11 2288
Tercio@11 2289 for i = 1, 17 do
Tercio@11 2290 local label = self.TimeLabels [i]
Tercio@11 2291 label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), 13)
Tercio@11 2292 label.line:SetHeight (height - 45)
Tercio@11 2293 end
Tercio@11 2294
Tercio@11 2295 local spacement = (self.Graphic:GetHeight()) / 8
Tercio@11 2296 for i = 1, 8 do
Tercio@11 2297 self ["dpsamt"..i]:SetPoint ("TOPLEFT", self, "TOPLEFT", 27, -25 + (-(spacement* (i-1))) )
Tercio@11 2298 self ["dpsamt"..i].line:SetWidth (width-20)
Tercio@11 2299 end
Tercio@11 2300
Tercio@11 2301 self.Graphic:SetSize (width - 135, height - 67)
Tercio@11 2302 self.Graphic:SetPoint ("topleft", self, "topleft", 108, -35)
Tercio@11 2303 end
Tercio@11 2304
Tercio@11 2305 local chart_panel_vlines_on = function (self)
Tercio@11 2306 for i = 1, 17 do
Tercio@11 2307 local label = self.TimeLabels [i]
Tercio@11 2308 label.line:Show()
Tercio@11 2309 end
Tercio@11 2310 end
Tercio@11 2311
Tercio@11 2312 local chart_panel_vlines_off = function (self)
Tercio@11 2313 for i = 1, 17 do
Tercio@11 2314 local label = self.TimeLabels [i]
Tercio@11 2315 label.line:Hide()
Tercio@11 2316 end
Tercio@11 2317 end
Tercio@11 2318
Tercio@11 2319 local chart_panel_set_title = function (self, title)
Tercio@11 2320 self.chart_title.text = title
Tercio@11 2321 end
Tercio@11 2322
Tercio@11 2323 local chart_panel_mousedown = function (self, button)
Tercio@11 2324 if (button == "LeftButton" and self.can_move) then
Tercio@11 2325 if (not self.isMoving) then
Tercio@11 2326 self:StartMoving()
Tercio@11 2327 self.isMoving = true
Tercio@11 2328 end
Tercio@11 2329 elseif (button == "RightButton" and not self.no_right_click_close) then
Tercio@11 2330 if (not self.isMoving) then
Tercio@11 2331 self:Hide()
Tercio@11 2332 end
Tercio@11 2333 end
Tercio@11 2334 end
Tercio@11 2335 local chart_panel_mouseup = function (self, button)
Tercio@11 2336 if (button == "LeftButton" and self.isMoving) then
Tercio@11 2337 self:StopMovingOrSizing()
Tercio@11 2338 self.isMoving = nil
Tercio@11 2339 end
Tercio@11 2340 end
Tercio@11 2341
Tercio@11 2342 local chart_panel_hide_close_button = function (self)
Tercio@11 2343 self.CloseButton:Hide()
Tercio@11 2344 end
Tercio@11 2345
Tercio@11 2346 local chart_panel_right_click_close = function (self, value)
Tercio@11 2347 if (type (value) == "boolean") then
Tercio@11 2348 if (value) then
Tercio@11 2349 self.no_right_click_close = nil
Tercio@11 2350 else
Tercio@11 2351 self.no_right_click_close = true
Tercio@11 2352 end
Tercio@11 2353 end
Tercio@11 2354 end
Tercio@11 2355
Tercio@11 2356 function DF:CreateChartPanel (parent, w, h, name)
Tercio@11 2357
Tercio@11 2358 if (not name) then
Tercio@11 2359 name = "DFPanel" .. DF.PanelCounter
Tercio@11 2360 DF.PanelCounter = DF.PanelCounter + 1
Tercio@11 2361 end
Tercio@11 2362
Tercio@11 2363 parent = parent or UIParent
Tercio@11 2364 w = w or 800
Tercio@11 2365 h = h or 500
Tercio@11 2366
Tercio@11 2367 local f = CreateFrame ("frame", name, parent)
Tercio@11 2368 f:SetSize (w or 500, h or 400)
Tercio@11 2369 f:EnableMouse (true)
Tercio@11 2370 f:SetMovable (true)
Tercio@11 2371
Tercio@11 2372 f:SetScript ("OnMouseDown", chart_panel_mousedown)
Tercio@11 2373 f:SetScript ("OnMouseUp", chart_panel_mouseup)
Tercio@11 2374
Tercio@11 2375 f:SetBackdrop (chart_panel_backdrop)
Tercio@11 2376 f:SetBackdropColor (.3, .3, .3, .3)
Tercio@11 2377
Tercio@11 2378 local c = CreateFrame ("Button", nil, f, "UIPanelCloseButton")
Tercio@11 2379 c:SetWidth (32)
Tercio@11 2380 c:SetHeight (32)
Tercio@11 2381 c:SetPoint ("TOPRIGHT", f, "TOPRIGHT", -3, -7)
Tercio@11 2382 c:SetFrameLevel (f:GetFrameLevel()+1)
Tercio@11 2383 c:SetAlpha (0.9)
Tercio@11 2384 f.CloseButton = c
Tercio@11 2385
Tercio@11 2386 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0})
Tercio@11 2387 title:SetPoint ("topleft", f, "topleft", 110, -13)
Tercio@11 2388
Tercio@11 2389 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
Tercio@11 2390 bottom_texture:SetTexture (0, 0, 0, .6)
Tercio@11 2391 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7)
Tercio@11 2392 bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7)
Tercio@11 2393
Tercio@11 2394 f.Overlays = {}
Tercio@11 2395 f.OverlaysAmount = 1
Tercio@11 2396
Tercio@11 2397 f.BoxLabels = {}
Tercio@11 2398 f.BoxLabelsAmount = 1
Tercio@11 2399
Tercio@11 2400 f.TimeLabels = {}
Tercio@11 2401 for i = 1, 17 do
Tercio@11 2402 local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 2403 time:SetText ("00:00")
Tercio@11 2404 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), 13)
Tercio@11 2405 f.TimeLabels [i] = time
Tercio@11 2406
Tercio@11 2407 local line = f:CreateTexture (nil, "border")
Tercio@11 2408 line:SetSize (1, h-45)
Tercio@11 2409 line:SetTexture (1, 1, 1, .1)
Tercio@11 2410 line:SetPoint ("bottomleft", time, "topright", 0, -10)
Tercio@11 2411 line:Hide()
Tercio@11 2412 time.line = line
Tercio@11 2413 end
Tercio@11 2414
Tercio@11 2415 --graphic
Tercio@11 2416 local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67)
Tercio@11 2417 g:SetXAxis (-1,1)
Tercio@11 2418 g:SetYAxis (-1,1)
Tercio@11 2419 g:SetGridSpacing (false, false)
Tercio@11 2420 g:SetGridColor ({0.5,0.5,0.5,0.3})
Tercio@11 2421 g:SetAxisDrawing (false,false)
Tercio@11 2422 g:SetAxisColor({1.0,1.0,1.0,1.0})
Tercio@11 2423 g:SetAutoScale (true)
Tercio@11 2424 g:SetLineTexture ("smallline")
Tercio@11 2425 g:SetBorderSize ("right", 0.001)
Tercio@11 2426 g:SetBorderSize ("left", 0.000)
Tercio@11 2427 g:SetBorderSize ("top", 0.002)
Tercio@11 2428 g:SetBorderSize ("bottom", 0.001)
Tercio@11 2429 g.VerticalLines = {}
Tercio@11 2430 g.max_value = 0
Tercio@11 2431
Tercio@11 2432 g:SetLineTexture ("line")
Tercio@11 2433
Tercio@11 2434 f.Graphic = g
Tercio@11 2435 f.GData = {}
Tercio@11 2436 f.OData = {}
Tercio@11 2437
Tercio@11 2438 --div lines
Tercio@11 2439 for i = 1, 8, 1 do
Tercio@11 2440 local line = g:CreateTexture (nil, "overlay")
Tercio@11 2441 line:SetTexture (1, 1, 1, .2)
Tercio@11 2442 line:SetWidth (670)
Tercio@11 2443 line:SetHeight (1.1)
Tercio@11 2444
Tercio@11 2445 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 2446 f ["dpsamt"..i] = s
Tercio@11 2447 s:SetText ("100k")
Tercio@11 2448 s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i)))
Tercio@11 2449
Tercio@11 2450 line:SetPoint ("topleft", s, "bottom", -27, 0)
Tercio@11 2451 s.line = line
Tercio@11 2452 end
Tercio@11 2453
Tercio@11 2454 f.SetTime = chart_panel_align_timelabels
Tercio@11 2455 f.EnableVerticalLines = chart_panel_vlines_on
Tercio@11 2456 f.DisableVerticalLines = chart_panel_vlines_off
Tercio@11 2457 f.SetTitle = chart_panel_set_title
Tercio@11 2458 f.SetScale = chart_panel_set_scale
Tercio@11 2459 f.Reset = chart_panel_reset
Tercio@11 2460 f.AddLine = chart_panel_add_data
Tercio@11 2461 f.CanMove = chart_panel_can_move
Tercio@11 2462 f.AddLabel = chart_panel_add_label
Tercio@11 2463 f.AddOverlay = chart_panel_add_overlay
Tercio@11 2464 f.HideCloseButton = chart_panel_hide_close_button
Tercio@11 2465 f.RightClickClose = chart_panel_right_click_close
Tercio@11 2466
Tercio@11 2467 f:SetScript ("OnSizeChanged", chart_panel_onresize)
Tercio@11 2468 chart_panel_onresize (f)
Tercio@11 2469
Tercio@11 2470 return f
Tercio@11 2471 end