Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(editor): functional menu bar + wire dead toolbar controls (UE5 alignment B1)

esengine0fcb98740d79
diff --git a/desktop/src/layout/MenuBar.tsx b/desktop/src/layout/MenuBar.tsx
index cfd49e1a1..5bde8a6bd 100644
--- a/desktop/src/layout/MenuBar.tsx
+++ b/desktop/src/layout/MenuBar.tsx
@@ -1,7 +1,24 @@
-// Top menu bar. Draws the Estella mark and the classic menu set. The window is
-// frameless (titleBarStyle: hiddenInset) so this strip doubles as the drag region.
+// Top menu bar — functional dropdowns wired to the real editor commands
+// (project open/save, history, entity ops, view toggles), in the UE5 menu idiom.
+// The window is frameless (titleBarStyle: hiddenInset) so this strip doubles as
+// the drag region; the menus + dropdowns opt out of dragging.
+import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
+import { Check } from 'lucide-react';
+import { useEditorStore } from '@/store/editorStore';
+import { EditorHistory } from '@/engine/EditorHistory';
+import { SceneCommands } from '@/engine/SceneCommands';
+import { ProjectStore } from '@/project/ProjectStore';
-const MENUS = ['File', 'Edit', 'Selection', 'View', 'Actor', 'Build', 'Window', 'Help'];
+const LAYOUT_KEY = 'estella.editor.layout.v1';
+
+type MenuItem =
+ | { sep: true }
+ | { label: string; shortcut?: string; onClick: () => void; disabled?: boolean; checked?: boolean };
+
+interface MenuDef {
+ title: string;
+ items: MenuItem[];
+}
function Mark() {
// The signature: a four-point starlight glyph — "Estella" = star.
@@ -17,24 +34,178 @@ function Mark() {
}
export function MenuBar() {
+ const [open, setOpen] = useState<string | null>(null);
+ const barRef = useRef<HTMLDivElement>(null);
+
+ // Re-render on history changes so undo/redo enabled state stays live.
+ useSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);
+ const project = useSyncExternalStore(ProjectStore.subscribe, ProjectStore.getSnapshot);
+ const {
+ selectedId, select,
+ showGrid, showGizmos, snapping, toggleGrid, toggleGizmos, toggleSnapping,
+ openLauncher,
+ } = useEditorStore();
+
+ // Close the open menu on an outside click or Escape.
+ useEffect(() => {
+ if (!open) return;
+ const onDown = (e: MouseEvent) => {
+ if (barRef.current && !barRef.current.contains(e.target as Node)) setOpen(null);
+ };
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') setOpen(null);
+ };
+ window.addEventListener('mousedown', onDown);
+ window.addEventListener('keydown', onKey);
+ return () => {
+ window.removeEventListener('mousedown', onDown);
+ window.removeEventListener('keydown', onKey);
+ };
+ }, [open]);
+
+ // Run an item's action, then close the menu.
+ const run = (fn: () => void) => () => {
+ setOpen(null);
+ fn();
+ };
+
+ const save = () => void ProjectStore.save().catch(() => ProjectStore.saveAsViaDialog());
+ const duplicate = () => {
+ if (selectedId == null) return;
+ const dup = SceneCommands.duplicateEntity(selectedId);
+ if (dup != null) select(dup);
+ };
+ const remove = () => {
+ if (selectedId == null) return;
+ SceneCommands.deleteEntity(selectedId);
+ select(null);
+ };
+ const addEntity = () => {
+ const e = SceneCommands.addEntity();
+ if (e != null) select(e);
+ };
+
+ const menus: MenuDef[] = [
+ {
+ title: 'File',
+ items: [
+ { label: 'Open Project…', shortcut: '⌘O', onClick: () => void ProjectStore.openViaDialog().then((ok) => ok && select(null)) },
+ { sep: true },
+ { label: 'Save Scene', shortcut: '⌘S', onClick: save, disabled: !project?.currentScene },
+ { label: 'Save Scene As…', shortcut: '⇧⌘S', onClick: () => void ProjectStore.saveAsViaDialog(), disabled: !project },
+ { sep: true },
+ { label: 'Close Project', onClick: openLauncher, disabled: !project },
+ ],
+ },
+ {
+ title: 'Edit',
+ items: [
+ { label: 'Undo', shortcut: '⌘Z', onClick: () => EditorHistory.undo(), disabled: !EditorHistory.canUndo() },
+ { label: 'Redo', shortcut: '⇧⌘Z', onClick: () => EditorHistory.redo(), disabled: !EditorHistory.canRedo() },
+ ],
+ },
+ {
+ title: 'Entity',
+ items: [
+ { label: 'Add Entity', onClick: addEntity },
+ { sep: true },
+ { label: 'Duplicate', shortcut: '⌘D', onClick: duplicate, disabled: selectedId == null },
+ { label: 'Delete', shortcut: '⌫', onClick: remove, disabled: selectedId == null },
+ { sep: true },
+ { label: 'Deselect', onClick: () => select(null), disabled: selectedId == null },
+ ],
+ },
+ {
+ title: 'View',
+ items: [
+ { label: 'Show Grid', onClick: toggleGrid, checked: showGrid },
+ { label: 'Show Gizmos', onClick: toggleGizmos, checked: showGizmos },
+ { label: 'Snapping', onClick: toggleSnapping, checked: snapping },
+ ],
+ },
+ {
+ title: 'Build',
+ items: [
+ { label: 'Build Project Scripts', onClick: () => void window.estella?.project?.buildScripts?.().catch(() => {}), disabled: !project },
+ { label: 'Extract Component Schemas', onClick: () => void window.estella?.project?.extractSchemas?.().catch(() => {}), disabled: !project },
+ ],
+ },
+ {
+ title: 'Window',
+ items: [
+ { label: 'Reset Layout', onClick: () => { localStorage.removeItem(LAYOUT_KEY); location.reload(); } },
+ { sep: true },
+ { label: 'Back to Launcher', onClick: openLauncher },
+ ],
+ },
+ {
+ title: 'Help',
+ items: [
+ {
+ label: 'About Estella',
+ onClick: () => void window.estella?.getVersion?.()
+ .then((v) => window.alert(`Estella Editor${v ? ' · ' + v : ''}\nA UE5-style editor for the Estella 2D engine.`))
+ .catch(() => window.alert('Estella Editor')),
+ },
+ ],
+ },
+ ];
+
return (
- <div className="menubar">
+ <div className="menubar" ref={barRef}>
<div className="menubar__brand">
<Mark />
<span className="menubar__title">Estella</span>
</div>
<nav className="menubar__menus">
- {MENUS.map((m) => (
- <button key={m} className="menubar__item" type="button">
- {m}
- </button>
+ {menus.map((m) => (
+ <div key={m.title} className="menubar__menu">
+ <button
+ className={`menubar__item${open === m.title ? ' is-open' : ''}`}
+ type="button"
+ onClick={() => setOpen((o) => (o === m.title ? null : m.title))}
+ onMouseEnter={() => setOpen((o) => (o ? m.title : o))}
+ >
+ {m.title}
+ </button>
+ {open === m.title && (
+ <div className="menu-dropdown" role="menu">
+ {m.items.map((it, i) =>
+ 'sep' in it ? (
+ <div key={i} className="menu-dropdown__sep" />
+ ) : (
+ <button
+ key={i}
+ type="button"
+ role="menuitem"
+ className="menu-dropdown__item"
+ disabled={it.disabled}
+ onClick={run(it.onClick)}
+ >
+ <span className="menu-dropdown__check">
+ {it.checked ? <Check size={13} strokeWidth={2.2} /> : null}
+ </span>
+ <span className="menu-dropdown__label">{it.label}</span>
+ {it.shortcut ? <span className="menu-dropdown__shortcut">{it.shortcut}</span> : null}
+ </button>
+ ),
+ )}
+ </div>
+ )}
+ </div>
))}
</nav>
- <div className="menubar__project">
- <span className="menubar__project-name">platformer</span>
- <span className="menubar__sep">/</span>
- <span className="menubar__scene mono">Level_01.scene</span>
- </div>
+ {project ? (
+ <div className="menubar__project">
+ <span className="menubar__project-name">{project.name}</span>
+ {project.currentScene ? (
+ <>
+ <span className="menubar__sep">/</span>
+ <span className="menubar__scene mono">{project.currentScene.split('/').pop()}</span>
+ </>
+ ) : null}
+ </div>
+ ) : null}
</div>
);
}
diff --git a/desktop/src/layout/Toolbar.tsx b/desktop/src/layout/Toolbar.tsx
index 88996e386..55af50c1c 100644
--- a/desktop/src/layout/Toolbar.tsx
+++ b/desktop/src/layout/Toolbar.tsx
@@ -19,6 +19,7 @@ import {
} from 'lucide-react';
import { useEditorStore } from '@/store/editorStore';
import { EditorHistory } from '@/engine/EditorHistory';
+import { ProjectStore } from '@/project/ProjectStore';
import type { ToolMode } from '@/types';
interface ToolDef {
@@ -73,6 +74,8 @@ export function Toolbar() {
toggleSnapping,
showGrid,
toggleGrid,
+ showGizmos,
+ toggleGizmos,
isPlaying,
isPaused,
togglePlay,
@@ -88,7 +91,11 @@ export function Toolbar() {
return (
<div className="toolbar">
<div className="toolbar__group">
- <TBtn icon={Save} label="Save Scene ⌘S" />
+ <TBtn
+ icon={Save}
+ label="Save Scene ⌘S"
+ onClick={() => void ProjectStore.save().catch(() => ProjectStore.saveAsViaDialog())}
+ />
</div>
<span className="toolbar__div" />
@@ -145,12 +152,17 @@ export function Toolbar() {
</div>
<div className="toolbar__group toolbar__right">
- <TBtn icon={Eye} label="View Options" />
+ <TBtn icon={Eye} label="Show Gizmos" active={showGizmos} onClick={toggleGizmos} />
<button type="button" className="chip" title="Build target">
<Smartphone size={13} strokeWidth={1.85} />
<span>Web</span>
</button>
- <button type="button" className="chip chip--accent" title="Build project">
+ <button
+ type="button"
+ className="chip chip--accent"
+ title="Build project scripts"
+ onClick={() => void window.estella?.project?.buildScripts?.().catch(() => {})}
+ >
<Hammer size={13} strokeWidth={1.85} />
<span>Build</span>
</button>
diff --git a/desktop/src/theme/app.css b/desktop/src/theme/app.css
index 71ae06d58..d1508a096 100644
--- a/desktop/src/theme/app.css
+++ b/desktop/src/theme/app.css
@@ -55,10 +55,71 @@
color: var(--text-dim);
border-radius: var(--r-xs);
}
-.menubar__item:hover {
+.menubar__item:hover,
+.menubar__item.is-open {
color: var(--text-hi);
background: var(--hover);
}
+.menubar__menu {
+ position: relative;
+ display: flex;
+}
+
+/* Menu dropdown */
+.menu-dropdown {
+ position: absolute;
+ top: calc(100% + 2px);
+ left: 0;
+ z-index: 1000;
+ min-width: 208px;
+ padding: 4px;
+ background: var(--raised);
+ border: 1px solid var(--line-strong);
+ border-radius: var(--r-sm);
+ box-shadow: var(--shadow-pop);
+ -webkit-app-region: no-drag;
+}
+.menu-dropdown__item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ height: 26px;
+ padding: 0 8px 0 4px;
+ border-radius: var(--r-xs);
+ font-size: var(--fs-sm);
+ color: var(--text);
+ text-align: left;
+}
+.menu-dropdown__item:not(:disabled):hover {
+ background: var(--star-dim);
+ color: var(--text-hi);
+}
+.menu-dropdown__item:disabled {
+ color: var(--text-faint);
+ cursor: default;
+}
+.menu-dropdown__check {
+ flex-shrink: 0;
+ width: 16px;
+ display: grid;
+ place-items: center;
+ color: var(--star-hi);
+}
+.menu-dropdown__label {
+ flex: 1;
+ white-space: nowrap;
+}
+.menu-dropdown__shortcut {
+ margin-left: 18px;
+ font-size: var(--fs-xs);
+ color: var(--text-faint);
+}
+.menu-dropdown__sep {
+ height: 1px;
+ margin: 4px 2px;
+ background: var(--line);
+}
.menubar__project {
margin-left: auto;
display: flex;