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

- framework update. - ToC Update.
author Tercio
date Tue, 19 Jul 2016 13:23:40 -0300
parents d1963bd45219
children a960d5372b0c
comparison
equal deleted inserted replaced
38:219f04e5ba55 39:7944c081e5b4
1 1
2 local dversion = 16 2 local dversion = 22
3 local major, minor = "DetailsFramework-1.0", dversion 3 local major, minor = "DetailsFramework-1.0", dversion
4 local DF, oldminor = LibStub:NewLibrary (major, minor) 4 local DF, oldminor = LibStub:NewLibrary (major, minor)
5 5
6 if (not DF) then 6 if (not DF) then
7 DetailsFrameworkCanLoad = false 7 DetailsFrameworkCanLoad = false
27 DF.SimplePanelCounter = DF.SimplePanelCounter or init_counter 27 DF.SimplePanelCounter = DF.SimplePanelCounter or init_counter
28 DF.ButtonCounter = DF.ButtonCounter or init_counter 28 DF.ButtonCounter = DF.ButtonCounter or init_counter
29 DF.SliderCounter = DF.SliderCounter or init_counter 29 DF.SliderCounter = DF.SliderCounter or init_counter
30 DF.SwitchCounter = DF.SwitchCounter or init_counter 30 DF.SwitchCounter = DF.SwitchCounter or init_counter
31 DF.SplitBarCounter = DF.SplitBarCounter or init_counter 31 DF.SplitBarCounter = DF.SplitBarCounter or init_counter
32
33 DF.FRAMELEVEL_OVERLAY = 750
34 DF.FRAMELEVEL_BACKGROUND = 150
32 35
33 DF.FrameWorkVersion = tostring (dversion) 36 DF.FrameWorkVersion = tostring (dversion)
34 function DF:PrintVersion() 37 function DF:PrintVersion()
35 print ("Details! Framework Version:", DF.FrameWorkVersion) 38 print ("Details! Framework Version:", DF.FrameWorkVersion)
36 end 39 end
102 "www_icons", 105 "www_icons",
103 "GetTemplate", 106 "GetTemplate",
104 "InstallTemplate", 107 "InstallTemplate",
105 "GetFrameworkFolder", 108 "GetFrameworkFolder",
106 "ShowPanicWarning", 109 "ShowPanicWarning",
110 "SetFrameworkDebugState",
111 "FindHighestParent",
112 "OpenInterfaceProfile",
107 } 113 }
108 114
109 DF.table = {} 115 DF.table = {}
110 116
111 function DF:GetFrameworkFolder() 117 function DF:GetFrameworkFolder()
112 return DF.folder 118 return DF.folder
119 end
120
121 function DF:SetFrameworkDebugState (state)
122 DF.debug = state
113 end 123 end
114 124
115 function DF:FadeFrame (frame, t) 125 function DF:FadeFrame (frame, t)
116 if (t == 0) then 126 if (t == 0) then
117 frame.hidden = false 127 frame.hidden = false
330 function DF:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc) 340 function DF:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc)
331 local FlashAnimation = frame:CreateAnimationGroup() 341 local FlashAnimation = frame:CreateAnimationGroup()
332 342
333 FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime 343 FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime
334 FlashAnimation.fadeOut:SetOrder (1) 344 FlashAnimation.fadeOut:SetOrder (1)
335 FlashAnimation.fadeOut:SetChange (1) 345 FlashAnimation.fadeOut:SetFromAlpha (0)
346 FlashAnimation.fadeOut:SetToAlpha (1)
336 347
337 FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime 348 FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime
338 FlashAnimation.fadeIn:SetOrder (2) 349 FlashAnimation.fadeIn:SetOrder (2)
339 FlashAnimation.fadeIn:SetChange (-1) 350 FlashAnimation.fadeIn:SetFromAlpha (1)
351 FlashAnimation.fadeIn:SetToAlpha (0)
340 352
341 frame.FlashAnimation = FlashAnimation 353 frame.FlashAnimation = FlashAnimation
342 FlashAnimation.frame = frame 354 FlashAnimation.frame = frame
343 FlashAnimation.onFinishFunc = onFinishFunc 355 FlashAnimation.onFinishFunc = onFinishFunc
344 356
471 end 483 end
472 484
473 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 485 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
474 --> menus 486 --> menus
475 487
488 local disable_on_combat = {}
489
476 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) 490 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)
477 491
478 if (not parent.widget_list) then 492 if (not parent.widget_list) then
479 DF:SetAsOptionsPanel (parent) 493 DF:SetAsOptionsPanel (parent)
480 end 494 end
485 499
486 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20) 500 height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20)
487 height = height*-1 501 height = height*-1
488 502
489 for index, widget_table in ipairs (menu) do 503 for index, widget_table in ipairs (menu) do
504
505 local widget_created
490 506
491 if (widget_table.type == "blank" or widget_table.type == "space") then 507 if (widget_table.type == "blank" or widget_table.type == "space") then
492 -- do nothing 508 -- do nothing
493 509
494 elseif (widget_table.type == "label" or widget_table.type == "text") then 510 elseif (widget_table.type == "label" or widget_table.type == "text") then
511 if (size > max_x) then 527 if (size > max_x) then
512 max_x = size 528 max_x = size
513 end 529 end
514 530
515 tinsert (parent.widget_list, dropdown) 531 tinsert (parent.widget_list, dropdown)
532 widget_created = dropdown
516 533
517 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then 534 elseif (widget_table.type == "toggle" or widget_table.type == "switch") then
518 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template) 535 local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template)
519 switch.tooltip = widget_table.desc 536 switch.tooltip = widget_table.desc
520 switch._get = widget_table.get 537 switch._get = widget_table.get
533 if (size > max_x) then 550 if (size > max_x) then
534 max_x = size 551 max_x = size
535 end 552 end
536 553
537 tinsert (parent.widget_list, switch) 554 tinsert (parent.widget_list, switch)
555 widget_created = switch
538 556
539 elseif (widget_table.type == "range" or widget_table.type == "slider") then 557 elseif (widget_table.type == "range" or widget_table.type == "slider") then
540 local is_decimanls = widget_table.usedecimals 558 local is_decimanls = widget_table.usedecimals
541 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) 559 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)
542 slider.tooltip = widget_table.desc 560 slider.tooltip = widget_table.desc
552 if (size > max_x) then 570 if (size > max_x) then
553 max_x = size 571 max_x = size
554 end 572 end
555 573
556 tinsert (parent.widget_list, slider) 574 tinsert (parent.widget_list, slider)
575 widget_created = slider
557 576
558 elseif (widget_table.type == "color" or widget_table.type == "color") then 577 elseif (widget_table.type == "color" or widget_table.type == "color") then
559 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template) 578 local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template)
560 colorpick.tooltip = widget_table.desc 579 colorpick.tooltip = widget_table.desc
561 colorpick._get = widget_table.get 580 colorpick._get = widget_table.get
576 if (size > max_x) then 595 if (size > max_x) then
577 max_x = size 596 max_x = size
578 end 597 end
579 598
580 tinsert (parent.widget_list, colorpick) 599 tinsert (parent.widget_list, colorpick)
600 widget_created = colorpick
581 601
582 elseif (widget_table.type == "execute" or widget_table.type == "button") then 602 elseif (widget_table.type == "execute" or widget_table.type == "button") then
583 603
584 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) 604 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)
585 if (not button_template) then 605 if (not button_template) then
594 if (size > max_x) then 614 if (size > max_x) then
595 max_x = size 615 max_x = size
596 end 616 end
597 617
598 tinsert (parent.widget_list, button) 618 tinsert (parent.widget_list, button)
599 619 widget_created = button
620
621 end
622
623 if (widget_table.nocombat) then
624 tinsert (disable_on_combat, widget_created)
600 end 625 end
601 626
602 if (widget_table.spacement) then 627 if (widget_table.spacement) then
603 cur_y = cur_y - 30 628 cur_y = cur_y - 30
604 else 629 else
605 cur_y = cur_y - 20 630 cur_y = cur_y - 20
606 end 631 end
607 632
608 if (cur_y < height) then 633 if (widget_table.type == "breakline" or cur_y < height) then
609 cur_y = y_offset 634 cur_y = y_offset
610 cur_x = cur_x + max_x + 30 635 cur_x = cur_x + max_x + 30
611
612 max_x = 0 636 max_x = 0
613 end 637 end
614 638
615 end 639 end
616 640
617 end 641 DF.RefreshUnsafeOptionsWidgets()
642
643 end
644
645 local lock_notsafe_widgets = function()
646 for _, widget in ipairs (disable_on_combat) do
647 widget:Disable()
648 end
649 end
650 local unlock_notsafe_widgets = function()
651 for _, widget in ipairs (disable_on_combat) do
652 widget:Enable()
653 end
654 end
655 function DF.RefreshUnsafeOptionsWidgets()
656 if (DF.PlayerHasCombatFlag) then
657 lock_notsafe_widgets()
658 else
659 unlock_notsafe_widgets()
660 end
661 end
662 DF.PlayerHasCombatFlag = false
663 local ProtectCombatFrame = CreateFrame ("frame")
664 ProtectCombatFrame:RegisterEvent ("PLAYER_REGEN_ENABLED")
665 ProtectCombatFrame:RegisterEvent ("PLAYER_REGEN_DISABLED")
666 ProtectCombatFrame:RegisterEvent ("PLAYER_ENTERING_WORLD")
667 ProtectCombatFrame:SetScript ("OnEvent", function (self, event)
668 if (event == "PLAYER_ENTERING_WORLD") then
669 if (InCombatLockdown()) then
670 DF.PlayerHasCombatFlag = true
671 else
672 DF.PlayerHasCombatFlag = false
673 end
674 DF.RefreshUnsafeOptionsWidgets()
675
676 elseif (event == "PLAYER_REGEN_ENABLED") then
677 DF.PlayerHasCombatFlag = false
678 DF.RefreshUnsafeOptionsWidgets()
679
680 elseif (event == "PLAYER_REGEN_DISABLED") then
681 DF.PlayerHasCombatFlag = true
682 DF.RefreshUnsafeOptionsWidgets()
683
684 end
685 end)
618 686
619 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 687 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
620 --> tutorials 688 --> tutorials
621 689
622 function DF:ShowTutorialAlertFrame (maintext, desctext, clickfunc) 690 function DF:ShowTutorialAlertFrame (maintext, desctext, clickfunc)
920 if (not parentName) then 988 if (not parentName) then
921 error ("Details! FrameWork: called $parent but parent was no name.", 2) 989 error ("Details! FrameWork: called $parent but parent was no name.", 2)
922 end 990 end
923 return parentName 991 return parentName
924 end 992 end
993
994 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
995 --> widget scripts and hooks
996
997 function DF:RunHooksForWidget (event, ...)
998 local hooks = self.HookList [event]
999
1000 if (not hooks) then
1001 print (self.widget:GetName(), "sem hook para", event)
1002 return
1003 end
1004
1005 for i, func in ipairs (hooks) do
1006 local success, canInterrupt = pcall (func, ...)
1007 if (not success) then
1008 error ("Details! Framework: " .. event .. " hook for " .. self:GetName() .. ": " .. canInterrupt)
1009 elseif (canInterrupt) then
1010 return true
1011 end
1012 end
1013 end
1014
1015 function DF:SetHook (hookType, func)
1016 if (self.HookList [hookType]) then
1017 if (type (func) == "function") then
1018 local isRemoval = false
1019 for i = #self.HookList [hookType], 1, -1 do
1020 if (self.HookList [hookType] [i] == func) then
1021 tremove (self.HookList [hookType], i)
1022 isRemoval = true
1023 break
1024 end
1025 end
1026 if (not isRemoval) then
1027 tinsert (self.HookList [hookType], func)
1028 end
1029 else
1030 if (DF.debug) then
1031 error ("Details! Framework: invalid function for widget " .. self.WidgetType .. ".")
1032 end
1033 end
1034 else
1035 if (DF.debug) then
1036 error ("Details! Framework: unknown hook type for widget " .. self.WidgetType .. ": '" .. hookType .. "'.")
1037 end
1038 end
1039 end
1040
1041 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1042 --> members
1043
1044 DF.GlobalWidgetControlNames = {
1045 textentry = "DF_TextEntryMetaFunctions",
1046 button = "DF_ButtonMetaFunctions",
1047 panel = "DF_PanelMetaFunctions",
1048 dropdown = "DF_DropdownMetaFunctions",
1049 label = "DF_LabelMetaFunctions",
1050 normal_bar = "DF_NormalBarMetaFunctions",
1051 image = "DF_ImageMetaFunctions",
1052 slider = "DF_SliderMetaFunctions",
1053 split_bar = "DF_SplitBarMetaFunctions",
1054 }
1055
1056 function DF:AddMemberForWidget (widgetName, memberType, memberName, func)
1057 if (DF.GlobalWidgetControlNames [widgetName]) then
1058 if (type (memberName) == "string" and (memberType == "SET" or memberType == "GET")) then
1059 if (func) then
1060 local widgetControlObject = _G [DF.GlobalWidgetControlNames [widgetName]]
1061
1062 if (memberType == "SET") then
1063 widgetControlObject ["SetMembers"] [memberName] = func
1064 elseif (memberType == "GET") then
1065 widgetControlObject ["GetMembers"] [memberName] = func
1066 end
1067 else
1068 if (DF.debug) then
1069 error ("Details! Framework: AddMemberForWidget invalid function.")
1070 end
1071 end
1072 else
1073 if (DF.debug) then
1074 error ("Details! Framework: AddMemberForWidget unknown memberName or memberType.")
1075 end
1076 end
1077 else
1078 if (DF.debug) then
1079 error ("Details! Framework: AddMemberForWidget unknown widget type: " .. (widgetName or "") .. ".")
1080 end
1081 end
1082 end
1083
1084 -----------------------------
1085
1086 function DF:OpenInterfaceProfile()
1087 InterfaceOptionsFrame_OpenToCategory (self.__name)
1088 InterfaceOptionsFrame_OpenToCategory (self.__name)
1089 for i = 1, 100 do
1090 local button = _G ["InterfaceOptionsFrameAddOnsButton" .. i]
1091 if (button) then
1092 local text = _G ["InterfaceOptionsFrameAddOnsButton" .. i .. "Text"]
1093 if (text) then
1094 text = text:GetText()
1095 if (text == self.__name) then
1096 local toggle = _G ["InterfaceOptionsFrameAddOnsButton" .. i .. "Toggle"]
1097 if (toggle) then
1098 if (toggle:GetNormalTexture():GetTexture():find ("PlusButton")) then
1099 --is minimized, need expand
1100 toggle:Click()
1101 _G ["InterfaceOptionsFrameAddOnsButton" .. i+1]:Click()
1102 elseif (toggle:GetNormalTexture():GetTexture():find ("MinusButton")) then
1103 --isn't minimized
1104 _G ["InterfaceOptionsFrameAddOnsButton" .. i+1]:Click()
1105 end
1106 end
1107 break
1108 end
1109 end
1110 else
1111 self:Msg ("Couldn't not find the profile panel.")
1112 break
1113 end
1114 end
1115 end
1116
1117 -----------------------------
1118 --safe copy from blizz api
1119 function DF:Mixin (object, ...)
1120 for i = 1, select("#", ...) do
1121 local mixin = select(i, ...);
1122 for k, v in pairs(mixin) do
1123 object[k] = v;
1124 end
1125 end
1126
1127 return object;
1128 end