annotate Libs/DF/panel.lua @ 18:680465749fc7

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