feat: add links to chunks
This commit is contained in:
parent
f17a913405
commit
1d9581abca
|
@ -4,6 +4,11 @@ using Dalamud.Game.Text.SeStringHandling;
|
|||
namespace ChatTwo;
|
||||
|
||||
internal abstract class Chunk {
|
||||
internal Payload? Link;
|
||||
|
||||
protected Chunk(Payload? link) {
|
||||
this.Link = link;
|
||||
}
|
||||
}
|
||||
|
||||
internal class TextChunk : Chunk {
|
||||
|
@ -13,11 +18,11 @@ internal class TextChunk : Chunk {
|
|||
internal bool Italic { get; set; }
|
||||
internal string Content { get; set; }
|
||||
|
||||
internal TextChunk(string content) {
|
||||
internal TextChunk(Payload? link, string content) : base(link) {
|
||||
this.Content = content;
|
||||
}
|
||||
|
||||
internal TextChunk(ChatType? fallbackColour, uint? foreground, uint? glow, bool italic, string content) {
|
||||
internal TextChunk(Payload? link, ChatType? fallbackColour, uint? foreground, uint? glow, bool italic, string content) : base(link) {
|
||||
this.FallbackColour = fallbackColour;
|
||||
this.Foreground = foreground;
|
||||
this.Glow = glow;
|
||||
|
@ -29,7 +34,7 @@ internal class TextChunk : Chunk {
|
|||
internal class IconChunk : Chunk {
|
||||
internal BitmapFontIcon Icon;
|
||||
|
||||
public IconChunk(BitmapFontIcon icon) {
|
||||
public IconChunk(Payload? link, BitmapFontIcon icon) : base(link) {
|
||||
this.Icon = icon;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,11 +86,11 @@ internal class Store : IDisposable {
|
|||
|
||||
var senderChunks = new List<Chunk>();
|
||||
if (formatting is { IsPresent: true }) {
|
||||
senderChunks.Add(new TextChunk(formatting.Before) {
|
||||
senderChunks.Add(new TextChunk(null, formatting.Before) {
|
||||
FallbackColour = chatCode.Type,
|
||||
});
|
||||
senderChunks.AddRange(ChunkUtil.ToChunks(sender, chatCode.Type));
|
||||
senderChunks.Add(new TextChunk(formatting.After) {
|
||||
senderChunks.Add(new TextChunk(null, formatting.After) {
|
||||
FallbackColour = chatCode.Type,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ internal sealed class ChatLog : IUiComponent {
|
|||
|
||||
if (tab.DisplayTimestamp) {
|
||||
var timestamp = message.Date.ToLocalTime().ToString("t");
|
||||
this.DrawChunk(new TextChunk($"[{timestamp}]") {
|
||||
this.DrawChunk(new TextChunk(null, $"[{timestamp}]") {
|
||||
Foreground = 0xFFFFFFFF,
|
||||
});
|
||||
ImGui.SameLine();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using ChatTwo.Code;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using Dalamud.Logging;
|
||||
|
||||
namespace ChatTwo.Util;
|
||||
namespace ChatTwo.Util;
|
||||
|
||||
internal static class ChunkUtil {
|
||||
internal static IEnumerable<Chunk> ToChunks(SeString msg, ChatType? defaultColour) {
|
||||
|
@ -11,9 +12,10 @@ internal static class ChunkUtil {
|
|||
var italic = false;
|
||||
var foreground = new Stack<uint>();
|
||||
var glow = new Stack<uint>();
|
||||
Payload? link = null;
|
||||
|
||||
void Append(string text) {
|
||||
chunks.Add(new TextChunk(text) {
|
||||
chunks.Add(new TextChunk(link, text) {
|
||||
FallbackColour = defaultColour,
|
||||
Foreground = foreground.Count > 0 ? foreground.Peek() : null,
|
||||
Glow = glow.Count > 0 ? glow.Peek() : null,
|
||||
|
@ -21,7 +23,13 @@ internal static class ChunkUtil {
|
|||
});
|
||||
}
|
||||
|
||||
PluginLog.Log("");
|
||||
foreach (var payload in msg.Payloads) {
|
||||
PluginLog.Log(payload.Type.ToString());
|
||||
if (payload.Type == PayloadType.Unknown) {
|
||||
PluginLog.Log(payload.Encode().Select(b => b.ToString("x2")).Aggregate(string.Concat));
|
||||
}
|
||||
|
||||
switch (payload.Type) {
|
||||
case PayloadType.EmphasisItalic:
|
||||
var newStatus = ((EmphasisItalicPayload) payload).IsEnabled;
|
||||
|
@ -46,19 +54,29 @@ internal static class ChunkUtil {
|
|||
|
||||
break;
|
||||
case PayloadType.AutoTranslateText:
|
||||
chunks.Add(new IconChunk(BitmapFontIcon.AutoTranslateBegin));
|
||||
chunks.Add(new IconChunk(link, BitmapFontIcon.AutoTranslateBegin));
|
||||
var autoText = ((AutoTranslatePayload) payload).Text;
|
||||
Append(autoText.Substring(2, autoText.Length - 4));
|
||||
chunks.Add(new IconChunk(BitmapFontIcon.AutoTranslateEnd));
|
||||
chunks.Add(new IconChunk(link, BitmapFontIcon.AutoTranslateEnd));
|
||||
break;
|
||||
case PayloadType.Icon:
|
||||
chunks.Add(new IconChunk(((IconPayload) payload).Icon));
|
||||
chunks.Add(new IconChunk(link, ((IconPayload) payload).Icon));
|
||||
break;
|
||||
case PayloadType.MapLink:
|
||||
case PayloadType.Quest:
|
||||
case PayloadType.DalamudLink:
|
||||
case PayloadType.Status:
|
||||
case PayloadType.Item:
|
||||
case PayloadType.Player:
|
||||
link = payload;
|
||||
break;
|
||||
case PayloadType.Unknown:
|
||||
var rawPayload = (RawPayload) payload;
|
||||
if (rawPayload.Data[1] == 0x13) {
|
||||
foreground.Pop();
|
||||
glow.Pop();
|
||||
} else if (rawPayload == RawPayload.LinkTerminator) {
|
||||
link = null;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue