private void RefreshFactionChatHistory(MyFaction faction)
        {
            m_chatHistory.Clear();

            var localFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);

            if (localFaction == null)
            {
                System.Diagnostics.Debug.Fail("Chat shouldn't be refreshed if local player is not a member of a faction!");
                return;
            }
            MyFactionChatHistory factionChat = MyChatSystem.FindFactionChatHistory(faction.FactionId, localFaction.FactionId);

            if (factionChat != null)
            {
                var chat = factionChat.Chat;
                foreach (var item in chat)
                {
                    bool alreadySentToMe;
                    if (item.IdentityId == MySession.Static.LocalPlayerId || (item.PlayersToSendTo.TryGetValue(MySession.Static.LocalPlayerId, out alreadySentToMe) && alreadySentToMe))
                    {
                        int alreadySentToCount = 0;
                        foreach (var keyValue in item.PlayersToSendTo)
                        {
                            if (keyValue.Value)
                            {
                                alreadySentToCount++;
                            }
                        }
                        var identity = MySession.Static.Players.TryGetIdentity(item.IdentityId);

                        if (identity == null)
                        {
                            continue;
                        }
                        bool isPlayer = identity.IdentityId == MySession.Static.LocalPlayerId;

                        m_chatHistory.AppendText(identity.DisplayName, isPlayer ? MyFontEnum.DarkBlue : MyFontEnum.Blue, m_chatHistory.TextScale, Vector4.One);
                        if (item.PlayersToSendTo != null && item.PlayersToSendTo.Count > 0 && alreadySentToCount < item.PlayersToSendTo.Count)
                        {
                            var pendingText = new StringBuilder();
                            pendingText.Append(" (");
                            pendingText.Append(alreadySentToCount.ToString());
                            pendingText.Append("/");
                            pendingText.Append(item.PlayersToSendTo.Count.ToString());
                            pendingText.Append(") ");
                            m_chatHistory.AppendText(pendingText, MyFontEnum.Red, m_chatHistory.TextScale, Vector4.One);
                        }
                        m_chatHistory.AppendText(": ", isPlayer ? MyFontEnum.DarkBlue : MyFontEnum.Blue, m_chatHistory.TextScale, Vector4.One);
                        m_chatHistory.AppendText(item.Text, MyFontEnum.White, m_chatHistory.TextScale, Vector4.One);
                        m_chatHistory.AppendLine();
                    }
                }
            }

            m_playerList.SelectedItems.Clear();
            m_chatHistory.ScrollbarOffset = 1.0f;
        }
Пример #2
0
        public static void AddFactionChatItem(long localPlayerId, long factionId1, long factionId2, MyFactionChatItem chatItem)
        {
            var factionChat = FindFactionChatHistory(factionId1, factionId2);

            if (factionChat == null)
            {
                factionChat = new MyFactionChatHistory(factionId1, factionId2);
                MySession.Static.FactionChatHistory.Add(factionChat);
            }

            if (factionChat.Chat.Count == MyChatConstants.MAX_FACTION_CHAT_HISTORY_COUNT)
            {
                factionChat.Chat.Dequeue();
            }
            factionChat.Chat.Enqueue(chatItem);
        }
        void m_factionList_ItemsSelected(MyGuiControlListbox obj)
        {
            if (m_factionList.SelectedItems.Count > 0)
            {
                var selectedItem = m_factionList.SelectedItems[0];
                var faction      = (MyFaction)selectedItem.UserData;
                RefreshFactionChatHistory(faction);

                var factions     = MySession.Static.Factions;
                var localFaction = factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);
                if (localFaction != null)
                {
                    MyFactionChatHistory factionChat = MyChatSystem.FindFactionChatHistory(faction.FactionId, localFaction.FactionId);
                    if (factionChat != null)
                    {
                        factionChat.UnreadMessageCount = 0;
                        UpdateFactionList(true);
                    }
                }

                m_chatbox.SetText(m_emptyText);
            }
        }