feat: Added quad-custom property tweening (such as roundSize,paddingAllOffset and so on)
class.lua
Added getProperty method that allow user to get custom property value. this method is used on atween
Refactored setProperty method
Now register:tween{} can add Ended, OnStepped. argments are same with atween but added item(pointing it self) as first argment
round.lua
Added getRound, getOutline method, this method is used on getProperty
atween/index.lua
Added Setter,Getter option on runTween/s
This commit is contained in:
parent
39f9d8c972
commit
e10170958a
4 changed files with 115 additions and 42 deletions
0
README.md
Normal file
0
README.md
Normal file
|
|
@ -26,37 +26,67 @@ function module.init(shared)
|
||||||
local round = shared.round; ---@module "src.libs.round"
|
local round = shared.round; ---@module "src.libs.round"
|
||||||
|
|
||||||
local function InstanceNewWithName(classname,parent,name)
|
local function InstanceNewWithName(classname,parent,name)
|
||||||
local item = InstanceNew(classname,parent)
|
local item = InstanceNew(classname,parent);
|
||||||
item.Name = name
|
item.Name = name;
|
||||||
return item
|
return item;
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: refactor getProperty
|
||||||
|
-- local propertyGetterRaw = {}
|
||||||
|
-- local propertySetterRaw = {}
|
||||||
|
|
||||||
|
local function getProperty(item,index,ClassName)
|
||||||
|
if type(item) == "table" then return item[index]; end
|
||||||
|
ClassName = ClassName or item.ClassName;
|
||||||
|
local isImage = (ClassName == "ImageLabel" or ClassName == "ImageButton");
|
||||||
|
if (index == "RoundSize" or index == "roundSize") and isImage then
|
||||||
|
if not round then
|
||||||
|
error("module 'round' needs to be loaded for get image round size but it is not found on 'src.libs'. you should adding that to src.libs directory");
|
||||||
|
end
|
||||||
|
return round.getRound(item);
|
||||||
|
elseif index == "UiRoundSize" or index == "uiRoundSize" or index == "UIRoundSize" then
|
||||||
|
local target = (ClassName == "UICorner" and item) or item:FindFirstChildOfClass("UICorner");
|
||||||
|
return (target and target.CornerRadius.Offset) or 0;
|
||||||
|
elseif index == "PaddingAll" or index == "paddingAll" then
|
||||||
|
local target = (ClassName == "UIPadding" and item) or item:FindFirstChildOfClass("UIPadding");
|
||||||
|
return (target and target.PaddingLeft) or UDim.new(0,0);
|
||||||
|
elseif index == "PaddingAllOffset" or index == "paddingAllOffset" then
|
||||||
|
local target = (ClassName == "UIPadding" and item) or item:FindFirstChildOfClass("UIPadding");
|
||||||
|
return (target and target.PaddingLeft.Offset) or 0;
|
||||||
|
elseif index == "Scale" then
|
||||||
|
local target = (ClassName == "UIScale" and item) or item:FindFirstChildOfClass("UIScale");
|
||||||
|
return (target and target.Scale) or 1;
|
||||||
|
end
|
||||||
|
return item[index];
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setProperty(item,index,value,ClassName)
|
local function setProperty(item,index,value,ClassName)
|
||||||
|
if type(item) == "table" then item[index] = value; return; end
|
||||||
ClassName = ClassName or item.ClassName;
|
ClassName = ClassName or item.ClassName;
|
||||||
local isImage = (ClassName == "ImageLabel" or ClassName == "ImageButton");
|
local isImage = (ClassName == "ImageLabel" or ClassName == "ImageButton");
|
||||||
if (index == "roundSize" or index == "RoundSize") and isImage then
|
if (index == "RoundSize" or index == "roundSize") and isImage then
|
||||||
if not round then
|
if not round then
|
||||||
warn "module 'round' needs to be loaded for set images round size but it is not found on 'src.libs'. you should adding that to src.libs directory"
|
error("module 'round' needs to be loaded for set image round size but it is not found on 'src.libs'. you should adding that to src.libs directory");
|
||||||
end
|
end
|
||||||
round.setRound(item,value);
|
round.setRound(item,value);
|
||||||
elseif index == "uiRoundSize" or index == "UIRoundSize" then
|
elseif index == "UiRoundSize" or index == "uiRoundSize" or index == "UIRoundSize" then
|
||||||
local uiCorner = item:FindFirstChildOfClass("UICorner") or InstanceNewWithName("UICorner",item,"_quad_round");
|
local uiCorner = (ClassName == "UICorner" and item) or item:FindFirstChildOfClass("UICorner") or InstanceNewWithName("UICorner",item,"_quad_round");
|
||||||
uiCorner.CornerRadius = UDim.new(0,value);
|
uiCorner.CornerRadius = UDim.new(0,value);
|
||||||
elseif index == "PaddingAll" or index == "paddingAll" then
|
elseif index == "PaddingAll" or index == "paddingAll" then
|
||||||
local target = ClassName == "UIPadding" and item or (item:FindFirstChildOfClass("UIPadding") or InstanceNewWithName("UIPadding",item,"_quad_padding"));
|
local target = (ClassName == "UIPadding" and item) or item:FindFirstChildOfClass("UIPadding") or InstanceNewWithName("UIPadding",item,"_quad_padding");
|
||||||
target.PaddingLeft = value;
|
target.PaddingLeft = value;
|
||||||
target.PaddingRight = value;
|
target.PaddingRight = value;
|
||||||
target.PaddingTop = value;
|
target.PaddingTop = value;
|
||||||
target.PaddingBottom = value;
|
target.PaddingBottom = value;
|
||||||
elseif index == "PaddingAllOffset" or index == "PaddingAllOffset" then
|
elseif index == "PaddingAllOffset" or index == "paddingAllOffset" then
|
||||||
local target = ClassName == "UIPadding" and item or (item:FindFirstChildOfClass("UIPadding") or InstanceNewWithName("UIPadding",item,"_quad_padding"));
|
local target = (ClassName == "UIPadding" and item) or item:FindFirstChildOfClass("UIPadding") or InstanceNewWithName("UIPadding",item,"_quad_padding");
|
||||||
local padding = UDim.new(0,value);
|
local padding = UDim.new(0,value);
|
||||||
target.PaddingLeft = padding;
|
target.PaddingLeft = padding;
|
||||||
target.PaddingRight = padding;
|
target.PaddingRight = padding;
|
||||||
target.PaddingTop = padding;
|
target.PaddingTop = padding;
|
||||||
target.PaddingBottom = padding;
|
target.PaddingBottom = padding;
|
||||||
elseif index == "Scale" then
|
elseif index == "Scale" then
|
||||||
local target = ClassName == "UIScale" and item or (item:FindFirstChildOfClass("UIScale") or InstanceNewWithName("UIScale",item,"_quad_scale"));
|
local target = (ClassName == "UIScale" and item) or item:FindFirstChildOfClass("UIScale") or InstanceNewWithName("UIScale",item,"_quad_scale");
|
||||||
target.Scale = value;
|
target.Scale = value;
|
||||||
else
|
else
|
||||||
item[index] = value; -- set property
|
item[index] = value; -- set property
|
||||||
|
|
@ -156,7 +186,18 @@ function module.init(shared)
|
||||||
if not advancedTween then
|
if not advancedTween then
|
||||||
return warn "module 'AdvancedTween' needs to be loaded for tween properties but it is not found on 'src.libs'. you should adding that to src.libs directory";
|
return warn "module 'AdvancedTween' needs to be loaded for tween properties but it is not found on 'src.libs'. you should adding that to src.libs directory";
|
||||||
end
|
end
|
||||||
advancedTween.RunTween(item,tween,{[index] = newValue});
|
local ended, onStepped;
|
||||||
|
if tween.Ended then
|
||||||
|
ended = function (...)
|
||||||
|
tween.Ended(item,...);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if tween.OnStepped then
|
||||||
|
onStepped = function (...)
|
||||||
|
tween.OnStepped(item,...);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
advancedTween.RunTween(item,tween,{[index] = newValue},ended,onStepped,setProperty,getProperty);
|
||||||
else
|
else
|
||||||
setProperty(item,index,newValue,ClassName);
|
setProperty(item,index,newValue,ClassName);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,20 @@ local DefaultItems = {
|
||||||
|
|
||||||
-- 예전 값,목표 값,알파를 주고 각각 해당하는 속성에 입력해줌
|
-- 예전 값,목표 값,알파를 주고 각각 해당하는 속성에 입력해줌
|
||||||
-- 기본적으로 모든 속성값 적용은 여기에서 이루워짐
|
-- 기본적으로 모든 속성값 적용은 여기에서 이루워짐
|
||||||
function LerpProperties(Item,Old,New,Alpha)
|
function LerpProperties(Item,Old,New,Alpha,Setter)
|
||||||
for Property,OldValue in pairs(Old) do
|
for Property,OldValue in pairs(Old) do
|
||||||
local NewValue = New[Property]
|
local NewValue = New[Property]
|
||||||
if NewValue ~= nil then
|
|
||||||
local Type = type(OldValue)
|
local Type = type(OldValue)
|
||||||
if DefaultItems[Type] then
|
local Value
|
||||||
|
if Type ~= type(NewValue) then
|
||||||
|
error(
|
||||||
|
("Unable to lerp property '%s' of '%s' due to type invalid. Old value type is '%s'. but New value type is '%s'")
|
||||||
|
:format(
|
||||||
|
tostring(Type),
|
||||||
|
tostring(type(NewValue))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elseif DefaultItems[Type] then
|
||||||
Item[Property] = Lerp(OldValue,NewValue,Alpha)
|
Item[Property] = Lerp(OldValue,NewValue,Alpha)
|
||||||
elseif Type == "UDim2" then
|
elseif Type == "UDim2" then
|
||||||
Item[Property] = UDim2.new(
|
Item[Property] = UDim2.new(
|
||||||
|
|
@ -89,10 +97,24 @@ function LerpProperties(Item,Old,New,Alpha)
|
||||||
Lerp(OldValue.g*255,NewValue.g*255),
|
Lerp(OldValue.g*255,NewValue.g*255),
|
||||||
Lerp(OldValue.b*255,NewValue.b*255)
|
Lerp(OldValue.b*255,NewValue.b*255)
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
error(
|
||||||
|
("Unable to lerp property '%s' of '%s'. Old value type is '%s'. but tweenable types are UDim2, UDim, Color3, Vector2, Vector3, CFrame, number only")
|
||||||
|
:format(
|
||||||
|
tostring(Property),
|
||||||
|
tostring(Item),
|
||||||
|
tostring(Type)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if Setter then
|
||||||
|
Setter(Item,Property,NewValue)
|
||||||
|
else
|
||||||
|
Item[Property] = Value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
module.LerpProperties = LerpProperties
|
||||||
|
|
||||||
------------------------------------
|
------------------------------------
|
||||||
-- 모듈 함수 지정
|
-- 모듈 함수 지정
|
||||||
|
|
@ -108,9 +130,9 @@ end
|
||||||
--해당 함수가 실행됨
|
--해당 함수가 실행됨
|
||||||
--Properties : 트윈할 속성과 목표값 예시 :
|
--Properties : 트윈할 속성과 목표값 예시 :
|
||||||
--Data.Properties.Position = UDim2.new(1,0,1,0) 처럼 하면 Position 속성의 목표를 1,0,1,0 으로 지정
|
--Data.Properties.Position = UDim2.new(1,0,1,0) 처럼 하면 Position 속성의 목표를 1,0,1,0 으로 지정
|
||||||
function module.RunTween(Item,Data,Properties,Ended,OnStepped,_)
|
function module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
||||||
-- remove self
|
-- remove self
|
||||||
if Item == module then Item = Data; Data = Properties; Properties = Ended; Ended = OnStepped; OnStepped = _; end
|
if Item == module then Item = Data; Data = Properties; Properties = Ended; Ended = OnStepped; OnStepped = Setter; Setter = Getter; Getter = _; end
|
||||||
|
|
||||||
-- 시간 저장
|
-- 시간 저장
|
||||||
local Time = Data.Time or 1
|
local Time = Data.Time or 1
|
||||||
|
|
@ -124,7 +146,11 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,_)
|
||||||
local NowAnimationIndex = {}
|
local NowAnimationIndex = {}
|
||||||
local LastProperties = {}
|
local LastProperties = {}
|
||||||
for Property,_ in pairs(Properties) do
|
for Property,_ in pairs(Properties) do
|
||||||
|
if Getter then
|
||||||
|
LastProperties[Property] = Getter(Property)
|
||||||
|
else
|
||||||
LastProperties[Property] = Item[Property]
|
LastProperties[Property] = Item[Property]
|
||||||
|
end
|
||||||
ThisPlayIndex[Property] = ThisPlayIndex[Property] ~= nil and ThisPlayIndex[Property] + 1 or 1
|
ThisPlayIndex[Property] = ThisPlayIndex[Property] ~= nil and ThisPlayIndex[Property] + 1 or 1
|
||||||
NowAnimationIndex[Property] = ThisPlayIndex[Property]
|
NowAnimationIndex[Property] = ThisPlayIndex[Property]
|
||||||
end
|
end
|
||||||
|
|
@ -168,7 +194,8 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,_)
|
||||||
Item,
|
Item,
|
||||||
LastProperties,
|
LastProperties,
|
||||||
Properties,
|
Properties,
|
||||||
Alpha
|
Alpha,
|
||||||
|
Setter
|
||||||
)
|
)
|
||||||
|
|
||||||
-- 다른 트윈이 속성을 바꾸고 있다면(이후 트윈이) 그 속성을 건들지 않도록 없엠
|
-- 다른 트윈이 속성을 바꾸고 있다면(이후 트윈이) 그 속성을 건들지 않도록 없엠
|
||||||
|
|
@ -240,11 +267,11 @@ function module.RunTween(Item,Data,Properties,Ended,OnStepped,_)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 여러개의 개체를 트윈시킴
|
-- 여러개의 개체를 트윈시킴
|
||||||
function module.RunTweens(Items,Data,Properties,Ended,OnStepped,_)
|
function module.RunTweens(Items,Data,Properties,Ended,OnStepped,Setter,Getter,_)
|
||||||
-- remove self
|
-- remove self
|
||||||
if Items == module then Items = Data; Data = Properties; Properties = Ended; Ended = OnStepped; OnStepped = _; end
|
if Items == module then Items = Data; Data = Properties; Properties = Ended; Ended = OnStepped; OnStepped = Setter; Setter = Getter; Getter = _; end
|
||||||
for _,Item in pairs(Items) do
|
for _,Item in pairs(Items) do
|
||||||
module.RunTween(Item,Data,Properties,Ended,OnStepped)
|
module.RunTween(Item,Data,Properties,Ended,OnStepped,Setter,Getter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,11 @@ function round.setOutline(ImageFrame,RoundSize)
|
||||||
ImageFrame.SliceScale = outlineSliceScale * RoundSize;
|
ImageFrame.SliceScale = outlineSliceScale * RoundSize;
|
||||||
return ImageFrame;
|
return ImageFrame;
|
||||||
end
|
end
|
||||||
|
function round.getRound(ImageFrame)
|
||||||
|
return ImageFrame.SliceScale / roundSliceScale;
|
||||||
|
end
|
||||||
|
function round.getOutline(ImageFrame)
|
||||||
|
return ImageFrame.SliceScale / outlineSliceScale;
|
||||||
|
end
|
||||||
|
|
||||||
return round;
|
return round;
|
||||||
Loading…
Reference in a new issue