AlertWindow.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using FairyGUI;
  2. using UI.Common;
  3. namespace GFGGame
  4. {
  5. //不要直接创建此类,通过AlertSystem调用
  6. public class AlertWindow : BaseView, IAlert
  7. {
  8. public delegate void AlertCallback(object data);
  9. private UI_AlertUI _ui;
  10. private float m_xLeftButton = 0;
  11. private float m_xRightButton = 0;
  12. private string m_content = "";
  13. private string m_tips = "";
  14. private string m_textLeft = "取消";
  15. private string m_textRight = "确认";
  16. private bool m_isShowLeftButton = false;
  17. private bool m_isShowRightButton = false;
  18. private object m_data = null;
  19. private AlertCallback m_leftButtonCallback = null;
  20. private AlertCallback m_rightButtonCallback = null;
  21. public AlertWindow() : base()
  22. {
  23. }
  24. public override void Dispose()
  25. {
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. AlertUI.Dispose();
  32. AlertSystem.Dispose();
  33. base.Dispose();
  34. }
  35. protected override void OnInit()
  36. {
  37. base.OnInit();
  38. packageName = UI_AlertUI.PACKAGE_NAME;
  39. _ui = UI_AlertUI.Create();
  40. this.viewCom = _ui.target;
  41. //this.viewCom.sortingOrder = ConstSortingOrder.TOP;
  42. isfullScreen = true;
  43. layer = ConstViewLayer.TOP;
  44. // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  45. this.viewCom.Center();
  46. m_xLeftButton = _ui.m_btnLeft.x;
  47. m_xRightButton = _ui.m_btnRight.x;
  48. // this.sortingOrder = ConstSortingOrder.FLOATING_PROMPT;
  49. this.SetMessage(m_content);
  50. this.SetTips(m_tips);
  51. this.SetLeftButton(m_isShowLeftButton, m_textLeft);
  52. this.SetRightButton(m_isShowRightButton, m_textRight);
  53. updateButtonPosition();
  54. _ui.m_btnLeft.onClick.Add(() =>
  55. {
  56. this.Hide();
  57. m_leftButtonCallback?.Invoke(m_data);
  58. });
  59. _ui.m_btnRight.onClick.Add(() =>
  60. {
  61. this.Hide();
  62. m_rightButtonCallback?.Invoke(m_data);
  63. });
  64. _ui.m_btnCheck.onClick.Add(OnBtnCheckClick);
  65. }
  66. protected override void OnShown()
  67. {
  68. base.OnShown();
  69. _ui.target.Center();
  70. Timers.inst.AddUpdate(CheckGuide);
  71. }
  72. protected override void OnHide()
  73. {
  74. base.OnHide();
  75. Timers.inst.Remove(CheckGuide);
  76. }
  77. //protected override void OnUpdate() {
  78. // base.OnUpdate();
  79. // if(this.root != null) {
  80. // int i = this.parent.GetChildIndex(this);
  81. // int iMax = this.parent.numChildren - 1;
  82. // if(i < iMax) {
  83. // this.parent.SetChildIndex(this, iMax);
  84. // }
  85. // }
  86. //}
  87. private void OnBtnCheckClick()
  88. {
  89. LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN = _ui.m_btnCheck.selected;
  90. }
  91. public IAlert SetLayer(string setlayer)
  92. {
  93. layer = setlayer;
  94. return this;
  95. }
  96. private void updateButtonPosition()
  97. {
  98. float xLeftButton = m_xLeftButton;
  99. float xRightButton = m_xRightButton;
  100. float xCenter = (m_xLeftButton + m_xRightButton) / 2;
  101. if (!m_isShowLeftButton && m_isShowRightButton)
  102. {
  103. xRightButton = xCenter;
  104. }
  105. else if (m_isShowLeftButton && !m_isShowRightButton)
  106. {
  107. xLeftButton = xCenter;
  108. }
  109. if (_ui != null)
  110. {
  111. _ui.m_btnLeft.x = xLeftButton;
  112. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  113. }
  114. if (_ui != null)
  115. {
  116. _ui.m_btnRight.x = xRightButton;
  117. this._ui.m_btnRight.visible = m_isShowRightButton;
  118. }
  119. }
  120. public IAlert Reset()
  121. {
  122. m_content = "";
  123. m_tips = "";
  124. m_textLeft = "取消";
  125. m_textRight = "确认";
  126. m_leftButtonCallback = null;
  127. m_rightButtonCallback = null;
  128. m_isShowLeftButton = false;
  129. m_isShowRightButton = false;
  130. // clickBlankToClose = false;
  131. m_data = null;
  132. if (this._ui != null)
  133. {
  134. this._ui.m_txtContent.text = m_content;
  135. }
  136. if (this._ui != null)
  137. {
  138. this._ui.m_txtTips.text = m_tips;
  139. }
  140. if (this._ui != null)
  141. {
  142. this._ui.m_btnLeft.text = m_textLeft;
  143. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  144. }
  145. if (this._ui != null)
  146. {
  147. this._ui.m_btnRight.text = m_textRight;
  148. this._ui.m_btnRight.visible = m_isShowRightButton;
  149. }
  150. updateButtonPosition();
  151. return this;
  152. }
  153. public IAlert SetMessage(string message)
  154. {
  155. this.m_content = message;
  156. if (this._ui != null)
  157. {
  158. this._ui.m_txtContent.text = m_content;
  159. // LogUtil.LogEditor("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size);
  160. if (this._ui.m_txtContent.textHeight > this._ui.m_txtContent.textFormat.size * 2)
  161. {
  162. this._ui.m_txtContent.align = AlignType.Left;
  163. }
  164. else
  165. {
  166. this._ui.m_txtContent.align = AlignType.Center;
  167. }
  168. this._ui.target.Center();
  169. }
  170. return this;
  171. }
  172. public IAlert SetTips(string message)
  173. {
  174. this.m_tips = message;
  175. if (this._ui != null)
  176. {
  177. this._ui.m_txtTips.text = m_tips;
  178. // LogUtil.LogEditor("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size);
  179. if (this._ui.m_txtTips.textHeight > this._ui.m_txtTips.textFormat.size * 2)
  180. {
  181. this._ui.m_txtTips.align = AlignType.Left;
  182. }
  183. else
  184. {
  185. this._ui.m_txtTips.align = AlignType.Center;
  186. }
  187. this._ui.target.Center();
  188. }
  189. return this;
  190. }
  191. public IAlert SetLeftButton(bool isShow, string textLeft = "取消", AlertCallback callback = null)
  192. {
  193. this.m_isShowLeftButton = isShow;
  194. this.m_leftButtonCallback = callback;
  195. this.m_textLeft = textLeft;
  196. if (this._ui != null)
  197. {
  198. this._ui.m_btnLeft.text = m_textLeft;
  199. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  200. }
  201. updateButtonPosition();
  202. return this;
  203. }
  204. public IAlert SetRightButton(bool isShow, string textRight = "确认", AlertCallback callback = null)
  205. {
  206. this.m_isShowRightButton = isShow;
  207. this.m_rightButtonCallback = callback;
  208. this.m_textRight = textRight;
  209. if (this._ui != null)
  210. {
  211. this._ui.m_btnRight.text = m_textRight;
  212. this._ui.m_btnRight.visible = m_isShowRightButton;
  213. }
  214. updateButtonPosition();
  215. return this;
  216. }
  217. public IAlert SetData(object data)
  218. {
  219. this.m_data = data;
  220. return this;
  221. }
  222. public IAlert SetClickBlankToClose(bool value)
  223. {
  224. // this.clickBlankToClose = value;
  225. return this;
  226. }
  227. private void CheckGuide(object param)
  228. {
  229. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  230. {
  231. UpdateToCheckGuide(null);
  232. }
  233. else
  234. {
  235. Timers.inst.Remove(CheckGuide);
  236. }
  237. }
  238. protected override void UpdateToCheckGuide(object param)
  239. {
  240. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  241. GuideController.TryGuide(_ui.m_btnRight.asCom, ConstGuideId.LUCKY_BOX, 3, "");
  242. }
  243. protected override void TryCompleteGuide()
  244. {
  245. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  246. if (GuideDataManager.currentGuideId == cfg.id)
  247. {
  248. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 3);
  249. GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX, 3);
  250. }
  251. }
  252. }
  253. }