74 lines
1.8 KiB
Lua
74 lines
1.8 KiB
Lua
-- xx界面
|
||
CLToastRoot = {}
|
||
|
||
---@type Coolape.CLPanelLua
|
||
local csSelf = nil
|
||
---@type UnityEngine.Transform
|
||
local transform = nil
|
||
local uiobjs = {}
|
||
local queue = CLLQueue.new()
|
||
local index = 0
|
||
|
||
CLToastRoot.Type = {
|
||
normal = 0,
|
||
success = 1,
|
||
warning = 2,
|
||
error = 3
|
||
}
|
||
-- 初始化,只会调用一次
|
||
function CLToastRoot.init(csObj)
|
||
csSelf = csObj
|
||
transform = csObj.transform
|
||
---@type UITable
|
||
uiobjs.Table = getCC(transform, "offset", "UITable")
|
||
uiobjs.prefab = getCC(uiobjs.Table.transform, "00000", "CLCellLua")
|
||
SetActive(uiobjs.prefab.gameObject, false)
|
||
end
|
||
|
||
-- 关闭页面
|
||
function CLToastRoot.show()
|
||
end
|
||
-- 关闭页面
|
||
function CLToastRoot.hide()
|
||
end
|
||
|
||
function CLToastRoot.borrow()
|
||
local cell
|
||
if queue:size() == 0 then
|
||
local go = GameObject.Instantiate(uiobjs.prefab.gameObject, uiobjs.Table.transform)
|
||
cell = go:GetComponent("CLCellLua")
|
||
else
|
||
cell = queue:deQueue()
|
||
end
|
||
cell.name = string.format("%11d", index)
|
||
index = index + 1
|
||
return cell
|
||
end
|
||
|
||
function CLToastRoot.returnToast(cell)
|
||
SetActive(cell.gameObject, false)
|
||
queue:enQueue(cell)
|
||
end
|
||
|
||
function CLToastRoot.toast(msg, type, staySec)
|
||
if isNilOrEmpty(msg) then
|
||
return
|
||
end
|
||
local cell = CLToastRoot.borrow()
|
||
SetActive(cell.gameObject, true)
|
||
cell:init({msg = msg, type = type, staySec = staySec}, nil)
|
||
uiobjs.Table:Reposition()
|
||
end
|
||
|
||
-- 处理ui上的事件,例如点击等
|
||
function CLToastRoot.uiEventDelegate(go)
|
||
local cell = go:GetComponent("CLCellLua")
|
||
if cell then
|
||
SetActive(go, false)
|
||
csSelf:invoke4Lua(CLToastRoot.returnToast, cell, 0.1)
|
||
end
|
||
end
|
||
|
||
--------------------------------------------
|
||
return CLToastRoot
|