CreateHUD.cs 11 KB

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