local UIGuildContribute = UIViewClass() function UIGuildContribute:OnOpened(context) for i,v in DataSheetManager.GuildDonate:GetEnumerator() do self.loop_Contribute:AddData(v,0) end self:RegistSystemEvent(EventID.UI_Guild_DonateRankRefresh, self.OnUpdateListInfo) self:RegistSystemEvent(EventID.UI_Guild_DonateEvent, self.DonateEvent) --self:RegistSystemEvent(EventID.UI_Guild_SelfInfoRefresh, self.SetDonateCount) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshCost) MDL.Guild.GuildDonateRankReq() self.curShowTDValue = true self.enoughCout = true --self:SetDonateCount() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title,Const_IDS.IDS_Guild_Donate) end function UIGuildContribute:OnUpdateListInfo( list ) self.rankList = list self:ShowRank(self.rankList) end function UIGuildContribute:RefreshCost() self.loop_Contribute:RefreshCells() end function UIGuildContribute:SetDonateCount() local length = DataSheetManager.ConstData:GetDataByID("GuildDonateDailyNum").IntValue local countStr = MDL.Guild.GetMyGuildInfo().contributeCount self.enoughCout = countStr > 0 if countStr == 0 then countStr = UTL.Color.FormatRedColor(countStr) else countStr = UTL.Color.FormatGreenColor(countStr) end self.txt_TodayContribute.text = string.FormatByIdsId(Const_IDS.IDS_GuildDonate_DailyNum, countStr,length) end function UIGuildContribute:ShowRank() self:GetSortList(self.rankList) self.loopScroll_Contribute:ClearCells() if #self.rankList == 0 then self.group_Empty01.gameObject:SetActive(true) self.group_Own.gameObject:SetActive(true) self:SetSelfInfo(nil) else local selfData = nil self.group_Empty01.gameObject:SetActive(false) self.group_Own.gameObject:SetActive(true) local length = DataSheetManager.ConstData:GetDataByID("GuildDonateRankShow").IntValue for i,v in ipairs(self.rankList) do if length >= i then if self.curShowTDValue then if v.todayDonateValue > 0 then self.loopScroll_Contribute:AddData(v,0) else break end else self.loopScroll_Contribute:AddData(v,0) end end if v.roleName == BattleDataGetter.GetPlayerName() then selfData = {index = i , data = v} end end if self.loopScroll_Contribute.Count == 0 then self.group_Empty01.gameObject:SetActive(true) end self:SetSelfInfo(selfData) end end function UIGuildContribute:GetSortList(list) if self.curShowTDValue then table.sort(list, function (a, b) if a.todayDonateValue == b.todayDonateValue then return a.lastDonateTime < b.lastDonateTime else return a.todayDonateValue > b.todayDonateValue end end ) else table.sort(list, function (a, b) if a.historyDonateValue == b.historyDonateValue then return a.lastDonateTime < b.lastDonateTime else return a.historyDonateValue > b.historyDonateValue end end ) end end function UIGuildContribute:SetSelfInfo(data) if data == nil then UIUtils.SetActive(self.txt_Name, false) self.sprite_Rank.gameObject:SetActive(false) self.txt_Score.text = nil UIUtils.SetLabelText(self.empty_Lab, Const_IDS.IDS_GuildDonate_PlayerNotDonate) return end self.empty_Lab.text = nil UIUtils.SetActive(self.txt_Name, true) if data.index <= 3 then UTL.Item.SetAtlasSprite(self.sprite_Rank, "UI_Battle", "bd_zs_0"..data.index) self.sprite_Rank.gameObject:SetActive(true) self.txt_Rank.text = nil else self.sprite_Rank.gameObject:SetActive(false) self.txt_Rank.text = data.index end self.txt_Name.text = BattleDataGetter.GetPlayerName() if self.curShowTDValue then self.txt_Score.text = data.data.todayDonateValue else self.txt_Score.text = data.data.historyDonateValue end end function UIGuildContribute:OnValueChanged(comp, index) if comp == self.toggle_TopGroup then if index == 0 then self.curShowTDValue = true self:ShowRank() elseif index == 1 then self.curShowTDValue = false self:ShowRank() end end end function UIGuildContribute:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIGuildContribute:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UIGuildContribute:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Contribute then self:InitContributeCell(cellTable,data, index) elseif scrollRect == self.loopScroll_Contribute then self:InitRankCell(cellTable,data, index) end end function UIGuildContribute:InitRankCell(cellTable,data, index) local state = index%2 UIUtils.SetActive(cellTable.sprite_Bg1.gameObject, state == 0) UIUtils.SetActive(cellTable.sprite_Bg2.gameObject, state == 1) if index <= 2 then UTL.Item.SetAtlasSprite(cellTable.sprite_Rank, "UI_Battle", "bd_zs_0"..index+1) UIUtils.SetActive(cellTable.sprite_Rank.gameObject, true) cellTable.txt_Rank.text = nil else UIUtils.SetActive(cellTable.sprite_Rank.gameObject, false) cellTable.txt_Rank.text = index + 1 end cellTable.txt_Name.text = data.roleName if self.curShowTDValue then cellTable.txt_Score.text = data.todayDonateValue else cellTable.txt_Score.text = data.historyDonateValue end end function UIGuildContribute:InitContributeCell(cellTable,data, index) UTL.Item.SetItemCell(cellTable.Item, data.DonateItemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(data.DonateItemId) cellTable.txt_ItemName.text = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[goodsItem.Name]), goodsItem.Color) --UIUtils.SetLabelText(cellTable.txt_ItemName,Const_IDS[goodsItem.Name]) local reward = DataSheetManager.GuildDonateReward:GetDataByID(data.Reward) for i,v in ipairs(reward.Item_Table) do UTL.Item.ItemIconWithoutBg(cellTable.rewards[i].icon_Get, v.ItemID) cellTable.rewards[i].txt_Cost.text = "+"..v.ItemNum local itemData = DataSheetManager.ItemData:GetDataByID(v.ItemID) UIUtils.SetLabelText(cellTable.rewards[i].txt_Name,Const_IDS[itemData.Name]) end local count = MDL.Bag.GetItemCount(data.DonateItemId) if count == 0 then cellTable.txt_ItemNum.text = string.FormatByIdsId(Const_IDS.IDS_GuildDonate_ItemNum, UTL.Color.FormatRedColor(count)) else cellTable.txt_ItemNum.text = string.FormatByIdsId(Const_IDS.IDS_GuildDonate_ItemNum, UTL.Color.FormatGreenColor(count)) end end function UIGuildContribute:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Contribute then if target == cellTable.Item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.DonateItemId) elseif target == cellTable.btn_Create then if self.enoughCout then local count = MDL.Bag.GetItemCount(data.DonateItemId) if count == 0 then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1011_InfoCode_Item_Not_Enough) --CTL.Tips.AddTipsMsg("功能跳转方案未定 找策划") elseif count == 1 then MDL.Guild.GuildDonateReq(data.ID,count) else --弹出捐献窗口 UIManager.OpenView(Const_UI_Lua.UIEnum.UIUseItemPop, { EventParamId = data.ID, ItemId = data.DonateItemId, TitleIDS = Const_IDS.IDS_Guild_Donate,TipIDS = Const_IDS.IDS_GuildDonate_ChooseDonateNum, BtnIDS = Const_IDS.IDS_Guild_DonateBtn, BuyEvent = EventID.UI_Guild_DonateEvent}) end else CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildDonate_DailyNumLimit) end end end end function UIGuildContribute:DonateEvent(id,useCount) MDL.Guild.GuildDonateReq(id,useCount) end return UIGuildContribute