feat(demo): add Bootstrap Demo Hub, Chinese UI font, and UI Demo showcase scene

This commit is contained in:
szy73711 committed 2026-12-01 03:13:35 +08:00
1 parent 3572f2da43
commit 4c83c086f4
49 files changed
+7864 -131

No files matched your search

@@ -3,11 +3,48 @@
export const ASSET_KEYS = {
MINI_SETTINGS_ICON: "tex.mini_settings_icon",
MINI_SETTINGS_WIDGET: "ui.mini_settings",
// Demo textures
DEMO_AVATAR_TEX: "tex.demo_avatar",
DEMO_BADGE_A_TEX: "tex.demo_badge_a",
DEMO_BADGE_B_TEX: "tex.demo_badge_b",
// Bootstrap Demo Hub widgets
DEMO_HUB_WIDGET: "ui.demo_hub",
DEMO_HUB_ITEM_WIDGET: "ui.demo_hub_item",
// UI Demo widgets
UI_DEMO_MAIN_WIDGET: "ui.demo_ui_main",
UI_DEMO_LIST_ITEM_WIDGET: "ui.demo_ui_list_item",
UI_DEMO_NORMAL_WIDGET: "ui.demo_ui_normal",
UI_DEMO_FULLSCREEN_WIDGET: "ui.demo_ui_fullscreen",
UI_DEMO_MODAL_WIDGET: "ui.demo_ui_modal",
UI_DEMO_CACHED_WIDGET: "ui.demo_ui_cached",
UI_DEMO_MULTI_WIDGET: "ui.demo_ui_multi",
UI_DEMO_TOAST_WIDGET: "ui.demo_ui_toast",
UI_DEMO_SYSTEM_WIDGET: "ui.demo_ui_system",
} as const;
export const BASE_ASSET_PATHS: Record<string, string> = {
[ASSET_KEYS.MINI_SETTINGS_ICON]: "/Game/UI/Textures/T_MiniSettingsIcon.T_MiniSettingsIcon",
[ASSET_KEYS.MINI_SETTINGS_WIDGET]: "/Game/UI/WBP_MiniSettings.WBP_MiniSettings_C",
[ASSET_KEYS.DEMO_AVATAR_TEX]: "/Game/UI/Textures/T_DemoAvatar.T_DemoAvatar",
[ASSET_KEYS.DEMO_BADGE_A_TEX]: "/Game/UI/Textures/T_DemoBadgeA.T_DemoBadgeA",
[ASSET_KEYS.DEMO_BADGE_B_TEX]: "/Game/UI/Textures/T_DemoBadgeB.T_DemoBadgeB",
[ASSET_KEYS.DEMO_HUB_WIDGET]: "/Game/UI/Demo/WBP_DemoHub.WBP_DemoHub_C",
[ASSET_KEYS.DEMO_HUB_ITEM_WIDGET]: "/Game/UI/Demo/WBP_DemoHubItem.WBP_DemoHubItem_C",
[ASSET_KEYS.UI_DEMO_MAIN_WIDGET]: "/Game/UI/Demo/WBP_UIDemoMain.WBP_UIDemoMain_C",
[ASSET_KEYS.UI_DEMO_LIST_ITEM_WIDGET]: "/Game/UI/Demo/WBP_UIDemoListItem.WBP_UIDemoListItem_C",
[ASSET_KEYS.UI_DEMO_NORMAL_WIDGET]: "/Game/UI/Demo/WBP_UIDemoNormal.WBP_UIDemoNormal_C",
[ASSET_KEYS.UI_DEMO_FULLSCREEN_WIDGET]: "/Game/UI/Demo/WBP_UIDemoFullscreen.WBP_UIDemoFullscreen_C",
[ASSET_KEYS.UI_DEMO_MODAL_WIDGET]: "/Game/UI/Demo/WBP_UIDemoModal.WBP_UIDemoModal_C",
[ASSET_KEYS.UI_DEMO_CACHED_WIDGET]: "/Game/UI/Demo/WBP_UIDemoCached.WBP_UIDemoCached_C",
[ASSET_KEYS.UI_DEMO_MULTI_WIDGET]: "/Game/UI/Demo/WBP_UIDemoMulti.WBP_UIDemoMulti_C",
[ASSET_KEYS.UI_DEMO_TOAST_WIDGET]: "/Game/UI/Demo/WBP_UIDemoToast.WBP_UIDemoToast_C",
[ASSET_KEYS.UI_DEMO_SYSTEM_WIDGET]: "/Game/UI/Demo/WBP_UIDemoSystem.WBP_UIDemoSystem_C",
};
export function RegisterBaseAssetCatalog(subsystem: UE.ULuaResourceSubsystem): void {
+267 -22
View File
@@ -10,6 +10,16 @@ export interface IButtonDelegateBackend {
BindButtonClicked(button: any): number;
UnbindButtonClicked(bindingId: number): boolean;
GetActiveBindingCount(): number;
BindButtonHovered?(button: any): number;
BindButtonUnhovered?(button: any): number;
BindCheckBoxChanged?(checkBox: any): number;
BindSliderChanged?(slider: any): number;
BindSpinBoxChanged?(spinBox: any): number;
BindEditableTextChanged?(textBox: any): number;
BindEditableTextCommitted?(textBox: any): number;
BindComboBoxSelectionChanged?(comboBox: any): number;
UnbindWidgetEvent?(bindingId: number): boolean;
}
export class UEButtonDelegateBackend implements IButtonDelegateBackend {
@@ -23,8 +33,44 @@ export class UEButtonDelegateBackend implements IButtonDelegateBackend {
return this.subsystem.BindButtonClicked(button);
}
BindButtonHovered(button: UE.UButton): number {
return this.subsystem.BindButtonHovered(button);
}
BindButtonUnhovered(button: UE.UButton): number {
return this.subsystem.BindButtonUnhovered(button);
}
BindCheckBoxChanged(checkBox: UE.UCheckBox): number {
return this.subsystem.BindCheckBoxChanged(checkBox);
}
BindSliderChanged(slider: UE.USlider): number {
return this.subsystem.BindSliderChanged(slider);
}
BindSpinBoxChanged(spinBox: UE.USpinBox): number {
return this.subsystem.BindSpinBoxChanged(spinBox);
}
BindEditableTextChanged(textBox: UE.UEditableTextBox): number {
return this.subsystem.BindEditableTextChanged(textBox);
}
BindEditableTextCommitted(textBox: UE.UEditableTextBox): number {
return this.subsystem.BindEditableTextCommitted(textBox);
}
BindComboBoxSelectionChanged(comboBox: UE.UComboBoxString): number {
return this.subsystem.BindComboBoxSelectionChanged(comboBox);
}
UnbindButtonClicked(bindingId: number): boolean {
return this.subsystem.UnbindButtonClicked(bindingId);
return this.subsystem.UnbindWidgetEvent(bindingId);
}
UnbindWidgetEvent(bindingId: number): boolean {
return this.subsystem.UnbindWidgetEvent(bindingId);
}
GetActiveBindingCount(): number {
@@ -32,13 +78,20 @@ export class UEButtonDelegateBackend implements IButtonDelegateBackend {
}
}
interface ButtonBindingRecord {
type WidgetCallback =
| ((this: void) => void)
| ((this: void, value: boolean) => void)
| ((this: void, value: number) => void)
| ((this: void, text: string) => void)
| ((this: void, text: string, extra: number) => void);
interface WidgetBindingRecord {
bindingId: number;
callback: (this: void) => void;
callback: WidgetCallback;
owner?: IsDisposedChecker;
}
class ButtonBindingHandle implements IDisposable {
class WidgetBindingHandle implements IDisposable {
private bridge: UIDelegateBridge | undefined;
private readonly bindingId: number;
@@ -61,13 +114,14 @@ const bridgeByGameInstanceKey: Record<string, UIDelegateBridge | undefined> = {}
/**
* 纯 TS 侧 UMG 委托桥接器(按 GameInstance 隔离):
* 配合 C++ ULuaUIEventSubsystem 实现纯 TS 控制器绑定 UButton.OnClicked,
* 配合 C++ ULuaUIEventSubsystem 实现纯 TS 控制器绑定常见 UMG 控件委托
* (Button / CheckBox / Slider / SpinBox / EditableTextBox / ComboBoxString),
* 无需 @unlua 继承 UUserWidget,100% 纳入单文件热更与 ScopedObject 自动解绑。
*/
export class UIDelegateBridge extends ScopedObject {
private readonly backend: IButtonDelegateBackend;
private readonly giKey?: string;
private bindings: Record<number, ButtonBindingRecord | undefined> = {};
private bindings: Record<number, WidgetBindingRecord | undefined> = {};
constructor(ctx: GameInstanceContext, backend: IButtonDelegateBackend) {
super();
@@ -78,44 +132,180 @@ export class UIDelegateBridge extends ScopedObject {
}
}
BindButtonClick(button: any, callback: (this: void) => void, owner?: IsDisposedChecker): IDisposable {
const bindingId = this.backend.BindButtonClicked(button);
assert(bindingId > 0, "UIDelegateBridge.BindButtonClick: failed to bind button");
private RegisterBinding(bindingId: number, callback: WidgetCallback, owner?: IsDisposedChecker): IDisposable {
assert(bindingId > 0, "UIDelegateBridge: failed to bind UMG widget event");
this.bindings[bindingId] = {
bindingId,
callback,
owner,
};
const handle = new ButtonBindingHandle(this, bindingId);
const handle = new WidgetBindingHandle(this, bindingId);
if (owner !== undefined && owner instanceof ScopedObject) {
owner.AddScopedObject(handle);
}
return handle;
}
BindButtonClick(button: any, callback: (this: void) => void, owner?: IsDisposedChecker): IDisposable {
const bindingId = this.backend.BindButtonClicked(button);
return this.RegisterBinding(bindingId, callback, owner);
}
BindButtonHovered(button: any, callback: (this: void) => void, owner?: IsDisposedChecker): IDisposable {
assert(this.backend.BindButtonHovered !== undefined, "UIDelegateBridge backend does not support BindButtonHovered");
const bindingId = this.backend.BindButtonHovered!(button);
return this.RegisterBinding(bindingId, callback, owner);
}
BindButtonUnhovered(button: any, callback: (this: void) => void, owner?: IsDisposedChecker): IDisposable {
assert(this.backend.BindButtonUnhovered !== undefined, "UIDelegateBridge backend does not support BindButtonUnhovered");
const bindingId = this.backend.BindButtonUnhovered!(button);
return this.RegisterBinding(bindingId, callback, owner);
}
BindCheckBoxChanged(
checkBox: any,
callback: (this: void, isChecked: boolean) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(this.backend.BindCheckBoxChanged !== undefined, "UIDelegateBridge backend does not support BindCheckBoxChanged");
const bindingId = this.backend.BindCheckBoxChanged!(checkBox);
return this.RegisterBinding(bindingId, callback, owner);
}
BindSliderChanged(
slider: any,
callback: (this: void, value: number) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(this.backend.BindSliderChanged !== undefined, "UIDelegateBridge backend does not support BindSliderChanged");
const bindingId = this.backend.BindSliderChanged!(slider);
return this.RegisterBinding(bindingId, callback, owner);
}
BindSpinBoxChanged(
spinBox: any,
callback: (this: void, value: number) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(this.backend.BindSpinBoxChanged !== undefined, "UIDelegateBridge backend does not support BindSpinBoxChanged");
const bindingId = this.backend.BindSpinBoxChanged!(spinBox);
return this.RegisterBinding(bindingId, callback, owner);
}
BindEditableTextChanged(
textBox: any,
callback: (this: void, text: string) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(
this.backend.BindEditableTextChanged !== undefined,
"UIDelegateBridge backend does not support BindEditableTextChanged"
);
const bindingId = this.backend.BindEditableTextChanged!(textBox);
return this.RegisterBinding(bindingId, callback, owner);
}
BindEditableTextCommitted(
textBox: any,
callback: (this: void, text: string, commitMethod: number) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(
this.backend.BindEditableTextCommitted !== undefined,
"UIDelegateBridge backend does not support BindEditableTextCommitted"
);
const bindingId = this.backend.BindEditableTextCommitted!(textBox);
return this.RegisterBinding(bindingId, callback, owner);
}
BindComboBoxSelectionChanged(
comboBox: any,
callback: (this: void, selectedItem: string, selectType: number) => void,
owner?: IsDisposedChecker
): IDisposable {
assert(
this.backend.BindComboBoxSelectionChanged !== undefined,
"UIDelegateBridge backend does not support BindComboBoxSelectionChanged"
);
const bindingId = this.backend.BindComboBoxSelectionChanged!(comboBox);
return this.RegisterBinding(bindingId, callback, owner);
}
UnbindById(bindingId: number): void {
if (this.bindings[bindingId] === undefined) {
return;
}
this.bindings[bindingId] = undefined;
this.backend.UnbindButtonClicked(bindingId);
if (this.backend.UnbindWidgetEvent !== undefined) {
this.backend.UnbindWidgetEvent(bindingId);
} else {
this.backend.UnbindButtonClicked(bindingId);
}
}
DispatchButtonClicked(bindingId: number): void {
private ResolveLiveRecord(bindingId: number): WidgetBindingRecord | undefined {
if (this.IsDisposed()) {
return;
return undefined;
}
const rec = this.bindings[bindingId];
if (rec === undefined) {
return;
return undefined;
}
if (rec.owner !== undefined && rec.owner.IsDisposed()) {
this.UnbindById(bindingId);
return;
return undefined;
}
return rec;
}
DispatchButtonClicked(bindingId: number): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void) => void);
}
}
DispatchActionEvent(bindingId: number): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void) => void);
}
}
DispatchBoolChanged(bindingId: number, value: boolean): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void, v: boolean) => void, value);
}
}
DispatchFloatChanged(bindingId: number, value: number): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void, v: number) => void, value);
}
}
DispatchTextChanged(bindingId: number, text: string): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void, t: string) => void, text);
}
}
DispatchTextCommitted(bindingId: number, text: string, commitMethod: number): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void, t: string, m: number) => void, text, commitMethod);
}
}
DispatchSelectionChanged(bindingId: number, selectedItem: string, selectType: number): void {
const rec = this.ResolveLiveRecord(bindingId);
if (rec !== undefined) {
tbpcall(rec.callback as (this: void, s: string, t: number) => void, selectedItem, selectType);
}
tbpcall(rec.callback);
}
GetActiveBindingCount(): number {
@@ -140,10 +330,7 @@ export class UIDelegateBridge extends ScopedObject {
}
}
/**
* 供 C++ FLuaCallbackBridge::CallInt 回调的纯函数入口。
* @noSelf
*/
/** @noSelf */
export function OnNativeButtonClicked(gameInstance: UE.ULuaGameInstance, bindingId: number): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
@@ -151,6 +338,64 @@ export function OnNativeButtonClicked(gameInstance: UE.ULuaGameInstance, binding
}
}
/** @noSelf */
export function OnNativeActionEvent(gameInstance: UE.ULuaGameInstance, bindingId: number): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchActionEvent(bindingId);
}
}
/** @noSelf */
export function OnNativeBoolChanged(gameInstance: UE.ULuaGameInstance, bindingId: number, value: boolean): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchBoolChanged(bindingId, value);
}
}
/** @noSelf */
export function OnNativeFloatChanged(gameInstance: UE.ULuaGameInstance, bindingId: number, value: number): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchFloatChanged(bindingId, value);
}
}
/** @noSelf */
export function OnNativeTextChanged(gameInstance: UE.ULuaGameInstance, bindingId: number, text: string): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchTextChanged(bindingId, text);
}
}
/** @noSelf */
export function OnNativeTextCommitted(
gameInstance: UE.ULuaGameInstance,
bindingId: number,
text: string,
commitMethod: number
): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchTextCommitted(bindingId, text, commitMethod);
}
}
/** @noSelf */
export function OnNativeSelectionChanged(
gameInstance: UE.ULuaGameInstance,
bindingId: number,
selectedItem: string,
selectType: number
): void {
const bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)];
if (bridge !== undefined) {
bridge.DispatchSelectionChanged(bindingId, selectedItem, selectType);
}
}
/** @noSelf */
export function CreateUEUIDelegateBridge(ctx: GameInstanceContext): UIDelegateBridge | undefined {
if (ctx.gameInstance === undefined) {
+162 -11
View File
@@ -5,7 +5,7 @@ import { EventHub } from "../../share/event/event_hub";
import { tbpcall } from "../../share/base/traceback";
import type { GameInstanceContext, LocalPlayerContext } from "../context/game_context";
import type { ResourceService } from "../resource/resource_service";
import { GetUIConfig, UI_LAYER_ZORDER, type UIConfigItem } from "./ui_config";
import { GetUIConfig, UI_LAYER_ZORDER, type UICacheTag, type UIConfigItem, type UILayer, type UIType } from "./ui_config";
import type { IWidgetAdapter, UIWindow } from "./ui_window";
const logger = Logger("UIManager");
@@ -28,6 +28,19 @@ export interface UIDiagnostics {
inputMode: "game" | "ui";
}
export interface WindowStackEntry {
name: string;
layer: UILayer;
type: UIType;
zOrder: number;
visible: boolean;
loading: boolean;
singleton: boolean;
cacheTag: UICacheTag;
blockWorldClick: boolean;
hiddenByFullscreen: boolean;
}
export class UEWidgetAdapter implements IWidgetAdapter {
FindChild(widget: UE.UUserWidget, name: string): UE.UWidget | undefined {
return UE.ULuaUIEventSubsystem.FindChildWidgetByName(widget, name);
@@ -78,7 +91,7 @@ export class UEWidgetFactory implements IWidgetFactory {
/**
* 玩家级窗口管理器(归属 LocalPlayerContext,支持多 PIE 实例隔离):
* - 单例去重与并发打开防重复创建;
* - 窗口栈 ZOrder 层级管理、缓存复用与焦点/输入模式恢复;
* - 窗口栈 ZOrder 层级管理、全屏互斥隐藏/恢复、缓存复用与焦点/输入模式恢复;
* - 切图/退出时安全取消在途加载并释放所有窗口与缓存。
*/
export class UIManager extends ScopedObject {
@@ -143,6 +156,7 @@ export class UIManager extends ScopedObject {
if (existing.IsLoaded()) {
const zOrder = this.AllocateZOrder(config);
existing.ShowInternal(zOrder, args);
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
if (onOpened !== undefined) {
tbpcall(onOpened, true, existing as T, undefined);
@@ -169,6 +183,7 @@ export class UIManager extends ScopedObject {
this.windowStack[this.windowStack.length] = cached;
const zOrder = this.AllocateZOrder(config);
cached.ReuseInternal(zOrder, args);
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
this.events.emit.OnWindowOpened(config.name, cached);
if (onOpened !== undefined) {
@@ -228,6 +243,7 @@ export class UIManager extends ScopedObject {
win.AttachWidgetInternal(widget);
const zOrder = this.AllocateZOrder(config);
win.ShowInternal(zOrder, args);
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
this.events.emit.OnWindowOpened(config.name, win);
if (onOpened !== undefined) {
@@ -255,14 +271,48 @@ export class UIManager extends ScopedObject {
}
}
/**
* 按实际 ZOrder 优先返回当前顶层活动窗口(而非纯打开顺序),
* 确保高 Layer(如 system / popup)始终正确识别为顶层窗口。
*/
GetTopWindow(): UIWindow | undefined {
for (let i = this.windowStack.length - 1; i >= 0; i--) {
let best: UIWindow | undefined = undefined;
let bestZOrder = -1;
for (let i = 0; i < this.windowStack.length; i++) {
const win = this.windowStack[i];
if (!win.IsDisposed() && !win.IsClosing()) {
return win;
if (win.IsDisposed() || win.IsClosing()) {
continue;
}
const z = win.IsLoaded() ? win.GetZOrder() : UI_LAYER_ZORDER[win.config.layer];
if (best === undefined || z >= bestZOrder) {
best = win;
bestZOrder = z;
}
}
return undefined;
return best;
}
/**
* 返回当前最高 ZOrder 的可见且需要 UI 输入焦点的窗口(跳过 tips 等非阻塞窗口)。
*/
GetTopBlockingWindow(): UIWindow | undefined {
let best: UIWindow | undefined = undefined;
let bestZOrder = -1;
for (let i = 0; i < this.windowStack.length; i++) {
const win = this.windowStack[i];
if (win.IsDisposed() || win.IsClosing() || !win.config.blockWorldClick) {
continue;
}
if (win.IsLoaded() && !win.IsVisible()) {
continue;
}
const z = win.IsLoaded() ? win.GetZOrder() : UI_LAYER_ZORDER[win.config.layer];
if (best === undefined || z >= bestZOrder) {
best = win;
bestZOrder = z;
}
}
return best;
}
HandleWindowCachedInternal(win: UIWindow): void {
@@ -272,17 +322,19 @@ export class UIManager extends ScopedObject {
oldCached.ForceDisposeFromCacheInternal();
}
this.cachedByName[win.config.name] = win;
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
this.events.emit.OnWindowClosed(win.config.name, win);
}
HandleWindowClosedInternal(win: UIWindow): void {
this.RemoveFromStackAndSingleton(win);
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
this.events.emit.OnWindowClosed(win.config.name, win);
}
EvictCache(): void {
EvictCache(): number {
const toEvict: UIWindow[] = [];
for (const [name, win] of pairs(this.cachedByName)) {
if (win !== undefined) {
@@ -293,6 +345,25 @@ export class UIManager extends ScopedObject {
for (let i = 0; i < toEvict.length; i++) {
toEvict[i].ForceDisposeFromCacheInternal();
}
return toEvict.length;
}
CloseAllExcept(keepWindow: UIWindow, alsoEvictCache = false): number {
const copy: UIWindow[] = [];
for (let i = this.windowStack.length - 1; i >= 0; i--) {
if (this.windowStack[i] !== keepWindow) {
copy[copy.length] = this.windowStack[i];
}
}
for (let i = 0; i < copy.length; i++) {
copy[i].Close();
}
if (alsoEvictCache) {
this.EvictCache();
}
this.SyncFullscreenVisibility();
this.SyncFocusAndInputMode();
return copy.length;
}
CloseAll(alsoEvictCache = true): void {
@@ -309,6 +380,39 @@ export class UIManager extends ScopedObject {
this.SyncFocusAndInputMode();
}
GetWindowStackSnapshot(): WindowStackEntry[] {
const list: WindowStackEntry[] = [];
for (let i = 0; i < this.windowStack.length; i++) {
const w = this.windowStack[i];
if (!w.IsDisposed()) {
list[list.length] = {
name: w.config.name,
layer: w.config.layer,
type: w.config.type,
zOrder: w.GetZOrder(),
visible: w.IsVisible(),
loading: w.IsLoading(),
singleton: w.config.singleton,
cacheTag: w.config.cacheTag,
blockWorldClick: w.config.blockWorldClick,
hiddenByFullscreen: w.IsHiddenByFullscreen(),
};
}
}
return list;
}
GetCachedWindowNames(): string[] {
const names: string[] = [];
for (const [name, w] of pairs(this.cachedByName)) {
if (w !== undefined && !w.IsDisposed()) {
names[names.length] = name;
}
}
table.sort(names);
return names;
}
GetDiagnostics(): UIDiagnostics {
let openWindows = 0;
let loadingWindows = 0;
@@ -355,9 +459,56 @@ export class UIManager extends ScopedObject {
}
}
/**
* 全屏窗口互斥管理:
* 打开 type="fullscreen" 窗口时,自动隐藏其下方的 background/normal 窗口;
* 全屏窗口关闭后,自动恢复原先被隐藏的下层窗口显示。
*/
private SyncFullscreenVisibility(): void {
let topFullscreen: UIWindow | undefined = undefined;
let topFullscreenZ = -1;
for (let i = 0; i < this.windowStack.length; i++) {
const win = this.windowStack[i];
if (
!win.IsDisposed() &&
!win.IsClosing() &&
win.IsLoaded() &&
win.config.type === "fullscreen"
) {
const z = win.GetZOrder();
if (topFullscreen === undefined || z >= topFullscreenZ) {
topFullscreen = win;
topFullscreenZ = z;
}
}
}
for (let i = 0; i < this.windowStack.length; i++) {
const win = this.windowStack[i];
if (win.IsDisposed() || win.IsClosing() || !win.IsLoaded()) {
continue;
}
const affectedLayer = win.config.layer === "background" || win.config.layer === "normal";
if (!affectedLayer) {
continue;
}
if (topFullscreen !== undefined && win !== topFullscreen && win.GetZOrder() < topFullscreenZ) {
if (win.IsVisible()) {
win.SetHiddenByFullscreenInternal(true);
win.Hide();
}
} else if (win.IsHiddenByFullscreen()) {
win.RestoreFromFullscreenInternal();
}
}
}
private SyncFocusAndInputMode(): void {
const top = this.GetTopWindow();
const nextMode: "game" | "ui" = top !== undefined && top.config.blockWorldClick ? "ui" : "game";
const topBlocking = this.GetTopBlockingWindow();
const topAny = this.GetTopWindow();
const nextMode: "game" | "ui" = topBlocking !== undefined ? "ui" : "game";
this.inputMode = nextMode;
const pc = this.playerCtx.playerController;
@@ -366,7 +517,7 @@ export class UIManager extends ScopedObject {
pc.bShowMouseCursor = true;
UE.UWidgetBlueprintLibrary.SetInputMode_UIOnlyEx(
pc,
top !== undefined ? (top.GetWidget() as UE.UWidget | undefined) : undefined,
topBlocking !== undefined ? (topBlocking.GetWidget() as UE.UWidget | undefined) : undefined,
UE.EMouseLockMode.DoNotLock,
false
);
@@ -376,7 +527,7 @@ export class UIManager extends ScopedObject {
}
}
this.events.emit.OnFocusRestored(top !== undefined ? top.config.name : undefined);
this.events.emit.OnFocusRestored(topAny !== undefined ? topAny.config.name : undefined);
}
override Dispose(): void {
+127 -19
View File
@@ -19,9 +19,9 @@ export interface IWidgetAdapter {
}
/**
* 纯 TS UMG 窗口控制器基类(拆分原 GameObjectWrapper 继承 -> 组合持有 UUserWidget 视图):
* - 100% 纳入 ts2lua-unreal v0.3.0 单文件热更闭环;
* - 统一托管资源加载句柄、按钮委托绑定、事件监听与防重入关闭状态机。
* 纯 TS UMG 窗口控制器基类(组合持有 UUserWidget 视图):
* - 100% 纳入 ts2lua-unreal 单文件热更闭环;
* - 统一托管资源加载句柄、全部 UMG 控件委托绑定、事件监听与防重入关闭状态机。
*/
export abstract class UIWindow extends ScopedObject {
public config!: UIConfigItem;
@@ -35,8 +35,10 @@ export abstract class UIWindow extends ScopedObject {
private isVisible = false;
private isClosing = false;
private isCached = false;
private hiddenByFullscreen = false;
private currentZOrder = 0;
private classLoadHandle?: ResourceLoadHandle<any>;
private buttonBindings: IDisposable[] = [];
private widgetBindings: IDisposable[] = [];
InitContextInternal(
ctx: GameInstanceContext,
@@ -54,6 +56,10 @@ export abstract class UIWindow extends ScopedObject {
return this.widget;
}
GetZOrder(): number {
return this.currentZOrder;
}
IsLoading(): boolean {
return this.isLoading;
}
@@ -74,6 +80,14 @@ export abstract class UIWindow extends ScopedObject {
return this.isCached;
}
IsHiddenByFullscreen(): boolean {
return this.hiddenByFullscreen;
}
SetHiddenByFullscreenInternal(hidden: boolean): void {
this.hiddenByFullscreen = hidden;
}
SetLoadingStateInternal(loading: boolean, handle?: ResourceLoadHandle<any>): void {
this.isLoading = loading;
this.classLoadHandle = handle;
@@ -100,31 +114,104 @@ export abstract class UIWindow extends ScopedObject {
return child as T;
}
/**
* 绑定 UButton 点击事件,缓存/关闭/销毁时统一成对解绑,防止复用重复上报。
*/
protected BindButtonClick(button: any, callback: (this: void) => void): IDisposable | undefined {
private TrackWidgetBinding(handle: IDisposable | undefined): IDisposable | undefined {
if (handle !== undefined) {
this.widgetBindings[this.widgetBindings.length] = handle;
}
return handle;
}
private GetDelegateBridge(): UIDelegateBridge | undefined {
const bridge = this.ctx.GetService<UIDelegateBridge>("uiDelegateBridge");
if (bridge === undefined) {
logger.Warn("UIDelegateBridge not registered on context", { window: this.config.name });
return undefined;
}
const handle = bridge.BindButtonClick(button, callback, this);
this.buttonBindings[this.buttonBindings.length] = handle;
return handle;
return bridge;
}
private UnbindAllButtons(): void {
for (let i = 0; i < this.buttonBindings.length; i++) {
this.buttonBindings[i].Dispose();
/**
* 绑定 UButton 点击事件,缓存/关闭/销毁时统一成对解绑,防止复用重复上报。
*/
protected BindButtonClick(button: any, callback: (this: void) => void): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindButtonClick(button, callback, this));
}
protected BindButtonHovered(button: any, callback: (this: void) => void): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindButtonHovered(button, callback, this));
}
protected BindButtonUnhovered(button: any, callback: (this: void) => void): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindButtonUnhovered(button, callback, this));
}
protected BindCheckBoxChanged(
checkBox: any,
callback: (this: void, isChecked: boolean) => void
): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindCheckBoxChanged(checkBox, callback, this));
}
protected BindSliderChanged(slider: any, callback: (this: void, value: number) => void): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindSliderChanged(slider, callback, this));
}
protected BindSpinBoxChanged(spinBox: any, callback: (this: void, value: number) => void): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindSpinBoxChanged(spinBox, callback, this));
}
protected BindEditableTextChanged(
textBox: any,
callback: (this: void, text: string) => void
): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindEditableTextChanged(textBox, callback, this));
}
protected BindEditableTextCommitted(
textBox: any,
callback: (this: void, text: string, commitMethod: number) => void
): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindEditableTextCommitted(textBox, callback, this));
}
protected BindComboBoxChanged(
comboBox: any,
callback: (this: void, selectedItem: string, selectType: number) => void
): IDisposable | undefined {
const bridge = this.GetDelegateBridge();
if (bridge === undefined) return undefined;
return this.TrackWidgetBinding(bridge.BindComboBoxSelectionChanged(comboBox, callback, this));
}
private UnbindAllWidgetEvents(): void {
for (let i = 0; i < this.widgetBindings.length; i++) {
this.widgetBindings[i].Dispose();
}
this.buttonBindings = [];
this.widgetBindings = [];
}
ShowInternal(zOrder: number, args?: unknown): void {
if (this.IsDisposed() || this.isClosing) {
return;
}
this.currentZOrder = zOrder;
this.hiddenByFullscreen = false;
tbpcall(() => {
this.OnPreShow(args);
});
@@ -144,6 +231,7 @@ export abstract class UIWindow extends ScopedObject {
}
this.isCached = false;
this.isClosing = false;
this.hiddenByFullscreen = false;
this.EnableAllEventListeners();
this.OnBindWidgets();
tbpcall(() => {
@@ -152,6 +240,23 @@ export abstract class UIWindow extends ScopedObject {
this.ShowInternal(zOrder, args);
}
RestoreFromFullscreenInternal(): void {
if (this.IsDisposed() || this.isClosing || this.isCached || !this.isLoaded) {
return;
}
this.hiddenByFullscreen = false;
if (this.isVisible) {
return;
}
if (this.widget !== undefined && this.widgetAdapter.IsWidgetValid(this.widget)) {
this.widgetAdapter.SetVisible(this.widget, true);
}
this.isVisible = true;
tbpcall(() => {
this.OnShow();
});
}
Hide(): void {
if (!this.isVisible) {
return;
@@ -169,7 +274,7 @@ export abstract class UIWindow extends ScopedObject {
* 幂等且防重入的窗口关闭入口:
* - 加载中关闭:取消在途类加载句柄,直接收尾;
* - 关闭中重复 Close:直接忽略;
* - 缓存策略窗口:解绑按钮委托、暂停事件监听、从视口摘除并交还缓存池;
* - 缓存策略窗口:解绑控件委托、暂停事件监听、从视口摘除并交还缓存池;
* - 非缓存窗口:执行 OnClose、解绑并 Dispose 全部托管资源。
*/
Close(onClosed?: (this: void) => void): void {
@@ -193,9 +298,10 @@ export abstract class UIWindow extends ScopedObject {
if (canCache) {
this.isVisible = false;
this.hiddenByFullscreen = false;
this.isCached = true;
this.isClosing = false;
this.UnbindAllButtons();
this.UnbindAllWidgetEvents();
this.DisableAllEventListeners();
this.widgetAdapter.RemoveFromParent(this.widget);
tbpcall(() => {
@@ -215,7 +321,8 @@ export abstract class UIWindow extends ScopedObject {
}
this.isVisible = false;
this.UnbindAllButtons();
this.hiddenByFullscreen = false;
this.UnbindAllWidgetEvents();
if (this.widget !== undefined && this.widgetAdapter.IsWidgetValid(this.widget)) {
this.widgetAdapter.RemoveFromParent(this.widget);
}
@@ -231,7 +338,8 @@ export abstract class UIWindow extends ScopedObject {
ForceDisposeFromCacheInternal(): void {
this.isCached = false;
this.UnbindAllButtons();
this.hiddenByFullscreen = false;
this.UnbindAllWidgetEvents();
if (this.widget !== undefined && this.widgetAdapter.IsWidgetValid(this.widget)) {
this.widgetAdapter.RemoveFromParent(this.widget);
}
+3 -3
View File
@@ -1,10 +1,10 @@
/** @noSelfInFile */
import { GetGameInstanceContext } from "../framework/context/game_context";
import { OpenMiniSettings } from "./startup";
import { RouteCurrentLevel } from "./demo/demo_router";
/**
* PIE / 启动地图玩家入口:绑定 LocalPlayer(0) 的 PlayerController 并打开首期最小设置窗口。
* PIE / 启动地图玩家入口:绑定 LocalPlayer(0) 的 PlayerController 并按当前关卡路由对应 Demo 场景。
*/
export function OnBeginPlay(pc: UE.ALuaPlayerController): void {
const world = pc.GetWorld();
@@ -20,7 +20,7 @@ export function OnBeginPlay(pc: UE.ALuaPlayerController): void {
ctx.OnWorldCleanup(world);
}
ctx.GetOrCreateLocalPlayer(0, pc);
OpenMiniSettings(ctx);
RouteCurrentLevel(ctx, pc);
}
export function OnEndPlay(pc: UE.ALuaPlayerController, _endPlayReason: number): void {
+183
View File
@@ -0,0 +1,183 @@
import type { IDisposable } from "../../share/base/interface";
import { Logger } from "../../share/base/logger";
import { ScopedObject } from "../../share/base/scoped_object";
import { ASSET_KEYS } from "../../framework/resource/asset_catalog";
import type { ResourceService } from "../../framework/resource/resource_service";
import { RegisterUIConfig } from "../../framework/ui/ui_config";
import type { UIDelegateBridge } from "../../framework/ui/ui_delegate_bridge";
import { UIWindow } from "../../framework/ui/ui_window";
import { OpenMiniSettings } from "../startup";
import { GetDemoScenes, type DemoSceneDescriptor } from "./demo_registry";
const logger = Logger("DemoHubWindow");
export interface DemoHubOpenArgs {
onSelectDemo?: (this: void, demo: DemoSceneDescriptor) => void;
}
/**
* Bootstrap 关卡的 Demo 场景切换面板(绑定 /Game/UI/Demo/WBP_DemoHub):
* - 动态读取 DemoRegistry 渲染场景入口卡片;
* - 支持一键切换至各个 Demo 关卡,并保留已有 MiniSettings 快捷验证入口。
*/
export class DemoHubWindow extends UIWindow {
public txtRuntimeInfo?: UE.UTextBlock;
public scrollDemoList?: UE.UScrollBox;
public btnOpenMiniSettings?: UE.UButton;
public itemWidgets: UE.UUserWidget[] = [];
public itemEnterButtons: Record<string, UE.UButton | undefined> = {};
private itemScope?: ScopedObject;
private onSelectDemo?: (this: void, demo: DemoSceneDescriptor) => void;
protected override OnBindWidgets(): void {
this.txtRuntimeInfo = this.RequireWidget<UE.UTextBlock>("TxtRuntimeInfo");
this.scrollDemoList = this.RequireWidget<UE.UScrollBox>("ScrollDemoList");
this.btnOpenMiniSettings = this.RequireWidget<UE.UButton>("BtnOpenMiniSettings");
this.BindButtonClick(this.btnOpenMiniSettings, () => {
OpenMiniSettings(this.ctx);
});
}
protected override OnPreShow(args?: unknown): void {
const openArgs = args as DemoHubOpenArgs | undefined;
this.onSelectDemo = openArgs !== undefined ? openArgs.onSelectDemo : undefined;
this.RefreshRuntimeInfo();
this.PopulateDemoCards();
}
protected override OnClose(): void {
this.ClearDemoCards();
}
private RefreshRuntimeInfo(): void {
const resSvc = this.ctx.GetService<ResourceService>("resource");
const modeText = resSvc !== undefined && resSvc.IsPackagedMode() ? "Packaged" : "PIE / Editor";
const info = string.format(
"Lua 运行时:%s | Context #%d | 资源模式:%s | 已注册 Demo:%d 个",
_VERSION,
this.ctx.contextId,
modeText,
GetDemoScenes().length
);
if (this.txtRuntimeInfo !== undefined && this.txtRuntimeInfo.SetText !== undefined) {
this.txtRuntimeInfo.SetText(info);
}
}
private ClearDemoCards(): void {
if (this.itemScope !== undefined) {
this.itemScope.Dispose();
this.itemScope = undefined;
}
if (this.scrollDemoList !== undefined && this.scrollDemoList.ClearChildren !== undefined) {
this.scrollDemoList.ClearChildren();
}
this.itemWidgets = [];
this.itemEnterButtons = {};
}
private PopulateDemoCards(): void {
this.ClearDemoCards();
const resSvc = this.ctx.GetService<ResourceService>("resource");
if (resSvc === undefined || this.scrollDemoList === undefined) {
return;
}
const scope = new ScopedObject();
this.itemScope = scope;
this.AddScopedObject(scope);
resSvc.LoadClassAsync(ASSET_KEYS.DEMO_HUB_ITEM_WIDGET, scope, (ok, itemClass, _lease, err) => {
if (!ok || itemClass === undefined || this.IsDisposed() || scope.IsDisposed()) {
logger.Error("Failed to load WBP_DemoHubItem", { err });
return;
}
this.BuildDemoCardWidgets(itemClass, scope);
});
}
private BuildDemoCardWidgets(itemClass: UE.UClass, scope: ScopedObject): void {
if (this.scrollDemoList === undefined) {
return;
}
const worldContext =
(this.ctx.GetWorldContext().world as UE.UObject | undefined) ??
(this.ctx.gameInstance as UE.UObject | undefined);
if (worldContext === undefined) {
return;
}
const lp0 = this.ctx.GetOrCreateLocalPlayer(0);
const bridge = this.ctx.GetService<UIDelegateBridge>("uiDelegateBridge");
const scenes = GetDemoScenes();
for (let i = 0; i < scenes.length; i++) {
const demo = scenes[i];
const card = UE.UWidgetBlueprintLibrary.Create(worldContext, itemClass, lp0.playerController);
if (card === undefined) {
continue;
}
const txtTitle = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoTitle") as
| UE.UTextBlock
| undefined;
const txtDesc = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoDesc") as
| UE.UTextBlock
| undefined;
const txtMeta = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoMeta") as
| UE.UTextBlock
| undefined;
const btnEnter = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "BtnEnterDemo") as
| UE.UButton
| undefined;
const txtEnterLabel = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtEnterLabel") as
| UE.UTextBlock
| undefined;
if (txtTitle !== undefined) {
txtTitle.SetText(demo.title);
}
if (txtDesc !== undefined) {
txtDesc.SetText(demo.description);
}
if (txtMeta !== undefined) {
txtMeta.SetText(string.format("%s | 关卡:%s", demo.tags, demo.mapAssetPath));
}
if (txtEnterLabel !== undefined) {
txtEnterLabel.SetText(demo.enabled ? "进入场景" : "敬请期待");
}
if (btnEnter !== undefined) {
btnEnter.SetIsEnabled(demo.enabled);
this.itemEnterButtons[demo.id] = btnEnter;
if (demo.enabled && bridge !== undefined) {
const handle: IDisposable = bridge.BindButtonClick(
btnEnter,
() => {
if (this.onSelectDemo !== undefined) {
this.onSelectDemo(demo);
}
},
scope
);
scope.AddScopedObject(handle);
}
}
this.scrollDemoList.AddChild(card);
this.itemWidgets[this.itemWidgets.length] = card;
}
}
}
RegisterUIConfig(DemoHubWindow, {
name: "DemoHubWindow",
assetKey: ASSET_KEYS.DEMO_HUB_WIDGET,
singleton: true,
layer: "normal",
type: "normal",
cacheTag: "no_cache",
blockWorldClick: true,
});
+74
View File
@@ -0,0 +1,74 @@
/** @noSelfInFile */
import type { GameInstanceContext } from "../../framework/context/game_context";
export interface DemoSceneDescriptor {
id: string;
title: string;
description: string;
mapName: string;
mapAssetPath: string;
tags: string;
enabled: boolean;
}
export const BOOTSTRAP_MAP_NAME = "L_Bootstrap";
export const BOOTSTRAP_MAP_PATH = "/Game/Maps/L_Bootstrap";
export const UI_DEMO_MAP_NAME = "L_DemoUI";
export const UI_DEMO_MAP_PATH = "/Game/Maps/L_DemoUI";
export const DEMO_SCENES: DemoSceneDescriptor[] = [
{
id: "ui_demo",
title: "UI 主界面与窗口实验室(UI Demo)",
description:
"完整演示游戏主界面布局、常用 UMG 控件(按钮/复选框/滑条/进度条/微调器/输入框/下拉框/动态列表/异步贴图)及 7 类窗口策略(普通/全屏互斥/模态/缓存复用/多实例/飘字/系统顶层)。",
mapName: UI_DEMO_MAP_NAME,
mapAssetPath: UI_DEMO_MAP_PATH,
tags: "UMG · 多层窗口栈 · 委托自动解绑 · 中文字体",
enabled: true,
},
{
id: "coming_resource_demo",
title: "资源热更与异步加载演示(预留槽位)",
description: "后续将在此扩展 PatchManifest 覆盖、并发合并加载与 GC 引用计数可视化演示。",
mapName: "L_DemoResource",
mapAssetPath: "/Game/Maps/L_DemoResource",
tags: "规划中 · ResourceService",
enabled: false,
},
{
id: "coming_gameplay_demo",
title: "3D 角色控制与输入演示(预留槽位)",
description: "后续将在此扩展 EnhancedInput、角色移动、射线检测与 HUD 非阻塞交互演示。",
mapName: "L_DemoGameplay",
mapAssetPath: "/Game/Maps/L_DemoGameplay",
tags: "规划中 · Gameplay / HUD",
enabled: false,
},
];
export function GetDemoScenes(): DemoSceneDescriptor[] {
return DEMO_SCENES;
}
export function FindDemoSceneById(id: string): DemoSceneDescriptor | undefined {
for (let i = 0; i < DEMO_SCENES.length; i++) {
if (DEMO_SCENES[i].id === id) {
return DEMO_SCENES[i];
}
}
return undefined;
}
export function FindDemoSceneByMapName(mapName: string): DemoSceneDescriptor | undefined {
for (let i = 0; i < DEMO_SCENES.length; i++) {
if (DEMO_SCENES[i].mapName === mapName) {
return DEMO_SCENES[i];
}
}
return undefined;
}
export type DemoSceneEntryFn = (this: void, ctx: GameInstanceContext) => void;
+110
View File
@@ -0,0 +1,110 @@
/** @noSelfInFile */
import { Logger } from "../../share/base/logger";
import type { GameInstanceContext } from "../../framework/context/game_context";
import { GetPrimaryUIManager } from "../startup";
import { DemoHubWindow } from "./demo_hub_window";
import {
BOOTSTRAP_MAP_NAME,
BOOTSTRAP_MAP_PATH,
FindDemoSceneById,
UI_DEMO_MAP_NAME,
type DemoSceneDescriptor,
} from "./demo_registry";
import { UIDemoMainWindow } from "./ui_demo/ui_demo_main_window";
const logger = Logger("DemoRouter");
export function OpenDemoHub(
ctx: GameInstanceContext,
onOpened?: (this: void, ok: boolean, win?: DemoHubWindow, err?: string) => void
): DemoHubWindow | undefined {
const uiMgr = GetPrimaryUIManager(ctx);
if (uiMgr === undefined) {
return undefined;
}
return uiMgr.ShowUI(
DemoHubWindow,
{
onSelectDemo: (demo: DemoSceneDescriptor) => {
SwitchToDemoById(ctx, demo.id);
},
},
onOpened
);
}
export function OpenUIDemoMain(
ctx: GameInstanceContext,
onOpened?: (this: void, ok: boolean, win?: UIDemoMainWindow, err?: string) => void
): UIDemoMainWindow | undefined {
const uiMgr = GetPrimaryUIManager(ctx);
if (uiMgr === undefined) {
return undefined;
}
return uiMgr.ShowUI(
UIDemoMainWindow,
{
onReturnToHub: () => {
ReturnToBootstrap(ctx);
},
},
onOpened
);
}
export function SwitchToDemoById(ctx: GameInstanceContext, demoId: string): boolean {
const demo = FindDemoSceneById(demoId);
if (demo === undefined || !demo.enabled) {
logger.Warn("Demo scene unavailable or disabled", { demoId });
return false;
}
const worldContext =
(ctx.GetWorldContext().world as UE.UObject | undefined) ??
(ctx.GetOrCreateLocalPlayer(0).playerController as UE.UObject | undefined);
if (worldContext === undefined) {
logger.Error("Cannot OpenLevel: no valid WorldContext", { demoId });
return false;
}
logger.Info("Switching to demo level", { demoId: demo.id, map: demo.mapAssetPath });
UE.UGameplayStatics.OpenLevel(worldContext, demo.mapAssetPath, true, "");
return true;
}
export function ReturnToBootstrap(ctx: GameInstanceContext): boolean {
const worldContext =
(ctx.GetWorldContext().world as UE.UObject | undefined) ??
(ctx.GetOrCreateLocalPlayer(0).playerController as UE.UObject | undefined);
if (worldContext === undefined) {
logger.Error("Cannot return to Bootstrap: no valid WorldContext");
return false;
}
logger.Info("Returning to Bootstrap Hub", { map: BOOTSTRAP_MAP_PATH });
UE.UGameplayStatics.OpenLevel(worldContext, BOOTSTRAP_MAP_PATH, true, "");
return true;
}
/**
* 按当前 UE 关卡名称自动挂载对应的 Demo 场景入口:
* - L_Bootstrap -> DemoHubWindow(场景切换大厅)
* - L_DemoUI -> UIDemoMainWindow(UI 组件与窗口实验室主界面)
* - 其他未知关卡 -> 默认兜底打开 DemoHubWindow
*/
export function RouteCurrentLevel(ctx: GameInstanceContext, pc: UE.APlayerController): void {
const levelName = UE.UGameplayStatics.GetCurrentLevelName(pc, true);
logger.Info("Routing player entry for level", { levelName });
if (levelName === UI_DEMO_MAP_NAME) {
OpenUIDemoMain(ctx);
return;
}
if (levelName === BOOTSTRAP_MAP_NAME) {
OpenDemoHub(ctx);
return;
}
OpenDemoHub(ctx);
}
@@ -0,0 +1,976 @@
import type { IDisposable } from "../../../share/base/interface";
import { Logger } from "../../../share/base/logger";
import { ScopedObject } from "../../../share/base/scoped_object";
import type { TimerHandle } from "../../../framework/core/scheduler";
import { ASSET_KEYS } from "../../../framework/resource/asset_catalog";
import type { ResourceService } from "../../../framework/resource/resource_service";
import { RegisterUIConfig } from "../../../framework/ui/ui_config";
import type { UIDelegateBridge } from "../../../framework/ui/ui_delegate_bridge";
import { UIWindow } from "../../../framework/ui/ui_window";
import { OpenMiniSettings } from "../../startup";
import {
UIDemoCachedWindow,
UIDemoFullscreenWindow,
UIDemoModalWindow,
UIDemoMultiWindow,
UIDemoNormalWindow,
UIDemoSystemWindow,
UIDemoToastWindow,
} from "./ui_demo_windows";
const logger = Logger("UIDemoMainWindow");
export interface UIDemoMainArgs {
onReturnToHub?: (this: void) => void;
}
interface DynamicListEntry {
id: number;
widget: UE.UUserWidget;
scope: ScopedObject;
}
interface ThemePreset {
label: string;
r: number;
g: number;
b: number;
}
const THEME_PRESETS: ThemePreset[] = [
{ label: "深海蓝(普通)", r: 0.149, g: 0.431, b: 0.855 },
{ label: "翡翠绿(稀有)", r: 0.133, g: 0.588, b: 0.388 },
{ label: "琥珀金(传说)", r: 0.761, g: 0.490, b: 0.110 },
{ label: "星云紫(史诗)", r: 0.478, g: 0.294, b: 0.784 },
];
const TEXT_COLORS: Array<{ name: string; r: number; g: number; b: number }> = [
{ name: "纯白", r: 0.941, g: 0.961, b: 0.988 },
{ name: "天青", r: 0.451, g: 0.788, b: 0.980 },
{ name: "金黄", r: 0.980, g: 0.812, b: 0.310 },
{ name: "珊瑚红", r: 0.980, g: 0.510, b: 0.510 },
];
const TEXT_SIZES: number[] = [14, 18, 22];
const PREVIEW_TEXTURES: Array<{ label: string; key: string }> = [
{ label: "冒险者头像", key: ASSET_KEYS.DEMO_AVATAR_TEX },
{ label: "翡翠菱形徽章", key: ASSET_KEYS.DEMO_BADGE_A_TEX },
{ label: "绯红星纹徽章", key: ASSET_KEYS.DEMO_BADGE_B_TEX },
{ label: "经典设置图标", key: ASSET_KEYS.MINI_SETTINGS_ICON },
];
const TINT_COLORS: Array<{ name: string; r: number; g: number; b: number }> = [
{ name: "原色", r: 1.0, g: 1.0, b: 1.0 },
{ name: "青蓝着色", r: 0.55, g: 0.90, b: 1.0 },
{ name: "金黄着色", r: 1.0, g: 0.85, b: 0.45 },
{ name: "玫红着色", r: 1.0, g: 0.55, b: 0.70 },
];
function MakeLinearColor(r: number, g: number, b: number, a = 1.0): UE.FLinearColor {
const c = UE.FLinearColor();
c.R = r;
c.G = g;
c.B = b;
c.A = a;
return c;
}
function MakeSlateColor(r: number, g: number, b: number, a = 1.0): UE.FSlateColor {
const sc = UE.FSlateColor();
sc.SpecifiedColor = MakeLinearColor(r, g, b, a);
sc.ColorUseRule = UE.ESlateColorStylingMode.UseColor_Specified;
return sc;
}
/**
* UI Demo 主界面窗口(绑定 /Game/UI/Demo/WBP_UIDemoMain):
* 集成了游戏主界面顶部栏、左侧 7 类窗口测试入口、中央 4 Tab UMG 组件实验室与右侧实时交互日志。
*/
export class UIDemoMainWindow extends UIWindow {
// TopBar
public imgPlayerAvatar?: UE.UImage;
public txtPlayerName?: UE.UTextBlock;
public barPlayerExp?: UE.UProgressBar;
public txtHudStats?: UE.UTextBlock;
public btnTopSettings?: UE.UButton;
public btnBackToHub?: UE.UButton;
// LeftNav
public btnWinNormal?: UE.UButton;
public btnWinFullscreen?: UE.UButton;
public btnWinModal?: UE.UButton;
public btnWinCached?: UE.UButton;
public btnWinMulti?: UE.UButton;
public btnWinToast?: UE.UButton;
public btnWinSystem?: UE.UButton;
public btnEvictCache?: UE.UButton;
public btnCloseOthers?: UE.UButton;
// Tabs
public btnTabBasic?: UE.UButton;
public btnTabInput?: UE.UButton;
public btnTabMedia?: UE.UButton;
public btnTabDiag?: UE.UButton;
public tabSwitcher?: UE.UWidgetSwitcher;
// Page 0: Basic
public txtBasicBtnStatus?: UE.UTextBlock;
public btnDemoAction?: UE.UButton;
public btnToggleDisable?: UE.UButton;
public btnDemoTarget?: UE.UButton;
public txtDemoTarget?: UE.UTextBlock;
public chkFeature?: UE.UCheckBox;
public txtCheckStatus?: UE.UTextBlock;
public txtSliderStatus?: UE.UTextBlock;
public sliderDemo?: UE.USlider;
public progressDemo?: UE.UProgressBar;
public btnProgressPlay?: UE.UButton;
public txtProgressPlay?: UE.UTextBlock;
public btnProgressReset?: UE.UButton;
public spinDemo?: UE.USpinBox;
public txtSpinStatus?: UE.UTextBlock;
// Page 1: Input & Selection
public inputNickname?: UE.UEditableTextBox;
public txtInputStatus?: UE.UTextBlock;
public btnApplyNickname?: UE.UButton;
public comboTheme?: UE.UComboBoxString;
public borderThemePreview?: UE.UBorder;
public txtComboStatus?: UE.UTextBlock;
public txtRichSample?: UE.UTextBlock;
public btnCycleTextColor?: UE.UButton;
public btnCycleTextSize?: UE.UButton;
// Page 2: Media & Containers
public imgPreview?: UE.UImage;
public txtImageStatus?: UE.UTextBlock;
public btnSwitchTex?: UE.UButton;
public btnTintTex?: UE.UButton;
public btnCycleVis?: UE.UButton;
public txtListSummary?: UE.UTextBlock;
public btnListAddOne?: UE.UButton;
public btnListAddTen?: UE.UButton;
public btnListClear?: UE.UButton;
public scrollDynamicList?: UE.UScrollBox;
// Page 3: Diagnostics
public txtDiagDetail?: UE.UTextBlock;
public btnDiagRefresh?: UE.UButton;
public btnDiagConcurrent?: UE.UButton;
public btnDiagCancelLoad?: UE.UButton;
// RightLog
public btnClearLog?: UE.UButton;
public scrollEventLog?: UE.UScrollBox;
public txtEventLog?: UE.UTextBlock;
// Observable state for automated UE tests & diagnostics
public activeTabIndex = 0;
public actionClickCount = 0;
public actionHovered = false;
public targetEnabled = true;
public targetClickCount = 0;
public checkboxChecked = false;
public sliderValue = 0.5;
public spinValue = 100;
public currentNickname = "冒险者_01";
public draftNickname = "";
public selectedTheme = "深海蓝(普通)";
public dynamicItemCount = 0;
private onReturnToHub?: (this: void) => void;
private multiSeq = 0;
private toastSeq = 0;
private progressTimer?: TimerHandle;
private textColorIndex = 0;
private textSizeIndex = 0;
private previewTexIndex = 0;
private previewTintIndex = 0;
private previewVisIndex = 0;
private nextListItemId = 0;
private listItemClass?: UE.UClass;
private dynamicItems: DynamicListEntry[] = [];
private logLines: string[] = [];
protected override OnBindWidgets(): void {
// TopBar
this.imgPlayerAvatar = this.RequireWidget<UE.UImage>("ImgPlayerAvatar");
this.txtPlayerName = this.RequireWidget<UE.UTextBlock>("TxtPlayerName");
this.barPlayerExp = this.RequireWidget<UE.UProgressBar>("BarPlayerExp");
this.txtHudStats = this.RequireWidget<UE.UTextBlock>("TxtHudStats");
this.btnTopSettings = this.RequireWidget<UE.UButton>("BtnTopSettings");
this.btnBackToHub = this.RequireWidget<UE.UButton>("BtnBackToHub");
this.BindButtonClick(this.btnTopSettings, () => {
this.AppendLog("[TopBar] 打开 MiniSettingsWindow");
OpenMiniSettings(this.ctx);
});
this.BindButtonClick(this.btnBackToHub, () => {
this.AppendLog("[TopBar] 返回 Bootstrap 场景大厅");
if (this.onReturnToHub !== undefined) {
this.onReturnToHub();
}
});
// LeftNav (Window types)
this.btnWinNormal = this.RequireWidget<UE.UButton>("BtnWinNormal");
this.btnWinFullscreen = this.RequireWidget<UE.UButton>("BtnWinFullscreen");
this.btnWinModal = this.RequireWidget<UE.UButton>("BtnWinModal");
this.btnWinCached = this.RequireWidget<UE.UButton>("BtnWinCached");
this.btnWinMulti = this.RequireWidget<UE.UButton>("BtnWinMulti");
this.btnWinToast = this.RequireWidget<UE.UButton>("BtnWinToast");
this.btnWinSystem = this.RequireWidget<UE.UButton>("BtnWinSystem");
this.btnEvictCache = this.RequireWidget<UE.UButton>("BtnEvictCache");
this.btnCloseOthers = this.RequireWidget<UE.UButton>("BtnCloseOthers");
this.BindButtonClick(this.btnWinNormal, () => {
this.OpenNormalDemoWindow();
});
this.BindButtonClick(this.btnWinFullscreen, () => {
this.OpenFullscreenDemoWindow();
});
this.BindButtonClick(this.btnWinModal, () => {
this.OpenModalDemoWindow("确认操作", "这是一条带半透明遮罩的模态弹窗,点击「确认」或「取消」将在右侧日志记录结果。");
});
this.BindButtonClick(this.btnWinCached, () => {
this.OpenCachedDemoWindow();
});
this.BindButtonClick(this.btnWinMulti, () => {
this.OpenMultiDemoWindow();
});
this.BindButtonClick(this.btnWinToast, () => {
this.ShowToast(string.format("飘字通知 #%d(Tips 层,不抢占 UI 焦点)", this.toastSeq + 1));
});
this.BindButtonClick(this.btnWinSystem, () => {
this.OpenSystemDemoWindow();
});
this.BindButtonClick(this.btnEvictCache, () => {
const evicted = this.uiManager.EvictCache();
this.AppendLog(string.format("[Cache] 已主动清空缓存池,释放 %d 个缓存窗口", evicted));
this.RefreshHudAndDiagnostics();
});
this.BindButtonClick(this.btnCloseOthers, () => {
const closed = this.uiManager.CloseAllExcept(this, false);
this.AppendLog(string.format("[UIManager] 已关闭除主界面外的 %d 个窗口", closed));
this.RefreshHudAndDiagnostics();
});
// Tabs
this.btnTabBasic = this.RequireWidget<UE.UButton>("BtnTabBasic");
this.btnTabInput = this.RequireWidget<UE.UButton>("BtnTabInput");
this.btnTabMedia = this.RequireWidget<UE.UButton>("BtnTabMedia");
this.btnTabDiag = this.RequireWidget<UE.UButton>("BtnTabDiag");
this.tabSwitcher = this.RequireWidget<UE.UWidgetSwitcher>("TabSwitcher");
this.BindButtonClick(this.btnTabBasic, () => this.SelectTab(0, "基础交互"));
this.BindButtonClick(this.btnTabInput, () => this.SelectTab(1, "输入与选择"));
this.BindButtonClick(this.btnTabMedia, () => this.SelectTab(2, "图片与列表"));
this.BindButtonClick(this.btnTabDiag, () => {
this.SelectTab(3, "框架诊断");
this.RefreshHudAndDiagnostics();
});
// Page 0: Basic
this.txtBasicBtnStatus = this.RequireWidget<UE.UTextBlock>("TxtBasicBtnStatus");
this.btnDemoAction = this.RequireWidget<UE.UButton>("BtnDemoAction");
this.btnToggleDisable = this.RequireWidget<UE.UButton>("BtnToggleDisable");
this.btnDemoTarget = this.RequireWidget<UE.UButton>("BtnDemoTarget");
this.txtDemoTarget = this.RequireWidget<UE.UTextBlock>("TxtDemoTarget");
this.chkFeature = this.RequireWidget<UE.UCheckBox>("ChkFeature");
this.txtCheckStatus = this.RequireWidget<UE.UTextBlock>("TxtCheckStatus");
this.txtSliderStatus = this.RequireWidget<UE.UTextBlock>("TxtSliderStatus");
this.sliderDemo = this.RequireWidget<UE.USlider>("SliderDemo");
this.progressDemo = this.RequireWidget<UE.UProgressBar>("ProgressDemo");
this.btnProgressPlay = this.RequireWidget<UE.UButton>("BtnProgressPlay");
this.txtProgressPlay = this.RequireWidget<UE.UTextBlock>("TxtProgressPlay");
this.btnProgressReset = this.RequireWidget<UE.UButton>("BtnProgressReset");
this.spinDemo = this.RequireWidget<UE.USpinBox>("SpinDemo");
this.txtSpinStatus = this.RequireWidget<UE.UTextBlock>("TxtSpinStatus");
this.BindButtonClick(this.btnDemoAction, () => {
this.actionClickCount = this.actionClickCount + 1;
this.RefreshBasicButtonStatus();
this.AppendLog(string.format("[Button] 测试按钮被点击(第 %d 次)", this.actionClickCount));
});
this.BindButtonHovered(this.btnDemoAction, () => {
this.actionHovered = true;
this.RefreshBasicButtonStatus();
this.AppendLog("[Button] 鼠标悬停进入测试按钮");
});
this.BindButtonUnhovered(this.btnDemoAction, () => {
this.actionHovered = false;
this.RefreshBasicButtonStatus();
});
this.BindButtonClick(this.btnToggleDisable, () => {
this.targetEnabled = !this.targetEnabled;
if (this.btnDemoTarget !== undefined) {
this.btnDemoTarget.SetIsEnabled(this.targetEnabled);
}
if (this.txtDemoTarget !== undefined) {
this.txtDemoTarget.SetText(this.targetEnabled ? "目标受控按钮(已启用)" : "目标受控按钮(已禁用)");
}
this.RefreshBasicButtonStatus();
this.AppendLog(this.targetEnabled ? "[Button] 目标按钮已启用" : "[Button] 目标按钮已禁用");
});
this.BindButtonClick(this.btnDemoTarget, () => {
this.targetClickCount = this.targetClickCount + 1;
this.AppendLog(string.format("[Button] 受控按钮触发点击 #%d", this.targetClickCount));
});
this.BindCheckBoxChanged(this.chkFeature, (checked: boolean) => {
this.checkboxChecked = checked;
if (this.txtCheckStatus !== undefined) {
this.txtCheckStatus.SetText(checked ? "复选框状态:已勾选(开启特性)" : "复选框状态:未勾选(关闭特性)");
}
this.AppendLog(checked ? "[CheckBox] 已勾选" : "[CheckBox] 已取消勾选");
});
this.BindSliderChanged(this.sliderDemo, (val: number) => {
this.ApplySliderProgress(val, false);
});
this.BindButtonClick(this.btnProgressPlay, () => {
this.ToggleProgressAnimation();
});
this.BindButtonClick(this.btnProgressReset, () => {
this.StopProgressAnimation();
this.ApplySliderProgress(0, true);
this.AppendLog("[ProgressBar] 进度已重置为 0%");
});
this.BindSpinBoxChanged(this.spinDemo, (val: number) => {
this.spinValue = val;
if (this.txtSpinStatus !== undefined) {
this.txtSpinStatus.SetText(string.format("当前数值:%.1f(范围 0 ~ 999)", val));
}
this.AppendLog(string.format("[SpinBox] 数值变更 -> %.1f", val));
});
// Page 1: Input & Selection
this.inputNickname = this.RequireWidget<UE.UEditableTextBox>("InputNickname");
this.txtInputStatus = this.RequireWidget<UE.UTextBlock>("TxtInputStatus");
this.btnApplyNickname = this.RequireWidget<UE.UButton>("BtnApplyNickname");
this.comboTheme = this.RequireWidget<UE.UComboBoxString>("ComboTheme");
this.borderThemePreview = this.RequireWidget<UE.UBorder>("BorderThemePreview");
this.txtComboStatus = this.RequireWidget<UE.UTextBlock>("TxtComboStatus");
this.txtRichSample = this.RequireWidget<UE.UTextBlock>("TxtRichSample");
this.btnCycleTextColor = this.RequireWidget<UE.UButton>("BtnCycleTextColor");
this.btnCycleTextSize = this.RequireWidget<UE.UButton>("BtnCycleTextSize");
this.BindEditableTextChanged(this.inputNickname, (text: string) => {
this.draftNickname = text;
const charCount = utf8.len(text) ?? string.len(text);
if (this.txtInputStatus !== undefined) {
this.txtInputStatus.SetText(
charCount > 0
? string.format("实时内容:%s(%d 字符)", text, charCount)
: "实时内容:空(0 字符)"
);
}
});
this.BindEditableTextCommitted(this.inputNickname, (text: string, commitMethod: number) => {
this.draftNickname = text;
this.AppendLog(string.format("[EditableTextBox] 提交文本:%s(Method=%d)", text, commitMethod));
if (text !== "") {
this.ApplyNickname(text);
}
});
this.BindButtonClick(this.btnApplyNickname, () => {
const nextName = this.draftNickname !== "" ? this.draftNickname : "天命旅人_88";
this.ApplyNickname(nextName);
});
this.BindComboBoxChanged(this.comboTheme, (option: string) => {
this.ApplyThemePreset(option);
});
this.BindButtonClick(this.btnCycleTextColor, () => {
this.textColorIndex = (this.textColorIndex + 1) % TEXT_COLORS.length;
const c = TEXT_COLORS[this.textColorIndex];
if (this.txtRichSample !== undefined) {
this.txtRichSample.SetColorAndOpacity(MakeSlateColor(c.r, c.g, c.b, 1.0));
}
this.AppendLog(string.format("[TextBlock] 切换文本颜色 -> %s", c.name));
});
this.BindButtonClick(this.btnCycleTextSize, () => {
this.textSizeIndex = (this.textSizeIndex + 1) % TEXT_SIZES.length;
const size = TEXT_SIZES[this.textSizeIndex];
if (this.txtRichSample !== undefined) {
this.txtRichSample.SetFontSize(size);
}
this.AppendLog(string.format("[TextBlock] 切换字号 -> %dpt", size));
});
// Page 2: Media & Containers
this.imgPreview = this.RequireWidget<UE.UImage>("ImgPreview");
this.txtImageStatus = this.RequireWidget<UE.UTextBlock>("TxtImageStatus");
this.btnSwitchTex = this.RequireWidget<UE.UButton>("BtnSwitchTex");
this.btnTintTex = this.RequireWidget<UE.UButton>("BtnTintTex");
this.btnCycleVis = this.RequireWidget<UE.UButton>("BtnCycleVis");
this.txtListSummary = this.RequireWidget<UE.UTextBlock>("TxtListSummary");
this.btnListAddOne = this.RequireWidget<UE.UButton>("BtnListAddOne");
this.btnListAddTen = this.RequireWidget<UE.UButton>("BtnListAddTen");
this.btnListClear = this.RequireWidget<UE.UButton>("BtnListClear");
this.scrollDynamicList = this.RequireWidget<UE.UScrollBox>("ScrollDynamicList");
this.BindButtonClick(this.btnSwitchTex, () => {
this.previewTexIndex = (this.previewTexIndex + 1) % PREVIEW_TEXTURES.length;
this.LoadPreviewTexture();
});
this.BindButtonClick(this.btnTintTex, () => {
this.previewTintIndex = (this.previewTintIndex + 1) % TINT_COLORS.length;
const tint = TINT_COLORS[this.previewTintIndex];
if (this.imgPreview !== undefined) {
this.imgPreview.SetColorAndOpacity(MakeLinearColor(tint.r, tint.g, tint.b, 1.0));
}
this.AppendLog(string.format("[Image] 切换着色 -> %s", tint.name));
this.RefreshImageStatus();
});
this.BindButtonClick(this.btnCycleVis, () => {
this.previewVisIndex = (this.previewVisIndex + 1) % 3;
const visModes = [
UE.ESlateVisibility.Visible,
UE.ESlateVisibility.Hidden,
UE.ESlateVisibility.Collapsed,
];
if (this.imgPreview !== undefined) {
this.imgPreview.SetVisibility(visModes[this.previewVisIndex]);
}
this.RefreshImageStatus();
this.AppendLog(string.format("[Image] 切换可见性 -> %s", this.GetVisibilityLabel()));
});
this.BindButtonClick(this.btnListAddOne, () => this.AddDynamicListItems(1));
this.BindButtonClick(this.btnListAddTen, () => this.AddDynamicListItems(10));
this.BindButtonClick(this.btnListClear, () => this.ClearDynamicListItems());
// Page 3: Diagnostics
this.txtDiagDetail = this.RequireWidget<UE.UTextBlock>("TxtDiagDetail");
this.btnDiagRefresh = this.RequireWidget<UE.UButton>("BtnDiagRefresh");
this.btnDiagConcurrent = this.RequireWidget<UE.UButton>("BtnDiagConcurrent");
this.btnDiagCancelLoad = this.RequireWidget<UE.UButton>("BtnDiagCancelLoad");
this.BindButtonClick(this.btnDiagRefresh, () => {
this.RefreshHudAndDiagnostics();
this.AppendLog("[Diag] 已手动刷新诊断快照");
});
this.BindButtonClick(this.btnDiagConcurrent, () => {
const w1 = this.OpenNormalDemoWindow();
const w2 = this.OpenNormalDemoWindow();
const same = w1 === w2;
this.AppendLog(string.format("[Diag] 并发双开单例测试:同一控制器=%s", tostring(same)));
this.ShowToast(same ? "并发双开测试通过:返回同一单例" : "并发双开测试异常");
});
this.BindButtonClick(this.btnDiagCancelLoad, () => {
const w = this.uiManager.ShowUI(UIDemoSystemWindow, { onLog: (m: string) => this.AppendLog(m) });
if (w !== undefined) {
w.Close();
}
this.AppendLog("[Diag] 已执行「打开后立即关闭」取消加载验证");
this.RefreshHudAndDiagnostics();
});
// RightLog
this.btnClearLog = this.RequireWidget<UE.UButton>("BtnClearLog");
this.scrollEventLog = this.RequireWidget<UE.UScrollBox>("ScrollEventLog");
this.txtEventLog = this.RequireWidget<UE.UTextBlock>("TxtEventLog");
this.BindButtonClick(this.btnClearLog, () => {
this.logLines = [];
this.RenderLogText();
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as UIDemoMainArgs | undefined;
this.onReturnToHub = a !== undefined ? a.onReturnToHub : undefined;
// Subscribe to UIManager lifecycle events so TopBar & Diagnostics stay live
this.uiManager.events.on.OnWindowOpened((winName: string) => {
this.AppendLog(string.format("[UIManager] 窗口打开:%s", winName));
this.RefreshHudAndDiagnostics();
}, this);
this.uiManager.events.on.OnWindowClosed((winName: string) => {
this.AppendLog(string.format("[UIManager] 窗口关闭:%s", winName));
this.RefreshHudAndDiagnostics();
}, this);
this.uiManager.events.on.OnFocusRestored(() => {
this.RefreshHudAndDiagnostics();
}, this);
this.LoadAvatarAndPreview();
this.PreloadDynamicListItemClass();
this.SelectTab(0, "基础交互");
this.RefreshBasicButtonStatus();
this.ApplySliderProgress(this.sliderValue, true);
this.RefreshListSummary();
this.AppendLog("[UIDemoMain] 主界面已就绪,可测试全部 UI 控件与 7 类窗口");
}
protected override OnShow(): void {
this.RefreshHudAndDiagnostics();
}
protected override OnHide(): void {
this.AppendLog("[UIDemoMain] OnHide(已被全屏窗口遮盖隐藏)");
}
protected override OnClose(): void {
this.StopProgressAnimation();
this.ClearDynamicListItems();
}
public SelectTab(index: number, label: string): void {
this.activeTabIndex = index;
if (this.tabSwitcher !== undefined) {
this.tabSwitcher.SetActiveWidgetIndex(index);
}
this.AppendLog(string.format("[Tab] 切换至:%s", label));
}
public OpenNormalDemoWindow(): UIDemoNormalWindow | undefined {
return this.uiManager.ShowUI(UIDemoNormalWindow, {
onLog: (m: string) => this.AppendLog(m),
});
}
public OpenFullscreenDemoWindow(): UIDemoFullscreenWindow | undefined {
return this.uiManager.ShowUI(UIDemoFullscreenWindow, {
onLog: (m: string) => this.AppendLog(m),
onOpenModal: () => {
this.OpenModalDemoWindow("全屏页上的模态弹窗", "验证 popup 层正确叠加在 fullscreen 全屏页面之上。");
},
});
}
public OpenModalDemoWindow(title: string, message: string): UIDemoModalWindow | undefined {
return this.uiManager.ShowUI(UIDemoModalWindow, {
title,
message,
onConfirm: () => {
this.AppendLog("[Modal] 用户点击了「确认」");
this.ShowToast("模态弹窗:已确认");
},
onCancel: () => {
this.AppendLog("[Modal] 用户点击了「取消」");
},
});
}
public OpenCachedDemoWindow(): UIDemoCachedWindow | undefined {
return this.uiManager.ShowUI(UIDemoCachedWindow, {
onLog: (m: string) => this.AppendLog(m),
});
}
public OpenMultiDemoWindow(): UIDemoMultiWindow | undefined {
this.multiSeq = this.multiSeq + 1;
return this.uiManager.ShowUI(UIDemoMultiWindow, {
instanceSeq: this.multiSeq,
onLog: (m: string) => this.AppendLog(m),
});
}
public ShowToast(message: string, durationSec = 2.2): UIDemoToastWindow | undefined {
this.toastSeq = this.toastSeq + 1;
return this.uiManager.ShowUI(UIDemoToastWindow, {
message,
durationSec,
offsetIndex: this.toastSeq - 1,
onLog: (m: string) => this.AppendLog(m),
});
}
public OpenSystemDemoWindow(): UIDemoSystemWindow | undefined {
return this.uiManager.ShowUI(UIDemoSystemWindow, {
onLog: (m: string) => this.AppendLog(m),
});
}
public AddDynamicListItems(count: number): void {
if (this.scrollDynamicList === undefined) {
return;
}
if (this.listItemClass === undefined) {
this.PreloadDynamicListItemClass(() => {
this.AddDynamicListItems(count);
});
return;
}
const worldContext =
(this.ctx.GetWorldContext().world as UE.UObject | undefined) ??
(this.ctx.gameInstance as UE.UObject | undefined);
if (worldContext === undefined) {
return;
}
const lp0 = this.ctx.GetOrCreateLocalPlayer(0);
const bridge = this.ctx.GetService<UIDelegateBridge>("uiDelegateBridge");
for (let i = 0; i < count; i++) {
this.nextListItemId = this.nextListItemId + 1;
const itemId = this.nextListItemId;
const itemWidget = UE.UWidgetBlueprintLibrary.Create(worldContext, this.listItemClass, lp0.playerController);
if (itemWidget === undefined) {
continue;
}
const itemScope = new ScopedObject();
const txtTitle = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "TxtItemTitle") as
| UE.UTextBlock
| undefined;
const btnAct = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "BtnItemAction") as
| UE.UButton
| undefined;
const btnDel = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "BtnItemDelete") as
| UE.UButton
| undefined;
if (txtTitle !== undefined) {
txtTitle.SetText(string.format("动态条目 #%d — 测试委托自动回收", itemId));
}
const entry: DynamicListEntry = {
id: itemId,
widget: itemWidget,
scope: itemScope,
};
if (bridge !== undefined) {
if (btnAct !== undefined) {
const hAct: IDisposable = bridge.BindButtonClick(
btnAct,
() => {
this.AppendLog(string.format("[ListItem #%d] 点击了「触发」", itemId));
this.ShowToast(string.format("触发了列表项 #%d", itemId), 1.5);
},
itemScope
);
itemScope.AddScopedObject(hAct);
}
if (btnDel !== undefined) {
const hDel: IDisposable = bridge.BindButtonClick(
btnDel,
() => {
this.RemoveDynamicListItem(itemId);
},
itemScope
);
itemScope.AddScopedObject(hDel);
}
}
this.scrollDynamicList.AddChild(itemWidget);
this.dynamicItems[this.dynamicItems.length] = entry;
}
this.dynamicItemCount = this.dynamicItems.length;
this.RefreshListSummary();
this.RefreshHudAndDiagnostics();
this.AppendLog(string.format("[ScrollBox] 新增 %d 个动态列表项(当前共 %d 项)", count, this.dynamicItemCount));
}
public RemoveDynamicListItem(itemId: number): void {
for (let i = this.dynamicItems.length - 1; i >= 0; i--) {
const entry = this.dynamicItems[i];
if (entry.id === itemId) {
entry.scope.Dispose();
if (entry.widget.RemoveFromParent !== undefined) {
entry.widget.RemoveFromParent();
}
table.remove(this.dynamicItems, i + 1);
break;
}
}
this.dynamicItemCount = this.dynamicItems.length;
this.RefreshListSummary();
this.RefreshHudAndDiagnostics();
this.AppendLog(string.format("[ScrollBox] 删除列表项 #%d(委托已自动解绑,剩余 %d 项)", itemId, this.dynamicItemCount));
}
public ClearDynamicListItems(): void {
const prev = this.dynamicItems.length;
for (let i = 0; i < this.dynamicItems.length; i++) {
this.dynamicItems[i].scope.Dispose();
}
this.dynamicItems = [];
this.dynamicItemCount = 0;
if (this.scrollDynamicList !== undefined && this.scrollDynamicList.ClearChildren !== undefined) {
this.scrollDynamicList.ClearChildren();
}
this.RefreshListSummary();
if (prev > 0) {
this.AppendLog(string.format("[ScrollBox] 已清空 %d 个动态列表项并释放全部子委托", prev));
this.RefreshHudAndDiagnostics();
}
}
private PreloadDynamicListItemClass(onReady?: (this: void) => void): void {
const resSvc = this.ctx.GetService<ResourceService>("resource");
if (resSvc === undefined) {
return;
}
resSvc.LoadClassAsync(ASSET_KEYS.UI_DEMO_LIST_ITEM_WIDGET, this, (ok, cls, _lease, err) => {
if (!ok || cls === undefined) {
logger.Warn("Failed to load WBP_UIDemoListItem", { err });
return;
}
this.listItemClass = cls;
if (onReady !== undefined && !this.IsDisposed()) {
onReady();
}
});
}
private LoadAvatarAndPreview(): void {
const resSvc = this.ctx.GetService<ResourceService>("resource");
if (resSvc === undefined) {
return;
}
resSvc.LoadTextureAsync(ASSET_KEYS.DEMO_AVATAR_TEX, this, (ok, tex) => {
if (ok && tex !== undefined && this.imgPlayerAvatar !== undefined && !this.IsDisposed()) {
this.imgPlayerAvatar.SetBrushFromTexture(tex, false);
}
});
this.LoadPreviewTexture();
}
private LoadPreviewTexture(): void {
const resSvc = this.ctx.GetService<ResourceService>("resource");
if (resSvc === undefined) {
return;
}
const spec = PREVIEW_TEXTURES[this.previewTexIndex];
resSvc.LoadTextureAsync(spec.key, this, (ok, tex) => {
if (ok && tex !== undefined && this.imgPreview !== undefined && !this.IsDisposed()) {
this.imgPreview.SetBrushFromTexture(tex, false);
this.RefreshImageStatus();
this.AppendLog(string.format("[Image] 异步贴图加载完成 -> %s", spec.label));
}
});
}
private GetVisibilityLabel(): string {
if (this.previewVisIndex === 0) return "Visible(可见)";
if (this.previewVisIndex === 1) return "Hidden(隐身占位)";
return "Collapsed(折叠不占位)";
}
private RefreshImageStatus(): void {
const spec = PREVIEW_TEXTURES[this.previewTexIndex];
const tint = TINT_COLORS[this.previewTintIndex];
if (this.txtImageStatus !== undefined) {
this.txtImageStatus.SetText(
string.format("贴图:%s | 着色:%s | 可见性:%s", spec.label, tint.name, this.GetVisibilityLabel())
);
}
}
private RefreshBasicButtonStatus(): void {
if (this.txtBasicBtnStatus !== undefined) {
this.txtBasicBtnStatus.SetText(
string.format(
"按钮状态:点击 %d 次 | 悬停:%s | 受控按钮:%s",
this.actionClickCount,
this.actionHovered ? "是" : "否",
this.targetEnabled ? "已启用" : "已禁用"
)
);
}
}
private ApplySliderProgress(val: number, syncSliderWidget: boolean): void {
const clamped = math.max(0, math.min(1, val));
this.sliderValue = clamped;
if (syncSliderWidget && this.sliderDemo !== undefined) {
this.sliderDemo.SetValue(clamped);
}
if (this.progressDemo !== undefined) {
this.progressDemo.SetPercent(clamped);
}
if (this.barPlayerExp !== undefined) {
this.barPlayerExp.SetPercent(clamped);
}
if (this.txtSliderStatus !== undefined) {
this.txtSliderStatus.SetText(
string.format("当前进度:%d%%(同时驱动主界面顶部经验条)", math.floor(clamped * 100 + 0.5))
);
}
}
private ToggleProgressAnimation(): void {
if (this.progressTimer !== undefined && this.progressTimer.IsActive()) {
this.StopProgressAnimation();
this.AppendLog("[ProgressBar] 暂停进度动画");
return;
}
if (this.txtProgressPlay !== undefined) {
this.txtProgressPlay.SetText("暂停自动进度动画");
}
this.AppendLog("[ProgressBar] 启动 WorldTimer 自动进度动画");
this.progressTimer = this.ctx.scheduler.AddWorldRepeatTimer(
0.05,
() => {
let nextVal = this.sliderValue + 0.025;
if (nextVal > 1.0) {
nextVal = 0.0;
}
this.ApplySliderProgress(nextVal, true);
},
this
);
}
private StopProgressAnimation(): void {
if (this.progressTimer !== undefined) {
this.progressTimer.Cancel();
this.progressTimer = undefined;
}
if (this.txtProgressPlay !== undefined) {
this.txtProgressPlay.SetText("开始自动进度动画");
}
}
private ApplyNickname(name: string): void {
this.currentNickname = name;
if (this.txtPlayerName !== undefined) {
this.txtPlayerName.SetText(string.format("%s Lv.12", name));
}
this.AppendLog(string.format("[Player] 昵称已更新为:%s", name));
this.ShowToast(string.format("昵称已更新:%s", name), 1.8);
}
private ApplyThemePreset(option: string): void {
this.selectedTheme = option;
let matched = THEME_PRESETS[0];
for (let i = 0; i < THEME_PRESETS.length; i++) {
if (THEME_PRESETS[i].label === option) {
matched = THEME_PRESETS[i];
break;
}
}
if (this.borderThemePreview !== undefined) {
this.borderThemePreview.SetBrushColor(MakeLinearColor(matched.r, matched.g, matched.b, 1.0));
}
if (this.txtComboStatus !== undefined) {
this.txtComboStatus.SetText(string.format("当前选中:%s", option));
}
this.AppendLog(string.format("[ComboBox] 切换主题 -> %s", option));
}
private RefreshListSummary(): void {
if (this.txtListSummary !== undefined) {
this.txtListSummary.SetText(
string.format("动态列表项:%d 条(新增/删除时观察顶部活跃绑定数变化)", this.dynamicItemCount)
);
}
}
public RefreshHudAndDiagnostics(): void {
if (this.IsDisposed()) {
return;
}
const uiDiag = this.uiManager.GetDiagnostics();
const bridge = this.ctx.GetService<UIDelegateBridge>("uiDelegateBridge");
const resSvc = this.ctx.GetService<ResourceService>("resource");
const activeBindings = bridge !== undefined ? bridge.GetActiveBindingCount() : 0;
if (this.txtHudStats !== undefined) {
this.txtHudStats.SetText(
string.format(
"窗口:%d | 缓存:%d | 绑定:%d | 模式:%s | 顶层:%s",
uiDiag.openWindows,
uiDiag.cachedWindows,
activeBindings,
uiDiag.inputMode === "ui" ? "UI" : "Game",
uiDiag.topWindowName ?? "无"
)
);
}
if (this.txtDiagDetail !== undefined) {
const stack = this.uiManager.GetWindowStackSnapshot();
const cachedNames = this.uiManager.GetCachedWindowNames();
const schedStats = this.ctx.scheduler.GetStats();
const resDiag = resSvc !== undefined ? resSvc.GetDiagnostics() : undefined;
const lines: string[] = [];
lines[lines.length] = string.format(
"【UIManager】打开: %d | 加载中: %d | 缓存: %d | 输入模式: %s | 顶层: %s",
uiDiag.openWindows,
uiDiag.loadingWindows,
uiDiag.cachedWindows,
uiDiag.inputMode,
uiDiag.topWindowName ?? "无"
);
lines[lines.length] = string.format(
"【UIDelegateBridge】活跃 UMG 控件委托数:%d",
activeBindings
);
if (resDiag !== undefined) {
lines[lines.length] = string.format(
"【ResourceService】在途加载: %d | 驻留资产: %d | 总引用计数: %d",
resDiag.nativeInFlight,
resDiag.nativeRetainedAssets,
resDiag.nativeTotalRefCount
);
}
lines[lines.length] = string.format(
"【FrameScheduler】Frame: %d | World: %d | Monotonic: %d",
schedStats.frameTasks,
schedStats.worldTasks,
schedStats.monotonicTasks
);
lines[lines.length] = "--- 活动窗口栈 ---";
for (let i = 0; i < stack.length; i++) {
const s = stack[i];
lines[lines.length] = string.format(
" %d. %s [layer=%s, type=%s, z=%d, vis=%s, block=%s%s]",
i + 1,
s.name,
s.layer,
s.type,
s.zOrder,
s.visible ? "Y" : "N",
s.blockWorldClick ? "Y" : "N",
s.hiddenByFullscreen ? ", hiddenByFull" : ""
);
}
lines[lines.length] =
cachedNames.length > 0
? "--- 缓存池:" + table.concat(cachedNames, ", ")
: "--- 缓存池:空";
this.txtDiagDetail.SetText(table.concat(lines, "\n"));
}
}
public AppendLog(entry: string): void {
const now = this.ctx.scheduler.NowSeconds();
const line = string.format("[%.1fs] %s", now, entry);
this.logLines[this.logLines.length] = line;
if (this.logLines.length > 40) {
table.remove(this.logLines, 1);
}
this.RenderLogText();
}
private RenderLogText(): void {
if (this.txtEventLog !== undefined) {
this.txtEventLog.SetText(
this.logLines.length > 0 ? table.concat(this.logLines, "\n") : "[日志已清空]"
);
}
if (this.scrollEventLog !== undefined && this.scrollEventLog.ScrollToEnd !== undefined) {
this.scrollEventLog.ScrollToEnd();
}
}
}
RegisterUIConfig(UIDemoMainWindow, {
name: "UIDemoMainWindow",
assetKey: ASSET_KEYS.UI_DEMO_MAIN_WIDGET,
singleton: true,
layer: "normal",
type: "normal",
cacheTag: "no_cache",
blockWorldClick: true,
});
@@ -0,0 +1,504 @@
import { ASSET_KEYS } from "../../../framework/resource/asset_catalog";
import type { ResourceService } from "../../../framework/resource/resource_service";
import { RegisterUIConfig } from "../../../framework/ui/ui_config";
import { UIWindow } from "../../../framework/ui/ui_window";
export type DemoLogFn = (this: void, message: string) => void;
// ===== 1. 普通信息窗口 (Normal / Singleton) =====
export interface NormalWindowArgs {
onLog?: DemoLogFn;
}
export class UIDemoNormalWindow extends UIWindow {
public txtNormalTitle?: UE.UTextBlock;
public txtNormalBody?: UE.UTextBlock;
public btnNormalPing?: UE.UButton;
public btnNormalClose?: UE.UButton;
public openOrRefreshCount = 0;
public pingCount = 0;
private onLog?: DemoLogFn;
protected override OnBindWidgets(): void {
this.txtNormalTitle = this.RequireWidget<UE.UTextBlock>("TxtNormalTitle");
this.txtNormalBody = this.RequireWidget<UE.UTextBlock>("TxtNormalBody");
this.btnNormalPing = this.RequireWidget<UE.UButton>("BtnNormalPing");
this.btnNormalClose = this.RequireWidget<UE.UButton>("BtnNormalClose");
this.BindButtonClick(this.btnNormalPing, () => {
this.pingCount = this.pingCount + 1;
this.RefreshBody();
this.EmitLog(string.format("[Normal] 触发交互 #%d", this.pingCount));
});
this.BindButtonClick(this.btnNormalClose, () => {
this.Close();
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as NormalWindowArgs | undefined;
if (a !== undefined && a.onLog !== undefined) {
this.onLog = a.onLog;
}
this.openOrRefreshCount = this.openOrRefreshCount + 1;
this.RefreshBody();
this.EmitLog(string.format("[Normal] OnPreShow(第 %d 次打开/刷新,ZOrder=%d)", this.openOrRefreshCount, this.GetZOrder()));
}
protected override OnClose(): void {
this.EmitLog("[Normal] OnClose 窗口已销毁");
}
private RefreshBody(): void {
if (this.txtNormalBody !== undefined) {
this.txtNormalBody.SetText(
string.format(
"Layer: normal | Type: normal | Singleton: true\n当前 ZOrder:%d | 打开/复用刷新次数:%d | 按钮交互:%d 次\n重复点击左侧「普通窗口」不会创建第二个实例,而是直接刷新本窗。",
this.GetZOrder(),
this.openOrRefreshCount,
this.pingCount
)
);
}
}
private EmitLog(msg: string): void {
if (this.onLog !== undefined) {
this.onLog(msg);
}
}
}
RegisterUIConfig(UIDemoNormalWindow, {
name: "UIDemoNormalWindow",
assetKey: ASSET_KEYS.UI_DEMO_NORMAL_WIDGET,
singleton: true,
layer: "normal",
type: "normal",
cacheTag: "no_cache",
blockWorldClick: true,
});
// ===== 2. 全屏窗口 (Fullscreen,自动隐藏并恢复下层 Normal 窗口) =====
export interface FullscreenWindowArgs {
onLog?: DemoLogFn;
onOpenModal?: (this: void) => void;
}
export class UIDemoFullscreenWindow extends UIWindow {
public txtFullDesc?: UE.UTextBlock;
public imgFullPreview?: UE.UImage;
public btnFullOpenModal?: UE.UButton;
public btnFullClose?: UE.UButton;
private onLog?: DemoLogFn;
private onOpenModal?: (this: void) => void;
protected override OnBindWidgets(): void {
this.txtFullDesc = this.RequireWidget<UE.UTextBlock>("TxtFullDesc");
this.imgFullPreview = this.RequireWidget<UE.UImage>("ImgFullPreview");
this.btnFullOpenModal = this.RequireWidget<UE.UButton>("BtnFullOpenModal");
this.btnFullClose = this.RequireWidget<UE.UButton>("BtnFullClose");
this.BindButtonClick(this.btnFullOpenModal, () => {
if (this.onOpenModal !== undefined) {
this.onOpenModal();
}
});
this.BindButtonClick(this.btnFullClose, () => {
this.Close();
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as FullscreenWindowArgs | undefined;
this.onLog = a !== undefined ? a.onLog : undefined;
this.onOpenModal = a !== undefined ? a.onOpenModal : undefined;
const resSvc = this.ctx.GetService<ResourceService>("resource");
if (resSvc !== undefined) {
resSvc.LoadTextureAsync(ASSET_KEYS.DEMO_BADGE_B_TEX, this, (ok, tex) => {
if (ok && tex !== undefined && this.imgFullPreview !== undefined && !this.IsDisposed()) {
this.imgFullPreview.SetBrushFromTexture(tex, false);
}
});
}
if (this.onLog !== undefined) {
this.onLog(string.format("[Fullscreen] 打开全屏窗口(ZOrder=%d),已自动隐藏下层 Normal 窗口", this.GetZOrder()));
}
}
protected override OnClose(): void {
if (this.onLog !== undefined) {
this.onLog("[Fullscreen] 关闭全屏窗口,自动恢复下层主界面显示");
}
}
}
RegisterUIConfig(UIDemoFullscreenWindow, {
name: "UIDemoFullscreenWindow",
assetKey: ASSET_KEYS.UI_DEMO_FULLSCREEN_WIDGET,
singleton: true,
layer: "normal",
type: "fullscreen",
cacheTag: "no_cache",
blockWorldClick: true,
});
// ===== 3. 模态弹窗 (Popup / Modal,遮罩拦截 + 确认/取消回调) =====
export interface ModalWindowArgs {
title?: string;
message?: string;
onConfirm?: (this: void) => void;
onCancel?: (this: void) => void;
}
export class UIDemoModalWindow extends UIWindow {
public txtModalTitle?: UE.UTextBlock;
public txtModalMessage?: UE.UTextBlock;
public btnModalConfirm?: UE.UButton;
public btnModalCancel?: UE.UButton;
private onConfirm?: (this: void) => void;
private onCancel?: (this: void) => void;
protected override OnBindWidgets(): void {
this.txtModalTitle = this.RequireWidget<UE.UTextBlock>("TxtModalTitle");
this.txtModalMessage = this.RequireWidget<UE.UTextBlock>("TxtModalMessage");
this.btnModalConfirm = this.RequireWidget<UE.UButton>("BtnModalConfirm");
this.btnModalCancel = this.RequireWidget<UE.UButton>("BtnModalCancel");
this.BindButtonClick(this.btnModalConfirm, () => {
const cb = this.onConfirm;
this.Close();
if (cb !== undefined) {
cb();
}
});
this.BindButtonClick(this.btnModalCancel, () => {
const cb = this.onCancel;
this.Close();
if (cb !== undefined) {
cb();
}
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as ModalWindowArgs | undefined;
this.onConfirm = a !== undefined ? a.onConfirm : undefined;
this.onCancel = a !== undefined ? a.onCancel : undefined;
if (this.txtModalTitle !== undefined) {
this.txtModalTitle.SetText(a !== undefined && a.title !== undefined ? a.title : "二次确认模态弹窗");
}
if (this.txtModalMessage !== undefined) {
this.txtModalMessage.SetText(
a !== undefined && a.message !== undefined
? a.message
: "半透明遮罩已拦截底层点击。请选择确认或取消以测试回调透传。"
);
}
}
}
RegisterUIConfig(UIDemoModalWindow, {
name: "UIDemoModalWindow",
assetKey: ASSET_KEYS.UI_DEMO_MODAL_WIDGET,
singleton: true,
layer: "popup",
type: "popup",
cacheTag: "no_cache",
blockWorldClick: true,
});
// ===== 4. 缓存复用窗口 (cacheTag = "cache") =====
export interface CachedWindowArgs {
onLog?: DemoLogFn;
}
export class UIDemoCachedWindow extends UIWindow {
public txtCachedStats?: UE.UTextBlock;
public btnCachedAction?: UE.UButton;
public btnCachedClose?: UE.UButton;
public reuseCount = 0;
public clickCount = 0;
private onLog?: DemoLogFn;
protected override OnBindWidgets(): void {
this.txtCachedStats = this.RequireWidget<UE.UTextBlock>("TxtCachedStats");
this.btnCachedAction = this.RequireWidget<UE.UButton>("BtnCachedAction");
this.btnCachedClose = this.RequireWidget<UE.UButton>("BtnCachedClose");
this.BindButtonClick(this.btnCachedAction, () => {
this.clickCount = this.clickCount + 1;
this.RefreshStats();
this.EmitLog(string.format("[Cached] 点击按钮(累计 %d 次,严格 +1 无重复绑定)", this.clickCount));
});
this.BindButtonClick(this.btnCachedClose, () => {
this.Close();
});
}
protected override OnReuseUI(): void {
this.reuseCount = this.reuseCount + 1;
this.EmitLog(string.format("[Cached] OnReuseUI 命中缓存秒开(第 %d 次复用)", this.reuseCount));
}
protected override OnPreShow(args?: unknown): void {
const a = args as CachedWindowArgs | undefined;
if (a !== undefined && a.onLog !== undefined) {
this.onLog = a.onLog;
}
this.RefreshStats();
if (this.reuseCount === 0) {
this.EmitLog("[Cached] 首次实例化创建成功");
}
}
protected override OnClose(): void {
this.EmitLog("[Cached] 关闭并归还缓存池(委托已自动解绑)");
}
private RefreshStats(): void {
if (this.txtCachedStats !== undefined) {
this.txtCachedStats.SetText(
string.format(
"缓存复用次数 (OnReuseUI):%d 次\n按钮累计点击:%d 次 | 当前 ZOrder:%d\n关闭后窗口实例进入缓存池,再次打开不重新创建 Widget,且按钮点击不会重复触发。",
this.reuseCount,
this.clickCount,
this.GetZOrder()
)
);
}
}
private EmitLog(msg: string): void {
if (this.onLog !== undefined) {
this.onLog(msg);
}
}
}
RegisterUIConfig(UIDemoCachedWindow, {
name: "UIDemoCachedWindow",
assetKey: ASSET_KEYS.UI_DEMO_CACHED_WIDGET,
singleton: true,
layer: "popup",
type: "normal",
cacheTag: "cache",
blockWorldClick: true,
});
// ===== 5. 多实例浮窗 (singleton = false) =====
export interface MultiWindowArgs {
instanceSeq: number;
onLog?: DemoLogFn;
}
export class UIDemoMultiWindow extends UIWindow {
public multiCard?: UE.UBorder;
public txtMultiTitle?: UE.UTextBlock;
public txtMultiBody?: UE.UTextBlock;
public btnMultiCount?: UE.UButton;
public btnMultiClose?: UE.UButton;
public instanceSeq = 1;
public localCount = 0;
private onLog?: DemoLogFn;
protected override OnBindWidgets(): void {
this.multiCard = this.RequireWidget<UE.UBorder>("MultiCard");
this.txtMultiTitle = this.RequireWidget<UE.UTextBlock>("TxtMultiTitle");
this.txtMultiBody = this.RequireWidget<UE.UTextBlock>("TxtMultiBody");
this.btnMultiCount = this.RequireWidget<UE.UButton>("BtnMultiCount");
this.btnMultiClose = this.RequireWidget<UE.UButton>("BtnMultiClose");
this.BindButtonClick(this.btnMultiCount, () => {
this.localCount = this.localCount + 1;
this.RefreshDisplay();
this.EmitLog(string.format("[Multi #%d] 独立计数 -> %d", this.instanceSeq, this.localCount));
});
this.BindButtonClick(this.btnMultiClose, () => {
this.Close();
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as MultiWindowArgs | undefined;
this.instanceSeq = a !== undefined ? a.instanceSeq : 1;
this.onLog = a !== undefined ? a.onLog : undefined;
// 按实例序号错位排布,便于视觉区分多个并发实例
const slotIndex = (this.instanceSeq - 1) % 6;
const offsetX = -150 + slotIndex * 60;
const offsetY = -90 + slotIndex * 38;
if (this.multiCard !== undefined && UE !== undefined && UE.ULuaUIEventSubsystem !== undefined) {
const pos = UE.FVector2D();
pos.X = offsetX;
pos.Y = offsetY;
UE.ULuaUIEventSubsystem.SetCanvasPosition(this.multiCard, pos);
}
this.RefreshDisplay();
this.EmitLog(string.format("[Multi #%d] 多实例打开(ZOrder=%d)", this.instanceSeq, this.GetZOrder()));
}
protected override OnClose(): void {
this.EmitLog(string.format("[Multi #%d] 已独立关闭", this.instanceSeq));
}
private RefreshDisplay(): void {
if (this.txtMultiTitle !== undefined) {
this.txtMultiTitle.SetText(string.format("多实例便签窗 #%d", this.instanceSeq));
}
if (this.txtMultiBody !== undefined) {
this.txtMultiBody.SetText(
string.format(
"singleton = false | ZOrder = %d\n本实例独立计数:%d\n可连续点击「多实例窗」同时存在多个窗口。",
this.GetZOrder(),
this.localCount
)
);
}
}
private EmitLog(msg: string): void {
if (this.onLog !== undefined) {
this.onLog(msg);
}
}
}
RegisterUIConfig(UIDemoMultiWindow, {
name: "UIDemoMultiWindow",
assetKey: ASSET_KEYS.UI_DEMO_MULTI_WIDGET,
singleton: false,
layer: "popup",
type: "normal",
cacheTag: "no_cache",
blockWorldClick: true,
});
// ===== 6. 飘字提示 Toast (layer = "tips", blockWorldClick = false, 自动消失) =====
export interface ToastWindowArgs {
message: string;
durationSec?: number;
offsetIndex?: number;
onLog?: DemoLogFn;
}
export class UIDemoToastWindow extends UIWindow {
public toastPill?: UE.UBorder;
public txtToastMessage?: UE.UTextBlock;
private onLog?: DemoLogFn;
protected override OnBindWidgets(): void {
this.toastPill = this.RequireWidget<UE.UBorder>("ToastPill");
this.txtToastMessage = this.RequireWidget<UE.UTextBlock>("TxtToastMessage");
}
protected override OnPreShow(args?: unknown): void {
const a = args as ToastWindowArgs | undefined;
const msg = a !== undefined ? a.message : "飘字通知";
const duration = a !== undefined && a.durationSec !== undefined ? a.durationSec : 2.2;
const offsetIdx = a !== undefined && a.offsetIndex !== undefined ? a.offsetIndex : 0;
this.onLog = a !== undefined ? a.onLog : undefined;
if (this.txtToastMessage !== undefined) {
this.txtToastMessage.SetText(msg);
}
if (this.toastPill !== undefined && UE !== undefined && UE.ULuaUIEventSubsystem !== undefined) {
const pos = UE.FVector2D();
pos.X = 0;
pos.Y = 92 + (offsetIdx % 4) * 48;
UE.ULuaUIEventSubsystem.SetCanvasPosition(this.toastPill, pos);
}
// 使用 WorldTimer 定时自动关闭,切图或手动关闭时通过 owner=this 自动取消
this.ctx.scheduler.AddWorldTimer(
duration,
() => {
this.Close();
},
this
);
if (this.onLog !== undefined) {
this.onLog(string.format("[Toast] 弹出提示:%s(%.1fs 后自动关闭,不抢焦点)", msg, duration));
}
}
}
RegisterUIConfig(UIDemoToastWindow, {
name: "UIDemoToastWindow",
assetKey: ASSET_KEYS.UI_DEMO_TOAST_WIDGET,
singleton: false,
layer: "tips",
type: "popup",
cacheTag: "no_cache",
blockWorldClick: false,
});
// ===== 7. 系统顶层弹窗 (layer = "system", ZOrder 400+) =====
export interface SystemWindowArgs {
onLog?: DemoLogFn;
}
export class UIDemoSystemWindow extends UIWindow {
public txtSystemBody?: UE.UTextBlock;
public btnSystemAck?: UE.UButton;
private onLog?: DemoLogFn;
protected override OnBindWidgets(): void {
this.txtSystemBody = this.RequireWidget<UE.UTextBlock>("TxtSystemBody");
this.btnSystemAck = this.RequireWidget<UE.UButton>("BtnSystemAck");
this.BindButtonClick(this.btnSystemAck, () => {
this.Close();
});
}
protected override OnPreShow(args?: unknown): void {
const a = args as SystemWindowArgs | undefined;
this.onLog = a !== undefined ? a.onLog : undefined;
if (this.txtSystemBody !== undefined) {
this.txtSystemBody.SetText(
string.format(
"Layer: system | ZOrder: %d\n优先级始终高于 normal / popup / tips 全部层级,常用于断线重连或强制系统公告。",
this.GetZOrder()
)
);
}
if (this.onLog !== undefined) {
this.onLog(string.format("[System] 打开系统级顶层弹窗(ZOrder=%d)", this.GetZOrder()));
}
}
protected override OnClose(): void {
if (this.onLog !== undefined) {
this.onLog("[System] 已确认关闭系统弹窗");
}
}
}
RegisterUIConfig(UIDemoSystemWindow, {
name: "UIDemoSystemWindow",
assetKey: ASSET_KEYS.UI_DEMO_SYSTEM_WIDGET,
singleton: true,
layer: "system",
type: "popup",
cacheTag: "no_cache",
blockWorldClick: true,
});
+189
View File
@@ -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);
@@ -257,6 +257,54 @@ RegisterUIConfig(CachedTestWindow, {
cacheTag: "cache",
});
class FullscreenTestWindow extends UIWindow {
protected override OnBindWidgets(): void {
this.RequireWidget("BtnClose");
}
}
RegisterUIConfig(FullscreenTestWindow, {
name: "FullscreenTestWindow",
assetKey: ASSET_KEYS.MINI_SETTINGS_WIDGET,
singleton: true,
layer: "normal",
type: "fullscreen",
cacheTag: "no_cache",
blockWorldClick: true,
});
class ToastTestWindow extends UIWindow {
protected override OnBindWidgets(): void {
this.RequireWidget("TxtStatus");
}
}
RegisterUIConfig(ToastTestWindow, {
name: "ToastTestWindow",
assetKey: ASSET_KEYS.MINI_SETTINGS_WIDGET,
singleton: false,
layer: "tips",
type: "popup",
cacheTag: "no_cache",
blockWorldClick: false,
});
class SystemTestWindow extends UIWindow {
protected override OnBindWidgets(): void {
this.RequireWidget("BtnClose");
}
}
RegisterUIConfig(SystemTestWindow, {
name: "SystemTestWindow",
assetKey: ASSET_KEYS.MINI_SETTINGS_WIDGET,
singleton: true,
layer: "system",
type: "popup",
cacheTag: "no_cache",
blockWorldClick: true,
});
export function CreateUIAndResourceSuite(): TestSuite {
return {
name: "Step2B_3.UIAndResource",
@@ -385,6 +433,63 @@ export function CreateUIAndResourceSuite(): TestSuite {
ctx.Dispose();
},
},
{
name: "UIManager fullscreen auto-hide/restore, non-blocking tips focus preservation, and layer ZOrder priority",
fn: () => {
const ctx = new GameInstanceContext();
const resBackend = new MockResourceBackend();
const resSvc = new ResourceService(ctx, resBackend);
resBackend.service = resSvc;
const btnBackend = new MockButtonBackend();
const btnBridge = new UIDelegateBridge(ctx, btnBackend);
btnBackend.bridge = btnBridge;
ctx.RegisterService("resource", resSvc);
ctx.RegisterService("uiDelegateBridge", btnBridge);
const widgetFactory = new MockWidgetFactory();
const lp = ctx.GetOrCreateLocalPlayer(0);
const uiMgr = lp.RegisterService(
"uiManager",
new UIManager(ctx, lp, resSvc, widgetFactory, new MockWidgetAdapter())
);
// 1. Open base normal window (blocking)
const baseWin = uiMgr.ShowUI(CachedTestWindow)!;
resBackend.FlushAll();
Assert(baseWin.IsVisible(), "base window visible");
AssertEqual(uiMgr.GetDiagnostics().inputMode, "ui");
// 2. Open non-blocking tips toast -> must NOT drop inputMode back to game
const toast1 = uiMgr.ShowUI(ToastTestWindow)!;
resBackend.FlushAll();
AssertEqual(uiMgr.GetDiagnostics().inputMode, "ui", "non-blocking tips preserves underlying UI input mode");
AssertEqual(uiMgr.GetDiagnostics().topWindowName, "ToastTestWindow", "tips has higher ZOrder than normal");
toast1.Close();
// 3. Open fullscreen window -> hides underlying normal window, restores on close
const fullWin = uiMgr.ShowUI(FullscreenTestWindow)!;
resBackend.FlushAll();
Assert(!baseWin.IsVisible(), "base window hidden while fullscreen is active");
Assert(baseWin.IsHiddenByFullscreen(), "base window marked hiddenByFullscreen");
// 4. Open system window on top -> highest layer ZOrder wins GetTopWindow
const sysWin = uiMgr.ShowUI(SystemTestWindow)!;
resBackend.FlushAll();
AssertEqual(uiMgr.GetDiagnostics().topWindowName, "SystemTestWindow");
// CloseAllExcept(baseWin) closes fullscreen + system and restores baseWin
const closedCount = uiMgr.CloseAllExcept(baseWin, false);
AssertEqual(closedCount, 2, "closed fullscreen and system windows");
Assert(baseWin.IsVisible(), "base window restored after fullscreen closed");
Assert(!baseWin.IsHiddenByFullscreen(), "hiddenByFullscreen cleared");
uiMgr.CloseAll(true);
AssertEqual(uiMgr.GetDiagnostics().openWindows, 0);
AssertEqual(btnBackend.GetActiveBindingCount(), 0);
AssertEqual(resSvc.GetDiagnostics().nativeTotalRefCount, 0);
ctx.Dispose();
},
},
],
};
}
+152
View File
@@ -0,0 +1,152 @@
// Auto-generated by UnLua TypeScript Generator (Generate IntelliSense & TS).
// Do not edit manually. Excludes runtime types owned by unlua.d.ts.
declare namespace UE {
class WBP_DemoHub_C extends UUserWidget {
TxtRuntimeInfo: UTextBlock;
TxtHubTitle: UTextBlock;
TxtHubSubtitle: UTextBlock;
ScrollDemoList: UScrollBox;
BtnOpenMiniSettings: UButton;
static StaticClass(this: void): UClass;
}
class WBP_DemoHubItem_C extends UUserWidget {
TxtEnterLabel: UTextBlock;
TxtDemoTitle: UTextBlock;
TxtDemoMeta: UTextBlock;
TxtDemoDesc: UTextBlock;
CardBorder: UBorder;
BtnEnterDemo: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoCached_C extends UUserWidget {
TxtCachedTitle: UTextBlock;
TxtCachedStats: UTextBlock;
BtnCachedClose: UButton;
BtnCachedAction: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoFullscreen_C extends UUserWidget {
TxtFullTitle: UTextBlock;
TxtFullDesc: UTextBlock;
ImgFullPreview: UImage;
BtnFullOpenModal: UButton;
BtnFullClose: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoListItem_C extends UUserWidget {
TxtItemTitle: UTextBlock;
BtnItemDelete: UButton;
BtnItemAction: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoMain_C extends UUserWidget {
TxtSpinStatus: UTextBlock;
TxtSliderStatus: UTextBlock;
TxtRichSample: UTextBlock;
TxtProgressPlay: UTextBlock;
TxtPlayerName: UTextBlock;
TxtListSummary: UTextBlock;
TxtInputStatus: UTextBlock;
TxtImageStatus: UTextBlock;
TxtHudStats: UTextBlock;
TxtEventLog: UTextBlock;
TxtDiagDetail: UTextBlock;
TxtDemoTarget: UTextBlock;
TxtComboStatus: UTextBlock;
TxtCheckStatus: UTextBlock;
TxtBasicBtnStatus: UTextBlock;
TabSwitcher: UWidgetSwitcher;
SpinDemo: USpinBox;
SliderDemo: USlider;
ScrollEventLog: UScrollBox;
ScrollDynamicList: UScrollBox;
ProgressDemo: UProgressBar;
InputNickname: UEditableTextBox;
ImgPreview: UImage;
ImgPlayerAvatar: UImage;
GridBadges: UUniformGridPanel;
ComboTheme: UComboBoxString;
ChkFeature: UCheckBox;
BtnWinToast: UButton;
BtnWinSystem: UButton;
BtnWinNormal: UButton;
BtnWinMulti: UButton;
BtnWinModal: UButton;
BtnWinFullscreen: UButton;
BtnWinCached: UButton;
BtnTopSettings: UButton;
BtnToggleDisable: UButton;
BtnTintTex: UButton;
BtnTabMedia: UButton;
BtnTabInput: UButton;
BtnTabDiag: UButton;
BtnTabBasic: UButton;
BtnSwitchTex: UButton;
BtnProgressReset: UButton;
BtnProgressPlay: UButton;
BtnListClear: UButton;
BtnListAddTen: UButton;
BtnListAddOne: UButton;
BtnEvictCache: UButton;
BtnDiagRefresh: UButton;
BtnDiagConcurrent: UButton;
BtnDiagCancelLoad: UButton;
BtnDemoTarget: UButton;
BtnDemoAction: UButton;
BtnCycleVis: UButton;
BtnCycleTextSize: UButton;
BtnCycleTextColor: UButton;
BtnCloseOthers: UButton;
BtnClearLog: UButton;
BtnBackToHub: UButton;
BtnApplyNickname: UButton;
BorderThemePreview: UBorder;
BarPlayerExp: UProgressBar;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoModal_C extends UUserWidget {
TxtModalTitle: UTextBlock;
TxtModalMessage: UTextBlock;
BtnModalConfirm: UButton;
BtnModalCancel: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoMulti_C extends UUserWidget {
TxtMultiTitle: UTextBlock;
TxtMultiBody: UTextBlock;
MultiCard: UBorder;
BtnMultiCount: UButton;
BtnMultiClose: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoNormal_C extends UUserWidget {
TxtNormalTitle: UTextBlock;
TxtNormalBody: UTextBlock;
BtnNormalPing: UButton;
BtnNormalClose: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoSystem_C extends UUserWidget {
TxtSystemTitle: UTextBlock;
TxtSystemBody: UTextBlock;
BtnSystemAck: UButton;
static StaticClass(this: void): UClass;
}
class WBP_UIDemoToast_C extends UUserWidget {
TxtToastMessage: UTextBlock;
ToastPill: UBorder;
static StaticClass(this: void): UClass;
}
}
+50 -3
View File
@@ -64,8 +64,24 @@ declare namespace UE {
static StaticClass(this: void): UClass;
}
class ULuaButtonClickProxy extends UObject {
HandleClicked(): void;
class ULuaButtonClickProxy extends ULuaWidgetEventProxyBase {
HandleEvent(): void;
static StaticClass(this: void): UClass;
}
class ULuaCheckBoxProxy extends ULuaWidgetEventProxyBase {
HandleCheckStateChanged(bIsChecked: boolean): void;
static StaticClass(this: void): UClass;
}
class ULuaComboBoxProxy extends ULuaWidgetEventProxyBase {
HandleSelectionChanged(SelectedItem: string, SelectionType: ESelectInfo): void;
static StaticClass(this: void): UClass;
}
class ULuaEditableTextProxy extends ULuaWidgetEventProxyBase {
HandleTextCommitted(Text: string, CommitMethod: ETextCommit): void;
HandleTextChanged(Text: string): void;
static StaticClass(this: void): UClass;
}
@@ -128,6 +144,16 @@ declare namespace UE {
static StaticClass(this: void): UClass;
}
class ULuaSliderProxy extends ULuaWidgetEventProxyBase {
HandleValueChanged(Value: number): void;
static StaticClass(this: void): UClass;
}
class ULuaSpinBoxProxy extends ULuaWidgetEventProxyBase {
HandleValueChanged(Value: number): void;
static StaticClass(this: void): UClass;
}
class ULuaStorageLibrary extends UBlueprintFunctionLibrary {
static WriteCorruptRawSlotForTest(this: void, SlotName: string, RawGarbage: string, UserIndex?: number): boolean;
static SaveSlotUtf8(this: void, SlotName: string, PayloadUtf8: string, UserIndex?: number): ELuaStorageStatus;
@@ -140,14 +166,35 @@ declare namespace UE {
}
class ULuaUIEventSubsystem extends UGameInstanceSubsystem {
ActiveButtonProxies: TMap<number, ULuaButtonClickProxy>;
ActiveProxies: TMap<number, ULuaWidgetEventProxyBase>;
UnbindWidgetEvent(BindingId: number): boolean;
UnbindButtonClicked(BindingId: number): boolean;
static SimulateSpinBoxValue(this: void, SpinBox: USpinBox | undefined, Value: number): boolean;
static SimulateSliderValue(this: void, Slider: USlider | undefined, Value: number): boolean;
static SimulateEditableTextCommit(this: void, TextBox: UEditableTextBox | undefined, NewText: string, CommitMethod: number): boolean;
static SimulateEditableTextChange(this: void, TextBox: UEditableTextBox | undefined, NewText: string): boolean;
static SimulateComboBoxSelect(this: void, ComboBox: UComboBoxString | undefined, Option: string): boolean;
static SimulateCheckBoxToggle(this: void, CheckBox: UCheckBox | undefined, bIsChecked: boolean): boolean;
static SimulateButtonHover(this: void, Button: UButton | undefined, bHovered: boolean): boolean;
static SimulateButtonClick(this: void, Button: UButton | undefined): boolean;
static SetCanvasPosition(this: void, Widget: UWidget | undefined, Position: FVector2D): boolean;
static GetFromGameInstance(this: void, GameInstance: UGameInstance | undefined): ULuaUIEventSubsystem;
GetActiveBindingCount(): number;
static FindChildWidgetByName(this: void, RootWidget: UUserWidget | undefined, WidgetName: string): UWidget;
BindSpinBoxChanged(SpinBox: USpinBox | undefined): number;
BindSliderChanged(Slider: USlider | undefined): number;
BindEditableTextCommitted(TextBox: UEditableTextBox | undefined): number;
BindEditableTextChanged(TextBox: UEditableTextBox | undefined): number;
BindComboBoxSelectionChanged(ComboBox: UComboBoxString | undefined): number;
BindCheckBoxChanged(CheckBox: UCheckBox | undefined): number;
BindButtonUnhovered(Button: UButton | undefined): number;
BindButtonHovered(Button: UButton | undefined): number;
BindButtonClicked(Button: UButton | undefined): number;
static StaticClass(this: void): UClass;
}
class ULuaWidgetEventProxyBase extends UObject {
static StaticClass(this: void): UClass;
}
}