AlertWindow.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. this.SetShowCheck(false);
  54. updateButtonPosition();
  55. _ui.m_btnLeft.onClick.Add(() =>
  56. {
  57. this.Hide();
  58. m_leftButtonCallback?.Invoke(m_data);
  59. });
  60. _ui.m_btnRight.onClick.Add(() =>
  61. {
  62. this.Hide();
  63. m_rightButtonCallback?.Invoke(m_data);
  64. });
  65. _ui.m_btnCheck.onClick.Add(OnBtnCheckClick);
  66. }
  67. protected override void OnShown()
  68. {
  69. base.OnShown();
  70. _ui.target.Center();
  71. Timers.inst.AddUpdate(CheckGuide);
  72. }
  73. protected override void OnHide()
  74. {
  75. base.OnHide();
  76. Timers.inst.Remove(CheckGuide);
  77. }
  78. //protected override void OnUpdate() {
  79. // base.OnUpdate();
  80. // if(this.root != null) {
  81. // int i = this.parent.GetChildIndex(this);
  82. // int iMax = this.parent.numChildren - 1;
  83. // if(i < iMax) {
  84. // this.parent.SetChildIndex(this, iMax);
  85. // }
  86. // }
  87. //}
  88. private void OnBtnCheckClick()
  89. {
  90. LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN = _ui.m_btnCheck.selected;
  91. }
  92. public IAlert SetLayer(string setlayer)
  93. {
  94. layer = setlayer;
  95. return this;
  96. }
  97. private void updateButtonPosition()
  98. {
  99. float xLeftButton = m_xLeftButton;
  100. float xRightButton = m_xRightButton;
  101. float xCenter = (m_xLeftButton + m_xRightButton) / 2;
  102. if (!m_isShowLeftButton && m_isShowRightButton)
  103. {
  104. xRightButton = xCenter;
  105. }
  106. else if (m_isShowLeftButton && !m_isShowRightButton)
  107. {
  108. xLeftButton = xCenter;
  109. }
  110. if (_ui != null)
  111. {
  112. _ui.m_btnLeft.x = xLeftButton;
  113. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  114. }
  115. if (_ui != null)
  116. {
  117. _ui.m_btnRight.x = xRightButton;
  118. this._ui.m_btnRight.visible = m_isShowRightButton;
  119. }
  120. }
  121. public IAlert Reset()
  122. {
  123. m_content = "";
  124. m_tips = "";
  125. m_textLeft = "取消";
  126. m_textRight = "确认";
  127. m_leftButtonCallback = null;
  128. m_rightButtonCallback = null;
  129. m_isShowLeftButton = false;
  130. m_isShowRightButton = false;
  131. // clickBlankToClose = false;
  132. m_data = null;
  133. if (this._ui != null)
  134. {
  135. this._ui.m_txtContent.text = m_content;
  136. }
  137. if (this._ui != null)
  138. {
  139. this._ui.m_txtTips.text = m_tips;
  140. }
  141. if (this._ui != null)
  142. {
  143. this._ui.m_btnLeft.text = m_textLeft;
  144. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  145. }
  146. if (this._ui != null)
  147. {
  148. this._ui.m_btnRight.text = m_textRight;
  149. this._ui.m_btnRight.visible = m_isShowRightButton;
  150. }
  151. updateButtonPosition();
  152. return this;
  153. }
  154. public IAlert SetMessage(string message)
  155. {
  156. this.m_content = message;
  157. if (this._ui != null)
  158. {
  159. this._ui.m_txtContent.text = m_content;
  160. // LogUtil.LogEditor("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size);
  161. if (this._ui.m_txtContent.textHeight > this._ui.m_txtContent.textFormat.size * 2)
  162. {
  163. this._ui.m_txtContent.align = AlignType.Left;
  164. }
  165. else
  166. {
  167. this._ui.m_txtContent.align = AlignType.Center;
  168. }
  169. this._ui.target.Center();
  170. }
  171. return this;
  172. }
  173. public IAlert SetTips(string message)
  174. {
  175. this.m_tips = message;
  176. if (this._ui != null)
  177. {
  178. this._ui.m_txtTips.text = m_tips;
  179. // LogUtil.LogEditor("alert height=" + this._ui.m_txtContent.textHeight + " size=" + this._ui.m_txtContent.textFormat.size);
  180. if (this._ui.m_txtTips.textHeight > this._ui.m_txtTips.textFormat.size * 2)
  181. {
  182. this._ui.m_txtTips.align = AlignType.Left;
  183. }
  184. else
  185. {
  186. this._ui.m_txtTips.align = AlignType.Center;
  187. }
  188. this._ui.target.Center();
  189. }
  190. return this;
  191. }
  192. public IAlert SetLeftButton(bool isShow, string textLeft = "取消", AlertCallback callback = null)
  193. {
  194. this.m_isShowLeftButton = isShow;
  195. this.m_leftButtonCallback = callback;
  196. this.m_textLeft = textLeft;
  197. if (this._ui != null)
  198. {
  199. this._ui.m_btnLeft.text = m_textLeft;
  200. this._ui.m_btnLeft.visible = m_isShowLeftButton;
  201. }
  202. updateButtonPosition();
  203. return this;
  204. }
  205. public IAlert SetRightButton(bool isShow, string textRight = "确认", AlertCallback callback = null)
  206. {
  207. this.m_isShowRightButton = isShow;
  208. this.m_rightButtonCallback = callback;
  209. this.m_textRight = textRight;
  210. if (this._ui != null)
  211. {
  212. this._ui.m_btnRight.text = m_textRight;
  213. this._ui.m_btnRight.visible = m_isShowRightButton;
  214. }
  215. updateButtonPosition();
  216. return this;
  217. }
  218. public IAlert SetShowCheck(bool isShow = false)
  219. {
  220. if(isShow)
  221. this._ui.m_checkType.selectedIndex = 1;
  222. else
  223. this._ui.m_checkType.selectedIndex = 0;
  224. return this;
  225. }
  226. public IAlert SetData(object data)
  227. {
  228. this.m_data = data;
  229. return this;
  230. }
  231. public IAlert SetClickBlankToClose(bool value)
  232. {
  233. // this.clickBlankToClose = value;
  234. return this;
  235. }
  236. private void CheckGuide(object param)
  237. {
  238. if (GuideDataManager.IsGuideFinish(ConstGuideId.LUCKY_BOX) <= 0)
  239. {
  240. UpdateToCheckGuide(null);
  241. }
  242. else
  243. {
  244. Timers.inst.Remove(CheckGuide);
  245. }
  246. }
  247. protected override void UpdateToCheckGuide(object param)
  248. {
  249. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  250. GuideController.TryGuide(_ui.m_btnRight.asCom, ConstGuideId.LUCKY_BOX, 3, "");
  251. }
  252. protected override void TryCompleteGuide()
  253. {
  254. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX);
  255. if (GuideDataManager.currentGuideId == cfg.id)
  256. {
  257. GuideController.TryCompleteGuideIndex(ConstGuideId.LUCKY_BOX, 3);
  258. GuideController.TryCompleteGuide(ConstGuideId.LUCKY_BOX, 3);
  259. }
  260. }
  261. }
  262. }