Improve plugin notification animations

This commit is contained in:
Lewin Kelly 2023-10-12 06:30:06 +01:00
parent a84c6a1d6c
commit ad7144c800
5 changed files with 100 additions and 46 deletions

View File

@ -17,11 +17,14 @@ local function initiate()
end end
local toolbar = plugin:CreateToolbar "Mercury Sync" local toolbar = plugin:CreateToolbar "Mercury Sync"
local button = toolbar:CreateButton(
"", -- The text next to the icon. Leave this blank if the icon is sufficient. local buttons = {
"Sync!", -- hover text toolbar:CreateButton(
"icon.png" -- The icon file's name. Make sure you change it to your own icon file's name! "", -- The text next to the icon. Leave this blank if the icon is sufficient.
) "Sync!", -- hover text
"icon.png" -- The icon file's name. Make sure you change it to your own icon file's name!
),
}
local Fusion = LoadLibrary "RbxFusion" local Fusion = LoadLibrary "RbxFusion"
@ -29,6 +32,9 @@ local New = Fusion.New
local Children = Fusion.Children local Children = Fusion.Children
local Value = Fusion.Value local Value = Fusion.Value
local Spring = Fusion.Spring local Spring = Fusion.Spring
-- local Tween = Fusion.Tween
-- local TweenInfo = Fusion.TweenInfo
local Observer = Fusion.Observer
local peek = Fusion.peek local peek = Fusion.peek
local g local g
@ -69,28 +75,34 @@ local function gui()
return g return g
end end
local function notifyCount()
local count = 0
for _, _ in pairs(notifications) do
count = count + 1
end
return count
end
local idCount = 0 local idCount = 0
local nCount = 0
local function notify(text) local function notify(text)
local startCount = notifyCount() nCount = nCount + 1
local position = Value(UDim2.new(0, -WIDTH, 0, 60 * (startCount + 1) - 50))
local transparency = Value(0)
idCount = idCount + 1 idCount = idCount + 1
local id = idCount local id = idCount
local position = Value(UDim2.new(0, -WIDTH, 0, 60 * nCount - 50))
local transparency = Value(0)
local textValue = Value(text)
local textChanged = Observer(textValue)
local arrowRotation = Value(0)
local done = Value(false)
local background = Value(Color3.new())
local backgroundSpring = Spring(background, 4)
local start = tick()
local disconn = textChanged:onChange(function()
if tick() - start > 0.5 then -- don't change color if it's just appearing
backgroundSpring:setPosition(Color3.new(0.4, 0.4, 0.4))
end
end)
local t = New "Frame" { local t = New "Frame" {
Name = "Notification", Name = "Notification",
Parent = gui().Notifications, Parent = gui().Notifications,
BackgroundColor3 = Color3.new(), BackgroundColor3 = backgroundSpring,
BackgroundTransparency = Spring(transparency, 15), BackgroundTransparency = Spring(transparency, 15),
BorderSizePixel = 0, BorderSizePixel = 0,
Position = Spring(position, 15), Position = Spring(position, 15),
@ -98,16 +110,25 @@ local function notify(text)
[Children] = { [Children] = {
New "ImageLabel" { New "ImageLabel" {
Image = "rbxasset://../../../Plugins/TestPlugin/icon2.png", Name = "InnerIcon",
Image = "rbxasset://../../../Plugins/TestPlugin/innerIcon.png",
BackgroundTransparency = 1, BackgroundTransparency = 1,
Position = UDim2.new(0, 5, 0, 5), Position = UDim2.new(0, 5, 0, 5),
Size = UDim2.new(0, 40, 0, 40), Size = UDim2.new(0, 40, 0, 40),
}, },
New "ImageLabel" {
Name = "OuterIcon",
Image = "rbxasset://../../../Plugins/TestPlugin/outerIcon.png",
BackgroundTransparency = 1,
Position = UDim2.new(0, 5, 0, 5),
Rotation = Spring(arrowRotation),
Size = UDim2.new(0, 40, 0, 40),
},
New "TextLabel" { New "TextLabel" {
Position = UDim2.new(0, 50, 0, 0), Position = UDim2.new(0, 50, 0, 0),
Size = UDim2.new(1, -60, 1, 0), Size = UDim2.new(1, -60, 1, 0),
BackgroundTransparency = 1, BackgroundTransparency = 1,
Text = text, Text = textValue,
TextWrapped = true, TextWrapped = true,
TextColor3 = Color3.new(1, 1, 1), TextColor3 = Color3.new(1, 1, 1),
Font = Enum.Font.SourceSans, Font = Enum.Font.SourceSans,
@ -117,48 +138,81 @@ local function notify(text)
}, },
}, },
} }
local tbl = {
obj = t,
pos = position,
}
notifications[id] = tbl
position:set(peek(position) + UDim2.new(0, WIDTH, 0, 0)) Spawn(function()
transparency:set(0.5) local tbl = {
wait(3) obj = t,
pos = position,
}
position:set(UDim2.new(0, 0, 0, -60)) notifications[id] = tbl
transparency:set(1)
notifications[id] = nil position:set(peek(position) + UDim2.new(0, WIDTH, 0, 0))
transparency:set(0.5)
for _, v in pairs(notifications) do repeat
if peek(v.pos).Y.Offset > peek(position).Y.Offset then wait(1)
v.pos:set(peek(v.pos) - UDim2.new(0, 0, 0, 60)) until peek(done)
wait(3)
position:set(UDim2.new(0, 0, 0, -60))
transparency:set(1)
notifications[id] = nil
nCount = nCount - 1
for _, v in pairs(notifications) do
if peek(v.pos).Y.Offset > peek(position).Y.Offset then
v.pos:set(peek(v.pos) - UDim2.new(0, 0, 0, 60))
end
end end
end
wait(1) wait(1)
t:Destroy() disconn()
t:Destroy()
end)
return {
text = textValue,
arrowRotation = arrowRotation,
done = done,
}
end end
local debounce local debounce
button.Click:connect(function()
buttons[1].Click:connect(function()
if debounce then if debounce then
return return
end end
debounce = true debounce = true
initiate() initiate()
local ok, res = ypcall(function() local n = notify "Syncing..."
return HttpService:GetAsync "http://localhost:2013/"
Spawn(function()
while not peek(n.done) do
n.arrowRotation:set(peek(n.arrowRotation) + 180)
wait(0.9)
end
end) end)
if ok then Spawn(function()
notify("Synced: " .. res) local ok, res = ypcall(function()
else return HttpService:GetAsync(
notify "Failed to sync! Is Mercury Sync Server running?" "http://localhost:2013/sync?" .. tick() * 10000
end -- nocache parameter doesn't work
)
end)
debounce = false if ok then
n.text:set("Synced: " .. res)
else
n.text:set "Failed to sync! Is Mercury Sync Server running?"
end
n.done:set(true)
debounce = false
end)
end) end)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

BIN
Sync/Plugin/innerIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

BIN
Sync/Plugin/outerIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB