feat(chat): CT-A4 — speaker names render in retail's tag colour
Campaign CT slice A4, and the first slice of Group A that shows on screen: a player's name in a chat line now draws green while the rest of the line keeps its message colour. The colour is AUTHORED, not computed. Retail keeps two parallel index-selected colour arrays on the text element and refreshes both from the same caller index on every append (UIElement_Text::AppendStringInfoWithFont @0x00469DE0): property 0x1B for ordinary glyphs, 0x1D for glyphs under an open tag. Property 0x1D is read exactly the way 0x1B already was, carried on ElementInfo, and seeded onto UiText beside DefaultColor. Measured on the chat transcript (0x2100006F / 0x10000011) as RGB(0,178,0). It deliberately does NOT go into RetailChatColorTable. That table is the runtime-built per-LogTextType mapping; the tag colour is per-element authored data, and filing it there would put it somewhere it would look right in tests and be wrong in principle. RunsForFragment is the load-bearing piece and is pure. Wrapping can drop the space it broke on, so a fragment is NOT simply the next N characters of the line — BuildLines locates each fragment in the source text to keep the span offsets honest, and the mapper clips spans to the fragment window. A tag straddling a wrap break is therefore split across both fragments and stays green on both, instead of changing colour mid-word. Two guards worth naming. A fragment containing no tag returns NULL rather than a single-run list, so the overwhelming majority of lines keep the existing flat draw path untouched. And an element authoring no 0x1D falls back to the line colour, so a name never renders in a colour nobody chose. The run/fragment contract is property-tested across every substring of a tell line, because CT-A1's RunsMatchLine refuses mismatched runs by silently falling back to flat text — a mapping bug here would degrade quietly rather than fail. Solution builds clean; full hermetic gate green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
44fb74f8a6
commit
53395e4de4
6 changed files with 318 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using AcDream.Core.Chat;
|
||||
using AcDream.UI.Abstractions.Panels.Chat;
|
||||
|
||||
namespace AcDream.App.UI.Layout;
|
||||
|
|
@ -64,14 +65,66 @@ internal static class ChatTranscriptRenderer
|
|||
/// unchanged" rule — see <see cref="RetailChatColorTable"/>'s own doc).
|
||||
/// Callers pass their transcript's <see cref="UiText.DefaultColor"/>.
|
||||
/// </param>
|
||||
/// <summary>
|
||||
/// The runs covering one wrapped fragment, or <see langword="null"/> when
|
||||
/// the fragment is a single colour.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Campaign CT slice A4. Wrapping splits a line into fragments, and a tag
|
||||
/// can straddle a break, so a fragment may hold part of a tagged run, all
|
||||
/// of it, or none.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Returns null unless a tag actually falls inside the window — a
|
||||
/// single-colour fragment must take the ordinary flat draw path rather
|
||||
/// than a one-run list that means the same thing.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal static IReadOnlyList<UiText.TextRun>? RunsForFragment(
|
||||
IReadOnlyList<ChatTextSpan> spans,
|
||||
int fragmentStart,
|
||||
int fragmentLength,
|
||||
Vector4 lineColor,
|
||||
Vector4 tagColor)
|
||||
{
|
||||
int fragmentEnd = fragmentStart + fragmentLength;
|
||||
var runs = new List<UiText.TextRun>();
|
||||
bool sawTag = false;
|
||||
int at = 0;
|
||||
|
||||
foreach (ChatTextSpan span in spans)
|
||||
{
|
||||
int spanStart = at;
|
||||
int spanEnd = at + span.Text.Length;
|
||||
at = spanEnd;
|
||||
|
||||
int from = Math.Max(spanStart, fragmentStart);
|
||||
int to = Math.Min(spanEnd, fragmentEnd);
|
||||
if (to <= from)
|
||||
continue;
|
||||
|
||||
bool tagged = span.Tag is not null;
|
||||
sawTag |= tagged;
|
||||
runs.Add(new UiText.TextRun(
|
||||
span.Text.Substring(from - spanStart, to - from),
|
||||
tagged ? tagColor : lineColor));
|
||||
}
|
||||
|
||||
return sawTag ? runs : null;
|
||||
}
|
||||
|
||||
public static List<UiText.Line> BuildLines(
|
||||
IReadOnlyList<FormattedLine> detailed,
|
||||
float maxW,
|
||||
Func<string, float> measure,
|
||||
Func<uint, bool>? accept,
|
||||
Vector4 defaultColor)
|
||||
Vector4 defaultColor,
|
||||
Vector4? tagColor = null,
|
||||
List<IReadOnlyList<UiText.TextRun>?>? runsPerLine = null)
|
||||
{
|
||||
var result = new List<UiText.Line>(detailed.Count);
|
||||
runsPerLine?.Clear();
|
||||
if (detailed.Count == 0)
|
||||
return result;
|
||||
|
||||
|
|
@ -88,8 +141,40 @@ internal static class ChatTranscriptRenderer
|
|||
continue;
|
||||
if (RetailChatColorTable.TryGetColor(d.LogTextType, out Vector4 resolved))
|
||||
currentColor = resolved;
|
||||
// Wrapping can DROP the space it broke on, so a fragment is not
|
||||
// simply the next N characters — locate each one in the source
|
||||
// line to keep the span offsets honest.
|
||||
int searchFrom = 0;
|
||||
foreach (string frag in WrapText(d.Text, maxW, measure))
|
||||
{
|
||||
result.Add(new UiText.Line(frag, currentColor));
|
||||
|
||||
if (runsPerLine is null)
|
||||
continue;
|
||||
|
||||
if (d.Spans is not { Count: > 0 } spans || frag.Length == 0)
|
||||
{
|
||||
runsPerLine.Add(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
int at = d.Text.IndexOf(frag, searchFrom, StringComparison.Ordinal);
|
||||
if (at < 0)
|
||||
{
|
||||
// Should not happen; a fragment always comes from the line.
|
||||
// Fall back to the flat colour rather than mis-colouring.
|
||||
runsPerLine.Add(null);
|
||||
continue;
|
||||
}
|
||||
searchFrom = at + frag.Length;
|
||||
|
||||
runsPerLine.Add(RunsForFragment(
|
||||
spans,
|
||||
at,
|
||||
frag.Length,
|
||||
currentColor,
|
||||
tagColor ?? currentColor));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue