XivChatEntry should use SeString

This commit is contained in:
Raymond 2021-07-15 22:09:31 -04:00
parent 85113e263f
commit 5c4ed3f715
7 changed files with 27 additions and 16 deletions

View file

@ -257,7 +257,7 @@ namespace Dalamud.Game
{ {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry
{ {
MessageBytes = Encoding.UTF8.GetBytes(Loc.Localize("DalamudUpdated", "The In-Game addon has been updated or was reinstalled successfully! Please check the discord for a full changelog.")), Message = Loc.Localize("DalamudUpdated", "The In-Game addon has been updated or was reinstalled successfully! Please check the discord for a full changelog."),
Type = XivChatType.Notice, Type = XivChatType.Notice,
}); });
@ -289,7 +289,7 @@ namespace Dalamud.Game
{ {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry
{ {
MessageBytes = new SeString(new List<Payload>() Message = new SeString(new List<Payload>()
{ {
new TextPayload(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")), new TextPayload(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")),
new TextPayload(" ["), new TextPayload(" ["),
@ -299,7 +299,7 @@ namespace Dalamud.Game
RawPayload.LinkTerminator, RawPayload.LinkTerminator,
new UIForegroundPayload(this.dalamud.Data, 0), new UIForegroundPayload(this.dalamud.Data, 0),
new TextPayload("]"), new TextPayload("]"),
}).Encode(), }),
Type = XivChatType.Urgent, Type = XivChatType.Urgent,
}); });
} }

View file

@ -184,7 +184,7 @@ namespace Dalamud.Game.Internal.Gui
Log.Verbose("[CHATGUI PRINT REGULAR]{0}", message); Log.Verbose("[CHATGUI PRINT REGULAR]{0}", message);
this.PrintChat(new XivChatEntry this.PrintChat(new XivChatEntry
{ {
MessageBytes = Encoding.UTF8.GetBytes(message), Message = message,
Type = this.dalamud.Configuration.GeneralChatType, Type = this.dalamud.Configuration.GeneralChatType,
}); });
} }
@ -199,7 +199,7 @@ namespace Dalamud.Game.Internal.Gui
Log.Verbose("[CHATGUI PRINT SESTRING]{0}", message.TextValue); Log.Verbose("[CHATGUI PRINT SESTRING]{0}", message.TextValue);
this.PrintChat(new XivChatEntry this.PrintChat(new XivChatEntry
{ {
MessageBytes = message.Encode(), Message = message,
Type = this.dalamud.Configuration.GeneralChatType, Type = this.dalamud.Configuration.GeneralChatType,
}); });
} }
@ -214,7 +214,7 @@ namespace Dalamud.Game.Internal.Gui
Log.Verbose("[CHATGUI PRINT REGULAR ERROR]{0}", message); Log.Verbose("[CHATGUI PRINT REGULAR ERROR]{0}", message);
this.PrintChat(new XivChatEntry this.PrintChat(new XivChatEntry
{ {
MessageBytes = Encoding.UTF8.GetBytes(message), Message = message,
Type = XivChatType.Urgent, Type = XivChatType.Urgent,
}); });
} }
@ -229,7 +229,7 @@ namespace Dalamud.Game.Internal.Gui
Log.Verbose("[CHATGUI PRINT SESTRING ERROR]{0}", message.TextValue); Log.Verbose("[CHATGUI PRINT SESTRING ERROR]{0}", message.TextValue);
this.PrintChat(new XivChatEntry this.PrintChat(new XivChatEntry
{ {
MessageBytes = message.Encode(), Message = message,
Type = XivChatType.Urgent, Type = XivChatType.Urgent,
}); });
} }
@ -249,10 +249,10 @@ namespace Dalamud.Game.Internal.Gui
continue; continue;
} }
var senderRaw = Encoding.UTF8.GetBytes(chat.Name ?? string.Empty); var senderRaw = (chat.Name ?? string.Empty).Encode();
using var senderOwned = framework.Libc.NewString(senderRaw); using var senderOwned = framework.Libc.NewString(senderRaw);
var messageRaw = chat.MessageBytes ?? Array.Empty<byte>(); var messageRaw = (chat.Message ?? string.Empty).Encode();
using var messageOwned = framework.Libc.NewString(messageRaw); using var messageOwned = framework.Libc.NewString(messageRaw);
this.HandlePrintMessageDetour(this.baseAddress, chat.Type, senderOwned.Address, messageOwned.Address, chat.SenderId, chat.Parameters); this.HandlePrintMessageDetour(this.baseAddress, chat.Type, senderOwned.Address, messageOwned.Address, chat.SenderId, chat.Parameters);

View file

@ -300,7 +300,7 @@ namespace Dalamud.Game.Text.SeStringHandling
EmphasisItalic = 0x1A, EmphasisItalic = 0x1A,
/// <summary> /// <summary>
/// See the <see cref="NewLinePayload"/> /// See the <see cref="NewLinePayload"/>.
/// </summary> /// </summary>
NewLine = 0x10, NewLine = 0x10,

View file

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
namespace Dalamud.Game.Text.SeStringHandling.Payloads namespace Dalamud.Game.Text.SeStringHandling.Payloads
@ -16,7 +16,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
public static NewLinePayload Payload => new(); public static NewLinePayload Payload => new();
/// <summary> /// <summary>
/// Gets the text of this payload, evaluates to <c>Environment.NewLine</c> /// Gets the text of this payload, evaluates to <c>Environment.NewLine</c>.
/// </summary> /// </summary>
public string Text => Environment.NewLine; public string Text => Environment.NewLine;

View file

@ -13,6 +13,15 @@ namespace Dalamud.Game.Text.SeStringHandling
/// </summary> /// </summary>
public class SeString public class SeString
{ {
/// <summary>
/// Initializes a new instance of the <see cref="SeString"/> class.
/// Creates a new SeString from an ordered list of payloads.
/// </summary>
public SeString()
{
this.Payloads = new List<Payload>();
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SeString"/> class. /// Initializes a new instance of the <see cref="SeString"/> class.
/// Creates a new SeString from an ordered list of payloads. /// Creates a new SeString from an ordered list of payloads.

View file

@ -1,5 +1,7 @@
using System; using System;
using Dalamud.Game.Text.SeStringHandling;
namespace Dalamud.Game.Text namespace Dalamud.Game.Text
{ {
/// <summary> /// <summary>
@ -20,12 +22,12 @@ namespace Dalamud.Game.Text
/// <summary> /// <summary>
/// Gets or sets the sender name. /// Gets or sets the sender name.
/// </summary> /// </summary>
public string Name { get; set; } = string.Empty; public SeString Name { get; set; } = string.Empty;
/// <summary> /// <summary>
/// Gets or sets the message bytes. /// Gets or sets the message.
/// </summary> /// </summary>
public byte[] MessageBytes { get; set; } public SeString Message { get; set; } = string.Empty;
/// <summary> /// <summary>
/// Gets or sets the message parameters. /// Gets or sets the message parameters.

View file

@ -727,7 +727,7 @@ namespace Dalamud.Plugin.Internal
{ {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry
{ {
MessageBytes = Encoding.UTF8.GetBytes(Locs.DalamudPluginUpdateFailed(metadata.Name, metadata.Version)), Message = Locs.DalamudPluginUpdateFailed(metadata.Name, metadata.Version),
Type = XivChatType.Urgent, Type = XivChatType.Urgent,
}); });
} }