CreateHUD.cs 9.2 KB

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