UI screen examples
Provides UI screen examples for Pixi’VN, showing React and Vue components, and demonstrating hooks (e.g. useQueryDialogue, useQueryChoiceMenuOptions, useQueryCanGoNext) and integration with narration for choices, next/back, input prompts, and history.
AI
You can use the button above to create your own AI UI screen.
These examples use simple UI primitives (Button, Card, Avatar, Dialog, Input, ...) imported from a components/ui folder, similar to what shadcn/ui (React) or shadcn-vue provide. Replace them with the equivalent components from your own UI library.
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>
);
}Instead of a dedicated "next" button, wrap the narrative screen in an overlay that advances the narration whenever the player clicks anywhere on it.
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>
);
}Wrap the narrative dialogue screen with it, so a click anywhere on the screen continues the narration (elements like the choice menu, the back button and the input dialog call stopPropagation() so interacting with them doesn't also trigger a "next"):
<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>
);
}