EncourageTips = EncourageTips or BaseClass(BaseView) local EncourageTips = EncourageTips EncourageTips.ShowType = { Open = 1, Update = 2, Close = 3, } EncourageTips.EncourageType = { -- 鼓舞界面类型 Default = 1, --默认类型,以幻魔鼓舞为标准默认类型 GuildBoss = 2, --社团boss鼓舞 } ------------------------- --[[ 通用的鼓舞界面 使用方法参考 self.data 格式,填补对应数据就可以了 --encourageType,社团boss鼓舞传这个参数 --]] ------------------------- function EncourageTips:__init(encourageType) self.base_file = "encourage" --不同模块的鼓舞界面功能大体一致,界面布局不同,可以自己单独搞个预制体 self.encourageType = encourageType if self.encourageType == EncourageTips.EncourageType.GuildBoss then self.is_guild_boss = true self.layout_file = "EncourageGuildBossTips" else self.layout_file = "EncourageTips" end self.layer_name = "Activity" self.destroy_imm = true self.change_scene_close = true self.append_to_ctl_queue = false --是否要添加进界面堆栈 self.need_show_money = true --是否要显示顶部的金钱栏 self.is_set_zdepth = true self.click_bg_toClose = true self.blur_activity_bg = true ------------------------ -- 一级全屏界面: self.hide_maincancas = false --隐藏主界面 self.use_background = true --不一定显示遮罩 -- 二级界面: -- self.hide_maincancas = false --是否需要隐藏主界面,看策划需求 -- self.use_background = true --需要遮罩 ------------------------ --默认数据以及范例 self.data = { [1] ={ type_id = 2,-- 鼓舞类型(红钻) limit = 1,-- 鼓舞最大次数 use_time = 0,-- 已鼓舞次数 click_call = false,--点击回调 first_free = false,--首次免费 }, [2] ={ type_id = 1,-- 鼓舞类型(彩钻) limit = 1,-- 鼓舞最大次数 use_time = 0,-- 已鼓舞次数 click_call = false,--点击回调 first_free = false,--首次免费 } } self.load_callback = function () self:LoadSuccess() self:AddEvent() end self.open_callback = function ( ) self:UpdateView() end self.close_win_callback = function ( ) self:Close() end self.destroy_callback = function ( ) self:DestroySuccess() end end function EncourageTips:CheckData( data ) if not data then return end self.data.title_name = data.title_name or self.data.title_name for i=1,2 do if data[i] then self.data[i].type_id = data[i].type_id or self.data[i].type_id self.data[i].limit = data[i].limit or self.data[i].limit self.data[i].use_time = data[i].use_time or self.data[i].use_time self.data[i].click_call = data[i].click_call or self.data[i].click_call self.data[i].first_free = data[i].first_free or self.data[i].first_free end end end function EncourageTips:Open( data ) self:CheckData(data) BaseView.Open(self) end function EncourageTips:LoadSuccess() local nodes = { "Window:raw","lb_left_2:tmp","lb_left_1:tmp","btn_close:obj", "des_1:tmp","icon_money_1:img","lb_money_1:tmp","btn_1:obj:img", "des_2:tmp","icon_money_2:img","lb_money_2:tmp","btn_2:obj:img", "btn_1/lb_btn_1:tmp", "btn_2/lb_btn_2:tmp", "lb_buff_tip:tmp", "moneyCon", } self:GetChildren(nodes) -- 社团boss鼓舞界面新加节点 if self.is_guild_boss then local nodes_guild_boss = { "encourage_award_money_1:img", "encourage_award_money_2:img", "encourage_award_1:tmp", "encourage_award_2:tmp", "des_1_num:tmp", "des_2_num:tmp", } self:GetChildren(nodes_guild_boss) end if self.is_guild_boss then lua_resM:setOutsideRawImage(self,self.Window_raw,GameResPath.GetViewBigBg("encourage_guild_boss_bg"),false) else lua_resM:setOutsideRawImage(self,self.Window_raw,GameResPath.GetViewBigBg("encourage_bg"),false) end if not self.money_view then self.money_view = UIMoneyView.New(self.moneyCon) end self.money_view:SetPosition(0,0) self.money_view:SetData() -- self.money_view:ChangeShowFlag("smallWindow2") end function EncourageTips:AddEvent() local function call_back( target ) if target == self.btn_close_obj then self:Close() elseif target == self.btn_1_obj then local function ok_callback( ... ) if self.data[1].click_call then self.data[1].click_call() else Message.show("鼓舞类型1") end end if self.cost_goods_can and self.cost_goods_can[1] then --道具足够啦,判断个毛线 ok_callback() return end local function toggle_function( flag ) BossModel:GetInstance().encourage_tip_toggle = flag end local function use_function( toggle_tip_data,call_fun_sum ) if not BossModel:GetInstance().encourage_tip_toggle then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end local need_num = self.cost_num_list[1] or 0 if self.data[1].first_free and self.data[1].use_time == 0 then need_num = 0 end local jin = RoleManager.Instance.mainRoleInfo.jin local jinLock = RoleManager.Instance.mainRoleInfo.jinLock if jinLock >= need_num and self.cost_type_list[1] == 2 then ok_callback() return end local buy_tip_data = { gold_type = self.cost_type_list[1],--货币类型 cost_price = need_num,--消耗金额 ok_callback = ok_callback,--成功 toggle_function = toggle_function,--多选 togglePriceStr = string.format("%s 鼓舞",need_num),--提示语 use_function = use_function,--最终调用 } CustomActivityModel:getInstance():BuyTips(buy_tip_data) elseif target == self.btn_2_obj then local function ok_callback( ... ) if self.data[2].click_call then self.data[2].click_call() else Message.show("鼓舞类型2") end end if self.cost_goods_can and self.cost_goods_can[2] then --道具足够啦,判断个毛线 ok_callback() return end local function toggle_function( flag ) BossModel:GetInstance().encourage_tip_toggle = flag end local function use_function( toggle_tip_data,call_fun_sum ) if not BossModel:GetInstance().encourage_tip_toggle then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end local need_num = self.cost_num_list[2] or 0 if self.data[2].first_free and self.data[2].use_time == 0 or (self.have_act_buff and self.data[2].use_time == 0) then need_num = 0 end local jin = RoleManager.Instance.mainRoleInfo.jin local jinLock = RoleManager.Instance.mainRoleInfo.jinLock if jinLock >= need_num and self.cost_type_list[2] == 2 then ok_callback() return end local buy_tip_data = { gold_type = self.cost_type_list[2],--货币类型 cost_price = need_num,--消耗金额 ok_callback = ok_callback,--成功 toggle_function = toggle_function,--多选 togglePriceStr = string.format("%s 鼓舞",need_num),--提示语 use_function = use_function,--最终调用 } CustomActivityModel:getInstance():BuyTips(buy_tip_data) end end AddClickEvent(self.btn_close_obj,call_back,false) AddClickEvent(self.btn_1_obj,call_back,false) AddClickEvent(self.btn_2_obj,call_back,false) local function updata_buff_state(id) if id == KfActivityModel.TabID.MaterialSubmit and self.is_loaded then self:UpdateViewDefault() end end self:BindEvent(KfActivityModel:getInstance(), KfActivityModel.ANS_UPDATE_VIEW, updata_buff_state) self:BindEvent(GlobalEventSystem, EventName.OPEN_VIP_VIEW, function () self:Close() end) end function EncourageTips:UpdateTips(data,extra_param_list) self:CheckData(data) if extra_param_list then if extra_param_list.show_encourage_percentage then self:UpdateGuildBossEncouragePercentage(true) elseif extra_param_list.show_encourage_times then self:UpdateGuildBossEncourageTimes() else self:UpdateView() end else self:UpdateView() end end function EncourageTips:UpdateView() if self.is_guild_boss then self:UpdateViewGuildBoss() else self:UpdateViewDefault() end end -- 默认鼓舞类型的updateview function EncourageTips:UpdateViewDefault( ) self.cost_goods_can = self.cost_goods_can or {}--道具足够 self.cost_num_list = self.cost_num_list or {} self.cost_type_list = self.cost_type_list or {} for i=1,2 do local can_encourage = self.data[i].use_time < self.data[i].limit local show_time = can_encourage and self.data[i].use_time + 1 or self.data[i].limit local conf = Config.Encourageattr[self.data[i].type_id .. "@" .. show_time] local old_conf = Config.Encourageattr[self.data[i].type_id .. "@" .. (show_time-1)] if self.data[i].use_time == self.data[i].limit then --满级 old_conf = Config.Encourageattr[self.data[i].type_id .. "@" .. self.data[i].limit] end if conf then --置灰按钮 SetImageGray( self["btn_" .. i .. "_img"], not can_encourage ) local tmp_btn_lb = self:GetChild("btn_" .. i .. "/lb_btn_"..i):GetComponent("TMPro.TextMeshProUGUI") if i==1 then SetTMPSharedMaterial(tmp_btn_lb,can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn) else SetTMPSharedMaterial(tmp_btn_lb,can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn) end --鼓舞描述 if can_encourage and self.data[i].use_time == 0 then self["des_" .. i .. "_tmp"].text = "PVE伤害" self:GetChild("des_" .. i .. "_num"):GetComponent("TMPro.TextMeshProUGUI").text = "+0%" else local show_content = Trim(old_conf.desc) local content_list = Split(show_content,[[\n]]) or {} self["des_" .. i .. "_tmp"].text = content_list[1] or "" self:GetChild("des_" .. i .. "_num"):GetComponent("TMPro.TextMeshProUGUI").text = content_list[2] or "" end ------------------------- local price_info = stringtotable(conf.price) local goods_info = stringtotable(conf.goods) --消耗道具显示 local use_goods = false local str_price = "" if TableSize(goods_info) > 0 then local goods_num = GoodsModel:getInstance():GetTypeGoodsNum( goods_info[1][2] ) if goods_num >= goods_info[1][3] then --拥有足够的替代物 str_price = goods_info[1][3] local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( goods_info[1][2] ).goods_icon lua_resM:setOutsideImageSprite(self,self["icon_money_" .. i .. "_img"],GameResPath.GetGoodsIcon(goods_icon),false) use_goods = true self.cost_goods_can[i] = true end end if not use_goods then str_price = price_info[1][3] local asset, source = WordManager:GetCommonMoneyIcon(tonumber(price_info[1][1])) lua_resM:setImageSprite(self, self["icon_money_" .. i .. "_img"], asset, source, true) self.cost_type_list[i] = tonumber(price_info[1][1]) self.cost_num_list[i] = tonumber(str_price) end if i == 2 then local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.BOSS_HUT_ADD --是否存在活动加成buff local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind) if buff_cfg and buff_info and self.data[i].use_time == 0 and self.encourageType ~= EncourageTips.EncourageType.GuildBoss then local sec = buff_info.etime - TimeUtil:getServerTime( ) if sec > 0 then self["lb_money_" .. i .. "_tmp"].text = "免费" local sec = buff_info.etime - TimeUtil:getServerTime( ) self.have_act_buff = true self:ActBuffTimeLate(sec) local buff_name = Config.Unitebuffkind[buff_kind] and Config.Unitebuffkind[buff_kind].name or "" self.lb_buff_tip_tmp.text = string.format("[%s] 生效期间首次免费",ColorUtil.TOPYELLOW,Trim(buff_name)) else self["lb_money_" .. i .. "_tmp"].text = str_price self.lb_buff_tip_tmp.text = "" end else self["lb_money_" .. i .. "_tmp"].text = str_price self.lb_buff_tip_tmp.text = "" end else if self.data[i].first_free and self.data[i].use_time == 0 then self["lb_money_" .. i .. "_tmp"].text = "免费" else if use_goods then -- 鼓舞卷 local goods_id = 102004 local has_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id) local color = has_num >= str_price and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK self["lb_money_" .. i .. "_tmp"].text = string.format('%s/%s', HtmlColorTxt( has_num, color),str_price) else self["lb_money_" .. i .. "_tmp"].text = str_price end end end --显示剩余次数 local left_time = self.data[i].limit - self.data[i].use_time self["lb_left_" .. i .. "_tmp"].text = string.format( "%s鼓舞:剩余%s次", WordManager:GetCommonMoneyStr(tonumber(price_info[1][1])),HtmlColorTxt( left_time , left_time > 0 and '#2cf89a' or '#ff203a')) end end end --活动BUFF时间倒计时 function EncourageTips: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 self.have_act_buff = false self:UpdateViewDefault() GlobalTimerQuest:CancelQuest(self.act_buff_timer_id) self.act_buff_timer_id = nil end end if not self.act_buff_timer_id then self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1) end onTimer() else self.have_act_buff = false self:UpdateViewDefault() end end end -- 社团boss类型的updateviw function EncourageTips:UpdateViewGuildBoss() self.cost_goods_can = self.cost_goods_can or {}--道具足够 self.cost_num_list = self.cost_num_list or {} self.cost_type_list = self.cost_type_list or {} for i=1,2 do self.cost_goods_can[i] = false--不走物品判断逻辑 if i == 1 then--免费鼓舞 self.cost_num_list[i] = 0 self.cost_type_list[i] = 0 else self.cost_num_list[i] = stringtotable(GuildModel:getInstance():GetGuildBossKV("bgold_encourage_cost"))[1] self.cost_type_list[i] = 2 end end self:UpdateGuildBossEncourageTimes() self:UpdateGuildBossEncouragePercentage() end --社团boss界面鼓舞次数刷新 function EncourageTips:UpdateGuildBossEncourageTimes( ) local damage_percentage = GuildModel:getInstance():GetGuildBossKV("encourage_hurt")/100 --万分比伤害,这里除去100拿百分比伤害 self.encourage_award_1_tmp.text = "+20" self.encourage_award_2_tmp.text = "+20" -- 设置红点 local limit_free = GuildModel:getInstance():GetGuildBossKV("free_encourage") local free_time = GuildModel:getInstance():GetLeftFreeEncourageTimes() --self.free_encourage_red_obj:SetActive(limit_free - free_time > 0) for i=1,2 do local can_encourage = self.data[i].use_time < self.data[i].limit -- local show_time = can_encourage and self.data[i].use_time + 1 or self.data[i].limit --置灰 SetImageGray( self["btn_" .. i .. "_img"], not can_encourage ) SetTMPSharedMaterial(self["lb_btn_" .. i .. "_tmp"], not can_encourage and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn or (i == 1 and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)) --价格 self["lb_money_" .. i .. "_tmp"].text = i == 1 and "免费" or stringtotable(GuildModel:getInstance():GetGuildBossKV("bgold_encourage_cost"))[1] --鼓舞加成 self["des_" .. i .. "_num_tmp"].text = "+" .. damage_percentage * self.data[i].use_time .. "%" --显示剩余次数 local left_time = self.data[i].limit - self.data[i].use_time self["lb_left_" .. i .. "_tmp"].text = "剩余" .. WordManager:AddColorToString(left_time,left_time > 0 and '32ff62' or 'fa1022',false) .. "次" end end --社团boss鼓舞加成系数刷新 function EncourageTips:UpdateGuildBossEncouragePercentage(guild_boss_need_show_anim) local damage_percentage = GuildModel:getInstance():GetGuildBossKV("encourage_hurt")/100 --万分比伤害,这里除去100拿百分比伤害 local damage = GuildModel:getInstance():GetEncourageGuildTimes()*damage_percentage -- self.des_1_title_tmp.text = "社团成员伤害" -- self.des_1_tmp.text = "+"..damage.."%" -- if guild_boss_need_show_anim then -- self:PlayGuildBossEncourageActionStart() -- end end -- --社团boss鼓舞界面的鼓舞加成 -- function EncourageTips:PlayGuildBossEncourageActionStart( ) -- self:StopTweenAction() -- SetLocalScale(self.des_1, 1,1,1) -- local function onComplete( ... ) -- self:PlayGuildBossEncourageActionEnd() -- end -- self.scale_start_id = TweenLite.to(self, self.des_1, TweenLite.UiAnimationType.SCALE, Vector3(1.5,1.5,1.5) ,0.1, onComplete) -- end -- function EncourageTips:PlayGuildBossEncourageActionEnd( ) -- local function onComplete( ... ) -- SetLocalScale(self.des_1, 1,1,1) -- self:StopTweenAction() -- end -- self.scale_end_id = TweenLite.to(self, self.des_1, TweenLite.UiAnimationType.SCALE, Vector3(1,1,1) ,0.1, onComplete) -- end -- function EncourageTips:StopTweenAction( ) -- if self.scale_start_id then -- TweenLite.Stop(self.scale_start_id) -- self.scale_start_id = nil -- end -- if self.scale_end_id then -- TweenLite.Stop(self.scale_end_id) -- self.scale_end_id = nil -- end -- end function EncourageTips:DestroySuccess( ) --self:StopTweenAction() if self.act_buff_timer_id then GlobalTimerQuest:CancelQuest(self.act_buff_timer_id) self.act_buff_timer_id = nil end if self.money_view then self.money_view:DeleteMe() self.money_view = nil end end