chore: upgrade ts2lua-unreal to v0.3.1 with lowercase lib/module.lua & lib/class.lua and commit framework refactor
This commit is contained in:
1 parent
783dccf53d
commit
3572f2da43
206 files changed
+14442
-13186
No files matched your search
@@ -0,0 +1,76 @@
|
||||
local ____exports = __module.env
|
||||
____exports.UI_LAYER_ZORDER = {
|
||||
background = 0,
|
||||
normal = 100,
|
||||
popup = 200,
|
||||
tips = 300,
|
||||
system = 400
|
||||
}
|
||||
---
|
||||
-- @module_data
|
||||
local configByCtor = {}
|
||||
---
|
||||
-- @module_data
|
||||
local configByName = {}
|
||||
--- 显式 UI 窗口注册表(替代源端
|
||||
--
|
||||
-- @UIConfig 装饰器,符合 ts2lua-unreal 编译期白名单规则)。
|
||||
function ____exports.RegisterUIConfig(ctor, input)
|
||||
local ____input_name_2 = input.name
|
||||
local ____input_assetKey_3 = input.assetKey
|
||||
local ____input_singleton_0 = input.singleton
|
||||
if ____input_singleton_0 == nil then
|
||||
____input_singleton_0 = true
|
||||
end
|
||||
local ____temp_4 = input.layer or "normal"
|
||||
local ____temp_5 = input.type or "normal"
|
||||
local ____temp_6 = input.cacheTag or "no_cache"
|
||||
local ____input_blockWorldClick_1 = input.blockWorldClick
|
||||
if ____input_blockWorldClick_1 == nil then
|
||||
____input_blockWorldClick_1 = true
|
||||
end
|
||||
local item = {
|
||||
name = ____input_name_2,
|
||||
assetKey = ____input_assetKey_3,
|
||||
singleton = ____input_singleton_0,
|
||||
layer = ____temp_4,
|
||||
type = ____temp_5,
|
||||
cacheTag = ____temp_6,
|
||||
blockWorldClick = ____input_blockWorldClick_1,
|
||||
ctor = ctor
|
||||
}
|
||||
configByCtor[ctor] = item
|
||||
configByName[item.name] = item
|
||||
return item
|
||||
end
|
||||
function ____exports.GetUIConfig(ctor)
|
||||
return configByCtor[ctor]
|
||||
end
|
||||
function ____exports.GetUIConfigByName(name)
|
||||
return configByName[name]
|
||||
end
|
||||
function __module.StashData(env, to)
|
||||
local ____has = to.__has__
|
||||
if not ____has then
|
||||
____has = {}
|
||||
to.__has__ = ____has
|
||||
end
|
||||
to.configByCtor = configByCtor
|
||||
____has.configByCtor = true
|
||||
to.configByName = configByName
|
||||
____has.configByName = true
|
||||
end
|
||||
function __module.RestoreData(env, from)
|
||||
local ____has = from.__has__
|
||||
if not ____has then
|
||||
return
|
||||
end
|
||||
if ____has.configByCtor then
|
||||
configByCtor = from.configByCtor
|
||||
end
|
||||
if ____has.configByName then
|
||||
configByName = from.configByName
|
||||
end
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
end
|
||||
@@ -0,0 +1,162 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
||||
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__share_base_traceback = __MODULE__.Import("share.base.traceback", __module)
|
||||
local tbpcall = M__share_base_traceback.tbpcall
|
||||
local M__framework_context_game_context = __MODULE__.Import("framework.context.game_context", __module)
|
||||
local GetGameInstanceKey = M__framework_context_game_context.GetGameInstanceKey
|
||||
local logger = Logger("UIDelegateBridge")
|
||||
____exports.UEButtonDelegateBackend = __TS__DefineClass("UEButtonDelegateBackend", __module)
|
||||
local UEButtonDelegateBackend = ____exports.UEButtonDelegateBackend
|
||||
UEButtonDelegateBackend.name = "UEButtonDelegateBackend"
|
||||
function UEButtonDelegateBackend.prototype.____constructor(self, subsystem)
|
||||
self.subsystem = subsystem
|
||||
end
|
||||
function UEButtonDelegateBackend.prototype.BindButtonClicked(self, button)
|
||||
return self.subsystem:BindButtonClicked(button)
|
||||
end
|
||||
function UEButtonDelegateBackend.prototype.UnbindButtonClicked(self, bindingId)
|
||||
return self.subsystem:UnbindButtonClicked(bindingId)
|
||||
end
|
||||
function UEButtonDelegateBackend.prototype.GetActiveBindingCount(self)
|
||||
return self.subsystem:GetActiveBindingCount()
|
||||
end
|
||||
local ButtonBindingHandle = __TS__DefineClass("ButtonBindingHandle", __module)
|
||||
ButtonBindingHandle.name = "ButtonBindingHandle"
|
||||
function ButtonBindingHandle.prototype.____constructor(self, bridge, bindingId)
|
||||
self.bridge = bridge
|
||||
self.bindingId = bindingId
|
||||
end
|
||||
function ButtonBindingHandle.prototype.Dispose(self)
|
||||
if self.bridge ~= nil then
|
||||
local b = self.bridge
|
||||
self.bridge = nil
|
||||
b:UnbindById(self.bindingId)
|
||||
end
|
||||
end
|
||||
---
|
||||
-- @module_data
|
||||
local bridgeByGameInstanceKey = {}
|
||||
____exports.UIDelegateBridge = __TS__DefineClass("UIDelegateBridge", __module)
|
||||
local UIDelegateBridge = ____exports.UIDelegateBridge
|
||||
UIDelegateBridge.name = "UIDelegateBridge"
|
||||
__TS__ClassExtends(UIDelegateBridge, ScopedObject)
|
||||
function UIDelegateBridge.prototype.____constructor(self, ctx, backend)
|
||||
ScopedObject.prototype.____constructor(self)
|
||||
self.bindings = {}
|
||||
self.backend = backend
|
||||
if ctx.gameInstance ~= nil then
|
||||
self.giKey = GetGameInstanceKey(ctx.gameInstance)
|
||||
bridgeByGameInstanceKey[self.giKey] = self
|
||||
end
|
||||
end
|
||||
function UIDelegateBridge.prototype.BindButtonClick(self, button, callback, owner)
|
||||
local bindingId = self.backend:BindButtonClicked(button)
|
||||
assert(bindingId > 0, "UIDelegateBridge.BindButtonClick: failed to bind button")
|
||||
self.bindings[bindingId] = {bindingId = bindingId, callback = callback, owner = owner}
|
||||
local handle = __TS__New(ButtonBindingHandle, self, bindingId)
|
||||
if owner ~= nil and __TS__InstanceOf(owner, ScopedObject) then
|
||||
owner:AddScopedObject(handle)
|
||||
end
|
||||
return handle
|
||||
end
|
||||
function UIDelegateBridge.prototype.UnbindById(self, bindingId)
|
||||
if self.bindings[bindingId] == nil then
|
||||
return
|
||||
end
|
||||
self.bindings[bindingId] = nil
|
||||
self.backend:UnbindButtonClicked(bindingId)
|
||||
end
|
||||
function UIDelegateBridge.prototype.DispatchButtonClicked(self, bindingId)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
local rec = self.bindings[bindingId]
|
||||
if rec == nil then
|
||||
return
|
||||
end
|
||||
if rec.owner ~= nil and rec.owner:IsDisposed() then
|
||||
self:UnbindById(bindingId)
|
||||
return
|
||||
end
|
||||
tbpcall(rec.callback)
|
||||
end
|
||||
function UIDelegateBridge.prototype.GetActiveBindingCount(self)
|
||||
return self.backend:GetActiveBindingCount()
|
||||
end
|
||||
function UIDelegateBridge.prototype.Dispose(self)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
local ids = {}
|
||||
for id in pairs(self.bindings) do
|
||||
ids[#ids + 1] = id
|
||||
end
|
||||
do
|
||||
local i = 0
|
||||
while i < #ids do
|
||||
self:UnbindById(ids[i + 1])
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
if self.giKey ~= nil and bridgeByGameInstanceKey[self.giKey] == self then
|
||||
bridgeByGameInstanceKey[self.giKey] = nil
|
||||
end
|
||||
ScopedObject.prototype.Dispose(self)
|
||||
end
|
||||
--- 供 C++ FLuaCallbackBridge::CallInt 回调的纯函数入口。
|
||||
--
|
||||
-- @noSelf
|
||||
function ____exports.OnNativeButtonClicked(gameInstance, bindingId)
|
||||
local bridge = bridgeByGameInstanceKey[GetGameInstanceKey(gameInstance)]
|
||||
if bridge ~= nil then
|
||||
bridge:DispatchButtonClicked(bindingId)
|
||||
end
|
||||
end
|
||||
---
|
||||
-- @noSelf
|
||||
function ____exports.CreateUEUIDelegateBridge(ctx)
|
||||
if ctx.gameInstance == nil then
|
||||
return nil
|
||||
end
|
||||
local subsystem = UE.ULuaUIEventSubsystem.GetFromGameInstance(ctx.gameInstance)
|
||||
if subsystem == nil then
|
||||
logger:Error("ULuaUIEventSubsystem unavailable on GameInstance")
|
||||
return nil
|
||||
end
|
||||
return __TS__New(
|
||||
____exports.UIDelegateBridge,
|
||||
ctx,
|
||||
__TS__New(____exports.UEButtonDelegateBackend, subsystem)
|
||||
)
|
||||
end
|
||||
function __module.StashData(env, to)
|
||||
local ____has = to.__has__
|
||||
if not ____has then
|
||||
____has = {}
|
||||
to.__has__ = ____has
|
||||
end
|
||||
to.bridgeByGameInstanceKey = bridgeByGameInstanceKey
|
||||
____has.bridgeByGameInstanceKey = true
|
||||
end
|
||||
function __module.RestoreData(env, from)
|
||||
local ____has = from.__has__
|
||||
if not ____has then
|
||||
return
|
||||
end
|
||||
if ____has.bridgeByGameInstanceKey then
|
||||
bridgeByGameInstanceKey = from.bridgeByGameInstanceKey
|
||||
end
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
Logger = M__share_base_logger.Logger
|
||||
ScopedObject = M__share_base_scoped_object.ScopedObject
|
||||
tbpcall = M__share_base_traceback.tbpcall
|
||||
GetGameInstanceKey = M__framework_context_game_context.GetGameInstanceKey
|
||||
end
|
||||
@@ -0,0 +1,357 @@
|
||||
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__share_event_event_hub = __MODULE__.Import("share.event.event_hub", __module)
|
||||
local EventHub = M__share_event_event_hub.EventHub
|
||||
local M__share_base_traceback = __MODULE__.Import("share.base.traceback", __module)
|
||||
local tbpcall = M__share_base_traceback.tbpcall
|
||||
local M__framework_ui_ui_config = __MODULE__.Import("framework.ui.ui_config", __module)
|
||||
local GetUIConfig = M__framework_ui_ui_config.GetUIConfig
|
||||
local UI_LAYER_ZORDER = M__framework_ui_ui_config.UI_LAYER_ZORDER
|
||||
local logger = Logger("UIManager")
|
||||
____exports.UEWidgetAdapter = __TS__DefineClass("UEWidgetAdapter", __module)
|
||||
local UEWidgetAdapter = ____exports.UEWidgetAdapter
|
||||
UEWidgetAdapter.name = "UEWidgetAdapter"
|
||||
function UEWidgetAdapter.prototype.____constructor(self)
|
||||
end
|
||||
function UEWidgetAdapter.prototype.FindChild(self, widget, name)
|
||||
return UE.ULuaUIEventSubsystem.FindChildWidgetByName(widget, name)
|
||||
end
|
||||
function UEWidgetAdapter.prototype.AddToViewport(self, widget, zOrder)
|
||||
if widget.IsInViewport ~= nil and widget:IsInViewport() then
|
||||
return
|
||||
end
|
||||
local hasPlayer = widget.GetOwningPlayer ~= nil and widget:GetOwningPlayer() ~= nil
|
||||
if hasPlayer and widget.AddToPlayerScreen ~= nil then
|
||||
widget:AddToPlayerScreen(zOrder)
|
||||
elseif widget.AddToViewport ~= nil then
|
||||
widget:AddToViewport(zOrder)
|
||||
end
|
||||
end
|
||||
function UEWidgetAdapter.prototype.RemoveFromParent(self, widget)
|
||||
if widget.RemoveFromParent ~= nil then
|
||||
widget:RemoveFromParent()
|
||||
end
|
||||
end
|
||||
function UEWidgetAdapter.prototype.SetVisible(self, widget, visible)
|
||||
if widget.SetVisibility ~= nil then
|
||||
widget:SetVisibility(visible and UE.ESlateVisibility.Visible or UE.ESlateVisibility.Collapsed)
|
||||
end
|
||||
end
|
||||
function UEWidgetAdapter.prototype.IsWidgetValid(self, widget)
|
||||
return widget ~= nil and UE.UKismetSystemLibrary.IsValid(widget)
|
||||
end
|
||||
____exports.UEWidgetFactory = __TS__DefineClass("UEWidgetFactory", __module)
|
||||
local UEWidgetFactory = ____exports.UEWidgetFactory
|
||||
UEWidgetFactory.name = "UEWidgetFactory"
|
||||
function UEWidgetFactory.prototype.____constructor(self)
|
||||
end
|
||||
function UEWidgetFactory.prototype.CreateWidget(self, widgetClass, worldContext, owningPlayer)
|
||||
if worldContext == nil then
|
||||
return nil
|
||||
end
|
||||
return UE.UWidgetBlueprintLibrary.Create(worldContext, widgetClass, owningPlayer)
|
||||
end
|
||||
____exports.UIManager = __TS__DefineClass("UIManager", __module)
|
||||
local UIManager = ____exports.UIManager
|
||||
UIManager.name = "UIManager"
|
||||
__TS__ClassExtends(UIManager, ScopedObject)
|
||||
function UIManager.prototype.____constructor(self, ctx, playerCtx, resourceService, widgetFactory, widgetAdapter)
|
||||
ScopedObject.prototype.____constructor(self)
|
||||
self.windowStack = {}
|
||||
self.singletonByName = {}
|
||||
self.cachedByName = {}
|
||||
self.zOrderCounter = 0
|
||||
self.inputMode = "game"
|
||||
self.ctx = ctx
|
||||
self.playerCtx = playerCtx
|
||||
self.resourceService = resourceService
|
||||
self.widgetFactory = widgetFactory or __TS__New(____exports.UEWidgetFactory)
|
||||
self.widgetAdapter = widgetAdapter or __TS__New(____exports.UEWidgetAdapter)
|
||||
self.events = __TS__New(
|
||||
EventHub,
|
||||
string.format("UIManager#%d_P%d", ctx.contextId, playerCtx.playerIndex)
|
||||
)
|
||||
ctx.appEvents.on.OnWorldCleanup(
|
||||
function()
|
||||
self:CloseAll(true)
|
||||
end,
|
||||
self
|
||||
)
|
||||
end
|
||||
function UIManager.prototype.ShowUI(self, ctor, args, onOpened)
|
||||
if self:IsDisposed() or self.ctx:IsShuttingDown() then
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, false, nil, "UIManager is shutting down")
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local config = GetUIConfig(ctor)
|
||||
if config == nil then
|
||||
error("UIManager.ShowUI: window class is not registered via RegisterUIConfig")
|
||||
return nil
|
||||
end
|
||||
if config.singleton then
|
||||
local existing = self.singletonByName[config.name]
|
||||
if existing ~= nil and not existing:IsDisposed() and not existing:IsClosing() then
|
||||
if existing:IsLoaded() then
|
||||
local zOrder = self:AllocateZOrder(config)
|
||||
existing:ShowInternal(zOrder, args)
|
||||
self:SyncFocusAndInputMode()
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, true, existing, nil)
|
||||
end
|
||||
elseif onOpened ~= nil then
|
||||
self.events.on.OnWindowOpened(
|
||||
function(openedName, openedWin)
|
||||
if openedName == config.name and openedWin == existing then
|
||||
tbpcall(onOpened, true, openedWin, nil)
|
||||
end
|
||||
end,
|
||||
existing
|
||||
)
|
||||
end
|
||||
return existing
|
||||
end
|
||||
end
|
||||
local cached = self.cachedByName[config.name]
|
||||
if cached ~= nil and not cached:IsDisposed() then
|
||||
self.cachedByName[config.name] = nil
|
||||
if config.singleton then
|
||||
self.singletonByName[config.name] = cached
|
||||
end
|
||||
self.windowStack[#self.windowStack + 1] = cached
|
||||
local zOrder = self:AllocateZOrder(config)
|
||||
cached:ReuseInternal(zOrder, args)
|
||||
self:SyncFocusAndInputMode()
|
||||
self.events.emit.OnWindowOpened(config.name, cached)
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, true, cached, nil)
|
||||
end
|
||||
return cached
|
||||
end
|
||||
local win = __TS__New(ctor)
|
||||
win:InitContextInternal(self.ctx, self, config, self.widgetAdapter)
|
||||
if config.singleton then
|
||||
self.singletonByName[config.name] = win
|
||||
end
|
||||
self.windowStack[#self.windowStack + 1] = win
|
||||
local loadHandle = self.resourceService:LoadClassAsync(
|
||||
config.assetKey,
|
||||
win,
|
||||
function(ok, widgetClass, _lease, errMsg)
|
||||
if win:IsDisposed() or win:IsClosing() or self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
if not ok or widgetClass == nil then
|
||||
logger:Error("Failed to load widget class", {window = config.name, assetKey = config.assetKey, err = errMsg})
|
||||
self:RemoveFromStackAndSingleton(win)
|
||||
win:SetLoadingStateInternal(false, nil)
|
||||
win:Dispose()
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, false, nil, errMsg or "Widget class load failed")
|
||||
end
|
||||
return
|
||||
end
|
||||
local worldContext = self.ctx:GetWorldContext().world or self.playerCtx.playerController or self.ctx.gameInstance
|
||||
local widget = self.widgetFactory:CreateWidget(widgetClass, worldContext, self.playerCtx.playerController)
|
||||
if widget == nil then
|
||||
local createErr = string.format("[%s] Failed to instantiate UUserWidget", config.name)
|
||||
logger:Error(createErr)
|
||||
self:RemoveFromStackAndSingleton(win)
|
||||
win:SetLoadingStateInternal(false, nil)
|
||||
win:Dispose()
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, false, nil, createErr)
|
||||
end
|
||||
return
|
||||
end
|
||||
win:AttachWidgetInternal(widget)
|
||||
local zOrder = self:AllocateZOrder(config)
|
||||
win:ShowInternal(zOrder, args)
|
||||
self:SyncFocusAndInputMode()
|
||||
self.events.emit.OnWindowOpened(config.name, win)
|
||||
if onOpened ~= nil then
|
||||
tbpcall(onOpened, true, win, nil)
|
||||
end
|
||||
end
|
||||
)
|
||||
win:SetLoadingStateInternal(true, loadHandle)
|
||||
return win
|
||||
end
|
||||
function UIManager.prototype.GetSingletonUI(self, ctor)
|
||||
local config = GetUIConfig(ctor)
|
||||
if config == nil then
|
||||
return nil
|
||||
end
|
||||
return self.singletonByName[config.name]
|
||||
end
|
||||
function UIManager.prototype.CloseSingletonUI(self, ctor)
|
||||
local win = self:GetSingletonUI(ctor)
|
||||
if win ~= nil then
|
||||
win:Close()
|
||||
end
|
||||
end
|
||||
function UIManager.prototype.GetTopWindow(self)
|
||||
do
|
||||
local i = #self.windowStack - 1
|
||||
while i >= 0 do
|
||||
local win = self.windowStack[i + 1]
|
||||
if not win:IsDisposed() and not win:IsClosing() then
|
||||
return win
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
function UIManager.prototype.HandleWindowCachedInternal(self, win)
|
||||
self:RemoveFromStackAndSingleton(win)
|
||||
local oldCached = self.cachedByName[win.config.name]
|
||||
if oldCached ~= nil and oldCached ~= win then
|
||||
oldCached:ForceDisposeFromCacheInternal()
|
||||
end
|
||||
self.cachedByName[win.config.name] = win
|
||||
self:SyncFocusAndInputMode()
|
||||
self.events.emit.OnWindowClosed(win.config.name, win)
|
||||
end
|
||||
function UIManager.prototype.HandleWindowClosedInternal(self, win)
|
||||
self:RemoveFromStackAndSingleton(win)
|
||||
self:SyncFocusAndInputMode()
|
||||
self.events.emit.OnWindowClosed(win.config.name, win)
|
||||
end
|
||||
function UIManager.prototype.EvictCache(self)
|
||||
local toEvict = {}
|
||||
for name, win in pairs(self.cachedByName) do
|
||||
if win ~= nil then
|
||||
self.cachedByName[name] = nil
|
||||
toEvict[#toEvict + 1] = win
|
||||
end
|
||||
end
|
||||
do
|
||||
local i = 0
|
||||
while i < #toEvict do
|
||||
toEvict[i + 1]:ForceDisposeFromCacheInternal()
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
function UIManager.prototype.CloseAll(self, alsoEvictCache)
|
||||
if alsoEvictCache == nil then
|
||||
alsoEvictCache = true
|
||||
end
|
||||
local copy = {}
|
||||
do
|
||||
local i = #self.windowStack - 1
|
||||
while i >= 0 do
|
||||
copy[#copy + 1] = self.windowStack[i + 1]
|
||||
i = i - 1
|
||||
end
|
||||
end
|
||||
do
|
||||
local i = 0
|
||||
while i < #copy do
|
||||
copy[i + 1]:Close()
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
if alsoEvictCache then
|
||||
self:EvictCache()
|
||||
end
|
||||
self:SyncFocusAndInputMode()
|
||||
end
|
||||
function UIManager.prototype.GetDiagnostics(self)
|
||||
local openWindows = 0
|
||||
local loadingWindows = 0
|
||||
do
|
||||
local i = 0
|
||||
while i < #self.windowStack do
|
||||
local w = self.windowStack[i + 1]
|
||||
if not w:IsDisposed() then
|
||||
if w:IsLoading() then
|
||||
loadingWindows = loadingWindows + 1
|
||||
else
|
||||
openWindows = openWindows + 1
|
||||
end
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
local cachedWindows = 0
|
||||
for _, w in pairs(self.cachedByName) do
|
||||
if w ~= nil and not w:IsDisposed() then
|
||||
cachedWindows = cachedWindows + 1
|
||||
end
|
||||
end
|
||||
local top = self:GetTopWindow()
|
||||
return {
|
||||
openWindows = openWindows,
|
||||
loadingWindows = loadingWindows,
|
||||
cachedWindows = cachedWindows,
|
||||
topWindowName = top ~= nil and top.config.name or nil,
|
||||
inputMode = self.inputMode
|
||||
}
|
||||
end
|
||||
function UIManager.prototype.AllocateZOrder(self, config)
|
||||
self.zOrderCounter = self.zOrderCounter + 1
|
||||
return UI_LAYER_ZORDER[config.layer] + self.zOrderCounter % 90
|
||||
end
|
||||
function UIManager.prototype.RemoveFromStackAndSingleton(self, win)
|
||||
if self.singletonByName[win.config.name] == win then
|
||||
self.singletonByName[win.config.name] = nil
|
||||
end
|
||||
do
|
||||
local i = #self.windowStack - 1
|
||||
while i >= 0 do
|
||||
if self.windowStack[i + 1] == win then
|
||||
table.remove(self.windowStack, i + 1)
|
||||
break
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
function UIManager.prototype.SyncFocusAndInputMode(self)
|
||||
local top = self:GetTopWindow()
|
||||
local nextMode = top ~= nil and top.config.blockWorldClick and "ui" or "game"
|
||||
self.inputMode = nextMode
|
||||
local pc = self.playerCtx.playerController
|
||||
if pc ~= nil and UE ~= nil and UE.UKismetSystemLibrary.IsValid(pc) then
|
||||
if nextMode == "ui" then
|
||||
pc.bShowMouseCursor = true
|
||||
local ____UE_UWidgetBlueprintLibrary_SetInputMode_UIOnlyEx_1 = UE.UWidgetBlueprintLibrary.SetInputMode_UIOnlyEx
|
||||
local ____temp_0
|
||||
if top ~= nil then
|
||||
____temp_0 = top:GetWidget()
|
||||
else
|
||||
____temp_0 = nil
|
||||
end
|
||||
____UE_UWidgetBlueprintLibrary_SetInputMode_UIOnlyEx_1(pc, ____temp_0, UE.EMouseLockMode.DoNotLock, false)
|
||||
else
|
||||
pc.bShowMouseCursor = false
|
||||
UE.UWidgetBlueprintLibrary.SetInputMode_GameOnly(pc, false)
|
||||
end
|
||||
end
|
||||
self.events.emit.OnFocusRestored(top ~= nil and top.config.name or nil)
|
||||
end
|
||||
function UIManager.prototype.Dispose(self)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
self:CloseAll(true)
|
||||
self.events:Dispose()
|
||||
ScopedObject.prototype.Dispose(self)
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
Logger = M__share_base_logger.Logger
|
||||
ScopedObject = M__share_base_scoped_object.ScopedObject
|
||||
EventHub = M__share_event_event_hub.EventHub
|
||||
tbpcall = M__share_base_traceback.tbpcall
|
||||
GetUIConfig = M__framework_ui_ui_config.GetUIConfig
|
||||
UI_LAYER_ZORDER = M__framework_ui_ui_config.UI_LAYER_ZORDER
|
||||
end
|
||||
@@ -0,0 +1,202 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||||
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__share_base_traceback = __MODULE__.Import("share.base.traceback", __module)
|
||||
local tbpcall = M__share_base_traceback.tbpcall
|
||||
local logger = Logger("UIWindow")
|
||||
____exports.UIWindow = __TS__DefineClass("UIWindow", __module)
|
||||
local UIWindow = ____exports.UIWindow
|
||||
UIWindow.name = "UIWindow"
|
||||
__TS__ClassExtends(UIWindow, ScopedObject)
|
||||
function UIWindow.prototype.____constructor(self, ...)
|
||||
ScopedObject.prototype.____constructor(self, ...)
|
||||
self.widget = nil
|
||||
self.isLoading = false
|
||||
self.isLoaded = false
|
||||
self.isVisible = false
|
||||
self.isClosing = false
|
||||
self.isCached = false
|
||||
self.buttonBindings = {}
|
||||
end
|
||||
function UIWindow.prototype.InitContextInternal(self, ctx, uiManager, config, widgetAdapter)
|
||||
self.ctx = ctx
|
||||
self.uiManager = uiManager
|
||||
self.config = config
|
||||
self.widgetAdapter = widgetAdapter
|
||||
end
|
||||
function UIWindow.prototype.GetWidget(self)
|
||||
return self.widget
|
||||
end
|
||||
function UIWindow.prototype.IsLoading(self)
|
||||
return self.isLoading
|
||||
end
|
||||
function UIWindow.prototype.IsLoaded(self)
|
||||
return self.isLoaded
|
||||
end
|
||||
function UIWindow.prototype.IsVisible(self)
|
||||
return self.isVisible
|
||||
end
|
||||
function UIWindow.prototype.IsClosing(self)
|
||||
return self.isClosing
|
||||
end
|
||||
function UIWindow.prototype.IsCached(self)
|
||||
return self.isCached
|
||||
end
|
||||
function UIWindow.prototype.SetLoadingStateInternal(self, loading, handle)
|
||||
self.isLoading = loading
|
||||
self.classLoadHandle = handle
|
||||
end
|
||||
function UIWindow.prototype.AttachWidgetInternal(self, widget)
|
||||
self.widget = widget
|
||||
self.isLoading = false
|
||||
self.isLoaded = true
|
||||
self.isCached = false
|
||||
self:OnBindWidgets()
|
||||
end
|
||||
function UIWindow.prototype.RequireWidget(self, widgetName)
|
||||
assert(
|
||||
self.widget ~= nil,
|
||||
string.format("[%s] Widget root is not attached", self.config.name)
|
||||
)
|
||||
local child = self.widgetAdapter:FindChild(self.widget, widgetName)
|
||||
assert(
|
||||
child ~= nil,
|
||||
string.format("[%s] Required child widget '%s' not found in Widget Blueprint", self.config.name, widgetName)
|
||||
)
|
||||
return child
|
||||
end
|
||||
function UIWindow.prototype.BindButtonClick(self, button, callback)
|
||||
local bridge = self.ctx:GetService("uiDelegateBridge")
|
||||
if bridge == nil then
|
||||
logger:Warn("UIDelegateBridge not registered on context", {window = self.config.name})
|
||||
return nil
|
||||
end
|
||||
local handle = bridge:BindButtonClick(button, callback, self)
|
||||
self.buttonBindings[#self.buttonBindings + 1] = handle
|
||||
return handle
|
||||
end
|
||||
function UIWindow.prototype.UnbindAllButtons(self)
|
||||
do
|
||||
local i = 0
|
||||
while i < #self.buttonBindings do
|
||||
self.buttonBindings[i + 1]:Dispose()
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
self.buttonBindings = {}
|
||||
end
|
||||
function UIWindow.prototype.ShowInternal(self, zOrder, args)
|
||||
if self:IsDisposed() or self.isClosing then
|
||||
return
|
||||
end
|
||||
tbpcall(function()
|
||||
self:OnPreShow(args)
|
||||
end)
|
||||
if self.widget ~= nil then
|
||||
self.widgetAdapter:AddToViewport(self.widget, zOrder)
|
||||
self.widgetAdapter:SetVisible(self.widget, true)
|
||||
end
|
||||
self.isVisible = true
|
||||
tbpcall(function()
|
||||
self:OnShow()
|
||||
end)
|
||||
end
|
||||
function UIWindow.prototype.ReuseInternal(self, zOrder, args)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
self.isCached = false
|
||||
self.isClosing = false
|
||||
self:EnableAllEventListeners()
|
||||
self:OnBindWidgets()
|
||||
tbpcall(function()
|
||||
self:OnReuseUI(args)
|
||||
end)
|
||||
self:ShowInternal(zOrder, args)
|
||||
end
|
||||
function UIWindow.prototype.Hide(self)
|
||||
if not self.isVisible then
|
||||
return
|
||||
end
|
||||
self.isVisible = false
|
||||
if self.widget ~= nil and self.widgetAdapter:IsWidgetValid(self.widget) then
|
||||
self.widgetAdapter:SetVisible(self.widget, false)
|
||||
end
|
||||
tbpcall(function()
|
||||
self:OnHide()
|
||||
end)
|
||||
end
|
||||
function UIWindow.prototype.Close(self, onClosed)
|
||||
if self:IsDisposed() or self.isCached or self.isClosing then
|
||||
return
|
||||
end
|
||||
self.isClosing = true
|
||||
if self.isLoading and self.classLoadHandle ~= nil then
|
||||
self.classLoadHandle:Cancel()
|
||||
self.classLoadHandle = nil
|
||||
self.isLoading = false
|
||||
end
|
||||
local canCache = self.config.cacheTag == "cache" and self.isLoaded and self.widget ~= nil and self.widgetAdapter:IsWidgetValid(self.widget) and not self.ctx:IsShuttingDown()
|
||||
if canCache then
|
||||
self.isVisible = false
|
||||
self.isCached = true
|
||||
self.isClosing = false
|
||||
self:UnbindAllButtons()
|
||||
self:DisableAllEventListeners()
|
||||
self.widgetAdapter:RemoveFromParent(self.widget)
|
||||
tbpcall(function()
|
||||
self:OnClose()
|
||||
end)
|
||||
self.uiManager:HandleWindowCachedInternal(self)
|
||||
if onClosed ~= nil then
|
||||
tbpcall(onClosed)
|
||||
end
|
||||
return
|
||||
end
|
||||
if self.isLoaded then
|
||||
tbpcall(function()
|
||||
self:OnClose()
|
||||
end)
|
||||
end
|
||||
self.isVisible = false
|
||||
self:UnbindAllButtons()
|
||||
if self.widget ~= nil and self.widgetAdapter:IsWidgetValid(self.widget) then
|
||||
self.widgetAdapter:RemoveFromParent(self.widget)
|
||||
end
|
||||
self.widget = nil
|
||||
self.uiManager:HandleWindowClosedInternal(self)
|
||||
self:Dispose()
|
||||
if onClosed ~= nil then
|
||||
tbpcall(onClosed)
|
||||
end
|
||||
end
|
||||
function UIWindow.prototype.ForceDisposeFromCacheInternal(self)
|
||||
self.isCached = false
|
||||
self:UnbindAllButtons()
|
||||
if self.widget ~= nil and self.widgetAdapter:IsWidgetValid(self.widget) then
|
||||
self.widgetAdapter:RemoveFromParent(self.widget)
|
||||
end
|
||||
self.widget = nil
|
||||
self:Dispose()
|
||||
end
|
||||
function UIWindow.prototype.OnBindWidgets(self)
|
||||
end
|
||||
function UIWindow.prototype.OnPreShow(self, _args)
|
||||
end
|
||||
function UIWindow.prototype.OnShow(self)
|
||||
end
|
||||
function UIWindow.prototype.OnReuseUI(self, _args)
|
||||
end
|
||||
function UIWindow.prototype.OnHide(self)
|
||||
end
|
||||
function UIWindow.prototype.OnClose(self)
|
||||
end
|
||||
function __module.UpdateImports()
|
||||
Logger = M__share_base_logger.Logger
|
||||
ScopedObject = M__share_base_scoped_object.ScopedObject
|
||||
tbpcall = M__share_base_traceback.tbpcall
|
||||
end
|
||||
Reference in new issue
Block a user