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

281 lines
12 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 2020年8月19日新增 通用快捷充值tip界面
  4. -- *>
  5. RechargeTipView = RechargeTipView or BaseClass(BaseView)
  6. local RechargeTipView = RechargeTipView
  7. RechargeTipView.IconRes = {--注意 这里前8个就是默认类型
  8. [0] = VipConst.IconResData[0],
  9. [1] = VipConst.IconResData[1],
  10. [2] = VipConst.IconResData[2],
  11. [3] = VipConst.IconResData[3],
  12. [4] = VipConst.IconResData[4],
  13. [5] = VipConst.IconResData[5],
  14. [6] = VipConst.IconResData[6],
  15. [7] = VipConst.IconResData[7],
  16. [8] = VipConst.IconResData[8],
  17. [9] = VipConst.IconResData[1],
  18. [10] = VipConst.IconResData[2],
  19. [11] = VipConst.IconResData[3],
  20. [12] = VipConst.IconResData[4],
  21. }
  22. function RechargeTipView:__init()
  23. self.base_file = "common"
  24. self.layout_file = "RechargeTipView"
  25. self.layer_name = "Top"
  26. self.destroy_imm = true
  27. self.change_scene_close = true
  28. self.is_set_zdepth = true
  29. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  30. self.blur_activity_bg = true
  31. self.use_show_anim = true
  32. self.use_hide_anim = true
  33. self.main_vo = RoleManager.Instance.mainRoleInfo
  34. self.model = VipModel:getInstance()
  35. self.need_show_qc = false -- 是否需要展示快速充值节点
  36. self.need_dia = 0 -- 还需多少彩钻
  37. self.rc_data = nil -- 推荐档位充值配置
  38. self.load_callback = function ()
  39. self:LoadSuccess()
  40. self:AddEvent()
  41. self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15800)
  42. end
  43. self.qc_con_pos_x_offset = 300 -- 快充节点动画偏移量
  44. self.open_callback = function ( )
  45. self:UpdateView()
  46. end
  47. self.destroy_callback = function ( )
  48. self:DestroySuccess()
  49. end
  50. end
  51. -- 需要传入相对应的数据结构才可以正常打开界面
  52. -- data = {
  53. -- price = 本次付费需要的金额(可不传,不提示价格)
  54. -- qc_type = 快充规则类型(默认0) 0:其他类型 1:投资类型 2:招财猫类型
  55. -- enough_callback = func1 界面内不用,在接口处判断是否需要打开本界面用
  56. -- close_callback = func2 关闭界面时的回调
  57. -- pay_callback = func3 充值后的回调
  58. -- }
  59. function RechargeTipView:Open(data)
  60. self.data = data
  61. BaseView.Open(self)
  62. end
  63. function RechargeTipView:LoadSuccess()
  64. local nodes = {
  65. -- 弹窗主体部分
  66. "tip_bg:raw",
  67. "tip_bg/close_btn:obj",
  68. "tip_bg/cancelBtn:obj",
  69. "tip_bg/confirmBtn:obj",
  70. "tip_bg/tip_content:tmp",
  71. -- 快速充值部分
  72. "qc_con:obj:img",
  73. "qc_con/diamond_icon:img",
  74. "qc_con/pst_bg:obj",
  75. "qc_con/pst_val:tmp",
  76. "qc_con/qc_name:tmp",
  77. "qc_con/qc_price:tmp",
  78. "tip_bg/rechargeTipsText:tmp",
  79. }
  80. self:GetChildren(nodes)
  81. self.qc_con_cg = self.qc_con:GetComponent("CanvasGroup")
  82. lua_resM:setOutsideImageSprite(self, self.qc_con_img, GameResPath.GetCommonImage("quick_recharge_bg"),true)
  83. lua_resM:setOutsideRawImage(self, self.tip_bg_raw, GameResPath.GetViewBigBg("tips_comm_bg6"))
  84. self.confirmBtnText_tmp = self:GetChild("tip_bg/confirmBtn/Text"):GetComponent(typeof(TMPro.TextMeshProUGUI))
  85. self.confirmBtnText_tmp.text = "前往"
  86. end
  87. function RechargeTipView:AddEvent()
  88. local function click_event(target)
  89. if target == self.close_btn_obj or target == self.cancelBtn_obj then -- 直接关闭
  90. self:Close()
  91. elseif target == self.confirmBtn_obj then -- 跳转到充值界面,并关闭界面
  92. OpenFun.Open(158, 0)
  93. self:Close()
  94. elseif target == self.qc_con_obj then -- 直接走充值sdk
  95. if PlatformMgr:getInstance():IsCloudTest( ) then
  96. Message.show("试玩版无法充值,请下载正式版本", "fault")
  97. return
  98. end
  99. if ClientConfig.plat_name == "xm_ml_del_test" or ClientConfig.plat_name == "xm_ml_test_ios"
  100. or ClientConfig.plat_name == "xm_ml_del_yyb" then
  101. Message.show("此次游戏为不计费删档测试,不开启付费功能", "fault")
  102. return
  103. end
  104. if self.rc_data and self.rc_data.product_id then
  105. if AppConst.UpdateMode then
  106. local callback = function(state)
  107. if self.data.pay_callback then
  108. self.data.pay_callback()
  109. end
  110. self:Close()
  111. end
  112. local custom_info = {
  113. pay_title = self.qc_name_tmp.text,
  114. id = self.rc_data.product_id,
  115. recharge_type = 1, -- 快速充值类型
  116. }
  117. local money = tonumber(self.rc_data.money)
  118. PlatformMgr:getInstance():PayRequest(money, custom_info, callback)
  119. -- 通知后端快速充值
  120. self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15803, self.rc_data.product_id, self.need_dia, 1)
  121. else
  122. local cheat_key = "recharge_" .. self.rc_data.product_id
  123. print("点击充值卡,通过秘籍购买====:", cheat_key)
  124. CheatModel:getInstance():Fire(CheatModel.SEND_CHEAT_TO_SERVER, cheat_key)
  125. -- 方便运营后端测试,在gm秘籍这边也发协议记录快捷充值
  126. self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15803, self.rc_data.product_id, self.need_dia, 1)
  127. self:Close()
  128. end
  129. else
  130. OpenFun.Open(158, 0)
  131. self:Close()
  132. end
  133. end
  134. end
  135. AddClickEvent(self.close_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  136. AddClickEvent(self.cancelBtn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  137. AddClickEvent(self.confirmBtn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
  138. AddClickEvent(self.qc_con_obj, click_event)
  139. local function update_recharge_card_data() -- 根据协议返回的充值卡类型调用节点更新逻辑
  140. self:UpdateQuickChargeCon()
  141. end
  142. self:BindEvent(self.model, VipModel.UPDATE_RECHARGE_CARD_DATA, update_recharge_card_data)
  143. end
  144. function RechargeTipView:UpdateView()
  145. self:UpdateTipCon() -- 更新提示文本内容
  146. end
  147. function RechargeTipView:UpdateTipCon( )
  148. local tip_str = ""
  149. if self.data.price then -- 存在价格,则计算差额
  150. if self.data.qc_type == 2 then -- 招财猫类型,特殊处理
  151. self.need_dia = self.data.price
  152. tip_str = string.format("再充值 %s%s 可转动一次\n是否前往充值?",
  153. -- ColorUtil.RED_DARK,
  154. WordManager:GetMoneyFaceStr(1),
  155. HtmlColorTxt(self.need_dia < 0 and 0 or self.need_dia, ColorUtil.ORANGE_DARK)
  156. )
  157. else -- 其他类型
  158. self.need_dia = self.data.price - self.main_vo.jin
  159. tip_str = string.format("您的%s不足,还差 %s%s\n是否前往充值?",
  160. "彩钻",
  161. WordManager:GetMoneyFaceStr(1),
  162. HtmlColorTxt(self.need_dia < 0 and 0 or self.need_dia, ColorUtil.YELLOW_DARK)
  163. )
  164. end
  165. -- 设定快捷充值标志量
  166. self.need_show_qc = self.data.qc_type
  167. and self.data.qc_type == 1 -- 投资类型都弹快捷充值
  168. or self.need_dia > 680 -- 其他情况,彩钻差超过680才弹出快捷充值
  169. else
  170. self.need_show_qc = false
  171. tip_str = "您的彩钻不足,是否前往充值?"
  172. end
  173. self.tip_content_tmp.text = tip_str
  174. local is_recharge = RechargeActivityModel:getInstance():IsRecharge()
  175. if is_recharge then--首充过
  176. self.rechargeTipsText_tmp.text = ""
  177. else--未首充过
  178. self.rechargeTipsText_tmp.text = string.format("<size=80%%>(现在首充,<color=%s>立领888元</color>三天豪礼)</size>",ColorUtil.ORANGE_DARK)
  179. end
  180. -- 设置tip节点坐标
  181. -- SetAnchoredPositionX(self.tip_bg, self.need_show_qc and -105.5 or 0)
  182. end
  183. -- 弹出快速充值界面(由协议返回来控制)
  184. function RechargeTipView:UpdateQuickChargeCon( )
  185. if self.need_show_qc then -- 需要展示快速充值界面时才处理
  186. -- 充值卡数据
  187. local all_rc_data = self.model.recharge_card_data.product_list
  188. local rc_data = {}
  189. local rc_temp, rc_cfg, rc_cfg_temp, rt_type = 99999999
  190. local top_rc_cur, top_rc_cfg, top_rt_type = 0
  191. -- 审核服跟非审核服的充值卡数据要做区分
  192. for k,v in ipairs(all_rc_data) do
  193. rc_cfg_temp = self.model:GetRechargeProductConfig(v.product_id)
  194. if rc_cfg_temp and rc_cfg_temp.is_auth_show == 1 and ClientConfig.alpha_mode then--审核服专用
  195. rc_data[#rc_data + 1] = v
  196. elseif rc_cfg_temp and rc_cfg_temp.is_auth_show == 0 and not ClientConfig.alpha_mode then--非审核服
  197. rc_data[#rc_data + 1] = v
  198. end
  199. end
  200. -- 获取到最接近的档位配置
  201. for k, v in pairs(rc_data) do
  202. rc_cfg_temp = self.model:GetRechargeProductConfig(v.product_id)
  203. if rc_cfg_temp.product_type == 1 then-- 是充值卡类型
  204. -- 获取最合适档位
  205. if rc_cfg_temp.game_currency >= self.need_dia
  206. and rc_cfg_temp.game_currency <= rc_temp then
  207. rc_cfg = rc_cfg_temp
  208. rc_temp = rc_cfg_temp.game_currency
  209. rt_type = v.return_type
  210. end
  211. -- 获取最高档位
  212. if top_rc_cur < rc_cfg_temp.game_currency then
  213. top_rc_cur = rc_cfg_temp.game_currency
  214. top_rc_cfg = rc_cfg_temp
  215. top_rt_type = v.return_type
  216. end
  217. end
  218. end
  219. -- 没有合适的档位就用最高档位
  220. rc_cfg = rc_cfg or top_rc_cfg
  221. rt_type = rt_type or top_rt_type
  222. -- 全局保存
  223. self.rc_data = rc_cfg
  224. -- 存在最接近的档位配置,加载数据,启动动画
  225. if rc_cfg then
  226. -- 加载中间的彩钻icon
  227. local icon_cfg = RechargeTipView.IconRes[tonumber(rc_cfg.product_id)] or {}
  228. local icon_res = icon_cfg.res or "re_icon_8"
  229. lua_resM:setOutsideImageSprite(self, self.diamond_icon_img, GameResPath.GetVipIconImage(icon_res), true)
  230. -- SetAnchoredPosition(self.diamond_icon, icon_cfg.x or -7.5, icon_cfg.y or 25)
  231. SetAnchoredPosition(self.diamond_icon, icon_cfg.x + 2, icon_cfg.y - 19)
  232. -- 加载档位标题和金额
  233. self.qc_name_tmp.text = Trim(rc_cfg.product_name)
  234. self.qc_price_tmp.text = ""..rc_cfg.money
  235. -- 获取充值返利相关
  236. local rc_rt = self.model:GetRechargeReturnConfig(rc_cfg.product_id, rt_type or "")
  237. self.pst_bg_obj:SetActive(rc_rt and true or false)
  238. -- 赠送的货币类型固定2
  239. self.pst_val_tmp.text = rc_rt and (WordManager:GetMoneyFaceStr(2) .. rc_rt.return_gold) or ""
  240. -- 播放动画
  241. self:StartQuickRechargeConAnim()
  242. end
  243. end
  244. end
  245. -- 播放快充动画
  246. function RechargeTipView:StartQuickRechargeConAnim( )
  247. self.qc_con_obj:SetActive(true)
  248. SetAnchoredPositionX(self.qc_con, self.qc_con.anchoredPosition.x - self.qc_con_pos_x_offset)
  249. self.qc_con_cg.alpha = 0
  250. local anim_time = 0.8
  251. self.qc_con_alpha_anim_id = TweenLite.to(self, self.qc_con_cg, TweenLite.UiAnimationType.ALPHA, 1, anim_time)
  252. self.qc_con_posx_anim_id = TweenLite.to(self, self.qc_con, TweenLite.UiAnimationType.ANCHORED_POSX, self.qc_con.anchoredPosition.x + self.qc_con_pos_x_offset, anim_time, nil, TweenFunc.EASE_OUT_QUINT)
  253. end
  254. function RechargeTipView:DestroySuccess( )
  255. if self.qc_con_alpha_anim_id then
  256. TweenLite.Stop(self.qc_con_alpha_anim_id)
  257. self.qc_con_alpha_anim_id = nil
  258. end
  259. if self.qc_con_posx_anim_id then
  260. TweenLite.Stop(self.qc_con_posx_anim_id)
  261. self.qc_con_posx_anim_id = nil
  262. end
  263. if self.data.close_callback then
  264. self.data.close_callback()
  265. end
  266. end