đŸ–Ĩī¸Player Controller Components

UMIPChatItemLinkerComponent

This class is responsible for linking item to the chat by generating hyperlink text.

  • We can link an item to the chat by calling LinkItem(). The 'InStyle' parameter represents the quality or rarity of the item. In many games, each item quality is associated with its own color.

  • The 'InItemContent' parameter is a base64 string containing item metadata in JSON format. Item metadata typically includes information like the item's name, durability, and enhancement level.

  • For now, an item link hyperlink for UMIPRichChatTextBlock will look like this:

    "<Rare id="" style="Rare" type="MyHyperLinkType" ItemDisplayName="InItemNameString" ItemContent="Base64String">InItemDisplayName</> "
  • Please note that the whitespace after the ending tag, "</> ", is crucial. If a player removes this whitespace, we will need to end hyperlinking by calling EndHyperLinkingText().

  • The 'OnChatTextChanged' function gets called when text changes in UMIPChatInputWidget. It checks if the text contains "</> ". If it doesn't, it triggers the EndHyperLinkingText() function.

  • Before a message is sent in UMIPChatInputWidget::OnTextCommitted, MakeHyperLinkStringForChatTextBlock is called to replace 'HyperLinkStyleToReplace', for example, "<Rare " with "<a ". This substitution is not ideal because UMIPRichChatTextBlock and UMIPRichChatTextBlock hyperlinks work differently, but it's the current approach.

  • It also listen for when OnHyperLinkTextClickedDelegate is broadcast, and check if Type is MyHyperLinkType which is equals to "Item" by default.

UMIPHyperLinkTextClickedListenerComponent

This class utilize the UGameplayMessageSubsystem to listen for any broadcast events tagged as Tag_HyperLink_Clicked.

When OnHyperLinkTextClicked is triggered, we check for the existence of the HyperLinkStatic::Type metadata in UMIPHyperLinkParamObject's metadata. If Type exist, OnHyperLinkTextClickedDelegate will broadcast both the Type and UMIPHyperLinkParamObject.

UMIPPlayerNameClickedListenerComponent

This class listens for when OnHyperLinkTextClickedDelegate is broadcast, and check if Type is MyHyperLinkType which equals to "PlayerName" by default.

UMIPChatWidgetCreatorComponent

To create UMIPChatMainWidget with ChatMainWidgetClass as an EditAnywhere variable. Upon BeginPlay(), it will first verify whether the Owner is a PlayerController, then it will check if it's a local PlayerController. If it is true, it will then instantiate UMIPChatMainWidget and add it to the viewport.

It also retrieves the DefaultChatTabsAndAllowedChannels from the settings and generates chat tabs in the main widget.

Additionally, it keeps track of the chat tab availability, with the current limit set to four tabs..

UMIPUnrealRepSendMessageProcessor

This class handles overriding messages for different channels.

  • OnServerMessage_Implementation() invokes ServerDoMulticastMessage() with InMessageToSend as the payload. ServerDoMulticastMessage() transforms MessageToSend into Message Received by calling FromMessageSend() and then invokes MulticastMessage(), a Multicast RPC in MessageBroadcasterComponent. Since MessageBroadcasterComponent is a game state component, all clients will receive the message.

  • OnSystemMessage_Implementation() constructs MessageReceived and calls BroadcastMessage() to broadcast the message to the local client.

  • OnWhisperMessage_Implementation() calls ServerDoWhisperMessage() to attempt to locate and broadcast the message to the recipient. First, it retrieves RecipientName from FMIPChatMessageSendStruct.Recipient. Once we get RecipientName, we call PlayerSessionListener->FindControllerByPlayerName() to attempt to locate the RecipientController. If found, a message is broadcast to the recipient by calling SendMessageToClientByController() and also broadcast to the owning client by passing GetOwner() as a Controller. If RecipientController is not found, a system message is only broadcast to oneself, indicating that the RecipientName is not online.

  • SendMessageToClientByController works by obtaining the UMIPClientMessageReceiverComponent from the controller and then invoking the ClientMessage, which is a Client RPC.

UMIPClientMessageReceiverComponent

This class is responsible for broadcasting message to owning client by invoking ClientMessage(), which calls MessageBroadcasterComponent->BroadcastMessage().

UMIPChatCommandListenerComponent

This class will listen for text changes. There are two types of commands: AfterSpace and AfterEnter commands.

  1. AfterSpace: If the first character is "/", then we check from "/" until a whitespace. Once a whitespace is found after "/", we can trigger the AfterSpace commands.

  2. AfterEnter will trigger when the user hits the spacebar. This can be used for action commands, such as /dance, /hello, /cry. It can also be used to switch channel when user hit enter.

UMIPActionChatCommandHandlerComponent

This class handles all action chat commands that have a direct parent tag of Tag_ChatCommand_AnimAction. For example, if the command string is "dance" and the command tag is "Tag_ChatCommand_AnimAction_Dance", in this case the direct parent tag is Tag_ChatCommand_AnimAction, then this class will call DoActionChatCommand() with the CommandTag.

UMIPEmoticonHandlerComponent

This class listens for ChatTextChanged events. When the chat text changes, the OnChatTextChanged() method is called. This is where we check if a user is trying to type an emoticon.

The process works by checking the text before the cursor's end position. If it ends with ":", we then check if the text following it matches any emoticon style in the set. If a match is found, we append the current text with the emoticon string in rich text image decorator format, like </>. Then ChatTextChangedInfo.bChanged is set to true to tell UMIPChatInputWidget::OnTextChanged() to SetText with the modified text.

UMIPUnrealRepChatThrottlerComponent

This class will retrieve a ChatThrottlersMapPtr from the DefaultChatThrottlersMap in UMIPChatSettings.

In OnMessageSentOnServer(), it will check if the chat channel is present in the ChatThrottlersMapPtr. If it is, a new instance of UMIPChatThrottler will be created.

The UMIPChatThrottler will start a timer for the chat delay duration, and once the timer expires, it will destroy itself and remove itself from ChatThrottlers.

In OnMessageSendOnServerPreChecks(), the function will verify if the chat channel exists in ChatThrottlers. If it does, an error string message will be returned, indicating the remaining time.

Last updated