HRB_RegisterView.cs 9.6 KB

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