CreateHUD.cs 8.8 KB

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