feat(control): grid snap, NPC context actions, and overlay dim fix

Re-enable users-branch UI, snap session tokens to square/hex grid from the control preview, refine inactive/open-info NPC menus, block marker actions while an effect brush is active, and dim materials/NPC overlays only when they are open.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-08-06 13:48:59 +08:00
parent e53d1ea934
commit 4456eb0277
24 changed files with 563 additions and 41 deletions
@@ -14,6 +14,8 @@ type Props = {
viewport: Viewport | null;
editable?: boolean;
onMove?: (placementId: string, nx: number, ny: number) => void;
/** Snap во время drag (пульт, привязка к сетке). */
snapNorm?: (nx: number, ny: number) => { nx: number; ny: number };
};
function TokenSprite({
@@ -23,6 +25,7 @@ function TokenSprite({
viewport,
editable,
onMove,
snapNorm,
}: {
placement: SceneToken;
nx: number;
@@ -30,6 +33,7 @@ function TokenSprite({
viewport: Viewport;
editable: boolean;
onMove?: (placementId: string, nx: number, ny: number) => void;
snapNorm?: (nx: number, ny: number) => { nx: number; ny: number };
}) {
const url = useTokenImageUrl(placement.tokenId);
const dragRef = useRef<{
@@ -132,8 +136,9 @@ function TokenSprite({
const p = hostToNorm(e.clientX, e.clientY, host);
const nextNx = Math.max(0, Math.min(1, d.startNx + (p.x - d.pointerNx)));
const nextNy = Math.max(0, Math.min(1, d.startNy + (p.y - d.pointerNy)));
d.lastNx = nextNx;
d.lastNy = nextNy;
const snapped = snapNorm ? snapNorm(nextNx, nextNy) : { nx: nextNx, ny: nextNy };
d.lastNx = snapped.nx;
d.lastNy = snapped.ny;
if (frameRef.current) return;
frameRef.current = requestAnimationFrame(() => {
frameRef.current = 0;
@@ -163,6 +168,7 @@ export function SceneTokensOverlay({
viewport,
editable = false,
onMove,
snapNorm,
}: Props) {
if (!viewport || placements.length === 0) return null;
const known = new Set(library.map((t) => t.id));
@@ -185,6 +191,7 @@ export function SceneTokensOverlay({
viewport={viewport}
editable={editable}
{...(onMove ? { onMove } : {})}
{...(snapNorm ? { snapNorm } : {})}
/>
);
})}
@@ -0,0 +1,33 @@
import { useCallback, useEffect, useState } from 'react';
import { ipcChannels } from '../../../shared/ipc/contracts';
import { getDndApi } from '../dndApi';
export function useTokenGridSnapSession(): [
boolean,
{ setEnabled: (enabled: boolean) => Promise<boolean> },
] {
const api = getDndApi();
const [enabled, setEnabledState] = useState(false);
useEffect(() => {
void api.invoke(ipcChannels.tokenGridSnap.getState, {}).then((res) => {
setEnabledState(Boolean(res.enabled));
});
return api.on(ipcChannels.tokenGridSnap.stateChanged, ({ enabled: next }) => {
setEnabledState(Boolean(next));
});
}, [api]);
const setEnabled = useCallback(
async (next: boolean) => {
setEnabledState(next);
const res = await api.invoke(ipcChannels.tokenGridSnap.setEnabled, { enabled: next });
setEnabledState(Boolean(res.enabled));
return Boolean(res.enabled);
},
[api],
);
return [enabled, { setEnabled }];
}