using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Sandbox.Engine.Multiplayer; using Sandbox.Game.Gui; using Sandbox.Game.Multiplayer; using Torch.Utils; using VRage.Game; using VRage.Network; using VRage.Replication; using VRageMath; using VRageRender; namespace Torch.API.Managers { /// /// Represents a scripted or user chat message. /// public readonly struct TorchChatMessage { private const string DEFAULT_FONT = MyFontEnum.Blue; #region Backwards compatibility [Obsolete] public TorchChatMessage(string author, string message, string font = DEFAULT_FONT) : this(author, message, default, font) { } [Obsolete] public TorchChatMessage(string author, ulong authorSteamId, string message, ChatChannel channel, long target, string font = DEFAULT_FONT) : this(author, authorSteamId, message, channel, target, default, font) { } [Obsolete] public TorchChatMessage(ulong authorSteamId, string message, ChatChannel channel, long target, string font = DEFAULT_FONT) : this(authorSteamId, message, channel, target, default, font) { } #endregion /// /// Creates a new torch chat message with the given author and message. /// /// Author's name /// Message /// Font public TorchChatMessage(string author, string message, Color color, string font = DEFAULT_FONT) { Timestamp = DateTime.Now; AuthorSteamId = null; Author = author; Message = message; Channel = ChatChannel.Global; Target = 0; Font = font; Color = color == default ? ColorUtils.TranslateColor(font) : color; } /// /// Creates a new torch chat message with the given author and message. /// /// Author's name /// Author's steam ID /// Message /// Font public TorchChatMessage(string author, ulong authorSteamId, string message, ChatChannel channel, long target, Color color, string font = DEFAULT_FONT) { Timestamp = DateTime.Now; AuthorSteamId = authorSteamId; Author = author; Message = message; Channel = channel; Target = target; Font = font; Color = color == default ? ColorUtils.TranslateColor(font) : color; } /// /// Creates a new torch chat message with the given author and message. /// /// Author's steam ID /// Message /// Font public TorchChatMessage(ulong authorSteamId, string message, ChatChannel channel, long target, Color color, string font = DEFAULT_FONT) { Timestamp = DateTime.Now; AuthorSteamId = authorSteamId; Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player"; Message = message; Channel = channel; Target = target; Font = font; Color = color == default ? ColorUtils.TranslateColor(font) : color; } /// /// This message's timestamp. /// public readonly DateTime Timestamp; /// /// The author's steam ID, if available. Else, null. /// public readonly ulong? AuthorSteamId; /// /// The author's name, if available. Else, null. /// public readonly string Author; /// /// The message contents. /// public readonly string Message; /// /// The chat channel the message is part of. /// public readonly ChatChannel Channel; /// /// The intended recipient of the message. /// public readonly long Target; /// /// The font, or null if default. /// public readonly string Font; /// /// The chat message color. /// public readonly Color Color; } /// /// Callback used to indicate that a messaage has been recieved. /// /// /// If true, this event has been consumed and should be ignored public delegate void MessageRecievedDel(TorchChatMessage msg, ref bool consumed); /// /// Callback used to indicate the user is attempting to send a message locally. /// /// Message the user is attempting to send /// If true, this event has been consumed and should be ignored public delegate void MessageSendingDel(string msg, ref bool consumed); public interface IChatManagerClient : IManager { /// /// Event that is raised when a message addressed to us is recieved. /// event MessageRecievedDel MessageRecieved; /// /// Event that is raised when we are attempting to send a message. /// event MessageSendingDel MessageSending; /// /// Triggers the event, /// typically raised by the user entering text into the chat window. /// /// The message to send void SendMessageAsSelf(string message); /// /// Displays a message on the UI given an author name and a message. /// /// Author name /// Message content /// font to use void DisplayMessageOnSelf(string author, string message, string font = "Blue" ); } }