annotate Libs/DF/panel.lua @ 63:3552946c0b9a tip

Added tag v8.2.0.062 for changeset d6704922ef5d
author Tercioo
date Fri, 28 Jun 2019 20:06:18 -0300
parents 0682d738499b
children
rev   line source
Tercio@11 1
Tercio@11 2 local DF = _G ["DetailsFramework"]
Tercio@20 3 if (not DF or not DetailsFrameworkCanLoad) then
Tercio@18 4 return
Tercio@18 5 end
Tercio@18 6
Tercio@20 7 local _
Tercio@11 8 --> lua locals
Tercio@11 9 local _rawset = rawset --> lua local
Tercio@11 10 local _rawget = rawget --> lua local
Tercio@11 11 local _setmetatable = setmetatable --> lua local
Tercio@11 12 local _unpack = unpack --> lua local
Tercio@11 13 local _type = type --> lua local
Tercio@11 14 local _math_floor = math.floor --> lua local
Tercio@11 15 local loadstring = loadstring --> lua local
Tercio@11 16
Tercio@11 17 local cleanfunction = function() end
Tercio@11 18 local APIFrameFunctions
Tercio@11 19
Tercio@39 20 do
Tercio@39 21 local metaPrototype = {
Tercio@39 22 WidgetType = "panel",
Tercio@39 23 SetHook = DF.SetHook,
Tercio@39 24 RunHooksForWidget = DF.RunHooksForWidget,
Tercio@39 25 }
Tercio@39 26
Tercio@39 27 _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype
Tercio@39 28 end
Tercio@39 29
Tercio@39 30 local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]]
Tercio@39 31
Tercio@58 32 --> mixin for options functions
Tercio@58 33 DF.OptionsFunctions = {
Tercio@58 34 SetOption = function (self, optionName, optionValue)
Tercio@58 35 if (self.options) then
Tercio@58 36 self.options [optionName] = optionValue
Tercio@58 37 else
Tercio@58 38 self.options = {}
Tercio@58 39 self.options [optionName] = optionValue
Tercio@58 40 end
Tercio@58 41 end,
Tercio@58 42
Tercio@58 43 GetOption = function (self, optionName)
Tercio@58 44 return self.options and self.options [optionName]
Tercio@58 45 end,
Tercio@58 46
Tercio@58 47 GetAllOptions = function (self)
Tercio@58 48 if (self.options) then
Tercio@58 49 local optionsTable = {}
Tercio@58 50 for key, _ in pairs (self.options) do
Tercio@58 51 optionsTable [#optionsTable + 1] = key
Tercio@58 52 end
Tercio@58 53 return optionsTable
Tercio@58 54 else
Tercio@58 55 return {}
Tercio@58 56 end
Tercio@58 57 end,
Tercio@58 58
Tercio@58 59 BuildOptionsTable = function (self, defaultOptions, userOptions)
Tercio@58 60 self.options = self.options or {}
Tercio@58 61 DF.table.deploy (self.options, userOptions or {})
Tercio@58 62 DF.table.deploy (self.options, defaultOptions or {})
Tercio@58 63 end
Tercio@58 64 }
Tercio@58 65
Tercio@11 66 ------------------------------------------------------------------------------------------------------------
Tercio@11 67 --> metatables
Tercio@11 68
Tercio@11 69 PanelMetaFunctions.__call = function (_table, value)
Tercio@11 70 --> nothing to do
Tercio@11 71 return true
Tercio@11 72 end
Tercio@11 73
Tercio@11 74 ------------------------------------------------------------------------------------------------------------
Tercio@11 75 --> members
Tercio@11 76
Tercio@11 77 --> tooltip
Tercio@11 78 local gmember_tooltip = function (_object)
Tercio@11 79 return _object:GetTooltip()
Tercio@11 80 end
Tercio@11 81 --> shown
Tercio@11 82 local gmember_shown = function (_object)
Tercio@11 83 return _object:IsShown()
Tercio@11 84 end
Tercio@11 85 --> backdrop color
Tercio@11 86 local gmember_color = function (_object)
Tercio@11 87 return _object.frame:GetBackdropColor()
Tercio@11 88 end
Tercio@11 89 --> backdrop table
Tercio@11 90 local gmember_backdrop = function (_object)
Tercio@11 91 return _object.frame:GetBackdrop()
Tercio@11 92 end
Tercio@11 93 --> frame width
Tercio@11 94 local gmember_width = function (_object)
Tercio@11 95 return _object.frame:GetWidth()
Tercio@11 96 end
Tercio@11 97 --> frame height
Tercio@11 98 local gmember_height = function (_object)
Tercio@11 99 return _object.frame:GetHeight()
Tercio@11 100 end
Tercio@11 101 --> locked
Tercio@11 102 local gmember_locked = function (_object)
Tercio@11 103 return _rawget (_object, "is_locked")
Tercio@11 104 end
Tercio@11 105
Tercio@39 106 PanelMetaFunctions.GetMembers = PanelMetaFunctions.GetMembers or {}
Tercio@39 107 PanelMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
Tercio@39 108 PanelMetaFunctions.GetMembers ["shown"] = gmember_shown
Tercio@39 109 PanelMetaFunctions.GetMembers ["color"] = gmember_color
Tercio@39 110 PanelMetaFunctions.GetMembers ["backdrop"] = gmember_backdrop
Tercio@39 111 PanelMetaFunctions.GetMembers ["width"] = gmember_width
Tercio@39 112 PanelMetaFunctions.GetMembers ["height"] = gmember_height
Tercio@39 113 PanelMetaFunctions.GetMembers ["locked"] = gmember_locked
Tercio@11 114
Tercio@11 115 PanelMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 116
Tercio@39 117 local func = PanelMetaFunctions.GetMembers [_member_requested]
Tercio@11 118 if (func) then
Tercio@11 119 return func (_table, _member_requested)
Tercio@11 120 end
Tercio@11 121
Tercio@11 122 local fromMe = _rawget (_table, _member_requested)
Tercio@11 123 if (fromMe) then
Tercio@11 124 return fromMe
Tercio@11 125 end
Tercio@11 126
Tercio@11 127 return PanelMetaFunctions [_member_requested]
Tercio@11 128 end
Tercio@11 129
Tercio@11 130
Tercio@11 131 --> tooltip
Tercio@11 132 local smember_tooltip = function (_object, _value)
Tercio@11 133 return _object:SetTooltip (_value)
Tercio@11 134 end
Tercio@11 135 --> show
Tercio@11 136 local smember_show = function (_object, _value)
Tercio@11 137 if (_value) then
Tercio@11 138 return _object:Show()
Tercio@11 139 else
Tercio@11 140 return _object:Hide()
Tercio@11 141 end
Tercio@11 142 end
Tercio@11 143 --> hide
Tercio@11 144 local smember_hide = function (_object, _value)
Tercio@11 145 if (not _value) then
Tercio@11 146 return _object:Show()
Tercio@11 147 else
Tercio@11 148 return _object:Hide()
Tercio@11 149 end
Tercio@11 150 end
Tercio@11 151 --> backdrop color
Tercio@11 152 local smember_color = function (_object, _value)
Tercio@11 153 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 154 return _object:SetBackdropColor (_value1, _value2, _value3, _value4)
Tercio@11 155 end
Tercio@11 156 --> frame width
Tercio@11 157 local smember_width = function (_object, _value)
Tercio@11 158 return _object.frame:SetWidth (_value)
Tercio@11 159 end
Tercio@11 160 --> frame height
Tercio@11 161 local smember_height = function (_object, _value)
Tercio@11 162 return _object.frame:SetHeight (_value)
Tercio@11 163 end
Tercio@11 164
Tercio@11 165 --> locked
Tercio@11 166 local smember_locked = function (_object, _value)
Tercio@11 167 if (_value) then
Tercio@11 168 _object.frame:SetMovable (false)
Tercio@11 169 return _rawset (_object, "is_locked", true)
Tercio@11 170 else
Tercio@11 171 _object.frame:SetMovable (true)
Tercio@11 172 _rawset (_object, "is_locked", false)
Tercio@11 173 return
Tercio@11 174 end
Tercio@11 175 end
Tercio@11 176
Tercio@11 177 --> backdrop
Tercio@11 178 local smember_backdrop = function (_object, _value)
Tercio@11 179 return _object.frame:SetBackdrop (_value)
Tercio@11 180 end
Tercio@11 181
Tercio@11 182 --> close with right button
Tercio@11 183 local smember_right_close = function (_object, _value)
Tercio@11 184 return _rawset (_object, "rightButtonClose", _value)
Tercio@11 185 end
Tercio@11 186
Tercio@39 187 PanelMetaFunctions.SetMembers = PanelMetaFunctions.SetMembers or {}
Tercio@39 188 PanelMetaFunctions.SetMembers["tooltip"] = smember_tooltip
Tercio@39 189 PanelMetaFunctions.SetMembers["show"] = smember_show
Tercio@39 190 PanelMetaFunctions.SetMembers["hide"] = smember_hide
Tercio@39 191 PanelMetaFunctions.SetMembers["color"] = smember_color
Tercio@39 192 PanelMetaFunctions.SetMembers["backdrop"] = smember_backdrop
Tercio@39 193 PanelMetaFunctions.SetMembers["width"] = smember_width
Tercio@39 194 PanelMetaFunctions.SetMembers["height"] = smember_height
Tercio@39 195 PanelMetaFunctions.SetMembers["locked"] = smember_locked
Tercio@39 196 PanelMetaFunctions.SetMembers["close_with_right"] = smember_right_close
Tercio@39 197
Tercio@11 198 PanelMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@39 199 local func = PanelMetaFunctions.SetMembers [_key]
Tercio@11 200 if (func) then
Tercio@11 201 return func (_table, _value)
Tercio@11 202 else
Tercio@11 203 return _rawset (_table, _key, _value)
Tercio@11 204 end
Tercio@11 205 end
Tercio@11 206
Tercio@11 207 ------------------------------------------------------------------------------------------------------------
Tercio@11 208 --> methods
Tercio@11 209
Tercio@11 210 --> right click to close
Tercio@11 211 function PanelMetaFunctions:CreateRightClickLabel (textType, w, h, close_text)
Tercio@11 212 local text
Tercio@11 213 w = w or 20
Tercio@11 214 h = h or 20
Tercio@11 215
Tercio@11 216 if (close_text) then
Tercio@11 217 text = close_text
Tercio@11 218 else
Tercio@11 219 if (textType) then
Tercio@11 220 textType = string.lower (textType)
Tercio@11 221 if (textType == "short") then
Tercio@11 222 text = "close window"
Tercio@11 223 elseif (textType == "medium") then
Tercio@11 224 text = "close window"
Tercio@11 225 elseif (textType == "large") then
Tercio@11 226 text = "close window"
Tercio@11 227 end
Tercio@11 228 else
Tercio@11 229 text = "close window"
Tercio@11 230 end
Tercio@11 231 end
Tercio@11 232
Tercio@11 233 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 234 end
Tercio@11 235
Tercio@11 236 --> show & hide
Tercio@11 237 function PanelMetaFunctions:Show()
Tercio@11 238 self.frame:Show()
Tercio@11 239
Tercio@11 240 end
Tercio@11 241 function PanelMetaFunctions:Hide()
Tercio@11 242 self.frame:Hide()
Tercio@11 243
Tercio@11 244 end
Tercio@11 245
Tercio@11 246 -- setpoint
Tercio@11 247 function PanelMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 248 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 249 if (not v1) then
Tercio@11 250 print ("Invalid parameter for SetPoint")
Tercio@11 251 return
Tercio@11 252 end
Tercio@11 253 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 254 end
Tercio@11 255
Tercio@11 256 -- sizes
Tercio@11 257 function PanelMetaFunctions:SetSize (w, h)
Tercio@11 258 if (w) then
Tercio@11 259 self.frame:SetWidth (w)
Tercio@11 260 end
Tercio@11 261 if (h) then
Tercio@11 262 self.frame:SetHeight (h)
Tercio@11 263 end
Tercio@11 264 end
Tercio@11 265
Tercio@11 266 -- clear
Tercio@11 267 function PanelMetaFunctions:HideWidgets()
Tercio@11 268 for widgetName, widgetSelf in pairs (self) do
Tercio@11 269 if (type (widgetSelf) == "table" and widgetSelf.dframework) then
Tercio@11 270 widgetSelf:Hide()
Tercio@11 271 end
Tercio@11 272 end
Tercio@11 273 end
Tercio@11 274
Tercio@11 275 -- backdrop
Tercio@11 276 function PanelMetaFunctions:SetBackdrop (background, edge, tilesize, edgesize, tile, left, right, top, bottom)
Tercio@11 277
Tercio@11 278 if (_type (background) == "boolean" and not background) then
Tercio@11 279 return self.frame:SetBackdrop (nil)
Tercio@11 280
Tercio@11 281 elseif (_type (background) == "table") then
Tercio@11 282 self.frame:SetBackdrop (background)
Tercio@11 283
Tercio@11 284 else
Tercio@11 285 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 286 currentBackdrop.bgFile = background or currentBackdrop.bgFile
Tercio@11 287 currentBackdrop.edgeFile = edgeFile or currentBackdrop.edgeFile
Tercio@11 288 currentBackdrop.tileSize = tilesize or currentBackdrop.tileSize
Tercio@11 289 currentBackdrop.edgeSize = edgesize or currentBackdrop.edgeSize
Tercio@11 290 currentBackdrop.tile = tile or currentBackdrop.tile
Tercio@11 291 currentBackdrop.insets.left = left or currentBackdrop.insets.left
Tercio@11 292 currentBackdrop.insets.right = left or currentBackdrop.insets.right
Tercio@11 293 currentBackdrop.insets.top = left or currentBackdrop.insets.top
Tercio@11 294 currentBackdrop.insets.bottom = left or currentBackdrop.insets.bottom
Tercio@11 295 self.frame:SetBackdrop (currentBackdrop)
Tercio@11 296 end
Tercio@11 297 end
Tercio@11 298
Tercio@11 299 -- backdropcolor
Tercio@11 300 function PanelMetaFunctions:SetBackdropColor (color, arg2, arg3, arg4)
Tercio@11 301 if (arg2) then
Tercio@11 302 self.frame:SetBackdropColor (color, arg2, arg3, arg4 or 1)
Tercio@11 303 else
Tercio@11 304 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 305 self.frame:SetBackdropColor (_value1, _value2, _value3, _value4)
Tercio@11 306 end
Tercio@11 307 end
Tercio@11 308
Tercio@11 309 -- border color
Tercio@11 310 function PanelMetaFunctions:SetBackdropBorderColor (color, arg2, arg3, arg4)
Tercio@11 311 if (arg2) then
Tercio@11 312 return self.frame:SetBackdropBorderColor (color, arg2, arg3, arg4)
Tercio@11 313 end
Tercio@11 314 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 315 self.frame:SetBackdropBorderColor (_value1, _value2, _value3, _value4)
Tercio@11 316 end
Tercio@11 317
Tercio@11 318 -- tooltip
Tercio@11 319 function PanelMetaFunctions:SetTooltip (tooltip)
Tercio@11 320 if (tooltip) then
Tercio@11 321 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 322 else
Tercio@11 323 return _rawset (self, "have_tooltip", nil)
Tercio@11 324 end
Tercio@11 325 end
Tercio@11 326 function PanelMetaFunctions:GetTooltip()
Tercio@11 327 return _rawget (self, "have_tooltip")
Tercio@11 328 end
Tercio@11 329
Tercio@11 330 -- frame levels
Tercio@11 331 function PanelMetaFunctions:GetFrameLevel()
Tercio@11 332 return self.widget:GetFrameLevel()
Tercio@11 333 end
Tercio@11 334 function PanelMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 335 if (not frame) then
Tercio@11 336 return self.widget:SetFrameLevel (level)
Tercio@11 337 else
Tercio@11 338 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 339 return self.widget:SetFrameLevel (framelevel)
Tercio@11 340 end
Tercio@11 341 end
Tercio@11 342
Tercio@11 343 -- frame stratas
Tercio@11 344 function PanelMetaFunctions:SetFrameStrata()
Tercio@11 345 return self.widget:GetFrameStrata()
Tercio@11 346 end
Tercio@11 347 function PanelMetaFunctions:SetFrameStrata (strata)
Tercio@11 348 if (_type (strata) == "table") then
Tercio@11 349 self.widget:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 350 else
Tercio@11 351 self.widget:SetFrameStrata (strata)
Tercio@11 352 end
Tercio@11 353 end
Tercio@11 354
Tercio@11 355 ------------------------------------------------------------------------------------------------------------
Tercio@11 356 --> scripts
Tercio@11 357
Tercio@11 358 local OnEnter = function (frame)
Tercio@39 359 local capsule = frame.MyObject
Tercio@39 360 local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule)
Tercio@39 361 if (kill) then
Tercio@39 362 return
Tercio@11 363 end
Tercio@11 364
Tercio@11 365 if (frame.MyObject.have_tooltip) then
Tercio@11 366 GameCooltip2:Reset()
Tercio@11 367 GameCooltip2:SetType ("tooltip")
Tercio@11 368 GameCooltip2:SetColor ("main", "transparent")
Tercio@11 369 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 370 GameCooltip2:SetOwner (frame)
Tercio@11 371 GameCooltip2:ShowCooltip()
Tercio@11 372 end
Tercio@11 373 end
Tercio@11 374
Tercio@11 375 local OnLeave = function (frame)
Tercio@39 376 local capsule = frame.MyObject
Tercio@39 377 local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule)
Tercio@39 378 if (kill) then
Tercio@39 379 return
Tercio@11 380 end
Tercio@11 381
Tercio@11 382 if (frame.MyObject.have_tooltip) then
Tercio@11 383 GameCooltip2:ShowMe (false)
Tercio@11 384 end
Tercio@11 385
Tercio@11 386 end
Tercio@11 387
Tercio@11 388 local OnHide = function (frame)
Tercio@39 389 local capsule = frame.MyObject
Tercio@39 390 local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule)
Tercio@39 391 if (kill) then
Tercio@39 392 return
Tercio@11 393 end
Tercio@11 394 end
Tercio@11 395
Tercio@11 396 local OnShow = function (frame)
Tercio@39 397 local capsule = frame.MyObject
Tercio@39 398 local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule)
Tercio@39 399 if (kill) then
Tercio@39 400 return
Tercio@11 401 end
Tercio@11 402 end
Tercio@11 403
Tercio@11 404 local OnMouseDown = function (frame, button)
Tercio@39 405 local capsule = frame.MyObject
Tercio@39 406 local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule)
Tercio@39 407 if (kill) then
Tercio@39 408 return
Tercio@11 409 end
Tercio@11 410
Tercio@11 411 if (frame.MyObject.container == UIParent) then
Tercio@11 412 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 413 frame.isMoving = true
Tercio@11 414 frame:StartMoving()
Tercio@11 415 end
Tercio@11 416
Tercio@11 417 elseif (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 418 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 419 frame.MyObject.container.isMoving = true
Tercio@11 420 frame.MyObject.container:StartMoving()
Tercio@11 421 end
Tercio@11 422 end
Tercio@11 423
Tercio@11 424
Tercio@11 425 end
Tercio@11 426
Tercio@11 427 local OnMouseUp = function (frame, button)
Tercio@39 428 local capsule = frame.MyObject
Tercio@39 429 local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule)
Tercio@39 430 if (kill) then
Tercio@39 431 return
Tercio@11 432 end
Tercio@11 433
Tercio@11 434 if (button == "RightButton" and frame.MyObject.rightButtonClose) then
Tercio@11 435 frame.MyObject:Hide()
Tercio@11 436 end
Tercio@11 437
Tercio@11 438 if (frame.MyObject.container == UIParent) then
Tercio@11 439 if (frame.isMoving) then
Tercio@11 440 frame:StopMovingOrSizing()
Tercio@11 441 frame.isMoving = false
Tercio@11 442 end
Tercio@11 443 else
Tercio@11 444 if (frame.MyObject.container.isMoving) then
Tercio@11 445 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 446 frame.MyObject.container.isMoving = false
Tercio@11 447 end
Tercio@11 448 end
Tercio@11 449 end
Tercio@11 450
Tercio@11 451 ------------------------------------------------------------------------------------------------------------
Tercio@11 452 --> object constructor
Tercio@11 453 function DF:CreatePanel (parent, w, h, backdrop, backdropcolor, bordercolor, member, name)
Tercio@11 454 return DF:NewPanel (parent, parent, name, member, w, h, backdrop, backdropcolor, bordercolor)
Tercio@11 455 end
Tercio@11 456
Tercio@11 457 function DF:NewPanel (parent, container, name, member, w, h, backdrop, backdropcolor, bordercolor)
Tercio@11 458
Tercio@11 459 if (not name) then
Tercio@11 460 name = "DetailsFrameworkPanelNumber" .. DF.PanelCounter
Tercio@11 461 DF.PanelCounter = DF.PanelCounter + 1
Tercio@11 462
Tercio@11 463 elseif (not parent) then
Tercio@11 464 parent = UIParent
Tercio@11 465 end
Tercio@11 466 if (not container) then
Tercio@11 467 container = parent
Tercio@11 468 end
Tercio@11 469
Tercio@11 470 if (name:find ("$parent")) then
Tercio@11 471 name = name:gsub ("$parent", parent:GetName())
Tercio@11 472 end
Tercio@11 473
Tercio@11 474 local PanelObject = {type = "panel", dframework = true}
Tercio@11 475
Tercio@11 476 if (member) then
Tercio@11 477 parent [member] = PanelObject
Tercio@11 478 end
Tercio@11 479
Tercio@11 480 if (parent.dframework) then
Tercio@11 481 parent = parent.widget
Tercio@11 482 end
Tercio@11 483 if (container.dframework) then
Tercio@11 484 container = container.widget
Tercio@11 485 end
Tercio@11 486
Tercio@11 487 --> default members:
Tercio@11 488 --> misc
Tercio@11 489 PanelObject.is_locked = true
Tercio@11 490 PanelObject.container = container
Tercio@11 491 PanelObject.rightButtonClose = false
Tercio@11 492
Tercio@11 493 PanelObject.frame = CreateFrame ("frame", name, parent, "DetailsFrameworkPanelTemplate")
Tercio@11 494 PanelObject.widget = PanelObject.frame
Tercio@11 495
Tercio@11 496 if (not APIFrameFunctions) then
Tercio@11 497 APIFrameFunctions = {}
Tercio@11 498 local idx = getmetatable (PanelObject.frame).__index
Tercio@11 499 for funcName, funcAddress in pairs (idx) do
Tercio@11 500 if (not PanelMetaFunctions [funcName]) then
Tercio@11 501 PanelMetaFunctions [funcName] = function (object, ...)
Tercio@20 502 local x = loadstring ( "return _G['"..object.frame:GetName().."']:"..funcName.."(...)")
Tercio@11 503 return x (...)
Tercio@11 504 end
Tercio@11 505 end
Tercio@11 506 end
Tercio@11 507 end
Tercio@11 508
Tercio@11 509 PanelObject.frame:SetWidth (w or 100)
Tercio@11 510 PanelObject.frame:SetHeight (h or 100)
Tercio@11 511
Tercio@11 512 PanelObject.frame.MyObject = PanelObject
Tercio@11 513
Tercio@39 514 PanelObject.HookList = {
Tercio@39 515 OnEnter = {},
Tercio@39 516 OnLeave = {},
Tercio@39 517 OnHide = {},
Tercio@39 518 OnShow = {},
Tercio@39 519 OnMouseDown = {},
Tercio@39 520 OnMouseUp = {},
Tercio@39 521 }
Tercio@39 522
Tercio@11 523 --> hooks
Tercio@11 524 PanelObject.frame:SetScript ("OnEnter", OnEnter)
Tercio@11 525 PanelObject.frame:SetScript ("OnLeave", OnLeave)
Tercio@11 526 PanelObject.frame:SetScript ("OnHide", OnHide)
Tercio@11 527 PanelObject.frame:SetScript ("OnShow", OnShow)
Tercio@11 528 PanelObject.frame:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 529 PanelObject.frame:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 530
Tercio@11 531 _setmetatable (PanelObject, PanelMetaFunctions)
Tercio@11 532
Tercio@11 533 if (backdrop) then
Tercio@11 534 PanelObject:SetBackdrop (backdrop)
Tercio@11 535 elseif (_type (backdrop) == "boolean") then
Tercio@11 536 PanelObject.frame:SetBackdrop (nil)
Tercio@11 537 end
Tercio@11 538
Tercio@11 539 if (backdropcolor) then
Tercio@11 540 PanelObject:SetBackdropColor (backdropcolor)
Tercio@11 541 end
Tercio@11 542
Tercio@11 543 if (bordercolor) then
Tercio@11 544 PanelObject:SetBackdropBorderColor (bordercolor)
Tercio@11 545 end
Tercio@11 546
Tercio@11 547 return PanelObject
Tercio@11 548 end
Tercio@11 549
Tercio@11 550 ------------fill panel
Tercio@11 551
Tercio@11 552 local button_on_enter = function (self)
Tercio@11 553 self.MyObject._icon:SetBlendMode ("ADD")
Tercio@49 554 if (self.MyObject.onenter_func) then
Tercio@49 555 pcall (self.MyObject.onenter_func, self.MyObject)
Tercio@49 556 end
Tercio@11 557 end
Tercio@11 558 local button_on_leave = function (self)
Tercio@11 559 self.MyObject._icon:SetBlendMode ("BLEND")
Tercio@49 560 if (self.MyObject.onleave_func) then
Tercio@49 561 pcall (self.MyObject.onleave_func, self.MyObject)
Tercio@49 562 end
Tercio@11 563 end
Tercio@11 564
Tercio@20 565 local add_row = function (self, t, need_update)
Tercio@20 566 local index = #self.rows+1
Tercio@20 567
Tercio@20 568 local thisrow = DF:NewPanel (self, self, "$parentHeader_" .. self._name .. index, nil, 1, 20)
Tercio@20 569 thisrow.backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]}
Tercio@20 570 thisrow.color = "silver"
Tercio@20 571 thisrow.type = t.type
Tercio@20 572 thisrow.func = t.func
Tercio@20 573 thisrow.name = t.name
Tercio@20 574 thisrow.notext = t.notext
Tercio@20 575 thisrow.icon = t.icon
Tercio@20 576 thisrow.iconalign = t.iconalign
Tercio@20 577
Tercio@20 578 thisrow.hidden = t.hidden or false
Tercio@20 579
Tercio@49 580 thisrow.onenter = t.onenter
Tercio@49 581 thisrow.onleave = t.onleave
Tercio@49 582
Tercio@20 583 local text = DF:NewLabel (thisrow, nil, self._name .. "$parentLabel" .. index, "text")
Tercio@20 584 text:SetPoint ("left", thisrow, "left", 2, 0)
Tercio@20 585 text:SetText (t.name)
Tercio@20 586
Tercio@20 587 tinsert (self._raw_rows, t)
Tercio@20 588 tinsert (self.rows, thisrow)
Tercio@20 589
Tercio@20 590 if (need_update) then
Tercio@20 591 self:AlignRows()
Tercio@20 592 end
Tercio@11 593 end
Tercio@11 594
Tercio@20 595 local align_rows = function (self)
Tercio@20 596
Tercio@20 597 local rows_shown = 0
Tercio@20 598 for index, row in ipairs (self.rows) do
Tercio@20 599 if (not row.hidden) then
Tercio@20 600 rows_shown = rows_shown + 1
Tercio@20 601 end
Tercio@20 602 end
Tercio@20 603
Tercio@20 604 local cur_width = 0
Tercio@20 605 local row_width = self._width / rows_shown
Tercio@22 606
Tercio@20 607 local sindex = 1
Tercio@20 608
Tercio@20 609 wipe (self._anchors)
Tercio@20 610
Tercio@20 611 for index, row in ipairs (self.rows) do
Tercio@20 612 if (not row.hidden) then
Tercio@20 613 if (self._autowidth) then
Tercio@20 614 if (self._raw_rows [index].width) then
Tercio@20 615 row.width = self._raw_rows [index].width
Tercio@20 616 else
Tercio@20 617 row.width = row_width
Tercio@20 618 end
Tercio@20 619 row:SetPoint ("topleft", self, "topleft", cur_width, 0)
Tercio@20 620 tinsert (self._anchors, cur_width)
Tercio@20 621 cur_width = cur_width + row_width + 1
Tercio@20 622 else
Tercio@20 623 row:SetPoint ("topleft", self, "topleft", cur_width, 0)
Tercio@20 624 row.width = self._raw_rows [index].width
Tercio@20 625 tinsert (self._anchors, cur_width)
Tercio@20 626 cur_width = cur_width + self._raw_rows [index].width + 1
Tercio@20 627 end
Tercio@42 628
Tercio@20 629 row:Show()
Tercio@20 630
Tercio@20 631 local type = row.type
Tercio@20 632
Tercio@20 633 if (type == "text") then
Tercio@20 634 for i = 1, #self.scrollframe.lines do
Tercio@20 635 local line = self.scrollframe.lines [i]
Tercio@20 636 local text = tremove (line.text_available)
Tercio@20 637 if (not text) then
Tercio@20 638 self:CreateRowText (line)
Tercio@20 639 text = tremove (line.text_available)
Tercio@20 640 end
Tercio@20 641 tinsert (line.text_inuse, text)
Tercio@20 642 text:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0)
Tercio@20 643 text:SetWidth (row.width)
Tercio@42 644
Tercio@42 645 DF:SetFontSize (text, row.textsize or 10)
Tercio@42 646 text:SetJustifyH (row.textalign or "left")
Tercio@20 647 end
Tercio@20 648 elseif (type == "entry") then
Tercio@20 649 for i = 1, #self.scrollframe.lines do
Tercio@20 650 local line = self.scrollframe.lines [i]
Tercio@20 651 local entry = tremove (line.entry_available)
Tercio@20 652 if (not entry) then
Tercio@20 653 self:CreateRowEntry (line)
Tercio@20 654 entry = tremove (line.entry_available)
Tercio@20 655 end
Tercio@20 656 tinsert (line.entry_inuse, entry)
Tercio@20 657 entry:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0)
Tercio@20 658 if (sindex == rows_shown) then
Tercio@20 659 entry:SetWidth (row.width - 25)
Tercio@20 660 else
Tercio@20 661 entry:SetWidth (row.width)
Tercio@20 662 end
Tercio@20 663 entry.func = row.func
Tercio@49 664
Tercio@49 665 entry.onenter_func = nil
Tercio@49 666 entry.onleave_func = nil
Tercio@49 667
Tercio@49 668 if (row.onenter) then
Tercio@49 669 entry.onenter_func = row.onenter
Tercio@49 670 end
Tercio@49 671 if (row.onleave) then
Tercio@49 672 entry.onleave_func = row.onleave
Tercio@49 673 end
Tercio@20 674 end
Tercio@20 675 elseif (type == "button") then
Tercio@20 676 for i = 1, #self.scrollframe.lines do
Tercio@20 677 local line = self.scrollframe.lines [i]
Tercio@20 678 local button = tremove (line.button_available)
Tercio@20 679 if (not button) then
Tercio@20 680 self:CreateRowButton (line)
Tercio@20 681 button = tremove (line.button_available)
Tercio@20 682 end
Tercio@20 683 tinsert (line.button_inuse, button)
Tercio@20 684 button:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0)
Tercio@20 685 if (sindex == rows_shown) then
Tercio@20 686 button:SetWidth (row.width - 25)
Tercio@20 687 else
Tercio@20 688 button:SetWidth (row.width)
Tercio@20 689 end
Tercio@20 690
Tercio@20 691 if (row.icon) then
Tercio@20 692 button._icon.texture = row.icon
Tercio@20 693 button._icon:ClearAllPoints()
Tercio@20 694 if (row.iconalign) then
Tercio@20 695 if (row.iconalign == "center") then
Tercio@20 696 button._icon:SetPoint ("center", button, "center")
Tercio@20 697 elseif (row.iconalign == "right") then
Tercio@20 698 button._icon:SetPoint ("right", button, "right")
Tercio@20 699 end
Tercio@20 700 else
Tercio@20 701 button._icon:SetPoint ("left", button, "left")
Tercio@20 702 end
Tercio@20 703 end
Tercio@20 704
Tercio@20 705 if (row.name and not row.notext) then
Tercio@20 706 button._text:SetPoint ("left", button._icon, "right", 2, 0)
Tercio@20 707 button._text.text = row.name
Tercio@49 708 end
Tercio@49 709
Tercio@49 710 button.onenter_func = nil
Tercio@49 711 button.onleave_func = nil
Tercio@49 712
Tercio@49 713 if (row.onenter) then
Tercio@49 714 button.onenter_func = row.onenter
Tercio@49 715 end
Tercio@49 716 if (row.onleave) then
Tercio@49 717 button.onleave_func = row.onleave
Tercio@49 718 end
Tercio@20 719
Tercio@20 720 end
Tercio@20 721 elseif (type == "icon") then
Tercio@20 722 for i = 1, #self.scrollframe.lines do
Tercio@20 723 local line = self.scrollframe.lines [i]
Tercio@20 724 local icon = tremove (line.icon_available)
Tercio@20 725 if (not icon) then
Tercio@20 726 self:CreateRowIcon (line)
Tercio@20 727 icon = tremove (line.icon_available)
Tercio@20 728 end
Tercio@20 729 tinsert (line.icon_inuse, icon)
Tercio@20 730 icon:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
Tercio@20 731 icon.func = row.func
Tercio@20 732 end
Tercio@49 733
Tercio@49 734 elseif (type == "texture") then
Tercio@49 735 for i = 1, #self.scrollframe.lines do
Tercio@49 736 local line = self.scrollframe.lines [i]
Tercio@49 737 local texture = tremove (line.texture_available)
Tercio@49 738 if (not texture) then
Tercio@49 739 self:CreateRowTexture (line)
Tercio@49 740 texture = tremove (line.texture_available)
Tercio@49 741 end
Tercio@49 742 tinsert (line.texture_inuse, texture)
Tercio@49 743 texture:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
Tercio@49 744 end
Tercio@49 745
Tercio@20 746 end
Tercio@20 747
Tercio@20 748 sindex = sindex + 1
Tercio@20 749 else
Tercio@20 750 row:Hide()
Tercio@20 751 end
Tercio@20 752 end
Tercio@20 753
Tercio@20 754 if (#self.rows > 0) then
Tercio@20 755 if (self._autowidth) then
Tercio@20 756 self.rows [#self.rows]:SetWidth (row_width - rows_shown + 1)
Tercio@20 757 else
Tercio@20 758 self.rows [#self.rows]:SetWidth (self._raw_rows [rows_shown].width - rows_shown + 1)
Tercio@20 759 end
Tercio@20 760 end
Tercio@20 761
Tercio@20 762 self.showing_amt = rows_shown
Tercio@20 763 end
Tercio@20 764
Tercio@20 765 local update_rows = function (self, updated_rows)
Tercio@49 766
Tercio@20 767 for i = 1, #updated_rows do
Tercio@20 768 local t = updated_rows [i]
Tercio@20 769 local raw = self._raw_rows [i]
Tercio@20 770
Tercio@20 771 if (not raw) then
Tercio@20 772 self:AddRow (t)
Tercio@20 773 else
Tercio@20 774 raw.name = t.name
Tercio@20 775 raw.hidden = t.hidden or false
Tercio@42 776 raw.textsize = t.textsize
Tercio@42 777 raw.textalign = t.textalign
Tercio@20 778
Tercio@20 779 local widget = self.rows [i]
Tercio@20 780 widget.name = t.name
Tercio@42 781 widget.textsize = t.textsize
Tercio@42 782 widget.textalign = t.textalign
Tercio@20 783 widget.hidden = t.hidden or false
Tercio@20 784
Tercio@49 785 --
Tercio@49 786 widget.onenter = t.onenter
Tercio@49 787 widget.onleave = t.onleave
Tercio@49 788 --
Tercio@49 789
Tercio@20 790 widget.text:SetText (t.name)
Tercio@42 791 DF:SetFontSize (widget.text, raw.textsize or 10)
Tercio@42 792 widget.text:SetJustifyH (raw.textalign or "left")
Tercio@42 793
Tercio@20 794 end
Tercio@20 795 end
Tercio@20 796
Tercio@20 797 for i = #updated_rows+1, #self._raw_rows do
Tercio@20 798 local raw = self._raw_rows [i]
Tercio@20 799 local widget = self.rows [i]
Tercio@20 800 raw.hidden = true
Tercio@20 801 widget.hidden = true
Tercio@20 802 end
Tercio@20 803
Tercio@20 804 for index, row in ipairs (self.scrollframe.lines) do
Tercio@20 805 for i = #row.text_inuse, 1, -1 do
Tercio@20 806 tinsert (row.text_available, tremove (row.text_inuse, i))
Tercio@20 807 end
Tercio@20 808 for i = 1, #row.text_available do
Tercio@20 809 row.text_available[i]:Hide()
Tercio@20 810 end
Tercio@20 811
Tercio@20 812 for i = #row.entry_inuse, 1, -1 do
Tercio@20 813 tinsert (row.entry_available, tremove (row.entry_inuse, i))
Tercio@20 814 end
Tercio@20 815 for i = 1, #row.entry_available do
Tercio@20 816 row.entry_available[i]:Hide()
Tercio@20 817 end
Tercio@20 818
Tercio@20 819 for i = #row.button_inuse, 1, -1 do
Tercio@20 820 tinsert (row.button_available, tremove (row.button_inuse, i))
Tercio@20 821 end
Tercio@20 822 for i = 1, #row.button_available do
Tercio@20 823 row.button_available[i]:Hide()
Tercio@20 824 end
Tercio@20 825
Tercio@20 826 for i = #row.icon_inuse, 1, -1 do
Tercio@20 827 tinsert (row.icon_available, tremove (row.icon_inuse, i))
Tercio@20 828 end
Tercio@20 829 for i = 1, #row.icon_available do
Tercio@20 830 row.icon_available[i]:Hide()
Tercio@20 831 end
Tercio@49 832
Tercio@49 833 for i = #row.texture_inuse, 1, -1 do
Tercio@49 834 tinsert (row.texture_available, tremove (row.texture_inuse, i))
Tercio@49 835 end
Tercio@49 836 for i = 1, #row.texture_available do
Tercio@49 837 row.texture_available[i]:Hide()
Tercio@49 838 end
Tercio@20 839 end
Tercio@20 840
Tercio@22 841 self.current_header = updated_rows
Tercio@22 842
Tercio@20 843 self:AlignRows()
Tercio@20 844
Tercio@20 845 end
Tercio@20 846
Tercio@20 847 local create_panel_text = function (self, row)
Tercio@20 848 row.text_total = row.text_total + 1
Tercio@20 849 local text = DF:NewLabel (row, nil, self._name .. "$parentLabel" .. row.text_total, "text" .. row.text_total)
Tercio@20 850 tinsert (row.text_available, text)
Tercio@20 851 end
Tercio@20 852
Tercio@20 853 local create_panel_entry = function (self, row)
Tercio@20 854 row.entry_total = row.entry_total + 1
Tercio@20 855 local editbox = DF:NewTextEntry (row, nil, "$parentEntry" .. row.entry_total, "entry", 120, 20)
Tercio@20 856 editbox.align = "left"
Tercio@20 857
Tercio@20 858 editbox:SetHook ("OnEnterPressed", function()
Tercio@20 859 editbox.widget.focuslost = true
Tercio@20 860 editbox:ClearFocus()
Tercio@20 861 editbox.func (editbox.index, editbox.text)
Tercio@20 862 return true
Tercio@49 863 end)
Tercio@49 864
Tercio@49 865 editbox:SetHook ("OnEnter", function()
Tercio@49 866 if (editbox.onenter_func) then
Tercio@49 867 pcall (editbox.onenter_func, editbox)
Tercio@49 868 end
Tercio@49 869 end)
Tercio@49 870 editbox:SetHook ("OnLeave", function()
Tercio@49 871 if (editbox.onleave_func) then
Tercio@49 872 pcall (editbox.onleave_func, editbox)
Tercio@49 873 end
Tercio@49 874 end)
Tercio@20 875
Tercio@20 876 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1})
Tercio@20 877 editbox:SetBackdropColor (1, 1, 1, 0.1)
Tercio@20 878 editbox:SetBackdropBorderColor (1, 1, 1, 0.1)
Tercio@20 879 editbox.editbox.current_bordercolor = {1, 1, 1, 0.1}
Tercio@20 880
Tercio@20 881 tinsert (row.entry_available, editbox)
Tercio@20 882 end
Tercio@20 883
Tercio@20 884 local create_panel_button = function (self, row)
Tercio@20 885 row.button_total = row.button_total + 1
Tercio@20 886 local button = DF:NewButton (row, nil, "$parentButton" .. row.button_total, "button" .. row.button_total, 120, 20)
Tercio@20 887
Tercio@20 888 --> create icon and the text
Tercio@20 889 local icon = DF:NewImage (button, nil, 20, 20)
Tercio@20 890 local text = DF:NewLabel (button)
Tercio@20 891
Tercio@20 892 button._icon = icon
Tercio@20 893 button._text = text
Tercio@20 894
Tercio@20 895 button:SetHook ("OnEnter", button_on_enter)
Tercio@20 896 button:SetHook ("OnLeave", button_on_leave)
Tercio@20 897
Tercio@20 898 tinsert (row.button_available, button)
Tercio@20 899 end
Tercio@20 900
Tercio@20 901 local icon_onclick = function (texture, iconbutton)
Tercio@20 902 iconbutton._icon.texture = texture
Tercio@20 903 iconbutton.func (iconbutton.index, texture)
Tercio@20 904 end
Tercio@20 905
Tercio@20 906 local create_panel_icon = function (self, row)
Tercio@20 907 row.icon_total = row.icon_total + 1
Tercio@20 908 local iconbutton = DF:NewButton (row, nil, "$parentIconButton" .. row.icon_total, "iconbutton", 22, 20)
Tercio@20 909 iconbutton:InstallCustomTexture()
Tercio@20 910
Tercio@20 911 iconbutton:SetHook ("OnEnter", button_on_enter)
Tercio@20 912 iconbutton:SetHook ("OnLeave", button_on_leave)
Tercio@20 913
Tercio@20 914 iconbutton:SetHook ("OnMouseUp", function()
Tercio@20 915 DF:IconPick (icon_onclick, true, iconbutton)
Tercio@20 916 return true
Tercio@20 917 end)
Tercio@20 918
Tercio@20 919 local icon = DF:NewImage (iconbutton, nil, 20, 20, "artwork", nil, "_icon", "$parentIcon" .. row.icon_total)
Tercio@20 920 iconbutton._icon = icon
Tercio@20 921
Tercio@20 922 icon:SetPoint ("center", iconbutton, "center", 0, 0)
Tercio@20 923
Tercio@20 924 tinsert (row.icon_available, iconbutton)
Tercio@20 925 end
Tercio@20 926
Tercio@49 927 local create_panel_texture = function (self, row)
Tercio@49 928 row.texture_total = row.texture_total + 1
Tercio@49 929 local texture = DF:NewImage (row, nil, 20, 20, "artwork", nil, "_icon" .. row.texture_total, "$parentIcon" .. row.texture_total)
Tercio@49 930 tinsert (row.texture_available, texture)
Tercio@49 931 end
Tercio@49 932
Tercio@20 933 local set_fill_function = function (self, func)
Tercio@20 934 self._fillfunc = func
Tercio@20 935 end
Tercio@20 936 local set_total_function = function (self, func)
Tercio@20 937 self._totalfunc = func
Tercio@20 938 end
Tercio@20 939 local drop_header_function = function (self)
Tercio@20 940 wipe (self.rows)
Tercio@20 941 end
Tercio@22 942
Tercio@22 943 local fillpanel_update_size = function (self, elapsed)
Tercio@22 944 local panel = self.MyObject
Tercio@22 945
Tercio@22 946 panel._width = panel:GetWidth()
Tercio@22 947 panel._height = panel:GetHeight()
Tercio@22 948
Tercio@22 949 panel:UpdateRowAmount()
Tercio@22 950 if (panel.current_header) then
Tercio@22 951 update_rows (panel, panel.current_header)
Tercio@22 952 end
Tercio@22 953 panel:Refresh()
Tercio@22 954
Tercio@22 955 self:SetScript ("OnUpdate", nil)
Tercio@22 956 end
Tercio@22 957
Tercio@20 958 -- ~fillpanel
Tercio@22 959 --alias
Tercio@22 960 function DF:CreateFillPanel (parent, rows, w, h, total_lines, fill_row, autowidth, options, member, name)
Tercio@22 961 return DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options)
Tercio@22 962 end
Tercio@22 963
Tercio@11 964 function DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options)
Tercio@11 965
Tercio@11 966 local panel = DF:NewPanel (parent, parent, name, member, w, h)
Tercio@11 967 panel.backdrop = nil
Tercio@11 968
Tercio@11 969 options = options or {rowheight = 20}
Tercio@11 970 panel.rows = {}
Tercio@20 971
Tercio@20 972 panel.AddRow = add_row
Tercio@20 973 panel.AlignRows = align_rows
Tercio@20 974 panel.UpdateRows = update_rows
Tercio@20 975 panel.CreateRowText = create_panel_text
Tercio@20 976 panel.CreateRowEntry = create_panel_entry
Tercio@20 977 panel.CreateRowButton = create_panel_button
Tercio@20 978 panel.CreateRowIcon = create_panel_icon
Tercio@49 979 panel.CreateRowTexture = create_panel_texture
Tercio@20 980 panel.SetFillFunction = set_fill_function
Tercio@20 981 panel.SetTotalFunction = set_total_function
Tercio@20 982 panel.DropHeader = drop_header_function
Tercio@20 983
Tercio@20 984 panel._name = name
Tercio@20 985 panel._width = w
Tercio@20 986 panel._height = h
Tercio@20 987 panel._raw_rows = {}
Tercio@20 988 panel._anchors = {}
Tercio@20 989 panel._fillfunc = fill_row
Tercio@20 990 panel._totalfunc = total_lines
Tercio@20 991 panel._autowidth = autowidth
Tercio@20 992
Tercio@22 993 panel:SetScript ("OnSizeChanged", function()
Tercio@22 994 panel:SetScript ("OnUpdate", fillpanel_update_size)
Tercio@22 995 end)
Tercio@22 996
Tercio@11 997 for index, t in ipairs (rows) do
Tercio@20 998 panel.AddRow (panel, t)
Tercio@11 999 end
Tercio@55 1000
Tercio@11 1001 local refresh_fillbox = function (self)
Tercio@20 1002
Tercio@11 1003 local offset = FauxScrollFrame_GetOffset (self)
Tercio@20 1004 local filled_lines = panel._totalfunc (panel)
Tercio@20 1005
Tercio@11 1006 for index = 1, #self.lines do
Tercio@20 1007
Tercio@11 1008 local row = self.lines [index]
Tercio@11 1009 if (index <= filled_lines) then
Tercio@20 1010
Tercio@11 1011 local real_index = index + offset
Tercio@20 1012 local results = panel._fillfunc (real_index, panel)
Tercio@11 1013
Tercio@49 1014 if (results and results [1]) then
Tercio@11 1015 row:Show()
Tercio@20 1016
Tercio@49 1017 local text, entry, button, icon, texture = 1, 1, 1, 1, 1
Tercio@11 1018
Tercio@20 1019 for index, t in ipairs (panel.rows) do
Tercio@20 1020 if (not t.hidden) then
Tercio@20 1021 if (t.type == "text") then
Tercio@20 1022 local fontstring = row.text_inuse [text]
Tercio@20 1023 text = text + 1
Tercio@20 1024 fontstring:SetText (results [index])
Tercio@20 1025 fontstring.index = real_index
Tercio@20 1026 fontstring:Show()
Tercio@11 1027
Tercio@20 1028 elseif (t.type == "entry") then
Tercio@20 1029 local entrywidget = row.entry_inuse [entry]
Tercio@20 1030 entry = entry + 1
Tercio@20 1031 entrywidget.index = real_index
Tercio@49 1032
Tercio@49 1033 if (type (results [index]) == "table") then
Tercio@49 1034 entrywidget:SetText (results [index].text)
Tercio@49 1035 entrywidget.id = results [index].id
Tercio@49 1036 entrywidget.data1 = results [index].data1
Tercio@49 1037 entrywidget.data2 = results [index].data2
Tercio@49 1038 else
Tercio@49 1039 entrywidget:SetText (results [index])
Tercio@49 1040 end
Tercio@49 1041
Tercio@49 1042 entrywidget:SetCursorPosition(0)
Tercio@49 1043
Tercio@20 1044 entrywidget:Show()
Tercio@20 1045
Tercio@20 1046 elseif (t.type == "button") then
Tercio@20 1047 local buttonwidget = row.button_inuse [button]
Tercio@20 1048 button = button + 1
Tercio@20 1049 buttonwidget.index = real_index
Tercio@22 1050
Tercio@20 1051 if (type (results [index]) == "table") then
Tercio@20 1052 if (results [index].text) then
Tercio@20 1053 buttonwidget:SetText (results [index].text)
Tercio@20 1054 end
Tercio@20 1055
Tercio@20 1056 if (results [index].icon) then
Tercio@20 1057 buttonwidget._icon:SetTexture (results [index].icon)
Tercio@20 1058 end
Tercio@20 1059
Tercio@20 1060 if (results [index].func) then
Tercio@22 1061 local func = function()
Tercio@22 1062 t.func (real_index, results [index].value)
Tercio@22 1063 panel:Refresh()
Tercio@22 1064 end
Tercio@22 1065 buttonwidget:SetClickFunction (func)
Tercio@22 1066 else
Tercio@22 1067 local func = function()
Tercio@22 1068 t.func (real_index, index)
Tercio@22 1069 panel:Refresh()
Tercio@22 1070 end
Tercio@22 1071 buttonwidget:SetClickFunction (func)
Tercio@20 1072 end
Tercio@49 1073
Tercio@49 1074 buttonwidget.id = results [index].id
Tercio@49 1075 buttonwidget.data1 = results [index].data1
Tercio@49 1076 buttonwidget.data2 = results [index].data2
Tercio@49 1077
Tercio@20 1078 else
Tercio@22 1079 local func = function()
Tercio@22 1080 t.func (real_index, index)
Tercio@22 1081 panel:Refresh()
Tercio@22 1082 end
Tercio@22 1083 buttonwidget:SetClickFunction (func)
Tercio@20 1084 buttonwidget:SetText (results [index])
Tercio@11 1085 end
Tercio@11 1086
Tercio@20 1087 buttonwidget:Show()
Tercio@11 1088
Tercio@20 1089 elseif (t.type == "icon") then
Tercio@20 1090 local iconwidget = row.icon_inuse [icon]
Tercio@20 1091 icon = icon + 1
Tercio@20 1092
Tercio@20 1093 iconwidget.line = index
Tercio@20 1094 iconwidget.index = real_index
Tercio@20 1095
Tercio@39 1096 --print (index, results [index])
Tercio@39 1097 if (type (results [index]) == "string") then
Tercio@39 1098 local result = results [index]:gsub (".-%\\", "")
Tercio@39 1099 iconwidget._icon.texture = results [index]
Tercio@39 1100 else
Tercio@39 1101 iconwidget._icon:SetTexture (results [index])
Tercio@39 1102 end
Tercio@20 1103
Tercio@20 1104 iconwidget:Show()
Tercio@49 1105
Tercio@49 1106 elseif (t.type == "texture") then
Tercio@49 1107 local texturewidget = row.texture_inuse [texture]
Tercio@49 1108 texture = texture + 1
Tercio@49 1109
Tercio@49 1110 texturewidget.line = index
Tercio@49 1111 texturewidget.index = real_index
Tercio@49 1112
Tercio@49 1113 if (type (results [index]) == "string") then
Tercio@49 1114 local result = results [index]:gsub (".-%\\", "")
Tercio@49 1115 texturewidget.texture = results [index]
Tercio@49 1116 else
Tercio@49 1117 texturewidget:SetTexture (results [index])
Tercio@49 1118 end
Tercio@49 1119
Tercio@49 1120 texturewidget:Show()
Tercio@11 1121 end
Tercio@11 1122 end
Tercio@11 1123 end
Tercio@20 1124
Tercio@11 1125 else
Tercio@11 1126 row:Hide()
Tercio@11 1127 end
Tercio@11 1128 else
Tercio@11 1129 row:Hide()
Tercio@11 1130 end
Tercio@11 1131 end
Tercio@11 1132 end
Tercio@11 1133
Tercio@11 1134 function panel:Refresh()
Tercio@22 1135 if (type (panel._totalfunc) == "boolean") then
Tercio@22 1136 --> not yet initialized
Tercio@22 1137 return
Tercio@22 1138 end
Tercio@20 1139 local filled_lines = panel._totalfunc (panel)
Tercio@17 1140 local scroll_total_lines = #panel.scrollframe.lines
Tercio@11 1141 local line_height = options.rowheight
Tercio@20 1142 refresh_fillbox (panel.scrollframe)
Tercio@11 1143 FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height)
Tercio@49 1144 panel.scrollframe:Show()
Tercio@11 1145 end
Tercio@11 1146
Tercio@11 1147 local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate")
Tercio@11 1148 scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end)
Tercio@11 1149 scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21)
Tercio@11 1150 scrollframe:SetPoint ("topright", panel.widget, "topright", -23, -21)
Tercio@11 1151 scrollframe:SetPoint ("bottomleft", panel.widget, "bottomleft")
Tercio@11 1152 scrollframe:SetPoint ("bottomright", panel.widget, "bottomright", -23, 0)
Tercio@11 1153 scrollframe:SetSize (w, h)
Tercio@11 1154 panel.scrollframe = scrollframe
Tercio@11 1155 scrollframe.lines = {}
Tercio@11 1156
Tercio@11 1157 --create lines
Tercio@22 1158 function panel:UpdateRowAmount()
Tercio@22 1159 local size = options.rowheight
Tercio@22 1160 local amount = math.floor (((panel._height-21) / size))
Tercio@22 1161
Tercio@22 1162 for i = #scrollframe.lines+1, amount do
Tercio@22 1163 local row = CreateFrame ("frame", panel:GetName() .. "Row_" .. i, panel.widget)
Tercio@22 1164 row:SetSize (1, size)
Tercio@22 1165 row.color = {1, 1, 1, .2}
Tercio@22 1166
Tercio@22 1167 row:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]]})
Tercio@22 1168
Tercio@22 1169 if (i%2 == 0) then
Tercio@22 1170 row:SetBackdropColor (.5, .5, .5, 0.2)
Tercio@22 1171 else
Tercio@22 1172 row:SetBackdropColor (1, 1, 1, 0.00)
Tercio@22 1173 end
Tercio@22 1174
Tercio@22 1175 row:SetPoint ("topleft", scrollframe, "topleft", 0, (i-1) * size * -1)
Tercio@22 1176 row:SetPoint ("topright", scrollframe, "topright", 0, (i-1) * size * -1)
Tercio@22 1177 tinsert (scrollframe.lines, row)
Tercio@22 1178
Tercio@22 1179 row.text_available = {}
Tercio@22 1180 row.text_inuse = {}
Tercio@22 1181 row.text_total = 0
Tercio@22 1182
Tercio@22 1183 row.entry_available = {}
Tercio@22 1184 row.entry_inuse = {}
Tercio@22 1185 row.entry_total = 0
Tercio@22 1186
Tercio@22 1187 row.button_available = {}
Tercio@22 1188 row.button_inuse = {}
Tercio@22 1189 row.button_total = 0
Tercio@22 1190
Tercio@22 1191 row.icon_available = {}
Tercio@22 1192 row.icon_inuse = {}
Tercio@22 1193 row.icon_total = 0
Tercio@49 1194
Tercio@49 1195 row.texture_available = {}
Tercio@49 1196 row.texture_inuse = {}
Tercio@49 1197 row.texture_total = 0
Tercio@20 1198 end
Tercio@11 1199 end
Tercio@22 1200 panel:UpdateRowAmount()
Tercio@22 1201
Tercio@20 1202 panel.AlignRows (panel)
Tercio@20 1203
Tercio@11 1204 return panel
Tercio@11 1205 end
Tercio@11 1206
Tercio@11 1207
Tercio@11 1208 ------------color pick
Tercio@11 1209 local color_pick_func = function()
Tercio@11 1210 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 1211 local a = OpacitySliderFrame:GetValue()
Tercio@11 1212 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 1213 end
Tercio@11 1214 local color_pick_func_cancel = function()
Tercio@11 1215 ColorPickerFrame:SetColorRGB (unpack (ColorPickerFrame.previousValues))
Tercio@11 1216 local r, g, b = ColorPickerFrame:GetColorRGB()
Tercio@11 1217 local a = OpacitySliderFrame:GetValue()
Tercio@11 1218 ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe)
Tercio@11 1219 end
Tercio@11 1220
Tercio@11 1221 function DF:ColorPick (frame, r, g, b, alpha, callback)
Tercio@11 1222
Tercio@11 1223 ColorPickerFrame:ClearAllPoints()
Tercio@11 1224 ColorPickerFrame:SetPoint ("bottomleft", frame, "topright", 0, 0)
Tercio@11 1225
Tercio@11 1226 ColorPickerFrame.dcallback = callback
Tercio@11 1227 ColorPickerFrame.dframe = frame
Tercio@11 1228
Tercio@11 1229 ColorPickerFrame.func = color_pick_func
Tercio@11 1230 ColorPickerFrame.opacityFunc = color_pick_func
Tercio@11 1231 ColorPickerFrame.cancelFunc = color_pick_func_cancel
Tercio@11 1232
Tercio@11 1233 ColorPickerFrame.opacity = alpha
Tercio@11 1234 ColorPickerFrame.hasOpacity = alpha and true
Tercio@11 1235
Tercio@11 1236 ColorPickerFrame.previousValues = {r, g, b}
Tercio@11 1237 ColorPickerFrame:SetParent (UIParent)
Tercio@11 1238 ColorPickerFrame:SetFrameStrata ("tooltip")
Tercio@11 1239 ColorPickerFrame:SetColorRGB (r, g, b)
Tercio@11 1240 ColorPickerFrame:Show()
Tercio@11 1241
Tercio@11 1242 end
Tercio@11 1243
Tercio@11 1244 ------------icon pick
Tercio@20 1245 function DF:IconPick (callback, close_when_select, param1, param2)
Tercio@11 1246
Tercio@11 1247 if (not DF.IconPickFrame) then
Tercio@11 1248
Tercio@11 1249 local string_lower = string.lower
Tercio@11 1250
Tercio@11 1251 DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent)
Tercio@11 1252 tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame")
Tercio@58 1253 DF.IconPickFrame:SetFrameStrata ("TOOLTIP")
Tercio@11 1254
Tercio@11 1255 DF.IconPickFrame:SetPoint ("center", UIParent, "center")
Tercio@11 1256 DF.IconPickFrame:SetWidth (350)
Tercio@58 1257 DF.IconPickFrame:SetHeight (277)
Tercio@11 1258 DF.IconPickFrame:EnableMouse (true)
Tercio@11 1259 DF.IconPickFrame:SetMovable (true)
Tercio@11 1260
Tercio@58 1261 DF:CreateTitleBar (DF.IconPickFrame, "Icon Picker")
Tercio@58 1262
Tercio@53 1263 DF.IconPickFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@53 1264
Tercio@53 1265 DF.IconPickFrame:SetBackdropBorderColor (0, 0, 0)
Tercio@11 1266 DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8)
Tercio@58 1267 DF.IconPickFrame:SetFrameLevel (5000)
Tercio@11 1268
Tercio@53 1269 DF.IconPickFrame:SetScript ("OnMouseDown", function (self)
Tercio@53 1270 if (not self.isMoving) then
Tercio@53 1271 DF.IconPickFrame:StartMoving()
Tercio@53 1272 self.isMoving = true
Tercio@53 1273 end
Tercio@53 1274 end)
Tercio@53 1275
Tercio@53 1276 DF.IconPickFrame:SetScript ("OnMouseUp", function (self)
Tercio@53 1277 if (self.isMoving) then
Tercio@53 1278 DF.IconPickFrame:StopMovingOrSizing()
Tercio@53 1279 self.isMoving = nil
Tercio@53 1280 end
Tercio@53 1281 end)
Tercio@53 1282
Tercio@11 1283 DF.IconPickFrame.emptyFunction = function() end
Tercio@11 1284 DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction
Tercio@11 1285
Tercio@11 1286 DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent)
Tercio@11 1287 DF.IconPickFrame.preview:SetFrameStrata ("tooltip")
Tercio@58 1288 DF.IconPickFrame.preview:SetFrameLevel (6001)
Tercio@11 1289 DF.IconPickFrame.preview:SetSize (76, 76)
Tercio@58 1290
Tercio@58 1291 local preview_image_bg = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
Tercio@58 1292 preview_image_bg:SetDrawLayer ("background", 0)
Tercio@58 1293 preview_image_bg:SetAllPoints (DF.IconPickFrame.preview)
Tercio@58 1294 preview_image_bg:SetColorTexture (0, 0, 0)
Tercio@58 1295
Tercio@11 1296 local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76)
Tercio@11 1297 preview_image:SetAllPoints (DF.IconPickFrame.preview)
Tercio@58 1298
Tercio@11 1299 DF.IconPickFrame.preview.icon = preview_image
Tercio@11 1300 DF.IconPickFrame.preview:Hide()
Tercio@11 1301
Tercio@58 1302 --serach
Tercio@11 1303 DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color)
Tercio@58 1304 DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -36)
Tercio@58 1305 DF.IconPickFrame.searchLabel:SetTemplate (DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
Tercio@58 1306
Tercio@11 1307 DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20)
Tercio@11 1308 DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0)
Tercio@58 1309 DF.IconPickFrame.search:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
Tercio@58 1310
Tercio@11 1311 DF.IconPickFrame.search:SetHook ("OnTextChanged", function()
Tercio@11 1312 DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText()
Tercio@11 1313 if (DF.IconPickFrame.searching == "") then
Tercio@11 1314 DF.IconPickFrameScroll:Show()
Tercio@11 1315 DF.IconPickFrame.searching = nil
Tercio@11 1316 DF.IconPickFrame.updateFunc()
Tercio@11 1317 else
Tercio@11 1318 DF.IconPickFrameScroll:Hide()
Tercio@11 1319 FauxScrollFrame_SetOffset (DF.IconPickFrame, 1)
Tercio@11 1320 DF.IconPickFrame.last_filter_index = 1
Tercio@11 1321 DF.IconPickFrame.updateFunc()
Tercio@11 1322 end
Tercio@11 1323 end)
Tercio@11 1324
Tercio@58 1325 --manually enter the icon path
Tercio@58 1326 DF.IconPickFrame.customIcon = DF:CreateLabel (DF.IconPickFrame, "Icon Path:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
Tercio@58 1327 DF.IconPickFrame.customIcon:SetPoint ("bottomleft", DF.IconPickFrame, "bottomleft", 12, 16)
Tercio@58 1328
Tercio@58 1329 DF.IconPickFrame.customIconEntry = DF:CreateTextEntry (DF.IconPickFrame, function()end, 200, 20, "CustomIconEntry", _, _, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
Tercio@58 1330 DF.IconPickFrame.customIconEntry:SetPoint ("left", DF.IconPickFrame.customIcon, "right", 2, 0)
Tercio@58 1331
Tercio@58 1332 DF.IconPickFrame.customIconEntry:SetHook ("OnTextChanged", function()
Tercio@58 1333 DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2)
Tercio@58 1334 DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText())
Tercio@58 1335 DF.IconPickFrame.preview:Show()
Tercio@58 1336 end)
Tercio@58 1337
Tercio@58 1338 DF.IconPickFrame.customIconEntry:SetHook ("OnEnter", function()
Tercio@58 1339 DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2)
Tercio@58 1340 DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText())
Tercio@58 1341 DF.IconPickFrame.preview:Show()
Tercio@58 1342 end)
Tercio@58 1343
Tercio@11 1344 --> close button
Tercio@11 1345 local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton")
Tercio@11 1346 close_button:SetWidth (32)
Tercio@11 1347 close_button:SetHeight (32)
Tercio@11 1348 close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7)
Tercio@11 1349 close_button:SetFrameLevel (close_button:GetFrameLevel()+2)
Tercio@58 1350 close_button:SetAlpha (0) --just hide, it is used below
Tercio@58 1351
Tercio@58 1352 --> accept custom icon button
Tercio@58 1353 local accept_custom_icon = function()
Tercio@58 1354 local path = DF.IconPickFrame.customIconEntry:GetText()
Tercio@58 1355
Tercio@58 1356 DF:QuickDispatch (DF.IconPickFrame.callback, path, DF.IconPickFrame.param1, DF.IconPickFrame.param2)
Tercio@58 1357
Tercio@58 1358 if (DF.IconPickFrame.click_close) then
Tercio@58 1359 close_button:Click()
Tercio@58 1360 end
Tercio@58 1361 end
Tercio@58 1362
Tercio@58 1363 DF.IconPickFrame.customIconAccept = DF:CreateButton (DF.IconPickFrame, accept_custom_icon, 82, 20, "Accept", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
Tercio@58 1364 DF.IconPickFrame.customIconAccept:SetPoint ("left", DF.IconPickFrame.customIconEntry, "right", 2, 0)
Tercio@58 1365
Tercio@58 1366 --fill with icons
Tercio@11 1367
Tercio@11 1368 local MACRO_ICON_FILENAMES = {}
Tercio@53 1369 local SPELLNAMES_CACHE = {}
Tercio@53 1370
Tercio@11 1371 DF.IconPickFrame:SetScript ("OnShow", function()
Tercio@53 1372
Tercio@53 1373 MACRO_ICON_FILENAMES [1] = "INV_MISC_QUESTIONMARK";
Tercio@11 1374 local index = 2;
Tercio@11 1375
Tercio@11 1376 for i = 1, GetNumSpellTabs() do
Tercio@53 1377 local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo (i)
Tercio@53 1378 offset = offset + 1
Tercio@53 1379 local tabEnd = offset + numSpells
Tercio@53 1380
Tercio@11 1381 for j = offset, tabEnd - 1 do
Tercio@11 1382 --to get spell info by slot, you have to pass in a pet argument
Tercio@53 1383 local spellType, ID = GetSpellBookItemInfo (j, "player")
Tercio@11 1384 if (spellType ~= "FUTURESPELL") then
Tercio@53 1385 MACRO_ICON_FILENAMES [index] = GetSpellBookItemTexture (j, "player") or 0
Tercio@53 1386 index = index + 1;
Tercio@53 1387
Tercio@53 1388 elseif (spellType == "FLYOUT") then
Tercio@53 1389 local _, _, numSlots, isKnown = GetFlyoutInfo (ID)
Tercio@11 1390 if (isKnown and numSlots > 0) then
Tercio@11 1391 for k = 1, numSlots do
Tercio@53 1392 local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo (ID, k)
Tercio@11 1393 if (isKnown) then
Tercio@53 1394 MACRO_ICON_FILENAMES [index] = GetSpellTexture (spellID) or 0
Tercio@11 1395 index = index + 1;
Tercio@11 1396 end
Tercio@11 1397 end
Tercio@11 1398 end
Tercio@53 1399
Tercio@11 1400 end
Tercio@11 1401 end
Tercio@11 1402 end
Tercio@11 1403
Tercio@11 1404 GetLooseMacroItemIcons (MACRO_ICON_FILENAMES)
Tercio@11 1405 GetLooseMacroIcons (MACRO_ICON_FILENAMES)
Tercio@11 1406 GetMacroIcons (MACRO_ICON_FILENAMES)
Tercio@53 1407 GetMacroItemIcons (MACRO_ICON_FILENAMES)
Tercio@58 1408
Tercio@58 1409 --reset the custom icon text entry
Tercio@58 1410 DF.IconPickFrame.customIconEntry:SetText ("")
Tercio@58 1411 --reset the search text entry
Tercio@58 1412 DF.IconPickFrame.search:SetText ("")
Tercio@11 1413 end)
Tercio@11 1414
Tercio@11 1415 DF.IconPickFrame:SetScript ("OnHide", function()
Tercio@53 1416 wipe (MACRO_ICON_FILENAMES)
Tercio@58 1417 DF.IconPickFrame.preview:Hide()
Tercio@11 1418 collectgarbage()
Tercio@11 1419 end)
Tercio@11 1420
Tercio@11 1421 DF.IconPickFrame.buttons = {}
Tercio@11 1422
Tercio@11 1423 local OnClickFunction = function (self)
Tercio@58 1424
Tercio@58 1425 DF:QuickDispatch (DF.IconPickFrame.callback, self.icon:GetTexture(), DF.IconPickFrame.param1, DF.IconPickFrame.param2)
Tercio@58 1426
Tercio@11 1427 if (DF.IconPickFrame.click_close) then
Tercio@11 1428 close_button:Click()
Tercio@11 1429 end
Tercio@11 1430 end
Tercio@11 1431
Tercio@11 1432 local onenter = function (self)
Tercio@11 1433 DF.IconPickFrame.preview:SetPoint ("bottom", self, "top", 0, 2)
Tercio@11 1434 DF.IconPickFrame.preview.icon:SetTexture (self.icon:GetTexture())
Tercio@11 1435 DF.IconPickFrame.preview:Show()
Tercio@11 1436 self.icon:SetBlendMode ("ADD")
Tercio@11 1437 end
Tercio@11 1438 local onleave = function (self)
Tercio@11 1439 DF.IconPickFrame.preview:Hide()
Tercio@11 1440 self.icon:SetBlendMode ("BLEND")
Tercio@11 1441 end
Tercio@11 1442
Tercio@11 1443 local backdrop = {bgFile = DF.folder .. "background", tile = true, tileSize = 16,
Tercio@11 1444 insets = {left = 0, right = 0, top = 0, bottom = 0}, edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 10}
Tercio@11 1445
Tercio@11 1446 for i = 0, 9 do
Tercio@11 1447 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..(i+1), DF.IconPickFrame)
Tercio@11 1448 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..(i+1).."Icon", "overlay")
Tercio@11 1449 newcheck.icon = image
Tercio@11 1450 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1451 newcheck:SetSize (30, 28)
Tercio@11 1452 newcheck:SetBackdrop (backdrop)
Tercio@11 1453
Tercio@11 1454 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1455 newcheck.param1 = i+1
Tercio@11 1456
Tercio@58 1457 newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -60)
Tercio@11 1458 newcheck:SetID (i+1)
Tercio@11 1459 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1460 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1461 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1462 end
Tercio@11 1463 for i = 11, 20 do
Tercio@11 1464 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1465 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1466 newcheck.icon = image
Tercio@11 1467 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1468 newcheck:SetSize (30, 28)
Tercio@11 1469 newcheck:SetBackdrop (backdrop)
Tercio@11 1470
Tercio@11 1471 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1472 newcheck.param1 = i
Tercio@11 1473
Tercio@11 1474 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1475 newcheck:SetID (i)
Tercio@11 1476 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1477 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1478 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1479 end
Tercio@11 1480 for i = 21, 30 do
Tercio@11 1481 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1482 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1483 newcheck.icon = image
Tercio@11 1484 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1485 newcheck:SetSize (30, 28)
Tercio@11 1486 newcheck:SetBackdrop (backdrop)
Tercio@11 1487
Tercio@11 1488 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1489 newcheck.param1 = i
Tercio@11 1490
Tercio@11 1491 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1492 newcheck:SetID (i)
Tercio@11 1493 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1494 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1495 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1496 end
Tercio@11 1497 for i = 31, 40 do
Tercio@11 1498 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1499 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1500 newcheck.icon = image
Tercio@11 1501 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1502 newcheck:SetSize (30, 28)
Tercio@11 1503 newcheck:SetBackdrop (backdrop)
Tercio@11 1504
Tercio@11 1505 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1506 newcheck.param1 = i
Tercio@11 1507
Tercio@11 1508 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1509 newcheck:SetID (i)
Tercio@11 1510 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1511 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1512 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1513 end
Tercio@11 1514 for i = 41, 50 do
Tercio@11 1515 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1516 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1517 newcheck.icon = image
Tercio@11 1518 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1519 newcheck:SetSize (30, 28)
Tercio@11 1520 newcheck:SetBackdrop (backdrop)
Tercio@11 1521
Tercio@11 1522 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1523 newcheck.param1 = i
Tercio@11 1524
Tercio@11 1525 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1526 newcheck:SetID (i)
Tercio@11 1527 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1528 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1529 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1530 end
Tercio@11 1531 for i = 51, 60 do
Tercio@11 1532 local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame)
Tercio@11 1533 local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay")
Tercio@11 1534 newcheck.icon = image
Tercio@11 1535 image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2)
Tercio@11 1536 newcheck:SetSize (30, 28)
Tercio@11 1537 newcheck:SetBackdrop (backdrop)
Tercio@11 1538
Tercio@11 1539 newcheck:SetScript ("OnClick", OnClickFunction)
Tercio@11 1540 newcheck.param1 = i
Tercio@11 1541
Tercio@11 1542 newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1)
Tercio@11 1543 newcheck:SetID (i)
Tercio@11 1544 DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck
Tercio@11 1545 newcheck:SetScript ("OnEnter", onenter)
Tercio@11 1546 newcheck:SetScript ("OnLeave", onleave)
Tercio@11 1547 end
Tercio@11 1548
Tercio@11 1549 local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate")
Tercio@58 1550 DF:ReskinSlider (scroll)
Tercio@11 1551
Tercio@11 1552 local ChecksFrame_Update = function (self)
Tercio@11 1553
Tercio@11 1554 local numMacroIcons = #MACRO_ICON_FILENAMES
Tercio@11 1555 local macroPopupIcon, macroPopupButton
Tercio@11 1556 local macroPopupOffset = FauxScrollFrame_GetOffset (scroll)
Tercio@11 1557 local index
Tercio@11 1558
Tercio@11 1559 local texture
Tercio@11 1560 local filter
Tercio@11 1561 if (DF.IconPickFrame.searching) then
Tercio@11 1562 filter = string_lower (DF.IconPickFrame.searching)
Tercio@11 1563 end
Tercio@53 1564
Tercio@53 1565 local pool
Tercio@53 1566 local shown = 0
Tercio@11 1567
Tercio@11 1568 if (filter and filter ~= "") then
Tercio@53 1569 if (#SPELLNAMES_CACHE == 0) then
Tercio@53 1570 --build name cache
Tercio@53 1571 local GetSpellInfo = GetSpellInfo
Tercio@53 1572 for i = 1, #MACRO_ICON_FILENAMES do
Tercio@53 1573 local spellName = GetSpellInfo (MACRO_ICON_FILENAMES [i])
Tercio@53 1574 SPELLNAMES_CACHE [i] = spellName or "NULL"
Tercio@11 1575 end
Tercio@11 1576 end
Tercio@53 1577
Tercio@53 1578 --do the filter
Tercio@53 1579 pool = {}
Tercio@53 1580 for i = 1, #SPELLNAMES_CACHE do
Tercio@53 1581 if (SPELLNAMES_CACHE [i]:find (filter)) then
Tercio@53 1582 pool [#pool+1] = MACRO_ICON_FILENAMES [i]
Tercio@53 1583 shown = shown + 1
Tercio@53 1584 end
Tercio@53 1585 end
Tercio@53 1586 else
Tercio@53 1587 shown = nil
Tercio@53 1588 end
Tercio@11 1589
Tercio@53 1590 if (not pool) then
Tercio@53 1591 pool = MACRO_ICON_FILENAMES
Tercio@53 1592 end
Tercio@53 1593
Tercio@53 1594 for i = 1, 60 do
Tercio@53 1595 macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"]
Tercio@53 1596 macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i]
Tercio@53 1597 index = (macroPopupOffset * 10) + i
Tercio@53 1598 texture = pool [index]
Tercio@53 1599 if ( index <= numMacroIcons and texture ) then
Tercio@53 1600
Tercio@53 1601 if (type (texture) == "number") then
Tercio@53 1602 macroPopupIcon:SetTexture (texture)
Tercio@53 1603 else
Tercio@53 1604 macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture)
Tercio@53 1605 end
Tercio@53 1606
Tercio@53 1607 macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64)
Tercio@53 1608 macroPopupButton.IconID = index
Tercio@53 1609 macroPopupButton:Show()
Tercio@53 1610 else
Tercio@11 1611 macroPopupButton:Hide()
Tercio@11 1612 end
Tercio@53 1613 end
Tercio@11 1614
Tercio@53 1615 pool = nil
Tercio@11 1616
Tercio@11 1617 -- Scrollbar stuff
Tercio@53 1618 FauxScrollFrame_Update (scroll, ceil ((shown or numMacroIcons) / 10) , 5, 20 )
Tercio@11 1619 end
Tercio@11 1620
Tercio@11 1621 DF.IconPickFrame.updateFunc = ChecksFrame_Update
Tercio@11 1622
Tercio@58 1623 scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -58)
Tercio@11 1624 scroll:SetWidth (330)
Tercio@11 1625 scroll:SetHeight (178)
Tercio@11 1626 scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end)
Tercio@11 1627 scroll.update = ChecksFrame_Update
Tercio@11 1628 DF.IconPickFrameScroll = scroll
Tercio@11 1629 DF.IconPickFrame:Hide()
Tercio@11 1630
Tercio@11 1631 end
Tercio@11 1632
Tercio@20 1633 DF.IconPickFrame.param1, DF.IconPickFrame.param2 = param1, param2
Tercio@20 1634
Tercio@11 1635 DF.IconPickFrame:Show()
Tercio@11 1636 DF.IconPickFrameScroll.update (DF.IconPickFrameScroll)
Tercio@11 1637 DF.IconPickFrame.callback = callback or DF.IconPickFrame.emptyFunction
Tercio@11 1638 DF.IconPickFrame.click_close = close_when_select
Tercio@11 1639
Tercio@11 1640 end
Tercio@11 1641
Tercioo@29 1642 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercioo@29 1643
Tercioo@29 1644 function DF:ShowPanicWarning (text)
Tercioo@29 1645 if (not DF.PanicWarningWindow) then
Tercioo@29 1646 DF.PanicWarningWindow = CreateFrame ("frame", "DetailsFrameworkPanicWarningWindow", UIParent)
Tercioo@29 1647 DF.PanicWarningWindow:SetHeight (80)
Tercioo@29 1648 DF.PanicWarningWindow:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercioo@29 1649 DF.PanicWarningWindow:SetBackdropColor (1, 0, 0, 0.2)
Tercioo@29 1650 DF.PanicWarningWindow:SetPoint ("topleft", UIParent, "topleft", 0, -250)
Tercioo@29 1651 DF.PanicWarningWindow:SetPoint ("topright", UIParent, "topright", 0, -250)
Tercioo@29 1652
Tercioo@29 1653 DF.PanicWarningWindow.text = DF.PanicWarningWindow:CreateFontString (nil, "overlay", "GameFontNormal")
Tercioo@29 1654 DF.PanicWarningWindow.text:SetPoint ("center", DF.PanicWarningWindow, "center")
Tercioo@29 1655 DF.PanicWarningWindow.text:SetTextColor (1, 0.6, 0)
Tercioo@29 1656 end
Tercioo@29 1657
Tercioo@29 1658 DF.PanicWarningWindow.text:SetText (text)
Tercioo@29 1659 DF.PanicWarningWindow:Show()
Tercioo@29 1660 end
Tercioo@29 1661
Tercioo@29 1662 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercioo@29 1663
Tercioo@29 1664
Tercio@11 1665 local simple_panel_mouse_down = function (self, button)
Tercio@11 1666 if (button == "RightButton") then
Tercio@11 1667 if (self.IsMoving) then
Tercio@11 1668 self.IsMoving = false
Tercio@11 1669 self:StopMovingOrSizing()
Tercio@11 1670 if (self.db and self.db.position) then
Tercio@11 1671 DF:SavePositionOnScreen (self)
Tercio@11 1672 end
Tercio@11 1673 end
Tercio@17 1674 if (not self.DontRightClickClose) then
Tercio@17 1675 self:Hide()
Tercio@17 1676 end
Tercio@11 1677 return
Tercio@11 1678 end
Tercio@11 1679 if (not self.IsMoving and not self.IsLocked) then
Tercio@11 1680 self.IsMoving = true
Tercio@11 1681 self:StartMoving()
Tercio@11 1682 end
Tercio@11 1683 end
Tercio@11 1684 local simple_panel_mouse_up = function (self, button)
Tercio@11 1685 if (self.IsMoving) then
Tercio@11 1686 self.IsMoving = false
Tercio@11 1687 self:StopMovingOrSizing()
Tercio@11 1688 if (self.db and self.db.position) then
Tercio@11 1689 DF:SavePositionOnScreen (self)
Tercio@11 1690 end
Tercio@11 1691 end
Tercio@11 1692 end
Tercio@11 1693 local simple_panel_settitle = function (self, title)
Tercio@22 1694 self.Title:SetText (title)
Tercio@11 1695 end
Tercio@11 1696
Tercio@22 1697 local simple_panel_close_click = function (self)
Tercio@22 1698 self:GetParent():GetParent():Hide()
Tercio@22 1699 end
Tercio@22 1700
Tercio@22 1701 local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}
Tercio@22 1702 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9}
Tercio@22 1703 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1}
Tercio@22 1704
Tercio@58 1705 --with_label was making the frame stay in place while its parent moves
Tercio@58 1706 --the slider was anchoring to with_label and here here were anchoring the slider again
Tercio@39 1707 function DF:CreateScaleBar (frame, config)
Tercio@58 1708 local scaleBar, text = DF:CreateSlider (frame, 120, 14, 0.6, 1.6, 0.1, config.scale, true, "ScaleBar", nil, "Scale:", DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE"), DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
Tercio@58 1709 --scaleBar:SetPoint ("right", frame.Close, "left", -26, 0)
Tercio@58 1710 text:SetPoint ("topleft", frame, "topleft", 12, -7)
Tercio@39 1711 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
Tercio@39 1712 scaleBar.OnValueChanged = function (_, _, value)
Tercio@39 1713 config.scale = value
Tercio@39 1714 if (not scaleBar.IsValueChanging) then
Tercio@39 1715 frame:SetScale (config.scale)
Tercio@39 1716 end
Tercio@39 1717 end
Tercio@39 1718 scaleBar:SetHook ("OnMouseUp", function()
Tercio@39 1719 frame:SetScale (config.scale)
Tercio@39 1720 end)
Tercio@58 1721
Tercio@58 1722 scaleBar:SetAlpha (0.2)
Tercio@58 1723
Tercio@58 1724 return scaleBar
Tercio@39 1725 end
Tercio@39 1726
Tercio@26 1727 local no_options = {}
Tercio@39 1728 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db)
Tercio@49 1729
Tercio@39 1730 if (db and name and not db [name]) then
Tercio@39 1731 db [name] = {scale = 1}
Tercio@39 1732 end
Tercio@11 1733
Tercio@11 1734 if (not name) then
Tercioo@29 1735 name = "DetailsFrameworkSimplePanel" .. DF.SimplePanelCounter
Tercioo@29 1736 DF.SimplePanelCounter = DF.SimplePanelCounter + 1
Tercio@11 1737 end
Tercio@11 1738 if (not parent) then
Tercio@11 1739 parent = UIParent
Tercio@11 1740 end
Tercio@26 1741
Tercio@26 1742 panel_options = panel_options or no_options
Tercio@49 1743
Tercio@11 1744 local f = CreateFrame ("frame", name, UIParent)
Tercio@11 1745 f:SetSize (w or 400, h or 250)
Tercio@11 1746 f:SetPoint ("center", UIParent, "center", 0, 0)
Tercio@11 1747 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 1748 f:EnableMouse()
Tercio@11 1749 f:SetMovable (true)
Tercio@22 1750 f:SetBackdrop (SimplePanel_frame_backdrop)
Tercio@22 1751 f:SetBackdropColor (unpack (SimplePanel_frame_backdrop_color))
Tercio@22 1752 f:SetBackdropBorderColor (unpack (SimplePanel_frame_backdrop_border_color))
Tercio@26 1753
Tercio@26 1754 f.DontRightClickClose = panel_options.DontRightClickClose
Tercio@26 1755
Tercio@26 1756 if (not panel_options.NoTUISpecialFrame) then
Tercio@26 1757 tinsert (UISpecialFrames, name)
Tercio@26 1758 end
Tercio@22 1759
Tercio@22 1760 local title_bar = CreateFrame ("frame", name .. "TitleBar", f)
Tercio@22 1761 title_bar:SetPoint ("topleft", f, "topleft", 2, -3)
Tercio@22 1762 title_bar:SetPoint ("topright", f, "topright", -2, -3)
Tercio@22 1763 title_bar:SetHeight (20)
Tercio@22 1764 title_bar:SetBackdrop (SimplePanel_frame_backdrop)
Tercio@22 1765 title_bar:SetBackdropColor (.2, .2, .2, 1)
Tercio@22 1766 title_bar:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@26 1767 f.TitleBar = title_bar
Tercio@22 1768
Tercio@22 1769 local close = CreateFrame ("button", name and name .. "CloseButton", title_bar)
Tercio@39 1770 close:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
Tercio@22 1771 close:SetSize (16, 16)
Tercio@22 1772 close:SetNormalTexture (DF.folder .. "icons")
Tercio@22 1773 close:SetHighlightTexture (DF.folder .. "icons")
Tercio@22 1774 close:SetPushedTexture (DF.folder .. "icons")
Tercio@22 1775 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@22 1776 close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@22 1777 close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@22 1778 close:SetAlpha (0.7)
Tercio@22 1779 close:SetScript ("OnClick", simple_panel_close_click)
Tercio@22 1780 f.Close = close
Tercio@22 1781
Tercio@22 1782 local title_string = title_bar:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal")
Tercio@22 1783 title_string:SetTextColor (.8, .8, .8, 1)
Tercio@22 1784 title_string:SetText (title or "")
Tercio@22 1785 f.Title = title_string
Tercio@22 1786
Tercio@39 1787 if (panel_options.UseScaleBar and db [name]) then
Tercio@39 1788 DF:CreateScaleBar (f, db [name])
Tercio@39 1789 f:SetScale (db [name].scale)
Tercio@39 1790 end
Tercio@39 1791
Tercio@22 1792 f.Title:SetPoint ("center", title_bar, "center")
Tercio@22 1793 f.Close:SetPoint ("right", title_bar, "right", -2, 0)
Tercio@22 1794
Tercio@11 1795 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1796 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1797
Tercio@11 1798 f.SetTitle = simple_panel_settitle
Tercio@11 1799
Tercio@11 1800 return f
Tercio@11 1801 end
Tercio@11 1802
Tercio@11 1803 local Panel1PxBackdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 64,
Tercio@11 1804 edgeFile = DF.folder .. "border_3", edgeSize = 9, insets = {left = 2, right = 2, top = 3, bottom = 3}}
Tercio@11 1805
Tercio@11 1806 local Panel1PxOnClickClose = function (self)
Tercio@11 1807 self:GetParent():Hide()
Tercio@11 1808 end
Tercio@11 1809 local Panel1PxOnToggleLock = function (self)
Tercio@11 1810 if (self.IsLocked) then
Tercio@11 1811 self.IsLocked = false
Tercio@11 1812 self:SetMovable (true)
Tercio@11 1813 self:EnableMouse (true)
Tercio@11 1814 self.Lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1815 self.Lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1816 self.Lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@17 1817 if (self.OnUnlock) then
Tercio@17 1818 self:OnUnlock()
Tercio@17 1819 end
Tercio@17 1820 if (self.db) then
Tercio@17 1821 self.db.IsLocked = self.IsLocked
Tercio@17 1822 end
Tercio@11 1823 else
Tercio@11 1824 self.IsLocked = true
Tercio@11 1825 self:SetMovable (false)
Tercio@11 1826 self:EnableMouse (false)
Tercio@11 1827 self.Lock:GetNormalTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1828 self.Lock:GetHighlightTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@11 1829 self.Lock:GetPushedTexture():SetTexCoord (16/128, 32/128, 0, 1)
Tercio@17 1830 if (self.OnLock) then
Tercio@17 1831 self:OnLock()
Tercio@17 1832 end
Tercio@17 1833 if (self.db) then
Tercio@17 1834 self.db.IsLocked = self.IsLocked
Tercio@17 1835 end
Tercio@11 1836 end
Tercio@11 1837 end
Tercio@11 1838 local Panel1PxOnClickLock = function (self)
Tercio@11 1839 local f = self:GetParent()
Tercio@11 1840 Panel1PxOnToggleLock (f)
Tercio@11 1841 end
Tercio@11 1842 local Panel1PxSetTitle = function (self, text)
Tercio@11 1843 self.Title:SetText (text or "")
Tercio@11 1844 end
Tercio@11 1845
Tercio@20 1846 local Panel1PxSetLocked= function (self, lock_state)
Tercio@20 1847 if (type (lock_state) ~= "boolean") then
Tercio@20 1848 return
Tercio@20 1849 end
Tercio@20 1850 if (lock_state) then
Tercio@20 1851 -- lock it
Tercio@20 1852 self.IsLocked = false
Tercio@20 1853 Panel1PxOnClickLock (self.Lock)
Tercio@20 1854 else
Tercio@20 1855 -- unlockit
Tercio@20 1856 self.IsLocked = true
Tercio@20 1857 Panel1PxOnClickLock (self.Lock)
Tercio@20 1858 end
Tercio@20 1859 end
Tercio@20 1860
Tercio@11 1861 local Panel1PxReadConfig = function (self)
Tercio@11 1862 local db = self.db
Tercio@11 1863 if (db) then
Tercio@11 1864 db.IsLocked = db.IsLocked or false
Tercio@11 1865 self.IsLocked = db.IsLocked
Tercio@11 1866 db.position = db.position or {x = 0, y = 0}
Tercio@19 1867 db.position.x = db.position.x or 0
Tercio@19 1868 db.position.y = db.position.y or 0
Tercio@11 1869 DF:RestoreFramePosition (self)
Tercio@11 1870 end
Tercio@11 1871 end
Tercio@11 1872
Tercio@11 1873 function DF:SavePositionOnScreen (frame)
Tercio@11 1874 if (frame.db and frame.db.position) then
Tercio@11 1875 local x, y = DF:GetPositionOnScreen (frame)
Tercio@18 1876 --print ("saving...", x, y, frame:GetName())
Tercio@19 1877 if (x and y) then
Tercio@19 1878 frame.db.position.x, frame.db.position.y = x, y
Tercio@19 1879 end
Tercio@11 1880 end
Tercio@11 1881 end
Tercio@11 1882
Tercio@11 1883 function DF:GetPositionOnScreen (frame)
Tercio@11 1884 local xOfs, yOfs = frame:GetCenter()
Tercio@11 1885 if (not xOfs) then
Tercio@11 1886 return
Tercio@11 1887 end
Tercio@11 1888 local scale = frame:GetEffectiveScale()
Tercio@11 1889 local UIscale = UIParent:GetScale()
Tercio@11 1890 xOfs = xOfs*scale - GetScreenWidth()*UIscale/2
Tercio@11 1891 yOfs = yOfs*scale - GetScreenHeight()*UIscale/2
Tercio@11 1892 return xOfs/UIscale, yOfs/UIscale
Tercio@11 1893 end
Tercio@11 1894
Tercio@11 1895 function DF:RestoreFramePosition (frame)
Tercio@11 1896 if (frame.db and frame.db.position) then
Tercio@11 1897 local scale, UIscale = frame:GetEffectiveScale(), UIParent:GetScale()
Tercio@11 1898 frame:ClearAllPoints()
Tercio@19 1899 frame.db.position.x = frame.db.position.x or 0
Tercio@19 1900 frame.db.position.y = frame.db.position.y or 0
Tercio@11 1901 frame:SetPoint ("center", UIParent, "center", frame.db.position.x * UIscale / scale, frame.db.position.y * UIscale / scale)
Tercio@11 1902 end
Tercio@11 1903 end
Tercio@11 1904
Tercio@20 1905 local Panel1PxSavePosition= function (self)
Tercio@20 1906 DF:SavePositionOnScreen (self)
Tercio@20 1907 end
Tercio@20 1908
Tercio@18 1909 local Panel1PxHasPosition = function (self)
Tercio@18 1910 local db = self.db
Tercio@18 1911 if (db) then
Tercio@18 1912 if (db.position and db.position.x and (db.position.x ~= 0 or db.position.y ~= 0)) then
Tercio@18 1913 return true
Tercio@18 1914 end
Tercio@18 1915 end
Tercio@18 1916 end
Tercio@18 1917
Tercio@13 1918 function DF:Create1PxPanel (parent, w, h, title, name, config, title_anchor, no_special_frame)
Tercio@11 1919 local f = CreateFrame ("frame", name, parent or UIParent)
Tercio@11 1920 f:SetSize (w or 100, h or 75)
Tercio@11 1921 f:SetPoint ("center", UIParent, "center")
Tercio@11 1922
Tercio@13 1923 if (name and not no_special_frame) then
Tercio@11 1924 tinsert (UISpecialFrames, name)
Tercio@11 1925 end
Tercio@11 1926
Tercio@11 1927 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
Tercio@11 1928 f:SetScript ("OnMouseUp", simple_panel_mouse_up)
Tercio@11 1929
Tercio@11 1930 f:SetBackdrop (Panel1PxBackdrop)
Tercio@11 1931 f:SetBackdropColor (0, 0, 0, 0.5)
Tercio@11 1932
Tercio@17 1933 f.IsLocked = (config and config.IsLocked ~= nil and config.IsLocked) or false
Tercio@11 1934 f:SetMovable (true)
Tercio@11 1935 f:EnableMouse (true)
Tercio@11 1936 f:SetUserPlaced (true)
Tercio@11 1937
Tercio@11 1938 f.db = config
Tercio@18 1939 --print (config.position.x, config.position.x)
Tercio@11 1940 Panel1PxReadConfig (f)
Tercio@11 1941
Tercio@11 1942 local close = CreateFrame ("button", name and name .. "CloseButton", f)
Tercio@11 1943 close:SetSize (16, 16)
Tercio@11 1944 close:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1945 close:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1946 close:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1947 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1948 close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1949 close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@11 1950 close:SetAlpha (0.7)
Tercio@11 1951
Tercio@11 1952 local lock = CreateFrame ("button", name and name .. "LockButton", f)
Tercio@11 1953 lock:SetSize (16, 16)
Tercio@11 1954 lock:SetNormalTexture (DF.folder .. "icons")
Tercio@11 1955 lock:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 1956 lock:SetPushedTexture (DF.folder .. "icons")
Tercio@11 1957 lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1958 lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1959 lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1)
Tercio@11 1960 lock:SetAlpha (0.7)
Tercio@11 1961
Tercio@11 1962 close:SetPoint ("topright", f, "topright", -3, -3)
Tercio@11 1963 lock:SetPoint ("right", close, "left", 3, 0)
Tercio@11 1964
Tercio@11 1965 close:SetScript ("OnClick", Panel1PxOnClickClose)
Tercio@11 1966 lock:SetScript ("OnClick", Panel1PxOnClickLock)
Tercio@11 1967
Tercio@11 1968 local title_string = f:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal")
Tercio@11 1969 title_string:SetPoint ("topleft", f, "topleft", 5, -5)
Tercio@11 1970 title_string:SetText (title or "")
Tercio@11 1971
Tercio@11 1972 if (title_anchor) then
Tercio@11 1973 if (title_anchor == "top") then
Tercio@11 1974 title_string:ClearAllPoints()
Tercio@11 1975 title_string:SetPoint ("bottomleft", f, "topleft", 0, 0)
Tercio@11 1976 close:ClearAllPoints()
Tercio@11 1977 close:SetPoint ("bottomright", f, "topright", 0, 0)
Tercio@11 1978 end
Tercio@11 1979 f.title_anchor = title_anchor
Tercio@11 1980 end
Tercio@11 1981
Tercio@11 1982 f.SetTitle = Panel1PxSetTitle
Tercio@11 1983 f.Title = title_string
Tercio@11 1984 f.Lock = lock
Tercio@11 1985 f.Close = close
Tercio@18 1986 f.HasPosition = Panel1PxHasPosition
Tercio@20 1987 f.SavePosition = Panel1PxSavePosition
Tercio@11 1988
Tercio@17 1989 f.IsLocked = not f.IsLocked
Tercio@20 1990 f.SetLocked = Panel1PxSetLocked
Tercio@17 1991 Panel1PxOnToggleLock (f)
Tercio@17 1992
Tercio@11 1993 return f
Tercio@11 1994 end
Tercio@11 1995
Tercio@11 1996 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@20 1997 -- ~prompt
Tercio@20 1998 function DF:ShowPromptPanel (message, func_true, func_false)
Tercio@20 1999
Tercio@20 2000 if (not DF.prompt_panel) then
Tercio@20 2001 local f = CreateFrame ("frame", "DetailsFrameworkPrompt", UIParent)
Tercio@22 2002 f:SetSize (400, 65)
Tercio@20 2003 f:SetFrameStrata ("DIALOG")
Tercio@22 2004 f:SetPoint ("center", UIParent, "center", 0, 300)
Tercio@20 2005 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@20 2006 f:SetBackdropColor (0, 0, 0, 0.8)
Tercio@20 2007 f:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@20 2008
Tercio@22 2009 local prompt = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@22 2010 prompt:SetPoint ("top", f, "top", 0, -15)
Tercio@22 2011 prompt:SetJustifyH ("center")
Tercio@22 2012 f.prompt = prompt
Tercio@22 2013
Tercio@22 2014 local button_true = DF:CreateButton (f, nil, 60, 20, "Yes")
Tercio@20 2015 button_true:SetPoint ("bottomleft", f, "bottomleft", 5, 5)
Tercio@20 2016 f.button_true = button_true
Tercio@20 2017
Tercio@22 2018 local button_false = DF:CreateButton (f, nil, 60, 20, "No")
Tercio@20 2019 button_false:SetPoint ("bottomright", f, "bottomright", -5, 5)
Tercio@20 2020 f.button_false = button_false
Tercio@20 2021
Tercio@20 2022 button_true:SetClickFunction (function()
Tercio@20 2023 local my_func = button_true.true_function
Tercio@20 2024 if (my_func) then
Tercio@20 2025 local okey, errormessage = pcall (my_func, true)
Tercio@20 2026 if (not okey) then
Tercio@20 2027 print ("error:", errormessage)
Tercio@20 2028 end
Tercio@22 2029 f:Hide()
Tercio@20 2030 end
Tercio@20 2031 end)
Tercio@20 2032
Tercio@20 2033 button_false:SetClickFunction (function()
Tercio@20 2034 local my_func = button_false.false_function
Tercio@20 2035 if (my_func) then
Tercio@20 2036 local okey, errormessage = pcall (my_func, true)
Tercio@20 2037 if (not okey) then
Tercio@20 2038 print ("error:", errormessage)
Tercio@20 2039 end
Tercio@22 2040 f:Hide()
Tercio@20 2041 end
Tercio@20 2042 end)
Tercio@20 2043
Tercio@20 2044 f:Hide()
Tercio@20 2045 DF.promtp_panel = f
Tercio@20 2046 end
Tercio@20 2047
Tercio@20 2048 assert (type (func_true) == "function" and type (func_false) == "function", "ShowPromptPanel expects two functions.")
Tercio@20 2049
Tercio@22 2050 DF.promtp_panel.prompt:SetText (message)
Tercio@20 2051 DF.promtp_panel.button_true.true_function = func_true
Tercio@20 2052 DF.promtp_panel.button_false.false_function = func_false
Tercio@20 2053
Tercio@20 2054 DF.promtp_panel:Show()
Tercio@20 2055 end
Tercio@22 2056
Tercio@22 2057
Tercio@22 2058 function DF:ShowTextPromptPanel (message, callback)
Tercio@22 2059
Tercio@22 2060 if (not DF.text_prompt_panel) then
Tercio@22 2061
Tercio@22 2062 local f = CreateFrame ("frame", "DetailsFrameworkPrompt", UIParent)
Tercio@22 2063 f:SetSize (400, 100)
Tercio@22 2064 f:SetFrameStrata ("DIALOG")
Tercio@22 2065 f:SetPoint ("center", UIParent, "center", 0, 300)
Tercio@22 2066 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@22 2067 f:SetBackdropColor (0, 0, 0, 0.8)
Tercio@22 2068 f:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@22 2069
Tercio@22 2070 local prompt = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@22 2071 prompt:SetPoint ("top", f, "top", 0, -15)
Tercio@22 2072 prompt:SetJustifyH ("center")
Tercio@22 2073 f.prompt = prompt
Tercioo@29 2074
Tercioo@29 2075 local button_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
Tercioo@29 2076 local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
Tercioo@29 2077
Tercioo@29 2078 local button_true = DF:CreateButton (f, nil, 60, 20, "Okey", nil, nil, nil, nil, nil, nil, options_dropdown_template, button_text_template)
Tercio@22 2079 button_true:SetPoint ("bottomleft", f, "bottomleft", 10, 5)
Tercio@22 2080 f.button_true = button_true
Tercio@22 2081
Tercioo@29 2082 local button_false = DF:CreateButton (f, function() f.textbox:ClearFocus(); f:Hide() end, 60, 20, "Cancel", nil, nil, nil, nil, nil, nil, options_dropdown_template, button_text_template)
Tercio@22 2083 button_false:SetPoint ("bottomright", f, "bottomright", -10, 5)
Tercio@22 2084 f.button_false = button_false
Tercio@22 2085
Tercioo@29 2086 local textbox = DF:CreateTextEntry (f, function()end, 380, 20, "textbox", nil, nil, options_dropdown_template)
Tercio@22 2087 textbox:SetPoint ("topleft", f, "topleft", 10, -45)
Tercioo@29 2088 f.EntryBox = textbox
Tercio@22 2089
Tercio@22 2090 button_true:SetClickFunction (function()
Tercio@22 2091 local my_func = button_true.true_function
Tercio@22 2092 if (my_func) then
Tercio@22 2093 local okey, errormessage = pcall (my_func, textbox:GetText())
Tercio@22 2094 textbox:ClearFocus()
Tercio@22 2095 if (not okey) then
Tercio@22 2096 print ("error:", errormessage)
Tercio@22 2097 end
Tercio@22 2098 f:Hide()
Tercio@22 2099 end
Tercio@22 2100 end)
Tercio@22 2101
Tercio@22 2102 f:Hide()
Tercio@22 2103 DF.text_prompt_panel = f
Tercio@22 2104 end
Tercio@22 2105
Tercio@22 2106 DF.text_prompt_panel:Show()
Tercio@22 2107
Tercioo@29 2108 DetailsFrameworkPrompt.EntryBox:SetText ("")
Tercio@22 2109 DF.text_prompt_panel.prompt:SetText (message)
Tercio@22 2110 DF.text_prompt_panel.button_true.true_function = callback
Tercioo@29 2111
Tercio@22 2112 DF.text_prompt_panel.textbox:SetFocus (true)
Tercio@22 2113
Tercio@22 2114 end
Tercio@22 2115
Tercio@20 2116 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 2117 --> options button -- ~options
Tercio@11 2118 function DF:CreateOptionsButton (parent, callback, name)
Tercio@11 2119
Tercio@11 2120 local b = CreateFrame ("button", name, parent)
Tercio@11 2121 b:SetSize (14, 14)
Tercio@11 2122 b:SetNormalTexture (DF.folder .. "icons")
Tercio@11 2123 b:SetHighlightTexture (DF.folder .. "icons")
Tercio@11 2124 b:SetPushedTexture (DF.folder .. "icons")
Tercio@11 2125 b:GetNormalTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 2126 b:GetHighlightTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 2127 b:GetPushedTexture():SetTexCoord (48/128, 64/128, 0, 1)
Tercio@11 2128 b:SetAlpha (0.7)
Tercio@11 2129
Tercio@11 2130 b:SetScript ("OnClick", callback)
Tercio@11 2131 b:SetScript ("OnEnter", function (self)
Tercio@11 2132 GameCooltip2:Reset()
Tercio@11 2133 GameCooltip2:AddLine ("Options")
Tercio@11 2134 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 2135 end)
Tercio@11 2136 b:SetScript ("OnLeave", function (self)
Tercio@11 2137 GameCooltip2:Hide()
Tercio@11 2138 end)
Tercio@11 2139
Tercio@11 2140 return b
Tercio@11 2141
Tercio@11 2142 end
Tercio@11 2143
Tercio@11 2144 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 2145 --> feedback panel -- ~feedback
Tercio@11 2146
Tercio@11 2147 function DF:CreateFeedbackButton (parent, callback, name)
Tercio@11 2148 local b = CreateFrame ("button", name, parent)
Tercio@11 2149 b:SetSize (12, 13)
Tercio@11 2150 b:SetNormalTexture (DF.folder .. "mail")
Tercio@11 2151 b:SetPushedTexture (DF.folder .. "mail")
Tercio@11 2152 b:SetHighlightTexture (DF.folder .. "mail")
Tercio@11 2153
Tercio@11 2154 b:SetScript ("OnClick", callback)
Tercio@11 2155 b:SetScript ("OnEnter", function (self)
Tercio@11 2156 GameCooltip2:Reset()
Tercio@11 2157 GameCooltip2:AddLine ("Send Feedback")
Tercio@11 2158 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 2159 end)
Tercio@11 2160 b:SetScript ("OnLeave", function (self)
Tercio@11 2161 GameCooltip2:Hide()
Tercio@11 2162 end)
Tercio@11 2163
Tercio@11 2164 return b
Tercio@11 2165 end
Tercio@11 2166
Tercio@11 2167 local backdrop_fb_line = {bgFile = DF.folder .. "background", edgeFile = DF.folder .. "border_3",
Tercio@11 2168 tile = true, tileSize = 64, edgeSize = 8, insets = {left = 2, right = 2, top = 2, bottom = 2}}
Tercio@11 2169
Tercio@11 2170 local on_enter_feedback = function (self)
Tercio@11 2171 self:SetBackdropColor (1, 1, 0, 0.5)
Tercio@11 2172 end
Tercio@11 2173 local on_leave_feedback = function (self)
Tercio@11 2174 self:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 2175 end
Tercio@11 2176
Tercio@11 2177 local on_click_feedback = function (self)
Tercio@11 2178
Tercio@11 2179 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 2180
Tercio@11 2181 if (not feedback_link_textbox) then
Tercio@11 2182 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 2183 editbox:SetAutoFocus (false)
Tercio@11 2184 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 2185 editbox.text = editbox.link
Tercio@11 2186 editbox:HighlightText()
Tercio@11 2187 end)
Tercio@11 2188 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 2189 editbox:Hide()
Tercio@11 2190 end)
Tercio@11 2191 editbox:SetHook ("OnChar", function()
Tercio@11 2192 editbox.text = editbox.link
Tercio@11 2193 editbox:HighlightText()
Tercio@11 2194 end)
Tercio@11 2195 editbox.text = ""
Tercio@11 2196
Tercio@11 2197 DF.feedback_link_textbox = editbox
Tercio@11 2198 feedback_link_textbox = editbox
Tercio@11 2199 end
Tercio@11 2200
Tercio@11 2201 feedback_link_textbox.link = self.link
Tercio@11 2202 feedback_link_textbox.text = self.link
Tercio@11 2203 feedback_link_textbox:Show()
Tercio@11 2204
Tercio@11 2205 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 2206
Tercio@11 2207 feedback_link_textbox:HighlightText()
Tercio@11 2208
Tercio@11 2209 feedback_link_textbox:SetFocus()
Tercio@11 2210 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 2211 end
Tercio@11 2212
Tercio@11 2213 local feedback_get_fb_line = function (self)
Tercio@11 2214
Tercio@11 2215 local line = self.feedback_lines [self.next_feedback]
Tercio@11 2216 if (not line) then
Tercio@11 2217 line = CreateFrame ("frame", "AddonFeedbackPanelFB" .. self.next_feedback, self)
Tercio@11 2218 line:SetBackdrop (backdrop_fb_line)
Tercio@11 2219 line:SetBackdropColor (0, 0, 0, 0.3)
Tercio@11 2220 line:SetSize (390, 42)
Tercio@11 2221 line:SetPoint ("topleft", self.feedback_anchor, "bottomleft", 0, -5 + ((self.next_feedback-1) * 46 * -1))
Tercio@11 2222 line:SetScript ("OnEnter", on_enter_feedback)
Tercio@11 2223 line:SetScript ("OnLeave", on_leave_feedback)
Tercio@11 2224 line:SetScript ("OnMouseUp", on_click_feedback)
Tercio@11 2225
Tercio@11 2226 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 2227 line.icon:SetSize (90, 36)
Tercio@11 2228
Tercio@11 2229 line.desc = line:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 2230
Tercio@11 2231 line.icon:SetPoint ("left", line, "left", 5, 0)
Tercio@11 2232 line.desc:SetPoint ("left", line.icon, "right", 5, 0)
Tercio@11 2233
Tercio@11 2234 local arrow = line:CreateTexture (nil, "overlay")
Tercio@11 2235 arrow:SetTexture ([[Interface\Buttons\JumpUpArrow]])
Tercio@11 2236 arrow:SetRotation (-1.55)
Tercio@11 2237 arrow:SetPoint ("right", line, "right", -5, 0)
Tercio@11 2238
Tercio@11 2239 self.feedback_lines [self.next_feedback] = line
Tercio@11 2240 end
Tercio@11 2241
Tercio@11 2242 self.next_feedback = self.next_feedback + 1
Tercio@11 2243
Tercio@11 2244 return line
Tercio@11 2245 end
Tercio@11 2246
Tercio@11 2247 local on_click_feedback = function (self)
Tercio@11 2248
Tercio@11 2249 local feedback_link_textbox = DF.feedback_link_textbox
Tercio@11 2250
Tercio@11 2251 if (not feedback_link_textbox) then
Tercio@11 2252 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34)
Tercio@11 2253 editbox:SetAutoFocus (false)
Tercio@11 2254 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 2255 editbox.text = editbox.link
Tercio@11 2256 editbox:HighlightText()
Tercio@11 2257 end)
Tercio@11 2258 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 2259 editbox:Hide()
Tercio@11 2260 end)
Tercio@11 2261 editbox:SetHook ("OnChar", function()
Tercio@11 2262 editbox.text = editbox.link
Tercio@11 2263 editbox:HighlightText()
Tercio@11 2264 end)
Tercio@11 2265 editbox.text = ""
Tercio@11 2266
Tercio@11 2267 DF.feedback_link_textbox = editbox
Tercio@11 2268 feedback_link_textbox = editbox
Tercio@11 2269 end
Tercio@11 2270
Tercio@11 2271 feedback_link_textbox.link = self.link
Tercio@11 2272 feedback_link_textbox.text = self.link
Tercio@11 2273 feedback_link_textbox:Show()
Tercio@11 2274
Tercio@11 2275 feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0)
Tercio@11 2276
Tercio@11 2277 feedback_link_textbox:HighlightText()
Tercio@11 2278
Tercio@11 2279 feedback_link_textbox:SetFocus()
Tercio@11 2280 feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 2281 end
Tercio@11 2282
Tercio@11 2283 local on_enter_addon = function (self)
Tercio@11 2284 if (self.tooltip) then
Tercio@11 2285 GameCooltip2:Preset (2)
Tercio@11 2286 GameCooltip2:AddLine ("|cFFFFFF00" .. self.name .. "|r")
Tercio@11 2287 GameCooltip2:AddLine ("")
Tercio@11 2288 GameCooltip2:AddLine (self.tooltip)
Tercio@11 2289 GameCooltip2:ShowCooltip (self, "tooltip")
Tercio@11 2290 end
Tercio@11 2291 self.icon:SetBlendMode ("ADD")
Tercio@11 2292 end
Tercio@11 2293 local on_leave_addon = function (self)
Tercio@11 2294 if (self.tooltip) then
Tercio@11 2295 GameCooltip2:Hide()
Tercio@11 2296 end
Tercio@11 2297 self.icon:SetBlendMode ("BLEND")
Tercio@11 2298 end
Tercio@11 2299 local on_click_addon = function (self)
Tercio@11 2300 local addon_link_textbox = DF.addon_link_textbox
Tercio@11 2301
Tercio@11 2302 if (not addon_link_textbox) then
Tercio@11 2303 local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 128, 64)
Tercio@11 2304 editbox:SetAutoFocus (false)
Tercio@11 2305 editbox:SetHook ("OnEditFocusGained", function()
Tercio@11 2306 editbox.text = editbox.link
Tercio@11 2307 editbox:HighlightText()
Tercio@11 2308 end)
Tercio@11 2309 editbox:SetHook ("OnEditFocusLost", function()
Tercio@11 2310 editbox:Hide()
Tercio@11 2311 end)
Tercio@11 2312 editbox:SetHook ("OnChar", function()
Tercio@11 2313 editbox.text = editbox.link
Tercio@11 2314 editbox:HighlightText()
Tercio@11 2315 end)
Tercio@11 2316 editbox.text = ""
Tercio@11 2317
Tercio@11 2318 DF.addon_link_textbox = editbox
Tercio@11 2319 addon_link_textbox = editbox
Tercio@11 2320 end
Tercio@11 2321
Tercio@11 2322 addon_link_textbox.link = self.link
Tercio@11 2323 addon_link_textbox.text = self.link
Tercio@11 2324 addon_link_textbox:Show()
Tercio@11 2325
Tercio@11 2326 addon_link_textbox:SetPoint ("topleft", self.icon, "topleft", 0, 0)
Tercio@11 2327
Tercio@11 2328 addon_link_textbox:HighlightText()
Tercio@11 2329
Tercio@11 2330 addon_link_textbox:SetFocus()
Tercio@11 2331 addon_link_textbox:SetFrameLevel (self:GetFrameLevel()+2)
Tercio@11 2332 end
Tercio@11 2333
Tercio@11 2334 local feedback_get_addons_line = function (self)
Tercio@11 2335 local line = self.addons_lines [self.next_addons]
Tercio@11 2336 if (not line) then
Tercio@11 2337
Tercio@11 2338 line = CreateFrame ("frame", "AddonFeedbackPanelSA" .. self.next_addons, self)
Tercio@11 2339 line:SetSize (128, 64)
Tercio@11 2340
Tercio@11 2341 if (self.next_addons == 1) then
Tercio@11 2342 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5)
Tercio@11 2343 elseif (self.next_addons_line_break == self.next_addons) then
Tercio@11 2344 line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5 + floor (self.next_addons_line_break/3) * 66 * -1)
Tercio@11 2345 self.next_addons_line_break = self.next_addons_line_break + 3
Tercio@11 2346 else
Tercio@11 2347 local previous = self.addons_lines [self.next_addons - 1]
Tercio@11 2348 line:SetPoint ("topleft", previous, "topright", 2, 0)
Tercio@11 2349 end
Tercio@11 2350
Tercio@11 2351 line:SetScript ("OnEnter", on_enter_addon)
Tercio@11 2352 line:SetScript ("OnLeave", on_leave_addon)
Tercio@11 2353 line:SetScript ("OnMouseUp", on_click_addon)
Tercio@11 2354
Tercio@11 2355 line.icon = line:CreateTexture (nil, "overlay")
Tercio@11 2356 line.icon:SetSize (128, 64)
Tercio@11 2357
Tercio@11 2358 line.icon:SetPoint ("topleft", line, "topleft", 0, 0)
Tercio@11 2359
Tercio@11 2360 self.addons_lines [self.next_addons] = line
Tercio@11 2361 end
Tercio@11 2362
Tercio@11 2363 self.next_addons = self.next_addons + 1
Tercio@11 2364
Tercio@11 2365 return line
Tercio@11 2366 end
Tercio@11 2367
Tercio@11 2368 local default_coords = {0, 1, 0, 1}
Tercio@11 2369 local feedback_add_fb = function (self, table)
Tercio@11 2370 local line = self:GetFeedbackLine()
Tercio@11 2371 line.icon:SetTexture (table.icon)
Tercio@11 2372 line.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 2373 line.desc:SetText (table.desc)
Tercio@11 2374 line.link = table.link
Tercio@11 2375 line:Show()
Tercio@11 2376 end
Tercio@11 2377
Tercio@11 2378 local feedback_add_addon = function (self, table)
Tercio@11 2379 local block = self:GetAddonsLine()
Tercio@11 2380 block.icon:SetTexture (table.icon)
Tercio@11 2381 block.icon:SetTexCoord (unpack (table.coords or default_coords))
Tercio@11 2382 block.link = table.link
Tercio@11 2383 block.tooltip = table.desc
Tercio@11 2384 block.name = table.name
Tercio@11 2385 block:Show()
Tercio@11 2386 end
Tercio@11 2387
Tercio@11 2388 local feedback_hide_all = function (self)
Tercio@11 2389 self.next_feedback = 1
Tercio@11 2390 self.next_addons = 1
Tercio@11 2391
Tercio@11 2392 for index, line in ipairs (self.feedback_lines) do
Tercio@11 2393 line:Hide()
Tercio@11 2394 end
Tercio@11 2395
Tercio@11 2396 for index, line in ipairs (self.addons_lines) do
Tercio@11 2397 line:Hide()
Tercio@11 2398 end
Tercio@11 2399 end
Tercio@11 2400
Tercio@11 2401 -- feedback_methods = { { icon = icon path, desc = description, link = url}}
Tercio@11 2402 function DF:ShowFeedbackPanel (addon_name, version, feedback_methods, more_addons)
Tercio@11 2403
Tercio@11 2404 local f = _G.AddonFeedbackPanel
Tercio@11 2405
Tercio@11 2406 if (not f) then
Tercio@11 2407 f = DF:Create1PxPanel (UIParent, 400, 100, addon_name .. " Feedback", "AddonFeedbackPanel", nil)
Tercio@11 2408 f:SetFrameStrata ("FULLSCREEN")
Tercio@11 2409 f:SetPoint ("center", UIParent, "center")
Tercio@11 2410 f:SetBackdropColor (0, 0, 0, 0.8)
Tercio@11 2411 f.feedback_lines = {}
Tercio@11 2412 f.addons_lines = {}
Tercio@11 2413 f.next_feedback = 1
Tercio@11 2414 f.next_addons = 1
Tercio@11 2415 f.next_addons_line_break = 4
Tercio@11 2416
Tercio@11 2417 local feedback_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 2418 feedback_anchor:SetText ("Feedback:")
Tercio@11 2419 feedback_anchor:SetPoint ("topleft", f, "topleft", 5, -30)
Tercio@11 2420 f.feedback_anchor = feedback_anchor
Tercio@11 2421 local excla_text = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 2422 excla_text:SetText ("click and copy the link")
Tercio@11 2423 excla_text:SetPoint ("topright", f, "topright", -5, -30)
Tercio@11 2424 excla_text:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 2425
Tercio@11 2426 local addons_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 2427 addons_anchor:SetText ("AddOns From the Same Author:")
Tercio@11 2428 f.addons_anchor = addons_anchor
Tercio@11 2429 local excla_text2 = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@11 2430 excla_text2:SetText ("click and copy the link")
Tercio@11 2431 excla_text2:SetTextColor (1, 0.8, 0.2, 0.6)
Tercio@11 2432 f.excla_text2 = excla_text2
Tercio@11 2433
Tercio@11 2434 f.GetFeedbackLine = feedback_get_fb_line
Tercio@11 2435 f.GetAddonsLine = feedback_get_addons_line
Tercio@11 2436 f.AddFeedbackMethod = feedback_add_fb
Tercio@11 2437 f.AddOtherAddon = feedback_add_addon
Tercio@11 2438 f.HideAll = feedback_hide_all
Tercio@11 2439
Tercio@11 2440 DF:SetFontSize (f.Title, 14)
Tercio@11 2441
Tercio@11 2442 end
Tercio@11 2443
Tercio@11 2444 f:HideAll()
Tercio@11 2445 f:SetTitle (addon_name)
Tercio@11 2446
Tercio@11 2447 for index, feedback in ipairs (feedback_methods) do
Tercio@11 2448 f:AddFeedbackMethod (feedback)
Tercio@11 2449 end
Tercio@11 2450
Tercio@11 2451 f.addons_anchor:SetPoint ("topleft", f, "topleft", 5, f.next_feedback * 50 * -1)
Tercio@11 2452 f.excla_text2:SetPoint ("topright", f, "topright", -5, f.next_feedback * 50 * -1)
Tercio@11 2453
Tercio@11 2454 for index, addon in ipairs (more_addons) do
Tercio@11 2455 f:AddOtherAddon (addon)
Tercio@11 2456 end
Tercio@11 2457
Tercio@11 2458 f:SetHeight (80 + ((f.next_feedback-1) * 50) + (ceil ((f.next_addons-1)/3) * 66))
Tercio@11 2459
Tercio@11 2460 f:Show()
Tercio@11 2461
Tercio@11 2462 return true
Tercio@11 2463 end
Tercio@11 2464
Tercio@11 2465
Tercio@11 2466 ------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 2467 --> chart panel -- ~chart
Tercio@11 2468
Tercio@11 2469 local chart_panel_backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
Tercio@11 2470 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}}
Tercio@11 2471
Tercio@11 2472 local chart_panel_align_timelabels = function (self, elapsed_time)
Tercio@11 2473
Tercio@11 2474 self.TimeScale = elapsed_time
Tercio@11 2475
Tercio@11 2476 local linha = self.TimeLabels [17]
Tercio@11 2477 local minutos, segundos = math.floor (elapsed_time / 60), math.floor (elapsed_time % 60)
Tercio@11 2478 if (segundos < 10) then
Tercio@11 2479 segundos = "0" .. segundos
Tercio@11 2480 end
Tercio@11 2481
Tercio@11 2482 if (minutos > 0) then
Tercio@11 2483 if (minutos < 10) then
Tercio@11 2484 minutos = "0" .. minutos
Tercio@11 2485 end
Tercio@11 2486 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 2487 else
Tercio@11 2488 linha:SetText ("00:" .. segundos)
Tercio@11 2489 end
Tercio@11 2490
Tercio@11 2491 local time_div = elapsed_time / 16 --786 -- 49.125
Tercio@11 2492
Tercio@11 2493 for i = 2, 16 do
Tercio@11 2494
Tercio@11 2495 local linha = self.TimeLabels [i]
Tercio@11 2496
Tercio@11 2497 local this_time = time_div * (i-1)
Tercio@11 2498 local minutos, segundos = math.floor (this_time / 60), math.floor (this_time % 60)
Tercio@11 2499
Tercio@11 2500 if (segundos < 10) then
Tercio@11 2501 segundos = "0" .. segundos
Tercio@11 2502 end
Tercio@11 2503
Tercio@11 2504 if (minutos > 0) then
Tercio@11 2505 if (minutos < 10) then
Tercio@11 2506 minutos = "0" .. minutos
Tercio@11 2507 end
Tercio@11 2508 linha:SetText (minutos .. ":" .. segundos)
Tercio@11 2509 else
Tercio@11 2510 linha:SetText ("00:" .. segundos)
Tercio@11 2511 end
Tercio@11 2512
Tercio@11 2513 end
Tercio@11 2514
Tercio@11 2515 end
Tercio@11 2516
Tercio@11 2517 local chart_panel_set_scale = function (self, amt, func, text)
Tercio@11 2518 if (type (amt) ~= "number") then
Tercio@11 2519 return
Tercio@11 2520 end
Tercio@11 2521
Tercio@56 2522 --each line amount, then multiply the line index by this number
Tercio@56 2523 local piece = amt / 8
Tercio@56 2524
Tercio@11 2525 for i = 1, 8 do
Tercio@11 2526 if (func) then
Tercio@56 2527 self ["dpsamt" .. math.abs (i-9)]:SetText (func (piece*i))
Tercio@11 2528 else
Tercio@11 2529 if (piece*i > 1) then
Tercio@56 2530 self ["dpsamt" .. math.abs (i-9)]:SetText (DF.FormatNumber (piece*i))
Tercio@11 2531 else
Tercio@56 2532 self ["dpsamt" .. math.abs (i-9)]:SetText (format ("%.3f", piece*i))
Tercio@11 2533 end
Tercio@11 2534 end
Tercio@11 2535 end
Tercio@11 2536 end
Tercio@11 2537
Tercio@11 2538 local chart_panel_can_move = function (self, can)
Tercio@11 2539 self.can_move = can
Tercio@11 2540 end
Tercio@11 2541
Tercio@11 2542 local chart_panel_overlay_reset = function (self)
Tercio@11 2543 self.OverlaysAmount = 1
Tercio@11 2544 for index, pack in ipairs (self.Overlays) do
Tercio@11 2545 for index2, texture in ipairs (pack) do
Tercio@11 2546 texture:Hide()
Tercio@11 2547 end
Tercio@11 2548 end
Tercio@11 2549 end
Tercio@11 2550
Tercio@11 2551 local chart_panel_reset = function (self)
Tercio@11 2552
Tercio@11 2553 self.Graphic:ResetData()
Tercio@11 2554 self.Graphic.max_value = 0
Tercio@11 2555
Tercio@11 2556 self.TimeScale = nil
Tercio@11 2557 self.BoxLabelsAmount = 1
Tercio@11 2558 table.wipe (self.GData)
Tercio@11 2559 table.wipe (self.OData)
Tercio@11 2560
Tercio@11 2561 for index, box in ipairs (self.BoxLabels) do
Tercio@11 2562 box.check:Hide()
Tercio@11 2563 box.button:Hide()
Tercio@11 2564 box.box:Hide()
Tercio@11 2565 box.text:Hide()
Tercio@11 2566 box.border:Hide()
Tercio@11 2567 box.showing = false
Tercio@11 2568 end
Tercio@11 2569
Tercio@11 2570 chart_panel_overlay_reset (self)
Tercio@11 2571 end
Tercio@11 2572
Tercio@11 2573 local chart_panel_enable_line = function (f, thisbox)
Tercio@11 2574
Tercio@11 2575 local index = thisbox.index
Tercio@11 2576 local type = thisbox.type
Tercio@11 2577
Tercio@11 2578 if (thisbox.enabled) then
Tercio@11 2579 --disable
Tercio@11 2580 thisbox.check:Hide()
Tercio@11 2581 thisbox.enabled = false
Tercio@11 2582 else
Tercio@11 2583 --enable
Tercio@11 2584 thisbox.check:Show()
Tercio@11 2585 thisbox.enabled = true
Tercio@11 2586 end
Tercio@11 2587
Tercio@11 2588 if (type == "graphic") then
Tercio@11 2589
Tercio@11 2590 f.Graphic:ResetData()
Tercio@11 2591 f.Graphic.max_value = 0
Tercio@11 2592
Tercio@11 2593 local max = 0
Tercio@11 2594 local max_time = 0
Tercio@11 2595
Tercio@11 2596 for index, box in ipairs (f.BoxLabels) do
Tercio@11 2597 if (box.type == type and box.showing and box.enabled) then
Tercio@11 2598 local data = f.GData [index]
Tercio@11 2599
Tercio@11 2600 f.Graphic:AddDataSeries (data[1], data[2], nil, data[3])
Tercio@11 2601
Tercio@11 2602 if (data[4] > max) then
Tercio@11 2603 max = data[4]
Tercio@11 2604 end
Tercio@11 2605 if (data [5] > max_time) then
Tercio@11 2606 max_time = data [5]
Tercio@11 2607 end
Tercio@11 2608 end
Tercio@11 2609 end
Tercio@11 2610
Tercio@11 2611 f:SetScale (max)
Tercio@11 2612 f:SetTime (max_time)
Tercio@11 2613
Tercio@11 2614 elseif (type == "overlay") then
Tercio@11 2615
Tercio@11 2616 chart_panel_overlay_reset (f)
Tercio@11 2617
Tercio@11 2618 for index, box in ipairs (f.BoxLabels) do
Tercio@11 2619 if (box.type == type and box.showing and box.enabled) then
Tercio@11 2620
Tercio@11 2621 f:AddOverlay (box.index)
Tercio@11 2622
Tercio@11 2623 end
Tercio@11 2624 end
Tercio@11 2625
Tercio@11 2626 end
Tercio@11 2627 end
Tercio@11 2628
Tercio@11 2629 local create_box = function (self, next_box)
Tercio@11 2630
Tercio@11 2631 local thisbox = {}
Tercio@11 2632 self.BoxLabels [next_box] = thisbox
Tercio@11 2633
Tercio@11 2634 local box = DF:NewImage (self.Graphic, nil, 16, 16, "border")
Tercio@11 2635 local text = DF:NewLabel (self.Graphic)
Tercio@11 2636
Tercio@11 2637 local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork")
Tercio@11 2638 border:SetPoint ("center", box, "center", -3, -4)
Tercio@11 2639 border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]])
Tercio@11 2640
Tercio@11 2641 local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay")
Tercio@56 2642 checktexture:SetPoint ("center", box, "center", 0, -1)
Tercio@11 2643 checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
Tercio@11 2644
Tercio@11 2645 thisbox.box = box
Tercio@11 2646 thisbox.text = text
Tercio@11 2647 thisbox.border = border
Tercio@11 2648 thisbox.check = checktexture
Tercio@11 2649 thisbox.enabled = true
Tercio@11 2650
Tercio@11 2651 local button = CreateFrame ("button", nil, self.Graphic)
Tercio@11 2652 button:SetSize (20, 20)
Tercio@11 2653 button:SetScript ("OnClick", function()
Tercio@11 2654 chart_panel_enable_line (self, thisbox)
Tercio@11 2655 end)
Tercio@56 2656 button:SetPoint ("topleft", box.widget or box, "topleft", 0, 0)
Tercio@56 2657 button:SetPoint ("bottomright", box.widget or box, "bottomright", 0, 0)
Tercio@56 2658
Tercio@56 2659 button:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@56 2660 button:SetBackdropColor (0, 0, 0, 0.0)
Tercio@56 2661 button:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@11 2662
Tercio@11 2663 thisbox.button = button
Tercio@11 2664
Tercio@11 2665 thisbox.box:SetPoint ("right", text, "left", -4, 0)
Tercio@11 2666
Tercio@11 2667 if (next_box == 1) then
Tercio@11 2668 thisbox.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 2669 else
Tercio@56 2670 thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -17, 0)
Tercio@11 2671 end
Tercio@11 2672
Tercio@11 2673 return thisbox
Tercio@11 2674
Tercio@11 2675 end
Tercio@11 2676
Tercio@11 2677 local realign_labels = function (self)
Tercio@11 2678
Tercio@56 2679 if (not self.ShowHeader) then
Tercio@56 2680 for _, box in ipairs (self.BoxLabels) do
Tercio@56 2681 box.check:Hide()
Tercio@56 2682 box.button:Hide()
Tercio@56 2683 box.border:Hide()
Tercio@56 2684 box.box:Hide()
Tercio@56 2685 box.text:Hide()
Tercio@56 2686 end
Tercio@56 2687 return
Tercio@56 2688 end
Tercio@56 2689
Tercio@11 2690 local width = self:GetWidth() - 108
Tercio@11 2691
Tercio@11 2692 local first_box = self.BoxLabels [1]
Tercio@11 2693 first_box.text:SetPoint ("topright", self, "topright", -35, -16)
Tercio@11 2694
Tercio@11 2695 local line_width = first_box.text:GetStringWidth() + 26
Tercio@11 2696
Tercio@11 2697 for i = 2, #self.BoxLabels do
Tercio@11 2698
Tercio@11 2699 local box = self.BoxLabels [i]
Tercio@11 2700
Tercio@11 2701 if (box.box:IsShown()) then
Tercio@11 2702
Tercio@11 2703 line_width = line_width + box.text:GetStringWidth() + 26
Tercio@11 2704
Tercio@11 2705 if (line_width > width) then
Tercio@11 2706 line_width = box.text:GetStringWidth() + 26
Tercio@11 2707 box.text:SetPoint ("topright", self, "topright", -35, -40)
Tercio@11 2708 else
Tercio@56 2709 box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -27, 0)
Tercio@11 2710 end
Tercio@11 2711 else
Tercio@11 2712 break
Tercio@11 2713 end
Tercio@11 2714 end
Tercio@11 2715
Tercio@56 2716 if (self.HeaderOnlyIndicator) then
Tercio@56 2717 for _, box in ipairs (self.BoxLabels) do
Tercio@56 2718 box.check:Hide()
Tercio@56 2719 box.button:Hide()
Tercio@56 2720 end
Tercio@56 2721 return
Tercio@56 2722 end
Tercio@56 2723
Tercio@11 2724 end
Tercio@11 2725
Tercio@11 2726 local chart_panel_add_label = function (self, color, name, type, number)
Tercio@56 2727
Tercio@11 2728 local next_box = self.BoxLabelsAmount
Tercio@11 2729 local thisbox = self.BoxLabels [next_box]
Tercio@11 2730
Tercio@11 2731 if (not thisbox) then
Tercio@11 2732 thisbox = create_box (self, next_box)
Tercio@11 2733 end
Tercio@11 2734
Tercio@11 2735 self.BoxLabelsAmount = self.BoxLabelsAmount + 1
Tercio@56 2736
Tercio@11 2737 thisbox.type = type
Tercio@11 2738 thisbox.index = number
Tercio@56 2739
Tercio@39 2740 thisbox.box:SetColorTexture (unpack (color))
Tercio@11 2741 thisbox.text:SetText (name)
Tercio@11 2742
Tercio@11 2743 thisbox.check:Show()
Tercio@11 2744 thisbox.button:Show()
Tercio@56 2745 thisbox.border:Hide()
Tercio@11 2746 thisbox.box:Show()
Tercio@11 2747 thisbox.text:Show()
Tercio@56 2748
Tercio@11 2749 thisbox.showing = true
Tercio@11 2750 thisbox.enabled = true
Tercio@11 2751
Tercio@11 2752 realign_labels (self)
Tercio@11 2753
Tercio@11 2754 end
Tercio@11 2755
Tercio@11 2756 local line_default_color = {1, 1, 1}
Tercio@11 2757 local draw_overlay = function (self, this_overlay, overlayData, color)
Tercio@11 2758
Tercio@11 2759 local pixel = self.Graphic:GetWidth() / self.TimeScale
Tercio@11 2760 local index = 1
Tercio@56 2761 local r, g, b, a = unpack (color or line_default_color)
Tercio@11 2762
Tercio@11 2763 for i = 1, #overlayData, 2 do
Tercio@11 2764 local aura_start = overlayData [i]
Tercio@11 2765 local aura_end = overlayData [i+1]
Tercio@11 2766
Tercio@11 2767 local this_block = this_overlay [index]
Tercio@11 2768 if (not this_block) then
Tercio@11 2769 this_block = self.Graphic:CreateTexture (nil, "border")
Tercio@11 2770 tinsert (this_overlay, this_block)
Tercio@11 2771 end
Tercio@11 2772 this_block:SetHeight (self.Graphic:GetHeight())
Tercio@11 2773
Tercio@11 2774 this_block:SetPoint ("left", self.Graphic, "left", pixel * aura_start, 0)
Tercio@11 2775 if (aura_end) then
Tercio@11 2776 this_block:SetWidth ((aura_end-aura_start)*pixel)
Tercio@11 2777 else
Tercio@11 2778 --malformed table
Tercio@11 2779 this_block:SetWidth (pixel*5)
Tercio@11 2780 end
Tercio@11 2781
Tercio@56 2782 this_block:SetColorTexture (r, g, b, a or 0.25)
Tercio@11 2783 this_block:Show()
Tercio@11 2784
Tercio@11 2785 index = index + 1
Tercio@11 2786 end
Tercio@11 2787
Tercio@11 2788 end
Tercio@11 2789
Tercio@11 2790 local chart_panel_add_overlay = function (self, overlayData, color, name, icon)
Tercio@11 2791
Tercio@11 2792 if (not self.TimeScale) then
Tercio@11 2793 error ("Use SetTime (time) before adding an overlay.")
Tercio@11 2794 end
Tercio@11 2795
Tercio@11 2796 if (type (overlayData) == "number") then
Tercio@11 2797 local overlay_index = overlayData
Tercio@11 2798 draw_overlay (self, self.Overlays [self.OverlaysAmount], self.OData [overlay_index][1], self.OData [overlay_index][2])
Tercio@11 2799 else
Tercio@11 2800 local this_overlay = self.Overlays [self.OverlaysAmount]
Tercio@11 2801 if (not this_overlay) then
Tercio@11 2802 this_overlay = {}
Tercio@11 2803 tinsert (self.Overlays, this_overlay)
Tercio@11 2804 end
Tercio@11 2805
Tercio@11 2806 draw_overlay (self, this_overlay, overlayData, color)
Tercio@11 2807
Tercio@11 2808 tinsert (self.OData, {overlayData, color or line_default_color})
Tercio@56 2809 if (name and self.HeaderShowOverlays) then
Tercio@11 2810 self:AddLabel (color or line_default_color, name, "overlay", #self.OData)
Tercio@11 2811 end
Tercio@11 2812 end
Tercio@11 2813
Tercio@11 2814 self.OverlaysAmount = self.OverlaysAmount + 1
Tercio@11 2815 end
Tercio@11 2816
Tercio@56 2817 -- Define the tricube weight function
Tercio@56 2818 function calc_cubeweight (i, j, d)
Tercio@56 2819 local w = ( 1 - math.abs ((j-i)/d)^3)^3
Tercio@56 2820 if w < 0 then
Tercio@56 2821 w = 0;
Tercio@56 2822 end
Tercio@56 2823 return w
Tercio@56 2824 end
Tercio@56 2825
Tercio@56 2826 local calc_lowess_smoothing = function (self, data, bandwidth)
Tercio@56 2827 local length = #data
Tercio@56 2828 local newData = {}
Tercio@56 2829
Tercio@56 2830 for i = 1, length do
Tercio@56 2831 local A = 0
Tercio@56 2832 local B = 0
Tercio@56 2833 local C = 0
Tercio@56 2834 local D = 0
Tercio@56 2835 local E = 0
Tercio@56 2836
Tercio@56 2837 -- Calculate span of values to be included in the regression
Tercio@56 2838 local jmin = floor (i-bandwidth/2)
Tercio@56 2839 local jmax = ceil (i+bandwidth/2)
Tercio@56 2840 if jmin < 1 then
Tercio@56 2841 jmin = 1
Tercio@56 2842 end
Tercio@56 2843 if jmax > length then
Tercio@56 2844 jmax = length
Tercio@56 2845 end
Tercio@56 2846
Tercio@56 2847 -- For all the values in the span, compute the weight and then the linear fit
Tercio@56 2848
Tercio@56 2849 for j = jmin, jmax do
Tercio@56 2850 w = calc_cubeweight (i, j, bandwidth/2)
Tercio@56 2851 x = j
Tercio@56 2852 y = data [j]
Tercio@56 2853
Tercio@56 2854 A = A + w*x
Tercio@56 2855 B = B + w*y
Tercio@56 2856 C = C + w*x^2
Tercio@56 2857 D = D + w*x*y
Tercio@56 2858 E = E + w
Tercio@56 2859 end
Tercio@56 2860
Tercio@56 2861 -- Calculate a (slope) and b (offset) for the linear fit
Tercio@56 2862 local a = (A*B-D*E)/(A^2 - C*E);
Tercio@56 2863 local b = (A*D-B*C)/(A^2 - C*E);
Tercio@56 2864
Tercio@56 2865 -- Calculate the smoothed value by the formula y=a*x+b (x <- i)
Tercio@56 2866 newData [i] = a*i+b;
Tercio@56 2867
Tercio@56 2868 end
Tercio@56 2869
Tercio@56 2870 return newData
Tercio@56 2871 end
Tercio@56 2872
Tercio@56 2873 local calc_stddev = function (self, data)
Tercio@56 2874 local total = 0
Tercio@56 2875 for i = 1, #data do
Tercio@56 2876 total = total + data[i]
Tercio@56 2877 end
Tercio@56 2878 local mean = total / #data
Tercio@56 2879
Tercio@56 2880 local totalDistance = 0
Tercio@56 2881 for i = 1, #data do
Tercio@56 2882 totalDistance = totalDistance + ((data[i] - mean) ^ 2)
Tercio@56 2883 end
Tercio@56 2884
Tercio@56 2885 local deviation = math.sqrt (totalDistance / #data)
Tercio@56 2886 return deviation
Tercio@56 2887 end
Tercio@56 2888
Tercio@56 2889
Tercio@56 2890
Tercio@11 2891 local SMA_table = {}
Tercio@11 2892 local SMA_max = 0
Tercio@11 2893 local reset_SMA = function()
Tercio@11 2894 table.wipe (SMA_table)
Tercio@11 2895 SMA_max = 0
Tercio@11 2896 end
Tercio@11 2897
Tercio@11 2898 local calc_SMA
Tercio@11 2899 calc_SMA = function (a, b, ...)
Tercio@11 2900 if (b) then
Tercio@11 2901 return calc_SMA (a + b, ...)
Tercio@11 2902 else
Tercio@11 2903 return a
Tercio@11 2904 end
Tercio@11 2905 end
Tercio@11 2906
Tercio@11 2907 local do_SMA = function (value, max_value)
Tercio@11 2908
Tercio@11 2909 if (#SMA_table == 10) then
Tercio@11 2910 tremove (SMA_table, 1)
Tercio@11 2911 end
Tercio@11 2912
Tercio@11 2913 SMA_table [#SMA_table + 1] = value
Tercio@11 2914
Tercio@11 2915 local new_value = calc_SMA (unpack (SMA_table)) / #SMA_table
Tercio@11 2916
Tercio@11 2917 if (new_value > SMA_max) then
Tercio@11 2918 SMA_max = new_value
Tercio@11 2919 return new_value, SMA_max
Tercio@11 2920 else
Tercio@11 2921 return new_value
Tercio@11 2922 end
Tercio@11 2923
Tercio@11 2924 end
Tercio@11 2925
Tercio@55 2926 local chart_panel_onresize = function (self)
Tercio@55 2927 local width, height = self:GetSize()
Tercio@55 2928 local spacement = width - 78 - 60
Tercio@55 2929 spacement = spacement / 16
Tercio@55 2930
Tercio@55 2931 for i = 1, 17 do
Tercio@55 2932 local label = self.TimeLabels [i]
Tercio@56 2933 label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), self.TimeLabelsHeight)
Tercio@55 2934 label.line:SetHeight (height - 45)
Tercio@55 2935 end
Tercio@55 2936
Tercio@55 2937 local spacement = (self.Graphic:GetHeight()) / 8
Tercio@55 2938 for i = 1, 8 do
Tercio@55 2939 self ["dpsamt"..i]:SetPoint ("TOPLEFT", self, "TOPLEFT", 27, -25 + (-(spacement* (i-1))) )
Tercio@55 2940 self ["dpsamt"..i].line:SetWidth (width-20)
Tercio@55 2941 end
Tercio@55 2942
Tercio@55 2943 self.Graphic:SetSize (width - 135, height - 67)
Tercio@55 2944 self.Graphic:SetPoint ("topleft", self, "topleft", 108, -35)
Tercio@55 2945 end
Tercio@55 2946
Tercio@11 2947 local chart_panel_add_data = function (self, graphicData, color, name, elapsed_time, lineTexture, smoothLevel, firstIndex)
Tercio@11 2948
Tercio@11 2949 local f = self
Tercio@11 2950 self = self.Graphic
Tercio@22 2951
Tercio@11 2952 local _data = {}
Tercio@11 2953 local max_value = graphicData.max_value
Tercio@11 2954 local amount = #graphicData
Tercio@11 2955
Tercio@11 2956 local scaleW = 1/self:GetWidth()
Tercio@56 2957
Tercio@11 2958 local content = graphicData
Tercio@11 2959 tinsert (content, 1, 0)
Tercio@11 2960 tinsert (content, 1, 0)
Tercio@11 2961 tinsert (content, #content+1, 0)
Tercio@11 2962 tinsert (content, #content+1, 0)
Tercio@11 2963
Tercio@11 2964 local _i = 3
Tercio@11 2965
Tercio@11 2966 local graphMaxDps = math.max (self.max_value, max_value)
Tercio@11 2967
Tercio@11 2968 if (not smoothLevel) then
Tercio@11 2969 while (_i <= #content-2) do
Tercio@11 2970 local v = (content[_i-2]+content[_i-1]+content[_i]+content[_i+1]+content[_i+2])/5 --> normalize
Tercio@11 2971 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 2972 _i = _i + 1
Tercio@11 2973 end
Tercio@11 2974
Tercio@11 2975 elseif (smoothLevel == "SHORT") then
Tercio@11 2976 while (_i <= #content-2) do
Tercio@11 2977 local value = (content[_i] + content[_i+1]) / 2
Tercio@11 2978 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2979 _data [#_data+1] = {scaleW*(_i-2), value}
Tercio@11 2980 _i = _i + 2
Tercio@11 2981 end
Tercio@11 2982
Tercio@11 2983 elseif (smoothLevel == "SMA") then
Tercio@11 2984 reset_SMA()
Tercio@11 2985 while (_i <= #content-2) do
Tercio@11 2986 local value, is_new_max_value = do_SMA (content[_i], max_value)
Tercio@11 2987 if (is_new_max_value) then
Tercio@11 2988 max_value = is_new_max_value
Tercio@11 2989 end
Tercio@11 2990 _data [#_data+1] = {scaleW*(_i-2), value} --> x and y coords
Tercio@11 2991 _i = _i + 1
Tercio@11 2992 end
Tercio@11 2993
Tercio@11 2994 elseif (smoothLevel == -1) then
Tercio@11 2995 while (_i <= #content-2) do
Tercio@11 2996 local current = content[_i]
Tercio@11 2997
Tercio@11 2998 local minus_2 = content[_i-2] * 0.6
Tercio@11 2999 local minus_1 = content[_i-1] * 0.8
Tercio@11 3000 local plus_1 = content[_i+1] * 0.8
Tercio@11 3001 local plus_2 = content[_i+2] * 0.6
Tercio@11 3002
Tercio@11 3003 local v = (current + minus_2 + minus_1 + plus_1 + plus_2)/5 --> normalize
Tercio@11 3004 _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords
Tercio@11 3005 _i = _i + 1
Tercio@11 3006 end
Tercio@11 3007
Tercio@11 3008 elseif (smoothLevel == 1) then
Tercio@11 3009 _i = 2
Tercio@11 3010 while (_i <= #content-1) do
Tercio@11 3011 local v = (content[_i-1]+content[_i]+content[_i+1])/3 --> normalize
Tercio@11 3012 _data [#_data+1] = {scaleW*(_i-1), v/graphMaxDps} --> x and y coords
Tercio@11 3013 _i = _i + 1
Tercio@11 3014 end
Tercio@11 3015
Tercio@11 3016 elseif (smoothLevel == 2) then
Tercio@11 3017 _i = 1
Tercio@11 3018 while (_i <= #content) do
Tercio@11 3019 local v = content[_i] --> do not normalize
Tercio@11 3020 _data [#_data+1] = {scaleW*(_i), v/graphMaxDps} --> x and y coords
Tercio@11 3021 _i = _i + 1
Tercio@11 3022 end
Tercio@11 3023
Tercio@11 3024 end
Tercio@11 3025
Tercio@11 3026 tremove (content, 1)
Tercio@11 3027 tremove (content, 1)
Tercio@11 3028 tremove (content, #graphicData)
Tercio@11 3029 tremove (content, #graphicData)
Tercio@11 3030
Tercio@11 3031 if (max_value > self.max_value) then
Tercio@11 3032 --> normalize previous data
Tercio@11 3033 if (self.max_value > 0) then
Tercio@11 3034 local normalizePercent = self.max_value / max_value
Tercio@11 3035 for dataIndex, Data in ipairs (self.Data) do
Tercio@11 3036 local Points = Data.Points
Tercio@11 3037 for i = 1, #Points do
Tercio@11 3038 Points[i][2] = Points[i][2]*normalizePercent
Tercio@11 3039 end
Tercio@11 3040 end
Tercio@11 3041 end
Tercio@11 3042
Tercio@11 3043 self.max_value = max_value
Tercio@11 3044 f:SetScale (max_value)
Tercio@11 3045
Tercio@11 3046 end
Tercio@11 3047
Tercio@11 3048 tinsert (f.GData, {_data, color or line_default_color, lineTexture, max_value, elapsed_time})
Tercio@11 3049 if (name) then
Tercio@11 3050 f:AddLabel (color or line_default_color, name, "graphic", #f.GData)
Tercio@11 3051 end
Tercio@11 3052
Tercio@11 3053 if (firstIndex) then
Tercio@11 3054 if (lineTexture) then
Tercio@11 3055 if (not lineTexture:find ("\\") and not lineTexture:find ("//")) then
Tercio@11 3056 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)LibGraph%-2%.0%.lua")
Tercio@11 3057 if path then
Tercio@11 3058 lineTexture = "Interface\\AddOns\\" .. path .. lineTexture
Tercio@11 3059 else
Tercio@11 3060 lineTexture = nil
Tercio@11 3061 end
Tercio@11 3062 end
Tercio@11 3063 end
Tercio@11 3064
Tercio@11 3065 table.insert (self.Data, 1, {Points = _data, Color = color or line_default_color, lineTexture = lineTexture, ElapsedTime = elapsed_time})
Tercio@11 3066 self.NeedsUpdate = true
Tercio@11 3067 else
Tercio@11 3068 self:AddDataSeries (_data, color or line_default_color, nil, lineTexture)
Tercio@11 3069 self.Data [#self.Data].ElapsedTime = elapsed_time
Tercio@11 3070 end
Tercio@11 3071
Tercio@11 3072 local max_time = 0
Tercio@11 3073 for _, data in ipairs (self.Data) do
Tercio@11 3074 if (data.ElapsedTime > max_time) then
Tercio@11 3075 max_time = data.ElapsedTime
Tercio@11 3076 end
Tercio@11 3077 end
Tercio@11 3078
Tercio@11 3079 f:SetTime (max_time)
Tercio@11 3080
Tercio@55 3081 chart_panel_onresize (f)
Tercio@11 3082 end
Tercio@11 3083
Tercio@55 3084
Tercio@11 3085
Tercio@56 3086
Tercio@11 3087 local chart_panel_vlines_on = function (self)
Tercio@11 3088 for i = 1, 17 do
Tercio@11 3089 local label = self.TimeLabels [i]
Tercio@11 3090 label.line:Show()
Tercio@11 3091 end
Tercio@11 3092 end
Tercio@11 3093
Tercio@11 3094 local chart_panel_vlines_off = function (self)
Tercio@11 3095 for i = 1, 17 do
Tercio@11 3096 local label = self.TimeLabels [i]
Tercio@11 3097 label.line:Hide()
Tercio@11 3098 end
Tercio@11 3099 end
Tercio@11 3100
Tercio@11 3101 local chart_panel_set_title = function (self, title)
Tercio@11 3102 self.chart_title.text = title
Tercio@11 3103 end
Tercio@11 3104
Tercio@11 3105 local chart_panel_mousedown = function (self, button)
Tercio@11 3106 if (button == "LeftButton" and self.can_move) then
Tercio@11 3107 if (not self.isMoving) then
Tercio@11 3108 self:StartMoving()
Tercio@11 3109 self.isMoving = true
Tercio@11 3110 end
Tercio@11 3111 elseif (button == "RightButton" and not self.no_right_click_close) then
Tercio@11 3112 if (not self.isMoving) then
Tercio@11 3113 self:Hide()
Tercio@11 3114 end
Tercio@11 3115 end
Tercio@11 3116 end
Tercio@11 3117 local chart_panel_mouseup = function (self, button)
Tercio@11 3118 if (button == "LeftButton" and self.isMoving) then
Tercio@11 3119 self:StopMovingOrSizing()
Tercio@11 3120 self.isMoving = nil
Tercio@11 3121 end
Tercio@11 3122 end
Tercio@11 3123
Tercio@11 3124 local chart_panel_hide_close_button = function (self)
Tercio@11 3125 self.CloseButton:Hide()
Tercio@11 3126 end
Tercio@11 3127
Tercio@11 3128 local chart_panel_right_click_close = function (self, value)
Tercio@11 3129 if (type (value) == "boolean") then
Tercio@11 3130 if (value) then
Tercio@11 3131 self.no_right_click_close = nil
Tercio@11 3132 else
Tercio@11 3133 self.no_right_click_close = true
Tercio@11 3134 end
Tercio@11 3135 end
Tercio@11 3136 end
Tercio@11 3137
Tercio@11 3138 function DF:CreateChartPanel (parent, w, h, name)
Tercio@11 3139
Tercio@11 3140 if (not name) then
Tercio@11 3141 name = "DFPanel" .. DF.PanelCounter
Tercio@11 3142 DF.PanelCounter = DF.PanelCounter + 1
Tercio@11 3143 end
Tercio@11 3144
Tercio@11 3145 parent = parent or UIParent
Tercio@11 3146 w = w or 800
Tercio@11 3147 h = h or 500
Tercio@11 3148
Tercio@11 3149 local f = CreateFrame ("frame", name, parent)
Tercio@11 3150 f:SetSize (w or 500, h or 400)
Tercio@11 3151 f:EnableMouse (true)
Tercio@11 3152 f:SetMovable (true)
Tercio@11 3153
Tercio@11 3154 f:SetScript ("OnMouseDown", chart_panel_mousedown)
Tercio@11 3155 f:SetScript ("OnMouseUp", chart_panel_mouseup)
Tercio@11 3156
Tercio@11 3157 f:SetBackdrop (chart_panel_backdrop)
Tercio@11 3158 f:SetBackdropColor (.3, .3, .3, .3)
Tercio@11 3159
Tercio@11 3160 local c = CreateFrame ("Button", nil, f, "UIPanelCloseButton")
Tercio@11 3161 c:SetWidth (32)
Tercio@11 3162 c:SetHeight (32)
Tercio@11 3163 c:SetPoint ("TOPRIGHT", f, "TOPRIGHT", -3, -7)
Tercio@11 3164 c:SetFrameLevel (f:GetFrameLevel()+1)
Tercio@11 3165 c:SetAlpha (0.9)
Tercio@11 3166 f.CloseButton = c
Tercio@11 3167
Tercio@11 3168 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0})
Tercio@11 3169 title:SetPoint ("topleft", f, "topleft", 110, -13)
Tercio@11 3170
Tercio@11 3171 f.Overlays = {}
Tercio@11 3172 f.OverlaysAmount = 1
Tercio@11 3173
Tercio@11 3174 f.BoxLabels = {}
Tercio@11 3175 f.BoxLabelsAmount = 1
Tercio@11 3176
Tercio@56 3177 f.ShowHeader = true
Tercio@56 3178 f.HeaderOnlyIndicator = false
Tercio@56 3179 f.HeaderShowOverlays = true
Tercio@11 3180
Tercio@11 3181 --graphic
Tercio@11 3182 local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67)
Tercio@11 3183 g:SetXAxis (-1,1)
Tercio@11 3184 g:SetYAxis (-1,1)
Tercio@11 3185 g:SetGridSpacing (false, false)
Tercio@11 3186 g:SetGridColor ({0.5,0.5,0.5,0.3})
Tercio@11 3187 g:SetAxisDrawing (false,false)
Tercio@11 3188 g:SetAxisColor({1.0,1.0,1.0,1.0})
Tercio@11 3189 g:SetAutoScale (true)
Tercio@11 3190 g:SetLineTexture ("smallline")
Tercio@11 3191 g:SetBorderSize ("right", 0.001)
Tercio@11 3192 g:SetBorderSize ("left", 0.000)
Tercio@11 3193 g:SetBorderSize ("top", 0.002)
Tercio@11 3194 g:SetBorderSize ("bottom", 0.001)
Tercio@11 3195 g.VerticalLines = {}
Tercio@11 3196 g.max_value = 0
Tercio@11 3197
Tercio@11 3198 g:SetLineTexture ("line")
Tercio@11 3199
Tercio@11 3200 f.Graphic = g
Tercio@11 3201 f.GData = {}
Tercio@11 3202 f.OData = {}
Tercio@56 3203 f.ChartFrames = {}
Tercio@11 3204
Tercio@11 3205 --div lines
Tercio@11 3206 for i = 1, 8, 1 do
Tercio@11 3207 local line = g:CreateTexture (nil, "overlay")
Tercio@56 3208 line:SetColorTexture (1, 1, 1, .05)
Tercio@11 3209 line:SetWidth (670)
Tercio@11 3210 line:SetHeight (1.1)
Tercio@11 3211
Tercio@11 3212 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 3213 f ["dpsamt"..i] = s
Tercio@11 3214 s:SetText ("100k")
Tercio@11 3215 s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i)))
Tercio@11 3216
Tercio@11 3217 line:SetPoint ("topleft", s, "bottom", -27, 0)
Tercio@56 3218 line:SetPoint ("topright", g, "right", 0, 0)
Tercio@11 3219 s.line = line
Tercio@11 3220 end
Tercio@11 3221
Tercio@56 3222 --create time labels and the bottom texture to use as a background to these labels
Tercio@56 3223 f.TimeLabels = {}
Tercio@56 3224 f.TimeLabelsHeight = 16
Tercio@56 3225
Tercio@56 3226 for i = 1, 17 do
Tercio@56 3227 local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@56 3228 time:SetText ("00:00")
Tercio@56 3229 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), f.TimeLabelsHeight)
Tercio@56 3230 f.TimeLabels [i] = time
Tercio@56 3231
Tercio@56 3232 local line = f:CreateTexture (nil, "border")
Tercio@56 3233 line:SetSize (1, h-45)
Tercio@56 3234 line:SetColorTexture (1, 1, 1, .1)
Tercio@56 3235 line:SetPoint ("bottomleft", time, "topright", 0, -10)
Tercio@56 3236 line:Hide()
Tercio@56 3237 time.line = line
Tercio@56 3238 end
Tercio@56 3239
Tercio@56 3240 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
Tercio@56 3241 bottom_texture:SetColorTexture (.1, .1, .1, .7)
Tercio@56 3242 bottom_texture:SetPoint ("topright", g, "bottomright", 0, 0)
Tercio@56 3243 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 12)
Tercio@56 3244
Tercio@56 3245
Tercio@56 3246
Tercio@11 3247 f.SetTime = chart_panel_align_timelabels
Tercio@11 3248 f.EnableVerticalLines = chart_panel_vlines_on
Tercio@11 3249 f.DisableVerticalLines = chart_panel_vlines_off
Tercio@11 3250 f.SetTitle = chart_panel_set_title
Tercio@11 3251 f.SetScale = chart_panel_set_scale
Tercio@11 3252 f.Reset = chart_panel_reset
Tercio@11 3253 f.AddLine = chart_panel_add_data
Tercio@11 3254 f.CanMove = chart_panel_can_move
Tercio@11 3255 f.AddLabel = chart_panel_add_label
Tercio@11 3256 f.AddOverlay = chart_panel_add_overlay
Tercio@11 3257 f.HideCloseButton = chart_panel_hide_close_button
Tercio@11 3258 f.RightClickClose = chart_panel_right_click_close
Tercio@56 3259 f.CalcStdDev = calc_stddev
Tercio@56 3260 f.CalcLowessSmoothing = calc_lowess_smoothing
Tercio@11 3261
Tercio@11 3262 f:SetScript ("OnSizeChanged", chart_panel_onresize)
Tercio@11 3263 chart_panel_onresize (f)
Tercio@11 3264
Tercio@11 3265 return f
Tercio@20 3266 end
Tercio@20 3267
Tercio@20 3268 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@20 3269 -- ~gframe
Tercio@20 3270 local gframe_on_enter_line = function (self)
Tercio@20 3271 self:SetBackdropColor (0, 0, 0, 0)
Tercio@20 3272
Tercio@20 3273 local parent = self:GetParent()
Tercio@20 3274 local ball = self.ball
Tercio@20 3275 ball:SetBlendMode ("ADD")
Tercio@20 3276
Tercio@20 3277 local on_enter = parent._onenter_line
Tercio@20 3278 if (on_enter) then
Tercio@20 3279 return on_enter (self, parent)
Tercio@20 3280 end
Tercio@20 3281 end
Tercio@20 3282
Tercio@20 3283 local gframe_on_leave_line = function (self)
Tercio@20 3284 self:SetBackdropColor (0, 0, 0, .6)
Tercio@20 3285
Tercio@20 3286 local parent = self:GetParent()
Tercio@20 3287 local ball = self.ball
Tercio@20 3288 ball:SetBlendMode ("BLEND")
Tercio@20 3289
Tercio@20 3290 local on_leave = parent._onleave_line
Tercio@20 3291 if (on_leave) then
Tercio@20 3292 return on_leave (self, parent)
Tercio@20 3293 end
Tercio@20 3294 end
Tercio@20 3295
Tercio@20 3296 local gframe_create_line = function (self)
Tercio@20 3297 local index = #self._lines+1
Tercio@20 3298
Tercio@20 3299 local f = CreateFrame ("frame", nil, self)
Tercio@20 3300 self._lines [index] = f
Tercio@20 3301 f.id = index
Tercio@20 3302 f:SetScript ("OnEnter", gframe_on_enter_line)
Tercio@20 3303 f:SetScript ("OnLeave", gframe_on_leave_line)
Tercio@20 3304
Tercio@20 3305 f:SetWidth (self._linewidth)
Tercio@20 3306
Tercio@20 3307 if (index == 1) then
Tercio@20 3308 f:SetPoint ("topleft", self, "topleft")
Tercio@20 3309 f:SetPoint ("bottomleft", self, "bottomleft")
Tercio@20 3310 else
Tercio@20 3311 local previous_line = self._lines [index-1]
Tercio@20 3312 f:SetPoint ("topleft", previous_line, "topright")
Tercio@20 3313 f:SetPoint ("bottomleft", previous_line, "bottomright")
Tercio@20 3314 end
Tercio@20 3315
Tercio@20 3316 local t = f:CreateTexture (nil, "background")
Tercio@20 3317 t:SetWidth (1)
Tercio@20 3318 t:SetPoint ("topright", f, "topright")
Tercio@20 3319 t:SetPoint ("bottomright", f, "bottomright")
Tercio@39 3320 t:SetColorTexture (1, 1, 1, .1)
Tercio@20 3321 f.grid = t
Tercio@20 3322
Tercio@20 3323 local b = f:CreateTexture (nil, "overlay")
Tercio@20 3324 b:SetTexture ([[Interface\COMMON\Indicator-Yellow]])
Tercio@20 3325 b:SetSize (16, 16)
Tercio@20 3326 f.ball = b
Tercio@20 3327 local anchor = CreateFrame ("frame", nil, f)
Tercio@20 3328 anchor:SetAllPoints (b)
Tercio@20 3329 b.tooltip_anchor = anchor
Tercio@20 3330
Tercio@20 3331 local spellicon = f:CreateTexture (nil, "artwork")
Tercio@20 3332 spellicon:SetPoint ("bottom", b, "bottom", 0, 10)
Tercio@20 3333 spellicon:SetSize (16, 16)
Tercio@20 3334 f.spellicon = spellicon
Tercio@20 3335
Tercio@53 3336 local text = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@53 3337 local textBackground = f:CreateTexture (nil, "artwork")
Tercio@53 3338 textBackground:SetSize (30, 16)
Tercio@53 3339 textBackground:SetColorTexture (0, 0, 0, 0.5)
Tercio@53 3340 textBackground:SetPoint ("bottom", f.ball, "top", 0, -6)
Tercio@53 3341 text:SetPoint ("center", textBackground, "center")
Tercio@53 3342 DF:SetFontSize (text, 10)
Tercio@53 3343 f.text = text
Tercio@53 3344 f.textBackground = textBackground
Tercio@53 3345
Tercio@20 3346 local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@20 3347 timeline:SetPoint ("bottomright", f, "bottomright", -2, 0)
Tercio@40 3348 DF:SetFontSize (timeline, 8)
Tercio@20 3349 f.timeline = timeline
Tercio@20 3350
Tercio@20 3351 return f
Tercio@20 3352 end
Tercio@20 3353
Tercio@20 3354 local gframe_getline = function (self, index)
Tercio@20 3355 local line = self._lines [index]
Tercio@20 3356 if (not line) then
Tercio@20 3357 line = gframe_create_line (self)
Tercio@20 3358 end
Tercio@20 3359 return line
Tercio@20 3360 end
Tercio@20 3361
Tercio@20 3362 local gframe_reset = function (self)
Tercio@20 3363 for i, line in ipairs (self._lines) do
Tercio@20 3364 line:Hide()
Tercio@20 3365 end
Tercio@20 3366 if (self.GraphLib_Lines_Used) then
Tercio@20 3367 for i = #self.GraphLib_Lines_Used, 1, -1 do
Tercio@20 3368 local line = tremove (self.GraphLib_Lines_Used)
Tercio@20 3369 tinsert (self.GraphLib_Lines, line)
Tercio@20 3370 line:Hide()
Tercio@20 3371 end
Tercio@20 3372 end
Tercio@20 3373 end
Tercio@20 3374
Tercio@20 3375 local gframe_update = function (self, lines)
Tercio@20 3376
Tercio@20 3377 local g = LibStub:GetLibrary ("LibGraph-2.0")
Tercio@20 3378 local h = self:GetHeight()/100
Tercio@20 3379 local amtlines = #lines
Tercio@20 3380 local linewidth = self._linewidth
Tercio@20 3381
Tercio@20 3382 local max_value = 0
Tercio@20 3383 for i = 1, amtlines do
Tercio@20 3384 if (lines [i].value > max_value) then
Tercio@20 3385 max_value = lines [i].value
Tercio@20 3386 end
Tercio@20 3387 end
Tercio@20 3388
Tercio@40 3389 self.MaxValue = max_value
Tercio@40 3390
Tercio@20 3391 local o = 1
Tercio@20 3392 local lastvalue = self:GetHeight()/2
Tercio@40 3393 max_value = math.max (max_value, 0.0000001)
Tercio@20 3394
Tercio@20 3395 for i = 1, min (amtlines, self._maxlines) do
Tercio@20 3396
Tercio@20 3397 local data = lines [i]
Tercio@20 3398
Tercio@20 3399 local pvalue = data.value / max_value * 100
Tercio@20 3400 if (pvalue > 98) then
Tercio@20 3401 pvalue = 98
Tercio@20 3402 end
Tercio@20 3403 pvalue = pvalue * h
Tercio@20 3404
Tercio@20 3405 g:DrawLine (self, (o-1)*linewidth, lastvalue, o*linewidth, pvalue, linewidth, {1, 1, 1, 1}, "overlay")
Tercio@20 3406 lastvalue = pvalue
Tercio@20 3407
Tercio@20 3408 local line = self:GetLine (i)
Tercio@20 3409 line:Show()
Tercio@20 3410 line.ball:Show()
Tercio@20 3411
Tercio@20 3412 line.ball:SetPoint ("bottomleft", self, "bottomleft", (o*linewidth)-8, pvalue-8)
Tercio@20 3413 line.spellicon:SetTexture (nil)
Tercio@20 3414 line.timeline:SetText (data.text)
Tercio@20 3415 line.timeline:Show()
Tercio@20 3416
Tercio@53 3417 if (data.utext) then
Tercio@53 3418 line.text:Show()
Tercio@53 3419 line.textBackground:Show()
Tercio@53 3420 line.text:SetText (data.utext)
Tercio@53 3421 else
Tercio@53 3422 line.text:Hide()
Tercio@53 3423 line.textBackground:Hide()
Tercio@53 3424 end
Tercio@53 3425
Tercio@20 3426 line.data = data
Tercio@20 3427
Tercio@20 3428 o = o + 1
Tercio@20 3429 end
Tercio@20 3430
Tercio@20 3431 end
Tercio@20 3432
Tercio@20 3433 function DF:CreateGFrame (parent, w, h, linewidth, onenter, onleave, member, name)
Tercio@20 3434 local f = CreateFrame ("frame", name, parent)
Tercio@20 3435 f:SetSize (w or 450, h or 150)
Tercio@45 3436 --f.CustomLine = [[Interface\AddOns\Details\Libs\LibGraph-2.0\line]]
Tercio@20 3437
Tercio@20 3438 if (member) then
Tercio@20 3439 parent [member] = f
Tercio@20 3440 end
Tercio@20 3441
Tercio@20 3442 f.CreateLine = gframe_create_line
Tercio@20 3443 f.GetLine = gframe_getline
Tercio@20 3444 f.Reset = gframe_reset
Tercio@20 3445 f.UpdateLines = gframe_update
Tercio@20 3446
Tercio@40 3447 f.MaxValue = 0
Tercio@40 3448
Tercio@20 3449 f._lines = {}
Tercio@20 3450
Tercio@20 3451 f._onenter_line = onenter
Tercio@20 3452 f._onleave_line = onleave
Tercio@20 3453
Tercio@20 3454 f._linewidth = linewidth or 50
Tercio@20 3455 f._maxlines = floor (f:GetWidth() / f._linewidth)
Tercio@20 3456
Tercio@20 3457 return f
Tercio@39 3458 end
Tercio@39 3459
Tercio@39 3460
Tercio@39 3461 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@39 3462 -- ~buttoncontainer
Tercio@39 3463
Tercio@39 3464 function DF:CreateButtonContainer (parent, name)
Tercio@39 3465 local f = CreateFrame ("frame", name, parent)
Tercio@39 3466 -- f.
Tercio@39 3467 end
Tercio@39 3468
Tercio@39 3469
Tercio@39 3470 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@39 3471 --> options tabs and buttons -dot
Tercio@39 3472
Tercio@39 3473 function DF:FindHighestParent (self)
Tercio@39 3474 local f
Tercio@39 3475 if (self:GetParent() == UIParent) then
Tercio@39 3476 f = self
Tercio@39 3477 end
Tercio@39 3478 if (not f) then
Tercio@39 3479 f = self
Tercio@39 3480 for i = 1, 6 do
Tercio@39 3481 local parent = f:GetParent()
Tercio@39 3482 if (parent == UIParent) then
Tercio@39 3483 break
Tercio@39 3484 else
Tercio@39 3485 f = parent
Tercio@39 3486 end
Tercio@39 3487 end
Tercio@39 3488 end
Tercio@39 3489
Tercio@39 3490 return f
Tercio@39 3491 end
Tercio@39 3492
Tercio@39 3493 DF.TabContainerFunctions = {}
Tercio@39 3494
Tercio@39 3495 local button_tab_template = DF.table.copy ({}, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
Tercio@39 3496 button_tab_template.backdropbordercolor = nil
Tercio@39 3497
Tercio@39 3498 DF.TabContainerFunctions.CreateUnderlineGlow = function (button)
Tercio@39 3499 local selectedGlow = button:CreateTexture (nil, "background", -4)
Tercio@39 3500 selectedGlow:SetPoint ("topleft", button.widget, "bottomleft", -7, 0)
Tercio@39 3501 selectedGlow:SetPoint ("topright", button.widget, "bottomright", 7, 0)
Tercio@39 3502 selectedGlow:SetTexture ([[Interface\BUTTONS\UI-Panel-Button-Glow]])
Tercio@39 3503 selectedGlow:SetTexCoord (0, 95/128, 30/64, 38/64)
Tercio@39 3504 selectedGlow:SetBlendMode ("ADD")
Tercio@39 3505 selectedGlow:SetHeight (8)
Tercio@39 3506 selectedGlow:SetAlpha (.75)
Tercio@39 3507 selectedGlow:Hide()
Tercio@39 3508 button.selectedUnderlineGlow = selectedGlow
Tercio@39 3509 end
Tercio@39 3510
Tercio@39 3511 DF.TabContainerFunctions.OnMouseDown = function (self, button)
Tercio@39 3512 --> search for UIParent
Tercio@39 3513 local f = DF:FindHighestParent (self)
Tercio@39 3514 local container = self:GetParent()
Tercio@39 3515
Tercio@39 3516 if (button == "LeftButton") then
Tercio@39 3517 if (not f.IsMoving and f:IsMovable()) then
Tercio@39 3518 f:StartMoving()
Tercio@39 3519 f.IsMoving = true
Tercio@39 3520 end
Tercio@39 3521 elseif (button == "RightButton") then
Tercio@39 3522 if (not f.IsMoving and container.IsContainer) then
Tercio@39 3523 if (self.IsFrontPage) then
Tercio@39 3524 if (container.CanCloseWithRightClick) then
Tercio@39 3525 if (f.CloseFunction) then
Tercio@39 3526 f:CloseFunction()
Tercio@39 3527 else
Tercio@39 3528 f:Hide()
Tercio@39 3529 end
Tercio@39 3530 end
Tercio@39 3531 else
Tercio@39 3532 --goes back to front page
Tercio@39 3533 DF.TabContainerFunctions.SelectIndex (self, _, 1)
Tercio@39 3534 end
Tercio@39 3535 end
Tercio@39 3536 end
Tercio@39 3537 end
Tercio@39 3538
Tercio@39 3539 DF.TabContainerFunctions.OnMouseUp = function (self, button)
Tercio@39 3540 local f = DF:FindHighestParent (self)
Tercio@39 3541 if (f.IsMoving) then
Tercio@39 3542 f:StopMovingOrSizing()
Tercio@39 3543 f.IsMoving = false
Tercio@39 3544 end
Tercio@39 3545 end
Tercio@39 3546
Tercio@39 3547 DF.TabContainerFunctions.SelectIndex = function (self, fixedParam, menuIndex)
Tercio@39 3548 local mainFrame = self.AllFrames and self or self.mainFrame or self:GetParent()
Tercio@39 3549
Tercio@39 3550 for i = 1, #mainFrame.AllFrames do
Tercio@39 3551 mainFrame.AllFrames[i]:Hide()
Tercio@39 3552 if (mainFrame.ButtonNotSelectedBorderColor) then
Tercio@39 3553 mainFrame.AllButtons[i]:SetBackdropBorderColor (unpack (mainFrame.ButtonNotSelectedBorderColor))
Tercio@39 3554 end
Tercio@39 3555 if (mainFrame.AllButtons[i].selectedUnderlineGlow) then
Tercio@39 3556 mainFrame.AllButtons[i].selectedUnderlineGlow:Hide()
Tercio@39 3557 end
Tercio@39 3558 end
Tercio@39 3559
Tercio@39 3560 mainFrame.AllFrames[menuIndex]:Show()
Tercio@39 3561 if (mainFrame.ButtonSelectedBorderColor) then
Tercio@39 3562 mainFrame.AllButtons[menuIndex]:SetBackdropBorderColor (unpack (mainFrame.ButtonSelectedBorderColor))
Tercio@39 3563 end
Tercio@39 3564 if (mainFrame.AllButtons[menuIndex].selectedUnderlineGlow) then
Tercio@39 3565 mainFrame.AllButtons[menuIndex].selectedUnderlineGlow:Show()
Tercio@39 3566 end
Tercio@39 3567 mainFrame.CurrentIndex = menuIndex
Tercio@39 3568 end
Tercio@39 3569
Tercio@39 3570 DF.TabContainerFunctions.SetIndex = function (self, index)
Tercio@39 3571 self.CurrentIndex = index
Tercio@39 3572 end
Tercio@39 3573
Tercio@39 3574 local tab_container_on_show = function (self)
Tercio@39 3575 local index = self.CurrentIndex
Tercio@39 3576 self.SelectIndex (self.AllButtons[index], nil, index)
Tercio@39 3577 end
Tercio@39 3578
Tercio@39 3579 function DF:CreateTabContainer (parent, title, frame_name, frame_list, options_table)
Tercio@39 3580
Tercio@39 3581 local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
Tercio@39 3582 local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
Tercio@39 3583 local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
Tercio@39 3584 local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
Tercio@39 3585 local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
Tercio@39 3586
Tercio@39 3587 options_table = options_table or {}
Tercio@39 3588 local frame_width = parent:GetWidth()
Tercio@39 3589 local frame_height = parent:GetHeight()
Tercio@39 3590 local y_offset = options_table.y_offset or 0
Tercio@39 3591 local button_width = options_table.button_width or 160
Tercio@39 3592 local button_height = options_table.button_height or 20
Tercio@39 3593 local button_anchor_x = options_table.button_x or 230
Tercio@39 3594 local button_anchor_y = options_table.button_y or -32
Tercio@39 3595 local button_text_size = options_table.button_text_size or 10
Tercio@39 3596
Tercio@39 3597 local mainFrame = CreateFrame ("frame", frame_name, parent.widget or parent)
Tercio@39 3598 mainFrame:SetAllPoints()
Tercio@39 3599 DF:Mixin (mainFrame, DF.TabContainerFunctions)
Tercio@39 3600
Tercio@39 3601 local mainTitle = DF:CreateLabel (mainFrame, title, 24, "white")
Tercio@39 3602 mainTitle:SetPoint ("topleft", mainFrame, "topleft", 10, -30 + y_offset)
Tercio@39 3603
Tercio@39 3604 mainFrame:SetFrameLevel (200)
Tercio@39 3605
Tercio@39 3606 mainFrame.AllFrames = {}
Tercio@39 3607 mainFrame.AllButtons = {}
Tercio@39 3608 mainFrame.CurrentIndex = 1
Tercio@39 3609 mainFrame.IsContainer = true
Tercio@39 3610 mainFrame.ButtonSelectedBorderColor = options_table.button_selected_border_color or {1, 1, 0, 1}
Tercio@39 3611 mainFrame.ButtonNotSelectedBorderColor = options_table.button_border_color or {0, 0, 0, 0}
Tercio@39 3612
Tercio@39 3613 if (options_table.right_click_interact ~= nil) then
Tercio@39 3614 mainFrame.CanCloseWithRightClick = options_table.right_click_interact
Tercio@39 3615 else
Tercio@39 3616 mainFrame.CanCloseWithRightClick = true
Tercio@39 3617 end
Tercio@39 3618
Tercio@39 3619 for i, frame in ipairs (frame_list) do
Tercio@39 3620 local f = CreateFrame ("frame", "$parent" .. frame.name, mainFrame)
Tercio@39 3621 f:SetAllPoints()
Tercio@39 3622 f:SetFrameLevel (210)
Tercio@39 3623 f:Hide()
Tercio@39 3624
Tercio@39 3625 local title = DF:CreateLabel (f, frame.title, 16, "silver")
Tercio@39 3626 title:SetPoint ("topleft", mainTitle, "bottomleft", 0, 0)
Tercio@39 3627
Tercio@39 3628 local tabButton = DF:CreateButton (mainFrame, DF.TabContainerFunctions.SelectIndex, button_width, button_height, frame.title, i, nil, nil, nil, nil, false, button_tab_template)
Tercio@39 3629 tabButton:SetFrameLevel (220)
Tercio@39 3630 tabButton.textsize = button_text_size
Tercio@39 3631 tabButton.mainFrame = mainFrame
Tercio@39 3632 DF.TabContainerFunctions.CreateUnderlineGlow (tabButton)
Tercio@39 3633
Tercio@58 3634 local right_click_to_back
Tercio@39 3635 if (i == 1) then
Tercio@58 3636 right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray")
Tercio@39 3637 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
Tercio@39 3638 f.IsFrontPage = true
Tercio@39 3639 else
Tercio@58 3640 right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray")
Tercio@39 3641 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
Tercio@39 3642 end
Tercio@39 3643
Tercio@58 3644 if (options_table.hide_click_label) then
Tercio@58 3645 right_click_to_back:Hide()
Tercio@58 3646 end
Tercio@58 3647
Tercio@39 3648 f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown)
Tercio@39 3649 f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp)
Tercio@39 3650
Tercio@39 3651 tinsert (mainFrame.AllFrames, f)
Tercio@39 3652 tinsert (mainFrame.AllButtons, tabButton)
Tercio@39 3653 end
Tercio@39 3654
Tercio@39 3655 --order buttons
Tercio@39 3656 local x = button_anchor_x
Tercio@39 3657 local y = button_anchor_y
Tercio@39 3658 local space_for_buttons = frame_width - (#frame_list*3) - button_anchor_x
Tercio@39 3659 local amount_buttons_per_row = floor (space_for_buttons / button_width)
Tercio@39 3660 local last_button = mainFrame.AllButtons[1]
Tercio@39 3661
Tercio@39 3662 mainFrame.AllButtons[1]:SetPoint ("topleft", mainTitle, "topleft", x, y)
Tercio@39 3663 x = x + button_width + 2
Tercio@39 3664
Tercio@39 3665 for i = 2, #mainFrame.AllButtons do
Tercio@39 3666 local button = mainFrame.AllButtons [i]
Tercio@39 3667 button:SetPoint ("topleft", mainTitle, "topleft", x, y)
Tercio@39 3668 x = x + button_width + 2
Tercio@39 3669
Tercio@39 3670 if (i % amount_buttons_per_row == 0) then
Tercio@39 3671 x = button_anchor_x
Tercio@39 3672 y = y - button_height - 1
Tercio@39 3673 end
Tercio@39 3674 end
Tercio@39 3675
Tercio@39 3676 --> when show the frame, reset to the current internal index
Tercio@39 3677 mainFrame:SetScript ("OnShow", tab_container_on_show)
Tercio@39 3678 --> select the first frame
Tercio@39 3679 mainFrame.SelectIndex (mainFrame.AllButtons[1], nil, 1)
Tercio@39 3680
Tercio@39 3681 return mainFrame
Tercio@39 3682 end
Tercio@39 3683
Tercio@39 3684
Tercio@39 3685
Tercio@39 3686
Tercio@39 3687
Tercio@40 3688 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@40 3689 -- ~listbox
Tercio@39 3690
Tercio@40 3691 local simple_list_box_ResetWidgets = function (self)
Tercio@40 3692 for _, widget in ipairs (self.widgets) do
Tercio@40 3693 widget:Hide()
Tercio@40 3694 end
Tercio@40 3695 self.nextWidget = 1
Tercio@40 3696 end
Tercio@39 3697
Tercio@40 3698 local simple_list_box_onenter = function (self, capsule)
Tercio@40 3699 self:GetParent().options.onenter (self, capsule, capsule.value)
Tercio@40 3700 end
Tercio@39 3701
Tercio@40 3702 local simple_list_box_onleave = function (self, capsule)
Tercio@40 3703 self:GetParent().options.onleave (self, capsule, capsule.value)
Tercio@40 3704 GameTooltip:Hide()
Tercio@40 3705 end
Tercio@39 3706
Tercio@40 3707 local simple_list_box_GetOrCreateWidget = function (self)
Tercio@40 3708 local index = self.nextWidget
Tercio@40 3709 local widget = self.widgets [index]
Tercio@40 3710 if (not widget) then
Tercio@40 3711 widget = DF:CreateButton (self, function()end, self.options.width, self.options.row_height, "", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
Tercio@40 3712 widget:SetHook ("OnEnter", simple_list_box_onenter)
Tercio@40 3713 widget:SetHook ("OnLeave", simple_list_box_onleave)
Tercio@40 3714 widget.textcolor = self.options.textcolor
Tercio@58 3715 widget.textsize = self.options.text_size
Tercio@58 3716 widget.onleave_backdrop = self.options.backdrop_color
Tercio@58 3717
Tercio@58 3718 widget.XButton = DF:CreateButton (widget, function()end, 16, 16)
Tercio@58 3719 widget.XButton:SetPoint ("topright", widget.widget, "topright")
Tercio@58 3720 widget.XButton:SetIcon ([[Interface\BUTTONS\UI-Panel-MinimizeButton-Up]], 16, 16, "overlay", nil, nil, 0, -4, 0, false)
Tercio@58 3721 widget.XButton.icon:SetDesaturated (true)
Tercio@58 3722
Tercio@58 3723 if (not self.options.show_x_button) then
Tercio@58 3724 widget.XButton:Hide()
Tercio@58 3725 end
Tercio@58 3726
Tercio@40 3727 tinsert (self.widgets, widget)
Tercio@40 3728 end
Tercio@40 3729 self.nextWidget = self.nextWidget + 1
Tercio@40 3730 return widget
Tercio@40 3731 end
Tercio@39 3732
Tercio@40 3733 local simple_list_box_RefreshWidgets = function (self)
Tercio@40 3734 self:ResetWidgets()
Tercio@40 3735 local amt = 0
Tercio@40 3736 for value, _ in pairs (self.list_table) do
Tercio@40 3737 local widget = self:GetOrCreateWidget()
Tercio@40 3738 widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4)
Tercio@40 3739 widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4)
Tercio@58 3740
Tercio@40 3741 widget:SetClickFunction (self.func, value)
Tercio@58 3742
Tercio@58 3743 if (self.options.show_x_button) then
Tercio@58 3744 widget.XButton:SetClickFunction (self.options.x_button_func, value)
Tercio@58 3745 widget.XButton.value = value
Tercio@58 3746 widget.XButton:Show()
Tercio@58 3747 else
Tercio@58 3748 widget.XButton:Hide()
Tercio@58 3749 end
Tercio@58 3750
Tercio@40 3751 widget.value = value
Tercio@40 3752
Tercio@40 3753 if (self.options.icon) then
Tercio@40 3754 if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then
Tercio@58 3755 local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1}
Tercio@58 3756 widget:SetIcon (self.options.icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords)
Tercio@58 3757
Tercio@40 3758 elseif (type (self.options.icon) == "function") then
Tercio@40 3759 local icon = self.options.icon (value)
Tercio@40 3760 if (icon) then
Tercio@58 3761 local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1}
Tercio@58 3762 widget:SetIcon (icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords)
Tercio@40 3763 end
Tercio@40 3764 end
Tercio@40 3765 else
Tercio@40 3766 widget:SetIcon ("", self.options.row_height, self.options.row_height)
Tercio@40 3767 end
Tercio@40 3768
Tercio@40 3769 if (self.options.text) then
Tercio@40 3770 if (type (self.options.text) == "function") then
Tercio@40 3771 local text = self.options.text (value)
Tercio@40 3772 if (text) then
Tercio@40 3773 widget:SetText (text)
Tercio@40 3774 else
Tercio@40 3775 widget:SetText ("")
Tercio@40 3776 end
Tercio@40 3777 else
Tercio@40 3778 widget:SetText (self.options.text or "")
Tercio@40 3779 end
Tercio@40 3780 else
Tercio@40 3781 widget:SetText ("")
Tercio@40 3782 end
Tercio@40 3783
Tercio@40 3784 widget.value = value
Tercio@58 3785
Tercio@58 3786 local r, g, b, a = DF:ParseColors (self.options.backdrop_color)
Tercio@58 3787 widget:SetBackdropColor (r, g, b, a)
Tercio@58 3788
Tercio@40 3789 widget:Show()
Tercio@40 3790 amt = amt + 1
Tercio@40 3791 end
Tercio@40 3792 if (amt == 0) then
Tercio@40 3793 self.EmptyLabel:Show()
Tercio@40 3794 else
Tercio@40 3795 self.EmptyLabel:Hide()
Tercio@40 3796 end
Tercio@40 3797 end
Tercio@39 3798
Tercio@40 3799 local backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}
Tercio@40 3800 local default_options = {
Tercio@40 3801 height = 400,
Tercio@40 3802 row_height = 16,
Tercio@40 3803 width = 230,
Tercio@40 3804 icon = false,
Tercio@40 3805 text = "",
Tercio@58 3806 text_size = 10,
Tercio@40 3807 textcolor = "wheat",
Tercio@58 3808
Tercio@58 3809 backdrop_color = {1, 1, 1, .5},
Tercio@58 3810 panel_border_color = {0, 0, 0, 0.5},
Tercio@58 3811
Tercio@40 3812 onenter = function (self, capsule)
Tercio@40 3813 if (capsule) then
Tercio@40 3814 capsule.textcolor = "white"
Tercio@40 3815 end
Tercio@40 3816 end,
Tercio@40 3817 onleave = function (self, capsule)
Tercio@40 3818 if (capsule) then
Tercio@40 3819 capsule.textcolor = self:GetParent().options.textcolor
Tercio@40 3820 end
Tercio@40 3821 GameTooltip:Hide()
Tercio@40 3822 end,
Tercio@40 3823 }
Tercio@39 3824
Tercio@40 3825 local simple_list_box_SetData = function (self, t)
Tercio@40 3826 self.list_table = t
Tercio@40 3827 end
Tercio@40 3828
Tercio@40 3829 function DF:CreateSimpleListBox (parent, name, title, empty_text, list_table, onclick, options)
Tercio@40 3830 local f = CreateFrame ("frame", name, parent)
Tercio@40 3831
Tercio@40 3832 f.ResetWidgets = simple_list_box_ResetWidgets
Tercio@40 3833 f.GetOrCreateWidget = simple_list_box_GetOrCreateWidget
Tercio@40 3834 f.Refresh = simple_list_box_RefreshWidgets
Tercio@40 3835 f.SetData = simple_list_box_SetData
Tercio@40 3836 f.nextWidget = 1
Tercio@40 3837 f.list_table = list_table
Tercio@40 3838 f.func = function (self, button, value)
Tercio@58 3839 --onclick (value)
Tercio@58 3840 DF:QuickDispatch (onclick, value)
Tercio@40 3841 f:Refresh()
Tercio@40 3842 end
Tercio@40 3843 f.widgets = {}
Tercio@58 3844
Tercio@58 3845 DF:ApplyStandardBackdrop (f)
Tercio@58 3846
Tercio@40 3847 f.options = options or {}
Tercio@40 3848 self.table.deploy (f.options, default_options)
Tercio@40 3849
Tercio@58 3850 if (f.options.x_button_func) then
Tercio@58 3851 local original_X_function = f.options.x_button_func
Tercio@58 3852 f.options.x_button_func = function (self, button, value)
Tercio@58 3853 DF:QuickDispatch (original_X_function, value)
Tercio@58 3854 f:Refresh()
Tercio@58 3855 end
Tercio@58 3856 end
Tercio@58 3857
Tercio@58 3858 f:SetBackdropBorderColor (unpack (f.options.panel_border_color))
Tercio@58 3859
Tercio@40 3860 f:SetSize (f.options.width + 2, f.options.height)
Tercio@40 3861
Tercio@40 3862 local name = DF:CreateLabel (f, title, 12, "silver")
Tercio@40 3863 name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@40 3864 name:SetPoint ("bottomleft", f, "topleft", 0, 2)
Tercio@40 3865 f.Title = name
Tercio@40 3866
Tercio@40 3867 local emptyLabel = DF:CreateLabel (f, empty_text, 12, "gray")
Tercio@40 3868 emptyLabel:SetAlpha (.6)
Tercio@40 3869 emptyLabel:SetSize (f.options.width-10, f.options.height)
Tercio@40 3870 emptyLabel:SetPoint ("center", 0, 0)
Tercio@40 3871 emptyLabel:Hide()
Tercio@40 3872 emptyLabel.align = "center"
Tercio@40 3873 f.EmptyLabel = emptyLabel
Tercio@40 3874
Tercio@40 3875 return f
Tercio@40 3876 end
Tercio@40 3877
Tercio@40 3878
Tercio@40 3879 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@40 3880 -- ~scrollbox
Tercio@40 3881
Tercio@40 3882 DF.SortFunctions = {}
Tercio@40 3883
Tercio@40 3884 local SortMember = ""
Tercio@40 3885 local SortByMember = function (t1, t2)
Tercio@40 3886 return t1[SortMember] > t2[SortMember]
Tercio@40 3887 end
Tercio@40 3888 local SortByMemberReverse = function (t1, t2)
Tercio@40 3889 return t1[SortMember] < t2[SortMember]
Tercio@40 3890 end
Tercio@40 3891
Tercio@40 3892 DF.SortFunctions.Sort = function (self, t, by, is_reverse)
Tercio@40 3893 SortMember = by
Tercio@40 3894 if (not is_reverse) then
Tercio@40 3895 table.sort (t, SortByMember)
Tercio@40 3896 else
Tercio@40 3897 table.sort (t, SortByMemberReverse)
Tercio@40 3898 end
Tercio@40 3899 end
Tercio@40 3900
Tercio@40 3901
Tercio@40 3902 DF.ScrollBoxFunctions = {}
Tercio@40 3903
Tercio@40 3904 DF.ScrollBoxFunctions.Refresh = function (self)
Tercio@40 3905 for _, frame in ipairs (self.Frames) do
Tercio@40 3906 frame:Hide()
Tercio@40 3907 frame._InUse = nil
Tercio@40 3908 end
Tercio@40 3909
Tercio@40 3910 local offset = 0
Tercio@40 3911 if (self.IsFauxScroll) then
Tercio@40 3912 FauxScrollFrame_Update (self, #self.data, self.LineAmount, self.LineHeight+1)
Tercio@40 3913 offset = FauxScrollFrame_GetOffset (self)
Tercio@40 3914 end
Tercio@40 3915
Tercio@53 3916 local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, self.LineAmount)
Tercio@40 3917 if (not okay) then
Tercio@40 3918 error ("Details! FrameWork: Refresh(): " .. totalLines)
Tercio@40 3919 end
Tercio@40 3920
Tercio@40 3921 for _, frame in ipairs (self.Frames) do
Tercio@40 3922 if (not frame._InUse) then
Tercio@40 3923 frame:Hide()
Tercio@40 3924 else
Tercio@40 3925 frame:Show()
Tercio@40 3926 end
Tercio@40 3927 end
Tercio@40 3928
Tercio@40 3929 self:Show()
Tercio@40 3930
Tercio@53 3931 if (self.HideScrollBar) then
Tercio@53 3932 local frameName = self:GetName()
Tercio@53 3933 if (frameName) then
Tercio@53 3934 local scrollBar = _G [frameName .. "ScrollBar"]
Tercio@53 3935 if (scrollBar) then
Tercio@53 3936 scrollBar:Hide()
Tercio@53 3937 end
Tercio@53 3938 else
Tercio@53 3939
Tercio@53 3940 end
Tercio@53 3941
Tercio@53 3942 end
Tercio@53 3943
Tercio@40 3944 return self.Frames
Tercio@40 3945 end
Tercio@40 3946
Tercio@40 3947 DF.ScrollBoxFunctions.OnVerticalScroll = function (self, offset)
Tercio@40 3948 FauxScrollFrame_OnVerticalScroll (self, offset, self.LineHeight, self.Refresh)
Tercio@40 3949 return true
Tercio@40 3950 end
Tercio@40 3951
Tercio@40 3952 DF.ScrollBoxFunctions.CreateLine = function (self, func)
Tercio@53 3953 if (not func) then
Tercio@53 3954 func = self.CreateLineFunc
Tercio@53 3955 end
Tercio@40 3956 local okay, newLine = pcall (func, self, #self.Frames+1)
Tercio@40 3957 if (okay) then
Tercio@40 3958 tinsert (self.Frames, newLine)
Tercio@53 3959 newLine.Index = #self.Frames
Tercio@40 3960 return newLine
Tercio@40 3961 else
Tercio@40 3962 error ("Details! FrameWork: CreateLine(): " .. newLine)
Tercio@40 3963 end
Tercio@40 3964 end
Tercio@40 3965
Tercio@40 3966 DF.ScrollBoxFunctions.GetLine = function (self, line_index)
Tercio@40 3967 local line = self.Frames [line_index]
Tercio@40 3968 if (line) then
Tercio@40 3969 line._InUse = true
Tercio@40 3970 end
Tercio@40 3971 return line
Tercio@40 3972 end
Tercio@40 3973
Tercio@40 3974 DF.ScrollBoxFunctions.SetData = function (self, data)
Tercio@40 3975 self.data = data
Tercio@40 3976 end
Tercio@40 3977 DF.ScrollBoxFunctions.GetData = function (self)
Tercio@40 3978 return self.data
Tercio@40 3979 end
Tercio@40 3980
Tercio@53 3981 DF.ScrollBoxFunctions.GetFrames = function (self)
Tercio@53 3982 return self.Frames
Tercio@53 3983 end
Tercio@53 3984
Tercio@53 3985 DF.ScrollBoxFunctions.GetNumFramesCreated = function (self)
Tercio@53 3986 return #self.Frames
Tercio@53 3987 end
Tercio@53 3988
Tercio@53 3989 DF.ScrollBoxFunctions.GetNumFramesShown = function (self)
Tercio@53 3990 return self.LineAmount
Tercio@53 3991 end
Tercio@53 3992
Tercio@53 3993 DF.ScrollBoxFunctions.SetNumFramesShown = function (self, new_amount)
Tercio@53 3994 --> hide frames which won't be used
Tercio@53 3995 if (new_amount < #self.Frames) then
Tercio@53 3996 for i = new_amount+1, #self.Frames do
Tercio@53 3997 self.Frames [i]:Hide()
Tercio@53 3998 end
Tercio@53 3999 end
Tercio@53 4000
Tercio@53 4001 --> set the new amount
Tercio@53 4002 self.LineAmount = new_amount
Tercio@53 4003 end
Tercio@53 4004
Tercio@53 4005 DF.ScrollBoxFunctions.SetFramesHeight = function (self, new_height)
Tercio@53 4006 self.LineHeight = new_height
Tercio@53 4007 self:OnSizeChanged()
Tercio@53 4008 self:Refresh()
Tercio@53 4009 end
Tercio@53 4010
Tercio@53 4011 DF.ScrollBoxFunctions.OnSizeChanged = function (self)
Tercio@53 4012 if (self.ReajustNumFrames) then
Tercio@53 4013 --> how many lines the scroll can show
Tercio@53 4014 local amountOfFramesToShow = floor (self:GetHeight() / self.LineHeight)
Tercio@53 4015
Tercio@53 4016 --> how many lines the scroll already have
Tercio@53 4017 local totalFramesCreated = self:GetNumFramesCreated()
Tercio@53 4018
Tercio@53 4019 --> how many lines are current shown
Tercio@53 4020 local totalFramesShown = self:GetNumFramesShown()
Tercio@53 4021
Tercio@53 4022 --> the amount of frames increased
Tercio@53 4023 if (amountOfFramesToShow > totalFramesShown) then
Tercio@53 4024 for i = totalFramesShown+1, amountOfFramesToShow do
Tercio@53 4025 --> check if need to create a new line
Tercio@53 4026 if (i > totalFramesCreated) then
Tercio@53 4027 self:CreateLine (self.CreateLineFunc)
Tercio@53 4028 end
Tercio@53 4029 end
Tercio@53 4030
Tercio@53 4031 --> the amount of frames decreased
Tercio@53 4032 elseif (amountOfFramesToShow < totalFramesShown) then
Tercio@53 4033 --> hide all frames above the new amount to show
Tercio@53 4034 for i = totalFramesCreated, amountOfFramesToShow, -1 do
Tercio@53 4035 if (self.Frames [i]) then
Tercio@53 4036 self.Frames [i]:Hide()
Tercio@53 4037 end
Tercio@53 4038 end
Tercio@53 4039 end
Tercio@53 4040
Tercio@53 4041 --> set the new amount of frames
Tercio@53 4042 self:SetNumFramesShown (amountOfFramesToShow)
Tercio@53 4043
Tercio@53 4044 --> refresh lines
Tercio@53 4045 self:Refresh()
Tercio@53 4046 end
Tercio@53 4047 end
Tercio@53 4048
Tercio@53 4049 function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height, create_line_func, auto_amount, no_scroll)
Tercio@40 4050 local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
Tercio@40 4051
Tercio@58 4052 DF:ApplyStandardBackdrop (scroll)
Tercio@58 4053
Tercio@40 4054 scroll:SetSize (width, height)
Tercio@40 4055 scroll.LineAmount = line_amount
Tercio@40 4056 scroll.LineHeight = line_height
Tercio@40 4057 scroll.IsFauxScroll = true
Tercio@53 4058 scroll.HideScrollBar = no_scroll
Tercio@40 4059 scroll.Frames = {}
Tercio@53 4060 scroll.ReajustNumFrames = auto_amount
Tercio@53 4061 scroll.CreateLineFunc = create_line_func
Tercio@40 4062
Tercio@40 4063 DF:Mixin (scroll, DF.SortFunctions)
Tercio@40 4064 DF:Mixin (scroll, DF.ScrollBoxFunctions)
Tercio@40 4065
Tercio@40 4066 scroll.refresh_func = refresh_func
Tercio@40 4067 scroll.data = data
Tercio@40 4068
Tercio@40 4069 scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll)
Tercio@53 4070 scroll:SetScript ("OnSizeChanged", DF.ScrollBoxFunctions.OnSizeChanged)
Tercio@40 4071
Tercio@40 4072 return scroll
Tercio@40 4073 end
Tercio@40 4074
Tercio@40 4075
Tercio@53 4076 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@53 4077 -- ~resizers
Tercio@40 4078
Tercio@53 4079 function DF:CreateResizeGrips (parent)
Tercio@53 4080 if (parent) then
Tercio@53 4081 local parentName = parent:GetName()
Tercio@53 4082
Tercio@53 4083 local leftResizer = CreateFrame ("button", parentName and parentName .. "LeftResizer" or nil, parent)
Tercio@53 4084 local rightResizer = CreateFrame ("button", parentName and parentName .. "RightResizer" or nil, parent)
Tercio@53 4085
Tercio@53 4086 leftResizer:SetPoint ("bottomleft", parent, "bottomleft")
Tercio@53 4087 rightResizer:SetPoint ("bottomright", parent, "bottomright")
Tercio@53 4088 leftResizer:SetSize (16, 16)
Tercio@53 4089 rightResizer:SetSize (16, 16)
Tercio@53 4090
Tercio@53 4091 rightResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]])
Tercio@53 4092 rightResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]])
Tercio@53 4093 rightResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]])
Tercio@53 4094 leftResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]])
Tercio@53 4095 leftResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]])
Tercio@53 4096 leftResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]])
Tercio@53 4097
Tercio@53 4098 leftResizer:GetNormalTexture():SetTexCoord (1, 0, 0, 1)
Tercio@53 4099 leftResizer:GetHighlightTexture():SetTexCoord (1, 0, 0, 1)
Tercio@53 4100 leftResizer:GetPushedTexture():SetTexCoord (1, 0, 0, 1)
Tercio@53 4101
Tercio@53 4102 return leftResizer, rightResizer
Tercio@53 4103 end
Tercio@53 4104 end
Tercio@58 4105
Tercio@58 4106
Tercio@58 4107 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@58 4108 -- ~keybind
Tercio@58 4109
Tercio@58 4110
Tercio@58 4111 --------------------------------
Tercio@58 4112 --> keybind frame ~key
Tercio@58 4113
Tercio@58 4114
Tercio@58 4115 local ignoredKeys = {
Tercio@58 4116 ["LSHIFT"] = true,
Tercio@58 4117 ["RSHIFT"] = true,
Tercio@58 4118 ["LCTRL"] = true,
Tercio@58 4119 ["RCTRL"] = true,
Tercio@58 4120 ["LALT"] = true,
Tercio@58 4121 ["RALT"] = true,
Tercio@58 4122 ["UNKNOWN"] = true,
Tercio@58 4123 }
Tercio@58 4124
Tercio@58 4125 local mouseKeys = {
Tercio@58 4126 ["LeftButton"] = "type1",
Tercio@58 4127 ["RightButton"] = "type2",
Tercio@58 4128 ["MiddleButton"] = "type3",
Tercio@58 4129 ["Button4"] = "type4",
Tercio@58 4130 ["Button5"] = "type5",
Tercio@58 4131 ["Button6"] = "type6",
Tercio@58 4132 ["Button7"] = "type7",
Tercio@58 4133 ["Button8"] = "type8",
Tercio@58 4134 ["Button9"] = "type9",
Tercio@58 4135 ["Button10"] = "type10",
Tercio@58 4136 ["Button11"] = "type11",
Tercio@58 4137 ["Button12"] = "type12",
Tercio@58 4138 ["Button13"] = "type13",
Tercio@58 4139 ["Button14"] = "type14",
Tercio@58 4140 ["Button15"] = "type15",
Tercio@58 4141 ["Button16"] = "type16",
Tercio@58 4142 }
Tercio@58 4143
Tercio@58 4144 local keysToMouse = {
Tercio@58 4145 ["type1"] = "LeftButton",
Tercio@58 4146 ["type2"] = "RightButton",
Tercio@58 4147 ["type3"] = "MiddleButton",
Tercio@58 4148 ["type4"] = "Button4",
Tercio@58 4149 ["type5"] = "Button5",
Tercio@58 4150 ["type6"] = "Button6",
Tercio@58 4151 ["type7"] = "Button7",
Tercio@58 4152 ["type8"] = "Button8",
Tercio@58 4153 ["type9"] = "Button9",
Tercio@58 4154 ["type10"] = "Button10",
Tercio@58 4155 ["type11"] = "Button11",
Tercio@58 4156 ["type12"] = "Button12",
Tercio@58 4157 ["type13"] = "Button13",
Tercio@58 4158 ["type14"] = "Button14",
Tercio@58 4159 ["type15"] = "Button15",
Tercio@58 4160 ["type16"] = "Button16",
Tercio@58 4161 }
Tercio@58 4162
Tercio@58 4163 local keybind_set_data = function (self, new_data_table)
Tercio@58 4164 self.Data = new_data_table
Tercio@58 4165 self.keybindScroll:UpdateScroll()
Tercio@58 4166 end
Tercio@58 4167
Tercio@58 4168 function DF:CreateKeybindBox (parent, name, data, callback, width, height, line_amount, line_height)
Tercio@58 4169
Tercio@58 4170 local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
Tercio@58 4171 local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
Tercio@58 4172 local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
Tercio@58 4173 local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
Tercio@58 4174 local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
Tercio@58 4175
Tercio@58 4176 local SCROLL_ROLL_AMOUNT = line_amount
Tercio@58 4177
Tercio@58 4178 --keybind set frame
Tercio@58 4179 local new_keybind_frame = CreateFrame ("frame", name, parent)
Tercio@58 4180 new_keybind_frame:SetSize (width, height)
Tercio@58 4181
Tercio@58 4182 -- keybind scrollframe
Tercio@58 4183 local keybindScroll = CreateFrame ("scrollframe", "$parentScrollFrame", new_keybind_frame, "FauxScrollFrameTemplate")
Tercio@58 4184 keybindScroll:SetSize (1019, 348)
Tercio@58 4185 keybindScroll.Frames = {}
Tercio@58 4186 new_keybind_frame.keybindScroll = keybindScroll
Tercio@58 4187
Tercio@58 4188 --waiting the player to press a key
Tercio@58 4189 new_keybind_frame.IsListening = false
Tercio@58 4190
Tercio@58 4191 --check for valid data table
Tercio@58 4192 if (type (data) ~= "table") then
Tercio@58 4193 print ("error: data must be a table. DF > CreateKeybindBox()")
Tercio@58 4194 return
Tercio@58 4195 end
Tercio@58 4196
Tercio@58 4197 if (not next (data)) then
Tercio@58 4198 --> build data table for the character class
Tercio@58 4199 local _, unitClass = UnitClass ("player")
Tercio@58 4200 if (unitClass) then
Tercio@58 4201 local specIds = DF:GetClassSpecIDs (unitClass)
Tercio@58 4202 if (specIds) then
Tercio@58 4203 for _, specId in ipairs (specIds) do
Tercio@58 4204 data [specId] = {}
Tercio@58 4205 end
Tercio@58 4206 end
Tercio@58 4207 end
Tercio@58 4208 end
Tercio@58 4209
Tercio@58 4210 new_keybind_frame.Data = data
Tercio@58 4211 new_keybind_frame.SetData = keybind_set_data
Tercio@58 4212
Tercio@58 4213 new_keybind_frame.EditingSpec = DF:GetCurrentSpec()
Tercio@58 4214 new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [new_keybind_frame.EditingSpec]
Tercio@58 4215
Tercio@58 4216 local allSpecButtons = {}
Tercio@58 4217 local switch_spec = function (self, button, specID)
Tercio@58 4218 new_keybind_frame.EditingSpec = specID
Tercio@58 4219 new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [specID]
Tercio@58 4220
Tercio@58 4221 for _, button in ipairs (allSpecButtons) do
Tercio@58 4222 button.selectedTexture:Hide()
Tercio@58 4223 end
Tercio@58 4224 self.MyObject.selectedTexture:Show()
Tercio@58 4225
Tercio@58 4226 --feedback ao jogador uma vez que as keybinds podem ter o mesmo valor
Tercio@58 4227 C_Timer.After (.04, function() new_keybind_frame:Hide() end)
Tercio@58 4228 C_Timer.After (.06, function() new_keybind_frame:Show() end)
Tercio@58 4229
Tercio@58 4230 --atualiza a scroll
Tercio@58 4231 keybindScroll:UpdateScroll()
Tercio@58 4232 end
Tercio@58 4233
Tercio@58 4234 --choose which spec to use
Tercio@58 4235 local spec1 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec1 Placeholder Text", 1, _, _, "SpecButton1", _, 0, options_button_template, options_text_template)
Tercio@58 4236 local spec2 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec2 Placeholder Text", 1, _, _, "SpecButton2", _, 0, options_button_template, options_text_template)
Tercio@58 4237 local spec3 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec3 Placeholder Text", 1, _, _, "SpecButton3", _, 0, options_button_template, options_text_template)
Tercio@58 4238 local spec4 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec4 Placeholder Text", 1, _, _, "SpecButton4", _, 0, options_button_template, options_text_template)
Tercio@58 4239
Tercio@58 4240 --format the button label and icon with the spec information
Tercio@58 4241 local className, class = UnitClass ("player")
Tercio@58 4242 local i = 1
Tercio@58 4243 local specIds = DF:GetClassSpecIDs (class)
Tercio@58 4244
Tercio@58 4245 for index, specId in ipairs (specIds) do
Tercio@58 4246 local button = new_keybind_frame ["SpecButton" .. index]
Tercio@58 4247 local spec_id, spec_name, spec_description, spec_icon, spec_background, spec_role, spec_class = GetSpecializationInfoByID (specId)
Tercio@58 4248 button.text = spec_name
Tercio@58 4249 button:SetClickFunction (switch_spec, specId)
Tercio@58 4250 button:SetIcon (spec_icon)
Tercio@58 4251 button.specID = specId
Tercio@58 4252
Tercio@58 4253 local selectedTexture = button:CreateTexture (nil, "background")
Tercio@58 4254 selectedTexture:SetAllPoints()
Tercio@58 4255 selectedTexture:SetColorTexture (1, 1, 1, 0.5)
Tercio@58 4256 if (specId ~= new_keybind_frame.EditingSpec) then
Tercio@58 4257 selectedTexture:Hide()
Tercio@58 4258 end
Tercio@58 4259 button.selectedTexture = selectedTexture
Tercio@58 4260
Tercio@58 4261 tinsert (allSpecButtons, button)
Tercio@58 4262 i = i + 1
Tercio@58 4263 end
Tercio@58 4264
Tercio@58 4265 local specsTitle = DF:CreateLabel (new_keybind_frame, "Config keys for spec:", 12, "silver")
Tercio@58 4266 specsTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 10, mainStartY)
Tercio@58 4267
Tercio@58 4268 keybindScroll:SetPoint ("topleft", specsTitle.widget, "bottomleft", 0, -120)
Tercio@58 4269
Tercio@58 4270 spec1:SetPoint ("topleft", specsTitle, "bottomleft", 0, -10)
Tercio@58 4271 spec2:SetPoint ("topleft", specsTitle, "bottomleft", 0, -30)
Tercio@58 4272 spec3:SetPoint ("topleft", specsTitle, "bottomleft", 0, -50)
Tercio@58 4273 if (class == "DRUID") then
Tercio@58 4274 spec4:SetPoint ("topleft", specsTitle, "bottomleft", 0, -70)
Tercio@58 4275 end
Tercio@58 4276
Tercio@58 4277 local enter_the_key = CreateFrame ("frame", nil, new_keybind_frame)
Tercio@58 4278 enter_the_key:SetFrameStrata ("tooltip")
Tercio@58 4279 enter_the_key:SetSize (200, 60)
Tercio@58 4280 enter_the_key:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
Tercio@58 4281 enter_the_key:SetBackdropColor (0, 0, 0, 1)
Tercio@58 4282 enter_the_key:SetBackdropBorderColor (1, 1, 1, 1)
Tercio@58 4283 enter_the_key.text = DF:CreateLabel (enter_the_key, "- Press a keyboard key to bind.\n- Click to bind a mouse button.\n- Press escape to cancel.", 11, "orange")
Tercio@58 4284 enter_the_key.text:SetPoint ("center", enter_the_key, "center")
Tercio@58 4285 enter_the_key:Hide()
Tercio@58 4286
Tercio@58 4287 local registerKeybind = function (self, key)
Tercio@58 4288 if (ignoredKeys [key]) then
Tercio@58 4289 return
Tercio@58 4290 end
Tercio@58 4291 if (key == "ESCAPE") then
Tercio@58 4292 enter_the_key:Hide()
Tercio@58 4293 new_keybind_frame.IsListening = false
Tercio@58 4294 new_keybind_frame:SetScript ("OnKeyDown", nil)
Tercio@58 4295 return
Tercio@58 4296 end
Tercio@58 4297
Tercio@58 4298 local bind = (IsShiftKeyDown() and "SHIFT-" or "") .. (IsControlKeyDown() and "CTRL-" or "") .. (IsAltKeyDown() and "ALT-" or "")
Tercio@58 4299 bind = bind .. key
Tercio@58 4300
Tercio@58 4301 --adiciona para a tabela de keybinds
Tercio@58 4302 local keybind = new_keybind_frame.CurrentKeybindEditingSet [self.keybindIndex]
Tercio@58 4303 keybind.key = bind
Tercio@58 4304
Tercio@58 4305 new_keybind_frame.IsListening = false
Tercio@58 4306 new_keybind_frame:SetScript ("OnKeyDown", nil)
Tercio@58 4307
Tercio@58 4308 enter_the_key:Hide()
Tercio@58 4309 new_keybind_frame.keybindScroll:UpdateScroll()
Tercio@58 4310
Tercio@58 4311 DF:QuickDispatch (callback)
Tercio@58 4312 end
Tercio@58 4313
Tercio@58 4314 local set_keybind_key = function (self, button, keybindIndex)
Tercio@58 4315 if (new_keybind_frame.IsListening) then
Tercio@58 4316 key = mouseKeys [button] or button
Tercio@58 4317 return registerKeybind (new_keybind_frame, key)
Tercio@58 4318 end
Tercio@58 4319 new_keybind_frame.IsListening = true
Tercio@58 4320 new_keybind_frame.keybindIndex = keybindIndex
Tercio@58 4321 new_keybind_frame:SetScript ("OnKeyDown", registerKeybind)
Tercio@58 4322
Tercio@58 4323 enter_the_key:Show()
Tercio@58 4324 enter_the_key:SetPoint ("bottom", self, "top")
Tercio@58 4325 end
Tercio@58 4326
Tercio@58 4327 local new_key_bind = function (self, button, specID)
Tercio@58 4328 tinsert (new_keybind_frame.CurrentKeybindEditingSet, {key = "-none-", action = "_target", actiontext = ""})
Tercio@58 4329 FauxScrollFrame_SetOffset (new_keybind_frame.keybindScroll, max (#new_keybind_frame.CurrentKeybindEditingSet-SCROLL_ROLL_AMOUNT, 0))
Tercio@58 4330 new_keybind_frame.keybindScroll:UpdateScroll()
Tercio@58 4331 end
Tercio@58 4332
Tercio@58 4333 local set_action_text = function (keybindIndex, _, text)
Tercio@58 4334 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
Tercio@58 4335 keybind.actiontext = text
Tercio@58 4336 DF:QuickDispatch (callback)
Tercio@58 4337 end
Tercio@58 4338
Tercio@58 4339 local set_action_on_espace_press = function (textentry, capsule)
Tercio@58 4340 capsule = capsule or textentry.MyObject
Tercio@58 4341 local keybind = new_keybind_frame.CurrentKeybindEditingSet [capsule.CurIndex]
Tercio@58 4342 textentry:SetText (keybind.actiontext)
Tercio@58 4343 DF:QuickDispatch (callback)
Tercio@58 4344 end
Tercio@58 4345
Tercio@58 4346 local lock_textentry = {
Tercio@58 4347 ["_target"] = true,
Tercio@58 4348 ["_taunt"] = true,
Tercio@58 4349 ["_interrupt"] = true,
Tercio@58 4350 ["_dispel"] = true,
Tercio@58 4351 ["_spell"] = false,
Tercio@58 4352 ["_macro"] = false,
Tercio@58 4353 }
Tercio@58 4354
Tercio@58 4355 local change_key_action = function (self, keybindIndex, value)
Tercio@58 4356 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
Tercio@58 4357 keybind.action = value
Tercio@58 4358 new_keybind_frame.keybindScroll:UpdateScroll()
Tercio@58 4359 DF:QuickDispatch (callback)
Tercio@58 4360 end
Tercio@58 4361 local fill_action_dropdown = function()
Tercio@58 4362
Tercio@58 4363 local locClass, class = UnitClass ("player")
Tercio@58 4364
Tercio@58 4365 local taunt = ""
Tercio@58 4366 local interrupt = ""
Tercio@58 4367 local dispel = ""
Tercio@58 4368
Tercio@58 4369 if (type (dispel) == "table") then
Tercio@58 4370 local dispelString = "\n"
Tercio@58 4371 for specID, spellid in pairs (dispel) do
Tercio@58 4372 local specid, specName = GetSpecializationInfoByID (specID)
Tercio@58 4373 local spellName = GetSpellInfo (spellid)
Tercio@58 4374 dispelString = dispelString .. "|cFFE5E5E5" .. specName .. "|r: |cFFFFFFFF" .. spellName .. "\n"
Tercio@58 4375 end
Tercio@58 4376 dispel = dispelString
Tercio@58 4377 else
Tercio@58 4378 dispel = ""
Tercio@58 4379 end
Tercio@58 4380
Tercio@58 4381 return {
Tercio@58 4382 --{value = "_target", label = "Target", onclick = change_key_action, desc = "Target the unit"},
Tercio@58 4383 --{value = "_taunt", label = "Taunt", onclick = change_key_action, desc = "Cast the taunt spell for your class\n\n|cFFFFFFFFSpell: " .. taunt},
Tercio@58 4384 --{value = "_interrupt", label = "Interrupt", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. interrupt},
Tercio@58 4385 --{value = "_dispel", label = "Dispel", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. dispel},
Tercio@58 4386 {value = "_spell", label = "Cast Spell", onclick = change_key_action, desc = "Type the spell name in the text box"},
Tercio@58 4387 {value = "_macro", label = "Run Macro", onclick = change_key_action, desc = "Type your macro in the text box"},
Tercio@58 4388 }
Tercio@58 4389 end
Tercio@58 4390
Tercio@58 4391 local copy_keybind = function (self, button, keybindIndex)
Tercio@58 4392 local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex]
Tercio@58 4393 for specID, t in pairs (new_keybind_frame.Data) do
Tercio@58 4394 if (specID ~= new_keybind_frame.EditingSpec) then
Tercio@58 4395 local key = CopyTable (keybind)
Tercio@58 4396 local specid, specName = GetSpecializationInfoByID (specID)
Tercio@58 4397 tinsert (new_keybind_frame.Data [specID], key)
Tercio@58 4398 DF:Msg ("Keybind copied to " .. specName)
Tercio@58 4399 end
Tercio@58 4400 end
Tercio@58 4401 DF:QuickDispatch (callback)
Tercio@58 4402 end
Tercio@58 4403
Tercio@58 4404 local delete_keybind = function (self, button, keybindIndex)
Tercio@58 4405 tremove (new_keybind_frame.CurrentKeybindEditingSet, keybindIndex)
Tercio@58 4406 new_keybind_frame.keybindScroll:UpdateScroll()
Tercio@58 4407 DF:QuickDispatch (callback)
Tercio@58 4408 end
Tercio@58 4409
Tercio@58 4410 local newTitle = DF:CreateLabel (new_keybind_frame, "Create a new Keybind:", 12, "silver")
Tercio@58 4411 newTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 200, mainStartY)
Tercio@58 4412 local createNewKeybind = DF:CreateButton (new_keybind_frame, new_key_bind, 160, 20, "New Key Bind", 1, _, _, "NewKeybindButton", _, 0, options_button_template, options_text_template)
Tercio@58 4413 createNewKeybind:SetPoint ("topleft", newTitle, "bottomleft", 0, -10)
Tercio@58 4414 --createNewKeybind:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]])
Tercio@58 4415
Tercio@58 4416 local update_keybind_list = function (self)
Tercio@58 4417
Tercio@58 4418 local keybinds = new_keybind_frame.CurrentKeybindEditingSet
Tercio@58 4419 FauxScrollFrame_Update (self, #keybinds, SCROLL_ROLL_AMOUNT, 21)
Tercio@58 4420 local offset = FauxScrollFrame_GetOffset (self)
Tercio@58 4421
Tercio@58 4422 for i = 1, SCROLL_ROLL_AMOUNT do
Tercio@58 4423 local index = i + offset
Tercio@58 4424 local f = self.Frames [i]
Tercio@58 4425 local data = keybinds [index]
Tercio@58 4426
Tercio@58 4427 if (data) then
Tercio@58 4428 --index
Tercio@58 4429 f.Index.text = index
Tercio@58 4430 --keybind
Tercio@58 4431 local keyBindText = keysToMouse [data.key] or data.key
Tercio@58 4432
Tercio@58 4433 keyBindText = keyBindText:gsub ("type1", "LeftButton")
Tercio@58 4434 keyBindText = keyBindText:gsub ("type2", "RightButton")
Tercio@58 4435 keyBindText = keyBindText:gsub ("type3", "MiddleButton")
Tercio@58 4436
Tercio@58 4437 f.KeyBind.text = keyBindText
Tercio@58 4438 f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "left")
Tercio@58 4439 f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "right")
Tercio@58 4440 --action
Tercio@58 4441 f.ActionDrop:SetFixedParameter (index)
Tercio@58 4442 f.ActionDrop:Select (data.action)
Tercio@58 4443 --action text
Tercio@58 4444 f.ActionText.text = data.actiontext
Tercio@58 4445 f.ActionText:SetEnterFunction (set_action_text, index)
Tercio@58 4446 f.ActionText.CurIndex = index
Tercio@58 4447
Tercio@58 4448 if (lock_textentry [data.action]) then
Tercio@58 4449 f.ActionText:Disable()
Tercio@58 4450 else
Tercio@58 4451 f.ActionText:Enable()
Tercio@58 4452 end
Tercio@58 4453
Tercio@58 4454 --copy
Tercio@58 4455 f.Copy:SetClickFunction (copy_keybind, index)
Tercio@58 4456 --delete
Tercio@58 4457 f.Delete:SetClickFunction (delete_keybind, index)
Tercio@58 4458
Tercio@58 4459 f:Show()
Tercio@58 4460 else
Tercio@58 4461 f:Hide()
Tercio@58 4462 end
Tercio@58 4463 end
Tercio@58 4464
Tercio@58 4465 self:Show()
Tercio@58 4466 end
Tercio@58 4467
Tercio@58 4468
Tercio@58 4469
Tercio@58 4470 keybindScroll:SetScript ("OnVerticalScroll", function (self, offset)
Tercio@58 4471 FauxScrollFrame_OnVerticalScroll (self, offset, 21, update_keybind_list)
Tercio@58 4472 end)
Tercio@58 4473 keybindScroll.UpdateScroll = update_keybind_list
Tercio@58 4474
Tercio@58 4475 local backdropColor = {.3, .3, .3, .3}
Tercio@58 4476 local backdropColorOnEnter = {.6, .6, .6, .6}
Tercio@58 4477 local on_enter = function (self)
Tercio@58 4478 self:SetBackdropColor (unpack (backdropColorOnEnter))
Tercio@58 4479 end
Tercio@58 4480 local on_leave = function (self)
Tercio@58 4481 self:SetBackdropColor (unpack (backdropColor))
Tercio@58 4482 end
Tercio@58 4483
Tercio@58 4484 local font = "GameFontHighlightSmall"
Tercio@58 4485
Tercio@58 4486 for i = 1, SCROLL_ROLL_AMOUNT do
Tercio@58 4487 local f = CreateFrame ("frame", "$KeyBindFrame" .. i, keybindScroll)
Tercio@58 4488 f:SetSize (1009, 20)
Tercio@58 4489 f:SetPoint ("topleft", keybindScroll, "topleft", 0, -(i-1)*29)
Tercio@58 4490 f:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@58 4491 f:SetBackdropColor (unpack (backdropColor))
Tercio@58 4492 f:SetScript ("OnEnter", on_enter)
Tercio@58 4493 f:SetScript ("OnLeave", on_leave)
Tercio@58 4494 tinsert (keybindScroll.Frames, f)
Tercio@58 4495
Tercio@58 4496 f.Index = DF:CreateLabel (f, "1")
Tercio@58 4497 f.KeyBind = DF:CreateButton (f, set_key_bind, 100, 20, "", _, _, _, "SetNewKeybindButton", _, 0, options_button_template, options_text_template)
Tercio@58 4498 f.ActionDrop = DF:CreateDropDown (f, fill_action_dropdown, 0, 120, 20, "ActionDropdown", _, options_dropdown_template)
Tercio@58 4499 f.ActionText = DF:CreateTextEntry (f, function()end, 660, 20, "TextBox", _, _, options_dropdown_template)
Tercio@58 4500 f.Copy = DF:CreateButton (f, copy_keybind, 20, 20, "", _, _, _, "CopyKeybindButton", _, 0, options_button_template, options_text_template)
Tercio@58 4501 f.Delete = DF:CreateButton (f, delete_keybind, 16, 20, "", _, _, _, "DeleteKeybindButton", _, 2, options_button_template, options_text_template)
Tercio@58 4502
Tercio@58 4503 f.Index:SetPoint ("left", f, "left", 10, 0)
Tercio@58 4504 f.KeyBind:SetPoint ("left", f, "left", 43, 0)
Tercio@58 4505 f.ActionDrop:SetPoint ("left", f, "left", 150, 0)
Tercio@58 4506 f.ActionText:SetPoint ("left", f, "left", 276, 0)
Tercio@58 4507 f.Copy:SetPoint ("left", f, "left", 950, 0)
Tercio@58 4508 f.Delete:SetPoint ("left", f, "left", 990, 0)
Tercio@58 4509
Tercio@58 4510 f.Copy:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]], nil, nil, nil, nil, nil, nil, 4)
Tercio@58 4511 f.Delete:SetIcon ([[Interface\Buttons\UI-StopButton]], nil, nil, nil, nil, nil, nil, 4)
Tercio@58 4512
Tercio@58 4513 f.Copy.tooltip = "copy this keybind to other specs"
Tercio@58 4514 f.Delete.tooltip = "erase this keybind"
Tercio@58 4515
Tercio@58 4516 --editbox
Tercio@58 4517 f.ActionText:SetJustifyH ("left")
Tercio@58 4518 f.ActionText:SetHook ("OnEscapePressed", set_action_on_espace_press)
Tercio@58 4519 f.ActionText:SetHook ("OnEditFocusGained", function()
Tercio@58 4520 local playerSpells = {}
Tercio@58 4521 local tab, tabTex, offset, numSpells = GetSpellTabInfo (2)
Tercio@58 4522 for i = 1, numSpells do
Tercio@58 4523 local index = offset + i
Tercio@58 4524 local spellType, spellId = GetSpellBookItemInfo (index, "player")
Tercio@58 4525 if (spellType == "SPELL") then
Tercio@58 4526 local spellName = GetSpellInfo (spellId)
Tercio@58 4527 tinsert (playerSpells, spellName)
Tercio@58 4528 end
Tercio@58 4529 end
Tercio@58 4530 f.ActionText.WordList = playerSpells
Tercio@58 4531 end)
Tercio@58 4532
Tercio@58 4533 f.ActionText:SetAsAutoComplete ("WordList")
Tercio@58 4534 end
Tercio@58 4535
Tercio@58 4536 local header = CreateFrame ("frame", "$parentOptionsPanelFrameHeader", keybindScroll)
Tercio@58 4537 header:SetPoint ("bottomleft", keybindScroll, "topleft", 0, 2)
Tercio@58 4538 header:SetPoint ("bottomright", keybindScroll, "topright", 0, 2)
Tercio@58 4539 header:SetHeight (16)
Tercio@58 4540
Tercio@58 4541 header.Index = DF:CreateLabel (header, "Index", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4542 header.Key = DF:CreateLabel (header, "Key", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4543 header.Action = DF:CreateLabel (header, "Action", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4544 header.Macro = DF:CreateLabel (header, "Spell Name / Macro", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4545 header.Copy = DF:CreateLabel (header, "Copy", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4546 header.Delete = DF:CreateLabel (header, "Delete", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
Tercio@58 4547
Tercio@58 4548 header.Index:SetPoint ("left", header, "left", 10, 0)
Tercio@58 4549 header.Key:SetPoint ("left", header, "left", 43, 0)
Tercio@58 4550 header.Action:SetPoint ("left", header, "left", 150, 0)
Tercio@58 4551 header.Macro:SetPoint ("left", header, "left", 276, 0)
Tercio@58 4552 header.Copy:SetPoint ("left", header, "left", 950, 0)
Tercio@58 4553 header.Delete:SetPoint ("left", header, "left", 990, 0)
Tercio@58 4554
Tercio@58 4555 new_keybind_frame:SetScript ("OnShow", function()
Tercio@58 4556
Tercio@58 4557 --new_keybind_frame.EditingSpec = EnemyGrid.CurrentSpec
Tercio@58 4558 --new_keybind_frame.CurrentKeybindEditingSet = EnemyGrid.CurrentKeybindSet
Tercio@58 4559
Tercio@58 4560 for _, button in ipairs (allSpecButtons) do
Tercio@58 4561 if (new_keybind_frame.EditingSpec ~= button.specID) then
Tercio@58 4562 button.selectedTexture:Hide()
Tercio@58 4563 else
Tercio@58 4564 button.selectedTexture:Show()
Tercio@58 4565 end
Tercio@58 4566 end
Tercio@58 4567
Tercio@58 4568 keybindScroll:UpdateScroll()
Tercio@58 4569 end)
Tercio@58 4570
Tercio@58 4571 new_keybind_frame:SetScript ("OnHide", function()
Tercio@58 4572 if (new_keybind_frame.IsListening) then
Tercio@58 4573 new_keybind_frame.IsListening = false
Tercio@58 4574 new_keybind_frame:SetScript ("OnKeyDown", nil)
Tercio@58 4575 end
Tercio@58 4576 end)
Tercio@58 4577
Tercio@58 4578 return new_keybind_frame
Tercio@58 4579 end
Tercio@58 4580
Tercio@58 4581 function DF:BuildKeybindFunctions (data, prefix)
Tercio@58 4582
Tercio@58 4583 --~keybind
Tercio@58 4584 local classLoc, class = UnitClass ("player")
Tercio@58 4585 local bindingList = data
Tercio@58 4586
Tercio@58 4587 local bindString = "self:ClearBindings();"
Tercio@58 4588 local bindKeyBindTypeFunc = [[local unitFrame = ...;]]
Tercio@58 4589 local bindMacroTextFunc = [[local unitFrame = ...;]]
Tercio@58 4590 local isMouseBinding
Tercio@58 4591
Tercio@58 4592 for i = 1, #bindingList do
Tercio@58 4593 local bind = bindingList [i]
Tercio@58 4594 local bindType
Tercio@58 4595
Tercio@58 4596 --which button to press
Tercio@58 4597 if (bind.key:find ("type")) then
Tercio@58 4598 local keyNumber = tonumber (bind.key:match ("%d"))
Tercio@58 4599 bindType = keyNumber
Tercio@58 4600 isMouseBinding = true
Tercio@58 4601 else
Tercio@58 4602 bindType = prefix .. "" .. i
Tercio@58 4603 bindString = bindString .. "self:SetBindingClick (0, '" .. bind.key .. "', self:GetName(), '" .. bindType .. "');"
Tercio@58 4604 bindType = "-" .. prefix .. "" .. i
Tercio@58 4605 isMouseBinding = nil
Tercio@58 4606 end
Tercio@58 4607
Tercio@58 4608 --keybind type
Tercio@58 4609 local shift, alt, ctrl = bind.key:match ("SHIFT"), bind.key:match ("ALT"), bind.key:match ("CTRL")
Tercio@58 4610 local CommandKeys = alt and alt .. "-" or ""
Tercio@58 4611 CommandKeys = ctrl and CommandKeys .. ctrl .. "-" or CommandKeys
Tercio@58 4612 CommandKeys = shift and CommandKeys .. shift .. "-" or CommandKeys
Tercio@58 4613
Tercio@58 4614 local keyBindType
Tercio@58 4615 if (isMouseBinding) then
Tercio@58 4616 keyBindType = [[unitFrame:SetAttribute ("@COMMANDtype@BINDTYPE", "macro");]]
Tercio@58 4617 else
Tercio@58 4618 keyBindType = [[unitFrame:SetAttribute ("type@BINDTYPE", "macro");]]
Tercio@58 4619 end
Tercio@58 4620
Tercio@58 4621 keyBindType = keyBindType:gsub ("@BINDTYPE", bindType)
Tercio@58 4622 keyBindType = keyBindType:gsub ("@COMMAND", CommandKeys)
Tercio@58 4623 bindKeyBindTypeFunc = bindKeyBindTypeFunc .. keyBindType
Tercio@58 4624
Tercio@58 4625 --spell or macro
Tercio@58 4626 if (bind.action == "_spell") then
Tercio@58 4627 local macroTextLine
Tercio@58 4628 if (isMouseBinding) then
Tercio@58 4629 macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]]
Tercio@58 4630 else
Tercio@58 4631 macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]]
Tercio@58 4632 end
Tercio@58 4633 macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType)
Tercio@58 4634 macroTextLine = macroTextLine:gsub ("@SPELL", bind.actiontext)
Tercio@58 4635 macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys)
Tercio@58 4636 bindMacroTextFunc = bindMacroTextFunc .. macroTextLine
Tercio@58 4637
Tercio@58 4638 elseif (bind.action == "_macro") then
Tercio@58 4639 local macroTextLine
Tercio@58 4640 if (isMouseBinding) then
Tercio@58 4641 macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "@MACRO");]]
Tercio@58 4642 else
Tercio@58 4643 macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "@MACRO");]]
Tercio@58 4644 end
Tercio@58 4645 macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType)
Tercio@58 4646 macroTextLine = macroTextLine:gsub ("@MACRO", bind.actiontext)
Tercio@58 4647 macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys)
Tercio@58 4648 bindMacroTextFunc = bindMacroTextFunc .. macroTextLine
Tercio@58 4649
Tercio@58 4650 end
Tercio@58 4651 end
Tercio@58 4652
Tercio@58 4653 --~key
Tercio@58 4654 local bindTypeFuncLoaded = loadstring (bindKeyBindTypeFunc)
Tercio@58 4655 local bindMacroFuncLoaded = loadstring (bindMacroTextFunc)
Tercio@58 4656
Tercio@58 4657 if (not bindMacroFuncLoaded or not bindTypeFuncLoaded) then
Tercio@58 4658 return
Tercio@58 4659 end
Tercio@58 4660
Tercio@58 4661 return bindString, bindTypeFuncLoaded, bindMacroFuncLoaded
Tercio@58 4662 end
Tercio@58 4663
Tercio@58 4664
Tercio@58 4665 function DF:SetKeybindsOnProtectedFrame (frame, bind_string, bind_type_func, bind_macro_func)
Tercio@58 4666
Tercio@58 4667 bind_type_func (frame)
Tercio@58 4668 bind_macro_func (frame)
Tercio@58 4669 frame:SetAttribute ("_onenter", bind_string)
Tercio@58 4670
Tercio@58 4671 end
Tercio@58 4672
Tercio@58 4673 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@58 4674 -- ~standard backdrop
Tercio@58 4675
Tercio@58 4676 function DF:ApplyStandardBackdrop (f, darkTheme, alphaScale)
Tercio@58 4677 alphaScale = alphaScale or 1.0
Tercio@58 4678
Tercio@58 4679 if (darkTheme) then
Tercio@58 4680 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Cooldown\cooldown2]], tileSize = 32, tile = true})
Tercio@58 4681 f:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@58 4682 f:SetBackdropColor (.54, .54, .54, .54 * alphaScale)
Tercio@58 4683 else
Tercio@58 4684 f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@58 4685 f:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@58 4686 f:SetBackdropColor (0, 0, 0, 0.2 * alphaScale)
Tercio@58 4687 end
Tercio@58 4688
Tercio@58 4689 if (not f.__background) then
Tercio@58 4690 f.__background = f:CreateTexture (nil, "background")
Tercio@58 4691 end
Tercio@58 4692
Tercio@58 4693 f.__background:SetColorTexture (0.2317647, 0.2317647, 0.2317647)
Tercio@58 4694 f.__background:SetVertexColor (0.27, 0.27, 0.27)
Tercio@58 4695 f.__background:SetAlpha (0.8 * alphaScale)
Tercio@58 4696 f.__background:SetVertTile (true)
Tercio@58 4697 f.__background:SetHorizTile (true)
Tercio@58 4698 f.__background:SetAllPoints()
Tercio@58 4699 end
Tercio@58 4700
Tercio@58 4701 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@58 4702 -- ~title bar
Tercio@58 4703
Tercio@58 4704 DF.TitleFunctions = {
Tercio@58 4705
Tercio@58 4706 SetTitle = function (self, titleText, titleColor, font, size)
Tercio@58 4707 self.TitleLabel:SetText (titleText or self.TitleLabel:GetText())
Tercio@58 4708
Tercio@58 4709 if (titleColor) then
Tercio@58 4710 local r, g, b, a = DF:ParseColors (titleColor)
Tercio@58 4711 self.TitleLabel:SetTextColor (r, g, b, a)
Tercio@58 4712 end
Tercio@58 4713
Tercio@58 4714 if (font) then
Tercio@58 4715 DF:SetFontFace (self.TitleLabel, font)
Tercio@58 4716 end
Tercio@58 4717
Tercio@58 4718 if (size) then
Tercio@58 4719 DF:SetFontSize (self.TitleLabel, size)
Tercio@58 4720 end
Tercio@58 4721 end
Tercio@58 4722
Tercio@58 4723
Tercio@58 4724 }
Tercio@58 4725
Tercio@58 4726 function DF:CreateTitleBar (f, titleText)
Tercio@58 4727
Tercio@58 4728 local titleBar = CreateFrame ("frame", f:GetName() and f:GetName() .. "TitleBar" or nil, f)
Tercio@58 4729 titleBar:SetPoint ("topleft", f, "topleft", 2, -3)
Tercio@58 4730 titleBar:SetPoint ("topright", f, "topright", -2, -3)
Tercio@58 4731 titleBar:SetHeight (20)
Tercio@58 4732 titleBar:SetBackdrop (SimplePanel_frame_backdrop) --it's an upload from this file
Tercio@58 4733 titleBar:SetBackdropColor (.2, .2, .2, 1)
Tercio@58 4734 titleBar:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@58 4735
Tercio@58 4736 local closeButton = CreateFrame ("button", titleBar:GetName() and titleBar:GetName() .. "CloseButton" or nil, titleBar)
Tercio@58 4737 closeButton:SetSize (16, 16)
Tercio@58 4738 closeButton:SetNormalTexture (DF.folder .. "icons")
Tercio@58 4739 closeButton:SetHighlightTexture (DF.folder .. "icons")
Tercio@58 4740 closeButton:SetPushedTexture (DF.folder .. "icons")
Tercio@58 4741 closeButton:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@58 4742 closeButton:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@58 4743 closeButton:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1)
Tercio@58 4744 closeButton:SetAlpha (0.7)
Tercio@58 4745 closeButton:SetScript ("OnClick", simple_panel_close_click) --upvalue from this file
Tercio@58 4746
Tercio@58 4747 local titleLabel = titleBar:CreateFontString (titleBar:GetName() and titleBar:GetName() .. "TitleText" or nil, "overlay", "GameFontNormal")
Tercio@58 4748 titleLabel:SetTextColor (.8, .8, .8, 1)
Tercio@58 4749 titleLabel:SetText (titleText or "")
Tercio@58 4750
Tercio@58 4751 --anchors
Tercio@58 4752 closeButton:SetPoint ("right", titleBar, "right", -2, 0)
Tercio@58 4753 titleLabel:SetPoint ("center", titleBar, "center")
Tercio@58 4754
Tercio@58 4755 --members
Tercio@58 4756 f.TitleBar = titleBar
Tercio@58 4757 f.CloseButton = closeButton
Tercio@58 4758 f.TitleLabel = titleLabel
Tercio@58 4759
Tercio@58 4760 DF:Mixin (f, DF.TitleFunctions)
Tercio@58 4761
Tercio@58 4762 return titleBar
Tercio@58 4763 end
Tercio@58 4764
Tercio@58 4765
Tercio@58 4766 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@58 4767 -- ~icon row
Tercio@58 4768
Tercio@58 4769 DF.IconRowFunctions = {
Tercio@58 4770
Tercio@58 4771 GetIcon = function (self)
Tercio@58 4772 local iconFrame = self.IconPool [self.NextIcon]
Tercio@58 4773
Tercio@58 4774 if (not iconFrame) then
Tercio@58 4775 local newIconFrame = CreateFrame ("cooldown", "$parentIconCooldown" .. self.NextIcon, self, "CooldownFrameTemplate")
Tercio@58 4776 newIconFrame:SetSize (self.options.icon_width, self.options.icon_height)
Tercio@58 4777
Tercio@58 4778 newIconFrame.Texture = newIconFrame:CreateTexture (nil, "background")
Tercio@58 4779 newIconFrame.Texture:SetAllPoints()
Tercio@58 4780
Tercio@58 4781 newIconFrame.Text = newIconFrame:CreateFontString (nil, "overlay", "GameFontNormal")
Tercio@58 4782 newIconFrame.Text:SetPoint ("center")
Tercio@58 4783 newIconFrame.Text:Hide()
Tercio@58 4784
Tercio@58 4785 newIconFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
Tercio@58 4786 newIconFrame:SetBackdropBorderColor (0, 0, 0, 0)
Tercio@58 4787 newIconFrame:EnableMouse (false)
Tercio@58 4788
Tercio@58 4789 self.IconPool [self.NextIcon] = newIconFrame
Tercio@58 4790 iconFrame = newIconFrame
Tercio@58 4791 end
Tercio@58 4792
Tercio@58 4793 iconFrame:ClearAllPoints()
Tercio@58 4794
Tercio@58 4795 local anchor = self.options.anchor
Tercio@58 4796 local anchorTo = self.NextIcon == 1 and self or self.IconPool [self.NextIcon - 1]
Tercio@58 4797 local xPadding = self.NextIcon == 1 and self.options.left_padding or self.options.icon_padding
Tercio@58 4798 local growDirection = self.options.grow_direction
Tercio@58 4799
Tercio@58 4800 if (growDirection == 1) then --grow to right
Tercio@58 4801 if (self.NextIcon == 1) then
Tercio@58 4802 iconFrame:SetPoint ("left", anchorTo, "left", xPadding, 0)
Tercio@58 4803 else
Tercio@58 4804 iconFrame:SetPoint ("left", anchorTo, "right", xPadding, 0)
Tercio@58 4805 end
Tercio@58 4806
Tercio@58 4807 elseif (growDirection == 2) then --grow to left
Tercio@58 4808 if (self.NextIcon == 1) then
Tercio@58 4809 iconFrame:SetPoint ("right", anchorTo, "right", xPadding, 0)
Tercio@58 4810 else
Tercio@58 4811 iconFrame:SetPoint ("right", anchorTo, "left", xPadding, 0)
Tercio@58 4812 end
Tercio@58 4813
Tercio@58 4814 end
Tercio@58 4815
Tercio@58 4816 DF:SetFontColor (iconFrame.Text, self.options.text_color)
Tercio@58 4817
Tercio@58 4818 self.NextIcon = self.NextIcon + 1
Tercio@58 4819 return iconFrame
Tercio@58 4820 end,
Tercio@58 4821
Tercio@58 4822 SetIcon = function (self, spellId, borderColor, startTime, duration)
Tercio@58 4823 local spellName, _, spellIcon = GetSpellInfo (spellId)
Tercio@58 4824
Tercio@58 4825 if (spellIcon) then
Tercio@58 4826 local iconFrame = self:GetIcon()
Tercio@58 4827 iconFrame.Texture:SetTexture (spellIcon)
Tercio@58 4828 iconFrame.Texture:SetTexCoord (unpack (self.options.texcoord))
Tercio@58 4829
Tercio@58 4830 if (borderColor) then
Tercio@58 4831 iconFrame:SetBackdropBorderColor (Plater:ParseColors (borderColor))
Tercio@58 4832 else
Tercio@58 4833 iconFrame:SetBackdropBorderColor (0, 0, 0 ,0)
Tercio@58 4834 end
Tercio@58 4835
Tercio@58 4836 if (startTime) then
Tercio@58 4837 CooldownFrame_Set (iconFrame, startTime, duration, true, true)
Tercio@58 4838
Tercio@58 4839 if (self.options.show_text) then
Tercio@58 4840 iconFrame.Text:Show()
Tercio@58 4841 iconFrame.Text:SetText (floor (startTime + duration - GetTime()))
Tercio@58 4842 else
Tercio@58 4843 iconFrame.Text:Hide()
Tercio@58 4844 end
Tercio@58 4845 else
Tercio@58 4846 iconFrame.Text:Hide()
Tercio@58 4847 end
Tercio@58 4848
Tercio@58 4849 iconFrame:Show()
Tercio@58 4850
Tercio@58 4851 --> update the size of the frame
Tercio@58 4852 self:SetWidth ((self.options.left_padding * 2) + (self.options.icon_padding * (self.NextIcon-2)) + (self.options.icon_width * (self.NextIcon - 1)))
Tercio@58 4853
Tercio@58 4854 --> show the frame
Tercio@58 4855 self:Show()
Tercio@58 4856
Tercio@58 4857 return iconFrame
Tercio@58 4858 end
Tercio@58 4859 end,
Tercio@58 4860
Tercio@58 4861 ClearIcons = function (self)
Tercio@58 4862 for i = 1, self.NextIcon -1 do
Tercio@58 4863 self.IconPool [i]:Hide()
Tercio@58 4864 end
Tercio@58 4865 self.NextIcon = 1
Tercio@58 4866 self:Hide()
Tercio@58 4867 end,
Tercio@58 4868
Tercio@58 4869 GetIconGrowDirection = function (self)
Tercio@58 4870 local side = self.options.anchor.side
Tercio@58 4871
Tercio@58 4872 if (side == 1) then
Tercio@58 4873 return 1
Tercio@58 4874 elseif (side == 2) then
Tercio@58 4875 return 2
Tercio@58 4876 elseif (side == 3) then
Tercio@58 4877 return 1
Tercio@58 4878 elseif (side == 4) then
Tercio@58 4879 return 1
Tercio@58 4880 elseif (side == 5) then
Tercio@58 4881 return 2
Tercio@58 4882 elseif (side == 6) then
Tercio@58 4883 return 1
Tercio@58 4884 elseif (side == 7) then
Tercio@58 4885 return 2
Tercio@58 4886 elseif (side == 8) then
Tercio@58 4887 return 1
Tercio@58 4888 elseif (side == 9) then
Tercio@58 4889 return 1
Tercio@58 4890 elseif (side == 10) then
Tercio@58 4891 return 1
Tercio@58 4892 elseif (side == 11) then
Tercio@58 4893 return 2
Tercio@58 4894 elseif (side == 12) then
Tercio@58 4895 return 1
Tercio@58 4896 elseif (side == 13) then
Tercio@58 4897 return 1
Tercio@58 4898 end
Tercio@58 4899 end
Tercio@58 4900 }
Tercio@58 4901
Tercio@58 4902 local default_icon_row_options = {
Tercio@58 4903 icon_width = 20,
Tercio@58 4904 icon_height = 20,
Tercio@58 4905 texcoord = {.1, .9, .1, .9},
Tercio@58 4906 show_text = true,
Tercio@58 4907 text_color = {1, 1, 1, 1},
Tercio@58 4908 left_padding = 2, --distance between right and left
Tercio@58 4909 top_padding = 2, --distance between top and bottom
Tercio@58 4910 icon_padding = 2, --distance between each icon
Tercio@58 4911 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
Tercio@58 4912 backdrop_color = {0, 0, 0, 0.5},
Tercio@58 4913 backdrop_border_color = {0, 0, 0, 1},
Tercio@58 4914 anchor = {side = 6, x = 2, y = 0},
Tercio@58 4915 grow_direction = 1, --1 = to right 2 = to left
Tercio@58 4916 }
Tercio@58 4917
Tercio@58 4918 function DF:CreateIconRow (parent, name, options)
Tercio@58 4919 local f = CreateFrame ("frame", name, parent)
Tercio@58 4920 f.IconPool = {}
Tercio@58 4921 f.NextIcon = 1
Tercio@58 4922
Tercio@58 4923 DF:Mixin (f, DF.IconRowFunctions)
Tercio@58 4924 DF:Mixin (f, DF.OptionsFunctions)
Tercio@58 4925
Tercio@58 4926 f:BuildOptionsTable (default_icon_row_options, options)
Tercio@58 4927
Tercio@58 4928 f:SetSize (f.options.icon_width, f.options.icon_height + (f.options.top_padding * 2))
Tercio@58 4929 f:SetBackdrop (f.options.backdrop)
Tercio@58 4930 f:SetBackdropColor (unpack (f.options.backdrop_color))
Tercio@58 4931 f:SetBackdropBorderColor (unpack (f.options.backdrop_border_color))
Tercio@58 4932
Tercio@58 4933 return f
Tercio@58 4934 end