diff --git a/Details-BCC.toc b/Details-BCC.toc index 6d6ade4a..a4354dfb 100644 --- a/Details-BCC.toc +++ b/Details-BCC.toc @@ -41,6 +41,7 @@ functions\savedata.lua functions\slash.lua functions\playerclass.lua functions\timedata.lua +functions\currentdps.lua functions\report.lua functions\rowanimation.lua functions\raidinfo.lua diff --git a/Details.toc b/Details.toc index 76d5b175..acb2cc2f 100644 --- a/Details.toc +++ b/Details.toc @@ -43,6 +43,7 @@ functions\savedata.lua functions\slash.lua functions\playerclass.lua functions\timedata.lua +functions\currentdps.lua functions\report.lua functions\rowanimation.lua functions\raidinfo.lua diff --git a/Libs/DF/button.lua b/Libs/DF/button.lua index 7eede29a..bc74989d 100644 --- a/Libs/DF/button.lua +++ b/Libs/DF/button.lua @@ -1200,8 +1200,8 @@ end local color_button_height = 16 local color_button_width = 16 -local set_colorpick_color = function (button, r, g, b, a) - a = a or 1 +local setColorPickColor = function (button, r, g, b, a) + r, g, b, a = DF:ParseColors(r, g, b, a) button.color_texture:SetVertexColor (r, g, b, a) end @@ -1209,20 +1209,24 @@ local colorpick_cancel = function (self) ColorPickerFrame:Hide() end +local getColorPickColor = function(self) + return self.color_texture:GetVertexColor() +end + function DF:CreateColorPickButton (parent, name, member, callback, alpha, button_template) return DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) end function DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) - --button local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2", nil, nil, nil, button_template) button.color_callback = callback button.Cancel = colorpick_cancel - button.SetColor = set_colorpick_color - + button.SetColor = setColorPickColor + button.GetColor = getColorPickColor + button.HookList.OnColorChanged = {} - + if (not button_template) then button:InstallCustomTexture() button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6, @@ -1242,7 +1246,6 @@ function DF:NewColorPickButton (parent, name, member, callback, alpha, button_te img:SetPoint ("topleft", button.widget, "topleft", 0, 0) img:SetPoint ("bottomright", button.widget, "bottomright", 0, 0) img:SetDrawLayer ("background", 3) - + return button - end diff --git a/Libs/DF/dropdown.lua b/Libs/DF/dropdown.lua index 6eaa8988..218546c6 100644 --- a/Libs/DF/dropdown.lua +++ b/Libs/DF/dropdown.lua @@ -1,20 +1,10 @@ local DF = _G ["DetailsFramework"] if (not DF or not DetailsFrameworkCanLoad) then - return + return end local _ -local _rawset = rawset --> lua local -local _rawget = rawget --> lua local -local _setmetatable = setmetatable --> lua local -local _unpack = unpack --> lua local -local _type = type --> lua local -local _math_floor = math.floor --> lua local -local loadstring = loadstring --> lua local -local _string_len = string.len --> lua local - -local cleanfunction = function() end local APIDropDownFunctions = false do @@ -24,14 +14,13 @@ do HasHook = DF.HasHook, ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, - dversion = DF.dversion, } --check if there's a metaPrototype already existing if (_G[DF.GlobalWidgetControlNames["dropdown"]]) then --get the already existing metaPrototype - local oldMetaPrototype = _G[DF.GlobalWidgetControlNames ["dropdown"]] + local oldMetaPrototype = _G[DF.GlobalWidgetControlNames["dropdown"]] --check if is older if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < DF.dversion) ) then --the version is older them the currently loading one @@ -42,59 +31,59 @@ do end else --first time loading the framework - _G[DF.GlobalWidgetControlNames ["dropdown"]] = metaPrototype + _G[DF.GlobalWidgetControlNames["dropdown"]] = metaPrototype end end -local DropDownMetaFunctions = _G[DF.GlobalWidgetControlNames ["dropdown"]] +local DropDownMetaFunctions = _G[DF.GlobalWidgetControlNames["dropdown"]] ------------------------------------------------------------------------------------------------------------ ---> metatables +--metatables - DropDownMetaFunctions.__call = function (_table, value) - --> unknow + DropDownMetaFunctions.__call = function(_table, value) + --unknown end - + ------------------------------------------------------------------------------------------------------------ --> members - --> selected value - local gmember_value = function (_object) - return _object:GetValue() + --selected value + local gmember_value = function(object) + return object:GetValue() end - --> tooltip - local gmember_tooltip = function (_object) - return _object:GetTooltip() + --tooltip + local gmember_tooltip = function(object) + return object:GetTooltip() end - --> shown - local gmember_shown = function (_object) - return _object:IsShown() + --shown + local gmember_shown = function(object) + return object:IsShown() end - --> frame width - local gmember_width = function (_object) - return _object.button:GetWidth() + --frame width + local gmember_width = function(object) + return object.button:GetWidth() end - --> frame height - local gmember_height = function (_object) - return _object.button:GetHeight() + --frame height + local gmember_height = function(object) + return object.button:GetHeight() end - --> current text - local gmember_text = function (_object) - return _object.label:GetText() + --current text + local gmember_text = function(object) + return object.label:GetText() end - --> menu creation function - local gmember_function = function (_object) - return _object:GetFunction() + --menu creation function + local gmember_function = function(object) + return object:GetFunction() end - --> menu width - local gmember_menuwidth = function (_object) - return _rawget (self, "realsizeW") + --menu width + local gmember_menuwidth = function(object) + return rawget(object, "realsizeW") end - --> menu height - local gmember_menuheight = function (_object) - return _rawget (self, "realsizeH") + --menu height + local gmember_menuheight = function(object) + return rawget(object, "realsizeH") end - + DropDownMetaFunctions.GetMembers = DropDownMetaFunctions.GetMembers or {} DropDownMetaFunctions.GetMembers ["value"] = gmember_value DropDownMetaFunctions.GetMembers ["text"] = gmember_text @@ -105,65 +94,64 @@ local DropDownMetaFunctions = _G[DF.GlobalWidgetControlNames ["dropdown"]] DropDownMetaFunctions.GetMembers ["menuheight"] = gmember_menuheight DropDownMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip DropDownMetaFunctions.GetMembers ["func"] = gmember_function - - DropDownMetaFunctions.__index = function (_table, _member_requested) - local func = DropDownMetaFunctions.GetMembers [_member_requested] + DropDownMetaFunctions.__index = function(object, memberName) + local func = DropDownMetaFunctions.GetMembers[memberName] if (func) then - return func (_table, _member_requested) + return func(object, memberName) end - - local fromMe = _rawget (_table, _member_requested) + + local fromMe = rawget(object, memberName) if (fromMe) then return fromMe end - - return DropDownMetaFunctions [_member_requested] + + return DropDownMetaFunctions[memberName] end - + ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - --> tooltip - local smember_tooltip = function (_object, _value) - return _object:SetTooltip (_value) + --tooltip + local smember_tooltip = function(object, value) + return object:SetTooltip(value) end - --> show - local smember_show = function (_object, _value) - if (_value) then - return _object:Show() + --show + local smember_show = function(object, value) + if (value) then + return object:Show() else - return _object:Hide() + return object:Hide() end end - --> hide - local smember_hide = function (_object, _value) - if (not _value) then - return _object:Show() + --hide + local smember_hide = function(object, value) + if (not value) then + return object:Show() else - return _object:Hide() + return object:Hide() end end - --> frame width - local smember_width = function (_object, _value) - return _object.dropdown:SetWidth (_value) + --frame width + local smember_width = function(object, value) + return object.dropdown:SetWidth(value) end - --> frame height - local smember_height = function (_object, _value) - return _object.dropdown:SetHeight (_value) + --frame height + local smember_height = function(object, value) + return object.dropdown:SetHeight(value) end - --> menu creation function - local smember_function = function (_object, _value) - return _object:SetFunction (_value) + --menu creation function + local smember_function = function(object, value) + return object:SetFunction(value) end - --> menu width - local smember_menuwidth = function (_object, _value) - _object:SetMenuSize (_value, nil) + --menu width + local smember_menuwidth = function(object, value) + object:SetMenuSize(value, nil) end - --> menu height - local smember_menuheight = function (_object, _value) - _object:SetMenuSize (nil, _value) + --menu height + local smember_menuheight = function(object, value) + object:SetMenuSize(nil, value) end - + DropDownMetaFunctions.SetMembers = DropDownMetaFunctions.SetMembers or {} DropDownMetaFunctions.SetMembers ["tooltip"] = smember_tooltip DropDownMetaFunctions.SetMembers ["show"] = smember_show @@ -173,13 +161,13 @@ local DropDownMetaFunctions = _G[DF.GlobalWidgetControlNames ["dropdown"]] DropDownMetaFunctions.SetMembers ["height"] = smember_height DropDownMetaFunctions.SetMembers ["menuheight"] = smember_menuheight DropDownMetaFunctions.SetMembers ["func"] = smember_function - - DropDownMetaFunctions.__newindex = function (_table, _key, _value) - local func = DropDownMetaFunctions.SetMembers [_key] + + DropDownMetaFunctions.__newindex = function(object, key, value) + local func = DropDownMetaFunctions.SetMembers[key] if (func) then - return func (_table, _value) + return func(object, value) else - return _rawset (_table, _key, _value) + return rawset(object, key, value) end end @@ -209,76 +197,76 @@ end end --> menu width and height - function DropDownMetaFunctions:SetMenuSize (w, h) - if (w) then - return _rawset (self, "realsizeW", w) + function DropDownMetaFunctions:SetMenuSize(width, height) + if (width) then + return rawset(self, "realsizeW", width) end - if (h) then - return _rawset (self, "realsizeH", h) + if (height) then + return rawset(self, "realsizeH", height) end end function DropDownMetaFunctions:GetMenuSize() - return _rawget (self, "realsizeW"), _rawget (self, "realsizeH") + return rawget(self, "realsizeW"), rawget(self, "realsizeH") end - + --> function - function DropDownMetaFunctions:SetFunction (func) - return _rawset (self, "func", func) + function DropDownMetaFunctions:SetFunction(func) + return rawset(self, "func", func) end function DropDownMetaFunctions:GetFunction() - return _rawget (self, "func") + return rawget(self, "func") end - + --> value function DropDownMetaFunctions:GetValue() - return _rawget (self, "myvalue") + return rawget(self, "myvalue") end - function DropDownMetaFunctions:SetValue (value) - return _rawset (self, "myvalue", value) + function DropDownMetaFunctions:SetValue(value) + return rawset(self, "myvalue", value) end --> setpoint - function DropDownMetaFunctions:SetPoint (v1, v2, v3, v4, v5) - v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self) + function DropDownMetaFunctions:SetPoint(v1, v2, v3, v4, v5) + v1, v2, v3, v4, v5 = DF:CheckPoints(v1, v2, v3, v4, v5, self) if (not v1) then - print ("Invalid parameter for SetPoint") + print("Invalid parameter for SetPoint") return end - return self.widget:SetPoint (v1, v2, v3, v4, v5) + return self.widget:SetPoint(v1, v2, v3, v4, v5) end --> sizes - function DropDownMetaFunctions:SetSize (w, h) - if (w) then - self.dropdown:SetWidth (w) + function DropDownMetaFunctions:SetSize(width, height) + if (width) then + self.dropdown:SetWidth(width) end - if (h) then - return self.dropdown:SetHeight (h) + if (height) then + return self.dropdown:SetHeight(height) end end - + --> tooltip - function DropDownMetaFunctions:SetTooltip (tooltip) + function DropDownMetaFunctions:SetTooltip(tooltip) if (tooltip) then - return _rawset (self, "have_tooltip", tooltip) + return rawset(self, "have_tooltip", tooltip) else - return _rawset (self, "have_tooltip", nil) + return rawset(self, "have_tooltip", nil) end end function DropDownMetaFunctions:GetTooltip() - return _rawget (self, "have_tooltip") + return rawget(self, "have_tooltip") end - + --> frame levels function DropDownMetaFunctions:GetFrameLevel() return self.dropdown:GetFrameLevel() end - function DropDownMetaFunctions:SetFrameLevel (level, frame) + function DropDownMetaFunctions:SetFrameLevel(level, frame) if (not frame) then - return self.dropdown:SetFrameLevel (level) + return self.dropdown:SetFrameLevel(level) else - local framelevel = frame:GetFrameLevel (frame) + level - return self.dropdown:SetFrameLevel (framelevel) + local framelevel = frame:GetFrameLevel(frame) + level + return self.dropdown:SetFrameLevel(framelevel) end end @@ -286,50 +274,47 @@ end function DropDownMetaFunctions:GetFrameStrata() return self.dropdown:GetFrameStrata() end - function DropDownMetaFunctions:SetFrameStrata (strata) - if (_type (strata) == "table") then - self.dropdown:SetFrameStrata (strata:GetFrameStrata()) + function DropDownMetaFunctions:SetFrameStrata(strata) + if (type(strata) == "table") then + self.dropdown:SetFrameStrata(strata:GetFrameStrata()) else - self.dropdown:SetFrameStrata (strata) + self.dropdown:SetFrameStrata(strata) end end - + --> enabled function DropDownMetaFunctions:IsEnabled() return self.dropdown:IsEnabled() end - + function DropDownMetaFunctions:Enable() - - self:SetAlpha (1) - _rawset (self, "lockdown", false) - + + self:SetAlpha(1) + rawset(self, "lockdown", false) + if (self.OnEnable) then - self.OnEnable (self) + self.OnEnable(self) end - --return self.dropdown:Enable() end - + function DropDownMetaFunctions:Disable() - - self:SetAlpha (.4) - _rawset (self, "lockdown", true) - + self:SetAlpha(.4) + rawset(self, "lockdown", true) + if (self.OnDisable) then - self.OnDisable (self) + self.OnDisable(self) end - --return self.dropdown:Disable() end --> fixed value - function DropDownMetaFunctions:SetFixedParameter (value) - _rawset (self, "FixedValue", value) + function DropDownMetaFunctions:SetFixedParameter(value) + rawset(self, "FixedValue", value) end - + ------------------------------------------------------------------------------------------------------------ --> scripts -local last_opened = false +local lastOpened = false local isOptionVisible = function(self, thisOption) if (type(thisOption.shown) == "boolean") then @@ -392,36 +377,36 @@ function DropDownMetaFunctions:NoOptionSelected() return end - self.label:SetText (self.empty_text or "no option selected") - self.label:SetPoint ("left", self.icon, "right", 2, 0) - self.label:SetTextColor (1, 1, 1, 0.4) + self.label:SetText(self.empty_text or "no option selected") + self.label:SetPoint("left", self.icon, "right", 2, 0) + self.label:SetTextColor(1, 1, 1, 0.4) if (self.empty_icon) then - self.icon:SetTexture (self.empty_icon) + self.icon:SetTexture(self.empty_icon) else - self.icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) - self.icon:SetTexCoord (0.625, 0.78125, 0.328125, 0.390625) + self.icon:SetTexture([[Interface\COMMON\UI-ModelControlPanel]]) + self.icon:SetTexCoord(0.625, 0.78125, 0.328125, 0.390625) end - self.icon:SetVertexColor (1, 1, 1, 0.4) + self.icon:SetVertexColor(1, 1, 1, 0.4) self.last_select = nil end function DropDownMetaFunctions:NoOption(state) if (state) then self:Disable() - self:SetAlpha (0.5) + self:SetAlpha(0.5) self.no_options = true - self.label:SetText ("no options") - self.label:SetPoint ("left", self.icon, "right", 2, 0) - self.label:SetTextColor (1, 1, 1, 0.4) - self.icon:SetTexture ([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) - self.icon:SetTexCoord (0, 1, 0, 1) - self.icon:SetVertexColor (1, 1, 1, 0.4) + self.label:SetText("no options") + self.label:SetPoint("left", self.icon, "right", 2, 0) + self.label:SetTextColor(1, 1, 1, 0.4) + self.icon:SetTexture([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) + self.icon:SetTexCoord(0, 1, 0, 1) + self.icon:SetVertexColor(1, 1, 1, 0.4) else self.no_options = false self:Enable() - self:SetAlpha (1) + self:SetAlpha(1) end end @@ -458,7 +443,7 @@ end --@onlyShown: the selected option index when selecting by option number must be visible --@runCallback: run the callback (onclick) function after selecting the option function DropDownMetaFunctions:Select(optionName, byOptionNumber, onlyShown, runCallback) - if (type (optionName) == "boolean" and not optionName) then + if (type(optionName) == "boolean" and not optionName) then self:NoOptionSelected() return false end @@ -577,7 +562,7 @@ function DropDownMetaFunctions:Selected(thisOption) self.icon:SetVertexColor(1, 1, 1, 1) end - self.icon:SetSize(self:GetHeight()-2, self:GetHeight()-2) + self.icon:SetSize(self:GetHeight()-4, self:GetHeight()-4) else self.label:SetPoint("left", self.label:GetParent(), "left", 4, 0) end @@ -626,10 +611,10 @@ function DropDownMetaFunctions:Open() self.dropdown.dropdownframe:Show() self.dropdown.dropdownborder:Show() self.opened = true - if (last_opened) then - last_opened:Close() + if (lastOpened) then + lastOpened:Close() end - last_opened = self + lastOpened = self end function DropDownMetaFunctions:Close() @@ -644,7 +629,7 @@ function DropDownMetaFunctions:Close() selectedTexture:Hide() self.opened = false - last_opened = false + lastOpened = false end --close by escape key @@ -756,7 +741,7 @@ function DetailsFrameworkDropDownOnMouseDown(button, buttontype) if (thisOption.iconsize) then thisOptionFrame.icon:SetSize(thisOption.iconsize[1], thisOption.iconsize[2]) else - thisOptionFrame.icon:SetSize(20, 20) + thisOptionFrame.icon:SetSize(thisOptionFrame:GetHeight()-6, thisOptionFrame:GetHeight()-6) end if (thisOption.font) then @@ -893,140 +878,137 @@ function DetailsFrameworkDropDownOnMouseDown(button, buttontype) end end -function DetailsFrameworkDropDownOnEnter (self) - +function DetailsFrameworkDropDownOnEnter(self) local capsule = self.MyObject - local kill = capsule:RunHooksForWidget ("OnEnter", self, capsule) + local kill = capsule:RunHooksForWidget("OnEnter", self, capsule) if (kill) then return end if (self.MyObject.onenter_backdrop) then - self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) + self:SetBackdropColor(unpack(self.MyObject.onenter_backdrop)) else - self:SetBackdropColor (.2, .2, .2, .2) + self:SetBackdropColor(.2, .2, .2, .2) end - + if (self.MyObject.onenter_backdrop_border_color) then - self:SetBackdropBorderColor (unpack (self.MyObject.onenter_backdrop_border_color)) + self:SetBackdropBorderColor(unpack(self.MyObject.onenter_backdrop_border_color)) end - + self.arrowTexture2:Show() - - if (self.MyObject.have_tooltip) then - GameCooltip2:Preset (2) - - if (type (self.MyObject.have_tooltip) == "function") then - GameCooltip2:AddLine (self.MyObject.have_tooltip() or "") + if (self.MyObject.have_tooltip) then + GameCooltip2:Preset(2) + + if (type(self.MyObject.have_tooltip) == "function") then + GameCooltip2:AddLine(self.MyObject.have_tooltip() or "") else - GameCooltip2:AddLine (self.MyObject.have_tooltip) + GameCooltip2:AddLine(self.MyObject.have_tooltip) end - GameCooltip2:SetOwner (self) + GameCooltip2:SetOwner(self) GameCooltip2:ShowCooltip() end - end -function DetailsFrameworkDropDownOnLeave (self) +function DetailsFrameworkDropDownOnLeave(self) local capsule = self.MyObject - local kill = capsule:RunHooksForWidget ("OnLeave", self, capsule) + local kill = capsule:RunHooksForWidget("OnLeave", self, capsule) if (kill) then return end if (self.MyObject.onleave_backdrop) then - self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) + self:SetBackdropColor(unpack(self.MyObject.onleave_backdrop)) else - self:SetBackdropColor (1, 1, 1, .5) + self:SetBackdropColor(1, 1, 1, .5) end - + if (self.MyObject.onleave_backdrop_border_color) then - self:SetBackdropBorderColor (unpack (self.MyObject.onleave_backdrop_border_color)) + self:SetBackdropBorderColor(unpack(self.MyObject.onleave_backdrop_border_color)) end - + self.arrowTexture2:Hide() - - if (self.MyObject.have_tooltip) then - GameCooltip2:ShowMe (false) + + if (self.MyObject.have_tooltip) then + GameCooltip2:ShowMe(false) end end -function DetailsFrameworkDropDownOnSizeChanged (self, w, h) - self.MyObject.label:SetSize (self:GetWidth()-40, 10) +function DetailsFrameworkDropDownOnSizeChanged(self) + self.MyObject.label:SetSize(self:GetWidth()-40, 10) end -function DetailsFrameworkDropDownOnShow (self) +function DetailsFrameworkDropDownOnShow(self) local capsule = self.MyObject - local kill = capsule:RunHooksForWidget ("OnShow", self, capsule) + local kill = capsule:RunHooksForWidget("OnShow", self, capsule) if (kill) then return end end -function DetailsFrameworkDropDownOnHide (self) +function DetailsFrameworkDropDownOnHide(self) local capsule = self.MyObject - local kill = capsule:RunHooksForWidget ("OnHide", self, capsule) + local kill = capsule:RunHooksForWidget("OnHide", self, capsule) if (kill) then return end - self.MyObject:Close() end -function DF:BuildDropDownFontList (on_click, icon, icon_texcoord, icon_size) +function DF:BuildDropDownFontList(onClick, icon, iconTexcoord, iconSize) local t = {} - local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") - for name, fontPath in pairs (SharedMedia:HashTable ("font")) do - t[#t+1] = {value = name, label = name, onclick = on_click, icon = icon, iconsize = icon_size, texcoord = icon_texcoord, font = fontPath, descfont = "abcdefg ABCDEFG"} + local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") + for name, fontPath in pairs(SharedMedia:HashTable("font")) do + t[#t+1] = {value = name, label = name, onclick = onClick, icon = icon, iconsize = iconSize, texcoord = iconTexcoord, font = fontPath, descfont = "abcdefg ABCDEFG"} end - table.sort (t, function (t1, t2) return t1.label < t2.label end) + table.sort(t, function(t1, t2) return t1.label < t2.label end) return t end ------------------------------------------------------------------------------------------------------------ -function DropDownMetaFunctions:SetTemplate (template) +--> template +function DropDownMetaFunctions:SetTemplate(template) self.template = template if (template.width) then - self:SetWidth (template.width) + self:SetWidth(template.width) end if (template.height) then - self:SetHeight (template.height) + self:SetHeight(template.height) end - + if (template.backdrop) then - self:SetBackdrop (template.backdrop) + self:SetBackdrop(template.backdrop) end if (template.backdropcolor) then - local r, g, b, a = DF:ParseColors (template.backdropcolor) - self:SetBackdropColor (r, g, b, a) + local r, g, b, a = DF:ParseColors(template.backdropcolor) + self:SetBackdropColor(r, g, b, a) self.onleave_backdrop = {r, g, b, a} end if (template.backdropbordercolor) then - local r, g, b, a = DF:ParseColors (template.backdropbordercolor) - self:SetBackdropBorderColor (r, g, b, a) + local r, g, b, a = DF:ParseColors(template.backdropbordercolor) + self:SetBackdropBorderColor(r, g, b, a) self.onleave_backdrop_border_color = {r, g, b, a} end if (template.onentercolor) then - local r, g, b, a = DF:ParseColors (template.onentercolor) + local r, g, b, a = DF:ParseColors(template.onentercolor) self.onenter_backdrop = {r, g, b, a} end - + if (template.onleavecolor) then - local r, g, b, a = DF:ParseColors (template.onleavecolor) + local r, g, b, a = DF:ParseColors(template.onleavecolor) self.onleave_backdrop = {r, g, b, a} end - + if (template.onenterbordercolor) then - local r, g, b, a = DF:ParseColors (template.onenterbordercolor) + local r, g, b, a = DF:ParseColors(template.onenterbordercolor) self.onenter_backdrop_border_color = {r, g, b, a} end if (template.onleavebordercolor) then - local r, g, b, a = DF:ParseColors (template.onleavebordercolor) + local r, g, b, a = DF:ParseColors(template.onleavebordercolor) self.onleave_backdrop_border_color = {r, g, b, a} end @@ -1061,286 +1043,268 @@ function DropDownMetaFunctions:RefreshDropIcon() self.dropdown.arrowTexture:SetPoint("right", self.dropdown, "right", unpack(template.dropiconpoints)) self.dropdown.arrowTexture2:SetPoint("right", self.dropdown, "right", unpack(template.dropiconpoints)) end - - end end ------------------------------------------------------------------------------------------------------------ --> object constructor -function DF:CreateDropDown (parent, func, default, w, h, member, name, template) - return DF:NewDropDown (parent, parent, name, member, w, h, func, default, template) +function DF:CreateDropDown(parent, func, default, width, height, member, name, template) + return DF:NewDropDown(parent, parent, name, member, width, height, func, default, template) end -function DF:NewDropDown (parent, container, name, member, w, h, func, default, template) - +function DF:NewDropDown(parent, container, name, member, width, height, func, default, template) if (not name) then name = "DetailsFrameworkDropDownNumber" .. DF.DropDownCounter DF.DropDownCounter = DF.DropDownCounter + 1 - + elseif (not parent) then - return error ("Details! FrameWork: parent not found.", 2) + return error("Details! FrameWork: parent not found.", 2) end + if (not container) then container = parent end - - if (name:find ("$parent")) then - local parentName = DF.GetParentName (parent) - name = name:gsub ("$parent", parentName) + + if (name:find("$parent")) then + local parentName = DF.GetParentName(parent) + name = name:gsub("$parent", parentName) end - - local DropDownObject = {type = "dropdown", dframework = true} - + + local dropDownObject = {type = "dropdown", dframework = true} + if (member) then - parent [member] = DropDownObject - end - + parent[member] = dropDownObject + end + if (parent.dframework) then parent = parent.widget end if (container.dframework) then container = container.widget - end - + end + if (default == nil) then default = 1 end - --> default members: - --> misc - DropDownObject.container = container - - DropDownObject.dropdown = DF:CreateNewDropdownFrame (parent, name) - - DropDownObject.widget = DropDownObject.dropdown - - DropDownObject.__it = {nil, nil} + dropDownObject.dropdown = DF:CreateNewDropdownFrame(parent, name) + dropDownObject.dropdown:SetWidth(width) + dropDownObject.dropdown:SetHeight(height) + + dropDownObject.container = container + dropDownObject.widget = dropDownObject.dropdown + dropDownObject.dropdown.MyObject = dropDownObject if (not APIDropDownFunctions) then APIDropDownFunctions = true - local idx = getmetatable (DropDownObject.dropdown).__index - for funcName, funcAddress in pairs (idx) do - if (not DropDownMetaFunctions [funcName]) then - DropDownMetaFunctions [funcName] = function (object, ...) - local x = loadstring ( "return _G['"..object.dropdown:GetName().."']:"..funcName.."(...)") - return x (...) + local idx = getmetatable(dropDownObject.dropdown).__index + for funcName, funcAddress in pairs(idx) do + if (not DropDownMetaFunctions[funcName]) then + DropDownMetaFunctions[funcName] = function(object, ...) + local x = loadstring( "return _G['"..object.dropdown:GetName().."']:"..funcName.."(...)") + return x(...) end end end end - - DropDownObject.dropdown.MyObject = DropDownObject - - DropDownObject.dropdown:SetWidth (w) - DropDownObject.dropdown:SetHeight (h) - DropDownObject.func = func - DropDownObject.realsizeW = 150 - DropDownObject.realsizeH = 150 - DropDownObject.FixedValue = nil - DropDownObject.opened = false - DropDownObject.menus = {} - DropDownObject.myvalue = nil - - DropDownObject.label = _G [name .. "_Text"] - - DropDownObject.icon = _G [name .. "_IconTexture"] - DropDownObject.statusbar = _G [name .. "_StatusBarTexture"] - DropDownObject.select = _G [name .. "_SelectedTexture"] - - local scroll = _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame"] + dropDownObject.func = func + dropDownObject.realsizeW = 150 + dropDownObject.realsizeH = 150 + dropDownObject.FixedValue = nil + dropDownObject.opened = false + dropDownObject.menus = {} + dropDownObject.myvalue = nil + dropDownObject.label = _G[name .. "_Text"] + dropDownObject.icon = _G[name .. "_IconTexture"] + dropDownObject.statusbar = _G[name .. "_StatusBarTexture"] + dropDownObject.select = _G[name .. "_SelectedTexture"] - DropDownObject.scroll = DF:NewScrollBar (scroll, _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame".."_ScrollChild"], -18, -18) - DF:ReskinSlider (scroll) - - function DropDownObject:HideScroll() + local scroll = _G[dropDownObject.dropdown:GetName() .. "_ScrollFrame"] + dropDownObject.scroll = DF:NewScrollBar(scroll, _G[dropDownObject.dropdown:GetName() .. "_ScrollFrame" .. "_ScrollChild"], -18, -18) + DF:ReskinSlider(scroll) + + function dropDownObject:HideScroll() scroll.baixo:Hide() scroll.cima:Hide() scroll.slider:Hide() end - function DropDownObject:ShowScroll() + + function dropDownObject:ShowScroll() scroll.baixo:Show() scroll.cima:Show() scroll.slider:Show() end - - DropDownObject:HideScroll() - DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10) - - DropDownObject.HookList = { + + dropDownObject:HideScroll() + dropDownObject.label:SetSize(dropDownObject.dropdown:GetWidth()-40, 10) + + --hook list + dropDownObject.HookList = { OnEnter = {}, OnLeave = {}, OnHide = {}, OnShow = {}, OnOptionSelected = {}, - } - - 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) - - elseif (type (default) == "number") then - if (not DropDownObject:Select (default)) then - DropDownObject:Select (default, true) + --set default scripts + dropDownObject.dropdown:SetScript("OnShow", DetailsFrameworkDropDownOnShow) + dropDownObject.dropdown:SetScript("OnHide", DetailsFrameworkDropDownOnHide) + dropDownObject.dropdown:SetScript("OnEnter", DetailsFrameworkDropDownOnEnter) + dropDownObject.dropdown:SetScript("OnLeave", DetailsFrameworkDropDownOnLeave) + + setmetatable(dropDownObject, DropDownMetaFunctions) + + --initialize first menu selected + if (type(default) == "string") then + dropDownObject:Select(default) + elseif (type(default) == "number") then + if (not dropDownObject:Select(default)) then + dropDownObject:Select(default, true) end end if (template) then - DropDownObject:SetTemplate(template) + dropDownObject:SetTemplate(template) end - - return DropDownObject + return dropDownObject end -local default_backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], +local defaultBackdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 1, tile = true, tileSize = 16, insets = {left = 1, right = 1, top = 0, bottom = 1}} -local border_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, insets = {left = 0, right = 0, top = 0, bottom = 0}} -local child_backdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 256, insets = {left = 0, right = 0, top = 0, bottom = 0}} +local borderBackdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, insets = {left = 0, right = 0, top = 0, bottom = 0}} +local childBackdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 256, insets = {left = 0, right = 0, top = 0, bottom = 0}} -function DF:CreateNewDropdownFrame (parent, name) - local f = CreateFrame ("button", name, parent,"BackdropTemplate") - f:SetBackdrop (default_backdrop) - f:SetSize (150, 20) - - local statusbar = f:CreateTexture ("$parent_StatusBarTexture", "BACKGROUND") - statusbar:SetPoint ("topleft", f, "topleft", 0, 0) - statusbar:SetPoint ("bottomright", f, "bottomright", 0, 0) +function DF:CreateNewDropdownFrame(parent, name) + local f = CreateFrame("button", name, parent, "BackdropTemplate") + f:SetBackdrop(defaultBackdrop) + f:SetBackdropColor(1, 1, 1, .5) + f:SetSize(150, 20) + + local statusbar = f:CreateTexture("$parent_StatusBarTexture", "BACKGROUND") + statusbar:SetPoint("topleft", f, "topleft", 0, 0) + statusbar:SetPoint("bottomright", f, "bottomright", 0, 0) f.statusbar = statusbar - - local icon = f:CreateTexture ("$parent_IconTexture", "ARTWORK") - icon:SetPoint ("left", f, "left", 2, 0) - icon:SetSize (20, 20) - icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) - icon:SetTexCoord (0.625, 0.78125, 0.328125, 0.390625) - icon:SetVertexColor (1, 1, 1, 0.4) + + local icon = f:CreateTexture("$parent_IconTexture", "ARTWORK") + icon:SetPoint("left", f, "left", 2, 0) + icon:SetSize(20, 20) + icon:SetTexture([[Interface\COMMON\UI-ModelControlPanel]]) + icon:SetTexCoord(0.625, 0.78125, 0.328125, 0.390625) + icon:SetVertexColor(1, 1, 1, 0.4) f.icon = icon - - local text = f:CreateFontString ("$parent_Text", "ARTWORK", "GameFontHighlightSmall") - text:SetPoint ("left", icon, "right", 5, 0) - text:SetJustifyH ("left") - text:SetText ("no option selected") - text:SetTextColor (1, 1, 1, 0.4) - DF:SetFontSize (text, 10) + + local text = f:CreateFontString("$parent_Text", "ARTWORK", "GameFontHighlightSmall") + text:SetPoint("left", icon, "right", 5, 0) + text:SetJustifyH("left") + text:SetText("no option selected") + text:SetTextColor(1, 1, 1, 0.4) + DF:SetFontSize(text, 10) f.text = text - - local arrow = f:CreateTexture ("$parent_ArrowTexture2", "OVERLAY") - arrow:SetPoint ("right", f, "right", 5, -1) - arrow:SetBlendMode ("ADD") - arrow:SetTexture ([[Interface\Buttons\UI-ScrollBar-ScrollDownButton-Highlight]]) - arrow:Hide() - arrow:SetSize (32, 28) - f.arrowTexture2 = arrow - - local buttonTexture = f:CreateTexture ("$parent_ArrowTexture", "OVERLAY") - buttonTexture:SetPoint ("right", f, "right", 5, -1) - buttonTexture:SetTexture ([[Interface\Buttons\UI-ScrollBar-ScrollDownButton-Up]]) - buttonTexture:SetSize (32, 28) - f.arrowTexture = buttonTexture - + + local arrowHightlight = f:CreateTexture ("$parent_ArrowTexture2", "OVERLAY", nil, 2) + arrowHightlight:SetPoint ("right", f, "right", 5, -1) + arrowHightlight:SetBlendMode ("ADD") + arrowHightlight:SetTexture ([[Interface\Buttons\UI-ScrollBar-ScrollDownButton-Highlight]]) + arrowHightlight:Hide() + arrowHightlight:SetSize (32, 28) + f.arrowTexture2 = arrowHightlight + + local arrowTexture = f:CreateTexture("$parent_ArrowTexture", "OVERLAY", nil, 1) + arrowTexture:SetPoint("right", f, "right", 5, -1) + arrowTexture:SetTexture([[Interface\Buttons\UI-ScrollBar-ScrollDownButton-Up]]) + arrowTexture:SetSize(32, 28) + f.arrowTexture = arrowTexture + --scripts f:SetScript ("OnSizeChanged", DetailsFrameworkDropDownOnSizeChanged) f:SetScript ("OnMouseDown", DetailsFrameworkDropDownOnMouseDown) - - --on load - f:SetBackdropColor (1, 1, 1, .5) - f.arrowTexture:SetDrawLayer ("OVERLAY", 1) - f.arrowTexture2:SetDrawLayer ("OVERLAY", 2) - + --dropdown - local border = CreateFrame ("frame", "$Parent_Border", f,"BackdropTemplate") + local border = CreateFrame("frame", "$Parent_Border", f, "BackdropTemplate") border:Hide() - border:SetFrameStrata ("FULLSCREEN") - border:SetSize (150, 150) - border:SetPoint ("topleft", f, "bottomleft") - border:SetBackdrop (border_backdrop) - border:SetScript ("OnHide", DetailsFrameworkDropDownOptionsFrameOnHide) - border:SetBackdropColor (0, 0, 0, 0.92) - border:SetBackdropBorderColor (0, 0, 0, 1) + border:SetFrameStrata("FULLSCREEN") + border:SetSize(150, 150) + border:SetPoint("topleft", f, "bottomleft", 0, 0) + border:SetBackdrop(borderBackdrop) + border:SetScript("OnHide", DetailsFrameworkDropDownOptionsFrameOnHide) + border:SetBackdropColor(0, 0, 0, 0.92) + border:SetBackdropBorderColor(0, 0, 0, 1) f.dropdownborder = border - - local scroll = CreateFrame ("ScrollFrame", "$Parent_ScrollFrame", f,"BackdropTemplate") + + local scroll = CreateFrame("ScrollFrame", "$Parent_ScrollFrame", f, "BackdropTemplate") + scroll:SetFrameStrata("FULLSCREEN") + scroll:SetSize(150, 150) + scroll:SetPoint("topleft", f, "bottomleft", 0, 0) scroll:Hide() - scroll:SetFrameStrata ("FULLSCREEN") - scroll:SetSize (150, 150) - scroll:SetPoint ("topleft", f, "bottomleft", 0, 0) f.dropdownframe = scroll - local child = CreateFrame ("frame", "$Parent_ScrollChild", scroll,"BackdropTemplate") - child:SetSize (150, 150) - child:SetPoint ("topleft", scroll, "topleft", 0, 0) - child:SetBackdrop (child_backdrop) + local child = CreateFrame("frame", "$Parent_ScrollChild", scroll, "BackdropTemplate") + child:SetSize(150, 150) + child:SetPoint("topleft", scroll, "topleft", 0, 0) + child:SetBackdrop(childBackdrop) child:SetBackdropColor (0, 0, 0, 1) - local t = child:CreateTexture(nil, "background") - t:SetAllPoints() - t:SetColorTexture(0, 0, 0, 1) - - DF:ApplyStandardBackdrop (child) - - local selected = child:CreateTexture ("$parent_SelectedTexture", "BACKGROUND") - selected:SetSize (150, 16) + local backgroundTexture = child:CreateTexture(nil, "background") + backgroundTexture:SetAllPoints() + backgroundTexture:SetColorTexture(0, 0, 0, 1) + + DF:ApplyStandardBackdrop(child) + + local selected = child:CreateTexture("$parent_SelectedTexture", "BACKGROUND") + selected:SetSize(150, 16) + selected:SetPoint("left", child, "left", 2, 0) + selected:SetTexture([[Interface\RAIDFRAME\Raid-Bar-Hp-Fill]]) selected:Hide() - selected:SetPoint ("left", child, "left", 2, 0) - selected:SetTexture ([[Interface\RAIDFRAME\Raid-Bar-Hp-Fill]]) child.selected = selected - - local mouseover = child:CreateTexture ("$parent_MouseOverTexture", "ARTWORK") - mouseover:SetBlendMode ("ADD") + + local mouseover = child:CreateTexture("$parent_MouseOverTexture", "ARTWORK") + mouseover:SetBlendMode("ADD") + mouseover:SetTexture([[Interface\Buttons\UI-Listbox-Highlight]]) + mouseover:SetSize(150, 15) + mouseover:SetPoint("left", child, "left", 2, 0) mouseover:Hide() - mouseover:SetTexture ([[Interface\Buttons\UI-Listbox-Highlight]]) - mouseover:SetSize (150, 15) - mouseover:SetPoint ("left", child, "left", 2, 0) child.mouseover = mouseover - - scroll:SetScrollChild (child) - tinsert (UISpecialFrames, f.dropdownborder:GetName()) - tinsert (UISpecialFrames, f.dropdownframe:GetName()) - + + scroll:SetScrollChild(child) + tinsert(UISpecialFrames, f.dropdownborder:GetName()) + tinsert(UISpecialFrames, f.dropdownframe:GetName()) + return f end -function DF:CreateDropdownButton (parent, name) +function DF:CreateDropdownButton(parent, name) + local f = CreateFrame("button", name, parent, "BackdropTemplate") + f:SetSize(150, 20) - local f = CreateFrame ("button", name, parent,"BackdropTemplate") - f:SetSize (150, 20) - - local statusbar = f:CreateTexture ("$parent_StatusBarTexture", "ARTWORK") - statusbar:SetPoint ("topleft", f, "topleft", 0, 0) - statusbar:SetPoint ("bottomright", f, "bottomright", 0, 0) - statusbar:SetSize (150, 20) - statusbar:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) + local statusbar = f:CreateTexture("$parent_StatusBarTexture", "ARTWORK") + statusbar:SetPoint("topleft", f, "topleft", 0, 0) + statusbar:SetPoint("bottomright", f, "bottomright", 0, 0) + statusbar:SetTexture([[Interface\Tooltips\UI-Tooltip-Background]]) f.statusbar = statusbar - - local icon = f:CreateTexture ("$parent_IconTexture", "OVERLAY") - icon:SetPoint ("left", f, "left", 2, 0) - icon:SetSize (20, 20) - icon:SetTexture ([[Interface\ICONS\Spell_ChargePositive]]) + + local icon = f:CreateTexture("$parent_IconTexture", "OVERLAY") + icon:SetPoint("left", f, "left", 2, 0) + icon:SetSize(20, 20) + icon:SetTexture([[Interface\ICONS\Spell_ChargePositive]]) f.icon = icon - - local text = f:CreateFontString ("$parent_Text", "OVERLAY", "GameFontHighlightSmall") - text:SetPoint ("left", icon, "right", 5, 0) - text:SetJustifyH ("left") - DF:SetFontSize (text, 10) + + local text = f:CreateFontString("$parent_Text", "OVERLAY", "GameFontHighlightSmall") + text:SetPoint("left", icon, "right", 5, 0) + text:SetJustifyH("left") + DF:SetFontSize(text, 10) f.label = text - - local rightButton = DF:CreateButton(f, function()end, 16, 16, "", 0, 0, "", "rightButton", "$parentRightButton", nil, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + + local rightButton = DF:CreateButton(f, function()end, 16, 16, "", 0, 0, "", "rightButton", "$parentRightButton", nil, DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) rightButton:SetPoint("right", f, "right", -2, 0) rightButton:Hide() - f:SetScript ("OnMouseDown", DetailsFrameworkDropDownOptionClick) - f:SetScript ("OnEnter", DetailsFrameworkDropDownOptionOnEnter) - f:SetScript ("OnLeave", DetailsFrameworkDropDownOptionOnLeave) + f:SetScript("OnMouseDown", DetailsFrameworkDropDownOptionClick) + f:SetScript("OnEnter", DetailsFrameworkDropDownOptionOnEnter) + f:SetScript("OnLeave", DetailsFrameworkDropDownOptionOnLeave) return f end diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index 02211dbf..06199088 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 324 +local dversion = 326 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -439,6 +439,26 @@ function DF.table.reverse (t) return new end +function DF.table.duplicate(t1, t2) + for key, value in pairs(t2) do + if (key ~= "__index" and key ~= "__newindex") then + --preserve a wowObject passing it to the new table with copying it + if (type(value) == "table" and table.GetObjectType and table:GetObjectType()) then + t1[key] = value + + elseif (type (value) == "table") then + t1[key] = t1[key] or {} + DF.table.copy(t1[key], t2[key]) + + else + t1[key] = value + end + end + end + + return t1 +end + --> copy from table2 to table1 overwriting values function DF.table.copy(t1, t2) for key, value in pairs(t2) do @@ -471,6 +491,14 @@ function DF.table.copytocompress(t1, t2) return t1 end +--add the indexes of table2 into table1 +function DF.table.append(t1, t2) + for i = 1, #t2 do + t1[#t1+1] = t2[i] + end + return t1 +end + --> copy values that does exist on table2 but not on table1 function DF.table.deploy (t1, t2) for key, value in pairs (t2) do @@ -774,10 +802,16 @@ local ValidOutlines = { function DF:SetFontOutline (fontString, outline) local fonte, size = fontString:GetFont() if (outline) then - if (ValidOutlines [outline]) then + if (type(outline) == "string") then + outline = outline:upper() + end + + if (ValidOutlines[outline]) then outline = outline - elseif (_type (outline) == "boolean" and outline) then + elseif (type(outline) == "boolean" and outline) then outline = "OUTLINE" + elseif (type(outline) == "boolean" and not outline) then + outline = "NONE" elseif (outline == 1) then outline = "OUTLINE" elseif (outline == 2) then @@ -850,6 +884,21 @@ function DF:CleanTruncateUTF8String(text) return text end +--DF:TruncateNumber(number, fractionDigits): truncate the amount of numbers used to show fraction. +function DF:TruncateNumber(number, fractionDigits) + fractionDigits = fractionDigits or 2 + --local truncatedNumber = format("%." .. fractionDigits .. "f", number) --4x slower than: + --http://lua-users.org/wiki/SimpleRound + local mult = 10 ^ fractionDigits + if (number >= 0) then + truncatedNumber = floor(number * mult + 0.5) / mult + else + truncatedNumber = ceil(number * mult + 0.5) / mult + end + + return truncatedNumber +end + function DF:Msg (msg, ...) print ("|cFFFFFFAA" .. (self.__name or "FW Msg:") .. "|r ", msg, ...) end @@ -1151,7 +1200,37 @@ end IsColorTable = true, } - + + --convert a any format of color to any other format of color + function DF:FormatColor(newFormat, r, g, b, a, decimalsAmount) + r, g, b, a = DF:ParseColors(r, g, b, a) + decimalsAmount = decimalsAmount or 4 + + r = DF:TruncateNumber(r, decimalsAmount) + g = DF:TruncateNumber(g, decimalsAmount) + b = DF:TruncateNumber(b, decimalsAmount) + a = DF:TruncateNumber(a, decimalsAmount) + + if (newFormat == "commastring") then + return r .. ", " .. g .. ", " .. b .. ", " .. a + + elseif (newFormat == "tablestring") then + return "{" .. r .. ", " .. g .. ", " .. b .. ", " .. a .. "}" + + elseif (newFormat == "table") then + return {r, g, b, a} + + elseif (newFormat == "tablemembers") then + return {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = 1} + + elseif (newFormat == "numbers") then + return r, g, b, a + + elseif (newFormat == "hex") then + return format("%.2x%.2x%.2x%.2x", a * 255, r * 255, g * 255, b * 255) + end + end + function DF:CreateColorTable (r, g, b, a) local t = { r = r or 1, @@ -1167,53 +1246,69 @@ end return DF.alias_text_colors [color] end - local tn = tonumber - function DF:ParseColors (_arg1, _arg2, _arg3, _arg4) - if (_type (_arg1) == "table") then - if (_arg1.IsColorTable) then - return _arg1:GetColor() - - elseif (not _arg1[1] and _arg1.r) then - _arg1, _arg2, _arg3, _arg4 = _arg1.r, _arg1.g, _arg1.b, _arg1.a - + function DF:ParseColors (red, green, blue, alpha) + local firstParameter = red + + --the first value passed is a table? + if (type(firstParameter) == "table") then + local colorTable = red + + if (colorTable.IsColorTable) then + --using colorTable mixin + return colorTable:GetColor() + + elseif (not colorTable[1] and colorTable.r) then + --{["r"] = 1, ["g"] = 1, ["b"] = 1} + red, green, blue, alpha = colorTable.r, colorTable.g, colorTable.b, colorTable.a + else - _arg1, _arg2, _arg3, _arg4 = _unpack (_arg1) + --{1, .7, .2, 1} + red, green, blue, alpha = unpack(colorTable) end - - elseif (_type (_arg1) == "string") then - - if (string.find (_arg1, "#")) then - _arg1 = _arg1:gsub ("#","") - if (string.len (_arg1) == 8) then --alpha - _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, tn ("0x" .. _arg1:sub (7, 8))/255, tn ("0x" .. _arg1:sub (1, 2))/255 + + --the first value passed is a string? + elseif (type(firstParameter) == "string") then + local colorString = red + --hexadecimal + if (string.find(colorString, "#")) then + colorString = colorString:gsub("#","") + if (string.len(colorString) == 8) then --with alpha + red, green, blue, alpha = tonumber("0x" .. colorString:sub(3, 4))/255, tonumber("0x" .. colorString:sub(5, 6))/255, tonumber("0x" .. colorString:sub(7, 8))/255, tonumber("0x" .. colorString:sub(1, 2))/255 else - _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (1, 2))/255, tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, 1 + red, green, blue, alpha = tonumber("0x" .. colorString:sub(1, 2))/255, tonumber("0x" .. colorString:sub(3, 4))/255, tonumber("0x" .. colorString:sub(5, 6))/255, 1 end - else - local color = DF.alias_text_colors [_arg1] - if (color) then - _arg1, _arg2, _arg3, _arg4 = _unpack (color) + --name of the color + local colorTable = DF.alias_text_colors[colorString] + if (colorTable) then + red, green, blue, alpha = unpack(colorTable) + + --string with number separated by comma + elseif (colorString:find(",")) then + local r, g, b, a = strsplit(",", colorString) + red, green, blue, alpha = tonumber(r), tonumber(g), tonumber(b), tonumber(a) + else - _arg1, _arg2, _arg3, _arg4 = _unpack (DF.alias_text_colors.none) + --no color found within the string, return default color + red, green, blue, alpha = unpack(DF.alias_text_colors.none) end end end - - if (not _arg1) then - _arg1 = 1 + + if (not red or type(red) ~= "number") then + red = 1 end - if (not _arg2) then - _arg2 = 1 + if (not green) or type(green) ~= "number" then + green = 1 end - if (not _arg3) then - _arg3 = 1 + if (not blue or type(blue) ~= "number") then + blue = 1 end - if (not _arg4) then - _arg4 = 1 + if (not alpha or type(alpha) ~= "number") then + alpha = 1 end - - return _arg1, _arg2, _arg3, _arg4 + + return red, green, blue, alpha end ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -2391,7 +2486,7 @@ function DF:GetBestFontForLanguage (language, western, cyrillic, china, korean, end if (language == "enUS" or language == "deDE" or language == "esES" or language == "esMX" or language == "frFR" or language == "itIT" or language == "ptBR") then - return western or "Accidental Presidency" + return western or "Friz Quadrata TT" elseif (language == "ruRU") then return cyrillic or "Arial Narrow" @@ -3152,6 +3247,7 @@ function DF:CreateGlowOverlay (parent, antsColor, glowColor) glowFrame.GlowColor = {r, g, b, a} glowFrame.outerGlow:SetScale (1.2) + glowFrame:EnableMouse(false) return glowFrame end @@ -3693,6 +3789,10 @@ function DF:GetCurrentSpec() end end +function DF:GetCurrentSpecId() + return DF:GetCurrentSpec() +end + local specs_per_class = { ["DEMONHUNTER"] = {577, 581}, ["DEATHKNIGHT"] = {250, 251, 252}, @@ -3733,18 +3833,21 @@ function DF:QuickDispatch (func, ...) return true end -function DF:Dispatch (func, ...) +function DF:Dispatch(func, ...) if (type (func) ~= "function") then - return dispatch_error (_, "Dispatch required a function.") + return dispatch_error (_, "DF:Dispatch expect a function as parameter 1.") end - local okay, result1, result2, result3, result4 = xpcall (func, geterrorhandler(), ...) - + local dispatchResult = {xpcall (func, geterrorhandler(), ...)} + local okay = dispatchResult[1] + if (not okay) then return nil end - - return result1, result2, result3, result4 + + tremove(dispatchResult, 1) + + return unpack(dispatchResult) end --[=[ @@ -3900,7 +4003,7 @@ end --> store and return a list of character races, always return the non-localized value DF.RaceCache = {} -function DF:GetCharacterRaceList (fullList) +function DF:GetCharacterRaceList() if (next (DF.RaceCache)) then return DF.RaceCache end @@ -3908,13 +4011,13 @@ function DF:GetCharacterRaceList (fullList) for i = 1, 100 do local raceInfo = C_CreatureInfo.GetRaceInfo (i) if (raceInfo and DF.RaceList [raceInfo.raceID]) then - tinsert (DF.RaceCache, {Name = raceInfo.raceName, FileString = raceInfo.clientFileString}) + tinsert (DF.RaceCache, {Name = raceInfo.raceName, FileString = raceInfo.clientFileString, ID = raceInfo.raceID}) end if IS_WOW_PROJECT_MAINLINE then local alliedRaceInfo = C_AlliedRaces.GetRaceInfoByID (i) if (alliedRaceInfo and DF.AlliedRaceList [alliedRaceInfo.raceID]) then - tinsert (DF.RaceCache, {Name = alliedRaceInfo.maleName, FileString = alliedRaceInfo.raceFileString}) + tinsert (DF.RaceCache, {Name = alliedRaceInfo.maleName, FileString = alliedRaceInfo.raceFileString, ID = alliedRaceInfo.raceID}) end end end @@ -4046,6 +4149,11 @@ function DF:AddRoleIconToText(text, role, size) return text end +function DF:GetRoleTCoordsAndTexture(roleID) + local texture, l, r, t, b = DF:GetRoleIconAndCoords(roleID) + return l, r, t, b, texture +end + -- TODO: maybe make this auto-generaded some day?... DF.CLEncounterID = { {ID = 2423, Name = "The Tarragrue"}, @@ -4243,6 +4351,10 @@ DF.BattlegroundSizes = { [1803] = 10, --Seething Shore } +function DF:GetBattlegroundSize(instanceInfoMapId) + return DF.BattlegroundSizes[instanceInfoMapId] +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --> execute range @@ -4340,6 +4452,10 @@ function GetWorldDeltaSeconds() return deltaTimeFrame.deltaTime end +function DF:GetWorldDeltaSeconds() + return deltaTimeFrame.deltaTime +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --> build the global script channel for scripts communication --send and retrieve data sent by othe users in scripts @@ -4368,6 +4484,7 @@ end if (Ambiguate (sourceName, "none") == commSource) then local func = DF.RegisteredScriptsComm [ID] if (func) then + DF:MakeFunctionSecure(func) DF:Dispatch (func, commSource, select (5, unpack (data))) --this use xpcall end end @@ -4449,7 +4566,7 @@ do if (object) then tinsert(self.inUse, object) if (self.onAcquire) then - local result, errortext = pcall(self.onAcquire, object) + DF:QuickDispatch(self.onAcquire, object) end return object, false else @@ -4458,7 +4575,7 @@ do if (newObject) then tinsert(self.inUse, newObject) if (self.onAcquire) then - local result, errortext = pcall(self.onAcquire, object) + DF:QuickDispatch(self.onAcquire, object) end return newObject, true end @@ -4474,6 +4591,10 @@ do if (self.inUse[i] == object) then tremove(self.inUse, i) tinsert(self.notUse, object) + + if (self.onRelease) then + DF:QuickDispatch(self.onRelease, object) + end break end end @@ -4485,7 +4606,7 @@ do tinsert(self.notUse, object) if (self.onReset) then - local result, errortext = pcall(self.onReset, object) + DF:QuickDispatch(self.onReset, object) end end end @@ -4519,12 +4640,24 @@ do Hide = hide, Show = show, GetAmount = getamount, + + SetCallbackOnRelease = function(self, func) + self.onRelease = func + end, + SetOnReset = function(self, func) self.onReset = func end, + SetCallbackOnReleaseAll = function(self, func) + self.onReset = func + end, + SetOnAcquire = function(self, func) self.onAcquire = func end, + SetCallbackOnGet = function(self, func) + self.onAcquire = func + end, } function DF:CreatePool(func, ...) @@ -4573,7 +4706,7 @@ end --block run code inside code ["RunScript"] = true, ["securecall"] = true, - ["getfenv"] = true, + ["setfenv"] = true, ["getfenv"] = true, ["loadstring"] = true, ["pcall"] = true, @@ -4662,6 +4795,10 @@ end _G.setfenv(func, newEnvironment) end + function DF:MakeFunctionSecure(func) + return DF:SetEnvironment(func) + end + ----------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Libs/DF/load.xml b/Libs/DF/load.xml index 9f3ff11a..a1d04971 100644 --- a/Libs/DF/load.xml +++ b/Libs/DF/load.xml @@ -2,6 +2,7 @@