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

568 lines
17 KiB

  1. CapsuleEggResultView = CapsuleEggResultView or BaseClass(BaseView)
  2. local CapsuleEggResultView = CapsuleEggResultView
  3. function CapsuleEggResultView:__init()
  4. self.base_file = "capsuleEgg"
  5. self.layout_file = "CapsuleEggResultView"
  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.is_set_zdepth = true
  17. self.model = CapsuleEggModel:getInstance()
  18. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  19. self.delay_show_time_list = {}
  20. self.delay_show_scale_list = {}
  21. self.item_list = {}
  22. self.start_pos_x = 0
  23. self.start_pos_y = 0
  24. self.draw_num_type = 0 --结算数量类型 1|单抽 10|10连 50|50连
  25. self.last_draw_time = 0
  26. self.load_callback = function ()
  27. self:LoadSuccess()
  28. self:AddEvent()
  29. end
  30. self.open_callback = function ( )
  31. self:OpenSuccess()
  32. end
  33. self.close_win_callback = function ( )
  34. self:Close()
  35. end
  36. self.destroy_callback = function ( )
  37. self:DestroySuccess()
  38. end
  39. end
  40. function CapsuleEggResultView:Open(pool_type)
  41. self.pool_type = pool_type
  42. BaseView.Open(self)
  43. end
  44. function CapsuleEggResultView:LoadSuccess()
  45. local nodes = {
  46. "resultBg:img:obj",
  47. "itemCon:obj",
  48. "ScrollView", "ScrollView/Viewport/Content", "ScrollView/Viewport:img",
  49. "visCon:obj",
  50. "visCon/confirmBtn:obj",
  51. "visCon/againBtn:obj",
  52. "visCon/costIcon:img",
  53. "visCon/costPrice:tmp",
  54. "visCon/againBtn/againText:tmp",
  55. "scoreNum:tmp",
  56. "effectCon:obj",
  57. "eggCon:obj",
  58. "eggCon/egg6:obj", "eggCon/egg7:obj", "eggCon/egg4:obj", "eggCon/egg3:obj",
  59. "eggCon/egg8:obj", "eggCon/egg5:obj", "eggCon/egg10:obj", "eggCon/egg9:obj",
  60. "eggCon/egg1:obj", "eggCon/egg2:obj",
  61. "visCon/lightEffect",
  62. "skipBtn:obj",
  63. }
  64. self:GetChildren(nodes)
  65. SetLocalPosition(self.transform, 0, 0,-1000)
  66. self.visCon_obj:SetActive(false)
  67. local function bg_back_func( ... )
  68. self.confirmBtn_obj:SetActive(true)
  69. self.againBtn_obj:SetActive(true)
  70. self.itemCon_obj:SetActive(false)
  71. self.awarditem = CapsuleEggAwardItem.New(self.itemCon)
  72. lua_resM:setOutsideImageSprite(self, self.resultBg_img, GameResPath.GetCapsuleEggRes("capsule_egg_result_shine_837_630"))
  73. if self.need_refreshData then
  74. self:UpdateView(self.pool_type)
  75. end
  76. end
  77. if self.background_wnd then
  78. bg_back_func()
  79. else
  80. self.bg_back_func = bg_back_func
  81. end
  82. self.resultBg_obj:SetActive(false)
  83. SetAnchoredPosition(self.effectCon,CapsuleEggConst.DrawEffectPos.pos_x,CapsuleEggConst.DrawEffectPos.pos_y)
  84. SetAnchoredPosition(self.lightEffect,0,-40)
  85. -- self:AddUIEffect("ui_jihuoxinxitong01", self.lightEffect, self.layer_name, nil, 1.2, true,nil,nil, nil, nil,nil)
  86. for i=1,10 do
  87. SetAnchoredPosition(self["egg"..i],CapsuleEggConst.DrawEggPos[i].pos_x,CapsuleEggConst.DrawEggPos[i].pos_y)
  88. end
  89. end
  90. function CapsuleEggResultView:AddEvent()
  91. local on_click = function ( click_obj )
  92. if self.confirmBtn_obj == click_obj then--关闭界面
  93. self:Close()
  94. elseif self.againBtn_obj == click_obj then--再来
  95. if TimeUtil:getServerTimeMs()/1000 - self.last_draw_time > 1 then
  96. self.last_draw_time = TimeUtil:getServerTimeMs()/1000
  97. self:LuckStart()
  98. end
  99. elseif self.skipBtn_obj == click_obj then--跳过动画
  100. self:DoDrawEndFun()
  101. end
  102. end
  103. AddClickEvent(self.confirmBtn_obj, on_click)
  104. AddClickEvent(self.againBtn_obj, on_click)
  105. AddClickEvent(self.skipBtn_obj, on_click)
  106. local function on_update_result()
  107. if not self.is_loaded then return end
  108. self.resultBg_obj:SetActive(true)
  109. self:UpdateRewardBoxes()
  110. self.visCon_obj:SetActive(true)
  111. end
  112. self:BindEvent(self.model,CapsuleEggConst.REFRESH_CAPSULE_EGG_RESULT_VIEW_AFTER_BIG_REWARD,on_update_result)
  113. end
  114. function CapsuleEggResultView:OpenSuccess()
  115. self:UpdateView(self.pool_type)
  116. end
  117. function CapsuleEggResultView:UpdateView(pool_type)
  118. self.pool_type = pool_type
  119. if self.is_loaded then
  120. self.need_refreshData = false
  121. else
  122. self.need_refreshData = true
  123. return
  124. end
  125. local debug_test = false
  126. if debug_test then
  127. local temp_data = {}
  128. local tt = {}
  129. tt.reward_cfg_id = 13
  130. tt.gtype_id = 230003
  131. tt.goods_num = 1
  132. for i=1,50 do
  133. table.insert(temp_data,tt)
  134. end
  135. self.reward_list = temp_data
  136. else
  137. self.reward_list = self.model:GetNowRewardList()
  138. end
  139. self:Reset()
  140. self.visCon_obj:SetActive(false)
  141. if not self.reward_list or #self.reward_list == 0 then
  142. return
  143. end
  144. local reward_count = #self.reward_list
  145. local max_gear = self.model:GetRewardMaxGear(self.reward_list)
  146. -- lua_resM:setOutsideImageSprite(self, self.capsuleImg_img, GameResPath.GetCapsuleEggRes("capsule_egg_result_open_"..max_gear))
  147. -- self.shine_obj:SetActive(true)
  148. -- self.capsuleImg_obj:SetActive(true)
  149. if reward_count == 1 then
  150. self.draw_num_type = 1
  151. self.againText_tmp.text = "再来1次"
  152. self.scoreNum_tmp.text = 1
  153. elseif reward_count>1 and reward_count<=10 then
  154. self.draw_num_type = 10
  155. self.againText_tmp.text = "再来10次"
  156. self.scoreNum_tmp.text = 10
  157. elseif reward_count>10 and reward_count<=50 then
  158. self.draw_num_type = 50
  159. self.againText_tmp.text = "再来50次"
  160. self.scoreNum_tmp.text = 50
  161. end
  162. self:UpdateCost()
  163. if self.delay_show_act then
  164. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
  165. self.delay_show_act = nil
  166. end
  167. for k,v in pairs(self.delay_show_time_list) do
  168. if v then
  169. TimerQuest.CancelQuest(GlobalTimerQuest, v)
  170. end
  171. end
  172. self.delay_show_time_list = {}
  173. for k,v in pairs(self.delay_show_scale_list) do
  174. if v then
  175. TimerQuest.CancelQuest(GlobalTimerQuest, v)
  176. end
  177. end
  178. self.delay_show_scale_list = {}
  179. self.resultBg_obj:SetActive(false)
  180. local function delay_method( )
  181. self:DoDrawEndFun()
  182. end
  183. self.delay_show_act = setTimeout(delay_method, 4)
  184. local effect_res = self.draw_num_type == 1 and "ui_zhuanhundanchou" or "ui_zhuanhunshilian"
  185. self:AddUIEffect(effect_res, self.effectCon, self.layer_name, nil, 2, false, nil, false,nil,nil,1)
  186. local egg_num = self.draw_num_type == 1 and 1 or 10
  187. if self.draw_num_type == 1 then
  188. SetAnchoredPosition(self["egg1"],0,-50)
  189. else
  190. SetAnchoredPosition(self["egg1"],CapsuleEggConst.DrawEggPos[1].pos_x,CapsuleEggConst.DrawEggPos[1].pos_y)
  191. end
  192. for i=1,10 do
  193. SetLocalScale(self["egg"..i],0,0,0)
  194. end
  195. for i=1,egg_num do
  196. local function delay_method_2( )
  197. local res_data = {
  198. layer_name = "Activity",
  199. father_node = self,
  200. transform = self["egg"..i],
  201. fashion_type = FuncOpenModel.TypeId.OtherGoods,
  202. figure_id = "model_otheregg_1",
  203. ui_model_type = UIModelCommon.ModelType.Model,
  204. position = CapsuleEggConst.DrawEggPos[i].model_pos,
  205. rotate = CapsuleEggConst.DrawEggPos[i].model_rotate,
  206. scale = 160,
  207. }
  208. FuncOpenModel:getInstance():SetModelRes(res_data)
  209. local function delay_show_scale( )
  210. SetLocalScale(self["egg"..i],1,1,1)
  211. end
  212. self.delay_show_scale_list[i] = setTimeout(delay_show_scale, 0.1)
  213. end
  214. self.delay_show_time_list[i] = setTimeout(delay_method_2, CapsuleEggConst.DrawEggPos[i].delay_show_time)
  215. end
  216. self.skipBtn_obj:SetActive(true)
  217. end
  218. function CapsuleEggResultView:DoDrawEndFun( )
  219. if self.delay_show_act then
  220. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
  221. self.delay_show_act = nil
  222. end
  223. self:AddUIEffect("ui_jihuoxinxitong01", self.lightEffect, self.layer_name, nil, 1.2, true,nil,nil, nil, nil,nil)
  224. local show_big_reward_list = self.model:GetBigRewardList(self.reward_list)
  225. if #show_big_reward_list ~= 0 then
  226. self.model:Fire(CapsuleEggConst.OPEN_CAPSULE_EGG_BIG_REWARD_VIEW,show_big_reward_list)
  227. else
  228. self.model:Fire(CapsuleEggConst.REFRESH_CAPSULE_EGG_RESULT_VIEW_AFTER_BIG_REWARD)
  229. end
  230. lua_resM:clearRoleMode(self)
  231. self:ClearUIEffect(self.effectCon)
  232. self.skipBtn_obj:SetActive(false)
  233. end
  234. function CapsuleEggResultView:Reset( )--重置
  235. self:ClearUIEffect(self.lightEffect)
  236. self:ClearUIEffect(self.effectCon)
  237. self:StopAction()
  238. if self.awarditem then
  239. self.awarditem:StopAction()
  240. self.awarditem:SetAwardItemVis(false)
  241. end
  242. self.Content.anchoredPosition = Vector2(self.start_pos_x,self.start_pos_y)
  243. for k,v in pairs(self.item_list) do
  244. v:SetAwardItemVis(false)
  245. v:StopAction()
  246. end
  247. self.skipBtn_obj:SetActive(false)
  248. end
  249. function CapsuleEggResultView:UpdateRewardBoxes()
  250. local reward_count = #self.reward_list
  251. if reward_count == 1 then
  252. self.itemCon_obj:SetActive(true)
  253. self.awarditem:SetData(self.reward_list[1],1)
  254. self.awarditem:StartAction(1)
  255. return
  256. end
  257. local x = 0
  258. local y = 0
  259. for i = 1, reward_count do
  260. local item = self.item_list[i]
  261. if not item then
  262. item = CapsuleEggAwardItem.New(self.Content)
  263. self.item_list[i] = item
  264. end
  265. item:SetData(self.reward_list[i],i)
  266. x = (84 + 42) * ((i-1)%5)+5
  267. y = -(84 + 30)* math.floor((i-1)/5)-15
  268. item:SetPosition(x,y)
  269. if reward_count ~= 50 then
  270. item:StartAction(i)
  271. end
  272. end
  273. self.Content.sizeDelta = Vector2(0, (84 + 30)* math.floor(reward_count/5)+15)
  274. if self.draw_num_type == 50 then
  275. self.Viewport_img.raycastTarget = false
  276. self:StartAction(self.start_pos_x,self.start_pos_y)
  277. end
  278. end
  279. function CapsuleEggResultView:StartAction( start_pos_x,start_pos_y )
  280. self.cur_x = start_pos_x
  281. self.cur_y = start_pos_y
  282. local count = 0
  283. local function end_func( ... )
  284. count = count + 1
  285. if count >= 5 then
  286. self.Viewport_img.raycastTarget = true
  287. end
  288. for i=1,10 do
  289. -- self.item_list[(count-1)*10 + i]:SetAwardData()
  290. self.item_list[(count-1)*10 + i]:StartAction(i)
  291. end
  292. end
  293. local action = cc.Sequence.New(cc.CallFunc.New(end_func),
  294. cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230,0),cc.CallFunc.New(end_func)--262
  295. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*2,0),cc.CallFunc.New(end_func)
  296. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*3,0),cc.CallFunc.New(end_func)
  297. ,cc.DelayTime.New(0.8),cc.MoveTo.New(0.35,cur_x,self.cur_y + 230*4,0),cc.CallFunc.New(end_func)
  298. )
  299. cc.ActionManager:getInstance():addAction(action, self.Content.transform)
  300. end
  301. function CapsuleEggResultView:StopAction( )
  302. if not self.is_loaded then return end
  303. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.Content.transform)
  304. end
  305. function CapsuleEggResultView:UpdateCost( )
  306. local costIcon_res = 0
  307. local cost_ticket_num_list = self.model:GetCostTicketNumList()
  308. local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.LUCKY_OFFER --是否存在活动加成buff 挑战次数+1
  309. local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
  310. -- buff_cfg = {discount = 80,data = 1}
  311. -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 10,vdata=0}}}
  312. self.ten_cost_num = 9
  313. local have_time = buff_cfg and buff_cfg.data or 0
  314. local show_offer_obj = false
  315. self.ten_buff_offer = 100
  316. if buff_cfg and buff_info then
  317. local sec = buff_info.etime - TimeUtil:getServerTime( )
  318. if sec > 0 then
  319. for k,v in pairs(buff_info.used) do
  320. if v.kdata == 10 then--十连还有次数
  321. have_time = have_time - v.vdata
  322. break
  323. end
  324. end
  325. if have_time > 0 then
  326. show_offer_obj = true
  327. self.ten_buff_offer = buff_cfg.discount
  328. end
  329. end
  330. end
  331. if self.draw_num_type == 1 then
  332. costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
  333. if cost_ticket_num_list[self.pool_type][1] < 1 then
  334. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1])
  335. else
  336. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1])
  337. end
  338. elseif self.draw_num_type == 10 then
  339. if self.model:GetCostTicketNumList()[self.pool_type][2] > 0 then
  340. costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,10)
  341. if cost_ticket_num_list[self.pool_type][2] < 1 then
  342. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][2])
  343. else
  344. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][2])
  345. end
  346. else
  347. local cost_num = math.floor(9*self.ten_buff_offer/100 + 0.5) or 9
  348. costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
  349. if cost_ticket_num_list[self.pool_type][1] < cost_num then
  350. self.costPrice_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1],cost_num)
  351. else
  352. self.costPrice_tmp.text = string.format("<%s>%s</color>/%s", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1],cost_num)
  353. end
  354. end
  355. elseif self.draw_num_type == 50 then
  356. if self.model:GetCostTicketNumList()[self.pool_type][3] > 0 then
  357. costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,50)
  358. if cost_ticket_num_list[self.pool_type][3] < 1 then
  359. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][3])
  360. else
  361. self.costPrice_tmp.text = string.format("<%s>%s</color>/1", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][3])
  362. end
  363. else
  364. costIcon_res = self.model:GetCostTicketGTypeId(self.pool_type,1)
  365. if cost_ticket_num_list[self.pool_type][1] < 45 then
  366. self.costPrice_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.RED_DARK, cost_ticket_num_list[self.pool_type][1])
  367. else
  368. self.costPrice_tmp.text = string.format("<%s>%s</color>/45", ColorUtil.GREEN_DARK, cost_ticket_num_list[self.pool_type][1])
  369. end
  370. end
  371. end
  372. --print("==WQ==:CapsuleEggResultView [start:239] costIcon_res:", costIcon_res)
  373. lua_resM:setOutsideImageSprite(self, self.costIcon_img, GameResPath.GetGoodsIcon(costIcon_res),true)
  374. end
  375. function CapsuleEggResultView:LuckStart( )
  376. local ticket_num_list = self.model:GetCostTicketNumList()
  377. local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
  378. local cost_price = 0
  379. local tickets_goods_type_id = 102305
  380. if self.pool_type == 1 then
  381. tickets_goods_type_id = 102305
  382. elseif self.pool_type == 2 then
  383. tickets_goods_type_id = 102308
  384. elseif self.pool_type == 3 then
  385. tickets_goods_type_id = 102311
  386. end
  387. local tickets_price = Config.Goodsprice[tickets_goods_type_id].price
  388. if self.draw_num_type == 1 then
  389. if ticket_num_list[self.pool_type][1] >= 1 then--有单抽券直接抽
  390. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  391. return
  392. else--补齐
  393. cost_price = tickets_price
  394. end
  395. elseif self.draw_num_type == 10 then
  396. if ticket_num_list[self.pool_type][2] >= 1 then
  397. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  398. return
  399. else
  400. local ten_need_num = math.floor(self.ten_cost_num*self.ten_buff_offer/100 + 0.5)--折扣完后要四舍五入
  401. if ticket_num_list[self.pool_type][1] >= ten_need_num then
  402. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  403. return
  404. else
  405. cost_price = (ten_need_num-ticket_num_list[self.pool_type][1])*tickets_price
  406. end
  407. end
  408. elseif self.draw_num_type == 50 then
  409. if ticket_num_list[self.pool_type][3] >= 1 then
  410. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  411. return
  412. else
  413. if ticket_num_list[self.pool_type][1] >= 45 then
  414. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  415. return
  416. else
  417. cost_price = (45-ticket_num_list[self.pool_type][1])*tickets_price
  418. end
  419. end
  420. end
  421. local function close_callback( ... )
  422. self:Close()
  423. end
  424. local function ok_callback()
  425. if GoodsModel:getInstance():IsJinEnough(cost_price) then
  426. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17003,self.pool_type,self.draw_num_type,0)
  427. return
  428. else
  429. local qc_data = {
  430. price = cost_price,
  431. close_callback = close_callback,
  432. }
  433. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  434. end
  435. end
  436. local function toggle_function( flag )
  437. self.model._again_draw_no_double_check = flag
  438. end
  439. local toggle_tip_data = {
  440. gold_ab_res = price_asset,
  441. gold_res = price_icon,
  442. price = cost_price,
  443. insufficientText = "",
  444. priceText = string.format("<color=#fdffc2>%s</color> 补齐所需的单抽券",cost_price),
  445. titleText = "提示",
  446. ok_callback = ok_callback,
  447. toggle_function = toggle_function,
  448. is_complex_ok_callback = true,
  449. jump_recharge_callback = close_callback,
  450. }
  451. if not self.model._again_draw_no_double_check and cost_price ~= 0 then
  452. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  453. else
  454. ok_callback()
  455. end
  456. end
  457. function CapsuleEggResultView:DestroySuccess( )
  458. if self.delay_show_act then
  459. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_act)
  460. self.delay_show_act = nil
  461. end
  462. for k,v in pairs(self.delay_show_time_list) do
  463. if v then
  464. TimerQuest.CancelQuest(GlobalTimerQuest, v)
  465. end
  466. end
  467. self.delay_show_time_list = {}
  468. for k,v in pairs(self.delay_show_scale_list) do
  469. if v then
  470. TimerQuest.CancelQuest(GlobalTimerQuest, v)
  471. end
  472. end
  473. self.delay_show_scale_list = {}
  474. if self.awarditem then
  475. self.awarditem:DeleteMe()
  476. self.awarditem = nil
  477. end
  478. for i,item in pairs(self.item_list) do
  479. item:DeleteMe()
  480. item = nil
  481. end
  482. self.item_list = {}
  483. self:StopAction()
  484. self:ClearUIEffect(self.lightEffect)
  485. self:ClearUIEffect(self.effectCon)
  486. CustomActivityModel:getInstance():SetGoodsCanFly(true)
  487. end