SpecialTipView = SpecialTipView or BaseClass(BaseView) local SpecialTipView = SpecialTipView local TimeUtil = TimeUtil function SpecialTipView:__init(layout_file_type, layer_name) self.layout_file_type = layout_file_type self.base_file = "common" self.layout_file = "SpecialTipView" -- 计时器里面会跑到的model,都要在这里注册,减少对_G表的搜索 self.scene_mgr = SceneManager:getInstance() self.dungeon_model = BaseDungeonModel:getInstance() self.layer_name = layer_name or "Main" self.destroy_imm = true self.use_background = false self.change_scene_close = true self.append_to_ctl_queue = false --是否要添加进界面堆栈 self.need_show_money = false --是否要显示顶部的金钱栏 self.floor_anim_list = {}--楼层动作列表 self.showing_main_tips = false -- 正在展示主横幅 self.showing_sub_tips = false -- 正在展示副横幅 self.load_callback = function () self:LoadSuccess() self:AddEvent() end self.open_callback = function ( ) self:UpdateView() end self.destroy_callback = function ( ) self:DestroySuccess() end end -- data = { --[其他参数] -- module_id,--模块id -- id,--子模块,与module_id共同使用来寻找Config.Languageextra中的提示语 -- [必须参数] -- type, -- 类型 默认1 1=显示文本定时关闭 2=持续显示倒计时类型1(必须写sepeical_str,且只带一个%s用来展示时间) 3=补充显示的小横幅,不覆盖主横幅的展示 -- sepeical_str,--强制显示文本,传了次文本时,不找配置,直接显示文本内容 -- show_time,--显示时长,时间过后会关闭tipview,nil或false时tipview需要发送事件手动关闭 -- end_time_callback,时间结束回调 -- } function SpecialTipView:InitMainTipData(data) self.module_id = data.module_id self.id = data.id self.sepeical_str = data.sepeical_str self.show_time = data.show_time self.main_type = data.type if self.end_time_callback then self.end_time_callback() end -- 清除掉所有主横幅计时器事件 self:RemoveCloseTimeId() self:RemoveTimerTypeId() self.showing_main_tips = true end function SpecialTipView:InitSubTipData(data) self.st_module_id = data.module_id self.st_id = data.id self.st_sepeical_str = data.sepeical_str self.st_show_time = data.show_time self.st_type = data.type if self.st_end_time_callback then self.st_end_time_callback() end -- 清除掉所有副横幅计时器事件 self:RemoveSubTipsCloseTimeId() self:RemoveSubTipsTimerTypeId() self.showing_sub_tips = true end function SpecialTipView:Open(data, layout_file_type, layer_name) if data.type ~= SpecialTipType.SubTip1 then -- 主tips,覆盖掉之前的主tips self:InitMainTipData(data) elseif data.type == SpecialTipType.SubTip1 then -- 副tips,覆盖副tips的横幅 self:InitSubTipData(data) end BaseView.Open(self) end function SpecialTipView:LoadSuccess() self.nodes = { "diImg:raw", "descText:tmp", "diSubImg:raw", "descSubText:tmp", "descMiddleText:tmp", } self:GetChildren(self.nodes) self:InitMainTipsText(false) self:InitSubTipsText(false) lua_resM:setOutsideRawImage(self, self.diImg_raw, GameResPath.GetViewBigBg("special_tip_di_3"), false) lua_resM:setOutsideRawImage(self, self.diSubImg_raw, GameResPath.GetViewBigBg("special_tip_di_4"), true) --设置sceneView的自适应 self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight) SetAnchoredPosition(self.transform, 0, 0) end function SpecialTipView:AddEvent() end function SpecialTipView:UpdateView() self:UpdateMainTips() self:UpdateSubTips() self:UpdateTipsNodePosition() end function SpecialTipView:UpdateMainTips( ) if not self.showing_main_tips then return end -- 初始化横幅文本 self:InitMainTipsText(true) self:UpdateAutoClose() if self.main_type == SpecialTipType.Normal then self.descText_tmp.text = self.sepeical_str -- 动态拓展倒计时的类型,就放在这里面,原则上倒计时类型可使用同一个self.tip_type_timer_id来保存计时器id elseif self.main_type == SpecialTipType.Middle then self.descMiddleText_tmp.text = self.sepeical_str else self:ShowTimerType() end end -- 类型1展示(秒数) function SpecialTipView:ShowTimerType( ) local end_time = self:GetTimerTypeEndTime() local druation_speed = self:GetTimerTypeDurationSpeed() local left_time -- 展开计时器 local function tipTypeTimerFunc() if self.main_type == SpecialTipType.Timer1 then--秒数倒计时 left_time = end_time - TimeUtil:getServerTime() elseif self.main_type == SpecialTipType.Timer2 then--豪秒数倒计时 left_time = end_time - TimeUtil:getServerTimeMs() / 1000 elseif self.main_type == SpecialTipType.Timer3 then left_time = end_time - TimeUtil:getServerTime() end left_time = left_time > 0 and left_time or 0 ----------------这个是例子 一定要看 --self.sepeical_str = 距离评级下降 %s --self:GetTimeStrFunc(left_time) = <#ffffff>00:00.00 local str = string.format(self.sepeical_str,self:GetTimeStrFunc(left_time)) self.descText_tmp.text = str or "" if left_time <= 0 then self.showing_main_tips = false if self.end_time_callback then self.end_time_callback() self.end_time_callback = nil end self:RemoveTimerTypeId() end end tipTypeTimerFunc() self.tip_type_timer_id = GlobalTimerQuest:AddPeriodQuest(tipTypeTimerFunc, druation_speed, -1) end --专属倒计时方法 function SpecialTipView:GetTimeStrFunc( left_time ) local time_str = "" if self.main_type == SpecialTipType.Timer1 then--秒数倒计时 time_str = string.format("<#ffffff>%s",left_time) elseif self.main_type == SpecialTipType.Timer2 then--豪秒数倒计时 time_str = string.format("<#ffffff>%s",TimeUtil:convertMillisecondTime(left_time)) elseif self.main_type == SpecialTipType.Timer3 then--00:00倒计时 time_str = string.format("<#ffffff>%s",TimeUtil:timeConversion(left_time, "MM-ss")) end return time_str end -- 更新副横幅 function SpecialTipView:UpdateSubTips( ) if not self.showing_sub_tips then return end -- 初始化文本节点 self:InitSubTipsText(true) self:UpdateSubTipAutoClose() self:ShowSubTimerType() end function SpecialTipView:ShowSubTimerType( ) self.descSubText_tmp.text = self.st_sepeical_str end ------------------------------------------------------------------------------------------------- -- 结束时间计算 function SpecialTipView:GetTimerTypeEndTime() if self.main_type == SpecialTipType.Timer2 then return TimeUtil:getServerTime() + self.show_time else return TimeUtil:getServerTime() + self.show_time end end -- 计时器速度 (秒) function SpecialTipView:GetTimerTypeDurationSpeed( ) if self.main_type == SpecialTipType.Timer2 then return 0.03 else return 0.5 end end -- 更新主横幅的倒计时 function SpecialTipView:UpdateAutoClose( ) --不设置显示时间时不会自动关闭界面 if not self.show_time then return end local function clockFun() self.show_time = self.show_time or 0 if self.show_time <= 0 then if self.end_time_callback then self.end_time_callback() self.end_time_callback = nil end self:InitMainTipsText(false) self.showing_main_tips = false self:CheckTipsClose() end self.show_time = self.show_time - 1 end if not self.close_time_id then self.close_time_id = GlobalTimerQuest:AddPeriodQuest(clockFun, 1, -1) end end -- 检查副标题的主倒计时 function SpecialTipView:UpdateSubTipAutoClose( ) if not self.st_show_time then return end local function st_clockFun() self.st_show_time = self.st_show_time or 0 if self.st_show_time <= 0 then if self.st_end_time_callback then self.st_end_time_callback() self.st_end_time_callback = nil end self:InitSubTipsText(false) self.showing_sub_tips = false self:CheckTipsClose() end self.st_show_time = self.st_show_time - 1 end if not self.st_close_time_id then self.st_close_time_id = GlobalTimerQuest:AddPeriodQuest(st_clockFun, 1, -1) end end -- 检查是否关闭tips界面 function SpecialTipView:CheckTipsClose( ) -- 当主Tips和副Tips都不显示的时候,关闭界面 if not self.showing_main_tips and not self.showing_sub_tips then self:Close() return end -- 调整节点位置 self:UpdateTipsNodePosition() end -- 调整横幅节点之间的相对位置 function SpecialTipView:UpdateTipsNodePosition( ) if self.showing_main_tips and self.showing_sub_tips then -- 两个都显示时,需要上下均分位置 SetAnchoredPositionY(self.diImg, 225 + 15) SetAnchoredPositionY(self.descText, 224 + 15) SetAnchoredPositionY(self.diSubImg, 225 - 25) SetAnchoredPositionY(self.descSubText, 226 - 25) SetAnchoredPositionY(self.descMiddleText, 221) elseif self.showing_main_tips then -- 只展示主tips节点 SetAnchoredPositionY(self.diImg, 225) SetAnchoredPositionY(self.descMiddleText, 221) SetAnchoredPositionY(self.descText, 224) elseif self.showing_sub_tips then -- 只展示副tips节点 SetAnchoredPositionY(self.diSubImg, 225) SetAnchoredPositionY(self.descSubText, 226) SetAnchoredPositionY(self.descMiddleText, 221) end end ------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- -- 当出现多个Tip同时发过来的时候做覆盖处理,最后一个发过来的作为当前显示 function SpecialTipView:UpdateTips(data,layout_file_type, layer_name) if data.type ~= SpecialTipType.SubTip1 then -- 主tips,覆盖掉之前的主tips self:InitMainTipData(data) self:UpdateMainTips() elseif data.type == SpecialTipType.SubTip1 then -- 副tips,覆盖副tips的横幅 self:InitSubTipData(data) self:UpdateSubTips() end self:UpdateTipsNodePosition() end -- 初始化所有的文本 function SpecialTipView:InitMainTipsText(show) if self.is_loaded then show = show or false self.diImg_raw.enabled = show self.descText_tmp.text = "" self.descMiddleText_tmp.text = "" end end function SpecialTipView:InitSubTipsText(show) if self.is_loaded then show = show or false self.diSubImg_raw.enabled = show self.descSubText_tmp.text = "" end end function SpecialTipView:RemoveCloseTimeId( ) if self.close_time_id then GlobalTimerQuest:CancelQuest(self.close_time_id) self.close_time_id = nil end end function SpecialTipView:RemoveTimerTypeId( ) if self.tip_type_timer_id then GlobalTimerQuest:CancelQuest(self.tip_type_timer_id) self.tip_type_timer_id = nil end end function SpecialTipView:RemoveSubTipsCloseTimeId( ) if self.st_close_time_id then GlobalTimerQuest:CancelQuest(self.st_close_time_id) self.st_close_time_id = nil end end function SpecialTipView:RemoveSubTipsTimerTypeId( ) if self.st_tip_type_timer_id then GlobalTimerQuest:CancelQuest(self.st_tip_type_timer_id) self.st_tip_type_timer_id = nil end end function SpecialTipView:DestroySuccess( ) self:RemoveCloseTimeId() self:RemoveTimerTypeId() self:RemoveSubTipsCloseTimeId() self:RemoveSubTipsTimerTypeId() end