源战役客户端
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.

152 rivejä
5.3 KiB

4 viikkoa sitten
  1. --子一级的tabbar按钮(单个按钮)
  2. UIVerTabSubBtn = UIVerTabSubBtn or BaseClass(BaseComponent)
  3. local UIVerTabSubBtn = UIVerTabSubBtn
  4. UIVerTabSubBtn.Height = 49
  5. function UIVerTabSubBtn:__init(parent, call_back, desc)
  6. self.sub_index = 1
  7. self.parent_idnex = 1
  8. self.call_back = nil
  9. self:CreateGameObject(UIType.UIVerTabSubBtn)
  10. self:InitData(call_back, desc)
  11. end
  12. function UIVerTabSubBtn:InitData(call_back, text)
  13. self.call_back = call_back
  14. self.btnText.text = text
  15. end
  16. function UIVerTabSubBtn:LoadSuccess()
  17. self.btnText = self:GetChild("Button/Text"):GetComponent("TextMeshProUGUI")
  18. self.selectBg = self:GetChild("Button/selectBg").gameObject
  19. self.selectBg_con = self:GetChild("Button/selectBg")
  20. self.Button_con = self:GetChild("Button")
  21. self.Button = self:GetChild("Button").gameObject
  22. self.img = self:GetChild("Button/img"):GetComponent("Image")
  23. self.img.gameObject:SetActive(false)
  24. self.button_image = self:GetChild("Button"):GetComponent("Image")
  25. self.dot = self:GetChild("Button/dot").gameObject
  26. self.des_effect = self:GetChild("Button/effect")
  27. self.des_img = self:GetChild("Button/image_source")
  28. self.des_txt = self:GetChild("Button/Text")
  29. self.line = self:GetChild("Button/line").gameObject
  30. self.des_effect.gameObject:SetActive(false)
  31. self.des_img.gameObject:SetActive(false)
  32. self.line:SetActive(true)
  33. self:InitEvent()
  34. end
  35. function UIVerTabSubBtn:InitEvent()
  36. end
  37. function UIVerTabSubBtn:SetSubDeail(text, parent_idnex, sub_index, call_back)
  38. self.parent_idnex = parent_idnex
  39. self.sub_index = sub_index
  40. self.call_back = call_back
  41. self:SetText(text)
  42. end
  43. function UIVerTabSubBtn:SetText(str)
  44. self.btnText.text = str
  45. end
  46. function UIVerTabSubBtn:ResetSubDeail(data)
  47. self.data = data
  48. self.scale = 1
  49. if self.data == nil then return end
  50. if self.data.type == 1 then --特效显示
  51. self.des_txt.gameObject:SetActive(false)
  52. self.des_effect.gameObject:SetActive(true)
  53. self.des_img.gameObject:SetActive(false)
  54. self:AddUIEffect("effect_designation_" .. self.data.id, self.des_effect.transform, "Activity", nil, scale, true)
  55. elseif self.data.type == 2 then --文字显示
  56. self.des_effect.gameObject:SetActive(false)
  57. self.des_txt.gameObject:SetActive(true)
  58. self.des_img.gameObject:SetActive(false)
  59. self.des_txt:GetComponent("Outline").effectColor = ColorUtil:GetGoodsColor(self.data.color)
  60. self.des_txt:GetComponent("Text").text = "<color=#A7BEDE>".. self.data.name .."</color>"
  61. SetLocalScale(self.des_txt.transform, scale)
  62. elseif self.data.type == 3 then -- 图片显示
  63. self.des_effect.gameObject:SetActive(false)
  64. self.des_txt.gameObject:SetActive(false)
  65. local call_back = function ( )
  66. self.des_img.gameObject:SetActive(true)
  67. end
  68. lua_resM:setOutsideImageSprite(self,self.des_img:GetComponent("ImageExtend"),GameResPath.GetDesignImage(self.data.goods_id),true,call_back)
  69. self.des_img:GetComponent("ImageExtend").gray = false
  70. if not DesignationModel:getInstance():GetDesignationByID(self.data.id) then
  71. self.des_img:GetComponent("ImageExtend").gray = true
  72. end
  73. SetLocalScale(self.des_img.transform, scale)
  74. elseif self.data.type == 4 then -- 特殊显示
  75. self.des_effect.gameObject:SetActive(false)
  76. self.des_txt.gameObject:SetActive(false)
  77. local call_back = function ( )
  78. self.des_img.gameObject:SetActive(true)
  79. end
  80. lua_resM:setOutsideImageSprite(self,self.des_img:GetComponent("ImageExtend"),GameResPath.GetDesignImage(self.data.goods_id),true,call_back)
  81. self.des_img:GetComponent("ImageExtend").gray = false
  82. if not DesignationModel:getInstance():GetDesignationByID(self.data.id) then
  83. self.des_img:GetComponent("ImageExtend").gray = true
  84. end
  85. SetLocalScale(self.des_img.transform, scale)
  86. end
  87. end
  88. function UIVerTabSubBtn:SetSelected(bool)
  89. if self.btnText then
  90. local normal_color = self.style_data and self.style_data.sub_btn_text_color_nor or Color(167/255,190/255,222/255,1)
  91. local select_color = self.style_data and self.style_data.sub_btn_text_color_sel or ColorUtil:ConvertHexToRGBColor( ColorUtil.WHITE_DARK )
  92. self.btnText.color = (not bool) and normal_color or select_color
  93. end
  94. if self.selectBg then
  95. self.selectBg:SetActive(bool)
  96. end
  97. if bool and self.parent_idnex and self.sub_index then
  98. if self.call_back then
  99. self.call_back(self.parent_idnex, self.sub_index)
  100. end
  101. end
  102. end
  103. --设置大小
  104. function UIVerTabSubBtn:SetTabSubBtnSize(data)
  105. self.Button_con.sizeDelta = Vector2(data.SUB_CON_WIDTH,data.SUB_CON_HEIGHT)
  106. self.selectBg_con.sizeDelta = Vector2(data.SUB_CON_WIDTH,data.SUB_CON_HEIGHT)
  107. end
  108. function UIVerTabSubBtn:SetStyleData( style_data )
  109. self.style_data = style_data
  110. self:SetTabSubBtnSize(style_data)
  111. end
  112. function UIVerTabSubBtn:SetSelectState(b)
  113. if self.selectBg then
  114. self.selectBg:SetActive(b)
  115. self.line:SetActive(not b)
  116. end
  117. end
  118. function UIVerTabSubBtn:SetImageTexture(asset_path,res_name)
  119. if asset_path and res_name then
  120. self.img.gameObject:SetActive(true)
  121. lua_resM:setImageSprite(self,self.img,asset_path,res_name)
  122. else
  123. self.img.gameObject:SetActive(false)
  124. end
  125. end
  126. function UIVerTabSubBtn:ShowRedDot(bool)
  127. if self.dot then
  128. self.dot:SetActive(bool)
  129. end
  130. end
  131. function UIVerTabSubBtn:SetNewSource(data)
  132. self:SetTabSubBtnSize(data)
  133. lua_resM:setImageSprite(self,self.button_image,data.subabname,data.sub_normal)
  134. lua_resM:setImageSprite(self,self.selectBg:GetComponent("Image"),data.subabname,data.sub_select)
  135. end