local UICountryTargetList = UIViewClass() local EventSystem = require('Event/EventSystem') --对应战争状态图标 local BattleModeImg = { [0] ="gjcj_icon_bw", --保卫 [1] ="gjcj_icon_rq",--入侵 [2] ="gjcj_icon_hp",--和平 [3] ="gjcj_icon_zz",--战争 } --对应战争状态短描述 local BattleModeShortIds = { [0] = Const_IDS.IDS_CountryPVP_Mode_Protect,--保卫 [1] = Const_IDS.IDS_CountryPVP_Mode_Invade,--入侵 [2] = Const_IDS.IDS_CountryPVP_Mode_Peace,--和平 [3] = Const_IDS.IDS_CountryPVP_Mode_War,--战争 } --对应战争状态长描述 local BattleModeLongIds = { [0] = Const_IDS.IDS_CountryPVP_Mode_Protect_Info,--保卫 [1] = Const_IDS.IDS_CountryPVP_Mode_Invade_Info,--入侵 [2] = Const_IDS.IDS_CountryPVP_Mode_Peace_Info,--和平 [3] = Const_IDS.IDS_CountryPVP_Mode_War_Info,--战争 } local CountryImg = { [1] = "gy_msz_wei.png", [2] = "gy_msz_shu.png", [3] = "gy_msz_wu.png", [4] = "gy_msz_qun.png", } --region 生命周期方法 function UICountryTargetList:OnCreated() self.obj_state = {} table.insert(self.obj_state,{txt_State = self.txt_State1, txt = self.txt_StateText1,img = self.img_StateIcon1}) table.insert(self.obj_state,{txt_State = self.txt_State2, txt = self.txt_StateText2,img = self.img_StateIcon2}) table.insert(self.obj_state,{txt_State = self.txt_State3, txt = self.txt_StateText3,img = self.img_StateIcon3}) table.insert(self.obj_state,{txt_State = self.txt_State4, txt = self.txt_StateText4,img = self.img_StateIcon4}) self.group_Teammate = {} table.insert(self.group_Teammate,self.cell_PlayerInfo1) table.insert(self.group_Teammate,self.cell_PlayerInfo2) table.insert(self.group_Teammate,self.cell_PlayerInfo3) end function UICountryTargetList:OnOpened(context) self:RegistSystemEvent(EventID.UI_UpdateFriendInfo,self.Init) self:RegistSystemEvent(EventID.Country_OnGetFoundCountry,self.Init) self:RegistSystemEvent(EventID.Country_FoldBattleList,self.FoldBattleList) self:RegistSystemEvent(EventID.Country_UnfoldBattleList,self.UnFoldBattleList) self:RegistSystemEvent(EventID.Country_RefreshBattleList,self.InitBattleList) self:RegistSystemEvent(EventID.Country_HideBattleList,self.HideBattleList) self:RegistSystemEvent(EventID.Country_UICountryTargetListFull,self.ShowTeamInfo) self:RegistSystemEvent(EventID.Country_UICountryTargetListFullNoTeam,self.ShowInfoNoTeam) self.isListForceShow = CTL.CountryPVP.IsShowByActivity() self:Init() end function UICountryTargetList:Init() self.teamAcid = {} UIUtils.SetActive(self.group_TeamInfo,false) self:InitBattleMode() self:InitBattleList() end function UICountryTargetList:OnButtonClicked(comp) if comp == self.btn_check then --点击战斗状态 self.showStateInfo = not self.showStateInfo UIUtils.SetActive(self.group_StateInfo,self.showStateInfo) if self.showStateInfo then UIUtils.SetActive(self.clickBg,true) end elseif comp == self.btn_Unfold or comp == self.event_List then --显示战斗列表 self.isListForceShow = true self:UnFoldBattleList(true) elseif comp == self.btn_Fold then --隐藏战斗列表 self.isListForceShow = false self:UnFoldBattleList(false) elseif comp == self.clickBg then self.showStateInfo = false UIUtils.SetActive(self.group_StateInfo,self.showStateInfo) UIUtils.SetActive(self.clickBg,false) elseif comp == self.btn_FoldTeam then --收起队伍信息 UIUtils.SetActive(self.group_TeamInfo,false) elseif comp == self.btn_Attack then --攻击 self:OnClickAttack() elseif comp == self.cell_PlayerInfo1.btn_PlayerInfo then self:OnClickOpenTeamInfo(self.teamAcid[1]) elseif comp == self.cell_PlayerInfo2.btn_PlayerInfo then self:OnClickOpenTeamInfo(self.teamAcid[2]) elseif comp == self.cell_PlayerInfo3.btn_PlayerInfo then self:OnClickOpenTeamInfo(self.teamAcid[3]) end end function UICountryTargetList:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Info then if target == cellTable.GameObject.UIHeroHead190.img_PlayerAvatarBg then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(data.roleInfo.accid) else self.selectEnemy = data self.selectAcid = data.roleInfo.accid MDL.CountryPVP.CountryPvpListGetTeamInfoReq(data.roleInfo.accid) end end end function UICountryTargetList:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Info then local roleInfo = data.roleInfo UIUtils.SetLabel(cellTable.txt_PlayerName,roleInfo.name) UIUtils.SetLabel(cellTable.txt_Guild,roleInfo.guildName) UIUtils.SetActive(cellTable.img_InTeam, not string.isNilOrEmpty(roleInfo.teamId)) --组队状态 CTL.Character.SetPortraitAndFrame(cellTable.GameObject.UIHeroHead190, roleInfo.portraitId,roleInfo.frameId, roleInfo.level) --国家信息显示 local state = roleInfo.countryId - 1 state = state > 0 and state or 0 cellTable.state_Country:SetState(state) --英语、印尼语显示图 if Localization.IsEnglish() or Localization.IsIndonesian() then UIUtils.SetLocalizationImage(cellTable.img_Country, CountryImg[roleInfo.countryId]) end --战力 UIUtils.SetLabel(cellTable.txt_BR,roleInfo.gs) --性别 UIUtils.SetActive(cellTable.image_Gender,true) CTL.Player.OperateGenderImage(cellTable.image_Gender, roleInfo.sex) --仇敌 UIUtils.SetActive(cellTable.img_Rival,MDL.Friend.IsPlayerRival(roleInfo.accid)) end end --endregion --region 战争状态显示 --战争状态显示 function UICountryTargetList:InitBattleMode() --当前状态 self:ShowCurrentState() --四个状态 for i = 1, 4 do local mode = i-1 self:SetBattleModeImg(self.obj_state[i].img,mode) if mode == MDL.CountryPVP.BattleMode.battle then local startTimeCfgId,endTimeCfgId = MDL.CountryPVP.GetPVPAttackTimeCfgId() local startTime = UTL.Time.GetDiffLocalStrById(startTimeCfgId) local endTime = UTL.Time.GetDiffLocalStrById(endTimeCfgId) UIUtils.SetLabel(self.obj_state[i].txt, string.FormatByIdsId(BattleModeLongIds[mode], startTime.."-"..endTime)) else UIUtils.SetLabelText(self.obj_state[i].txt,BattleModeLongIds[mode]) end UIUtils.SetLabelText(self.obj_state[i].txt_State,BattleModeShortIds[mode]) end self.showStateInfo = false UIUtils.SetActive(self.group_StateInfo,self.showStateInfo) end function UICountryTargetList:ShowCurrentState() --当前状态 local currentMode = MDL.CountryPVP.GetCurrentBattleMode() if self.currentMode == MDL.CountryPVP.BattleMode.peace and currentMode == MDL.CountryPVP.BattleMode.battle then EventSystem.Dispatch(EventID.UI_MainShowYellowTips, UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_NeutralAreaInWar)) end --增加切换提示 if self.currentMode == MDL.CountryPVP.BattleMode.battle and currentMode == MDL.CountryPVP.BattleMode.peace then EventSystem.Dispatch(EventID.UI_MainShowYellowTips, UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_NeutralAreaInPeace)) end self.currentMode = currentMode self:SetBattleModeImg(self.img_State,currentMode) UIUtils.SetLabelText(self.txt_State,BattleModeShortIds[currentMode]) self:ShowBattleTips(currentMode) --中立地图需要刷新 if currentMode == MDL.CountryPVP.BattleMode.peace or currentMode == MDL.CountryPVP.BattleMode.battle then local serverStartTime,serverEndTime = MDL.CountryPVP.GetPVPAttackTime() local currentServerTime = UTL.Time.GetServerTimestamp() local offsetTime = 0 if currentServerTime < serverStartTime then offsetTime = serverStartTime - currentServerTime elseif currentServerTime < serverEndTime then offsetTime = serverEndTime - currentServerTime end if offsetTime > 0 then offsetTime = offsetTime + 3 --延迟3秒 防止不刷新 self:StartRepeatFunc(self.OnRefreshStateFunc,offsetTime,1) end end UIUtils.SetActive(self.clickBg,false) end function UICountryTargetList:ShowBattleTips(currentMode) --无国家信息时,状态不对,不提示 if MDL.Country.GetMyCountryId() == nil then return end if CTL.CountryWantedTask.IsShowBattleTips() then local idsStr; if currentMode == MDL.CountryPVP.BattleMode.peace then --和平 idsStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_EnterNeutralAreaInPeace) elseif currentMode == MDL.CountryPVP.BattleMode.battle then --战争 idsStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_EnterNeutralAreaInWar) elseif currentMode == MDL.CountryPVP.BattleMode.defend then --保卫 idsStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_EnterMyCountry) else --入侵 idsStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_CountryPVP_EnterOtherCountry) end if GameAppInfo.IsJapanesePackage() then --日语这里的文本太长了播放不全,7秒可以 EventSystem.Dispatch(EventID.UI_MainShowYellowTips, idsStr, 7) else EventSystem.Dispatch(EventID.UI_MainShowYellowTips, idsStr) end end end function UICountryTargetList:OnRefreshStateFunc(deltaTime, timeSinceUpdate) EventSystem.Dispatch(EventID.Country_OnGetFoundCountry) end function UICountryTargetList:SetBattleModeImg(img,state) UTL.Item.SetAtlasSprite(img, "UI_Country", BattleModeImg[state]) end --endregion --region 战斗列表 function UICountryTargetList:InitBattleList() if CTL.CountryPVP.IsShowBattleList() then self:HideBattleList(false) else self:HideBattleList(true) end end function UICountryTargetList:HideBattleList(isHide) if isHide then UIUtils.SetActive(self.battlePanel,false) EventSystem.Dispatch(EventID.UI_TownHome_ShowRightMainBtnGroup, true) EventSystem.Dispatch(EventID.UI_ActivityNotice_HideSelf, true) if self.isListForceShow == true then return end self:FoldBattleList() else if CTL.CountryPVP.IsShowBattleList() then UIUtils.SetActive(self.battlePanel,true) if self.isListForceShow then self:UnFoldBattleList(true) else self:UnFoldBattleList(false) end end end end --展开战斗列表 function UICountryTargetList:UnFoldBattleList(isUnfold) EventSystem.Dispatch(EventID.UI_TownHome_ShowRightMainBtnGroup,not isUnfold) EventSystem.Dispatch(EventID.UI_ActivityNotice_HideSelf,not isUnfold) self.state:SetState(isUnfold and 0 or 1) if isUnfold then self:LoadBattleList() end end --收起战斗列表 function UICountryTargetList:FoldBattleList() self:UnFoldBattleList(false) end --加载战斗列表 function UICountryTargetList:LoadBattleList() local result = CTL.CountryPVP.GetBattleList() if result and #result > 0 then self.loop_Info:ReloadAll(result) local selectIndex = 0 if self.selectAcid then for i,v in ipairs(result) do if v.roleInfo.accid == self.selectAcid then selectIndex = i - 1 end end self.loop_Info:SelectIndex(selectIndex) end else EventSystem.Dispatch(EventID.UI_TownHome_ShowRightMainBtnGroup,true) EventSystem.Dispatch(EventID.UI_ActivityNotice_HideSelf,true) end end --endregion --region 组队信息 --显示队伍信息 function UICountryTargetList:ShowTeamInfo(memberInfo) UIUtils.SetActive(self.group_TeamInfo,true) for i, v in ipairs(self.group_Teammate) do local memberData if memberInfo then memberData = memberInfo[i] end if memberData then self.teamAcid[i] = memberData.acid self:RefreshSingleTeamMember(memberData, v) UIUtils.SetActive(self.group_Teammate[i].gameObject,true) else self.teamAcid[i] = "" CTL.Character.SetHeadEmpty(v.PlayerHead.PlayerHead) UIUtils.SetActive(self.group_Teammate[i].gameObject,false) end end self:ShowTeamCountry() end function UICountryTargetList:ShowInfoNoTeam() UIUtils.SetActive(self.group_TeamInfo,true) for i, v in ipairs(self.group_Teammate) do if i == 1 and self.selectEnemy then self.teamAcid[i] = self.selectEnemy.roleInfo.accid self:RefreshSingleInfoNoTeam(self.selectEnemy.roleInfo, v) UIUtils.SetActive(self.group_Teammate[i].gameObject,true) else self.teamAcid[i] = "" CTL.Character.SetHeadEmpty(v.PlayerHead.PlayerHead) UIUtils.SetActive(self.group_Teammate[i].gameObject,false) end end self:ShowTeamCountry() end function UICountryTargetList:ShowTeamCountry() --国家 if self.selectEnemy then --国家信息显示 local state = self.selectEnemy.roleInfo.countryId - 1 state = state > 0 and state or 0 self.state_TeamCountry:SetState(state) end end --单个队员信息 function UICountryTargetList:RefreshSingleTeamMember(data, cell) CTL.Character.SetPortraitAndFrame(cell.PlayerHead.PlayerHead, data.portraitId, data.frameId,data.level) UIUtils.SetLabel(cell.txt_PlayerName,data.name) --是否为仇敌 if data.acid then UIUtils.SetActive(cell.img_Rival,MDL.Friend.IsPlayerRival(data.acid)) else UIUtils.SetActive(cell.img_Rival,false) end --战力 UIUtils.SetLabel(cell.txt_BR,data.gs) --性别 UIUtils.SetActive(cell.image_Gender,true) CTL.Player.OperateGenderImage(cell.image_Gender, data.sex) --工会 UIUtils.SetLabel(cell.txt_GuildName,data.guildName) UIUtils.SetLabel(cell.txt_GuildNameInitiate, data.guildEmblemContent) local guildEmblemCfg = DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame) if guildEmblemCfg then UTL.Item.SetAtlasSprite(cell.img_GuildIcon, "UI_Guild", guildEmblemCfg.Image) end --远离/战斗 local isBattle = data.OfflineBattleMapId > 0 or data.SyncBattleMapId > 0 local isFaraway = CTL.CountryPVP.IsTeammateKeepAwayFrom(data.mapId) if isBattle then --战斗中 UIUtils.SetActive(cell.txt_State,true) UIUtils.SetLabelText(cell.txt_State,Const_IDS.IDS_CountryPVP_Team_Fighting) elseif isFaraway then --远离中 UIUtils.SetActive(cell.txt_State,true) UIUtils.SetLabelText(cell.txt_State,Const_IDS.IDS_CountryPVP_Team_Away) else UIUtils.SetActive(cell.txt_State,false) end if cell.PlayerHead.img_Leader then UIUtils.SetActive(cell.PlayerHead.img_Leader,true) end end --显示没有队伍的成员信息 function UICountryTargetList:RefreshSingleInfoNoTeam(data, cell) CTL.Character.SetPortraitAndFrame(cell.PlayerHead.PlayerHead, data.portraitId, data.frameId,data.level) UIUtils.SetLabel(cell.txt_PlayerName,data.name) --是否为仇敌 UIUtils.SetActive(cell.img_Rival,MDL.Friend.IsPlayerRival(data.accid)) --战力 UIUtils.SetLabel(cell.txt_BR,data.gs) --性别 UIUtils.SetActive(cell.image_Gender,true) CTL.Player.OperateGenderImage(cell.image_Gender, data.sex) --工会 UIUtils.SetLabel(cell.txt_GuildName,data.guildName) UIUtils.SetLabel(cell.txt_GuildNameInitiate, data.guildEmblemContent) local guildEmblemCfg = DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame) if guildEmblemCfg then UTL.Item.SetAtlasSprite(cell.img_GuildIcon, "UI_Guild", guildEmblemCfg.Image) end if cell.PlayerHead.img_Leader then UIUtils.SetActive(cell.PlayerHead.img_Leader,false) end UIUtils.SetActive(cell.txt_State,false) end function UICountryTargetList:OnClickAttack() if self.selectEnemy == nil then return end --是否在战斗中 if self.selectEnemy.roleInfo.isInOfflineBattle or self.selectEnemy.roleInfo.isInSyncBattle then CTL.Tips.AddTipsMsg(Const_IDS.IDS_CountryPVP_JudgeCondition_Fighting) return end --中立地图要在战斗时间内 if CTL.CountryPVP.IsInNeutralityMap() and MDL.CountryPVP.GetCurrentBattleMode() == MDL.CountryPVP.BattleMode.peace then CTL.Tips.AddTipsMsg(Const_IDS.IDS_CountryPVP_JudgeCondition_Offtime) return end MDL.CountryPVP.EnterCountryPvpReq(CTL.CountryPVP.GetPVPMapId(), self.selectEnemy.roleInfo.accid,self.selectEnemy.roleInfo) end function UICountryTargetList:OnClickOpenTeamInfo(acid) if not string.isNilOrEmpty(acid) then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(acid) end end --endregion return UICountryTargetList