源战役客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
10 KiB

  1. --普通礼包
  2. GiftNormalView = GiftNormalView or BaseClass(BaseView)
  3. local GiftNormalView = GiftNormalView
  4. function GiftNormalView:__init()
  5. self.base_file = "gift"
  6. self.layout_file = "GiftNormalView"
  7. self.layer_name = "Top"
  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.model:setIsOpenView(true)
  16. self.base_height = 190
  17. self.delay_time = 15
  18. self.col_num = 5 -- 奖励展示的行展示数
  19. self.max_num = 25
  20. self.item_list = {}
  21. self.load_callback = function ()
  22. self.model.is_show_reward_view = true
  23. self:LoadSuccess()
  24. self:addEvents()
  25. end
  26. self.open_callback = function ()
  27. self:setData()
  28. self:setRewardShow()
  29. end
  30. self.close_callback = function ()
  31. end
  32. self.destroy_callback = function ()
  33. self:DestroySuccess()
  34. --判断是否需要弹物品使用框
  35. local vo = ItemUseModel:getInstance():GetItemShowVo()
  36. if vo then
  37. GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
  38. end
  39. end
  40. end
  41. function GiftNormalView:Open(goods_vo)
  42. self.goods_vo = goods_vo
  43. BaseView.Open(self)
  44. end
  45. function GiftNormalView:Reset( )
  46. if self.pos_id then
  47. TweenLite.Stop(self.pos_id)
  48. self.pos_id = nil
  49. end
  50. if self.award_timer_id then
  51. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  52. self.award_timer_id = nil
  53. end
  54. if self.timer_id then
  55. GlobalTimerQuest:CancelQuest(self.timer_id)
  56. self.timer_id = nil
  57. end
  58. SetSizeDeltaY(self.award_scroll, self.base_height)
  59. end
  60. function GiftNormalView:DestroySuccess()
  61. self.model.is_show_reward_view = false
  62. if self.pos_id then
  63. TweenLite.Stop(self.pos_id)
  64. self.pos_id = nil
  65. end
  66. if self.award_timer_id then
  67. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  68. self.award_timer_id = nil
  69. end
  70. if self.timer_id then
  71. GlobalTimerQuest:CancelQuest(self.timer_id)
  72. self.timer_id = nil
  73. end
  74. for i,item in pairs(self.item_list) do
  75. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
  76. end
  77. self.item_list = {}
  78. if self.success_event then
  79. self.model:UnBind(self.success_event)
  80. self.success_event = nil
  81. end
  82. if self.goods_item then
  83. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.goods_item)
  84. self.goods_item = nil
  85. end
  86. self.model:handleCheckGoodsUseItem()
  87. end
  88. function GiftNormalView:LoadSuccess()
  89. local nodes = {
  90. "bg/titlebg:img", "bg/scroll_mask:obj",
  91. "bg:img", "bg/time_text:tmp", "bg/award_con:obj",
  92. "mask_bg:obj","bg/close_btn:obj",
  93. "bg/award_scroll:obj", "bg/award_scroll/Viewport/award_scroll_con",
  94. --重复开启的
  95. "bg/btn_con/continue_btn:obj", "bg/btn_con/item_con:obj", "bg/btn_con/continue_btn/continue_btn_text:tmp", "bg/btn_con:obj",
  96. "bg/btn_con/goods_num_text:tmp",
  97. }
  98. self:GetChildren(nodes)
  99. SetAnchoredPositionY(self.bg, 0)
  100. lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetCommonImage("com_award_result_view_new_bg"),false)
  101. lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage("com_award_result_view_new_title"),false)
  102. end
  103. function GiftNormalView:UpdateTime( )
  104. local time = self.delay_time
  105. local function countDown()
  106. if self._use_delete_method then return end
  107. time = time - 1
  108. if time > 0 then
  109. self.time_text_tmp.text = string.format("%s 秒后关闭界面",HtmlColorTxt(time, "#31e056"))
  110. else
  111. self:Close()
  112. end
  113. end
  114. countDown()
  115. if not self.timer_id then
  116. self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
  117. end
  118. end
  119. function GiftNormalView:addEvents()
  120. local function click_func(target)
  121. if target == self.continue_btn_obj then
  122. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_vo.goods_id, self.goods_vo.type_id, 1)
  123. elseif target == self.mask_bg_obj or self.close_btn_obj then
  124. self:Close()
  125. end
  126. end
  127. AddClickEvent(self.mask_bg_obj, click_func)
  128. AddClickEvent(self.continue_btn_obj, click_func)
  129. AddClickEvent(self.close_btn_obj, click_func)
  130. local function success_func(vo)
  131. if vo.goods_id == self.goods_vo.goods_id then
  132. self.goods_vo.goods_num = vo.goods_num
  133. self:setData()
  134. self:setRewardShow()
  135. end
  136. end
  137. self.success_event = self.model:Bind(GiftModel.USE_GIFT_SUCCESS, success_func)
  138. end
  139. function GiftNormalView:setData()
  140. if self.goods_vo == nil then return end
  141. if not self.goods_item then
  142. self.goods_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con, nil, self.layer_name)
  143. self.goods_item:SetItemSize(47, 47)
  144. end
  145. self.goods_item:SetData(self.goods_vo.type_id)
  146. self.goods_item:SetNumText(self.goods_vo.goods_num)
  147. -- self.goods_num_text_tmp.text = string.format("剩余数量: %s", HtmlColorTxt(self.goods_vo.goods_num, ColorUtil.GREEN_DARK))
  148. self.goods_num_text_tmp.text = ""
  149. if self.goods_vo.goods_num > 0 then
  150. self.btn_con_obj:SetActive(true)
  151. self.base_height = 155 + 50 + 6--50是按钮con的大小 5为间距
  152. else
  153. self.btn_con_obj:SetActive(false)
  154. self.base_height = 155
  155. end
  156. end
  157. --展示奖励
  158. function GiftNormalView:setRewardShow()
  159. if self.model.show_goods == nil then return end
  160. self.show_goods_list = DeepCopy(self.model.show_goods)
  161. local delete_list = {}
  162. local basic
  163. for index,data in ipairs(self.show_goods_list) do
  164. basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(data.goodid)
  165. if basic and basic.type == 52 and (basic.subtype == 1 or basic.subtype == 2 or basic.subtype == 3 or basic.subtype == 6) then
  166. delete_list[data.goodid] = data.gnum
  167. end
  168. end
  169. local goodid
  170. for i = #self.show_goods_list,1,-1 do
  171. goodid = self.show_goods_list[i].goodid
  172. if delete_list[goodid] then
  173. table.remove(self.show_goods_list,i)
  174. end
  175. end
  176. local vo
  177. for id,num in pairs(delete_list) do
  178. for i = 1,num do
  179. vo = {
  180. type=0,
  181. goodid=id,
  182. gnum=1,
  183. }
  184. table.insert(self.show_goods_list,vo)
  185. end
  186. end
  187. self:UpdateItemList()
  188. self.model.show_goods = nil
  189. end
  190. function GiftNormalView:UpdateItemList( )
  191. for k,v in pairs(self.item_list) do
  192. v:SetVisible(false,nil,true)
  193. end
  194. local item_list = self.show_goods_list
  195. local new_list = {}
  196. for k,v in pairs(item_list) do
  197. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.goodid)
  198. v.sort_id = goods_vo.color * 10000000000000 + goods_vo.type_id
  199. if v.type == GoodsModel.TYPE.EQUIP then--装备+100W
  200. v.sort_id = v.sort_id + 10000000
  201. end
  202. new_list[#new_list + 1] = v
  203. end
  204. local sort_func = function ( a, b )
  205. return a.sort_id > b.sort_id
  206. end
  207. table.sort(new_list, sort_func)
  208. item_list = new_list
  209. if not item_list or TableSize(item_list) == 0 then return end
  210. local len = #item_list
  211. self.parent_con = self.award_scroll_con
  212. self.award_scroll_obj:SetActive(true)
  213. --如果比最大高度要高 那就只能滚动了
  214. local offer_x = 4
  215. local offer_y = 0
  216. local space_x = 8
  217. local space_y = 8
  218. local item_height = 78
  219. if len > self.max_num then
  220. self.parent_con = self.award_scroll_con
  221. self.award_con_obj:SetActive(false)
  222. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
  223. end
  224. local max_height = (item_height + space_y) * (math.ceil(self.max_num/self.col_num)-1)--最大高度限制5行
  225. local x = 0
  226. local y = 0
  227. for i, v in ipairs(item_list) do
  228. local item = self.item_list[i]
  229. if item == nil then
  230. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.parent_con)
  231. item:SetItemSize(78,78)
  232. self.item_list[i] = item
  233. end
  234. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v.type, v.goodid)
  235. local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
  236. local stren_data = nil
  237. if goodVo then
  238. item:SetData(goods_Id, v.gnum, goodVo.color, stren_data, lock,true,nil)
  239. else
  240. -- error("没有找到物品信息 "..v.typeId)
  241. end
  242. item:SetVisible(false,nil,true)
  243. end
  244. self.scroll_mask_obj:SetActive(true)
  245. local index = 0
  246. if self.award_timer_id then
  247. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  248. self.award_timer_id = nil
  249. end
  250. local function countDown()
  251. index = index + 1
  252. if len >= index then
  253. if self.item_list[index] then
  254. self.item_list[index]:SetVisible(true,nil,true)
  255. local height = (item_height + space_y) * (math.ceil(index/self.col_num) - 1)
  256. height = height >= max_height and max_height or height
  257. SetSizeDeltaY(self.bg, self.base_height + height)
  258. if index > self.max_num then
  259. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
  260. else
  261. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(index/self.col_num))
  262. end
  263. SetSizeDeltaY(self.parent_con, (item_height + space_y) * math.ceil(index/self.col_num))
  264. --如果大于了就得滚动
  265. if index >= self.max_num then
  266. local pos_y = (math.ceil((index - self.max_num) / self.col_num) )* (item_height + space_y)
  267. if self.pos_id then
  268. TweenLite.Stop(self.pos_id)
  269. self.pos_id = nil
  270. end
  271. self.pos_id = TweenLite.to(self, self.parent_con, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.15, callback)
  272. end
  273. end
  274. else
  275. if self.award_timer_id then
  276. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  277. self.award_timer_id = nil
  278. end
  279. self:UpdateTime()
  280. end
  281. end
  282. if not self.award_timer_id then
  283. self.award_timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,0.15)
  284. end
  285. end