SceneChangeFinishEvent_CreateHUD.cs 6.4 KB

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