From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XMainClient/XApolloDocument.cs | 310 +++++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XApolloDocument.cs (limited to 'Client/Assets/Scripts/XMainClient/XApolloDocument.cs') diff --git a/Client/Assets/Scripts/XMainClient/XApolloDocument.cs b/Client/Assets/Scripts/XMainClient/XApolloDocument.cs new file mode 100644 index 00000000..305ffcd4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XApolloDocument.cs @@ -0,0 +1,310 @@ +using System; +using System.Collections.Generic; +using KKSG; +using XMainClient.UI; +using XMainClient.UI.UICommon; +using XUpdater; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XApolloDocument : XDocComponent + { + public override uint ID + { + get + { + return XApolloDocument.uuID; + } + } + + private JoinRoomReply voipRoomInfo { get; set; } + + public bool IsRealVoice + { + get + { + this.doc = XDocuments.GetSpecificDocument(XChatDocument.uuID); + return this.doc != null && this.doc.GetBattleRaw().real > 0; + } + } + + public bool IsRealtimeVoiceOn + { + get + { + IApolloManager xapolloManager = XSingleton.singleton.XApolloManager; + return this.mJoinRoomSucc && xapolloManager.openMusic; + } + } + + public int TimeOut + { + get + { + bool flag = this._timeout == 0; + if (flag) + { + this._timeout = XSingleton.singleton.GetInt("SetApolloTimeout"); + } + return this._timeout; + } + } + + public bool JoinRoomSucc + { + get + { + return this.mJoinRoomSucc; + } + } + + public bool IsWaittingJoinRoom + { + get + { + return this.startLoop && !this.mJoinRoomSucc; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("XApolloDocument"); + + private List roomRoles = new List(); + + private List roomStates = new List(); + + private bool mJoinRoomSucc = false; + + private XChatDocument doc; + + private int _timeout = 0; + + private bool startLoop = false; + + private float acc_time = 0f; + + private float all_time = 0f; + + private float currVol = 1f; + + private float muteVol = 100f; + + public override void OnAttachToHost(XObject host) + { + } + + protected override void OnReconnected(XReconnectedEventArgs arg) + { + } + + public override void OnDetachFromHost() + { + this.QuitRoom(); + base.OnDetachFromHost(); + } + + public override void Update(float fDeltaT) + { + base.Update(fDeltaT); + bool flag = this.startLoop; + if (flag) + { + this.acc_time += fDeltaT; + this.all_time += fDeltaT; + bool flag2 = this.all_time > (float)this.TimeOut && !this.JoinRoomSucc; + if (flag2) + { + this.startLoop = false; + this.mJoinRoomSucc = false; + XSingleton.singleton.AddGreenLog("join room timeout, Apollo error!", null, null, null, null, null); + bool flag3 = !XSingleton.singleton.EditorMode; + if (flag3) + { + XSingleton.singleton.ShowSystemTip(XSingleton.singleton.GetString("VOICE_APOLLO_FAIL"), "fece00"); + } + } + bool flag4 = this.acc_time > 0.4f; + if (flag4) + { + bool flag5 = !this.mJoinRoomSucc; + if (flag5) + { + IApolloManager xapolloManager = XSingleton.singleton.XApolloManager; + bool joinRoomResult = xapolloManager.GetJoinRoomResult(); + if (joinRoomResult) + { + this.mJoinRoomSucc = true; + XYuyinView yuyinHandler = DlgBase.singleton._yuyinHandler; + bool flag6 = yuyinHandler != null; + if (flag6) + { + yuyinHandler.SetSpeak(false); + xapolloManager.openMusic = false; + yuyinHandler.SetMusic(true); + XOptionsDocument specificDocument = XDocuments.GetSpecificDocument(XOptionsDocument.uuID); + int @int = XSingleton.singleton.GetInt("SetSpeakerVolume"); + xapolloManager.SetMusicVolum((int)((float)@int * specificDocument.voiceVolme)); + } + this.RefreshState(this.roomRoles.ToArray(), this.roomStates.ToArray()); + } + } + this.acc_time = 0f; + } + } + } + + private void HideState() + { + bool flag = DlgBase.singleton.IsLoaded(); + if (flag) + { + bool flag2 = DlgBase.singleton.TeamMonitor != null; + if (flag2) + { + DlgBase.singleton.TeamMonitor.HideVoice(); + } + XSceneDamageRankDocument specificDocument = XDocuments.GetSpecificDocument(XSceneDamageRankDocument.uuID); + bool flag3 = specificDocument != null; + if (flag3) + { + specificDocument.RankHandler.HideVoice(); + } + } + } + + public void RequestJoinRoom() + { + bool isRealVoice = this.IsRealVoice; + if (isRealVoice) + { + XSingleton.singleton.EnableAutoPlay(false); + XSingleton.singleton.StopAutoPlay(); + PtcC2G_JoinRoom proto = new PtcC2G_JoinRoom(); + XSingleton.singleton.Send(proto); + } + else + { + this.HideState(); + } + } + + public void JoinRoom(JoinRoomReply data) + { + XSingleton.singleton.AddLog("url1:", data.url1, " url2:", data.url2, " url3:", data.url3, XDebugColor.XDebug_None); + XSingleton.singleton.AddLog("roomid:", data.roomID.ToString(), " roomkey: ", data.roomKey.ToString(), " member: ", data.memberID.ToString(), XDebugColor.XDebug_None); + this.voipRoomInfo = data; + this.mJoinRoomSucc = false; + this.acc_time = 0f; + this.all_time = 0f; + this.startLoop = true; + IApolloManager xapolloManager = XSingleton.singleton.XApolloManager; + xapolloManager.SetRealtimeMode(); + bool flag = !string.IsNullOrEmpty(data.url1); + if (flag) + { + data.url1 = "udp://" + data.url1; + } + bool flag2 = !string.IsNullOrEmpty(data.url2); + if (flag2) + { + data.url2 = "udp://" + data.url2; + } + bool flag3 = !string.IsNullOrEmpty(data.url3); + if (flag3) + { + data.url3 = "udp://" + data.url3; + } + xapolloManager.JoinRoom(data.url1, data.url2, data.url3, data.roomID, data.roomKey, (short)data.memberID); + } + + public void QuitRoom() + { + this.RecoverySound(); + XSingleton.singleton.EnableAutoPlay(true); + bool flag = this.voipRoomInfo != null; + if (flag) + { + XSingleton.singleton.XApolloManager.QuitRoom(this.voipRoomInfo.roomID, (short)this.voipRoomInfo.memberID); + PtcC2G_QuitRoom ptcC2G_QuitRoom = new PtcC2G_QuitRoom(); + ptcC2G_QuitRoom.Data.roomID = this.voipRoomInfo.roomID; + ptcC2G_QuitRoom.Data.memberID = this.voipRoomInfo.memberID; + XSingleton.singleton.Send(ptcC2G_QuitRoom); + this.startLoop = false; + this.mJoinRoomSucc = false; + this.voipRoomInfo = null; + } + } + + public void OnMembersInfoChange(List _server) + { + this.roomRoles.Clear(); + this.roomStates.Clear(); + for (int i = 0; i < _server.Count; i++) + { + this.roomRoles.Add(_server[i].roleID); + this.roomStates.Add((int)_server[i].state); + } + this.RefreshState(this.roomRoles.ToArray(), this.roomStates.ToArray()); + } + + public void RefreshState(ulong[] roleids, int[] states) + { + bool flag = DlgBase.singleton.IsLoaded() && DlgBase.singleton.IsVisible(); + if (flag) + { + bool isRealVoice = this.IsRealVoice; + if (isRealVoice) + { + bool flag2 = DlgBase.singleton.TeamMonitor != null; + if (flag2) + { + DlgBase.singleton.TeamMonitor.RefreshVoice(roleids, states); + } + XSceneDamageRankDocument specificDocument = XDocuments.GetSpecificDocument(XSceneDamageRankDocument.uuID); + bool flag3 = specificDocument != null; + if (flag3) + { + specificDocument.RankHandler.RefreshVoice(roleids, states); + } + } + } + } + + public void SendStateServer(uint state) + { + PtcC2G_SetVoipMemberState ptcC2G_SetVoipMemberState = new PtcC2G_SetVoipMemberState(); + ptcC2G_SetVoipMemberState.Data.nstate = state; + XSingleton.singleton.Send(ptcC2G_SetVoipMemberState); + } + + public void PlayGameSound(bool on) + { + bool flag = !on; + if (flag) + { + this.MuteSound(); + } + else + { + this.RecoverySound(); + } + } + + public void MuteSound() + { + bool flag = this.muteVol >= 100f; + if (flag) + { + this.muteVol = (float)XSingleton.singleton.GetInt("SetMusicVol") / 100f; + } + this.currVol = this.muteVol; + XSingleton.singleton.SetMainBusVolume(this.currVol); + } + + public void RecoverySound() + { + this.currVol = 1f; + XSingleton.singleton.SetMainBusVolume(this.currVol); + } + } +} -- cgit v1.1-26-g67d0