Use Tuple syntax

This commit is contained in:
teinarss
2020-08-02 13:41:03 +02:00
committed by Paul Chote
parent 8a74f6ea18
commit 19b02875c7
90 changed files with 738 additions and 826 deletions

View File

@@ -20,25 +20,25 @@ namespace OpenRA.Mods.Common.Widgets
public class LabelWithHighlightWidget : LabelWidget
{
public Color HighlightColor = ChromeMetrics.Get<Color>("TextHighlightColor");
readonly CachedTransform<string, Pair<string, bool>[]> textComponents;
readonly CachedTransform<string, (string Text, bool Highlighted)[]> textComponents;
[ObjectCreator.UseCtor]
public LabelWithHighlightWidget()
: base()
{
textComponents = new CachedTransform<string, Pair<string, bool>[]>(MakeComponents);
textComponents = new CachedTransform<string, (string, bool)[]>(MakeComponents);
}
protected LabelWithHighlightWidget(LabelWithHighlightWidget other)
: base(other)
{
HighlightColor = other.HighlightColor;
textComponents = new CachedTransform<string, Pair<string, bool>[]>(MakeComponents);
textComponents = new CachedTransform<string, (string, bool)[]>(MakeComponents);
}
Pair<string, bool>[] MakeComponents(string text)
(string, bool)[] MakeComponents(string text)
{
List<Pair<string, bool>> components = new List<Pair<string, bool>>();
var components = new List<(string, bool)>();
foreach (var l in text.Split(new[] { "\\n" }, StringSplitOptions.None))
{
var line = l;
@@ -54,18 +54,18 @@ namespace OpenRA.Mods.Common.Widgets
{
// Normal line segment before highlight
var lineNormal = line.Substring(0, highlightStart);
components.Add(Pair.New(lineNormal, false));
components.Add((lineNormal, false));
}
// Highlight line segment
var lineHighlight = line.Substring(highlightStart + 1, highlightEnd - highlightStart - 1);
components.Add(Pair.New(lineHighlight, true));
components.Add((lineHighlight, true));
line = line.Substring(highlightEnd + 1);
}
else
{
// Final normal line segment
components.Add(Pair.New(line, false));
components.Add((line, false));
break;
}
}
@@ -79,8 +79,8 @@ namespace OpenRA.Mods.Common.Widgets
var advance = 0;
foreach (var c in textComponents.Update(text))
{
base.DrawInner(c.First, font, c.Second ? HighlightColor : color, position + new int2(advance, 0));
advance += font.Measure(c.First).X;
base.DrawInner(c.Text, font, c.Highlighted ? HighlightColor : color, position + new int2(advance, 0));
advance += font.Measure(c.Text).X;
}
}