Mercurial > wow > hansgar_and_franzok_assist
comparison Libs/DF/dropdown.lua @ 22:dbd417f413a8
- framework update.
| author | Tercio |
|---|---|
| date | Tue, 08 Sep 2015 13:16:49 -0300 |
| parents | dc1c77254f80 |
| children | 5da06cb420d4 |
comparison
equal
deleted
inserted
replaced
| 21:7fef991992f6 | 22:dbd417f413a8 |
|---|---|
| 327 | 327 |
| 328 return true | 328 return true |
| 329 end | 329 end |
| 330 | 330 |
| 331 function DropDownMetaFunctions:NoOptionSelected() | 331 function DropDownMetaFunctions:NoOptionSelected() |
| 332 if (self.no_options) then | |
| 333 return | |
| 334 end | |
| 332 self.label:SetText (self.empty_text or "no option selected") | 335 self.label:SetText (self.empty_text or "no option selected") |
| 336 self.label:SetPoint ("left", self.icon, "right", 2, 0) | |
| 333 self.label:SetTextColor (1, 1, 1, 0.4) | 337 self.label:SetTextColor (1, 1, 1, 0.4) |
| 334 if (self.empty_icon) then | 338 if (self.empty_icon) then |
| 335 self.icon:SetTexture (self.empty_icon) | 339 self.icon:SetTexture (self.empty_icon) |
| 336 else | 340 else |
| 337 self.icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) | 341 self.icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) |
| 346 if (state) then | 350 if (state) then |
| 347 self:Disable() | 351 self:Disable() |
| 348 self:SetAlpha (0.5) | 352 self:SetAlpha (0.5) |
| 349 self.no_options = true | 353 self.no_options = true |
| 350 self.label:SetText ("no options") | 354 self.label:SetText ("no options") |
| 355 self.label:SetPoint ("left", self.icon, "right", 2, 0) | |
| 351 self.label:SetTextColor (1, 1, 1, 0.4) | 356 self.label:SetTextColor (1, 1, 1, 0.4) |
| 352 self.icon:SetTexture ([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) | 357 self.icon:SetTexture ([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) |
| 353 self.icon:SetTexCoord (0, 1, 0, 1) | 358 self.icon:SetTexCoord (0, 1, 0, 1) |
| 354 self.icon:SetVertexColor (1, 1, 1, 0.4) | 359 self.icon:SetVertexColor (1, 1, 1, 0.4) |
| 355 else | 360 else |
| 442 end | 447 end |
| 443 else | 448 else |
| 444 self.icon:SetVertexColor (1, 1, 1, 1) | 449 self.icon:SetVertexColor (1, 1, 1, 1) |
| 445 end | 450 end |
| 446 | 451 |
| 452 self.icon:SetSize (self:GetHeight()-2, self:GetHeight()-2) | |
| 447 else | 453 else |
| 448 self.label:SetPoint ("left", self.label:GetParent(), "left", 4, 0) | 454 self.label:SetPoint ("left", self.label:GetParent(), "left", 4, 0) |
| 449 end | 455 end |
| 450 | 456 |
| 451 self.statusbar:SetTexture (_table.statusbar) | 457 self.statusbar:SetTexture (_table.statusbar) |
| 480 button.table.onclick (button:GetParent():GetParent():GetParent().MyObject, button.object.FixedValue, button.table.value) | 486 button.table.onclick (button:GetParent():GetParent():GetParent().MyObject, button.object.FixedValue, button.table.value) |
| 481 end | 487 end |
| 482 | 488 |
| 483 --> set the value of selected option in main object | 489 --> set the value of selected option in main object |
| 484 button.object.myvalue = button.table.value | 490 button.object.myvalue = button.table.value |
| 491 button.object.myvaluelabel = button.table.label | |
| 485 end | 492 end |
| 486 | 493 |
| 487 function DropDownMetaFunctions:Open() | 494 function DropDownMetaFunctions:Open() |
| 488 self.dropdown.dropdownframe:Show() | 495 self.dropdown.dropdownframe:Show() |
| 489 self.dropdown.dropdownborder:Show() | 496 self.dropdown.dropdownborder:Show() |
| 561 local mouseOverTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_MouseOverTexture"] | 568 local mouseOverTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_MouseOverTexture"] |
| 562 | 569 |
| 563 local i = 1 | 570 local i = 1 |
| 564 local showing = 0 | 571 local showing = 0 |
| 565 local currentText = button.text:GetText() or "" | 572 local currentText = button.text:GetText() or "" |
| 573 local currentIndex | |
| 566 | 574 |
| 567 if (object.OnMouseDownHook) then | 575 if (object.OnMouseDownHook) then |
| 568 local interrupt = object.OnMouseDownHook (button, buttontype, menu, scrollFrame, scrollChild, selectedTexture) | 576 local interrupt = object.OnMouseDownHook (button, buttontype, menu, scrollFrame, scrollChild, selectedTexture) |
| 569 if (interrupt) then | 577 if (interrupt) then |
| 570 return | 578 return |
| 571 end | 579 end |
| 572 end | 580 end |
| 573 | 581 |
| 574 for _, _table in ipairs (menu) do | 582 for tindex, _table in ipairs (menu) do |
| 575 | 583 |
| 576 local show = isOptionVisible (_table) | 584 local show = isOptionVisible (_table) |
| 577 | 585 |
| 578 if (show) then | 586 if (show) then |
| 579 local _this_row = object.menus [i] | 587 local _this_row = object.menus [i] |
| 637 else | 645 else |
| 638 selectedTexture:SetPoint ("left", _this_row.statusbar, "left", 0, 0) | 646 selectedTexture:SetPoint ("left", _this_row.statusbar, "left", 0, 0) |
| 639 end | 647 end |
| 640 | 648 |
| 641 selectedTexture:Show() | 649 selectedTexture:Show() |
| 642 selectedTexture:SetVertexColor (1, 1, 1, .3); | 650 selectedTexture:SetVertexColor (1, 1, 1, .3) |
| 651 selectedTexture:SetTexCoord (0, 29/32, 5/32, 27/32) | |
| 652 | |
| 653 currentIndex = tindex | |
| 643 currentText = nil | 654 currentText = nil |
| 644 end | 655 end |
| 645 | 656 |
| 646 if (_table.color) then | 657 if (_table.color) then |
| 647 local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) | 658 local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) |
| 717 for index, row in ipairs (object.menus) do | 728 for index, row in ipairs (object.menus) do |
| 718 row:SetPoint ("topright", scrollChild, "topright", -5, ((-index-1)*20)-5) | 729 row:SetPoint ("topright", scrollChild, "topright", -5, ((-index-1)*20)-5) |
| 719 end | 730 end |
| 720 end | 731 end |
| 721 | 732 |
| 722 object.scroll:SetValue (0) | 733 if (object.myvaluelabel and currentIndex and scrollFrame.slider:IsShown()) then |
| 734 object.scroll:SetValue (max ((currentIndex*20) - 80, 0)) | |
| 735 else | |
| 736 object.scroll:SetValue (0) | |
| 737 end | |
| 738 | |
| 723 object:Open() | 739 object:Open() |
| 724 | 740 |
| 725 else | 741 else |
| 726 --> clear menu | 742 --> clear menu |
| 727 | 743 |
| 747 self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) | 763 self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) |
| 748 else | 764 else |
| 749 self:SetBackdropColor (.2, .2, .2, .2) | 765 self:SetBackdropColor (.2, .2, .2, .2) |
| 750 end | 766 end |
| 751 | 767 |
| 768 if (self.MyObject.onenter_backdrop_border_color) then | |
| 769 self:SetBackdropBorderColor (unpack (self.MyObject.onenter_backdrop_border_color)) | |
| 770 end | |
| 771 | |
| 752 self.arrowTexture2:Show() | 772 self.arrowTexture2:Show() |
| 753 | 773 |
| 754 if (self.MyObject.have_tooltip) then | 774 if (self.MyObject.have_tooltip) then |
| 755 GameCooltip2:Preset (2) | 775 GameCooltip2:Preset (2) |
| 756 | 776 |
| 761 end | 781 end |
| 762 | 782 |
| 763 GameCooltip2:SetOwner (self) | 783 GameCooltip2:SetOwner (self) |
| 764 GameCooltip2:ShowCooltip() | 784 GameCooltip2:ShowCooltip() |
| 765 end | 785 end |
| 766 | 786 |
| 767 local parent = self:GetParent().MyObject | |
| 768 if (parent and parent.type == "panel") then | |
| 769 if (parent.GradientEnabled) then | |
| 770 parent:RunGradient() | |
| 771 end | |
| 772 end | |
| 773 | |
| 774 end | 787 end |
| 775 | 788 |
| 776 function DetailsFrameworkDropDownOnLeave (self) | 789 function DetailsFrameworkDropDownOnLeave (self) |
| 777 if (self.MyObject.OnLeaveHook) then | 790 if (self.MyObject.OnLeaveHook) then |
| 778 local interrupt = self.MyObject.OnLeaveHook (self) | 791 local interrupt = self.MyObject.OnLeaveHook (self) |
| 785 self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) | 798 self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) |
| 786 else | 799 else |
| 787 self:SetBackdropColor (1, 1, 1, .5) | 800 self:SetBackdropColor (1, 1, 1, .5) |
| 788 end | 801 end |
| 789 | 802 |
| 803 if (self.MyObject.onleave_backdrop_border_color) then | |
| 804 self:SetBackdropBorderColor (unpack (self.MyObject.onleave_backdrop_border_color)) | |
| 805 end | |
| 806 | |
| 790 self.arrowTexture2:Hide() | 807 self.arrowTexture2:Hide() |
| 791 | 808 |
| 792 if (self.MyObject.have_tooltip) then | 809 if (self.MyObject.have_tooltip) then |
| 793 GameCooltip2:ShowMe (false) | 810 GameCooltip2:ShowMe (false) |
| 794 end | |
| 795 | |
| 796 local parent = self:GetParent().MyObject | |
| 797 if (parent and parent.type == "panel") then | |
| 798 if (parent.GradientEnabled) then | |
| 799 parent:RunGradient (false) | |
| 800 end | |
| 801 end | 811 end |
| 802 end | 812 end |
| 803 | 813 |
| 804 function DetailsFrameworkDropDownOnSizeChanged (self, w, h) | 814 function DetailsFrameworkDropDownOnSizeChanged (self, w, h) |
| 805 self.MyObject.label:SetSize (self:GetWidth()-40, 10) | 815 self.MyObject.label:SetSize (self:GetWidth()-40, 10) |
| 834 table.sort (t, function (t1, t2) return t1.label < t2.label end) | 844 table.sort (t, function (t1, t2) return t1.label < t2.label end) |
| 835 return t | 845 return t |
| 836 end | 846 end |
| 837 | 847 |
| 838 ------------------------------------------------------------------------------------------------------------ | 848 ------------------------------------------------------------------------------------------------------------ |
| 849 function DropDownMetaFunctions:SetTemplate (template) | |
| 850 | |
| 851 if (template.width) then | |
| 852 self:SetWidth (template.width) | |
| 853 end | |
| 854 if (template.height) then | |
| 855 self:SetHeight (template.height) | |
| 856 end | |
| 857 | |
| 858 if (template.backdrop) then | |
| 859 self:SetBackdrop (template.backdrop) | |
| 860 end | |
| 861 if (template.backdropcolor) then | |
| 862 local r, g, b, a = DF:ParseColors (template.backdropcolor) | |
| 863 self:SetBackdropColor (r, g, b, a) | |
| 864 self.onleave_backdrop = {r, g, b, a} | |
| 865 end | |
| 866 if (template.backdropbordercolor) then | |
| 867 local r, g, b, a = DF:ParseColors (template.backdropbordercolor) | |
| 868 self:SetBackdropBorderColor (r, g, b, a) | |
| 869 self.onleave_backdrop_border_color = {r, g, b, a} | |
| 870 end | |
| 871 | |
| 872 if (template.onentercolor) then | |
| 873 local r, g, b, a = DF:ParseColors (template.onentercolor) | |
| 874 self.onenter_backdrop = {r, g, b, a} | |
| 875 end | |
| 876 | |
| 877 if (template.onleavecolor) then | |
| 878 local r, g, b, a = DF:ParseColors (template.onleavecolor) | |
| 879 self.onleave_backdrop = {r, g, b, a} | |
| 880 end | |
| 881 | |
| 882 if (template.onenterbordercolor) then | |
| 883 local r, g, b, a = DF:ParseColors (template.onenterbordercolor) | |
| 884 self.onenter_backdrop_border_color = {r, g, b, a} | |
| 885 end | |
| 886 | |
| 887 if (template.onleavebordercolor) then | |
| 888 local r, g, b, a = DF:ParseColors (template.onleavebordercolor) | |
| 889 self.onleave_backdrop_border_color = {r, g, b, a} | |
| 890 end | |
| 891 | |
| 892 end | |
| 893 | |
| 894 ------------------------------------------------------------------------------------------------------------ | |
| 839 --> object constructor | 895 --> object constructor |
| 840 | 896 |
| 841 function DF:CreateDropDown (parent, func, default, w, h, member, name) | 897 function DF:CreateDropDown (parent, func, default, w, h, member, name, template) |
| 842 return DF:NewDropDown (parent, parent, name, member, w, h, func, default) | 898 return DF:NewDropDown (parent, parent, name, member, w, h, func, default, template) |
| 843 end | 899 end |
| 844 | 900 |
| 845 function DF:NewDropDown (parent, container, name, member, w, h, func, default) | 901 function DF:NewDropDown (parent, container, name, member, w, h, func, default, template) |
| 846 | 902 |
| 847 if (not name) then | 903 if (not name) then |
| 848 name = "DetailsFrameworkDropDownNumber" .. DF.DropDownCounter | 904 name = "DetailsFrameworkDropDownNumber" .. DF.DropDownCounter |
| 849 DF.DropDownCounter = DF.DropDownCounter + 1 | 905 DF.DropDownCounter = DF.DropDownCounter + 1 |
| 850 | 906 |
| 957 if (not DropDownObject:Select (default)) then | 1013 if (not DropDownObject:Select (default)) then |
| 958 DropDownObject:Select (default, true) | 1014 DropDownObject:Select (default, true) |
| 959 end | 1015 end |
| 960 end | 1016 end |
| 961 | 1017 |
| 1018 if (template) then | |
| 1019 DropDownObject:SetTemplate (template) | |
| 1020 end | |
| 1021 | |
| 962 return DropDownObject | 1022 return DropDownObject |
| 963 | 1023 |
| 964 end | 1024 end |
