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

142 lines
4.3 KiB

  1. CommonAwardFlyView = CommonAwardFlyView or BaseClass(BaseView)
  2. local CommonAwardFlyView = CommonAwardFlyView
  3. function CommonAwardFlyView:__init()
  4. self.base_file = "common"
  5. self.layout_file = "CommonAwardFlyView"
  6. self.layer_name = "Top"
  7. self.destroy_imm = true
  8. self.use_background = false
  9. self.append_to_ctl_queue = false
  10. self.item_list = {}
  11. self.item_con_list = {}
  12. self.offer_x = 640--X轴偏移量
  13. self.offer_y = -360--X轴偏移量
  14. self.is_set_zdepth = true
  15. self.end_offer_x = 0
  16. self.end_offer_y = 0
  17. self.load_callback = function ()
  18. self:LoadSuccess()
  19. self:UpdateView()
  20. end
  21. self.close_callback = function ()
  22. self:Remove()
  23. end
  24. end
  25. function CommonAwardFlyView:Remove()
  26. for i,v in ipairs(self.item_list) do
  27. UIObjPool:PushItem(UIObjPool.UIType.AwardItem, v)
  28. end
  29. self.item_list = {}
  30. for i,v in ipairs(self.item_con_list) do
  31. cc.ActionManager:getInstance():removeAllActionsFromTarget(v.transform)
  32. end
  33. end
  34. --target初始节点
  35. --end_target终点节点
  36. -- data = {
  37. -- item_list = {
  38. -- [1] = {target,end_target,goods_vo}--goods_vo = {type_kind,type_id,type_num}--万一你要显示道具数量那不是坑爹
  39. -- }
  40. -- offer_x = 640,整体偏移量
  41. -- offer_y = 360,整体偏移量
  42. -- end_offer_x = 0,--结束位置偏移量
  43. -- end_offer_y = 0,--结束位置偏移量
  44. -- end_func = callback--结束方法
  45. -- times = 2
  46. -- }
  47. function CommonAwardFlyView:Open( data )
  48. self.data = data or self.data
  49. if not self.data then
  50. self:Close()
  51. return
  52. end
  53. self.offer_x = self.data.offer_x or self.offer_x
  54. self.offer_y = self.data.offer_y or self.offer_y
  55. self.end_offer_x = self.data.end_offer_x or self.end_offer_x
  56. self.end_offer_y = self.data.end_offer_y or self.end_offer_y
  57. print("huangcong:CommonAwardFlyView [start:45] self.data:", self.data)
  58. PrintTable(self.data)
  59. print("huangcong:CommonAwardFlyView [end]")
  60. BaseView.Open(self)
  61. end
  62. function CommonAwardFlyView:LoadSuccess()
  63. local nodes = {
  64. "itemCon"
  65. }
  66. self:GetChildren(nodes)
  67. self:InitEvent()
  68. end
  69. function CommonAwardFlyView:InitEvent()
  70. end
  71. function CommonAwardFlyView:UpdateView()
  72. if not self.data or not self.data.item_list then
  73. self:Close()
  74. return
  75. end
  76. self:UpdateItemList()
  77. end
  78. --更新道具列表
  79. function CommonAwardFlyView:UpdateItemList( )
  80. local list = self.data.item_list
  81. local count = 0
  82. local len = #list
  83. for i,v in ipairs(list) do
  84. local item = self.item_list[i]
  85. if item == nil then
  86. local item_transform = UiFactory.createChild(self.transform, UIType.EmptyObject)
  87. item_transform.transform.pivot = Vector2(0, 1)
  88. item_transform.transform.sizeDelta = Vector2(78, 78)
  89. item_transform.transform.anchorMin = Vector2(0, 1)
  90. item_transform.transform.anchorMax = Vector2(0, 1)
  91. item_transform:SetActive(false)
  92. self.item_con_list[i] = item_transform
  93. item = UIObjPool:PopItem(UIObjPool.UIType.AwardItem,item_transform.transform)
  94. self.item_list[i] = item
  95. local goods_vo = v[3]
  96. if goods_vo then
  97. item:SetData(goods_vo[2],goods_vo[3] or nil)
  98. end
  99. self:StartAction(item_transform.transform,v[1],v[2],i == len)
  100. end
  101. end
  102. end
  103. function CommonAwardFlyView:StartAction( transform,target,end_target,is_end )
  104. if IsNull(target) or IsNull(end_target) then return end
  105. --设置初始状态
  106. local start_abs_pos = target.transform:TransformPoint(Vector3.zero)
  107. local start_pos = self.transform:InverseTransformPoint(Vector3.New(start_abs_pos.x, start_abs_pos.y, 0))
  108. local end_abs_pos = end_target.transform:TransformPoint(Vector3.zero)
  109. local end_pos = self.transform:InverseTransformPoint(Vector3.New(end_abs_pos.x, end_abs_pos.y, 0))
  110. -- new_pos.x = new_pos.x + 145
  111. -- new_pos.y = new_pos.y + 210
  112. -- SetLocalScale(transform,1.1,1.1,1.1)
  113. SetAnchoredPosition(transform,start_pos.x + self.offer_x,start_pos.y + self.offer_y)
  114. transform.gameObject:SetActive(true)
  115. local time = self.data.time or 1
  116. local action = cc.MoveTo.createAnchoredType(time, end_pos.x + self.offer_x + self.end_offer_x, end_pos.y + self.offer_y + self.end_offer_y)
  117. local function end_func()
  118. transform.gameObject:SetActive(false)
  119. -- SetLocalScale(transform,1,1,1)
  120. if is_end then--最后要设置已获得
  121. if self.data.end_func then
  122. self.data.end_func()
  123. end
  124. self:Close()
  125. end
  126. end
  127. -- action = cc.Spawn.New(action, cc.ScaleTo.New(time,0.8,0.8,0.8))
  128. action = cc.Sequence.New(action,cc.CallFunc.New(end_func))
  129. cc.ActionManager:getInstance():addAction(action, transform)
  130. end