Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1. 首先初始化字体系统
- if isfile("SmallestPixel7.font") then
- delfile("SmallestPixel7.font")
- end
- writefile("fs-tahoma-8px.ttf", game:HttpGet("https://github.com/i77lhm/storage/raw/refs/heads/main/fonts/fs-tahoma-8px.ttf"))
- -- 自定义字体注册
- local fontAsset
- do
- getsynasset = getcustomasset or getsynasset
- Font = setreadonly(Font, false)
- function Font:Register(Name, Weight, Style, Asset)
- if not isfile(Name .. ".font") then
- if not isfile(Asset.Id) then
- writefile(Asset.Id, Asset.Font)
- end
- local Data = {
- name = Name,
- faces = {{
- name = "Regular",
- weight = Weight,
- style = Style,
- assetId = getsynasset(Asset.Id)
- }}
- }
- writefile(Name .. ".font", game:GetService("HttpService"):JSONEncode(Data))
- return getsynasset(Name .. ".font")
- else
- warn("Font already registered")
- end
- end
- function Font:GetRegistry(Name)
- if isfile(Name .. ".font") then
- return getsynasset(Name .. ".font")
- end
- end
- Font:Register("SmallestPixel7", 400, "normal", {Id = "fs-tahoma-8px.ttf", Font = ""})
- fontAsset = Font:GetRegistry("SmallestPixel7")
- end
- -- 2. 通知配置
- local config = {
- minWidth = 120, -- 最小宽度
- maxWidth = 400, -- 最大宽度
- padding = 12, -- 内边距
- duration = 3,
- spacing = 4, -- 默认持续时间
- accentColor = Color3.fromRGB(255, 174, 174), -- 强调色
- backgroundColor = Color3.fromRGB(30, 30, 40), -- 背景色
- textColor = Color3.fromRGB(255, 255, 255), -- 文字颜色
- fontSize = 12 -- 字体大小
- }
- local Notifications = {ActiveNotifs = {}}
- local TweenService = game:GetService("TweenService")
- local RunService = game:GetService("RunService")
- local Players = game:GetService("Players")
- local CoreGui = game:GetService("CoreGui")
- local TextService = game:GetService("TextService")
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Name = "NotificationSystem"
- ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- ScreenGui.Parent = RunService:IsStudio() and Players.LocalPlayer:WaitForChild("PlayerGui") or CoreGui
- local function SetFont(label)
- if fontAsset then
- label.FontFace = Font.new(fontAsset)
- else
- label.Font = Enum.Font.Arcade
- end
- label.TextSize = config.fontSize
- end
- local function GetTextWidth(text)
- local textParams = Instance.new("GetTextBoundsParams")
- textParams.Text = text
- textParams.Font = fontAsset and Font.new(fontAsset) or Enum.Font.Arcade
- textParams.Size = config.fontSize
- textParams.Width = math.huge
- local bounds = TextService:GetTextBoundsAsync(textParams)
- return bounds.X
- end
- function Notifications:UpdatePositions()
- local startY = 20
- local notificationHeight = 30
- for i, notif in ipairs(self.ActiveNotifs) do
- local yPos = startY + ((notificationHeight + config.spacing) * (i-1))
- local xPos = notif.Config.side == "right" and
- (workspace.CurrentCamera.ViewportSize.X - notif.Container.AbsoluteSize.X - 20) or
- 20
- TweenService:Create(
- notif.Container,
- TweenInfo.new(0.3, Enum.EasingStyle.Quad),
- {Position = UDim2.new(0, xPos, 0, yPos)}
- ):Play()
- end
- end
- function Notifications:New(customConfig)
- local currentConfig = table.clone(config)
- for k,v in pairs(customConfig or {}) do
- currentConfig[k] = v
- end
- local textWidth = GetTextWidth(currentConfig.text)
- local calculatedWidth = math.clamp(textWidth + currentConfig.padding * 2, currentConfig.minWidth, currentConfig.maxWidth)
- local container = Instance.new("Frame")
- container.Name = "Notification"
- container.BackgroundTransparency = 1
- container.Size = UDim2.new(0, calculatedWidth, 0, 15)
- container.Position = UDim2.new(currentConfig.side == "right" and 1 or -1, currentConfig.side == "right" and -20 or 20, 0, 20)
- container.AnchorPoint = currentConfig.side == "right" and Vector2.new(1, 0) or Vector2.new(0, 0)
- container.Parent = ScreenGui
- local background = Instance.new("Frame")
- background.Name = "Background"
- background.Size = UDim2.new(1, 0, 1, 0)
- background.BackgroundColor3 = currentConfig.backgroundColor
- background.BackgroundTransparency = 1
- background.BorderSizePixel = 0
- background.Parent = container
- local accent = Instance.new("Frame")
- accent.Name = "Accent"
- accent.Size = UDim2.new(0, 3, 1, 0)
- accent.Position = UDim2.new(currentConfig.side == "right" and 1 or 0, currentConfig.side == "right" and -3 or 0, 0, 0)
- accent.AnchorPoint = currentConfig.side == "right" and Vector2.new(1, 0) or Vector2.new(0, 0)
- accent.BackgroundColor3 = currentConfig.color or currentConfig.accentColor
- accent.BackgroundTransparency = 1
- accent.BorderSizePixel = 0
- accent.Parent = background
- local textLabel = Instance.new("TextLabel")
- textLabel.Name = "Text"
- textLabel.Text = currentConfig.text
- textLabel.TextColor3 = currentConfig.textColor
- textLabel.TextTransparency = 1
- textLabel.TextXAlignment = Enum.TextXAlignment.Left
- textLabel.BackgroundTransparency = 1
- textLabel.Size = UDim2.new(1, -currentConfig.padding, 1, 0)
- textLabel.Position = UDim2.new(0, currentConfig.side == "right" and 0 or currentConfig.padding/2, 0, 0)
- textLabel.TextWrapped = true
- textLabel.Parent = background
- SetFont(textLabel)
- textLabel.TextXAlignment = currentConfig.side == "right" and Enum.TextXAlignment.Right or Enum.TextXAlignment.Left
- local notification = {
- Container = container,
- Config = currentConfig,
- Destroy = function(self)
- local tweenOut = TweenInfo.new(0.5, Enum.EasingStyle.Quad)
- local slideOutPos = UDim2.new(currentConfig.side == "right" and 1 or -1, currentConfig.side == "right" and -20 or 20, 0, container.Position.Y.Offset)
- TweenService:Create(background, tweenOut, {BackgroundTransparency = 1}):Play()
- TweenService:Create(accent, tweenOut, {BackgroundTransparency = 1}):Play()
- TweenService:Create(textLabel, tweenOut, {TextTransparency = 1}):Play()
- TweenService:Create(container, tweenOut, {Position = slideOutPos}):Play()
- for i, notif in ipairs(Notifications.ActiveNotifs) do
- if notif == self then
- table.remove(Notifications.ActiveNotifs, i)
- break
- end
- end
- Notifications:UpdatePositions()
- task.wait(0.5)
- container:Destroy()
- end,
- UpdateText = function(self, newText)
- textLabel.Text = newText
- local textWidth = GetTextWidth(newText)
- local newWidth = math.clamp(textWidth + currentConfig.padding * 2, currentConfig.minWidth, currentConfig.maxWidth)
- TweenService:Create(container, TweenInfo.new(0.3), {Size = UDim2.new(0, newWidth, 0, 30)}):Play()
- Notifications:UpdatePositions()
- end,
- UpdateFont = function(self)
- SetFont(textLabel)
- end
- }
- table.insert(self.ActiveNotifs, notification)
- local tweenIn = TweenInfo.new(0.5, Enum.EasingStyle.Quad)
- local targetX = currentConfig.side == "right" and (workspace.CurrentCamera.ViewportSize.X - calculatedWidth - 20) or 20
- TweenService:Create(background, tweenIn, {BackgroundTransparency = 0}):Play()
- TweenService:Create(accent, tweenIn, {BackgroundTransparency = 0}):Play()
- TweenService:Create(textLabel, tweenIn, {TextTransparency = 0}):Play()
- TweenService:Create(container, tweenIn, {Position = UDim2.new(0, targetX, 0, 20)}):Play()
- self:UpdatePositions()
- if currentConfig.flash then
- task.spawn(function()
- local time = 0
- while task.wait(0.05) do
- if not container.Parent then break end
- time = time + 0.05
- local pulse = (math.sin(time * 5) + 1) / 2
- accent.BackgroundColor3 = (currentConfig.color or currentConfig.accentColor):Lerp(Color3.new(1, 1, 1), pulse)
- end
- end)
- end
- task.delay(currentConfig.duration, function()
- if container.Parent then
- notification:Destroy()
- end
- end)
- return notification
- end
- function Notifications:Notify(text, duration, flash, side)
- return self:New({
- text = text or "Notification",
- duration = duration or config.duration,
- flash = flash or false,
- side = side or "left"
- })
- end
- return Notifications
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement