285 lines
10 KiB
Luau
285 lines
10 KiB
Luau
--!strict
|
|
local Players = game:GetService("Players")
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
local RunService = game:GetService("RunService")
|
|
local TweenService = game:GetService("TweenService")
|
|
|
|
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
|
local player = Players.LocalPlayer
|
|
local gold = Color3.fromRGB(255, 211, 95)
|
|
|
|
local gui = Instance.new("ScreenGui")
|
|
gui.Name = "TrophyBalance"
|
|
gui.ResetOnSpawn = false
|
|
gui.DisplayOrder = 24
|
|
gui.Parent = player:WaitForChild("PlayerGui")
|
|
|
|
local function frame(name: string, parent: Instance, size: UDim2, color: Color3, radius: number): Frame
|
|
local item = Instance.new("Frame")
|
|
item.Name = name
|
|
item.Size = size
|
|
item.BackgroundColor3 = color
|
|
item.BorderSizePixel = 0
|
|
item.Parent = parent
|
|
Instance.new("UICorner", item).CornerRadius = UDim.new(0, radius)
|
|
return item
|
|
end
|
|
|
|
local function edge(item: GuiObject, color: Color3, thickness: number, transparency: number): UIStroke
|
|
local stroke = Instance.new("UIStroke")
|
|
stroke.Color = color
|
|
stroke.Thickness = thickness
|
|
stroke.Transparency = transparency
|
|
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
|
stroke.Parent = item
|
|
return stroke
|
|
end
|
|
|
|
local function label(name: string, parent: Instance, text: string, position: UDim2, size: UDim2, fontSize: number, color: Color3): TextLabel
|
|
local item = Instance.new("TextLabel")
|
|
item.Name = name
|
|
item.BackgroundTransparency = 1
|
|
item.Position = position
|
|
item.Size = size
|
|
item.Font = Enum.Font.GothamBold
|
|
item.Text = text
|
|
item.TextSize = fontSize
|
|
item.TextColor3 = color
|
|
item.Parent = parent
|
|
return item
|
|
end
|
|
|
|
local pill = UI.plate(gui, "Wallet", UDim2.fromOffset(0, 0), UDim2.fromOffset(236, 51), UI.Outline)
|
|
UI.contour(pill, UI.Gold)
|
|
pill.AnchorPoint = Vector2.new(1, 0)
|
|
local coin = UI.element("GoldCoin", pill, UDim2.fromOffset(13, 7), UDim2.fromOffset(36, 36))
|
|
local walletCoin = UI.bindCoin(coin)
|
|
|
|
local title = label("CurrencyName", pill, "ТРОФЕИ", UDim2.fromOffset(158, 8), UDim2.fromOffset(72, 35), 13, UI.Ink)
|
|
title.FontFace = UI.Display
|
|
title.TextXAlignment = Enum.TextXAlignment.Left
|
|
local divider = UI.frame("Divider", pill, UDim2.fromOffset(146, 12), UDim2.fromOffset(1, 26), UI.Outline)
|
|
divider.Rotation = 12
|
|
local balance = label("Balance", pill, "0", UDim2.fromOffset(60, 5), UDim2.fromOffset(81, 42), 27, UI.Ink)
|
|
balance.FontFace = UI.Display
|
|
balance.TextXAlignment = Enum.TextXAlignment.Left
|
|
balance.TextScaled = true
|
|
Instance.new("UITextSizeConstraint", balance).MaxTextSize = 27
|
|
local gain = label("Gain", pill, "", UDim2.fromOffset(-64, 15), UDim2.fromOffset(55, 21), 16, gold)
|
|
gain.FontFace = UI.Display
|
|
gain.TextStrokeTransparency = .55
|
|
gain.TextXAlignment = Enum.TextXAlignment.Right
|
|
gain.Visible = false
|
|
local pulse = Instance.new("UIScale", pill)
|
|
local layoutScale = 1
|
|
local progressMotion: Tween? = nil
|
|
local sessionGain = 0
|
|
local lastDrop: number? = nil
|
|
local gainUntil = 0
|
|
local lastLanding = -math.huge
|
|
local progressTrack = UI.element("ProgressBar", pill, UDim2.new(0, 8, 1, -5), UDim2.new(1, -16, 0, 2))
|
|
progressTrack.Name = "PickupProgress"
|
|
progressTrack.Visible = false
|
|
local progressFill = progressTrack:WaitForChild("Fill") :: Frame
|
|
progressFill.BackgroundColor3 = gold
|
|
progressFill.Size = UDim2.fromScale(0, 1)
|
|
UI.sheen(progressFill)
|
|
local flash = frame("CreditFlash", pill, UDim2.fromOffset(38, 38), gold, 99)
|
|
flash.AnchorPoint = Vector2.new(.5, .5)
|
|
flash.Position = UDim2.fromOffset(31, 25)
|
|
flash.BackgroundTransparency = 1
|
|
local flashEdge = edge(flash, Color3.fromRGB(255, 237, 146), 2, 1)
|
|
|
|
local flightLayer = frame("CoinFlights", gui, UDim2.fromScale(1, 1), gold, 0)
|
|
flightLayer.BackgroundTransparency = 1
|
|
flightLayer.ZIndex = 5
|
|
|
|
type Flight = {
|
|
icon: Frame, rig: UI.CoinRig, scale: UIScale, tail: {Frame}, from: Vector2, started: number,
|
|
amount: number, id: number, progress: number, milestone: boolean,
|
|
}
|
|
local flights: {Flight} = {}
|
|
local nextLaunch = 0
|
|
local sessionShown = 0
|
|
local originBalance = 0
|
|
local FLIGHT_TIME = .46
|
|
|
|
local function formatBalance(amount: number): string
|
|
local digits = tostring(math.floor(amount))
|
|
local grouped = digits:reverse():gsub("(%d%d%d)", "%1 "):reverse()
|
|
return (grouped:gsub("^ ", ""))
|
|
end
|
|
|
|
local function inArena(): boolean
|
|
return player:GetAttribute("InArena") == true
|
|
end
|
|
|
|
local function paintBalance()
|
|
local amount = if inArena() then originBalance + sessionShown else (player:GetAttribute("TrophyBalance") :: number?) or 0
|
|
balance.Text = formatBalance(amount)
|
|
end
|
|
|
|
local function fit()
|
|
layoutScale = UI.combatScale(gui)
|
|
pulse.Scale = layoutScale
|
|
if inArena() then
|
|
UI.placeCombat(pill, "Wallet")
|
|
else
|
|
pill.AnchorPoint = Vector2.new(1, 0)
|
|
pill.Position = UDim2.new(1, -12, 0, if gui.AbsoluteSize.X < 620 then 68 else 7)
|
|
end
|
|
end
|
|
|
|
local function updateZone()
|
|
if progressMotion then progressMotion:Cancel() end
|
|
for _, flight in flights do
|
|
flight.icon:Destroy()
|
|
for _, particle in flight.tail do particle:Destroy() end
|
|
end
|
|
table.clear(flights)
|
|
nextLaunch = 0
|
|
originBalance = (player:GetAttribute("TrophyOriginBalance") :: number?) or 0
|
|
sessionShown = ((player:GetAttribute("TrophyBalance") :: number?) or 0) - originBalance
|
|
gain.Visible = false
|
|
progressTrack.Visible = false
|
|
lastDrop = nil
|
|
sessionGain = 0
|
|
lastLanding = -math.huge
|
|
pulse.Scale = layoutScale
|
|
flashEdge.Transparency = 1
|
|
fit()
|
|
paintBalance()
|
|
end
|
|
|
|
gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
|
player:GetAttributeChangedSignal("InArena"):Connect(updateZone)
|
|
player:GetAttributeChangedSignal("TrophyBalance"):Connect(function()
|
|
if not inArena() then paintBalance() end
|
|
end)
|
|
player:GetAttributeChangedSignal("TrophyOriginBalance"):Connect(function()
|
|
originBalance = (player:GetAttribute("TrophyOriginBalance") :: number?) or 0
|
|
paintBalance()
|
|
end)
|
|
updateZone()
|
|
|
|
local function acknowledge(flight: Flight, now: number)
|
|
lastLanding = now
|
|
sessionShown += flight.amount
|
|
paintBalance()
|
|
if progressMotion then progressMotion:Cancel() end
|
|
if not gain.Visible then sessionGain = 0 end
|
|
if flight.id ~= lastDrop then progressFill.Size = UDim2.fromScale(0, 1) end
|
|
lastDrop = flight.id
|
|
sessionGain += flight.amount
|
|
gainUntil = now + 1.8
|
|
gain.Text = "+" .. sessionGain
|
|
gain.Visible = true
|
|
progressTrack.Visible = true
|
|
pulse.Scale = layoutScale * (if flight.milestone then 1.15 else 1.055)
|
|
TweenService:Create(pulse, TweenInfo.new(.22, Enum.EasingStyle.Quart), {Scale = layoutScale}):Play()
|
|
flash.Size = UDim2.fromOffset(34, 34)
|
|
flashEdge.Transparency = if flight.milestone then .06 else .28
|
|
TweenService:Create(flash, TweenInfo.new(.24), {Size = UDim2.fromOffset(57, 57)}):Play()
|
|
TweenService:Create(flashEdge, TweenInfo.new(.24), {Transparency = 1}):Play()
|
|
progressMotion = TweenService:Create(progressFill, TweenInfo.new(.14), {Size = UDim2.fromScale(flight.progress, 1)})
|
|
progressMotion:Play()
|
|
end
|
|
|
|
local function worldOrigin(point: Vector3?): Vector2
|
|
local camera = workspace.CurrentCamera
|
|
local size = flightLayer.AbsoluteSize
|
|
if point and camera and size.X > 0 and size.Y > 0 then
|
|
local projected, visible = camera:WorldToScreenPoint(point)
|
|
if visible and projected.Z > 0 then
|
|
local offset = Vector2.new(projected.X, projected.Y) - flightLayer.AbsolutePosition
|
|
return Vector2.new(math.clamp(offset.X / size.X, .03, .97), math.clamp(offset.Y / size.Y, .03, .97))
|
|
end
|
|
end
|
|
return Vector2.new(.59, .67)
|
|
end
|
|
|
|
type Arrival = {amount: number, milestone: boolean}
|
|
local pickupArrived = Instance.new("BindableEvent")
|
|
pickupArrived.Name = "PickupArrived"
|
|
pickupArrived.Event:Connect(function(id: number, arrivals: {Arrival}, collected: number, total: number, point: Vector3?)
|
|
if not inArena() or total <= 0 then return end
|
|
local from = worldOrigin(point)
|
|
local now = os.clock()
|
|
for index, arrival in ipairs(arrivals) do
|
|
local icon = coin:Clone()
|
|
icon.Name = "FlyingCoin"
|
|
icon.AnchorPoint = Vector2.new(.5, .5)
|
|
icon.Visible = false
|
|
icon.Parent = flightLayer
|
|
local scale = Instance.new("UIScale", icon)
|
|
local tail: {Frame} = {}
|
|
for i = 1, 3 do
|
|
local dot = frame("GoldenTrail", flightLayer, UDim2.fromOffset(11 - i * 2, 11 - i * 2), gold, 99)
|
|
dot.AnchorPoint = Vector2.new(.5, .5)
|
|
dot.BackgroundTransparency = .12 + i * .17
|
|
dot.Visible = false
|
|
table.insert(tail, dot)
|
|
end
|
|
local started = math.max(now, nextLaunch)
|
|
nextLaunch = started + .032
|
|
table.insert(flights, {
|
|
icon = icon, rig = UI.bindCoin(icon), scale = scale, tail = tail, from = from, started = started, id = id,
|
|
amount = arrival.amount, milestone = arrival.milestone,
|
|
progress = math.clamp((collected - #arrivals + index) / total, 0, 1),
|
|
})
|
|
end
|
|
end)
|
|
pickupArrived.Parent = gui
|
|
|
|
local function curve(from: Vector2, to: Vector2, control: Vector2, t: number): Vector2
|
|
return from:Lerp(control, t):Lerp(control:Lerp(to, t), t)
|
|
end
|
|
|
|
local render = RunService.RenderStepped:Connect(function()
|
|
local now = os.clock()
|
|
local cycle = (now / 2.8) % 1
|
|
local sweep = math.min(cycle * 3.8, 1)
|
|
local sparkle = math.sin(sweep * math.pi) ^ 2
|
|
local creditFlash = math.max(0, 1 - (now - lastLanding) / .22)
|
|
UI.spinCoin(walletCoin, now * 2.24, math.max(sparkle, creditFlash), sweep)
|
|
if gain.Visible and now >= gainUntil then
|
|
gain.Visible = false
|
|
progressTrack.Visible = false
|
|
end
|
|
if #flights == 0 then return end
|
|
local layerSize = flightLayer.AbsoluteSize
|
|
local destination = coin.AbsolutePosition + coin.AbsoluteSize / 2 - flightLayer.AbsolutePosition
|
|
local i = 1
|
|
while i <= #flights do
|
|
local flight = flights[i]
|
|
local u = (now - flight.started) / FLIGHT_TIME
|
|
if u >= 1 then
|
|
flight.icon:Destroy()
|
|
for _, dot in flight.tail do dot:Destroy() end
|
|
acknowledge(flight, now)
|
|
table.remove(flights, i)
|
|
continue
|
|
elseif u >= 0 then
|
|
local from = Vector2.new(flight.from.X * layerSize.X, flight.from.Y * layerSize.Y)
|
|
local control = from:Lerp(destination, .53) - Vector2.new(0, math.min(86, layerSize.Y * .11))
|
|
local t = u^1.45
|
|
local pos = curve(from, destination, control, t)
|
|
flight.icon.Position = UDim2.fromOffset(pos.X, pos.Y)
|
|
flight.scale.Scale = .97 - .38 * t
|
|
UI.spinCoin(flight.rig, math.pi / 2 + 7.5 * u, math.sin(u * math.pi) ^ 4, u)
|
|
flight.icon.Visible = true
|
|
for j, dot in flight.tail do
|
|
local behind = t - j * .053
|
|
dot.Visible = behind > 0
|
|
if behind > 0 then
|
|
local path = curve(from, destination, control, behind)
|
|
dot.Position = UDim2.fromOffset(path.X, path.Y)
|
|
end
|
|
end
|
|
end
|
|
i += 1
|
|
end
|
|
end)
|
|
|
|
script.Destroying:Once(function() render:Disconnect() end)
|