CreateHUD.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using ET.EventType;
  2. using FairyGUI;
  3. namespace ET.Client
  4. {
  5. [Event]
  6. public class ShowHUDEventHandler : BEvent<ShowHUDEvent>
  7. {
  8. protected override async ETTask OnEvent(ShowHUDEvent _)
  9. {
  10. var view = await UIHelper.Create( "HUD" );
  11. var pgTower = view.GetChild("HPBarTower") as GProgressBar;
  12. var pgBoss1 = view.GetChild("HPBarBoss1") as GProgressBar;
  13. var pgBoss2 = view.GetChild("HPBarBoss2") as GProgressBar;
  14. var pgBoss3 = view.GetChild("HPBarBoss3") as GProgressBar;
  15. var progresslike = view.GetChild("EnergyBar") as GProgressBar;
  16. pgTower.visible = false;
  17. pgBoss1.visible = false;
  18. pgBoss2.visible = false;
  19. pgBoss3.visible = false;
  20. progresslike.visible = false;
  21. var compIcon = view.GetChild("Comp_gifticon");
  22. var compTips = view.GetChild("Comp_tips");
  23. var btn = view.GetChild("btn_start");
  24. btn.onClick.Set(() =>
  25. {
  26. btn.visible = false;
  27. compIcon.visible = false;
  28. compTips.visible = false;
  29. CameraMgr.PlayStartAnimation(() =>
  30. {
  31. compIcon.visible = true;
  32. EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.Start));
  33. }).Coroutine();
  34. });
  35. EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.ClientIsReady));
  36. }
  37. }
  38. [Event]
  39. public class SkillChangeEventHandler : BEvent<SkillChangeEvent>
  40. {
  41. protected override async ETTask OnEvent(SkillChangeEvent a)
  42. {
  43. Log.Debug("actor's skill changed.");
  44. /*var view = UIHelper.GetUI("HUD") as GComponent;
  45. if(view != null)
  46. {
  47. HUDMgr.InitView(view);
  48. }*/
  49. await ETTask.CompletedTask;
  50. }
  51. }
  52. [Event]
  53. public class HPRefreshEventHandler : BEvent<HPRefresh>
  54. {
  55. GProgressBar pgTower;
  56. GProgressBar pgBoss1;
  57. GProgressBar pgBoss2;
  58. GProgressBar pgBoss3;
  59. GProgressBar pgTKLike;
  60. protected override async ETTask OnEvent(HPRefresh a)
  61. {
  62. var view = UIHelper.GetUI("HUD") as GComponent;
  63. if (view != null)
  64. {
  65. GProgressBar progress = null;
  66. switch (a.HPIndex)
  67. {
  68. case HPRefresh.Index.Tower:
  69. if (pgTower == null)
  70. {
  71. pgTower = view.GetChild("HPBarTower").asProgress;
  72. }
  73. progress = pgTower;
  74. break;
  75. case HPRefresh.Index.Boss1:
  76. if (pgBoss1 == null)
  77. {
  78. pgBoss1 = view.GetChild("HPBarBoss1").asProgress;
  79. }
  80. progress = pgBoss1;
  81. break;
  82. case HPRefresh.Index.Boss2:
  83. if (pgBoss2 == null)
  84. {
  85. pgBoss2 = view.GetChild("HPBarBoss2").asProgress;
  86. }
  87. progress = pgBoss2;
  88. break;
  89. case HPRefresh.Index.Boss3:
  90. if (pgBoss3 == null)
  91. {
  92. pgBoss3 = view.GetChild("HPBarBoss3").asProgress;
  93. }
  94. progress = pgBoss3;
  95. break;
  96. case HPRefresh.Index.TiktokLike:
  97. if (pgTKLike == null)
  98. {
  99. pgTKLike = view.GetChild("EnergyBar").asProgress;
  100. }
  101. progress = pgTKLike;
  102. break;
  103. }
  104. progress.visible = a.Visible;
  105. if (a.Visible)
  106. {
  107. progress.value = a.Progress;
  108. var name = progress.GetChild("name");
  109. if (name != null)
  110. {
  111. name.text = a.Name;
  112. }
  113. var txt = progress.GetChild("title");
  114. if (txt != null)
  115. {
  116. txt.text = a.Title;
  117. }
  118. }
  119. }
  120. await ETTask.CompletedTask;
  121. }
  122. }
  123. [Event]
  124. public class RankEventHandler : BEvent<RankChangeEvent>
  125. {
  126. protected override async ETTask OnEvent(RankChangeEvent a)
  127. {
  128. var view = UIHelper.GetUI("HUD") as GComponent;
  129. if (view == null) return;
  130. var list = view.GetChild("list_rank").asList;
  131. if (list == null) return;
  132. list.visible = a.InfoList != null && a.InfoList.Count > 0;
  133. if(list.visible)
  134. {
  135. int i = 0;
  136. for (; i<a.InfoList.Count; i++)
  137. {
  138. var chd = list.GetChildAt(i).asCom;
  139. if(chd == null)
  140. {
  141. Log.Error($"rank list child not exist: {i}");
  142. continue;
  143. }
  144. var txt = chd.GetChild("text");
  145. txt.text = a.InfoList[i].Name;
  146. chd.visible = true;
  147. }
  148. for(; i < 3; i++)
  149. {
  150. var chd = list.GetChildAt(i);
  151. if(chd != null)
  152. {
  153. chd.visible = false;
  154. }
  155. }
  156. }
  157. await ETTask.CompletedTask;
  158. }
  159. }
  160. [Event]
  161. public class ShowUIAnimationHandler : BEvent<ShowUIAnimation>
  162. {
  163. protected override async ETTask OnEvent(ShowUIAnimation a)
  164. {
  165. var view = UIHelper.GetUI("HUD") as GComponent;
  166. if (view == null) return;
  167. switch(a.Type)
  168. {
  169. case ShowUIAnimation.AniType.Gift:
  170. var trans = view.GetTransition($"t_gift_00{a.Param1}");
  171. if (trans != null)
  172. {
  173. trans.Play();
  174. }
  175. else
  176. {
  177. Log.Error($"NotFound UIAni: {a.Type},{a.Param1}");
  178. }
  179. break;
  180. case ShowUIAnimation.AniType.Monster:
  181. trans = view.GetTransition("t_warning");
  182. trans.Play();
  183. trans = view.GetTransition($"t_warning_00{a.Param1}");
  184. if (trans != null)
  185. {
  186. trans.Play();
  187. }
  188. else
  189. {
  190. Log.Error($"NotFound UIAni: {a.Type},{a.Param1}");
  191. }
  192. break;
  193. case ShowUIAnimation.AniType.Tower:
  194. trans = view.GetTransition("t_help");
  195. trans.Play();
  196. break;
  197. case ShowUIAnimation.AniType.LikeEnergy:
  198. trans = view.GetTransition("t_help");
  199. trans.Play();
  200. break;
  201. default:
  202. Log.Error($"unknow ui animation: {a.Type}");
  203. break;
  204. }
  205. await ETTask.CompletedTask;
  206. }
  207. }
  208. [Event]
  209. public class ShowOrHideHeadBarHandler : BEvent<ShowOrHideHeadBar>
  210. {
  211. protected override async ETTask OnEvent(ShowOrHideHeadBar a)
  212. {
  213. if(a != null)
  214. {
  215. GlobalViewMgr.Instance.HeadbarView.visible = a.Flag;
  216. }
  217. else
  218. {
  219. GlobalViewMgr.Instance.HeadbarView.visible = !GlobalViewMgr.Instance.HeadbarView.visible;
  220. }
  221. await ETTask.CompletedTask;
  222. }
  223. }
  224. [Event]
  225. public class SoundMuteEventHandler : BEvent<SoundMuteEvent>
  226. {
  227. protected override async ETTask OnEvent(SoundMuteEvent a)
  228. {
  229. bool isMute = SoundManager.Instance.UnityAudioSource.mute;
  230. if (a != null)
  231. {
  232. isMute = a.Flag;
  233. }
  234. else
  235. {
  236. isMute = !isMute;
  237. }
  238. SoundManager.Instance.UnityAudioSource.mute = isMute;
  239. GameSetting.Instance.SetBool(GameSetting.Sets.Mute_int, isMute);
  240. await ETTask.CompletedTask;
  241. }
  242. }
  243. }