local UITipsPanel = UIViewClass() local UIShowTipDuration = 5 local TipsFrequency = 0.5 local UITipsItemKey = "UITipsItemKey" local UITipsTextKey = "UITipsTextKey" function UITipsPanel:OnOpened() self:Init() self._existedTipsList = {} self:StartRepeatFunc(self.OnUpdateFun, TipsFrequency) self:ShowTips(0) self:SetPushStyle(LuaConst.PushStyleEnum.NOTCLOSE) end function UITipsPanel:Init() self:RegistSystemEvent(EventID.UI_Tips_RecoverUpdate, self.RecoverUpdate) self:RegistSystemEvent(EventID.UI_Tips_ClearQueue, self.ClearQueue) end function UITipsPanel:GetTipsMsg() return MDL.Tips.GetTipsMsg() end function UITipsPanel:RemoveTipsMsg() return MDL.Tips.RemoveTipsMsg() end function UITipsPanel:ClearTipsMsg() return MDL.Tips.ClearTipsMsg() end function UITipsPanel:RecoverUpdate() if #self:GetTipsMsg() > 0 and #self._existedTipsList == 0 then self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun, TipsFrequency) self:ShowTips(0) end end function UITipsPanel:OnUpdateFun(deltaTime, timeSinceUpdate) if #self:GetTipsMsg() == 0 and #self._existedTipsList == 0 then self:StopRepeatFunc(self.OnUpdateFun) else self:ShowTips(timeSinceUpdate) self:DestroySingleTip(timeSinceUpdate) end end function UITipsPanel:ShowTips(time) -- 判断队列不为空且有消息 local tipMsg = self:GetTipsMsg() if tipMsg ~= nil and #tipMsg > 0 then self:SetTips(tipMsg[1], time) self:RemoveTipsMsg() end end function UITipsPanel:SetTips(msg, time) local createdTip = nil local type = msg.type local text = msg.content if type == MDL.Tips.TipsType.Item then -- 说明传入的信息为table。需要处理图片信息 createdTip = self:GetTipsTempObj(self.Sprite_Tips.gameObject, UITipsItemKey) table.insert(self._existedTipsList, {obj = createdTip, key = UITipsItemKey, time = time}) local itemName = createdTip.Txt_Item local itemCount = createdTip.Txt_Num itemName.text = text.Name if text.ExtraDesc then itemCount.text = "x"..text.Count..text.ExtraDesc else itemCount.text = "x"..text.Count end local itemData = DataSheetManager.ItemData:GetDataByID(text.Id) if itemData.ChipType > 0 then UIUtils.SetActive(createdTip.group_Hero.gameObject, true) UIUtils.SetActive(createdTip.img_Item, false) local shardIcon = createdTip.group_Hero.sprite_Shards local heroIcon = createdTip.group_Hero.img_Hero local img_Item = createdTip.group_Hero.img_Item if itemData.FirstType == LuaConst.ItemType.HeroFragment then local path = ConstAssetPathConfig.path2..itemData.Icon..".png" UIUtils.SetImageByAssetBundle(heroIcon, path) UIUtils.SetActive(img_Item, false) UIUtils.SetActive(heroIcon, true) UIUtils.SetActive(shardIcon, itemData.SecondType ~= 2) else UTL.Item.ItemIconWithoutBg(img_Item, itemData.ID) UIUtils.SetActive(img_Item, true) UIUtils.SetActive(heroIcon, false) UIUtils.SetActive(shardIcon, true) end else UIUtils.SetActive(createdTip.group_Hero.gameObject, false) UIUtils.SetActive(createdTip.img_Item, true) UTL.Item.ItemIconWithoutBg(createdTip.img_Item, itemData.ID) end CTL.Sound.PlayGameSound("UI_obtain") elseif type == MDL.Tips.TipsType.FormatText or type == MDL.Tips.TipsType.Text then createdTip = self:GetTipsTempObj(self.Txt_Tips.gameObject, UITipsTextKey) table.insert(self._existedTipsList, {obj = createdTip, key = UITipsTextKey, time = time}) UIUtils.SetLabel(createdTip.Txt_Msg, text) elseif type == MDL.Tips.TipsType.SingleIDS then createdTip = self:GetTipsTempObj(self.Txt_Tips.gameObject, UITipsTextKey) table.insert(self._existedTipsList, {obj = createdTip, key = UITipsTextKey, time = time}) UIUtils.SetLabelText(createdTip.Txt_Msg, text) end UIUtils.SetActive(createdTip.gameObject, true) end function UITipsPanel:DestroySingleTip(time) if self._existedTipsList ~= nil and #self._existedTipsList > 0 then local firstTips = self._existedTipsList[1] if (time - firstTips.time) >= UIShowTipDuration then self:DestroyCollection(self.Content, 1) table.remove(self._existedTipsList,1) end end end function UITipsPanel:ClearQueue() self:ClearTipsMsg() for k=#self._existedTipsList,1,-1 do self:DestroyCollection(self.Content, k) table.remove(self._existedTipsList,k) end end function UITipsPanel:GetTipsTempObj(tipObj, tipKey) self:InstantiateCollection(self.Content, tipObj) return self.Content[#self.Content] end return UITipsPanel