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

129 line
3.1 KiB

  1. FullTabButton = FullTabButton or BaseClass(BaseItem)
  2. local FullTabButton = FullTabButton
  3. function FullTabButton:__init(parent)
  4. self.base_file = "uiComponent"
  5. self.layout_file = "FullTabButton"
  6. self.index = 0
  7. self.name = ""
  8. self.tabbar_asset = ""
  9. self.dark_res = ""
  10. self.light_res = ""
  11. self:Load()
  12. self.is_selected = -1
  13. self.show_red_dot = -1
  14. end
  15. function FullTabButton:__delete()
  16. if self.timer_id then
  17. TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_id)
  18. self.timer_id = nil
  19. end
  20. if self.tween_id then
  21. TweenLite.Stop(self.tween_id)
  22. self.tween_id = nil
  23. end
  24. end
  25. function FullTabButton:Load_callback()
  26. self.select_img = self:GetChild("Select").gameObject
  27. self.btn_img = self:GetChild("Icon"):GetComponent("Image")
  28. self.redPoint = self:GetChild("Dot").gameObject
  29. self.line = self:GetChild("Line").gameObject
  30. self:InitEvent()
  31. if self.need_refreshData then
  32. self:SetData(self.index,self.tabbar_asset,self.data,self.callback,self.show_anim)
  33. end
  34. end
  35. function FullTabButton:SetData(index,tabbar_asset,data,callback,show_anim)
  36. self.index = index
  37. self.tabbar_asset = tabbar_asset
  38. self.data = data
  39. self.callback = callback
  40. self.show_anim = show_anim
  41. self.name = data.name or ""
  42. self.light_res = data.light_res or ""
  43. self.dark_res = data.dark_res or ""
  44. if self.is_loaded then
  45. self.index = index
  46. if self.dark_res ~= "" then
  47. lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.dark_res,true)
  48. end
  49. if self.is_selected ~= -1 then
  50. self:SetSelect(self.is_selected)
  51. end
  52. if self.show_red_dot ~= -1 then
  53. self:ShowRedPoint(self.show_red_dot)
  54. end
  55. if show_anim then
  56. self.transform.anchoredPosition = Vector2(-150, (self.index - 1) * -100 - 65)
  57. local function delay_func( ... )
  58. self.tween_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.POSX, 0, 0.2, nil)
  59. end
  60. self.timer_id = setTimeout(delay_func, 0.1 * self.index)
  61. else
  62. self.transform.anchoredPosition = Vector2(0, (self.index - 1) * -100 - 65)
  63. end
  64. else
  65. self.need_refreshData = true
  66. end
  67. end
  68. function FullTabButton:SetSelect(bool)
  69. bool = bool == nil and -1 or bool
  70. if self.is_loaded then
  71. if bool ~= -1 then
  72. if bool then
  73. self.line:SetActive(false)
  74. self.select_img:SetActive(true)
  75. if self.light_res ~= "" then
  76. lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.light_res,true)
  77. end
  78. else
  79. self.line:SetActive(true)
  80. self.select_img:SetActive(false)
  81. if self.dark_res ~= "" then
  82. lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.dark_res,true)
  83. end
  84. end
  85. self.is_selected = -1
  86. end
  87. else
  88. self.is_selected = bool
  89. end
  90. end
  91. function FullTabButton:InitEvent()
  92. local function onTabBtnHandler(target)
  93. if self.callback ~= nil then
  94. self:ClickCall()
  95. end
  96. end
  97. AddClickEvent(self.gameObject,onTabBtnHandler,2)
  98. end
  99. function FullTabButton:ShowRedPoint(bool)
  100. bool = bool == nil and -1 or bool
  101. if self.is_loaded then
  102. if bool ~= -1 then
  103. self.redPoint:SetActive(bool)
  104. self.show_red_dot = -1
  105. end
  106. else
  107. self.show_red_dot = bool
  108. end
  109. end
  110. function FullTabButton:ClickCall( )
  111. self.callback(self.index)
  112. end