UISettleComponentSystem.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using static ET.GameSetting;
  9. using static System.Net.Mime.MediaTypeNames;
  10. namespace ET.Client
  11. {
  12. [FriendOf(typeof(UISettleComponent))]
  13. public static class UISettleComponentSystem
  14. {
  15. [ObjectSystem]
  16. public class UISettleComponentAwakeSystem : AwakeSystem<UISettleComponent>
  17. {
  18. protected override void Awake(UISettleComponent self, params object[] param)
  19. {
  20. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  21. self.closeBtn = rc.Get<GameObject>("closeBtn");
  22. self.closeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(); });
  23. self.nextBtn = rc.Get<GameObject>("nextBtn");
  24. self.nextBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnNextBtn(); });
  25. for (int i = 0;i < 4;i++)
  26. {
  27. var playItem = rc.Get<GameObject>("playItem" + (i + 1));
  28. var playIcon = rc.Get<GameObject>("playIcon" + (i + 1)).GetComponent<UnityEngine.UI.Image>();
  29. var playName = rc.Get<GameObject>("playName" + (i + 1)).GetComponent<UnityEngine.UI.Text>();
  30. var playId = rc.Get<GameObject>("playId" + (i + 1)).GetComponent<UnityEngine.UI.Text>();
  31. var fightCardContent = rc.Get<GameObject>("fightCardContent" + (i + 1));
  32. var haveBeenOutContent = rc.Get<GameObject>("haveBeenOutContent" + (i + 1));
  33. var playSettleType = rc.Get<GameObject>("playSettleType" + (i + 1)).GetComponent<UnityEngine.UI.Image>();
  34. if (self.settleItemUIs == null)
  35. {
  36. self.settleItemUIs = new List<SettleItemUI> ();
  37. }
  38. SettleItemUI settleItemUI = new SettleItemUI();
  39. settleItemUI.playItem = playItem;
  40. settleItemUI.playIcon = playIcon;
  41. settleItemUI.playName = playName;
  42. settleItemUI.fightCardContent = fightCardContent;
  43. settleItemUI.haveBeenOutContent = haveBeenOutContent;
  44. settleItemUI.playId = playId;
  45. settleItemUI.playSettleType = playSettleType;
  46. self.settleItemUIs.Add(settleItemUI);
  47. }
  48. self.fightCardItem = rc.Get<GameObject>("fightCardItem");
  49. self.fightCardItem1 = rc.Get<GameObject>("fightCardItem1");
  50. self.Init();
  51. }
  52. }
  53. private static async void Init(this UISettleComponent self)
  54. {
  55. for (int i = 0;i < self.settleItemUIs.Count;i++)
  56. {
  57. self.settleItemUIs[i].playItem.SetActive( false);
  58. }
  59. var settleInfo = self.ClientScene().GetComponent<StartFightRoomComponment>().GetSettlementInfo();
  60. var playDatas = settleInfo.PlayerInfo;
  61. if (playDatas == null)
  62. {
  63. Log.Error("数据错误,结算失败");
  64. }
  65. for (int i = 0;i < playDatas.Count;i++)
  66. {
  67. self.settleItemUIs[i].playItem.SetActive(true);
  68. self.settleItemUIs[i].playName.text = playDatas[i].name;
  69. self.settleItemUIs[i].playId.text = playDatas[i].id.ToString();
  70. //switch (playDatas[i].)
  71. //{
  72. //}
  73. //self.settleItemUIs[i].playSettleType
  74. self.LoadCardList(self.settleItemUIs[i].fightCardContent, self.settleItemUIs[i].haveBeenOutContent, playDatas[i].cardInfo.RemainCards, playDatas[i].cardInfo.UsedInfo);
  75. }
  76. }
  77. private static async void LoadCardList(this UISettleComponent self, GameObject fightCardContent, GameObject haveBeenOutContent, List<int> cardList, List<ActInfo> actInfos)
  78. {
  79. for (int i = 0; i < fightCardContent.transform.childCount; i++)
  80. {
  81. var child = fightCardContent.transform.GetChild(i);
  82. UnityEngine.Object.Destroy(child.gameObject);
  83. }
  84. for (int i = 0; i < haveBeenOutContent.transform.childCount; i++)
  85. {
  86. var child = haveBeenOutContent.transform.GetChild(i);
  87. UnityEngine.Object.Destroy(child.gameObject);
  88. }
  89. cardList.Sort();
  90. for (int i = 0; i < cardList.Count; i++)
  91. {
  92. var uifightItem = GameUtil.Instance.InitializeObj(self.fightCardItem);
  93. uifightItem.SetActive(true);
  94. uifightItem.transform.SetParent(fightCardContent.transform, false);
  95. string spiring = string.Concat(GameSetting.Instance.selfPlayCardCenterSpiteName, cardList[i]);
  96. var sprite = await GameObjectPool.Instance.AcquireSprite(spiring);
  97. UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
  98. icon.sprite = sprite;
  99. icon.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(68,103);
  100. }
  101. if (actInfos != null && actInfos.Count > 0)
  102. {
  103. for (int l = 0; l < actInfos.Count; l++)
  104. {
  105. //这里只存一张 根据类型 自己去补
  106. ActInfo actInfo = actInfos[l];
  107. List<int> havCardVals = null;
  108. ActInfoType actInfoType = (ActInfoType)actInfo.Type;
  109. switch (actInfoType)
  110. {
  111. case ActInfoType.LightPole:
  112. case ActInfoType.BackPole:
  113. case ActInfoType.DarkPole:
  114. {
  115. havCardVals = new List<int>() { actInfo.Card, actInfo.Card, actInfo.Card, actInfo.Card };
  116. break;
  117. }
  118. case ActInfoType.Peng:
  119. {
  120. havCardVals = new List<int>() { actInfo.Card, actInfo.Card, actInfo.Card };
  121. break;
  122. }
  123. case ActInfoType.Chi:
  124. {
  125. havCardVals = new List<int>() { actInfo.Card, actInfo.Card + 1, actInfo.Card + 2 };
  126. break;
  127. }
  128. }
  129. for (int k = 0; k < havCardVals.Count; k++)
  130. {
  131. var uiHavItem = GameUtil.Instance.InitializeObj(self.fightCardItem);
  132. string spiring = string.Concat(GameSetting.Instance.selfPlayCardShowSpiteName, havCardVals[k]);
  133. uiHavItem.SetActive(true);
  134. uiHavItem.transform.SetParent(haveBeenOutContent.transform, false);
  135. var sprite = await GameObjectPool.Instance.AcquireSprite(spiring);
  136. UnityEngine.UI.Image icon = uiHavItem.GetComponentInChildren<UnityEngine.UI.Image>();
  137. icon.sprite = sprite;
  138. icon.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(43, 65);
  139. }
  140. var uiHavItem1 = GameUtil.Instance.InitializeObj(self.fightCardItem1);
  141. uiHavItem1.SetActive(true);
  142. uiHavItem1.transform.SetParent(haveBeenOutContent.transform, false);
  143. UnityEngine.UI.Image icon1 = uiHavItem1.GetComponentInChildren<UnityEngine.UI.Image>();
  144. icon1.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(43, 65);
  145. icon1.enabled = false;
  146. }
  147. }
  148. }
  149. public static async void OnCloseBtn(this UISettleComponent self)
  150. {
  151. await SoundManager.Instance.PlaySound("clickbtnsound");
  152. self.OnCloseAsync();
  153. }
  154. public static async void OnNextBtn(this UISettleComponent self)
  155. {
  156. await SoundManager.Instance.PlaySound("clickbtnsound");
  157. var ui = self.ClientScene().GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
  158. var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
  159. startFightRoomComponentUI.RestartPlayGame();
  160. self.OnCloseAsync();
  161. }
  162. public static async void OnCloseAsync(this UISettleComponent self)
  163. {
  164. await UIHelper.Remove(self.ClientScene(),UIType.UISettle);
  165. }
  166. }
  167. }