|
|
@@ -0,0 +1,208 @@
|
|
|
+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;
|
|
|
+
|
|
|
+/* 注册界面 */
|
|
|
+public class RegisterView : MonoBehaviour
|
|
|
+{
|
|
|
+ [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 btnNext;
|
|
|
+ [SerializeField] GameObject btnSave;
|
|
|
+ [SerializeField] Text registerTip;
|
|
|
+
|
|
|
+ void OnEnable()
|
|
|
+ {
|
|
|
+ InitPage();
|
|
|
+ }
|
|
|
+
|
|
|
+ void Start()
|
|
|
+ {
|
|
|
+ InitInputLimit();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ if (CaptchaController.ins.captcha_Register < 0) {
|
|
|
+ StartCoroutine(CaptchaController.ins.GetCaptcha(
|
|
|
+ CaptchaController.CaptchaType.Register,
|
|
|
+ registerInCaptcha.transform.Find("CodeImage").GetComponent<Image>()
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ InputField GetInputField(GameObject inputNode) {
|
|
|
+ return inputNode.transform.Find("InputField").GetComponent<InputField>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private string usrRecord = "";
|
|
|
+ private string pwdRecord = "";
|
|
|
+ public void RegisterNext()
|
|
|
+ {
|
|
|
+ InputField user = GetInputField(registerInUser);
|
|
|
+ if (user.text.Length < 6) {
|
|
|
+ registerTip.color = Color.red;
|
|
|
+ registerTip.GetComponent<TextAutoLanguage>().SetText(46);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InputField pwd1 = GetInputField(registerInPWD1);
|
|
|
+ if (pwd1.text.Length < 6) {
|
|
|
+ registerTip.color = Color.red;
|
|
|
+ registerTip.GetComponent<TextAutoLanguage>().SetText(47);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InputField pwd2 = GetInputField(registerInPWD2);
|
|
|
+ if (pwd1.text != pwd2.text) {
|
|
|
+ registerTip.color = Color.red;
|
|
|
+ registerTip.GetComponent<TextAutoLanguage>().SetText(48);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InputField captcha = GetInputField(registerInCaptcha);
|
|
|
+ if (!captcha.text.Equals(CaptchaController.ins.captcha_Register.ToString())) {
|
|
|
+ Debug.Log("验证码错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ usrRecord = user.text;
|
|
|
+ pwdRecord = pwd1.text;
|
|
|
+ StartCoroutine(LoginController.ins.Register(
|
|
|
+ usrRecord, pwdRecord, (res) => {
|
|
|
+ Debug.Log(res.msg);
|
|
|
+ if (res.code == 0) {
|
|
|
+ InitPage(true); //前往完善用户信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ));
|
|
|
+ // InputField nickname = GetInputField(registerInNickname);
|
|
|
+ // if (nickname.text.Trim().Length == 0) {
|
|
|
+ // registerTip.color = Color.yellow;
|
|
|
+ // registerTip.GetComponent<TextAutoLanguage>().SetText(49);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // UserInfos userInfos = GetUserInfos();
|
|
|
+ // foreach (var userInfo in userInfos.list)
|
|
|
+ // {
|
|
|
+ // if (userInfo.user == user.text) {
|
|
|
+ // registerTip.color = Color.yellow;
|
|
|
+ // registerTip.GetComponent<TextAutoLanguage>().SetText(50);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // UserInfo userInfo1 = new UserInfo();
|
|
|
+ // userInfo1.user = user.text;
|
|
|
+ // userInfo1.pwd = pwd1.text;
|
|
|
+ // userInfo1.nickname = nickname.text;
|
|
|
+ // Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
|
|
|
+ // for (int i = 0; i < toggleGroup.childCount; i++) {
|
|
|
+ // if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
|
|
|
+ // userInfo1.gender = i == 0 ? 1 : 2;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // userInfos.list.Add(userInfo1);
|
|
|
+ // SetUserInfos(userInfos);
|
|
|
+ // registerTip.color = Color.green;
|
|
|
+ // registerTip.GetComponent<TextAutoLanguage>().SetText(51);
|
|
|
+ // //自动跳转到登录并填写登录信息
|
|
|
+ // GetInputField(loginInUser).text = userInfo1.user;
|
|
|
+ // GetInputField(loginInPWD).text = userInfo1.pwd;
|
|
|
+ // SelectLoginMode(1);
|
|
|
+ // Invoke("showLoginView", 0.5f);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RegisterSave() {
|
|
|
+ InputField nickname = GetInputField(registerInNickname);
|
|
|
+ if (nickname.text.Trim().Length == 0) {
|
|
|
+ registerTip.color = Color.yellow;
|
|
|
+ registerTip.GetComponent<TextAutoLanguage>().SetText(49);
|
|
|
+ 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);
|
|
|
+ if (birthday.text.Length != 10) {
|
|
|
+ Debug.Log("未填写出生日期");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InputField location = GetInputField(registerInLocation);
|
|
|
+ if (location.text.Length == 0) {
|
|
|
+ Debug.Log("未填写所在地区");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StartCoroutine(LoginController.ins.CompleteUserInfo(
|
|
|
+ usrRecord, pwdRecord, nickname.text, gender, birthday.text,
|
|
|
+ countryCode, stateCode, cityCode
|
|
|
+ ,(res) => {
|
|
|
+ Debug.Log(res.msg);
|
|
|
+ if (res.code == 0) {
|
|
|
+ GameObject.FindObjectOfType<LoginMgr>().showLoginView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ [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;
|
|
|
+ };
|
|
|
+ }
|
|
|
+}
|