123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- using ET.EventType;
- using FairyGUI;
- using System.Collections.Generic;
- using UnityEngine;
- namespace ET.Client
- {
- public class HUDComonent
- {
- public static GComponent Root;
- public static GProgressBar pgTower;
- public static GProgressBar pgBoss1;
- public static GProgressBar pgBoss2;
- public static GProgressBar pgBoss3;
- public static GProgressBar pgBoss4;
- public static GProgressBar pgTKLike;
- public static GList listRank;
- public static GComponent[,] listGift = new GComponent[4,6];
- }
- [Event]
- public class ShowHUDEventHandler : BEvent<ShowHUDEvent>
- {
- protected override async ETTask OnEvent(ShowHUDEvent _)
- {
- var view = await UIHelper.Create( "HUD" );
- HUDComonent.Root = view;
- HUDComonent.pgTower = view.GetChild("HPBarTower") as GProgressBar;
- HUDComonent.pgBoss1 = view.GetChild("HPBarBoss1") as GProgressBar;
- HUDComonent.pgBoss2 = view.GetChild("HPBarBoss2") as GProgressBar;
- HUDComonent.pgBoss3 = view.GetChild("HPBarBoss3") as GProgressBar;
- HUDComonent.pgBoss4 = view.GetChild("HPBarBoss4") as GProgressBar;
- HUDComonent.pgTKLike = view.GetChild("EnergyBar") as GProgressBar;
- HUDComonent.listRank = view.GetChild("list_rank").asList;
- for( int i = 1; i <= 4; i++ )
- {
- for (int j = 1; j <= 6; j++)
- {
- HUDComonent.listGift[i-1, j-1] = view.GetChild($"CompGift{i}{j}").asCom;
- }
- }
- for (int i = 0; i < HUDComonent.listRank.numChildren; i++)
- {
- HUDComonent.listRank.GetChildAt(i).visible = false;
- }
- HUDComonent.listRank.visible = false;
- HUDComonent.pgTower.visible = false;
- HUDComonent.pgBoss1.visible = false;
- HUDComonent.pgBoss2.visible = false;
- HUDComonent.pgBoss3.visible = false;
- HUDComonent.pgBoss4.visible = false;
- HUDComonent.pgTKLike.visible = false;
- HUDComonent.pgTKLike.value = 0;
- var compIcon = view.GetChild("CompGifticon");
- var compTips = view.GetChild("CompTips");
- var btn = view.GetChild("btn_start");
- btn.onClick.Set(() =>
- {
- btn.visible = false;
- compIcon.visible = false;
- compTips.visible = false;
- HUDComonent.listRank.visible = false;
- bool flag = GlobalViewMgr.Instance.HeadbarView.visible;
- if (flag)
- {
- GlobalViewMgr.Instance.HeadbarView.visible = false;
- }
- CameraMgr.PlayStartAnimation(() =>
- {
- compIcon.visible = true;
- HUDComonent.listRank.visible = true;
- HUDComonent.pgTKLike.visible = true;
- if (flag)
- {
- GlobalViewMgr.Instance.HeadbarView.visible = true;
- }
- EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.Start));
- }).Coroutine();
- });
- EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.ClientIsReady));
- }
- }
- [Event]
- public class HPRefreshEventHandler : BEvent<HPRefresh>
- {
- protected override async ETTask OnEvent(HPRefresh a)
- {
- if (UIHelper.GetUI("HUD") == null)
- {
- return;
- }
- GProgressBar progress = null;
- switch (a.HPIndex)
- {
- case HPRefresh.Index.Tower:
- progress = HUDComonent.pgTower;
- HUDComonent.pgTKLike.visible = a.Visible;
- break;
- case HPRefresh.Index.Boss1:
- progress = HUDComonent.pgBoss1;
- break;
- case HPRefresh.Index.Boss2:
- progress = HUDComonent.pgBoss2;
- break;
- case HPRefresh.Index.Boss3:
- progress = HUDComonent.pgBoss3;
- break;
- case HPRefresh.Index.Boss4:
- progress = HUDComonent.pgBoss4;
- break;
- case HPRefresh.Index.TiktokLike:
- progress = HUDComonent.pgTKLike;
- break;
- default:
- Log.Error($"unkown hp bar: {a.HPIndex}");
- return;
- }
-
- progress.visible = a.Visible;
- if (a.Visible)
- {
- progress.value = a.Progress;
- var name = progress.GetChild("name");
- if (name != null)
- {
- name.text = a.Name;
- }
- var txt = progress.GetChild("title");
- if (txt != null)
- {
- txt.text = a.Title;
- }
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class RankEventHandler : BEvent<RankChangeEvent>
- {
- protected override async ETTask OnEvent(RankChangeEvent a)
- {
- if (UIHelper.GetUI("HUD") == null)
- {
- return;
- }
- var list = HUDComonent.listRank;
- if (list == null) return;
- List < ET.RankInfo > datalist = a.InfoList ?? new List<ET.RankInfo>();
- for (int i = 0; i < datalist.Count && i < list.numChildren; i++)
- {
- var chd = list.GetChildAt(i).asCom;
- if(chd == null)
- {
- return;
- }
- var txt = chd.GetChild("text");
- txt.text = datalist[i].Name;
- var mask = chd.GetChild("compIcon").asCom;
- var icon = mask.GetChild("iconLoader").asLoader;
- var url = datalist[i].Url;
- if (!string.IsNullOrEmpty(url))
- {
- LoadHeadIcon(icon, url).Coroutine();
- }
- chd.visible = true;
- }
- for(int i = datalist.Count; i < list.numChildren; i++)
- {
- var chd = list.GetChildAt(i);
- if(chd != null)
- {
- chd.visible = false;
- }
- }
- await ETTask.CompletedTask;
- }
- private async ETTask LoadHeadIcon(GLoader loader, string url)
- {
- var tex = await UrlImageLoader.Instance.LoadImage(url);
- if (tex != null)
- {
- if (GRoot.inst.GetChild("HUD") != null)
- {
- loader.texture = new NTexture(tex);
- }
- }
- }
- }
- [Event]
- public class ShowUIAnimationHandler : BEvent<ShowUIAnimation>
- {
- private static bool bPlayingLikes = false;
- protected override async ETTask OnEvent(ShowUIAnimation a)
- {
- if (UIHelper.GetUI("HUD") == null)
- {
- return;
- }
- var view = HUDComonent.Root;
- if (view == null) return;
- switch(a.Type)
- {
- case ShowUIAnimation.AniType.Monster:
- var trans = view.GetTransition("t_warning");
- trans.Play();
- trans = view.GetTransition($"t_warning_00{a.Param1}");
- if (trans != null)
- {
- trans.Play();
- }
- else
- {
- Log.Error($"NotFound UIAni: {a.Type},{a.Param1}");
- }
- break;
- case ShowUIAnimation.AniType.Tower:
- if (a.Param1 == 0)
- {
- view.GetTransition("t_help").Play();
- }
- else if (a.Param1 == 1)
- {
- view.GetTransition("t_jiayuangaoji").Play();
- }
- break;
- case ShowUIAnimation.AniType.LikeEnergy:
- HUDComonent.pgTKLike.value = a.Param1;
- if (bPlayingLikes) return;
- bPlayingLikes = true;
- HUDComonent.pgTKLike.GetTransition("t0").Play();
- view.GetTransition("+1").Play(() => { bPlayingLikes = false; });
- break;
- default:
- Log.Error($"unknow ui animation: {a.Type}");
- break;
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class TiktokGiftEventHandler : BEvent<TiktokGiftEvent>
- {
- private static List<TiktokGiftEvent> Pool = new() { };
- private static List<TiktokGiftEvent> playlist = new();
- private static List<string> idlelist = new() { "t_gift_1", "t_gift_2", "t_gift_3", "t_gift_4" };
- public static void Reset()
- {
- idlelist.Clear();
- idlelist.Add("t_gift_1");
- idlelist.Add("t_gift_2");
- idlelist.Add("t_gift_3");
- idlelist.Add("t_gift_4");
- }
- protected override async ETTask OnEvent(TiktokGiftEvent a)
- {
- if (UIHelper.GetUI("HUD") == null)
- {
- return;
- }
- TiktokGiftEvent ob = null;
- if (Pool.Count > 0)
- {
- ob = Pool[0];
- Pool.RemoveAt(0);
- }
- else
- {
- ob = new TiktokGiftEvent();
- }
- ob.nickname = a.nickname;
- ob.avatar = a.avatar;
- ob.index = a.index;
- ob.num = a.num;
- if (idlelist.Count == 0)
- {
- playlist.Add(ob);
- return;
- }
- string workani = idlelist[0];
- idlelist.RemoveAt(0);
- int workindex = workani[7] - '1';
- var comp = HUDComonent.listGift[workindex, ob.index - 1];
- comp.GetChild("Text1").text = ob.nickname;
- comp.GetChild("Text2").text = "X" + ob.num;
- var mask = comp.GetChild("n0").asCom;
- var icon = mask.GetChild("iconLoader").asLoader;
- var url = ob.avatar;
- if (!string.IsNullOrEmpty(url))
- {
- LoadHeadIcon(icon, url).Coroutine();
- }
- HUDComonent.Root.GetTransition($"{workani}{ob.index}").Play(() =>
- {
- Pool.Add(ob);
- idlelist.Add(workani);
- if(playlist.Count >0)
- {
- var toplay = playlist[0];
- playlist.RemoveAt(0);
- OnEvent(toplay).Coroutine();
- }
- });
- await ETTask.CompletedTask;
- }
- private async ETTask LoadHeadIcon(GLoader loader, string url)
- {
- var tex = await UrlImageLoader.Instance.LoadImage(url);
- if (tex != null)
- {
- if (GRoot.inst.GetChild("HUD") != null)
- {
- loader.texture = new NTexture(tex);
- }
- }
- }
- }
- [Event]
- public class ShowOrHideHeadBarHandler : BEvent<ShowOrHideHeadBar>
- {
- protected override async ETTask OnEvent(ShowOrHideHeadBar a)
- {
- if(a != null)
- {
- GlobalViewMgr.Instance.HeadbarView.visible = a.Flag;
- }
- else
- {
- GlobalViewMgr.Instance.HeadbarView.visible = !GlobalViewMgr.Instance.HeadbarView.visible;
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class SoundMuteEventHandler : BEvent<SoundMuteEvent>
- {
- protected override async ETTask OnEvent(SoundMuteEvent a)
- {
- bool isMute = SoundManager.Instance.UnityAudioSource.mute;
- if (a != null)
- {
- isMute = a.Flag;
- }
- else
- {
- isMute = !isMute;
- }
- SoundManager.Instance.UnityAudioSource.mute = isMute;
- GameSetting.Instance.SetBool(GameSetting.Sets.Mute_int, isMute);
- await ETTask.CompletedTask;
- }
- }
- }
|