源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

359 lines
12 KiB

--tabbar按钮(单个按钮)
UIVerTabBtn = UIVerTabBtn or BaseClass(BaseComponent)
local UIVerTabBtn = UIVerTabBtn
UIVerTabBtn.BTN_HEIGHT = 50 --tab按钮的高度,不包括下一级tab按钮的容器高度
UIVerTabBtn.SUB_CON_WIDTH = 171 --下一级tab按钮的容器宽度
UIVerTabBtn.TYPE = {
normal = 1,
designation = 2,
}
UIVerTabBtn.Parms = {
[1] = {
BTN_HEIGHT = 56,
BTN_WIDTH = 186,
BTN_Y_SPACE = 10,
SUB_CON_WIDTH = 186,
SUB_CON_HEIGHT = 48,
SUB_BTN_Y_SPACE = 2,
SubConPosOffset = {5, -20},
normalsource = "ui_tab_bg",
selectsource = "ui_tab_bg_select2",
abname = "uicomponent_asset",
-- text_color_nor = Color(1,1,1,1),
-- text_color_sel = Color(1,1,1,1),
-- sub_btn_text_color_nor = Color(1,1,1,1),
-- sub_btn_text_color_sel = Color(1,1,1,1),
need_newsouce = false,--如果是false 就不需要填后面的参数了
need_show_arrow = true,--是否显示上下箭头
},
-- [2] = {
-- BTN_HEIGHT = 51,
-- BTN_WIDTH = 206,
-- BTN_Y_SPACE = 8,
-- SUB_CON_WIDTH = 210,
-- SUB_CON_HEIGHT = 68,
-- SUB_BTN_Y_SPACE = 0,
-- SubConPosOffset = {3, -20},
-- normalsource = "design_blue",
-- selectsource = "design_orange",
-- abname = "designation_asset",
-- need_newsouce = true,
-- sub_normal = "design_sub_blue",
-- sub_select = "design_sub_orange",
-- subabname = "designation_asset",
-- text_color_nor = Color(255/255,255/255,255/255,1),
-- text_color_sel = Color(155/255,87/255,47/255,1),
-- },
}
-- is_btn_need_select_img:大类按钮是否需要设置选中的背景图
function UIVerTabBtn:__init(parent, call_back, desc, tabbar,type_id,is_btn_need_select_img)
self.tabbar = tabbar
self.sub_btn_list = {}
self.tab_data = nil
self.index = 1
self.call_back = nil
self.type_id = type_id or 1
self.is_btn_need_select_img = is_btn_need_select_img or false
self.style_data = UIVerTabBtn.Parms[self.type_id]
self.show = false --是否展开
self.select_anything = false --是否可以在有子类的时候选中大类
self.new_source = false
self:CreateGameObject(UIType.UIVerTabBtn)
self:InitData(call_back, desc)
end
function UIVerTabBtn:__delete()
self:UnBindEvent()
end
function UIVerTabBtn:UnBindEvent()
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 UIVerTabBtn:InitData(call_back, text)
self.call_back = call_back
self.btnText.text = text
end
function UIVerTabBtn:LoadSuccess()
self.nodes = {
"tab/normalText:tmp:obj",
}
self:GetChildren(self.nodes)
self.btnText = self:GetChild("tab/Text"):GetComponent("TextMeshProUGUI")
self.btnText_obj = self:GetChild("tab/Text").gameObject
self.icon = self:GetChild("tab/icon"):GetComponent("Image")
self.icon_tran = self:GetChild("tab/icon")
self.icon_pos = self.icon_tran.localPosition
self.imgSelect = self:GetChild("tab/selectBg").gameObject
self.imgSelect_img = self:GetChild("tab/selectBg"):GetComponent("Image")
self.iconObj = self:GetChild("tab/icon").gameObject
self.addBtn = self:GetChild("subCon").gameObject
self.tab = self:GetChild("tab").gameObject
self.tab_image = self:GetChild("tab"):GetComponent("Image")
self.tab_con = self:GetChild("tab")
self.subCon = self:GetChild("subCon")
self.img = self:GetChild("tab/img").gameObject
self.img:SetActive(false)
self.dot = self:GetChild("tab/dot").gameObject
self.dot:SetActive(false)
if self.is_btn_need_select_img then
lua_resM:setImageSprite(self,self.imgSelect_img,"uiComponent_asset","ui_subtab_selected")
else
lua_resM:setImageSprite(self,self.imgSelect_img,"uiComponent_asset","com_empty")
end
self:InitEvent()
end
function UIVerTabBtn:InitEvent()
local select_fun = function (tabbar, parent_idnex, sub_index)
if self.tabbar == tabbar then
if self.index == parent_idnex then
self:SetSelectSubIndex(parent_idnex, sub_index)
else
self:SetSelectSubIndex(0, 0)
end
end
end
self.event_id = GlobalEventSystem:Bind(EventName.SUB_TAB_BTN_BE_SELECTED, select_fun)
end
function UIVerTabBtn:SetSelectMode(index,sub_index,force_show, quick_select)
self.show = not self.show
if force_show then
self.show = true
end
if self.show and index then
lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
lua_resM:setImageSprite(self,self.tab_image,UIVerTabBtn.Parms[self.type_id].abname,UIVerTabBtn.Parms[self.type_id].selectsource)
-- if self.new_source then
-- lua_resM:setImageSprite(self, self.tab_image, "designation_asset", "design_orange")
--self.btnText.color = UIVerTabBtn.Parms[self.type_id].text_color_sel
-- end
-- self.icon_tran.localPosition = Vector3(self.icon_pos.x, self.icon_pos.y - 7,0)
self:ShowSubBtnVisible(true)
if sub_index then
-- self:SetSelectSubIndex(index, sub_index)
GlobalEventSystem:Fire(EventName.SUB_TAB_BTN_BE_SELECTED, self.tabbar, index, sub_index)
elseif quick_select then
local select_index
if self.sub_red_list and #self.sub_red_list > 0 then
select_index = self.sub_red_list[1]
else
select_index = self.sub_btn_list[1] and self.sub_btn_list[1].sub_index
end
if select_index then
-- self:SetSelectSubIndex(index, select_index)
GlobalEventSystem:Fire(EventName.SUB_TAB_BTN_BE_SELECTED, self.tabbar, index, select_index)
end
end
else
lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
lua_resM:setImageSprite(self,self.tab_image,UIVerTabBtn.Parms[self.type_id].abname,UIVerTabBtn.Parms[self.type_id].normalsource)
-- if self.new_source then
-- lua_resM:setImageSprite(self,self.tab_image,"designation_asset","design_blue")
--self.btnText.color = UIVerTabBtn.Parms[self.type_id].text_color_nor
-- end
-- self.icon_tran.localPosition = Vector3(self.icon_pos.x, self.icon_pos.y,0)
self:ShowSubBtnVisible(false)
end
end
function UIVerTabBtn:RefreshBtnState(show)
self.show = show
if self.show then
lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
lua_resM:setImageSprite(self,self.tab_image,UIVerTabBtn.Parms[self.type_id].abname,UIVerTabBtn.Parms[self.type_id].selectsource)
-- if self.new_source then
-- lua_resM:setImageSprite(self,self.tab_image,"designation_asset","design_orange")
--self.btnText.color = UIVerTabBtn.Parms[self.type_id].text_color_sel
-- end
-- self.icon_tran.localPosition = Vector3(self.icon_pos.x, self.icon_pos.y - 7,0)
else
lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
-- lua_resM:setImageSprite(self,self.tab_image,"uicomponent_asset","ui_tab_bg",true)
lua_resM:setImageSprite(self,self.tab_image,UIVerTabBtn.Parms[self.type_id].abname,UIVerTabBtn.Parms[self.type_id].normalsource)
-- if self.new_source then
-- lua_resM:setImageSprite(self,self.tab_image,"designation_asset","design_blue")
--self.btnText.color = UIVerTabBtn.Parms[self.type_id].text_color_nor
-- end
-- self.icon_tran.localPosition = Vector3(self.icon_pos.x, self.icon_pos.y,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 UIVerTabBtn:SetSelectSubIndex(index, sub_index)
for i,v in ipairs(self.sub_btn_list) do
if v.parent_idnex == index and v.sub_index == sub_index then
v:SetSelected(true)
else
v:SetSelected(false)
end
end
end
--设置tab数据
function UIVerTabBtn:SetTabDetail(data, index, call_back, select_anything)
self.tab_data = data
self.index = index
self.call_back = call_back
self.select_anything = select_anything
if self.tab_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)
SetAnchoredPositionX(self.btnText.transform,-0.55)
SetSizeDeltaX(self.btnText.transform,176.1)
elseif self.style_data and self.style_data.need_show_arrow then
self.iconObj:SetActive(true)
SetAnchoredPositionX(self.btnText.transform,-7.61)
SetSizeDeltaX(self.btnText.transform,161.97)
end
self:SetTabBtnSize()
self:SetSubBtns(self.tab_data.sub_tab, self.index, call_back)
end
function UIVerTabBtn:SetText(str)
self.btnText.text = str
self.normalText_tmp.text = str
end
--设置下一级的按钮
function UIVerTabBtn: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 = UIVerTabSubBtn.New(self.subCon)
self.sub_btn_list[i] = sub_tab
end
sub_tab:SetSubDeail(v, parent_index, i, call_back)
sub_tab:SetVisible(true)
sub_tab:SetStyleData(UIVerTabBtn.Parms[self.type_id])
local x = -5
local y = -(i - 1) * (UIVerTabBtn.Parms[self.type_id].SUB_CON_HEIGHT + (UIVerTabBtn.Parms[self.type_id].SUB_BTN_Y_SPACE or 10)) + 20
if UIVerTabBtn.Parms[self.type_id].need_newsouce then
sub_tab:SetNewSource(UIVerTabBtn.Parms[self.type_id])
sub_tab:ResetSubDeail(self.tab_data.info[i])
end
self.iconObj:SetActive(self.style_data and self.style_data.need_show_arrow or false)
local is_text_middle = self.style_data and self.style_data.need_show_arrow or false
if not is_text_middle then
SetAnchoredPositionX(self.btnText.transform,-0.55)
SetSizeDeltaX(self.btnText.transform,176.1)
else
SetAnchoredPositionX(self.btnText.transform,-7.61)
SetSizeDeltaX(self.btnText.transform,161.97)
end
sub_tab:SetPosition(x, y)
local function onBtnClickHandler(target)
GlobalEventSystem:Fire(EventName.SUB_TAB_BTN_BE_SELECTED, self.tabbar, sub_tab.parent_idnex, sub_tab.sub_index)
end
if sub_tab.Button then
AddClickEvent(sub_tab.Button, onBtnClickHandler,LuaSoundManager.SOUND_UI.SWITCH)
end
end
self.subCon.gameObject:SetActive(false)
end
function UIVerTabBtn: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
self.call_back(self.index,0)
end
else
self.call_back(self.index,0)
end
end
function UIVerTabBtn:SetSubConSize(height)
self.subCon.sizeDelta = Vector2(UIVerTabBtn.Parms[self.type_id].SUB_CON_WIDTH, height)
end
--设置大小
function UIVerTabBtn:SetTabBtnSize()
if not self.type_id or not UIVerTabBtn.Parms[self.type_id] then return end
-- print("Nice:UIVerTabBtn [243]222 : ")
self.tab_con.sizeDelta = Vector2(UIVerTabBtn.Parms[self.type_id].BTN_WIDTH,UIVerTabBtn.Parms[self.type_id].BTN_HEIGHT)
local pos_offset = UIVerTabBtn.Parms[self.type_id].SubConPosOffset
if pos_offset then
SetLocalPosition(self.subCon, pos_offset[1], -self.tab_con.sizeDelta.y + pos_offset[2])
end
end
function UIVerTabBtn:SetSelectState(b)
self.normalText_obj:SetActive(not b)
self.btnText_obj:SetActive(b)
self.imgSelect:SetActive(b)
end
function UIVerTabBtn: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,true)
else
self.img:SetActive(false)
end
end
function UIVerTabBtn:ShowRedDot(list)
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.dot:SetActive(false)
else
self.dot:SetActive(true)
for i, v in pairs(list) do
if self.sub_btn_list[v] then
self.sub_btn_list[v]:ShowRedDot(true)
end
end
end
end
function UIVerTabBtn:SetNewSource( )
self.new_source = true
self.iconObj:SetActive(false)
SetAnchoredPositionX(self.btnText.transform,-0.55)
SetSizeDeltaX(self.btnText.transform,176.1)
self:SetTabBtnSize()
for i, v in ipairs(self.sub_btn_list) do
v:SetNewSource()
v:ResetSubDeail(self.tab_data.info[i])
end
SetLocalPosition(self.subCon.transform, 1, -42, 0)
end