CreateHUD.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using ET.EventType;
  2. using FairyGUI;
  3. namespace ET.Client
  4. {
  5. [Event]
  6. public class SceneChangeFinishEvent_CreateUIHelp : BEvent<ShowHUDEvent>
  7. {
  8. protected override async ETTask OnEvent(ShowHUDEvent _)
  9. {
  10. var view = await UIHelper.Create( "HUD" );
  11. HUDMgr.InitView( view );
  12. }
  13. }
  14. [Event]
  15. public class SkillChangeEventHandler : BEvent<SkillChangeEvent>
  16. {
  17. protected override async ETTask OnEvent(SkillChangeEvent a)
  18. {
  19. Log.Debug("actor's skill changed.");
  20. /*var view = UIHelper.GetUI("HUD") as GComponent;
  21. if(view != null)
  22. {
  23. HUDMgr.InitView(view);
  24. }*/
  25. await ETTask.CompletedTask;
  26. }
  27. }
  28. [Event]
  29. public class HPRefreshEventHandler : BEvent<HPRefresh>
  30. {
  31. GProgressBar progressBar1;
  32. GProgressBar progressBar2;
  33. GTextField txt1;
  34. GTextField txt2;
  35. protected override async ETTask OnEvent(HPRefresh a)
  36. {
  37. var view = UIHelper.GetUI("HUD") as GComponent;
  38. if (view != null)
  39. {
  40. GProgressBar progress = null;
  41. GTextField txt = null;
  42. if (a.HPIndex == HPRefresh.Index.Tower)
  43. {
  44. if (progressBar1 == null)
  45. {
  46. progressBar1 = view.GetChild("HPBar1").asProgress;
  47. txt1 = progressBar1.GetChild("title").asTextField;
  48. }
  49. progress = progressBar1;
  50. txt = txt1;
  51. }
  52. else
  53. {
  54. if (progressBar2 == null)
  55. {
  56. progressBar2 = view.GetChild("HPBar2").asProgress;
  57. txt2 = progressBar2.GetChild("title").asTextField;
  58. }
  59. progress = progressBar2;
  60. txt = txt2;
  61. }
  62. progress.visible = true;
  63. progress.value = a.Progress;
  64. txt.text = a.Progress.ToString("F2") + "%";
  65. }
  66. await ETTask.CompletedTask;
  67. }
  68. }
  69. [Event]
  70. public class RankEventHandler : BEvent<RankChangeEvent>
  71. {
  72. protected override async ETTask OnEvent(RankChangeEvent a)
  73. {
  74. var view = UIHelper.GetUI("HUD") as GComponent;
  75. if (view == null) return;
  76. var list = view.GetChild("list_rank").asList;
  77. if (list == null) return;
  78. list.visible = a.InfoList != null && a.InfoList.Count > 0;
  79. if(list.visible)
  80. {
  81. int i = 0;
  82. for (; i<a.InfoList.Count; i++)
  83. {
  84. var chd = list.GetChildAt(i).asCom;
  85. if(chd == null)
  86. {
  87. Log.Error($"rank list child not exist: {i}");
  88. continue;
  89. }
  90. var txt = chd.GetChild("text");
  91. txt.text = a.InfoList[i].Name;
  92. chd.visible = true;
  93. }
  94. for(; i < 3; i++)
  95. {
  96. var chd = list.GetChildAt(i);
  97. if(chd != null)
  98. {
  99. chd.visible = false;
  100. }
  101. }
  102. }
  103. await ETTask.CompletedTask;
  104. }
  105. }
  106. [Event]
  107. public class BattleMsgHandler : BEvent<BattleMsgEvent>
  108. {
  109. int CurIndex = 0;
  110. protected override async ETTask OnEvent(BattleMsgEvent a)
  111. {
  112. var view = UIHelper.GetUI("HUD") as GComponent;
  113. if (view != null)
  114. {
  115. var list = view.GetChild("InfoList").asList;
  116. if (CurIndex >= list.numChildren)
  117. {
  118. CurIndex = 0;
  119. }
  120. var comp = list.GetChildAt(CurIndex).asCom;
  121. var txt = comp.GetChild("text");
  122. txt.text = a.msg;
  123. ++CurIndex;
  124. }
  125. await ETTask.CompletedTask;
  126. }
  127. }
  128. /*[Event]
  129. public class CameraOkHandler : BEvent<CameraOkEvent>
  130. {
  131. protected override async ETTask OnEvent(CameraOkEvent a)
  132. {
  133. var view = UIHelper.GetUI("HUD") as GComponent;
  134. view.GetChild("btn_start").visible = true;
  135. await ETTask.CompletedTask;
  136. }
  137. }*/
  138. public static class HUDMgr
  139. {
  140. public static void InitView(GComponent view)
  141. {
  142. /*var btn1 = view.GetChild("btn_skill1");
  143. var btn2 = view.GetChild("btn_skill2");
  144. var actor = UnitMgr.Instance.Actor;
  145. if (actor == null || !actor.IsSkillOk)
  146. {
  147. btn1.visible = false;
  148. btn2.visible = false;
  149. return;
  150. }
  151. btn1.visible = actor.GetSkill(0) != null;
  152. btn2.visible = actor.GetSkill(1) != null;
  153. var img = view.GetChild("img_direction");
  154. btn1.onClick.Set(() => {
  155. EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(0)) ;
  156. });
  157. btn2.onClick.Set(() => {
  158. EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(1));
  159. });
  160. btn1.visible = false;
  161. btn2.visible = false;
  162. for (int i=1; i<= 99; i++)
  163. {
  164. var btn = view.GetChild($"btn_func{i}");
  165. if (btn == null) break;
  166. var index = i;
  167. btn.onClick.Set(() =>
  168. {
  169. if(index == 1)
  170. {
  171. GlobalViewMgr.Instance.HeadbarView.visible = !GlobalViewComponent.Instance.HeadbarView.visible;
  172. return;
  173. }
  174. EventSystem.Instance.Publish<BattleFunc>(BattleFunc.Static.Clone(index));
  175. });
  176. }
  177. bool isMute = SoundManager.Instance.UnityAudioSource.mute;
  178. var btnmute = view.GetChild("btn_mute");
  179. var gou = (btnmute as GComponent).GetChild("checked");
  180. gou.visible = isMute;
  181. btnmute.onClick.Set(() =>
  182. {
  183. isMute = !isMute;
  184. gou.visible = isMute;
  185. SoundManager.Instance.UnityAudioSource.mute = isMute;
  186. GameSetting.Instance.SetBool(GameSetting.Sets.Mute_int, isMute);
  187. });*/
  188. var progress1 = view.GetChild("HPBar1") as GProgressBar;
  189. var progress2 = view.GetChild("HPBar2") as GProgressBar;
  190. progress1.visible = progress2.visible = false;
  191. var txthp1 = progress1.GetChild("title");
  192. txthp1.text = "";
  193. var txthp2 = progress2.GetChild("title");
  194. txthp2.text = "";
  195. var btn = view.GetChild("btn_start");
  196. btn.onClick.Set( () => {
  197. btn.visible = false;
  198. EventSystem.Instance.Publish(BattleFunc.Static.Clone((int)BattleFunc.FUNC.Start));
  199. });
  200. }
  201. }
  202. }