CreateHUD.cs 12 KB

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