源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

172 řádky
3.9 KiB

před 4 týdny
  1. --[[
  2. Bar
  3. self.tabBar = UIHorTabBar.New(self.tabCon)
  4. self.tabBar:SetData({"按钮1","按钮2"}, call_back)
  5. self.tabBar:SetSize(180,60)
  6. self.tabBar:SetSelectTab(1)
  7. ]]
  8. UIHorTabBar = UIHorTabBar or BaseClass(BaseComponent)
  9. function UIHorTabBar:__init(handle_wnd)
  10. self:CreateGameObject(UIType.UIHorTabBar)
  11. self.item_list = {}
  12. end
  13. --[[
  14. data = {"标签1","标签2","标签3"}
  15. ]]
  16. function UIHorTabBar:SetData( data, call_back )
  17. self.data = data
  18. self.call_back = call_back
  19. local call_back = function ( index )
  20. self:SetSelectTab(index)
  21. if self.call_back then
  22. self.call_back(index)
  23. end
  24. end
  25. for i,v in ipairs(data) do
  26. local item = self.item_list[i]
  27. if not item then
  28. item = UIHorTabBtn.New(self.ScrollViewCon, call_back)
  29. self.item_list[i] = item
  30. end
  31. item:SetVisible(true)
  32. item:SetText(i, v)
  33. end
  34. self:BoolCanClick(true)
  35. for i=#data+1, #self.item_list do
  36. self.item_list[i]:SetVisible(false)
  37. end
  38. end
  39. function UIHorTabBar:BoolCanClick(state)
  40. self.can_click_state = state
  41. for k,v in pairs(self.item_list) do
  42. v:SetCanClick(self.can_click_state)
  43. end
  44. end
  45. function UIHorTabBar:ShowItemRedDot( index, bool )
  46. if self.item_list[index] then
  47. self.item_list[index]:ShowRedDot(bool)
  48. end
  49. end
  50. function UIHorTabBar:GetSize( )
  51. local count = 0
  52. for k,v in pairs(self.item_list) do
  53. if v:GetVisible() then
  54. count = count + 1
  55. end
  56. end
  57. return count
  58. end
  59. function UIHorTabBar:GetTotalSize( )
  60. local count = 0
  61. for k,v in pairs(self.item_list) do
  62. count = count + 1
  63. end
  64. return count
  65. end
  66. function UIHorTabBar:SetSelectTab( index )
  67. self.cur_index = index
  68. if self.item_list[self.last_index] then
  69. self.item_list[self.last_index]:SetSelected(false)
  70. end
  71. if self.item_list[self.cur_index] then
  72. self.item_list[self.cur_index]:SetSelected(true)
  73. end
  74. self.last_index = self.cur_index
  75. end
  76. function UIHorTabBar:SetItemVisible( index, bool )
  77. if self.item_list[index] then
  78. self.item_list[index]:SetVisible(bool)
  79. end
  80. end
  81. function UIHorTabBar:GetItemVisible( index )
  82. if self.item_list[index] then
  83. return self.item_list[index]:GetVisible()
  84. end
  85. end
  86. function UIHorTabBar:SetSize( w, h )
  87. self.grid_layout.cellSize = Vector2(w, h)
  88. end
  89. function UIHorTabBar:SetScrollConPos(x, y)
  90. local max_width = GetSizeDeltaX(self.ScrollViewCon)
  91. if max_width > 0 then
  92. if x > 0 then
  93. x = 0
  94. else
  95. x = math.max(x,-max_width)
  96. end
  97. self.ScrollViewCon.transform.localPosition = Vector2(x, y)
  98. else
  99. self.con_x = x
  100. self.con_y = y
  101. local function delay_method( )
  102. self:SetScrollConPos(self.con_x,self.con_y)
  103. end
  104. self.delay_time = self.delay_time or setTimeout(delay_method, 0.01)
  105. end
  106. end
  107. function UIHorTabBar:LoadSuccess()
  108. self.ScrollView = self:GetChild("ScrollView")
  109. self.ScrollViewViewport = self:GetChild("ScrollView/Viewport")
  110. self.ScrollViewCon = self:GetChild("ScrollView/Viewport/Content")
  111. self.group = self.gameObject:GetComponent("ToggleGroup")
  112. self.scroll_view_rect = self.ScrollView:GetComponent("ScrollRect")
  113. self.scroll_view_rect.horizontal = true
  114. self.scroll_view_rect.vertical = false
  115. self.grid_layout = self.ScrollViewCon:GetComponent("GridLayoutGroup")
  116. self.transform.anchoredPosition = Vector2.zero
  117. self.transform.sizeDelta = Vector2(0, 116)
  118. self:InitEvent()
  119. end
  120. function UIHorTabBar:SetHorizontal( bool )
  121. self.scroll_view_rect.horizontal = bool
  122. end
  123. function UIHorTabBar:SetBtnRes( asset, res1, res2 )
  124. for k,v in pairs(self.item_list) do
  125. v:SetBtnRes(asset, res1, res2)
  126. end
  127. end
  128. function UIHorTabBar:SetBtnLabelColor(color1,color2)
  129. for k,v in pairs(self.item_list) do
  130. v:SetBtnLabelColor(color1,color2)
  131. end
  132. end
  133. function UIHorTabBar:SetSpacing( w, h )
  134. self.grid_layout.spacing = Vector2(w, h)
  135. end
  136. function UIHorTabBar:InitEvent()
  137. end
  138. function UIHorTabBar:GetItemByIndex(index)
  139. local item = self.item_list[index]
  140. if not item then
  141. return
  142. end
  143. return item
  144. end
  145. function UIHorTabBar:__delete( )
  146. for k,v in pairs(self.item_list) do
  147. v:DeleteMe()
  148. end
  149. self.item_list = {}
  150. end