From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/Team/XTeamSmallChatHandler.cs | 202 +++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Team/XTeamSmallChatHandler.cs (limited to 'Client/Assets/Scripts/XMainClient/Team/XTeamSmallChatHandler.cs') diff --git a/Client/Assets/Scripts/XMainClient/Team/XTeamSmallChatHandler.cs b/Client/Assets/Scripts/XMainClient/Team/XTeamSmallChatHandler.cs new file mode 100644 index 00000000..dc3a67aa --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Team/XTeamSmallChatHandler.cs @@ -0,0 +1,202 @@ +using System; +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XMainClient.UI.UICommon; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XTeamSmallChatHandler : DlgHandlerBase + { + private ChatChannelType CurrentChannel + { + get + { + return this.teamDoc.bInTeam ? ChatChannelType.Team : ChatChannelType.World; + } + } + + private static int MSG_DISPLAY_COUNT = 3; + + private XUIPool m_TextPool = new XUIPool(XSingleton.singleton.m_uiTool); + + private XUIPool m_AudioPool = new XUIPool(XSingleton.singleton.m_uiTool); + + private IXUIButton m_BtnVoice; + + private GameObject m_SpeakInfo; + + private List m_ChatList = new List(); + + private XChatDocument chatDoc; + + private XTeamDocument teamDoc; + + private Vector2 m_DragDistance = Vector2.zero; + + private bool m_CancelRecord = false; + + protected override void Init() + { + base.Init(); + this.chatDoc = XDocuments.GetSpecificDocument(XChatDocument.uuID); + this.teamDoc = XDocuments.GetSpecificDocument(XTeamDocument.uuID); + this.m_BtnVoice = (base.PanelObject.transform.Find("BtnVoice").GetComponent("XUIButton") as IXUIButton); + this.m_SpeakInfo = base.PanelObject.transform.Find("SpeakPanel/SpeakInfo").gameObject; + } + + public override void RegisterEvent() + { + base.RegisterEvent(); + this.m_BtnVoice.RegisterPressEventHandler(new ButtonPressEventHandler(this._OnVoiceBtn)); + this.m_BtnVoice.RegisterDragEventHandler(new ButtonDragEventHandler(this._OnVoiceButtonDrag)); + } + + public override void OnUnload() + { + base.OnUnload(); + } + + protected override void OnShow() + { + base.OnShow(); + this.m_SpeakInfo.SetActive(false); + } + + private void _OnVoiceButtonDrag(IXUIButton sp, Vector2 delta) + { + this.m_DragDistance += delta; + bool flag = this.m_DragDistance.magnitude >= 100f; + if (flag) + { + this.m_CancelRecord = true; + } + else + { + this.m_CancelRecord = false; + } + } + + private void _OnVoiceBtn(IXUIButton btn, bool state) + { + if (state) + { + this.m_DragDistance = Vector2.zero; + bool useApollo = XChatDocument.UseApollo; + if (useApollo) + { + XSingleton.singleton.StartRecord(VoiceUsage.CHAT, null); + } + else + { + XSingleton.singleton.StartRecord(VoiceUsage.CHAT, null); + } + } + else + { + DlgBase.singleton.SetActiveChannel(ChatChannelType.Team); + bool useApollo2 = XChatDocument.UseApollo; + if (useApollo2) + { + XSingleton.singleton.StopRecord(this.m_CancelRecord); + } + else + { + XSingleton.singleton.StopRecord(this.m_CancelRecord); + } + } + } + + private void _OnChatBgClicked(IXUISprite iSp) + { + DlgBase.singleton.ShowChannel(this.CurrentChannel); + } + + public void RefreshPage() + { + List chatInfoList = this.chatDoc.GetChatInfoList(this.CurrentChannel); + int num = (chatInfoList != null) ? Math.Min(chatInfoList.Count, XTeamSmallChatHandler.MSG_DISPLAY_COUNT) : 0; + int num2 = Math.Max(0, num - XTeamSmallChatHandler.MSG_DISPLAY_COUNT); + this.m_ChatList.Clear(); + this.m_TextPool.FakeReturnAll(); + this.m_AudioPool.FakeReturnAll(); + for (int i = num2; i < num; i++) + { + this._SetChatInfo(chatInfoList[i]); + } + this.m_TextPool.ActualReturnAll(false); + this.m_AudioPool.ActualReturnAll(false); + this._SetAllChatInfoPosition(); + } + + public void OnGetChatInfo(ChatInfo newInfo) + { + bool flag = newInfo.mChannelId != this.CurrentChannel; + if (!flag) + { + this._SetChatInfo(newInfo); + this._SetAllChatInfoPosition(); + } + } + + private void _SetChatInfo(ChatInfo info) + { + XSmallChatInfo xsmallChatInfo = this._CreateSmallChatInfo(); + xsmallChatInfo.info = info; + xsmallChatInfo.uiobject = (info.isAudioChat ? this.m_AudioPool.FetchGameObject(false) : this.m_TextPool.FetchGameObject(false)); + this._SetChatUI(xsmallChatInfo.info, xsmallChatInfo.uiobject); + this.m_ChatList.Add(xsmallChatInfo); + } + + private void _SetAllChatInfoPosition() + { + int num = 0; + for (int i = 0; i < this.m_ChatList.Count; i++) + { + GameObject uiobject = this.m_ChatList[i].uiobject; + IXUILabel ixuilabel = uiobject.transform.Find("content").GetComponent("XUILabel") as IXUILabel; + uiobject.transform.localPosition = new Vector3(0f, (float)(-(float)num)); + num += (int)ixuilabel.GetPrintSize().y; + } + } + + private XSmallChatInfo _CreateSmallChatInfo() + { + bool flag = this.m_ChatList.Count == XTeamSmallChatHandler.MSG_DISPLAY_COUNT; + XSmallChatInfo xsmallChatInfo; + if (flag) + { + xsmallChatInfo = this.m_ChatList[0]; + for (int i = 0; i < this.m_ChatList.Count - 1; i++) + { + this.m_ChatList[i] = this.m_ChatList[i + 1]; + } + this.m_ChatList.RemoveAt(this.m_ChatList.Count - 1); + } + else + { + xsmallChatInfo = new XSmallChatInfo(); + } + bool flag2 = xsmallChatInfo.info != null && xsmallChatInfo.uiobject != null; + if (flag2) + { + bool isAudioChat = xsmallChatInfo.info.isAudioChat; + if (isAudioChat) + { + this.m_AudioPool.ReturnInstance(xsmallChatInfo.uiobject, false); + } + else + { + this.m_TextPool.ReturnInstance(xsmallChatInfo.uiobject, false); + } + } + return xsmallChatInfo; + } + + private void _SetChatUI(ChatInfo info, GameObject go) + { + XChatSmallView.InitMiniChatUI(info, go); + } + } +} -- cgit v1.1-26-g67d0