AlertWindow.cs 9.0 KB

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