From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/BroadcastDlg.cs | 229 ++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/BroadcastDlg.cs (limited to 'Client/Assets/Scripts/XMainClient/BroadcastDlg.cs') diff --git a/Client/Assets/Scripts/XMainClient/BroadcastDlg.cs b/Client/Assets/Scripts/XMainClient/BroadcastDlg.cs new file mode 100644 index 00000000..db59e0d7 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/BroadcastDlg.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XMainClient.UI.UICommon; +using XUpdater; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class BroadcastDlg : DlgBase + { + public override string fileName + { + get + { + return "GameSystem/BroadcastDlg"; + } + } + + public override bool autoload + { + get + { + return true; + } + } + + public override bool isHideChat + { + get + { + return false; + } + } + + private static bool isCameraOpen = false; + + public readonly int max_count = 40; + + public List barrages = new List(); + + public string lastCahceMsg = string.Empty; + + private Vector3 originPos = Vector3.zero; + + private float closeTime = 0f; + + private float closeDuration = 0.3f; + + private bool isClosing = false; + + private uint timer = 0u; + + protected override void Init() + { + base.Init(); + base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_OPEN")); + GameObject tpl = base.uiBehaviour.loopScrool.GetTpl(); + bool flag = tpl != null && tpl.GetComponent() == null; + if (flag) + { + tpl.AddComponent(); + } + } + + public override void RegisterEvent() + { + base.RegisterEvent(); + base.uiBehaviour.m_btnBarrage.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnEndClick)); + base.uiBehaviour.m_btnCamera.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCameraClick)); + base.uiBehaviour.m_btnClose.RegisterClickEventHandler(new ButtonClickEventHandler(this.ClosePanel)); + base.uiBehaviour.m_btnShare.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnShareClick)); + } + + protected override void OnShow() + { + base.OnShow(); + this.timer = XSingleton.singleton.SetTimer(0.5f, new XTimerMgr.ElapsedEventHandler(this.TimerShow), null); + this.originPos = DlgBase.singleton.GetIconPos(); + this.isClosing = false; + base.uiBehaviour.transform.localPosition = Vector3.zero; + base.uiBehaviour.transform.localScale = Vector3.one; + } + + protected override void OnUnload() + { + XSingleton.singleton.KillTimer(this.timer); + base.OnUnload(); + } + + public void Push(string _nickname, string _content) + { + BroadNode item = default(BroadNode); + item.nickname = _nickname; + item.content = _content; + bool flag = this.barrages.Count > this.max_count; + if (flag) + { + this.barrages.RemoveRange(0, this.barrages.Count - this.max_count); + } + this.barrages.Add(item); + } + + private void TimerShow(object o) + { + this.ShowList(); + this.timer = XSingleton.singleton.SetTimer(0.4f, new XTimerMgr.ElapsedEventHandler(this.TimerShow), null); + } + + public void ShowList() + { + bool flag = base.IsVisible(); + if (flag) + { + List list = new List(); + string b = string.Empty; + for (int i = 0; i < this.barrages.Count; i++) + { + BarrageMsg barrageMsg = new BarrageMsg(); + barrageMsg.LoopID = XSingleton.singleton.XHash(this.barrages[i].content + i); + barrageMsg.nickname = this.barrages[i].nickname; + barrageMsg.content = this.barrages[i].content; + list.Add(barrageMsg); + b = XSingleton.singleton.StringCombine(barrageMsg.nickname, barrageMsg.content); + } + bool flag2 = string.IsNullOrEmpty(this.lastCahceMsg) || this.lastCahceMsg != b; + if (flag2) + { + base.uiBehaviour.loopScrool.Init(list, new DelegateHandler(this.RefreshItem), null, 1, false); + } + bool flag3 = this.barrages != null && this.barrages.Count > 0; + if (flag3) + { + int index = this.barrages.Count - 1; + this.lastCahceMsg = XSingleton.singleton.StringCombine(this.barrages[index].nickname, this.barrages[index].content); + } + } + } + + public override void OnUpdate() + { + base.OnUpdate(); + bool flag = this.isClosing; + if (flag) + { + base.uiBehaviour.gameObject.transform.localPosition = Vector3.Lerp(Vector3.zero, this.originPos, (Time.time - this.closeTime) / this.closeDuration); + base.uiBehaviour.gameObject.transform.localScale = Vector3.Lerp(Vector3.one, 0.1f * Vector3.one, (Time.time - this.closeTime) / this.closeDuration); + bool flag2 = Time.time - this.closeTime >= this.closeDuration; + if (flag2) + { + this.isClosing = false; + this.SetVisible(false, true); + DlgBase.singleton.Show(true); + } + } + } + + private void RefreshItem(ILoopItemObject item, LoopItemData data) + { + BarrageMsg barrageMsg = data as BarrageMsg; + bool flag = barrageMsg != null; + if (flag) + { + GameObject obj = item.GetObj(); + bool flag2 = obj != null; + if (flag2) + { + BroadBarrageItem component = obj.GetComponent(); + bool flag3 = component != null; + if (flag3) + { + component.Refresh(barrageMsg.nickname, barrageMsg.content); + } + } + } + else + { + XSingleton.singleton.AddErrorLog("BroadBarrageItem info is null", null, null, null, null, null); + } + } + + private bool OnEndClick(IXUIButton btn) + { + XSingleton.singleton.XBroadCast.StopBroadcast(); + this.ClosePanel(btn); + return true; + } + + private bool OnCameraClick(IXUIButton btn) + { + bool flag = BroadcastDlg.isCameraOpen; + if (flag) + { + XSingleton.singleton.XBroadCast.ShowCamera(false); + BroadcastDlg.isCameraOpen = false; + base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_OPEN")); + } + else + { + bool flag2 = XSingleton.singleton.XBroadCast.ShowCamera(true); + if (flag2) + { + BroadcastDlg.isCameraOpen = true; + base.uiBehaviour.m_lblCamera.SetText(XStringDefineProxy.GetString("BROAD_CAMERA_CLOSE")); + } + } + return true; + } + + private bool OnShareClick(IXUIButton btn) + { + XSingleton.singleton.AddGreenLog("sharebtn click", null, null, null, null, null); + this.ClosePanel(btn); + return true; + } + + private bool ClosePanel(IXUIButton btn) + { + bool flag = !this.isClosing; + if (flag) + { + this.closeTime = Time.time; + this.isClosing = true; + } + return true; + } + } +} -- cgit v1.1-26-g67d0