源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

287 rindas
8.3 KiB

pirms 4 nedēļām
  1. --tabbar按钮(单个按钮)
  2. NewUICusVerTabBtn = NewUICusVerTabBtn or BaseClass(BaseComponent)
  3. -- NewUICusVerTabBtn.BTN_HEIGHT = 66 --tab按钮的高度,不包括下一级tab按钮的容器高度
  4. -- NewUICusVerTabBtn.SUB_CON_WIDTH = 178 --下一级tab按钮的容器宽度
  5. function NewUICusVerTabBtn:__init(parent, sub_item, size, tabbar,child_offset)
  6. self.tabbar = tabbar
  7. self.sub_btn_list = {}
  8. self.tab_data = nil
  9. self.index = 1
  10. self.call_back = nil
  11. self.show = false --是否展开
  12. self.select_anything = false --是否可以在有子类的时候选中大类
  13. self.btn_width = size and size.x or 189 --tab按钮的宽度,不包括下一级tab按钮的容器宽度
  14. self.btn_height = size and size.y or 66 --tab按钮的高度,不包括下一级tab按钮的容器高度
  15. self.sub_con_width = size and size.x - 16 or 178 --下一级tab按钮的容器宽度
  16. self.sub_item = sub_item
  17. self.child_offset = child_offset
  18. self:CreateGameObject(UIType.UIVerTabBtn)
  19. end
  20. function NewUICusVerTabBtn:__delete()
  21. for i,v in ipairs(self.sub_btn_list) do
  22. v:DeleteMe()
  23. v = nil
  24. end
  25. self.sub_btn_list = {}
  26. if self.event_id then
  27. GlobalEventSystem:UnBind(self.event_id)
  28. self.event_id = nil
  29. end
  30. end
  31. function NewUICusVerTabBtn:LoadSuccess()
  32. self.btnText = self:GetChild("tab/Text"):GetComponent("Text")
  33. self.btn_tran = self:GetChild("tab/Text")
  34. self.icon = self:GetChild("tab/icon"):GetComponent("Image")
  35. self.icon_tran = self:GetChild("tab/icon")
  36. self.imgSelect = self:GetChild("tab/selectBg").gameObject
  37. self.iconObj = self:GetChild("tab/icon").gameObject
  38. self.addBtn = self:GetChild("subCon").gameObject
  39. self.tab = self:GetChild("tab").gameObject
  40. self.tab_img = self:GetChild("tab")
  41. self.subCon = self:GetChild("subCon")
  42. self.img = self:GetChild("tab/img").gameObject
  43. self.red_dot = self:GetChild("tab/dot").gameObject
  44. self:RedreshSize()
  45. self:InitEvent()
  46. end
  47. function NewUICusVerTabBtn:InitEvent()
  48. -- local function onBtnClickHandler(target)
  49. -- if target == self.tab then
  50. -- if self.call_back then
  51. -- self.call_back(self.index,0)
  52. -- end
  53. -- end
  54. -- end
  55. -- AddClickEvent(self.tab, onBtnClickHandler,2)
  56. end
  57. --设置tab数据
  58. function NewUICusVerTabBtn:SetTabDetail(data, index, call_back, select_anything, force_size)
  59. self.tab_data = data
  60. self.index = index
  61. self.call_back = call_back
  62. self.select_anything = select_anything
  63. self.force_size = force_size
  64. if data == nil or self.tab_data.main_tab == nil then return end
  65. self:SetText(self.tab_data.main_tab)
  66. if self.tab_data == nil or #self.tab_data.sub_tab == 0 then
  67. self.iconObj:SetActive(false)
  68. else
  69. self.iconObj:SetActive(true)
  70. end
  71. self:SetSubBtns(self.tab_data.sub_tab, self.index, call_back)
  72. end
  73. --设置下一级的按钮
  74. function NewUICusVerTabBtn:SetSubBtns(sub_tab_list, parent_index, call_back)
  75. for i,v in ipairs(self.sub_btn_list) do
  76. v:SetVisible(false)
  77. end
  78. for i,v in ipairs(sub_tab_list) do
  79. local sub_tab = self.sub_btn_list[i]
  80. if sub_tab == nil then
  81. sub_tab = self.sub_item.New(self.subCon)
  82. self.sub_btn_list[i] = sub_tab
  83. if self.force_size then
  84. sub_tab:SetTabSubBtnSize(self.sub_con_width)
  85. end
  86. end
  87. -- sub_tab:SetSubDeail(v, parent_index, i, call_back)
  88. sub_tab:SetData(v, parent_index, i, call_back)
  89. sub_tab:SetVisible(true)
  90. local x = 0
  91. local y = -(i - 1) * self.sub_item.Height
  92. x = self.offset and self.offset.x + x or x
  93. y = self.offset and -(i - 1) * self.offset.y + y or y
  94. sub_tab:SetPosition(x, y)
  95. -- local function onBtnClickHandler(target)
  96. -- self:SetSelectSubIndex(0, 0)
  97. -- self:SetSelectSubIndex(sub_tab.parent_idnex, sub_tab.sub_index)
  98. -- end
  99. -- if sub_tab.Button then
  100. -- AddClickEvent(sub_tab.Button, onBtnClickHandler,2)
  101. -- end
  102. end
  103. self.subCon.gameObject:SetActive(false)
  104. end
  105. --选中菜单
  106. function NewUICusVerTabBtn:SetSelectMode(index, sub_index,force_show)
  107. if self.index == index then
  108. self.show = not self.show
  109. else
  110. self.show = false
  111. end
  112. -- self.show = not self.show
  113. if force_show and self.index == index then
  114. self.show = true
  115. end
  116. if self.show and index then
  117. self.icon_tran.transform.localRotation = Quaternion.Euler(0,0,-90)
  118. self:SetSelectState(true)
  119. --SetRotate(self.icon_tran, 0, 0, -90)
  120. --lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
  121. --self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2,0)
  122. self:ShowSubBtnVisible(true)
  123. -- if sub_index then
  124. -- self:SetSelectSubIndex(index, sub_index)
  125. -- end
  126. else
  127. SetLocalRotation(self.icon_tran, 0, 0, 0)
  128. self:SetSelectState(false)
  129. --lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
  130. --self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
  131. self:ShowSubBtnVisible(false)
  132. end
  133. end
  134. --设置图标,隐藏sub
  135. function NewUICusVerTabBtn:RefreshBtnState(show)
  136. self.show = show
  137. if self.show then
  138. self.icon_tran.transform.localRotation = Quaternion.Euler(0,0,-90)
  139. --SetRotate(self.icon_tran, 0, 0, -90)
  140. --lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_minus",true)
  141. --self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2,0)
  142. else
  143. SetLocalRotation(self.icon_tran, 0, 0, 0)
  144. --lua_resM:setImageSprite(self,self.icon,"uicomponent_asset","ui_addicon",true)
  145. --self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
  146. end
  147. if self.subCon and self.sub_btn_list and #self.sub_btn_list ~= 0 then
  148. self.subCon.gameObject:SetActive(show)
  149. end
  150. end
  151. --设置选中的子一级tab
  152. function NewUICusVerTabBtn:SetSelectSubIndex(index, sub_index)
  153. for i,v in ipairs(self.sub_btn_list) do
  154. if v.parent_index == index and v.sub_index == sub_index then
  155. v:SetSelected(true, true)
  156. else
  157. v:SetSelected(false)
  158. end
  159. end
  160. end
  161. function NewUICusVerTabBtn:SetText(str)
  162. self.btnText.text = str
  163. end
  164. function NewUICusVerTabBtn:ShowSubBtnVisible(bool)
  165. if self.subCon and self.sub_btn_list and #self.sub_btn_list ~= 0 then
  166. self.subCon.gameObject:SetActive(bool)
  167. if self.select_anything then
  168. --if self.call_back then self.call_back(self.index,0) end
  169. end
  170. else
  171. --if self.call_back then self.call_back(self.index,0) end
  172. end
  173. end
  174. function NewUICusVerTabBtn:SetSubConSize(height)
  175. -- self.subCon.sizeDelta = Vector2(NewUICusVerTabBtn.SUB_CON_WIDTH, height)
  176. end
  177. --设置大小
  178. function NewUICusVerTabBtn:SetTabBtnSize()
  179. end
  180. function NewUICusVerTabBtn:SetSelectState(b)
  181. self.imgSelect:SetActive(b)
  182. if b then
  183. self:SetSelectBg()
  184. end
  185. end
  186. function NewUICusVerTabBtn:SetSelectBg()
  187. if self.imgSelect:GetComponent("Image").sprite.name == "empty" then
  188. lua_resM:setImageSprite(self,self.imgSelect:GetComponent("Image"),"common_asset","tyui_btn3_1")
  189. self.imgSelect.transform.anchorMin = Vector2(0, 0)
  190. self.imgSelect.transform.anchorMax = Vector2(1, 1)
  191. self.imgSelect.transform.offsetMax = Vector2(0, 0)
  192. self.imgSelect.transform.offsetMin = Vector2(0, 0)
  193. SetAnchoredPosition(self.imgSelect.transform,0,0)
  194. end
  195. end
  196. function NewUICusVerTabBtn:SetImageTexture(asset_path,res_name)
  197. if asset_path and res_name then
  198. self.img:SetActive(true)
  199. lua_resM:setImageSprite(self,self.img:GetComponent("Image"),asset_path,res_name)
  200. else
  201. self.img:SetActive(false)
  202. end
  203. end
  204. function NewUICusVerTabBtn:ShowRedDot(list)
  205. if list and #list > 0 then
  206. table.sort(list)
  207. end
  208. self.sub_red_list = list
  209. for i, v in ipairs(self.sub_btn_list) do
  210. v:ShowRedDot(false)
  211. end
  212. if not list or #list == 0 then
  213. self.red_dot:SetActive(false)
  214. else
  215. self.red_dot:SetActive(true)
  216. for i, v in ipairs(list) do
  217. if self.sub_btn_list[v] then
  218. self.sub_btn_list[v]:ShowRedDot(true)
  219. end
  220. end
  221. end
  222. if list[0] then
  223. self.red_dot:SetActive(true)
  224. end
  225. end
  226. function NewUICusVerTabBtn:SetSubOffset(offset)
  227. self.offset = offset
  228. end
  229. --加载完但不显示的不需计算高度
  230. function NewUICusVerTabBtn:GetVisibleCount(visible)
  231. local count = 0
  232. for _,v in ipairs(self.sub_btn_list) do
  233. if v:GetVisible() == visible or not v.is_loaded then
  234. count = count + 1
  235. end
  236. end
  237. return count
  238. end
  239. function NewUICusVerTabBtn:RedreshSize()
  240. self.tab_img.sizeDelta = Vector2(self.btn_width, self.btn_height)
  241. --self.icon_tran.localPosition = Vector3(self.btn_width- 26, -self.btn_height / 2 + 7,0)
  242. SetAnchoredPosition(self.tab.transform,0,0)
  243. if self.child_offset then
  244. self.subCon.localPosition = Vector3(self.child_offset.x, self.child_offset.y,0)
  245. else
  246. self.subCon.localPosition = Vector3(self.subCon.localPosition.x, -self.btn_height,0)
  247. end
  248. end