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

136 řádky
3.5 KiB

před 4 týdny
  1. ComboxView = ComboxView or BaseClass(BaseView)
  2. local ComboxView = ComboxView
  3. function ComboxView:__init(parent_wnd, prefab_data, layer_name)
  4. self.base_file = "uiComponent"
  5. self.layout_file = prefab_data and prefab_data.ComboxView or "ComboxView"
  6. self.layer_name = layer_name or "Activity"
  7. self.destroy_imm = true
  8. self.use_background = false
  9. self.change_scene_close = true
  10. self.prefab_data = prefab_data or {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", show_type = "down"}
  11. self.height_extra = 0
  12. self.pos = Vector3(0,0,0)
  13. self.item_list = {}
  14. self.red_data = {}
  15. self:SetOfferXY()
  16. self.load_callback = function ()
  17. self:LoadSuccess()
  18. self:AddEvent()
  19. end
  20. self.open_callback = function ( )
  21. self:OpenSuccess()
  22. end
  23. self.destroy_callback = function ( )
  24. self:DestroySuccess()
  25. end
  26. end
  27. function ComboxView:Close()
  28. if self.combox_close_callback then
  29. self.combox_close_callback()
  30. end
  31. BaseView.Close(self)
  32. end
  33. function ComboxView:Open(data,callback,combox_close_callback,pos,red_data)
  34. self.data = data or {}
  35. self.callback = callback
  36. self.combox_close_callback = combox_close_callback
  37. self.pos = pos
  38. self.red_data = red_data or {}
  39. BaseView.Open(self)
  40. end
  41. --设置偏移量
  42. function ComboxView:SetOfferXY( )
  43. if self.layout_file == "ComboxView" then
  44. self.bg_add_height = 0
  45. self.bg_offerx = -11
  46. self.bg_offery = 0
  47. end
  48. end
  49. function ComboxView:SetSize(width,height)
  50. self.width = width
  51. self.height = height
  52. if self.img_bg then
  53. local height = #self.data * (ComboxItem.Height+self.height_extra)+18
  54. if #self.data == 0 then
  55. height = (ComboxItem.Height+self.height_extra)
  56. end
  57. self.img_bg.sizeDelta = Vector2(self.width,height)
  58. end
  59. end
  60. function ComboxView:LoadSuccess()
  61. self.img_bg = self:GetChild("img_bg")
  62. self.con = self:GetChild("img_bg/con")
  63. self.touch_con = self:GetChild("touch_con").gameObject
  64. SetSizeDelta(self.touch_con.transform, ScreenWidth*1.5, ScreenHeight*1.5)
  65. local width = self.width or self.img_bg.sizeDelta.x
  66. --总高度
  67. local height = #self.data * (ComboxItem.Height+self.height_extra)+3
  68. if #self.data == 0 then
  69. height = (ComboxItem.Height+self.height_extra)
  70. end
  71. self.height = height
  72. self.img_bg.sizeDelta = Vector2(width,height+self.bg_add_height)
  73. if self.pos then
  74. self:SetTransOffsetY()
  75. local pos = self.img_bg:InverseTransformPoint(self.pos)
  76. self.img_bg.localPosition = Vector3(pos.x+self.bg_offerx,pos.y+self.bg_offery,0)
  77. end
  78. end
  79. function ComboxView:SetTransOffsetY( )
  80. if self.prefab_data.offset_y then
  81. if self.prefab_data.show_type == "down" then
  82. self.bg_offery = -30 + self.prefab_data.offset_y + self.height
  83. else
  84. self.bg_offery = 16 + self.prefab_data.offset_y + self.height + self.height
  85. end
  86. end
  87. end
  88. function ComboxView:AddEvent()
  89. local function onClick(...)
  90. self:Close()
  91. end
  92. AddClickEvent(self.touch_con,onClick)
  93. end
  94. function ComboxView:OpenSuccess()
  95. -------------------------
  96. local function callback(index)
  97. if self.callback then
  98. self.callback(index)
  99. end
  100. self:Close()
  101. end
  102. local x = 0
  103. local height = self.img_bg.sizeDelta.y
  104. for i=1,#self.data do
  105. local item = self.item_list[i]
  106. if not item then
  107. item = ComboxItem.New(self.img_bg,nil,nil,self.prefab_data)
  108. self.item_list[i] = item
  109. item:SetPosition(x,-(i-1) * ComboxItem.Height-3)
  110. end
  111. item:SetData(i,self.data[i],callback,self.red_data[i])
  112. item:SetWidth(self.img_bg.sizeDelta.x)
  113. end
  114. end
  115. function ComboxView:UpdateView( )
  116. end
  117. function ComboxView:DestroySuccess( )
  118. for k,v in pairs(self.item_list) do
  119. v:DeleteMe()
  120. end
  121. self.item_list = {}
  122. end