mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 21:08:28 +00:00
draw chat
This commit is contained in:
parent
f41fa4b591
commit
e7272ef710
1 changed files with 41 additions and 0 deletions
|
@ -26,12 +26,29 @@ namespace SanAndreasUnity.UI {
|
|||
public static Texture2D UpArrowTexture { get; set; }
|
||||
public static Texture2D DownArrowTexture { get; set; }
|
||||
|
||||
public int maxNumChatMessages = 5;
|
||||
|
||||
Queue<Chat.ChatMessage> m_chatMessages = new Queue<Chat.ChatMessage>();
|
||||
|
||||
|
||||
|
||||
void Awake () {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Chat.ChatManager.onChatMessage += OnChatMsg;
|
||||
}
|
||||
|
||||
void OnChatMsg(Chat.ChatMessage chatMsg)
|
||||
{
|
||||
if (m_chatMessages.Count >= this.maxNumChatMessages)
|
||||
m_chatMessages.Dequeue();
|
||||
|
||||
m_chatMessages.Enqueue(chatMsg);
|
||||
}
|
||||
|
||||
void OnGUI () {
|
||||
|
||||
if (!Loader.HasLoaded)
|
||||
|
@ -50,6 +67,10 @@ namespace SanAndreasUnity.UI {
|
|||
// draw hud
|
||||
DrawHud( this.hudScreenCorner, this.hudSize, this.hudPadding, this.healthColor, this.healthBackgroundColor );
|
||||
|
||||
// draw chat
|
||||
if (! GameManager.IsInStartupScene && ! PauseMenu.IsOpened)
|
||||
DrawChat(m_chatMessages);
|
||||
|
||||
// draw dot in the middle of screen
|
||||
if (this.drawRedDotOnScreenCenter)
|
||||
GUIUtils.DrawRect (GUIUtils.GetCenteredRect (new Vector2 (2f, 2f)), Color.red);
|
||||
|
@ -167,6 +188,26 @@ namespace SanAndreasUnity.UI {
|
|||
GUIUtils.DrawBar (rect, fillPerc, fillColor, backgroundColor, borderWidth);
|
||||
}
|
||||
|
||||
static void DrawChat(Queue<Chat.ChatMessage> chatMessages)
|
||||
{
|
||||
if (chatMessages.Count < 1)
|
||||
return;
|
||||
|
||||
float width = Screen.width * 0.25f;
|
||||
float height = Screen.height * 0.33f;
|
||||
Rect rect = GUIUtils.GetCornerRect(ScreenCorner.BottomLeft, new Vector2(width, height), Vector2.one * 50);
|
||||
|
||||
GUILayout.BeginArea(rect);
|
||||
|
||||
foreach (var chatMsg in chatMessages)
|
||||
{
|
||||
GUILayout.Label("<color=blue>" + chatMsg.sender + "</color> : " + chatMsg.msg);
|
||||
}
|
||||
|
||||
GUILayout.EndArea();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue