--[[ 背包系统 --]] local UIBagMain = UIViewClass() local EventSystem = require('Event/EventSystem') local GreenBgImg = "Assets/UI/Atlas/UI_CommonNew/loading_bg_06.png" local RedBgImg = "Assets/UI/Atlas/UI_CommonNew/loading_bg_07.png" local TotalSecondsOneDay = UTL.Time.TotalSecondsOneDay local GetServerTimestamp = UTL.Time.GetServerTimestamp local ExpireTimeSort = function(a, b) return a.expireTime > b.expireTime end function UIBagMain:OnCreated() self.displayBagCellData = nil; for __, tabData in ipairs(MDL.Bag.BagTypeTabData) do self.UICommonPopUpTab.loop_Tab:AddData(tabData, 0); end end function UIBagMain:OnOpened() self:RegistSystemEvent(EventID.BagItem_Update, self.UpdateAllItem); CTL.Bag.ShowExpireItemDeleteTips(); for index, tabData in ipairs(MDL.Bag.BagTypeTabData) do if tabData.pageType == CTL.Bag.GetCurrentShowItemType() then self.UICommonPopUpTab.loop_Tab:SelectIndex(index-1); end end UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title, Const_IDS.IDS_Bag) self.playSound = true self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) end function UIBagMain:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UIBagMain:UpdateAllItem() self:InitBagAllItem(); self.playSound = false self.UICommonPopUpTab.loop_Tab:RefreshCells(); self.playSound = true end function UIBagMain:InitBagAllItem() self.itemExpireTime = {} self.displayBagCellData = CTL.Bag.GetBagData() self.LoopScroll:ReloadAll(self.displayBagCellData) UIUtils.SetActive(self.group_ItemEmpty, self.displayBagCellData[1] == nil) end function UIBagMain:UpdateExpireTime(deltaTime, timeSinceUpdate) if #self.itemExpireTime > 0 then local serverTime = GetServerTimestamp() for i = #self.itemExpireTime, 1, -1 do local data = self.itemExpireTime[i] if data.expireTime - serverTime <= 0 then table.remove(self.itemExpireTime, i) local cellTable = self.LoopScroll:GetCellTableByIndex(data.index) UIUtils.SetActive(cellTable.item.group_TimeLimit, false) else break end end if #self.itemExpireTime > 0 then self:StartRepeatFunc(self.UpdateExpireTime, self.itemExpireTime[#self.itemExpireTime].expireTime - serverTime, 1) end end end function UIBagMain:OnButtonClicked(comp) if comp == self.UICommonPopUpTab.btn_Close then CTL.Bag.SetCurrentShowItemType(MDL.Bag.BagType.Consumables); self:CloseView() return; end end function UIBagMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.LoopScroll then if not data.itemData then UIUtils.SetActive(cellTable.item.gameObject, false); return; end UIUtils.SetActive(cellTable.item.gameObject, true); UTL.Item.SetItemCell(cellTable.item, data.itemData.CfgId, data.itemData.Count); -- 新道具提示 UIUtils.SetActive(cellTable.item.sprite_New, MDL.Bag.IsNewTip(data.itemData.Id)); -- 红点提示 UIUtils.SetActive(cellTable.item.sprite_Arrow, false); UIUtils.SetActive(cellTable.item.Img_RedPoint, CTL.Bag.IsItemHasRedpoint(data.itemData)); UIUtils.SetActive(cellTable.item.sprite_Selected, false); UIUtils.SetActive(cellTable.item.bg, false); --道具过期时间 local leftTime = data.itemData.ExpireTime - GetServerTimestamp() if leftTime > 0 then UIUtils.SetActive(cellTable.item.group_TimeLimit, true) UTL.Item.SetItemExpireTime(cellTable.item.txt_TimeLimit, leftTime); if leftTime < TotalSecondsOneDay then UIUtils.SetImageByAssetBundle(cellTable.item.img_TimeBg, RedBgImg) else UIUtils.SetImageByAssetBundle(cellTable.item.img_TimeBg, GreenBgImg) end table.insert(self.itemExpireTime, {expireTime = data.itemData.ExpireTime, index = index}) table.sort(self.itemExpireTime, ExpireTimeSort) self:StartRepeatFunc(self.UpdateExpireTime, self.itemExpireTime[#self.itemExpireTime].expireTime - GetServerTimestamp(), 1) else UIUtils.SetActive(cellTable.item.group_TimeLimit, false) end elseif scrollRect == self.UICommonPopUpTab.loop_Tab then UIUtils.SetActive(cellTable.img_RedDot, CTL.Bag.IsPageHasRedpoint(data.pageType)); UIUtils.SetActive(cellTable.img_Arrow, false) UIUtils.SetActive(cellTable.img_ArrowS, false) UIUtils.SetActive(cellTable.group_SignState, false) UIUtils.SetActive(cellTable.group_SignStateS, false) if CTL.Bag.IsBagPageMaxNum(data.pageType) then UIUtils.SetActive(cellTable.group_SignState, true) UIUtils.SetActive(cellTable.group_SignStateS, true) UIUtils.SetLabelText(cellTable.txt_Fire, Const_IDS.IDS_MailFulled) UIUtils.SetLabelText(cellTable.txt_FireS, Const_IDS.IDS_MailFulled) UIUtils.SetActive(cellTable.UIState, true) UIUtils.SetActive(cellTable.UIStateS, true) cellTable.UIState:SetState(3) cellTable.UIStateS:SetState(3) else UIUtils.SetActive(cellTable.group_SignState, false) UIUtils.SetActive(cellTable.group_SignStateS, false) UIUtils.SetActive(cellTable.UIState, false) UIUtils.SetActive(cellTable.UIStateS, false) end UIUtils.SetLabelText(cellTable.txt_Name_Nomal, Const_IDS[data.pageTextId]); UIUtils.SetLabelText(cellTable.txt_Name_Selected, Const_IDS[data.pageTextId]); end end function UIBagMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.LoopScroll then CTL.Sound.PlayGameSound("UI_pieces") if not data.itemData then return; end if data.itemData then MDL.Bag.RemoveOneNewTip(data.itemData.Id) end UIUtils.SetActive(cellTable.item.sprite_New.gameObject,false) --显示信息 UTL.ItemTips.ShowBagTips(data.itemData) elseif scrollRect == self.UICommonPopUpTab.loop_Tab then end end function UIBagMain:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then if self.playSound then CTL.Sound.PlayGameSound("UI_sound_Qieye01"); end CTL.Bag.SetCurrentShowItemType(data.pageType); self:InitBagAllItem(); end end function UIBagMain:OnClosed() MDL.Bag.ClearAllNewTips(); MDL.Bag.ClearBagDisplayData(); EventSystem.Dispatch(EventID.Bag_CloseMain) end return UIBagMain