From d13d14732475bd2922b6f7649e9458d6326fa1ce Mon Sep 17 00:00:00 2001 From: Continuity Date: Mon, 19 Feb 2024 15:57:12 +0100 Subject: [PATCH] - DF lib update --- Plater_ChangeLog.lua | 1 + libs/DF/definitions.lua | 7 ++- libs/DF/fw.lua | 91 ++++++++++++++++++++++++-------- libs/DF/picture.lua | 114 +++++++++++++++++++++++++++++----------- 4 files changed, 159 insertions(+), 54 deletions(-) diff --git a/Plater_ChangeLog.lua b/Plater_ChangeLog.lua index cfae4f2d..6ece82cc 100644 --- a/Plater_ChangeLog.lua +++ b/Plater_ChangeLog.lua @@ -8,6 +8,7 @@ function Plater.GetChangelogTable() if (not Plater.ChangeLogTable) then Plater.ChangeLogTable = { + {1708341442, "Bug Fix", "February 19th, 2024", "Fixing interrupt animation being enabled to break following cast bars.", "cont1nuity"}, {1708341442, "Bug Fix", "February 19th, 2024", "Fixing consolidated auras sometimes not showing properly when sorting for longest duration.", "cont1nuity"}, {1708341442, "Bug Fix", "February 8th, 2024", "Fixing DK rune visuals not updating properly when on cooldown (for real this time).", "cont1nuity"}, {1708341442, "Bug Fix", "February 7th, 2024", "Fixing backup range check error in SoD.", "cont1nuity"}, diff --git a/libs/DF/definitions.lua b/libs/DF/definitions.lua index 934fddae..6591eb7f 100644 --- a/libs/DF/definitions.lua +++ b/libs/DF/definitions.lua @@ -144,7 +144,7 @@ ---@field GetColorHue fun(self:table, r:number, g:number, b:number) : number return the hue of a color from red to blue to green to yellow and back to red ---@field IsHtmlColor fun(self:table, colorName:any) : unknown return true if DF.alias_text_colors has the colorName as a key ---@field CreateColorTable fun(self:table, r:number, g:number, b:number, a:number) : table return a table with {r, g, b, a} ----@field FormatColor fun(self:table, newFormat:string, r:number|string, g:number?, b:number?, a:number?, decimalsAmount:number?) : string|table|number|nil, number|nil, number|nil, number|nil takes in a color in one format and converts it to another specified format. +---@field FormatColor fun(self:table, newFormat:string, r:number|string|table, g:number?, b:number?, a:number?, decimalsAmount:number?) : string|table|number|nil, number|nil, number|nil, number|nil takes in a color in one format and converts it to another specified format. ---@field CreateEditor fun(self:table, parent:frame, name:string?, options:df_editor_defaultoptions?) : df_editor ---@field RandomBool fun(self:table, odds: number?) : boolean return a random boolean ---@field CreateHighlightTexture fun(self:table, parent:frame, parentKey:string?, alpha:number?, name:string?) : texture @@ -152,7 +152,10 @@ ---@field CreateColorPickButton fun(self:table, parent:frame, name:string?, member:string?, callback:function, alpha:number?, buttonTemplate:table?) : df_button ---@field CreateSlider fun(self:table, parent:frame, width:number?, height:number?, minValue:number?, maxValue:number?, step:number?, defaultv:number?, isDecemal:boolean?, member:string?, name:string?, label:string?, sliderTemplate:string|table?, labelTemplate:string|table?) : df_slider, df_label? ---@field CreateFrameContainer fun(self:table, parent:frame, options:table?, frameName:string?) : df_framecontainer create a frame container, which is a frame that envelops another frame, and can be moved, resized, etc. ----@field +---@field CreateAnimation fun(self:table, animationGroup:animationgroup, animationType:animationtype, order:number, duration:number, arg1:any, arg2:any, arg3:any, arg4:any, arg5:any, arg6:any, arg7:any, arg8:any) : animation +---@field CreateTexture fun(self:table, parent:frame, texture:atlasname|texturepath|textureid|nil, width:number?, height:number?, layer:drawlayer?, coords:table?, member:string?, name:string?) : df_image +---@field CreateFrameShake fun(self:table, parent:uiobject, duration:number?, amplitude:number?, frequency:number?, absoluteSineX:boolean?, absoluteSineY:boolean?, scaleX:number?, scaleY:number?, fadeInTime:number?, fadeOutTime:number?, anchorPoints:table?) : df_frameshake +---@field SetTexCoordFromAtlasInfo fun(self:table, texture:texture, atlasInfo:atlasinfo) : nil ---@field diff --git a/libs/DF/fw.lua b/libs/DF/fw.lua index 9b1e830b..8985c9a2 100644 --- a/libs/DF/fw.lua +++ b/libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 512 +local dversion = 514 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary(major, minor) @@ -522,6 +522,10 @@ function DF:RandomBool(odds) end end +function DF:SetTexCoordFromAtlasInfo(texture, atlasInfo) + texture:SetTexCoord(atlasInfo.leftTexCoord, atlasInfo.rightTexCoord, atlasInfo.topTexCoord, atlasInfo.bottomTexCoord) +end + ------------------------------------------------------------------------------------------------------------ --table @@ -2061,16 +2065,16 @@ end IsColorTable = true, } - --takes in a color in one format and converts it to another specified format. - --here are the parameters it accepts: - --newFormat (string): The format to convert the color to. It can be one of the following: "commastring", "tablestring", "table", "tablemembers", "numbers", "hex". - --r (number|string): The red component of the color or a string representing the color. - --g (number|nil): The green component of the color. This is optional if r is a string. - --b (number|nil): The blue component of the color. This is optional if r is a string. - --a (number|nil): The alpha component of the color. This is optional and defaults to 1 if not provided. - --decimalsAmount (number|nil): The number of decimal places to round the color components to. This is optional and defaults to 4 if not provided. - --The function returns the color in the new format. The return type depends on the newFormat parameter. It can be a string, a table, or four separate number values (for the "numbers" format). - --For the "hex" format, it returns a string representing the color in hexadecimal format. + ---* takes in a color in one format and converts it to another specified format. + ---* here are the parameters it accepts: + ---* newFormat (string): The format to convert the color to. It can be one of the following: "commastring", "tablestring", "table", "tablemembers", "numbers", "hex". + ---* r (number|string): The red component of the color or a string representing the color. + ---* g (number|nil): The green component of the color. This is optional if r is a string. + ---* b (number|nil): The blue component of the color. This is optional if r is a string. + ---* a (number|nil): The alpha component of the color. This is optional and defaults to 1 if not provided. + ---* decimalsAmount (number|nil): The number of decimal places to round the color components to. This is optional and defaults to 4 if not provided. + ---* The function returns the color in the new format. The return type depends on the newFormat parameter. It can be a string, a table, or four separate number values (for the "numbers" format). + ---* For the "hex" format, it returns a string representing the color in hexadecimal format. ---@param newFormat string ---@param r number|string ---@param g number|nil @@ -2844,9 +2848,30 @@ function DF:CreateAnimationHub(parent, onPlay, onFinished) return newAnimation end -function DF:CreateAnimation(animation, animationType, order, duration, arg1, arg2, arg3, arg4, arg5, arg6, arg7) - local anim = animation:CreateAnimation(animationType) - anim:SetOrder(order or animation.NextAnimation) +---* Create a new animation for an animation hub or group. +---* Alpha: CreateAnimation(animGroup, "Alpha", order, duration, fromAlpha, toAlpha). +---* Scale: CreateAnimation(animGroup, "Scale", order, duration, fromScaleX, fromScaleY, toScaleX, toScaleY, originPoint, x, y). +---* Translation: CreateAnimation(animGroup, "Translation", order, duration, xOffset, yOffset). +---* Rotation: CreateAnimation(animGroup, "Rotation", order, duration, degrees, originPoint, x, y). +---* Path: CreateAnimation(animGroup, "Path", order, duration, xOffset, yOffset, curveType). +---* VertexColor: CreateAnimation(animGroup, "VertexColor", order, duration, r1, g1, b1, a1, r2, g2, b2, a2). +---@param animationGroup animationgroup +---@param animationType animationtype +---@param order number +---@param duration number +---@param arg1 any +---@param arg2 any +---@param arg3 any +---@param arg4 any +---@param arg5 any +---@param arg6 any +---@param arg7 any +---@param arg8 any +---@return animation +function DF:CreateAnimation(animationGroup, animationType, order, duration, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + ---@type animation + local anim = animationGroup:CreateAnimation(animationType) + anim:SetOrder(order or animationGroup.NextAnimation) anim:SetDuration(duration) animationType = string.upper(animationType) @@ -2871,9 +2896,33 @@ function DF:CreateAnimation(animation, animationType, order, duration, arg1, arg elseif (animationType == "TRANSLATION") then anim:SetOffset(arg1, arg2) + + elseif (animationType == "PATH") then + local newControlPoint = anim:CreateControlPoint() + anim:SetCurveType(arg4 or "SMOOTH") + newControlPoint:SetOffset(arg2, arg3) + newControlPoint:SetOrder(#anim:GetControlPoints()) + + elseif (animationType == "VERTEXCOLOR" or animationType == "COLOR") then + local r1, g1, b1, a1 = arg1, arg2, arg3, arg4 + local r2, g2, b2, a2 = arg5, arg6, arg7, arg8 + + if ((type(r1) == "table" or type(r1) == "string") and (type(g1) == "table" or type(g1) == "string")) then + r2, g2, b2, a2 = DF:ParseColors(g1) + r1, g1, b1, a1 = DF:ParseColors(r1) + + elseif ((type(r1) == "table" or type(r1) == "string")) then + r1, g1, b1, a1 = DF:ParseColors(r1) + + elseif ((type(r2) == "table" or type(r2) == "string")) then + r2, g2, b2, a2 = DF:ParseColors(r2) + end + + anim:SetStartColor(CreateColor(r1, g1, b1, a1)) + anim:SetEndColor(CreateColor(r2, g2, b2, a2)) end - animation.NextAnimation = animation.NextAnimation + 1 + animationGroup.NextAnimation = animationGroup.NextAnimation + 1 return anim end @@ -3117,7 +3166,7 @@ local frameshake_play = function(parent, shakeObject, scaleDirection, scaleAmpli --update the amount of shake running on this frame parent.__frameshakes.enabled = parent.__frameshakes.enabled + 1 - if (not parent:GetScript("OnUpdate")) then + if (not parent:HasScript("OnUpdate")) then parent:SetScript("OnUpdate", function()end) end end @@ -3151,7 +3200,7 @@ local frameshake_SetConfig = function(parent, shakeObject, duration, amplitude, shakeObject.OriginalDuration = shakeObject.Duration end ----@class frameshake : table +---@class df_frameshake : table ---@field Amplitude number ---@field Frequency number ---@field Duration number @@ -3168,9 +3217,9 @@ end ---@field OriginalFrequency number ---@field OriginalAmplitude number ---@field OriginalDuration number ----@field PlayFrameShake fun(parent:uiobject, shakeObject:frameshake, scaleDirection:number?, scaleAmplitude:number?, scaleFrequency:number?, scaleDuration:number?) ----@field StopFrameShake fun(parent:uiobject, shakeObject:frameshake) ----@field SetFrameShakeSettings fun(parent:uiobject, shakeObject:frameshake, duration:number?, amplitude:number?, frequency:number?, absoluteSineX:boolean?, absoluteSineY:boolean?, scaleX:number?, scaleY:number?, fadeInTime:number?, fadeOutTime:number?) +---@field PlayFrameShake fun(parent:uiobject, shakeObject:df_frameshake, scaleDirection:number?, scaleAmplitude:number?, scaleFrequency:number?, scaleDuration:number?) +---@field StopFrameShake fun(parent:uiobject, shakeObject:df_frameshake) +---@field SetFrameShakeSettings fun(parent:uiobject, shakeObject:df_frameshake, duration:number?, amplitude:number?, frequency:number?, absoluteSineX:boolean?, absoluteSineY:boolean?, scaleX:number?, scaleY:number?, fadeInTime:number?, fadeOutTime:number?) ---create a frame shake object ---@param parent uiobject @@ -3184,7 +3233,7 @@ end ---@param fadeInTime number? ---@param fadeOutTime number? ---@param anchorPoints table? ----@return frameshake +---@return df_frameshake function DF:CreateFrameShake(parent, duration, amplitude, frequency, absoluteSineX, absoluteSineY, scaleX, scaleY, fadeInTime, fadeOutTime, anchorPoints) --create the shake table local frameShake = { diff --git a/libs/DF/picture.lua b/libs/DF/picture.lua index 24915a3a..c1860c6f 100644 --- a/libs/DF/picture.lua +++ b/libs/DF/picture.lua @@ -226,9 +226,16 @@ detailsFramework:Mixin(ImageMetaFunctions, detailsFramework.ScriptHookMixin) end end - function ImageMetaFunctions:SetGradient(gradientType, fromColor, toColor) + function ImageMetaFunctions:SetGradient(gradientType, fromColor, toColor, bInvert) fromColor = detailsFramework:FormatColor("tablemembers", fromColor) toColor = detailsFramework:FormatColor("tablemembers", toColor) + + if (bInvert) then + local temp = fromColor + fromColor = toColor + toColor = temp + end + self.image:SetGradient(gradientType, fromColor, toColor) end @@ -238,34 +245,50 @@ detailsFramework:Mixin(ImageMetaFunctions, detailsFramework.ScriptHookMixin) ---@class df_image : texture ---@field SetGradient fun(gradientType: "vertical"|"horizontal", fromColor: table, toColor: table) + ---@class df_gradienttable : table + ---@field gradient "vertical"|"horizontal" + ---@field fromColor table|string + ---@field toColor table|string + ---@field invert boolean? + ---create an object that encapsulates a texture and add additional methods to it ---@param parent frame - ---@param texture texturepath|textureid - ---@param width number - ---@param height number - ---@param layer drawlayer - ---@param coords {key1: number, key2: number, key3: number, key4: number} - ---@param member string - ---@param name string - ---@return table|nil + ---@param texture texturepath|textureid|df_gradienttable|nil + ---@param width number? + ---@param height number? + ---@param layer drawlayer? + ---@param coords {key1: number, key2: number, key3: number, key4: number}? + ---@param member string? + ---@param name string? + ---@return df_image function detailsFramework:CreateTexture(parent, texture, width, height, layer, coords, member, name) return detailsFramework:NewImage(parent, texture, width, height, layer, coords, member, name) end ---create an object that encapsulates a texture and add additional methods to it ---@param parent frame - ---@param texture texturepath|textureid - ---@param width number - ---@param height number - ---@param layer drawlayer - ---@param coords {key1: number, key2: number, key3: number, key4: number} - ---@param member string - ---@param name string - ---@return table|nil + ---@param texture texturepath|textureid|df_gradienttable|nil + ---@param width number? + ---@param height number? + ---@param layer drawlayer? + ---@param coords {key1: number, key2: number, key3: number, key4: number}? + ---@param member string? + ---@param name string? + ---@return df_image function detailsFramework:CreateImage(parent, texture, width, height, layer, coords, member, name) return detailsFramework:NewImage(parent, texture, width, height, layer, coords, member, name) end + ---create an object that encapsulates a texture and add additional methods to it + ---@param parent frame + ---@param texture texturepath|textureid|df_gradienttable|nil + ---@param width number? + ---@param height number? + ---@param layer drawlayer? + ---@param texCoord {key1: number, key2: number, key3: number, key4: number}? + ---@param member string? + ---@param name string? + ---@return df_image function detailsFramework:NewImage(parent, texture, width, height, layer, texCoord, member, name) if (not parent) then return error("DetailsFrameWork: NewImage() parent not found.", 2) @@ -313,26 +336,45 @@ detailsFramework:Mixin(ImageMetaFunctions, detailsFramework.ScriptHookMixin) ImageObject.image.MyObject = ImageObject - if (width) then - ImageObject.image:SetWidth(width) - end - if (height) then - ImageObject.image:SetHeight(height) - end - if (texture) then if (type(texture) == "table") then if (texture.gradient) then + ---@type df_gradienttable + local gradientTable = texture + if (detailsFramework.IsDragonflight() or detailsFramework.IsNonRetailWowWithRetailAPI()) then ImageObject.image:SetColorTexture(1, 1, 1, 1) - local fromColor = detailsFramework:FormatColor("tablemembers", texture.fromColor) - local toColor = detailsFramework:FormatColor("tablemembers", texture.toColor) - ImageObject.image:SetGradient(texture.gradient, fromColor, toColor) + local fromColor = detailsFramework:FormatColor("tablemembers", gradientTable.fromColor) + local toColor = detailsFramework:FormatColor("tablemembers", gradientTable.toColor) + + if (gradientTable.invert) then + local temp = fromColor + fromColor = toColor + toColor = temp + end + + ImageObject.image:SetGradient(gradientTable.gradient, fromColor, toColor) else - local fromR, fromG, fromB, fromA = detailsFramework:ParseColors(texture.fromColor) - local toR, toG, toB, toA = detailsFramework:ParseColors(texture.toColor) + local fromR, fromG, fromB, fromA = detailsFramework:ParseColors(gradientTable.fromColor) + local toR, toG, toB, toA = detailsFramework:ParseColors(gradientTable.toColor) + + if (gradientTable.invert) then + local temp = fromR + fromR = toR + toR = temp + temp = fromG + fromG = toG + toG = temp + temp = fromB + fromB = toB + toB = temp + temp = fromA + fromA = toA + toA = temp + end + ImageObject.image:SetColorTexture(1, 1, 1, 1) - ImageObject.image:SetGradientAlpha(texture.gradient, fromR, fromG, fromB, fromA, toR, toG, toB, toA) + ImageObject.image:SetGradientAlpha(gradientTable.gradient, fromR, fromG, fromB, fromA, toR, toG, toB, toA) end else local r, g, b, a = detailsFramework:ParseColors(texture) @@ -352,7 +394,10 @@ detailsFramework:Mixin(ImageMetaFunctions, detailsFramework.ScriptHookMixin) end end else - ImageObject.image:SetTexture(texture) + local textureType = type(texture) + if (textureType == "string" or textureType == "number") then + ImageObject.image:SetTexture(texture) + end end end @@ -360,6 +405,13 @@ detailsFramework:Mixin(ImageMetaFunctions, detailsFramework.ScriptHookMixin) ImageObject.image:SetTexCoord(unpack(texCoord)) end + if (width) then + ImageObject.image:SetWidth(width) + end + if (height) then + ImageObject.image:SetHeight(height) + end + ImageObject.HookList = { }