Update events/UI to reflect new chat

This commit is contained in:
John Gross
2019-03-05 11:31:00 -08:00
parent f16e825b57
commit 72ceeffdad
4 changed files with 17 additions and 6 deletions

View File

@@ -58,14 +58,14 @@ namespace Torch.API.Managers
/// <param name="authorSteamId">Author's steam ID</param> /// <param name="authorSteamId">Author's steam ID</param>
/// <param name="message">Message</param> /// <param name="message">Message</param>
/// <param name="font">Font</param> /// <param name="font">Font</param>
public TorchChatMessage(ulong authorSteamId, string message, string font = MyFontEnum.Blue) public TorchChatMessage(ulong authorSteamId, string message, ChatChannel channel, long target, string font = MyFontEnum.Blue)
{ {
Timestamp = DateTime.Now; Timestamp = DateTime.Now;
AuthorSteamId = authorSteamId; AuthorSteamId = authorSteamId;
Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player"; Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player";
Message = message; Message = message;
Channel = ChatChannel.Global; Channel = channel;
Target = 0; Target = target;
Font = font; Font = font;
} }

View File

@@ -20,6 +20,8 @@ using NLog;
using Torch; using Torch;
using Sandbox; using Sandbox;
using Sandbox.Engine.Multiplayer; using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Gui;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World; using Sandbox.Game.World;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
@@ -131,6 +133,15 @@ namespace Torch.Server
bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight; bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
var span = new Span(); var span = new Span();
span.Inlines.Add($"{msg.Timestamp} "); span.Inlines.Add($"{msg.Timestamp} ");
switch (msg.Channel)
{
case ChatChannel.Faction:
span.Inlines.Add(new Run($"[{MySession.Static.Factions.TryGetFactionById(msg.Target)?.Tag ?? "???"}] ") { Foreground = Brushes.Green });
break;
case ChatChannel.Private:
span.Inlines.Add(new Run($"[to {MySession.Static.Players.TryGetIdentity(msg.Target)?.DisplayName ?? "???"}] ") { Foreground = Brushes.DeepPink });
break;
}
span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) }); span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) });
span.Inlines.Add($": {msg.Message}"); span.Inlines.Add($": {msg.Message}");
span.Inlines.Add(new LineBreak()); span.Inlines.Add(new LineBreak());

View File

@@ -127,7 +127,7 @@ namespace Torch.Managers.ChatManager
private void Multiplayer_ChatMessageReceived(ulong steamUserId, string messageText, ChatChannel channel, long targetId, string customAuthorName) private void Multiplayer_ChatMessageReceived(ulong steamUserId, string messageText, ChatChannel channel, long targetId, string customAuthorName)
{ {
var torchMsg = new TorchChatMessage(steamUserId, messageText, var torchMsg = new TorchChatMessage(steamUserId, messageText, channel, targetId,
(steamUserId == MyGameService.UserId) ? MyFontEnum.DarkBlue : MyFontEnum.Blue); (steamUserId == MyGameService.UserId) ? MyFontEnum.DarkBlue : MyFontEnum.Blue);
if (!RaiseMessageRecieved(torchMsg) && HasHud) if (!RaiseMessageRecieved(torchMsg) && HasHud)
_hudChatMessageReceived.Invoke(MyHud.Chat, steamUserId, messageText, channel, targetId, customAuthorName); _hudChatMessageReceived.Invoke(MyHud.Chat, steamUserId, messageText, channel, targetId, customAuthorName);

View File

@@ -61,7 +61,7 @@ namespace Torch.Managers.ChatManager
{ {
if (targetSteamId == Sync.MyId) if (targetSteamId == Sync.MyId)
{ {
RaiseMessageRecieved(new TorchChatMessage(authorId, message)); RaiseMessageRecieved(new TorchChatMessage(authorId, message, ChatChannel.Global, 0));
return; return;
} }
if (MyMultiplayer.Static == null) if (MyMultiplayer.Static == null)
@@ -131,7 +131,7 @@ namespace Torch.Managers.ChatManager
MessageProcessing?.Invoke(torchMsg, ref consumed); MessageProcessing?.Invoke(torchMsg, ref consumed);
if (!consumed) if (!consumed)
_chatLog.Info($"{torchMsg.Author}: {torchMsg.Message}"); _chatLog.Info($"[{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}");
} }
public static string GetMemberName(ulong steamId) public static string GetMemberName(ulong steamId)