|
|
- -- <*
- -- @Author: Saber
- -- @Description: 2020年8月19日新增 通用快捷充值tip界面
- -- *>
- RechargeTipView = RechargeTipView or BaseClass(BaseView)
- local RechargeTipView = RechargeTipView
-
- RechargeTipView.IconRes = {--注意 这里前8个就是默认类型
- [0] = VipConst.IconResData[0],
- [1] = VipConst.IconResData[1],
- [2] = VipConst.IconResData[2],
- [3] = VipConst.IconResData[3],
- [4] = VipConst.IconResData[4],
- [5] = VipConst.IconResData[5],
- [6] = VipConst.IconResData[6],
- [7] = VipConst.IconResData[7],
- [8] = VipConst.IconResData[8],
- [9] = VipConst.IconResData[1],
- [10] = VipConst.IconResData[2],
- [11] = VipConst.IconResData[3],
- [12] = VipConst.IconResData[4],
- }
-
- function RechargeTipView:__init()
- self.base_file = "common"
- self.layout_file = "RechargeTipView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.change_scene_close = true
- self.is_set_zdepth = true
- self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
- self.blur_activity_bg = true
- self.use_show_anim = true
- self.use_hide_anim = true
-
- self.main_vo = RoleManager.Instance.mainRoleInfo
- self.model = VipModel:getInstance()
- self.need_show_qc = false -- 是否需要展示快速充值节点
- self.need_dia = 0 -- 还需多少彩钻
- self.rc_data = nil -- 推荐档位充值配置
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15800)
- end
- self.qc_con_pos_x_offset = 300 -- 快充节点动画偏移量
- self.open_callback = function ( )
- self:UpdateView()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- -- 需要传入相对应的数据结构才可以正常打开界面
- -- data = {
- -- price = 本次付费需要的金额(可不传,不提示价格)
- -- qc_type = 快充规则类型(默认0) 0:其他类型 1:投资类型 2:招财猫类型
- -- enough_callback = func1 界面内不用,在接口处判断是否需要打开本界面用
- -- close_callback = func2 关闭界面时的回调
- -- pay_callback = func3 充值后的回调
- -- }
- function RechargeTipView:Open(data)
- self.data = data
- BaseView.Open(self)
- end
-
- function RechargeTipView:LoadSuccess()
- local nodes = {
- -- 弹窗主体部分
- "tip_bg:raw",
- "tip_bg/close_btn:obj",
- "tip_bg/cancelBtn:obj",
- "tip_bg/confirmBtn:obj",
- "tip_bg/tip_content:tmp",
- -- 快速充值部分
- "qc_con:obj:img",
- "qc_con/diamond_icon:img",
- "qc_con/pst_bg:obj",
- "qc_con/pst_val:tmp",
- "qc_con/qc_name:tmp",
- "qc_con/qc_price:tmp",
- "tip_bg/rechargeTipsText:tmp",
- }
- self:GetChildren(nodes)
- self.qc_con_cg = self.qc_con:GetComponent("CanvasGroup")
- lua_resM:setOutsideImageSprite(self, self.qc_con_img, GameResPath.GetCommonImage("quick_recharge_bg"),true)
- lua_resM:setOutsideRawImage(self, self.tip_bg_raw, GameResPath.GetViewBigBg("tips_comm_bg6"))
- self.confirmBtnText_tmp = self:GetChild("tip_bg/confirmBtn/Text"):GetComponent(typeof(TMPro.TextMeshProUGUI))
- self.confirmBtnText_tmp.text = "前往"
- end
-
- function RechargeTipView:AddEvent()
- local function click_event(target)
- if target == self.close_btn_obj or target == self.cancelBtn_obj then -- 直接关闭
- self:Close()
- elseif target == self.confirmBtn_obj then -- 跳转到充值界面,并关闭界面
- OpenFun.Open(158, 0)
- self:Close()
- elseif target == self.qc_con_obj then -- 直接走充值sdk
- if PlatformMgr:getInstance():IsCloudTest( ) then
- Message.show("试玩版无法充值,请下载正式版本", "fault")
- return
- end
- if ClientConfig.plat_name == "xm_ml_del_test" or ClientConfig.plat_name == "xm_ml_test_ios"
- or ClientConfig.plat_name == "xm_ml_del_yyb" then
- Message.show("此次游戏为不计费删档测试,不开启付费功能", "fault")
- return
- end
- if self.rc_data and self.rc_data.product_id then
- if AppConst.UpdateMode then
- local callback = function(state)
- if self.data.pay_callback then
- self.data.pay_callback()
- end
- self:Close()
- end
-
- local custom_info = {
- pay_title = self.qc_name_tmp.text,
- id = self.rc_data.product_id,
- recharge_type = 1, -- 快速充值类型
- }
-
- local money = tonumber(self.rc_data.money)
- PlatformMgr:getInstance():PayRequest(money, custom_info, callback)
- -- 通知后端快速充值
- self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15803, self.rc_data.product_id, self.need_dia, 1)
- else
- local cheat_key = "recharge_" .. self.rc_data.product_id
- print("点击充值卡,通过秘籍购买====:", cheat_key)
- CheatModel:getInstance():Fire(CheatModel.SEND_CHEAT_TO_SERVER, cheat_key)
- -- 方便运营后端测试,在gm秘籍这边也发协议记录快捷充值
- self.model:Fire(VipModel.REQUEST_CCMD_EVENT, 15803, self.rc_data.product_id, self.need_dia, 1)
- self:Close()
- end
- else
- OpenFun.Open(158, 0)
- self:Close()
- end
- end
- end
- AddClickEvent(self.close_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.cancelBtn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.confirmBtn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.qc_con_obj, click_event)
-
- local function update_recharge_card_data() -- 根据协议返回的充值卡类型调用节点更新逻辑
- self:UpdateQuickChargeCon()
- end
- self:BindEvent(self.model, VipModel.UPDATE_RECHARGE_CARD_DATA, update_recharge_card_data)
- end
-
- function RechargeTipView:UpdateView()
- self:UpdateTipCon() -- 更新提示文本内容
- end
-
- function RechargeTipView:UpdateTipCon( )
- local tip_str = ""
- if self.data.price then -- 存在价格,则计算差额
- if self.data.qc_type == 2 then -- 招财猫类型,特殊处理
- self.need_dia = self.data.price
- tip_str = string.format("再充值 %s%s 可转动一次\n是否前往充值?",
- -- ColorUtil.RED_DARK,
- WordManager:GetMoneyFaceStr(1),
- HtmlColorTxt(self.need_dia < 0 and 0 or self.need_dia, ColorUtil.ORANGE_DARK)
- )
- else -- 其他类型
- self.need_dia = self.data.price - self.main_vo.jin
- tip_str = string.format("您的%s不足,还差 %s%s\n是否前往充值?",
- "彩钻",
- WordManager:GetMoneyFaceStr(1),
- HtmlColorTxt(self.need_dia < 0 and 0 or self.need_dia, ColorUtil.YELLOW_DARK)
- )
- end
-
- -- 设定快捷充值标志量
- self.need_show_qc = self.data.qc_type
- and self.data.qc_type == 1 -- 投资类型都弹快捷充值
- or self.need_dia > 680 -- 其他情况,彩钻差超过680才弹出快捷充值
- else
- self.need_show_qc = false
- tip_str = "您的彩钻不足,是否前往充值?"
- end
-
- self.tip_content_tmp.text = tip_str
- local is_recharge = RechargeActivityModel:getInstance():IsRecharge()
- if is_recharge then--首充过
- self.rechargeTipsText_tmp.text = ""
- else--未首充过
- self.rechargeTipsText_tmp.text = string.format("<size=80%%>(现在首充,<color=%s>立领888元</color>三天豪礼)</size>",ColorUtil.ORANGE_DARK)
- end
- -- 设置tip节点坐标
- -- SetAnchoredPositionX(self.tip_bg, self.need_show_qc and -105.5 or 0)
- end
-
- -- 弹出快速充值界面(由协议返回来控制)
- function RechargeTipView:UpdateQuickChargeCon( )
- if self.need_show_qc then -- 需要展示快速充值界面时才处理
- -- 充值卡数据
- local all_rc_data = self.model.recharge_card_data.product_list
- local rc_data = {}
- local rc_temp, rc_cfg, rc_cfg_temp, rt_type = 99999999
- local top_rc_cur, top_rc_cfg, top_rt_type = 0
- -- 审核服跟非审核服的充值卡数据要做区分
- for k,v in ipairs(all_rc_data) do
- rc_cfg_temp = self.model:GetRechargeProductConfig(v.product_id)
- if rc_cfg_temp and rc_cfg_temp.is_auth_show == 1 and ClientConfig.alpha_mode then--审核服专用
- rc_data[#rc_data + 1] = v
- elseif rc_cfg_temp and rc_cfg_temp.is_auth_show == 0 and not ClientConfig.alpha_mode then--非审核服
- rc_data[#rc_data + 1] = v
- end
- end
- -- 获取到最接近的档位配置
- for k, v in pairs(rc_data) do
- rc_cfg_temp = self.model:GetRechargeProductConfig(v.product_id)
- if rc_cfg_temp.product_type == 1 then-- 是充值卡类型
- -- 获取最合适档位
- if rc_cfg_temp.game_currency >= self.need_dia
- and rc_cfg_temp.game_currency <= rc_temp then
- rc_cfg = rc_cfg_temp
- rc_temp = rc_cfg_temp.game_currency
- rt_type = v.return_type
- end
- -- 获取最高档位
- if top_rc_cur < rc_cfg_temp.game_currency then
- top_rc_cur = rc_cfg_temp.game_currency
- top_rc_cfg = rc_cfg_temp
- top_rt_type = v.return_type
- end
- end
- end
- -- 没有合适的档位就用最高档位
- rc_cfg = rc_cfg or top_rc_cfg
- rt_type = rt_type or top_rt_type
- -- 全局保存
- self.rc_data = rc_cfg
- -- 存在最接近的档位配置,加载数据,启动动画
- if rc_cfg then
- -- 加载中间的彩钻icon
- local icon_cfg = RechargeTipView.IconRes[tonumber(rc_cfg.product_id)] or {}
- local icon_res = icon_cfg.res or "re_icon_8"
- lua_resM:setOutsideImageSprite(self, self.diamond_icon_img, GameResPath.GetVipIconImage(icon_res), true)
- -- SetAnchoredPosition(self.diamond_icon, icon_cfg.x or -7.5, icon_cfg.y or 25)
- SetAnchoredPosition(self.diamond_icon, icon_cfg.x + 2, icon_cfg.y - 19)
- -- 加载档位标题和金额
- self.qc_name_tmp.text = Trim(rc_cfg.product_name)
- self.qc_price_tmp.text = "¥"..rc_cfg.money
- -- 获取充值返利相关
- local rc_rt = self.model:GetRechargeReturnConfig(rc_cfg.product_id, rt_type or "")
- self.pst_bg_obj:SetActive(rc_rt and true or false)
- -- 赠送的货币类型固定2
- self.pst_val_tmp.text = rc_rt and (WordManager:GetMoneyFaceStr(2) .. rc_rt.return_gold) or ""
- -- 播放动画
- self:StartQuickRechargeConAnim()
- end
- end
- end
-
- -- 播放快充动画
- function RechargeTipView:StartQuickRechargeConAnim( )
- self.qc_con_obj:SetActive(true)
- SetAnchoredPositionX(self.qc_con, self.qc_con.anchoredPosition.x - self.qc_con_pos_x_offset)
- self.qc_con_cg.alpha = 0
- local anim_time = 0.8
- self.qc_con_alpha_anim_id = TweenLite.to(self, self.qc_con_cg, TweenLite.UiAnimationType.ALPHA, 1, anim_time)
- 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)
- end
-
- function RechargeTipView:DestroySuccess( )
- if self.qc_con_alpha_anim_id then
- TweenLite.Stop(self.qc_con_alpha_anim_id)
- self.qc_con_alpha_anim_id = nil
- end
- if self.qc_con_posx_anim_id then
- TweenLite.Stop(self.qc_con_posx_anim_id)
- self.qc_con_posx_anim_id = nil
- end
- if self.data.close_callback then
- self.data.close_callback()
- end
- end
|