feat(demo): add Bootstrap Demo Hub, Chinese UI font, and UI Demo showcase scene
This commit is contained in:
1 parent
3572f2da43
commit
4c83c086f4
49 files changed
+7864
-131
No files matched your search
@@ -9,6 +9,17 @@ import { UEStorageBackend } from "../../framework/storage/storage_backend";
|
||||
import type { UIDelegateBridge } from "../../framework/ui/ui_delegate_bridge";
|
||||
import { MiniSettingsWindow } from "../../game/setting/mini_settings_window";
|
||||
import { SettingService } from "../../game/setting/setting_service";
|
||||
import { DemoHubWindow } from "../../game/demo/demo_hub_window";
|
||||
import { OpenDemoHub, OpenUIDemoMain } from "../../game/demo/demo_router";
|
||||
import {
|
||||
UIDemoCachedWindow,
|
||||
UIDemoFullscreenWindow,
|
||||
UIDemoModalWindow,
|
||||
UIDemoMultiWindow,
|
||||
UIDemoNormalWindow,
|
||||
UIDemoSystemWindow,
|
||||
UIDemoToastWindow,
|
||||
} from "../../game/demo/ui_demo/ui_demo_windows";
|
||||
import { GetPrimaryUIManager } from "../../game/startup";
|
||||
import { ScopedObject } from "../../share/base/scoped_object";
|
||||
import { Assert, AssertEqual, FormatReport, RunSuites, type TestSuite, type TestSummary } from "../harness/test_runner";
|
||||
@@ -290,6 +301,184 @@ export function RunAllUETests(
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "UE.DemoHubAndUIDemo",
|
||||
cases: [
|
||||
{
|
||||
name: "Bootstrap DemoHubWindow loads Chinese UMG cards and cleans up with zero leaks",
|
||||
fn: () => {
|
||||
Assert(gameInstance !== undefined && world !== undefined, "GI & World required");
|
||||
const ctx = GetGameInstanceContext(gameInstance!)!;
|
||||
const uiMgr = GetPrimaryUIManager(ctx)!;
|
||||
const resSvc = ctx.GetService<ResourceService>("resource")!;
|
||||
const uiBridge = ctx.GetService<UIDelegateBridge>("uiDelegateBridge")!;
|
||||
|
||||
ctx.OnWorldCleanup(world);
|
||||
|
||||
let hubOpened = false;
|
||||
const hub = OpenDemoHub(ctx, (ok) => {
|
||||
hubOpened = ok;
|
||||
});
|
||||
Assert(hub !== undefined, "DemoHubWindow controller created");
|
||||
|
||||
PumpUEFrames(25, 0.02);
|
||||
|
||||
Assert(hubOpened && hub!.IsLoaded(), "DemoHubWindow loaded");
|
||||
Assert(hub!.itemWidgets.length >= 1, "DemoHub dynamically populated demo cards");
|
||||
Assert(hub!.itemEnterButtons["ui_demo"] !== undefined, "UI Demo entry button created");
|
||||
|
||||
hub!.Close();
|
||||
Assert(hub!.IsDisposed(), "DemoHubWindow disposed cleanly");
|
||||
AssertEqual(uiMgr.GetDiagnostics().openWindows, 0, "openWindows back to 0");
|
||||
AssertEqual(uiBridge.GetActiveBindingCount(), 0, "delegate bindings back to 0");
|
||||
AssertEqual(resSvc.GetDiagnostics().nativeTotalRefCount, 0, "resource refs back to 0");
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "UIDemoMainWindow exercises all UMG widgets and all 7 window types with zero leaks",
|
||||
fn: () => {
|
||||
Assert(gameInstance !== undefined && world !== undefined, "GI & World required");
|
||||
const ctx = GetGameInstanceContext(gameInstance!)!;
|
||||
const uiMgr = GetPrimaryUIManager(ctx)!;
|
||||
const resSvc = ctx.GetService<ResourceService>("resource")!;
|
||||
const uiBridge = ctx.GetService<UIDelegateBridge>("uiDelegateBridge")!;
|
||||
|
||||
ctx.OnWorldCleanup(world);
|
||||
|
||||
let mainOpened = false;
|
||||
const mainWin = OpenUIDemoMain(ctx, (ok) => {
|
||||
mainOpened = ok;
|
||||
})!;
|
||||
Assert(mainWin !== undefined, "UIDemoMainWindow created");
|
||||
|
||||
PumpUEFrames(30, 0.02);
|
||||
Assert(mainOpened && mainWin.IsLoaded(), "UIDemoMainWindow loaded");
|
||||
|
||||
// 1. Test UMG widget delegates via real UE C++ Simulate* helpers
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateButtonClick(mainWin.btnDemoAction), "Button click");
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateButtonHover(mainWin.btnDemoAction, true), "Button hover");
|
||||
AssertEqual(mainWin.actionClickCount, 1);
|
||||
AssertEqual(mainWin.actionHovered, true);
|
||||
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateCheckBoxToggle(mainWin.chkFeature, true), "CheckBox toggle");
|
||||
AssertEqual(mainWin.checkboxChecked, true);
|
||||
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateSliderValue(mainWin.sliderDemo, 0.75), "Slider value");
|
||||
Assert(math.abs(mainWin.sliderValue - 0.75) < 0.001, "sliderValue updated");
|
||||
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateSpinBoxValue(mainWin.spinDemo, 250), "SpinBox value");
|
||||
AssertEqual(mainWin.spinValue, 250);
|
||||
|
||||
Assert(
|
||||
UE.ULuaUIEventSubsystem.SimulateEditableTextChange(mainWin.inputNickname, "星河骑士"),
|
||||
"EditableText change"
|
||||
);
|
||||
AssertEqual(mainWin.draftNickname, "星河骑士");
|
||||
|
||||
Assert(
|
||||
UE.ULuaUIEventSubsystem.SimulateEditableTextCommit(mainWin.inputNickname, "星河骑士", 1),
|
||||
"EditableText commit"
|
||||
);
|
||||
AssertEqual(mainWin.currentNickname, "星河骑士");
|
||||
|
||||
Assert(
|
||||
UE.ULuaUIEventSubsystem.SimulateComboBoxSelect(mainWin.comboTheme, "翡翠绿(稀有)"),
|
||||
"ComboBox select"
|
||||
);
|
||||
AssertEqual(mainWin.selectedTheme, "翡翠绿(稀有)");
|
||||
|
||||
// 2. Test dynamic ScrollBox list items & delegate cleanup
|
||||
const bindingsBeforeList = uiBridge.GetActiveBindingCount();
|
||||
mainWin.AddDynamicListItems(3);
|
||||
AssertEqual(mainWin.dynamicItemCount, 3, "3 dynamic items added");
|
||||
Assert(uiBridge.GetActiveBindingCount() > bindingsBeforeList, "list item button delegates bound");
|
||||
mainWin.ClearDynamicListItems();
|
||||
AssertEqual(mainWin.dynamicItemCount, 0, "dynamic items cleared");
|
||||
AssertEqual(uiBridge.GetActiveBindingCount(), bindingsBeforeList, "list item delegates fully unbound");
|
||||
|
||||
// 3. Test all 7 window types
|
||||
// 3a. Normal singleton
|
||||
const norm1 = mainWin.OpenNormalDemoWindow()!;
|
||||
const norm2 = mainWin.OpenNormalDemoWindow()!;
|
||||
AssertEqual(norm1, norm2, "Normal window is singleton");
|
||||
|
||||
// 3b. Fullscreen hides MainWindow and restores it upon close
|
||||
const fullWin = mainWin.OpenFullscreenDemoWindow()!;
|
||||
|
||||
// 3c. Modal popup with confirm callback
|
||||
let modalConfirmed = false;
|
||||
const modalWin = uiMgr.ShowUI(UIDemoModalWindow, {
|
||||
title: "测试弹窗",
|
||||
message: "测试模态确认",
|
||||
onConfirm: () => {
|
||||
modalConfirmed = true;
|
||||
},
|
||||
})!;
|
||||
|
||||
// 3d. Cached window
|
||||
const cachedWin = mainWin.OpenCachedDemoWindow()!;
|
||||
|
||||
// 3e. Multi-instance (2 distinct controllers)
|
||||
const multi1 = mainWin.OpenMultiDemoWindow()!;
|
||||
const multi2 = mainWin.OpenMultiDemoWindow()!;
|
||||
Assert(multi1 !== multi2, "Multi-instance creates distinct windows");
|
||||
|
||||
// 3f. System top layer
|
||||
const sysWin = mainWin.OpenSystemDemoWindow()!;
|
||||
|
||||
// 3g. Toast (tips layer, non-blocking, short duration)
|
||||
const toastWin = mainWin.ShowToast("自动测试飘字", 0.1)!;
|
||||
|
||||
PumpUEFrames(30, 0.02);
|
||||
|
||||
// After 0.6s of pumped frames, toast (0.1s) should have auto-closed!
|
||||
Assert(toastWin.IsDisposed(), "Toast auto-closed via WorldTimer");
|
||||
Assert(!mainWin.IsVisible(), "MainWindow hidden while Fullscreen is open");
|
||||
AssertEqual(uiMgr.GetDiagnostics().topWindowName, "UIDemoSystemWindow", "System window on top");
|
||||
AssertEqual(uiMgr.GetDiagnostics().inputMode, "ui", "Input mode stays UI");
|
||||
|
||||
// Confirm modal
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateButtonClick(modalWin.btnModalConfirm), "Click Modal Confirm");
|
||||
Assert(modalConfirmed, "Modal confirm callback fired");
|
||||
Assert(modalWin.IsDisposed(), "Modal disposed after confirm");
|
||||
|
||||
// Cached window: click -> close to cache -> reopen -> click strictly once
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateButtonClick(cachedWin.btnCachedAction), "Cached click #1");
|
||||
AssertEqual(cachedWin.clickCount, 1);
|
||||
cachedWin.Close();
|
||||
Assert(cachedWin.IsCached(), "Cached window moved to cache");
|
||||
const cachedReused = mainWin.OpenCachedDemoWindow()!;
|
||||
AssertEqual(cachedReused, cachedWin, "Cached window reused");
|
||||
AssertEqual(cachedReused.reuseCount, 1, "OnReuseUI invoked once");
|
||||
Assert(UE.ULuaUIEventSubsystem.SimulateButtonClick(cachedReused.btnCachedAction), "Cached click #2");
|
||||
AssertEqual(cachedReused.clickCount, 2, "Cached click after reuse increments by exactly 1");
|
||||
|
||||
// Close fullscreen -> MainWindow automatically restored!
|
||||
fullWin.Close();
|
||||
Assert(mainWin.IsVisible(), "MainWindow automatically restored after Fullscreen closed");
|
||||
|
||||
// Clean teardown everything -> 0 leaks across UI, Delegates, Resources
|
||||
uiMgr.CloseAll(true);
|
||||
AssertEqual(uiMgr.GetDiagnostics().openWindows, 0, "openWindows back to 0");
|
||||
AssertEqual(uiMgr.GetDiagnostics().cachedWindows, 0, "cachedWindows back to 0");
|
||||
AssertEqual(uiBridge.GetActiveBindingCount(), 0, "delegate bindings back to 0");
|
||||
AssertEqual(resSvc.GetDiagnostics().nativeTotalRefCount, 0, "resource refcount back to 0");
|
||||
|
||||
// Verify unused symbol check stays clean
|
||||
Assert(
|
||||
DemoHubWindow !== undefined &&
|
||||
UIDemoNormalWindow !== undefined &&
|
||||
UIDemoFullscreenWindow !== undefined &&
|
||||
UIDemoCachedWindow !== undefined &&
|
||||
UIDemoMultiWindow !== undefined &&
|
||||
UIDemoToastWindow !== undefined &&
|
||||
UIDemoSystemWindow !== undefined,
|
||||
"all demo window classes registered"
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const summary = RunSuites(suites);
|
||||
|
||||
Reference in new issue
Block a user