feat(demo): add Bootstrap Demo Hub, Chinese UI font, and UI Demo showcase scene
This commit is contained in:
1 parent
3572f2da43
commit
4c83c086f4
49 files changed
+7864
-131
No files matched your search
@@ -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
|
||||
|
||||
@@ -302,6 +302,51 @@ RegisterUIConfig(CachedTestWindow, {
|
||||
layer = "normal",
|
||||
cacheTag = "cache"
|
||||
})
|
||||
local FullscreenTestWindow = __TS__DefineClass("FullscreenTestWindow", __module)
|
||||
FullscreenTestWindow.name = "FullscreenTestWindow"
|
||||
__TS__ClassExtends(FullscreenTestWindow, UIWindow)
|
||||
function FullscreenTestWindow.prototype.OnBindWidgets(self)
|
||||
self:RequireWidget("BtnClose")
|
||||
end
|
||||
RegisterUIConfig(FullscreenTestWindow, {
|
||||
name = "FullscreenTestWindow",
|
||||
assetKey = ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
||||
singleton = true,
|
||||
layer = "normal",
|
||||
type = "fullscreen",
|
||||
cacheTag = "no_cache",
|
||||
blockWorldClick = true
|
||||
})
|
||||
local ToastTestWindow = __TS__DefineClass("ToastTestWindow", __module)
|
||||
ToastTestWindow.name = "ToastTestWindow"
|
||||
__TS__ClassExtends(ToastTestWindow, UIWindow)
|
||||
function ToastTestWindow.prototype.OnBindWidgets(self)
|
||||
self:RequireWidget("TxtStatus")
|
||||
end
|
||||
RegisterUIConfig(ToastTestWindow, {
|
||||
name = "ToastTestWindow",
|
||||
assetKey = ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
||||
singleton = false,
|
||||
layer = "tips",
|
||||
type = "popup",
|
||||
cacheTag = "no_cache",
|
||||
blockWorldClick = false
|
||||
})
|
||||
local SystemTestWindow = __TS__DefineClass("SystemTestWindow", __module)
|
||||
SystemTestWindow.name = "SystemTestWindow"
|
||||
__TS__ClassExtends(SystemTestWindow, UIWindow)
|
||||
function SystemTestWindow.prototype.OnBindWidgets(self)
|
||||
self:RequireWidget("BtnClose")
|
||||
end
|
||||
RegisterUIConfig(SystemTestWindow, {
|
||||
name = "SystemTestWindow",
|
||||
assetKey = ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
||||
singleton = true,
|
||||
layer = "system",
|
||||
type = "popup",
|
||||
cacheTag = "no_cache",
|
||||
blockWorldClick = true
|
||||
})
|
||||
function ____exports.CreateUIAndResourceSuite()
|
||||
return {
|
||||
name = "Step2B_3.UIAndResource",
|
||||
@@ -467,6 +512,96 @@ function ____exports.CreateUIAndResourceSuite()
|
||||
)
|
||||
ctx:Dispose()
|
||||
end
|
||||
},
|
||||
{
|
||||
name = "UIManager fullscreen auto-hide/restore, non-blocking tips focus preservation, and layer ZOrder priority",
|
||||
fn = function()
|
||||
local ctx = __TS__New(GameInstanceContext)
|
||||
local resBackend = __TS__New(MockResourceBackend)
|
||||
local resSvc = __TS__New(ResourceService, ctx, resBackend)
|
||||
resBackend.service = resSvc
|
||||
local btnBackend = __TS__New(MockButtonBackend)
|
||||
local btnBridge = __TS__New(UIDelegateBridge, ctx, btnBackend)
|
||||
btnBackend.bridge = btnBridge
|
||||
ctx:RegisterService("resource", resSvc)
|
||||
ctx:RegisterService("uiDelegateBridge", btnBridge)
|
||||
local widgetFactory = __TS__New(MockWidgetFactory)
|
||||
local lp = ctx:GetOrCreateLocalPlayer(0)
|
||||
local uiMgr = lp:RegisterService(
|
||||
"uiManager",
|
||||
__TS__New(
|
||||
UIManager,
|
||||
ctx,
|
||||
lp,
|
||||
resSvc,
|
||||
widgetFactory,
|
||||
__TS__New(MockWidgetAdapter)
|
||||
)
|
||||
)
|
||||
local baseWin = uiMgr:ShowUI(CachedTestWindow)
|
||||
resBackend:FlushAll()
|
||||
Assert(
|
||||
baseWin:IsVisible(),
|
||||
"base window visible"
|
||||
)
|
||||
AssertEqual(
|
||||
uiMgr:GetDiagnostics().inputMode,
|
||||
"ui"
|
||||
)
|
||||
local 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()
|
||||
local fullWin = uiMgr:ShowUI(FullscreenTestWindow)
|
||||
resBackend:FlushAll()
|
||||
Assert(
|
||||
not baseWin:IsVisible(),
|
||||
"base window hidden while fullscreen is active"
|
||||
)
|
||||
Assert(
|
||||
baseWin:IsHiddenByFullscreen(),
|
||||
"base window marked hiddenByFullscreen"
|
||||
)
|
||||
local sysWin = uiMgr:ShowUI(SystemTestWindow)
|
||||
resBackend:FlushAll()
|
||||
AssertEqual(
|
||||
uiMgr:GetDiagnostics().topWindowName,
|
||||
"SystemTestWindow"
|
||||
)
|
||||
local closedCount = uiMgr:CloseAllExcept(baseWin, false)
|
||||
AssertEqual(closedCount, 2, "closed fullscreen and system windows")
|
||||
Assert(
|
||||
baseWin:IsVisible(),
|
||||
"base window restored after fullscreen closed"
|
||||
)
|
||||
Assert(
|
||||
not baseWin:IsHiddenByFullscreen(),
|
||||
"hiddenByFullscreen cleared"
|
||||
)
|
||||
uiMgr:CloseAll(true)
|
||||
AssertEqual(
|
||||
uiMgr:GetDiagnostics().openWindows,
|
||||
0
|
||||
)
|
||||
AssertEqual(
|
||||
btnBackend:GetActiveBindingCount(),
|
||||
0
|
||||
)
|
||||
AssertEqual(
|
||||
resSvc:GetDiagnostics().nativeTotalRefCount,
|
||||
0
|
||||
)
|
||||
ctx:Dispose()
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user