Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --!optimize 2
- local TextService = game:GetService("TextService")
- local root = script.Parent.Parent
- local functions = root.Functions
- local shadow = require(functions.Shadow)
- local services = root.Services
- local tweens = require(services.Tweens)
- local gui = root.Gui
- local colors = require(gui.Colors)
- local core = require(gui.Core)
- local mouseInBounds = core.MouseInBounds
- local instanceEvent = core.InstanceEvent
- local event = core.Event
- local maxWidth = 115
- local container = Instance.new("Frame")
- container.BackgroundTransparency = 1
- container.BorderSizePixel = 0
- container.ClipsDescendants = true
- container.Visible = false
- container.Name = "Tooltip"
- container.Parent = core.Window
- local frame = Instance.new("Frame")
- frame.BackgroundColor3 = colors.Tooltip
- frame.BorderColor3 = colors.Border.Primary
- frame.ZIndex = 2147483647 -- int-32 limit.
- frame.Parent = container
- local label = Instance.new("TextLabel")
- label.Position = UDim2.fromOffset(6, 6)
- label.Size = UDim2.new(0, maxWidth, 1, 0)
- label.BackgroundTransparency = 1
- label.Font = Enum.Font.SourceSans
- label.RichText = true
- label.TextSize = 14
- label.TextColor3 = colors.Text.Primary
- label.TextXAlignment = Enum.TextXAlignment.Left
- label.TextYAlignment = Enum.TextYAlignment.Top
- label.TextWrapped = true
- label.Text = ""
- label.ZIndex = 2147483647 -- int-32 limit.
- label.Parent = frame
- shadow(frame, true)
- local function updatePosition()
- if container.Visible == false then return end
- local mousePosition = core.MousePosition
- container.Position = UDim2.fromOffset(
- mousePosition.X + 3,
- mousePosition.Y + 16
- )
- end
- event.MouseMove:Connect(updatePosition)
- local toggled = true
- local wasVisible = false
- local becameVisible = false
- local moveUpdate = false
- type Module = {
- Setup: (area: GuiBase2d, tooltip: string) -> (),
- Toggle: (state: boolean) -> ()
- }
- local module = {}
- module.Toggle = function(state)
- if state == true then
- toggled = true
- else
- toggled = false
- container.Visible = false
- end
- end
- module.Setup = function(area, tooltip)
- local size = TextService:GetTextSize(tooltip, 14, Enum.Font.SourceSans, Vector2.new(maxWidth, math.huge))
- local containerSize = UDim2.fromOffset(size.X + 18, size.Y + 22)
- size = UDim2.fromOffset(size.X + 12, size.Y + 16)
- local thread = nil
- local moveConnection = nil
- local clickConnection = nil
- local function hover()
- thread = coroutine.create(function()
- task.wait(0.7)
- moveConnection:Disconnect()
- moveConnection = nil
- local mousePosition = core.MousePosition
- container.Position = UDim2.fromOffset(
- mousePosition.X + 3,
- mousePosition.Y + 16
- )
- frame.Position = UDim2.fromOffset(1, -(containerSize.Y.Offset + 1))
- frame.Size = size
- container.Size = containerSize
- label.Text = tooltip
- container.Visible = true
- tweens:Create(frame, TweenInfo.new(0.0667, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = UDim2.fromOffset(1, 1)}):Play()
- task.wait(10)
- container.Visible = false
- if moveConnection == nil then
- moveConnection = event.MouseMove:Connect(function()
- if toggled == false then return end
- if mouseInBounds(area) == true then
- if thread ~= nil then coroutine.close(thread) end
- hover()
- end
- end)
- end
- thread = nil
- end)
- coroutine.resume(thread)
- end
- instanceEvent.MouseEnter(area, function()
- if toggled == false then return end
- if thread ~= nil then return end
- if container.Visible == false and wasVisible == false then
- moveConnection = event.MouseMove:Connect(function()
- if toggled == false then return end
- if mouseInBounds(area) == true then
- if thread ~= nil then coroutine.close(thread) end
- hover()
- end
- end)
- clickConnection = event.MouseButton1Down:Connect(function()
- if thread ~= nil then
- coroutine.close(thread)
- thread = nil
- end
- if moveConnection == nil then
- moveConnection = event.MouseMove:Connect(function()
- if toggled == false then return end
- if mouseInBounds(area) == true then
- if thread ~= nil then coroutine.close(thread) end
- hover()
- end
- end)
- end
- container.Visible = false
- end)
- hover()
- else
- local mousePosition = core.MousePosition
- container.Position = UDim2.fromOffset(
- mousePosition.X + 3,
- mousePosition.Y + 16
- )
- frame.Position = UDim2.fromOffset(1, 1)
- frame.Size = size
- container.Size = containerSize
- label.Text = tooltip
- container.Visible = true
- becameVisible = true
- task.wait()
- becameVisible = false
- end
- end)
- instanceEvent.MouseLeave(area, function()
- if thread ~= nil then
- coroutine.close(thread)
- thread = nil
- end
- if moveConnection ~= nil then
- moveConnection:Disconnect()
- moveConnection = nil
- end
- if clickConnection ~= nil then
- clickConnection:Disconnect()
- clickConnection = nil
- end
- if becameVisible == false and container.Visible == true then
- wasVisible = true
- container.Visible = false
- task.wait()
- wasVisible = false
- end
- end)
- area:GetPropertyChangedSignal("AbsolutePosition"):Connect(function()
- if toggled == false then return end
- if moveUpdate == true then return end
- moveUpdate = true
- updatePosition()
- task.wait()
- moveUpdate = false
- end)
- end
- return table.freeze(module) :: Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement