feat(demo): add Bootstrap Demo Hub, Chinese UI font, and UI Demo showcase scene
This commit is contained in:
1 parent
3572f2da43
commit
4c83c086f4
49 files changed
+7864
-131
No files matched your search
@@ -0,0 +1,993 @@
|
||||
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_ui_demo_ui_demo_windows = __MODULE__.Import("game.demo.ui_demo.ui_demo_windows", __module)
|
||||
local UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
|
||||
local UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
|
||||
local UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
|
||||
local UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
|
||||
local UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
|
||||
local UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
|
||||
local UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
|
||||
local logger = Logger("UIDemoMainWindow")
|
||||
local THEME_PRESETS = {{label = "深海蓝(普通)", r = 0.149, g = 0.431, b = 0.855}, {label = "翡翠绿(稀有)", r = 0.133, g = 0.588, b = 0.388}, {label = "琥珀金(传说)", r = 0.761, g = 0.49, b = 0.11}, {label = "星云紫(史诗)", r = 0.478, g = 0.294, b = 0.784}}
|
||||
local TEXT_COLORS = {{name = "纯白", r = 0.941, g = 0.961, b = 0.988}, {name = "天青", r = 0.451, g = 0.788, b = 0.98}, {name = "金黄", r = 0.98, g = 0.812, b = 0.31}, {name = "珊瑚红", r = 0.98, g = 0.51, b = 0.51}}
|
||||
local TEXT_SIZES = {14, 18, 22}
|
||||
local PREVIEW_TEXTURES = {{label = "冒险者头像", key = ASSET_KEYS.DEMO_AVATAR_TEX}, {label = "翡翠菱形徽章", key = ASSET_KEYS.DEMO_BADGE_A_TEX}, {label = "绯红星纹徽章", key = ASSET_KEYS.DEMO_BADGE_B_TEX}, {label = "经典设置图标", key = ASSET_KEYS.MINI_SETTINGS_ICON}}
|
||||
local TINT_COLORS = {{name = "原色", r = 1, g = 1, b = 1}, {name = "青蓝着色", r = 0.55, g = 0.9, b = 1}, {name = "金黄着色", r = 1, g = 0.85, b = 0.45}, {name = "玫红着色", r = 1, g = 0.55, b = 0.7}}
|
||||
local function MakeLinearColor(self, r, g, b, a)
|
||||
if a == nil then
|
||||
a = 1
|
||||
end
|
||||
local c = UE.FLinearColor()
|
||||
c.R = r
|
||||
c.G = g
|
||||
c.B = b
|
||||
c.A = a
|
||||
return c
|
||||
end
|
||||
local function MakeSlateColor(self, r, g, b, a)
|
||||
if a == nil then
|
||||
a = 1
|
||||
end
|
||||
local sc = UE.FSlateColor()
|
||||
sc.SpecifiedColor = MakeLinearColor(
|
||||
nil,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
a
|
||||
)
|
||||
sc.ColorUseRule = UE.ESlateColorStylingMode.UseColor_Specified
|
||||
return sc
|
||||
end
|
||||
____exports.UIDemoMainWindow = __TS__DefineClass("UIDemoMainWindow", __module)
|
||||
local UIDemoMainWindow = ____exports.UIDemoMainWindow
|
||||
UIDemoMainWindow.name = "UIDemoMainWindow"
|
||||
__TS__ClassExtends(UIDemoMainWindow, UIWindow)
|
||||
function UIDemoMainWindow.prototype.____constructor(self, ...)
|
||||
UIWindow.prototype.____constructor(self, ...)
|
||||
self.activeTabIndex = 0
|
||||
self.actionClickCount = 0
|
||||
self.actionHovered = false
|
||||
self.targetEnabled = true
|
||||
self.targetClickCount = 0
|
||||
self.checkboxChecked = false
|
||||
self.sliderValue = 0.5
|
||||
self.spinValue = 100
|
||||
self.currentNickname = "冒险者_01"
|
||||
self.draftNickname = ""
|
||||
self.selectedTheme = "深海蓝(普通)"
|
||||
self.dynamicItemCount = 0
|
||||
self.multiSeq = 0
|
||||
self.toastSeq = 0
|
||||
self.textColorIndex = 0
|
||||
self.textSizeIndex = 0
|
||||
self.previewTexIndex = 0
|
||||
self.previewTintIndex = 0
|
||||
self.previewVisIndex = 0
|
||||
self.nextListItemId = 0
|
||||
self.dynamicItems = {}
|
||||
self.logLines = {}
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OnBindWidgets(self)
|
||||
self.imgPlayerAvatar = self:RequireWidget("ImgPlayerAvatar")
|
||||
self.txtPlayerName = self:RequireWidget("TxtPlayerName")
|
||||
self.barPlayerExp = self:RequireWidget("BarPlayerExp")
|
||||
self.txtHudStats = self:RequireWidget("TxtHudStats")
|
||||
self.btnTopSettings = self:RequireWidget("BtnTopSettings")
|
||||
self.btnBackToHub = self:RequireWidget("BtnBackToHub")
|
||||
self:BindButtonClick(
|
||||
self.btnTopSettings,
|
||||
function()
|
||||
self:AppendLog("[TopBar] 打开 MiniSettingsWindow")
|
||||
OpenMiniSettings(self.ctx)
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnBackToHub,
|
||||
function()
|
||||
self:AppendLog("[TopBar] 返回 Bootstrap 场景大厅")
|
||||
if self.onReturnToHub ~= nil then
|
||||
self.onReturnToHub()
|
||||
end
|
||||
end
|
||||
)
|
||||
self.btnWinNormal = self:RequireWidget("BtnWinNormal")
|
||||
self.btnWinFullscreen = self:RequireWidget("BtnWinFullscreen")
|
||||
self.btnWinModal = self:RequireWidget("BtnWinModal")
|
||||
self.btnWinCached = self:RequireWidget("BtnWinCached")
|
||||
self.btnWinMulti = self:RequireWidget("BtnWinMulti")
|
||||
self.btnWinToast = self:RequireWidget("BtnWinToast")
|
||||
self.btnWinSystem = self:RequireWidget("BtnWinSystem")
|
||||
self.btnEvictCache = self:RequireWidget("BtnEvictCache")
|
||||
self.btnCloseOthers = self:RequireWidget("BtnCloseOthers")
|
||||
self:BindButtonClick(
|
||||
self.btnWinNormal,
|
||||
function()
|
||||
self:OpenNormalDemoWindow()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinFullscreen,
|
||||
function()
|
||||
self:OpenFullscreenDemoWindow()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinModal,
|
||||
function()
|
||||
self:OpenModalDemoWindow("确认操作", "这是一条带半透明遮罩的模态弹窗,点击「确认」或「取消」将在右侧日志记录结果。")
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinCached,
|
||||
function()
|
||||
self:OpenCachedDemoWindow()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinMulti,
|
||||
function()
|
||||
self:OpenMultiDemoWindow()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinToast,
|
||||
function()
|
||||
self:ShowToast(string.format("飘字通知 #%d(Tips 层,不抢占 UI 焦点)", self.toastSeq + 1))
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnWinSystem,
|
||||
function()
|
||||
self:OpenSystemDemoWindow()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnEvictCache,
|
||||
function()
|
||||
local evicted = self.uiManager:EvictCache()
|
||||
self:AppendLog(string.format("[Cache] 已主动清空缓存池,释放 %d 个缓存窗口", evicted))
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnCloseOthers,
|
||||
function()
|
||||
local closed = self.uiManager:CloseAllExcept(self, false)
|
||||
self:AppendLog(string.format("[UIManager] 已关闭除主界面外的 %d 个窗口", closed))
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
)
|
||||
self.btnTabBasic = self:RequireWidget("BtnTabBasic")
|
||||
self.btnTabInput = self:RequireWidget("BtnTabInput")
|
||||
self.btnTabMedia = self:RequireWidget("BtnTabMedia")
|
||||
self.btnTabDiag = self:RequireWidget("BtnTabDiag")
|
||||
self.tabSwitcher = self:RequireWidget("TabSwitcher")
|
||||
self:BindButtonClick(
|
||||
self.btnTabBasic,
|
||||
function() return self:SelectTab(0, "基础交互") end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnTabInput,
|
||||
function() return self:SelectTab(1, "输入与选择") end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnTabMedia,
|
||||
function() return self:SelectTab(2, "图片与列表") end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnTabDiag,
|
||||
function()
|
||||
self:SelectTab(3, "框架诊断")
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
)
|
||||
self.txtBasicBtnStatus = self:RequireWidget("TxtBasicBtnStatus")
|
||||
self.btnDemoAction = self:RequireWidget("BtnDemoAction")
|
||||
self.btnToggleDisable = self:RequireWidget("BtnToggleDisable")
|
||||
self.btnDemoTarget = self:RequireWidget("BtnDemoTarget")
|
||||
self.txtDemoTarget = self:RequireWidget("TxtDemoTarget")
|
||||
self.chkFeature = self:RequireWidget("ChkFeature")
|
||||
self.txtCheckStatus = self:RequireWidget("TxtCheckStatus")
|
||||
self.txtSliderStatus = self:RequireWidget("TxtSliderStatus")
|
||||
self.sliderDemo = self:RequireWidget("SliderDemo")
|
||||
self.progressDemo = self:RequireWidget("ProgressDemo")
|
||||
self.btnProgressPlay = self:RequireWidget("BtnProgressPlay")
|
||||
self.txtProgressPlay = self:RequireWidget("TxtProgressPlay")
|
||||
self.btnProgressReset = self:RequireWidget("BtnProgressReset")
|
||||
self.spinDemo = self:RequireWidget("SpinDemo")
|
||||
self.txtSpinStatus = self:RequireWidget("TxtSpinStatus")
|
||||
self:BindButtonClick(
|
||||
self.btnDemoAction,
|
||||
function()
|
||||
self.actionClickCount = self.actionClickCount + 1
|
||||
self:RefreshBasicButtonStatus()
|
||||
self:AppendLog(string.format("[Button] 测试按钮被点击(第 %d 次)", self.actionClickCount))
|
||||
end
|
||||
)
|
||||
self:BindButtonHovered(
|
||||
self.btnDemoAction,
|
||||
function()
|
||||
self.actionHovered = true
|
||||
self:RefreshBasicButtonStatus()
|
||||
self:AppendLog("[Button] 鼠标悬停进入测试按钮")
|
||||
end
|
||||
)
|
||||
self:BindButtonUnhovered(
|
||||
self.btnDemoAction,
|
||||
function()
|
||||
self.actionHovered = false
|
||||
self:RefreshBasicButtonStatus()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnToggleDisable,
|
||||
function()
|
||||
self.targetEnabled = not self.targetEnabled
|
||||
if self.btnDemoTarget ~= nil then
|
||||
self.btnDemoTarget:SetIsEnabled(self.targetEnabled)
|
||||
end
|
||||
if self.txtDemoTarget ~= nil then
|
||||
self.txtDemoTarget:SetText(self.targetEnabled and "目标受控按钮(已启用)" or "目标受控按钮(已禁用)")
|
||||
end
|
||||
self:RefreshBasicButtonStatus()
|
||||
self:AppendLog(self.targetEnabled and "[Button] 目标按钮已启用" or "[Button] 目标按钮已禁用")
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnDemoTarget,
|
||||
function()
|
||||
self.targetClickCount = self.targetClickCount + 1
|
||||
self:AppendLog(string.format("[Button] 受控按钮触发点击 #%d", self.targetClickCount))
|
||||
end
|
||||
)
|
||||
self:BindCheckBoxChanged(
|
||||
self.chkFeature,
|
||||
function(checked)
|
||||
self.checkboxChecked = checked
|
||||
if self.txtCheckStatus ~= nil then
|
||||
self.txtCheckStatus:SetText(checked and "复选框状态:已勾选(开启特性)" or "复选框状态:未勾选(关闭特性)")
|
||||
end
|
||||
self:AppendLog(checked and "[CheckBox] 已勾选" or "[CheckBox] 已取消勾选")
|
||||
end
|
||||
)
|
||||
self:BindSliderChanged(
|
||||
self.sliderDemo,
|
||||
function(val)
|
||||
self:ApplySliderProgress(val, false)
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnProgressPlay,
|
||||
function()
|
||||
self:ToggleProgressAnimation()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnProgressReset,
|
||||
function()
|
||||
self:StopProgressAnimation()
|
||||
self:ApplySliderProgress(0, true)
|
||||
self:AppendLog("[ProgressBar] 进度已重置为 0%")
|
||||
end
|
||||
)
|
||||
self:BindSpinBoxChanged(
|
||||
self.spinDemo,
|
||||
function(val)
|
||||
self.spinValue = val
|
||||
if self.txtSpinStatus ~= nil then
|
||||
self.txtSpinStatus:SetText(string.format("当前数值:%.1f(范围 0 ~ 999)", val))
|
||||
end
|
||||
self:AppendLog(string.format("[SpinBox] 数值变更 -> %.1f", val))
|
||||
end
|
||||
)
|
||||
self.inputNickname = self:RequireWidget("InputNickname")
|
||||
self.txtInputStatus = self:RequireWidget("TxtInputStatus")
|
||||
self.btnApplyNickname = self:RequireWidget("BtnApplyNickname")
|
||||
self.comboTheme = self:RequireWidget("ComboTheme")
|
||||
self.borderThemePreview = self:RequireWidget("BorderThemePreview")
|
||||
self.txtComboStatus = self:RequireWidget("TxtComboStatus")
|
||||
self.txtRichSample = self:RequireWidget("TxtRichSample")
|
||||
self.btnCycleTextColor = self:RequireWidget("BtnCycleTextColor")
|
||||
self.btnCycleTextSize = self:RequireWidget("BtnCycleTextSize")
|
||||
self:BindEditableTextChanged(
|
||||
self.inputNickname,
|
||||
function(text)
|
||||
self.draftNickname = text
|
||||
local charCount = utf8.len(text) or string.len(text)
|
||||
if self.txtInputStatus ~= nil then
|
||||
self.txtInputStatus:SetText(charCount > 0 and string.format("实时内容:%s(%d 字符)", text, charCount) or "实时内容:空(0 字符)")
|
||||
end
|
||||
end
|
||||
)
|
||||
self:BindEditableTextCommitted(
|
||||
self.inputNickname,
|
||||
function(text, commitMethod)
|
||||
self.draftNickname = text
|
||||
self:AppendLog(string.format("[EditableTextBox] 提交文本:%s(Method=%d)", text, commitMethod))
|
||||
if text ~= "" then
|
||||
self:ApplyNickname(text)
|
||||
end
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnApplyNickname,
|
||||
function()
|
||||
local nextName = self.draftNickname ~= "" and self.draftNickname or "天命旅人_88"
|
||||
self:ApplyNickname(nextName)
|
||||
end
|
||||
)
|
||||
self:BindComboBoxChanged(
|
||||
self.comboTheme,
|
||||
function(option)
|
||||
self:ApplyThemePreset(option)
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnCycleTextColor,
|
||||
function()
|
||||
self.textColorIndex = (self.textColorIndex + 1) % #TEXT_COLORS
|
||||
local c = TEXT_COLORS[self.textColorIndex + 1]
|
||||
if self.txtRichSample ~= nil then
|
||||
self.txtRichSample:SetColorAndOpacity(MakeSlateColor(
|
||||
nil,
|
||||
c.r,
|
||||
c.g,
|
||||
c.b,
|
||||
1
|
||||
))
|
||||
end
|
||||
self:AppendLog(string.format("[TextBlock] 切换文本颜色 -> %s", c.name))
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnCycleTextSize,
|
||||
function()
|
||||
self.textSizeIndex = (self.textSizeIndex + 1) % #TEXT_SIZES
|
||||
local size = TEXT_SIZES[self.textSizeIndex + 1]
|
||||
if self.txtRichSample ~= nil then
|
||||
self.txtRichSample:SetFontSize(size)
|
||||
end
|
||||
self:AppendLog(string.format("[TextBlock] 切换字号 -> %dpt", size))
|
||||
end
|
||||
)
|
||||
self.imgPreview = self:RequireWidget("ImgPreview")
|
||||
self.txtImageStatus = self:RequireWidget("TxtImageStatus")
|
||||
self.btnSwitchTex = self:RequireWidget("BtnSwitchTex")
|
||||
self.btnTintTex = self:RequireWidget("BtnTintTex")
|
||||
self.btnCycleVis = self:RequireWidget("BtnCycleVis")
|
||||
self.txtListSummary = self:RequireWidget("TxtListSummary")
|
||||
self.btnListAddOne = self:RequireWidget("BtnListAddOne")
|
||||
self.btnListAddTen = self:RequireWidget("BtnListAddTen")
|
||||
self.btnListClear = self:RequireWidget("BtnListClear")
|
||||
self.scrollDynamicList = self:RequireWidget("ScrollDynamicList")
|
||||
self:BindButtonClick(
|
||||
self.btnSwitchTex,
|
||||
function()
|
||||
self.previewTexIndex = (self.previewTexIndex + 1) % #PREVIEW_TEXTURES
|
||||
self:LoadPreviewTexture()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnTintTex,
|
||||
function()
|
||||
self.previewTintIndex = (self.previewTintIndex + 1) % #TINT_COLORS
|
||||
local tint = TINT_COLORS[self.previewTintIndex + 1]
|
||||
if self.imgPreview ~= nil then
|
||||
self.imgPreview:SetColorAndOpacity(MakeLinearColor(
|
||||
nil,
|
||||
tint.r,
|
||||
tint.g,
|
||||
tint.b,
|
||||
1
|
||||
))
|
||||
end
|
||||
self:AppendLog(string.format("[Image] 切换着色 -> %s", tint.name))
|
||||
self:RefreshImageStatus()
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnCycleVis,
|
||||
function()
|
||||
self.previewVisIndex = (self.previewVisIndex + 1) % 3
|
||||
local visModes = {UE.ESlateVisibility.Visible, UE.ESlateVisibility.Hidden, UE.ESlateVisibility.Collapsed}
|
||||
if self.imgPreview ~= nil then
|
||||
self.imgPreview:SetVisibility(visModes[self.previewVisIndex + 1])
|
||||
end
|
||||
self:RefreshImageStatus()
|
||||
self:AppendLog(string.format(
|
||||
"[Image] 切换可见性 -> %s",
|
||||
self:GetVisibilityLabel()
|
||||
))
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnListAddOne,
|
||||
function() return self:AddDynamicListItems(1) end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnListAddTen,
|
||||
function() return self:AddDynamicListItems(10) end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnListClear,
|
||||
function() return self:ClearDynamicListItems() end
|
||||
)
|
||||
self.txtDiagDetail = self:RequireWidget("TxtDiagDetail")
|
||||
self.btnDiagRefresh = self:RequireWidget("BtnDiagRefresh")
|
||||
self.btnDiagConcurrent = self:RequireWidget("BtnDiagConcurrent")
|
||||
self.btnDiagCancelLoad = self:RequireWidget("BtnDiagCancelLoad")
|
||||
self:BindButtonClick(
|
||||
self.btnDiagRefresh,
|
||||
function()
|
||||
self:RefreshHudAndDiagnostics()
|
||||
self:AppendLog("[Diag] 已手动刷新诊断快照")
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnDiagConcurrent,
|
||||
function()
|
||||
local w1 = self:OpenNormalDemoWindow()
|
||||
local w2 = self:OpenNormalDemoWindow()
|
||||
local same = w1 == w2
|
||||
self:AppendLog(string.format(
|
||||
"[Diag] 并发双开单例测试:同一控制器=%s",
|
||||
tostring(same)
|
||||
))
|
||||
self:ShowToast(same and "并发双开测试通过:返回同一单例" or "并发双开测试异常")
|
||||
end
|
||||
)
|
||||
self:BindButtonClick(
|
||||
self.btnDiagCancelLoad,
|
||||
function()
|
||||
local w = self.uiManager:ShowUI(
|
||||
UIDemoSystemWindow,
|
||||
{onLog = function(____, m) return self:AppendLog(m) end}
|
||||
)
|
||||
if w ~= nil then
|
||||
w:Close()
|
||||
end
|
||||
self:AppendLog("[Diag] 已执行「打开后立即关闭」取消加载验证")
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
)
|
||||
self.btnClearLog = self:RequireWidget("BtnClearLog")
|
||||
self.scrollEventLog = self:RequireWidget("ScrollEventLog")
|
||||
self.txtEventLog = self:RequireWidget("TxtEventLog")
|
||||
self:BindButtonClick(
|
||||
self.btnClearLog,
|
||||
function()
|
||||
self.logLines = {}
|
||||
self:RenderLogText()
|
||||
end
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OnPreShow(self, args)
|
||||
local a = args
|
||||
local ____temp_0
|
||||
if a ~= nil then
|
||||
____temp_0 = a.onReturnToHub
|
||||
else
|
||||
____temp_0 = nil
|
||||
end
|
||||
self.onReturnToHub = ____temp_0
|
||||
self.uiManager.events.on.OnWindowOpened(
|
||||
function(winName)
|
||||
self:AppendLog(string.format("[UIManager] 窗口打开:%s", winName))
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end,
|
||||
self
|
||||
)
|
||||
self.uiManager.events.on.OnWindowClosed(
|
||||
function(winName)
|
||||
self:AppendLog(string.format("[UIManager] 窗口关闭:%s", winName))
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end,
|
||||
self
|
||||
)
|
||||
self.uiManager.events.on.OnFocusRestored(
|
||||
function()
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end,
|
||||
self
|
||||
)
|
||||
self:LoadAvatarAndPreview()
|
||||
self:PreloadDynamicListItemClass()
|
||||
self:SelectTab(0, "基础交互")
|
||||
self:RefreshBasicButtonStatus()
|
||||
self:ApplySliderProgress(self.sliderValue, true)
|
||||
self:RefreshListSummary()
|
||||
self:AppendLog("[UIDemoMain] 主界面已就绪,可测试全部 UI 控件与 7 类窗口")
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OnShow(self)
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OnHide(self)
|
||||
self:AppendLog("[UIDemoMain] OnHide(已被全屏窗口遮盖隐藏)")
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OnClose(self)
|
||||
self:StopProgressAnimation()
|
||||
self:ClearDynamicListItems()
|
||||
end
|
||||
function UIDemoMainWindow.prototype.SelectTab(self, index, label)
|
||||
self.activeTabIndex = index
|
||||
if self.tabSwitcher ~= nil then
|
||||
self.tabSwitcher:SetActiveWidgetIndex(index)
|
||||
end
|
||||
self:AppendLog(string.format("[Tab] 切换至:%s", label))
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenNormalDemoWindow(self)
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoNormalWindow,
|
||||
{onLog = function(____, m) return self:AppendLog(m) end}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenFullscreenDemoWindow(self)
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoFullscreenWindow,
|
||||
{
|
||||
onLog = function(____, m) return self:AppendLog(m) end,
|
||||
onOpenModal = function()
|
||||
self:OpenModalDemoWindow("全屏页上的模态弹窗", "验证 popup 层正确叠加在 fullscreen 全屏页面之上。")
|
||||
end
|
||||
}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenModalDemoWindow(self, title, message)
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoModalWindow,
|
||||
{
|
||||
title = title,
|
||||
message = message,
|
||||
onConfirm = function()
|
||||
self:AppendLog("[Modal] 用户点击了「确认」")
|
||||
self:ShowToast("模态弹窗:已确认")
|
||||
end,
|
||||
onCancel = function()
|
||||
self:AppendLog("[Modal] 用户点击了「取消」")
|
||||
end
|
||||
}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenCachedDemoWindow(self)
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoCachedWindow,
|
||||
{onLog = function(____, m) return self:AppendLog(m) end}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenMultiDemoWindow(self)
|
||||
self.multiSeq = self.multiSeq + 1
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoMultiWindow,
|
||||
{
|
||||
instanceSeq = self.multiSeq,
|
||||
onLog = function(____, m) return self:AppendLog(m) end
|
||||
}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ShowToast(self, message, durationSec)
|
||||
if durationSec == nil then
|
||||
durationSec = 2.2
|
||||
end
|
||||
self.toastSeq = self.toastSeq + 1
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoToastWindow,
|
||||
{
|
||||
message = message,
|
||||
durationSec = durationSec,
|
||||
offsetIndex = self.toastSeq - 1,
|
||||
onLog = function(____, m) return self:AppendLog(m) end
|
||||
}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.OpenSystemDemoWindow(self)
|
||||
return self.uiManager:ShowUI(
|
||||
UIDemoSystemWindow,
|
||||
{onLog = function(____, m) return self:AppendLog(m) end}
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.AddDynamicListItems(self, count)
|
||||
if self.scrollDynamicList == nil then
|
||||
return
|
||||
end
|
||||
if self.listItemClass == nil then
|
||||
self:PreloadDynamicListItemClass(function()
|
||||
self:AddDynamicListItems(count)
|
||||
end)
|
||||
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")
|
||||
do
|
||||
local i = 0
|
||||
while i < count do
|
||||
do
|
||||
self.nextListItemId = self.nextListItemId + 1
|
||||
local itemId = self.nextListItemId
|
||||
local itemWidget = UE.UWidgetBlueprintLibrary.Create(worldContext, self.listItemClass, lp0.playerController)
|
||||
if itemWidget == nil then
|
||||
goto __continue90
|
||||
end
|
||||
local itemScope = __TS__New(ScopedObject)
|
||||
local txtTitle = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "TxtItemTitle")
|
||||
local btnAct = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "BtnItemAction")
|
||||
local btnDel = UE.ULuaUIEventSubsystem.FindChildWidgetByName(itemWidget, "BtnItemDelete")
|
||||
if txtTitle ~= nil then
|
||||
txtTitle:SetText(string.format("动态条目 #%d — 测试委托自动回收", itemId))
|
||||
end
|
||||
local entry = {id = itemId, widget = itemWidget, scope = itemScope}
|
||||
if bridge ~= nil then
|
||||
if btnAct ~= nil then
|
||||
local hAct = bridge:BindButtonClick(
|
||||
btnAct,
|
||||
function()
|
||||
self:AppendLog(string.format("[ListItem #%d] 点击了「触发」", itemId))
|
||||
self:ShowToast(
|
||||
string.format("触发了列表项 #%d", itemId),
|
||||
1.5
|
||||
)
|
||||
end,
|
||||
itemScope
|
||||
)
|
||||
itemScope:AddScopedObject(hAct)
|
||||
end
|
||||
if btnDel ~= nil then
|
||||
local hDel = bridge:BindButtonClick(
|
||||
btnDel,
|
||||
function()
|
||||
self:RemoveDynamicListItem(itemId)
|
||||
end,
|
||||
itemScope
|
||||
)
|
||||
itemScope:AddScopedObject(hDel)
|
||||
end
|
||||
end
|
||||
self.scrollDynamicList:AddChild(itemWidget)
|
||||
self.dynamicItems[#self.dynamicItems + 1] = entry
|
||||
end
|
||||
::__continue90::
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
self.dynamicItemCount = #self.dynamicItems
|
||||
self:RefreshListSummary()
|
||||
self:RefreshHudAndDiagnostics()
|
||||
self:AppendLog(string.format("[ScrollBox] 新增 %d 个动态列表项(当前共 %d 项)", count, self.dynamicItemCount))
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RemoveDynamicListItem(self, itemId)
|
||||
do
|
||||
local i = #self.dynamicItems - 1
|
||||
while i >= 0 do
|
||||
local entry = self.dynamicItems[i + 1]
|
||||
if entry.id == itemId then
|
||||
entry.scope:Dispose()
|
||||
if entry.widget.RemoveFromParent ~= nil then
|
||||
entry.widget:RemoveFromParent()
|
||||
end
|
||||
table.remove(self.dynamicItems, i + 1)
|
||||
break
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
end
|
||||
self.dynamicItemCount = #self.dynamicItems
|
||||
self:RefreshListSummary()
|
||||
self:RefreshHudAndDiagnostics()
|
||||
self:AppendLog(string.format("[ScrollBox] 删除列表项 #%d(委托已自动解绑,剩余 %d 项)", itemId, self.dynamicItemCount))
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ClearDynamicListItems(self)
|
||||
local prev = #self.dynamicItems
|
||||
do
|
||||
local i = 0
|
||||
while i < #self.dynamicItems do
|
||||
self.dynamicItems[i + 1].scope:Dispose()
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
self.dynamicItems = {}
|
||||
self.dynamicItemCount = 0
|
||||
if self.scrollDynamicList ~= nil and self.scrollDynamicList.ClearChildren ~= nil then
|
||||
self.scrollDynamicList:ClearChildren()
|
||||
end
|
||||
self:RefreshListSummary()
|
||||
if prev > 0 then
|
||||
self:AppendLog(string.format("[ScrollBox] 已清空 %d 个动态列表项并释放全部子委托", prev))
|
||||
self:RefreshHudAndDiagnostics()
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.PreloadDynamicListItemClass(self, onReady)
|
||||
local resSvc = self.ctx:GetService("resource")
|
||||
if resSvc == nil then
|
||||
return
|
||||
end
|
||||
resSvc:LoadClassAsync(
|
||||
ASSET_KEYS.UI_DEMO_LIST_ITEM_WIDGET,
|
||||
self,
|
||||
function(ok, cls, _lease, err)
|
||||
if not ok or cls == nil then
|
||||
logger:Warn("Failed to load WBP_UIDemoListItem", {err = err})
|
||||
return
|
||||
end
|
||||
self.listItemClass = cls
|
||||
if onReady ~= nil and not self:IsDisposed() then
|
||||
onReady()
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.LoadAvatarAndPreview(self)
|
||||
local resSvc = self.ctx:GetService("resource")
|
||||
if resSvc == nil then
|
||||
return
|
||||
end
|
||||
resSvc:LoadTextureAsync(
|
||||
ASSET_KEYS.DEMO_AVATAR_TEX,
|
||||
self,
|
||||
function(ok, tex)
|
||||
if ok and tex ~= nil and self.imgPlayerAvatar ~= nil and not self:IsDisposed() then
|
||||
self.imgPlayerAvatar:SetBrushFromTexture(tex, false)
|
||||
end
|
||||
end
|
||||
)
|
||||
self:LoadPreviewTexture()
|
||||
end
|
||||
function UIDemoMainWindow.prototype.LoadPreviewTexture(self)
|
||||
local resSvc = self.ctx:GetService("resource")
|
||||
if resSvc == nil then
|
||||
return
|
||||
end
|
||||
local spec = PREVIEW_TEXTURES[self.previewTexIndex + 1]
|
||||
resSvc:LoadTextureAsync(
|
||||
spec.key,
|
||||
self,
|
||||
function(ok, tex)
|
||||
if ok and tex ~= nil and self.imgPreview ~= nil and not self:IsDisposed() then
|
||||
self.imgPreview:SetBrushFromTexture(tex, false)
|
||||
self:RefreshImageStatus()
|
||||
self:AppendLog(string.format("[Image] 异步贴图加载完成 -> %s", spec.label))
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.GetVisibilityLabel(self)
|
||||
if self.previewVisIndex == 0 then
|
||||
return "Visible(可见)"
|
||||
end
|
||||
if self.previewVisIndex == 1 then
|
||||
return "Hidden(隐身占位)"
|
||||
end
|
||||
return "Collapsed(折叠不占位)"
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RefreshImageStatus(self)
|
||||
local spec = PREVIEW_TEXTURES[self.previewTexIndex + 1]
|
||||
local tint = TINT_COLORS[self.previewTintIndex + 1]
|
||||
if self.txtImageStatus ~= nil then
|
||||
self.txtImageStatus:SetText(string.format(
|
||||
"贴图:%s | 着色:%s | 可见性:%s",
|
||||
spec.label,
|
||||
tint.name,
|
||||
self:GetVisibilityLabel()
|
||||
))
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RefreshBasicButtonStatus(self)
|
||||
if self.txtBasicBtnStatus ~= nil then
|
||||
self.txtBasicBtnStatus:SetText(string.format("按钮状态:点击 %d 次 | 悬停:%s | 受控按钮:%s", self.actionClickCount, self.actionHovered and "是" or "否", self.targetEnabled and "已启用" or "已禁用"))
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ApplySliderProgress(self, val, syncSliderWidget)
|
||||
local clamped = math.max(
|
||||
0,
|
||||
math.min(1, val)
|
||||
)
|
||||
self.sliderValue = clamped
|
||||
if syncSliderWidget and self.sliderDemo ~= nil then
|
||||
self.sliderDemo:SetValue(clamped)
|
||||
end
|
||||
if self.progressDemo ~= nil then
|
||||
self.progressDemo:SetPercent(clamped)
|
||||
end
|
||||
if self.barPlayerExp ~= nil then
|
||||
self.barPlayerExp:SetPercent(clamped)
|
||||
end
|
||||
if self.txtSliderStatus ~= nil then
|
||||
self.txtSliderStatus:SetText(string.format(
|
||||
"当前进度:%d%%(同时驱动主界面顶部经验条)",
|
||||
math.floor(clamped * 100 + 0.5)
|
||||
))
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ToggleProgressAnimation(self)
|
||||
if self.progressTimer ~= nil and self.progressTimer:IsActive() then
|
||||
self:StopProgressAnimation()
|
||||
self:AppendLog("[ProgressBar] 暂停进度动画")
|
||||
return
|
||||
end
|
||||
if self.txtProgressPlay ~= nil then
|
||||
self.txtProgressPlay:SetText("暂停自动进度动画")
|
||||
end
|
||||
self:AppendLog("[ProgressBar] 启动 WorldTimer 自动进度动画")
|
||||
self.progressTimer = self.ctx.scheduler:AddWorldRepeatTimer(
|
||||
0.05,
|
||||
function()
|
||||
local nextVal = self.sliderValue + 0.025
|
||||
if nextVal > 1 then
|
||||
nextVal = 0
|
||||
end
|
||||
self:ApplySliderProgress(nextVal, true)
|
||||
end,
|
||||
self
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.StopProgressAnimation(self)
|
||||
if self.progressTimer ~= nil then
|
||||
self.progressTimer:Cancel()
|
||||
self.progressTimer = nil
|
||||
end
|
||||
if self.txtProgressPlay ~= nil then
|
||||
self.txtProgressPlay:SetText("开始自动进度动画")
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ApplyNickname(self, name)
|
||||
self.currentNickname = name
|
||||
if self.txtPlayerName ~= nil then
|
||||
self.txtPlayerName:SetText(string.format("%s Lv.12", name))
|
||||
end
|
||||
self:AppendLog(string.format("[Player] 昵称已更新为:%s", name))
|
||||
self:ShowToast(
|
||||
string.format("昵称已更新:%s", name),
|
||||
1.8
|
||||
)
|
||||
end
|
||||
function UIDemoMainWindow.prototype.ApplyThemePreset(self, option)
|
||||
self.selectedTheme = option
|
||||
local matched = THEME_PRESETS[1]
|
||||
do
|
||||
local i = 0
|
||||
while i < #THEME_PRESETS do
|
||||
if THEME_PRESETS[i + 1].label == option then
|
||||
matched = THEME_PRESETS[i + 1]
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
if self.borderThemePreview ~= nil then
|
||||
self.borderThemePreview:SetBrushColor(MakeLinearColor(
|
||||
nil,
|
||||
matched.r,
|
||||
matched.g,
|
||||
matched.b,
|
||||
1
|
||||
))
|
||||
end
|
||||
if self.txtComboStatus ~= nil then
|
||||
self.txtComboStatus:SetText(string.format("当前选中:%s", option))
|
||||
end
|
||||
self:AppendLog(string.format("[ComboBox] 切换主题 -> %s", option))
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RefreshListSummary(self)
|
||||
if self.txtListSummary ~= nil then
|
||||
self.txtListSummary:SetText(string.format("动态列表项:%d 条(新增/删除时观察顶部活跃绑定数变化)", self.dynamicItemCount))
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RefreshHudAndDiagnostics(self)
|
||||
if self:IsDisposed() then
|
||||
return
|
||||
end
|
||||
local uiDiag = self.uiManager:GetDiagnostics()
|
||||
local bridge = self.ctx:GetService("uiDelegateBridge")
|
||||
local resSvc = self.ctx:GetService("resource")
|
||||
local activeBindings = bridge ~= nil and bridge:GetActiveBindingCount() or 0
|
||||
if self.txtHudStats ~= nil then
|
||||
self.txtHudStats:SetText(string.format(
|
||||
"窗口:%d | 缓存:%d | 绑定:%d | 模式:%s | 顶层:%s",
|
||||
uiDiag.openWindows,
|
||||
uiDiag.cachedWindows,
|
||||
activeBindings,
|
||||
uiDiag.inputMode == "ui" and "UI" or "Game",
|
||||
uiDiag.topWindowName or "无"
|
||||
))
|
||||
end
|
||||
if self.txtDiagDetail ~= nil then
|
||||
local stack = self.uiManager:GetWindowStackSnapshot()
|
||||
local cachedNames = self.uiManager:GetCachedWindowNames()
|
||||
local schedStats = self.ctx.scheduler:GetStats()
|
||||
local resDiag = resSvc ~= nil and resSvc:GetDiagnostics() or nil
|
||||
local lines = {}
|
||||
lines[#lines + 1] = string.format(
|
||||
"【UIManager】打开: %d | 加载中: %d | 缓存: %d | 输入模式: %s | 顶层: %s",
|
||||
uiDiag.openWindows,
|
||||
uiDiag.loadingWindows,
|
||||
uiDiag.cachedWindows,
|
||||
uiDiag.inputMode,
|
||||
uiDiag.topWindowName or "无"
|
||||
)
|
||||
lines[#lines + 1] = string.format("【UIDelegateBridge】活跃 UMG 控件委托数:%d", activeBindings)
|
||||
if resDiag ~= nil then
|
||||
lines[#lines + 1] = string.format("【ResourceService】在途加载: %d | 驻留资产: %d | 总引用计数: %d", resDiag.nativeInFlight, resDiag.nativeRetainedAssets, resDiag.nativeTotalRefCount)
|
||||
end
|
||||
lines[#lines + 1] = string.format("【FrameScheduler】Frame: %d | World: %d | Monotonic: %d", schedStats.frameTasks, schedStats.worldTasks, schedStats.monotonicTasks)
|
||||
lines[#lines + 1] = "--- 活动窗口栈 ---"
|
||||
do
|
||||
local i = 0
|
||||
while i < #stack do
|
||||
local s = stack[i + 1]
|
||||
lines[#lines + 1] = string.format(
|
||||
" %d. %s [layer=%s, type=%s, z=%d, vis=%s, block=%s%s]",
|
||||
i + 1,
|
||||
s.name,
|
||||
s.layer,
|
||||
s.type,
|
||||
s.zOrder,
|
||||
s.visible and "Y" or "N",
|
||||
s.blockWorldClick and "Y" or "N",
|
||||
s.hiddenByFullscreen and ", hiddenByFull" or ""
|
||||
)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
lines[#lines + 1] = #cachedNames > 0 and "--- 缓存池:" .. table.concat(cachedNames, ", ") or "--- 缓存池:空"
|
||||
self.txtDiagDetail:SetText(table.concat(lines, "\n"))
|
||||
end
|
||||
end
|
||||
function UIDemoMainWindow.prototype.AppendLog(self, entry)
|
||||
local now = self.ctx.scheduler:NowSeconds()
|
||||
local line = string.format("[%.1fs] %s", now, entry)
|
||||
self.logLines[#self.logLines + 1] = line
|
||||
if #self.logLines > 40 then
|
||||
table.remove(self.logLines, 1)
|
||||
end
|
||||
self:RenderLogText()
|
||||
end
|
||||
function UIDemoMainWindow.prototype.RenderLogText(self)
|
||||
if self.txtEventLog ~= nil then
|
||||
self.txtEventLog:SetText(#self.logLines > 0 and table.concat(self.logLines, "\n") or "[日志已清空]")
|
||||
end
|
||||
if self.scrollEventLog ~= nil and self.scrollEventLog.ScrollToEnd ~= nil then
|
||||
self.scrollEventLog:ScrollToEnd()
|
||||
end
|
||||
end
|
||||
RegisterUIConfig(____exports.UIDemoMainWindow, {
|
||||
name = "UIDemoMainWindow",
|
||||
assetKey = ASSET_KEYS.UI_DEMO_MAIN_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
|
||||
UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
|
||||
UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
|
||||
UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
|
||||
UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
|
||||
UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
|
||||
UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
|
||||
UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
|
||||
end
|
||||
@@ -0,0 +1,471 @@
|
||||
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
|
||||
Reference in new issue
Block a user