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