D:\ValheimDev\Dumps\Old\assembly_valheim\MessageHud.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\MessageHud.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
   
public class MessageHud : MonoBehaviour public class MessageHud : MonoBehaviour
{ {
    private void Awake()     private void Awake()
    {     {
        MessageHud.m_instance = this;         MessageHud.m_instance = this;
    }     }
   
    private void OnDestroy()     private void OnDestroy()
    {     {
        MessageHud.m_instance = null;         MessageHud.m_instance = null;
    }     }
   
    public static MessageHud instance     public static MessageHud instance
    {     {
        get         get
        {         {
            return MessageHud.m_instance;             return MessageHud.m_instance;
        }         }
    }     }
   
    private void Start()     private void Start()
    {     {
        this.m_messageText.CrossFadeAlpha(0f, 0f, true);         this.m_messageText.CrossFadeAlpha(0f, 0f, true);
        this.m_messageIcon.canvasRenderer.SetAlpha(0f);         this.m_messageIcon.canvasRenderer.SetAlpha(0f);
        this.m_messageCenterText.CrossFadeAlpha(0f, 0f, true);         this.m_messageCenterText.CrossFadeAlpha(0f, 0f, true);
        for (int i = 0; i < this.m_maxUnlockMessages; i++)         for (int i = 0; i < this.m_maxUnlockMessages; i++)
        {         {
            this.m_unlockMessages.Add(null);             this.m_unlockMessages.Add(null);
        }         }
        ZRoutedRpc.instance.Register<int, string>("ShowMessage", new Action<long, int, string>(this.RPC_ShowMessage));         ZRoutedRpc.instance.Register<int, string>("ShowMessage", new Action<long, int, string>(this.RPC_ShowMessage));
    }     }
   
    private void Update()     private void Update()
    {     {
        if (Hud.IsUserHidden())         if (Hud.IsUserHidden())
        {         {
            this.HideAll();             this.HideAll();
            return;             return;
        }         }
        this.UpdateUnlockMsg(Time.deltaTime);         this.UpdateUnlockMsg(Time.deltaTime);
        this.UpdateMessage(Time.deltaTime);         this.UpdateMessage(Time.deltaTime);
        this.UpdateBiomeFound(Time.deltaTime);         this.UpdateBiomeFound(Time.deltaTime);
    }     }
   
    private void HideAll()     private void HideAll()
    {     {
        for (int i = 0; i < this.m_maxUnlockMessages; i++)         for (int i = 0; i < this.m_maxUnlockMessages; i++)
        {         {
            if (this.m_unlockMessages[i] != null)             if (this.m_unlockMessages[i] != null)
            {             {
                UnityEngine.Object.Destroy(this.m_unlockMessages[i]);                 UnityEngine.Object.Destroy(this.m_unlockMessages[i]);
                this.m_unlockMessages[i] = null;                 this.m_unlockMessages[i] = null;
            }             }
        }         }
        this.m_messageText.CrossFadeAlpha(0f, 0f, true);         this.m_messageText.CrossFadeAlpha(0f, 0f, true);
        this.m_messageIcon.canvasRenderer.SetAlpha(0f);         this.m_messageIcon.canvasRenderer.SetAlpha(0f);
        this.m_messageCenterText.CrossFadeAlpha(0f, 0f, true);         this.m_messageCenterText.CrossFadeAlpha(0f, 0f, true);
        if (this.m_biomeMsgInstance)         if (this.m_biomeMsgInstance)
        {         {
            UnityEngine.Object.Destroy(this.m_biomeMsgInstance);             UnityEngine.Object.Destroy(this.m_biomeMsgInstance);
            this.m_biomeMsgInstance = null;             this.m_biomeMsgInstance = null;
        }         }
    }     }
   
    public void MessageAll(MessageHud.MessageType type, string text)     public void MessageAll(MessageHud.MessageType type, string text)
    {     {
        ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ShowMessage", new object[]         ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ShowMessage", new object[]
        {         {
            (int)type,             (int)type,
            text             text
        });         });
    }     }
   
    private void RPC_ShowMessage(long sender, int type, string text)     private void RPC_ShowMessage(long sender, int type, string text)
    {     {
        this.ShowMessage((MessageHud.MessageType)type, text, 0, null);         this.ShowMessage((MessageHud.MessageType)type, text, 0, null);
    }     }
   
    public void ShowMessage(MessageHud.MessageType type, string text, int amount = 0, Sprite icon = null)     public void ShowMessage(MessageHud.MessageType type, string text, int amount = 0, Sprite icon = null)
    {     {
        if (Hud.IsUserHidden())         if (Hud.IsUserHidden())
        {         {
            return;             return;
        }         }
        text = Localization.instance.Localize(text);         text = Localization.instance.Localize(text);
        if (type == MessageHud.MessageType.TopLeft)         if (type == MessageHud.MessageType.TopLeft)
        {         {
            MessageHud.MsgData msgData = new MessageHud.MsgData();             MessageHud.MsgData msgData = new MessageHud.MsgData();
            msgData.m_icon = icon;             msgData.m_icon = icon;
            msgData.m_text = text;             msgData.m_text = text;
            msgData.m_amount = amount;             msgData.m_amount = amount;
            this.m_msgQeue.Enqueue(msgData);             this.m_msgQeue.Enqueue(msgData);
            this.AddLog(text);             this.AddLog(text);
            return;             return;
        }         }
        if (type != MessageHud.MessageType.Center)         if (type != MessageHud.MessageType.Center)
        {         {
            return;             return;
        }         }
        this.m_messageCenterText.text = text;         this.m_messageCenterText.text = text;
        this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText         this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText
        {         {
            text = this.m_messageCenterText,             text = this.m_messageCenterText,
            alpha = 1f,             alpha = 1f,
            time = 0f             time = 0f
        });         });
        this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText         this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText
        {         {
            text = this.m_messageCenterText,             text = this.m_messageCenterText,
            alpha = 0f,             alpha = 0f,
            time = 4f             time = 4f
        });         });
    }     }
   
    private void UpdateMessage(float dt)     private void UpdateMessage(float dt)
    {     {
        if ((double)dt > 0.5)         if ((double)dt > 0.5)
        {         {
            return;             return;
        }         }
        if (this._crossFadeTextBuffer.Count > 0)         if (this._crossFadeTextBuffer.Count > 0)
        {         {
            MessageHud.CrossFadeText crossFadeText = this._crossFadeTextBuffer[0];             MessageHud.CrossFadeText crossFadeText = this._crossFadeTextBuffer[0];
            this._crossFadeTextBuffer.RemoveAt(0);             this._crossFadeTextBuffer.RemoveAt(0);
            crossFadeText.text.CrossFadeAlpha(crossFadeText.alpha, crossFadeText.time, true);             crossFadeText.text.CrossFadeAlpha(crossFadeText.alpha, crossFadeText.time, true);
        }         }
        this.m_msgQueueTimer += dt;         this.m_msgQueueTimer += dt;
        if (this.m_msgQeue.Count > 0)         if (this.m_msgQeue.Count > 0)
        {         {
            MessageHud.MsgData msgData = this.m_msgQeue.Peek();             MessageHud.MsgData msgData = this.m_msgQeue.Peek();
            bool flag = this.m_msgQueueTimer < 4f && msgData.m_text == this.currentMsg.m_text && msgData.m_icon == this.currentMsg.m_icon;             bool flag = this.m_msgQueueTimer < 4f && msgData.m_text == this.currentMsg.m_text && msgData.m_icon == this.currentMsg.m_icon;
            if (this.m_msgQueueTimer >= 1f || flag)             if (this.m_msgQueueTimer >= 1f || flag)
            {             {
                MessageHud.MsgData msgData2 = this.m_msgQeue.Dequeue();                 MessageHud.MsgData msgData2 = this.m_msgQeue.Dequeue();
                this.m_messageText.text = msgData2.m_text;                 this.m_messageText.text = msgData2.m_text;
                if (flag)                 if (flag)
                {                 {
                    msgData2.m_amount += this.currentMsg.m_amount;                     msgData2.m_amount += this.currentMsg.m_amount;
                }                 }
                if (msgData2.m_amount > 1)                 if (msgData2.m_amount > 1)
                {                 {
                    TMP_Text messageText = this.m_messageText;                     TMP_Text messageText = this.m_messageText;
                    messageText.text = messageText.text + " x" + msgData2.m_amount.ToString();                     messageText.text = messageText.text + " x" + msgData2.m_amount.ToString();
                }                 }
                this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText                 this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText
                {                 {
                    text = this.m_messageText,                     text = this.m_messageText,
                    alpha = 1f,                     alpha = 1f,
                    time = 0f                     time = 0f
                });                 });
                this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText                 this._crossFadeTextBuffer.Add(new MessageHud.CrossFadeText
                {                 {
                    text = this.m_messageText,                     text = this.m_messageText,
                    alpha = 0f,                     alpha = 0f,
                    time = 4f                     time = 4f
                });                 });
                if (msgData2.m_icon != null)                 if (msgData2.m_icon != null)
                {                 {
                    this.m_messageIcon.sprite = msgData2.m_icon;                     this.m_messageIcon.sprite = msgData2.m_icon;
                    this.m_messageIcon.canvasRenderer.SetAlpha(1f);                     this.m_messageIcon.canvasRenderer.SetAlpha(1f);
                    this.m_messageIcon.CrossFadeAlpha(0f, 4f, true);                     this.m_messageIcon.CrossFadeAlpha(0f, 4f, true);
                }                 }
                else                 else
                {                 {
                    this.m_messageIcon.canvasRenderer.SetAlpha(0f);                     this.m_messageIcon.canvasRenderer.SetAlpha(0f);
                }                 }
                this.currentMsg = msgData2;                 this.currentMsg = msgData2;
                this.m_msgQueueTimer = 0f;                 this.m_msgQueueTimer = 0f;
            }             }
        }         }
    }     }
   
    private void UpdateBiomeFound(float dt)     private void UpdateBiomeFound(float dt)
    {     {
        if (this.m_biomeMsgInstance != null && this.m_biomeMsgInstance.GetComponentInChildren<Animator>().GetCurrentAnimatorStateInfo(0).IsTag("done"))         if (this.m_biomeMsgInstance != null && this.m_biomeMsgInstance.GetComponentInChildren<Animator>().GetCurrentAnimatorStateInfo(0).IsTag("done"))
        {         {
            UnityEngine.Object.Destroy(this.m_biomeMsgInstance);             UnityEngine.Object.Destroy(this.m_biomeMsgInstance);
            this.m_biomeMsgInstance = null;             this.m_biomeMsgInstance = null;
        }         }
        if (this.m_biomeFoundQueue.Count > 0 && this.m_biomeMsgInstance == null && this.m_msgQeue.Count == 0 && this.m_msgQueueTimer > 2f)         if (this.m_biomeFoundQueue.Count > 0 && this.m_biomeMsgInstance == null && this.m_msgQeue.Count == 0 && this.m_msgQueueTimer > 2f)
        {         {
            MessageHud.BiomeMessage biomeMessage = this.m_biomeFoundQueue.Dequeue();             MessageHud.BiomeMessage biomeMessage = this.m_biomeFoundQueue.Dequeue();
            this.m_biomeMsgInstance = UnityEngine.Object.Instantiate<GameObject>(this.m_biomeFoundPrefab, base.transform);             this.m_biomeMsgInstance = UnityEngine.Object.Instantiate<GameObject>(this.m_biomeFoundPrefab, base.transform);
            TMP_Text component = Utils.FindChild(this.m_biomeMsgInstance.transform, "Title", Utils.IterativeSearchType.DepthFirst).GetComponent<TMP_Text>();             TMP_Text component = Utils.FindChild(this.m_biomeMsgInstance.transform, "Title", Utils.IterativeSearchType.DepthFirst).GetComponent<TMP_Text>();
            string text = Localization.instance.Localize(biomeMessage.m_text);             string text = Localization.instance.Localize(biomeMessage.m_text);
            component.text = text;             component.text = text;
            if (biomeMessage.m_playStinger && this.m_biomeFoundStinger)             if (biomeMessage.m_playStinger && this.m_biomeFoundStinger)
            {             {
                UnityEngine.Object.Instantiate<GameObject>(this.m_biomeFoundStinger);                 UnityEngine.Object.Instantiate<GameObject>(this.m_biomeFoundStinger);
            }             }
        }         }
    }     }
   
    public void ShowBiomeFoundMsg(string text, bool playStinger)     public void ShowBiomeFoundMsg(string text, bool playStinger)
    {     {
        MessageHud.BiomeMessage biomeMessage = new MessageHud.BiomeMessage();         MessageHud.BiomeMessage biomeMessage = new MessageHud.BiomeMessage();
        biomeMessage.m_text = text;         biomeMessage.m_text = text;
        biomeMessage.m_playStinger = playStinger;         biomeMessage.m_playStinger = playStinger;
        this.m_biomeFoundQueue.Enqueue(biomeMessage);         this.m_biomeFoundQueue.Enqueue(biomeMessage);
    }     }
   
    public void QueueUnlockMsg(Sprite icon, string topic, string description)     public void QueueUnlockMsg(Sprite icon, string topic, string description)
    {     {
        MessageHud.UnlockMsg unlockMsg = new MessageHud.UnlockMsg();         MessageHud.UnlockMsg unlockMsg = new MessageHud.UnlockMsg();
        unlockMsg.m_icon = icon;         unlockMsg.m_icon = icon;
        unlockMsg.m_topic = Localization.instance.Localize(topic);         unlockMsg.m_topic = Localization.instance.Localize(topic);
        unlockMsg.m_description = Localization.instance.Localize(description);         unlockMsg.m_description = Localization.instance.Localize(description);
        this.m_unlockMsgQueue.Enqueue(unlockMsg);         this.m_unlockMsgQueue.Enqueue(unlockMsg);
.        this.AddLog(topic + ":" + description);         this.m_unlockMsgCount++; 
          this.AddLog(topic + ": " + description);
        ZLog.Log("Queue unlock msg:" + topic + ":" + description);         ZLog.Log("Queue unlock msg:" + topic + ":" + description);
    }     }
   
    private int GetFreeUnlockMsgSlot()     private int GetFreeUnlockMsgSlot()
    {     {
        for (int i = 0; i < this.m_unlockMessages.Count; i++)         for (int i = 0; i < this.m_unlockMessages.Count; i++)
        {         {
            if (this.m_unlockMessages[i] == null)             if (this.m_unlockMessages[i] == null)
            {             {
                return i;                 return i;
            }             }
        }         }
        return -1;         return -1;
    }     }
   
    private void UpdateUnlockMsg(float dt)     private void UpdateUnlockMsg(float dt)
    {     {
        for (int i = 0; i < this.m_unlockMessages.Count; i++)         for (int i = 0; i < this.m_unlockMessages.Count; i++)
        {         {
            GameObject gameObject = this.m_unlockMessages[i];             GameObject gameObject = this.m_unlockMessages[i];
            if (!(gameObject == null) && gameObject.GetComponentInChildren<Animator>().GetCurrentAnimatorStateInfo(0).IsTag("done"))             if (!(gameObject == null) && gameObject.GetComponentInChildren<Animator>().GetCurrentAnimatorStateInfo(0).IsTag("done"))
            {             {
                UnityEngine.Object.Destroy(gameObject);                 UnityEngine.Object.Destroy(gameObject);
                this.m_unlockMessages[i] = null;                 this.m_unlockMessages[i] = null;
                break;                 break;
            }             }
        }         }
        if (this.m_unlockMsgQueue.Count > 0)         if (this.m_unlockMsgQueue.Count > 0)
        {         {
            int freeUnlockMsgSlot = this.GetFreeUnlockMsgSlot();             int freeUnlockMsgSlot = this.GetFreeUnlockMsgSlot();
            if (freeUnlockMsgSlot != -1)             if (freeUnlockMsgSlot != -1)
            {             {
                Transform transform = base.transform;                 Transform transform = base.transform;
                GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(this.m_unlockMsgPrefab, transform);                 GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(this.m_unlockMsgPrefab, transform);
                this.m_unlockMessages[freeUnlockMsgSlot] = gameObject2;                 this.m_unlockMessages[freeUnlockMsgSlot] = gameObject2;
                RectTransform rectTransform = gameObject2.transform as RectTransform;                 RectTransform rectTransform = gameObject2.transform as RectTransform;
                Vector3 vector = rectTransform.anchoredPosition;                 Vector3 vector = rectTransform.anchoredPosition;
                vector.y -= (float)(this.m_maxUnlockMsgSpace * freeUnlockMsgSlot);                 vector.y -= (float)(this.m_maxUnlockMsgSpace * freeUnlockMsgSlot);
                rectTransform.anchoredPosition = vector;                 rectTransform.anchoredPosition = vector;
                MessageHud.UnlockMsg unlockMsg = this.m_unlockMsgQueue.Dequeue();                 MessageHud.UnlockMsg unlockMsg = this.m_unlockMsgQueue.Dequeue();
                Image component = rectTransform.Find("UnlockMessage/icon_bkg/UnlockIcon").GetComponent<Image>();                 Image component = rectTransform.Find("UnlockMessage/icon_bkg/UnlockIcon").GetComponent<Image>();
                TMP_Text component2 = rectTransform.Find("UnlockMessage/UnlockTitle").GetComponent<TMP_Text>();                 TMP_Text component2 = rectTransform.Find("UnlockMessage/UnlockTitle").GetComponent<TMP_Text>();
                TMP_Text component3 = rectTransform.Find("UnlockMessage/UnlockDescription").GetComponent<TMP_Text>();                 TMP_Text component3 = rectTransform.Find("UnlockMessage/UnlockDescription").GetComponent<TMP_Text>();
                component.sprite = unlockMsg.m_icon;                 component.sprite = unlockMsg.m_icon;
                component2.text = unlockMsg.m_topic;                 component2.text = unlockMsg.m_topic;
                component3.text = unlockMsg.m_description;                 component3.text = unlockMsg.m_description;
.                  return;
            }             }
        }         }
.          else if (this.m_unlockMsgCount > 0)
          {
              Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, string.Format("{0} $inventory_logs_new", this.m_unlockMsgCount), 0, null);
              this.m_unlockMsgCount = 0;
          }
    }     }
   
    private void AddLog(string logText)     private void AddLog(string logText)
    {     {
        this.m_messageLog.Add(logText);         this.m_messageLog.Add(logText);
        while (this.m_messageLog.Count > this.m_maxLogMessages)         while (this.m_messageLog.Count > this.m_maxLogMessages)
        {         {
            this.m_messageLog.RemoveAt(0);             this.m_messageLog.RemoveAt(0);
        }         }
    }     }
   
    public List<string> GetLog()     public List<string> GetLog()
    {     {
        return this.m_messageLog;         return this.m_messageLog;
    }     }
   
    private MessageHud.MsgData currentMsg = new MessageHud.MsgData();     private MessageHud.MsgData currentMsg = new MessageHud.MsgData();
   
    private static MessageHud m_instance;     private static MessageHud m_instance;
   
    public TMP_Text m_messageText;     public TMP_Text m_messageText;
   
    public Image m_messageIcon;     public Image m_messageIcon;
   
    public TMP_Text m_messageCenterText;     public TMP_Text m_messageCenterText;
   
    public GameObject m_unlockMsgPrefab;     public GameObject m_unlockMsgPrefab;
   
    public int m_maxUnlockMsgSpace = 110;     public int m_maxUnlockMsgSpace = 110;
   
    public int m_maxUnlockMessages = 4;     public int m_maxUnlockMessages = 4;
   
    public int m_maxLogMessages = 50;     public int m_maxLogMessages = 50;
   
    public GameObject m_biomeFoundPrefab;     public GameObject m_biomeFoundPrefab;
   
    public GameObject m_biomeFoundStinger;     public GameObject m_biomeFoundStinger;
   
    private Queue<MessageHud.BiomeMessage> m_biomeFoundQueue = new Queue<MessageHud.BiomeMessage>();     private Queue<MessageHud.BiomeMessage> m_biomeFoundQueue = new Queue<MessageHud.BiomeMessage>();
   
    private List<string> m_messageLog = new List<string>();     private List<string> m_messageLog = new List<string>();
   
    private List<GameObject> m_unlockMessages = new List<GameObject>();     private List<GameObject> m_unlockMessages = new List<GameObject>();
   
    private Queue<MessageHud.UnlockMsg> m_unlockMsgQueue = new Queue<MessageHud.UnlockMsg>();     private Queue<MessageHud.UnlockMsg> m_unlockMsgQueue = new Queue<MessageHud.UnlockMsg>();
   
    private Queue<MessageHud.MsgData> m_msgQeue = new Queue<MessageHud.MsgData>();     private Queue<MessageHud.MsgData> m_msgQeue = new Queue<MessageHud.MsgData>();
   
    private float m_msgQueueTimer = -1f;     private float m_msgQueueTimer = -1f;
