123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- using ET.EventType;
- using FairyGUI;
- namespace ET.Client
- {
- [Event]
- public class SceneChangeFinishEvent_CreateUIHelp : BEvent<ShowHUDEvent>
- {
- protected override async ETTask OnEvent(ShowHUDEvent _)
- {
- var view = await UIHelper.Create( "HUD" );
- HUDMgr.InitView( view );
- }
- }
- [Event]
- public class SkillChangeEventHandler : BEvent<SkillChangeEvent>
- {
- protected override async ETTask OnEvent(SkillChangeEvent a)
- {
- Log.Debug("actor's skill changed.");
- /*var view = UIHelper.GetUI("HUD") as GComponent;
- if(view != null)
- {
- HUDMgr.InitView(view);
- }*/
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class HPRefreshEventHandler : BEvent<HPRefresh>
- {
- GProgressBar progressBar1;
- GProgressBar progressBar2;
- GTextField txt1;
- GTextField txt2;
- protected override async ETTask OnEvent(HPRefresh a)
- {
- var view = UIHelper.GetUI("HUD") as GComponent;
- if (view != null)
- {
- GProgressBar progress = null;
- GTextField txt = null;
- if (a.HPIndex == HPRefresh.Index.Tower)
- {
- if (progressBar1 == null)
- {
- progressBar1 = view.GetChild("HPBar1").asProgress;
- txt1 = progressBar1.GetChild("title").asTextField;
- }
- progress = progressBar1;
- txt = txt1;
- }
- else
- {
- if (progressBar2 == null)
- {
- progressBar2 = view.GetChild("HPBar2").asProgress;
- txt2 = progressBar2.GetChild("title").asTextField;
- }
- progress = progressBar2;
- txt = txt2;
- }
- progress.visible = true;
- progress.value = a.Progress;
- txt.text = a.Progress.ToString("F2") + "%";
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class RankEventHandler : BEvent<RankChangeEvent>
- {
- protected override async ETTask OnEvent(RankChangeEvent a)
- {
- var view = UIHelper.GetUI("HUD") as GComponent;
- if (view == null) return;
- var list = view.GetChild("list_rank").asList;
- if (list == null) return;
- list.visible = a.InfoList != null && a.InfoList.Count > 0;
- if(list.visible)
- {
- int i = 0;
- for (; i<a.InfoList.Count; i++)
- {
- var chd = list.GetChildAt(i).asCom;
- if(chd == null)
- {
- Log.Error($"rank list child not exist: {i}");
- continue;
- }
- var txt = chd.GetChild("text");
- txt.text = a.InfoList[i].Name;
- chd.visible = true;
- }
- for(; i < 3; i++)
- {
- var chd = list.GetChildAt(i);
- if(chd != null)
- {
- chd.visible = false;
- }
- }
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class BattleMsgHandler : BEvent<BattleMsgEvent>
- {
- int CurIndex = 0;
- protected override async ETTask OnEvent(BattleMsgEvent a)
- {
- var view = UIHelper.GetUI("HUD") as GComponent;
- if (view != null)
- {
- var list = view.GetChild("InfoList").asList;
- if (CurIndex >= list.numChildren)
- {
- CurIndex = 0;
- }
- var comp = list.GetChildAt(CurIndex).asCom;
- var txt = comp.GetChild("text");
- txt.text = a.msg;
- ++CurIndex;
- }
- await ETTask.CompletedTask;
- }
- }
- /*[Event]
- public class CameraOkHandler : BEvent<CameraOkEvent>
- {
- protected override async ETTask OnEvent(CameraOkEvent a)
- {
- var view = UIHelper.GetUI("HUD") as GComponent;
- view.GetChild("btn_start").visible = true;
- await ETTask.CompletedTask;
- }
- }*/
-
- public static class HUDMgr
- {
- public static void InitView(GComponent view)
- {
- /*var btn1 = view.GetChild("btn_skill1");
- var btn2 = view.GetChild("btn_skill2");
- var actor = UnitMgr.Instance.Actor;
- if (actor == null || !actor.IsSkillOk)
- {
- btn1.visible = false;
- btn2.visible = false;
- return;
- }
- btn1.visible = actor.GetSkill(0) != null;
- btn2.visible = actor.GetSkill(1) != null;
- var img = view.GetChild("img_direction");
- btn1.onClick.Set(() => {
- EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(0)) ;
- });
- btn2.onClick.Set(() => {
- EventSystem.Instance.Publish<LaunchSkillEvent>(LaunchSkillEvent.Static.Clone(1));
- });
- btn1.visible = false;
- btn2.visible = false;
- for (int i=1; i<= 99; i++)
- {
- var btn = view.GetChild($"btn_func{i}");
- if (btn == null) break;
- var index = i;
- btn.onClick.Set(() =>
- {
- if(index == 1)
- {
- GlobalViewMgr.Instance.HeadbarView.visible = !GlobalViewComponent.Instance.HeadbarView.visible;
- return;
- }
- EventSystem.Instance.Publish<BattleFunc>(BattleFunc.Static.Clone(index));
- });
- }
- bool isMute = SoundManager.Instance.UnityAudioSource.mute;
- var btnmute = view.GetChild("btn_mute");
- var gou = (btnmute as GComponent).GetChild("checked");
- gou.visible = isMute;
- btnmute.onClick.Set(() =>
- {
- isMute = !isMute;
- gou.visible = isMute;
- SoundManager.Instance.UnityAudioSource.mute = isMute;
- GameSetting.Instance.SetBool(GameSetting.Sets.Mute_int, isMute);
- });*/
- var progress1 = view.GetChild("HPBar1") as GProgressBar;
- var progress2 = view.GetChild("HPBar2") as GProgressBar;
- progress1.visible = progress2.visible = false;
- var txthp1 = progress1.GetChild("title");
- txthp1.text = "";
- var txthp2 = progress2.GetChild("title");
- txthp2.text = "";
- var btn = view.GetChild("btn_start");
- btn.onClick.Set( () => {
- btn.visible = false;
- EventSystem.Instance.Publish(BattleFunc.Static.Clone((int)BattleFunc.FUNC.Start));
- });
- }
- }
- }
|