local UIInBattleWatchView = UIViewClass() local EMOJI_PREFIX_STR = "[%s]" function UIInBattleWatchView:OnOpened(context) if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncFairSoloTournament) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamFairChampionship) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVPPractice) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSoloPractice) then UIUtils.SetActive(self.group_Buttons, false) UIUtils.SetActive(self.group_Skill, true) self.hasSkill = true self.skillView = self.skillRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleAttackPanel), nil, "Replay/UIReplayBattleAttackPanel") self:UpdateWatcherIcon() self:RegistSystemEvent(EventID.Level_SwitchHero, self.UpdateWatcherIcon) else UIUtils.SetActive(self.group_Buttons, true) UIUtils.SetActive(self.group_Skill, false) end --多人战斗更换视角切换按钮 self.isTeamChangeWatch = BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairTeamPVP) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamFairChampionship) if self.isTeamChangeWatch then UIUtils.SetActive(self.btn_SwitchViewTeam, true) UIUtils.SetActive(self.btn_SwitchView, false) self:UpdateWatcherIcon() else UIUtils.SetActive(self.btn_SwitchViewTeam, false) UIUtils.SetActive(self.btn_SwitchView, true) end self:RegistSystemEvent(EventID.UI_ChannelChat_ClearInputField, self.ClearInputField) self:RegistSystemEvent(EventID.UI_UpdateSyncUnfairSoloWatch_ShowBullet, self.UpdateBulletSwitch) self:Init() UIUtils.SetActive(self.group_Chat, MDL.Player.GetPublicSentimentUnLock()) end function UIInBattleWatchView:Init() self.isShowBullet = CTL.WatchBattle.GetIsShowBullet() self:UpdateBulletSwitch(self.isShowBullet) CTL.WatchBattle.SetIsShowBullet(self.isShowBullet) self.canvas_ChatDlg:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleChatDlgWatch)) end function UIInBattleWatchView:UpdateBulletSwitch(isShow) self.isShowBullet = isShow UIUtils.SetActive(self.BGM_Open, isShow) UIUtils.SetActive(self.BGM_Close, not isShow) end function UIInBattleWatchView:OnButtonClicked(comp) if comp == self.btn_Reward then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroMatch1v1SubtitleReward) elseif comp == self.btn_Setting then -- 弹幕设置 UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroMatch1v1SubtitleSetting) elseif comp == self.btn_SwitchView or comp == self.btn_SwitchViewTeam or comp == self.btn_switch then -- 切换视角 CTL.WatchBattle.SwitchPlayer() self:UpdateWatcherIcon() elseif comp == self.btn_Exit or comp == self.btn_exit then CTL.Setting.BackToTown() elseif comp == self.btn_Sent then -- 发送输入内容 self:SendMsg(self.obj_InputField.text) elseif comp == self.btn_BGM then -- 点击弹幕开启toggle CTL.WatchBattle.SetIsShowBullet(not self.isShowBullet) elseif comp == self.btn_Emoji then self:OnClickFaceBtn() elseif comp == self.event_Condition_BackBtn then UIUtils.SetActive(self.group_Condition.gameObject, false) end end function UIInBattleWatchView:UpdateWatcherIcon() if self.isTeamChangeWatch then local heroId = BattleDataGetter.GetMainPlayerCharacterID() UTL.Item.SetHeroIconByHeroId(self.texture_HeadImg, heroId, BattleDataGetter.GetHeroIsAwaken(BattleDataGetter.GetCurPlayerID(), heroId)) end if self.hasSkill then self:SetPlayerInfo() end end --region **************** 观战界面下输入框相关 ******************************** function UIInBattleWatchView:OnClickFaceBtn() local isActive = self.group_Condition.gameObject.activeSelf UIUtils.SetActive(self.group_Condition.gameObject, not isActive) self.Emoji_Condition:ReloadAll(MDL.ChannelChat.GetSortedEmojiList()) end function UIInBattleWatchView:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.Emoji_Condition then UIUtils.SetLabel(cellTable.txt_emoji, string.format(EMOJI_PREFIX_STR, data.ID)) end end function UIInBattleWatchView:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.Emoji_Condition then self:OnCommonClickEmoji(data) end end function UIInBattleWatchView:OnCommonClickEmoji(data) local emojiShow = string.format("[%s]", UIUtils.GetLocalizedTxt(Const_IDS[data.EmojiName])) local msg = self.obj_InputField.text msg = msg .. emojiShow self:SetInputTextAndMoveEnd(msg) end function UIInBattleWatchView:MoveCursor() self.obj_InputField:MoveTextEnd(false) end function UIInBattleWatchView:SetInputTextAndMoveEnd(txt) self.obj_InputField.text = txt --光标移动需要等一帧生效 self:StartRepeatFunc(self.MoveCursor, 0.02, 1) end function UIInBattleWatchView:IsOutOfLengthWhenInsertContent(content) return not CTL.ChannelChat.IsOutOfLengthWhenInsertContent(content, self:GetChannelID()) end function UIInBattleWatchView:SendMsg(content) --处于禁言状态 if MDL.HomeMain.GetSilenceBuff() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_OfficialPrivilege_FailInSend) return elseif #content <= 0 then -- 弹幕为空 CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroMatch1v1_InputBullet) return end if MDL.ChannelChat.CanSendMsg() then local msg = content if (MDL.ChannelChat.IsJoinChannel(MDL.ChannelChat.ChannelCfgId.Bullet) or self:IsInWatchPractice()) and not CTL.ChannelChat.IsOutOfLength(msg, self:GetChannelID()) then CTL.ChannelChat.SendTextMsg(msg, self:GetChannelID(), nil, nil, CTL.WatchBattle.GetBulletColor()) end else CTL.Tips.AddTipsMsg(MDL.ChannelChat.GetForbiddenMsg()) end end function UIInBattleWatchView:IsInWatchPractice() if (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVPPractice) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSoloPractice)) then return MDL.ChannelChat.IsJoinChannel(MDL.ChannelChat.ChannelCfgId.PKRoom) end end function UIInBattleWatchView:ClearInputField() self.obj_InputField.text = nil MDL.ChannelChat.SetNotSendMsg(""); end function UIInBattleWatchView:GetChannelID() if (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVPPractice) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSoloPractice)) then return MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.PKRoom) end return MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.Bullet) end --endregion ************************************************************* function UIInBattleWatchView:OnClosed() UIUtils.SetActive(self.group_Condition.gameObject, false) end -- 设置玩家头像 function UIInBattleWatchView:SetPlayerInfo() local myEntity = BattleDataGetter.GetCurEntity() local heroId = BattleDataGetter.GetMainPlayerCharacterID() local heroName = myEntity and myEntity._logicInitData.Name or "" UTL.Item.SetHeroIconByHeroId(self.group_playerInfo.texture_HeadImg, heroId, BattleDataGetter.GetHeroIsAwaken(myEntity:GetPlayerID(), heroId)) self.group_playerInfo.labLocal_name.text = heroName end return UIInBattleWatchView