mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
* FIx RGB returning wrong color and change it to RGBA * Don't use the old RGB variable * Fix UIGlowPayload too * Add RGBA to ABGR helper and new method for glow/foreground to expose it directly * Move from Utils to ColorHelpers * Rename the function
119 lines
3.4 KiB
C#
119 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
using Lumina.Excel.GeneratedSheets;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
|
|
|
|
/// <summary>
|
|
/// An SeString Payload representing a UI foreground color applied to following text payloads.
|
|
/// </summary>
|
|
public class UIForegroundPayload : Payload
|
|
{
|
|
private UIColor color;
|
|
|
|
[JsonProperty]
|
|
private ushort colorKey;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="UIForegroundPayload"/> class.
|
|
/// Creates a new UIForegroundPayload for the given UIColor key.
|
|
/// </summary>
|
|
/// <param name="colorKey">A UIColor key.</param>
|
|
public UIForegroundPayload(ushort colorKey)
|
|
{
|
|
this.colorKey = colorKey;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="UIForegroundPayload"/> class.
|
|
/// Creates a new UIForegroundPayload for the given UIColor key.
|
|
/// </summary>
|
|
internal UIForegroundPayload()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a payload representing disabling foreground color on following text.
|
|
/// </summary>
|
|
// TODO Make this work with DI
|
|
public static UIForegroundPayload UIForegroundOff => new(0);
|
|
|
|
/// <inheritdoc/>
|
|
public override PayloadType Type => PayloadType.UIForeground;
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether or not this payload represents applying a foreground color, or disabling one.
|
|
/// </summary>
|
|
public bool IsEnabled => this.ColorKey != 0;
|
|
|
|
/// <summary>
|
|
/// Gets a Lumina UIColor object representing this payload. The actual color data is at UIColor.UIForeground.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The value is evaluated lazily and cached.
|
|
/// </remarks>
|
|
[JsonIgnore]
|
|
public UIColor UIColor => this.color ??= this.DataResolver.GetExcelSheet<UIColor>().GetRow(this.colorKey);
|
|
|
|
/// <summary>
|
|
/// Gets or sets the color key used as a lookup in the UIColor table for this foreground color.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public ushort ColorKey
|
|
{
|
|
get
|
|
{
|
|
return this.colorKey;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.colorKey = value;
|
|
this.color = null;
|
|
this.Dirty = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Red/Green/Blue/Alpha values for this foreground color, encoded as a typical hex color.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public uint RGBA => this.UIColor.UIForeground;
|
|
|
|
/// <summary>
|
|
/// Gets the ABGR value for this foreground color, as ImGui requires it in PushColor.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public uint ABGR => Interface.ColorHelpers.SwapEndianness(this.UIColor.UIForeground);
|
|
|
|
/// <inheritdoc/>
|
|
public override string ToString()
|
|
{
|
|
return $"{this.Type} - UIColor: {this.colorKey} color: {(this.IsEnabled ? this.RGBA : 0)}";
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override byte[] EncodeImpl()
|
|
{
|
|
var colorBytes = MakeInteger(this.colorKey);
|
|
var chunkLen = colorBytes.Length + 1;
|
|
|
|
var bytes = new List<byte>(new byte[]
|
|
{
|
|
START_BYTE, (byte)SeStringChunkType.UIForeground, (byte)chunkLen,
|
|
});
|
|
|
|
bytes.AddRange(colorBytes);
|
|
bytes.Add(END_BYTE);
|
|
|
|
return bytes.ToArray();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
|
{
|
|
this.colorKey = (ushort)GetInteger(reader);
|
|
}
|
|
}
|