Add hover highlights to paint interactions
This commit is contained in:
@@ -87,6 +87,8 @@ type PaintPreviewCleanup = () => void
|
|||||||
type PaintInteraction = {
|
type PaintInteraction = {
|
||||||
key: string
|
key: string
|
||||||
apply: (() => void) | null
|
apply: (() => void) | null
|
||||||
|
hoverMode: HoverHighlightMode
|
||||||
|
hoveredId: AnyNodeId
|
||||||
preview: (() => PaintPreviewCleanup | null) | null
|
preview: (() => PaintPreviewCleanup | null) | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,6 +745,11 @@ export const SelectionManager = () => {
|
|||||||
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'wall')
|
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'wall')
|
||||||
return {
|
return {
|
||||||
key: `wall:${node.id}:${role ?? 'unsupported'}`,
|
key: `wall:${node.id}:${role ?? 'unsupported'}`,
|
||||||
|
hoveredId: node.id as AnyNodeId,
|
||||||
|
hoverMode:
|
||||||
|
compatible && hasActivePaintMaterial(activePaintMaterial) && role
|
||||||
|
? 'paint-ready'
|
||||||
|
: 'paint-disabled',
|
||||||
apply:
|
apply:
|
||||||
compatible && hasActivePaintMaterial(activePaintMaterial)
|
compatible && hasActivePaintMaterial(activePaintMaterial)
|
||||||
? () => {
|
? () => {
|
||||||
@@ -780,6 +787,11 @@ export const SelectionManager = () => {
|
|||||||
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'roof')
|
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'roof')
|
||||||
return {
|
return {
|
||||||
key: `roof:${roofNode.id}:${role ?? 'unsupported'}`,
|
key: `roof:${roofNode.id}:${role ?? 'unsupported'}`,
|
||||||
|
hoveredId: roofNode.id as AnyNodeId,
|
||||||
|
hoverMode:
|
||||||
|
compatible && hasActivePaintMaterial(activePaintMaterial) && role
|
||||||
|
? 'paint-ready'
|
||||||
|
: 'paint-disabled',
|
||||||
apply:
|
apply:
|
||||||
compatible && hasActivePaintMaterial(activePaintMaterial)
|
compatible && hasActivePaintMaterial(activePaintMaterial)
|
||||||
? () => {
|
? () => {
|
||||||
@@ -817,6 +829,11 @@ export const SelectionManager = () => {
|
|||||||
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'stair')
|
role !== null && isActivePaintMaterialCompatible(activePaintMaterial, 'stair')
|
||||||
return {
|
return {
|
||||||
key: `stair:${stairNode.id}:${role ?? 'unsupported'}`,
|
key: `stair:${stairNode.id}:${role ?? 'unsupported'}`,
|
||||||
|
hoveredId: stairNode.id as AnyNodeId,
|
||||||
|
hoverMode:
|
||||||
|
compatible && hasActivePaintMaterial(activePaintMaterial) && role
|
||||||
|
? 'paint-ready'
|
||||||
|
: 'paint-disabled',
|
||||||
apply:
|
apply:
|
||||||
compatible && hasActivePaintMaterial(activePaintMaterial)
|
compatible && hasActivePaintMaterial(activePaintMaterial)
|
||||||
? () => {
|
? () => {
|
||||||
@@ -848,6 +865,8 @@ export const SelectionManager = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
key: `${target}:${node.id}:surface`,
|
key: `${target}:${node.id}:surface`,
|
||||||
|
hoveredId: node.id as AnyNodeId,
|
||||||
|
hoverMode: compatible ? 'paint-ready' : 'paint-disabled',
|
||||||
apply: compatible
|
apply: compatible
|
||||||
? () => {
|
? () => {
|
||||||
useScene
|
useScene
|
||||||
@@ -875,6 +894,8 @@ export const SelectionManager = () => {
|
|||||||
if (disabledNodeTypes.includes(node.type)) {
|
if (disabledNodeTypes.includes(node.type)) {
|
||||||
return {
|
return {
|
||||||
key: `${node.type}:${node.id}:unsupported`,
|
key: `${node.type}:${node.id}:unsupported`,
|
||||||
|
hoveredId: node.id as AnyNodeId,
|
||||||
|
hoverMode: 'paint-disabled',
|
||||||
apply: null,
|
apply: null,
|
||||||
preview: () => previewCursor('not-allowed'),
|
preview: () => previewCursor('not-allowed'),
|
||||||
}
|
}
|
||||||
@@ -896,6 +917,8 @@ export const SelectionManager = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearActivePreview()
|
clearActivePreview()
|
||||||
|
useViewer.setState({ hoveredId: interaction.hoveredId })
|
||||||
|
setHoverHighlightMode(interaction.hoverMode)
|
||||||
|
|
||||||
const restore = interaction.preview?.()
|
const restore = interaction.preview?.()
|
||||||
if (restore) {
|
if (restore) {
|
||||||
@@ -912,6 +935,10 @@ export const SelectionManager = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearActivePreview()
|
clearActivePreview()
|
||||||
|
if (useViewer.getState().hoveredId === interaction.hoveredId) {
|
||||||
|
useViewer.setState({ hoveredId: null })
|
||||||
|
}
|
||||||
|
setHoverHighlightMode('default')
|
||||||
}
|
}
|
||||||
|
|
||||||
const onClick = (event: NodeEvent) => {
|
const onClick = (event: NodeEvent) => {
|
||||||
@@ -932,6 +959,7 @@ export const SelectionManager = () => {
|
|||||||
} else {
|
} else {
|
||||||
clearActivePreview()
|
clearActivePreview()
|
||||||
}
|
}
|
||||||
|
setHoverHighlightMode(interaction.hoverMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
const allTypes = [
|
const allTypes = [
|
||||||
@@ -962,8 +990,10 @@ export const SelectionManager = () => {
|
|||||||
emitter.off(`${type}:click` as any, onClick as any)
|
emitter.off(`${type}:click` as any, onClick as any)
|
||||||
}
|
}
|
||||||
clearActivePreview()
|
clearActivePreview()
|
||||||
|
useViewer.setState({ hoveredId: null })
|
||||||
|
setHoverHighlightMode('default')
|
||||||
}
|
}
|
||||||
}, [curvingWall, mode, movingNode])
|
}, [curvingWall, mode, movingNode, setHoverHighlightMode])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onKeyDown = (event: KeyboardEvent) => {
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user