Commit 232502b5 authored by Chunchi Che's avatar Chunchi Che

update NewWaitRoom

parent 3aea11bc
...@@ -42,6 +42,10 @@ export function sendHsReady() { ...@@ -42,6 +42,10 @@ export function sendHsReady() {
socketMiddleWare({ cmd: socketCmd.SEND, payload }); socketMiddleWare({ cmd: socketCmd.SEND, payload });
} }
export function sendHsNotReady() {
// TODO
}
export function sendHsStart() { export function sendHsStart() {
const hasStart = new ygopro.YgoCtosMsg({ const hasStart = new ygopro.YgoCtosMsg({
ctos_hs_start: new ygopro.CtosHsStart({}), ctos_hs_start: new ygopro.CtosHsStart({}),
......
import { CheckCircleFilled } from "@ant-design/icons"; import { CheckCircleFilled } from "@ant-design/icons";
import { ygopro } from "@/api"; import { sendHsNotReady, sendHsReady, sendUpdateDeck, ygopro } from "@/api";
import PlayerState = ygopro.StocHsPlayerChange.State; import PlayerState = ygopro.StocHsPlayerChange.State;
import { Avatar, Button, ConfigProvider, Popover, Skeleton, Space } from "antd"; import { Avatar, Button, ConfigProvider, Popover, Skeleton, Space } from "antd";
import classNames from "classnames"; import classNames from "classnames";
import { forwardRef, useImperativeHandle, useRef, useState } from "react"; import {
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from "react";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { accountStore, Player, roomStore } from "@/stores"; import { accountStore, deckStore, IDeck, Player, roomStore } from "@/stores";
import { Background, IconFont, Select } from "@/ui/Shared"; import { Background, IconFont, Select } from "@/ui/Shared";
import { Chat } from "./Chat"; import { Chat } from "./Chat";
...@@ -35,10 +41,17 @@ const theme = { ...@@ -35,10 +41,17 @@ const theme = {
export const Component: React.FC = () => { export const Component: React.FC = () => {
const { user } = useSnapshot(accountStore); const { user } = useSnapshot(accountStore);
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const { decks } = useSnapshot(deckStore);
const [deck, setDeck] = useState<IDeck>(JSON.parse(JSON.stringify(decks[0])));
const room = useSnapshot(roomStore); const room = useSnapshot(roomStore);
// const ref = useRef<MoraButtonRef>(null); // const ref = useRef<MoraButtonRef>(null);
// ref.current?.getMoraResult(); // 用这个来异步获取猜拳结果 // ref.current?.getMoraResult(); // 用这个来异步获取猜拳结果
useEffect(() => {
sendUpdateDeck(deck);
window.myExtraDeckCodes = [...deck.extra];
}, [deck]);
return ( return (
<ConfigProvider theme={theme}> <ConfigProvider theme={theme}>
<div <div
...@@ -60,7 +73,17 @@ export const Component: React.FC = () => { ...@@ -60,7 +73,17 @@ export const Component: React.FC = () => {
<LoadingOutlined /> <LoadingOutlined />
对方正在选择先后 对方正在选择先后
</div> */} </div> */}
<Controller /> <Controller
onDeckChange={(deckName: string) => {
const deck = deckStore.get(deckName);
// 同步后端
if (deck) {
setDeck(deck);
} else {
alert(`Deck ${deckName} not found`);
}
}}
/>
<div className={styles["both-side-container"]}> <div className={styles["both-side-container"]}>
<PlayerZone <PlayerZone
who={Who.Me} who={Who.Me}
...@@ -68,8 +91,18 @@ export const Component: React.FC = () => { ...@@ -68,8 +91,18 @@ export const Component: React.FC = () => {
avatar={user?.avatar_url} avatar={user?.avatar_url}
btn={ btn={
<> <>
<Button size="large" className={styles["btn-join"]}> <Button
决斗准备 size="large"
className={styles["btn-join"]}
onClick={() => {
room.getMePlayer().state == PlayerState.NO_READY
? sendHsReady()
: sendHsNotReady();
}}
>
{room.getMePlayer().state == PlayerState.NO_READY
? "决斗准备"
: "取消准备"}
</Button> </Button>
{/* <MoraButton ref={ref} /> */} {/* <MoraButton ref={ref} /> */}
</> </>
...@@ -218,20 +251,25 @@ const PlayerZone: React.FC<{ ...@@ -218,20 +251,25 @@ const PlayerZone: React.FC<{
); );
}; };
const Controller: React.FC = () => { const Controller: React.FC<{ onDeckChange: (deckName: string) => void }> = ({
onDeckChange,
}) => {
const snap = useSnapshot(deckStore);
return ( return (
<Space> <Space>
<Select <Select
title="卡组" title="卡组"
showSearch showSearch
defaultValue="lucy"
style={{ width: 300 }} style={{ width: 300 }}
options={[ defaultValue={snap.decks[0].deckName}
{ value: "jack", label: "Jack" }, options={snap.decks.map((deck) => ({
{ value: "lucy", label: "Lucy" }, value: deck.deckName,
{ value: "Yiminghe", label: "yiminghe" }, title: deck.deckName,
{ value: "disabled", label: "Disabled", disabled: true }, }))}
]} onChange={
// @ts-ignore
(value) => onDeckChange(value)
}
/> />
<Button size="large" icon={<IconFont type="icon-record" size={18} />}> <Button size="large" icon={<IconFont type="icon-record" size={18} />}>
加入观战 加入观战
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment