Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reziable panels #720

Merged
merged 7 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"marked": "^5.1.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-resizable-panels": "^2.1.6",
"react-scripts": "^5.0.1",
"react-virtuoso": "^4.12.0",
"typescript": "^4",
Expand Down
35 changes: 25 additions & 10 deletions client/src/menu/game/GameScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Icon from "../../components/Icon";
import { Button } from "../../components/Button";
import translate from "../../game/lang";
import { useGameState } from "../../components/useHooks";
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";

export enum ContentMenu {
ChatMenu = "ChatMenu",
Expand All @@ -25,6 +26,16 @@ export enum ContentMenu {
GraveyardMenu = "GraveyardMenu",
WikiMenu = "WikiMenu",
}

export const MENU_ELEMENTS = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the enum should just be defined like this. We don't use the values part of the enum

[ContentMenu.ChatMenu]: ChatMenu,
[ContentMenu.PlayerListMenu]: PlayerListMenu,
[ContentMenu.RoleSpecificMenu]: AbilityMenu,
[ContentMenu.WillMenu]: WillMenu,
[ContentMenu.GraveyardMenu]: GraveyardMenu,
[ContentMenu.WikiMenu]: WikiMenu
}

const ALL_CONTENT_MENUS = Object.values(ContentMenu);

export interface MenuController {
Expand Down Expand Up @@ -182,23 +193,27 @@ export default function GameScreen(): ReactElement {
})

const allMenusClosed = menuController.menusOpen().length === 0;
const minSize = 10;

return <MenuControllerContext.Provider value={menuController}>
<div className="game-screen">
<div className="header">
<HeaderMenu chatMenuNotification={chatMenuNotification}/>
</div>
<div className="content">
{menuController.menuOpen(ContentMenu.ChatMenu) && <ChatMenu/>}
{menuController.menuOpen(ContentMenu.RoleSpecificMenu) && <AbilityMenu/>}
{menuController.menuOpen(ContentMenu.WillMenu) && <WillMenu/>}
{menuController.menuOpen(ContentMenu.PlayerListMenu) && <PlayerListMenu/>}
{menuController.menuOpen(ContentMenu.GraveyardMenu) && <GraveyardMenu/>}
{menuController.menuOpen(ContentMenu.WikiMenu) && <WikiMenu/>}
{allMenusClosed && <div className="no-content">
<PanelGroup direction="horizontal" className="content">
{menuController.menusOpen().map((menu, index, menusOpen) => {
const MenuElement = MENU_ELEMENTS[menu];
return <>
<Panel minSize={minSize}>
<MenuElement />
</Panel>
{menusOpen.some((_, i) => i > index) && <PanelResizeHandle />}
</>
})}
{allMenusClosed && <Panel><div className="no-content">
{translate("menu.gameScreen.noContent")}
</div>}
</div>
</div></Panel>}
</PanelGroup>
</div>
</MenuControllerContext.Provider>
}
Expand Down
19 changes: 2 additions & 17 deletions client/src/menu/game/gameScreen.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,11 @@
}

.game-screen .content {
display: flex;
flex-direction: row;

flex-grow: 1;
flex-shrink: 0;
flex-basis: auto;

height: 1vh;
overflow-x: hidden;
}
.game-screen .content > div {
overflow-x: hidden;
resize: horizontal;

.game-screen .content > div > div{
height: 100%;
max-height: 100%;

max-width: 100%;
width: 15%;
min-width: 10%;

background-color: var(--background-color);
border: .13rem solid var(--background-border-color);
Expand All @@ -47,7 +32,7 @@
}

@media only screen and (max-width: 600px) {
.game-screen .content > div {
.game-screen .content > div > div {
width: 100%;
resize: none;
}
Expand Down
3 changes: 1 addition & 2 deletions client/src/menu/game/gameScreenContent/chatMenu.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

.game-screen .content > .chat-menu {
.game-screen .content .chat-menu {
display: flex;
flex-direction: column;
width: 45%;
}
@media only screen and (max-width: 600px) {
.game-screen .content > .chat-menu {
Expand Down
3 changes: 0 additions & 3 deletions client/src/menu/game/gameScreenContent/graveyardMenu.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.game-screen .content > .graveyard-menu {
width: 10%;
}
@media only screen and (max-width: 600px) {
.game-screen .content > .graveyard-menu {
width: 100%;
Expand Down
3 changes: 0 additions & 3 deletions client/src/menu/game/gameScreenContent/playerListMenu.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.game-screen .content > .player-list-menu {
width: 25%;
}
@media only screen and (max-width: 600px) {
.game-screen .content > .player-list-menu {
width: 100%;
Expand Down
23 changes: 17 additions & 6 deletions client/src/menu/spectator/SpectatorGameScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import ChatMenu from "../game/gameScreenContent/ChatMenu";
import PlayerListMenu from "../game/gameScreenContent/PlayerListMenu";
import GraveyardMenu from "../game/gameScreenContent/GraveyardMenu";
import HeaderMenu from "../game/HeaderMenu";
import { MenuController, ContentMenu, useMenuController, MenuControllerContext } from "../game/GameScreen";
import { MenuController, ContentMenu, useMenuController, MenuControllerContext, MENU_ELEMENTS } from "../game/GameScreen";
import { MobileContext } from "../Anchor";
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
import translate from "../../game/lang";


const DEFAULT_START_PHASE_SCREEN_TIME = 3;
Expand Down Expand Up @@ -63,11 +65,20 @@ export default function SpectatorGameScreen(): ReactElement {
</div>
{showStartedScreen
? <PhaseStartedScreen/>
: <div className="content">
{contentController.menuOpen(ContentMenu.ChatMenu) && <ChatMenu/>}
{contentController.menuOpen(ContentMenu.PlayerListMenu) && <PlayerListMenu/>}
{contentController.menuOpen(ContentMenu.GraveyardMenu) && <GraveyardMenu/>}
</div>}
: <PanelGroup direction="horizontal" className="content">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is a lil duped from gameScreen but it's chill

{contentController.menusOpen().map((menu, index, menusOpen) => {
const MenuElement = MENU_ELEMENTS[menu];
return <>
<Panel minSize={10}>
<MenuElement />
</Panel>
{menusOpen.some((_, i) => i > index) && <PanelResizeHandle />}
</>
})}
{contentController.menusOpen().length === 0 && <Panel><div className="no-content">
{translate("menu.gameScreen.noContent")}
</div></Panel>}
</PanelGroup>}
</div>
</MenuControllerContext.Provider>
);
Expand Down
Loading