comparison Libs/DF/panel.lua @ 39:7944c081e5b4

- framework update. - ToC Update.
author Tercio
date Tue, 19 Jul 2016 13:23:40 -0300
parents 5da06cb420d4
children a960d5372b0c
comparison
equal deleted inserted replaced
38:219f04e5ba55 39:7944c081e5b4
13 local _type = type --> lua local 13 local _type = type --> lua local
14 local _math_floor = math.floor --> lua local 14 local _math_floor = math.floor --> lua local
15 local loadstring = loadstring --> lua local 15 local loadstring = loadstring --> lua local
16 16
17 local cleanfunction = function() end 17 local cleanfunction = function() end
18 local PanelMetaFunctions = {}
19 local APIFrameFunctions 18 local APIFrameFunctions
19
20 do
21 local metaPrototype = {
22 WidgetType = "panel",
23 SetHook = DF.SetHook,
24 RunHooksForWidget = DF.RunHooksForWidget,
25 }
26
27 _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype
28 end
29
30 local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]]
20 31
21 ------------------------------------------------------------------------------------------------------------ 32 ------------------------------------------------------------------------------------------------------------
22 --> metatables 33 --> metatables
23 34
24 PanelMetaFunctions.__call = function (_table, value) 35 PanelMetaFunctions.__call = function (_table, value)
56 --> locked 67 --> locked
57 local gmember_locked = function (_object) 68 local gmember_locked = function (_object)
58 return _rawget (_object, "is_locked") 69 return _rawget (_object, "is_locked")
59 end 70 end
60 71
61 local get_members_function_index = { 72 PanelMetaFunctions.GetMembers = PanelMetaFunctions.GetMembers or {}
62 ["tooltip"] = gmember_tooltip, 73 PanelMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
63 ["shown"] = gmember_shown, 74 PanelMetaFunctions.GetMembers ["shown"] = gmember_shown
64 ["color"] = gmember_color, 75 PanelMetaFunctions.GetMembers ["color"] = gmember_color
65 ["backdrop"] = gmember_backdrop, 76 PanelMetaFunctions.GetMembers ["backdrop"] = gmember_backdrop
66 ["width"] = gmember_width, 77 PanelMetaFunctions.GetMembers ["width"] = gmember_width
67 ["height"] = gmember_height, 78 PanelMetaFunctions.GetMembers ["height"] = gmember_height
68 ["locked"] = gmember_locked, 79 PanelMetaFunctions.GetMembers ["locked"] = gmember_locked
69 }
70 80
71 PanelMetaFunctions.__index = function (_table, _member_requested) 81 PanelMetaFunctions.__index = function (_table, _member_requested)
72 82
73 local func = get_members_function_index [_member_requested] 83 local func = PanelMetaFunctions.GetMembers [_member_requested]
74 if (func) then 84 if (func) then
75 return func (_table, _member_requested) 85 return func (_table, _member_requested)
76 end 86 end
77 87
78 local fromMe = _rawget (_table, _member_requested) 88 local fromMe = _rawget (_table, _member_requested)
138 --> close with right button 148 --> close with right button
139 local smember_right_close = function (_object, _value) 149 local smember_right_close = function (_object, _value)
140 return _rawset (_object, "rightButtonClose", _value) 150 return _rawset (_object, "rightButtonClose", _value)
141 end 151 end
142 152
143 local set_members_function_index = { 153 PanelMetaFunctions.SetMembers = PanelMetaFunctions.SetMembers or {}
144 ["tooltip"] = smember_tooltip, 154 PanelMetaFunctions.SetMembers["tooltip"] = smember_tooltip
145 ["show"] = smember_show, 155 PanelMetaFunctions.SetMembers["show"] = smember_show
146 ["hide"] = smember_hide, 156 PanelMetaFunctions.SetMembers["hide"] = smember_hide
147 ["color"] = smember_color, 157 PanelMetaFunctions.SetMembers["color"] = smember_color
148 ["backdrop"] = smember_backdrop, 158 PanelMetaFunctions.SetMembers["backdrop"] = smember_backdrop
149 ["width"] = smember_width, 159 PanelMetaFunctions.SetMembers["width"] = smember_width
150 ["height"] = smember_height, 160 PanelMetaFunctions.SetMembers["height"] = smember_height
151 ["locked"] = smember_locked, 161 PanelMetaFunctions.SetMembers["locked"] = smember_locked
152 ["close_with_right"] = smember_right_close, 162 PanelMetaFunctions.SetMembers["close_with_right"] = smember_right_close
153 } 163
154
155 PanelMetaFunctions.__newindex = function (_table, _key, _value) 164 PanelMetaFunctions.__newindex = function (_table, _key, _value)
156 local func = set_members_function_index [_key] 165 local func = PanelMetaFunctions.SetMembers [_key]
157 if (func) then 166 if (func) then
158 return func (_table, _value) 167 return func (_table, _value)
159 else 168 else
160 return _rawset (_table, _key, _value) 169 return _rawset (_table, _key, _value)
161 end 170 end
307 else 316 else
308 self.widget:SetFrameStrata (strata) 317 self.widget:SetFrameStrata (strata)
309 end 318 end
310 end 319 end
311 320
312 --> hooks
313 function PanelMetaFunctions:SetHook (hookType, func)
314 if (func) then
315 _rawset (self, hookType.."Hook", func)
316 else
317 _rawset (self, hookType.."Hook", nil)
318 end
319 end
320
321 ------------------------------------------------------------------------------------------------------------ 321 ------------------------------------------------------------------------------------------------------------
322 --> scripts 322 --> scripts
323 323
324 local OnEnter = function (frame) 324 local OnEnter = function (frame)
325 if (frame.MyObject.OnEnterHook) then 325 local capsule = frame.MyObject
326 local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject) 326 local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule)
327 if (interrupt) then 327 if (kill) then
328 return 328 return
329 end
330 end 329 end
331 330
332 if (frame.MyObject.have_tooltip) then 331 if (frame.MyObject.have_tooltip) then
333 GameCooltip2:Reset() 332 GameCooltip2:Reset()
334 GameCooltip2:SetType ("tooltip") 333 GameCooltip2:SetType ("tooltip")
338 GameCooltip2:ShowCooltip() 337 GameCooltip2:ShowCooltip()
339 end 338 end
340 end 339 end
341 340
342 local OnLeave = function (frame) 341 local OnLeave = function (frame)
343 if (frame.MyObject.OnLeaveHook) then 342 local capsule = frame.MyObject
344 local interrupt = frame.MyObject.OnLeaveHook (frame, frame.MyObject) 343 local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule)
345 if (interrupt) then 344 if (kill) then
346 return 345 return
347 end
348 end 346 end
349 347
350 if (frame.MyObject.have_tooltip) then 348 if (frame.MyObject.have_tooltip) then
351 GameCooltip2:ShowMe (false) 349 GameCooltip2:ShowMe (false)
352 end 350 end
353 351
354 end 352 end
355 353
356 local OnHide = function (frame) 354 local OnHide = function (frame)
357 if (frame.MyObject.OnHideHook) then 355 local capsule = frame.MyObject
358 local interrupt = frame.MyObject.OnHideHook (frame, frame.MyObject) 356 local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule)
359 if (interrupt) then 357 if (kill) then
360 return 358 return
361 end
362 end 359 end
363 end 360 end
364 361
365 local OnShow = function (frame) 362 local OnShow = function (frame)
366 if (frame.MyObject.OnShowHook) then 363 local capsule = frame.MyObject
367 local interrupt = frame.MyObject.OnShowHook (frame, frame.MyObject) 364 local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule)
368 if (interrupt) then 365 if (kill) then
369 return 366 return
370 end
371 end 367 end
372 end 368 end
373 369
374 local OnMouseDown = function (frame, button) 370 local OnMouseDown = function (frame, button)
375 if (frame.MyObject.OnMouseDownHook) then 371 local capsule = frame.MyObject
376 local interrupt = frame.MyObject.OnMouseDownHook (frame, button, frame.MyObject) 372 local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule)
377 if (interrupt) then 373 if (kill) then
378 return 374 return
379 end
380 end 375 end
381 376
382 if (frame.MyObject.container == UIParent) then 377 if (frame.MyObject.container == UIParent) then
383 if (not frame.isLocked and frame:IsMovable()) then 378 if (not frame.isLocked and frame:IsMovable()) then
384 frame.isMoving = true 379 frame.isMoving = true
394 389
395 390
396 end 391 end
397 392
398 local OnMouseUp = function (frame, button) 393 local OnMouseUp = function (frame, button)
399 if (frame.MyObject.OnMouseUpHook) then 394 local capsule = frame.MyObject
400 local interrupt = frame.MyObject.OnMouseUpHook (frame, button, frame.MyObject) 395 local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule)
401 if (interrupt) then 396 if (kill) then
402 return 397 return
403 end
404 end 398 end
405 399
406 if (button == "RightButton" and frame.MyObject.rightButtonClose) then 400 if (button == "RightButton" and frame.MyObject.rightButtonClose) then
407 frame.MyObject:Hide() 401 frame.MyObject:Hide()
408 end 402 end
454 end 448 end
455 if (container.dframework) then 449 if (container.dframework) then
456 container = container.widget 450 container = container.widget
457 end 451 end
458 452
459
460 --> default members: 453 --> default members:
461 --> hooks
462 PanelObject.OnEnterHook = nil
463 PanelObject.OnLeaveHook = nil
464 PanelObject.OnHideHook = nil
465 PanelObject.OnShowHook = nil
466 PanelObject.OnMouseDownHook = nil
467 PanelObject.OnMouseUpHook = nil
468 --> misc 454 --> misc
469 PanelObject.is_locked = true 455 PanelObject.is_locked = true
470 PanelObject.container = container 456 PanelObject.container = container
471 PanelObject.rightButtonClose = false 457 PanelObject.rightButtonClose = false
472 458
488 474
489 PanelObject.frame:SetWidth (w or 100) 475 PanelObject.frame:SetWidth (w or 100)
490 PanelObject.frame:SetHeight (h or 100) 476 PanelObject.frame:SetHeight (h or 100)
491 477
492 PanelObject.frame.MyObject = PanelObject 478 PanelObject.frame.MyObject = PanelObject
479
480 PanelObject.HookList = {
481 OnEnter = {},
482 OnLeave = {},
483 OnHide = {},
484 OnShow = {},
485 OnMouseDown = {},
486 OnMouseUp = {},
487 }
493 488
494 --> hooks 489 --> hooks
495 PanelObject.frame:SetScript ("OnEnter", OnEnter) 490 PanelObject.frame:SetScript ("OnEnter", OnEnter)
496 PanelObject.frame:SetScript ("OnLeave", OnLeave) 491 PanelObject.frame:SetScript ("OnLeave", OnLeave)
497 PanelObject.frame:SetScript ("OnHide", OnHide) 492 PanelObject.frame:SetScript ("OnHide", OnHide)
966 icon = icon + 1 961 icon = icon + 1
967 962
968 iconwidget.line = index 963 iconwidget.line = index
969 iconwidget.index = real_index 964 iconwidget.index = real_index
970 965
971 local result = results [index]:gsub (".-%\\", "") 966 --print (index, results [index])
972 iconwidget._icon.texture = results [index] 967 if (type (results [index]) == "string") then
968 local result = results [index]:gsub (".-%\\", "")
969 iconwidget._icon.texture = results [index]
970 else
971 iconwidget._icon:SetTexture (results [index])
972 end
973 973
974 iconwidget:Show() 974 iconwidget:Show()
975 end 975 end
976 end 976 end
977 end 977 end
1492 1492
1493 local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true} 1493 local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}
1494 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9} 1494 local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9}
1495 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1} 1495 local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1}
1496 1496
1497 function DF:CreateScaleBar (frame, config)
1498 local scaleBar = 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", "OPTIONS_FONT_TEMPLATE"))
1499 scaleBar:SetPoint ("right", frame.Close, "left", -2, 0)
1500 scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
1501 scaleBar.OnValueChanged = function (_, _, value)
1502 config.scale = value
1503 if (not scaleBar.IsValueChanging) then
1504 frame:SetScale (config.scale)
1505 end
1506 end
1507 scaleBar:SetHook ("OnMouseUp", function()
1508 frame:SetScale (config.scale)
1509 end)
1510 end
1511
1497 local no_options = {} 1512 local no_options = {}
1498 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options) 1513 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db)
1514
1515 if (db and name and not db [name]) then
1516 db [name] = {scale = 1}
1517 end
1499 1518
1500 if (not name) then 1519 if (not name) then
1501 name = "DetailsFrameworkSimplePanel" .. DF.SimplePanelCounter 1520 name = "DetailsFrameworkSimplePanel" .. DF.SimplePanelCounter
1502 DF.SimplePanelCounter = DF.SimplePanelCounter + 1 1521 DF.SimplePanelCounter = DF.SimplePanelCounter + 1
1503 end 1522 end
1531 title_bar:SetBackdropColor (.2, .2, .2, 1) 1550 title_bar:SetBackdropColor (.2, .2, .2, 1)
1532 title_bar:SetBackdropBorderColor (0, 0, 0, 1) 1551 title_bar:SetBackdropBorderColor (0, 0, 0, 1)
1533 f.TitleBar = title_bar 1552 f.TitleBar = title_bar
1534 1553
1535 local close = CreateFrame ("button", name and name .. "CloseButton", title_bar) 1554 local close = CreateFrame ("button", name and name .. "CloseButton", title_bar)
1555 close:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
1536 close:SetSize (16, 16) 1556 close:SetSize (16, 16)
1537 close:SetNormalTexture (DF.folder .. "icons") 1557 close:SetNormalTexture (DF.folder .. "icons")
1538 close:SetHighlightTexture (DF.folder .. "icons") 1558 close:SetHighlightTexture (DF.folder .. "icons")
1539 close:SetPushedTexture (DF.folder .. "icons") 1559 close:SetPushedTexture (DF.folder .. "icons")
1540 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1) 1560 close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1)
1546 1566
1547 local title_string = title_bar:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal") 1567 local title_string = title_bar:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal")
1548 title_string:SetTextColor (.8, .8, .8, 1) 1568 title_string:SetTextColor (.8, .8, .8, 1)
1549 title_string:SetText (title or "") 1569 title_string:SetText (title or "")
1550 f.Title = title_string 1570 f.Title = title_string
1571
1572 if (panel_options.UseScaleBar and db [name]) then
1573 DF:CreateScaleBar (f, db [name])
1574 f:SetScale (db [name].scale)
1575 end
1551 1576
1552 f.Title:SetPoint ("center", title_bar, "center") 1577 f.Title:SetPoint ("center", title_bar, "center")
1553 f.Close:SetPoint ("right", title_bar, "right", -2, 0) 1578 f.Close:SetPoint ("right", title_bar, "right", -2, 0)
1554 1579
1555 f:SetScript ("OnMouseDown", simple_panel_mouse_down) 1580 f:SetScript ("OnMouseDown", simple_panel_mouse_down)
2475 self.BoxLabelsAmount = self.BoxLabelsAmount + 1 2500 self.BoxLabelsAmount = self.BoxLabelsAmount + 1
2476 2501
2477 thisbox.type = type 2502 thisbox.type = type
2478 thisbox.index = number 2503 thisbox.index = number
2479 2504
2480 thisbox.box:SetTexture (unpack (color)) 2505 thisbox.box:SetColorTexture (unpack (color))
2481 thisbox.text:SetText (name) 2506 thisbox.text:SetText (name)
2482 2507
2483 thisbox.check:Show() 2508 thisbox.check:Show()
2484 thisbox.button:Show() 2509 thisbox.button:Show()
2485 thisbox.border:Show() 2510 thisbox.border:Show()
2517 else 2542 else
2518 --malformed table 2543 --malformed table
2519 this_block:SetWidth (pixel*5) 2544 this_block:SetWidth (pixel*5)
2520 end 2545 end
2521 2546
2522 this_block:SetTexture (r, g, b, 0.25) 2547 this_block:SetColorTexture (r, g, b, 0.25)
2523 this_block:Show() 2548 this_block:Show()
2524 2549
2525 index = index + 1 2550 index = index + 1
2526 end 2551 end
2527 2552
2829 2854
2830 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0}) 2855 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0})
2831 title:SetPoint ("topleft", f, "topleft", 110, -13) 2856 title:SetPoint ("topleft", f, "topleft", 110, -13)
2832 2857
2833 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture") 2858 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
2834 bottom_texture:SetTexture (0, 0, 0, .6) 2859 bottom_texture:SetColorTexture (0, 0, 0, .6)
2835 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7) 2860 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7)
2836 bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7) 2861 bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7)
2837 2862
2838 f.Overlays = {} 2863 f.Overlays = {}
2839 f.OverlaysAmount = 1 2864 f.OverlaysAmount = 1
2848 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), 13) 2873 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), 13)
2849 f.TimeLabels [i] = time 2874 f.TimeLabels [i] = time
2850 2875
2851 local line = f:CreateTexture (nil, "border") 2876 local line = f:CreateTexture (nil, "border")
2852 line:SetSize (1, h-45) 2877 line:SetSize (1, h-45)
2853 line:SetTexture (1, 1, 1, .1) 2878 line:SetColorTexture (1, 1, 1, .1)
2854 line:SetPoint ("bottomleft", time, "topright", 0, -10) 2879 line:SetPoint ("bottomleft", time, "topright", 0, -10)
2855 line:Hide() 2880 line:Hide()
2856 time.line = line 2881 time.line = line
2857 end 2882 end
2858 2883
2880 f.OData = {} 2905 f.OData = {}
2881 2906
2882 --div lines 2907 --div lines
2883 for i = 1, 8, 1 do 2908 for i = 1, 8, 1 do
2884 local line = g:CreateTexture (nil, "overlay") 2909 local line = g:CreateTexture (nil, "overlay")
2885 line:SetTexture (1, 1, 1, .2) 2910 line:SetColorTexture (1, 1, 1, .2)
2886 line:SetWidth (670) 2911 line:SetWidth (670)
2887 line:SetHeight (1.1) 2912 line:SetHeight (1.1)
2888 2913
2889 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall") 2914 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
2890 f ["dpsamt"..i] = s 2915 f ["dpsamt"..i] = s
2964 2989
2965 local t = f:CreateTexture (nil, "background") 2990 local t = f:CreateTexture (nil, "background")
2966 t:SetWidth (1) 2991 t:SetWidth (1)
2967 t:SetPoint ("topright", f, "topright") 2992 t:SetPoint ("topright", f, "topright")
2968 t:SetPoint ("bottomright", f, "bottomright") 2993 t:SetPoint ("bottomright", f, "bottomright")
2969 t:SetTexture (1, 1, 1, .1) 2994 t:SetColorTexture (1, 1, 1, .1)
2970 f.grid = t 2995 f.grid = t
2971 2996
2972 local b = f:CreateTexture (nil, "overlay") 2997 local b = f:CreateTexture (nil, "overlay")
2973 b:SetTexture ([[Interface\COMMON\Indicator-Yellow]]) 2998 b:SetTexture ([[Interface\COMMON\Indicator-Yellow]])
2974 b:SetSize (16, 16) 2999 b:SetSize (16, 16)
3079 f._linewidth = linewidth or 50 3104 f._linewidth = linewidth or 50
3080 f._maxlines = floor (f:GetWidth() / f._linewidth) 3105 f._maxlines = floor (f:GetWidth() / f._linewidth)
3081 3106
3082 return f 3107 return f
3083 end 3108 end
3109
3110
3111 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3112 -- ~buttoncontainer
3113
3114 function DF:CreateButtonContainer (parent, name)
3115 local f = CreateFrame ("frame", name, parent)
3116 -- f.
3117 end
3118
3119
3120 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3121 --> options tabs and buttons -dot
3122
3123 function DF:FindHighestParent (self)
3124 local f
3125 if (self:GetParent() == UIParent) then
3126 f = self
3127 end
3128 if (not f) then
3129 f = self
3130 for i = 1, 6 do
3131 local parent = f:GetParent()
3132 if (parent == UIParent) then
3133 break
3134 else
3135 f = parent
3136 end
3137 end
3138 end
3139
3140 return f
3141 end
3142
3143 DF.TabContainerFunctions = {}
3144
3145 local button_tab_template = DF.table.copy ({}, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
3146 button_tab_template.backdropbordercolor = nil
3147
3148 DF.TabContainerFunctions.CreateUnderlineGlow = function (button)
3149 local selectedGlow = button:CreateTexture (nil, "background", -4)
3150 selectedGlow:SetPoint ("topleft", button.widget, "bottomleft", -7, 0)
3151 selectedGlow:SetPoint ("topright", button.widget, "bottomright", 7, 0)
3152 selectedGlow:SetTexture ([[Interface\BUTTONS\UI-Panel-Button-Glow]])
3153 selectedGlow:SetTexCoord (0, 95/128, 30/64, 38/64)
3154 selectedGlow:SetBlendMode ("ADD")
3155 selectedGlow:SetHeight (8)
3156 selectedGlow:SetAlpha (.75)
3157 selectedGlow:Hide()
3158 button.selectedUnderlineGlow = selectedGlow
3159 end
3160
3161 DF.TabContainerFunctions.OnMouseDown = function (self, button)
3162 --> search for UIParent
3163 local f = DF:FindHighestParent (self)
3164 local container = self:GetParent()
3165
3166 if (button == "LeftButton") then
3167 if (not f.IsMoving and f:IsMovable()) then
3168 f:StartMoving()
3169 f.IsMoving = true
3170 end
3171 elseif (button == "RightButton") then
3172 if (not f.IsMoving and container.IsContainer) then
3173 if (self.IsFrontPage) then
3174 if (container.CanCloseWithRightClick) then
3175 if (f.CloseFunction) then
3176 f:CloseFunction()
3177 else
3178 f:Hide()
3179 end
3180 end
3181 else
3182 --goes back to front page
3183 DF.TabContainerFunctions.SelectIndex (self, _, 1)
3184 end
3185 end
3186 end
3187 end
3188
3189 DF.TabContainerFunctions.OnMouseUp = function (self, button)
3190 local f = DF:FindHighestParent (self)
3191 if (f.IsMoving) then
3192 f:StopMovingOrSizing()
3193 f.IsMoving = false
3194 end
3195 end
3196
3197 DF.TabContainerFunctions.SelectIndex = function (self, fixedParam, menuIndex)
3198 local mainFrame = self.AllFrames and self or self.mainFrame or self:GetParent()
3199
3200 for i = 1, #mainFrame.AllFrames do
3201 mainFrame.AllFrames[i]:Hide()
3202 if (mainFrame.ButtonNotSelectedBorderColor) then
3203 mainFrame.AllButtons[i]:SetBackdropBorderColor (unpack (mainFrame.ButtonNotSelectedBorderColor))
3204 end
3205 if (mainFrame.AllButtons[i].selectedUnderlineGlow) then
3206 mainFrame.AllButtons[i].selectedUnderlineGlow:Hide()
3207 end
3208 end
3209
3210 mainFrame.AllFrames[menuIndex]:Show()
3211 if (mainFrame.ButtonSelectedBorderColor) then
3212 mainFrame.AllButtons[menuIndex]:SetBackdropBorderColor (unpack (mainFrame.ButtonSelectedBorderColor))
3213 end
3214 if (mainFrame.AllButtons[menuIndex].selectedUnderlineGlow) then
3215 mainFrame.AllButtons[menuIndex].selectedUnderlineGlow:Show()
3216 end
3217 mainFrame.CurrentIndex = menuIndex
3218 end
3219
3220 DF.TabContainerFunctions.SetIndex = function (self, index)
3221 self.CurrentIndex = index
3222 end
3223
3224 local tab_container_on_show = function (self)
3225 local index = self.CurrentIndex
3226 self.SelectIndex (self.AllButtons[index], nil, index)
3227 end
3228
3229 function DF:CreateTabContainer (parent, title, frame_name, frame_list, options_table)
3230
3231 local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
3232 local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
3233 local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
3234 local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
3235 local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
3236
3237 options_table = options_table or {}
3238 local frame_width = parent:GetWidth()
3239 local frame_height = parent:GetHeight()
3240 local y_offset = options_table.y_offset or 0
3241 local button_width = options_table.button_width or 160
3242 local button_height = options_table.button_height or 20
3243 local button_anchor_x = options_table.button_x or 230
3244 local button_anchor_y = options_table.button_y or -32
3245 local button_text_size = options_table.button_text_size or 10
3246
3247 local mainFrame = CreateFrame ("frame", frame_name, parent.widget or parent)
3248 mainFrame:SetAllPoints()
3249 DF:Mixin (mainFrame, DF.TabContainerFunctions)
3250
3251 local mainTitle = DF:CreateLabel (mainFrame, title, 24, "white")
3252 mainTitle:SetPoint ("topleft", mainFrame, "topleft", 10, -30 + y_offset)
3253
3254 mainFrame:SetFrameLevel (200)
3255
3256 mainFrame.AllFrames = {}
3257 mainFrame.AllButtons = {}
3258 mainFrame.CurrentIndex = 1
3259 mainFrame.IsContainer = true
3260 mainFrame.ButtonSelectedBorderColor = options_table.button_selected_border_color or {1, 1, 0, 1}
3261 mainFrame.ButtonNotSelectedBorderColor = options_table.button_border_color or {0, 0, 0, 0}
3262
3263 if (options_table.right_click_interact ~= nil) then
3264 mainFrame.CanCloseWithRightClick = options_table.right_click_interact
3265 else
3266 mainFrame.CanCloseWithRightClick = true
3267 end
3268
3269 for i, frame in ipairs (frame_list) do
3270 local f = CreateFrame ("frame", "$parent" .. frame.name, mainFrame)
3271 f:SetAllPoints()
3272 f:SetFrameLevel (210)
3273 f:Hide()
3274
3275 local title = DF:CreateLabel (f, frame.title, 16, "silver")
3276 title:SetPoint ("topleft", mainTitle, "bottomleft", 0, 0)
3277
3278 local tabButton = DF:CreateButton (mainFrame, DF.TabContainerFunctions.SelectIndex, button_width, button_height, frame.title, i, nil, nil, nil, nil, false, button_tab_template)
3279 tabButton:SetFrameLevel (220)
3280 tabButton.textsize = button_text_size
3281 tabButton.mainFrame = mainFrame
3282 DF.TabContainerFunctions.CreateUnderlineGlow (tabButton)
3283
3284 if (i == 1) then
3285 local right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray")
3286 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
3287 f.IsFrontPage = true
3288 else
3289 local right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray")
3290 right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0)
3291 end
3292
3293 f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown)
3294 f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp)
3295
3296 tinsert (mainFrame.AllFrames, f)
3297 tinsert (mainFrame.AllButtons, tabButton)
3298 end
3299
3300 --order buttons
3301 local x = button_anchor_x
3302 local y = button_anchor_y
3303 local space_for_buttons = frame_width - (#frame_list*3) - button_anchor_x
3304 local amount_buttons_per_row = floor (space_for_buttons / button_width)
3305 local last_button = mainFrame.AllButtons[1]
3306
3307 mainFrame.AllButtons[1]:SetPoint ("topleft", mainTitle, "topleft", x, y)
3308 x = x + button_width + 2
3309
3310 for i = 2, #mainFrame.AllButtons do
3311 local button = mainFrame.AllButtons [i]
3312 button:SetPoint ("topleft", mainTitle, "topleft", x, y)
3313 x = x + button_width + 2
3314
3315 if (i % amount_buttons_per_row == 0) then
3316 x = button_anchor_x
3317 y = y - button_height - 1
3318 end
3319 end
3320
3321 --> when show the frame, reset to the current internal index
3322 mainFrame:SetScript ("OnShow", tab_container_on_show)
3323 --> select the first frame
3324 mainFrame.SelectIndex (mainFrame.AllButtons[1], nil, 1)
3325
3326 return mainFrame
3327 end
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339