源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

154 строки
6.1 KiB

4 недель назад
  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 藏宝图:普通藏宝图奖励界面
  4. -- *>
  5. TreasureMapNormalRollView = TreasureMapNormalRollView or BaseClass(BaseView)
  6. local TreasureMapNormalRollView = TreasureMapNormalRollView
  7. function TreasureMapNormalRollView:__init()
  8. self.base_file = "treasureMap"
  9. self.layout_file = "TreasureMapNormalRollView"
  10. self.layer_name = "Activity"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.hide_maincancas = false --全屏界面需要隐藏主UI
  14. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  15. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  16. self.model = TreasureMapModel:getInstance()
  17. self.shine_time = 4
  18. self.show_delay_end_time = 0.3
  19. self.auto_close_time = 10 -- 几秒后自动关闭
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:AddEvent()
  23. end
  24. self.open_callback = function ( )
  25. self:UpdateView()
  26. end
  27. self.destroy_callback = function ( )
  28. self:DestroySuccess()
  29. end
  30. end
  31. function TreasureMapNormalRollView:Open(reward_data)
  32. self.reward_data = reward_data
  33. BaseView.Open(self)
  34. end
  35. function TreasureMapNormalRollView:LoadSuccess()
  36. local nodes = {
  37. "bg:raw", "close_btn:obj",
  38. "icon_con:cg",
  39. "light:imgex",
  40. "comfirm_btn:obj",
  41. "auto_close:tmp",
  42. }
  43. self:GetChildren(nodes)
  44. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetTreasureMapImage("tm_nor_bg"))
  45. self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.icon_con)
  46. self.awardItem:SetItemSize(78, 78)
  47. self.awardItem:SetAnchoredPosition(0, 0)
  48. end
  49. function TreasureMapNormalRollView:AddEvent()
  50. local function click_event(target)
  51. if target == self.close_btn_obj then -- 关闭按钮
  52. self:Close()
  53. elseif target == self.comfirm_btn_obj then -- 确认按钮
  54. self:Close()
  55. end
  56. end
  57. AddClickEvent(self.close_btn_obj, click_event)
  58. AddClickEvent(self.comfirm_btn_obj, click_event)
  59. end
  60. function TreasureMapNormalRollView:UpdateView()
  61. self:UpdateBasicData()
  62. self:StartTreasureOpenAnim()
  63. end
  64. -- 加载基础数据
  65. function TreasureMapNormalRollView:UpdateBasicData( )
  66. local reward_cfg = Config.Treasuremaprewards[self.reward_data.reward_id]
  67. local reward = reward_cfg and stringtotable(reward_cfg.rewards)[1] or {}
  68. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(reward[1] , reward[2])
  69. self.awardItem:SetData(goods_Id, reward[3], nil, nil, lock)
  70. end
  71. -- 打开的宝箱做出动画表现
  72. function TreasureMapNormalRollView:StartTreasureOpenAnim( )
  73. self.is_animating = true
  74. local show_delay_end = cc.DelayTime.New(self.show_delay_end_time)
  75. -- 光束闪烁表现
  76. local function action_light_show_alpha_func(percent)
  77. self.light_imgex.alpha = percent
  78. end
  79. local function action_light_hide_alpha_func(percent)
  80. self.light_imgex.alpha = 1 - percent
  81. end
  82. -- local total_shine_time = 0
  83. local action_tb = {}
  84. -- for k = 1, self.shine_time do
  85. -- math.randomseed(os.time() + 2 * k)
  86. -- local random_time = math.random(3, 15) * 0.01
  87. -- action_tb[#action_tb+1] = cc.CustomUpdate.New(random_time, action_light_show_alpha_func)
  88. -- total_shine_time = total_shine_time + random_time
  89. -- math.randomseed(os.time() + 2 * k + 1)
  90. -- random_time = math.random(3, 15) * 0.01
  91. -- action_tb[#action_tb+1] = cc.CustomUpdate.New(random_time, action_light_hide_alpha_func)
  92. -- total_shine_time = total_shine_time + random_time
  93. -- end
  94. action_tb[#action_tb+1] = show_delay_end
  95. local action_shine_show_final = cc.CustomUpdate.New(0.5, action_light_show_alpha_func)
  96. action_tb[#action_tb+1] = action_shine_show_final
  97. local action_light = cc.Sequence.New(unpack(action_tb))
  98. cc.ActionManager:getInstance():addAction(action_light, self.light)
  99. -- 奖励淡出表现
  100. local function icon_con_alpha_func(percent)
  101. self.icon_con_cg.alpha = percent
  102. end
  103. local function animation_end_func() -- 动画结束之后,弹出倒计时和关闭按钮
  104. self.is_animating = false
  105. self.close_btn_obj:SetActive(true)
  106. self.comfirm_btn_obj:SetActive(true)
  107. self:StartAutoCloseTimer()
  108. end
  109. local action_icon_con_show = cc.CustomUpdate.New(0.5, icon_con_alpha_func)
  110. -- local action_icon_con = cc.Sequence.New(cc.DelayTime.New(total_shine_time + self.show_delay_end_time),
  111. -- action_icon_con_show, cc.CallFunc.New(animation_end_func))
  112. local action_icon_con = cc.Sequence.New(show_delay_end, action_icon_con_show, cc.CallFunc.New(animation_end_func))
  113. cc.ActionManager:getInstance():addAction(action_icon_con, self.icon_con)
  114. end
  115. -- 自动关闭倒计时
  116. function TreasureMapNormalRollView:StartAutoCloseTimer( )
  117. local end_time = TimeUtil:getServerTime() + self.auto_close_time
  118. local function auto_close_time_func()
  119. local left_time = end_time - TimeUtil:getServerTime()
  120. if left_time > 0 then
  121. self.auto_close_tmp.text = string.format("<color=%s>%s</color> 秒后自动关闭", ColorUtil.GREEN_DARK, left_time)
  122. else
  123. self:Close()
  124. end
  125. end
  126. if not self.auto_close_time_func_id then
  127. self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
  128. end
  129. end
  130. function TreasureMapNormalRollView:DestroySuccess( )
  131. if self.awardItem then
  132. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
  133. self.awardItem = nil
  134. end
  135. if self.auto_close_time_func_id then
  136. GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
  137. self.auto_close_time_func_id = nil
  138. end
  139. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.light)
  140. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.icon_con)
  141. self.model._check_tm_tips = TreasureMapConst.Normal
  142. self.model:CheckTreasureTipUseViewOpen()
  143. end