|
|
- --子一级的tabbar按钮(单个按钮)
- UIHorTabBtn = UIHorTabBtn or BaseClass(BaseComponent)
-
- UIHorTabBtn.Height = 50
-
- function UIHorTabBtn:__init(parent, call_back)
- self.parent = parent
- self.call_back = call_back
- self.index = 0
- self.cur_layout = lua_viewM.cur_layout or "" --公共组件,要判断是否对应界面
- self:CreateGameObject(UIType.UIHorTabBtn)
- end
-
- function UIHorTabBtn:LoadSuccess()
- self.is_loaded = true
- self.back_img = self:GetChild("Background"):GetComponent("Image")
- self.label = self:GetChild("Label"):GetComponent("TMP_Text")
- -- self.toggle = self.gameObject:GetComponent("Toggle")
- self.redDot = self:GetChild("redDot").gameObject
- self.checkMark = self:GetChild("Background/Checkmark"):GetComponent("Image")
- self.CheckmarkObj = self:GetChild("Background/Checkmark").gameObject
- self.lock_obj = self:GetChild("lock").gameObject
- self.redDot:SetActive(false)
- if self.need_reselect then
- self:SetSelected(self.is_select)
- end
- self:SetLabelColor()
- self:InitEvent()
- end
-
- function UIHorTabBtn:SetBtnRes( asset, res1, res2 )
- lua_resM:setImageSprite(self, self.back_img, asset, res1)
- lua_resM:setImageSprite(self, self.checkMark, asset, res2)
- end
-
- function UIHorTabBtn:InitEvent()
- local function onClickBtnHandler(target)
- if self.data and self.data.open_lv then
- local str = string.format("%s级后开放", self.data.open_lv)
- Message.show(str)
- return
- end
- self:Call()
- end
- AddClickEvent(self.gameObject, onClickBtnHandler, 2)
- end
-
- function UIHorTabBtn:SetText( index, str )
- self.index = index
- local show_lock = false
- if type(str) == "table" then
- self.label.text = str.text
- self.data = str
- show_lock = str.show_lock and true or false
- else
- self.label.text = str
- end
- self.lock_obj:SetActive(show_lock)
- SetAnchoredPositionX( self.label.transform, show_lock and 8 or -1.5)
- end
-
- function UIHorTabBtn:ShowRedDot( bool )
- self.redDot:SetActive(bool)
- end
-
- function UIHorTabBtn:SetSelected( bool )
- self.is_select = bool
- if self.is_loaded then
- self:SetLabelColor()
- self.need_reselect = false
- else
- self.need_reselect = true
- end
- end
-
- function UIHorTabBtn:SetVisible( bool )
- self.gameObject:SetActive(bool)
- end
-
- function UIHorTabBtn:GetVisible( )
- return self.gameObject.activeSelf
- end
-
- function UIHorTabBtn:SetBtnLabelColor(color1,color2)
- self.color1 = color1
- self.color2 = color2
- self:SetLabelColor()
- end
-
- function UIHorTabBtn:SetLabelColor()
- self.CheckmarkObj:SetActive(self.is_select)
- self.label.color = self.is_select and (self.color2 or ColorUtil:ConvertHexToRGBColor("#ffffff")) or (self.color1 or ColorUtil:ConvertHexToRGBColor("#9eb3cf"))
- SetTMPSharedMaterial(self.label,self.is_select and ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab or ShaderTools.TMPSharedMaterialType.HKYTW7FFDefault)
- end
-
- function UIHorTabBtn:Call( )
- if self.call_back and not self.is_select then
- self.call_back(self.index)
- end
- self:SetLabelColor()
- end
-
-
- function UIHorTabBtn:SetCanClick(state)
- self.back_img.raycastTarget = state
- end
-
- function UIHorTabBtn:__delete( )
-
- end
|