--[[ 背包道具tips 子界面相关规则 只能存在一个父一个子,如果打开第三个,就把这个子替了。 ]] local EventSystem = require('Event/EventSystem') local UIBagItemTips = UIViewClass() local ItemBg = ConstAssetPathConfig.ItemBg function UIBagItemTips:OnCreated() self.tipsData = nil; self.itemExpireTime = 0; self.isHasChildTips = false end function UIBagItemTips:OnOpened(context) self:RegistSystemEvent(EventID.Bag_CloseMain, self.CloseView) self:RegistSystemEvent(EventID.UI_ItemTips_Closed, self.OnItemTipsClosed) self:SetPanelTipsPos(0, nil, nil); self.tipsData = context; self:SetTipsData(); self:SetPushStyle(LuaConst.PushStyleEnum.CLOSENOTRECOVER) end --父节点点关闭关了子界面的时候子界面才会发事件再走到父界面的这儿 function UIBagItemTips:OnItemTipsClosed() self.isHasChildTips = false self:SetPanelTipsPos(0, nil, nil) end function UIBagItemTips:SetPanelTipsPos(posX, posY, posZ) self.Panel_ItemTips:SetLocalPosition(posX, posY, posZ) end function UIBagItemTips:SetTipsData() --道具数据 self.scroll_Details:ClearCells(); self:SetTipsBaseData(); self:SetBottomButtons(); local itemCfgData = DataSheetManager.ItemData:GetDataByID(self.tipsData.itemData.CfgId); if itemCfgData.FirstType == LuaConst.ItemType.GiftBag then self:SetGiftBagContent(); end if not self.tipsData.isChildTips and CTL.ItemSources.IsShowItemSource(self.tipsData.itemData.CfgId) then self.scroll_Details:AddData({ dataType = 4 }, 2); end end function UIBagItemTips:SetTipsBaseData() UTL.Item.SetItemCell(self.ItemBase, self.tipsData.itemData.CfgId); local itemCfgData = DataSheetManager.ItemData:GetDataByID(self.tipsData.itemData.CfgId); local qualityData = DataSheetManager.QualityColor:GetDataByID(itemCfgData.Color) local colorBg = qualityData.EquipFragmentComposeBase local colorPrint = qualityData.EquipRefineIcon local itemNameAndDesc = UTL.Item.GetItemDataSpliceByType(self.tipsData.itemData.CfgId, self.tipsData.itemData.Id); local colorName = UTL.Color.FormatQualityText(itemNameAndDesc.Name, itemCfgData.Color) UIUtils.SetImageByAssetBundle(self.img_ItemInfoBg, string.format(ItemBg, colorBg)) UIUtils.SetImageByAssetBundle(self.img_Print, string.format(ItemBg, colorPrint)) UIUtils.SetLabel(self.txt_ItemName, colorName); UIUtils.SetLabelText(self.txt_ItemType, Const_IDS[itemCfgData.Tips]) if itemCfgData.LimitLevelRequire_Team > 0 then UIUtils.SetActive(self.txt_LevelLimitation, true); if itemCfgData.LimitLevelRequire_Team <= MDL.Player.GetRoleLevel() then local Level = UTL.Item.GetNobilityByTeamLevel(itemCfgData.LimitLevelRequire_Team) -- 爵位转换 UIUtils.SetLabel(self.txt_LevelLimitation, " "..Level); else local Level = UTL.Item.GetNobilityByTeamLevel(itemCfgData.LimitLevelRequire_Team) -- 爵位转换 local redLevelStr = UTL.Color.FormatRedColor(Level); UIUtils.SetLabel(self.txt_LevelLimitation, " "..redLevelStr); end else UIUtils.SetActive(self.txt_LevelLimitation, false); end self.scroll_Details:AddData({data = itemNameAndDesc.Des, dataType = 1}, 0); self.itemExpireTime = self.tipsData.itemData.ExpireTime or 0; if self.itemExpireTime <= 0 then UIUtils.SetActive(self.section_Prepare, false); UIUtils.SetActive(self.group_TimeCountdownGreen, false); UIUtils.SetActive(self.group_TimeCountdownRed, false); else UIUtils.SetActive(self.section_Prepare, true); local serverTimeStamp = UTL.Time.GetServerTimestamp() local leftTime = self.itemExpireTime - serverTimeStamp self:StartRepeatFunc(self.OnUpdateFun, leftTime) if leftTime > UTL.Time.TotalSecondsOneDay then UIUtils.SetActive(self.group_TimeCountdownGreen, true) UIUtils.SetActive(self.group_TimeCountdownRed, false) self.group_TimeCountdownGreen:ResetAndBeginCustomTimer(false, leftTime, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_BossChallenge_SeasonLeftTime"]), 1) else UIUtils.SetActive(self.group_TimeCountdownGreen, false) UIUtils.SetActive(self.group_TimeCountdownRed, true) self.group_TimeCountdownRed:ResetAndBeginCustomTimer(false, leftTime, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_BossChallenge_SeasonLeftTime"]), 1) end end end function UIBagItemTips:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIBagItemTips:OnUpdateFun(deltaTime, timeSinceUpdate) self:CloseView(); end function UIBagItemTips:SetBottomButtons() local buttonCount = self.tipsData.btnList and table.getn(self.tipsData.btnList) or 0; if buttonCount == 0 then UIUtils.SetActive(self.group_Btns.gameObject, false) return end UIUtils.SetActive(self.group_Btns.gameObject, true) for i=1, buttonCount do local cell = self.group_Btns[i] if not cell then cell = self:InstantiateCollection(self.group_Btns, self.group_Btns[1].gameObject) end local data = self.tipsData.btnList[i] UIUtils.SetActive(cell.gameObject, true) UIUtils.SetLabel(cell.txt_Button, UIUtils.GetLocalizedTxt(data.textIDS)) end for i = buttonCount + 1, #self.group_Btns do UIUtils.SetActive(self.group_Btns[i].gameObject, false) end end function UIBagItemTips:SetGiftBagContent() local giftBagData = DataSheetManager.UseableItem:GetDataByUseableID(self.tipsData.itemData.CfgId); local cfg local itemCount = 0; if giftBagData.RewardClientShowMust>0 then cfg = DataSheetManager.RewardClientShow:GetDataByClientShowID(giftBagData.RewardClientShowMust); self.scroll_Details:AddData({title = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Bag_ItemTips_Title_CertainlyGet"]), data = DataSheetUtil.GetRewardClientShowItemTable(cfg), dataType = 2, }, 1); end if giftBagData.RewardClientShowRandom>0 then cfg = DataSheetManager.RewardClientShow:GetDataByClientShowID(giftBagData.RewardClientShowRandom); self.scroll_Details:AddData({title = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Bag_ItemTips_Title_RandomGet"]), data = DataSheetUtil.GetRewardClientShowItemTable(cfg), dataType = 2, }, 1); end local giftBagItemData = CTL.Bag.GetGiftBagItemData(giftBagData) itemCount = giftBagItemData and table.getn(giftBagItemData) or 0; if itemCount>0 then self.scroll_Details:AddData({title = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Bag_ItemTips_Title_ChooseGet"]), cfgData = giftBagData, dataType = 3, }, 1); end end function UIBagItemTips:OnButtonClicked(comp) if comp == self.btn_Close then if not self.isHasChildTips then self:CloseView() else --关闭子界面(会走到OnItemTipsClosed,设置成没有子界面。),被关闭的子界面必须通过这种方式关闭(即把自己的遮罩关了),不能自己关闭 EventSystem.Dispatch(EventID.UI_ItemTips_Closed_Child, false) --发true的话父界面还是认为持有子界面 end elseif comp == self.btn_Use then if UTL.ItemTips.IsCanOperateItem(self.tipsData.btnList[1].operType, self.tipsData.itemData.CfgId, self.tipsData.itemData, self.tipsData.btnList[1].funtionModule) then self:CloseView(); if self.tipsData.btnList[1].callbackFunc then self.tipsData.btnList[1].callbackFunc(self.tipsData.itemData.CfgId, true, self.tipsData.itemData); end end elseif comp == self.btn_Use_1 then if UTL.ItemTips.IsCanOperateItem(self.tipsData.btnList[2].operType, self.tipsData.itemData.CfgId, self.tipsData.itemData, self.tipsData.btnList[1].funtionModule) then self:CloseView(); if self.tipsData.btnList[2].callbackFunc then self.tipsData.btnList[2].callbackFunc(self.tipsData.itemData.CfgId, true, self.tipsData.itemData); end end else for i, v in ipairs(self.group_Btns) do if comp == v.event_Click then local data = self.tipsData.btnList[i] if UTL.ItemTips.IsCanOperateItem(data.operType, self.tipsData.itemData.CfgId, self.tipsData.itemData, data.funtionModule) then self:CloseView() if data.callbackFunc then data.callbackFunc(self.tipsData.itemData.CfgId, true, self.tipsData.itemData) end end end end end end function UIBagItemTips:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_ItemSources then cellTable.txt_ItemSources.text = data.desc cellTable.state_ItemSources:SetState(data.isUnlock) elseif scrollRect == self.scroll_Details then if data.dataType == 1 then UIUtils.SetLabel(cellTable.txt_ItemInfoDes, data.data); elseif data.dataType == 3 then cellTable.Content.gameObject.transform:SetAnchoredPosition(0, 0) UIUtils.SetLabel(cellTable.txt_ItemInfoTitle, data.title); local totalItemCount = #data.cfgData.GiftBagItemID for i=1, totalItemCount do local itemCell = cellTable.Content[i] if not itemCell then self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.group_Item.gameObject) itemCell = cellTable.Content[i] end UTL.Item.SetItemCell(itemCell.template_Item.item, data.cfgData.GiftBagItemID[i], data.cfgData.GiftBagItemNum[i]) UIUtils.SetActive(itemCell.gameObject, true); self:ShowCellOwnedTag(itemCell.template_Item.bg_Owned, data.cfgData.GiftBagItemID[i]) end for i=totalItemCount+1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false); end self.scroll_Details:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.BeginDrag, index) self.scroll_Details:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.Drag, index) self.scroll_Details:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.EndDrag, index) elseif data.dataType == 2 then cellTable.Content.gameObject.transform:SetAnchoredPosition(0, 0) UIUtils.SetLabel(cellTable.txt_ItemInfoTitle, data.title); local totalItemCount = #data.data for i=1, totalItemCount do local itemCell = cellTable.Content[i] if not itemCell then self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.group_Item.gameObject) itemCell = cellTable.Content[i] end UTL.Item.SetItemCell(itemCell.template_Item.item, data.data[i].ItemID, data.data[i].ItemNum) UIUtils.SetActive(itemCell.gameObject, true); self:ShowCellOwnedTag(itemCell.template_Item.bg_Owned, data.data[i].ItemID) end for i=totalItemCount+1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false); end elseif data.dataType == 4 then local sourcesList = MDL.ItemSources.GetItemSourcesById(self.tipsData.itemData.CfgId) for i, sourceData in ipairs(sourcesList) do local item = cellTable.Content[i] if not item then item = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.Content[1].gameObject) end UIUtils.SetActive(item.gameObject, true) item.txt_ItemSources.text = sourceData.desc item.state_ItemSources:SetState(sourceData.isUnlock) end end end end function UIBagItemTips:Cell_OnBeginDrag(scrollRect, index, comp, eventData) self.curDragObj = self.scroll_Details.gameObject UIUtils.ExecuteBeginDrag(self.curDragObj, eventData) end function UIBagItemTips:Cell_OnDrag(scrollRect, index, comp, eventData) UIUtils.ExecuteDrag(self.curDragObj, eventData) end function UIBagItemTips:Cell_OnEndDrag(scrollRect, index, comp, eventData) UIUtils.ExecuteEndDrag(self.curDragObj, eventData) end function UIBagItemTips:ShowCellOwnedTag(tagObj, itemID) UIUtils.SetActive(tagObj, false) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemID) local hasItemCount = CTL.Bag.GetHasCountByItemCfgID(itemID) if itemCfgData.FirstType == LuaConst.ItemType.Appearance then UIUtils.SetActive(tagObj, hasItemCount > 0 or self:IsAppearanceItemOwned(itemID, itemCfgData)) elseif itemCfgData.FirstType == LuaConst.ItemType.Portrait then local portraitData = MDL.Character.GetPortraitDataByItemId(itemID) UIUtils.SetActive(tagObj, hasItemCount > 0 or MDL.Character.IsActiveByInfo(portraitData)) elseif itemCfgData.FirstType == LuaConst.ItemType.Frame then local frameData = MDL.Character.GetFrameDataByItemId(itemID) UIUtils.SetActive(tagObj, hasItemCount > 0 or MDL.Character.IsActiveByInfo(frameData)) elseif itemCfgData.FirstType == LuaConst.ItemType.Title then local titleData = CTL.Title.GetTitleDataByItemId(itemID) UIUtils.SetActive(tagObj, hasItemCount > 0 or MDL.Title.HasTitleByGeneralTitleID(titleData.ID)) elseif itemCfgData.FirstType == LuaConst.ItemType.GiftBag and itemCfgData.ThirdType == LuaConst.ItemGiftBagThirdType.GiftChooseGiftBag then if hasItemCount > 0 then UIUtils.SetActive(tagObj, true) return end UIUtils.SetActive(tagObj, self:ShowPreviewGiftBagOwnedTag(itemID)) end end function UIBagItemTips:IsAppearanceItemOwned(itemID, itemCfgData) if itemCfgData.SecondType == MDL.Appearance.AppearanceType.Hero then local appearanceCfgId = MDL.Appearance.GetAppearanceCfgIdByItemId(itemID) local appearanceCfg = DataSheetManager.HeroAppearance:GetDataByID(appearanceCfgId) local appearanceData = MDL.Appearance.GetAppearanceDataByHeroID_AppearanceID(appearanceCfg.HeroID, appearanceCfgId, MDL.Appearance.AppearanceType.Hero) return appearanceData.isActive elseif itemCfgData.SecondType == MDL.Appearance.AppearanceType.Weapon then local appearanceCfgId = MDL.Appearance.GetAppearanceCfgIdByItemId(itemID) local appearanceCfg = DataSheetManager.WeaponAppearance:GetDataByID(appearanceCfgId) local appearanceData = MDL.Appearance.GetAppearanceDataByHeroID_AppearanceID(appearanceCfg.HeroID, appearanceCfgId, MDL.Appearance.AppearanceType.Weapon) return appearanceData.isActive elseif itemCfgData.SecondType == MDL.Appearance.AppearanceType.Horse then local appearanceCfgId = MDL.WarHorse.GetAppearanceDataByItemID(itemID).ID local activeState = MDL.WarHorse.GetOwnType(appearanceCfgId) local isCurNotActive = activeState == MDL.WarHorse.OwnedType.UnOwned or activeState == MDL.WarHorse.OwnedType.Overdue return not isCurNotActive end return false end function UIBagItemTips:ShowPreviewGiftBagOwnedTag(itemID) local giftRewardGetData = DataSheetManager.GiftRewardGet:GetDataByGiftID(itemID).Item_Table for _, item in ipairs(giftRewardGetData) do local hasItemCount = CTL.Bag.GetHasCountByItemCfgID(item.ItemID) if hasItemCount > 0 then return true end local itemCfgData = DataSheetManager.ItemData:GetDataByID(item.ItemID) if self:IsAppearanceItemOwned(item.ItemID, itemCfgData) then return true end end return false end function UIBagItemTips:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.scroll_Details then for i, itemCell in ipairs(cellTable.Content) do if target == itemCell.event_Click then if not self.tipsData.isChildTips then --只有父界面才做这个处理 self.isHasChildTips = true self.Panel_ItemTips:SetLocalPosition(-316, nil, nil); end EventSystem.Dispatch(EventID.UI_ItemTips_Closed_Child, true) --关掉当前子界面(如果自己也是子界面的话就帮父界面关掉自己 if data.dataType == 2 then UTL.ItemTips.ShowCommonTipsById(data.data[i].ItemID, true, true); elseif data.dataType == 3 then UTL.ItemTips.ShowCommonTipsById(data.cfgData.GiftBagItemID[i], true, true); end elseif target == itemCell.btn_ItemSources then local sourcesList = MDL.ItemSources.GetItemSourcesById(self.tipsData.itemData.CfgId) local sourceData = sourcesList[i] if sourceData.isUnlock > 0 then EventSystem.Dispatch(EventID.UI_PayMall_SaveCurrentShopTabIndex) --保存一下商城打开的页签 if CTL.ItemSources.ExecuteSourceFunctionById(sourceData.sourceId, self.tipsData.itemData.CfgId) then self:CloseView(); end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end end end end function UIBagItemTips:OnClosed() if self.isHasChildTips then EventSystem.Dispatch(EventID.UI_ItemTips_Closed_Child, true) end end return UIBagItemTips