Refactor arena modes and add objective event feed
This commit is contained in:
1 parent
df6ab8efe1
commit
b87a3770a1
26 files changed
+1221
-654
No files matched your search
@@ -0,0 +1,23 @@
|
||||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local remote = ReplicatedStorage:WaitForChild("ArenaObjectiveEvent") :: RemoteEvent
|
||||
type Handler = (any) -> ()
|
||||
local handlers: {[string]: {Handler}} = {}
|
||||
local Router = {}
|
||||
|
||||
function Router.on(kind: string, handler: Handler): () -> ()
|
||||
local list = handlers[kind] or {}
|
||||
handlers[kind] = list
|
||||
table.insert(list, handler)
|
||||
return function()
|
||||
local index = table.find(list, handler)
|
||||
if index then table.remove(list, index) end
|
||||
end
|
||||
end
|
||||
|
||||
remote.OnClientEvent:Connect(function(kind: string, payload: any)
|
||||
if typeof(payload) ~= "table" then return end
|
||||
for _, handler in table.clone(handlers[kind] or {}) do task.spawn(handler, payload) end
|
||||
end)
|
||||
|
||||
return Router
|
||||
@@ -0,0 +1,126 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local Strings = require(ReplicatedStorage:WaitForChild("Hunter"):WaitForChild("Strings") :: ModuleScript)
|
||||
local Router = require(script.Parent:WaitForChild("EventRouter") :: ModuleScript)
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
local hud = playerGui:WaitForChild("ArenaRoundHud")
|
||||
local match = ReplicatedStorage:WaitForChild("ArenaRound"):WaitForChild("Procedural")
|
||||
local MAX_ROWS, LIFETIME, FADE = 4, 6, .35
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "ArenaObjectiveFeed"
|
||||
gui.DisplayOrder = 12
|
||||
gui.ResetOnSpawn = false
|
||||
gui.Parent = playerGui
|
||||
|
||||
local stack = Instance.new("Frame")
|
||||
stack.BackgroundTransparency = 1
|
||||
stack.Position = UDim2.fromOffset(16, 194)
|
||||
stack.Size = UDim2.new(.6, 0, 0, 190)
|
||||
stack.Parent = gui
|
||||
local limit = Instance.new("UISizeConstraint", stack)
|
||||
limit.MaxSize = Vector2.new(345, 190)
|
||||
local scale = Instance.new("UIScale", stack)
|
||||
local layout = Instance.new("UIListLayout", stack)
|
||||
layout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
layout.Padding = UDim.new(0, 5)
|
||||
local connections: {RBXScriptConnection} = {}
|
||||
local function resize()
|
||||
scale.Scale = UI.combatScale(gui)
|
||||
local bottom = hud:GetAttribute("ContentBottom")
|
||||
stack.Position = UDim2.fromOffset(16, math.max(194, (if typeof(bottom) == "number" then bottom else 0) + 12))
|
||||
end
|
||||
resize()
|
||||
table.insert(connections, stack:GetPropertyChangedSignal("AbsoluteSize"):Connect(resize))
|
||||
table.insert(connections, hud:GetAttributeChangedSignal("ContentBottom"):Connect(resize))
|
||||
|
||||
local menu = playerGui:WaitForChild("ArenaResults")
|
||||
local watchedMenu: ScreenGui? = nil
|
||||
local menuConnection: RBXScriptConnection? = nil
|
||||
local rows: {CanvasGroup} = {}
|
||||
local order = 0
|
||||
local alive = true
|
||||
|
||||
local function refresh()
|
||||
local active = player:GetAttribute("InArena") == true and match:GetAttribute("Phase") == "Round"
|
||||
gui.Enabled = active and menu:GetAttribute("LiveScoreboardOpen") ~= true
|
||||
and playerGui:GetAttribute("HunterVoting") ~= true and not (watchedMenu and watchedMenu.Enabled)
|
||||
if not active then
|
||||
for _, row in rows do row:Destroy() end
|
||||
table.clear(rows)
|
||||
end
|
||||
end
|
||||
local function watchMenu(instance: Instance)
|
||||
if instance.Name ~= "MainMenu" or not instance:IsA("ScreenGui") then return end
|
||||
if menuConnection then menuConnection:Disconnect() end
|
||||
watchedMenu = instance
|
||||
menuConnection = instance:GetPropertyChangedSignal("Enabled"):Connect(refresh)
|
||||
refresh()
|
||||
end
|
||||
local initialMenu = playerGui:FindFirstChild("MainMenu")
|
||||
if initialMenu then watchMenu(initialMenu) end
|
||||
table.insert(connections, playerGui.ChildAdded:Connect(watchMenu))
|
||||
table.insert(connections, playerGui.ChildRemoved:Connect(function(child)
|
||||
if child ~= watchedMenu then return end
|
||||
if menuConnection then menuConnection:Disconnect(); menuConnection = nil end
|
||||
watchedMenu = nil
|
||||
refresh()
|
||||
end))
|
||||
table.insert(connections, menu:GetAttributeChangedSignal("LiveScoreboardOpen"):Connect(refresh))
|
||||
table.insert(connections, playerGui:GetAttributeChangedSignal("HunterVoting"):Connect(refresh))
|
||||
table.insert(connections, player:GetAttributeChangedSignal("InArena"):Connect(refresh))
|
||||
table.insert(connections, match:GetAttributeChangedSignal("Phase"):Connect(refresh))
|
||||
refresh()
|
||||
|
||||
local function remove(row: CanvasGroup)
|
||||
local index = table.find(rows, row)
|
||||
if not index then return end
|
||||
table.remove(rows, index)
|
||||
row:Destroy()
|
||||
end
|
||||
local function add(message: string, side: string?)
|
||||
if not alive or player:GetAttribute("InArena") ~= true or match:GetAttribute("Phase") ~= "Round" then return end
|
||||
order -= 1
|
||||
local tint = if side == "Blue" then UI.Blue elseif side == "Orange" then UI.Orange else UI.Gold
|
||||
local row = Instance.new("CanvasGroup")
|
||||
row.Name = "Event"
|
||||
row.LayoutOrder = order
|
||||
row.Size = UDim2.new(1, 0, 0, 36)
|
||||
row.BackgroundTransparency = 1
|
||||
row.GroupTransparency = 1
|
||||
local plate = UI.plate(row, "Plate", UDim2.new(), UDim2.fromScale(1, 1), tint)
|
||||
local dot = Instance.new("Frame", plate)
|
||||
dot.AnchorPoint = Vector2.new(0, .5)
|
||||
dot.Position = UDim2.new(0, 10, .5, 0)
|
||||
dot.Size = UDim2.fromOffset(8, 8)
|
||||
dot.BackgroundColor3 = tint
|
||||
dot.BorderSizePixel = 0
|
||||
Instance.new("UICorner", dot).CornerRadius = UDim.new(1, 0)
|
||||
local label = UI.label(plate, "Message", message, UDim2.fromOffset(25, 0), UDim2.new(1, -34, 1, 0), 16, UI.Ink)
|
||||
label.TextXAlignment = Enum.TextXAlignment.Left
|
||||
label.TextTruncate = Enum.TextTruncate.AtEnd
|
||||
row.Parent = stack
|
||||
table.insert(rows, 1, row)
|
||||
if #rows > MAX_ROWS then remove(rows[#rows]) end
|
||||
TweenService:Create(row, TweenInfo.new(.15), {GroupTransparency = 0}):Play()
|
||||
task.delay(LIFETIME - FADE, function()
|
||||
if not row.Parent then return end
|
||||
TweenService:Create(row, TweenInfo.new(FADE), {GroupTransparency = 1}):Play()
|
||||
task.delay(FADE, remove, row)
|
||||
end)
|
||||
end
|
||||
|
||||
local unsubscribe: {() -> ()} = {}
|
||||
for kind, format in Strings.feed do
|
||||
table.insert(unsubscribe, Router.on(kind, function(payload) add(format(payload), payload.side) end))
|
||||
end
|
||||
script.Destroying:Once(function()
|
||||
alive = false
|
||||
for _, clean in unsubscribe do clean() end
|
||||
for _, connection in connections do connection:Disconnect() end
|
||||
if menuConnection then menuConnection:Disconnect() end
|
||||
gui:Destroy()
|
||||
end)
|
||||
Reference in new issue
Block a user