CreateHUD.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. if (flag)
  67. {
  68. GlobalViewMgr.Instance.HeadbarView.visible = true;
  69. }
  70. EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.Start));
  71. }).Coroutine();
  72. });
  73. EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.ClientIsReady));
  74. }
  75. }
  76. [Event]
  77. public class HPRefreshEventHandler : BEvent<HPRefresh>
  78. {
  79. protected override async ETTask OnEvent(HPRefresh a)
  80. {
  81. if (UIHelper.GetUI("HUD") == null)
  82. {
  83. return;
  84. }
  85. GProgressBar progress = null;
  86. switch (a.HPIndex)
  87. {
  88. case HPRefresh.Index.Tower:
  89. progress = HUDComonent.pgTower;
  90. HUDComonent.pgTKLike.visible = a.Visible;
  91. break;
  92. case HPRefresh.Index.Boss1:
  93. progress = HUDComonent.pgBoss1;
  94. break;
  95. case HPRefresh.Index.Boss2:
  96. progress = HUDComonent.pgBoss2;
  97. break;
  98. case HPRefresh.Index.Boss3:
  99. progress = HUDComonent.pgBoss3;
  100. break;
  101. case HPRefresh.Index.Boss4:
  102. progress = HUDComonent.pgBoss4;
  103. break;
  104. case HPRefresh.Index.TiktokLike:
  105. progress = HUDComonent.pgTKLike;
  106. break;
  107. }
  108. progress.visible = a.Visible;
  109. if (a.Visible)
  110. {
  111. progress.value = a.Progress;
  112. var name = progress.GetChild("name");
  113. if (name != null)
  114. {
  115. name.text = a.Name;
  116. }
  117. var txt = progress.GetChild("title");
  118. if (txt != null)
  119. {
  120. txt.text = a.Title;
  121. }
  122. }
  123. await ETTask.CompletedTask;
  124. }
  125. }
  126. [Event]
  127. public class RankEventHandler : BEvent<RankChangeEvent>
  128. {
  129. protected override async ETTask OnEvent(RankChangeEvent a)
  130. {
  131. if (UIHelper.GetUI("HUD") == null)
  132. {
  133. return;
  134. }
  135. var list = HUDComonent.listRank;
  136. if (list == null) return;
  137. for (int i = 0; i < a.InfoList.Count && i < list.numChildren; i++)
  138. {
  139. var chd = list.GetChildAt(i).asCom;
  140. if(chd == null)
  141. {
  142. return;
  143. }
  144. var txt = chd.GetChild("text");
  145. txt.text = a.InfoList[i].Name;
  146. var mask = chd.GetChild("compIcon").asCom;
  147. var icon = mask.GetChild("iconLoader").asLoader;
  148. var url = a.InfoList[i].Url;
  149. if (!string.IsNullOrEmpty(url))
  150. {
  151. LoadHeadIcon(icon, url).Coroutine();
  152. }
  153. chd.visible = true;
  154. }
  155. for(int i = a.InfoList.Count; i < list.numChildren; i++)
  156. {
  157. var chd = list.GetChildAt(i);
  158. if(chd != null)
  159. {
  160. chd.visible = false;
  161. }
  162. }
  163. await ETTask.CompletedTask;
  164. }
  165. private async ETTask LoadHeadIcon(GLoader loader, string url)
  166. {
  167. var tex = await UrlImageLoader.Instance.LoadImage(url);
  168. if (tex != null)
  169. {
  170. if (GRoot.inst.GetChild("HUD") != null)
  171. {
  172. loader.texture = new NTexture(tex);
  173. }
  174. }
  175. }
  176. }
  177. [Event]
  178. public class ShowUIAnimationHandler : BEvent<ShowUIAnimation>
  179. {
  180. protected override async ETTask OnEvent(ShowUIAnimation a)
  181. {
  182. if (UIHelper.GetUI("HUD") == null)
  183. {
  184. return;
  185. }
  186. var view = HUDComonent.Root;
  187. if (view == null) return;
  188. switch(a.Type)
  189. {
  190. case ShowUIAnimation.AniType.Monster:
  191. var trans = view.GetTransition("t_warning");
  192. trans.Play();
  193. trans = view.GetTransition($"t_warning_00{a.Param1}");
  194. if (trans != null)
  195. {
  196. trans.Play();
  197. }
  198. else
  199. {
  200. Log.Error($"NotFound UIAni: {a.Type},{a.Param1}");
  201. }
  202. break;
  203. case ShowUIAnimation.AniType.Tower:
  204. if (a.Param1 == 0)
  205. {
  206. view.GetTransition("t_help").Play();
  207. }
  208. else if (a.Param1 == 1)
  209. {
  210. view.GetTransition("t_jiayuangaoji").Play();
  211. }
  212. break;
  213. case ShowUIAnimation.AniType.LikeEnergy:
  214. HUDComonent.pgTKLike.visible = true;
  215. HUDComonent.pgTKLike.value = a.Param1;
  216. trans = HUDComonent.pgTKLike.GetTransition("t0");
  217. trans.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. }