303 lines
9.7 KiB
Lua
303 lines
9.7 KiB
Lua
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.hiddenByFullscreen = false
|
|
self.currentZOrder = 0
|
|
self.widgetBindings = {}
|
|
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.GetZOrder(self)
|
|
return self.currentZOrder
|
|
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.IsHiddenByFullscreen(self)
|
|
return self.hiddenByFullscreen
|
|
end
|
|
function UIWindow.prototype.SetHiddenByFullscreenInternal(self, hidden)
|
|
self.hiddenByFullscreen = hidden
|
|
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.TrackWidgetBinding(self, handle)
|
|
if handle ~= nil then
|
|
self.widgetBindings[#self.widgetBindings + 1] = handle
|
|
end
|
|
return handle
|
|
end
|
|
function UIWindow.prototype.GetDelegateBridge(self)
|
|
local bridge = self.ctx:GetService("uiDelegateBridge")
|
|
if bridge == nil then
|
|
logger:Warn("UIDelegateBridge not registered on context", {window = self.config.name})
|
|
return nil
|
|
end
|
|
return bridge
|
|
end
|
|
function UIWindow.prototype.BindButtonClick(self, button, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindButtonClick(button, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindButtonHovered(self, button, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindButtonHovered(button, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindButtonUnhovered(self, button, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindButtonUnhovered(button, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindCheckBoxChanged(self, checkBox, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindCheckBoxChanged(checkBox, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindSliderChanged(self, slider, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindSliderChanged(slider, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindSpinBoxChanged(self, spinBox, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindSpinBoxChanged(spinBox, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindEditableTextChanged(self, textBox, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindEditableTextChanged(textBox, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindEditableTextCommitted(self, textBox, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindEditableTextCommitted(textBox, callback, self))
|
|
end
|
|
function UIWindow.prototype.BindComboBoxChanged(self, comboBox, callback)
|
|
local bridge = self:GetDelegateBridge()
|
|
if bridge == nil then
|
|
return nil
|
|
end
|
|
return self:TrackWidgetBinding(bridge:BindComboBoxSelectionChanged(comboBox, callback, self))
|
|
end
|
|
function UIWindow.prototype.UnbindAllWidgetEvents(self)
|
|
do
|
|
local i = 0
|
|
while i < #self.widgetBindings do
|
|
self.widgetBindings[i + 1]:Dispose()
|
|
i = i + 1
|
|
end
|
|
end
|
|
self.widgetBindings = {}
|
|
end
|
|
function UIWindow.prototype.ShowInternal(self, zOrder, args)
|
|
if self:IsDisposed() or self.isClosing then
|
|
return
|
|
end
|
|
self.currentZOrder = zOrder
|
|
self.hiddenByFullscreen = false
|
|
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.hiddenByFullscreen = false
|
|
self:EnableAllEventListeners()
|
|
self:OnBindWidgets()
|
|
tbpcall(function()
|
|
self:OnReuseUI(args)
|
|
end)
|
|
self:ShowInternal(zOrder, args)
|
|
end
|
|
function UIWindow.prototype.RestoreFromFullscreenInternal(self)
|
|
if self:IsDisposed() or self.isClosing or self.isCached or not self.isLoaded then
|
|
return
|
|
end
|
|
self.hiddenByFullscreen = false
|
|
if self.isVisible then
|
|
return
|
|
end
|
|
if self.widget ~= nil and self.widgetAdapter:IsWidgetValid(self.widget) then
|
|
self.widgetAdapter:SetVisible(self.widget, true)
|
|
end
|
|
self.isVisible = true
|
|
tbpcall(function()
|
|
self:OnShow()
|
|
end)
|
|
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.hiddenByFullscreen = false
|
|
self.isCached = true
|
|
self.isClosing = false
|
|
self:UnbindAllWidgetEvents()
|
|
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.hiddenByFullscreen = false
|
|
self:UnbindAllWidgetEvents()
|
|
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.hiddenByFullscreen = false
|
|
self:UnbindAllWidgetEvents()
|
|
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
|