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

266 line
8.7 KiB

  1. --活动礼包开启
  2. GiftActNormalView = GiftActNormalView or BaseClass(BaseView)
  3. local GiftActNormalView = GiftActNormalView
  4. function GiftActNormalView:__init()
  5. self.base_file = "gift"
  6. self.layout_file = "GiftActNormalView"
  7. self.layer_name = "Activity"
  8. --self.use_local_view = true
  9. self.click_bg_toClose = true
  10. self.destroy_imm = true
  11. self.use_background = true
  12. self.is_set_zdepth = true
  13. self.close_mode = CloseMode.CloseDestroy
  14. self.model = GiftModel:getInstance()
  15. self.delay_time = 10
  16. self.col_num = 5 -- 奖励展示的行展示数
  17. self.max_num = 10
  18. self.item_list = {}
  19. self.name_item_list = {}
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:addEvents()
  23. end
  24. self.open_callback = function ()
  25. self:UpdateView()
  26. end
  27. self.close_callback = function ()
  28. end
  29. self.destroy_callback = function ()
  30. self:DestroySuccess()
  31. end
  32. end
  33. function GiftActNormalView:Open(show_goods_list,only_read_goods_type_id)
  34. self.show_goods_list = show_goods_list
  35. self.only_read_goods_type_id = only_read_goods_type_id
  36. BaseView.Open(self)
  37. end
  38. function GiftActNormalView:DestroySuccess()
  39. if self.award_timer_id then
  40. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  41. self.award_timer_id = nil
  42. end
  43. if self.timer_id then
  44. GlobalTimerQuest:CancelQuest(self.timer_id)
  45. self.timer_id = nil
  46. end
  47. for i,item in pairs(self.item_list) do
  48. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
  49. end
  50. self.item_list = {}
  51. for k,v in pairs(self.name_item_list) do
  52. v:DeleteMe()
  53. v = nil
  54. end
  55. self.name_item_list = {}
  56. end
  57. function GiftActNormalView:LoadSuccess()
  58. local nodes = {
  59. "bg:raw", "titlebg:img", "mask_bg:obj",
  60. "time_text:tmp", "awardScroll:obj", "awardScroll/Viewport/awardCon", "awardNCon:obj",
  61. }
  62. self:GetChildren(nodes)
  63. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("com_act_reward_result_bg"), false)
  64. lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage("com_act_reward_title_bg"),false)
  65. end
  66. function GiftActNormalView:addEvents()
  67. local function click_func(target)
  68. if target == self.mask_bg_obj then
  69. self:Close()
  70. end
  71. end
  72. AddClickEvent(self.mask_bg_obj, click_func)
  73. end
  74. function GiftActNormalView:UpdateView()
  75. local item_list = self.show_goods_list or {}
  76. if #item_list <= 5 then--带名字的道具
  77. self:UpdateNameItemList()
  78. else
  79. self:UpdateItemList()
  80. end
  81. end
  82. function GiftActNormalView:UpdateTime( )
  83. local time = self.delay_time
  84. local function countDown()
  85. if self._use_delete_method then return end
  86. time = time - 1
  87. if time > 0 then
  88. self.time_text_tmp.text = string.format("点击任意区域关闭 (%s)",HtmlColorTxt(time.."s",ColorUtil.GREEN_DARK))
  89. else
  90. self:Close()
  91. end
  92. end
  93. countDown()
  94. if not self.timer_id then
  95. self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
  96. end
  97. end
  98. function GiftActNormalView:UpdateNameItemList( )
  99. for k,v in pairs(self.name_item_list) do
  100. v:SetVisible(false,nil,true)
  101. end
  102. local item_list = self.show_goods_list or {}
  103. local new_list = {}
  104. for k,v in pairs(item_list) do
  105. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v[2])
  106. if goods_vo then
  107. v.sort_id = goods_vo.color * 10000000000000 + goods_vo.type_id
  108. if v.type == GoodsModel.TYPE.EQUIP then--装备+100W
  109. v.sort_id = v.sort_id + 10000000
  110. end
  111. new_list[#new_list + 1] = v
  112. end
  113. end
  114. local sort_func = function ( a, b )
  115. return a.sort_id > b.sort_id
  116. end
  117. table.sort(new_list, sort_func)
  118. item_list = new_list
  119. if not item_list or TableSize(item_list) == 0 then return end
  120. local len = #item_list
  121. self.parent_con = self.awardNCon
  122. self.awardScroll_obj:SetActive(false)
  123. self.awardNCon_obj:SetActive(true)
  124. local x = 0
  125. local y = 0
  126. for i, v in ipairs(item_list) do
  127. local item = self.name_item_list[i]
  128. if item == nil then
  129. item = GiftActNormalItem.New(self.parent_con,nil,self.layer_name)
  130. self.name_item_list[i] = item
  131. end
  132. item:SetData(i,v,self.only_read_goods_type_id)
  133. item:SetVisible(false,nil,true)
  134. end
  135. local index = 0
  136. local function countDown()
  137. index = index + 1
  138. if len >= index then
  139. if self.name_item_list[index] then
  140. self.name_item_list[index]:SetVisible(true,nil,true)
  141. end
  142. else
  143. if self.award_timer_id then
  144. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  145. self.award_timer_id = nil
  146. end
  147. self:UpdateTime()
  148. end
  149. end
  150. if not self.award_timer_id then
  151. self.award_timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,0.15)
  152. end
  153. end
  154. function GiftActNormalView:UpdateItemList( )
  155. for k,v in pairs(self.item_list) do
  156. v:SetVisible(false,nil,true)
  157. end
  158. local item_list = self.show_goods_list or {}
  159. local new_list = {}
  160. for k,v in pairs(item_list) do
  161. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v[2])
  162. if goods_vo then
  163. v.sort_id = goods_vo.color * 10000000000000 + goods_vo.type_id
  164. if v.type == GoodsModel.TYPE.EQUIP then--装备+100W
  165. v.sort_id = v.sort_id + 10000000
  166. end
  167. new_list[#new_list + 1] = v
  168. end
  169. end
  170. local sort_func = function ( a, b )
  171. return a.sort_id > b.sort_id
  172. end
  173. table.sort(new_list, sort_func)
  174. item_list = new_list
  175. if not item_list or TableSize(item_list) == 0 then return end
  176. local len = #item_list
  177. --如果比最大高度要高 那就只能滚动了
  178. local space_x = 30
  179. local space_y = 20
  180. local item_height = 78
  181. self.parent_con = self.awardCon
  182. self.awardNCon_obj:SetActive(false)
  183. self.awardScroll_obj:SetActive(true)
  184. local x = 0
  185. local y = 0
  186. for i, v in ipairs(item_list) do
  187. local item = self.item_list[i]
  188. if item == nil then
  189. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.parent_con)
  190. item.resetTransform = true
  191. item:SetItemSize(78,78)
  192. self.item_list[i] = item
  193. end
  194. if not self.only_read_goods_type_id then
  195. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
  196. local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
  197. local stren_data = nil
  198. if goodVo then
  199. item:SetData(goods_Id, v[3], nil, stren_data, lock,true,nil)
  200. else
  201. -- error("没有找到物品信息 "..v.typeId)
  202. end
  203. else--如果物品格式第一个数字不是按照物品类型来的,那就直接展示物品
  204. item:SetData(v[2], v[3])
  205. end
  206. item:SetVisible(false,nil,true)
  207. x = (78+41.5)*((i-1)%self.col_num)
  208. y = -(78+20)*math.floor((i-1)/self.col_num)
  209. item:SetPosition(x,y)
  210. if v[4] then
  211. item:SetNumLimitVisible( true, v[4])
  212. end
  213. end
  214. local max_height = (78+20) * math.ceil(len/self.col_num) + 100--最大高度限制10行
  215. SetSizeDeltaY(self.awardCon,max_height)
  216. local index = 0
  217. local function countDown()
  218. index = index + 1
  219. if len >= index then
  220. if self.item_list[index] then
  221. self.item_list[index]:SetVisible(true,nil,true)
  222. end
  223. -- if index%self.col_num == 0 and index ~= 0 and index > self.col_num then
  224. -- SetAnchoredPositionY(self.awardCon,(78+20)*math.floor(index/self.col_num))
  225. -- print("huangcong:GiftActNormalView [start:244] :", math.floor(index/self.col_num),index)
  226. -- end
  227. if index >= self.max_num then
  228. local pos_y = (math.ceil((index - self.max_num) / self.col_num) )* (item_height + space_y)
  229. if self.pos_id then
  230. TweenLite.Stop(self.pos_id)
  231. self.pos_id = nil
  232. end
  233. self.pos_id = TweenLite.to(self, self.parent_con, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.15, callback)
  234. end
  235. else
  236. if self.award_timer_id then
  237. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  238. self.award_timer_id = nil
  239. end
  240. self:UpdateTime()
  241. end
  242. end
  243. if not self.award_timer_id then
  244. self.award_timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,0.15)
  245. end
  246. end