public void BePopulatedCorrectly()
    {
        var message = new ChatEntry.Model()
        {
            messageType   = ChatMessage.Type.PUBLIC,
            senderName    = "user-test",
            recipientName = "",
            bodyText      = "test message",
        };

        entry.Populate(message);

        Assert.AreEqual(entry.worldMessageColor, entry.body.color);
        Assert.AreEqual("<b>user-test:</b>", entry.username.text);
        Assert.AreEqual("<b>user-test:</b> test message", entry.body.text);

        message.messageType = ChatMessage.Type.PRIVATE;
        message.subType     = ChatEntry.Model.SubType.PRIVATE_TO;

        entry.Populate(message);
        Assert.AreEqual(entry.privateToMessageColor, entry.username.color);

        message.subType = ChatEntry.Model.SubType.PRIVATE_FROM;
        entry.Populate(message);
        Assert.AreEqual(entry.privateFromMessageColor, entry.username.color);

        message.messageType = ChatMessage.Type.SYSTEM;
        entry.Populate(message);
        Assert.AreEqual(entry.systemColor, entry.body.color);
    }
Exemplo n.º 2
0
    public virtual void AddEntry(ChatEntry.Model chatEntryModel, bool setScrollPositionToBottom = false)
    {
        var       chatEntryGO = Instantiate(Resources.Load(ENTRY_PATH) as GameObject, chatEntriesContainer);
        ChatEntry chatEntry   = chatEntryGO.GetComponent <ChatEntry>();

        if (enableFadeoutMode && EntryIsVisible(chatEntry))
        {
            chatEntry.SetFadeout(true);
        }
        else
        {
            chatEntry.SetFadeout(false);
        }

        chatEntry.Populate(chatEntryModel);

        if (chatEntryModel.messageType == ChatMessage.Type.PRIVATE)
        {
            chatEntry.OnPress += OnPressPrivateMessage;
        }

        chatEntry.OnTriggerHover += OnMessageTriggerHover;
        chatEntry.OnCancelHover  += OnMessageCancelHover;

        entries.Add(chatEntry);

        SortEntries();

        Utils.ForceUpdateLayout(transform as RectTransform, delayed: false);

        if (setScrollPositionToBottom)
        {
            scrollRect.verticalNormalizedPosition = 0;
        }
    }
Exemplo n.º 3
0
    public override void AddEntry(ChatEntry.Model chatEntryModel, bool setScrollPositionToBottom = false)
    {
        AddSeparatorEntryIfNeeded(chatEntryModel);

        var       chatEntryGO = Instantiate(Resources.Load(chatEntryModel.subType == ChatEntry.Model.SubType.PRIVATE_TO ? ENTRY_PATH_SENT : ENTRY_PATH_RECEIVED) as GameObject, chatEntriesContainer);
        ChatEntry chatEntry   = chatEntryGO.GetComponent <ChatEntry>();

        chatEntry.SetFadeout(false);
        chatEntry.Populate(chatEntryModel);

        chatEntry.OnTriggerHover += OnMessageTriggerHover;
        chatEntry.OnCancelHover  += OnMessageCancelHover;

        entries.Add(chatEntry);
        Utils.ForceUpdateLayout(transform as RectTransform, delayed: false);

        if (setScrollPositionToBottom)
        {
            scrollRect.verticalNormalizedPosition = 0;
        }
    }