void m_playerList_ItemsSelected(MyGuiControlListbox obj)
        {
            if (m_playerList.SelectedItems.Count > 0)
            {
                var selectedItem = m_playerList.SelectedItems[0];
                if (selectedItem != m_globalItem)
                {
                    var playerIdentity = (MyIdentity)selectedItem.UserData;
                    RefreshPlayerChatHistory(playerIdentity);

                    var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.LocalPlayerId, playerIdentity.IdentityId);
                    if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                    {
                        playerChatHistory.UnreadMessageCount = 0;
                        UpdatePlayerList();
                    }
                }
                else
                {
                    RefreshGlobalChatHistory();

                    MyChatHistory chatHistory;
                    if (MySession.Static.ChatHistory.TryGetValue(MySession.LocalPlayerId, out chatHistory) && chatHistory.GlobalChatHistory.UnreadMessageCount > 0)
                    {
                        chatHistory.GlobalChatHistory.UnreadMessageCount = 0;
                        UpdatePlayerList();
                    }
                }
                m_chatbox.SetText(m_emptyText);
            }
        }
        public void IncrementPlayerUnreadMessageCount(long otherPlayerId, bool refresh)
        {
            MyPlayerChatHistory chatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, otherPlayerId);

            if (chatHistory != null)
            {
                chatHistory.UnreadMessageCount++;
                if (refresh)
                {
                    UpdatePlayerList();
                }
            }
        }
        private void RefreshPlayerList()
        {
            //Add the global chat log first
            m_globalItem = new MyGuiControlListbox.Item(MyTexts.Get(MySpaceTexts.TerminalTab_Chat_ChatHistory));
            m_playerList.Add(m_globalItem);

            //Comms broadcast history
            m_tempStringBuilder.Clear();
            m_tempStringBuilder.Append(MyTexts.Get(MySpaceTexts.TerminalTab_Chat_GlobalChat));

            MyChatHistory chatHistory;

            if (MySession.Static.ChatHistory.TryGetValue(MySession.Static.LocalPlayerId, out chatHistory) && chatHistory.GlobalChatHistory.UnreadMessageCount > 0)
            {
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(chatHistory.GlobalChatHistory.UnreadMessageCount);
                m_tempStringBuilder.Append(")");
            }

            m_broadcastItem = new MyGuiControlListbox.Item(m_tempStringBuilder);
            m_playerList.Add(m_broadcastItem);

            //var allPlayers = MySession.Static.Players.GetAllIdentities();
            var allPlayers = MySession.Static.Players.GetAllPlayers();

            m_tempOnlinePlayers.Clear();
            m_tempOfflinePlayers.Clear();

            foreach (var player in allPlayers)
            {
                var playerIdentity = MySession.Static.Players.TryGetIdentity(MySession.Static.Players.TryGetIdentityId(player.SteamId, player.SerialId));

                if (playerIdentity != null && playerIdentity.IdentityId != MySession.Static.LocalPlayerId && player.SerialId == 0)
                {
                    if (playerIdentity.Character == null)
                    {
                        m_tempOfflinePlayers.Add(playerIdentity);
                    }
                    else
                    {
                        m_tempOnlinePlayers.Add(playerIdentity);
                    }
                }
            }

            foreach (var onlinePlayer in m_tempOnlinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(onlinePlayer.DisplayName);

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, onlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: onlinePlayer);
                m_playerList.Add(item);
            }

            foreach (var offlinePlayer in m_tempOfflinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(offlinePlayer.DisplayName);
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(MyTexts.GetString(MySpaceTexts.TerminalTab_Chat_Offline));
                m_tempStringBuilder.Append(")");

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, offlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: offlinePlayer, fontOverride: MyFontEnum.DarkBlue);
                m_playerList.Add(item);
            }
        }