UIMainComponentSystem.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ET.Client
  6. {
  7. [FriendOf(typeof(UIMainComponent))]
  8. public static class UIMainComponentSystem
  9. {
  10. [ObjectSystem]
  11. public class UIMainComponentAwakeSystem : AwakeSystem<UIMainComponent>
  12. {
  13. protected override async void Awake(UIMainComponent self, params object[] param)
  14. {
  15. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  16. self.createRoomBtn = rc.Get<GameObject>("createRoomBtn");
  17. self.createRoomTxt = rc.Get<GameObject>("createRoomTxt");
  18. self.joinRoomBtn = rc.Get<GameObject>("joinRoomBtn");
  19. self.clubRoomBtn = rc.Get<GameObject>("clubBtn");
  20. self.playerIcon = rc.Get<GameObject>("playerIcon");
  21. self.playerId = rc.Get<GameObject>("playerId");
  22. self.playerName = rc.Get<GameObject>("playerName");
  23. self.playerLevel = rc.Get<GameObject>("playerLevel");
  24. self.vipVaule = rc.Get<GameObject>("vipVaule");
  25. self.expVaule = rc.Get<GameObject>("expVaule");
  26. self.createRoomBtn.OnClick(() => { self.OnCreateRoom(); });
  27. //self.createRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateRoom(); });
  28. self.joinRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnJoinRoom(); });
  29. self.clubRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnClub(); });
  30. self.playerIcon.GetComponent<Button>().onClick.AddListener(() => { self.OnPlayer(); });
  31. var roleInfo = self.ClientScene().GetComponent<RoleInfoComponment>().GetRoleInfo();
  32. self.playerName.GetComponent<Text>().text = roleInfo.name;
  33. self.playerId.GetComponent<Text>().text = roleInfo.roleId.ToString();
  34. self.vipVaule.GetComponent<Text>().text = roleInfo.vip.ToString();
  35. self.playerLevel.GetComponent<Text>().text = "LV." + roleInfo.level.ToString();
  36. self.expVaule.GetComponent<Image>().fillAmount = roleInfo.exp / 100f;
  37. ///down btn////
  38. self.shopBtn = rc.Get<GameObject>("shopBtn");
  39. self.settingBtn = rc.Get<GameObject>("settingBtn");
  40. self.ruleBtn = rc.Get<GameObject>("ruleBtn");
  41. self.statsBtn = rc.Get<GameObject>("statsBtn");
  42. self.shareBtn = rc.Get<GameObject>("shareBtn");
  43. self.avtiveBtn = rc.Get<GameObject>("avtiveBtn");
  44. self.shopBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShop(); });
  45. self.settingBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnSetting(); });
  46. self.ruleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRule(); });
  47. self.statsBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnStats(); });
  48. self.avtiveBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnAvtive(); });
  49. self.shareBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShare(); });
  50. //leftBtn
  51. self.iphoneBtn = rc.Get<GameObject>("iphoneBtn");
  52. self.invitationCodeBtn = rc.Get<GameObject>("invitationCodeBtn");
  53. self.realNameBtn = rc.Get<GameObject>("realNameBtn");
  54. self.iphoneBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnIphone(); });
  55. self.invitationCodeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInvitationCode(); });
  56. self.realNameBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRealName(); });
  57. //up
  58. self.hourseCardAddBtn = rc.Get<GameObject>("hourseCradAddBtn");
  59. self.curServiceBtn = rc.Get<GameObject>("cusServiceBtn");
  60. self.messageBtn = rc.Get<GameObject>("messageBtn");
  61. self.hourseCardTxt = rc.Get<GameObject>("hourseCradTxt");
  62. self.hourseCardAddBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnHourseCardAdd(); });
  63. self.curServiceBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCurService(); });
  64. self.messageBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMessage(); });
  65. //提示面板
  66. self.titlePanelObj = rc.Get<GameObject>("titlePanle");
  67. //每次进来都弹一次
  68. self.titlePanelObj.SetActive(true);
  69. self.closeTitleBtn = rc.Get<GameObject>("closeTitleBtn");
  70. self.closeTitleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseTitle(); });
  71. self.createRoomType = 0;
  72. self.roomId = "";
  73. if (param != null && param.Length > 0)
  74. {
  75. Dictionary<string, object> dic = param[0] as Dictionary<string, object>;
  76. self.createRoomType = (int)dic["result"];
  77. self.roomId = dic["roomId"] as string;
  78. }
  79. //self.createRoomTxt.GetComponent<Text>().text = self.createRoomType == 0 ? "创建房间" : "返回房间";
  80. await SoundManager.Instance.PlaySound("common_playBg",true);
  81. }
  82. }
  83. #region 中间按钮
  84. public static async void OnCreateRoom(this UIMainComponent self)
  85. {
  86. await SoundManager.Instance.PlaySound("clickbtnsound");
  87. if (self.createRoomType == 0)
  88. {
  89. self.CreateRoom().Coroutine();
  90. }
  91. else
  92. {
  93. self.ReturnRoom().Coroutine();
  94. }
  95. }
  96. public static async void OnJoinRoom(this UIMainComponent self)
  97. {
  98. await SoundManager.Instance.PlaySound("clickbtnsound");
  99. await UIHelper.Create(self.ClientScene(), UIType.UIJoinRoom, UILayer.High);
  100. }
  101. public static async void OnClub(this UIMainComponent self)
  102. {
  103. await SoundManager.Instance.PlaySound("clickbtnsound");
  104. var scene = self.ClientScene();
  105. await UIHelper.Remove(scene, UIType.UIMain);
  106. await UIHelper.Create(scene, UIType.UIClubCreate, UILayer.Mid);
  107. }
  108. #endregion
  109. #region 头像点击
  110. public static void OnPlayer(this UIMainComponent self)
  111. {
  112. }
  113. #endregion
  114. #region 下面按钮
  115. public static async void OnShop(this UIMainComponent self)
  116. {
  117. await SoundManager.Instance.PlaySound("clickbtnsound");
  118. await UIHelper.Create(self.ClientScene(), UIType.UIShop, UILayer.Mid);
  119. }
  120. public static async void OnSetting(this UIMainComponent self)
  121. {
  122. await SoundManager.Instance.PlaySound("clickbtnsound");
  123. await UIHelper.Create(self.ClientScene(), UIType.UISetting, UILayer.Mid);
  124. }
  125. public static async void OnRule(this UIMainComponent self)
  126. {
  127. await SoundManager.Instance.PlaySound("clickbtnsound");
  128. await UIHelper.Create(self.ClientScene(), UIType.UIRule, UILayer.Mid);
  129. }
  130. public static async void OnStats(this UIMainComponent self)
  131. {
  132. await SoundManager.Instance.PlaySound("clickbtnsound");
  133. await UIHelper.Create(self.ClientScene(), UIType.UIStats, UILayer.Mid);
  134. }
  135. public static async void OnShare(this UIMainComponent self)
  136. {
  137. await SoundManager.Instance.PlaySound("clickbtnsound");
  138. await UIHelper.Create(self.ClientScene(), UIType.UIShare, UILayer.Mid);
  139. }
  140. public static async void OnAvtive(this UIMainComponent self)
  141. {
  142. await SoundManager.Instance.PlaySound("clickbtnsound");
  143. await UIHelper.Create(self.ClientScene(), UIType.UIAvtive, UILayer.Mid);
  144. }
  145. #endregion
  146. #region 左边按钮
  147. public static async void OnIphone(this UIMainComponent self)
  148. {
  149. await SoundManager.Instance.PlaySound("clickbtnsound");
  150. await UIHelper.Create(self.ClientScene(), UIType.UIIphone, UILayer.Mid);
  151. }
  152. public static async void OnInvitationCode(this UIMainComponent self)
  153. {
  154. await SoundManager.Instance.PlaySound("clickbtnsound");
  155. await UIHelper.Create(self.ClientScene(), UIType.UIInvate, UILayer.Mid);
  156. }
  157. public static async void OnRealName(this UIMainComponent self)
  158. {
  159. await SoundManager.Instance.PlaySound("clickbtnsound");
  160. await UIHelper.Create(self.ClientScene(), UIType.UIRealNameAuthen, UILayer.Mid);
  161. }
  162. #endregion
  163. #region 上面按钮
  164. public static async void OnHourseCardAdd(this UIMainComponent self)
  165. {
  166. await SoundManager.Instance.PlaySound("clickbtnsound");
  167. }
  168. public static async void OnCurService(this UIMainComponent self)
  169. {
  170. await SoundManager.Instance.PlaySound("clickbtnsound");
  171. await UIHelper.Create(self.ClientScene(), UIType.UICustomerService, UILayer.Mid);
  172. }
  173. public static async void OnCloseTitle(this UIMainComponent self)
  174. {
  175. await SoundManager.Instance.PlaySound("clickbtnsound");
  176. self.titlePanelObj.SetActive(false);
  177. }
  178. public static async void OnMessage(this UIMainComponent self)
  179. {
  180. await SoundManager.Instance.PlaySound("clickbtnsound");
  181. await UIHelper.Create(self.ClientScene(), UIType.UIMessage, UILayer.Mid);
  182. }
  183. #endregion
  184. static async ETTask CreateRoom(this UIMainComponent self)
  185. {
  186. try
  187. {
  188. await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_CreatRoom,null, async (messageObj,errorCode) =>
  189. {
  190. if (errorCode != ErrorCode.ERR_Success)
  191. {
  192. await CommonUtil.Instance.OpenCommonServerMsgPanel($"创建失败,errCode={errorCode}");
  193. return;
  194. }
  195. RoomInfo roomInfo = messageObj as RoomInfo;
  196. var startFightRoomComponment = GameUtil.Instance.GetSceneComponent().GetComponent<StartFightRoomComponment>();
  197. if (startFightRoomComponment == null)
  198. {
  199. startFightRoomComponment = GameUtil.Instance.GetSceneComponent().AddComponent<StartFightRoomComponment>();
  200. }
  201. startFightRoomComponment.ClearStartFightRoomInfo();
  202. startFightRoomComponment.SetStartFightRoomInfoFromCreate(roomInfo);
  203. //目前就用一个场景吧,后面看再单独分开。
  204. //关闭主界面
  205. await UIHelper.Remove(GameUtil.Instance.GetSceneComponent(), UIType.UIMain);
  206. //打开开始打牌界面
  207. await UIHelper.Create(GameUtil.Instance.GetSceneComponent(), UIType.UIStartFightRoom, UILayer.Mid);
  208. });
  209. }
  210. catch (Exception e)
  211. {
  212. Log.Error($"创建房间出错...{e.Message}");
  213. }
  214. }
  215. static async ETTask ReturnRoom(this UIMainComponent self)
  216. {
  217. try
  218. {
  219. if (string.IsNullOrEmpty(self.roomId))
  220. {
  221. return;
  222. }
  223. Dictionary<string, object> dic = new Dictionary<string, object>()
  224. {
  225. { "roomId",self.roomId}
  226. };
  227. await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_JoinRoom, dic,async (messageObj, errorCode) =>
  228. {
  229. if (errorCode != ErrorCode.ERR_Success)
  230. {
  231. await CommonUtil.Instance.OpenCommonServerMsgPanel($"返回房间失败,errCode={errorCode}");
  232. return;
  233. }
  234. //关闭主界面
  235. await UIHelper.Remove(GameUtil.Instance.GetSceneComponent(), UIType.UIMain);
  236. //打开开始打牌界面
  237. await UIHelper.Create(GameUtil.Instance.GetSceneComponent(), UIType.UIStartFightRoom, UILayer.Mid);
  238. });
  239. }
  240. catch (Exception e)
  241. {
  242. Log.Error($"返回房间出错...{e.Message}");
  243. }
  244. }
  245. }
  246. }