Mercurial > wow > hansgar_and_franzok_assist
comparison Libs/DF/fw.lua @ 20:dc1c77254f80
- added close button to users panel.
- framework update.
| author | Tercio |
|---|---|
| date | Tue, 11 Aug 2015 12:46:46 -0300 |
| parents | 680465749fc7 |
| children | dbd417f413a8 |
comparison
equal
deleted
inserted
replaced
| 19:215f0dd37a6c | 20:dc1c77254f80 |
|---|---|
| 1 | 1 |
| 2 local major, minor = "DetailsFramework-1.0", 3 | 2 local major, minor = "DetailsFramework-1.0", 5 |
| 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 DetailsFrameWorkLoadValid = false | 6 DetailsFrameworkCanLoad = false |
| 7 return | 7 return |
| 8 end | 8 end |
| 9 | 9 |
| 10 DetailsFrameWorkLoadValid = true | 10 DetailsFrameworkCanLoad = true |
| 11 | 11 |
| 12 local _type = type | 12 local _type = type |
| 13 local _unpack = unpack | 13 local _unpack = unpack |
| 14 local _ | 14 local _ |
| 15 local upper = string.upper | 15 local upper = string.upper |
| 36 | 36 |
| 37 _G ["DetailsFramework"] = DF | 37 _G ["DetailsFramework"] = DF |
| 38 | 38 |
| 39 DF.embeds = DF.embeds or {} | 39 DF.embeds = DF.embeds or {} |
| 40 local embed_functions = { | 40 local embed_functions = { |
| 41 "RemoveRealName", | |
| 42 "table", | |
| 43 "BuildDropDownFontList", | |
| 41 "SetFontSize", | 44 "SetFontSize", |
| 42 "SetFontFace", | 45 "SetFontFace", |
| 43 "SetFontColor", | 46 "SetFontColor", |
| 44 "GetFontSize", | 47 "GetFontSize", |
| 45 "GetFontFace", | 48 "GetFontFace", |
| 53 "ParseColors", | 56 "ParseColors", |
| 54 "BuildMenu", | 57 "BuildMenu", |
| 55 "ShowTutorialAlertFrame", | 58 "ShowTutorialAlertFrame", |
| 56 "GetNpcIdFromGuid", | 59 "GetNpcIdFromGuid", |
| 57 "ShowFeedbackPanel", | 60 "ShowFeedbackPanel", |
| 61 "SetAsOptionsPanel", | |
| 58 | 62 |
| 59 "CreateDropDown", | 63 "CreateDropDown", |
| 60 "CreateButton", | 64 "CreateButton", |
| 61 "CreateColorPickButton", | 65 "CreateColorPickButton", |
| 62 "CreateLabel", | 66 "CreateLabel", |
| 73 "CreateSlider", | 77 "CreateSlider", |
| 74 "CreateSplitBar", | 78 "CreateSplitBar", |
| 75 "CreateTextEntry", | 79 "CreateTextEntry", |
| 76 "Create1PxPanel", | 80 "Create1PxPanel", |
| 77 "CreateFeedbackButton", | 81 "CreateFeedbackButton", |
| 78 | 82 "CreateOptionsFrame", |
| 83 "ShowPromptPanel", | |
| 79 "www_icons", | 84 "www_icons", |
| 80 } | 85 } |
| 86 | |
| 87 DF.table = {} | |
| 88 | |
| 89 function DF.table.reverse (t) | |
| 90 local new = {} | |
| 91 local index = 1 | |
| 92 for i = #t, 1, -1 do | |
| 93 new [index] = t[i] | |
| 94 index = index + 1 | |
| 95 end | |
| 96 return new | |
| 97 end | |
| 98 | |
| 99 --> copy from table2 to table1 overwriting values | |
| 100 function DF.table.copy (t1, t2) | |
| 101 for key, value in pairs (t2) do | |
| 102 if (type (value) == "table") then | |
| 103 t1 [key] = t1 [key] or {} | |
| 104 DF.table.copy (t1 [key], t2 [key]) | |
| 105 else | |
| 106 t1 [key] = value | |
| 107 end | |
| 108 end | |
| 109 return t1 | |
| 110 end | |
| 111 | |
| 112 --> copy values that does exist on table2 but not on table1 | |
| 113 function DF.table.deploy (t1, t2) | |
| 114 for key, value in pairs (t2) do | |
| 115 if (type (value) == "table") then | |
| 116 t1 [key] = t1 [key] or {} | |
| 117 DF.table.deploy (t1 [key], t2 [key]) | |
| 118 elseif (not t1 [key]) then | |
| 119 t1 [key] = value | |
| 120 end | |
| 121 end | |
| 122 end | |
| 123 | |
| 124 function DF.table.dump (t, s, deep) | |
| 125 s = s or "" | |
| 126 deep = deep or 0 | |
| 127 local space = "" | |
| 128 for i = 1, deep do | |
| 129 space = space .. " " | |
| 130 end | |
| 131 for key, value in pairs (t) do | |
| 132 local tpe = _type (value) | |
| 133 if (type (key) ~= "string") then | |
| 134 key = "unknown?" | |
| 135 end | |
| 136 if (tpe == "table") then | |
| 137 s = s .. space .. "[" .. key .. "] = |cFFa9ffa9table {|r\n" | |
| 138 s = s .. DF.table.dump (value, nil, deep+1) | |
| 139 s = s .. space .. "|cFFa9ffa9}|r\n" | |
| 140 elseif (tpe == "string") then | |
| 141 s = s .. space .. "[" .. key .. "] = '|cFFfff1c1" .. value .. "|r'\n" | |
| 142 elseif (tpe == "number") then | |
| 143 s = s .. space .. "[" .. key .. "] = |cFFffc1f4" .. value .. "|r\n" | |
| 144 elseif (tpe == "function") then | |
| 145 s = s .. space .. "[" .. key .. "] = function()\n" | |
| 146 elseif (tpe == "boolean") then | |
| 147 s = s .. space .. "[" .. key .. "] = |cFF99d0ff" .. (value and "true" or "false") .. "|r\n" | |
| 148 end | |
| 149 end | |
| 150 return s | |
| 151 end | |
| 81 | 152 |
| 82 DF.www_icons = { | 153 DF.www_icons = { |
| 83 texture = "feedback_sites", | 154 texture = "feedback_sites", |
| 84 wowi = {0, 0.7890625, 0, 37/128}, | 155 wowi = {0, 0.7890625, 0, 37/128}, |
| 85 curse = {0, 0.7890625, 38/123, 79/128}, | 156 curse = {0, 0.7890625, 38/123, 79/128}, |
| 90 for k, v in pairs (embed_functions) do | 161 for k, v in pairs (embed_functions) do |
| 91 target[v] = self[v] | 162 target[v] = self[v] |
| 92 end | 163 end |
| 93 self.embeds [target] = true | 164 self.embeds [target] = true |
| 94 return target | 165 return target |
| 166 end | |
| 167 | |
| 168 function DF:RemoveRealName (name) | |
| 169 return name:gsub (("%-.*"), "") | |
| 95 end | 170 end |
| 96 | 171 |
| 97 function DF:SetFontSize (fontString, ...) | 172 function DF:SetFontSize (fontString, ...) |
| 98 local fonte, _, flags = fontString:GetFont() | 173 local fonte, _, flags = fontString:GetFont() |
| 99 fontString:SetFont (fonte, max (...), flags) | 174 fontString:SetFont (fonte, max (...), flags) |
| 490 end | 565 end |
| 491 | 566 |
| 492 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 567 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 493 --> menus | 568 --> menus |
| 494 | 569 |
| 495 function DF:BuildMenu (parent, menu, x_offset, y_offset, height) | 570 function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points) |
| 496 | 571 |
| 497 local cur_x = x_offset | 572 local cur_x = x_offset |
| 498 local cur_y = y_offset | 573 local cur_y = y_offset |
| 499 local max_x = 0 | 574 local max_x = 0 |
| 500 | 575 |
| 501 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20) | 576 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20) |
| 502 height = height*-1 | 577 height = height*-1 |
| 503 | 578 |
| 504 for index, widget_table in ipairs (menu) do | 579 for index, widget_table in ipairs (menu) do |
| 505 | 580 |
| 506 if (widget_table.type == "select" or widget_table.type == "dropdown") then | 581 if (widget_table.type == "blank" or widget_table.type == "space") then |
| 507 local dropdown = self:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get()) | 582 -- do nothing |
| 583 | |
| 584 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") | |
| 586 label._get = widget_table.get | |
| 587 label.widget_type = "label" | |
| 588 label:SetPoint (cur_x, cur_y) | |
| 589 tinsert (parent.widget_list, label) | |
| 590 | |
| 591 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()) | |
| 508 dropdown.tooltip = widget_table.desc | 593 dropdown.tooltip = widget_table.desc |
| 509 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12) | 594 dropdown._get = widget_table.get |
| 595 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) | |
| 510 dropdown:SetPoint ("left", label, "right", 2) | 597 dropdown:SetPoint ("left", label, "right", 2) |
| 511 label:SetPoint (cur_x, cur_y) | 598 label:SetPoint (cur_x, cur_y) |
| 512 | 599 |
| 513 local size = label.widget:GetStringWidth() + 140 + 4 | 600 local size = label.widget:GetStringWidth() + 140 + 4 |
| 514 if (size > max_x) then | 601 if (size > max_x) then |
| 515 max_x = size | 602 max_x = size |
| 516 end | 603 end |
| 517 | 604 |
| 605 tinsert (parent.widget_list, dropdown) | |
| 606 | |
| 518 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then | 607 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then |
| 519 local switch = self:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get()) | 608 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get()) |
| 520 switch.tooltip = widget_table.desc | 609 switch.tooltip = widget_table.desc |
| 610 switch._get = widget_table.get | |
| 611 switch.widget_type = "toggle" | |
| 521 switch.OnSwitch = widget_table.set | 612 switch.OnSwitch = widget_table.set |
| 522 | 613 |
| 523 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12) | 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) |
| 524 switch:SetPoint ("left", label, "right", 2) | 615 switch:SetPoint ("left", label, "right", 2) |
| 525 label:SetPoint (cur_x, cur_y) | 616 label:SetPoint (cur_x, cur_y) |
| 526 | 617 |
| 527 local size = label.widget:GetStringWidth() + 60 + 4 | 618 local size = label.widget:GetStringWidth() + 60 + 4 |
| 528 if (size > max_x) then | 619 if (size > max_x) then |
| 529 max_x = size | 620 max_x = size |
| 530 end | 621 end |
| 531 | 622 |
| 623 tinsert (parent.widget_list, switch) | |
| 624 | |
| 532 elseif (widget_table.type == "range" or widget_table.type == "slider") then | 625 elseif (widget_table.type == "range" or widget_table.type == "slider") then |
| 533 local is_decimanls = widget_table.usedecimals | 626 local is_decimanls = widget_table.usedecimals |
| 534 local slider = self:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls) | 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) |
| 535 slider.tooltip = widget_table.desc | 628 slider.tooltip = widget_table.desc |
| 629 slider._get = widget_table.get | |
| 630 slider.widget_type = "range" | |
| 536 slider:SetHook ("OnValueChange", widget_table.set) | 631 slider:SetHook ("OnValueChange", widget_table.set) |
| 537 | 632 |
| 538 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12) | 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) |
| 539 slider:SetPoint ("left", label, "right", 2) | 634 slider:SetPoint ("left", label, "right", 2) |
| 540 label:SetPoint (cur_x, cur_y) | 635 label:SetPoint (cur_x, cur_y) |
| 541 | 636 |
| 542 local size = label.widget:GetStringWidth() + 140 + 6 | 637 local size = label.widget:GetStringWidth() + 140 + 6 |
| 543 if (size > max_x) then | 638 if (size > max_x) then |
| 544 max_x = size | 639 max_x = size |
| 545 end | 640 end |
| 546 | 641 |
| 642 tinsert (parent.widget_list, slider) | |
| 643 | |
| 547 elseif (widget_table.type == "color" or widget_table.type == "color") then | 644 elseif (widget_table.type == "color" or widget_table.type == "color") then |
| 548 local colorpick = self:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set) | 645 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set) |
| 549 colorpick.tooltip = widget_table.desc | 646 colorpick.tooltip = widget_table.desc |
| 647 colorpick._get = widget_table.get | |
| 648 colorpick.widget_type = "color" | |
| 550 | 649 |
| 551 local default_value, g, b, a = widget_table.get() | 650 local default_value, g, b, a = widget_table.get() |
| 552 if (type (default_value) == "table") then | 651 if (type (default_value) == "table") then |
| 553 colorpick:SetColor (unpack (default_value)) | 652 colorpick:SetColor (unpack (default_value)) |
| 554 else | 653 else |
| 555 colorpick:SetColor (default_value, g, b, a) | 654 colorpick:SetColor (default_value, g, b, a) |
| 556 end | 655 end |
| 557 | 656 |
| 558 local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12) | 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) |
| 559 colorpick:SetPoint ("left", label, "right", 2) | 658 colorpick:SetPoint ("left", label, "right", 2) |
| 560 label:SetPoint (cur_x, cur_y) | 659 label:SetPoint (cur_x, cur_y) |
| 561 | 660 |
| 562 local size = label.widget:GetStringWidth() + 60 + 4 | 661 local size = label.widget:GetStringWidth() + 60 + 4 |
| 563 if (size > max_x) then | 662 if (size > max_x) then |
| 564 max_x = size | 663 max_x = size |
| 565 end | 664 end |
| 566 | 665 |
| 666 tinsert (parent.widget_list, colorpick) | |
| 667 | |
| 567 elseif (widget_table.type == "execute" or widget_table.type == "button") then | 668 elseif (widget_table.type == "execute" or widget_table.type == "button") then |
| 568 | 669 |
| 569 local button = self:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name) | 670 local button = DF:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name) |
| 570 button:InstallCustomTexture() | 671 button:InstallCustomTexture() |
| 571 button:SetPoint (cur_x, cur_y) | 672 button:SetPoint (cur_x, cur_y) |
| 572 button.tooltip = widget_table.desc | 673 button.tooltip = widget_table.desc |
| 674 button.widget_type = "execute" | |
| 573 | 675 |
| 574 local size = button:GetWidth() + 4 | 676 local size = button:GetWidth() + 4 |
| 575 if (size > max_x) then | 677 if (size > max_x) then |
| 576 max_x = size | 678 max_x = size |
| 577 end | 679 end |
| 680 | |
| 681 tinsert (parent.widget_list, button) | |
| 578 | 682 |
| 579 end | 683 end |
| 580 | 684 |
| 581 if (widget_table.spacement) then | 685 if (widget_table.spacement) then |
| 582 cur_y = cur_y - 30 | 686 cur_y = cur_y - 30 |
| 661 TutorialAlertFrame.clickfunc = clickfunc | 765 TutorialAlertFrame.clickfunc = clickfunc |
| 662 TutorialAlertFrame:Show() | 766 TutorialAlertFrame:Show() |
| 663 DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST") | 767 DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST") |
| 664 end | 768 end |
| 665 | 769 |
| 770 local refresh_options = function (self) | |
| 771 for _, widget in ipairs (self.widget_list) do | |
| 772 if (widget._get) then | |
| 773 if (widget.widget_type == "label") then | |
| 774 if (widget._get()) then | |
| 775 widget:SetText (widget._get()) | |
| 776 end | |
| 777 elseif (widget.widget_type == "select") then | |
| 778 widget:Select (widget._get()) | |
| 779 elseif (widget.widget_type == "toggle" or widget.widget_type == "range") then | |
| 780 widget:SetValue (widget._get()) | |
| 781 elseif (widget.widget_type == "color") then | |
| 782 local default_value, g, b, a = widget._get() | |
| 783 if (type (default_value) == "table") then | |
| 784 widget:SetColor (unpack (default_value)) | |
| 785 else | |
| 786 widget:SetColor (default_value, g, b, a) | |
| 787 end | |
| 788 end | |
| 789 end | |
| 790 end | |
| 791 end | |
| 792 | |
| 793 function DF:SetAsOptionsPanel (frame) | |
| 794 frame.RefreshOptions = refresh_options | |
| 795 frame.widget_list = {} | |
| 796 end | |
| 797 | |
| 666 function DF:CreateOptionsFrame (name, title, template) | 798 function DF:CreateOptionsFrame (name, title, template) |
| 667 | 799 |
| 668 template = template or 1 | 800 template = template or 1 |
| 669 | 801 |
| 670 if (template == 2) then | 802 if (template == 2) then |
| 671 local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate") | 803 local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate") |
| 672 tinsert (UISpecialFrames, name) | 804 tinsert (UISpecialFrames, name) |
| 673 options_frame:SetSize (500, 200) | 805 options_frame:SetSize (500, 200) |
| 806 options_frame.RefreshOptions = refresh_options | |
| 807 options_frame.widget_list = {} | |
| 674 | 808 |
| 675 options_frame:SetScript ("OnMouseDown", function(self, button) | 809 options_frame:SetScript ("OnMouseDown", function(self, button) |
| 676 if (button == "RightButton") then | 810 if (button == "RightButton") then |
| 677 if (self.moving) then | 811 if (self.moving) then |
| 678 self.moving = false | 812 self.moving = false |
| 707 elseif (template == 1) then | 841 elseif (template == 1) then |
| 708 | 842 |
| 709 local options_frame = CreateFrame ("frame", name, UIParent) | 843 local options_frame = CreateFrame ("frame", name, UIParent) |
| 710 tinsert (UISpecialFrames, name) | 844 tinsert (UISpecialFrames, name) |
| 711 options_frame:SetSize (500, 200) | 845 options_frame:SetSize (500, 200) |
| 846 options_frame.RefreshOptions = refresh_options | |
| 847 options_frame.widget_list = {} | |
| 712 | 848 |
| 713 options_frame:SetScript ("OnMouseDown", function(self, button) | 849 options_frame:SetScript ("OnMouseDown", function(self, button) |
| 714 if (button == "RightButton") then | 850 if (button == "RightButton") then |
| 715 if (self.moving) then | 851 if (self.moving) then |
| 716 self.moving = false | 852 self.moving = false |