.   
      private int m_unlockMsgCount;
   
    private GameObject m_biomeMsgInstance;     private GameObject m_biomeMsgInstance;
   
    private List<MessageHud.CrossFadeText> _crossFadeTextBuffer = new List<MessageHud.CrossFadeText>();     private List<MessageHud.CrossFadeText> _crossFadeTextBuffer = new List<MessageHud.CrossFadeText>();
   
    public enum MessageType     public enum MessageType
    {     {
        TopLeft = 1,         TopLeft = 1,
        Center         Center
    }     }
   
    private class UnlockMsg     private class UnlockMsg
    {     {
        public Sprite m_icon;         public Sprite m_icon;
   
        public string m_topic;         public string m_topic;
   
        public string m_description;         public string m_description;
    }     }
   
    private class MsgData     private class MsgData
    {     {
        public Sprite m_icon;         public Sprite m_icon;
   
        public string m_text;         public string m_text;
   
        public int m_amount;         public int m_amount;
    }     }
   
    private class BiomeMessage     private class BiomeMessage
    {     {
        public string m_text;         public string m_text;
   
        public bool m_playStinger;         public bool m_playStinger;
    }     }
   
    private struct CrossFadeText     private struct CrossFadeText
    {     {
        public TMP_Text text;         public TMP_Text text;
   
        public float alpha;         public float alpha;
   
        public float time;         public float time;
    }     }
} }