94 lines
4.0 KiB
Lua
94 lines
4.0 KiB
Lua
local ____exports = __module.env
|
||||
|
|
local M__share_base_logger = __MODULE__.Import("share.base.logger", __module)
|
|||
|
|
local Logger = M__share_base_logger.Logger
|
|||
|
|
local M__game_startup = __MODULE__.Import("game.startup", __module)
|
|||
|
|
local GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
|
|||
|
|
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_registry = __MODULE__.Import("game.demo.demo_registry", __module)
|
|||
|
|
local BOOTSTRAP_MAP_NAME = M__game_demo_demo_registry.BOOTSTRAP_MAP_NAME
|
|||
|
|
local BOOTSTRAP_MAP_PATH = M__game_demo_demo_registry.BOOTSTRAP_MAP_PATH
|
|||
|
|
local FindDemoSceneById = M__game_demo_demo_registry.FindDemoSceneById
|
|||
|
|
local UI_DEMO_MAP_NAME = M__game_demo_demo_registry.UI_DEMO_MAP_NAME
|
|||
|
|
local M__game_demo_ui_demo_ui_demo_main_window = __MODULE__.Import("game.demo.ui_demo.ui_demo_main_window", __module)
|
|||
|
|
local UIDemoMainWindow = M__game_demo_ui_demo_ui_demo_main_window.UIDemoMainWindow
|
|||
|
|
local logger
|
|||
|
|
function ____exports.SwitchToDemoById(ctx, demoId)
|
|||
|
|
local demo = FindDemoSceneById(demoId)
|
|||
|
|
if demo == nil or not demo.enabled then
|
|||
|
|
logger:Warn("Demo scene unavailable or disabled", {demoId = demoId})
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
local worldContext = ctx:GetWorldContext().world or ctx:GetOrCreateLocalPlayer(0).playerController
|
|||
|
|
if worldContext == nil then
|
|||
|
|
logger:Error("Cannot OpenLevel: no valid WorldContext", {demoId = demoId})
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
logger:Info("Switching to demo level", {demoId = demo.id, map = demo.mapAssetPath})
|
|||
|
|
UE.UGameplayStatics.OpenLevel(worldContext, demo.mapAssetPath, true, "")
|
|||
|
|
return true
|
|||
|
|
end
|
|||
|
|
function ____exports.ReturnToBootstrap(ctx)
|
|||
|
|
local worldContext = ctx:GetWorldContext().world or ctx:GetOrCreateLocalPlayer(0).playerController
|
|||
|
|
if worldContext == nil then
|
|||
|
|
logger:Error("Cannot return to Bootstrap: no valid WorldContext")
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
logger:Info("Returning to Bootstrap Hub", {map = BOOTSTRAP_MAP_PATH})
|
|||
|
|
UE.UGameplayStatics.OpenLevel(worldContext, BOOTSTRAP_MAP_PATH, true, "")
|
|||
|
|
return true
|
|||
|
|
end
|
|||
|
|
logger = Logger("DemoRouter")
|
|||
|
|
function ____exports.OpenDemoHub(ctx, onOpened)
|
|||
|
|
local uiMgr = GetPrimaryUIManager(ctx)
|
|||
|
|
if uiMgr == nil then
|
|||
|
|
return nil
|
|||
|
|
end
|
|||
|
|
return uiMgr:ShowUI(
|
|||
|
|
DemoHubWindow,
|
|||
|
|
{onSelectDemo = function(demo)
|
|||
|
|
____exports.SwitchToDemoById(ctx, demo.id)
|
|||
|
|
end},
|
|||
|
|
onOpened
|
|||
|
|
)
|
|||
|
|
end
|
|||
|
|
function ____exports.OpenUIDemoMain(ctx, onOpened)
|
|||
|
|
local uiMgr = GetPrimaryUIManager(ctx)
|
|||
|
|
if uiMgr == nil then
|
|||
|
|
return nil
|
|||
|
|
end
|
|||
|
|
return uiMgr:ShowUI(
|
|||
|
|
UIDemoMainWindow,
|
|||
|
|
{onReturnToHub = function()
|
|||
|
|
____exports.ReturnToBootstrap(ctx)
|
|||
|
|
end},
|
|||
|
|
onOpened
|
|||
|
|
)
|
|||
|
|
end
|
|||
|
|
--- 按当前 UE 关卡名称自动挂载对应的 Demo 场景入口:
|
|||
|
|
-- - L_Bootstrap -> DemoHubWindow(场景切换大厅)
|
|||
|
|
-- - L_DemoUI -> UIDemoMainWindow(UI 组件与窗口实验室主界面)
|
|||
|
|
-- - 其他未知关卡 -> 默认兜底打开 DemoHubWindow
|
|||
|
|
function ____exports.RouteCurrentLevel(ctx, pc)
|
|||
|
|
local levelName = UE.UGameplayStatics.GetCurrentLevelName(pc, true)
|
|||
|
|
logger:Info("Routing player entry for level", {levelName = levelName})
|
|||
|
|
if levelName == UI_DEMO_MAP_NAME then
|
|||
|
|
____exports.OpenUIDemoMain(ctx)
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
if levelName == BOOTSTRAP_MAP_NAME then
|
|||
|
|
____exports.OpenDemoHub(ctx)
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
____exports.OpenDemoHub(ctx)
|
|||
|
|
end
|
|||
|
|
function __module.UpdateImports()
|
|||
|
|
Logger = M__share_base_logger.Logger
|
|||
|
|
GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
|
|||
|
|
DemoHubWindow = M__game_demo_demo_hub_window.DemoHubWindow
|
|||
|
|
BOOTSTRAP_MAP_NAME = M__game_demo_demo_registry.BOOTSTRAP_MAP_NAME
|
|||
|
|
BOOTSTRAP_MAP_PATH = M__game_demo_demo_registry.BOOTSTRAP_MAP_PATH
|
|||
|
|
FindDemoSceneById = M__game_demo_demo_registry.FindDemoSceneById
|
|||
|
|
UI_DEMO_MAP_NAME = M__game_demo_demo_registry.UI_DEMO_MAP_NAME
|
|||
|
|
UIDemoMainWindow = M__game_demo_ui_demo_ui_demo_main_window.UIDemoMainWindow
|
|||
|
|
end
|