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

+249
View File
@@ -15,6 +15,19 @@ local M__game_setting_mini_settings_window = __MODULE__.Import("game.setting.min
local MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
local M__game_setting_setting_service = __MODULE__.Import("game.setting.setting_service", __module)
local SettingService = M__game_setting_setting_service.SettingService
local M__game_demo_demo_hub_window = __MODULE__.Import("game.demo.demo_hub_window", __module)
local DemoHubWindow = M__game_demo_demo_hub_window.DemoHubWindow
local M__game_demo_demo_router = __MODULE__.Import("game.demo.demo_router", __module)
local OpenDemoHub = M__game_demo_demo_router.OpenDemoHub
local OpenUIDemoMain = M__game_demo_demo_router.OpenUIDemoMain
local M__game_demo_ui_demo_ui_demo_windows = __MODULE__.Import("game.demo.ui_demo.ui_demo_windows", __module)
local UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
local UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
local UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
local UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
local UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
local UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
local UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
local M__game_startup = __MODULE__.Import("game.startup", __module)
local GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
local M__share_base_scoped_object = __MODULE__.Import("share.base.scoped_object", __module)
@@ -387,6 +400,232 @@ function ____exports.RunAllUETests(gameInstance, world)
UE.ULuaStorageLibrary.DeleteSlot("sdata", 0, true)
end
}}
},
{
name = "UE.DemoHubAndUIDemo",
cases = {
{
name = "Bootstrap DemoHubWindow loads Chinese UMG cards and cleans up with zero leaks",
fn = function()
Assert(gameInstance ~= nil and world ~= nil, "GI & World required")
local ctx = GetGameInstanceContext(gameInstance)
local uiMgr = GetPrimaryUIManager(ctx)
local resSvc = ctx:GetService("resource")
local uiBridge = ctx:GetService("uiDelegateBridge")
ctx:OnWorldCleanup(world)
local hubOpened = false
local hub = OpenDemoHub(
ctx,
function(ok)
hubOpened = ok
end
)
Assert(hub ~= nil, "DemoHubWindow controller created")
PumpUEFrames(25, 0.02)
Assert(
hubOpened and hub:IsLoaded(),
"DemoHubWindow loaded"
)
Assert(#hub.itemWidgets >= 1, "DemoHub dynamically populated demo cards")
Assert(hub.itemEnterButtons.ui_demo ~= nil, "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"
)
end
},
{
name = "UIDemoMainWindow exercises all UMG widgets and all 7 window types with zero leaks",
fn = function()
Assert(gameInstance ~= nil and world ~= nil, "GI & World required")
local ctx = GetGameInstanceContext(gameInstance)
local uiMgr = GetPrimaryUIManager(ctx)
local resSvc = ctx:GetService("resource")
local uiBridge = ctx:GetService("uiDelegateBridge")
ctx:OnWorldCleanup(world)
local mainOpened = false
local mainWin = OpenUIDemoMain(
ctx,
function(ok)
mainOpened = ok
end
)
Assert(mainWin ~= nil, "UIDemoMainWindow created")
PumpUEFrames(30, 0.02)
Assert(
mainOpened and mainWin:IsLoaded(),
"UIDemoMainWindow loaded"
)
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, "翡翠绿(稀有)")
local 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"
)
local norm1 = mainWin:OpenNormalDemoWindow()
local norm2 = mainWin:OpenNormalDemoWindow()
AssertEqual(norm1, norm2, "Normal window is singleton")
local fullWin = mainWin:OpenFullscreenDemoWindow()
local modalConfirmed = false
local modalWin = uiMgr:ShowUI(
UIDemoModalWindow,
{
title = "测试弹窗",
message = "测试模态确认",
onConfirm = function()
modalConfirmed = true
end
}
)
local cachedWin = mainWin:OpenCachedDemoWindow()
local multi1 = mainWin:OpenMultiDemoWindow()
local multi2 = mainWin:OpenMultiDemoWindow()
Assert(multi1 ~= multi2, "Multi-instance creates distinct windows")
local sysWin = mainWin:OpenSystemDemoWindow()
local toastWin = mainWin:ShowToast("自动测试飘字", 0.1)
PumpUEFrames(30, 0.02)
Assert(
toastWin:IsDisposed(),
"Toast auto-closed via WorldTimer"
)
Assert(
not 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"
)
Assert(
UE.ULuaUIEventSubsystem.SimulateButtonClick(modalWin.btnModalConfirm),
"Click Modal Confirm"
)
Assert(modalConfirmed, "Modal confirm callback fired")
Assert(
modalWin:IsDisposed(),
"Modal disposed after confirm"
)
Assert(
UE.ULuaUIEventSubsystem.SimulateButtonClick(cachedWin.btnCachedAction),
"Cached click #1"
)
AssertEqual(cachedWin.clickCount, 1)
cachedWin:Close()
Assert(
cachedWin:IsCached(),
"Cached window moved to cache"
)
local 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")
fullWin:Close()
Assert(
mainWin:IsVisible(),
"MainWindow automatically restored after Fullscreen closed"
)
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"
)
Assert(DemoHubWindow ~= nil and UIDemoNormalWindow ~= nil and UIDemoFullscreenWindow ~= nil and UIDemoCachedWindow ~= nil and UIDemoMultiWindow ~= nil and UIDemoToastWindow ~= nil and UIDemoSystemWindow ~= nil, "all demo window classes registered")
end
}
}
}
}
local summary = RunSuites(suites)
@@ -401,6 +640,16 @@ function __module.UpdateImports()
UEStorageBackend = M__framework_storage_storage_backend.UEStorageBackend
MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
SettingService = M__game_setting_setting_service.SettingService
DemoHubWindow = M__game_demo_demo_hub_window.DemoHubWindow
OpenDemoHub = M__game_demo_demo_router.OpenDemoHub
OpenUIDemoMain = M__game_demo_demo_router.OpenUIDemoMain
UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
ScopedObject = M__share_base_scoped_object.ScopedObject
Assert = M__tests_harness_test_runner.Assert