Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local NotificationModule = {}
- -- Cosmic Notification Configuration
- local CONFIG = {
- DURATION = 5, -- Notification display time
- ANIMATION_DURATION = 0.4, -- Smooth animation speed
- PADDING = 20, -- Padding from screen edge
- MAX_NOTIFICATIONS = 3, -- Maximum simultaneous notifications
- STYLES = {
- DEFAULT = {
- Background = Color3.fromRGB(20, 20, 40),
- Accent = Color3.fromRGB(50, 50, 100),
- Text = Color3.fromRGB(200, 220, 255),
- Glow = Color3.fromRGB(100, 150, 255)
- },
- SUCCESS = {
- Background = Color3.fromRGB(0, 30, 20),
- Accent = Color3.fromRGB(0, 100, 70),
- Text = Color3.fromRGB(100, 255, 180),
- Glow = Color3.fromRGB(0, 255, 150)
- },
- WARNING = {
- Background = Color3.fromRGB(40, 30, 0),
- Accent = Color3.fromRGB(100, 80, 0),
- Text = Color3.fromRGB(255, 220, 100),
- Glow = Color3.fromRGB(255, 180, 50)
- },
- ERROR = {
- Background = Color3.fromRGB(40, 0, 0),
- Accent = Color3.fromRGB(100, 0, 0),
- Text = Color3.fromRGB(255, 120, 120),
- Glow = Color3.fromRGB(255, 50, 50)
- },
- INFO = {
- Background = Color3.fromRGB(0, 20, 40),
- Accent = Color3.fromRGB(0, 50, 100),
- Text = Color3.fromRGB(100, 200, 255),
- Glow = Color3.fromRGB(50, 150, 255)
- }
- }
- }
- -- Services
- local Players = game:GetService("Players")
- local TweenService = game:GetService("TweenService")
- -- Notification Queue
- local NotificationQueue = {
- Active = {},
- Pending = {}
- }
- -- Create Starry Background
- local function createStarryBackground(parent, styleConfig)
- local stars = Instance.new("Frame")
- stars.Size = UDim2.new(1, 0, 1, 0)
- stars.BackgroundTransparency = 1
- stars.ClipsDescendants = true
- stars.Parent = parent
- -- Create multiple layers of stars
- for i = 1, 20 do
- local star = Instance.new("Frame")
- star.Size = UDim2.new(0, math.random(1, 2), 0, math.random(1, 2))
- star.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- star.BackgroundTransparency = math.random(6, 9) / 10
- star.Position = UDim2.new(math.random(), math.random(), math.random(), math.random())
- star.Parent = stars
- -- Twinkling effect
- local twinkleTween = TweenService:Create(star,
- TweenInfo.new(
- math.random(1, 3),
- Enum.EasingStyle.Sine,
- Enum.EasingDirection.InOut,
- -1,
- true
- ),
- {BackgroundTransparency = math.random(7, 9) / 10}
- )
- twinkleTween:Play()
- end
- return stars
- end
- -- Create Notification Frame
- local function createNotificationFrame(container, style)
- local styleConfig = CONFIG.STYLES[style] or CONFIG.STYLES.DEFAULT
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 300, 0, 90)
- frame.BackgroundColor3 = styleConfig.Background
- frame.BorderSizePixel = 0
- frame.Parent = container
- -- Starry Background
- local starryBg = createStarryBackground(frame, styleConfig)
- -- Rounded Corners
- local corner = Instance.new("UICorner")
- corner.CornerRadius = UDim.new(0, 15)
- corner.Parent = frame
- -- Soft Glow Border
- local glowBorder = Instance.new("Frame")
- glowBorder.Size = UDim2.new(1, 6, 1, 6)
- glowBorder.Position = UDim2.new(0, -3, 0, -3)
- glowBorder.BackgroundColor3 = styleConfig.Glow
- glowBorder.BackgroundTransparency = 0.7
- glowBorder.BorderSizePixel = 0
- glowBorder.ZIndex = 0
- local glowCorner = Instance.new("UICorner")
- glowCorner.CornerRadius = UDim.new(0, 18)
- glowCorner.Parent = glowBorder
- glowBorder.Parent = frame
- return frame
- end
- -- Create Notification Content
- local function createNotificationContent(frame, title, description, style)
- local styleConfig = CONFIG.STYLES[style] or CONFIG.STYLES.DEFAULT
- -- Progress Container
- local progressContainer = Instance.new("Frame")
- progressContainer.Size = UDim2.new(1, -20, 0, 4)
- progressContainer.Position = UDim2.new(0, 10, 1, -10)
- progressContainer.BackgroundColor3 = styleConfig.Accent
- progressContainer.BackgroundTransparency = 0.7
- progressContainer.BorderSizePixel = 0
- progressContainer.Parent = frame
- local progressCorner = Instance.new("UICorner")
- progressCorner.CornerRadius = UDim.new(1, 0)
- progressCorner.Parent = progressContainer
- -- Progress Bar
- local progressBar = Instance.new("Frame")
- progressBar.Size = UDim2.new(1, 0, 1, 0)
- progressBar.BackgroundColor3 = styleConfig.Text
- progressBar.BorderSizePixel = 0
- progressBar.Parent = progressContainer
- local progressBarCorner = Instance.new("UICorner")
- progressBarCorner.CornerRadius = UDim.new(1, 0)
- progressBarCorner.Parent = progressBar
- -- Title Label
- local titleLabel = Instance.new("TextLabel")
- titleLabel.Text = title
- titleLabel.Font = Enum.Font.GothamBold
- titleLabel.TextColor3 = styleConfig.Text
- titleLabel.TextSize = 17
- titleLabel.TextXAlignment = Enum.TextXAlignment.Left
- titleLabel.Position = UDim2.new(0, 15, 0, 15)
- titleLabel.Size = UDim2.new(1, -30, 0, 25)
- titleLabel.BackgroundTransparency = 1
- titleLabel.Parent = frame
- -- Description Label
- local descLabel = Instance.new("TextLabel")
- descLabel.Text = description
- descLabel.Font = Enum.Font.Gotham
- descLabel.TextColor3 = styleConfig.Text
- descLabel.TextTransparency = 0.3
- descLabel.TextSize = 14
- descLabel.TextXAlignment = Enum.TextXAlignment.Left
- descLabel.TextWrapped = true
- descLabel.Position = UDim2.new(0, 15, 0, 40)
- descLabel.Size = UDim2.new(1, -30, 0, 35)
- descLabel.BackgroundTransparency = 1
- descLabel.Parent = frame
- return titleLabel, descLabel, progressBar
- end
- -- Create Notification Container
- local function createNotificationContainer(player)
- local container = Instance.new("ScreenGui")
- container.Name = "CosmicNotificationGui"
- container.ResetOnSpawn = false
- container.DisplayOrder = 100
- container.Parent = player.PlayerGui
- -- Vertical Layout (Top to Bottom)
- local layout = Instance.new("UIListLayout")
- layout.SortOrder = Enum.SortOrder.TopToBottom
- layout.Padding = UDim.new(0, 15)
- layout.HorizontalAlignment = Enum.HorizontalAlignment.Right
- layout.Parent = container
- return container
- end
- -- Animate Notification In
- local function animateNotificationIn(frame)
- local startPos = UDim2.new(1, frame.Size.X.Offset, 0, -frame.Size.Y.Offset)
- local endPos = UDim2.new(1, -frame.Size.X.Offset - CONFIG.PADDING, 0, CONFIG.PADDING)
- frame.Position = startPos
- frame.BackgroundTransparency = 1
- local tweenInfoIn = TweenInfo.new(
- CONFIG.ANIMATION_DURATION,
- Enum.EasingStyle.Back,
- Enum.EasingDirection.Out
- )
- local tweenPos = TweenService:Create(frame, tweenInfoIn, {
- Position = endPos,
- BackgroundTransparency = 0
- })
- tweenPos:Play()
- end
- -- Animate Notification Out
- local function animateNotificationOut(frame)
- local endPos = UDim2.new(1, frame.Size.X.Offset, 0, -frame.Size.Y.Offset)
- local tweenInfoOut = TweenInfo.new(
- CONFIG.ANIMATION_DURATION,
- Enum.EasingStyle.Back,
- Enum.EasingDirection.In
- )
- local tweenOut = TweenService:Create(frame, tweenInfoOut, {
- Position = endPos,
- BackgroundTransparency = 1
- })
- tweenOut:Play()
- tweenOut.Completed:Connect(function()
- -- Remove from active notifications
- for i, notification in ipairs(NotificationQueue.Active) do
- if notification.Frame == frame then
- table.remove(NotificationQueue.Active, i)
- break
- end
- end
- frame:Destroy()
- -- Try to show next pending notification
- NotificationModule:ProcessQueue()
- end)
- end
- -- Animate Progress Bar
- local function animateProgressBar(progressBar, duration)
- local tweenInfo = TweenInfo.new(
- duration,
- Enum.EasingStyle.Linear
- )
- local progressTween = TweenService:Create(progressBar, tweenInfo, {
- Size = UDim2.new(0, 0, 1, 0)
- })
- progressTween:Play()
- end
- -- Process Notification Queue
- function NotificationModule:ProcessQueue()
- -- If we haven't reached max notifications and there are pending notifications
- if #self.NotificationQueue.Active < CONFIG.MAX_NOTIFICATIONS and
- #self.NotificationQueue.Pending > 0 then
- -- Get the next pending notification
- local nextNotification = table.remove(self.NotificationQueue.Pending, 1)
- -- Show the notification
- self:Show(
- nextNotification.Title,
- nextNotification.Description,
- nextNotification.Style
- )
- end
- end
- -- Main Notification Function
- function NotificationModule:Show(title, description, style)
- local player = Players.LocalPlayer
- if not player then return end
- -- Validate style
- style = style or "DEFAULT"
- style = CONFIG.STYLES[style] and style or "DEFAULT"
- -- If we've reached max notifications, queue this notification
- if #NotificationQueue.Active >= CONFIG.MAX_NOTIFICATIONS then
- table.insert(NotificationQueue.Pending, {
- Title = title,
- Description = description,
- Style = style
- })
- return
- end
- -- Create or find existing GUI container
- local container = player.PlayerGui:FindFirstChild("CosmicNotificationGui")
- or createNotificationContainer(player)
- -- Create notification frame
- local frame = createNotificationFrame(container, style)
- local titleLabel, descLabel, progressBar = createNotificationContent(
- frame, title, description, style
- )
- -- Track this active notification
- local notification = {
- Frame = frame,
- Title = title,
- Description = description,
- Style = style
- }
- table.insert(NotificationQueue.Active, notification)
- -- Animate in
- animateNotificationIn(frame)
- -- Animate progress bar
- animateProgressBar(progressBar, CONFIG.DURATION)
- -- Auto-dismiss
- task.delay(CONFIG.DURATION, function()
- if frame and frame.Parent then
- animateNotificationOut(frame)
- end
- end)
- return frame
- end
- -- Initialize NotificationQueue in the module
- NotificationModule.NotificationQueue = NotificationQueue
- -- Expose notification styles
- NotificationModule.Style = {
- DEFAULT = "DEFAULT",
- SUCCESS = "SUCCESS",
- WARNING = "WARNING",
- ERROR = "ERROR",
- INFO = "INFO"
- }
- return NotificationModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement