Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Notification = function()
- local notification = guiTemplates.Notification:Clone()
- local duration = 20
- local displayed = false
- local ripple = true
- local isError = false
- local clickIntensity = 10
- local events = {
- Clicked = Instance.new('BindableEvent'),
- Closed = Instance.new('BindableEvent')
- }
- local properties = {
- Name = {
- Get = function()
- return notification.Name
- end,
- Change = function(name)
- notification.Name = name
- end,
- },
- Title = {
- Get = function()
- return notification.Body.ContentTitle.Text
- end,
- Change = function(text)
- notification.Body.ContentTitle.Text = text
- end,
- },
- Text = {
- Get = function()
- return notification.Body.ContentText.Text
- end,
- Change = function(text)
- notification.Body.ContentText.Text = text
- end,
- },
- Duration = {
- Get = function()
- return duration
- end,
- Change = function(number)
- duration = number
- end,
- },
- Ripple = {
- Get = function()
- return ripple
- end,
- Change = function(bool)
- ripple = (bool == true) and true or false
- end,
- },
- Error = {
- Get = function()
- return isError
- end,
- Change = function(bool)
- isError = bool
- end,
- },
- ClickIntensity = {
- Get = function()
- return clickIntensity
- end,
- Change = function(number)
- clickIntensity = number
- end,
- },
- }
- local object = {}
- for name, event in pairs(events) do
- object[name] = event.Event
- end
- function object:Destroy()
- notification:Destroy()
- end
- function object:Close(disableFire)
- if displayed then
- notification:TweenPosition(UDim2.new(1, notification.AbsolutePosition.X+15, 0, notification.AbsolutePosition.Y), 'Out', 'Sine', 0.25)
- if not disableFire then
- delay(0.25, function()
- events.Closed:Fire()
- end)
- end
- wait(0.125)
- for _, existingNotification in pairs(interfaceGui.NotificationPanel:GetChildren()) do
- if existingNotification.AbsolutePosition.Y < notification.AbsolutePosition.Y then
- existingNotification:TweenPosition(UDim2.new(1, -(existingNotification.AbsoluteSize.X+15), 0, existingNotification.AbsolutePosition.Y+(existingNotification.AbsoluteSize.Y+15)), 'In', 'Sine', 0.25)
- end
- end
- displayed = false
- end
- wait(0.25)
- self:Destroy()
- end
- function object:Display()
- if not displayed then
- notification:TweenPosition(UDim2.new(1, -(notification.AbsoluteSize.X+15), 1, -(notification.AbsoluteSize.Y+15)), 'Out', 'Sine', 0.25)
- for _, existingNotification in pairs(interfaceGui.NotificationPanel:GetChildren()) do
- --if not existingNotification.Name == notification.Name then
- existingNotification:TweenPosition(UDim2.new(1, -(existingNotification.AbsoluteSize.X+15), 0, existingNotification.AbsolutePosition.Y-(existingNotification.AbsoluteSize.Y+15)), 'Out', 'Sine', 0.25)
- --end
- end
- if isError then
- sounds.Error:Play()
- else
- sounds.Notification:Play()
- end
- delay(duration or 20, function()
- self:Close()
- end)
- displayed = true
- end
- end
- notification.Name = #interfaceGui.NotificationPanel:GetChildren()
- notification.Parent = interfaceGui.NotificationPanel
- notification.MouseButton1Down:Connect(function(mouseX, mouseY)
- if displayed then
- if ripple then
- rippleService.ButtonAnimation(notification, mouseX, mouseY)
- end
- notification:TweenSizeAndPosition(UDim2.new(0, notification.AbsoluteSize.X-clickIntensity/2, 0, notification.AbsoluteSize.Y-clickIntensity/2), UDim2.new(1, notification.Position.X.Offset+(clickIntensity/8), 1, notification.Position.Y.Offset+(clickIntensity/4)), 'In', 'Quad', clickIntensity/50)
- wait(clickIntensity/50)
- notification:TweenSizeAndPosition(UDim2.new(0, notification.AbsoluteSize.X+clickIntensity/2, 0, notification.AbsoluteSize.Y+clickIntensity/2), UDim2.new(1, notification.Position.X.Offset-(clickIntensity/8), 1, notification.Position.Y.Offset-(clickIntensity/4)), 'Out', 'Quad', clickIntensity/50)
- wait(0.25)
- object:Close(true)
- events.Clicked:Fire()
- end
- end)
- notification.Header.Controls.Close.MouseButton1Down:Connect(function(mouseX, mouseY)
- if displayed then
- if ripple then
- rippleService.ButtonAnimation(notification.Header.Controls.Close, mouseX, mouseY)
- end
- object:Close()
- end
- end)
- return setmetatable(object, {
- __index = function(self, index)
- if properties[index] then
- return properties[index].Get()
- end
- end,
- __newindex = function(self, index, ...)
- if properties[index] then
- return properties[index].Change(...)
- end
- end
- })
- end,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement