Advertisement
Guest User

Notificaton object

a guest
Nov 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.28 KB | None | 0 0
  1.     Notification = function()
  2.         local notification = guiTemplates.Notification:Clone()
  3.         local duration = 20
  4.         local displayed = false
  5.         local ripple = true
  6.         local isError = false
  7.         local clickIntensity = 10
  8.         local events = {
  9.             Clicked = Instance.new('BindableEvent'),
  10.             Closed = Instance.new('BindableEvent')
  11.         }
  12.         local properties = {
  13.             Name = {
  14.                 Get = function()
  15.                     return notification.Name
  16.                 end,
  17.                 Change = function(name)
  18.                     notification.Name = name
  19.                 end,
  20.             },
  21.             Title = {
  22.                 Get = function()
  23.                     return notification.Body.ContentTitle.Text
  24.                 end,
  25.                 Change = function(text)
  26.                     notification.Body.ContentTitle.Text = text
  27.                 end,
  28.             },
  29.             Text = {
  30.                 Get = function()
  31.                     return notification.Body.ContentText.Text
  32.                 end,
  33.                 Change = function(text)
  34.                     notification.Body.ContentText.Text = text
  35.                 end,
  36.             },
  37.             Duration = {
  38.                 Get = function()
  39.                     return duration
  40.                 end,
  41.                 Change = function(number)
  42.                     duration = number
  43.                 end,
  44.             },
  45.             Ripple = {
  46.                 Get = function()
  47.                     return ripple
  48.                 end,
  49.                 Change = function(bool)
  50.                     ripple = (bool == true) and true or false
  51.                 end,
  52.             },
  53.             Error = {
  54.                 Get = function()
  55.                     return isError
  56.                 end,
  57.                 Change = function(bool)
  58.                     isError = bool
  59.                 end,
  60.             },
  61.             ClickIntensity = {
  62.                 Get = function()
  63.                     return clickIntensity
  64.                 end,
  65.                 Change = function(number)
  66.                     clickIntensity = number
  67.                 end,
  68.             },
  69.         }
  70.         local object = {}
  71.         for name, event in pairs(events) do
  72.             object[name] = event.Event
  73.         end
  74.         function object:Destroy()
  75.             notification:Destroy()
  76.         end
  77.         function object:Close(disableFire)
  78.             if displayed then
  79.                 notification:TweenPosition(UDim2.new(1, notification.AbsolutePosition.X+15, 0, notification.AbsolutePosition.Y), 'Out', 'Sine', 0.25)
  80.                 if not disableFire then
  81.                     delay(0.25, function()
  82.                         events.Closed:Fire()
  83.                     end)
  84.                 end
  85.                 wait(0.125)
  86.                 for _, existingNotification in pairs(interfaceGui.NotificationPanel:GetChildren()) do
  87.                     if existingNotification.AbsolutePosition.Y < notification.AbsolutePosition.Y then
  88.                         existingNotification:TweenPosition(UDim2.new(1, -(existingNotification.AbsoluteSize.X+15), 0, existingNotification.AbsolutePosition.Y+(existingNotification.AbsoluteSize.Y+15)), 'In', 'Sine', 0.25)
  89.                     end
  90.                 end
  91.                 displayed = false
  92.             end
  93.             wait(0.25)
  94.             self:Destroy()
  95.         end
  96.         function object:Display()
  97.             if not displayed then
  98.                 notification:TweenPosition(UDim2.new(1, -(notification.AbsoluteSize.X+15), 1, -(notification.AbsoluteSize.Y+15)), 'Out', 'Sine', 0.25)
  99.                 for _, existingNotification in pairs(interfaceGui.NotificationPanel:GetChildren()) do
  100.                     --if not existingNotification.Name == notification.Name then
  101.                         existingNotification:TweenPosition(UDim2.new(1, -(existingNotification.AbsoluteSize.X+15), 0, existingNotification.AbsolutePosition.Y-(existingNotification.AbsoluteSize.Y+15)), 'Out', 'Sine', 0.25)
  102.                     --end
  103.                 end
  104.                 if isError then
  105.                     sounds.Error:Play()
  106.                 else
  107.                     sounds.Notification:Play()
  108.                 end
  109.                 delay(duration or 20, function()
  110.                     self:Close()
  111.                 end)
  112.                 displayed = true
  113.             end
  114.         end
  115.         notification.Name = #interfaceGui.NotificationPanel:GetChildren()
  116.         notification.Parent = interfaceGui.NotificationPanel
  117.         notification.MouseButton1Down:Connect(function(mouseX, mouseY)
  118.             if displayed then
  119.                 if ripple then
  120.                     rippleService.ButtonAnimation(notification, mouseX, mouseY)
  121.                 end
  122.                 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)
  123.                 wait(clickIntensity/50)
  124.                 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)
  125.                 wait(0.25)
  126.                 object:Close(true)
  127.                 events.Clicked:Fire()
  128.             end
  129.         end)
  130.         notification.Header.Controls.Close.MouseButton1Down:Connect(function(mouseX, mouseY)
  131.             if displayed then
  132.                 if ripple then
  133.                     rippleService.ButtonAnimation(notification.Header.Controls.Close, mouseX, mouseY)
  134.                 end
  135.                 object:Close()
  136.             end
  137.         end)
  138.         return setmetatable(object, {
  139.             __index = function(self, index)
  140.                 if properties[index] then
  141.                     return properties[index].Get()
  142.                 end
  143.             end,
  144.             __newindex = function(self, index, ...)
  145.                 if properties[index] then
  146.                     return properties[index].Change(...)
  147.                 end
  148.             end
  149.         })
  150.     end,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement