Advertisement
Guest User

Notification object

a guest
Nov 19th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.92 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,
  151.     CommandBar = function()
  152.         local commandBar = guiTemplates.CommandBar:Clone()
  153.         local allCommands = remoteFunction:InvokeServer('GetCommands')
  154.         local events = {
  155.             Closed = Instance.new('BindableEvent'),
  156.         }
  157.         local properties = {
  158.             Name = {
  159.                 Get = function()
  160.                     return commandBar.Name
  161.                 end,
  162.                 Change = function(name)
  163.                     commandBar.Name = name
  164.                 end,
  165.             },
  166.             Text = {
  167.                 Get = function()
  168.                     return commandBar.TextBox.Text
  169.                 end,
  170.                 Change = function(text)
  171.                     commandBar.TextBox.Text = text
  172.                 end,
  173.             },
  174.         }
  175.         local object = {}
  176.         for name, event in pairs(events) do
  177.             object[name] = event.Event
  178.         end
  179.         function object:Destroy()
  180.             commandBar:Destroy()
  181.         end
  182.         function object:Display()
  183.             if interfaceGui:FindFirstChild('CommandBar') then
  184.                 interfaceGui.CommandBar:TweenPosition(UDim2.new(0, 0, 1, interfaceGui.AbsoluteSize.Y + 15), 'In', 'Sine', 0.1)
  185.                 wait(0.2)
  186.             end
  187.             commandBar:TweenPosition(UDim2.new(0, 0, 1, 0), 'Out', 'Sine', 0.1)
  188.             commandBar.TextBox:CaptureFocus()
  189.         end
  190.         function object:Close()
  191.             commandBar.TextBox:ReleaseFocus()
  192.             commandBar:TweenPosition(UDim2.new(0, 0, 1, commandBar.AbsoluteSize.Y + 15), 'Out', 'Sine', 0.1)
  193.         end
  194.         commandBar.Position = UDim2.new(0, 0, 1, commandBar.AbsoluteSize.Y + 15)
  195.         commandBar.Parent = interfaceGui
  196.         local function queryTable(tbl, data)
  197.             local found = nil
  198.             local success, result = pcall(function()
  199.                 if data == nil then return end
  200.                 for _,search in pairs(tbl) do
  201.                     if string.find(string.lower(search[1]),string.lower(data)) == 1 then
  202.                         -- if found then return nil end -- ambig
  203.                         found = search[1]
  204.                     end
  205.                 end
  206.             end)
  207.             return found
  208.         end
  209.         local function getTextSuggession(text)
  210.             local command
  211.             local result
  212.             print('commands to query: ' .. tostring(#allCommands))
  213.             for _, command in pairs(allCommands) do
  214.                 if string.lower(command.Name) == string.lower(text) then
  215.                     command = command.Name
  216.                 else
  217.                     for _, aliase in pairs(command.Aliases or {}) do
  218.                         if string.lower(aliase) == string.lower(text) then
  219.                             command = aliase
  220.                         end
  221.                     end
  222.                 end
  223.             end
  224.             print('command found from text suggession: '..command)
  225.             if command then
  226.                 result = text .. string.sub(command, string.len(text)+1)
  227.             end
  228.             return result
  229.         end
  230.         commandBar.TextBox.Changed:Connect(function()
  231.             local result
  232.             if string.len(commandBar.TextBox.Text) > 0 then
  233.                 result = getTextSuggession(commandBar.TextBox.Text)
  234.                 if result and not result == commandBar.TextBox.Text then
  235.                     commandBar.TextLabel.Text = result
  236.                 else
  237.                     commandBar.TextLabel.Text = ''
  238.                 end
  239.                 if string.match(commandBar.TextBox.Text, '  ') then
  240.                     result = getTextSuggession(string.match(commandBar.TextBox.Text, '%a+'))
  241.                     if result ~= '' then
  242.                         print('command query result')
  243.                         commandBar.TextBox.Text = result
  244.                         --idk what to do at this point
  245.                     end
  246.                 end
  247.             end
  248.         end)
  249.         return  setmetatable(object, {
  250.             __index = function(self, index)
  251.                 if properties[index] then
  252.                     return properties[index].Get()
  253.                 end
  254.             end,
  255.             __newindex = function(self, index, ...)
  256.                 if properties[index] then
  257.                     return properties[index].Change(...)
  258.                 end
  259.             end
  260.         })
  261.     end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement