RegisterView.cs 11 KB

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