changhong_newclient/lua_probject/base_project/Game/View/Common/MsgWindow.lua

81 lines
2.0 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
--通用消息弹出框View
--author--
MsgWindow = {}
MsgWindow.MsgMode = {
OkAndCancel = 1,
OnlyOk = 2
}
MsgWindow.RES_LIST = {
2025-07-28 23:47:06 +08:00
"MessageBox",
"MessageBox1"
2025-05-24 14:29:14 +08:00
}
local M = MsgWindow
2025-07-28 23:47:06 +08:00
function MsgWindow.new(blur_view, tip, mode, url, showCheck, data)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-05-24 14:29:14 +08:00
self.class = "MsgWindow"
self._blur_view = blur_view
self._close_destroy = true
self._tip = tip
self._mode = mode
2025-07-28 23:47:06 +08:00
self.onOk = event("onOk", true)
self.onCancel = event("onCancel", true)
2025-05-24 14:29:14 +08:00
self.showCheck = showCheck
2025-07-28 23:47:06 +08:00
self.data = data
local self_url = url and url or "ui://Common/" .. MsgWindow.RES_LIST[self._mode]
2025-05-24 14:29:14 +08:00
self:init(self_url)
return self
end
function M:init(url)
2025-07-28 23:47:06 +08:00
BaseWindow.init(self, url)
2025-05-24 14:29:14 +08:00
self._close_destroy = true
2025-07-28 23:47:06 +08:00
if not self.data or not self.data.closeZone then
self._close_zone = false
end
2025-05-24 14:29:14 +08:00
local view = self._view
local btn_ok = view:GetChild("btn_ok")
btn_ok.onClick:Add(function()
self.onOk()
self:Destroy()
end)
local tex_message = view:GetChild("tex_message")
if (self._tip) then tex_message.text = self._tip end
2025-07-28 23:47:06 +08:00
2025-05-24 14:29:14 +08:00
local btn_close = view:GetChild('btn_close1')
2025-07-28 23:47:06 +08:00
if not self.data or not self.data.openClose then
btn_close.visible = false
end
if (btn_close ~= nil) then
2025-05-24 14:29:14 +08:00
btn_close.onClick:Add(
function()
self:CloseEvent()
end
2025-07-28 23:47:06 +08:00
--self:Destroy()
2025-05-24 14:29:14 +08:00
)
end
self.btnCheck = view:GetChild("btnCheck")
if self.btnCheck then
self.btnCheck.visible = false
if self.showCheck then
self.btnCheck.selected = true
self.btnCheck.visible = true
end
end
2025-07-28 23:47:06 +08:00
if self.data and self.data.titleUrl then
view:GetChild('n18').icon = self.data.titleUrl
end
2025-05-24 14:29:14 +08:00
end
function M:Close()
BaseWindow.Close(self)
2025-07-28 23:47:06 +08:00
if (self._mode == MsgWindow.MsgMode.OkAndCancel) then
2025-05-24 14:29:14 +08:00
self.onCancel()
end
end