-- xx界面 local CLLPPopTime = {} ---@type Coolape.CLPanelLua local csSelf = nil ---@type UnityEngine.Transform local transform = nil local uiobjs = {} local defaultTime local callback local hours = {} local minutes = {} local seconds = {} local hh, mm, ss local firstCell -- 初始化,只会调用一次 function CLLPPopTime.init(csObj) csSelf = csObj transform = csObj.transform -- table.insert(hours, joinStr(NumEx.nStrForLen(23, 2), "点")) -- for i = 0, 22 do -- table.insert(hours, joinStr(NumEx.nStrForLen(i, 2), "点")) -- end -- table.insert(minutes, joinStr(NumEx.nStrForLen(59, 2), "分")) -- table.insert(seconds, joinStr(NumEx.nStrForLen(59, 2), "秒")) -- for i = 0, 58 do -- table.insert(minutes, joinStr(NumEx.nStrForLen(i, 2), "分")) -- table.insert(seconds, joinStr(NumEx.nStrForLen(i, 2), "秒")) -- end ---@type UISprite uiobjs.SpriteBg = getCC(transform, "Bottom/offset/SpriteBg", "UISprite") local offset = getChild(transform, "Bottom/offset") ---@type Coolape.CLUILoopGrid uiobjs.listGridHH = getCC(offset, "ListHH/Content/Grid", "CLUILoopGrid") uiobjs.centerOnChildHH = uiobjs.listGridHH:GetComponent("UICenterOnChild") ---@type Coolape.CLUILoopGrid uiobjs.listGridMM = getCC(offset, "ListMM/Content/Grid", "CLUILoopGrid") uiobjs.centerOnChildMM = uiobjs.listGridMM:GetComponent("UICenterOnChild") ---@type Coolape.CLUILoopGrid uiobjs.listGridSS = getCC(offset, "ListSS/Content/Grid", "CLUILoopGrid") uiobjs.centerOnChildSS = uiobjs.listGridSS:GetComponent("UICenterOnChild") end -- 设置数据 function CLLPPopTime.setData(paras) callback = MapEx.getObject(paras, "callback") defaultTime = MapEx.getString(paras, "time") defaultTime = isNilOrEmpty(defaultTime) and DateEx.toHHMMSS(DateEx.nowMS) or defaultTime local strs = strSplit(defaultTime, ":") hh = strs[1] mm = strs[2] ss = strs[3] CLLPPopTime.setPopList(hh, mm, ss) end function CLLPPopTime.setPopList(hh, mm, ss) hours = {} local h = hh -1 if h < 0 then h = 23 end table.insert(hours, joinStr(NumEx.nStrForLen(h, 2), "点")) for i = 0, 22 do h = hh + i if h > 23 then h = h - 24 end table.insert(hours, joinStr(NumEx.nStrForLen(h, 2), "点")) end minutes = {} seconds = {} local m = mm -1 if m < 0 then m = 59 end local s = ss -1 if s < 0 then s = 59 end table.insert(minutes, joinStr(NumEx.nStrForLen(m, 2), "分")) table.insert(seconds, joinStr(NumEx.nStrForLen(s, 2), "秒")) for i = 0, 58 do m = mm + i if m > 59 then m = m - 60 end s = ss + i if s > 59 then s = s - 60 end table.insert(minutes, joinStr(NumEx.nStrForLen(m, 2), "分")) table.insert(seconds, joinStr(NumEx.nStrForLen(s, 2), "秒")) end end --当有通用背板显示时的回调 function CLLPPopTime.onShowFrame() end -- 显示,在c#中。show为调用refresh,show和refresh的区别在于,当页面已经显示了的情况,当页面再次出现在最上层时,只会调用refresh function CLLPPopTime.show() firstCell = nil uiobjs.listGridHH:setList(hours, CLLPPopTime.initCellHour, CLLPPopTime.onHeadHour, CLLPPopTime.onEndHour) uiobjs.centerOnChildHH:Recenter() -- uiobjs.centerOnChildHH:CenterOn(firstCell.transform) firstCell = nil uiobjs.listGridMM:setList(minutes, CLLPPopTime.initCellMinute, CLLPPopTime.onHeadMinute, CLLPPopTime.onEndMinute) uiobjs.centerOnChildMM:Recenter() -- uiobjs.centerOnChildMM:CenterOn(firstCell.transform) firstCell = nil uiobjs.listGridSS:setList(seconds, CLLPPopTime.initCellSec, CLLPPopTime.onHeadSec, CLLPPopTime.onEndSec) uiobjs.centerOnChildSS:Recenter() -- uiobjs.centerOnChildSS:CenterOn(firstCell.transform) end function CLLPPopTime.initCellHour(cell, data) cell:init(data, nil) cell.luaTable.setCenterObj(uiobjs.centerOnChildHH) if firstCell == nil then firstCell = cell end end function CLLPPopTime.onHeadHour(head) uiobjs.listGridHH:insertList(hours) end function CLLPPopTime.onEndHour(tail) uiobjs.listGridHH:appendList(hours) end function CLLPPopTime.initCellMinute(cell, data) cell:init(data, nil) cell.luaTable.setCenterObj(uiobjs.centerOnChildMM) if firstCell == nil then firstCell = cell end end function CLLPPopTime.onHeadMinute(head) uiobjs.listGridMM:insertList(minutes) end function CLLPPopTime.onEndMinute(tail) uiobjs.listGridMM:appendList(minutes) end function CLLPPopTime.initCellSec(cell, data) cell:init(data, nil) cell.luaTable.setCenterObj(uiobjs.centerOnChildSS) if firstCell == nil then firstCell = cell end end function CLLPPopTime.onHeadSec(head) uiobjs.listGridSS:insertList(seconds) end function CLLPPopTime.onEndSec(tail) uiobjs.listGridSS:appendList(seconds) end function CLLPPopTime.onStartCenterOnChild(scrollview) end function CLLPPopTime.onCenterChild(center, scrollview) ---@type Coolape.CLUILoopGrid local grid = getCC(scrollview.transform, "Grid", "CLUILoopGrid") grid:refreshContentOnly() end function CLLPPopTime.onFinishCenterChild(scrollview) end -- 刷新 function CLLPPopTime.refresh() end -- 关闭页面 function CLLPPopTime.hide() end -- 网络请求的回调;cmd:指命,succ:成功失败,msg:消息;paras:服务器下行数据 function CLLPPopTime.procNetwork(cmd, succ, msg, paras) end -- 处理ui上的事件,例如点击等 function CLLPPopTime.uiEventDelegate(go) local goName = go.name if goName == "ButtonClose" then hideTopPanel(csSelf) elseif goName == "ButtonOkay" then local cell = uiobjs.centerOnChildHH.centeredObject:GetComponent("CLCellLua") local hh = cell.luaTable.getData() hh = string.gsub(hh, "点", "") cell = uiobjs.centerOnChildMM.centeredObject:GetComponent("CLCellLua") local mm = cell.luaTable.getData() mm = string.gsub(mm, "分", "") cell = uiobjs.centerOnChildSS.centeredObject:GetComponent("CLCellLua") local ss = cell.luaTable.getData() ss = string.gsub(ss, "秒", "") hideTopPanel(csSelf) Utl.doCallback(callback, joinStr(hh, ":", mm, ":", ss)) end end -- 当顶层页面发生变化时回调 function CLLPPopTime.onTopPanelChange(topPanel) end -- 当按了返回键时,关闭自己(返值为true时关闭) function CLLPPopTime.hideSelfOnKeyBack() if NetProto and csSelf then NetProto.removePanelListener(csSelf) end return true end -------------------------------------------- return CLLPPopTime