local UIHeroMatch1v1InBattleInfo = UIViewClass() local VICTORY_EFFECT_SHOW_TIME = DataSheetManager.ConstData:GetDataByID("HeroMatch1v1Interface3").IntValue function UIHeroMatch1v1InBattleInfo:OnOpened(context) self.myHeadComps = { [1] = self.heads_camp1.img_HeroHead1, [2] = self.heads_camp1.img_HeroHead2, [3] = self.heads_camp1.img_HeadSub3, [4] = self.heads_camp1.img_HeadSub4, [5] = self.heads_camp1.img_HeadSub5, [6] = self.heads_camp1.img_HeadSub6, } self.enemyHeadComps = { [1] = self.heads_camp2.img_HeroHead1, [2] = self.heads_camp2.img_HeroHead2, [3] = self.heads_camp2.img_HeadSub3, [4] = self.heads_camp2.img_HeadSub4, [5] = self.heads_camp2.img_HeadSub5, [6] = self.heads_camp2.img_HeadSub6, } self.myPlayerID = BattleDataGetter.GetCurPlayerID() for i, v in ipairs(BattleDataGetter.GetRoomPlayerIDList()) do if v ~= self.myPlayerID then self.enemyPlayerID = v end end self.buffPanel = {} self:RegistSystemEvent(EventID.Battle_HeroMatch1v1_NextRound, self.RefreshBattleInfo) self:RegistSystemEvent(EventID.Level_SwitchHero, self.OnRoundHeroSwitch) self:RegistSystemEvent(EventID.UIBattle_PlayerHPMessageChanged, self.OnHPMessageChanged) self:RegistSystemEvent(EventID.UI_UpdateBuff_OtherHero, self.UpdateEnemyBuffShow) self:RegistSystemEvent(EventID.UI_UpdateBuff_Self, self.UpdateOwnBuffShow) self:RegistSystemEvent(EventID.UI_UIBattleCountDownPanel_CloseEvent, self.ShowBattleRound) self:RegistSystemEvent(EventID.UIBattle_VictoryPopPanelClosed, self.ShowBattleRound) self:Init() end function UIHeroMatch1v1InBattleInfo:Init() self.myCampID = BattleDataGetter.GetMyCampID() self:SetScore() self.buffPanel[1] = self.heads_camp1.buffItem_Root:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), { type = LuaConst.UIBuffShowType.PlayerSelf, entityId = BattleDataGetter.GetPlayerActiveEntity(self.myPlayerID):GetEntityID() }, "Battle/UIBattleBuffOneLine" ) self.buffPanel[2] = self.heads_camp2.buffItem_Root:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), { type = LuaConst.UIBuffShowType.PlayerOthers, entityId = BattleDataGetter.GetPlayerActiveEntity(self.enemyPlayerID):GetEntityID() }, "Battle/UIBattleBuffOppositeOneLine" ) local playerInfo1 = BattleDataGetter.GetPlayerInfo(self.myPlayerID) local playerInfo2 = BattleDataGetter.GetPlayerInfo(self.enemyPlayerID) -- 玩家名字 UIUtils.SetLabel(self.txt_PlayerName2, BattleDataGetter.GetPlayerNameByPlayerID(self.enemyPlayerID)) UIUtils.SetLabel(self.txt_PlayerName1, BattleDataGetter.GetPlayerNameByPlayerID(self.myPlayerID)) CTL.Character.SetPortraitAndFrame(self.template_Head1, playerInfo1.portraitId, playerInfo1.frameId, nil, playerInfo1.acid) CTL.Character.SetPortraitAndFrame(self.template_Head2, playerInfo2.portraitId, playerInfo2.frameId, nil, playerInfo2.acid) self.timer = self:StartRepeatFunc(self.RefreshLeftTime, 1, -1) -- 设置玩家头像 self:RefreshHeadsInfo() end function UIHeroMatch1v1InBattleInfo:ShowBattleRound() CTL.HeroMatch1v1.ShowBattleRoundIcon(self.curRound) end function UIHeroMatch1v1InBattleInfo:OnRoundHeroSwitch(type, entity) -- 更新头像 self:RefreshHeadsInfo() -- 更新Buff if BattleDataGetter.CheckEntityBelongsToPlayer(entity.EntityID, self.myPlayerID) then self.buffPanel[1]:OnEntityChange(entity.EntityID) else self.buffPanel[2]:OnEntityChange(entity.EntityID) end end function UIHeroMatch1v1InBattleInfo:UpdateOwnBuffShow(entity, buffData, time, layer, sourceEntityId) self.buffPanel[1]:UpdateBuffShow(buffData, time, layer, sourceEntityId) end function UIHeroMatch1v1InBattleInfo:UpdateEnemyBuffShow(entity, buffData, time, layer, sourceEntityId) self.buffPanel[2]:UpdateBuffShow(buffData, time, layer, sourceEntityId) end function UIHeroMatch1v1InBattleInfo:RefreshHeadsInfo() local myHeads = BattleDataGetter.GetFirstMyHeroInfo() local enemyPlayerID, enemyHeads = BattleDataGetter.GetFirstEnemyHeroInfo() for index, _ in ipairs(myHeads) do if myHeads[index] > 0 then UTL.Item.SetHeroIconByHeroId(self.myHeadComps[index], myHeads[index], BattleDataGetter.GetHeroIsAwaken(BattleDataGetter.GetCurPlayerID(), myHeads[index])) UIUtils.SetActive(self.myHeadComps[index], true) else UIUtils.SetActive(self.myHeadComps[index], false) end if enemyHeads[index] > 0 then UTL.Item.SetHeroIconByHeroId(self.enemyHeadComps[index], enemyHeads[index], BattleDataGetter.GetHeroIsAwaken(enemyPlayerID, enemyHeads[index])) UIUtils.SetActive(self.enemyHeadComps[index], true) else UIUtils.SetActive(self.enemyHeadComps[index], false) end end end function UIHeroMatch1v1InBattleInfo:OnHPMessageChanged(entity) local comp_Attr = entity.components.attr local hplmt = comp_Attr:GetAttrValueNum(LuaConst.AttrType.hplmt) if hplmt <= 0 then return end local hp = FP.tonumberV1(comp_Attr.hp) local percentVal, percentStr = CTL.HeroMatch1v1.GetLeftHpPercentStr(hp, hplmt, "IDS_HeroMatch1v1_Blood") if entity:GetPlayerID() == self.myPlayerID then UIUtils.SetLabel(self.heads_camp1.txt_Hp, percentStr) self.heads_camp1.slider_HP.value = percentVal else UIUtils.SetLabel(self.heads_camp2.txt_Hp, percentStr) self.heads_camp2.slider_HP.value = percentVal end end function UIHeroMatch1v1InBattleInfo:RefreshBattleInfo(round, entity) self.roundTime = BattleDataGetter.GetRoundRemainTime() local isWin = entity:GetCampID() ~= self.myCampID self:SetScore() CTL.LevelSelect.ShowCommonSummaryTemplatePanel(isWin, VICTORY_EFFECT_SHOW_TIME, "IDS_HeroMatch1v1_WaitNextBattle") end function UIHeroMatch1v1InBattleInfo:RefreshLeftTime(deltaTime, timeSinceUpdate) local time = BattleDataGetter.GetRoundRemainTime() if time >= 0 then UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(time)) else UIUtils.SetLabel(self.txt_Time, "") end end function UIHeroMatch1v1InBattleInfo:SetScore() self.scoreList = BattleDataGetter.GetHeroMatch1v1RoundWinners() self.myScore, self.enemyScore = 0, 0 self.curRound = #self.scoreList + 1 if #self.scoreList > 0 then for _, winCampID in ipairs(self.scoreList) do if self.myCampID == winCampID then self.myScore = self.myScore + 1 else self.enemyScore = self.enemyScore + 1 end end end UIUtils.SetLabel(self.txt_Score1, self.myScore) UIUtils.SetLabel(self.txt_Score3, self.enemyScore) UIUtils.SetLabel(self.txt_Round, string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_Round4"], self.curRound)) end function UIHeroMatch1v1InBattleInfo:OnButtonClicked(comp) if comp == self.btn_Exit then CTL.Setting.BackToTown() elseif comp == self.btn_Setting then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) end end return UIHeroMatch1v1InBattleInfo