RegisterView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. using UnityEngine.Networking;
  8. using System.Text.RegularExpressions;
  9. using DG.Tweening;
  10. using Newtonsoft.Json;
  11. /* 注册界面 */
  12. public class RegisterView : MonoBehaviour
  13. {
  14. [SerializeField] GameObject registerInUser;
  15. [SerializeField] GameObject registerInPWD1;
  16. [SerializeField] GameObject registerInPWD2;
  17. [SerializeField] GameObject registerInCaptcha;
  18. [SerializeField] GameObject registerInNickname;
  19. [SerializeField] GameObject registerInGender;
  20. [SerializeField] GameObject registerInBirthday;
  21. [SerializeField] GameObject registerInLocation;
  22. [SerializeField] GameObject btnNext;
  23. [SerializeField] GameObject btnSave;
  24. //状态记录
  25. public int captcha_Register = -222222222;
  26. void OnEnable()
  27. {
  28. InitPage();
  29. //弹出协议,不同意则退出注册
  30. AgreementPopup agreementPopup = transform.parent.Find("AgreementPopup").GetComponent<AgreementPopup>();
  31. agreementPopup.onDisagree = () => {
  32. agreementPopup.onDisagree = null;
  33. GameObject.FindObjectOfType<LoginMgr>().showLoginView();
  34. };
  35. agreementPopup.gameObject.SetActive(true);
  36. }
  37. void Start()
  38. {
  39. InitInputLimit();
  40. }
  41. void InitInputLimit() {
  42. GameObject[] inputNodes = {registerInUser, registerInPWD1, registerInPWD2};
  43. foreach (var inputNode in inputNodes) {
  44. InputField inputField = GetInputField(inputNode);
  45. inputField.onValueChanged.AddListener(delegate(string text) {
  46. Match match = new Regex("[^A-Za-z0-9]").Match(text);
  47. if (match.Success) {
  48. inputField.text = text.Replace(match.Value, "");
  49. }
  50. });
  51. }
  52. }
  53. void InitPage(bool isNext = false) {
  54. registerInUser.SetActive(!isNext);
  55. registerInPWD1.SetActive(!isNext);
  56. registerInPWD2.SetActive(!isNext);
  57. registerInCaptcha.SetActive(!isNext);
  58. btnNext.SetActive(!isNext);
  59. registerInNickname.SetActive(isNext);
  60. registerInGender.SetActive(isNext);
  61. registerInBirthday.SetActive(isNext);
  62. registerInLocation.SetActive(isNext);
  63. btnSave.SetActive(isNext);
  64. if (isNext) {
  65. GetLocation();
  66. } else {
  67. ChnageCaptcha();
  68. }
  69. }
  70. InputField GetInputField(GameObject inputNode) {
  71. return inputNode.transform.Find("InputField").GetComponent<InputField>();
  72. }
  73. public void ChnageCaptcha() {
  74. StartCoroutine(CaptchaController.Instance.GetCaptcha(
  75. registerInCaptcha.transform.Find("CodeImage").GetComponent<Image>(),
  76. (code) => { captcha_Register = code; }
  77. ));
  78. }
  79. private string usrRecord = "";
  80. private string pwdRecord = "";
  81. JCUnityLib.Throttler throttlerRegisterNext = new JCUnityLib.Throttler(2000);
  82. public void RegisterNext()
  83. {
  84. InputField user = GetInputField(registerInUser);
  85. if (user.text.Length < 6) {
  86. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("账号长度至少6位"));
  87. return;
  88. }
  89. InputField pwd1 = GetInputField(registerInPWD1);
  90. if (pwd1.text.Length < 6) {
  91. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("密码长度至少6位"));
  92. return;
  93. }
  94. InputField pwd2 = GetInputField(registerInPWD2);
  95. if (pwd1.text != pwd2.text) {
  96. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("两次输入的密码不一致"));
  97. return;
  98. }
  99. InputField captcha = GetInputField(registerInCaptcha);
  100. if (!captcha.text.Equals(captcha_Register.ToString())) {
  101. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("验证码错误"));
  102. return;
  103. }
  104. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  105. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  106. return;
  107. }
  108. if (throttlerRegisterNext.CanPass() == false) {
  109. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  110. return;
  111. }
  112. usrRecord = user.text;
  113. pwdRecord = pwd1.text;
  114. StartCoroutine(LoginController.Instance.Register(
  115. usrRecord, pwdRecord, (res) => {
  116. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  117. if (res.code == 0) {
  118. InitPage(true); //前往完善用户信息
  119. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  120. }
  121. }
  122. ));
  123. }
  124. JCUnityLib.Throttler throttlerRegisterSave = new JCUnityLib.Throttler(2000);
  125. public void RegisterSave() {
  126. InputField nickname = GetInputField(registerInNickname);
  127. string text_nickname = nickname.text.Trim();
  128. if (text_nickname.Length == 0) {
  129. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入游戏昵称"));
  130. return;
  131. }
  132. int gender = 0;
  133. Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
  134. for (int i = 0; i < toggleGroup.childCount; i++) {
  135. if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
  136. gender = i == 0 ? 1 : 2;
  137. break;
  138. }
  139. }
  140. InputField birthday = GetInputField(registerInBirthday);
  141. string text_birthday = birthday.text;
  142. if (text_birthday.Length != 10) {
  143. text_birthday = "2000-01-01";
  144. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写出生日期"));
  145. // return;
  146. }
  147. InputField location = GetInputField(registerInLocation);
  148. if (location.text.Length == 0) {
  149. countryCode = "";
  150. stateCode = "";
  151. cityCode = "";
  152. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写所在地区"));
  153. // return;
  154. }
  155. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  156. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  157. return;
  158. }
  159. if (throttlerRegisterSave.CanPass() == false) {
  160. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  161. return;
  162. }
  163. StartCoroutine(LoginController.Instance.CompleteUserInfo(
  164. usrRecord, pwdRecord, text_nickname, gender, text_birthday,
  165. countryCode, stateCode, cityCode
  166. ,(res) => {
  167. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  168. if (res.code == 0) {
  169. GameObject.FindObjectOfType<LoginMgr>().showLoginView();
  170. }
  171. }
  172. ));
  173. }
  174. #region Picker
  175. [SerializeField] GameObject datePickerPrefab;
  176. public void OpenDatePicker() {
  177. GameObject o = GameObject.Instantiate(datePickerPrefab);
  178. o.GetComponentInChildren<JC.Unity.Picker.DatePickerGroup>().onEnter += (JC.Unity.Picker.DatePickerGroup picker) => {
  179. GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
  180. };
  181. }
  182. [SerializeField] GameObject locationPickerPrefab;
  183. private string countryCode = "", stateCode = "", cityCode = "";
  184. public void OpenLocationPicker() {
  185. // GameObject o = GameObject.Instantiate(locationPickerPrefab);
  186. // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
  187. // countryCode = info.GetCountryRegion().Item2;
  188. // stateCode = info.GetState().Item2;
  189. // cityCode = info.GetCity().Item2;
  190. // GetInputField(registerInLocation).text =
  191. // info.GetCountryRegion().Item1 + " " +
  192. // info.GetState().Item1 + " " +
  193. // info.GetCity().Item1;
  194. // };
  195. //2022-12-6 gps获取地理位置
  196. GetLocation();
  197. }
  198. void GetLocation()
  199. {
  200. try
  201. {
  202. System.Action eOnAgree = () => {
  203. GPSTool.GetAddress((address) => {
  204. if (address != null) {
  205. countryCode = address[0];
  206. stateCode = address[1];
  207. cityCode = address[2];
  208. GetInputField(registerInLocation).text =
  209. countryCode + " " +
  210. stateCode + " " +
  211. cityCode;
  212. }
  213. });
  214. };
  215. if (!HomeView.ShowProminentBeforeConnectBLE(eOnAgree)) eOnAgree.Invoke();
  216. }
  217. catch (System.Exception e) { Debug.LogError(e); }
  218. }
  219. #endregion
  220. }