80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using System.Collections;
|
|
|
|
using Audio;
|
|
|
|
using Network;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace ConsoleConnection
|
|
{
|
|
public class TextFieldPopup : MonoBehaviour
|
|
{
|
|
[Header("Input field")]
|
|
public InputField InputField = null;
|
|
public Button ValidateButton = null;
|
|
|
|
[Header("Search field")]
|
|
public RectTransform ChangePlayerNameContainer;
|
|
public RectTransform TopMenuContainer;
|
|
|
|
private TouchScreenKeyboard keyboard;
|
|
public Button CancelButton;
|
|
|
|
private void Start()
|
|
{
|
|
CancelButton.onClick.AddListener(() =>
|
|
{
|
|
CancelKeyboard();
|
|
AudioManager.Instance.Play(AudioManager.SoundIds.Back);
|
|
});
|
|
|
|
ValidateButton.onClick.AddListener(() => {
|
|
SubmitText();
|
|
});
|
|
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
HideKeyboard();
|
|
}
|
|
|
|
public void ShowKeyboard(bool isPassword = false)
|
|
{
|
|
StartCoroutine(WaitForFirstFocus(isPassword));
|
|
}
|
|
|
|
// we need to wait a frame in order to be able to display the keyboard.
|
|
private IEnumerator WaitForFirstFocus(bool isPassword = false)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
if (isPassword)
|
|
InputField.contentType = InputField.ContentType.Password;
|
|
else {
|
|
InputField.contentType = InputField.ContentType.Standard;
|
|
}
|
|
|
|
keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, isPassword);
|
|
InputField.Select();
|
|
}
|
|
|
|
public void SubmitText()
|
|
{
|
|
ConsoleNetworkManager.Instance.Send(JSONParseHelper.GetSubmitKeyboardCommand(InputField.text));
|
|
}
|
|
|
|
public void CancelKeyboard()
|
|
{
|
|
ConsoleNetworkManager.Instance.Send(JSONParseHelper.GetCancelKeyboardCommand());
|
|
}
|
|
|
|
public void HideKeyboard()
|
|
{
|
|
// DeactivateInputField doesn't work here so we use this hack to close the keyboard
|
|
keyboard.active = false;
|
|
}
|
|
}
|
|
}
|