Files
Main/Assets/GameAssets/Resources/Lua/UI/Components/UICheckBoxList.lua
2025-01-25 04:38:09 +08:00

72 lines
1.8 KiB
Lua

------------------------------------------------
--作者: 何健
--日期: 2020-02-11
--文件: UICheckBoxList.lua
--模块: UICheckBoxList
--描述: 选择框控件列表,单选
------------------------------------------------
local L_CheckBox = {}
local UICheckBoxList ={
Trans = nil,
Go = nil,
CallBack = nil,
CheckBoxList = List:New(),
}
function L_CheckBox:OnFirstShow(trans, id)
local _M = Utils.DeepCopy(self)
_M.Trans = trans
_M.Go = trans.gameObject
_M.id = id
_M.OkGo = UIUtils.FindGo(trans, "Ok")
_M.CheckBtn = UIUtils.FindBtn(trans)
_M.OkGo:SetActive(_M.IsChecked)
UIUtils.AddBtnEvent(_M.CheckBtn, _M.onClickCheckBtn, _M)
return _M
end
--设置选中
function L_CheckBox:SetChecked(ischeck)
if self.IsChecked ~= ischeck then
self.IsChecked = ischeck
self.OkGo:SetActive(self.IsChecked)
end
end
function L_CheckBox:onClickCheckBtn()
if self.CallBack then
self.CallBack(self.id)
end
end
function UICheckBoxList:OnFirstShow(trans)
local _M = Utils.DeepCopy(self)
_M.Trans = trans
_M.Go = trans.gameObject
local _index = 1
while true do
local _childTrans = UIUtils.FindTrans(trans, tostring(_index))
if _childTrans then
local _checkItem = L_CheckBox:OnFirstShow(_childTrans, _index)
_checkItem.CallBack = Utils.Handler(_M.onClickCheckBtn, _M)
_M.CheckBoxList:Add(_checkItem)
else
break
end
_index = _index + 1
end
return _M
end
--设置选中
function UICheckBoxList:SetChecked(id)
for i = 1, #self.CheckBoxList do
self.CheckBoxList[i]:SetChecked(id == i)
end
if self.CallBack then
self.CallBack(id)
end
end
function UICheckBoxList:onClickCheckBtn(id)
self:SetChecked(id)
end
return UICheckBoxList