|
|
- -- <*
- -- @Author: Saber
- -- @Description: 经验快车快速挂机提取收益界面
- -- *>
- ExpQuickHangUpView = ExpQuickHangUpView or BaseClass(BaseView)
- local ExpQuickHangUpView = ExpQuickHangUpView
- local Status = Status
- local Config_Exp = Config.Exp
-
- function ExpQuickHangUpView:__init()
- self.base_file = "expDun"
- self.layout_file = "ExpQuickHangUpView"
- self.layer_name = "Activity"
- self.destroy_imm = true
- self.use_background = true
- self.is_set_zdepth = true
- self.blur_activity_bg = true
- self.use_show_anim = true
- self.use_hide_anim = true
- self.jump_close = true
- self.is_full = false -- 记录当前是否已经存够时间,防止出现升级后存在进度倒退的情况
- self.receive_type = nil -- 协议返回的快速挂机领取类型
- self.force_gray = false
- self.main_role = RoleManager.Instance.mainRoleInfo
- self.buff_have_time = 0--是否有免费的二倍数次数
- self.cur_lv = self.main_role.level
- self.cur_exp = self.main_role.exp
- self.last_update_time = 0
-
- self.model = ExpDunModel:getInstance()
- self.dun_model = BaseDungeonModel:getInstance()
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:UpdateView()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function ExpQuickHangUpView:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function ExpQuickHangUpView:LoadSuccess()
- local nodes = {
- "content", "content/sub_bg:raw",
- -- 次数及经验信息
- "content/use_num:tmp",
- -- 钻石购买栏
- "content/money_icon1:img:obj", "content/hangup_require1:tmp:obj", "content/receive_btn1:obj:imgex", "content/receive_btn1/receive_btn1_lb:tmp",
- -- vip栏
- "content/hangup_require2:obj:tmp", "content/receive_btn2:obj:imgex", "content/receive_btn2/receive_btn2_lb:tmp",
- --普通
- "content/hangup_require3:tmp", "content/receive_btn3:obj:imgex", "content/receive_btn3/receive_btn3_lb:tmp",
- -- 红点
- "content/receive_btn_red1:obj", "content/receive_btn_red2:obj", "content/receive_btn_red3:obj",
- -- 经验值进度相关
- "content/exp_tip:tmp", "content/level:tmp", "content/exp_progress:tmp", "content/exp_storge:tmp",
- "content/exp_fill:img",
- -- 奖励预览
- "content/award_con",
- --buff相关
- "content/buffText:tmp",
- }
- self:GetChildren(nodes)
-
- lua_resM:setOutsideRawImage(self, self.sub_bg_raw, GameResPath.GetViewBigBg("exp_hangup_bg"))
- self.exp_tip_tmp.text = "超级加速可获得<color=#fdffc2>大量经验值</color>和<color=#fdffc2>1个小时挂机收益</color>,等级、交易券、装备全都要"
- local function close_callback()
- self:Close()
- end
- self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, nil, nil, true)
- self.tabWindowComponent:SetTitleText("超级加速")
- self.tabWindowComponent:SetBackgroundRes("WindowNew2_bg")
- end
-
- function ExpQuickHangUpView:AddEvent()
- local function click_event(target)
- if target == self.close_btn_obj then
- self:Close()
- elseif target == self.receive_btn1_obj then -- 备注:协议类型坑爹,配置是123排下去的,但是协议对应是321的顺序
- self:OnReceiveBtnClick(3)
- elseif target == self.receive_btn2_obj then
- self:OnReceiveBtnClick(2)
- elseif target == self.receive_btn3_obj then
- self:OnReceiveBtnClick(1)
- elseif target == self.hangup_require2_obj then -- 跳转贵族
- OpenFun.Open(451, 5)
- self:Close()
- end
- end
- AddClickEvent(self.close_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE)
- AddClickEvent(self.receive_btn1_obj, click_event)
- AddClickEvent(self.receive_btn2_obj, click_event)
- AddClickEvent(self.receive_btn3_obj, click_event)
- AddClickEvent(self.hangup_require2_obj, click_event)
-
- -- 升级检测
- local function update_view()
- self:UpdateHangupCountAndCost()
- self:UpdateExpStorge()
- end
- self.on_level_up_id = self.main_role:Bind(EventName.CHANGE_LEVEL, update_view)
- self:BindEvent(self.model, ExpDunModel.UPDATE_QUICKHANGUP_DATA, update_view)
-
- local function on_receive_reward(vo)
- self.is_full = false
- self.receive_type = vo.reward_arg
- self:UpdateBtnFlag(true)
- end
- self:BindEvent(self.model, ExpDunModel.UPDATE_HANGUP_VIEW, on_receive_reward)
-
- local function update_quick_hangup_red(type)
- if not type or type == ExpDunModel.Red_Type.QuickHangUp then
- self:UpdateQuickHangupRed()
- end
- end
- self:BindEvent(self.model, ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE, update_quick_hangup_red)
-
- local function update_exp()
- -- 这个经验会分多段发过来,这边做一个延时
- local function delay_method( )
- self:UpdateRoleLvAndExp()
- end
- if self.update_exp_id then
- GlobalTimerQuest:CancelQuest(self.update_exp_id)
- self.update_exp_id = nil
- end
- self.update_exp_id = setTimeout(delay_method, 0.5)
- end
- self:BindEvent(self.model, ExpDunModel.SHOW_QUICK_HANGUP_ACTION, update_exp)
-
-
- local function updata_buff_state(id)
- if id == KfActivityModel.TabID.MaterialSubmit and self.is_loaded then
- self:UpdateQuickHangupRed()
- end
- end
- self:BindEvent(KfActivityModel:getInstance(), KfActivityModel.ANS_UPDATE_VIEW, updata_buff_state)
- end
-
- function ExpQuickHangUpView:UpdateView()
- self:UpdateBasicData()
- self:UpdateRoleLvAndExp(true)
- self:UpdateQuickHangupRed()
- self:UpdateHangupCountAndCost()
- self:UpdateExpStorge()
- end
-
- -- 加载基础数据
- function ExpQuickHangUpView:UpdateBasicData( )
- -- 加载期望获得道具
- local reward_list = self.model:GetExpDunExpectDropCfg()
- --如果有BOSS掉落活动 这里要添加展示奖励
- local act_award_list = OperateActivityModel:getInstance():GetBossActDropAward()
- local limit_time_item_len = #reward_list
- if #act_award_list>0 then
- for i,v in ipairs(act_award_list) do
- reward_list[#reward_list + 1] = v[2]
- end
- end
-
- self.reward_item_creator = self.reward_item_creator or self:AddUIComponent(UI.ItemListCreator)
- local info = {
- data_list = reward_list,
- item_con = self.award_con,
- scroll_view = self.award_con,
- obj_pool_type = UIObjPool.UIType.AwardItem,
- item_width = 62,
- space_x = 7,
- create_frequency = 0.01,
- alignment = UnityEngine.TextAnchor.UpperLeft,
- on_update_item = function(item, i, v)
- item:SetData(v, 1)
- item:SetItemSize(62, 62)
- if i > limit_time_item_len then--需要显示限时
- item:SetNumLimitVisible(true,6)
- else
- item:SetNumLimitVisible(false)
- end
- end,
- }
- self.reward_item_creator:UpdateItems(info)
- end
-
- function ExpQuickHangUpView:UpdateHangupCountAndCost()
- -- 加载快速挂机次数
- local max_count, use_count = self.model:GetHangUpTimeCount()
- local left_count = max_count - use_count + self.buff_have_time
- self.use_num_tmp.text = string.format("<size=%s%%><color=%s>%s</color>%s次</size>",self.buff_have_time>0 and 80 or 100 ,left_count > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, left_count, self.buff_have_time>0 and HtmlColorTxt("(+1)", ColorUtil.YELLOW_DARK) or "")
- -- 加载当前等级的配置
- local hangup_exp_cfg = self.model:GetBuyExpBasicExpCfg()
- local base_exp = 0
- if hangup_exp_cfg then
- base_exp = hangup_exp_cfg.base_exp
- end
- -- 加载描述文本
- -- local sup_vip_times_cfg = self.model:GetExpDunConfig("sup_vip_times")
- -- local sup_vip_times = sup_vip_times_cfg.value or 0
- -- self.vip_tips_tmp.text = string.format("激活贵族可多领取%s次", sup_vip_times)
- -- 加载按钮倍数
- self:UpdateBtnsTimes()
- -- 加载花费
- local mult_cost_cfg = self.model:GetExpDunConfig("multi_exp_cost")
-
- local jin = self.main_role.jin
- -- 缓存类型1的购买花费
- self.type1_cost = mult_cost_cfg and mult_cost_cfg.value or 0
- self.hangup_require1_tmp.text = string.format(" <color=%s>%s</color>",
- self.type1_cost <= jin and "#FDFFC2" or ColorUtil.RED_DARK, self.type1_cost)
- self.hangup_require2_tmp.text = "<u>贵族免费</u>"
- self.hangup_require3_tmp.text = "免费"
- self.receive_btn3_imgex.gray = self.main_role.sup_vip_type ~= 0 or self.force_gray
- SetTMPSharedMaterial(self.receive_btn3_lb_tmp,
- (self.main_role.sup_vip_type ~= 0 or self.force_gray)
- and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
- or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
- end
-
- function ExpQuickHangUpView:UpdateBtnsTimes( )
- local exp_mult_cfg = self.model:GetExpDunConfig("exp_multiple_time")
- if exp_mult_cfg then
- local cfgs = stringtotable(exp_mult_cfg.value)
- for k = 1, 3 do
- self["receive_btn"..k.."_lb_tmp"].text = string.format("%s倍提取", cfgs[k][1])
- -- 缓存类型1的提升倍数
- if k == 1 then
- self.type1_times = cfgs[k][1]
- end
- end
- end
- end
-
- -- 更新快速挂机累计表现
- function ExpQuickHangUpView:UpdateExpStorge( )
- self:ClearExpStorgeTimer()
- local condition = Config.Modulesub["610@15"].open_lv
- local lv = RoleManager.Instance.mainRoleInfo.level
- if condition > lv then -- 未达到开放等级,默认0进度
- self.exp_storge_tmp.text = string.format("%s级开放超级加速", condition)
- else
- local last_time = self.model:GetQuickHangUpReceiveTime()
- local max_time, use_time = self.model:GetHangUpTimeCount()
- local left_time -- 距离下次刷新的时间
- if last_time ~= 0 and use_time < max_time then
- -- 加载当前等级的配置
- local hangup_exp_cfg = self.model:GetBuyExpBasicExpCfg()
- if not hangup_exp_cfg then
- self:ClearExpStorgeTimer()
- return
- end
- local end_time = last_time + hangup_exp_cfg.time -- 下次刷新的时间戳
- local function quick_hangup_timer()
- left_time = end_time - TimeUtil:getServerTime()
- if left_time < 0 then
- self.exp_storge_tmp.text = string.format("当前存储经验:<color=#ffffff>%s</color>/%s<color=%s>(已满)</color>",
- WordManager:ConvertNum(hangup_exp_cfg.base_exp),
- WordManager:ConvertNum(hangup_exp_cfg.base_exp),
- ColorUtil.GREEN_DARK)
- self:ClearExpStorgeTimer()
- self:UpdateBtnsTimes()
- self:UpdateBtnFlag()
- else
- self.exp_storge_tmp.text = string.format("当前存储经验:<color=#ffffff>%s</color>/%s",
- WordManager:ConvertNum(math.ceil(hangup_exp_cfg.base_exp * (hangup_exp_cfg.time - left_time) / hangup_exp_cfg.time)),
- WordManager:ConvertNum(hangup_exp_cfg.base_exp))
- for k = 1, 3 do
- local time_str = TimeUtil:timeConvert2(left_time, "mm:ss")
- self["receive_btn"..k.."_lb_tmp"].text = time_str
- end
- end
- end
- self.exp_storge_timer = GlobalTimerQuest:AddPeriodQuest(quick_hangup_timer, 0.5, -1)
- quick_hangup_timer()
- self:UpdateBtnFlag(left_time > 0)
- else
- self.exp_storge_tmp.text = string.format("当前存储经验:今日次数已用完")
- end
- end
- end
-
- function ExpQuickHangUpView:ClearExpStorgeTimer( )
- if self.exp_storge_timer then
- GlobalTimerQuest:CancelQuest(self.exp_storge_timer)
- self.exp_storge_timer = nil
- end
- end
-
- function ExpQuickHangUpView:OnReceiveBtnClick( btn_index )
- local function ok_callback()
- self.dun_model:Fire(BaseDungeonModel.REQUEST_CCMD_EVENT, 61050, 2, btn_index)
- end
- -- 按钮索引3对应配置第一条购买配置,也就是要花钱的那条
- if btn_index == 3 and self.model:GetQuickHangupTypeOneFlag() and self.buff_have_time == 0 then
- local priceText = string.format("<color=%s>%s</color> 彩钻获取%s倍收益?", ColorUtil.YELLOW_DARK, self.type1_cost, self.type1_times)
- local data = {
- insufficientText = "",
- price = self.type1_cost,
- priceText = priceText,
- titleText = "提示",
- ok_callback = ok_callback,
- no_need_toggle = false,
- toggle_function = function()
- self.model:UncheckQuickHangupTypeOne()
- end,
- }
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
- else
- if btn_index == 1 and self.main_role.sup_vip_type ~= 0 then -- 免费档位贵族不给买
- Message.show("贵族玩家可领取1.5倍加速", "fault")
- return
- else
- ok_callback()
- end
- end
- end
-
- -- 修改所有领取按钮的状态 gray:灰化 btn_index:根据协议返回的类型控制按钮状态
- function ExpQuickHangUpView:UpdateBtnFlag( gray )
- local max_time, use_time = self.model:GetHangUpTimeCount()
- -- 这里还需要判断一下剩余次数够不够,不够了全部置灰
- self.force_gray = gray
- gray = gray or use_time >= max_time
- self.receive_btn1_imgex.gray = gray
- self.receive_btn2_imgex.gray = gray
- self.receive_btn3_imgex.gray = gray
- SetTMPSharedMaterial(self.receive_btn1_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
- or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
- SetTMPSharedMaterial(self.receive_btn2_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
- or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
- SetTMPSharedMaterial(self.receive_btn3_lb_tmp, gray and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn
- or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
- end
-
- -- 更新快速挂机红点
- function ExpQuickHangUpView:UpdateQuickHangupRed( )
- -- local bool = self.model:GetExpRedByRedType(ExpDunModel.Red_Type.QuickHangUp)
- local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.ADVENTURE_EXP --玩家放置冒险获得1次免费2倍速BUFF
- local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
- local buff_str = ""
- local have_time = 0
- -- buff_cfg = {discount = 80,data = 1}
- -- buff_info = {etime = TimeUtil:getServerTime( )+300,used = {{kdata = 1,vdata=0}}}
- if buff_cfg and buff_info then
- local sec = buff_info.etime - TimeUtil:getServerTime( )
- if sec > 0 then
- have_time = 1
- for k,v in pairs(buff_info.used) do
- if v.kdata == 1 and v.vdata == 1 then--buff有一次免费二倍
- have_time = 0
- break
- end
- end
- local buff_name = Config.Unitebuffkind[buff_kind] and Config.Unitebuffkind[buff_kind].name or ""
- if have_time >= 1 then
- buff_str = string.format("%s生效期间可免费获取%s次",buff_name,buff_cfg.data)
- end
- self:ActBuffTimeLate(sec)
- end
- end
- self.buffText_tmp.text = buff_str
- self.buff_have_time = have_time
- -- 2021年3月16日修改 不再在内层显示红点,全部false
- self.receive_btn_red1_obj:SetActive(have_time >= 1 and self.model:GetExpRedByRedType(ExpDunModel.Red_Type.QuickHangUp))
- -- self.receive_btn_red1_obj:SetActive((bool and self.main_role.jin >= self.type1_cost) or have_time >= 1)
- self.hangup_require1_obj:SetActive(have_time == 0)
- self.money_icon1_obj:SetActive(have_time == 0)
-
- -- -- vip关联的要检测以下是否是灰化了按钮,灰化情况下不出红点
- -- self.receive_btn_red2_obj:SetActive(bool and self.main_role.sup_vip_type ~= 0 )
- -- self.receive_btn_red3_obj:SetActive(bool and self.main_role.sup_vip_type == 0 )
- -- if bool then -- 红点都刷新了,那就顺便刷一下按钮
- -- self:UpdateBtnFlag()
- -- end
- end
-
- -- 更新玩家的经验和等级
- function ExpQuickHangUpView:UpdateRoleLvAndExp(force)
- if force or Status.NowTime - self.last_update_time > 1 then
- local add_lv = self.main_role.level - self.cur_lv
- local cur_exp = self.main_role.exp
- local cur_percentage = self.cur_exp / Config_Exp[self.cur_lv].exp
- local target_percentage = 0
- local function get_percentage(lv)
- if lv <= 0 then
- -- 不满一级,则补上最后的百分比
- local last_percentage = self.main_role.exp / Config_Exp[self.main_role.level].exp
- target_percentage = target_percentage + last_percentage
- else
- -- 获得经验的等级超过1级,则图片的填充百分比按整数增加
- target_percentage = target_percentage < 1 and 1 or (target_percentage + 1)
- lv = lv - 1
- get_percentage(lv)
- end
- end
- -- 递归获得提升n级增长的百分比
- get_percentage(add_lv)
- local add_percentage = target_percentage - cur_percentage
- if add_percentage > 0 then
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.exp_fill)
- local function action_percentage_func(percent)
- percent = percent - 1.0
- local real_pec = percent * percent * percent * percent * percent + 1
- local _, final_percentage = math.modf(cur_percentage + add_percentage * real_pec);
- self.exp_fill_img.fillAmount = final_percentage
- end
- local action_percentage = cc.CustomUpdate.New(1, action_percentage_func)
- cc.ActionManager:getInstance():addAction(action_percentage, self.exp_fill)
- end
- self.exp_fill_img.fillAmount = cur_percentage
- self.cur_lv = self.main_role.level
- self.cur_exp = self.main_role.exp
- self.level_tmp.text = string.format("Lv.%s", self.cur_lv)
- self.exp_progress_tmp.text = string.format("%s/%s", WordManager:ConvertNum(self.cur_exp), WordManager:ConvertNum(Config_Exp[self.cur_lv].exp))
- self.last_update_time = Status.NowTime
- end
- end
-
- function ExpQuickHangUpView:DestroySuccess( )
- if self.act_buff_timer_id then
- GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
- self.act_buff_timer_id = nil
- end
-
- if self.on_level_up_id then
- self.main_role:UnBind(self.on_level_up_id)
- self.on_level_up_id = nil
- end
- if self.update_exp_id then
- GlobalTimerQuest:CancelQuest(self.update_exp_id)
- self.update_exp_id = nil
- end
- if self.tabWindowComponent then
- self.tabWindowComponent:DeleteMe()
- self.tabWindowComponent = nil
- end
-
- self:ClearExpStorgeTimer()
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.exp_fill)
- end
-
- --活动BUFF时间倒计时
- function ExpQuickHangUpView:ActBuffTimeLate( sec )
- if self.is_loaded then
- if self.act_sec == sec then
- return
- else
- self.act_sec = sec
- end
- if self.act_buff_timer_id then
- GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
- self.act_buff_timer_id = nil
- end
- local sec = sec or 0
- if sec > 0 then
- local function onTimer()
- sec = sec - 1
- if sec > 0 then
-
- else
- if self.act_buff_timer_id then
- GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
- self.act_buff_timer_id = nil
- end
- self:UpdateQuickHangupRed()
- end
- end
- if not self.act_buff_timer_id then
- self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
- end
- onTimer()
- else
- self:UpdateQuickHangupRed()
- end
- end
- end
|