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.

fix(editor): inspector keyboard + mixed-value safety; unify graph Save buttons

esengine8018002400b1
diff --git a/desktop/src/components/ColorControl.tsx b/desktop/src/components/ColorControl.tsx
index a4f3ce174..5b35c0795 100644
--- a/desktop/src/components/ColorControl.tsx
+++ b/desktop/src/components/ColorControl.tsx
@@ -74,10 +74,11 @@ function useDragTrack(onMove: (x: number, y: number) => void) {
export function ColorControl({
value,
+ mixed,
onBegin,
onEnd,
onChange,
-}: ControlGesture & { value: string; onChange: (v: string) => void }) {
+}: ControlGesture & { value: string; mixed?: boolean; onChange: (v: string) => void }) {
const pop = usePopover();
const sw = useRef<HTMLButtonElement>(null);
const { r, g, b, a } = hexToRgba(value);
@@ -143,10 +144,17 @@ export function ColorControl({
return (
<>
<button ref={sw} type="button" className="sw" onMouseDown={(e) => e.stopPropagation()} onClick={open}>
- <span className="sw-fill" style={{ background: rgbCss(r, g, b), opacity: a }} />
+ {/* Multi-select with differing colors: a striped swatch + "—" hex, so a nudge
+ doesn't silently overwrite every entity with the first one's color. */}
+ <span
+ className="sw-fill"
+ style={mixed
+ ? { background: 'repeating-linear-gradient(45deg,#5a5a5a 0 5px,#3a3a3a 5px 10px)' }
+ : { background: rgbCss(r, g, b), opacity: a }}
+ />
</button>
<span className="field">
- <input value={editing ? text : value} spellCheck={false} onFocus={focusHex} onBlur={blurHex} onChange={(e) => typeHex(e.target.value)} />
+ <input value={editing ? text : mixed ? '' : value} placeholder={mixed ? '—' : undefined} spellCheck={false} onFocus={focusHex} onBlur={blurHex} onChange={(e) => typeHex(e.target.value)} />
</span>
{pop.anchor && (
<Popover anchor={pop.anchor} width={200} onClose={close}>
diff --git a/desktop/src/components/NumField.tsx b/desktop/src/components/NumField.tsx
index 5b0d3aeb5..60212870c 100644
--- a/desktop/src/components/NumField.tsx
+++ b/desktop/src/components/NumField.tsx
@@ -82,6 +82,7 @@ export function NumField({
}: ControlGesture & { value: number; suffix?: string; mixed?: boolean; empty?: boolean; placeholder?: string; onCommit: (n: number) => void }) {
const [editing, setEditing] = useState(false);
const [text, setText] = useState('');
+ const startValue = useRef(value); // pre-edit value, for Escape-revert
return (
<span className="field">
<input
@@ -89,6 +90,7 @@ export function NumField({
placeholder={mixed ? '—' : empty ? placeholder : undefined}
spellCheck={false}
onFocus={() => {
+ startValue.current = value;
setText(empty ? '' : fmt(value));
setEditing(true);
onBegin?.();
@@ -97,6 +99,24 @@ export function NumField({
setEditing(false);
onEnd?.();
}}
+ onKeyDown={(e) => {
+ // Arrow = ±step (Shift finer ÷10, Alt coarser ×10 — the useScrub modifiers);
+ // Enter commits (blur → onEnd); Escape reverts the live-committed edit.
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
+ e.preventDefault();
+ const step = e.shiftKey ? 0.1 : e.altKey ? 10 : 1;
+ const cur = Number.isFinite(parseFloat(text)) ? parseFloat(text) : value;
+ const next = Math.round((cur + (e.key === 'ArrowUp' ? step : -step)) * 1000) / 1000;
+ setText(fmt(next));
+ onCommit(next);
+ } else if (e.key === 'Enter') {
+ e.currentTarget.blur();
+ } else if (e.key === 'Escape') {
+ onCommit(startValue.current); // undo the live edits this session made
+ setText(fmt(startValue.current));
+ e.currentTarget.blur();
+ }
+ }}
onChange={(e) => {
setText(e.target.value);
const n = parseFloat(e.target.value);
diff --git a/desktop/src/panels/AnimatorEditor.tsx b/desktop/src/panels/AnimatorEditor.tsx
index e7a516d59..3b3426cda 100644
--- a/desktop/src/panels/AnimatorEditor.tsx
+++ b/desktop/src/panels/AnimatorEditor.tsx
@@ -14,7 +14,7 @@
* carrying an AND-list of typed parameter conditions + an exit-time flag.
*/
import { useRef, useState, useSyncExternalStore } from 'react';
-import { Plus, Trash2, Save, X } from 'lucide-react';
+import { Plus, Trash2, X } from 'lucide-react';
import {
animatorEdges,
addAnimatorState, removeAnimatorState, moveAnimatorState, renameAnimatorState, setAnimatorInitial,
@@ -28,7 +28,7 @@ import { AnimatorGraphDocument } from '@/animator/AnimatorGraphDocument';
import { t } from '@/i18n';
import { NodeGraphCanvas, type CanvasNode } from '@/components/NodeGraphCanvas';
import { Select } from '@/components/Select';
-import { DirtyDot } from '@/components/DirtyDot';
+import { SaveButton } from '@/components/SaveButton';
type AnimatorCanvasNode = AnimatorState & CanvasNode;
@@ -97,9 +97,9 @@ export function AnimatorEditor() {
<>
<button type="button" className="ng-btn" onClick={addStateAt} title={t('anim.addStateTip')}><Plus size={13} strokeWidth={2} /> {t('anim.stateBtn')}</button>
{(selState || selEdge) && <button type="button" className="ng-btn" title={t('ng.deleteSelected')} onClick={deleteSelected}><Trash2 size={13} strokeWidth={1.9} /></button>}
- <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <DirtyDot />}</span>
+ <span className="ng-doc-title">{filePath.split('/').pop()}</span>
<span style={{ flex: 1 }} />
- <button type="button" className="ng-btn primary" disabled={!dirty} onClick={save}><Save size={13} strokeWidth={1.9} /> {t('ng.save')}</button>
+ <SaveButton dirty={dirty} onSave={save} label={t('ng.save')} />
</>
);
diff --git a/desktop/src/panels/BtTreeEditor.tsx b/desktop/src/panels/BtTreeEditor.tsx
index a26d8c740..f72bba730 100644
--- a/desktop/src/panels/BtTreeEditor.tsx
+++ b/desktop/src/panels/BtTreeEditor.tsx
@@ -11,7 +11,7 @@
* drag-to-connect reparents a node under the drop target.
*/
import { useRef, useState, useSyncExternalStore } from 'react';
-import { Trash2, Save } from 'lucide-react';
+import { Trash2 } from 'lucide-react';
import {
btNodes, btEdges, addBtChild, addBtOrphan, removeBtNode, moveBtNode, setBtNodeField, reparentBtNode,
canHaveChildren, maxChildren,
@@ -21,7 +21,7 @@ import { BtDocument } from '@/bt/BtDocument';
import { t } from '@/i18n';
import { NodeGraphCanvas, type CanvasNode, type MenuItem } from '@/components/NodeGraphCanvas';
import { Select } from '@/components/Select';
-import { DirtyDot } from '@/components/DirtyDot';
+import { SaveButton } from '@/components/SaveButton';
import { SuggestInput } from '@/components/SuggestInput';
import { aiActionItems, aiConditionItems } from '@/components/aiSuggest';
@@ -86,7 +86,7 @@ export function BtTreeEditor() {
const toolbar = (
<>
- <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <DirtyDot />}</span>
+ <span className="ng-doc-title">{filePath.split('/').pop()}</span>
<span style={{ flex: 1 }} />
{selected && def.root.id !== selected && (
<button type="button" className="ng-btn" title={t('bt.deleteNode')}
@@ -94,9 +94,7 @@ export function BtTreeEditor() {
<Trash2 size={13} strokeWidth={1.9} />
</button>
)}
- <button type="button" className="ng-btn primary" disabled={!dirty} onClick={save}>
- <Save size={13} strokeWidth={1.9} /> {t('ng.save')}
- </button>
+ <SaveButton dirty={dirty} onSave={save} label={t('ng.save')} />
</>
);
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index a92e98c47..8637df165 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -160,6 +160,7 @@ function VecField({
const scrub = useScrub(value, onCommit, { onBegin, onEnd });
const [editing, setEditing] = useState(false);
const [text, setText] = useState('');
+ const startValue = useRef(value);
return (
<span className="vfield">
<i className={`ax ${axis}`} {...scrub}>
@@ -170,6 +171,7 @@ function VecField({
placeholder={mixed ? '—' : undefined}
spellCheck={false}
onFocus={() => {
+ startValue.current = value;
setText(fmt(value));
setEditing(true);
onBegin?.();
@@ -178,6 +180,23 @@ function VecField({
setEditing(false);
onEnd?.();
}}
+ onKeyDown={(e) => {
+ // Arrow = ±step (Shift ÷10, Alt ×10); Enter commits; Escape reverts.
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
+ e.preventDefault();
+ const step = e.shiftKey ? 0.1 : e.altKey ? 10 : 1;
+ const cur = Number.isFinite(parseFloat(text)) ? parseFloat(text) : value;
+ const next = Math.round((cur + (e.key === 'ArrowUp' ? step : -step)) * 1000) / 1000;
+ setText(fmt(next));
+ onCommit(next);
+ } else if (e.key === 'Enter') {
+ e.currentTarget.blur();
+ } else if (e.key === 'Escape') {
+ onCommit(startValue.current);
+ setText(fmt(startValue.current));
+ e.currentTarget.blur();
+ }
+ }}
onChange={(e) => {
setText(e.target.value);
const n = parseFloat(e.target.value);
@@ -840,6 +859,7 @@ const isImageAsset = (t: AssetType): boolean => t === 'texture' || t === 'sprite
export function AssetControl({
value,
assetType,
+ mixed,
readOnly,
onBegin,
onEnd,
@@ -847,6 +867,7 @@ export function AssetControl({
}: ControlGesture & {
value: string | number;
assetType?: string;
+ mixed?: boolean;
/** Display-only (the live "Game" inspector): asset identity is not live-tunable
* — a picked ref would land in a World slot that holds a realm-local handle. */
readOnly?: boolean;
@@ -921,13 +942,14 @@ export function AssetControl({
onClick={() => info && revealAsset(info.path)}
>
<span className="th">
- {assetType === 'texture' && info ? (
+ {!mixed && assetType === 'texture' && info ? (
<img src={`estella://project/${info.path}`} alt="" draggable={false} />
) : (
<Box size={11} strokeWidth={1.7} />
)}
</span>
- <span className="an">{info ? info.name : t('det.none')}</span>
+ {/* Multi-select disagreement: "—", not the first entity's asset. */}
+ <span className={`an${mixed ? ' dd-none' : ''}`}>{mixed ? '—' : info ? info.name : t('det.none')}</span>
</button>
{!readOnly && (
<button type="button" className="pk" title={t('det.pickAsset')} onMouseDown={(e) => e.stopPropagation()} onClick={openPick}>
@@ -1254,7 +1276,7 @@ function FieldRow({ entities, comp, field, write }: { entities: EntityId[]; comp
control = <EntityControl value={field.value as number} mixed={mixed} onBegin={begin} onEnd={end} onChange={apply} />;
break;
case 'color':
- control = <ColorControl value={field.value as string} onBegin={begin} onEnd={end} onChange={apply} />;
+ control = <ColorControl value={field.value as string} mixed={mixed} onBegin={begin} onEnd={end} onChange={apply} />;
break;
case 'gradient':
control = <GradientControl value={field.value as GradientValue} onBegin={begin} onEnd={end} onChange={apply} />;
@@ -1267,6 +1289,7 @@ function FieldRow({ entities, comp, field, write }: { entities: EntityId[]; comp
<AssetControl
value={field.value as string | number}
assetType={field.assetType}
+ mixed={mixed}
readOnly={!!write}
onBegin={begin}
onEnd={end}
@@ -1353,6 +1376,12 @@ function FieldRow({ entities, comp, field, write }: { entities: EntityId[]; comp
disabled: pasteValue == null,
onClick: doPaste,
},
+ {
+ label: t('det.resetToDefault'),
+ icon: <RotateCcw size={13} strokeWidth={1.9} />,
+ disabled: !modified,
+ onClick: reset,
+ },
]}
/>
)}
diff --git a/desktop/src/panels/MaterialGraphEditor.tsx b/desktop/src/panels/MaterialGraphEditor.tsx
index fa329253b..80bbe2068 100644
--- a/desktop/src/panels/MaterialGraphEditor.tsx
+++ b/desktop/src/panels/MaterialGraphEditor.tsx
@@ -14,7 +14,7 @@
* them like any edge.
*/
import { useRef, useState, useSyncExternalStore } from 'react';
-import { Save, Plus, Trash2 } from 'lucide-react';
+import { Plus, Trash2 } from 'lucide-react';
import {
NODE_SPECS,
addNode,
@@ -30,7 +30,7 @@ import { t } from '@/i18n';
import { MaterialGraphDocument } from '@/material/MaterialGraphDocument';
import { saveMaterialGraph } from '@/material/openMaterialGraph';
import { ColorControl } from '@/components/ColorControl';
-import { DirtyDot } from '@/components/DirtyDot';
+import { SaveButton } from '@/components/SaveButton';
import { NumField } from '@/components/NumField';
import {
NodeGraphCanvas,
@@ -130,11 +130,9 @@ export function MaterialGraphEditor() {
<Trash2 size={13} strokeWidth={1.9} />
</button>
)}
- <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <DirtyDot />}</span>
+ <span className="ng-doc-title">{filePath.split('/').pop()}</span>
<span style={{ flex: 1 }} />
- <button type="button" className="ng-btn primary" disabled={!dirty} onClick={() => void saveMaterialGraph(filePath, graph)}>
- <Save size={13} strokeWidth={1.9} /> {t('mat.save')}
- </button>
+ <SaveButton dirty={dirty} onSave={() => void saveMaterialGraph(filePath, graph)} label={t('mat.save')} />
</>
);
diff --git a/desktop/src/panels/StateMachineEditor.tsx b/desktop/src/panels/StateMachineEditor.tsx
index ac923987e..2f9e4fe5d 100644
--- a/desktop/src/panels/StateMachineEditor.tsx
+++ b/desktop/src/panels/StateMachineEditor.tsx
@@ -14,7 +14,7 @@
* generic component shared with the behavior-tree editor.
*/
import { useMemo, useRef, useState, useSyncExternalStore } from 'react';
-import { Plus, Trash2, Save } from 'lucide-react';
+import { Plus, Trash2 } from 'lucide-react';
import {
fsmEdges, addState, removeState, moveState, renameState, setStateHook, setInitial,
addTransition, removeTransition, updateTransition, actionRefName, actionRefArg,
@@ -24,7 +24,7 @@ import { FsmGraphDocument } from '@/fsm/FsmGraphDocument';
import { t } from '@/i18n';
import { NodeGraphCanvas, type CanvasNode } from '@/components/NodeGraphCanvas';
import { Select } from '@/components/Select';
-import { DirtyDot } from '@/components/DirtyDot';
+import { SaveButton } from '@/components/SaveButton';
import { SuggestInput } from '@/components/SuggestInput';
import { aiActionItems, aiConditionItems } from '@/components/aiSuggest';
@@ -86,9 +86,9 @@ export function StateMachineEditor() {
<>
<button type="button" className="ng-btn" onClick={addStateAt} title={t('fsm.addStateTip')}><Plus size={13} strokeWidth={2} /> {t('fsm.stateBtn')}</button>
{(selState || selEdge) && <button type="button" className="ng-btn" title={t('ng.deleteSelected')} onClick={deleteSelected}><Trash2 size={13} strokeWidth={1.9} /></button>}
- <span className="ng-doc-title">{filePath.split('/').pop()}{dirty && <DirtyDot />}</span>
+ <span className="ng-doc-title">{filePath.split('/').pop()}</span>
<span style={{ flex: 1 }} />
- <button type="button" className="ng-btn primary" disabled={!dirty} onClick={save}><Save size={13} strokeWidth={1.9} /> {t('ng.save')}</button>
+ <SaveButton dirty={dirty} onSave={save} label={t('ng.save')} />
</>
);