Mercurial > wow > hansgar_and_franzok_assist
changeset 39:7944c081e5b4
- framework update.
- ToC Update.
| author | Tercio |
|---|---|
| date | Tue, 19 Jul 2016 13:23:40 -0300 |
| parents | 219f04e5ba55 |
| children | a960d5372b0c |
| files | Hansgar_And_Franzok_Assist.toc Libs/DF/button.lua Libs/DF/button.xml Libs/DF/cooltip.lua Libs/DF/dropdown.lua Libs/DF/dropdown.xml Libs/DF/fw.lua Libs/DF/label.lua Libs/DF/load.xml Libs/DF/normal_bar.lua Libs/DF/panel.lua Libs/DF/picture.lua Libs/DF/slider.lua Libs/DF/split_bar.lua Libs/DF/textentry.lua |
| diffstat | 15 files changed, 1496 insertions(+), 691 deletions(-) [+] |
line wrap: on
line diff
--- a/Hansgar_And_Franzok_Assist.toc Mon Jul 04 23:06:23 2016 -0300 +++ b/Hansgar_And_Franzok_Assist.toc Tue Jul 19 13:23:40 2016 -0300 @@ -1,4 +1,4 @@ -## Interface: 60200 +## Interface: 70000 ## Title: Hansgar And Franzok Assist ## Notes: Helps with Smart Stampers on Mythic during this encounter. ## SavedVariables: Hansgar_And_Franzok_DB
--- a/Libs/DF/button.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/button.lua Tue Jul 19 13:23:40 2016 -0300 @@ -16,7 +16,18 @@ local cleanfunction = function() end local APIButtonFunctions = false -local ButtonMetaFunctions = {} + +do + local metaPrototype = { + WidgetType = "button", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["button"]] = _G [DF.GlobalWidgetControlNames ["button"]] or metaPrototype +end + +local ButtonMetaFunctions = _G [DF.GlobalWidgetControlNames ["button"]] ------------------------------------------------------------------------------------------------------------ --> metatables @@ -75,26 +86,25 @@ return _rawget (_object, "is_locked") end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["text"] = gmember_text, - ["clickfunction"] = gmember_function, - ["texture"] = gmember_texture, - ["locked"] = gmember_locked, - ["fontcolor"] = gmember_textcolor, - ["fontface"] = gmember_textfont, - ["fontsize"] = gmember_textsize, - ["textcolor"] = gmember_textcolor, --alias - ["textfont"] = gmember_textfont, --alias - ["textsize"] = gmember_textsize --alias - } + ButtonMetaFunctions.GetMembers = ButtonMetaFunctions.GetMembers or {} + ButtonMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + ButtonMetaFunctions.GetMembers ["shown"] = gmember_shown + ButtonMetaFunctions.GetMembers ["width"] = gmember_width + ButtonMetaFunctions.GetMembers ["height"] = gmember_height + ButtonMetaFunctions.GetMembers ["text"] = gmember_text + ButtonMetaFunctions.GetMembers ["clickfunction"] = gmember_function + ButtonMetaFunctions.GetMembers ["texture"] = gmember_texture + ButtonMetaFunctions.GetMembers ["locked"] = gmember_locked + ButtonMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor + ButtonMetaFunctions.GetMembers ["fontface"] = gmember_textfont + ButtonMetaFunctions.GetMembers ["fontsize"] = gmember_textsize + ButtonMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias + ButtonMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias + ButtonMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias ButtonMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = ButtonMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -206,25 +216,24 @@ _object.capsule_textalign = "right" end end - - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["show"] = smember_show, - ["hide"] = smember_hide, - ["width"] = smember_width, - ["height"] = smember_height, - ["text"] = smember_text, - ["clickfunction"] = smember_function, - ["textcolor"] = smember_textcolor, - ["textfont"] = smember_textfont, - ["textsize"] = smember_textsize, - ["texture"] = smember_texture, - ["locked"] = smember_locked, - ["textalign"] = smember_textalign, - } + + ButtonMetaFunctions.SetMembers = ButtonMetaFunctions.SetMembers or {} + ButtonMetaFunctions.SetMembers ["tooltip"] = smember_tooltip + ButtonMetaFunctions.SetMembers ["show"] = smember_show + ButtonMetaFunctions.SetMembers ["hide"] = smember_hide + ButtonMetaFunctions.SetMembers ["width"] = smember_width + ButtonMetaFunctions.SetMembers ["height"] = smember_height + ButtonMetaFunctions.SetMembers ["text"] = smember_text + ButtonMetaFunctions.SetMembers ["clickfunction"] = smember_function + ButtonMetaFunctions.SetMembers ["textcolor"] = smember_textcolor + ButtonMetaFunctions.SetMembers ["textfont"] = smember_textfont + ButtonMetaFunctions.SetMembers ["textsize"] = smember_textsize + ButtonMetaFunctions.SetMembers ["texture"] = smember_texture + ButtonMetaFunctions.SetMembers ["locked"] = smember_locked + ButtonMetaFunctions.SetMembers ["textalign"] = smember_textalign ButtonMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = ButtonMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -473,15 +482,6 @@ return self.funcright() end ---> hooks - function ButtonMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - --> custom textures function ButtonMetaFunctions:InstallCustomTexture (texture, rect, coords, use_split, side_textures, side_textures2) @@ -587,6 +587,8 @@ local OnEnter = function (button) + local capsule = button.MyObject + if (button.textureTopLeft) then button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128) button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128) @@ -598,12 +600,10 @@ button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128) button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128) end - - if (button.MyObject.OnEnterHook) then - local interrupt = button.MyObject.OnEnterHook (button, button.MyObject) - if (interrupt) then - return - end + + local kill = capsule:RunHooksForWidget ("OnEnter", button, capsule) + if (kill) then + return end button.MyObject.is_mouse_over = true @@ -637,6 +637,8 @@ local OnLeave = function (button) + local capsule = button.MyObject + if (button.textureLeft and not button.MyObject.is_mouse_down) then button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128) button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128) @@ -648,12 +650,10 @@ button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128) button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128) end - - if (button.MyObject.OnLeaveHook) then - local interrupt = button.MyObject.OnLeaveHook (button, button.MyObject) - if (interrupt) then - return - end + + local kill = capsule:RunHooksForWidget ("OnLeave", button, capsule) + if (kill) then + return end button.MyObject.is_mouse_over = false @@ -682,27 +682,27 @@ end local OnHide = function (button) - if (button.MyObject.OnHideHook) then - local interrupt = button.MyObject.OnHideHook (button, button.MyObject) - if (interrupt) then - return - end + local capsule = button.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", button, capsule) + if (kill) then + return end end local OnShow = function (button) - if (button.MyObject.OnShowHook) then - local interrupt = button.MyObject.OnShowHook (button, button.MyObject) - if (interrupt) then - return - end + local capsule = button.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", button, capsule) + if (kill) then + return end end local OnMouseDown = function (button, buttontype) + local capsule = button.MyObject + if (not button:IsEnabled()) then return - end + end if (button.textureTopLeft) then button.textureLeft:SetTexCoord (0, 4/128, 72/128, 88/128) @@ -715,12 +715,10 @@ button.textureBottomLeft:SetTexCoord (0, 8/128, 88/128, 96/128) button.textureBottomRight:SetTexCoord (120/128, 1, 88/128, 96/128) end - - if (button.MyObject.OnMouseDownHook) then - local interrupt = button.MyObject.OnMouseDownHook (button, buttontype, button.MyObject) - if (interrupt) then - return - end + + local kill = capsule:RunHooksForWidget ("OnMouseDown", button, capsule) + if (kill) then + return end button.MyObject.is_mouse_down = true @@ -803,11 +801,10 @@ end end - if (button.MyObject.OnMouseUpHook) then - local interrupt = button.MyObject.OnMouseUpHook (button, buttontype, button.MyObject) - if (interrupt) then - return - end + local capsule = button.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseUp", button, capsule) + if (kill) then + return end button.MyObject.is_mouse_down = false @@ -957,20 +954,10 @@ end --> default members: - --> hooks - ButtonObject.OnEnterHook = nil - ButtonObject.OnLeaveHook = nil - ButtonObject.OnHideHook = nil - ButtonObject.OnShowHook = nil - ButtonObject.OnMouseDownHook = nil - ButtonObject.OnMouseUpHook = nil - --> misc ButtonObject.is_locked = true ButtonObject.container = container - ButtonObject.have_tooltip = nil ButtonObject.options = {OnGrab = false} - ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate") ButtonObject.widget = ButtonObject.button @@ -1006,12 +993,15 @@ ButtonObject.button.text:SetText (text) ButtonObject.button.text:SetPoint ("center", ButtonObject.button, "center") - + local text_width = ButtonObject.button.text:GetStringWidth() if (text_width > w-15 and ButtonObject.button.text:GetText() ~= "") then - if (not short_method) then + if (short_method == false) then --> if is false, do not use auto resize + --do nothing + elseif (not short_method) then --> if the value is omitted, use the default resize local new_width = text_width+15 ButtonObject.button:SetWidth (new_width) + elseif (short_method == 1) then local loop = true local textsize = 11 @@ -1051,6 +1041,15 @@ end --> hooks + ButtonObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnMouseDown = {}, + OnMouseUp = {}, + } + ButtonObject.button:SetScript ("OnEnter", OnEnter) ButtonObject.button:SetScript ("OnLeave", OnLeave) ButtonObject.button:SetScript ("OnHide", OnHide) @@ -1119,7 +1118,7 @@ --textura da cor local img = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, "color_texture", "$parentTex") - img:SetTexture (1, 1, 1) + img:SetColorTexture (1, 1, 1) img:SetPoint ("topleft", button.widget, "topleft", 1, -2) img:SetPoint ("bottomright", button.widget, "bottomright", -1, 1) img:SetDrawLayer ("background", 2)
--- a/Libs/DF/button.xml Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/button.xml Tue Jul 19 13:23:40 2016 -0300 @@ -19,7 +19,7 @@ </Layer> <Layer level="OVERLAY"> - <Texture name="$parent_TextureDisabled" setAllPoints="true" hidden="true" parentKey="texture_disabled" file = "Interface\AddOns\Details\images\button_disable_overlay"/> + <Texture name="$parent_TextureDisabled" setAllPoints="true" hidden="true" parentKey="texture_disabled" file = "Interface\Tooltips\UI-Tooltip-Background"/> </Layer> </Layers> @@ -28,6 +28,8 @@ <OnDisable> self.texture_disabled:Show() + self.texture_disabled:SetVertexColor (0, 0, 0) + self.texture_disabled:SetAlpha (.5) </OnDisable> <OnEnable>
--- a/Libs/DF/cooltip.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/cooltip.lua Tue Jul 19 13:23:40 2016 -0300 @@ -2493,7 +2493,7 @@ end --> check data integrity - if (type (iconTexture) ~= "string" and (type (iconTexture) ~= "table" or not iconTexture.GetObjectType or iconTexture:GetObjectType() ~= "Texture") ) then + if ( (type (iconTexture) ~= "string" and type (iconTexture) ~= "number") and (type (iconTexture) ~= "table" or not iconTexture.GetObjectType or iconTexture:GetObjectType() ~= "Texture") ) then return --> return error end @@ -3033,10 +3033,17 @@ --> all done CoolTip:ClearAllOptions() - local preset2_backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile = DF.folder .. "border_3", tile=true, - edgeSize = 16, tileSize = 64, insets = {left = 3, right = 3, top = 4, bottom = 4}} +-- local preset2_backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile = DF.folder .. "border_3", tile=true, +-- edgeSize = 16, tileSize = 64, insets = {left = 3, right = 3, top = 4, bottom = 4}} + local preset2_backdrop = {bgFile = DF.folder .. "background", edgeFile = [[Interface\Buttons\WHITE8X8]], tile = true, + edgeSize = 1, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}} + local default_backdrop_color = {0.09019, 0.09019, 0.18823, 0.8} + local default_backdropborder_color = {1, 1, 1, 1} + + local gray_table = {0.37, 0.37, 0.37, 0.95} local white_table = {1, 1, 1, 1} + local black_table = {0.2, 0.2, 0.2, 1} function CoolTip:Preset (number) self:Reset() @@ -3058,9 +3065,11 @@ self:SetOption ("ButtonsYMod", -4) self:SetOption ("YSpacingMod", -4) self:SetOption ("IgnoreButtonAutoHeight", true) - self:SetColor (1, 0.5, 0.5, 0.5, 0.5) - self:SetBackdrop (1, preset2_backdrop, nil, white_table) + --self:SetColor (1, 0.5, 0.5, 0.5, 0.5) + self:SetColor (1, 0.5, 0.5, 0.5, 0) + + self:SetBackdrop (1, preset2_backdrop, gray_table, black_table) end end
--- a/Libs/DF/dropdown.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/dropdown.lua Tue Jul 19 13:23:40 2016 -0300 @@ -16,7 +16,18 @@ local cleanfunction = function() end local APIDropDownFunctions = false -local DropDownMetaFunctions = {} + +do + local metaPrototype = { + WidgetType = "dropdown", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["dropdown"]] = _G [DF.GlobalWidgetControlNames ["dropdown"]] or metaPrototype +end + +local DropDownMetaFunctions = _G [DF.GlobalWidgetControlNames ["dropdown"]] ------------------------------------------------------------------------------------------------------------ --> metatables @@ -65,21 +76,20 @@ return _rawget (self, "realsizeH") end - local get_members_function_index = { - ["value"] = gmember_value, - ["text"] = gmember_text, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["menuwidth"] = gmember_menuwidth, - ["height"] = gmember_height, - ["menuheight"] = gmember_menuheight, - ["tooltip"] = gmember_tooltip, - ["func"] = gmember_function, - } + DropDownMetaFunctions.GetMembers = DropDownMetaFunctions.GetMembers or {} + DropDownMetaFunctions.GetMembers ["value"] = gmember_value + DropDownMetaFunctions.GetMembers ["text"] = gmember_text + DropDownMetaFunctions.GetMembers ["shown"] = gmember_shown + DropDownMetaFunctions.GetMembers ["width"] = gmember_width + DropDownMetaFunctions.GetMembers ["menuwidth"] = gmember_menuwidth + DropDownMetaFunctions.GetMembers ["height"] = gmember_height + DropDownMetaFunctions.GetMembers ["menuheight"] = gmember_menuheight + DropDownMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + DropDownMetaFunctions.GetMembers ["func"] = gmember_function DropDownMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = DropDownMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -135,19 +145,18 @@ _object:SetMenuSize (nil, _value) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["show"] = smember_show, - ["hide"] = smember_hide, - ["width"] = smember_width, - ["menuwidth"] = smember_menuwidth, - ["height"] = smember_height, - ["menuheight"] = smember_menuheight, - ["func"] = smember_function, - } + DropDownMetaFunctions.SetMembers = DropDownMetaFunctions.SetMembers or {} + DropDownMetaFunctions.SetMembers ["tooltip"] = smember_tooltip + DropDownMetaFunctions.SetMembers ["show"] = smember_show + DropDownMetaFunctions.SetMembers ["hide"] = smember_hide + DropDownMetaFunctions.SetMembers ["width"] = smember_width + DropDownMetaFunctions.SetMembers ["menuwidth"] = smember_menuwidth + DropDownMetaFunctions.SetMembers ["height"] = smember_height + DropDownMetaFunctions.SetMembers ["menuheight"] = smember_menuheight + DropDownMetaFunctions.SetMembers ["func"] = smember_function DropDownMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = DropDownMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -285,15 +294,6 @@ _rawset (self, "FixedValue", value) end ---> hooks - function DropDownMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - ------------------------------------------------------------------------------------------------------------ --> scripts @@ -752,11 +752,10 @@ function DetailsFrameworkDropDownOnEnter (self) - if (self.MyObject.OnEnterHook) then - local interrupt = self.MyObject.OnEnterHook (self) - if (interrupt) then - return - end + local capsule = self.MyObject + local kill = capsule:RunHooksForWidget ("OnEnter", self, capsule) + if (kill) then + return end if (self.MyObject.onenter_backdrop) then @@ -787,11 +786,10 @@ end function DetailsFrameworkDropDownOnLeave (self) - if (self.MyObject.OnLeaveHook) then - local interrupt = self.MyObject.OnLeaveHook (self) - if (interrupt) then - return - end + local capsule = self.MyObject + local kill = capsule:RunHooksForWidget ("OnLeave", self, capsule) + if (kill) then + return end if (self.MyObject.onleave_backdrop) then @@ -816,20 +814,18 @@ end function DetailsFrameworkDropDownOnShow (self) - if (self.MyObject and self.MyObject.OnShowHook) then - local interrupt = self.MyObject.OnShowHook (self) - if (interrupt) then - return - end + local capsule = self.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", self, capsule) + if (kill) then + return end end function DetailsFrameworkDropDownOnHide (self) - if (self.MyObject and self.MyObject.OnHideHook) then - local interrupt = self.MyObject.OnHideHook (self) - if (interrupt) then - return - end + local capsule = self.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", self, capsule) + if (kill) then + return end self.MyObject:Close() @@ -934,15 +930,8 @@ end --> default members: - --> hooks - DropDownObject.OnEnterHook = nil - DropDownObject.OnLeaveHook = nil - DropDownObject.OnHideHook = nil - DropDownObject.OnShowHook = nil - DropDownObject.OnMouseDownHook = nil --> misc DropDownObject.container = container - DropDownObject.have_tooltip = nil DropDownObject.dropdown = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownTemplate") DropDownObject.widget = DropDownObject.dropdown @@ -1002,11 +991,22 @@ DropDownObject:HideScroll() DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10) + DropDownObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + } + + DropDownObject.dropdown:SetScript ("OnShow", DetailsFrameworkDropDownOnShow) + DropDownObject.dropdown:SetScript ("OnHide", DetailsFrameworkDropDownOnHide) + DropDownObject.dropdown:SetScript ("OnEnter", DetailsFrameworkDropDownOnEnter) + DropDownObject.dropdown:SetScript ("OnLeave", DetailsFrameworkDropDownOnLeave) + --> setup class _setmetatable (DropDownObject, DropDownMetaFunctions) - + --> initialize first menu selected - if (type (default) == "string") then DropDownObject:Select (default) @@ -1020,6 +1020,6 @@ DropDownObject:SetTemplate (template) end - return DropDownObject + return DropDownObject end \ No newline at end of file
--- a/Libs/DF/dropdown.xml Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/dropdown.xml Tue Jul 19 13:23:40 2016 -0300 @@ -79,15 +79,15 @@ <Anchor point="TOPLEFT" relativeTo="$Parent" relativePoint="BOTTOMLEFT"/> </Anchors> - <Backdrop bgFile="Interface\AddOns\Details\images\background" edgeFile="Interface\AddOns\Details\images\border_3" tile="true"> + <Backdrop bgFile="Interface\FrameGeneral\UI-Background-Marble" edgeFile="Interface\Buttons\WHITE8X8" tile="true"> <EdgeSize> - <AbsValue val="16"/> + <AbsValue val="1"/> </EdgeSize> <TileSize> <AbsValue val="256"/> </TileSize> <BackgroundInsets> - <AbsInset left="4" right="4" top="4" bottom="5"/> + <AbsInset left="0" right="0" top="0" bottom="0"/> </BackgroundInsets> </Backdrop> @@ -96,7 +96,8 @@ DetailsFrameworkDropDownOptionsFrameOnHide (self); </OnHide> <OnLoad> - self:SetBackdropColor (0, 0, 0, 0.95); + self:SetBackdropColor (0, 0, 0, 0.92); + self:SetBackdropBorderColor (0, 0, 0, 1); </OnLoad> </Scripts> @@ -109,7 +110,7 @@ </Anchors> <ScrollChild> - <Frame name="$Parent_ScrollChild" frameStrata="DIALOG" parentKey="scrollchild"> + <Frame name="$Parent_ScrollChild" frameStrata="FULLSCREEN" parentKey="scrollchild"> <Size x="150" y="150"/> @@ -160,19 +161,19 @@ </OnLoad> <OnShow> - DetailsFrameworkDropDownOnShow (self); + <!--DetailsFrameworkDropDownOnShow (self);--> </OnShow> <OnHide> - DetailsFrameworkDropDownOnHide (self); + <!--DetailsFrameworkDropDownOnHide (self);--> </OnHide> <OnEnter> - DetailsFrameworkDropDownOnEnter (self); + <!--DetailsFrameworkDropDownOnEnter (self);--> </OnEnter> <OnLeave> - DetailsFrameworkDropDownOnLeave (self); + <!--DetailsFrameworkDropDownOnLeave (self);--> </OnLeave> <OnSizeChanged>
--- a/Libs/DF/fw.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/fw.lua Tue Jul 19 13:23:40 2016 -0300 @@ -1,5 +1,5 @@ -local dversion = 16 +local dversion = 22 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -30,6 +30,9 @@ DF.SwitchCounter = DF.SwitchCounter or init_counter DF.SplitBarCounter = DF.SplitBarCounter or init_counter +DF.FRAMELEVEL_OVERLAY = 750 +DF.FRAMELEVEL_BACKGROUND = 150 + DF.FrameWorkVersion = tostring (dversion) function DF:PrintVersion() print ("Details! Framework Version:", DF.FrameWorkVersion) @@ -104,6 +107,9 @@ "InstallTemplate", "GetFrameworkFolder", "ShowPanicWarning", + "SetFrameworkDebugState", + "FindHighestParent", + "OpenInterfaceProfile", } DF.table = {} @@ -112,6 +118,10 @@ return DF.folder end +function DF:SetFrameworkDebugState (state) + DF.debug = state +end + function DF:FadeFrame (frame, t) if (t == 0) then frame.hidden = false @@ -332,11 +342,13 @@ FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime FlashAnimation.fadeOut:SetOrder (1) - FlashAnimation.fadeOut:SetChange (1) + FlashAnimation.fadeOut:SetFromAlpha (0) + FlashAnimation.fadeOut:SetToAlpha (1) FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime FlashAnimation.fadeIn:SetOrder (2) - FlashAnimation.fadeIn:SetChange (-1) + FlashAnimation.fadeIn:SetFromAlpha (1) + FlashAnimation.fadeIn:SetToAlpha (0) frame.FlashAnimation = FlashAnimation FlashAnimation.frame = frame @@ -473,6 +485,8 @@ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --> menus + local disable_on_combat = {} + 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) if (not parent.widget_list) then @@ -488,6 +502,8 @@ for index, widget_table in ipairs (menu) do + local widget_created + if (widget_table.type == "blank" or widget_table.type == "space") then -- do nothing @@ -513,6 +529,7 @@ end tinsert (parent.widget_list, dropdown) + widget_created = dropdown elseif (widget_table.type == "toggle" or widget_table.type == "switch") then local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template) @@ -535,6 +552,7 @@ end tinsert (parent.widget_list, switch) + widget_created = switch elseif (widget_table.type == "range" or widget_table.type == "slider") then local is_decimanls = widget_table.usedecimals @@ -554,6 +572,7 @@ end tinsert (parent.widget_list, slider) + widget_created = slider elseif (widget_table.type == "color" or widget_table.type == "color") then local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template) @@ -578,6 +597,7 @@ end tinsert (parent.widget_list, colorpick) + widget_created = colorpick elseif (widget_table.type == "execute" or widget_table.type == "button") then @@ -596,8 +616,13 @@ end tinsert (parent.widget_list, button) + widget_created = button end + + if (widget_table.nocombat) then + tinsert (disable_on_combat, widget_created) + end if (widget_table.spacement) then cur_y = cur_y - 30 @@ -605,16 +630,59 @@ cur_y = cur_y - 20 end - if (cur_y < height) then + if (widget_table.type == "breakline" or cur_y < height) then cur_y = y_offset cur_x = cur_x + max_x + 30 - max_x = 0 end end + DF.RefreshUnsafeOptionsWidgets() + end + + local lock_notsafe_widgets = function() + for _, widget in ipairs (disable_on_combat) do + widget:Disable() + end + end + local unlock_notsafe_widgets = function() + for _, widget in ipairs (disable_on_combat) do + widget:Enable() + end + end + function DF.RefreshUnsafeOptionsWidgets() + if (DF.PlayerHasCombatFlag) then + lock_notsafe_widgets() + else + unlock_notsafe_widgets() + end + end + DF.PlayerHasCombatFlag = false + local ProtectCombatFrame = CreateFrame ("frame") + ProtectCombatFrame:RegisterEvent ("PLAYER_REGEN_ENABLED") + ProtectCombatFrame:RegisterEvent ("PLAYER_REGEN_DISABLED") + ProtectCombatFrame:RegisterEvent ("PLAYER_ENTERING_WORLD") + ProtectCombatFrame:SetScript ("OnEvent", function (self, event) + if (event == "PLAYER_ENTERING_WORLD") then + if (InCombatLockdown()) then + DF.PlayerHasCombatFlag = true + else + DF.PlayerHasCombatFlag = false + end + DF.RefreshUnsafeOptionsWidgets() + + elseif (event == "PLAYER_REGEN_ENABLED") then + DF.PlayerHasCombatFlag = false + DF.RefreshUnsafeOptionsWidgets() + + elseif (event == "PLAYER_REGEN_DISABLED") then + DF.PlayerHasCombatFlag = true + DF.RefreshUnsafeOptionsWidgets() + + end + end) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --> tutorials @@ -922,3 +990,139 @@ end return parentName end + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +--> widget scripts and hooks + +function DF:RunHooksForWidget (event, ...) + local hooks = self.HookList [event] + + if (not hooks) then + print (self.widget:GetName(), "sem hook para", event) + return + end + + for i, func in ipairs (hooks) do + local success, canInterrupt = pcall (func, ...) + if (not success) then + error ("Details! Framework: " .. event .. " hook for " .. self:GetName() .. ": " .. canInterrupt) + elseif (canInterrupt) then + return true + end + end +end + +function DF:SetHook (hookType, func) + if (self.HookList [hookType]) then + if (type (func) == "function") then + local isRemoval = false + for i = #self.HookList [hookType], 1, -1 do + if (self.HookList [hookType] [i] == func) then + tremove (self.HookList [hookType], i) + isRemoval = true + break + end + end + if (not isRemoval) then + tinsert (self.HookList [hookType], func) + end + else + if (DF.debug) then + error ("Details! Framework: invalid function for widget " .. self.WidgetType .. ".") + end + end + else + if (DF.debug) then + error ("Details! Framework: unknown hook type for widget " .. self.WidgetType .. ": '" .. hookType .. "'.") + end + end +end + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +--> members + +DF.GlobalWidgetControlNames = { + textentry = "DF_TextEntryMetaFunctions", + button = "DF_ButtonMetaFunctions", + panel = "DF_PanelMetaFunctions", + dropdown = "DF_DropdownMetaFunctions", + label = "DF_LabelMetaFunctions", + normal_bar = "DF_NormalBarMetaFunctions", + image = "DF_ImageMetaFunctions", + slider = "DF_SliderMetaFunctions", + split_bar = "DF_SplitBarMetaFunctions", +} + +function DF:AddMemberForWidget (widgetName, memberType, memberName, func) + if (DF.GlobalWidgetControlNames [widgetName]) then + if (type (memberName) == "string" and (memberType == "SET" or memberType == "GET")) then + if (func) then + local widgetControlObject = _G [DF.GlobalWidgetControlNames [widgetName]] + + if (memberType == "SET") then + widgetControlObject ["SetMembers"] [memberName] = func + elseif (memberType == "GET") then + widgetControlObject ["GetMembers"] [memberName] = func + end + else + if (DF.debug) then + error ("Details! Framework: AddMemberForWidget invalid function.") + end + end + else + if (DF.debug) then + error ("Details! Framework: AddMemberForWidget unknown memberName or memberType.") + end + end + else + if (DF.debug) then + error ("Details! Framework: AddMemberForWidget unknown widget type: " .. (widgetName or "") .. ".") + end + end +end + +----------------------------- + +function DF:OpenInterfaceProfile() + InterfaceOptionsFrame_OpenToCategory (self.__name) + InterfaceOptionsFrame_OpenToCategory (self.__name) + for i = 1, 100 do + local button = _G ["InterfaceOptionsFrameAddOnsButton" .. i] + if (button) then + local text = _G ["InterfaceOptionsFrameAddOnsButton" .. i .. "Text"] + if (text) then + text = text:GetText() + if (text == self.__name) then + local toggle = _G ["InterfaceOptionsFrameAddOnsButton" .. i .. "Toggle"] + if (toggle) then + if (toggle:GetNormalTexture():GetTexture():find ("PlusButton")) then + --is minimized, need expand + toggle:Click() + _G ["InterfaceOptionsFrameAddOnsButton" .. i+1]:Click() + elseif (toggle:GetNormalTexture():GetTexture():find ("MinusButton")) then + --isn't minimized + _G ["InterfaceOptionsFrameAddOnsButton" .. i+1]:Click() + end + end + break + end + end + else + self:Msg ("Couldn't not find the profile panel.") + break + end + end +end + +----------------------------- +--safe copy from blizz api +function DF:Mixin (object, ...) + for i = 1, select("#", ...) do + local mixin = select(i, ...); + for k, v in pairs(mixin) do + object[k] = v; + end + end + + return object; +end
--- a/Libs/DF/label.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/label.lua Tue Jul 19 13:23:40 2016 -0300 @@ -15,7 +15,18 @@ local cleanfunction = function() end local APILabelFunctions = false -local LabelMetaFunctions = {} + +do + local metaPrototype = { + WidgetType = "label", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["label"]] = _G [DF.GlobalWidgetControlNames ["label"]] or metaPrototype +end + +local LabelMetaFunctions = _G [DF.GlobalWidgetControlNames ["label"]] ------------------------------------------------------------------------------------------------------------ --> metatables @@ -58,23 +69,21 @@ return fontsize end - - local get_members_function_index = { - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["text"] = gmember_text, - ["fontcolor"] = gmember_textcolor, - ["fontface"] = gmember_textfont, - ["fontsize"] = gmember_textsize, - ["textcolor"] = gmember_textcolor, --alias - ["textfont"] = gmember_textfont, --alias - ["textsize"] = gmember_textsize --alias - } + LabelMetaFunctions.GetMembers = LabelMetaFunctions.GetMembers or {} + LabelMetaFunctions.GetMembers ["shown"] = gmember_shown + LabelMetaFunctions.GetMembers ["width"] = gmember_width + LabelMetaFunctions.GetMembers ["height"] = gmember_height + LabelMetaFunctions.GetMembers ["text"] = gmember_text + LabelMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor + LabelMetaFunctions.GetMembers ["fontface"] = gmember_textfont + LabelMetaFunctions.GetMembers ["fontsize"] = gmember_textsize + LabelMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias + LabelMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias + LabelMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias LabelMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = LabelMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -157,27 +166,26 @@ DF:SetFontOutline (_object.label, _value) end - local set_members_function_index = { - ["show"] = smember_show, - ["hide"] = smember_hide, - ["align"] = smember_textalign, - ["valign"] = smember_textvalign, - ["text"] = smember_text, - ["width"] = smember_width, - ["height"] = smember_height, - ["fontcolor"] = smember_textcolor, - ["color"] = smember_textcolor,--alias - ["fontface"] = smember_textfont, - ["fontsize"] = smember_textsize, - ["textcolor"] = smember_textcolor,--alias - ["textfont"] = smember_textfont,--alias - ["textsize"] = smember_textsize,--alias - ["shadow"] = smember_outline, - ["outline"] = smember_outline,--alias - } + LabelMetaFunctions.SetMembers = LabelMetaFunctions.SetMembers or {} + LabelMetaFunctions.SetMembers["show"] = smember_show + LabelMetaFunctions.SetMembers["hide"] = smember_hide + LabelMetaFunctions.SetMembers["align"] = smember_textalign + LabelMetaFunctions.SetMembers["valign"] = smember_textvalign + LabelMetaFunctions.SetMembers["text"] = smember_text + LabelMetaFunctions.SetMembers["width"] = smember_width + LabelMetaFunctions.SetMembers["height"] = smember_height + LabelMetaFunctions.SetMembers["fontcolor"] = smember_textcolor + LabelMetaFunctions.SetMembers["color"] = smember_textcolor--alias + LabelMetaFunctions.SetMembers["fontface"] = smember_textfont + LabelMetaFunctions.SetMembers["fontsize"] = smember_textsize + LabelMetaFunctions.SetMembers["textcolor"] = smember_textcolor--alias + LabelMetaFunctions.SetMembers["textfont"] = smember_textfont--alias + LabelMetaFunctions.SetMembers["textsize"] = smember_textsize--alias + LabelMetaFunctions.SetMembers["shadow"] = smember_outline + LabelMetaFunctions.SetMembers["outline"] = smember_outline--alias LabelMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = LabelMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -305,7 +313,8 @@ DF:SetFontSize (LabelObject.label, size) end - + LabelObject.HookList = { + } LabelObject.label:SetJustifyH ("LEFT")
--- a/Libs/DF/load.xml Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/load.xml Tue Jul 19 13:23:40 2016 -0300 @@ -8,6 +8,7 @@ <Script file="picture.lua"/> <Script file="slider.lua"/> <Script file="scrollbar.lua"/> + <Script file="math.lua"/> <Include file="tutorial_alert.xml"/> <Include file="split_bar.xml"/>
--- a/Libs/DF/normal_bar.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/normal_bar.lua Tue Jul 19 13:23:40 2016 -0300 @@ -15,9 +15,20 @@ local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") local cleanfunction = function() end -local BarMetaFunctions = {} local APIBarFunctions +do + local metaPrototype = { + WidgetType = "normal_bar", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["normal_bar"]] = _G [DF.GlobalWidgetControlNames ["normal_bar"]] or metaPrototype +end + +local BarMetaFunctions = _G [DF.GlobalWidgetControlNames ["normal_bar"]] + ------------------------------------------------------------------------------------------------------------ --> metatables @@ -111,28 +122,27 @@ return _object.textleft:GetTextColor() end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["value"] = gmember_value, - ["lefttext"] = gmember_ltext, - ["righttext"] = gmember_rtext, - ["color"] = gmember_color, - ["icon"] = gmember_icon, - ["texture"] = gmember_texture, - ["fontsize"] = gmember_textsize, - ["fontface"] = gmember_textfont, - ["fontcolor"] = gmember_textcolor, - ["textsize"] = gmember_textsize, --alias - ["textfont"] = gmember_textfont, --alias - ["textcolor"] = gmember_textcolor --alias - } + BarMetaFunctions.GetMembers = BarMetaFunctions.GetMembers or {} + BarMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + BarMetaFunctions.GetMembers ["shown"] = gmember_shown + BarMetaFunctions.GetMembers ["width"] = gmember_width + BarMetaFunctions.GetMembers ["height"] = gmember_height + BarMetaFunctions.GetMembers ["value"] = gmember_value + BarMetaFunctions.GetMembers ["lefttext"] = gmember_ltext + BarMetaFunctions.GetMembers ["righttext"] = gmember_rtext + BarMetaFunctions.GetMembers ["color"] = gmember_color + BarMetaFunctions.GetMembers ["icon"] = gmember_icon + BarMetaFunctions.GetMembers ["texture"] = gmember_texture + BarMetaFunctions.GetMembers ["fontsize"] = gmember_textsize + BarMetaFunctions.GetMembers ["fontface"] = gmember_textfont + BarMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor + BarMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias + BarMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias + BarMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias BarMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = BarMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -267,30 +277,29 @@ return DF:SetFontOutline (_object.textright, _value) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["shown"] = smember_shown, - ["width"] = smember_width, - ["height"] = smember_height, - ["value"] = smember_value, - ["righttext"] = smember_rtext, - ["lefttext"] = smember_ltext, - ["color"] = smember_color, - ["icon"] = smember_icon, - ["texture"] = smember_texture, - ["fontsize"] = smember_textsize, - ["fontface"] = smember_textfont, - ["fontcolor"] = smember_textcolor, - ["textsize"] = smember_textsize, --alias - ["textfont"] = smember_textfont, --alias - ["textcolor"] = smember_textcolor, --alias - ["shadow"] = smember_outline, - ["outline"] = smember_outline, --alias - } + BarMetaFunctions.SetMembers = BarMetaFunctions.SetMembers or {} + BarMetaFunctions.SetMembers["tooltip"] = smember_tooltip + BarMetaFunctions.SetMembers["shown"] = smember_shown + BarMetaFunctions.SetMembers["width"] = smember_width + BarMetaFunctions.SetMembers["height"] = smember_height + BarMetaFunctions.SetMembers["value"] = smember_value + BarMetaFunctions.SetMembers["righttext"] = smember_rtext + BarMetaFunctions.SetMembers["lefttext"] = smember_ltext + BarMetaFunctions.SetMembers["color"] = smember_color + BarMetaFunctions.SetMembers["icon"] = smember_icon + BarMetaFunctions.SetMembers["texture"] = smember_texture + BarMetaFunctions.SetMembers["fontsize"] = smember_textsize + BarMetaFunctions.SetMembers["fontface"] = smember_textfont + BarMetaFunctions.SetMembers["fontcolor"] = smember_textcolor + BarMetaFunctions.SetMembers["textsize"] = smember_textsize --alias + BarMetaFunctions.SetMembers["textfont"] = smember_textfont --alias + BarMetaFunctions.SetMembers["textcolor"] = smember_textcolor --alias + BarMetaFunctions.SetMembers["shadow"] = smember_outline + BarMetaFunctions.SetMembers["outline"] = smember_outline --alias BarMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = BarMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -420,24 +429,14 @@ self.container = container end ---> hooks - function BarMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - ------------------------------------------------------------------------------------------------------------ --> scripts local OnEnter = function (frame) - if (frame.MyObject.OnEnterHook) then - local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) + if (kill) then + return end frame.MyObject.background:Show() @@ -451,11 +450,10 @@ end local OnLeave = function (frame) - if (frame.MyObject.OnLeaveHook) then - local interrupt = frame.MyObject.OnLeaveHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) + if (kill) then + return end if (frame.MyObject.have_tooltip) then @@ -464,29 +462,26 @@ end local OnHide = function (frame) - if (frame.MyObject.OnHideHook) then - local interrupt = frame.MyObject.OnHideHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) + if (kill) then + return end end local OnShow = function (frame) - if (frame.MyObject.OnShowHook) then - local interrupt = frame.MyObject.OnShowHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) + if (kill) then + return end end local OnMouseDown = function (frame, button) - if (frame.MyObject.OnMouseDownHook) then - local interrupt = frame.MyObject.OnMouseDownHook (frame, button) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) + if (kill) then + return end if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then @@ -498,11 +493,10 @@ end local OnMouseUp = function (frame, button) - if (frame.MyObject.OnMouseUpHook) then - local interrupt = frame.MyObject.OnMouseUpHook (frame, button) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) + if (kill) then + return end if (frame.MyObject.container.isMoving) then @@ -674,18 +668,8 @@ h = h or 14 --> default members: - --> hooks - BarObject.OnEnterHook = nil - BarObject.OnLeaveHook = nil - BarObject.OnHideHook = nil - BarObject.OnShowHook = nil - BarObject.OnMouseDownHook = nil - BarObject.OnMouseUpHook = nil - BarObject.OnTimerEndHook = nil --> misc - BarObject.tooltip = nil BarObject.locked = false - BarObject.have_tooltip = nil BarObject.container = container @@ -729,6 +713,15 @@ BarObject.div_timer = _G [name .. "_sparkTimer"] --> hooks + BarObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnMouseDown = {}, + OnMouseUp = {}, + } + BarObject.statusbar:SetScript ("OnEnter", OnEnter) BarObject.statusbar:SetScript ("OnLeave", OnLeave) BarObject.statusbar:SetScript ("OnHide", OnHide)
--- a/Libs/DF/panel.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/panel.lua Tue Jul 19 13:23:40 2016 -0300 @@ -15,9 +15,20 @@ local loadstring = loadstring --> lua local local cleanfunction = function() end -local PanelMetaFunctions = {} local APIFrameFunctions +do + local metaPrototype = { + WidgetType = "panel", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype +end + +local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]] + ------------------------------------------------------------------------------------------------------------ --> metatables @@ -58,19 +69,18 @@ return _rawget (_object, "is_locked") end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["color"] = gmember_color, - ["backdrop"] = gmember_backdrop, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["locked"] = gmember_locked, - } + PanelMetaFunctions.GetMembers = PanelMetaFunctions.GetMembers or {} + PanelMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + PanelMetaFunctions.GetMembers ["shown"] = gmember_shown + PanelMetaFunctions.GetMembers ["color"] = gmember_color + PanelMetaFunctions.GetMembers ["backdrop"] = gmember_backdrop + PanelMetaFunctions.GetMembers ["width"] = gmember_width + PanelMetaFunctions.GetMembers ["height"] = gmember_height + PanelMetaFunctions.GetMembers ["locked"] = gmember_locked PanelMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = PanelMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -140,20 +150,19 @@ return _rawset (_object, "rightButtonClose", _value) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["show"] = smember_show, - ["hide"] = smember_hide, - ["color"] = smember_color, - ["backdrop"] = smember_backdrop, - ["width"] = smember_width, - ["height"] = smember_height, - ["locked"] = smember_locked, - ["close_with_right"] = smember_right_close, - } - + PanelMetaFunctions.SetMembers = PanelMetaFunctions.SetMembers or {} + PanelMetaFunctions.SetMembers["tooltip"] = smember_tooltip + PanelMetaFunctions.SetMembers["show"] = smember_show + PanelMetaFunctions.SetMembers["hide"] = smember_hide + PanelMetaFunctions.SetMembers["color"] = smember_color + PanelMetaFunctions.SetMembers["backdrop"] = smember_backdrop + PanelMetaFunctions.SetMembers["width"] = smember_width + PanelMetaFunctions.SetMembers["height"] = smember_height + PanelMetaFunctions.SetMembers["locked"] = smember_locked + PanelMetaFunctions.SetMembers["close_with_right"] = smember_right_close + PanelMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = PanelMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -309,24 +318,14 @@ end end ---> hooks - function PanelMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - ------------------------------------------------------------------------------------------------------------ --> scripts local OnEnter = function (frame) - if (frame.MyObject.OnEnterHook) then - local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) + if (kill) then + return end if (frame.MyObject.have_tooltip) then @@ -340,11 +339,10 @@ end local OnLeave = function (frame) - if (frame.MyObject.OnLeaveHook) then - local interrupt = frame.MyObject.OnLeaveHook (frame, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) + if (kill) then + return end if (frame.MyObject.have_tooltip) then @@ -354,29 +352,26 @@ end local OnHide = function (frame) - if (frame.MyObject.OnHideHook) then - local interrupt = frame.MyObject.OnHideHook (frame, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) + if (kill) then + return end end local OnShow = function (frame) - if (frame.MyObject.OnShowHook) then - local interrupt = frame.MyObject.OnShowHook (frame, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) + if (kill) then + return end end local OnMouseDown = function (frame, button) - if (frame.MyObject.OnMouseDownHook) then - local interrupt = frame.MyObject.OnMouseDownHook (frame, button, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) + if (kill) then + return end if (frame.MyObject.container == UIParent) then @@ -396,11 +391,10 @@ end local OnMouseUp = function (frame, button) - if (frame.MyObject.OnMouseUpHook) then - local interrupt = frame.MyObject.OnMouseUpHook (frame, button, frame.MyObject) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) + if (kill) then + return end if (button == "RightButton" and frame.MyObject.rightButtonClose) then @@ -456,15 +450,7 @@ container = container.widget end - --> default members: - --> hooks - PanelObject.OnEnterHook = nil - PanelObject.OnLeaveHook = nil - PanelObject.OnHideHook = nil - PanelObject.OnShowHook = nil - PanelObject.OnMouseDownHook = nil - PanelObject.OnMouseUpHook = nil --> misc PanelObject.is_locked = true PanelObject.container = container @@ -491,6 +477,15 @@ PanelObject.frame.MyObject = PanelObject + PanelObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnMouseDown = {}, + OnMouseUp = {}, + } + --> hooks PanelObject.frame:SetScript ("OnEnter", OnEnter) PanelObject.frame:SetScript ("OnLeave", OnLeave) @@ -968,8 +963,13 @@ iconwidget.line = index iconwidget.index = real_index - local result = results [index]:gsub (".-%\\", "") - iconwidget._icon.texture = results [index] + --print (index, results [index]) + if (type (results [index]) == "string") then + local result = results [index]:gsub (".-%\\", "") + iconwidget._icon.texture = results [index] + else + iconwidget._icon:SetTexture (results [index]) + end iconwidget:Show() end @@ -1494,8 +1494,27 @@ local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9} local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1} +function DF:CreateScaleBar (frame, config) + 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")) + scaleBar:SetPoint ("right", frame.Close, "left", -2, 0) + scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) + scaleBar.OnValueChanged = function (_, _, value) + config.scale = value + if (not scaleBar.IsValueChanging) then + frame:SetScale (config.scale) + end + end + scaleBar:SetHook ("OnMouseUp", function() + frame:SetScale (config.scale) + end) +end + local no_options = {} -function DF:CreateSimplePanel (parent, w, h, title, name, panel_options) +function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db) + + if (db and name and not db [name]) then + db [name] = {scale = 1} + end if (not name) then name = "DetailsFrameworkSimplePanel" .. DF.SimplePanelCounter @@ -1533,6 +1552,7 @@ f.TitleBar = title_bar local close = CreateFrame ("button", name and name .. "CloseButton", title_bar) + close:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) close:SetSize (16, 16) close:SetNormalTexture (DF.folder .. "icons") close:SetHighlightTexture (DF.folder .. "icons") @@ -1549,6 +1569,11 @@ title_string:SetText (title or "") f.Title = title_string + if (panel_options.UseScaleBar and db [name]) then + DF:CreateScaleBar (f, db [name]) + f:SetScale (db [name].scale) + end + f.Title:SetPoint ("center", title_bar, "center") f.Close:SetPoint ("right", title_bar, "right", -2, 0) @@ -2477,7 +2502,7 @@ thisbox.type = type thisbox.index = number - thisbox.box:SetTexture (unpack (color)) + thisbox.box:SetColorTexture (unpack (color)) thisbox.text:SetText (name) thisbox.check:Show() @@ -2519,7 +2544,7 @@ this_block:SetWidth (pixel*5) end - this_block:SetTexture (r, g, b, 0.25) + this_block:SetColorTexture (r, g, b, 0.25) this_block:Show() index = index + 1 @@ -2831,7 +2856,7 @@ title:SetPoint ("topleft", f, "topleft", 110, -13) local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture") - bottom_texture:SetTexture (0, 0, 0, .6) + bottom_texture:SetColorTexture (0, 0, 0, .6) bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7) bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7) @@ -2850,7 +2875,7 @@ local line = f:CreateTexture (nil, "border") line:SetSize (1, h-45) - line:SetTexture (1, 1, 1, .1) + line:SetColorTexture (1, 1, 1, .1) line:SetPoint ("bottomleft", time, "topright", 0, -10) line:Hide() time.line = line @@ -2882,7 +2907,7 @@ --div lines for i = 1, 8, 1 do local line = g:CreateTexture (nil, "overlay") - line:SetTexture (1, 1, 1, .2) + line:SetColorTexture (1, 1, 1, .2) line:SetWidth (670) line:SetHeight (1.1) @@ -2966,7 +2991,7 @@ t:SetWidth (1) t:SetPoint ("topright", f, "topright") t:SetPoint ("bottomright", f, "bottomright") - t:SetTexture (1, 1, 1, .1) + t:SetColorTexture (1, 1, 1, .1) f.grid = t local b = f:CreateTexture (nil, "overlay") @@ -3080,4 +3105,235 @@ f._maxlines = floor (f:GetWidth() / f._linewidth) return f -end \ No newline at end of file +end + + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +-- ~buttoncontainer + +function DF:CreateButtonContainer (parent, name) + local f = CreateFrame ("frame", name, parent) +-- f. +end + + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +--> options tabs and buttons -dot + +function DF:FindHighestParent (self) + local f + if (self:GetParent() == UIParent) then + f = self + end + if (not f) then + f = self + for i = 1, 6 do + local parent = f:GetParent() + if (parent == UIParent) then + break + else + f = parent + end + end + end + + return f +end + +DF.TabContainerFunctions = {} + +local button_tab_template = DF.table.copy ({}, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")) +button_tab_template.backdropbordercolor = nil + +DF.TabContainerFunctions.CreateUnderlineGlow = function (button) + local selectedGlow = button:CreateTexture (nil, "background", -4) + selectedGlow:SetPoint ("topleft", button.widget, "bottomleft", -7, 0) + selectedGlow:SetPoint ("topright", button.widget, "bottomright", 7, 0) + selectedGlow:SetTexture ([[Interface\BUTTONS\UI-Panel-Button-Glow]]) + selectedGlow:SetTexCoord (0, 95/128, 30/64, 38/64) + selectedGlow:SetBlendMode ("ADD") + selectedGlow:SetHeight (8) + selectedGlow:SetAlpha (.75) + selectedGlow:Hide() + button.selectedUnderlineGlow = selectedGlow +end + +DF.TabContainerFunctions.OnMouseDown = function (self, button) + --> search for UIParent + local f = DF:FindHighestParent (self) + local container = self:GetParent() + + if (button == "LeftButton") then + if (not f.IsMoving and f:IsMovable()) then + f:StartMoving() + f.IsMoving = true + end + elseif (button == "RightButton") then + if (not f.IsMoving and container.IsContainer) then + if (self.IsFrontPage) then + if (container.CanCloseWithRightClick) then + if (f.CloseFunction) then + f:CloseFunction() + else + f:Hide() + end + end + else + --goes back to front page + DF.TabContainerFunctions.SelectIndex (self, _, 1) + end + end + end +end + +DF.TabContainerFunctions.OnMouseUp = function (self, button) + local f = DF:FindHighestParent (self) + if (f.IsMoving) then + f:StopMovingOrSizing() + f.IsMoving = false + end +end + +DF.TabContainerFunctions.SelectIndex = function (self, fixedParam, menuIndex) + local mainFrame = self.AllFrames and self or self.mainFrame or self:GetParent() + + for i = 1, #mainFrame.AllFrames do + mainFrame.AllFrames[i]:Hide() + if (mainFrame.ButtonNotSelectedBorderColor) then + mainFrame.AllButtons[i]:SetBackdropBorderColor (unpack (mainFrame.ButtonNotSelectedBorderColor)) + end + if (mainFrame.AllButtons[i].selectedUnderlineGlow) then + mainFrame.AllButtons[i].selectedUnderlineGlow:Hide() + end + end + + mainFrame.AllFrames[menuIndex]:Show() + if (mainFrame.ButtonSelectedBorderColor) then + mainFrame.AllButtons[menuIndex]:SetBackdropBorderColor (unpack (mainFrame.ButtonSelectedBorderColor)) + end + if (mainFrame.AllButtons[menuIndex].selectedUnderlineGlow) then + mainFrame.AllButtons[menuIndex].selectedUnderlineGlow:Show() + end + mainFrame.CurrentIndex = menuIndex +end + +DF.TabContainerFunctions.SetIndex = function (self, index) + self.CurrentIndex = index +end + +local tab_container_on_show = function (self) + local index = self.CurrentIndex + self.SelectIndex (self.AllButtons[index], nil, index) +end + +function DF:CreateTabContainer (parent, title, frame_name, frame_list, options_table) + + local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE") + local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") + local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE") + local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE") + local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE") + + options_table = options_table or {} + local frame_width = parent:GetWidth() + local frame_height = parent:GetHeight() + local y_offset = options_table.y_offset or 0 + local button_width = options_table.button_width or 160 + local button_height = options_table.button_height or 20 + local button_anchor_x = options_table.button_x or 230 + local button_anchor_y = options_table.button_y or -32 + local button_text_size = options_table.button_text_size or 10 + + local mainFrame = CreateFrame ("frame", frame_name, parent.widget or parent) + mainFrame:SetAllPoints() + DF:Mixin (mainFrame, DF.TabContainerFunctions) + + local mainTitle = DF:CreateLabel (mainFrame, title, 24, "white") + mainTitle:SetPoint ("topleft", mainFrame, "topleft", 10, -30 + y_offset) + + mainFrame:SetFrameLevel (200) + + mainFrame.AllFrames = {} + mainFrame.AllButtons = {} + mainFrame.CurrentIndex = 1 + mainFrame.IsContainer = true + mainFrame.ButtonSelectedBorderColor = options_table.button_selected_border_color or {1, 1, 0, 1} + mainFrame.ButtonNotSelectedBorderColor = options_table.button_border_color or {0, 0, 0, 0} + + if (options_table.right_click_interact ~= nil) then + mainFrame.CanCloseWithRightClick = options_table.right_click_interact + else + mainFrame.CanCloseWithRightClick = true + end + + for i, frame in ipairs (frame_list) do + local f = CreateFrame ("frame", "$parent" .. frame.name, mainFrame) + f:SetAllPoints() + f:SetFrameLevel (210) + f:Hide() + + local title = DF:CreateLabel (f, frame.title, 16, "silver") + title:SetPoint ("topleft", mainTitle, "bottomleft", 0, 0) + + local tabButton = DF:CreateButton (mainFrame, DF.TabContainerFunctions.SelectIndex, button_width, button_height, frame.title, i, nil, nil, nil, nil, false, button_tab_template) + tabButton:SetFrameLevel (220) + tabButton.textsize = button_text_size + tabButton.mainFrame = mainFrame + DF.TabContainerFunctions.CreateUnderlineGlow (tabButton) + + if (i == 1) then + local right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray") + right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) + f.IsFrontPage = true + else + local right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray") + right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) + end + + f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown) + f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp) + + tinsert (mainFrame.AllFrames, f) + tinsert (mainFrame.AllButtons, tabButton) + end + + --order buttons + local x = button_anchor_x + local y = button_anchor_y + local space_for_buttons = frame_width - (#frame_list*3) - button_anchor_x + local amount_buttons_per_row = floor (space_for_buttons / button_width) + local last_button = mainFrame.AllButtons[1] + + mainFrame.AllButtons[1]:SetPoint ("topleft", mainTitle, "topleft", x, y) + x = x + button_width + 2 + + for i = 2, #mainFrame.AllButtons do + local button = mainFrame.AllButtons [i] + button:SetPoint ("topleft", mainTitle, "topleft", x, y) + x = x + button_width + 2 + + if (i % amount_buttons_per_row == 0) then + x = button_anchor_x + y = y - button_height - 1 + end + end + + --> when show the frame, reset to the current internal index + mainFrame:SetScript ("OnShow", tab_container_on_show) + --> select the first frame + mainFrame.SelectIndex (mainFrame.AllButtons[1], nil, 1) + + return mainFrame +end + + + + + + + + + + + +
--- a/Libs/DF/picture.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/picture.lua Tue Jul 19 13:23:40 2016 -0300 @@ -15,7 +15,18 @@ local cleanfunction = function() end local APIImageFunctions = false -local ImageMetaFunctions = {} + +do + local metaPrototype = { + WidgetType = "image", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["image"]] = _G [DF.GlobalWidgetControlNames ["image"]] or metaPrototype +end + +local ImageMetaFunctions = _G [DF.GlobalWidgetControlNames ["image"]] ------------------------------------------------------------------------------------------------------------ --> metatables @@ -48,17 +59,16 @@ return _object.image:GetAlpha() end - local get_members_function_index = { - ["shown"] = gmember_shown, - ["alpha"] = gmember_alpha, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["texture"] = gmember_texture, - } - + ImageMetaFunctions.GetMembers = ImageMetaFunctions.GetMembers or {} + ImageMetaFunctions.GetMembers ["shown"] = gmember_shown + ImageMetaFunctions.GetMembers ["alpha"] = gmember_alpha + ImageMetaFunctions.GetMembers ["width"] = gmember_width + ImageMetaFunctions.GetMembers ["height"] = gmember_height + ImageMetaFunctions.GetMembers ["texture"] = gmember_texture + ImageMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = ImageMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -146,20 +156,19 @@ end end - local set_members_function_index = { - ["show"] = smember_show, - ["hide"] = smember_hide, - ["alpha"] = smember_alpha, - ["width"] = smember_width, - ["height"] = smember_height, - ["texture"] = smember_texture, - ["texcoord"] = smember_texcoord, - ["color"] = smember_color, - ["blackwhite"] = smember_desaturated, - } - + ImageMetaFunctions.SetMembers = ImageMetaFunctions.SetMembers or {} + ImageMetaFunctions.SetMembers ["show"] = smember_show + ImageMetaFunctions.SetMembers ["hide"] = smember_hide + ImageMetaFunctions.SetMembers ["alpha"] = smember_alpha + ImageMetaFunctions.SetMembers ["width"] = smember_width + ImageMetaFunctions.SetMembers ["height"] = smember_height + ImageMetaFunctions.SetMembers ["texture"] = smember_texture + ImageMetaFunctions.SetMembers ["texcoord"] = smember_texcoord + ImageMetaFunctions.SetMembers ["color"] = smember_color + ImageMetaFunctions.SetMembers ["blackwhite"] = smember_desaturated + ImageMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = ImageMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -280,6 +289,9 @@ ImageObject.image:SetTexCoord (unpack (coords)) end + ImageObject.HookList = { + } + setmetatable (ImageObject, ImageMetaFunctions) return ImageObject
--- a/Libs/DF/slider.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/slider.lua Tue Jul 19 13:23:40 2016 -0300 @@ -17,7 +17,18 @@ local cleanfunction = function() end local APISliderFunctions = false -DFSliderMetaFunctions = DFSliderMetaFunctions or {} + +do + local metaPrototype = { + WidgetType = "slider", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["slider"]] = _G [DF.GlobalWidgetControlNames ["slider"]] or metaPrototype +end + +local DFSliderMetaFunctions = _G [DF.GlobalWidgetControlNames ["slider"]] ------------------------------------------------------------------------------------------------------------ --> metatables @@ -87,19 +98,18 @@ return _object() end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["locked"] = gmember_locked, - ["fractional"] = gmember_fractional, - ["value"] = gmember_value, - } + DFSliderMetaFunctions.GetMembers = DFSliderMetaFunctions.GetMembers or {} + DFSliderMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + DFSliderMetaFunctions.GetMembers ["shown"] = gmember_shown + DFSliderMetaFunctions.GetMembers ["width"] = gmember_width + DFSliderMetaFunctions.GetMembers ["height"] = gmember_height + DFSliderMetaFunctions.GetMembers ["locked"] = gmember_locked + DFSliderMetaFunctions.GetMembers ["fractional"] = gmember_fractional + DFSliderMetaFunctions.GetMembers ["value"] = gmember_value DFSliderMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = DFSliderMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -163,20 +173,19 @@ _object (_value) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["show"] = smember_show, - ["hide"] = smember_hide, - ["backdrop"] = smember_backdrop, - ["width"] = smember_width, - ["height"] = smember_height, - ["locked"] = smember_locked, - ["fractional"] = smember_fractional, - ["value"] = smember_value, - } + DFSliderMetaFunctions.SetMembers = DFSliderMetaFunctions.SetMembers or {} + DFSliderMetaFunctions.SetMembers ["tooltip"] = smember_tooltip + DFSliderMetaFunctions.SetMembers ["show"] = smember_show + DFSliderMetaFunctions.SetMembers ["hide"] = smember_hide + DFSliderMetaFunctions.SetMembers ["backdrop"] = smember_backdrop + DFSliderMetaFunctions.SetMembers ["width"] = smember_width + DFSliderMetaFunctions.SetMembers ["height"] = smember_height + DFSliderMetaFunctions.SetMembers ["locked"] = smember_locked + DFSliderMetaFunctions.SetMembers ["fractional"] = smember_fractional + DFSliderMetaFunctions.SetMembers ["value"] = smember_value DFSliderMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = DFSliderMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -324,16 +333,6 @@ return _rawset (self, "lockdown", true) end - --print ("iskar disable:", DFSliderMetaFunctions.Disable) - ---> hooks - function DFSliderMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end ------------------------------------------------------------------------------------------------------------ --> scripts @@ -346,11 +345,10 @@ DetailsFrameworkSliderButtons1:ShowMe (slider) - if (slider.MyObject.OnEnterHook) then - local interrupt = slider.MyObject.OnEnterHook (slider) - if (interrupt) then - return - end + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnEnter", slider, capsule) + if (kill) then + return end slider.thumb:SetAlpha (1) @@ -379,11 +377,10 @@ DetailsFrameworkSliderButtons1:PrepareToHide() - if (slider.MyObject.OnLeaveHook) then - local interrupt = slider.MyObject.OnLeaveHook (slider) - if (interrupt) then - return - end + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnLeave", slider, capsule) + if (kill) then + return end slider.thumb:SetAlpha (.7) @@ -435,6 +432,8 @@ local button_plus = CreateFrame ("button", "DetailsFrameworkSliderButtonsPlusButton", f) local button_minor = CreateFrame ("button", "DetailsFrameworkSliderButtonsMinorButton", f) + button_plus:SetFrameStrata (f:GetFrameStrata()) + button_minor:SetFrameStrata (f:GetFrameStrata()) button_plus:SetScript ("OnEnter", function (self) if (f.is_going_hide) then @@ -650,25 +649,34 @@ end local OnMouseDown = function (slider, button) + slider.MyObject.IsValueChanging = true + + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseDown", slider, button, capsule) + if (kill) then + return + end + if (button == "RightButton") then slider.MyObject:TypeValue() end end local OnMouseUp = function (slider, button) - --if (button == "RightButton") then - -- if (slider.MyObject.typing_value) then - -- slider.MyObject:SetValue (slider.MyObject.previous_value [2]) - -- end - --end + slider.MyObject.IsValueChanging = nil + + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseUp", slider, button, capsule) + if (kill) then + return + end end local OnHide = function (slider) - if (slider.MyObject.OnHideHook) then - local interrupt = slider.MyObject.OnHideHook (slider) - if (interrupt) then - return - end + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", slider, capsule) + if (kill) then + return end if (slider.MyObject.typing_value) then @@ -679,11 +687,10 @@ end local OnShow = function (slider) - if (slider.MyObject.OnShowHook) then - local interrupt = slider.MyObject.OnShowHook (slider) - if (interrupt) then - return - end + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", slider, capsule) + if (kill) then + return end end @@ -707,13 +714,16 @@ table_insert (slider.MyObject.previous_value, 1, amt) table_remove (slider.MyObject.previous_value, 4) - if (slider.MyObject.OnValueChangeHook) then - local interrupt = slider.MyObject.OnValueChangeHook (slider, slider.MyObject.FixedValue, amt) - if (interrupt) then - return - end + local capsule = slider.MyObject + local kill = capsule:RunHooksForWidget ("OnValueChanged", slider, capsule.FixedValue, amt, capsule) + if (kill) then + return end - + local kill = capsule:RunHooksForWidget ("OnValueChange", slider, capsule.FixedValue, amt, capsule) + if (kill) then + return + end + if (slider.MyObject.OnValueChanged) then slider.MyObject.OnValueChanged (slider, slider.MyObject.FixedValue, amt) end @@ -1084,17 +1094,8 @@ h = h or 19 --> default members: - --> hooks - SliderObject.OnEnterHook = nil - SliderObject.OnLeaveHook = nil - SliderObject.OnHideHook = nil - SliderObject.OnShowHook = nil - SliderObject.OnValueChangeHook = nil - --> misc SliderObject.lockdown = false SliderObject.container = container - SliderObject.have_tooltip = nil - SliderObject.FixedValue = nil SliderObject.useDecimals = isDecemal or false SliderObject.slider = CreateFrame ("slider", name, parent) @@ -1124,6 +1125,7 @@ SliderObject.slider:SetBackdrop ({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8}) SliderObject.slider:SetBackdropColor (0.9, 0.7, 0.7, 1.0) + --SliderObject.slider:SetBackdropColor (0, 0, 0, 1) SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork") SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob") @@ -1156,15 +1158,26 @@ SliderObject.previous_value = {defaultv or 0, 0, 0} --> hooks - SliderObject.slider:SetScript ("OnEnter", OnEnter) - SliderObject.slider:SetScript ("OnLeave", OnLeave) - SliderObject.slider:SetScript ("OnHide", OnHide) - SliderObject.slider:SetScript ("OnShow", OnShow) - SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged) - SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown) - SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp) + SliderObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnMouseDown = {}, + OnMouseUp = {}, - + OnValueChange = {}, + OnValueChanged = {}, + } + + SliderObject.slider:SetScript ("OnEnter", OnEnter) + SliderObject.slider:SetScript ("OnLeave", OnLeave) + SliderObject.slider:SetScript ("OnHide", OnHide) + SliderObject.slider:SetScript ("OnShow", OnShow) + SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged) + SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown) + SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp) + _setmetatable (SliderObject, DFSliderMetaFunctions) if (with_label) then
--- a/Libs/DF/split_bar.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/split_bar.lua Tue Jul 19 13:23:40 2016 -0300 @@ -13,9 +13,20 @@ local _math_floor = math.floor --> lua local local cleanfunction = function() end -local SplitBarMetaFunctions = {} local APISplitBarFunctions +do + local metaPrototype = { + WidgetType = "split_bar", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["split_bar"]] = _G [DF.GlobalWidgetControlNames ["split_bar"]] or metaPrototype +end + +local SplitBarMetaFunctions = _G [DF.GlobalWidgetControlNames ["split_bar"]] + ------------------------------------------------------------------------------------------------------------ --> metatables @@ -122,30 +133,29 @@ return _object.textleft:GetTextColor() end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["value"] = gmember_value, - ["righttext"] = gmember_rtext, - ["lefttext"] = gmember_ltext, - ["rightcolor"] = gmember_rcolor, - ["leftcolor"] = gmember_lcolor, - ["righticon"] = gmember_ricon, - ["lefticon"] = gmember_licon, - ["texture"] = gmember_texture, - ["fontsize"] = gmember_textsize, - ["fontface"] = gmember_textfont, - ["fontcolor"] = gmember_textcolor, - ["textsize"] = gmember_textsize, --alias - ["textfont"] = gmember_textfont, --alias - ["textcolor"] = gmember_textcolor --alias - } + SplitBarMetaFunctions.GetMembers = SplitBarMetaFunctions.GetMembers or {} + SplitBarMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + SplitBarMetaFunctions.GetMembers ["shown"] = gmember_shown + SplitBarMetaFunctions.GetMembers ["width"] = gmember_width + SplitBarMetaFunctions.GetMembers ["height"] = gmember_height + SplitBarMetaFunctions.GetMembers ["value"] = gmember_value + SplitBarMetaFunctions.GetMembers ["righttext"] = gmember_rtext + SplitBarMetaFunctions.GetMembers ["lefttext"] = gmember_ltext + SplitBarMetaFunctions.GetMembers ["rightcolor"] = gmember_rcolor + SplitBarMetaFunctions.GetMembers ["leftcolor"] = gmember_lcolor + SplitBarMetaFunctions.GetMembers ["righticon"] = gmember_ricon + SplitBarMetaFunctions.GetMembers ["lefticon"] = gmember_licon + SplitBarMetaFunctions.GetMembers ["texture"] = gmember_texture + SplitBarMetaFunctions.GetMembers ["fontsize"] = gmember_textsize + SplitBarMetaFunctions.GetMembers ["fontface"] = gmember_textfont + SplitBarMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor + SplitBarMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias + SplitBarMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias + SplitBarMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias SplitBarMetaFunctions.__index = function (_table, _member_requested) - local func = get_members_function_index [_member_requested] + local func = SplitBarMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -274,29 +284,28 @@ return _object.textright:SetTextColor (_value1, _value2, _value3, _value4) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["shown"] = smember_shown, - ["width"] = smember_width, - ["height"] = smember_height, - ["value"] = smember_value, - ["righttext"] = smember_rtext, - ["lefttext"] = smember_ltext, - ["rightcolor"] = smember_rcolor, - ["leftcolor"] = smember_lcolor, - ["righticon"] = smember_ricon, - ["lefticon"] = smember_licon, - ["texture"] = smember_texture, - ["fontsize"] = smember_textsize, - ["fontface"] = smember_textfont, - ["fontcolor"] = smember_textcolor, - ["textsize"] = smember_textsize, --alias - ["textfont"] = smember_textfont, --alias - ["textcolor"] = smember_textcolor --alias - } + SplitBarMetaFunctions.SetMembers = SplitBarMetaFunctions.SetMembers or {} + SplitBarMetaFunctions.SetMembers ["tooltip"] = smember_tooltip + SplitBarMetaFunctions.SetMembers ["shown"] = smember_shown + SplitBarMetaFunctions.SetMembers ["width"] = smember_width + SplitBarMetaFunctions.SetMembers ["height"] = smember_height + SplitBarMetaFunctions.SetMembers ["value"] = smember_value + SplitBarMetaFunctions.SetMembers ["righttext"] = smember_rtext + SplitBarMetaFunctions.SetMembers ["lefttext"] = smember_ltext + SplitBarMetaFunctions.SetMembers ["rightcolor"] = smember_rcolor + SplitBarMetaFunctions.SetMembers ["leftcolor"] = smember_lcolor + SplitBarMetaFunctions.SetMembers ["righticon"] = smember_ricon + SplitBarMetaFunctions.SetMembers ["lefticon"] = smember_licon + SplitBarMetaFunctions.SetMembers ["texture"] = smember_texture + SplitBarMetaFunctions.SetMembers ["fontsize"] = smember_textsize + SplitBarMetaFunctions.SetMembers ["fontface"] = smember_textfont + SplitBarMetaFunctions.SetMembers ["fontcolor"] = smember_textcolor + SplitBarMetaFunctions.SetMembers ["textsize"] = smember_textsize --alias + SplitBarMetaFunctions.SetMembers ["textfont"] = smember_textfont --alias + SplitBarMetaFunctions.SetMembers ["textcolor"] = smember_textcolor --alias SplitBarMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = SplitBarMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -425,23 +434,13 @@ end end ---> hooks - function SplitBarMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - ------------------------------------------------------------------------------------------------------------ --> scripts local OnEnter = function (frame) - if (frame.MyObject.OnEnterHook) then - local interrupt = frame.MyObject.OnEnterHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) + if (kill) then + return end frame.MyObject.div:SetPoint ("left", frame, "left", frame:GetValue() * (frame:GetWidth()/100) - 18, 0) @@ -454,11 +453,10 @@ end local OnLeave = function (frame) - if (frame.MyObject.OnLeaveHook) then - local interrupt = frame.MyObject.OnLeaveHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) + if (kill) then + return end if (frame.MyObject.have_tooltip) then @@ -467,29 +465,26 @@ end local OnHide = function (frame) - if (frame.MyObject.OnHideHook) then - local interrupt = frame.MyObject.OnHideHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) + if (kill) then + return end end local OnShow = function (frame) - if (frame.MyObject.OnShowHook) then - local interrupt = frame.MyObject.OnShowHook (frame) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) + if (kill) then + return end end local OnMouseDown = function (frame, button) - if (frame.MyObject.OnMouseDownHook) then - local interrupt = frame.MyObject.OnMouseDownHook (frame, button) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) + if (kill) then + return end if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then @@ -501,11 +496,10 @@ end local OnMouseUp = function (frame, button) - if (frame.MyObject.OnMouseUpHook) then - local interrupt = frame.MyObject.OnMouseUpHook (frame, button) - if (interrupt) then - return - end + local capsule = frame.MyObject + local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) + if (kill) then + return end if (frame.MyObject.container.isMoving) then @@ -564,17 +558,8 @@ end --> default members: - --> hooks - SplitBarObject.OnEnterHook = nil - SplitBarObject.OnLeaveHook = nil - SplitBarObject.OnHideHook = nil - SplitBarObject.OnShowHook = nil - SplitBarObject.OnMouseDownHook = nil - SplitBarObject.OnMouseUpHook = nil --> misc - SplitBarObject.tooltip = nil SplitBarObject.locked = false - SplitBarObject.have_tooltip = nil SplitBarObject.container = container --> create widgets @@ -610,15 +595,25 @@ SplitBarObject.div = _G [name .. "_Spark"] - + --> hooks - SplitBarObject.statusbar:SetScript ("OnEnter", OnEnter) - SplitBarObject.statusbar:SetScript ("OnLeave", OnLeave) - SplitBarObject.statusbar:SetScript ("OnHide", OnHide) - SplitBarObject.statusbar:SetScript ("OnShow", OnShow) - SplitBarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) - SplitBarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp) - SplitBarObject.statusbar:SetScript ("OnSizeChanged", OnSizeChanged) + SplitBarObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnMouseDown = {}, + OnMouseUp = {}, + OnSizeChanged = {}, + } + + SplitBarObject.statusbar:SetScript ("OnEnter", OnEnter) + SplitBarObject.statusbar:SetScript ("OnLeave", OnLeave) + SplitBarObject.statusbar:SetScript ("OnHide", OnHide) + SplitBarObject.statusbar:SetScript ("OnShow", OnShow) + SplitBarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) + SplitBarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp) + SplitBarObject.statusbar:SetScript ("OnSizeChanged", OnSizeChanged) _setmetatable (SplitBarObject, SplitBarMetaFunctions)
--- a/Libs/DF/textentry.lua Mon Jul 04 23:06:23 2016 -0300 +++ b/Libs/DF/textentry.lua Tue Jul 19 13:23:40 2016 -0300 @@ -16,9 +16,19 @@ local cleanfunction = function() end local APITextEntryFunctions = false -local TextEntryMetaFunctions = {} -DF.TextEntryCounter = 1 +do + local metaPrototype = { + WidgetType = "textentry", + SetHook = DF.SetHook, + RunHooksForWidget = DF.RunHooksForWidget, + } + + _G [DF.GlobalWidgetControlNames ["textentry"]] = _G [DF.GlobalWidgetControlNames ["textentry"]] or metaPrototype +end + +local TextEntryMetaFunctions = _G [DF.GlobalWidgetControlNames ["textentry"]] +DF.TextEntryCounter = DF.TextEntryCounter or 1 ------------------------------------------------------------------------------------------------------------ --> metatables @@ -51,17 +61,15 @@ return _object.editbox:GetText() end - local get_members_function_index = { - ["tooltip"] = gmember_tooltip, - ["shown"] = gmember_shown, - ["width"] = gmember_width, - ["height"] = gmember_height, - ["text"] = gmember_text, - } + TextEntryMetaFunctions.GetMembers = TextEntryMetaFunctions.GetMembers or {} + TextEntryMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip + TextEntryMetaFunctions.GetMembers ["shown"] = gmember_shown + TextEntryMetaFunctions.GetMembers ["width"] = gmember_width + TextEntryMetaFunctions.GetMembers ["height"] = gmember_height + TextEntryMetaFunctions.GetMembers ["text"] = gmember_text TextEntryMetaFunctions.__index = function (_table, _member_requested) - - local func = get_members_function_index [_member_requested] + local func = TextEntryMetaFunctions.GetMembers [_member_requested] if (func) then return func (_table, _member_requested) end @@ -121,19 +129,18 @@ return _object.editbox:SetJustifyH (string.lower (_value)) end - local set_members_function_index = { - ["tooltip"] = smember_tooltip, - ["show"] = smember_show, - ["hide"] = smember_hide, - ["width"] = smember_width, - ["height"] = smember_height, - ["text"] = smember_text, - ["multiline"] = smember_multiline, - ["align"] = smember_horizontalpos, - } + TextEntryMetaFunctions.SetMembers = TextEntryMetaFunctions.SetMembers or {} + TextEntryMetaFunctions.SetMembers ["tooltip"] = smember_tooltip + TextEntryMetaFunctions.SetMembers ["show"] = smember_show + TextEntryMetaFunctions.SetMembers ["hide"] = smember_hide + TextEntryMetaFunctions.SetMembers ["width"] = smember_width + TextEntryMetaFunctions.SetMembers ["height"] = smember_height + TextEntryMetaFunctions.SetMembers ["text"] = smember_text + TextEntryMetaFunctions.SetMembers ["multiline"] = smember_multiline + TextEntryMetaFunctions.SetMembers ["align"] = smember_horizontalpos TextEntryMetaFunctions.__newindex = function (_table, _key, _value) - local func = set_members_function_index [_key] + local func = TextEntryMetaFunctions.SetMembers [_key] if (func) then return func (_table, _value) else @@ -143,6 +150,21 @@ ------------------------------------------------------------------------------------------------------------ --> methods + local cleanfunction = function()end + function TextEntryMetaFunctions:SetEnterFunction (func, param1, param2) + if (func) then + _rawset (self, "func", func) + else + _rawset (self, "func", cleanfunction) + end + + if (param1 ~= nil) then + _rawset (self, "param1", param1) + end + if (param2 ~= nil) then + _rawset (self, "param2", param2) + end + end --> set point function TextEntryMetaFunctions:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y, Width) @@ -252,14 +274,6 @@ end --> hooks - function TextEntryMetaFunctions:SetHook (hookType, func) - if (func) then - _rawset (self, hookType.."Hook", func) - else - _rawset (self, hookType.."Hook", nil) - end - end - function TextEntryMetaFunctions:Enable() if (not self.editbox:IsEnabled()) then self.editbox:Enable() @@ -291,19 +305,19 @@ end ------------------------------------------------------------------------------------------------------------ ---> scripts +--> scripts and hooks + local OnEnter = function (textentry) + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnEnter", textentry, capsule) + if (kill) then + return + end - if (textentry.MyObject.OnEnterHook) then - local interrupt = textentry.MyObject.OnEnterHook (textentry) - if (interrupt) then - return - end - end - - if (textentry.MyObject.have_tooltip) then + if (capsule.have_tooltip) then GameCooltip2:Preset (2) - GameCooltip2:AddLine (textentry.MyObject.have_tooltip) + GameCooltip2:AddLine (capsule.have_tooltip) GameCooltip2:ShowCooltip (textentry, "tooltip") end @@ -313,17 +327,16 @@ textentry.current_bordercolor = textentry.current_bordercolor or {textentry:GetBackdropBorderColor()} textentry:SetBackdropBorderColor (1, 1, 1, 1) end - end local OnLeave = function (textentry) - if (textentry.MyObject.OnLeaveHook) then - local interrupt = textentry.MyObject.OnLeaveHook (textentry) - if (interrupt) then - return - end + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnLeave", textentry, capsule) + if (kill) then + return end - + if (textentry.MyObject.have_tooltip) then GameCooltip2:ShowMe (false) end @@ -333,34 +346,32 @@ if (textentry:IsEnabled()) then textentry:SetBackdropBorderColor (unpack (textentry.current_bordercolor)) end - end local OnHide = function (textentry) - if (textentry.MyObject.OnHideHook) then - local interrupt = textentry.MyObject.OnHideHook (textentry) - if (interrupt) then - return - end + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnHide", textentry, capsule) + if (kill) then + return end end local OnShow = function (textentry) - if (textentry.MyObject.OnShowHook) then - local interrupt = textentry.MyObject.OnShowHook (textentry) - if (interrupt) then - return - end + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnShow", textentry, capsule) + if (kill) then + return end end - local OnEnterPressed = function (textentry, byScript) + local OnEnterPressed = function (textentry, byScript) + local capsule = textentry.MyObject - if (textentry.MyObject.OnEnterPressedHook) then - local interrupt = textentry.MyObject.OnEnterPressedHook (textentry) - if (interrupt) then - return - end + local kill = capsule:RunHooksForWidget ("OnEnterPressed", textentry, capsule) + if (kill) then + return end local texto = DF:trim (textentry:GetText()) @@ -373,38 +384,47 @@ textentry:SetText ("") textentry.MyObject.currenttext = "" end - textentry.focuslost = true --> perdeu_focus isso aqui pra quando estiver editando e clicar em outra caixa - textentry:ClearFocus() - if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then - textentry.MyObject.next:SetFocus() + if (not capsule.NoClearFocusOnEnterPressed) then + textentry.focuslost = true --> quando estiver editando e clicar em outra caixa + textentry:ClearFocus() + + if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then + textentry.MyObject.next:SetFocus() + end end end local OnEscapePressed = function (textentry) + local capsule = textentry.MyObject - if (textentry.MyObject.OnEscapePressedHook) then - local interrupt = textentry.MyObject.OnEscapePressedHook (textentry) - if (interrupt) then - return - end - end - - --textentry:SetText("") - --textentry.MyObject.currenttext = "" + local kill = capsule:RunHooksForWidget ("OnEscapePressed", textentry, capsule) + if (kill) then + return + end + textentry.focuslost = true textentry:ClearFocus() end + local OnSpacePressed = function (textentry) + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnSpacePressed", textentry, capsule) + if (kill) then + return + end + end + local OnEditFocusLost = function (textentry) + local capsule = textentry.MyObject + if (textentry:IsShown()) then - if (textentry.MyObject.OnEditFocusLostHook) then - local interrupt = textentry.MyObject.OnEditFocusLostHook (textentry) - if (interrupt) then - return - end + local kill = capsule:RunHooksForWidget ("OnEditFocusLost", textentry, capsule) + if (kill) then + return end if (not textentry.focuslost) then @@ -428,39 +448,42 @@ end local OnEditFocusGained = function (textentry) - if (textentry.MyObject.OnEditFocusGainedHook) then - local interrupt = textentry.MyObject.OnEditFocusGainedHook (textentry) - if (interrupt) then - return - end + + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnEditFocusGained", textentry, capsule) + if (kill) then + return end + textentry.MyObject.label:SetTextColor (1, 1, 1, 1) end - local OnChar = function (textentry, text) - if (textentry.MyObject.OnCharHook) then - local interrupt = textentry.MyObject.OnCharHook (textentry, text) - if (interrupt) then - return - end + local OnChar = function (textentry, char) + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnChar", textentry, char, capsule) + if (kill) then + return end end local OnTextChanged = function (textentry, byUser) - if (textentry.MyObject.OnTextChangedHook) then - local interrupt = textentry.MyObject.OnTextChangedHook (textentry, byUser) - if (interrupt) then - return - end + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnTextChanged", textentry, byUser, capsule) + if (kill) then + return end end local OnTabPressed = function (textentry) - if (textentry.MyObject.OnTabPressedHook) then - local interrupt = textentry.MyObject.OnTabPressedHook (textentry, byUser) - if (interrupt) then - return - end + + local capsule = textentry.MyObject + + local kill = capsule:RunHooksForWidget ("OnTabPressed", textentry, byUser, capsule) + if (kill) then + return end if (textentry.MyObject.next) then @@ -583,7 +606,7 @@ w = space elseif (w and space) then if (DF.debug) then - print ("warning: you are using width and space, try use only space for better results.") + --print ("warning: you are using width and space, try use only space for better results.") end end @@ -617,6 +640,22 @@ TextEntryObject.editbox:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}}) --> hooks + + TextEntryObject.HookList = { + OnEnter = {}, + OnLeave = {}, + OnHide = {}, + OnShow = {}, + OnEnterPressed = {}, + OnEscapePressed = {}, + OnSpacePressed = {}, + OnEditFocusLost = {}, + OnEditFocusGained = {}, + OnChar = {}, + OnTextChanged = {}, + OnTabPressed = {}, + } + TextEntryObject.editbox:SetScript ("OnEnter", OnEnter) TextEntryObject.editbox:SetScript ("OnLeave", OnLeave) TextEntryObject.editbox:SetScript ("OnHide", OnHide) @@ -624,6 +663,7 @@ TextEntryObject.editbox:SetScript ("OnEnterPressed", OnEnterPressed) TextEntryObject.editbox:SetScript ("OnEscapePressed", OnEscapePressed) + TextEntryObject.editbox:SetScript ("OnSpacePressed", OnSpacePressed) TextEntryObject.editbox:SetScript ("OnEditFocusLost", OnEditFocusLost) TextEntryObject.editbox:SetScript ("OnEditFocusGained", OnEditFocusGained) TextEntryObject.editbox:SetScript ("OnChar", OnChar) @@ -653,8 +693,8 @@ function DF:NewSpellEntry (parent, func, w, h, param1, param2, member, name) local editbox = DF:NewTextEntry (parent, parent, name, member, w, h, func, param1, param2) - editbox:SetHook ("OnEditFocusGained", SpellEntryOnEditFocusGained) - editbox:SetHook ("OnTextChanged", SpellEntryOnTextChanged) +-- editbox:SetHook ("OnEditFocusGained", SpellEntryOnEditFocusGained) +-- editbox:SetHook ("OnTextChanged", SpellEntryOnTextChanged) return editbox end @@ -734,4 +774,275 @@ borderframe.editbox.borderframe = borderframe return borderframe -end \ No newline at end of file +end + + +------------------------------------------------------------------------------------ +--auto complete + +-- block ------------------- +--code author Saiket from http://www.wowinterface.com/forums/showpost.php?p=245759&postcount=6 +--- @return StartPos, EndPos of highlight in this editbox. +local function GetTextHighlight ( self ) + local Text, Cursor = self:GetText(), self:GetCursorPosition(); + self:Insert( "" ); -- Delete selected text + local TextNew, CursorNew = self:GetText(), self:GetCursorPosition(); + -- Restore previous text + self:SetText( Text ); + self:SetCursorPosition( Cursor ); + local Start, End = CursorNew, #Text - ( #TextNew - CursorNew ); + self:HighlightText( Start, End ); + return Start, End; +end +local StripColors; +do + local CursorPosition, CursorDelta; + --- Callback for gsub to remove unescaped codes. + local function StripCodeGsub ( Escapes, Code, End ) + if ( #Escapes % 2 == 0 ) then -- Doesn't escape Code + if ( CursorPosition and CursorPosition >= End - 1 ) then + CursorDelta = CursorDelta - #Code; + end + return Escapes; + end + end + --- Removes a single escape sequence. + local function StripCode ( Pattern, Text, OldCursor ) + CursorPosition, CursorDelta = OldCursor, 0; + return Text:gsub( Pattern, StripCodeGsub ), OldCursor and CursorPosition + CursorDelta; + end + --- Strips Text of all color escape sequences. + -- @param Cursor Optional cursor position to keep track of. + -- @return Stripped text, and the updated cursor position if Cursor was given. + function StripColors ( Text, Cursor ) + Text, Cursor = StripCode( "(|*)(|c%x%x%x%x%x%x%x%x)()", Text, Cursor ); + return StripCode( "(|*)(|r)()", Text, Cursor ); + end +end + +local COLOR_END = "|r"; +--- Wraps this editbox's selected text with the given color. +local function ColorSelection ( self, ColorCode ) + local Start, End = GetTextHighlight( self ); + local Text, Cursor = self:GetText(), self:GetCursorPosition(); + if ( Start == End ) then -- Nothing selected + --Start, End = Cursor, Cursor; -- Wrap around cursor + return; -- Wrapping the cursor in a color code and hitting backspace crashes the client! + end + -- Find active color code at the end of the selection + local ActiveColor; + if ( End < #Text ) then -- There is text to color after the selection + local ActiveEnd; + local CodeEnd, _, Escapes, Color = 0; + while ( true ) do + _, CodeEnd, Escapes, Color = Text:find( "(|*)(|c%x%x%x%x%x%x%x%x)", CodeEnd + 1 ); + if ( not CodeEnd or CodeEnd > End ) then + break; + end + if ( #Escapes % 2 == 0 ) then -- Doesn't escape Code + ActiveColor, ActiveEnd = Color, CodeEnd; + end + end + + if ( ActiveColor ) then + -- Check if color gets terminated before selection ends + CodeEnd = 0; + while ( true ) do + _, CodeEnd, Escapes = Text:find( "(|*)|r", CodeEnd + 1 ); + if ( not CodeEnd or CodeEnd > End ) then + break; + end + if ( CodeEnd > ActiveEnd and #Escapes % 2 == 0 ) then -- Terminates ActiveColor + ActiveColor = nil; + break; + end + end + end + end + + local Selection = Text:sub( Start + 1, End ); + -- Remove color codes from the selection + local Replacement, CursorReplacement = StripColors( Selection, Cursor - Start ); + + self:SetText( ( "" ):join( + Text:sub( 1, Start ), + ColorCode, Replacement, COLOR_END, + ActiveColor or "", Text:sub( End + 1 ) + ) ); + + -- Restore cursor and highlight, adjusting for wrapper text + Cursor = Start + CursorReplacement; + if ( CursorReplacement > 0 ) then -- Cursor beyond start of color code + Cursor = Cursor + #ColorCode; + end + if ( CursorReplacement >= #Replacement ) then -- Cursor beyond end of color + Cursor = Cursor + #COLOR_END; + end + + self:SetCursorPosition( Cursor ); + -- Highlight selection and wrapper + self:HighlightText( Start, #ColorCode + ( #Replacement - #Selection ) + #COLOR_END + End ); +end +-- end of the block --------------------- + +local get_last_word = function (self) + self.lastword = "" + local cursor_pos = self.editbox:GetCursorPosition() + local text = self.editbox:GetText() + for i = cursor_pos, 1, -1 do + local character = text:sub (i, i) + if (character:match ("%a")) then + self.lastword = character .. self.lastword + else + break + end + end +end + +--On Text Changed +local AutoComplete_OnTextChanged = function (editboxWidget, byUser, capsule) + capsule = capsule or editboxWidget.MyObject + + local chars_now = editboxWidget:GetText():len() + if (not editboxWidget.ignore_textchange) then + --> backspace + if (chars_now == capsule.characters_count -1) then + capsule.lastword = capsule.lastword:sub (1, capsule.lastword:len()-1) + --> delete lots of text + elseif (chars_now < capsule.characters_count) then + --o auto complete selecionou outra palavra bem menor e caiu nesse filtro + editboxWidget.end_selection = nil + capsule:GetLastWord() + end + else + editboxWidget.ignore_textchange = nil + end + capsule.characters_count = chars_now +end + +local AutoComplete_OnSpacePressed = function (editboxWidget, capsule) + capsule = capsule or editboxWidget.MyObject + +-- if (not gotMatch) then + --editboxWidget.end_selection = nil +-- end +end + +local AutoComplete_OnEscapePressed = function (editboxWidget) + editboxWidget.end_selection = nil +end + +local AutoComplete_OnEnterPressed = function (editboxWidget) + + local capsule = editboxWidget.MyObject + if (editboxWidget.end_selection) then + editboxWidget:SetCursorPosition (editboxWidget.end_selection) + editboxWidget:HighlightText (0, 0) + editboxWidget.end_selection = nil + --editboxWidget:Insert (" ") --estava causando a adição de uma palavra a mais quando o próximo catactere for um espaço + else + if (editboxWidget:IsMultiLine()) then + editboxWidget:Insert ("\n") + --reseta a palavra se acabou de ganhar focus e apertou enter + if (editboxWidget.focusGained) then + capsule.lastword = "" + editboxWidget.focusGained = nil + end + else + editboxWidget:Insert ("") + editboxWidget.focuslost = true + editboxWidget:ClearFocus() + end + end + capsule.lastword = "" + +end + +local AutoComplete_OnEditFocusGained = function (editboxWidget) + local capsule = editboxWidget.MyObject + capsule:GetLastWord() + editboxWidget.end_selection = nil + editboxWidget.focusGained = true + capsule.characters_count = editboxWidget:GetText():len() +end + +local AutoComplete_OnChar = function (editboxWidget, char, capsule) + if (char == "") then + return + end + + capsule = capsule or editboxWidget.MyObject + editboxWidget.end_selection = nil + + if (editboxWidget.ignore_input) then + return + end + + --reseta a palavra se acabou de ganhar focus e apertou espaço + if (editboxWidget.focusGained and char == " ") then + capsule.lastword = "" + editboxWidget.focusGained = nil + else + editboxWidget.focusGained = nil + end + + if (char:match ("%a") or (char == " " and capsule.lastword ~= "")) then + capsule.lastword = capsule.lastword .. char + else + capsule.lastword = "" + end + + editboxWidget.ignore_input = true + if (capsule.lastword:len() >= 2) then + + local wordList = capsule [capsule.poolName] + if (not wordList) then + if (DF.debug) then + error ("Details! Framework: Invalid word list table.") + end + return + end + + for i = 1, #wordList do + local thisWord = wordList [i] + if (thisWord and (thisWord:find ("^" .. capsule.lastword) or thisWord:lower():find ("^" .. capsule.lastword))) then + local rest = thisWord:gsub (capsule.lastword, "") + rest = rest:lower():gsub (capsule.lastword, "") + local cursor_pos = editboxWidget:GetCursorPosition() + editboxWidget:Insert (rest) + editboxWidget:HighlightText (cursor_pos, cursor_pos + rest:len()) + editboxWidget:SetCursorPosition (cursor_pos) + editboxWidget.end_selection = cursor_pos + rest:len() + editboxWidget.ignore_textchange = true + break + end + end + + end + editboxWidget.ignore_input = false +end + +function TextEntryMetaFunctions:SetAsAutoComplete (poolName) + + self.lastword = "" + self.characters_count = 0 + self.poolName = poolName + self.GetLastWord = get_last_word --editbox:GetLastWord() + self.NoClearFocusOnEnterPressed = true --avoid auto clear focus + + self:SetHook ("OnEditFocusGained", AutoComplete_OnEditFocusGained) + self.editbox:HookScript ("OnEscapePressed", AutoComplete_OnEscapePressed) + +-- self:SetHook ("OnTextChanged", AutoComplete_OnTextChanged) + self:SetHook ("OnEnterPressed", AutoComplete_OnEnterPressed) +-- self:SetHook ("OnChar", AutoComplete_OnChar) +-- self:SetHook ("OnSpacePressed", AutoComplete_OnSpacePressed) + + self.editbox:SetScript ("OnTextChanged", AutoComplete_OnTextChanged) +-- self.editbox:SetScript ("OnEnterPressed", AutoComplete_OnEnterPressed) + self.editbox:SetScript ("OnChar", AutoComplete_OnChar) + self.editbox:SetScript ("OnSpacePressed", AutoComplete_OnSpacePressed) + +end + +-- endp \ No newline at end of file
