コード例 #1
0
        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
        private static MyFactionChatItem FindFactionChatItem(long playerId, long factionId1, long factionId2, TimeSpan timestamp, string text)
        {
            var factionChat = MyChatSystem.FindFactionChatHistory(factionId1, factionId2);

            if (factionChat != null)
            {
                foreach (var factionChatItem in factionChat.Chat)
                {
                    if (factionChatItem.Timestamp == timestamp && factionChatItem.Text == text)
                    {
                        return(factionChatItem);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        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);
            }
        }