SanAndreasUnity/Assets/Scripts/UI/ChatInputDisplay.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2019-11-16 16:55:00 +01:00
using UnityEngine;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.UI
{
public class ChatInputDisplay : MonoBehaviour
{
string m_chatText = "";
2019-11-16 16:59:34 +01:00
public ScreenCorner screenCorner = ScreenCorner.BottomRight;
public Vector2 padding = new Vector2(40, 40);
public float textInputWidth = 200;
2019-11-16 16:55:00 +01:00
void Start()
{
PauseMenu.onGUI += this.OnPauseMenuGUI;
}
void OnPauseMenuGUI()
{
string buttonText = "Send";
Vector2 buttonSize = GUIUtils.CalcScreenSizeForText(buttonText, GUI.skin.button);
2019-11-16 16:59:34 +01:00
Rect rect = GUIUtils.GetCornerRect(this.screenCorner, buttonSize, this.padding);
2019-11-16 16:55:00 +01:00
if (GUI.Button(rect, buttonText))
{
Chat.ChatManager.SendChatMessageToAllPlayersAsLocalPlayer(m_chatText);
m_chatText = "";
}
2019-11-16 16:59:34 +01:00
rect.xMin -= this.textInputWidth;
2019-11-16 16:55:00 +01:00
rect.xMax -= buttonSize.x + 15;
2019-11-16 17:15:49 +01:00
GUI.SetNextControlName("chat_text_input");
2019-11-16 16:55:00 +01:00
m_chatText = GUI.TextField(rect, m_chatText, 100);
2019-11-16 17:15:49 +01:00
if (Event.current.isKey && GUI.GetNameOfFocusedControl () == "chat_text_input")
{
if (Event.current.keyCode == KeyCode.Return)
{
// enter pressed
Chat.ChatManager.SendChatMessageToAllPlayersAsLocalPlayer(m_chatText);
m_chatText = "";
}
}
2019-11-16 17:54:33 +01:00
GUI.SetNextControlName("");
2019-11-16 16:55:00 +01:00
}
}
}