MyCenterForms.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using SUIFW;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class MyCenterForms : BaseUIForms
  8. {
  9. public RawImage texIcon;
  10. public Text userName;
  11. public Text userAccount;
  12. public Text accountManager;
  13. public static Action<Texture> swithAvatarAction;
  14. public AvatarList avatarList;
  15. public GameObject AvatarListObj;
  16. public Button showAcatarListBtn;
  17. public Button closeAcatarListBtn;
  18. public GameObject ChangeNameObj;
  19. public ChangeNamePop changeNamePop;
  20. public Button changeNameBtn;
  21. public GameObject LimitObj;
  22. public Button showLimitObjBtn;
  23. public Button closeLimitObjBtn;
  24. public GameObject ActivityObj;
  25. public ActivityMgr activityMgr;
  26. public Button activityBtn;
  27. public Text activityBtnText;
  28. public Button loginOutBtn;
  29. public Button returnBtn;
  30. private void Awake()
  31. {
  32. swithAvatarAction += OnSwithAvatar;
  33. showAcatarListBtn.onClick.AddListener(ShowAvatarListPop);
  34. closeAcatarListBtn.onClick.AddListener(CloseAvatarListPop);
  35. changeNameBtn.onClick.AddListener(ClickOnChangeName);
  36. showLimitObjBtn.onClick.AddListener(ShowLimitObj);
  37. closeLimitObjBtn.onClick.AddListener(HeidLimitObj);
  38. activityBtn.onClick.AddListener(ShowActivityObj);
  39. loginOutBtn.onClick.AddListener(ClickOnLoginOut);
  40. returnBtn.onClick.AddListener(ClickOnReturn);
  41. }
  42. private void Start()
  43. {
  44. avatarList.Init();
  45. }
  46. #region 窗体生命周期
  47. public override void Display()
  48. {
  49. base.Display();
  50. Init();
  51. }
  52. public override void Redisplay()
  53. {
  54. base.Redisplay();
  55. }
  56. public override void Freeze()
  57. {
  58. base.Freeze();
  59. }
  60. public override void Hiding()
  61. {
  62. base.Hiding();
  63. }
  64. #endregion
  65. public void Init()
  66. {
  67. if (UserInfo.textIcon == null)
  68. {
  69. texIcon.texture = UserInfo.defaulttextIcon;
  70. }
  71. else
  72. {
  73. texIcon.texture = UserInfo.textIcon;
  74. }
  75. userAccount.text = "当前账号: " + UserInfo.Account;
  76. if (UserInfo.userName == "")
  77. {
  78. userName.text = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length - 4);
  79. }
  80. else
  81. {
  82. userName.text = UserInfo.userName;
  83. }
  84. activityBtn.gameObject.SetActive(true);
  85. switch (UserInfo.activateType)
  86. {
  87. case 1:
  88. accountManager.text = "未激活账号";
  89. accountManager.color = Color.gray;
  90. activityBtnText.text = "激活";
  91. break;
  92. case 2:
  93. string indate = UserInfo.indate.ToString();
  94. if (indate == "0")
  95. {
  96. accountManager.text = "未激活账号";
  97. accountManager.color = Color.gray;
  98. activityBtnText.text = "激活";
  99. }
  100. else
  101. {
  102. string ti = GetTime(UserInfo.indate);
  103. accountManager.text = "账号已激活 有效期至" + ti;
  104. ChangeTextGreen();
  105. activityBtnText.text = "续费";
  106. }
  107. break;
  108. case 3:
  109. accountManager.text = "账号永久激活";
  110. ChangeTextGreen();
  111. activityBtn.gameObject.SetActive(false);
  112. break;
  113. }
  114. AvatarListObj.SetActive(false);
  115. ChangeNameObj.SetActive(false);
  116. LimitObj.SetActive(false);
  117. ActivityObj.SetActive(false);
  118. accountManager.gameObject.SetActive(false);
  119. showLimitObjBtn.gameObject.SetActive(false);
  120. }
  121. private void OnSwithAvatar(Texture tex)
  122. {
  123. texIcon.texture = tex;
  124. }
  125. public void LoginOut()
  126. {
  127. SaveNameandAvatar();
  128. WSHandler.clientClosed();
  129. CloseOrReturnUIForms();
  130. ShowUIForms(SysConst.LoginForms);
  131. }
  132. private void SaveNameandAvatar()
  133. {
  134. if (userName.text != "")
  135. {
  136. UserInfo.userName = userName.text;
  137. }
  138. NetWorkHeaders.SetUserInfo();
  139. }
  140. private void ClickOnReturn()
  141. {
  142. SaveNameandAvatar();
  143. CloseOrReturnUIForms();
  144. ShowUIForms(SysConst.MainPanelForms);
  145. }
  146. private void ClickOnLoginOut()
  147. {
  148. ShowUIForms(SysConst.PopForms);
  149. PopForms.Instance.ShowPublic(PopType.PopTwo, RtcStrConfig.outLoginmsg, "确定", () => { LoginOut(); }, "取消");
  150. }
  151. public void ShowAvatarListPop()
  152. {
  153. AvatarListObj.SetActive(true);
  154. }
  155. public void CloseAvatarListPop()
  156. {
  157. AvatarListObj.SetActive(false);
  158. }
  159. public void ClickOnChangeName()
  160. {
  161. ChangeNameObj.SetActive(true);
  162. changeNamePop.Init();
  163. }
  164. public void ShowLimitObj()
  165. {
  166. LimitObj.SetActive(true);
  167. }
  168. public void HeidLimitObj()
  169. {
  170. LimitObj.SetActive(false);
  171. }
  172. public void ShowActivityObj()
  173. {
  174. ActivityObj.SetActive(true);
  175. activityMgr.Init();
  176. }
  177. private void ChangeTextGreen()
  178. {
  179. Color color = Color.white;
  180. color.r = 74 / 255f;
  181. color.g = 227 / 255f;
  182. color.b = 173 / 255f;
  183. color.a = 255 / 255f;
  184. accountManager.color = color;
  185. }
  186. public string GetTime(double timechu)
  187. {
  188. DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  189. DateTime dt = startTime.AddSeconds(timechu);
  190. string t = dt.ToString("yyyy-MM-dd HH:mm:ss");
  191. string[] arr = t.Split(' ');
  192. return arr[0];
  193. }
  194. private void OnDestroy()
  195. {
  196. swithAvatarAction -= OnSwithAvatar;
  197. }
  198. }