|
1 | 1 | import { Box, Stack } from "@mui/material" |
2 | 2 | import type React from "react" |
3 | 3 | import { useEffect, useState } from "react" |
| 4 | +import EventSystem from "@/systems/EventSystem.ts" |
| 5 | +import MatchMode from "@/systems/match_mode/MatchMode" |
4 | 6 | import PreferencesSystem from "@/systems/preferences/PreferencesSystem" |
5 | 7 | import { useUIContext } from "@/ui/helpers/UIProviderHelpers" |
6 | 8 | import MatchModeConfigPanel from "@/ui/panels/configuring/MatchModeConfigPanel" |
| 9 | +import MultiplayerStartModal from "@/ui/modals/multiplayer/MultiplayerStartModal" |
| 10 | +import ConfirmModal from "@/ui/modals/common/ConfirmModal" |
7 | 11 | import { SynthesisIcons } from "@/ui/components/StyledComponents" |
8 | 12 | import { TopBarButton } from "@/ui/components/topbar/TopBarButton" |
9 | 13 | import { TOP_BAR_GLYPH_SX } from "@/ui/components/topbar/TopBarConfig" |
10 | 14 | import { TopBarIcon } from "@/ui/components/topbar/TopBarIcons" |
11 | | -import MultiplayerStartModal from "@/modals/multiplayer/MultiplayerStartModal.tsx" |
| 15 | +import { globalAddToast } from "@/ui/components/GlobalUIControls" |
12 | 16 |
|
13 | 17 | export const ScoreboardButton: React.FC = () => { |
14 | 18 | const [alwaysOn, setAlwaysOn] = useState(() => PreferencesSystem.getUserPreference("AlwaysShowScoreboard")) |
@@ -40,16 +44,42 @@ export const ScoreboardButton: React.FC = () => { |
40 | 44 | const GameplayControls: React.FC = () => { |
41 | 45 | const { openModal, togglePanel } = useUIContext() |
42 | 46 |
|
| 47 | + const [isMatchRunning, setIsMatchRunning] = useState(() => MatchMode.getInstance().isMatchEnabled()) |
| 48 | + |
| 49 | + useEffect(() => { |
| 50 | + return EventSystem.listen("MatchStateChangedEvent", () => { |
| 51 | + setIsMatchRunning(MatchMode.getInstance().isMatchEnabled()) |
| 52 | + }) |
| 53 | + }, []) |
| 54 | + |
43 | 55 | const openMatchMode = () => togglePanel(MatchModeConfigPanel, undefined) |
44 | 56 |
|
| 57 | + const abortMatchMode = () => { |
| 58 | + openModal( |
| 59 | + ConfirmModal, |
| 60 | + { message: "Are you sure you want to abort the current match? This cannot be undone." }, |
| 61 | + undefined, |
| 62 | + { |
| 63 | + title: "Abort Match", |
| 64 | + acceptText: "Abort Match", |
| 65 | + cancelText: "Cancel", |
| 66 | + onAccept: () => { |
| 67 | + MatchMode.getInstance().sandboxModeStart() |
| 68 | + globalAddToast("info", "Match Mode Cancelled") |
| 69 | + }, |
| 70 | + } |
| 71 | + ) |
| 72 | + } |
| 73 | + |
45 | 74 | const openMultiplayer = () => openModal(MultiplayerStartModal, undefined) |
46 | 75 |
|
47 | 76 | return ( |
48 | 77 | <Stack direction="row" alignItems="center" gap={1.5}> |
49 | 78 | <TopBarButton |
50 | | - label="Start Match" |
51 | | - icon={<TopBarIcon name="gp-match-mode" size={30} />} |
52 | | - onClick={openMatchMode} |
| 79 | + label={isMatchRunning ? "Abort Match" : "Start Match"} |
| 80 | + active={isMatchRunning} |
| 81 | + icon={<TopBarIcon name={isMatchRunning ? "gp-match-mode-abort" : "gp-match-mode"} size={30} />} |
| 82 | + onClick={isMatchRunning ? abortMatchMode : openMatchMode} |
53 | 83 | /> |
54 | 84 | <TopBarButton |
55 | 85 | label="Open Multiplayer" |
|
0 commit comments