RegisterView.cs 12 KB

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