Skip to content

Commit db5c0f6

Browse files
Main Menu Screen [AARD-1878] (#1128)
2 parents 38e191b + 569f664 commit db5c0f6

File tree

3 files changed

+84
-21
lines changed

3 files changed

+84
-21
lines changed

fission/src/Synthesis.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Scene from "@/components/Scene.tsx"
22
import { AnimatePresence } from "framer-motion"
3-
import { ReactElement, useCallback, useEffect, useState } from "react"
3+
import { ReactElement, useCallback, useEffect, useRef, useState } from "react"
44
import { ModalControlProvider, useModalManager } from "@/ui/ModalContext"
55
import { PanelControlProvider, usePanelManager } from "@/ui/PanelContext"
66
import { useTheme } from "@/ui/ThemeContext"
@@ -65,9 +65,10 @@ import GlobalUIComponent from "./ui/components/GlobalUIComponent.tsx"
6565
import InitialConfigPanel from "./ui/panels/configuring/initial-config/InitialConfigPanel.tsx"
6666
import WPILibConnectionStatus from "./ui/components/WPILibConnectionStatus.tsx"
6767
import AutoTestPanel from "./ui/panels/simulation/AutoTestPanel.tsx"
68+
import MainMenuModal from "@/modals/MainMenuModal"
6869

6970
function Synthesis() {
70-
const { openModal, closeModal, getActiveModalElement } = useModalManager(initialModals)
71+
const { openModal, closeModal, getActiveModalElement, registerModal } = useModalManager(initialModals)
7172
const { openPanel, closePanel, closeAllPanels, getActivePanelElements } = usePanelManager(initialPanels)
7273
const { showTooltip } = useTooltipManager()
7374

@@ -82,34 +83,44 @@ function Synthesis() {
8283
const panelElements = getActivePanelElements()
8384
const modalElement = getActiveModalElement()
8485

86+
const mainLoopHandle = useRef(0)
87+
registerModal("main-menu", {
88+
id: "main-menu",
89+
component: (
90+
<MainMenuModal
91+
key="main-menu"
92+
modalId="main-menu"
93+
startSingleplayerCallback={() => {
94+
World.InitWorld()
95+
96+
if (!PreferencesSystem.getGlobalPreference<boolean>("ReportAnalytics") && !import.meta.env.DEV) {
97+
setConsentPopupDisable(false)
98+
}
99+
100+
const mainLoop = () => {
101+
mainLoopHandle.current = requestAnimationFrame(mainLoop)
102+
World.UpdateWorld()
103+
}
104+
mainLoop()
105+
106+
World.SceneRenderer.UpdateSkyboxColors(defaultTheme)
107+
}}
108+
/>
109+
),
110+
})
111+
85112
useEffect(() => {
86113
const urlParams = new URLSearchParams(document.location.search)
87114
if (urlParams.has("code")) {
88115
window.opener.convertAuthToken(urlParams.get("code"))
89116
window.close()
90117
return
91118
}
92-
93-
World.InitWorld()
94-
95-
if (!PreferencesSystem.getGlobalPreference<boolean>("ReportAnalytics") && !import.meta.env.DEV) {
96-
setConsentPopupDisable(false)
97-
}
98-
99-
let mainLoopHandle = 0
100-
const mainLoop = () => {
101-
mainLoopHandle = requestAnimationFrame(mainLoop)
102-
103-
World.UpdateWorld()
104-
}
105-
mainLoop()
106-
107-
World.SceneRenderer.UpdateSkyboxColors(defaultTheme)
108-
119+
openModal("main-menu")
109120
// Cleanup
110121
return () => {
111122
// TODO: Teardown literally everything
112-
cancelAnimationFrame(mainLoopHandle)
123+
cancelAnimationFrame(mainLoopHandle.current)
113124
World.DestroyWorld()
114125
// World.SceneRenderer.RemoveAllSceneObjects();
115126
}

fission/src/ui/components/Modal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type ModalProps = {
2222
cancelBlocked?: boolean
2323
middleBlocked?: boolean
2424
acceptBlocked?: boolean
25+
allowClickAway?: boolean
2526
children?: ReactNode
2627
className?: string
2728
contentClassName?: string
@@ -44,6 +45,7 @@ const Modal: React.FC<ModalProps> = ({
4445
cancelBlocked = false,
4546
middleBlocked = false,
4647
acceptBlocked = false,
48+
allowClickAway = true,
4749
className,
4850
contentClassName,
4951
}) => {
@@ -52,7 +54,12 @@ const Modal: React.FC<ModalProps> = ({
5254
const iconEl: ReactNode = typeof icon === "string" ? <img src={icon} className="w-6" alt="Icon" /> : icon
5355

5456
return (
55-
<ClickAwayListener onClickAway={_ => closeModal()} key={modalId}>
57+
<ClickAwayListener
58+
onClickAway={_ => {
59+
if (allowClickAway) closeModal()
60+
}}
61+
key={modalId}
62+
>
5663
<div
5764
id={modalId}
5865
key={modalId}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from "react"
2+
import Modal, { ModalPropsImpl } from "@/components/Modal"
3+
import { SynthesisIcons } from "../components/StyledComponents"
4+
import Button from "@/components/Button.tsx"
5+
import { useModalControlContext } from "@/ui/ModalContext"
6+
import { Global_AddToast } from "@/components/GlobalUIControls.ts"
7+
8+
const MainMenuModal: React.FC<ModalPropsImpl & { startSingleplayerCallback: () => void }> = ({
9+
modalId,
10+
startSingleplayerCallback,
11+
}) => {
12+
const { closeModal } = useModalControlContext()
13+
14+
return (
15+
<Modal
16+
name={"Welcome"}
17+
icon={SynthesisIcons.Gamepad}
18+
modalId={modalId}
19+
middleEnabled={false}
20+
cancelEnabled={false}
21+
acceptEnabled={false}
22+
allowClickAway={false}
23+
>
24+
<div className="flex flex-col">
25+
<Button
26+
value={"Singleplayer"}
27+
onClick={() => {
28+
closeModal()
29+
startSingleplayerCallback()
30+
}}
31+
className="w-full my-1"
32+
/>
33+
<Button
34+
value={"Multiplayer"}
35+
onClick={() => {
36+
Global_AddToast?.("error", "Not Supported", "Multiplayer is not yet supported. Come back soon!")
37+
}}
38+
className="w-full mt-1 mb-3"
39+
/>
40+
</div>
41+
</Modal>
42+
)
43+
}
44+
45+
export default MainMenuModal

0 commit comments

Comments
 (0)