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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): eye-hide for UI, click-through cycling in UI, and F on real selections
yhh4b4a5d389f37
diff --git a/desktop/electron/main.ts b/desktop/electron/main.tsindex 1b0bf0831..bd8015124 100644--- a/desktop/electron/main.ts+++ b/desktop/electron/main.ts@@ -269,6 +269,9 @@ function createWindow() {// Keep the renderer sandboxed; all privileged work goes through preload IPC.contextIsolation: true,nodeIntegration: false,+ // An engine editor keeps simulating while occluded — and the automation+ // hooks' rAF-based waits must not freeze when another window covers us.+ backgroundThrottling: false,},});diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.tsindex 7f146dab9..8644a0490 100644--- a/desktop/src/commands/editorCommands.ts+++ b/desktop/src/commands/editorCommands.ts@@ -232,7 +232,10 @@ commands.register({keybinding: 'f',isEnabled: () => sel().selectedId != null,run: () => {- const ids = [...sel().selectedIds];+ // Selection holds source ids; the viewport works on runtime entities.+ const ids = [...sel().selectedIds]+ .map((sid) => SceneModel.runtimeFor(sid))+ .filter((rt): rt is NonNullable<typeof rt> => rt != null);if (ids.length > 0) ViewportController.frameSelection(ids);},});diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex c08101a62..96bb853dc 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -2,7 +2,7 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport {Camera, CameraView, EditorView, Light2D, Sprite, Transform, Canvas, BoxCollider, CircleCollider,- UINode, UICameraInfo, screenToUiWorld, uiWorldToScreen, uiPickWorld, type UICameraData,+ UINode, UICameraInfo, screenToUiWorld, uiWorldToScreen, uiPickAllWorld, type UICameraData,} from 'esengine';import type { EntityId } from '@/types';import { EngineHost } from './EngineHost';@@ -117,32 +117,35 @@ export const ViewportController = {};},- /** The UI entity under the pointer (editor pick: any layout box, not just- * raycast targets — so plain text and panels are selectable), or null. */- pickUIEntity(clientX: number, clientY: number): EntityId | null {+ /** All UI entities under the pointer, most specific first (editor pick: any+ * layout box, not just raycast targets — so plain text and panels are+ * selectable). Locked / hidden entries are dropped. */+ pickUIEntities(clientX: number, clientY: number): EntityId[] {const world = EngineHost.world;const module = EngineHost.module;const cam = EngineHost.getResource(UICameraInfo) as UICameraData | undefined;- if (!world || !module || !cam?.valid) return null;- type Registry = Parameters<typeof uiPickWorld>[1];+ if (!world || !module || !cam?.valid) return [];+ type Registry = Parameters<typeof uiPickAllWorld>[1];const reg = (world as unknown as { getCppRegistry(): Registry | null }).getCppRegistry();const s = clientToScreen(clientX, clientY);- if (!reg || !s) return null;+ if (!reg || !s) return [];const wp = screenToUiWorld(cam, s.sx, s.sy);- const hit = uiPickWorld(module, reg, wp.x, wp.y);- if (hit == null) return null;- const src = SceneModel.sourceFor(hit);- if (src != null && (SceneModel.isLocked(src) || SceneModel.isHidden(src))) return null;- return hit;+ return uiPickAllWorld(module, reg, wp.x, wp.y).filter((hit) => {+ const src = SceneModel.sourceFor(hit);+ return src == null || (!SceneModel.isLocked(src) && !SceneModel.isHidden(src));+ });+ },++ /** The topmost UI entity under the pointer, or null. */+ pickUIEntity(clientX: number, clientY: number): EntityId | null {+ return this.pickUIEntities(clientX, clientY)[0] ?? null;},/** Selectable entities under the pointer, topmost-first (UI, then world by* descending layer, later-drawn winning ties). `pickEntity` is its head;* click-through cycling walks the rest. */pickEntitiesAt(clientX: number, clientY: number): EntityId[] {- const out: EntityId[] = [];- const ui = this.pickUIEntity(clientX, clientY);- if (ui != null) out.push(ui);+ const out: EntityId[] = [...this.pickUIEntities(clientX, clientY)];const world = EngineHost.world;const wp = this.canvasToWorld(clientX, clientY);@@ -206,7 +209,7 @@ export const ViewportController = {const world = EngineHost.world;const module = EngineHost.module;if (!world || !module || !world.has(id, UINode) || !world.has(id, Transform)) return null;- type Registry = Parameters<typeof uiPickWorld>[1];+ type Registry = Parameters<typeof uiPickAllWorld>[1];const reg = (world as unknown as { getCppRegistry(): Registry | null }).getCppRegistry();if (!reg) return null;const t = world.get(id, Transform);diff --git a/desktop/src/engine/schema.ts b/desktop/src/engine/schema.tsindex c1f1c2227..4990e5d91 100644--- a/desktop/src/engine/schema.ts+++ b/desktop/src/engine/schema.ts@@ -39,6 +39,7 @@ const HIDDEN_COMPONENTS = new Set(['Parent', 'Children', 'Name']);// turns that behaviour off without hiding the entity.const RENDER_COMPONENTS = new Set(['Sprite', 'ShapeRenderer', 'SpineAnimation', 'BitmapText', 'TilemapLayer', 'ParticleEmitter',+ 'UIVisual', 'Text',]);/** Whether a component's enable flag participates in the entity's render visibility. */export function isRenderComponent(name: string): boolean {diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdxindex 819cbbeed..b20364d7c 100644--- a/docs/astro/src/content/docs/guides/ui.mdx+++ b/docs/astro/src/content/docs/guides/ui.mdx@@ -143,6 +143,7 @@ Text draws from a dynamic glyph atlas with **two pipelines**, chosen per Text by| `shadowColor` / `shadowBlur` / `shadowOffsetX` / `shadowOffsetY` | — | Drop shadow. || `richText` | boolean | `false` | Parse inline rich-text markup. || `renderMode` | `TextRenderMode` | `Auto` | Glyph pipeline: `Auto` / `Bitmap` / `Sdf` (see above). |+| `enabled` | boolean | `true` | Render toggle (the editor's eye uses it too). |## `UIVisual` — the filldiff --git a/docs/astro/src/content/docs/zh-cn/guides/ui.mdx b/docs/astro/src/content/docs/zh-cn/guides/ui.mdxindex f5684c854..1a26c8ab1 100644--- a/docs/astro/src/content/docs/zh-cn/guides/ui.mdx+++ b/docs/astro/src/content/docs/zh-cn/guides/ui.mdx@@ -136,6 +136,7 @@ addStartupSystem(buildPauseMenu);| `shadowColor` / `shadowBlur` / `shadowOffsetX` / `shadowOffsetY` | — | 投影。 || `richText` | boolean | `false` | 解析内联富文本标记。 || `renderMode` | `TextRenderMode` | `Auto` | 字形管线:`Auto` / `Bitmap` / `Sdf`(见上)。 |+| `enabled` | boolean | `true` | 渲染开关(编辑器的眼睛图标也走它)。 |## `UIVisual` —— 填充diff --git a/sdk/src/core-ui.ts b/sdk/src/core-ui.tsindex 423e50319..ce24af353 100644--- a/sdk/src/core-ui.ts+++ b/sdk/src/core-ui.ts@@ -53,6 +53,7 @@ export {uiWorldToScreen,uiHitTestWorld,uiPickWorld,+ uiPickAllWorld,TextInput,FillMethod,FillOrigin,diff --git a/sdk/src/ui/core/text.ts b/sdk/src/ui/core/text.tsindex 9fd51f7a3..578610a8d 100644--- a/sdk/src/ui/core/text.ts+++ b/sdk/src/ui/core/text.ts@@ -55,6 +55,8 @@ export interface TextData {shadowOffsetY: number;richText: boolean;renderMode: TextRenderMode;+ /** Render toggle — the editor's eye and runtime hiding both flip this. */+ enabled: boolean;}export const Text = defineComponent<TextData>('Text', {@@ -77,6 +79,7 @@ export const Text = defineComponent<TextData>('Text', {shadowOffsetY: 0,richText: false,renderMode: TextRenderMode.Auto,+ enabled: true,}, {fields: {align: { enum: enumOptions(TextAlign) },diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.tsindex 6c7365566..d8eedd021 100644--- a/sdk/src/ui/index.ts+++ b/sdk/src/ui/index.ts@@ -280,7 +280,7 @@ export {type UICameraData,} from './core/ui-camera-info';-export { screenToUiWorld, uiWorldToScreen, uiHitTestWorld, uiPickWorld } from './util/ui-pick';+export { screenToUiWorld, uiWorldToScreen, uiHitTestWorld, uiPickWorld, uiPickAllWorld } from './util/ui-pick';export {UILayoutGeneration,diff --git a/sdk/src/ui/text/plugin.ts b/sdk/src/ui/text/plugin.tsindex 49dc55e62..c603db2f2 100644--- a/sdk/src/ui/text/plugin.ts+++ b/sdk/src/ui/text/plugin.ts@@ -91,7 +91,8 @@ export class TextPlugin implements Plugin {for (const e of world.getEntitiesWithComponents([Text, Transform])) {const entity = e as Entity;const t = world.get(entity, Text) as TextData;- if (!t.content) continue;+ // enabled === false: pre-upgrade data lacks the field → visible.+ if (!t.content || t.enabled === false) continue;const tr = world.get(entity, Transform) as TransformData;const renderer = this.rendererFor(diff --git a/sdk/src/ui/util/ui-pick.ts b/sdk/src/ui/util/ui-pick.tsindex ccbdb232f..e93b078c0 100644--- a/sdk/src/ui/util/ui-pick.ts+++ b/sdk/src/ui/util/ui-pick.ts@@ -48,3 +48,21 @@ export function uiPickWorld(const hit = module.uiHitTest_pick(registry, worldX, worldY);return hit === NO_HIT ? null : hit;}++/** All editor-pickable UI entities under the point, most specific first+ * (backs click-through cycling). */+export function uiPickAllWorld(+ module: ESEngineModule,+ registry: CppRegistry,+ worldX: number,+ worldY: number,+): Entity[] {+ if (!module.uiHitTest_pickAll || !module.uiHitTest_pickResult) return [];+ const count = module.uiHitTest_pickAll(registry, worldX, worldY);+ const out: Entity[] = [];+ for (let i = 0; i < count; i++) {+ const e = module.uiHitTest_pickResult(i);+ if (e !== NO_HIT) out.push(e);+ }+ return out;+}diff --git a/sdk/src/ui/widgets/helpers.ts b/sdk/src/ui/widgets/helpers.tsindex e8b99b8aa..f728cdf6f 100644--- a/sdk/src/ui/widgets/helpers.ts+++ b/sdk/src/ui/widgets/helpers.ts@@ -143,6 +143,7 @@ export function buildText(init: TextInit = {}): TextData {shadowOffsetY: init.shadowOffsetY ?? 0,richText: init.richText ?? false,renderMode: init.renderMode ?? TextRenderMode.Auto,+ enabled: init.enabled ?? true,};}diff --git a/sdk/src/ui/widgets/prefabs/Button.esprefab b/sdk/src/ui/widgets/prefabs/Button.esprefabindex bdfa410e3..80ee5cb41 100644--- a/sdk/src/ui/widgets/prefabs/Button.esprefab+++ b/sdk/src/ui/widgets/prefabs/Button.esprefab@@ -365,7 +365,8 @@"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],diff --git a/sdk/src/ui/widgets/prefabs/Dropdown.esprefab b/sdk/src/ui/widgets/prefabs/Dropdown.esprefabindex 3298b7e0f..40f2e7b7b 100644--- a/sdk/src/ui/widgets/prefabs/Dropdown.esprefab+++ b/sdk/src/ui/widgets/prefabs/Dropdown.esprefab@@ -365,7 +365,8 @@"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],diff --git a/sdk/src/ui/widgets/prefabs/ListView.esprefab b/sdk/src/ui/widgets/prefabs/ListView.esprefabindex 1e132b002..4c692121d 100644--- a/sdk/src/ui/widgets/prefabs/ListView.esprefab+++ b/sdk/src/ui/widgets/prefabs/ListView.esprefab@@ -330,7 +330,8 @@"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],diff --git a/sdk/src/ui/widgets/prefabs/generated.ts b/sdk/src/ui/widgets/prefabs/generated.tsindex b4e993080..828a9076b 100644--- a/sdk/src/ui/widgets/prefabs/generated.ts+++ b/sdk/src/ui/widgets/prefabs/generated.ts@@ -369,7 +369,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],@@ -1890,7 +1891,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],@@ -2230,7 +2232,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"shadowOffsetX": 0,"shadowOffsetY": 0,"richText": false,- "renderMode": 0+ "renderMode": 0,+ "enabled": true}}],diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex 575891b05..36f7c3158 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -356,6 +356,8 @@ export interface ESEngineModule {uiHitTest_getHitEntity(): number;uiHitTest_getHitEntityPrev(): number;uiHitTest_pick?(registry: CppRegistry, worldX: number, worldY: number): number;+ uiHitTest_pickAll?(registry: CppRegistry, worldX: number, worldY: number): number;+ uiHitTest_pickResult?(index: number): number;uiNode_computedWidth(registry: CppRegistry, entity: number): number;uiNode_computedHeight(registry: CppRegistry, entity: number): number;uiRenderOrder_update(registry: CppRegistry): void;diff --git a/sdk/tests/ui-text-render-mode.test.ts b/sdk/tests/ui-text-render-mode.test.tsindex c06446412..ac88c30a0 100644--- a/sdk/tests/ui-text-render-mode.test.ts+++ b/sdk/tests/ui-text-render-mode.test.ts@@ -16,9 +16,15 @@ describe('TextRenderMode', () => {expect(meta?.enum?.map(o => o.label)).toEqual(['Auto', 'Bitmap', 'Sdf']);});+ it('Text defaults enabled (the render toggle the editor eye flips)', () => {+ expect((Text._default as { enabled: boolean }).enabled).toBe(true);+ });+it('buildText defaults renderMode to Auto and passes overrides through', () => {expect(buildText().renderMode).toBe(TextRenderMode.Auto);expect(buildText({ renderMode: TextRenderMode.Sdf }).renderMode).toBe(TextRenderMode.Sdf);+ expect(buildText().enabled).toBe(true);+ expect(buildText({ enabled: false }).enabled).toBe(false);});});diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex b19b6a717..56453fd98 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -598,6 +598,15 @@ u32 uiHitTest_pick(ecs::Registry& registry, f32 worldX, f32 worldY) {return ctx().require<ecs::UISystem>().pick(registry, worldX, worldY);}+// Editor pick list (click-through cycling): count + indexed results.+u32 uiHitTest_pickAll(ecs::Registry& registry, f32 worldX, f32 worldY) {+ return ctx().require<ecs::UISystem>().pickAll(registry, worldX, worldY);+}++u32 uiHitTest_pickResult(u32 index) {+ return ctx().require<ecs::UISystem>().pickResult(index);+}+// Resolved (Yoga-pass) pixel size of a UI node, for the editor's selection outline.// The node's world box is this size, pivot-centered on its Transform.f32 uiNode_computedWidth(ecs::Registry& r, u32 e) {@@ -695,6 +704,8 @@ EMSCRIPTEN_BINDINGS(esengine_ui_systems) {emscripten::function("uiHitTest_getHitEntity", &esengine::uiHitTest_getHitEntity);emscripten::function("uiHitTest_getHitEntityPrev", &esengine::uiHitTest_getHitEntityPrev);emscripten::function("uiHitTest_pick", &esengine::uiHitTest_pick);+ emscripten::function("uiHitTest_pickAll", &esengine::uiHitTest_pickAll);+ emscripten::function("uiHitTest_pickResult", &esengine::uiHitTest_pickResult);emscripten::function("uiNode_computedWidth", &esengine::uiNode_computedWidth);emscripten::function("uiNode_computedHeight", &esengine::uiNode_computedHeight);emscripten::function("uiRenderOrder_update", &esengine::uiRenderOrder_update);diff --git a/src/esengine/ecs/UISystem.cpp b/src/esengine/ecs/UISystem.cppindex 17ffd7afb..06572c805 100644--- a/src/esengine/ecs/UISystem.cpp+++ b/src/esengine/ecs/UISystem.cpp@@ -16,6 +16,9 @@#include "components/UINode.hpp"#include "components/UIVisual.hpp"+#include <algorithm>+#include <cstdint>+namespace esengine::ecs {void UISystem::hitTestUpdate(@@ -70,15 +73,19 @@ void UISystem::hitTestUpdate(}}-u32 UISystem::pick(Registry& registry, f32 worldX, f32 worldY) const {+u32 UISystem::pickAll(Registry& registry, f32 worldX, f32 worldY) {+ pickResults_.clear();const auto& nodes = tree.nodes_;// Rank hits by hierarchy depth (the most specific element under the// cursor — clicking a label picks the label, not its panel), breaking// ties by draw order.- Entity best = INVALID_ENTITY;- i32 bestDepth = -1;- i32 bestOrder = INT32_MIN;+ struct Hit {+ Entity entity;+ i32 depth;+ i32 order;+ };+ std::vector<Hit> hits;for (i32 i = static_cast<i32>(nodes.size()) - 1; i >= 0; i--) {Entity entity = nodes[i].entity;@@ -109,14 +116,20 @@ u32 UISystem::pick(Registry& registry, f32 worldX, f32 worldY) const {a = parent;}auto* vis = registry.tryGet<UIVisual>(entity);- const i32 order = vis ? vis->uiOrder : INT32_MIN;- if (depth > bestDepth || (depth == bestDepth && order > bestOrder)) {- bestDepth = depth;- bestOrder = order;- best = entity;- }+ hits.push_back({entity, depth, vis ? vis->uiOrder : INT32_MIN});}- return best.id();++ std::sort(hits.begin(), hits.end(), [](const Hit& a, const Hit& b) {+ if (a.depth != b.depth) return a.depth > b.depth;+ return a.order > b.order;+ });+ pickResults_.reserve(hits.size());+ for (const Hit& h : hits) pickResults_.push_back(h.entity);+ return static_cast<u32>(pickResults_.size());+}++u32 UISystem::pick(Registry& registry, f32 worldX, f32 worldY) {+ return pickAll(registry, worldX, worldY) > 0 ? pickResults_[0].id() : INVALID_ENTITY.id();}} // namespace esengine::ecsdiff --git a/src/esengine/ecs/UISystem.hpp b/src/esengine/ecs/UISystem.hppindex 74a2f32fd..ceb9db5e0 100644--- a/src/esengine/ecs/UISystem.hpp+++ b/src/esengine/ecs/UISystem.hpp@@ -17,6 +17,8 @@#include "Registry.hpp"#include "UITree.hpp"+#include <vector>+namespace esengine::ecs {/**@@ -73,18 +75,34 @@ public:bool mouseDown, bool mousePressed, bool mouseReleased);/**- * @brief Editor pick: topmost UI entity whose layout box contains the point.+ * @brief Editor pick: the most specific UI entity whose layout box contains+ * the point (hierarchy depth desc, draw order breaking ties).** Unlike hitTestUpdate this ignores Interactable — plain text and panels* are selectable — and mutates no interaction state.*/- u32 pick(Registry& registry, f32 worldX, f32 worldY) const;+ u32 pick(Registry& registry, f32 worldX, f32 worldY);++ /**+ * @brief Editor pick list: ALL UI entities under the point, most specific+ * first. Returns the count; read entries via pickResult (the list+ * backs click-through cycling).+ */+ u32 pickAll(Registry& registry, f32 worldX, f32 worldY);++ /** @brief Entry `index` of the last pickAll (or INVALID_ENTITY). */+ u32 pickResult(u32 index) const {+ return index < pickResults_.size() ? pickResults_[index].id() : INVALID_ENTITY.id();+ }/** @brief Entity hit by the most recent hitTestUpdate (or INVALID_ENTITY) */u32 getHitEntity() const { return hitResult.hit_entity.id(); }/** @brief Entity hit by the previous frame's hitTestUpdate */u32 getPrevHitEntity() const { return hitResult.prev_hit_entity.id(); }++private:+ std::vector<Entity> pickResults_;};} // namespace esengine::ecs