mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-17 21:37:43 +01:00
SeString renderer: fix colors, add link support (#1983)
* Add coloring options * Add link support * simplify * fixes * Prevent EncodeString from causing crashes * Fix link range application and add link example * Fix test widget * Make DalamudLinkPayload backward compatible * make it better to use * make it better to use * Mark SeString rendering functions experimental via comments * rename * Simplify * Make sestring draw functions take in draw params * Improvements
This commit is contained in:
parent
5fdd88b488
commit
b6eb18d550
25 changed files with 2009 additions and 766 deletions
|
|
@ -3,6 +3,8 @@ using System.IO;
|
|||
using Lumina.Text.Payloads;
|
||||
using Lumina.Text.ReadOnly;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -13,32 +15,39 @@ public class DalamudLinkPayload : Payload
|
|||
/// <inheritdoc/>
|
||||
public override PayloadType Type => PayloadType.DalamudLink;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin command ID to be linked.
|
||||
/// </summary>
|
||||
public uint CommandId { get; internal set; } = 0;
|
||||
/// <summary>Gets the plugin command ID to be linked.</summary>
|
||||
public uint CommandId { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin name to be linked.
|
||||
/// </summary>
|
||||
/// <summary>Gets an optional extra integer value 1.</summary>
|
||||
public int Extra1 { get; internal set; }
|
||||
|
||||
/// <summary>Gets an optional extra integer value 2.</summary>
|
||||
public int Extra2 { get; internal set; }
|
||||
|
||||
/// <summary>Gets the plugin name to be linked.</summary>
|
||||
public string Plugin { get; internal set; } = string.Empty;
|
||||
|
||||
/// <summary>Gets an optional extra string.</summary>
|
||||
public string ExtraString { get; internal set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.Type} - Plugin: {this.Plugin}, Command: {this.CommandId}";
|
||||
}
|
||||
public override string ToString() =>
|
||||
$"{this.Type} - {this.Plugin} ({this.CommandId}/{this.Extra1}/{this.Extra2}/{this.ExtraString})";
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override byte[] EncodeImpl()
|
||||
{
|
||||
return new Lumina.Text.SeStringBuilder()
|
||||
.BeginMacro(MacroCode.Link)
|
||||
.AppendIntExpression((int)EmbeddedInfoType.DalamudLink - 1)
|
||||
.AppendStringExpression(this.Plugin)
|
||||
.AppendUIntExpression(this.CommandId)
|
||||
.EndMacro()
|
||||
.ToArray();
|
||||
.BeginMacro(MacroCode.Link)
|
||||
.AppendIntExpression((int)EmbeddedInfoType.DalamudLink - 1)
|
||||
.AppendUIntExpression(this.CommandId)
|
||||
.AppendIntExpression(this.Extra1)
|
||||
.AppendIntExpression(this.Extra2)
|
||||
.BeginStringExpression()
|
||||
.Append(JsonConvert.SerializeObject(new[] { this.Plugin, this.ExtraString }))
|
||||
.EndExpression()
|
||||
.EndMacro()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -49,16 +58,53 @@ public class DalamudLinkPayload : Payload
|
|||
var body = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position));
|
||||
var rosps = new ReadOnlySePayloadSpan(ReadOnlySePayloadType.Macro, MacroCode.Link, body.AsSpan());
|
||||
|
||||
if (!rosps.TryGetExpression(out var pluginExpression, out var commandIdExpression))
|
||||
return;
|
||||
if (!rosps.TryGetExpression(
|
||||
out var commandIdExpression,
|
||||
out var extra1Expression,
|
||||
out var extra2Expression,
|
||||
out var compositeExpression))
|
||||
{
|
||||
if (!rosps.TryGetExpression(out var pluginExpression, out commandIdExpression))
|
||||
return;
|
||||
|
||||
if (!pluginExpression.TryGetString(out var pluginString))
|
||||
return;
|
||||
if (!pluginExpression.TryGetString(out var pluginString))
|
||||
return;
|
||||
|
||||
if (!commandIdExpression.TryGetUInt(out var commandId))
|
||||
return;
|
||||
if (!commandIdExpression.TryGetUInt(out var commandId))
|
||||
return;
|
||||
|
||||
this.Plugin = pluginString.ExtractText();
|
||||
this.CommandId = commandId;
|
||||
this.Plugin = pluginString.ExtractText();
|
||||
this.CommandId = commandId;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!commandIdExpression.TryGetUInt(out var commandId))
|
||||
return;
|
||||
|
||||
if (!extra1Expression.TryGetInt(out var extra1))
|
||||
return;
|
||||
|
||||
if (!extra2Expression.TryGetInt(out var extra2))
|
||||
return;
|
||||
|
||||
if (!compositeExpression.TryGetString(out var compositeString))
|
||||
return;
|
||||
|
||||
string[] extraData;
|
||||
try
|
||||
{
|
||||
extraData = JsonConvert.DeserializeObject<string[]>(compositeString.ExtractText());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.CommandId = commandId;
|
||||
this.Extra1 = extra1;
|
||||
this.Extra2 = extra2;
|
||||
this.Plugin = extraData[0];
|
||||
this.ExtraString = extraData[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue