local UIGuildWarShopPanel = UIViewClass() function UIGuildWarShopPanel:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_GuildWar_GuildWarBattleShop) self.txt_IngotNum.text = 0 self.products = {} for i,v in DataSheetManager.GuildWarBattleShop:GetEnumerator() do self.LoopScroll_Buy:AddData(v,0) end if not BattleDataGetter.IsGuildWarWaitingArea() then MDL.GuildWar.C2GGetGuildWarProductReq() self:RegistSystemEvent(EventID.UI_GuildWarResourcesShopUpdate,self.OnResourcesUpdate) self.timeHandles = {} end self.txt_level.text = 1 self:StartRepeatFunc(self.OnUpdateFun, 1) end function UIGuildWarShopPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIGuildWarShopPanel:OnButtonClicked(comp) if self.UICommonPopUp.btn_Close == comp or self.Bottom == comp then self:CloseView() end end function UIGuildWarShopPanel:OnResourcesUpdate(msg) self.products = msg.product or 0 self.LoopScroll_Buy:RefreshCells() self.txt_IngotNum.text = msg.resources self.resources = msg.resources local data = DataSheetManager.GuildWarBattleLevel:GetDataByID(msg.level > 0 and msg.level or 1) local _, nextData = DataSheetManager.GuildWarBattleLevel:TryGetDataByID(msg.level + 1) if nextData then self.txt_Num.text = string.FormatByIdsId(Const_IDS.IDS_GuildWar_ShopLevelSigh2, msg.levelExp, nextData.Exp) else self.txt_Num.text = nil end self.txt_level.text = msg.level end function UIGuildWarShopPanel:GetDataById(id) for i,v in ipairs(self.products) do if v.productId == id then return v end end end function UIGuildWarShopPanel:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetImageByAssetBundle(cellTable.img_Buff,ConstAssetPathConfig.Path29..data.Icon..".png") UIUtils.SetLabelText(cellTable.txt_BuffName, Const_IDS[data.Name]) local info = self:GetDataById(data.ID) local count = 0 if info then local coolDownEndTime = info.coolDownEndTime - UTL.Time.GetServerTimestamp() if coolDownEndTime > 0 then cellTable.img_IngotBg.gameObject:SetActive(false) cellTable.btn_Buy.gameObject:SetActive(false) cellTable.txt_Time:ResetAndBeginCustomTimer(false, coolDownEndTime,0,"{0}:{1}") self.index = index self:StartRepeatFunc(self.DelayUpdateIndex, coolDownEndTime, 1) else cellTable.img_IngotBg.gameObject:SetActive(true) cellTable.btn_Buy.gameObject:SetActive(true) cellTable.txt_Time:EndTimer() end count = info.level else cellTable.img_IngotBg.gameObject:SetActive(true) cellTable.btn_Buy.gameObject:SetActive(true) cellTable.txt_Time:EndTimer() end if data.MaxNum>0 then cellTable.txt_Info03.text = "("..count.."/"..data.MaxNum..")" else cellTable.txt_Info03.text = nil end if count > 0 and count == data.MaxNum then cellTable.img_IngotBg.gameObject:SetActive(false) cellTable.btn_Buy.gameObject:SetActive(false) cellTable.txt_Info01.text = string.FormatByIdsId(Const_IDS[data.Desc2],data.Param * data.MaxNum) UIUtils.SetLabelText(cellTable.txt_Max, Const_IDS.IDS_GuildWarBattleShop_AlreadyLevelMax) else if data.Cooldown > 0 then UIUtils.SetLabelText(cellTable.txt_Info01, Const_IDS[data.Desc1]) cellTable.txt_Max.text = nil cellTable.btn_Buy:SetText(Const_IDS.IDS_GuildWarBattleShop_ActiveBtn) else cellTable.txt_Info01.text = string.FormatByIdsId(Const_IDS[data.Desc1],data.Param * count,data.Param * (count+1)) cellTable.txt_Max.text = nil cellTable.btn_Buy:SetText(Const_IDS.IDS_GuildWarBattleShop_LevelUpBtn) end count = count == 0 and 1 or (count + 1) local costCount = data.cost[count] cellTable.txt_IngotNum.text = costCount if data.BattleLevelExp[count] > 0 then cellTable.txt_experience.text = string.FormatByIdsId(Const_IDS.IDS_GuildWar_ShopLevelSigh3, data.BattleLevelExp[count]) else cellTable.txt_experience.text = nil end end end function UIGuildWarShopPanel:DelayUpdateIndex() self.LoopScroll_Buy:UpdateIndex(self.index) end function UIGuildWarShopPanel:OnCellClicked(scrollRect, index, cellTable, target, data) local info = self:GetDataById(data.ID) local level = info and info.level or 0 local costCount = data.cost[level + 1] if target == cellTable.btn_Buy then if BattleDataGetter.IsGuildWarWaitingArea() then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildWarInReadyScene) elseif self.resources < costCount then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildWarBattleShop_SourceNotEnough) elseif not MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildWarCommander) then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail4) else local idsStr = Const_IDS.IDS_GuildWarBattleShop_LevelUpConfirm if data.Cooldown > 0 then idsStr = Const_IDS.IDS_GuildWarBattleShop_ActiveConfirm end local str = string.FormatByIdsId(idsStr,cellTable.txt_BuffName.text) UTL.MessageBox.ShowOKCancelBox(nil, str, function () MDL.GuildWar.GuildWarReduceResourceReq(data.ID,level) end,nil) end end end function UIGuildWarShopPanel:OnUpdateFun(deltaTime, timeSinceUpdate) MDL.GuildWar.C2GGetGuildWarProductReq() end return UIGuildWarShopPanel