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

110 行
3.0 KiB

  1. --子一级的tabbar按钮(单个按钮)
  2. UIHorTabBtn = UIHorTabBtn or BaseClass(BaseComponent)
  3. UIHorTabBtn.Height = 50
  4. function UIHorTabBtn:__init(parent, call_back)
  5. self.parent = parent
  6. self.call_back = call_back
  7. self.index = 0
  8. self.cur_layout = lua_viewM.cur_layout or "" --公共组件,要判断是否对应界面
  9. self:CreateGameObject(UIType.UIHorTabBtn)
  10. end
  11. function UIHorTabBtn:LoadSuccess()
  12. self.is_loaded = true
  13. self.back_img = self:GetChild("Background"):GetComponent("Image")
  14. self.label = self:GetChild("Label"):GetComponent("TMP_Text")
  15. -- self.toggle = self.gameObject:GetComponent("Toggle")
  16. self.redDot = self:GetChild("redDot").gameObject
  17. self.checkMark = self:GetChild("Background/Checkmark"):GetComponent("Image")
  18. self.CheckmarkObj = self:GetChild("Background/Checkmark").gameObject
  19. self.lock_obj = self:GetChild("lock").gameObject
  20. self.redDot:SetActive(false)
  21. if self.need_reselect then
  22. self:SetSelected(self.is_select)
  23. end
  24. self:SetLabelColor()
  25. self:InitEvent()
  26. end
  27. function UIHorTabBtn:SetBtnRes( asset, res1, res2 )
  28. lua_resM:setImageSprite(self, self.back_img, asset, res1)
  29. lua_resM:setImageSprite(self, self.checkMark, asset, res2)
  30. end
  31. function UIHorTabBtn:InitEvent()
  32. local function onClickBtnHandler(target)
  33. if self.data and self.data.open_lv then
  34. local str = string.format("%s级后开放", self.data.open_lv)
  35. Message.show(str)
  36. return
  37. end
  38. self:Call()
  39. end
  40. AddClickEvent(self.gameObject, onClickBtnHandler, 2)
  41. end
  42. function UIHorTabBtn:SetText( index, str )
  43. self.index = index
  44. local show_lock = false
  45. if type(str) == "table" then
  46. self.label.text = str.text
  47. self.data = str
  48. show_lock = str.show_lock and true or false
  49. else
  50. self.label.text = str
  51. end
  52. self.lock_obj:SetActive(show_lock)
  53. SetAnchoredPositionX( self.label.transform, show_lock and 8 or -1.5)
  54. end
  55. function UIHorTabBtn:ShowRedDot( bool )
  56. self.redDot:SetActive(bool)
  57. end
  58. function UIHorTabBtn:SetSelected( bool )
  59. self.is_select = bool
  60. if self.is_loaded then
  61. self:SetLabelColor()
  62. self.need_reselect = false
  63. else
  64. self.need_reselect = true
  65. end
  66. end
  67. function UIHorTabBtn:SetVisible( bool )
  68. self.gameObject:SetActive(bool)
  69. end
  70. function UIHorTabBtn:GetVisible( )
  71. return self.gameObject.activeSelf
  72. end
  73. function UIHorTabBtn:SetBtnLabelColor(color1,color2)
  74. self.color1 = color1
  75. self.color2 = color2
  76. self:SetLabelColor()
  77. end
  78. function UIHorTabBtn:SetLabelColor()
  79. self.CheckmarkObj:SetActive(self.is_select)
  80. self.label.color = self.is_select and (self.color2 or ColorUtil:ConvertHexToRGBColor("#ffffff")) or (self.color1 or ColorUtil:ConvertHexToRGBColor("#9eb3cf"))
  81. SetTMPSharedMaterial(self.label,self.is_select and ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab or ShaderTools.TMPSharedMaterialType.HKYTW7FFDefault)
  82. end
  83. function UIHorTabBtn:Call( )
  84. if self.call_back and not self.is_select then
  85. self.call_back(self.index)
  86. end
  87. self:SetLabelColor()
  88. end
  89. function UIHorTabBtn:SetCanClick(state)
  90. self.back_img.raycastTarget = state
  91. end
  92. function UIHorTabBtn:__delete( )
  93. end