RegisterView.cs 12 KB

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