123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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_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;
- private bool _setAlertLayer = false;
- public AlertWindow() : base()
- {
- }
- protected override void OnInit()
- {
- base.OnInit();
- _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.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();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- //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_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_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 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;
- }
- protected override void UpdateToCheckGuide(object param)
- {
- if (!ViewManager.CheckIsTopView(this.viewCom)) return;
- GuideController.TryGuide(_ui.m_btnRight, ConstGuideId.LUCKY_BOX, 4, "点击确定");
- GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX, 4);
- }
- }
- }
|