local UIChangAnSiegeBattle = UIViewClass() local SiegeCityMBFGateBLood = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFGateBLood").IntValue --主战场城门血量 local SiegeCityMBFGateBLood1 = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFBossBLood1").IntValue --主战场二阶段中央雕像(君主)血量 local SiegeCityMBFGateBLood2 = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFBossBLood2").IntValue --主战场二阶段左侧雕像(大司马)血量 local SiegeCityMBFGateBLood3 = DataSheetManager.ConstData:GetDataByID("SiegeCityMBFBossBLood3").IntValue --主战场二阶段右侧雕像(大司空)血量 local EventSystem = require('Event/EventSystem') local WAIT_TIME_REMAIN_WARN = 5 local CommandMsgAttackIDS = { "IDS_SiegeCity_Command5", "IDS_SiegeCity_Command2", "IDS_SiegeCity_Command3", "IDS_SiegeCity_Command9", "IDS_SiegeCity_Command6", "IDS_SiegeCity_Command8", "IDS_SiegeCity_Command7", } local CommandMsgDefendIDS = { "IDS_SiegeCity_Command15", "IDS_SiegeCity_Command12", "IDS_SiegeCity_Command13", "IDS_SiegeCity_Command19", "IDS_SiegeCity_Command16", "IDS_SiegeCity_Command18", "IDS_SiegeCity_Command17", } local CommandItemEnum = MDL.ChangAnSiege.CommandItemEnum function UIChangAnSiegeBattle:OnOpened(context) self:RegistSystemEvent(EventID.UI_ChangAnSiege_PushSiegeCityInfo, self.OnPushSiegeCityInfo) self:RegistSystemEvent(EventID.CityWar_HeroDead, self.OnHeroKillHero) self:RegistSystemEvent(EventID.UI_ChangAnSiege_BuildRedPoint, self.OnRefreshBuildRedPoint) self:RegistSystemEvent(EventID.UI_Interact_Show , self.ShowInteractUI) self.killInfoNoticeViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleKillInfoNotice), {compareCamp = true}) if BattleDataGetter.IsCityWarSideLevel() then UIUtils.SetLabelText(self.lab_Fight, Const_IDS.IDS_SiegeCity_InABF_Data_5) elseif CTL.ChangAnSiege.IsDefendCamp() then UIUtils.SetLabelText(self.lab_Fight, Const_IDS.IDS_SiegeCity_InMBF_Data_3) else UIUtils.SetLabelText(self.lab_Fight, Const_IDS.IDS_SiegeCity_InMBF_Data_2) end if BattleDataGetter.IsCityWarFirstStage() or BattleDataGetter.IsSyncCityWarMainWaitingArea() then UIUtils.SetActive(self.group_CityHp, true) UIUtils.SetActive(self.group_BossHp.gameObject, false) UIUtils.SetActive(self.btn_Build.gameObject, true) self:UpdateCityWallHp(SiegeCityMBFGateBLood) elseif BattleDataGetter.IsCityWarSecondStage() then UIUtils.SetActive(self.group_CityHp, false) UIUtils.SetActive(self.group_BossHp.gameObject, true) UIUtils.SetActive(self.btn_Build.gameObject, false) self:UpdateStatueHp(SiegeCityMBFGateBLood1, SiegeCityMBFGateBLood1, self.group_BossHp[1]) self:UpdateStatueHp(SiegeCityMBFGateBLood2, SiegeCityMBFGateBLood2, self.group_BossHp[2]) self:UpdateStatueHp(SiegeCityMBFGateBLood3, SiegeCityMBFGateBLood3, self.group_BossHp[3]) else UIUtils.SetActive(self.group_CityHp, false) UIUtils.SetActive(self.group_BossHp.gameObject, false) UIUtils.SetActive(self.btn_Build.gameObject, false) end UIUtils.SetActive(self.ready_Group, BattleDataGetter.IsCityWarWaitingLevel()) if BattleDataGetter.IsCityWarWaitingLevel() then self.txt_Info:SetText(UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_ReadyStage_Tip_1)) end self:OnUpdateFun() self:StartRepeatFunc(self.OnUpdateFun, 1) self.txt_All.text = 0 self.txt_Fight.text = 0 self.txt_kill.text = 0 self.txt_Assist.text = 0 local isSideLevel = BattleDataGetter.IsSyncCityWarSideWaitingArea() or BattleDataGetter.IsCityWarSideLevel() if not isSideLevel then self:RegistSystemEvent(EventID.SDK_OnVoiceRoomStateChange, self.RefreshVoiceUI) if CTL.VoiceRoom.IsInVoiceRoom(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege) then self:RefreshVoiceUI() else if MDL.ChangAnSiege.GetChatChannel() == nil then MDL.ChangAnSiege.GetRoomChatInfoReq() else MDL.VoiceRoom.VoiceCallStateReq(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege) end end UIUtils.SetActive(self.event_OpenMic, MDL.ChangAnSiege.IsBattleLeader() or false) else UIUtils.SetActive(self.event_ListenIn, false) UIUtils.SetActive(self.event_OpenMic, false) if MDL.ChangAnSiege.GetChatChannel() == nil then MDL.ChangAnSiege.GetRoomChatInfoReq() end end UIUtils.SetActive(self.group_BattleInfo, not BattleDataGetter.IsCityWarWaitingLevel()) self:RefreshKillInfo() self:RefreshCommandMsg() self:RefreshCommandRedPoint() end function UIChangAnSiegeBattle:RefreshCommandMsg() UIUtils.SetActive(self.CommandMsg.gameObject, false) UIUtils.SetActive(self.btn_Mask, false) if BattleDataGetter.IsCityWarSideLevel() or BattleDataGetter.IsSyncCityWarSideWaitingArea() then UIUtils.SetActive(self.btn_Command, false) else UIUtils.SetActive(self.btn_Command, true) end end function UIChangAnSiegeBattle:RefreshContribution() local info = BattleDataGetter.GetMyCityWarScoreInfo() self.txt_All.text = math.floor(info.killScore + info.assistScore + info.otherScore) self.txt_Fight.text = math.floor(info.otherScore) end function UIChangAnSiegeBattle:RefreshKillInfo() self.txt_kill.text = BattleDataGetter.GetCityWarTotalKillNum(LevelPlayerManager.MyPlayerIDInRoom) or 0 self.txt_Assist.text = BattleDataGetter.GetCityWarAssistKillNum(LevelPlayerManager.MyPlayerIDInRoom) or 0 end function UIChangAnSiegeBattle:OnPushSiegeCityInfo(info) if BattleDataGetter.IsCityWarFirstStage() then self:UpdateCityWallHp(info.hp) elseif BattleDataGetter.IsCityWarSecondStage() then self:UpdateAllStatueHp(info.statueHps) end end function UIChangAnSiegeBattle:UpdateCityWallHp(hp) local maxValue = SiegeCityMBFGateBLood local curValue = hp UIUtils.SetLabel(self.txt_Hp, string.FormatByIdsId(Const_IDS.IDS_SiegeCity_InMBF_DataDetail_10, curValue, maxValue)) self.img_CityHp.fillAmount = curValue / maxValue end function UIChangAnSiegeBattle:UpdateAllStatueHp(statueHps) for i, v in ipairs(statueHps) do self:UpdateStatueHp(v.statueHp, v.statueMaxHp, self.group_BossHp[v.id]) end end function UIChangAnSiegeBattle:UpdateStatueHp(hp, maxHp, collection) local value = math.getPreciseDecimal(hp / maxHp, 3) collection.sprite_HpFg_Show1.fillAmount = value collection.hpValue.text = (value * 100) .. "%" end function UIChangAnSiegeBattle:OnButtonClicked(comp) if comp == self.btn_Build then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeConstruct) elseif comp == self.btn_detail then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeBattlefieldDataPanel) elseif comp == self.event_ListenIn then --收听 local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() listen = not listen MDL.VoiceRoom.VoiceCallSetStateReq(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege, call, listen) if listen then CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_Listening"]) CTL.Sound.PlayGameSound("UI_voice_system") else CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_NotListening"]) CTL.Sound.PlayGameSound("UI_invalid") end elseif comp == self.event_OpenMic then --麦克风 local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() call = not call MDL.VoiceRoom.VoiceCallSetStateReq(MDL.VoiceRoom.VoiceRoomType.ChangAnSiege, call, listen) if call then CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_NotSpeakingBtn"]) CTL.Sound.PlayGameSound("UI_voice_system") else CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_SpeakingBtn"]) CTL.Sound.PlayGameSound("UI_invalid") end elseif comp == self.btn_Command then if BattleDataGetter.IsCityWarWaitingLevel() then self:OpenCommand() elseif BattleDataGetter.GetMyPlayerInfo().siegeCityCanBuild then self:OpenCommand() if CTL.ChangAnSiege.commandRedPoint then CTL.ChangAnSiege.commandRedPoint = false self:RefreshCommandRedPoint() end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_SiegeCity_Command4"]) end elseif comp == self.btn_Mask then UIUtils.SetActive(self.CommandMsg.gameObject, false) UIUtils.SetActive(self.btn_Mask, false) else for i, v in ipairs(self.CommandMsg) do if v.btn_Click == comp then self:OnClickedCommand(i) break end end end end function UIChangAnSiegeBattle:OnUpdateFun(deltaTime, timeSinceUpdate) if BattleDataGetter.IsCityWarWaitingLevel() then self:OnUpdateWait() else self:OnUpdateBattle() end end function UIChangAnSiegeBattle:OnUpdateBattle() local curTimer if BattleDataGetter.IsCityWarFirstStage() then curTimer = BattleDataGetter.GetBattleEndTime() - UTL.Time.GetServerTimestamp() if curTimer < 0 then curTimer = 0 end else curTimer = BattleDataGetter.GetRemainTime() end UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(curTimer)) self:RefreshContribution() end function UIChangAnSiegeBattle:OnUpdateWait() local endTime = MDL.ChangAnSiege.GetStageTime(MDL.ChangAnSiege.SiegeCitySeasonStage.Preparation).endTime local offset = endTime - UTL.Time.GetServerTimestamp() UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(offset)) if offset > 0 and offset <= WAIT_TIME_REMAIN_WARN and not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel, { offset }) end end function UIChangAnSiegeBattle:OnHeroKillHero(killer, deadEntity, deadComboKill) logging.log(LTAG.LOG, " UIChangAnSiegeBattle:OnHeroKillHero ") local deadPlayerID = deadEntity:GetPlayerID() if not killer then --好像有些情况关卡会杀Hero,且这种情况下KillerEntity为空,所以这里要判空 return end local originKiller = killer:GetOriginEntity() if originKiller:IsHero() then local killerPlayerID = originKiller:GetPlayerID() local killerName = LevelPlayerManager.GetPlayerName(killerPlayerID) local guildIdA = originKiller:GetCampID() local killNums = 0 local heroIDA = originKiller:GetCharacterID() local playerNameB = LevelPlayerManager.GetPlayerName(deadPlayerID) local guildIdB = deadEntity:GetCampID() local heroIDB = deadEntity:GetCharacterID() local info = { killNums = killNums, firstBlood = 0, playerNameA = killerName, guildIdA = guildIdA, playerNameB = playerNameB, guildIdB = guildIdB, playerHeroIdA = heroIDA, playerHeroIdB = heroIDB, killNumsB = 0, playerIdA = killerPlayerID, playerIdB = deadPlayerID } --A 是杀人者 ,B是被杀者 EventSystem.Dispatch(EventID.SyncBattle_KillInfoNotice, info) end self:RefreshKillInfo() self:RefreshContribution() end function UIChangAnSiegeBattle:RefreshVoiceUI() UIUtils.SetActive(self.group_Right, true) local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() self.img_ListenIn:SetState(listen and 1 or 0) self.img_OpenMic:SetState(call and 1 or 0) end function UIChangAnSiegeBattle:OnClickedCommand(index) if BattleDataGetter.IsCityWarWaitingLevel() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_SiegeCity_Command14"]) return end self:SendCommand(index) end function UIChangAnSiegeBattle:SendCommand(index) UIUtils.SetActive(self.CommandMsg.gameObject, false) UIUtils.SetActive(self.btn_Mask, false) local value = CTL.ChangAnSiege.GetCommandStrByIndex(index) if value == false then if index == CommandItemEnum.GuardElite then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_3720_InfoCode_SiegeCity_NoBoss) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_SiegeCity_Command14) end else MDL.ChangAnSiege.SiegeCommandTipsReq(value, index) end end function UIChangAnSiegeBattle:OpenCommand() self:InitCommandStr() UIUtils.SetActive(self.CommandMsg.gameObject, true) UIUtils.SetActive(self.btn_Mask, true) end function UIChangAnSiegeBattle:InitCommandStr() for i, v in ipairs(self.CommandMsg) do v.txt_Words.text = CTL.ChangAnSiege.GetCommandBtnTextByIndex(i) end UIUtils.SetActive(self.CommandMsg[CommandItemEnum.DriverCrushCar].gameObject, not MDL.ChangAnSiege.IsDefendCountry()) UIUtils.SetActive(self.CommandMsg[CommandItemEnum.GuardElite].gameObject, not MDL.ChangAnSiege.IsDefendCountry()) if not MDL.ChangAnSiege.IsDefendCountry() then if not BattleDataGetter.GetCityWarDefendBossIsDead() and BattleDataGetter.IsCityWarFirstStage() then self.CommandMsg[CommandItemEnum.GuardElite].effect:PlayUIEffect() else self.CommandMsg[CommandItemEnum.GuardElite].effect:StopUIEffect() end end end function UIChangAnSiegeBattle:OnRefreshBuildRedPoint(value) if self.curBuildRp ~= value then UIUtils.SetActive(self.buildRedPoint, value or false) self.curBuildRp = value end end function UIChangAnSiegeBattle:RefreshCommandRedPoint() self.btn_Command:SetRedPoint(not BattleDataGetter.IsCityWarWaitingLevel() and MDL.ChangAnSiege.IsBattleLeader() and CTL.ChangAnSiege.commandRedPoint) end function UIChangAnSiegeBattle:ShowInteractUI(isShow) if isShow then self.commandCanvas.overrideSorting = true self.commandCanvas.sortingLayerName = "UIDefault" else self.commandCanvas.overrideSorting = false end end return UIChangAnSiegeBattle