179 lines
7.2 KiB
Lua
179 lines
7.2 KiB
Lua
local ____lualib = require("lualib_bundle")
|
||||
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|||
|
|
local __TS__New = ____lualib.__TS__New
|
|||
|
|
local ____exports = __module.env
|
|||
|
|
local M__share_base_logger = __MODULE__.Import("share.base.logger", __module)
|
|||
|
|
local Logger = M__share_base_logger.Logger
|
|||
|
|
local M__share_base_scoped_object = __MODULE__.Import("share.base.scoped_object", __module)
|
|||
|
|
local ScopedObject = M__share_base_scoped_object.ScopedObject
|
|||
|
|
local M__framework_resource_asset_catalog = __MODULE__.Import("framework.resource.asset_catalog", __module)
|
|||
|
|
local ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|||
|
|
local M__framework_ui_ui_config = __MODULE__.Import("framework.ui.ui_config", __module)
|
|||
|
|
local RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
|||
|
|
local M__framework_ui_ui_window = __MODULE__.Import("framework.ui.ui_window", __module)
|
|||
|
|
local UIWindow = M__framework_ui_ui_window.UIWindow
|
|||
|
|
local M__game_startup = __MODULE__.Import("game.startup", __module)
|
|||
|
|
local OpenMiniSettings = M__game_startup.OpenMiniSettings
|
|||
|
|
local M__game_demo_demo_registry = __MODULE__.Import("game.demo.demo_registry", __module)
|
|||
|
|
local GetDemoScenes = M__game_demo_demo_registry.GetDemoScenes
|
|||
|
|
local logger = Logger("DemoHubWindow")
|
|||
|
|
____exports.DemoHubWindow = __TS__DefineClass("DemoHubWindow", __module)
|
|||
|
|
local DemoHubWindow = ____exports.DemoHubWindow
|
|||
|
|
DemoHubWindow.name = "DemoHubWindow"
|
|||
|
|
__TS__ClassExtends(DemoHubWindow, UIWindow)
|
|||
|
|
function DemoHubWindow.prototype.____constructor(self, ...)
|
|||
|
|
UIWindow.prototype.____constructor(self, ...)
|
|||
|
|
self.itemWidgets = {}
|
|||
|
|
self.itemEnterButtons = {}
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.OnBindWidgets(self)
|
|||
|
|
self.txtRuntimeInfo = self:RequireWidget("TxtRuntimeInfo")
|
|||
|
|
self.scrollDemoList = self:RequireWidget("ScrollDemoList")
|
|||
|
|
self.btnOpenMiniSettings = self:RequireWidget("BtnOpenMiniSettings")
|
|||
|
|
self:BindButtonClick(
|
|||
|
|
self.btnOpenMiniSettings,
|
|||
|
|
function()
|
|||
|
|
OpenMiniSettings(self.ctx)
|
|||
|
|
end
|
|||
|
|
)
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.OnPreShow(self, args)
|
|||
|
|
local openArgs = args
|
|||
|
|
local ____temp_0
|
|||
|
|
if openArgs ~= nil then
|
|||
|
|
____temp_0 = openArgs.onSelectDemo
|
|||
|
|
else
|
|||
|
|
____temp_0 = nil
|
|||
|
|
end
|
|||
|
|
self.onSelectDemo = ____temp_0
|
|||
|
|
self:RefreshRuntimeInfo()
|
|||
|
|
self:PopulateDemoCards()
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.OnClose(self)
|
|||
|
|
self:ClearDemoCards()
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.RefreshRuntimeInfo(self)
|
|||
|
|
local resSvc = self.ctx:GetService("resource")
|
|||
|
|
local modeText = resSvc ~= nil and resSvc:IsPackagedMode() and "Packaged" or "PIE / Editor"
|
|||
|
|
local info = string.format(
|
|||
|
|
"Lua 运行时:%s | Context #%d | 资源模式:%s | 已注册 Demo:%d 个",
|
|||
|
|
_VERSION,
|
|||
|
|
self.ctx.contextId,
|
|||
|
|
modeText,
|
|||
|
|
#GetDemoScenes()
|
|||
|
|
)
|
|||
|
|
if self.txtRuntimeInfo ~= nil and self.txtRuntimeInfo.SetText ~= nil then
|
|||
|
|
self.txtRuntimeInfo:SetText(info)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.ClearDemoCards(self)
|
|||
|
|
if self.itemScope ~= nil then
|
|||
|
|
self.itemScope:Dispose()
|
|||
|
|
self.itemScope = nil
|
|||
|
|
end
|
|||
|
|
if self.scrollDemoList ~= nil and self.scrollDemoList.ClearChildren ~= nil then
|
|||
|
|
self.scrollDemoList:ClearChildren()
|
|||
|
|
end
|
|||
|
|
self.itemWidgets = {}
|
|||
|
|
self.itemEnterButtons = {}
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.PopulateDemoCards(self)
|
|||
|
|
self:ClearDemoCards()
|
|||
|
|
local resSvc = self.ctx:GetService("resource")
|
|||
|
|
if resSvc == nil or self.scrollDemoList == nil then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
local scope = __TS__New(ScopedObject)
|
|||
|
|
self.itemScope = scope
|
|||
|
|
self:AddScopedObject(scope)
|
|||
|
|
resSvc:LoadClassAsync(
|
|||
|
|
ASSET_KEYS.DEMO_HUB_ITEM_WIDGET,
|
|||
|
|
scope,
|
|||
|
|
function(ok, itemClass, _lease, err)
|
|||
|
|
if not ok or itemClass == nil or self:IsDisposed() or scope:IsDisposed() then
|
|||
|
|
logger:Error("Failed to load WBP_DemoHubItem", {err = err})
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
self:BuildDemoCardWidgets(itemClass, scope)
|
|||
|
|
end
|
|||
|
|
)
|
|||
|
|
end
|
|||
|
|
function DemoHubWindow.prototype.BuildDemoCardWidgets(self, itemClass, scope)
|
|||
|
|
if self.scrollDemoList == nil then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
local worldContext = self.ctx:GetWorldContext().world or self.ctx.gameInstance
|
|||
|
|
if worldContext == nil then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
local lp0 = self.ctx:GetOrCreateLocalPlayer(0)
|
|||
|
|
local bridge = self.ctx:GetService("uiDelegateBridge")
|
|||
|
|
local scenes = GetDemoScenes()
|
|||
|
|
do
|
|||
|
|
local i = 0
|
|||
|
|
while i < #scenes do
|
|||
|
|
do
|
|||
|
|
local demo = scenes[i + 1]
|
|||
|
|
local card = UE.UWidgetBlueprintLibrary.Create(worldContext, itemClass, lp0.playerController)
|
|||
|
|
if card == nil then
|
|||
|
|
goto __continue19
|
|||
|
|
end
|
|||
|
|
local txtTitle = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoTitle")
|
|||
|
|
local txtDesc = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoDesc")
|
|||
|
|
local txtMeta = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtDemoMeta")
|
|||
|
|
local btnEnter = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "BtnEnterDemo")
|
|||
|
|
local txtEnterLabel = UE.ULuaUIEventSubsystem.FindChildWidgetByName(card, "TxtEnterLabel")
|
|||
|
|
if txtTitle ~= nil then
|
|||
|
|
txtTitle:SetText(demo.title)
|
|||
|
|
end
|
|||
|
|
if txtDesc ~= nil then
|
|||
|
|
txtDesc:SetText(demo.description)
|
|||
|
|
end
|
|||
|
|
if txtMeta ~= nil then
|
|||
|
|
txtMeta:SetText(string.format("%s | 关卡:%s", demo.tags, demo.mapAssetPath))
|
|||
|
|
end
|
|||
|
|
if txtEnterLabel ~= nil then
|
|||
|
|
txtEnterLabel:SetText(demo.enabled and "进入场景" or "敬请期待")
|
|||
|
|
end
|
|||
|
|
if btnEnter ~= nil then
|
|||
|
|
btnEnter:SetIsEnabled(demo.enabled)
|
|||
|
|
self.itemEnterButtons[demo.id] = btnEnter
|
|||
|
|
if demo.enabled and bridge ~= nil then
|
|||
|
|
local handle = bridge:BindButtonClick(
|
|||
|
|
btnEnter,
|
|||
|
|
function()
|
|||
|
|
if self.onSelectDemo ~= nil then
|
|||
|
|
self.onSelectDemo(demo)
|
|||
|
|
end
|
|||
|
|
end,
|
|||
|
|
scope
|
|||
|
|
)
|
|||
|
|
scope:AddScopedObject(handle)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
self.scrollDemoList:AddChild(card)
|
|||
|
|
self.itemWidgets[#self.itemWidgets + 1] = card
|
|||
|
|
end
|
|||
|
|
::__continue19::
|
|||
|
|
i = i + 1
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
RegisterUIConfig(____exports.DemoHubWindow, {
|
|||
|
|
name = "DemoHubWindow",
|
|||
|
|
assetKey = ASSET_KEYS.DEMO_HUB_WIDGET,
|
|||
|
|
singleton = true,
|
|||
|
|
layer = "normal",
|
|||
|
|
type = "normal",
|
|||
|
|
cacheTag = "no_cache",
|
|||
|
|
blockWorldClick = true
|
|||
|
|
})
|
|||
|
|
function __module.UpdateImports()
|
|||
|
|
Logger = M__share_base_logger.Logger
|
|||
|
|
ScopedObject = M__share_base_scoped_object.ScopedObject
|
|||
|
|
ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|||
|
|
RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
|
|||
|
|
UIWindow = M__framework_ui_ui_window.UIWindow
|
|||
|
|
OpenMiniSettings = M__game_startup.OpenMiniSettings
|
|||
|
|
GetDemoScenes = M__game_demo_demo_registry.GetDemoScenes
|
|||
|
|
end
|