UI 화면 예제
Pixi’VN을 위한 UI 화면 예제를 제공하며, React 및 Vue 컴포넌트를 보여주고, 훅(예: useQueryDialogue, useQueryChoiceMenuOptions, useQueryCanGoNext)과 선택지, 다음/뒤로, 입력 프롬프트, 히스토리를 위한 내레이션 통합을 시연합니다.
AI
위의 버튼을 사용하여 나만의 AI UI 화면을 만들 수 있습니다.
이 예제들은 간단한 UI 프리미티브(Button, Card, Avatar, Dialog, Input 등)를 사용합니다 components/ui 폴더에서 가져온 것으로, shadcn/ui(React) 또는 shadcn-vue가 제공하는 것과 유사합니다. 이를 여러분의 UI 라이브러리에 있는 동등한 컴포넌트로 교체하세요.
import { Markdown } from "@tanstack/markdown/react";
import { Avatar } from "@/components/ui/avatar";
import { Card, CardContent } from "@/components/ui/card";
import { useQueryDialogue } from "@/hooks/useQueryInterface";
import ChoiceMenu from "@/components/narration/ChoiceMenu";
export default function NarrationScreen() {
const { data: { text, character } = {} } = useQueryDialogue();
return (
<div
style={{
position: "absolute",
inset: 0,
display: "flex",
flexDirection: "column",
}}
>
<div style={{ flex: 1, minHeight: 0 }}>
<ChoiceMenu />
</div>
{text && (
<Card
style={{
flex: "0 0 auto",
height: "35%",
minHeight: 0,
pointerEvents: "auto",
}}
>
<CardContent
style={{
display: "flex",
gap: 12,
height: "100%",
minHeight: 0,
overflow: "hidden",
}}
>
{character?.icon && (
<Avatar size="lg" style={{ flexShrink: 0 }}>
<img
src={character.icon}
loading="lazy"
alt=""
style={{
width: "100%",
height: "100%",
objectFit: "cover",
}}
/>
</Avatar>
)}
<div style={{ flex: 1, minHeight: 0, overflow: "auto" }}>
{character?.name && (
<b>{`${character.name} ${character.surname || ""}`}</b>
)}
<Markdown allowHtml>{text}</Markdown>
</div>
</CardContent>
</Card>
)}
</div>
);
}import { Button } from "@/components/ui/button";
import useNarrationFunctions from "@/hooks/useNarrationFunctions";
import { useQueryChoiceMenuOptions } from "@/hooks/useQueryInterface";
export default function ChoiceMenu() {
const { data: menu = [] } = useQueryChoiceMenuOptions();
const { selectChoice } = useNarrationFunctions();
if (menu.length === 0) {
return null;
}
return (
<div
onClick={(e) => e.stopPropagation()}
style={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100%",
overflow: "auto",
gap: 8,
pointerEvents: "auto",
}}
>
{menu.map((item) => (
<Button
key={item.choiceIndex}
variant="secondary"
onClick={() => selectChoice(item)}
>
{item.text}
</Button>
))}
</div>
);
}전용 "다음" 버튼 대신, 플레이어가 화면 어디를 클릭하든 내레이션이 진행되는 오버레이로 내러티브 화면을 감쌉니다.
import { useState } from "react";
import useNarrationFunctions from "@/hooks/useNarrationFunctions";
import { useQueryCanGoNext } from "@/hooks/useQueryInterface";
export default function ContinueOverlay({
children,
}: {
children: React.ReactNode;
}) {
const { data: canGoNext = false } = useQueryCanGoNext();
const [loading, setLoading] = useState(false);
const { goNext } = useNarrationFunctions();
return (
<div
onClick={() => {
if (!canGoNext || loading) {
return;
}
setLoading(true);
goNext().finally(() => setLoading(false));
}}
style={{
position: "relative",
width: "100%",
height: "100%",
pointerEvents: "auto",
}}
>
{children}
</div>
);
}내러티브 대화 화면을 이것으로 감싸서 화면 어디를 클릭해도 내레이션이 진행되도록 합니다(선택지 메뉴, 뒤로 가기 버튼, 입력 대화상자 같은 요소는 stopPropagation()을 호출하므로 이들과 상호작용해도 "다음"이 함께 트리거되지 않습니다):
<ContinueOverlay>
<NarrationScreen />
</ContinueOverlay>import { useState } from "react";
import { Button } from "@/components/ui/button";
import useNarrationFunctions from "@/hooks/useNarrationFunctions";
import { useQueryCanGoBack } from "@/hooks/useQueryInterface";
export default function BackButton() {
const { data: canGoBack = false } = useQueryCanGoBack();
const [loading, setLoading] = useState(false);
const { goBack } = useNarrationFunctions();
if (!canGoBack) {
return null;
}
return (
<Button
variant="secondary"
disabled={loading}
onClick={(e) => {
e.stopPropagation();
setLoading(true);
goBack().finally(() => setLoading(false));
}}
>
Back
</Button>
);
}import { narration } from "@drincs/pixi-vn";
import { useQueryClient } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import {
INTERFACE_DATA_QUERY_KEY,
useQueryDialogue,
useQueryInputValue,
} from "@/hooks/useQueryInterface";
export default function TextInputDialog() {
const { data: { text } = {} } = useQueryDialogue();
const {
data: { isRequired: open, currentValue, type } = {
isRequired: false,
currentValue: undefined,
type: undefined,
},
} = useQueryInputValue<string | number>();
const [value, setValue] = useState<string | number>("");
const queryClient = useQueryClient();
useEffect(() => {
if (open) {
setValue(currentValue ?? "");
}
}, [open]);
const confirm = () => {
narration.input.value = value;
queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_QUERY_KEY] });
};
return (
<Dialog open={open}>
<DialogContent onClick={(e) => e.stopPropagation()}>
<DialogHeader>
<DialogTitle>Your input is needed</DialogTitle>
{text && <DialogDescription>{text}</DialogDescription>}
</DialogHeader>
<Input
type={type === "number" ? "number" : "text"}
value={value}
onChange={(e) => {
setValue(
type === "number"
? e.target.valueAsNumber
: e.target.value,
);
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
confirm();
}
}}
/>
<DialogFooter>
<Button onClick={confirm}>Confirm</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}