mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-14 20:54:16 +01:00
Merge pull request #1334 from Haselnussbomber/v9-fix-createitemlink
This commit is contained in:
commit
04de7d2bbb
3 changed files with 58 additions and 26 deletions
|
|
@ -130,7 +130,13 @@ public class MapLinkPayload : Payload
|
||||||
var y = Math.Truncate((this.YCoord + fudge) * 10.0f) / 10.0f;
|
var y = Math.Truncate((this.YCoord + fudge) * 10.0f) / 10.0f;
|
||||||
|
|
||||||
// the formatting and spacing the game uses
|
// the formatting and spacing the game uses
|
||||||
return $"( {x:0.0} , {y:0.0} )";
|
var clientState = Service<ClientState.ClientState>.Get();
|
||||||
|
return clientState.ClientLanguage switch
|
||||||
|
{
|
||||||
|
ClientLanguage.German => $"( {x:0.0}, {y:0.0} )",
|
||||||
|
ClientLanguage.Japanese => $"({x:0.0}, {y:0.0})",
|
||||||
|
_ => $"( {x:0.0} , {y:0.0} )",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,27 @@ public class SeString
|
||||||
/// with the appropriate glow and coloring.
|
/// with the appropriate glow and coloring.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of all the payloads required to insert the link marker.</returns>
|
/// <returns>A list of all the payloads required to insert the link marker.</returns>
|
||||||
public static IEnumerable<Payload> TextArrowPayloads => new List<Payload>(new Payload[]
|
public static IEnumerable<Payload> TextArrowPayloads
|
||||||
{
|
{
|
||||||
new UIForegroundPayload(0x01F4),
|
get
|
||||||
new UIGlowPayload(0x01F5),
|
{
|
||||||
new TextPayload($"{(char)SeIconChar.LinkMarker}"),
|
var clientState = Service<ClientState.ClientState>.Get();
|
||||||
|
var markerSpace = clientState.ClientLanguage switch
|
||||||
|
{
|
||||||
|
ClientLanguage.German => " ",
|
||||||
|
ClientLanguage.French => " ",
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
return new List<Payload>
|
||||||
|
{
|
||||||
|
new UIForegroundPayload(500),
|
||||||
|
new UIGlowPayload(501),
|
||||||
|
new TextPayload($"{(char)SeIconChar.LinkMarker}{markerSpace}"),
|
||||||
UIGlowPayload.UIGlowOff,
|
UIGlowPayload.UIGlowOff,
|
||||||
UIForegroundPayload.UIForegroundOff,
|
UIForegroundPayload.UIForegroundOff,
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an empty SeString.
|
/// Gets an empty SeString.
|
||||||
|
|
@ -171,6 +184,7 @@ public class SeString
|
||||||
var data = Service<DataManager>.Get();
|
var data = Service<DataManager>.Get();
|
||||||
|
|
||||||
var displayName = displayNameOverride;
|
var displayName = displayNameOverride;
|
||||||
|
var rarity = 1; // default: white
|
||||||
if (displayName == null)
|
if (displayName == null)
|
||||||
{
|
{
|
||||||
switch (kind)
|
switch (kind)
|
||||||
|
|
@ -178,7 +192,9 @@ public class SeString
|
||||||
case ItemPayload.ItemKind.Normal:
|
case ItemPayload.ItemKind.Normal:
|
||||||
case ItemPayload.ItemKind.Collectible:
|
case ItemPayload.ItemKind.Collectible:
|
||||||
case ItemPayload.ItemKind.Hq:
|
case ItemPayload.ItemKind.Hq:
|
||||||
displayName = data.GetExcelSheet<Item>()?.GetRow(itemId)?.Name;
|
var item = data.GetExcelSheet<Item>()?.GetRow(itemId);
|
||||||
|
displayName = item?.Name;
|
||||||
|
rarity = item?.Rarity ?? 1;
|
||||||
break;
|
break;
|
||||||
case ItemPayload.ItemKind.EventItem:
|
case ItemPayload.ItemKind.EventItem:
|
||||||
displayName = data.GetExcelSheet<EventItem>()?.GetRow(itemId)?.Name;
|
displayName = data.GetExcelSheet<EventItem>()?.GetRow(itemId)?.Name;
|
||||||
|
|
@ -202,21 +218,20 @@ public class SeString
|
||||||
displayName += $" {(char)SeIconChar.Collectible}";
|
displayName += $" {(char)SeIconChar.Collectible}";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: probably a cleaner way to build these than doing the bulk+insert
|
var textColor = (ushort)(549 + ((rarity - 1) * 2));
|
||||||
var payloads = new List<Payload>(new Payload[]
|
var textGlowColor = (ushort)(textColor + 1);
|
||||||
{
|
|
||||||
new UIForegroundPayload(0x0225),
|
|
||||||
new UIGlowPayload(0x0226),
|
|
||||||
new ItemPayload(itemId, kind),
|
|
||||||
// arrow goes here
|
|
||||||
new TextPayload(displayName),
|
|
||||||
RawPayload.LinkTerminator,
|
|
||||||
// sometimes there is another set of uiglow/foreground off payloads here
|
|
||||||
// might be necessary when including additional text after the item name
|
|
||||||
});
|
|
||||||
payloads.InsertRange(3, TextArrowPayloads);
|
|
||||||
|
|
||||||
return new SeString(payloads);
|
// Note: `SeStringBuilder.AddItemLink` uses this function, so don't call it here!
|
||||||
|
return new SeStringBuilder()
|
||||||
|
.AddUiForeground(textColor)
|
||||||
|
.AddUiGlow(textGlowColor)
|
||||||
|
.Add(new ItemPayload(itemId, kind))
|
||||||
|
.Append(TextArrowPayloads)
|
||||||
|
.AddText(displayName)
|
||||||
|
.AddUiGlowOff()
|
||||||
|
.AddUiForegroundOff()
|
||||||
|
.Add(RawPayload.LinkTerminator)
|
||||||
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
|
|
||||||
namespace Dalamud.Game.Text.SeStringHandling;
|
namespace Dalamud.Game.Text.SeStringHandling;
|
||||||
|
|
@ -30,6 +33,13 @@ public class SeStringBuilder
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
public SeStringBuilder Append(string text) => this.AddText(text);
|
public SeStringBuilder Append(string text) => this.AddText(text);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Append payloads to the builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="payloads">A list of payloads.</param>
|
||||||
|
/// <returns>The current builder.</returns>
|
||||||
|
public SeStringBuilder Append(IEnumerable<Payload> payloads) => this.Append(new SeString(payloads.ToList()));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Append raw text to the builder.
|
/// Append raw text to the builder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -104,7 +114,7 @@ public class SeStringBuilder
|
||||||
/// <param name="itemNameOverride">Override for the item's name.</param>
|
/// <param name="itemNameOverride">Override for the item's name.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
public SeStringBuilder AddItemLink(uint itemId, bool isHq, string? itemNameOverride = null) =>
|
public SeStringBuilder AddItemLink(uint itemId, bool isHq, string? itemNameOverride = null) =>
|
||||||
this.Add(new ItemPayload(itemId, isHq, itemNameOverride));
|
this.Append(SeString.CreateItemLink(itemId, isHq, itemNameOverride));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add an item link to the builder.
|
/// Add an item link to the builder.
|
||||||
|
|
@ -113,14 +123,15 @@ public class SeStringBuilder
|
||||||
/// <param name="kind">Kind of item to encode.</param>
|
/// <param name="kind">Kind of item to encode.</param>
|
||||||
/// <param name="itemNameOverride">Override for the item's name.</param>
|
/// <param name="itemNameOverride">Override for the item's name.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
public SeStringBuilder AddItemLink(uint itemId, ItemPayload.ItemKind kind, string? itemNameOverride = null) =>
|
public SeStringBuilder AddItemLink(uint itemId, ItemPayload.ItemKind kind = ItemPayload.ItemKind.Normal, string? itemNameOverride = null) =>
|
||||||
this.Add(new ItemPayload(itemId, kind, itemNameOverride));
|
this.Append(SeString.CreateItemLink(itemId, kind, itemNameOverride));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add an item link to the builder.
|
/// Add an item link to the builder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rawItemId">The raw item ID.</param>
|
/// <param name="rawItemId">The raw item ID.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
|
/// <remarks>To terminate this item link, add a <see cref="RawPayload.LinkTerminator"/>.</remarks>
|
||||||
public SeStringBuilder AddItemLinkRaw(uint rawItemId) =>
|
public SeStringBuilder AddItemLinkRaw(uint rawItemId) =>
|
||||||
this.Add(ItemPayload.FromRaw(rawItemId));
|
this.Add(ItemPayload.FromRaw(rawItemId));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue