local UICountrySalarySend = UIViewClass() local SelectMaxCount = 3 local CountrySpoilJoinLimit = DataSheetManager.ConstData:GetDataByID("CountrySpoilJoinLimit").IntValue local SortAttributes = {"attribution", "JobTitle", "Power", "Lv"} --贡献>职位>战力>等级(玩家点击选择排序的基本顺序) local PrioritySortCondition --玩家点击选择的优先排序条件(每次关闭界面需要清空) function UICountrySalarySend:OnCreated() self.btnToAttr = { [self.group_Details_Player.btn_Contribution] = SortAttributes[1], [self.group_Details_Player.btn_Position] = SortAttributes[2], [self.group_Details_Player.btn_GS] = SortAttributes[3], [self.group_Details_Player.btn_Level] = SortAttributes[4], } end function UICountrySalarySend:OnOpened(context) if context.isGuild then self:InitGuild() else self:InitPlayer() end end function UICountrySalarySend:InitGuild() self.selectGuilds = {} MDL.Country.CountrySalaryTreasureGiveListReq(self.context.rewardId) self:RegistSystemEvent(EventID.Country_OnSalaryTreasureGiveList, self.OnSalaryTreasureGiveList) UIUtils.SetActive(self.group_Details_Guild, true) UIUtils.SetActive(self.group_Details_Player.gameObject, false) local rewardData = DataSheetManager.CountryRewards:GetDataByID(self.context.rewardId) local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.ItemID) --道具名称 local colorText = UTL.Color.FormatQualityText(UTL.Item.GetItemDataSpliceByType(rewardData.ItemID).Name, itemData.Color) self.UICommonPopUp.txt_Title.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GiftChooseTitle, colorText) self.event_Send:SetGray(true, true) end function UICountrySalarySend:InitPlayer() self.selectPlayers = {} self.curMinUpdateTime = 0 MDL.Country.CountrySalaryTreasureAllocationListReq(self.context.rewardId) self:RegistSystemEvent(EventID.Country_OnSalaryTreasureAllocationList, self.OnSalaryTreasureAllocationList) UIUtils.SetActive(self.group_Details_Guild, false) UIUtils.SetActive(self.group_Details_Player.gameObject, true) local rewardData = DataSheetManager.CountryRewards:GetDataByID(self.context.rewardId) local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.ItemID) --道具名称 local colorText = UTL.Color.FormatQualityText(UTL.Item.GetItemDataSpliceByType(rewardData.ItemID).Name, itemData.Color) self.UICommonPopUp.txt_Title.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_PresentChooseTitle, colorText) self.group_Details_Player.event_Share:SetGray(true, true) end local function SortGiveList(a, b) if a.GiveNum == 0 and b.GiveNum == 0 then if a.CountryGuildType ~= b.CountryGuildType then return a.CountryGuildType < b.CountryGuildType else if a.Activeness == b.Activeness then return a.EmblemFrame > b.EmblemFrame else return a.Activeness > b.Activeness end end elseif b.GiveNum == 0 then return false elseif a.GiveNum == 0 then return true else if a.CountryGuildType ~= b.CountryGuildType then return a.CountryGuildType < b.CountryGuildType else if a.Activeness == b.Activeness then return a.EmblemFrame > b.EmblemFrame else return a.Activeness > b.Activeness end end end end function UICountrySalarySend:OnSalaryTreasureGiveList(msg) self.notBindNum = msg.NotBindNum local sortList = {} for i, v in ipairs(msg.GiveItemList) do table.insert(sortList, v) end table.sort(sortList, SortGiveList) self.giveItemList = sortList self.LoopScroll_Guild:ReloadAll(sortList) self.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GuildChooseNum, #self.selectGuilds) self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GiftIntro, msg.NotBindNum) end --打开界面时的排序规则:分配数—上次分配—职位—战力 local function SortByDefaultRule(a, b) if a.AllocationNum == b.AllocationNum then if a.PreAllocation == b.PreAllocation then if a.JobTitle == b.JobTitle then return a.Power > b.Power else return a.JobTitle < b.JobTitle end else return a.PreAllocation end else return a.AllocationNum < b.AllocationNum end end --玩家点击选择排序规则:分配数优先,然后玩家选择优先条件排序 local function SortByPriorityRule(a, b) if a.AllocationNum == b.AllocationNum then if a[PrioritySortCondition] == b[PrioritySortCondition] then for _, v in ipairs(SortAttributes) do if v ~= PrioritySortCondition and a[v] ~= b[v] then if v == SortAttributes[2] then return a[v] < b[v] else return a[v] > b[v] end end end return false else if PrioritySortCondition == SortAttributes[2] then return a[PrioritySortCondition] < b[PrioritySortCondition] else return a[PrioritySortCondition] > b[PrioritySortCondition] end end else return a.AllocationNum < b.AllocationNum end end function UICountrySalarySend:OnSalaryTreasureAllocationList(msg) self.notBindNum = msg.NotBindNum self.bindNum = msg.BindNum local sortList = {} for i, v in ipairs(msg.AllocationItemList) do table.insert(sortList, v) end table.sort(sortList, SortByDefaultRule) self.giveItemList = sortList self.group_Details_Player.LoopScroll_Details:ReloadAll(self.giveItemList) self.group_Details_Player.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_PlayerChooseNum, #self.selectPlayers) self.group_Details_Player.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_PresentIntro, self.bindNum, self.notBindNum) end function UICountrySalarySend:RefreshTabsAndOrderList() UIUtils.SetActive(self.group_Details_Player.icon_Contribution, PrioritySortCondition and PrioritySortCondition == self.btnToAttr[self.group_Details_Player.btn_Contribution] or false) UIUtils.SetActive(self.group_Details_Player.icon_Position, PrioritySortCondition and PrioritySortCondition == self.btnToAttr[self.group_Details_Player.btn_Position]or false) UIUtils.SetActive(self.group_Details_Player.icon_GS, PrioritySortCondition and PrioritySortCondition == self.btnToAttr[self.group_Details_Player.btn_GS] or false) UIUtils.SetActive(self.group_Details_Player.icon_Level, PrioritySortCondition and PrioritySortCondition == self.btnToAttr[self.group_Details_Player.btn_Level] or false) if PrioritySortCondition then table.sort(self.giveItemList, SortByPriorityRule) else table.sort(self.giveItemList, SortByDefaultRule) end self.group_Details_Player.LoopScroll_Details:ReloadAll(self.giveItemList) end function UICountrySalarySend:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.event_Send then if self.notBindNum == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_NoSpoilToGift) else if #self.selectGuilds == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_SelectFirst) else MDL.Country.CountrySalaryTreasureGiveReq(self.context.rewardId, self.selectGuilds) end end elseif comp == self.group_Details_Player.event_Share then if #self.selectPlayers == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_SelectFirst) elseif self.selectNotBind then UTL.MessageBox.ShowOKCancelBox("", Const_IDS.IDS_Stockroom_PresentConfirm, function() MDL.Country.CountrySalaryTreasureAllocationReq(self.context.rewardId, self.selectPlayers) end ) else MDL.Country.CountrySalaryTreasureAllocationReq(self.context.rewardId, self.selectPlayers) end elseif comp == self.group_Details_Player.btn_Contribution or comp == self.group_Details_Player.btn_Position or comp == self.group_Details_Player.btn_GS or comp == self.group_Details_Player.btn_Level then if PrioritySortCondition == self.btnToAttr[comp] then PrioritySortCondition = nil else PrioritySortCondition = self.btnToAttr[comp] end self:RefreshTabsAndOrderList() end end function UICountrySalarySend:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.LoopScroll_Guild then if target == cellTable.btn_Interact then MDL.Country.CountryGetTargetGuildInfoReq(data.GuildID) end else if target == cellTable.btn_Interact then CTL.PlayerInteract.OpenFriendInteractView(data.Acid) end end end function UICountrySalarySend:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.LoopScroll_Guild then self:InitGuildCell(index, cellTable, data) else self:InitPlayerCell(index, cellTable, data) end end function UICountrySalarySend:InitPlayerCell(index, cellTable, data) cellTable.lab_HeroName.text = data.Name cellTable.txt_Position.text = nil UIUtils.SetLabel(cellTable.txt_Level, UTL.Item.GetNobilityByTeamLevel(data.Lv)) cellTable.txt_CE.text = data.Power cellTable.txt_Wcontribution.text = data.attribution local jobData = DataSheetManager.GuildJob:GetDataByID(data.JobTitle) cellTable.txt_Position.text = UIUtils.GetLocalizedTxt(Const_IDS[jobData.JobName]) local canApplyTime = CountrySpoilJoinLimit - (UTL.Time.GetServerTimestamp() - data.JoinGuildTime) cellTable.txt_AfterTime:EndTimer() UIUtils.SetActive(cellTable.img_LastDistribution, data.PreAllocation) if canApplyTime > 0 and CountrySpoilJoinLimit >= canApplyTime then CTL.Country.SetCdTime(cellTable.txt_AfterTime, canApplyTime, Const_IDS.IDS_Stockroom_PresentTimeLimit) if self.curMinUpdateTime == 0 or self.curMinUpdateTime > canApplyTime then self.curMinUpdateTime = canApplyTime self:StartRepeatFunc(self.RefreshPlayers, canApplyTime + 1, 1) end UIUtils.SetActive(cellTable.toggle_Select, false) UIUtils.SetActive(cellTable.img_BlackCover, true) elseif data.AllocationNum > 0 then UIUtils.SetActive(cellTable.toggle_Select, false) UIUtils.SetActive(cellTable.img_GivenBg, true) UIUtils.SetActive(cellTable.img_BlackCover, true) table.removebyvalue(self.selectPlayers, data.Acid) self.group_Details_Player.event_Share:SetGray(#self.selectPlayers == 0, true) else UIUtils.SetActive(cellTable.toggle_Select, true) if table.containValue(self.selectPlayers, data.Acid) then cellTable.toggle_Select.isOn = true else cellTable.toggle_Select.isOn = false end --cellTable.txt_Finish.text = nil UIUtils.SetActive(cellTable.img_GivenBg, false) UIUtils.SetActive(cellTable.img_BlackCover, false) UIUtils.SetActive(cellTable.img_Bg_01, true) end CTL.Character.SetPortraitAndFrame(cellTable.playerHead, data.PortraitId, data.FrameId) end function UICountrySalarySend:InitGuildCell(index, cellTable, data) UTL.Item.SetAtlasSprite(cellTable.img_Emblem, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(data.EmblemFrame).Image) cellTable.txt_Emblem.text = data.EmblemContent cellTable.txt_Name.text = data.GuildName cellTable.txt_Server.text = CTL.CrossServer.GetServerShowStr(data.ServerShowID) cellTable.txt_PlayerName.text = data.GuildLeadName if data.CountryGuildType > 0 then cellTable.txt_Class.text = MDL.Country.GetGuildTitleColorName(data.CountryGuildType) end local activeness = 3 local activenessArray = DataSheetManager.ConstData:GetDataByID("GuildActivityValueRange").IntListValue for i, v in ipairs(activenessArray) do if data.Activeness <= v then activeness = i - 1 break end end UIUtils.SetActive(cellTable.img_Bg_02, false) cellTable.lights:SetState(activeness) if data.GiveNum > 0 then UIUtils.SetActive(cellTable.toggle_Select, false) UIUtils.SetActive(cellTable.img_GivenBg, true) table.removebyvalue(self.selectGuilds, data.GuildID) self.event_Send:SetGray(#self.selectGuilds == 0, true) else UIUtils.SetActive(cellTable.toggle_Select, true) if table.containValue(self.selectGuilds, data.GuildID) then cellTable.toggle_Select.isOn = true else cellTable.toggle_Select.isOn = false end UIUtils.SetActive(cellTable.img_GivenBg, false) UIUtils.SetActive(cellTable.img_BlackCover, false) end end function UICountrySalarySend:OnCellValueChanged(scrollRect, index, cellTable, target, value) if scrollRect == self.LoopScroll_Guild then self:OnGuildCellValueChanged(index, cellTable, target, value) else self:OnPlayerCellValueChanged(index, cellTable, target, value) end end function UICountrySalarySend:OnGuildCellValueChanged(index, cellTable, target, value) if target == cellTable.toggle_Select then local data = self.giveItemList[index + 1] if value == true then if not table.containValue(self.selectGuilds, data.GuildID) then table.insert(self.selectGuilds, data.GuildID) UIUtils.SetActive(cellTable.img_Bg_02, true) if self.notBindNum < #self.selectGuilds then if self.notBindNum == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_NoSpoilToGift) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_ChooseNumLimit) end cellTable.toggle_Select.isOn = false UIUtils.SetActive(cellTable.img_Bg_02, false) return end end else UIUtils.SetActive(cellTable.img_Bg_02, false) table.removebyvalue(self.selectGuilds, data.GuildID) end self.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GuildChooseNum, #self.selectGuilds) self.event_Send:SetGray(#self.selectGuilds == 0, true) end end function UICountrySalarySend:OnPlayerCellValueChanged(index, cellTable, target, value) if target == cellTable.toggle_Select then local data = self.giveItemList[index + 1] if value == true then if not table.containValue(self.selectPlayers, data.Acid) then table.insert(self.selectPlayers, data.Acid) UIUtils.SetActive(cellTable.img_Bg_02, true) if self.bindNum > #self.selectPlayers then self.selectNotBind = false elseif self.bindNum < #self.selectPlayers and self.notBindNum + self.bindNum > #self.selectPlayers then self.selectNotBind = true elseif #self.selectPlayers > self.notBindNum + self.bindNum then if self.notBindNum + self.bindNum == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_NoSpoilToPresent) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_ChooseNumLimit) end cellTable.toggle_Select.isOn = false UIUtils.SetActive(cellTable.img_Bg_02, false) end end else table.removebyvalue(self.selectPlayers, data.Acid) UIUtils.SetActive(cellTable.img_Bg_02, false) end self.group_Details_Player.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_PlayerChooseNum, #self.selectPlayers) self.group_Details_Player.event_Share:SetGray(#self.selectPlayers == 0, true) end end function UICountrySalarySend:RefreshPlayers() self.group_Details_Player.LoopScroll_Details:RefreshCells(false) end function UICountrySalarySend:OnClosed() PrioritySortCondition = nil end return UICountrySalarySend