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

74 lines
1.6 KiB

  1. ComboxItem = ComboxItem or BaseClass(BaseItem)
  2. local ComboxItem = ComboxItem
  3. ComboxItem.Height = 38
  4. function ComboxItem:__init(parent_wnd, prefab_asset, layer_name, prefab_data)
  5. self.base_file = prefab_asset or "uiComponent"
  6. if prefab_data and prefab_data.ComboxItem then
  7. self.layout_file = prefab_data and prefab_data.ComboxItem
  8. else
  9. self.layout_file = "ComboxItem"
  10. end
  11. self.show_red = nil
  12. self:Load()
  13. end
  14. function ComboxItem:Load_callback()
  15. self:LoadSuccess()
  16. end
  17. function ComboxItem:LoadSuccess()
  18. self.show_text = self:GetChild("text"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  19. self.img_red_obj = self:GetChild("img_red").gameObject
  20. self.di_line = self:GetChild("bg_41_1")
  21. if self.width then
  22. self:SetWidth(self.width)
  23. end
  24. self:AddEvents()
  25. if self.need_refreshData then
  26. self:UpdateView()
  27. end
  28. end
  29. function ComboxItem:SetWidth(width)
  30. self.width = width
  31. if self.is_loaded then
  32. self.need_resetWidth = false
  33. SetSizeDeltaX(self.transform, self.width)
  34. else
  35. self.need_resetWidth = true
  36. end
  37. end
  38. function ComboxItem:AddEvents( )
  39. local function onClick(...)
  40. if self.callback then
  41. self.callback(self.index)
  42. end
  43. end
  44. AddClickEvent(self.gameObject,onClick)
  45. end
  46. function ComboxItem:UpdateView( )
  47. self.show_text.text = self.str
  48. self.img_red_obj:SetActive(self.show_red and true or false)
  49. end
  50. function ComboxItem:SetData(index,str,callback,show_red)
  51. self.index = index
  52. self.str = str
  53. self.callback = callback
  54. self.show_red = show_red
  55. if self.is_loaded then
  56. self.need_refreshData = false
  57. self:UpdateView()
  58. else
  59. self.need_refreshData = true
  60. end
  61. end
  62. function ComboxItem:__delete( )
  63. end