| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using UnityEngine.Networking;
- using System.Text.RegularExpressions;
- using DG.Tweening;
- using Newtonsoft.Json;
- using JCUnityLib;
- /* 注册界面 */
- public class HRB_RegisterView : ViewBase
- {
- [SerializeField] GameObject registerInUser;
- [SerializeField] GameObject registerInPWD1;
- [SerializeField] GameObject registerInPWD2;
- [SerializeField] GameObject registerInCaptcha;
- [SerializeField] GameObject registerInNickname;
- [SerializeField] GameObject registerInGender;
- [SerializeField] GameObject registerInBirthday;
- [SerializeField] GameObject registerInLocation;
- [SerializeField] GameObject btnBack;
- [SerializeField] GameObject btnNext;
- [SerializeField] GameObject btnSave;
- //状态记录
- int captcha_Register = -222222222;
- void OnEnable()
- {
- InitPage();
- //弹出协议,不同意则退出注册
- AgreementPopup agreementPopup = GameObject.Find("TempCanvas").transform.Find("AgreementPopup").GetComponent<AgreementPopup>();
- agreementPopup.onDisagree = () => {
- agreementPopup.onDisagree = null;
- HRB_ViewMgr.Instance.DestroyView<HRB_RegisterView>();
- };
- agreementPopup.gameObject.SetActive(true);
- }
- void Start()
- {
- InitInputLimit();
- btnBack.GetComponent<Button>().onClick.AddListener(() => {
- HRB_ViewMgr.Instance.DestroyView<HRB_RegisterView>();
- });
- btnNext.GetComponent<Button>().onClick.AddListener(RegisterNext);
- btnSave.GetComponent<Button>().onClick.AddListener(RegisterSave);
- registerInBirthday.GetComponent<Button>().onClick.AddListener(OpenDatePicker);
- registerInLocation.GetComponent<Button>().onClick.AddListener(OpenLocationPicker);
- }
- void InitInputLimit() {
- GameObject[] inputNodes = {registerInUser, registerInPWD1, registerInPWD2};
- foreach (var inputNode in inputNodes) {
- InputField inputField = GetInputField(inputNode);
- inputField.onValueChanged.AddListener(delegate(string text) {
- Match match = new Regex("[^A-Za-z0-9]").Match(text);
- if (match.Success) {
- inputField.text = text.Replace(match.Value, "");
- }
- });
- }
- }
- void InitPage(bool isNext = false) {
- registerInUser.SetActive(!isNext);
- registerInPWD1.SetActive(!isNext);
- registerInPWD2.SetActive(!isNext);
- registerInCaptcha.SetActive(!isNext);
- btnNext.SetActive(!isNext);
- registerInNickname.SetActive(isNext);
- registerInGender.SetActive(isNext);
- registerInBirthday.SetActive(isNext);
- registerInLocation.SetActive(isNext);
- btnSave.SetActive(isNext);
- if (isNext) {
- DoTweenUtil.CallDelay(1, GetLocation);
- } else {
- ChnageCaptcha();
- }
- }
- InputField GetInputField(GameObject inputNode) {
- return inputNode.transform.Find("InputField").GetComponent<InputField>();
- }
- public void ChnageCaptcha() {
- StartCoroutine(CaptchaController.Instance.GetCaptcha(
- registerInCaptcha.transform.Find("CodeImage").GetComponent<Image>(),
- (code) => { captcha_Register = code; }
- ));
- }
- private string usrRecord = "";
- private string pwdRecord = "";
- JCUnityLib.Throttler throttlerRegisterNext = new JCUnityLib.Throttler(2000);
- public void RegisterNext()
- {
- InputField user = GetInputField(registerInUser);
- if (user.text.Length < 6) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("账号长度至少6位"));
- return;
- }
- InputField pwd1 = GetInputField(registerInPWD1);
- if (pwd1.text.Length < 6) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("密码长度至少6位"));
- return;
- }
- InputField pwd2 = GetInputField(registerInPWD2);
- if (pwd1.text != pwd2.text) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("两次输入的密码不一致"));
- return;
- }
- InputField captcha = GetInputField(registerInCaptcha);
- if (!captcha.text.Equals(captcha_Register.ToString())) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("验证码错误"));
- return;
- }
- if (!AgreenmentOption.ins.IsAgreementChecked()) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
- return;
- }
- if (throttlerRegisterNext.CanPass() == false) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
- return;
- }
- usrRecord = user.text;
- pwdRecord = pwd1.text;
- StartCoroutine(LoginController.Instance.Register(
- usrRecord, pwdRecord, (res) => {
- if (res.code == 0) {
- PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByCNKey(res.msg));
- InitPage(true); //前往完善用户信息
- HRB_ViewMgr.Instance.NotifyView<HRB_LoginView>("FillLoginInput", usrRecord, pwdRecord);
- } else {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
- }
- }
- ));
- }
- JCUnityLib.Throttler throttlerRegisterSave = new JCUnityLib.Throttler(2000);
- public void RegisterSave() {
- InputField nickname = GetInputField(registerInNickname);
- string text_nickname = nickname.text.Trim();
- if (text_nickname.Length == 0) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入游戏昵称"));
- return;
- }
- int gender = 0;
- Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
- for (int i = 0; i < toggleGroup.childCount; i++) {
- if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
- gender = i == 0 ? 1 : 2;
- break;
- }
- }
- InputField birthday = GetInputField(registerInBirthday);
- string text_birthday = birthday.text;
- if (text_birthday.Length != 10) {
- text_birthday = "2000-01-01";
- // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写出生日期"));
- // return;
- }
- InputField location = GetInputField(registerInLocation);
- if (location.text.Length == 0) {
- countryCode = "";
- stateCode = "";
- cityCode = "";
- // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写所在地区"));
- // return;
- }
- if (!AgreenmentOption.ins.IsAgreementChecked()) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
- return;
- }
- if (throttlerRegisterSave.CanPass() == false) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
- return;
- }
- StartCoroutine(LoginController.Instance.CompleteUserInfo(
- usrRecord, pwdRecord, text_nickname, gender, text_birthday,
- countryCode, stateCode, cityCode
- ,(res) => {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
- if (res.code == 0) {
- HRB_ViewMgr.Instance.DestroyView<HRB_RegisterView>();
- }
- }
- ));
- }
- #region Picker
- [SerializeField] GameObject datePickerPrefab;
- public void OpenDatePicker() {
- GameObject o = GameObject.Instantiate(datePickerPrefab);
- o.GetComponentInChildren<JC.Unity.Picker.DatePickerGroup>().onEnter += (JC.Unity.Picker.DatePickerGroup picker) => {
- GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
- };
- }
- [SerializeField] GameObject locationPickerPrefab;
- private string countryCode = "", stateCode = "", cityCode = "";
- public void OpenLocationPicker() {
- // GameObject o = GameObject.Instantiate(locationPickerPrefab);
- // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
- // countryCode = info.GetCountryRegion().Item2;
- // stateCode = info.GetState().Item2;
- // cityCode = info.GetCity().Item2;
- // GetInputField(registerInLocation).text =
- // info.GetCountryRegion().Item1 + " " +
- // info.GetState().Item1 + " " +
- // info.GetCity().Item1;
- // };
- //2022-12-6 gps获取地理位置
- GetLocation();
- }
- void GetLocation()
- {
- try
- {
- System.Action eOnAgree = () => {
- GPSTool.GetAddress((address) => {
- if (address != null) {
- countryCode = address[0];
- stateCode = address[1];
- cityCode = address[2];
- GetInputField(registerInLocation).text =
- countryCode + " " +
- stateCode + " " +
- cityCode;
- }
- });
- };
- if (!HomeView.ShowProminentBeforeConnectBLE(eOnAgree)) eOnAgree.Invoke();
- }
- catch (System.Exception e) { Debug.LogError(e); }
- }
- #endregion
- }
|