Files
2026-11-29 15:49:17 +03:00

573 lines
24 KiB
Luau
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--!strict
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local UI = {}
UI.Ink = Color3.fromRGB(241, 247, 253)
UI.Muted = Color3.fromRGB(160, 179, 198)
UI.Outline = Color3.fromRGB(229, 236, 242)
UI.Panel = Color3.fromRGB(25, 29, 34)
UI.Blue = Color3.fromRGB(83, 229, 248)
UI.Orange = Color3.fromRGB(255, 150, 71)
UI.Mint = Color3.fromRGB(114, 242, 178)
UI.Gold = Color3.fromRGB(255, 199, 79)
UI.Display = Font.new("rbxasset://fonts/families/Montserrat.json", Enum.FontWeight.Heavy, Enum.FontStyle.Italic)
local combatBottom = {Wallet = 76, Ammo = 16, Skin = 135}
type CombatSlot = "Wallet" | "Ammo" | "Skin"
function UI.combatScale(gui: ScreenGui): number
return if gui.AbsoluteSize.X < 560 then .80 else 1
end
function UI.placeCombat(item: GuiObject, slot: CombatSlot)
item.AnchorPoint = Vector2.new(1, 1)
item.Position = UDim2.new(1, -20, 1, -combatBottom[slot])
end
function UI.frame(name: string, parent: Instance, position: UDim2, size: UDim2, color: Color3): Frame
local frame = Instance.new("Frame")
frame.Name, frame.Position, frame.Size = name, position, size
frame.BackgroundColor3, frame.BorderSizePixel = color, 0
frame.Parent = parent
return frame
end
function UI.label(parent: Instance, name: string, value: string, pos: UDim2, size: UDim2, textSize: number, color: Color3): TextLabel
local text = Instance.new("TextLabel")
text.Name, text.Position, text.Size = name, pos, size
text.BackgroundTransparency = 1
text.Font = Enum.Font.GothamBold
text.Text, text.TextSize, text.TextColor3 = value, textSize, color
text.Parent = parent
return text
end
function UI.edge(target: GuiObject, color: Color3, opacity: number): UIStroke
local stroke = Instance.new("UIStroke")
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
stroke.Color, stroke.Thickness, stroke.Transparency = color, 1.2, 1 - opacity
stroke.Parent = target
return stroke
end
local white = Color3.new(1, 1, 1)
local zero, full = UDim2.fromScale(0, 0), UDim2.fromScale(1, 1)
local function layer(name: string, parent: Instance): Frame
local item = UI.frame(name, parent, zero, full, white)
item.BackgroundTransparency = 1
return item
end
local function plateArt(name: string, parent: Instance, cut: number, thick: number): Frame
local art = layer(name, parent)
art:SetAttribute("CornerCut", cut)
local fills, trim = layer("Surfaces", art), layer("Trim", art)
UI.frame("Body", fills, UDim2.fromOffset(0, cut), UDim2.new(1, 0, 1, -2 * cut), UI.Panel)
UI.frame("Upper", fills, UDim2.fromOffset(cut, 0), UDim2.new(1, -cut, 0, cut), UI.Panel)
UI.frame("Lower", fills, UDim2.new(0, 0, 1, -cut), UDim2.new(1, -cut, 0, cut), UI.Panel)
for _, far in {false, true} do
local s = if far then 1 else 0
local inset = if far then -cut else cut
local corner = UI.frame(if far then "LowerCut" else "UpperCut", fills, UDim2.new(s, inset, s, inset),
UDim2.fromOffset(cut * math.sqrt(2), cut * math.sqrt(2)), UI.Panel)
corner.AnchorPoint, corner.Rotation = Vector2.new(.5, .5), 45
local edge = UI.frame(corner.Name, trim, UDim2.new(s, inset / 2, s, inset / 2),
UDim2.fromOffset(cut * math.sqrt(2), thick), UI.Outline)
edge.AnchorPoint, edge.Rotation = Vector2.new(.5, .5), -45
end
UI.frame("Top", trim, UDim2.fromOffset(cut, 0), UDim2.new(1, -cut, 0, thick), UI.Outline)
UI.frame("Bottom", trim, UDim2.new(0, 0, 1, -thick), UDim2.new(1, -cut, 0, thick), UI.Outline)
UI.frame("Left", trim, UDim2.fromOffset(0, cut), UDim2.new(0, thick, 1, -cut), UI.Outline)
UI.frame("Right", trim, UDim2.new(1, -thick, 0, 0), UDim2.new(0, thick, 1, -cut), UI.Outline)
return art
end
local motion = TweenInfo.new(.13, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local function paint(art: Instance, fill: Color3, edge: Color3)
local surfaces, trim = art:FindFirstChild("Surfaces"), art:FindFirstChild("Trim")
assert(surfaces and trim, "Plate is missing its art layers")
for _, part in surfaces:GetChildren() do
if part:IsA("Frame") then part.BackgroundColor3 = fill end
end
for _, part in trim:GetChildren() do
if part:IsA("Frame") then part.BackgroundColor3 = edge end
end
end
local function strokeAt(parent: Instance, name: string, a: Vector2, b: Vector2, width: number, color: Color3): Frame
local delta = b - a
local mid = (a + b) / 2
local line = UI.frame(name, parent, UDim2.fromOffset(mid.X, mid.Y), UDim2.fromOffset(delta.Magnitude + 1.4, width), color)
line.AnchorPoint = Vector2.new(.5, .5)
line.Rotation = math.deg(math.atan2(delta.Y, delta.X))
return line
end
local function coinCamera(view: ViewportFrame): Camera
local camera = Instance.new("Camera")
camera.Name = "CoinCamera"
camera.FieldOfView = 30
camera.CFrame = CFrame.lookAt(Vector3.new(0, .035, 2.83), Vector3.zero)
camera.Parent = view
return camera
end
local function buildCoin(parent: Instance)
local art = layer("GoldCoin", parent)
art.Size = UDim2.fromOffset(36, 36)
local view = Instance.new("ViewportFrame")
view.Name = "Viewport"
view.Size = full
view.BackgroundTransparency = 1
view.Ambient = Color3.fromRGB(182, 152, 107)
view.LightColor = Color3.fromRGB(255, 232, 166)
view.LightDirection = Vector3.new(-.46, -.63, -.79)
view.Parent = art
view.CurrentCamera = coinCamera(view)
local world = Instance.new("WorldModel")
world.Parent = view
local model = Instance.new("Model")
model.Name = "TrophyCoin"
model.Parent = world
local function part(name: string, size: Vector3, at: CFrame, color: Color3, round: boolean): Part
local piece = Instance.new("Part")
piece.Name, piece.Size, piece.CFrame = name, size, at
piece.Shape = if round then Enum.PartType.Cylinder else Enum.PartType.Block
piece.Material = Enum.Material.SmoothPlastic
piece.Color = color
piece.Anchored, piece.CanCollide, piece.CanQuery, piece.CanTouch = true, false, false, false
piece.CastShadow = false
piece.Parent = model
return piece
end
local amber = Color3.fromRGB(204, 123, 25)
local bevel = Color3.fromRGB(255, 216, 109)
local face = Color3.fromRGB(241, 172, 49)
local stamp = Color3.fromRGB(142, 73, 17)
model.PrimaryPart = part("ReededRim", Vector3.new(.22, 1.27, 1.27), CFrame.identity, amber, true)
part("OuterBevel", Vector3.new(.25, 1.19, 1.19), CFrame.identity, bevel, true)
part("FaceRing", Vector3.new(.28, 1.09, 1.09), CFrame.identity, amber, true)
part("GoldFace", Vector3.new(.30, 1.02, 1.02), CFrame.identity, face, true)
for index = 0, 15 do
local angle = index * math.pi / 8
local at = CFrame.Angles(angle, 0, 0) * CFrame.new(0, .622, 0)
local tint = if index % 2 == 0 then bevel else face
part("RimReed", Vector3.new(.177, .025, .027), at, tint, false)
end
for _, side in {-1, 1} do
for _, z in {-.135, .135} do
part("StampH", Vector3.new(.018, .47, .077), CFrame.new(side * .151, 0, z), stamp, false)
end
part("StampH", Vector3.new(.019, .079, .27), CFrame.new(side * .151, 0, 0), stamp, false)
end
model:PivotTo(CFrame.fromOrientation(-.08, math.pi / 2, .08))
local glint = layer("Glint", art)
glint.Size = UDim2.fromOffset(23, 23)
glint.AnchorPoint, glint.Position = Vector2.new(.5, .5), UDim2.fromScale(.78, .26)
glint.Visible = false
local starScale = Instance.new("UIScale", glint)
starScale.Name = "Intensity"
for i = 0, 3 do
local ray = UI.frame("Ray", glint, UDim2.fromScale(.5, .5),
UDim2.fromOffset(if i < 2 then 2.5 else 1.3, if i < 2 then 22 - i * 6 else 11), Color3.fromRGB(255, 251, 217))
ray.AnchorPoint = Vector2.new(.5, .5)
ray.Rotation = if i == 0 then 0 elseif i == 1 then 90 elseif i == 2 then 45 else 135
local feather = Instance.new("UIGradient")
feather.Rotation = 90
feather.Transparency = NumberSequence.new({
NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(.5, 0), NumberSequenceKeypoint.new(1, 1),
})
feather.Parent = ray
end
end
local function buildElements(): Folder
local elements = Instance.new("Folder")
elements.Name = "Elements"
plateArt("Plate", elements, 13, 2)
plateArt("ScoreChip", elements, 11, 1)
local lightning = layer("ContourLightning", elements)
lightning.ZIndex = 3
local glowLayer, coreLayer = layer("Halo", lightning), layer("Core", lightning)
for i = 1, 6 do
for _, group in {glowLayer, coreLayer} do
local piece = UI.frame("Piece" .. i, group, zero, UDim2.fromOffset(0, 0), UI.Blue)
piece.AnchorPoint = Vector2.new(.5, .5)
end
end
local states = layer("ButtonStates", elements)
for _, name in {"Normal", "Hover", "Pressed", "Disabled"} do
local state = plateArt(name, states, 10, 1.7)
state.Visible = name == "Normal"
local tint = if name == "Hover" then .39 elseif name == "Pressed" then .17 else .03
paint(state, UI.Panel:Lerp(UI.Blue, tint), if name == "Disabled" then UI.Panel:Lerp(UI.Muted, .23) else UI.Blue)
end
local row = UI.frame("RowHighlight", elements, zero, full, UI.Blue)
row.BackgroundTransparency = 1
Instance.new("UICorner", row).CornerRadius = UDim.new(0, 5)
local playerRow = UI.frame("PlayerRow", elements, zero, UDim2.new(1, -5, 0, 28), UI.Panel:Lerp(UI.Blue, .14))
Instance.new("UICorner", playerRow).CornerRadius = UDim.new(0, 6)
local portrait = Instance.new("ImageLabel")
portrait.Name = "Portrait"
portrait.Size = UDim2.fromOffset(28, 28)
portrait.BackgroundColor3, portrait.BorderSizePixel = UI.Panel:Lerp(UI.Blue, .25), 0
portrait.ScaleType = Enum.ScaleType.Crop
portrait.Parent = elements
Instance.new("UICorner", portrait).CornerRadius = UDim.new(1, 0)
UI.edge(portrait, UI.Blue, .8)
UI.label(portrait, "Initial", "", zero, full, 13, UI.Ink)
local meter = UI.frame("ProgressBar", elements, zero, UDim2.fromOffset(100, 7), Color3.fromRGB(43, 57, 69))
meter.ClipsDescendants = true
Instance.new("UICorner", meter).CornerRadius = UDim.new(0, 3)
local fill = UI.frame("Fill", meter, zero, full, UI.Mint)
Instance.new("UICorner", fill).CornerRadius = UDim.new(0, 3)
local shield = layer("Shield", elements)
shield.Size = UDim2.fromOffset(21, 22)
local shieldPoints = {Vector2.new(10.5, 2), Vector2.new(19, 5.5), Vector2.new(17.5, 14.5),
Vector2.new(10.5, 20), Vector2.new(3.5, 14.5), Vector2.new(2, 5.5)}
for i, a in shieldPoints do strokeAt(shield, "Side", a, shieldPoints[i % #shieldPoints + 1], 2, UI.Mint) end
local ammo = layer("Ammo", elements)
ammo.Size = UDim2.fromOffset(27, 18)
for i = 0, 2 do
local casing = UI.frame("Cartridge", ammo, UDim2.fromOffset(3 + i * 8, 2), UDim2.fromOffset(5, 15), UI.Ink)
casing.Rotation = 13
Instance.new("UICorner", casing).CornerRadius = UDim.new(0, 2)
end
buildCoin(elements)
local key = UI.frame("Keycap", elements, zero, UDim2.fromOffset(25, 23), UI.Ink)
Instance.new("UICorner", key).CornerRadius = UDim.new(0, 4)
UI.label(key, "Key", "E", zero, full, 13, UI.Panel).Font = Enum.Font.GothamBlack
local glint = layer("SkinGlint", elements)
glint.Size = UDim2.fromOffset(18, 18)
local diamond = UI.frame("Mark", glint, UDim2.fromOffset(4, 4), UDim2.fromOffset(10, 10), UI.Blue)
diamond.Rotation = 45
UI.edge(diamond, UI.Ink, .65)
local tick = UI.frame("CrosshairTick", elements, zero, UDim2.fromOffset(2, 9), UI.Ink)
tick.AnchorPoint = Vector2.new(.5, .5)
UI.edge(tick, Color3.new(0, 0, 0), .65).Thickness = 1
local arc = layer("StreakArc", elements)
arc.Size = UDim2.fromOffset(165, 104)
for section = 1, 2 do
local group = layer("Segment" .. section, arc)
local radius = if section == 1 then Vector2.new(85, 77) else Vector2.new(76, 66)
local firstAngle = if section == 1 then 76 else 82
local sweep = if section == 1 then 69 else 58
for i = 1, 14 do
local u = (i - 1) / 14
local t = math.rad(firstAngle - u * sweep)
local nextT = math.rad(firstAngle - (u + 1 / 14) * sweep)
local a = Vector2.new(math.cos(t) * radius.X, math.sin(t) * radius.Y)
local b = Vector2.new(math.cos(nextT) * radius.X, math.sin(nextT) * radius.Y)
local width = 1.8 + math.sin(math.pi * (u + 1 / 28)) ^ .7 * (if section == 1 then 6.0 else 4.8)
local piece = strokeAt(group, "Piece" .. i, a, b, width, UI.Gold)
piece.BackgroundTransparency = if section == 1 then .94 else 1
end
end
local multiplier = UI.label(arc, "Multiplier", "×0", UDim2.fromOffset(94, 33), UDim2.fromOffset(72, 37), 27, UI.Gold)
multiplier.FontFace = UI.Display
multiplier.TextXAlignment = Enum.TextXAlignment.Left
multiplier.TextStrokeColor3, multiplier.TextStrokeTransparency = UI.Panel, .22
multiplier.Visible = false
return elements
end
UI.buildElements = buildElements
local elements = script:FindFirstChild("Elements") or buildElements()
function UI.element(name: string, parent: Instance, position: UDim2?, size: UDim2?): Frame
local template = elements:FindFirstChild(name)
assert(template and template:IsA("Frame"), "Missing UI element " .. name)
local frame = template:Clone()
if position then frame.Position = position end
if size then frame.Size = size end
frame.Parent = parent
return frame
end
export type CoinRig = {view: ViewportFrame, model: Model, glint: Frame, intensity: UIScale}
function UI.bindCoin(art: Frame): CoinRig
local view = art:WaitForChild("Viewport") :: ViewportFrame
local camera = view:FindFirstChild("CoinCamera")
view.CurrentCamera = if camera and camera:IsA("Camera") then camera else coinCamera(view)
local glint = art:WaitForChild("Glint") :: Frame
return {
view = view, model = view:WaitForChild("WorldModel"):WaitForChild("TrophyCoin") :: Model,
glint = glint, intensity = glint:WaitForChild("Intensity") :: UIScale,
}
end
function UI.spinCoin(rig: CoinRig, angle: number, flash: number, sweep: number)
rig.model:PivotTo(CFrame.fromOrientation(-.09, angle, .08 + .09 * math.sin(angle * .7)))
rig.glint.Visible = flash > .035
if rig.glint.Visible then
rig.intensity.Scale = .18 + .98 * flash
rig.glint.Position = UDim2.fromScale(.75 - .23 * sweep, .23 - .05 * math.sin(math.pi * sweep))
rig.glint.Rotation = 12 + sweep * 34
end
rig.view.LightColor = Color3.fromRGB(255, 226, 157):Lerp(Color3.fromRGB(255, 251, 220), flash)
end
function UI.portrait(parent: Instance, pos: UDim2, size: number, accent: Color3): ImageLabel
local template = elements:FindFirstChild("Portrait")
assert(template and template:IsA("ImageLabel"))
local art = template:Clone()
art.Name, art.Position, art.Size = "Avatar", pos, UDim2.fromOffset(size, size)
art.BackgroundColor3 = UI.Panel:Lerp(accent, .25)
local ring = art:FindFirstChildOfClass("UIStroke")
if ring then ring.Color = accent end
art.Parent = parent
return art
end
function UI.plate(parent: Instance, name: string, position: UDim2, size: UDim2, accent: Color3, fill: Color3?): Frame
local art = UI.element("Plate", parent, position, size)
art.Name = name
paint(art, fill or UI.Panel, accent)
return art
end
function UI.tintPlate(art: Frame, color: Color3, fill: Color3?)
paint(art, fill or UI.Panel, color)
end
type Bolt = {
art: Frame, core: {Frame}, halo: {Frame}, points: {Vector2}, lengths: {number},
size: Vector2, perimeter: number, phase: number,
}
local outlines: {[Frame]: Bolt} = {}
local contourRender: RBXScriptConnection? = nil
local lastContourFrame = 0
local function drawableScale(item: Frame): number?
local node: Instance? = item
local scale = 1
while node do
if node:IsA("GuiObject") then
if not node.Visible then return nil end
local modifier = node:FindFirstChildOfClass("UIScale")
if modifier then scale *= modifier.Scale end
elseif node:IsA("ScreenGui") then
return if node.Enabled then scale else nil
end
node = node.Parent
end
return nil
end
local function measure(plate: Frame, bolt: Bolt, size: Vector2)
bolt.size = size
local cut = (plate:GetAttribute("CornerCut") :: number?) or 13
local w, h = size.X - 1, size.Y - 1
bolt.points = {
Vector2.new(cut, 1), Vector2.new(w, 1), Vector2.new(w, size.Y - cut),
Vector2.new(size.X - cut, h), Vector2.new(1, h), Vector2.new(1, cut),
}
bolt.perimeter = 0
for i, point in bolt.points do
local edgeLength = (bolt.points[i % #bolt.points + 1] - point).Magnitude
bolt.lengths[i] = edgeLength
bolt.perimeter += edgeLength
end
end
local function contourPoint(bolt: Bolt, distance: number, wobble: number): Vector2
local remaining = distance % bolt.perimeter
for i, edgeLength in bolt.lengths do
if remaining <= edgeLength and edgeLength > 0 then
local a, b = bolt.points[i], bolt.points[i % #bolt.points + 1]
local direction = (b - a) / edgeLength
return a + direction * remaining + Vector2.new(-direction.Y, direction.X) * wobble
end
remaining -= edgeLength
end
return bolt.points[1]
end
local function playContours()
local now = os.clock()
if now - lastContourFrame < 1 / 40 then return end
lastContourFrame = now
for plate, bolt in outlines do
local scale = drawableScale(plate)
if not scale or scale < .01 then continue end
local size = plate.AbsoluteSize / scale
if size.X < 25 or size.Y < 24 then continue end
if (bolt.size - size).Magnitude > .7 then measure(plate, bolt, size) end
local accent = (bolt.art:GetAttribute("Accent") :: Color3?) or UI.Blue
local tail = now * 218 + bolt.phase - 28
local zigzag = math.floor(now * 16)
local a = contourPoint(bolt, tail, 0)
for i, core in bolt.core do
local strength = i / #bolt.core
local wobble = if i == #bolt.core then 0 else math.sin(i * 11.7 + zigzag * 1.9 + bolt.phase) * 2
local b = contourPoint(bolt, tail + 28 * strength, wobble)
local center, delta = (a + b) / 2, b - a
local rotation = math.deg(math.atan2(delta.Y, delta.X))
local halo = bolt.halo[i]
halo.Rotation, core.Rotation = rotation, rotation
local position = UDim2.fromOffset(center.X, center.Y)
halo.Position, core.Position = position, position
halo.Size = UDim2.fromOffset(delta.Magnitude + 3, 5)
core.Size = UDim2.fromOffset(delta.Magnitude + 1.5, 1 + strength * 1.7)
halo.BackgroundColor3 = accent
core.BackgroundColor3 = accent:Lerp(white, .25 + strength * .68)
halo.BackgroundTransparency = .97 - strength * .25
core.BackgroundTransparency = .81 - strength * .76
a = b
end
end
end
function UI.contour(plate: Frame, accent: Color3): Frame
local art = UI.element("ContourLightning", plate)
art:SetAttribute("Accent", accent)
local core: {Frame}, halo: {Frame} = {}, {}
local coreLayer, haloLayer = art:WaitForChild("Core"), art:WaitForChild("Halo")
for i = 1, 6 do
table.insert(core, coreLayer:WaitForChild("Piece" .. i) :: Frame)
table.insert(halo, haloLayer:WaitForChild("Piece" .. i) :: Frame)
end
outlines[plate] = {
art = art, core = core, halo = halo, points = {}, lengths = {},
size = Vector2.zero, perimeter = 0, phase = Random.new():NextNumber(0, 2500),
}
if not contourRender then contourRender = RunService.RenderStepped:Connect(playContours) end
plate.Destroying:Once(function()
outlines[plate] = nil
if next(outlines) == nil and contourRender then
contourRender:Disconnect()
contourRender = nil
end
end)
return art
end
function UI.sheen(target: GuiObject)
local glint = Instance.new("UIGradient")
glint.Name = "Shimmer"
glint.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(163, 171, 181)),
ColorSequenceKeypoint.new(.38, Color3.fromRGB(201, 211, 219)),
ColorSequenceKeypoint.new(.52, white),
ColorSequenceKeypoint.new(.65, Color3.fromRGB(210, 218, 224)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(166, 177, 187)),
})
glint.Offset = Vector2.new(-.64, 0)
glint.Parent = target
local tween = TweenService:Create(glint, TweenInfo.new(1.75, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
Offset = Vector2.new(.64, 0),
})
tween:Play()
target.Destroying:Once(function() tween:Cancel() end)
return glint
end
function UI.bindButton(item: TextButton, accent: Color3, compact: boolean?)
item.AutoButtonColor = false
local states = if compact then nil else UI.element("ButtonStates", item)
local caption = if compact then nil else UI.label(item, "Caption", item.Text, zero, full, item.TextSize, item.TextColor3)
local simpleEdge = if compact then UI.edge(item, accent, .26) else nil
if caption then
item.BackgroundTransparency = 1
item.TextTransparency = 1
caption.ZIndex = item.ZIndex + 2
end
local scale = Instance.new("UIScale", item)
local hovered, focused, pressed = false, false, false
local lastTween: Tween? = nil
if states then
local hoverArt = states:WaitForChild("Hover") :: Frame
local hoverTrim = hoverArt:WaitForChild("Trim"):WaitForChild("Top") :: Frame
UI.sheen(hoverTrim)
UI.contour(hoverArt, accent)
end
local function colorStates()
if not states then return end
local base = item.BackgroundColor3
for _, art in states:GetChildren() do
if art:IsA("Frame") then
local name = art.Name
local amount = if name == "Hover" then .27 elseif name == "Pressed" then .08 else 0
local edge = if name == "Disabled" then UI.Panel:Lerp(UI.Muted, .28)
elseif name == "Normal" then accent:Lerp(UI.Panel, .43) else accent
paint(art, base:Lerp(accent, amount), edge)
end
end
end
local function update()
local enabled = item.Interactable and item.Visible
local nextState = if not enabled then "Disabled" elseif pressed then "Pressed" elseif hovered or focused then "Hover" else "Normal"
if item:GetAttribute("UIState") == nextState then return end
item:SetAttribute("UIState", nextState)
if states then
for _, art in states:GetChildren() do
if art:IsA("GuiObject") then art.Visible = art.Name == nextState end
end
elseif simpleEdge then
simpleEdge.Transparency = if nextState == "Pressed" then 0 elseif nextState == "Hover" then .12 else .74
end
if lastTween then lastTween:Cancel() end
lastTween = TweenService:Create(scale, motion, {Scale = if nextState == "Pressed" then .965 elseif nextState == "Hover" then 1.02 else 1})
lastTween:Play()
end
local function copyText()
if not caption then return end
caption.Text, caption.TextColor3, caption.TextSize = item.Text, item.TextColor3, item.TextSize
caption.FontFace, caption.TextScaled = item.FontFace, item.TextScaled
end
copyText()
if caption then
for _, prop in {"Text", "TextColor3", "TextSize", "FontFace", "TextScaled"} do
item:GetPropertyChangedSignal(prop):Connect(copyText)
end
item:GetPropertyChangedSignal("BackgroundColor3"):Connect(colorStates)
end
item.MouseEnter:Connect(function() hovered = true update() end)
item.MouseLeave:Connect(function() hovered, pressed = false, false update() end)
item.SelectionGained:Connect(function() focused = true update() end)
item.SelectionLost:Connect(function() focused, pressed = false, false update() end)
local function isPress(input: InputObject): boolean
return input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch
or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.Return
end
item.InputBegan:Connect(function(input)
if isPress(input) and item.Interactable then pressed = true update() end
end)
item.InputEnded:Connect(function(input)
if isPress(input) then pressed = false update() end
end)
for _, prop in {"Interactable", "Visible"} do
item:GetPropertyChangedSignal(prop):Connect(function()
if not item.Visible or not item.Interactable then hovered, focused, pressed = false, false, false end
update()
end)
end
colorStates()
update()
end
function UI.hoverRow(row: Frame, accent: Color3)
local overlay = UI.element("RowHighlight", row)
overlay.BackgroundColor3 = accent
local animation: Tween? = nil
local function update(hovered: boolean)
local on = hovered and row.Visible and row.Interactable
row:SetAttribute("UIState", if on then "Hover" else "Normal")
if animation then animation:Cancel() end
animation = TweenService:Create(overlay, motion, {BackgroundTransparency = if on then .80 else 1})
animation:Play()
end
row.MouseEnter:Connect(function() update(true) end)
row.MouseLeave:Connect(function() update(false) end)
row:GetPropertyChangedSignal("Visible"):Connect(function() if not row.Visible then update(false) end end)
row:GetPropertyChangedSignal("Interactable"):Connect(function() if not row.Interactable then update(false) end end)
row:SetAttribute("UIState", "Normal")
end
return UI