local UIChangAnSiegeBattleArray = UIViewClass() local SiegeCityBuildPeople = DataSheetManager.ConstData:GetDataByID("SiegeCityBuildPeople").IntValue function UIChangAnSiegeBattleArray:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_SiegeCity_AdjustHelp_Title) self:RegistSystemEvent(EventID.UI_ChangePlayerSeat, self.ChangePlayerSeat) self:RegistSystemEvent(EventID.ChangAnSiege_StageChanged, self.OnStageChanged) self.scrollToCountry = {} self.isDefence = context.defendSituation.countryId == MDL.Country.GetMyCountryId() if self.isDefence then self.state_Info:SetState(1) self.defenceCountryIds = {} for i = 1, 4 do if i ~= context.defendSituation.countryId then table.insert(self.defenceCountryIds, i) end end for i, v in ipairs(self.defenceCountryIds) do self:SetCountryView(self.group_Defend[i], v) end self:SetCountryView(self.group_Defend[4], 99) table.insert(self.defenceCountryIds, 99) else self.state_Info:SetState(0) self:SetCountryView(self.group_Main, MDL.Country.GetMyCountryId()) self:SetCountryView(self.group_Sub, 99) self.defenceCountryIds = { MDL.Country.GetMyCountryId(), 99 } end self.selectPlayerInfo = nil self:OnStageChanged() UIUtils.SetActive(self.UICommonPopUp.img_Info, true) end function UIChangAnSiegeBattleArray:OnStageChanged() self.selectCell = nil if MDL.ChangAnSiege.GetCurStage() == MDL.ChangAnSiege.SiegeCitySeasonStage.Register then UIUtils.SetLabelText(self.lab_Notice_2, Const_IDS.IDS_SiegeCity_BattleField_AdjustTips_1) else UIUtils.SetLabelText(self.lab_Notice_2, Const_IDS.IDS_SiegeCity_BattleField_AdjustTips_6) end end function UIChangAnSiegeBattleArray:ChangePlayerSeat(members) logging.log(LTAG.LOG, "ChangePlayerSeat", members) self.context.members = members if self.isDefence then for i, v in ipairs(self.defenceCountryIds) do self:SetCountryView(self.group_Defend[i], v, true) end self:SetCountryView(self.group_Defend[4], 99, true) else self:SetCountryView(self.group_Main, MDL.Country.GetMyCountryId(), true) self:SetCountryView(self.group_Sub, 99, true) end end function UIChangAnSiegeBattleArray:SetTitleText(collection, members, countryId) collection.lab_Title.text = MDL.ChangAnSiege.GetCountryTabDesc(countryId, self.isDefence) local num = #members if MDL.ChangAnSiege.IsSecondBattlefield(countryId) then collection.txt_Num.text = MDL.ChangAnSiege.GetMembersFormatStr(num) else collection.txt_Num.text = MDL.ChangAnSiege.GetMembersFormatStr(num, MDL.ChangAnSiege.GetMainCityMemberCount()) end end function UIChangAnSiegeBattleArray:SetCountryView(collection, countryId, isRefresh) local members = nil for i, v in ipairs(self.context.members) do if v.countryId == countryId then members = v.members end end if isRefresh then self:UpdatePlayerScrollView(collection, members, countryId) else self:SetPlayerScrollView(collection, members, countryId) end self:SetTitleText(collection, members, countryId) end function UIChangAnSiegeBattleArray:UpdatePlayerScrollView(collection, members, countryId) if MDL.ChangAnSiege.IsSecondBattlefield(countryId) then collection.scroll_Country:ClearCells() for i, v in ipairs(members) do collection.scroll_Country:AddData(v, 0) end collection.scroll_Country:AddData(nil, 0) else for i = 1, MDL.ChangAnSiege.GetMainCityMemberCount() do collection.scroll_Country:UpdateIndex(i - 1, members[i]) end end end function UIChangAnSiegeBattleArray:SetPlayerScrollView(collection, members, countryId) self.scrollToCountry[collection.scroll_Country] = countryId if MDL.ChangAnSiege.IsSecondBattlefield(countryId) then for i, v in ipairs(members) do collection.scroll_Country:AddData(v, 0) end collection.scroll_Country:AddData(nil, 0) else for i = 1, MDL.ChangAnSiege.GetMainCityMemberCount() do collection.scroll_Country:AddData(members[i], 0) end end end function UIChangAnSiegeBattleArray:OnClosed() UIUtils.SetActive(self.UICommonPopUp.img_Info, false) end function UIChangAnSiegeBattleArray:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIChangAnSiegeBattleArray:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.UICommonPopUp.img_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.SiegeCityAdjust }) end end function UIChangAnSiegeBattleArray:OnCellInit(scrollRect, index, cellTable, data) local playerInfo = data if playerInfo then cellTable.txt_Name.text = playerInfo.name cellTable.txt_BR.text = playerInfo.gs UIUtils.SetActive(cellTable.player_Group, true) if self.scrollToCountry[scrollRect] ~= 99 then UIUtils.SetActive(cellTable.img_Captain, index < SiegeCityBuildPeople or CTL.ChangAnSiege.IsLeaderByJobId(playerInfo.officialJob)) else UIUtils.SetActive(cellTable.img_Captain, false) end CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead, playerInfo.portraitId, playerInfo.frameId) cellTable.txt_Empty.text = nil if data.acid == BattleDataGetter.GetAcID() then cellTable.txt_Name.text = UTL.Color.FormatGreenColor(playerInfo.name) else cellTable.txt_Name.text = UTL.Color.FormatWhiteColor(playerInfo.name) end else cellTable.txt_Name.text = nil cellTable.txt_BR.text = nil UIUtils.SetLabelText(cellTable.txt_Empty, Const_IDS.IDS_SiegeCity_BattleField_NullPosition) UIUtils.SetActive(cellTable.player_Group, false) UIUtils.SetActive(cellTable.img_Captain, false) end if not self.isDefence then UIUtils.SetActive(cellTable.img_CellBg1, math.floor(index / 2)%2 == 0) UIUtils.SetActive(cellTable.img_CellBg2, math.floor(index / 2)%2 == 1) else UIUtils.SetActive(cellTable.img_CellBg1, index % 2 == 0) UIUtils.SetActive(cellTable.img_CellBg2, index % 2 == 1) end if data and self.selectPlayerInfo and self.selectPlayerInfo.acid == data.acid then UIUtils.SetActive(cellTable.img_Select, true) else UIUtils.SetActive(cellTable.img_Select, false) end end function UIChangAnSiegeBattleArray:OnCellClicked(scrollRect, index, cellTable, target, data) if MDL.ChangAnSiege.GetCurStage() ~= MDL.ChangAnSiege.SiegeCitySeasonStage.Register then CTL.Tips.AddTipsMsg(Const_IDS.IDS_SiegeCity_BattleField_AdjustTips_6) return end if self.selectPlayerInfo == nil and data then self.selectPlayerInfo = data UIUtils.SetActive(cellTable.img_Select, true) self.selectCountryId = self.scrollToCountry[scrollRect] self.selectCell = cellTable elseif self.selectPlayerInfo == data then UIUtils.SetActive(cellTable.img_Select, false) self.selectPlayerInfo = nil self.selectCountryId = nil if data == nil then CTL.Tips.AddTipsMsg(Const_IDS.IDS_SiegeCity_BattleField_AdjustTips_2) end else local destCountryId = self.scrollToCountry[scrollRect] local playerId2 = nil if data then playerId2 = data.acid end MDL.ChangAnSiege.ChangePlayerSeatReq(self.selectPlayerInfo.acid, self.selectCountryId, playerId2, self.scrollToCountry[scrollRect]) self.selectPlayerInfo = nil self.selectCountryId = nil end end return UIChangAnSiegeBattleArray