源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

277 行
7.7 KiB

  1. TreasureHouseResultView = TreasureHouseResultView or BaseClass(BaseView)
  2. local TreasureHouseResultView = TreasureHouseResultView
  3. function TreasureHouseResultView:__init()
  4. self.base_file = "treasureHouse"
  5. self.layout_file = "TreasureHouseResultView"
  6. self.layer_name = "Activity"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.hide_maincancas = true --是否隐藏主界面
  11. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  12. self.need_show_money = false --是否要显示顶部的金钱栏
  13. self.blur_activity_bg = true
  14. self.use_show_anim = true
  15. self.use_hide_anim = true
  16. self.model = TreasureHouseModel:getInstance()
  17. self.item_list = {}
  18. self.start_pos_x = 0
  19. self.start_pos_y = 0
  20. self.draw_num_type = 0 --结算数量类型 1|单抽 10|10连
  21. self.load_callback = function ()
  22. self:LoadSuccess()
  23. self:AddEvent()
  24. end
  25. self.open_callback = function ( )
  26. self:OpenSuccess()
  27. end
  28. self.close_win_callback = function ( )
  29. self:Close()
  30. end
  31. self.destroy_callback = function ( )
  32. self:DestroySuccess()
  33. end
  34. end
  35. function TreasureHouseResultView:Open(data)
  36. self.data = data
  37. self.pool_type = self.data.pool_type
  38. BaseView.Open(self)
  39. end
  40. function TreasureHouseResultView:LoadSuccess()
  41. local nodes = {
  42. "resultBg:img",
  43. "itemCon:obj",
  44. "ScrollView", "ScrollView/Viewport/Content", "ScrollView/Viewport:img",
  45. "visCon:obj",
  46. "visCon/confirmBtn:obj",
  47. "visCon/againBtn:obj",
  48. "visCon/costIcon:img",
  49. "visCon/costPrice:tmp",
  50. "visCon/againBtn/againText:tmp",
  51. }
  52. self:GetChildren(nodes)
  53. SetLocalPosition(self.transform, 0, 0,-1000)
  54. local function bg_back_func( ... )
  55. self.confirmBtn_obj:SetActive(true)
  56. self.againBtn_obj:SetActive(true)
  57. self.itemCon_obj:SetActive(false)
  58. self.awarditem = TreasureHouseResultItem.New(self.itemCon)
  59. lua_resM:setOutsideImageSprite(self, self.resultBg_img, GameResPath.GetCapsuleEggRes("capsule_egg_result_shine_837_630"))
  60. if self.need_refreshData then
  61. self:UpdateView(self.pool_type)
  62. end
  63. end
  64. if self.background_wnd then
  65. bg_back_func()
  66. else
  67. self.bg_back_func = bg_back_func
  68. end
  69. end
  70. function TreasureHouseResultView:AddEvent()
  71. local on_click = function ( click_obj )
  72. if self.confirmBtn_obj == click_obj then--关闭界面
  73. self:Close()
  74. elseif self.againBtn_obj == click_obj then--再来
  75. self:LuckStart()
  76. end
  77. end
  78. AddClickEvent(self.confirmBtn_obj, on_click)
  79. AddClickEvent(self.againBtn_obj, on_click)
  80. end
  81. function TreasureHouseResultView:OpenSuccess()
  82. self:UpdateView()
  83. end
  84. function TreasureHouseResultView:UpdateView()
  85. if self.is_loaded then
  86. self.need_refreshData = false
  87. else
  88. self.need_refreshData = true
  89. return
  90. end
  91. self.reward_list = self.data.award
  92. self:Reset()
  93. self.visCon_obj:SetActive(false)
  94. if not self.reward_list or #self.reward_list == 0 then
  95. return
  96. end
  97. local reward_count = #self.reward_list
  98. if reward_count == 1 then
  99. self.draw_num_type = 1
  100. self.againText_tmp.text = "再来1次"
  101. elseif reward_count>1 and reward_count<=10 then
  102. self.draw_num_type = 10
  103. self.againText_tmp.text = "再来10次"
  104. end
  105. self:UpdateCost()
  106. local function delay_method( )
  107. self:UpdateRewardBoxes()
  108. self.visCon_obj:SetActive(true)
  109. end
  110. setTimeout(delay_method, 0.6)
  111. end
  112. function TreasureHouseResultView:Reset( )--重置
  113. self:StopAction()
  114. if self.awarditem then
  115. self.awarditem:StopAction()
  116. self.awarditem:SetAwardItemVis(false)
  117. end
  118. self.Content.anchoredPosition = Vector2(self.start_pos_x,self.start_pos_y)
  119. for k,v in pairs(self.item_list) do
  120. v:SetAwardItemVis(false)
  121. v:StopAction()
  122. end
  123. end
  124. function TreasureHouseResultView:UpdateRewardBoxes()
  125. local reward_count = #self.reward_list
  126. if reward_count == 1 then
  127. self.itemCon_obj:SetActive(true)
  128. self.awarditem:SetData(self.reward_list[1],1)
  129. self.awarditem:StartAction(1)
  130. return
  131. end
  132. local x = 0
  133. local y = 0
  134. for i = 1, reward_count do
  135. local item = self.item_list[i]
  136. if not item then
  137. item = TreasureHouseResultItem.New(self.Content)
  138. self.item_list[i] = item
  139. end
  140. item:SetData(self.reward_list[i],i)
  141. x = (84 + 42) * ((i-1)%5)+5
  142. y = -(84 + 30)* math.floor((i-1)/5)-15
  143. item:SetPosition(x,y)
  144. if reward_count ~= 50 then
  145. item:StartAction(i)
  146. end
  147. end
  148. self.Content.sizeDelta = Vector2(0, (84 + 30)* math.floor(reward_count/5)+15)
  149. if self.draw_num_type == 50 then
  150. self.Viewport_img.raycastTarget = false
  151. self:StartAction(self.start_pos_x,self.start_pos_y)
  152. end
  153. end
  154. function TreasureHouseResultView:StartAction( start_pos_x,start_pos_y )
  155. self.cur_x = start_pos_x
  156. self.cur_y = start_pos_y
  157. local count = 0
  158. local function end_func( ... )
  159. count = count + 1
  160. if count >= 5 then
  161. self.Viewport_img.raycastTarget = true
  162. end
  163. for i=1,10 do
  164. -- self.item_list[(count-1)*10 + i]:SetAwardData()
  165. self.item_list[(count-1)*10 + i]:StartAction(i)
  166. end
  167. end
  168. local action = cc.Sequence.New(cc.CallFunc.New(end_func),
  169. cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230,0),cc.CallFunc.New(end_func)--262
  170. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*2,0),cc.CallFunc.New(end_func)
  171. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*3,0),cc.CallFunc.New(end_func)
  172. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*4,0),cc.CallFunc.New(end_func)
  173. )
  174. cc.ActionManager:getInstance():addAction(action, self.Content.transform)
  175. end
  176. function TreasureHouseResultView:StopAction( )
  177. if not self.is_loaded then return end
  178. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.Content.transform)
  179. end
  180. function TreasureHouseResultView:UpdateCost( )
  181. if self.draw_num_type == 1 then
  182. self.costPrice_tmp.text = "1"
  183. elseif self.draw_num_type == 10 then
  184. self.costPrice_tmp.text = "10"
  185. end
  186. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
  187. lua_resM:setOutsideImageSprite(self, self.costIcon_img, GameResPath.GetGoodsIcon(goods_icon),false)
  188. end
  189. function TreasureHouseResultView:LuckStart( )
  190. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  191. local need_show = goods_num < self.pool_type
  192. local str = ""
  193. local buy_price = GoodsModel:getInstance():GetGoodsPrice(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  194. local cost_price = (self.pool_type - goods_num) * buy_price
  195. local function close_callback( ... )
  196. self:Close()
  197. end
  198. local function ok_callback( ... )
  199. if GoodsModel:getInstance():IsJinEnough(cost_price) then
  200. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10401, self.pool_type)
  201. else
  202. local qc_data = {
  203. price = cost_price,
  204. close_callback = close_callback,
  205. }
  206. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  207. end
  208. end
  209. local function toggle_function( flag )
  210. self.model.not_show_treasure_house_tip = flag
  211. end
  212. local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
  213. local toggle_tip_data = {
  214. gold_ab_res = price_asset,
  215. gold_res = price_icon,
  216. price = cost_price,
  217. insufficientText = "",
  218. priceText = string.format("<color=#fdffc2>%s</color> 补足所需的珍宝阁秘钥。",cost_price),
  219. titleText = "提示",
  220. ok_callback = ok_callback,
  221. toggle_function = toggle_function,
  222. is_complex_ok_callback = true,
  223. jump_recharge_callback = close_callback,
  224. }
  225. if not self.model.not_show_treasure_house_tip and cost_price > 0 then
  226. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  227. else
  228. ok_callback()
  229. end
  230. end
  231. function TreasureHouseResultView:DestroySuccess( )
  232. if self.awarditem then
  233. self.awarditem:DeleteMe()
  234. self.awarditem = nil
  235. end
  236. for i,item in pairs(self.item_list) do
  237. item:DeleteMe()
  238. item = nil
  239. end
  240. self.item_list = {}
  241. self:StopAction()
  242. end