Files
esengine/packages/behavior-tree-editor/src/components/menu/NodeContextMenu.tsx
YHH b42a7b4e43 Feature/editor optimization (#251)
* refactor: 编辑器/运行时架构拆分与构建系统升级

* feat(core): 层级系统重构与UI变换矩阵修复

* refactor: 移除 ecs-components 聚合包并修复跨包组件查找问题

* fix(physics): 修复跨包组件类引用问题

* feat: 统一运行时架构与浏览器运行支持

* feat(asset): 实现浏览器运行时资产加载系统

* fix: 修复文档、CodeQL安全问题和CI类型检查错误

* fix: 修复文档、CodeQL安全问题和CI类型检查错误

* fix: 修复文档、CodeQL安全问题、CI类型检查和测试错误

* test: 补齐核心模块测试用例,修复CI构建配置

* fix: 修复测试用例中的类型错误和断言问题

* fix: 修复 turbo build:npm 任务的依赖顺序问题

* fix: 修复 CI 构建错误并优化构建性能
2025-12-01 22:28:51 +08:00

96 lines
3.1 KiB
TypeScript

import { React, Icons } from '@esengine/editor-runtime';
const { Trash2, Replace, Plus } = Icons;
interface NodeContextMenuProps {
visible: boolean;
position: { x: number; y: number };
nodeId: string | null;
isBlackboardVariable?: boolean;
onReplaceNode?: () => void;
onDeleteNode?: () => void;
onCreateNode?: () => void;
}
export const NodeContextMenu: React.FC<NodeContextMenuProps> = ({
visible,
position,
nodeId,
isBlackboardVariable = false,
onReplaceNode,
onDeleteNode,
onCreateNode
}) => {
if (!visible) return null;
const menuItemStyle = {
padding: '8px 16px',
cursor: 'pointer',
color: '#cccccc',
fontSize: '13px',
transition: 'background-color 0.15s',
display: 'flex',
alignItems: 'center',
gap: '8px'
};
return (
<div
style={{
position: 'fixed',
left: position.x,
top: position.y,
backgroundColor: '#2d2d30',
border: '1px solid #454545',
borderRadius: '4px',
boxShadow: '0 4px 16px rgba(0, 0, 0, 0.5)',
zIndex: 10000,
minWidth: '150px',
padding: '4px 0'
}}
onClick={(e) => e.stopPropagation()}
>
{nodeId ? (
<>
{onReplaceNode && (
<div
onClick={onReplaceNode}
style={menuItemStyle}
onMouseEnter={(e) => e.currentTarget.style.backgroundColor = '#094771'}
onMouseLeave={(e) => e.currentTarget.style.backgroundColor = 'transparent'}
>
<Replace size={14} />
</div>
)}
{onDeleteNode && (
<div
onClick={onDeleteNode}
style={{ ...menuItemStyle, color: '#f48771' }}
onMouseEnter={(e) => e.currentTarget.style.backgroundColor = '#5a1a1a'}
onMouseLeave={(e) => e.currentTarget.style.backgroundColor = 'transparent'}
>
<Trash2 size={14} />
</div>
)}
</>
) : (
<>
{onCreateNode && (
<div
onClick={onCreateNode}
style={menuItemStyle}
onMouseEnter={(e) => e.currentTarget.style.backgroundColor = '#094771'}
onMouseLeave={(e) => e.currentTarget.style.backgroundColor = 'transparent'}
>
<Plus size={14} />
</div>
)}
</>
)}
</div>
);
};