comparison Libs/DF/fw.lua @ 22:dbd417f413a8

- framework update.
author Tercio
date Tue, 08 Sep 2015 13:16:49 -0300
parents dc1c77254f80
children 7a285d98b95f
comparison
equal deleted inserted replaced
21:7fef991992f6 22:dbd417f413a8
1 1
2 local major, minor = "DetailsFramework-1.0", 5 2 local major, minor = "DetailsFramework-1.0", 8
3 local DF, oldminor = LibStub:NewLibrary (major, minor) 3 local DF, oldminor = LibStub:NewLibrary (major, minor)
4 4
5 if (not DF) then 5 if (not DF) then
6 DetailsFrameworkCanLoad = false 6 DetailsFrameworkCanLoad = false
7 return 7 return
20 DF.DropDownCounter = 1 20 DF.DropDownCounter = 1
21 DF.PanelCounter = 1 21 DF.PanelCounter = 1
22 DF.ButtonCounter = 1 22 DF.ButtonCounter = 1
23 DF.SliderCounter = 1 23 DF.SliderCounter = 1
24 DF.SplitBarCounter = 1 24 DF.SplitBarCounter = 1
25
26 LibStub:GetLibrary("AceTimer-3.0"):Embed (DF)
25 27
26 do 28 do
27 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)fw.lua") 29 local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)fw.lua")
28 if (path) then 30 if (path) then
29 DF.folder = "Interface\\AddOns\\" .. path 31 DF.folder = "Interface\\AddOns\\" .. path
78 "CreateSplitBar", 80 "CreateSplitBar",
79 "CreateTextEntry", 81 "CreateTextEntry",
80 "Create1PxPanel", 82 "Create1PxPanel",
81 "CreateFeedbackButton", 83 "CreateFeedbackButton",
82 "CreateOptionsFrame", 84 "CreateOptionsFrame",
85 "NewSpecialLuaEditorEntry",
83 "ShowPromptPanel", 86 "ShowPromptPanel",
87 "ShowTextPromptPanel",
84 "www_icons", 88 "www_icons",
89 "GetTemplate",
90 "GetFrameworkFolder",
85 } 91 }
86 92
87 DF.table = {} 93 DF.table = {}
94
95 function DF:GetFrameworkFolder()
96 return DF.folder
97 end
88 98
89 function DF.table.reverse (t) 99 function DF.table.reverse (t)
90 local new = {} 100 local new = {}
91 local index = 1 101 local index = 1
92 for i = #t, 1, -1 do 102 for i = #t, 1, -1 do
113 function DF.table.deploy (t1, t2) 123 function DF.table.deploy (t1, t2)
114 for key, value in pairs (t2) do 124 for key, value in pairs (t2) do
115 if (type (value) == "table") then 125 if (type (value) == "table") then
116 t1 [key] = t1 [key] or {} 126 t1 [key] = t1 [key] or {}
117 DF.table.deploy (t1 [key], t2 [key]) 127 DF.table.deploy (t1 [key], t2 [key])
118 elseif (not t1 [key]) then 128 elseif (t1 [key] == nil) then
119 t1 [key] = value 129 t1 [key] = value
120 end 130 end
121 end 131 end
122 end 132 end
123 133
565 end 575 end
566 576
567 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 577 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
568 --> menus 578 --> menus
569 579
570 function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points) 580 function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template)
581
582 if (not parent.widget_list) then
583 DF:SetAsOptionsPanel (parent)
584 end
571 585
572 local cur_x = x_offset 586 local cur_x = x_offset
573 local cur_y = y_offset 587 local cur_y = y_offset
574 local max_x = 0 588 local max_x = 0
575 589
580 594
581 if (widget_table.type == "blank" or widget_table.type == "space") then 595 if (widget_table.type == "blank" or widget_table.type == "space") then
582 -- do nothing 596 -- do nothing
583 597
584 elseif (widget_table.type == "label" or widget_table.type == "text") then 598 elseif (widget_table.type == "label" or widget_table.type == "text") then
585 local label = DF:CreateLabel (parent, widget_table.get() or widget_table.text, widget_table.text_template or widget_table.size, widget_table.color, widget_table.font, nil, "$parentWidget" .. index, "overlay") 599 local label = DF:CreateLabel (parent, widget_table.get() or widget_table.text, widget_table.text_template or text_template or widget_table.size, widget_table.color, widget_table.font, nil, "$parentWidget" .. index, "overlay")
586 label._get = widget_table.get 600 label._get = widget_table.get
587 label.widget_type = "label" 601 label.widget_type = "label"
588 label:SetPoint (cur_x, cur_y) 602 label:SetPoint (cur_x, cur_y)
589 tinsert (parent.widget_list, label) 603 tinsert (parent.widget_list, label)
590 604
591 elseif (widget_table.type == "select" or widget_table.type == "dropdown") then 605 elseif (widget_table.type == "select" or widget_table.type == "dropdown") then
592 local dropdown = DF:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get()) 606 local dropdown = DF:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get(), dropdown_template)
593 dropdown.tooltip = widget_table.desc 607 dropdown.tooltip = widget_table.desc
594 dropdown._get = widget_table.get 608 dropdown._get = widget_table.get
595 dropdown.widget_type = "select" 609 dropdown.widget_type = "select"
596 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12) 610 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
597 dropdown:SetPoint ("left", label, "right", 2) 611 dropdown:SetPoint ("left", label, "right", 2)
598 label:SetPoint (cur_x, cur_y) 612 label:SetPoint (cur_x, cur_y)
599 613
600 local size = label.widget:GetStringWidth() + 140 + 4 614 local size = label.widget:GetStringWidth() + 140 + 4
601 if (size > max_x) then 615 if (size > max_x) then
603 end 617 end
604 618
605 tinsert (parent.widget_list, dropdown) 619 tinsert (parent.widget_list, dropdown)
606 620
607 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then 621 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then
608 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get()) 622 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template)
609 switch.tooltip = widget_table.desc 623 switch.tooltip = widget_table.desc
610 switch._get = widget_table.get 624 switch._get = widget_table.get
611 switch.widget_type = "toggle" 625 switch.widget_type = "toggle"
612 switch.OnSwitch = widget_table.set 626 switch.OnSwitch = widget_table.set
613 627
614 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12) 628 if (switch_is_box) then
629 switch:SetAsCheckBox()
630 end
631
632 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
615 switch:SetPoint ("left", label, "right", 2) 633 switch:SetPoint ("left", label, "right", 2)
616 label:SetPoint (cur_x, cur_y) 634 label:SetPoint (cur_x, cur_y)
617 635
618 local size = label.widget:GetStringWidth() + 60 + 4 636 local size = label.widget:GetStringWidth() + 60 + 4
619 if (size > max_x) then 637 if (size > max_x) then
622 640
623 tinsert (parent.widget_list, switch) 641 tinsert (parent.widget_list, switch)
624 642
625 elseif (widget_table.type == "range" or widget_table.type == "slider") then 643 elseif (widget_table.type == "range" or widget_table.type == "slider") then
626 local is_decimanls = widget_table.usedecimals 644 local is_decimanls = widget_table.usedecimals
627 local slider = DF:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls) 645 local slider = DF:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls, nil, nil, slider_template)
628 slider.tooltip = widget_table.desc 646 slider.tooltip = widget_table.desc
629 slider._get = widget_table.get 647 slider._get = widget_table.get
630 slider.widget_type = "range" 648 slider.widget_type = "range"
631 slider:SetHook ("OnValueChange", widget_table.set) 649 slider:SetHook ("OnValueChange", widget_table.set)
632 650
633 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12) 651 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
634 slider:SetPoint ("left", label, "right", 2) 652 slider:SetPoint ("left", label, "right", 2)
635 label:SetPoint (cur_x, cur_y) 653 label:SetPoint (cur_x, cur_y)
636 654
637 local size = label.widget:GetStringWidth() + 140 + 6 655 local size = label.widget:GetStringWidth() + 140 + 6
638 if (size > max_x) then 656 if (size > max_x) then
640 end 658 end
641 659
642 tinsert (parent.widget_list, slider) 660 tinsert (parent.widget_list, slider)
643 661
644 elseif (widget_table.type == "color" or widget_table.type == "color") then 662 elseif (widget_table.type == "color" or widget_table.type == "color") then
645 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set) 663 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template)
646 colorpick.tooltip = widget_table.desc 664 colorpick.tooltip = widget_table.desc
647 colorpick._get = widget_table.get 665 colorpick._get = widget_table.get
648 colorpick.widget_type = "color" 666 colorpick.widget_type = "color"
649 667
650 local default_value, g, b, a = widget_table.get() 668 local default_value, g, b, a = widget_table.get()
652 colorpick:SetColor (unpack (default_value)) 670 colorpick:SetColor (unpack (default_value))
653 else 671 else
654 colorpick:SetColor (default_value, g, b, a) 672 colorpick:SetColor (default_value, g, b, a)
655 end 673 end
656 674
657 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12) 675 local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12)
658 colorpick:SetPoint ("left", label, "right", 2) 676 colorpick:SetPoint ("left", label, "right", 2)
659 label:SetPoint (cur_x, cur_y) 677 label:SetPoint (cur_x, cur_y)
660 678
661 local size = label.widget:GetStringWidth() + 60 + 4 679 local size = label.widget:GetStringWidth() + 60 + 4
662 if (size > max_x) then 680 if (size > max_x) then
665 683
666 tinsert (parent.widget_list, colorpick) 684 tinsert (parent.widget_list, colorpick)
667 685
668 elseif (widget_table.type == "execute" or widget_table.type == "button") then 686 elseif (widget_table.type == "execute" or widget_table.type == "button") then
669 687
670 local button = DF:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name) 688 local button = DF:NewButton (parent, nil, "$parentWidget" .. index, nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name, nil, button_template)
671 button:InstallCustomTexture() 689 if (not button_template) then
690 button:InstallCustomTexture()
691 end
692
672 button:SetPoint (cur_x, cur_y) 693 button:SetPoint (cur_x, cur_y)
673 button.tooltip = widget_table.desc 694 button.tooltip = widget_table.desc
674 button.widget_type = "execute" 695 button.widget_type = "execute"
675 696
676 local size = button:GetWidth() + 4 697 local size = button:GetWidth() + 4
898 c:SetFrameLevel (options_frame:GetFrameLevel()+1) 919 c:SetFrameLevel (options_frame:GetFrameLevel()+1)
899 920
900 return options_frame 921 return options_frame
901 end 922 end
902 end 923 end
924
925 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
926 --> templates
927
928 DF.font_templates = {}
929 DF.font_templates ["ORANGE_FONT_TEMPLATE"] = {color = "orange", size = 11, font = "Accidental Presidency"}
930 DF.font_templates ["OPTIONS_FONT_TEMPLATE"] = {color = "yellow", size = 12, font = "Accidental Presidency"}
931
932 DF.dropdown_templates = {}
933 DF.dropdown_templates ["OPTIONS_DROPDOWN_TEMPLATE"] = {
934 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
935 backdropcolor = {1, 1, 1, .5},
936 backdropbordercolor = {0, 0, 0, 1},
937 onentercolor = {1, 1, 1, .5},
938 onenterbordercolor = {1, 1, 1, 1},
939 }
940
941 DF.switch_templates = {}
942 DF.switch_templates ["OPTIONS_CHECKBOX_TEMPLATE"] = {
943 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
944 backdropcolor = {1, 1, 1, .5},
945 backdropbordercolor = {0, 0, 0, 1},
946 width = 18,
947 height = 18,
948 enabled_backdropcolor = {1, 1, 1, .5},
949 disabled_backdropcolor = {1, 1, 1, .2},
950 onenterbordercolor = {1, 1, 1, 1},
951 }
952 DF.switch_templates ["OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"] = {
953 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
954 backdropcolor = {1, 1, 1, .5},
955 backdropbordercolor = {0, 0, 0, 1},
956 width = 18,
957 height = 18,
958 enabled_backdropcolor = {1, 1, 1, .5},
959 disabled_backdropcolor = {1, 1, 1, .5},
960 onenterbordercolor = {1, 1, 1, 1},
961 }
962
963 DF.button_templates = {}
964 DF.button_templates ["OPTIONS_BUTTON_TEMPLATE"] = {
965 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
966 backdropcolor = {1, 1, 1, .5},
967 backdropbordercolor = {0, 0, 0, 1},
968 }
969
970 DF.slider_templates = {}
971 DF.slider_templates ["OPTIONS_SLIDER_TEMPLATE"] = {
972 backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
973 backdropcolor = {1, 1, 1, .5},
974 backdropbordercolor = {0, 0, 0, 1},
975 onentercolor = {1, 1, 1, .5},
976 onenterbordercolor = {1, 1, 1, 1},
977 thumbtexture = [[Interface\Tooltips\UI-Tooltip-Background]],
978 thumbwidth = 16,
979 thumbheight = 14,
980 thumbcolor = {0, 0, 0, 0.5},
981 }
982
983 function DF:GetTemplate (type, template_name)
984 local template_table
985 if (type == "font") then
986 template_table = DF.font_templates
987 elseif (type == "dropdown") then
988 template_table = DF.dropdown_templates
989 elseif (type == "button") then
990 template_table = DF.button_templates
991 elseif (type == "switch") then
992 template_table = DF.switch_templates
993 elseif (type == "slider") then
994 template_table = DF.slider_templates
995 end
996 return template_table [template_name]
997 end
998