Files
UnrealLuaDemo/Script/lua/game/demo/ui_demo/ui_demo_windows.lua
T

472 lines
16 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
local ____lualib = require("lualib_bundle")
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = __module.env
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
____exports.UIDemoNormalWindow = __TS__DefineClass("UIDemoNormalWindow", __module)
local UIDemoNormalWindow = ____exports.UIDemoNormalWindow
UIDemoNormalWindow.name = "UIDemoNormalWindow"
__TS__ClassExtends(UIDemoNormalWindow, UIWindow)
function UIDemoNormalWindow.prototype.____constructor(self, ...)
UIWindow.prototype.____constructor(self, ...)
self.openOrRefreshCount = 0
self.pingCount = 0
end
function UIDemoNormalWindow.prototype.OnBindWidgets(self)
self.txtNormalTitle = self:RequireWidget("TxtNormalTitle")
self.txtNormalBody = self:RequireWidget("TxtNormalBody")
self.btnNormalPing = self:RequireWidget("BtnNormalPing")
self.btnNormalClose = self:RequireWidget("BtnNormalClose")
self:BindButtonClick(
self.btnNormalPing,
function()
self.pingCount = self.pingCount + 1
self:RefreshBody()
self:EmitLog(string.format("[Normal] 触发交互 #%d", self.pingCount))
end
)
self:BindButtonClick(
self.btnNormalClose,
function()
self:Close()
end
)
end
function UIDemoNormalWindow.prototype.OnPreShow(self, args)
local a = args
if a ~= nil and a.onLog ~= nil then
self.onLog = a.onLog
end
self.openOrRefreshCount = self.openOrRefreshCount + 1
self:RefreshBody()
self:EmitLog(string.format(
"[Normal] OnPreShow(第 %d 次打开/刷新,ZOrder=%d)",
self.openOrRefreshCount,
self:GetZOrder()
))
end
function UIDemoNormalWindow.prototype.OnClose(self)
self:EmitLog("[Normal] OnClose 窗口已销毁")
end
function UIDemoNormalWindow.prototype.RefreshBody(self)
if self.txtNormalBody ~= nil then
self.txtNormalBody:SetText(string.format(
"Layer: normal | Type: normal | Singleton: true\n当前 ZOrder:%d | 打开/复用刷新次数:%d | 按钮交互:%d 次\n重复点击左侧「普通窗口」不会创建第二个实例,而是直接刷新本窗。",
self:GetZOrder(),
self.openOrRefreshCount,
self.pingCount
))
end
end
function UIDemoNormalWindow.prototype.EmitLog(self, msg)
if self.onLog ~= nil then
self.onLog(msg)
end
end
RegisterUIConfig(____exports.UIDemoNormalWindow, {
name = "UIDemoNormalWindow",
assetKey = ASSET_KEYS.UI_DEMO_NORMAL_WIDGET,
singleton = true,
layer = "normal",
type = "normal",
cacheTag = "no_cache",
blockWorldClick = true
})
____exports.UIDemoFullscreenWindow = __TS__DefineClass("UIDemoFullscreenWindow", __module)
local UIDemoFullscreenWindow = ____exports.UIDemoFullscreenWindow
UIDemoFullscreenWindow.name = "UIDemoFullscreenWindow"
__TS__ClassExtends(UIDemoFullscreenWindow, UIWindow)
function UIDemoFullscreenWindow.prototype.OnBindWidgets(self)
self.txtFullDesc = self:RequireWidget("TxtFullDesc")
self.imgFullPreview = self:RequireWidget("ImgFullPreview")
self.btnFullOpenModal = self:RequireWidget("BtnFullOpenModal")
self.btnFullClose = self:RequireWidget("BtnFullClose")
self:BindButtonClick(
self.btnFullOpenModal,
function()
if self.onOpenModal ~= nil then
self.onOpenModal()
end
end
)
self:BindButtonClick(
self.btnFullClose,
function()
self:Close()
end
)
end
function UIDemoFullscreenWindow.prototype.OnPreShow(self, args)
local a = args
local ____temp_0
if a ~= nil then
____temp_0 = a.onLog
else
____temp_0 = nil
end
self.onLog = ____temp_0
local ____temp_1
if a ~= nil then
____temp_1 = a.onOpenModal
else
____temp_1 = nil
end
self.onOpenModal = ____temp_1
local resSvc = self.ctx:GetService("resource")
if resSvc ~= nil then
resSvc:LoadTextureAsync(
ASSET_KEYS.DEMO_BADGE_B_TEX,
self,
function(ok, tex)
if ok and tex ~= nil and self.imgFullPreview ~= nil and not self:IsDisposed() then
self.imgFullPreview:SetBrushFromTexture(tex, false)
end
end
)
end
if self.onLog ~= nil then
self.onLog(string.format(
"[Fullscreen] 打开全屏窗口(ZOrder=%d),已自动隐藏下层 Normal 窗口",
self:GetZOrder()
))
end
end
function UIDemoFullscreenWindow.prototype.OnClose(self)
if self.onLog ~= nil then
self.onLog("[Fullscreen] 关闭全屏窗口,自动恢复下层主界面显示")
end
end
RegisterUIConfig(____exports.UIDemoFullscreenWindow, {
name = "UIDemoFullscreenWindow",
assetKey = ASSET_KEYS.UI_DEMO_FULLSCREEN_WIDGET,
singleton = true,
layer = "normal",
type = "fullscreen",
cacheTag = "no_cache",
blockWorldClick = true
})
____exports.UIDemoModalWindow = __TS__DefineClass("UIDemoModalWindow", __module)
local UIDemoModalWindow = ____exports.UIDemoModalWindow
UIDemoModalWindow.name = "UIDemoModalWindow"
__TS__ClassExtends(UIDemoModalWindow, UIWindow)
function UIDemoModalWindow.prototype.OnBindWidgets(self)
self.txtModalTitle = self:RequireWidget("TxtModalTitle")
self.txtModalMessage = self:RequireWidget("TxtModalMessage")
self.btnModalConfirm = self:RequireWidget("BtnModalConfirm")
self.btnModalCancel = self:RequireWidget("BtnModalCancel")
self:BindButtonClick(
self.btnModalConfirm,
function()
local cb = self.onConfirm
self:Close()
if cb ~= nil then
cb()
end
end
)
self:BindButtonClick(
self.btnModalCancel,
function()
local cb = self.onCancel
self:Close()
if cb ~= nil then
cb()
end
end
)
end
function UIDemoModalWindow.prototype.OnPreShow(self, args)
local a = args
local ____temp_2
if a ~= nil then
____temp_2 = a.onConfirm
else
____temp_2 = nil
end
self.onConfirm = ____temp_2
local ____temp_3
if a ~= nil then
____temp_3 = a.onCancel
else
____temp_3 = nil
end
self.onCancel = ____temp_3
if self.txtModalTitle ~= nil then
self.txtModalTitle:SetText(a ~= nil and a.title ~= nil and a.title or "二次确认模态弹窗")
end
if self.txtModalMessage ~= nil then
self.txtModalMessage:SetText(a ~= nil and a.message ~= nil and a.message or "半透明遮罩已拦截底层点击。请选择确认或取消以测试回调透传。")
end
end
RegisterUIConfig(____exports.UIDemoModalWindow, {
name = "UIDemoModalWindow",
assetKey = ASSET_KEYS.UI_DEMO_MODAL_WIDGET,
singleton = true,
layer = "popup",
type = "popup",
cacheTag = "no_cache",
blockWorldClick = true
})
____exports.UIDemoCachedWindow = __TS__DefineClass("UIDemoCachedWindow", __module)
local UIDemoCachedWindow = ____exports.UIDemoCachedWindow
UIDemoCachedWindow.name = "UIDemoCachedWindow"
__TS__ClassExtends(UIDemoCachedWindow, UIWindow)
function UIDemoCachedWindow.prototype.____constructor(self, ...)
UIWindow.prototype.____constructor(self, ...)
self.reuseCount = 0
self.clickCount = 0
end
function UIDemoCachedWindow.prototype.OnBindWidgets(self)
self.txtCachedStats = self:RequireWidget("TxtCachedStats")
self.btnCachedAction = self:RequireWidget("BtnCachedAction")
self.btnCachedClose = self:RequireWidget("BtnCachedClose")
self:BindButtonClick(
self.btnCachedAction,
function()
self.clickCount = self.clickCount + 1
self:RefreshStats()
self:EmitLog(string.format("[Cached] 点击按钮(累计 %d 次,严格 +1 无重复绑定)", self.clickCount))
end
)
self:BindButtonClick(
self.btnCachedClose,
function()
self:Close()
end
)
end
function UIDemoCachedWindow.prototype.OnReuseUI(self)
self.reuseCount = self.reuseCount + 1
self:EmitLog(string.format("[Cached] OnReuseUI 命中缓存秒开(第 %d 次复用)", self.reuseCount))
end
function UIDemoCachedWindow.prototype.OnPreShow(self, args)
local a = args
if a ~= nil and a.onLog ~= nil then
self.onLog = a.onLog
end
self:RefreshStats()
if self.reuseCount == 0 then
self:EmitLog("[Cached] 首次实例化创建成功")
end
end
function UIDemoCachedWindow.prototype.OnClose(self)
self:EmitLog("[Cached] 关闭并归还缓存池(委托已自动解绑)")
end
function UIDemoCachedWindow.prototype.RefreshStats(self)
if self.txtCachedStats ~= nil then
self.txtCachedStats:SetText(string.format(
"缓存复用次数 (OnReuseUI):%d 次\n按钮累计点击:%d 次 | 当前 ZOrder:%d\n关闭后窗口实例进入缓存池,再次打开不重新创建 Widget,且按钮点击不会重复触发。",
self.reuseCount,
self.clickCount,
self:GetZOrder()
))
end
end
function UIDemoCachedWindow.prototype.EmitLog(self, msg)
if self.onLog ~= nil then
self.onLog(msg)
end
end
RegisterUIConfig(____exports.UIDemoCachedWindow, {
name = "UIDemoCachedWindow",
assetKey = ASSET_KEYS.UI_DEMO_CACHED_WIDGET,
singleton = true,
layer = "popup",
type = "normal",
cacheTag = "cache",
blockWorldClick = true
})
____exports.UIDemoMultiWindow = __TS__DefineClass("UIDemoMultiWindow", __module)
local UIDemoMultiWindow = ____exports.UIDemoMultiWindow
UIDemoMultiWindow.name = "UIDemoMultiWindow"
__TS__ClassExtends(UIDemoMultiWindow, UIWindow)
function UIDemoMultiWindow.prototype.____constructor(self, ...)
UIWindow.prototype.____constructor(self, ...)
self.instanceSeq = 1
self.localCount = 0
end
function UIDemoMultiWindow.prototype.OnBindWidgets(self)
self.multiCard = self:RequireWidget("MultiCard")
self.txtMultiTitle = self:RequireWidget("TxtMultiTitle")
self.txtMultiBody = self:RequireWidget("TxtMultiBody")
self.btnMultiCount = self:RequireWidget("BtnMultiCount")
self.btnMultiClose = self:RequireWidget("BtnMultiClose")
self:BindButtonClick(
self.btnMultiCount,
function()
self.localCount = self.localCount + 1
self:RefreshDisplay()
self:EmitLog(string.format("[Multi #%d] 独立计数 -> %d", self.instanceSeq, self.localCount))
end
)
self:BindButtonClick(
self.btnMultiClose,
function()
self:Close()
end
)
end
function UIDemoMultiWindow.prototype.OnPreShow(self, args)
local a = args
self.instanceSeq = a ~= nil and a.instanceSeq or 1
local ____temp_4
if a ~= nil then
____temp_4 = a.onLog
else
____temp_4 = nil
end
self.onLog = ____temp_4
local slotIndex = (self.instanceSeq - 1) % 6
local offsetX = -150 + slotIndex * 60
local offsetY = -90 + slotIndex * 38
if self.multiCard ~= nil and UE ~= nil and UE.ULuaUIEventSubsystem ~= nil then
local pos = UE.FVector2D()
pos.X = offsetX
pos.Y = offsetY
UE.ULuaUIEventSubsystem.SetCanvasPosition(self.multiCard, pos)
end
self:RefreshDisplay()
self:EmitLog(string.format(
"[Multi #%d] 多实例打开(ZOrder=%d)",
self.instanceSeq,
self:GetZOrder()
))
end
function UIDemoMultiWindow.prototype.OnClose(self)
self:EmitLog(string.format("[Multi #%d] 已独立关闭", self.instanceSeq))
end
function UIDemoMultiWindow.prototype.RefreshDisplay(self)
if self.txtMultiTitle ~= nil then
self.txtMultiTitle:SetText(string.format("多实例便签窗 #%d", self.instanceSeq))
end
if self.txtMultiBody ~= nil then
self.txtMultiBody:SetText(string.format(
"singleton = false | ZOrder = %d\n本实例独立计数:%d\n可连续点击「多实例窗」同时存在多个窗口。",
self:GetZOrder(),
self.localCount
))
end
end
function UIDemoMultiWindow.prototype.EmitLog(self, msg)
if self.onLog ~= nil then
self.onLog(msg)
end
end
RegisterUIConfig(____exports.UIDemoMultiWindow, {
name = "UIDemoMultiWindow",
assetKey = ASSET_KEYS.UI_DEMO_MULTI_WIDGET,
singleton = false,
layer = "popup",
type = "normal",
cacheTag = "no_cache",
blockWorldClick = true
})
____exports.UIDemoToastWindow = __TS__DefineClass("UIDemoToastWindow", __module)
local UIDemoToastWindow = ____exports.UIDemoToastWindow
UIDemoToastWindow.name = "UIDemoToastWindow"
__TS__ClassExtends(UIDemoToastWindow, UIWindow)
function UIDemoToastWindow.prototype.OnBindWidgets(self)
self.toastPill = self:RequireWidget("ToastPill")
self.txtToastMessage = self:RequireWidget("TxtToastMessage")
end
function UIDemoToastWindow.prototype.OnPreShow(self, args)
local a = args
local msg = a ~= nil and a.message or "飘字通知"
local duration = a ~= nil and a.durationSec ~= nil and a.durationSec or 2.2
local offsetIdx = a ~= nil and a.offsetIndex ~= nil and a.offsetIndex or 0
local ____temp_5
if a ~= nil then
____temp_5 = a.onLog
else
____temp_5 = nil
end
self.onLog = ____temp_5
if self.txtToastMessage ~= nil then
self.txtToastMessage:SetText(msg)
end
if self.toastPill ~= nil and UE ~= nil and UE.ULuaUIEventSubsystem ~= nil then
local pos = UE.FVector2D()
pos.X = 0
pos.Y = 92 + offsetIdx % 4 * 48
UE.ULuaUIEventSubsystem.SetCanvasPosition(self.toastPill, pos)
end
self.ctx.scheduler:AddWorldTimer(
duration,
function()
self:Close()
end,
self
)
if self.onLog ~= nil then
self.onLog(string.format("[Toast] 弹出提示:%s(%.1fs 后自动关闭,不抢焦点)", msg, duration))
end
end
RegisterUIConfig(____exports.UIDemoToastWindow, {
name = "UIDemoToastWindow",
assetKey = ASSET_KEYS.UI_DEMO_TOAST_WIDGET,
singleton = false,
layer = "tips",
type = "popup",
cacheTag = "no_cache",
blockWorldClick = false
})
____exports.UIDemoSystemWindow = __TS__DefineClass("UIDemoSystemWindow", __module)
local UIDemoSystemWindow = ____exports.UIDemoSystemWindow
UIDemoSystemWindow.name = "UIDemoSystemWindow"
__TS__ClassExtends(UIDemoSystemWindow, UIWindow)
function UIDemoSystemWindow.prototype.OnBindWidgets(self)
self.txtSystemBody = self:RequireWidget("TxtSystemBody")
self.btnSystemAck = self:RequireWidget("BtnSystemAck")
self:BindButtonClick(
self.btnSystemAck,
function()
self:Close()
end
)
end
function UIDemoSystemWindow.prototype.OnPreShow(self, args)
local a = args
local ____temp_6
if a ~= nil then
____temp_6 = a.onLog
else
____temp_6 = nil
end
self.onLog = ____temp_6
if self.txtSystemBody ~= nil then
self.txtSystemBody:SetText(string.format(
"Layer: system | ZOrder: %d\n优先级始终高于 normal / popup / tips 全部层级,常用于断线重连或强制系统公告。",
self:GetZOrder()
))
end
if self.onLog ~= nil then
self.onLog(string.format(
"[System] 打开系统级顶层弹窗(ZOrder=%d)",
self:GetZOrder()
))
end
end
function UIDemoSystemWindow.prototype.OnClose(self)
if self.onLog ~= nil then
self.onLog("[System] 已确认关闭系统弹窗")
end
end
RegisterUIConfig(____exports.UIDemoSystemWindow, {
name = "UIDemoSystemWindow",
assetKey = ASSET_KEYS.UI_DEMO_SYSTEM_WIDGET,
singleton = true,
layer = "system",
type = "popup",
cacheTag = "no_cache",
blockWorldClick = true
})
function __module.UpdateImports()
ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
RegisterUIConfig = M__framework_ui_ui_config.RegisterUIConfig
UIWindow = M__framework_ui_ui_window.UIWindow
end