Files
community_bridge/web/src/dialogue.jsx
T

54 lines
1.6 KiB
React
Raw Normal View History

2025-02-21 11:02:18 -06:00
import { useState } from 'react'
2025-02-22 06:42:11 -06:00
import { fetchNui } from './fetch'
2025-02-21 11:02:18 -06:00
import './dialogue.css'
function Dialogue() {
const [count, setCount] = useState(0)
const [dialogueOptions, setDialogueOption] = useState([])
const [currentText, setCurrentText] = useState("Welcome traveler! How can I help you today?")
const [speakerName, setSpeakerName] = useState("Friendly NPC")
const handleMessage = (event) => {
var data = event.data;
2025-02-22 06:42:11 -06:00
if (data !== undefined && data.type === "close") {
2025-02-21 11:02:18 -06:00
document.getElementById('root').classList.add("hidden");
}
if (data !== undefined && data.type === "open") {
setDialogueOption(data.options);
setCurrentText(data.text);
setSpeakerName(data.name);
document.getElementById('root').classList.remove("hidden");
}
};
window.addEventListener("message", handleMessage);
return (
<>
<div className="container">
{/* Dialogue System */}
<div className="dialogue-container">
<h2>{speakerName}</h2>
<div className="dialogue-text">
<p>{currentText}</p>
</div>
<div className="dialogue-options">
{dialogueOptions.map((option) => (
<button
key={option.id}
2025-02-22 06:42:11 -06:00
onClick={() => fetchNui("dialogue:SelectOption", { name: speakerName, id: option.id })}
2025-02-21 11:02:18 -06:00
className="dialogue-button"
>
{option.label}
</button>
))}
</div>
</div>
</div>
</>
)
}
export default Dialogue