123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Api;
- using Plugins.CxShine.page;
- using UI.Common;
- using UI.Loading;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- public class LoginComp : MonoBehaviour
- {
- public GameObject LoginUI;
- public GameObject hallPrefab;
- public Dropdown Dropdown;
- public Text PhoneFront;
- public InputField PhoneInputField;
- public InputField CodeInputField;
- public GameObject SendButton;
- public LoadingComp LoadingComp;
- private bool _sending = false;
- private float _sendTime;
- Dictionary<string, string> phonePrefixes = new Dictionary<string, string>
- {
- { "India", "+91" },
- { "Brunei", "+673" },
- { "Cambodia", "+855" },
- { "Indonesia", "+62" },
- { "Laos", "+856" },
- { "Malaysia", "+60" },
- { "Myanmar", "+95" },
- { "Philippines", "+63" },
- { "Singapore", "+65" },
- { "Thailand", "+66" },
- { "Vietnam", "+84" }
- };
- public string GetPhonePrefixByCountry(string countryName)
- {
- if (phonePrefixes.ContainsKey(countryName))
- {
- return phonePrefixes[countryName];
- }
- return null;
- }
- void Start()
- {
- openLoading();
- if (AccountManager.Instance.HasSession())
- {
- AccountManager.Instance.requestSelfInfo(data => { OnLoginSuccess(); }, (code, err) =>
- {
- TipsComp.ShowTips("Need Login");
- initLoginUI();
- });
- }
- else
- {
- initLoginUI();
- }
- }
- private void openLoading()
- {
- LoginUI.SetActive(false);
- LoadingComp.gameObject.SetActive(true);
- }
- private void closeLoading()
- {
- LoginUI.SetActive(true);
- LoadingComp.gameObject.SetActive(false);
- }
- private void OpenHall()
- {
- PageManagerComp.singleton.OpenPage(hallPrefab);
- }
- private void OnLoginSuccess()
- {
- ApiComp.Instance.LoadConfig(() =>
- {
- Invoke(nameof(OpenHall), 3.0f);
- },
- (a, b) =>
- {
- closeLoading();
- TipsComp.ShowTips("LoadConfigErr" + b);
- });
- }
- private void initLoginUI()
- {
- closeLoading();
- Dropdown.options.Clear();
- foreach (var key in phonePrefixes.Keys)
- {
- Dropdown.options.Add(new Dropdown.OptionData(key + "" + phonePrefixes[key]));
- }
- RefreshFrontPhoneUI();
- }
- private void RefreshFrontPhoneUI()
- {
- PhoneFront.text = getCurrentSelectValue();
- }
- public void A__OnDropdownSelected()
- {
- RefreshFrontPhoneUI();
- }
- private string getCurrentSelectValue()
- {
- int i = 0;
- foreach (var key in phonePrefixes.Keys)
- {
- if (i == Dropdown.value)
- {
- return phonePrefixes[key];
- }
- i++;
- }
- return phonePrefixes["India"];
- }
- private void HideSendButton()
- {
- // SendButton.SetActive(false);
- _sending = true;
- _sendTime = Time.time;
- InvokeRepeating(nameof(Repeat1SecondsCheckSendButton), 0.01f, 1.0f);
- }
- private void Repeat1SecondsCheckSendButton()
- {
- if (_sending)
- {
- int seconds = 30 - (int)(Time.time - _sendTime);
- if (seconds < 0)
- {
- _sending = false;
- CancelInvoke(nameof(Repeat1SecondsCheckSendButton));
- SendButton.gameObject.GetComponentInChildren<Text>().text = "send";
- }
- else
- {
- SendButton.gameObject.GetComponentInChildren<Text>().text = seconds + "";
- }
- }
- }
- public void A__ClickSendCode()
- {
- if (_sending)
- {
- TipsComp.ShowTips("wait");
- return;
- }
- string verify = PhoneInputField.text.Trim().Replace(" ","");
- if (String.IsNullOrEmpty(verify) || !float.TryParse(verify, out _))
- {
- TipsComp.ShowTips("Phone Number Error");
- return;
- }
- openLoading();
- string phone = getCurrentSelectValue().Replace("+", "") + PhoneInputField.text.Trim().Replace(" ","");
- ApiComp.Instance.NotSessionSendVerifyCode(phone,
- data =>
- {
- closeLoading();
- TipsComp.ShowTips("Success!Please enter your Code");
- HideSendButton();
- },
- (code, err) =>
- {
- closeLoading();
- TipsComp.ShowTips(err);
- });
- }
- public void A__ClickLogin()
- {
- string verify = PhoneInputField.text.Trim().Replace(" ","");
- if (String.IsNullOrEmpty(verify) || !float.TryParse(verify, out _))
- {
- TipsComp.ShowTips("Phone Number Error");
- return;
- }
- verify = CodeInputField.text.Trim();
- if (String.IsNullOrEmpty(verify) || !float.TryParse(verify, out _))
- {
- TipsComp.ShowTips("Code Number Error");
- return;
- }
-
- openLoading();
-
- string phone = getCurrentSelectValue().Replace("+", "") + PhoneInputField.text.Trim().Replace(" ","");
- string code = CodeInputField.text.Trim();
- bool isIndia = getCurrentSelectValue().Equals("+91");
-
- Debug.Log("is India"+isIndia);
- AccountManager.Instance.login(phone, code, isIndia, data =>
- {
- OnLoginSuccess();
- },
- (code, err) =>
- {
- closeLoading();
- TipsComp.ShowTips("LoginError" + err);
- }
- );
- }
- }
|