Advertisement
kele666CN

notif

Apr 14th, 2025 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1. -- 1. 首先初始化字体系统
  2. if isfile("SmallestPixel7.font") then
  3. delfile("SmallestPixel7.font")
  4. end
  5.  
  6. writefile("fs-tahoma-8px.ttf", game:HttpGet("https://github.com/i77lhm/storage/raw/refs/heads/main/fonts/fs-tahoma-8px.ttf"))
  7.  
  8. -- 自定义字体注册
  9. local fontAsset
  10. do
  11. getsynasset = getcustomasset or getsynasset
  12. Font = setreadonly(Font, false)
  13. function Font:Register(Name, Weight, Style, Asset)
  14. if not isfile(Name .. ".font") then
  15. if not isfile(Asset.Id) then
  16. writefile(Asset.Id, Asset.Font)
  17. end
  18.  
  19. local Data = {
  20. name = Name,
  21. faces = {{
  22. name = "Regular",
  23. weight = Weight,
  24. style = Style,
  25. assetId = getsynasset(Asset.Id)
  26. }}
  27. }
  28.  
  29. writefile(Name .. ".font", game:GetService("HttpService"):JSONEncode(Data))
  30. return getsynasset(Name .. ".font")
  31. else
  32. warn("Font already registered")
  33. end
  34. end
  35.  
  36. function Font:GetRegistry(Name)
  37. if isfile(Name .. ".font") then
  38. return getsynasset(Name .. ".font")
  39. end
  40. end
  41.  
  42. Font:Register("SmallestPixel7", 400, "normal", {Id = "fs-tahoma-8px.ttf", Font = ""})
  43. fontAsset = Font:GetRegistry("SmallestPixel7")
  44. end
  45.  
  46. -- 2. 通知配置
  47. local config = {
  48. minWidth = 120, -- 最小宽度
  49. maxWidth = 400, -- 最大宽度
  50. padding = 12, -- 内边距
  51. duration = 3,
  52. spacing = 4, -- 默认持续时间
  53. accentColor = Color3.fromRGB(255, 174, 174), -- 强调色
  54. backgroundColor = Color3.fromRGB(30, 30, 40), -- 背景色
  55. textColor = Color3.fromRGB(255, 255, 255), -- 文字颜色
  56. fontSize = 12 -- 字体大小
  57. }
  58.  
  59. local Notifications = {ActiveNotifs = {}}
  60. local TweenService = game:GetService("TweenService")
  61. local RunService = game:GetService("RunService")
  62. local Players = game:GetService("Players")
  63. local CoreGui = game:GetService("CoreGui")
  64. local TextService = game:GetService("TextService")
  65.  
  66. local ScreenGui = Instance.new("ScreenGui")
  67. ScreenGui.Name = "NotificationSystem"
  68. ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  69. ScreenGui.Parent = RunService:IsStudio() and Players.LocalPlayer:WaitForChild("PlayerGui") or CoreGui
  70.  
  71. local function SetFont(label)
  72. if fontAsset then
  73. label.FontFace = Font.new(fontAsset)
  74. else
  75. label.Font = Enum.Font.Arcade
  76. end
  77. label.TextSize = config.fontSize
  78. end
  79.  
  80. local function GetTextWidth(text)
  81. local textParams = Instance.new("GetTextBoundsParams")
  82. textParams.Text = text
  83. textParams.Font = fontAsset and Font.new(fontAsset) or Enum.Font.Arcade
  84. textParams.Size = config.fontSize
  85. textParams.Width = math.huge
  86.  
  87. local bounds = TextService:GetTextBoundsAsync(textParams)
  88. return bounds.X
  89. end
  90.  
  91. function Notifications:UpdatePositions()
  92. local startY = 20
  93. local notificationHeight = 30
  94.  
  95. for i, notif in ipairs(self.ActiveNotifs) do
  96. local yPos = startY + ((notificationHeight + config.spacing) * (i-1))
  97. local xPos = notif.Config.side == "right" and
  98. (workspace.CurrentCamera.ViewportSize.X - notif.Container.AbsoluteSize.X - 20) or
  99. 20
  100. TweenService:Create(
  101. notif.Container,
  102. TweenInfo.new(0.3, Enum.EasingStyle.Quad),
  103. {Position = UDim2.new(0, xPos, 0, yPos)}
  104. ):Play()
  105. end
  106. end
  107.  
  108. function Notifications:New(customConfig)
  109. local currentConfig = table.clone(config)
  110. for k,v in pairs(customConfig or {}) do
  111. currentConfig[k] = v
  112. end
  113.  
  114. local textWidth = GetTextWidth(currentConfig.text)
  115. local calculatedWidth = math.clamp(textWidth + currentConfig.padding * 2, currentConfig.minWidth, currentConfig.maxWidth)
  116.  
  117. local container = Instance.new("Frame")
  118. container.Name = "Notification"
  119. container.BackgroundTransparency = 1
  120. container.Size = UDim2.new(0, calculatedWidth, 0, 15)
  121. container.Position = UDim2.new(currentConfig.side == "right" and 1 or -1, currentConfig.side == "right" and -20 or 20, 0, 20)
  122. container.AnchorPoint = currentConfig.side == "right" and Vector2.new(1, 0) or Vector2.new(0, 0)
  123. container.Parent = ScreenGui
  124.  
  125. local background = Instance.new("Frame")
  126. background.Name = "Background"
  127. background.Size = UDim2.new(1, 0, 1, 0)
  128. background.BackgroundColor3 = currentConfig.backgroundColor
  129. background.BackgroundTransparency = 1
  130. background.BorderSizePixel = 0
  131. background.Parent = container
  132.  
  133. local accent = Instance.new("Frame")
  134. accent.Name = "Accent"
  135. accent.Size = UDim2.new(0, 3, 1, 0)
  136. accent.Position = UDim2.new(currentConfig.side == "right" and 1 or 0, currentConfig.side == "right" and -3 or 0, 0, 0)
  137. accent.AnchorPoint = currentConfig.side == "right" and Vector2.new(1, 0) or Vector2.new(0, 0)
  138. accent.BackgroundColor3 = currentConfig.color or currentConfig.accentColor
  139. accent.BackgroundTransparency = 1
  140. accent.BorderSizePixel = 0
  141. accent.Parent = background
  142.  
  143. local textLabel = Instance.new("TextLabel")
  144. textLabel.Name = "Text"
  145. textLabel.Text = currentConfig.text
  146. textLabel.TextColor3 = currentConfig.textColor
  147. textLabel.TextTransparency = 1
  148. textLabel.TextXAlignment = Enum.TextXAlignment.Left
  149. textLabel.BackgroundTransparency = 1
  150. textLabel.Size = UDim2.new(1, -currentConfig.padding, 1, 0)
  151. textLabel.Position = UDim2.new(0, currentConfig.side == "right" and 0 or currentConfig.padding/2, 0, 0)
  152. textLabel.TextWrapped = true
  153. textLabel.Parent = background
  154.  
  155. SetFont(textLabel)
  156.  
  157. textLabel.TextXAlignment = currentConfig.side == "right" and Enum.TextXAlignment.Right or Enum.TextXAlignment.Left
  158.  
  159. local notification = {
  160. Container = container,
  161. Config = currentConfig,
  162. Destroy = function(self)
  163. local tweenOut = TweenInfo.new(0.5, Enum.EasingStyle.Quad)
  164. local slideOutPos = UDim2.new(currentConfig.side == "right" and 1 or -1, currentConfig.side == "right" and -20 or 20, 0, container.Position.Y.Offset)
  165.  
  166. TweenService:Create(background, tweenOut, {BackgroundTransparency = 1}):Play()
  167. TweenService:Create(accent, tweenOut, {BackgroundTransparency = 1}):Play()
  168. TweenService:Create(textLabel, tweenOut, {TextTransparency = 1}):Play()
  169. TweenService:Create(container, tweenOut, {Position = slideOutPos}):Play()
  170.  
  171. for i, notif in ipairs(Notifications.ActiveNotifs) do
  172. if notif == self then
  173. table.remove(Notifications.ActiveNotifs, i)
  174. break
  175. end
  176. end
  177.  
  178. Notifications:UpdatePositions()
  179.  
  180. task.wait(0.5)
  181. container:Destroy()
  182. end,
  183. UpdateText = function(self, newText)
  184. textLabel.Text = newText
  185. local textWidth = GetTextWidth(newText)
  186. local newWidth = math.clamp(textWidth + currentConfig.padding * 2, currentConfig.minWidth, currentConfig.maxWidth)
  187.  
  188. TweenService:Create(container, TweenInfo.new(0.3), {Size = UDim2.new(0, newWidth, 0, 30)}):Play()
  189. Notifications:UpdatePositions()
  190. end,
  191. UpdateFont = function(self)
  192. SetFont(textLabel)
  193. end
  194. }
  195.  
  196. table.insert(self.ActiveNotifs, notification)
  197.  
  198. local tweenIn = TweenInfo.new(0.5, Enum.EasingStyle.Quad)
  199. local targetX = currentConfig.side == "right" and (workspace.CurrentCamera.ViewportSize.X - calculatedWidth - 20) or 20
  200.  
  201. TweenService:Create(background, tweenIn, {BackgroundTransparency = 0}):Play()
  202. TweenService:Create(accent, tweenIn, {BackgroundTransparency = 0}):Play()
  203. TweenService:Create(textLabel, tweenIn, {TextTransparency = 0}):Play()
  204. TweenService:Create(container, tweenIn, {Position = UDim2.new(0, targetX, 0, 20)}):Play()
  205.  
  206. self:UpdatePositions()
  207.  
  208. if currentConfig.flash then
  209. task.spawn(function()
  210. local time = 0
  211. while task.wait(0.05) do
  212. if not container.Parent then break end
  213. time = time + 0.05
  214. local pulse = (math.sin(time * 5) + 1) / 2
  215. accent.BackgroundColor3 = (currentConfig.color or currentConfig.accentColor):Lerp(Color3.new(1, 1, 1), pulse)
  216. end
  217. end)
  218. end
  219.  
  220. task.delay(currentConfig.duration, function()
  221. if container.Parent then
  222. notification:Destroy()
  223. end
  224. end)
  225.  
  226. return notification
  227. end
  228.  
  229. function Notifications:Notify(text, duration, flash, side)
  230. return self:New({
  231. text = text or "Notification",
  232. duration = duration or config.duration,
  233. flash = flash or false,
  234. side = side or "left"
  235. })
  236. end
  237.  
  238. return Notifications
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement