源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

287 行
8.3 KiB

--tabbar按钮(单个按钮)
NewUICusVerTabBtn = NewUICusVerTabBtn or BaseClass(BaseComponent)
-- NewUICusVerTabBtn.BTN_HEIGHT = 66 --tab按钮的高度,不包括下一级tab按钮的容器高度
-- NewUICusVerTabBtn.SUB_CON_WIDTH = 178 --下一级tab按钮的容器宽度
function NewUICusVerTabBtn:__init(parent, sub_item, size, tabbar,child_offset)
self.tabbar = tabbar
self.sub_btn_list = {}
self.tab_data = nil
self.index = 1
self.call_back = nil
self.show = false --是否展开
self.select_anything = false --是否可以在有子类的时候选中大类
self.btn_width = size and size.x or 189 --tab按钮的宽度,不包括下一级tab按钮的容器宽度
self.btn_height = size and size.y or 66 --tab按钮的高度,不包括下一级tab按钮的容器高度
self.sub_con_width = size and size.x - 16 or 178 --下一级tab按钮的容器宽度
self.sub_item = sub_item
self.child_offset = child_offset
self:CreateGameObject(UIType.UIVerTabBtn)
end
function NewUICusVerTabBtn:__delete()
for i,v in ipairs(self.sub_btn_list) do
v:DeleteMe()
v = nil
end
self.sub_btn_list = {}
if self.event_id then
GlobalEventSystem:UnBind(self.event_id)
self.event_id = nil
end
end
function NewUICusVerTabBtn:LoadSuccess()
self.btnText = self:GetChild("tab/Text"):GetComponent("Text")
self.btn_tran = self:GetChild("tab/Text")
self.icon = self:GetChild("tab/icon"):GetComponent("Image")
self.icon_tran = self:GetChild("tab/icon")
self.imgSelect = self:GetChild("tab/selectBg").gameObject
self.iconObj = self:GetChild("tab/icon").gameObject
self.addBtn = self:GetChild("subCon").gameObject
self.tab = self:GetChild("tab").gameObject
self.tab_img = self:GetChild("tab")
self.subCon = self:GetChild("subCon")
self.img = self:GetChild("tab/img").gameObject
self.red_dot = self:GetChild("tab/dot").gameObject
self:RedreshSize()
self:InitEvent()
end
function NewUICusVerTabBtn:InitEvent()
-- local function onBtnClickHandler(target)
-- if target == self.tab then
-- if self.call_back then
-- self.call_back(self.index,0)
-- end
-- end
-- end
-- AddClickEvent(self.tab, onBtnClickHandler,2)
end
--设置tab数据
function NewUICusVerTabBtn:SetTabDetail(data, index, call_back, select_anything, force_size)
self.tab_data = data
self.index = index
self.call_back = call_back
self.select_anything = select_anything
self.force_size = force_size
if data == nil or self.tab_data.main_tab == nil then return end
self:SetText(self.tab_data.main_tab)
if self.tab_data == nil or #self.tab_data.sub_tab == 0 then
self.iconObj:SetActive(false)
else
self.iconObj:SetActive(true)
end
self:SetSubBtns(self.tab_data.sub_tab, self.index, call_back)
end
--设置下一级的按钮
function NewUICusVerTabBtn:SetSubBtns(sub_tab_list, parent_index, call_back)
for i,v in ipairs(self.sub_btn_list) do
v:SetVisible(false)
end
for i,v in ipairs(sub_tab_list) do
local sub_tab = self.sub_btn_list[i]
if sub_tab == nil then
sub_tab = self.sub_item.New(self.subCon)
self.sub_btn_list[i] = sub_tab
if self.force_size then
sub_tab:SetTabSubBtnSize(self.sub_con_width)
end
end
-- sub_tab:SetSubDeail(v, parent_index, i, call_back)
sub_tab:SetData(v, parent_index, i, call_back)
sub_tab:SetVisible(true)
local x = 0
local y = -(i - 1) * self.sub_item.Height
x = self.offset and self.offset.x + x or x
y = self.offset and -(i - 1) * self.offset.y + y or y
sub_tab:SetPosition(x, y)
-- local function onBtnClickHandler(target)
-- self:SetSelectSubIndex(0, 0)
-- self:SetSelectSubIndex(sub_tab.parent_idnex, sub_tab.sub_index)
-- end
-- if sub_tab.Button then
-- AddClickEvent(sub_tab.Button, onBtnClickHandler,2)
-- end
end
self.subCon.gameObject:SetActive(false)
end
--选中菜单
function NewUICusVerTabBtn:SetSelectMode(index, sub_index,force_show)
if self.index == index then
self.show = not self.show
else
self.show = false
end
-- self.show = not self.show
if force_show and self.index == index then
self.show = true
end
if self.show and index then
self.icon_tran.transform.localRotation = Quaternion.Euler(0,0,-90)
self:SetSelectState(true)
--SetRotate(self.icon_tran, 0, 0, -90)
--lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
--self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2,0)
self:ShowSubBtnVisible(true)
-- if sub_index then
-- self:SetSelectSubIndex(index, sub_index)
-- end
else
SetLocalRotation(self.icon_tran, 0, 0, 0)
self:SetSelectState(false)
--lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
--self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
self:ShowSubBtnVisible(false)
end
end
--设置图标,隐藏sub
function NewUICusVerTabBtn:RefreshBtnState(show)
self.show = show
if self.show then
self.icon_tran.transform.localRotation = Quaternion.Euler(0,0,-90)
--SetRotate(self.icon_tran, 0, 0, -90)
--lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
--self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2,0)
else
SetLocalRotation(self.icon_tran, 0, 0, 0)
--lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
--self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
end
if self.subCon and self.sub_btn_list and #self.sub_btn_list ~= 0 then
self.subCon.gameObject:SetActive(show)
end
end
--设置选中的子一级tab
function NewUICusVerTabBtn:SetSelectSubIndex(index, sub_index)
for i,v in ipairs(self.sub_btn_list) do
if v.parent_index == index and v.sub_index == sub_index then
v:SetSelected(true, true)
else
v:SetSelected(false)
end
end
end
function NewUICusVerTabBtn:SetText(str)
self.btnText.text = str
end
function NewUICusVerTabBtn:ShowSubBtnVisible(bool)
if self.subCon and self.sub_btn_list and #self.sub_btn_list ~= 0 then
self.subCon.gameObject:SetActive(bool)
if self.select_anything then
--if self.call_back then self.call_back(self.index,0) end
end
else
--if self.call_back then self.call_back(self.index,0) end
end
end
function NewUICusVerTabBtn:SetSubConSize(height)
-- self.subCon.sizeDelta = Vector2(NewUICusVerTabBtn.SUB_CON_WIDTH, height)
end
--设置大小
function NewUICusVerTabBtn:SetTabBtnSize()
end
function NewUICusVerTabBtn:SetSelectState(b)
self.imgSelect:SetActive(b)
if b then
self:SetSelectBg()
end
end
function NewUICusVerTabBtn:SetSelectBg()
if self.imgSelect:GetComponent("Image").sprite.name == "empty" then
lua_resM:setImageSprite(self,self.imgSelect:GetComponent("Image"),"common_asset","tyui_btn3_1")
self.imgSelect.transform.anchorMin = Vector2(0, 0)
self.imgSelect.transform.anchorMax = Vector2(1, 1)
self.imgSelect.transform.offsetMax = Vector2(0, 0)
self.imgSelect.transform.offsetMin = Vector2(0, 0)
SetAnchoredPosition(self.imgSelect.transform,0,0)
end
end
function NewUICusVerTabBtn:SetImageTexture(asset_path,res_name)
if asset_path and res_name then
self.img:SetActive(true)
lua_resM:setImageSprite(self,self.img:GetComponent("Image"),asset_path,res_name)
else
self.img:SetActive(false)
end
end
function NewUICusVerTabBtn:ShowRedDot(list)
if list and #list > 0 then
table.sort(list)
end
self.sub_red_list = list
for i, v in ipairs(self.sub_btn_list) do
v:ShowRedDot(false)
end
if not list or #list == 0 then
self.red_dot:SetActive(false)
else
self.red_dot:SetActive(true)
for i, v in ipairs(list) do
if self.sub_btn_list[v] then
self.sub_btn_list[v]:ShowRedDot(true)
end
end
end
if list[0] then
self.red_dot:SetActive(true)
end
end
function NewUICusVerTabBtn:SetSubOffset(offset)
self.offset = offset
end
--加载完但不显示的不需计算高度
function NewUICusVerTabBtn:GetVisibleCount(visible)
local count = 0
for _,v in ipairs(self.sub_btn_list) do
if v:GetVisible() == visible or not v.is_loaded then
count = count + 1
end
end
return count
end
function NewUICusVerTabBtn:RedreshSize()
self.tab_img.sizeDelta = Vector2(self.btn_width, self.btn_height)
--self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
SetAnchoredPosition(self.tab.transform,0,0)
if self.child_offset then
self.subCon.localPosition = Vector3(self.child_offset.x, self.child_offset.y,0)
else
self.subCon.localPosition = Vector3(self.subCon.localPosition.x, -self.btn_height,0)
end
end