interaction-prompt.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use client";
  2. import { useEffect, useState } from "react";
  3. import { useEditorStore } from "@/lib/store";
  4. import { useIsMobile } from "@/lib/use-mobile";
  5. export function InteractionPrompt() {
  6. const [showPrompt, setShowPrompt] = useState(false);
  7. const isPlaying = useEditorStore((s) => s.isPlaying);
  8. const isMobile = useIsMobile();
  9. useEffect(() => {
  10. if (!isPlaying) {
  11. setShowPrompt(false);
  12. return;
  13. }
  14. const handleNearby = () => setShowPrompt(true);
  15. const handleFar = () => setShowPrompt(false);
  16. const handleDialogOpen = () => setShowPrompt(false);
  17. window.addEventListener("character-nearby", handleNearby);
  18. window.addEventListener("character-far", handleFar);
  19. window.addEventListener("dialog-open", handleDialogOpen);
  20. return () => {
  21. window.removeEventListener("character-nearby", handleNearby);
  22. window.removeEventListener("character-far", handleFar);
  23. window.removeEventListener("dialog-open", handleDialogOpen);
  24. };
  25. }, [isPlaying]);
  26. if (!isPlaying || !showPrompt) return null;
  27. if (isMobile) {
  28. return (
  29. <button
  30. onClick={() => {
  31. window.dispatchEvent(new CustomEvent("request-character-interact"));
  32. }}
  33. className="absolute bottom-28 left-1/2 -translate-x-1/2 z-20 bg-white/20 backdrop-blur-sm text-white px-6 py-3 rounded-full text-sm font-medium active:bg-white/40 border border-white/30"
  34. >
  35. Tap to interact
  36. </button>
  37. );
  38. }
  39. return (
  40. <div className="absolute bottom-10 left-1/2 -translate-x-1/2 z-10 bg-black/70 text-white px-4 py-2 rounded-md text-sm">
  41. Press &quot;E&quot; to interact
  42. </div>
  43. );
  44. }