using FairyGUI; using UI.Common; namespace GFGGame { //不要直接创建此类,通过AlertSystem调用 public class AlertWindow : BaseView, IAlert { public delegate void AlertCallback(object data); private UI_AlertUI _ui; private float m_xLeftButton = 0; private float m_xRightButton = 0; private string m_content = ""; private string m_tips = ""; private string m_textLeft = "取消"; private string m_textRight = "确认"; private bool m_isShowLeftButton = false; private bool m_isShowRightButton = false; private object m_data = null; private AlertCallback m_leftButtonCallback = null; private AlertCallback m_rightButtonCallback = null; public AlertWindow() : base() { } public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } AlertUI.Dispose(); AlertSystem.Dispose(); base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_AlertUI.PACKAGE_NAME; _ui = UI_AlertUI.Create(); this.viewCom = _ui.target; isfullScreen = true; layer = ConstViewLayer.TOP; // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; this.viewCom.Center(); m_xLeftButton = _ui.m_btnLeft.x; m_xRightButton = _ui.m_btnRight.x; // this.sortingOrder = ConstSortingOrder.FLOATING_PROMPT; this.SetMessage(m_content); this.SetTips(m_tips); this.SetLeftButton(m_isShowLeftButton, m_textLeft); this.SetRightButton(m_isShowRightButton, m_textRight); updateButtonPosition(); _ui.m_btnLeft.onClick.Add(() => { this.Hide(); m_leftButtonCallback?.Invoke(m_data); }); _ui.m_btnRight.onClick.Add(() => { this.Hide(); m_rightButtonCallback?.Invoke(m_data); }); } protected override void OnShown() { base.OnShown(); _ui.target.Center(); Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); Timers.inst.Remove(CheckGuide); } //protected override void OnUpdate() { // base.OnUpdate(); // if(this.root != null) { // int i = this.parent.GetChildIndex(this); // int iMax = this.parent.numChildren - 1; // if(i < iMax) { // this.parent.SetChildIndex(this, iMax); // } // } //} public IAlert SetLayer(string setlayer) { layer = setlayer; return this; } private void updateButtonPosition() { float xLeftButton = m_xLeftButton; float xRightButton = m_xRightButton; float xCenter = (m_xLeftButton + m_xRightButton) / 2; if (!m_isShowLeftButton && m_isShowRightButton) { xRightButton = xCenter; } else if (m_isShowLeftButton && !m_isShowRightButton) { xLeftButton = xCenter; } if (_ui != null) { _ui.m_btnLeft.x = xLeftButton; this._ui.m_btnLeft.visible = m_isShowLeftButton; } if (_ui != null) { _ui.m_btnRight.x = xRightButton; this._ui.m_btnRight.visible = m_isShowRightButton; } } public IAlert Reset() { m_content = ""; m_tips = ""; m_textLeft = "取消"; m_textRight = "确认"; m_leftButtonCallback = null; m_rightButtonCallback = null; m_isShowLeftButton = false; m_isShowRightButton = false; // clickBlankToClose = false; m_data = null; if (this._ui != null) { this._ui.m_txtContent.text = m_content; } if (this._ui != null) { this._ui.m_txtTips.text = m_tips; } if (this._ui != null) { this._ui.m_btnLeft.text = m_textLeft; this._ui.m_btnLeft.visible = m_isShowLeftButton; } if (this._ui != null) { this._ui.m_btnRight.text = m_textRight; this._ui.m_btnRight.visible = m_isShowRightButton; } updateButtonPosition(); return this; } public IAlert SetMessage(string message) { this.m_content = message; if (this._ui != null) { this._ui.m_txtContent.text = m_content; // Debug.Log("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size); if (this._ui.m_txtContent.textHeight > this._ui.m_txtContent.textFormat.size * 2) { this._ui.m_txtContent.align = AlignType.Left; } else { this._ui.m_txtContent.align = AlignType.Center; } this._ui.target.Center(); } return this; } public IAlert SetTips(string message) { this.m_tips = message; if (this._ui != null) { this._ui.m_txtTips.text = m_tips; // Debug.Log("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size); if (this._ui.m_txtTips.textHeight > this._ui.m_txtTips.textFormat.size * 2) { this._ui.m_txtTips.align = AlignType.Left; } else { this._ui.m_txtTips.align = AlignType.Center; } this._ui.target.Center(); } return this; } public IAlert SetLeftButton(bool isShow, string textLeft = "取消", AlertCallback callback = null) { this.m_isShowLeftButton = isShow; this.m_leftButtonCallback = callback; this.m_textLeft = textLeft; if (this._ui != null) { this._ui.m_btnLeft.text = m_textLeft; this._ui.m_btnLeft.visible = m_isShowLeftButton; } updateButtonPosition(); return this; } public IAlert SetRightButton(bool isShow, string textRight = "确认", AlertCallback callback = null) { this.m_isShowRightButton = isShow; this.m_rightButtonCallback = callback; this.m_textRight = textRight; if (this._ui != null) { this._ui.m_btnRight.text = m_textRight; this._ui.m_btnRight.visible = m_isShowRightButton; } updateButtonPosition(); return this; } public IAlert SetData(object data) { this.m_data = data; return this; } public IAlert SetClickBlankToClose(bool value) { // this.clickBlankToClose = value; return this; } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0) { UpdateToCheckGuide(null); } else { Timers.inst.Remove(CheckGuide); } } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_btnRight.asCom, ConstGuideId.LUCKY_BOX, 3, ""); } protected override void TryCompleteGuide() { GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX); if (GuideDataManager.currentGuideId == cfg.id) { GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 3); GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX, 3); } } } }