Advertisement
Achitsak

lib

Apr 1st, 2025 (edited)
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.98 KB | None | 0 0
  1. local NotificationModule = {}
  2.  
  3. -- Cosmic Notification Configuration
  4. local CONFIG = {
  5.     DURATION = 5, -- Notification display time
  6.     ANIMATION_DURATION = 0.4, -- Smooth animation speed
  7.     PADDING = 20, -- Padding from screen edge
  8.     MAX_NOTIFICATIONS = 3, -- Maximum simultaneous notifications
  9.     STYLES = {
  10.         DEFAULT = {
  11.             Background = Color3.fromRGB(20, 20, 40),
  12.             Accent = Color3.fromRGB(50, 50, 100),
  13.             Text = Color3.fromRGB(200, 220, 255),
  14.             Glow = Color3.fromRGB(100, 150, 255)
  15.         },
  16.         SUCCESS = {
  17.             Background = Color3.fromRGB(0, 30, 20),
  18.             Accent = Color3.fromRGB(0, 100, 70),
  19.             Text = Color3.fromRGB(100, 255, 180),
  20.             Glow = Color3.fromRGB(0, 255, 150)
  21.         },
  22.         WARNING = {
  23.             Background = Color3.fromRGB(40, 30, 0),
  24.             Accent = Color3.fromRGB(100, 80, 0),
  25.             Text = Color3.fromRGB(255, 220, 100),
  26.             Glow = Color3.fromRGB(255, 180, 50)
  27.         },
  28.         ERROR = {
  29.             Background = Color3.fromRGB(40, 0, 0),
  30.             Accent = Color3.fromRGB(100, 0, 0),
  31.             Text = Color3.fromRGB(255, 120, 120),
  32.             Glow = Color3.fromRGB(255, 50, 50)
  33.         },
  34.         INFO = {
  35.             Background = Color3.fromRGB(0, 20, 40),
  36.             Accent = Color3.fromRGB(0, 50, 100),
  37.             Text = Color3.fromRGB(100, 200, 255),
  38.             Glow = Color3.fromRGB(50, 150, 255)
  39.         }
  40.     }
  41. }
  42.  
  43. -- Services
  44. local Players = game:GetService("Players")
  45. local TweenService = game:GetService("TweenService")
  46.  
  47. -- Notification Queue
  48. local NotificationQueue = {
  49.     Active = {},
  50.     Pending = {}
  51. }
  52.  
  53. -- Create Starry Background
  54. local function createStarryBackground(parent, styleConfig)
  55.     local stars = Instance.new("Frame")
  56.     stars.Size = UDim2.new(1, 0, 1, 0)
  57.     stars.BackgroundTransparency = 1
  58.     stars.ClipsDescendants = true
  59.     stars.Parent = parent
  60.  
  61.     -- Create multiple layers of stars
  62.     for i = 1, 20 do
  63.         local star = Instance.new("Frame")
  64.         star.Size = UDim2.new(0, math.random(1, 2), 0, math.random(1, 2))
  65.         star.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  66.         star.BackgroundTransparency = math.random(6, 9) / 10
  67.         star.Position = UDim2.new(math.random(), math.random(), math.random(), math.random())
  68.         star.Parent = stars
  69.  
  70.         -- Twinkling effect
  71.         local twinkleTween = TweenService:Create(star,
  72.             TweenInfo.new(
  73.                 math.random(1, 3),
  74.                 Enum.EasingStyle.Sine,
  75.                 Enum.EasingDirection.InOut,
  76.                 -1,
  77.                 true
  78.             ),
  79.             {BackgroundTransparency = math.random(7, 9) / 10}
  80.         )
  81.         twinkleTween:Play()
  82.     end
  83.  
  84.     return stars
  85. end
  86.  
  87. -- Create Notification Frame
  88. local function createNotificationFrame(container, style)
  89.     local styleConfig = CONFIG.STYLES[style] or CONFIG.STYLES.DEFAULT
  90.    
  91.     local frame = Instance.new("Frame")
  92.     frame.Size = UDim2.new(0, 300, 0, 90)
  93.     frame.BackgroundColor3 = styleConfig.Background
  94.     frame.BorderSizePixel = 0
  95.     frame.Parent = container
  96.  
  97.     -- Starry Background
  98.     local starryBg = createStarryBackground(frame, styleConfig)
  99.  
  100.     -- Rounded Corners
  101.     local corner = Instance.new("UICorner")
  102.     corner.CornerRadius = UDim.new(0, 15)
  103.     corner.Parent = frame
  104.  
  105.     -- Soft Glow Border
  106.     local glowBorder = Instance.new("Frame")
  107.     glowBorder.Size = UDim2.new(1, 6, 1, 6)
  108.     glowBorder.Position = UDim2.new(0, -3, 0, -3)
  109.     glowBorder.BackgroundColor3 = styleConfig.Glow
  110.     glowBorder.BackgroundTransparency = 0.7
  111.     glowBorder.BorderSizePixel = 0
  112.     glowBorder.ZIndex = 0
  113.    
  114.     local glowCorner = Instance.new("UICorner")
  115.     glowCorner.CornerRadius = UDim.new(0, 18)
  116.     glowCorner.Parent = glowBorder
  117.    
  118.     glowBorder.Parent = frame
  119.  
  120.     return frame
  121. end
  122.  
  123. -- Create Notification Content
  124. local function createNotificationContent(frame, title, description, style)
  125.     local styleConfig = CONFIG.STYLES[style] or CONFIG.STYLES.DEFAULT
  126.    
  127.     -- Progress Container
  128.     local progressContainer = Instance.new("Frame")
  129.     progressContainer.Size = UDim2.new(1, -20, 0, 4)
  130.     progressContainer.Position = UDim2.new(0, 10, 1, -10)
  131.     progressContainer.BackgroundColor3 = styleConfig.Accent
  132.     progressContainer.BackgroundTransparency = 0.7
  133.     progressContainer.BorderSizePixel = 0
  134.     progressContainer.Parent = frame
  135.  
  136.     local progressCorner = Instance.new("UICorner")
  137.     progressCorner.CornerRadius = UDim.new(1, 0)
  138.     progressCorner.Parent = progressContainer
  139.  
  140.     -- Progress Bar
  141.     local progressBar = Instance.new("Frame")
  142.     progressBar.Size = UDim2.new(1, 0, 1, 0)
  143.     progressBar.BackgroundColor3 = styleConfig.Text
  144.     progressBar.BorderSizePixel = 0
  145.     progressBar.Parent = progressContainer
  146.  
  147.     local progressBarCorner = Instance.new("UICorner")
  148.     progressBarCorner.CornerRadius = UDim.new(1, 0)
  149.     progressBarCorner.Parent = progressBar
  150.  
  151.     -- Title Label
  152.     local titleLabel = Instance.new("TextLabel")
  153.     titleLabel.Text = title
  154.     titleLabel.Font = Enum.Font.GothamBold
  155.     titleLabel.TextColor3 = styleConfig.Text
  156.     titleLabel.TextSize = 17
  157.     titleLabel.TextXAlignment = Enum.TextXAlignment.Left
  158.     titleLabel.Position = UDim2.new(0, 15, 0, 15)
  159.     titleLabel.Size = UDim2.new(1, -30, 0, 25)
  160.     titleLabel.BackgroundTransparency = 1
  161.     titleLabel.Parent = frame
  162.  
  163.     -- Description Label
  164.     local descLabel = Instance.new("TextLabel")
  165.     descLabel.Text = description
  166.     descLabel.Font = Enum.Font.Gotham
  167.     descLabel.TextColor3 = styleConfig.Text
  168.     descLabel.TextTransparency = 0.3
  169.     descLabel.TextSize = 14
  170.     descLabel.TextXAlignment = Enum.TextXAlignment.Left
  171.     descLabel.TextWrapped = true
  172.     descLabel.Position = UDim2.new(0, 15, 0, 40)
  173.     descLabel.Size = UDim2.new(1, -30, 0, 35)
  174.     descLabel.BackgroundTransparency = 1
  175.     descLabel.Parent = frame
  176.  
  177.     return titleLabel, descLabel, progressBar
  178. end
  179.  
  180. -- Create Notification Container
  181. local function createNotificationContainer(player)
  182.     local container = Instance.new("ScreenGui")
  183.     container.Name = "CosmicNotificationGui"
  184.     container.ResetOnSpawn = false
  185.     container.DisplayOrder = 100
  186.     container.Parent = player.PlayerGui
  187.  
  188.     -- Vertical Layout (Top to Bottom)
  189.     local layout = Instance.new("UIListLayout")
  190.     layout.SortOrder = Enum.SortOrder.TopToBottom
  191.     layout.Padding = UDim.new(0, 15)
  192.     layout.HorizontalAlignment = Enum.HorizontalAlignment.Right
  193.     layout.Parent = container
  194.  
  195.     return container
  196. end
  197.  
  198. -- Animate Notification In
  199. local function animateNotificationIn(frame)
  200.     local startPos = UDim2.new(1, frame.Size.X.Offset, 0, -frame.Size.Y.Offset)
  201.     local endPos = UDim2.new(1, -frame.Size.X.Offset - CONFIG.PADDING, 0, CONFIG.PADDING)
  202.    
  203.     frame.Position = startPos
  204.     frame.BackgroundTransparency = 1
  205.    
  206.     local tweenInfoIn = TweenInfo.new(
  207.         CONFIG.ANIMATION_DURATION,
  208.         Enum.EasingStyle.Back,
  209.         Enum.EasingDirection.Out
  210.     )
  211.    
  212.     local tweenPos = TweenService:Create(frame, tweenInfoIn, {
  213.         Position = endPos,
  214.         BackgroundTransparency = 0
  215.     })
  216.    
  217.     tweenPos:Play()
  218. end
  219.  
  220. -- Animate Notification Out
  221. local function animateNotificationOut(frame)
  222.     local endPos = UDim2.new(1, frame.Size.X.Offset, 0, -frame.Size.Y.Offset)
  223.    
  224.     local tweenInfoOut = TweenInfo.new(
  225.         CONFIG.ANIMATION_DURATION,
  226.         Enum.EasingStyle.Back,
  227.         Enum.EasingDirection.In
  228.     )
  229.    
  230.     local tweenOut = TweenService:Create(frame, tweenInfoOut, {
  231.         Position = endPos,
  232.         BackgroundTransparency = 1
  233.     })
  234.    
  235.     tweenOut:Play()
  236.    
  237.     tweenOut.Completed:Connect(function()
  238.         -- Remove from active notifications
  239.         for i, notification in ipairs(NotificationQueue.Active) do
  240.             if notification.Frame == frame then
  241.                 table.remove(NotificationQueue.Active, i)
  242.                 break
  243.             end
  244.         end
  245.        
  246.         frame:Destroy()
  247.        
  248.         -- Try to show next pending notification
  249.         NotificationModule:ProcessQueue()
  250.     end)
  251. end
  252.  
  253. -- Animate Progress Bar
  254. local function animateProgressBar(progressBar, duration)
  255.     local tweenInfo = TweenInfo.new(
  256.         duration,
  257.         Enum.EasingStyle.Linear
  258.     )
  259.    
  260.     local progressTween = TweenService:Create(progressBar, tweenInfo, {
  261.         Size = UDim2.new(0, 0, 1, 0)
  262.     })
  263.    
  264.     progressTween:Play()
  265. end
  266.  
  267. -- Process Notification Queue
  268. function NotificationModule:ProcessQueue()
  269.     -- If we haven't reached max notifications and there are pending notifications
  270.     if #self.NotificationQueue.Active < CONFIG.MAX_NOTIFICATIONS and
  271.        #self.NotificationQueue.Pending > 0 then
  272.         -- Get the next pending notification
  273.         local nextNotification = table.remove(self.NotificationQueue.Pending, 1)
  274.        
  275.         -- Show the notification
  276.         self:Show(
  277.             nextNotification.Title,
  278.             nextNotification.Description,
  279.             nextNotification.Style
  280.         )
  281.     end
  282. end
  283.  
  284. -- Main Notification Function
  285. function NotificationModule:Show(title, description, style)
  286.     local player = Players.LocalPlayer
  287.     if not player then return end
  288.    
  289.     -- Validate style
  290.     style = style or "DEFAULT"
  291.     style = CONFIG.STYLES[style] and style or "DEFAULT"
  292.    
  293.     -- If we've reached max notifications, queue this notification
  294.     if #NotificationQueue.Active >= CONFIG.MAX_NOTIFICATIONS then
  295.         table.insert(NotificationQueue.Pending, {
  296.             Title = title,
  297.             Description = description,
  298.             Style = style
  299.         })
  300.         return
  301.     end
  302.    
  303.     -- Create or find existing GUI container
  304.     local container = player.PlayerGui:FindFirstChild("CosmicNotificationGui")
  305.         or createNotificationContainer(player)
  306.    
  307.     -- Create notification frame
  308.     local frame = createNotificationFrame(container, style)
  309.     local titleLabel, descLabel, progressBar = createNotificationContent(
  310.         frame, title, description, style
  311.     )
  312.    
  313.     -- Track this active notification
  314.     local notification = {
  315.         Frame = frame,
  316.         Title = title,
  317.         Description = description,
  318.         Style = style
  319.     }
  320.     table.insert(NotificationQueue.Active, notification)
  321.    
  322.     -- Animate in
  323.     animateNotificationIn(frame)
  324.    
  325.     -- Animate progress bar
  326.     animateProgressBar(progressBar, CONFIG.DURATION)
  327.    
  328.     -- Auto-dismiss
  329.     task.delay(CONFIG.DURATION, function()
  330.         if frame and frame.Parent then
  331.             animateNotificationOut(frame)
  332.         end
  333.     end)
  334.    
  335.     return frame
  336. end
  337.  
  338. -- Initialize NotificationQueue in the module
  339. NotificationModule.NotificationQueue = NotificationQueue
  340.  
  341. -- Expose notification styles
  342. NotificationModule.Style = {
  343.     DEFAULT = "DEFAULT",
  344.     SUCCESS = "SUCCESS",
  345.     WARNING = "WARNING",
  346.     ERROR = "ERROR",
  347.     INFO = "INFO"
  348. }
  349.  
  350. return NotificationModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement