2020-12-22 03:13:43 +00:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
using System.Collections;
|
2020-03-26 02:49:09 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
|
|
public class LoginScreen : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public FlatButton LoginButton;
|
|
|
|
|
|
public FlatButton RegisterButton;
|
2020-03-27 17:26:26 +00:00
|
|
|
|
public TMP_InputField Server;
|
2020-03-26 02:49:09 +00:00
|
|
|
|
public TMP_InputField EmailUsername;
|
|
|
|
|
|
public TMP_InputField Email;
|
|
|
|
|
|
public TMP_InputField Username;
|
|
|
|
|
|
public TMP_InputField Password;
|
|
|
|
|
|
public TextMeshProUGUI Error;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _registering;
|
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
2020-03-27 01:53:03 +00:00
|
|
|
|
Error.text = " ";
|
2020-03-26 02:49:09 +00:00
|
|
|
|
LoginButton.CurrentState = FlatButtonState.Selected;
|
|
|
|
|
|
CultClient.AddMessageListener<LoginSuccessMessage>(success => SceneManager.LoadScene("Main"));
|
2020-03-27 01:53:03 +00:00
|
|
|
|
CultClient.OnError += s => Error.text = s;
|
2020-05-31 03:10:11 +01:00
|
|
|
|
RegisterButton.OnClick += () =>
|
2020-03-26 02:49:09 +00:00
|
|
|
|
{
|
2020-03-28 05:18:57 +00:00
|
|
|
|
if(!CultClient.Connected)
|
|
|
|
|
|
CultClient.Connect(Server.text);
|
2020-03-26 02:49:09 +00:00
|
|
|
|
if (_registering)
|
|
|
|
|
|
{
|
|
|
|
|
|
CultClient.Register(Email.text, Username.text, Password.text);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_registering = true;
|
|
|
|
|
|
EmailUsername.gameObject.SetActive(false);
|
|
|
|
|
|
Email.gameObject.SetActive(true);
|
|
|
|
|
|
Username.gameObject.SetActive(true);
|
|
|
|
|
|
LoginButton.CurrentState = FlatButtonState.Unselected;
|
|
|
|
|
|
RegisterButton.CurrentState = FlatButtonState.Selected;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2020-05-31 03:10:11 +01:00
|
|
|
|
LoginButton.OnClick += () =>
|
2020-03-26 02:49:09 +00:00
|
|
|
|
{
|
2020-03-28 05:18:57 +00:00
|
|
|
|
if(!CultClient.Connected)
|
|
|
|
|
|
CultClient.Connect(Server.text);
|
2020-03-26 02:49:09 +00:00
|
|
|
|
if (_registering)
|
|
|
|
|
|
{
|
|
|
|
|
|
_registering = false;
|
|
|
|
|
|
EmailUsername.gameObject.SetActive(true);
|
|
|
|
|
|
Email.gameObject.SetActive(false);
|
|
|
|
|
|
Username.gameObject.SetActive(false);
|
|
|
|
|
|
LoginButton.CurrentState = FlatButtonState.Selected;
|
|
|
|
|
|
RegisterButton.CurrentState = FlatButtonState.Unselected;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CultClient.Login(EmailUsername.text, Password.text);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2020-03-29 04:19:24 +01:00
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Server.isFocused)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_registering)
|
|
|
|
|
|
Email.Select();
|
|
|
|
|
|
else EmailUsername.Select();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (EmailUsername.isFocused)
|
|
|
|
|
|
Password.Select();
|
|
|
|
|
|
else if (Email.isFocused)
|
|
|
|
|
|
Username.Select();
|
|
|
|
|
|
else if (Username.isFocused)
|
|
|
|
|
|
Password.Select();
|
|
|
|
|
|
else if (Password.isFocused && Input.GetKeyDown(KeyCode.Return))
|
|
|
|
|
|
(_registering ? RegisterButton : LoginButton).OnPointerClick(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-03-26 02:49:09 +00:00
|
|
|
|
}
|