--!strict local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local TweenService = game:GetService("TweenService") local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript) local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript) local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript) local ModeCard = require(ReplicatedStorage:WaitForChild("ModeCard") :: ModuleScript) local state = ReplicatedStorage:WaitForChild("ArenaRound") local vote = state:WaitForChild("ModeVote") :: RemoteEvent local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local gui = Instance.new("ScreenGui") gui.Name = "ArenaModeVote" gui.ResetOnSpawn, gui.IgnoreGuiInset = false, true gui.DisplayOrder = 44 gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling gui.Enabled = false gui.Parent = playerGui local shade = UI.frame("Shade", gui, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), Color3.fromRGB(7, 11, 21)) shade.Active, shade.BackgroundTransparency = true, .17 local panelWidth, panelHeight = 940, 560 local panel = UI.plate(shade, "Ballot", UDim2.fromScale(.5, .5), UDim2.fromOffset(panelWidth, panelHeight), UI.Outline, Color3.fromRGB(17, 23, 36)) panel.AnchorPoint = Vector2.new(.5, .5) UI.contour(panel, UI.Blue) local scale = Instance.new("UIScale", panel) local function fit() local size = shade.AbsoluteSize scale.Scale = math.clamp(math.min((size.X - 24) / panelWidth, (size.Y - 24) / panelHeight), .01, 1) end local resize = shade:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit) fit() local function leftLabel(parent: Instance, name: string, text: string, x: number, y: number, w: number, h: number, fontSize: number, color: Color3): TextLabel local item = UI.label(parent, name, text, UDim2.fromOffset(x, y), UDim2.fromOffset(w, h), fontSize, color) item.TextXAlignment = Enum.TextXAlignment.Left return item end local title = leftLabel(panel, "Title", "СЛЕДУЮЩИЙ РЕЖИМ", 25, 16, 625, 43, 33, UI.Ink) title.FontFace = UI.Display local arenaText = leftLabel(panel, "Arena", "", 26, 57, 620, 21, 14, UI.Muted) local clock = UI.label(panel, "Countdown", "", UDim2.fromOffset(775, 19), UDim2.fromOffset(139, 44), 30, UI.Blue) clock.FontFace = UI.Display clock.TextXAlignment = Enum.TextXAlignment.Right local caption = leftLabel(panel, "VoteStatus", "", 25, 491, 890, 23, 16, UI.Ink) local detail = leftLabel(panel, "ModeDetail", "", 25, 515, 890, 22, 14, UI.Muted) local line = UI.element("ProgressBar", panel, UDim2.fromOffset(25, 542), UDim2.fromOffset(890, 3)) local fill = line:WaitForChild("Fill") :: Frame fill.BackgroundColor3 = UI.Blue UI.sheen(fill) type VoteCard = {card: ModeCard.Card, group: CanvasGroup, origin: Vector2, zoom: UIScale} type Outcome = {winner: string, endsAt: number} local cards: {[string]: VoteCard} = {} local currentArena: string? = nil local hoveredRule: string? = nil local selectedRule: string? = nil local deadline, duration = 0, 1 local locked = false local revealEndsAt: number? = nil local animations: {Tween} = {} local function tween(target: Instance, time: number, easing: Enum.EasingStyle, goal: {[string]: any}) local animation = TweenService:Create(target, TweenInfo.new(time, easing, Enum.EasingDirection.Out), goal) table.insert(animations, animation) animation:Play() end local function stopAnimations() for _, animation in animations do animation:Cancel() end table.clear(animations) end local function refreshDetail() local rule = Rules.find(if locked then selectedRule else hoveredRule or selectedRule) if locked then detail.Text = if rule then "Ваш голос · " .. rule.title else "" else detail.Text = if rule then rule.detail else "Наведите на режим, чтобы увидеть его правила." end end for i, rule in Rules.All do local center = Vector2.new(131 + ((i - 1) % 4) * 226, 180 + ((i - 1) // 4) * 207) local group = Instance.new("CanvasGroup") group.Name = rule.id .. "Slot" group.AnchorPoint = Vector2.new(.5, .5) group.Position = UDim2.fromOffset(center.X, center.Y) group.Size = UDim2.fromOffset(230, 214) group.BackgroundTransparency = 1 group.Parent = panel local zoom = Instance.new("UIScale", group) local card = ModeCard.new(group, rule.id, UDim2.fromOffset(8, 8), UDim2.fromOffset(214, 198), true) local button = assert(card.button) cards[rule.id] = {card = card, group = group, origin = center, zoom = zoom} local function showDetail() if locked then return end hoveredRule = rule.id refreshDetail() end local function hideDetail() if hoveredRule == rule.id then hoveredRule = nil refreshDetail() end end button.MouseEnter:Connect(showDetail) button.MouseLeave:Connect(hideDetail) button.SelectionGained:Connect(showDetail) button.SelectionLost:Connect(hideDetail) button.Activated:Connect(function() if currentArena and not locked and workspace:GetServerTimeNow() < deadline - Rules.VoteLockSeconds then vote:FireServer(currentArena, rule.id) end end) end local function hide() gui.Enabled = false currentArena = nil hoveredRule, selectedRule = nil, nil locked, revealEndsAt = false, nil playerGui:SetAttribute("HunterVoting", nil) stopAnimations() end local function startBallot(id: string, endsAt: number, timeLeft: number) stopAnimations() currentArena, deadline = id, endsAt hoveredRule, selectedRule = nil, nil locked, revealEndsAt = false, nil local match = Modes.state(state, id) duration = (match:GetAttribute("PhaseDuration") :: number?) or timeLeft title.Text = "СЛЕДУЮЩИЙ РЕЖИМ" arenaText.Text = "ДИНАМИЧЕСКАЯ АРЕНА" clock.Visible, line.Visible = true, true clock.TextColor3, fill.BackgroundColor3 = UI.Blue, UI.Blue caption.TextXAlignment, detail.TextXAlignment = Enum.TextXAlignment.Left, Enum.TextXAlignment.Left for _, slot in cards do slot.group.Position = UDim2.fromOffset(slot.origin.X, slot.origin.Y) slot.group.GroupTransparency, slot.group.Rotation, slot.group.ZIndex = 0, 0, 1 slot.zoom.Scale = 1 assert(slot.card.button).Interactable = true ModeCard.setMuted(slot.card, false) end gui.Enabled = true playerGui:SetAttribute("HunterVoting", true) panel.Position = UDim2.fromScale(.5, .53) tween(panel, .22, Enum.EasingStyle.Quart, {Position = UDim2.fromScale(.5, .5)}) end local function lockBallot() if locked then return end locked = true hoveredRule = nil clock.TextColor3 = Color3.fromRGB(212, 212, 212) fill.BackgroundColor3 = Color3.fromRGB(145, 145, 145) caption.Text = "ГОЛОСОВАНИЕ ЗАКРЫТО" refreshDetail() for _, slot in cards do assert(slot.card.button).Interactable = false ModeCard.setSelected(slot.card, false) ModeCard.setMuted(slot.card, true) end end local function reveal(outcome: Outcome, now: number) local winner = cards[outcome.winner] if revealEndsAt or not winner then return end lockBallot() revealEndsAt = math.max(outcome.endsAt, now + 1.35) title.Text = "РЕЖИМ ВЫБРАН" clock.Visible, line.Visible = false, false caption.TextXAlignment, detail.TextXAlignment = Enum.TextXAlignment.Center, Enum.TextXAlignment.Center caption.Text = if selectedRule then "СЛЕДУЮЩИЙ РАУНД" else "ВЫ ВОЗВРАЩАЕТЕСЬ В ЛОББИ" detail.Text = Rules.get(outcome.winner).detail local center = Vector2.new(panelWidth / 2, panelHeight / 2) for _, slot in cards do if slot == winner then slot.group.ZIndex = 3 ModeCard.setMuted(slot.card, false) ModeCard.setSelected(slot.card, true) tween(slot.group, .72, Enum.EasingStyle.Quart, {Position = UDim2.fromScale(.5, .5)}) tween(slot.zoom, .72, Enum.EasingStyle.Quart, {Scale = 1.65}) else local direction = (slot.origin - center).Unit local destination = slot.origin + direction * 490 tween(slot.group, .8, Enum.EasingStyle.Cubic, { Position = UDim2.fromOffset(destination.X, destination.Y), Rotation = direction.X * 17, GroupTransparency = 1, }) end end end local received = vote.OnClientEvent:Connect(function(id: string, endsAt: number, counts: {[string]: number}, total: number, selection: string?, outcome: Outcome?) local now = workspace:GetServerTimeNow() local left = endsAt - now if outcome then if outcome.endsAt <= now or (gui.Enabled and (id ~= currentArena or endsAt ~= deadline)) then return end elseif left <= 0 then return end if not gui.Enabled or currentArena ~= id or deadline ~= endsAt then startBallot(id, endsAt, left) end selectedRule = selection for rule, slot in cards do slot.card.badge.Text = tostring(counts[rule] or 0) if not locked then ModeCard.setSelected(slot.card, rule == selection) end end if outcome then reveal(outcome, now) return end if left <= Rules.VoteLockSeconds then lockBallot() end refreshDetail() if not locked then local own = Rules.find(selection) caption.Text = if own then "Ваш голос · " .. own.title .. " / Всего " .. total else "Выберите режим · Всего голосов " .. total end end) local timer = RunService.Heartbeat:Connect(function() if not gui.Enabled then return end local now = workspace:GetServerTimeNow() local dismissAt = revealEndsAt if dismissAt then if now >= dismissAt then hide() end return end if now >= deadline + Rules.VoteRevealSeconds + 2 then hide() return end local left = math.max(0, deadline - now) if left <= Rules.VoteLockSeconds then lockBallot() end clock.Text = string.format("00:%02d", math.ceil(left)) fill.Size = UDim2.fromScale(math.clamp(left / math.max(duration, 1), 0, 1), 1) end) script.Destroying:Once(function() hide() received:Disconnect() timer:Disconnect() resize:Disconnect() gui:Destroy() end)