UIStartFightRoomComponentSystem.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using UnityEngine;
  6. using UnityEngine.PlayerLoop;
  7. using UnityEngine.UI;
  8. using static System.Net.Mime.MediaTypeNames;
  9. namespace ET.Client
  10. {
  11. #region 战斗推送相关
  12. [Event(SceneType.Client)]
  13. public class JoinRoomPush_AddComponent : AEvent<EventType.JoinRoomPush>
  14. {
  15. protected override async ETTask Run(Scene scene, EventType.JoinRoomPush args)
  16. {
  17. Log.Error("@@@ 刷新加入房间状态");
  18. CommonBridge.Instance.SetDispathPush(scene,args);
  19. }
  20. }
  21. [Event(SceneType.Client)]
  22. public class KickPush_AddComponent : AEvent<EventType.KickPush>
  23. {
  24. protected override async ETTask Run(Scene scene, EventType.KickPush args)
  25. {
  26. Log.Error("@@@ 刷新T人之后 房间状态");
  27. CommonBridge.Instance.SetDispathPush(scene,args);
  28. }
  29. }
  30. [Event(SceneType.Client)]
  31. public class ReadyPush_AddComponent : AEvent<EventType.ReadyPush>
  32. {
  33. protected override async ETTask Run(Scene scene, EventType.ReadyPush args)
  34. {
  35. Log.Error("@@@ 刷新准备之后 房间状态");
  36. CommonBridge.Instance.SetDispathPush(scene, args);
  37. }
  38. }
  39. //都准备之后 开始倒计时推送
  40. [Event(SceneType.Client)]
  41. public class ReadyStartPush_AddComponent : AEvent<EventType.ReadyStartPush>
  42. {
  43. protected override async ETTask Run(Scene scene, EventType.ReadyStartPush args)
  44. {
  45. Log.Error("@@@ 刷新准备之后 房间状态");
  46. CommonBridge.Instance.SetDispathPush(scene, args);
  47. }
  48. }
  49. //正式开始 发牌
  50. [Event(SceneType.Client)]
  51. public class GameStartPush_AddComponent : AEvent<EventType.GameStartPush>
  52. {
  53. protected override async ETTask Run(Scene scene, EventType.GameStartPush args)
  54. {
  55. Log.Error("@@@ 正式开始 发牌");
  56. CommonBridge.Instance.SetDispathPush(scene, args);
  57. }
  58. }
  59. //玩家摸牌
  60. [Event(SceneType.Client)]
  61. public class GameDrawCardPush_AddComponent : AEvent<EventType.GameDrawCardPush>
  62. {
  63. protected override async ETTask Run(Scene scene, EventType.GameDrawCardPush args)
  64. {
  65. Log.Error("@@@ 玩家摸牌");
  66. CommonBridge.Instance.SetDispathPush(scene, args);
  67. }
  68. }
  69. #endregion
  70. #region 定时器 刷新
  71. [Invoke(TimerInvokeType.fightTimeShow)]
  72. public class UIStartFightRoomComponentChecker : ATimer<UIStartFightRoomComponent>
  73. {
  74. protected override void Run(UIStartFightRoomComponent self)
  75. {
  76. try
  77. {
  78. self.Check();
  79. }
  80. catch (Exception e)
  81. {
  82. Log.Error($"idle check error: {self.Id}\n{e}");
  83. }
  84. }
  85. }
  86. [Invoke(TimerInvokeType.startFightTimeCount)]
  87. public class UIStartFightTimeCountChecker : ATimer<UIStartFightRoomComponent>
  88. {
  89. protected override void Run(UIStartFightRoomComponent self)
  90. {
  91. try
  92. {
  93. self.UpdateTimeCount();
  94. }
  95. catch (Exception e)
  96. {
  97. Log.Error($"idle check error: {self.Id}\n{e}");
  98. }
  99. }
  100. }
  101. #endregion
  102. [FriendOf(typeof(UIStartFightRoomComponent))]
  103. public static class UIStartFightRoomComponentSystem
  104. {
  105. public static void Check(this UIStartFightRoomComponent self)
  106. {
  107. self.timeTxt.text = string.Format("{0}:{1}", DateTime.Now.Hour, DateTime.Now.Minute);
  108. }
  109. public static void UpdateTimeCount(this UIStartFightRoomComponent self)
  110. {
  111. if (self.startTimeCount > 0)
  112. {
  113. self.timeCountObj.SetActive(true);
  114. self.timeCountTxt.text = self.startTimeCount.ToString();
  115. }
  116. else
  117. {
  118. self.timeCountObj.SetActive(false);
  119. if (self.startTimer > 0)
  120. TimerComponent.Instance?.Remove(ref self.startTimer);
  121. }
  122. self.startTimeCount = self.startTimeCount - 1;
  123. }
  124. [ObjectSystem]
  125. public class UIStartFightRoomComponentAwakeSystem : AwakeSystem<UIStartFightRoomComponent>
  126. {
  127. protected override void Awake(UIStartFightRoomComponent self, params object[] param)
  128. {
  129. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  130. //头像部分
  131. self.houseIcon = rc.Get<GameObject>("houseIcon");
  132. self.houseIdTxt = rc.Get<GameObject>("houseIdTxt");
  133. self.gameNumTxt = rc.Get<GameObject>("gameNumTxt");
  134. self.curResidueTxt = rc.Get<GameObject>("curResidueTxt");
  135. //右上系统信息部分
  136. self.wifiImage = rc.Get<GameObject>("wifiImage");
  137. self.powerImage = rc.Get<GameObject>("powerImage");
  138. var timeTxt = rc.Get<GameObject>("timeTxt");
  139. self.timeTxt = timeTxt.GetComponent<UnityEngine.UI.Text>();
  140. self.menuBtn = rc.Get<GameObject>("menuBtn");
  141. self.menuBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuBtn(); });
  142. self.faceBtn = rc.Get<GameObject>("faceBtn");
  143. self.faceBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceBtn(); });
  144. self.videoBtn = rc.Get<GameObject>("videoBtn");
  145. self.videoBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnVideoBtn(); });
  146. //菜单
  147. self.menuPanel = rc.Get<GameObject>("menuPanel");
  148. self.menuPanel.SetActive(false);
  149. self.maskBtn = rc.Get<GameObject>("maskBtn");
  150. self.maskBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelClose(); });
  151. self.menuBackBtn = rc.Get<GameObject>("menuBackBtn");
  152. self.menuBackBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelBack(); });
  153. self.menuQuitBtn = rc.Get<GameObject>("menuQuitBtn");
  154. self.menuQuitBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelQuit(); });
  155. self.menuSettingBtn = rc.Get<GameObject>("menuSettingBtn");
  156. self.menuSettingBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelSetting(); });
  157. //表情面板
  158. self.facePanel = rc.Get<GameObject>("facePanel");
  159. self.facePanel.SetActive(false);
  160. self.fastToggleBtn = rc.Get<GameObject>("fastToggleBtn");
  161. self.fastToggleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceFastToggleBtn(0); });
  162. self.faceToggleBtn = rc.Get<GameObject>("faceToggleBtn");
  163. self.faceToggleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceFastToggleBtn(1); });
  164. self.faceAndVideoObj = rc.Get<GameObject>("faceAndVideoObj");
  165. self.faceAndVideoObj.SetActive(false);
  166. self.facePanelCloseBtn = rc.Get<GameObject>("facePanelCloseBtn");
  167. self.facePanelCloseBtn.GetComponent<Button>().onClick.AddListener(() => { self.facePanel.SetActive(false); });
  168. //表情列表以及快捷语列表
  169. self.listFastGridBg = rc.Get<GameObject>("listFastGridBg");
  170. self.listFastGridBg.SetActive(false);
  171. self.listFastContent = rc.Get<GameObject>("listFastContent");
  172. self.gridFastItem = rc.Get<GameObject>("gridFastItem");
  173. self.listFaceGridBg = rc.Get<GameObject>("listFaceGridBg");
  174. self.listFaceGridBg.SetActive(false);
  175. self.listFaceContent = rc.Get<GameObject>("listFaceContent");
  176. self.gridFaceItem = rc.Get<GameObject>("gridFaceItem");
  177. self.timeCountObj = rc.Get<GameObject>("timeCountObj");
  178. self.timeCountTxt = rc.Get<GameObject>("timeCountTxt").GetComponent<UnityEngine.UI.Text>();
  179. //玩
  180. self.readyBtn = rc.Get<GameObject>("readyBtn");
  181. self.readyBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnReadyAndInviteBtn(0); });
  182. self.inviteBtn = rc.Get<GameObject>("inviteBtn");
  183. self.inviteBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnReadyAndInviteBtn(1); });
  184. self.fightCardItem = rc.Get<GameObject>("fightCardItem");
  185. self.fightCardItem.SetActive(false);
  186. GameUtil.Instance.SetCardCloneItem(self.fightCardItem,0);
  187. self.fightCardItem1 = rc.Get<GameObject>("fightCardItem1");
  188. self.fightCardItem1.SetActive(false);
  189. GameUtil.Instance.SetCardCloneItem(self.fightCardItem1, 1);
  190. for (int i = 1;i <= 4;i++)
  191. {
  192. UIStartFightRoomPlayerCom uIStartFightRoomPlayerCom = new UIStartFightRoomPlayerCom();
  193. var playerObj = rc.Get<GameObject>("player" + i);
  194. var playerIconObj = rc.Get<GameObject>("playerIcon" + i);
  195. var readyImage = rc.Get<GameObject>("readyImage" + i);
  196. var playerIconImage = playerIconObj.GetComponent<UnityEngine.UI.Image>();
  197. uIStartFightRoomPlayerCom.playerObj = playerObj;
  198. uIStartFightRoomPlayerCom.readyImage = readyImage;
  199. uIStartFightRoomPlayerCom.playerIcon = playerIconImage;
  200. var fightCardContentNode = rc.Get<GameObject>("fightCardContent" + i);
  201. uIStartFightRoomPlayerCom.fightCardNode = fightCardContentNode;
  202. var disCardContentNode = rc.Get<GameObject>("disCardContent" + i);
  203. uIStartFightRoomPlayerCom.disCardsNode = disCardContentNode;
  204. self.uIStartFightRoomPlayerComs.Add(uIStartFightRoomPlayerCom);
  205. playerObj.SetActive(false);
  206. var playChatObj = rc.Get<GameObject>("playChatObj" + i);
  207. self.playChatObjList.Add(playChatObj);
  208. }
  209. self.Init();
  210. }
  211. }
  212. private static async void Init(this UIStartFightRoomComponent self)
  213. {
  214. self.RepeatedTimer = TimerComponent.Instance.NewRepeatedTimer(ConstValue.fightTimeRefreshTime / 2 + 100, TimerInvokeType.fightTimeShow, self);
  215. var startFightRoomInfo = self.ClientScene().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  216. CommonBridge.Instance.dispathPush += DispathPush;
  217. self.readyBtn.SetActive(true);
  218. self.inviteBtn.SetActive(true);
  219. self.houseIdTxt.GetComponent<UnityEngine.UI.Text>().text = startFightRoomInfo.roomInfo.RoomId.ToString();
  220. self.gameNumTxt.GetComponent<UnityEngine.UI.Text>().text = startFightRoomInfo.roomInfo.OwnerId.ToString();
  221. self.curResidueTxt.GetComponent<UnityEngine.UI.Text>().text = "0";
  222. await SoundManager.Instance.PlaySound("common_playing", true);
  223. }
  224. private static void DispathPush(Scene scene, object type)
  225. {
  226. switch (type)
  227. {
  228. case EventType.JoinRoomPush:
  229. {
  230. var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
  231. var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
  232. var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  233. //处理其他玩家信息
  234. for (int i = 1; i < startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count; i++)
  235. {
  236. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
  237. }
  238. if (startFightRoomInfo.roomInfo.OtherInfo != null && startFightRoomInfo.roomInfo.OtherInfo.Count > 0)
  239. {
  240. for (int i = 0; i < startFightRoomInfo.roomInfo.OtherInfo.Count; i++)
  241. {
  242. var otherPlayInfo = startFightRoomInfo.roomInfo.OtherInfo[i];
  243. if (i >= startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count - 1)
  244. {
  245. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
  246. }
  247. else
  248. {
  249. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
  250. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(false);
  251. }
  252. }
  253. }
  254. break;
  255. }
  256. case EventType.KickPush:
  257. {
  258. break;
  259. }
  260. case EventType.ReadyPush:
  261. {
  262. var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
  263. var startFightRoomComponent = ui.GetComponent<UIStartFightRoomComponent>();
  264. var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  265. //先处理自己的信息
  266. if (startFightRoomInfo.roomInfo.MyInfo != null)
  267. {
  268. startFightRoomComponent.readyBtn.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 0);
  269. startFightRoomComponent.inviteBtn.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 0);
  270. startFightRoomComponent.uIStartFightRoomPlayerComs[0].playerObj.SetActive(true);
  271. startFightRoomComponent.faceAndVideoObj.SetActive(true);
  272. startFightRoomComponent.uIStartFightRoomPlayerComs[0].readyImage.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 1);
  273. }
  274. //处理其他玩家信息
  275. for (int i = 1;i < startFightRoomComponent.uIStartFightRoomPlayerComs.Count;i++)
  276. {
  277. startFightRoomComponent.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
  278. }
  279. if (startFightRoomInfo.roomInfo.OtherInfo != null && startFightRoomInfo.roomInfo.OtherInfo.Count > 0)
  280. {
  281. for (int i = 0; i < startFightRoomInfo.roomInfo.OtherInfo.Count; i++)
  282. {
  283. var otherPlayInfo = startFightRoomInfo.roomInfo.OtherInfo[i];
  284. if (i >= startFightRoomComponent.uIStartFightRoomPlayerComs.Count - 1)
  285. {
  286. startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
  287. }
  288. else
  289. {
  290. startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
  291. startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(otherPlayInfo.state == 1);
  292. }
  293. }
  294. }
  295. break;
  296. }
  297. case EventType.ReadyStartPush:
  298. {
  299. //开始 倒计时
  300. var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  301. Log.Error("@@@@@ 倒计时: " + startFightRoomInfo.readyStartTimeCount);
  302. var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
  303. var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
  304. startFightRoomComponentUI.startTimeCount = startFightRoomInfo.readyStartTimeCount;
  305. startFightRoomComponentUI.startTimer = TimerComponent.Instance.NewRepeatedTimer(ConstValue.fightTimeRefreshTime / 2 + 100, TimerInvokeType.startFightTimeCount, startFightRoomComponentUI);
  306. break;
  307. }
  308. case EventType.GameStartPush:
  309. case EventType.GameDrawCardPush:
  310. {
  311. //正式开始 发牌
  312. var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
  313. var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
  314. var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  315. var myCardInfo = startFightRoomInfo.roomInfo.MyInfo;
  316. var otherCardInfo = startFightRoomInfo.roomInfo.OtherInfo;
  317. #region 其他玩家牌处理
  318. //处理其他玩家信息
  319. for (int i = 1; i < startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count; i++)
  320. {
  321. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
  322. }
  323. if (otherCardInfo != null && otherCardInfo.Count > 0)
  324. {
  325. RefreshPlayCardList(0, otherCardInfo, startFightRoomComponentUI);
  326. }
  327. #endregion
  328. #region 自己牌处理
  329. //处理牌型
  330. //自己牌
  331. if (myCardInfo != null)
  332. {
  333. RefreshPlayCardList(1, new List<PlayerInfo>() { myCardInfo }, startFightRoomComponentUI);
  334. }
  335. #endregion
  336. break;
  337. }
  338. }
  339. }
  340. #region 右上系统部分
  341. public static void OnMenuBtn(this UIStartFightRoomComponent self)
  342. {
  343. self.menuPanel.SetActive(!self.menuPanel.activeInHierarchy);
  344. }
  345. public static async void OnFaceBtn(this UIStartFightRoomComponent self)
  346. {
  347. await SoundManager.Instance.PlaySound("clickbtnsound");
  348. self.facePanel.SetActive(true);
  349. self.LoadChatData(0);
  350. }
  351. public static void OnVideoBtn(this UIStartFightRoomComponent self)
  352. {
  353. }
  354. #endregion
  355. #region 菜单
  356. public static void OnMenuPanelClose(this UIStartFightRoomComponent self)
  357. {
  358. self.menuPanel.SetActive(false);
  359. }
  360. public static async void OnMenuPanelBack(this UIStartFightRoomComponent self)
  361. {
  362. Action<object> myAction = (param) =>
  363. {
  364. int result = (int)param;
  365. if (result == 1)
  366. {
  367. self.ReturnMainUI().Coroutine();
  368. }
  369. };
  370. Dictionary<string,object> dic = new Dictionary<string, object>()
  371. {
  372. { "callback",myAction},
  373. { "title","提示"},
  374. { "content","返回大厅,你的房间仍会保留。"},
  375. { "yesTxt","确定"},
  376. { "cancelTxt","取消"},
  377. };
  378. await SoundManager.Instance.PlaySound("clickbtnsound");
  379. await UIHelper.Create(self.ClientScene(), UIType.UIAlert, UILayer.High, dic);
  380. }
  381. public static void OnMenuPanelQuit(this UIStartFightRoomComponent self)
  382. {
  383. }
  384. public static void OnMenuPanelSetting(this UIStartFightRoomComponent self)
  385. {
  386. }
  387. #endregion
  388. #region 表情
  389. public static async void OnFaceFastToggleBtn(this UIStartFightRoomComponent self,int index)
  390. {
  391. await SoundManager.Instance.PlaySound("clickbtnsound");
  392. self.LoadChatData(index);
  393. }
  394. static async void LoadChatData(this UIStartFightRoomComponent self, int index)
  395. {
  396. self.listFaceGridBg.SetActive(false);
  397. self.listFastGridBg.SetActive(false);
  398. string[] abName = new string[] { "com_bg1", "com_bg2" };
  399. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "commonatlas");
  400. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("commonatlas", abName[0]);
  401. Sprite sprite1 = ResourcesComponentHelper.Instance.GetSprite("commonatlas", abName[1]);
  402. self.fastToggleBtn.GetComponent<UnityEngine.UI.Image>().sprite = index == 0 ? sprite: sprite1;
  403. self.faceToggleBtn.GetComponent<UnityEngine.UI.Image>().sprite = index == 1 ? sprite : sprite1;
  404. self.CleanChatItem(index);
  405. if (index == 0)
  406. {
  407. self.listFastGridBg.SetActive(true);
  408. var startFightRoomInfo = self.ClientScene().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  409. int sexType = startFightRoomInfo.roomInfo.MyInfo.sex;
  410. var fightConfig = FightChatConfigCategory.Instance.GetAll();
  411. var achievedDic = fightConfig.Where(kvp => kvp.Value.Type == sexType);
  412. foreach (var item in achievedDic)
  413. {
  414. if (GameObjectPool.Instance.chatFastItemPools.Count > 0)
  415. {
  416. GameObject uiFastItem = GameObjectPool.Instance.chatFastItemPools[0];
  417. GameObjectPool.Instance.chatFastItemPools.RemoveAt(0);
  418. uiFastItem.SetActive(true);
  419. uiFastItem.transform.SetParent(self.listFastContent.transform, false);
  420. var txt = uiFastItem.GetComponentInChildren<UnityEngine.UI.Text>();
  421. txt.text = item.Value.Content;
  422. var btn = txt.gameObject.GetComponent<Button>();
  423. btn.onClick.RemoveAllListeners();
  424. btn.onClick.AddListener(async () =>
  425. {
  426. Log.Error("btn click1: " + item.Value.Content + " vedio: " + item.Value.VedioPath);
  427. await SoundManager.Instance.PlaySound(item.Value.VedioPath);
  428. self.facePanel.SetActive(false);
  429. self.playChatObjList[0].SetActive(true);
  430. var playChatTxt = self.playChatObjList[0].GetComponentInChildren<UnityEngine.UI.Text>();
  431. playChatTxt.text = item.Value.Content;
  432. await TimerComponent.Instance.WaitAsync(3000);
  433. self.playChatObjList[0].SetActive(false);
  434. });
  435. }
  436. else
  437. {
  438. var uiFastItem = GameUtil.Instance.InitializeObj(self.gridFastItem);
  439. uiFastItem.gameObject.SetActive(true);
  440. uiFastItem.transform.SetParent(self.listFastContent.transform, false);
  441. var txt = uiFastItem.GetComponentInChildren<UnityEngine.UI.Text>();
  442. txt.text = item.Value.Content;
  443. var btn = txt.gameObject.GetComponent<Button>();
  444. btn.onClick.RemoveAllListeners();
  445. btn.onClick.AddListener(() =>
  446. {
  447. Log.Error("btn click2: " + item.Value.Content);
  448. });
  449. }
  450. }
  451. }
  452. else
  453. {
  454. }
  455. }
  456. static void CleanChatItem(this UIStartFightRoomComponent self,int index)
  457. {
  458. Transform node = null;
  459. List<GameObject> list = null;
  460. if (index == 0)
  461. {
  462. node = self.listFastContent.transform;
  463. list = GameObjectPool.Instance.chatFastItemPools;
  464. }
  465. else
  466. {
  467. node = self.listFaceContent.transform;
  468. list = GameObjectPool.Instance.chatFaceItemPools;
  469. }
  470. for (int i = 0; i < node.childCount; i++)
  471. {
  472. var child = node.GetChild(i);
  473. list.Add(child.gameObject);
  474. child.gameObject.SetActive(false);
  475. }
  476. }
  477. #endregion
  478. #region 邀请以及准备
  479. public static void OnReadyAndInviteBtn(this UIStartFightRoomComponent self, int index)
  480. {
  481. if (index == 0)
  482. {
  483. self.ReadyRes().Coroutine();
  484. }
  485. else
  486. {
  487. //邀请
  488. }
  489. }
  490. #endregion
  491. public static void SetBattery()
  492. {
  493. //var level = SystemInfo.batteryLevel == -1 ? 1 : SystemInfo.batteryLevel;
  494. //batteryLevelImg.fillAmount = level;
  495. //batteryTxt.text = (level * 100).ToString() + "%";
  496. //var isCharging = SystemInfo.batteryStatus == BatteryStatus.Charging;
  497. //charging.gameObject.SetActive(isCharging);
  498. }
  499. static async ETTask ReturnMainUI(this UIStartFightRoomComponent self)
  500. {
  501. var scene = self.ClientScene();
  502. await UIHelper.Remove(scene, UIType.UIStartFightRoom);
  503. var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
  504. Dictionary<string, object> dic = new Dictionary<string, object>()
  505. {
  506. { "result",1},
  507. { "roomId",startFightRoomInfo.roomInfo.RoomId.ToString()}
  508. };
  509. await UIHelper.Create(scene, UIType.UIMain, UILayer.Mid, dic);
  510. }
  511. static async ETTask ReadyRes(this UIStartFightRoomComponent self)
  512. {
  513. //try
  514. {
  515. var scene = self.ClientScene();
  516. var session = scene.GetComponent<SessionComponent>().Session;
  517. if (session != null)
  518. {
  519. G2C_Ready g2Ready = (G2C_Ready)await session.Call(
  520. new C2G_Ready() { });
  521. if (g2Ready.Error != ErrorCode.ERR_Success)
  522. {
  523. Log.Error($"g2Ready错误...errCode={g2Ready.Error}" + " mess: " + g2Ready.Message);
  524. return;
  525. }
  526. }
  527. }
  528. //catch (Exception e)
  529. //{
  530. // Log.Error($"准备出错...{e.Message}");
  531. //}
  532. }
  533. public static async void OnCloseAsync(this UIStartFightRoomComponent self)
  534. {
  535. await UIHelper.Remove(self.ClientScene(),UIType.UIStartFightRoom);
  536. }
  537. public static async void RefreshPlayCardList(int index, List<PlayerInfo> playerInfos, UIStartFightRoomComponent startFightRoomComponentUI)
  538. {
  539. if (index == 0)
  540. {
  541. for (int i = 0; i < playerInfos.Count; i++)
  542. {
  543. var otherPlayInfo = playerInfos[i];
  544. if (i >= startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count - 1)
  545. {
  546. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
  547. }
  548. else
  549. {
  550. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
  551. startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(false);
  552. var fightCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].fightCardNode;
  553. var disCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].disCardsNode;
  554. CleanCardItemList(fightCardParentNode.transform,0);
  555. for (int p = 0; p < otherPlayInfo.cardInfo.RemainCardsNum; p++)
  556. {
  557. if (GameObjectPool.Instance.fightCardItemPools.Count > 0)
  558. {
  559. GameObject uifightItem = GameObjectPool.Instance.fightCardItemPools[0];
  560. GameObjectPool.Instance.fightCardItemPools.RemoveAt(0);
  561. uifightItem.gameObject.SetActive(true);
  562. uifightItem.transform.SetParent(fightCardParentNode.transform, false);
  563. var sprite = await GameObjectPool.Instance.AcquireSprite(GameSetting.Instance.otherPlayCardSpiteName);
  564. UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
  565. icon.sprite = sprite;
  566. var btn = icon.gameObject.GetComponent<Button>();
  567. btn.onClick.RemoveAllListeners();
  568. btn.onClick.AddListener(() =>
  569. {
  570. Log.Error("card Click...");
  571. });
  572. }
  573. else
  574. {
  575. int cloneItemIndex = i % 2 == 0? 1 : 0;
  576. var uifightItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(cloneItemIndex));
  577. uifightItem.SetActive(true);
  578. uifightItem.transform.SetParent(fightCardParentNode.transform, false);
  579. var sprite = await GameObjectPool.Instance.AcquireSprite(GameSetting.Instance.otherPlayCardSpiteName);
  580. UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
  581. icon.sprite = sprite;
  582. }
  583. }
  584. //已经出过的牌列表
  585. CleanCardItemList(disCardParentNode.transform, 1);
  586. if (otherPlayInfo.cardInfo.DisCards != null)
  587. {
  588. for (int l = 0; l < otherPlayInfo.cardInfo.DisCards.Count; l++)
  589. {
  590. int value = otherPlayInfo.cardInfo.DisCards[l];
  591. if (GameObjectPool.Instance.disCardItemPools.Count > 0)
  592. {
  593. GameObject uiDisItem = GameObjectPool.Instance.disCardItemPools[0];
  594. GameObjectPool.Instance.disCardItemPools.RemoveAt(0);
  595. uiDisItem.gameObject.SetActive(true);
  596. uiDisItem.transform.SetParent(disCardParentNode.transform, false);
  597. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  598. UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
  599. icon.sprite = sprite;
  600. }
  601. else
  602. {
  603. int cloneItemIndex = i % 2 == 0 ? 1 : 0;
  604. var uiDisItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(cloneItemIndex));
  605. uiDisItem.SetActive(true);
  606. uiDisItem.transform.SetParent(disCardParentNode.transform, false);
  607. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  608. UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
  609. icon.sprite = sprite;
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. else
  617. {
  618. var myCardInfo = playerInfos[0];
  619. if (myCardInfo.cardInfo.RemainCards == null)
  620. {
  621. Log.Error("自己牌队列为NULL");
  622. return;
  623. }
  624. var parentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].fightCardNode;
  625. var disCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].disCardsNode;
  626. startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].readyImage.SetActive(false);
  627. Log.Error("card数量: " + myCardInfo.cardInfo.RemainCards.Count);
  628. CleanCardItemList(parentNode.transform,0);
  629. for (int i = 0; i < myCardInfo.cardInfo.RemainCards.Count;i++)
  630. {
  631. var value = myCardInfo.cardInfo.RemainCards[i];
  632. if (GameObjectPool.Instance.fightCardItemPools.Count > 0)
  633. {
  634. GameObject uifightItem = GameObjectPool.Instance.fightCardItemPools[0];
  635. GameObjectPool.Instance.fightCardItemPools.RemoveAt(0);
  636. uifightItem.gameObject.SetActive(true);
  637. uifightItem.transform.SetParent(parentNode.transform, false);
  638. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  639. UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
  640. icon.sprite = sprite;
  641. var btn = icon.gameObject.GetComponent<Button>();
  642. btn.onClick.RemoveAllListeners();
  643. btn.onClick.AddListener(() =>
  644. {
  645. Log.Error("card Click... " + string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  646. });
  647. }
  648. else
  649. {
  650. var uifightItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(0));
  651. uifightItem.gameObject.SetActive(true);
  652. uifightItem.transform.SetParent(parentNode.transform, false);
  653. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  654. UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
  655. icon.sprite = sprite;
  656. icon.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  657. {
  658. Log.Error("card Click... " + string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  659. });
  660. }
  661. }
  662. //已经出过的牌列表
  663. CleanCardItemList(disCardParentNode.transform, 1);
  664. if (myCardInfo.cardInfo.DisCards != null)
  665. {
  666. for (int l = 0; l < myCardInfo.cardInfo.DisCards.Count; l++)
  667. {
  668. int value = myCardInfo.cardInfo.DisCards[l];
  669. if (GameObjectPool.Instance.disCardItemPools.Count > 0)
  670. {
  671. GameObject uiDisItem = GameObjectPool.Instance.disCardItemPools[0];
  672. GameObjectPool.Instance.disCardItemPools.RemoveAt(0);
  673. uiDisItem.gameObject.SetActive(true);
  674. uiDisItem.transform.SetParent(disCardParentNode.transform, false);
  675. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  676. UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
  677. icon.sprite = sprite;
  678. }
  679. else
  680. {
  681. var uiDisItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(0));
  682. uiDisItem.SetActive(true);
  683. uiDisItem.transform.SetParent(disCardParentNode.transform, false);
  684. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
  685. UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
  686. icon.sprite = sprite;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. public static void CleanCardItemList(Transform node,int index)
  693. {
  694. List<GameObject> tempList = index == 0? GameObjectPool.Instance.fightCardItemPools: GameObjectPool.Instance.disCardItemPools;
  695. for (int i = 0;i < node.childCount;i++)
  696. {
  697. var child = node.GetChild(i);
  698. tempList.Add(child.gameObject);
  699. child.gameObject.SetActive(false);
  700. }
  701. }
  702. [ObjectSystem]
  703. public class UIStartFightRoomComponentDestroySystem : DestroySystem<UIStartFightRoomComponent>
  704. {
  705. protected override void Destroy(UIStartFightRoomComponent self)
  706. {
  707. TimerComponent.Instance?.Remove(ref self.RepeatedTimer);
  708. CommonBridge.Instance.Clear();
  709. }
  710. }
  711. }
  712. }