Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LiveSplit.Splits/UI/ColumnType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum ColumnType
{
Delta, SplitTime, DeltaorSplitTime, SegmentDelta, SegmentTime, SegmentDeltaorSegmentTime
Delta, SplitTime, DeltaorSplitTime, SegmentDelta, SegmentTime, SegmentDeltaorSegmentTime, CustomVariable
}
5 changes: 3 additions & 2 deletions src/LiveSplit.Splits/UI/Components/ColumnSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/LiveSplit.Splits/UI/Components/ColumnSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,18 @@ private static string GetColumnType(ColumnType type)
{
return "Segment Delta";
}
else
else if (type == ColumnType.SegmentDeltaorSegmentTime)
{
return "Segment Delta or Segment Time";
}
else if (type == ColumnType.CustomVariable)
{
return "Custom Variable";
}
else
{
return "Unknown";
}
}

private static ColumnType ParseColumnType(string columnType)
Expand Down
74 changes: 16 additions & 58 deletions src/LiveSplit.Splits/UI/Components/LabelsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,20 @@

using LiveSplit.Model;
using LiveSplit.Model.Comparisons;
using LiveSplit.TimeFormatters;

namespace LiveSplit.UI.Components;

public class LabelsComponent : IComponent
{
public SplitsSettings Settings { get; set; }

protected SimpleLabel MeasureTimeLabel { get; set; }
protected SimpleLabel MeasureDeltaLabel { get; set; }

protected ITimeFormatter TimeFormatter { get; set; }
protected ITimeFormatter DeltaTimeFormatter { get; set; }

protected TimeAccuracy CurrentAccuracy { get; set; }
protected TimeAccuracy CurrentDeltaAccuracy { get; set; }
protected bool CurrentDropDecimals { get; set; }

protected int FrameCount { get; set; }

public GraphicsCache Cache { get; set; }

public IEnumerable<ColumnData> ColumnsList { get; set; }
public IList<SimpleLabel> LabelsList { get; set; }
protected List<(int exLength, float exWidth, float width)> ColumnWidths { get; }

public float PaddingTop => 0f;
public float PaddingLeft => 0f;
Expand All @@ -45,19 +35,15 @@ public class LabelsComponent : IComponent
public float MinimumHeight { get; set; }

public IDictionary<string, Action> ContextMenuControls => null;
public LabelsComponent(SplitsSettings settings, IEnumerable<ColumnData> columns)
public LabelsComponent(SplitsSettings settings, IEnumerable<ColumnData> columns, List<(int exLength, float exWidth, float width)> columnWidths)
{
Settings = settings;
MinimumHeight = 31;

MeasureTimeLabel = new SimpleLabel();
MeasureDeltaLabel = new SimpleLabel();
TimeFormatter = new SplitTimeFormatter(Settings.SplitTimesAccuracy);
DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals);

Cache = new GraphicsCache();
LabelsList = [];
ColumnsList = columns;
ColumnWidths = columnWidths;
}

private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height, LayoutMode mode)
Expand All @@ -69,30 +55,6 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he
), 0, 0, width, height);
}

MeasureTimeLabel.Text = TimeFormatter.Format(new TimeSpan(24, 0, 0));
MeasureDeltaLabel.Text = DeltaTimeFormatter.Format(new TimeSpan(0, 9, 0, 0));

MeasureTimeLabel.Font = state.LayoutSettings.TimesFont;
MeasureTimeLabel.IsMonospaced = true;
MeasureDeltaLabel.Font = state.LayoutSettings.TimesFont;
MeasureDeltaLabel.IsMonospaced = true;

MeasureTimeLabel.SetActualWidth(g);
MeasureDeltaLabel.SetActualWidth(g);

if (Settings.SplitTimesAccuracy != CurrentAccuracy)
{
TimeFormatter = new SplitTimeFormatter(Settings.SplitTimesAccuracy);
CurrentAccuracy = Settings.SplitTimesAccuracy;
}

if (Settings.DeltasAccuracy != CurrentDeltaAccuracy || Settings.DropDecimals != CurrentDropDecimals)
{
DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals);
CurrentDeltaAccuracy = Settings.DeltasAccuracy;
CurrentDropDecimals = Settings.DropDecimals;
}

foreach (SimpleLabel label in LabelsList)
{
label.ShadowColor = state.LayoutSettings.ShadowsColor;
Expand All @@ -105,24 +67,15 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he

if (ColumnsList.Count() == LabelsList.Count)
{
while (ColumnWidths.Count < LabelsList.Count)
{
ColumnWidths.Add((0, 0f, 0f));
}

float curX = width - 7;
foreach (SimpleLabel label in LabelsList.Reverse())
{
ColumnData column = ColumnsList.ElementAt(LabelsList.IndexOf(label));

float labelWidth = 0f;
if (column.Type is ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime)
{
labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth);
}
else if (column.Type is ColumnType.Delta or ColumnType.SegmentDelta)
{
labelWidth = MeasureDeltaLabel.ActualWidth;
}
else
{
labelWidth = MeasureTimeLabel.ActualWidth;
}
float labelWidth = ColumnWidths[LabelsList.IndexOf(label)].width;

curX -= labelWidth + 5;
label.Width = labelWidth;
Expand Down Expand Up @@ -212,9 +165,14 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width,

Cache.Restart();
Cache["ColumnsCount"] = ColumnsList.Count();
foreach (SimpleLabel label in LabelsList)
for (int index = 0; index < LabelsList.Count; index++)
{
Cache["Columns" + LabelsList.IndexOf(label) + "Text"] = label.Text;
SimpleLabel label = LabelsList[index];
Cache["Columns" + index + "Text"] = label.Text;
if (index < ColumnWidths.Count)
{
Cache["Columns" + index + "Width"] = ColumnWidths[index].width;
}
}

if (invalidator != null && (Cache.HasChanged || FrameCount > 1))
Expand Down
89 changes: 44 additions & 45 deletions src/LiveSplit.Splits/UI/Components/SplitComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class SplitComponent : IComponent
public ISegment Split { get; set; }

protected SimpleLabel NameLabel { get; set; }
protected SimpleLabel MeasureTimeLabel { get; set; }
protected SimpleLabel MeasureDeltaLabel { get; set; }
public SplitsSettings Settings { get; set; }

protected int FrameCount { get; set; }
Expand Down Expand Up @@ -47,6 +45,7 @@ public class SplitComponent : IComponent

public IEnumerable<ColumnData> ColumnsList { get; set; }
public IList<SimpleLabel> LabelsList { get; set; }
protected List<(int exLength, float exWidth, float width)> ColumnWidths { get; }

public float VerticalHeight { get; set; }

Expand All @@ -60,17 +59,16 @@ public float HorizontalWidth

public IDictionary<string, Action> ContextMenuControls => null;

public SplitComponent(SplitsSettings settings, IEnumerable<ColumnData> columnsList)
public SplitComponent(SplitsSettings settings, IEnumerable<ColumnData> columnsList, List<(int exLength, float exWidth, float width)> columnWidths)
{
NameLabel = new SimpleLabel()
{
HorizontalAlignment = StringAlignment.Near,
X = 8,
};
MeasureTimeLabel = new SimpleLabel();
MeasureDeltaLabel = new SimpleLabel();
Settings = settings;
ColumnsList = columnsList;
ColumnWidths = columnWidths;
TimeFormatter = new SplitTimeFormatter(Settings.SplitTimesAccuracy);
DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals);
MinimumHeight = 25;
Expand Down Expand Up @@ -99,17 +97,6 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he
), 0, 0, width, height);
}

MeasureTimeLabel.Text = TimeFormatter.Format(new TimeSpan(24, 0, 0));
MeasureDeltaLabel.Text = DeltaTimeFormatter.Format(new TimeSpan(0, 9, 0, 0));

MeasureTimeLabel.Font = state.LayoutSettings.TimesFont;
MeasureTimeLabel.IsMonospaced = true;
MeasureDeltaLabel.Font = state.LayoutSettings.TimesFont;
MeasureDeltaLabel.IsMonospaced = true;

MeasureTimeLabel.SetActualWidth(g);
MeasureDeltaLabel.SetActualWidth(g);

NameLabel.ShadowColor = state.LayoutSettings.ShadowsColor;
NameLabel.OutlineColor = state.LayoutSettings.TextOutlineColor;
foreach (SimpleLabel label in LabelsList)
Expand Down Expand Up @@ -229,25 +216,17 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he

if (ColumnsList.Count() == LabelsList.Count)
{
while (ColumnWidths.Count < LabelsList.Count)
{
ColumnWidths.Add((0, 0f, 0f));
}

float curX = width - 7;
float nameX = width - 7;
foreach (SimpleLabel label in LabelsList.Reverse())
{
ColumnData column = ColumnsList.ElementAt(LabelsList.IndexOf(label));

float labelWidth = 0f;
if (column.Type is ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime)
{
labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth);
}
else if (column.Type is ColumnType.Delta or ColumnType.SegmentDelta)
{
labelWidth = MeasureDeltaLabel.ActualWidth;
}
else
{
labelWidth = MeasureTimeLabel.ActualWidth;
}
int i = LabelsList.IndexOf(label);
float labelWidth = ColumnWidths[i].width;

label.Width = labelWidth + 20;
curX -= labelWidth + 5;
Expand All @@ -261,6 +240,10 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he
if (!string.IsNullOrEmpty(label.Text))
{
nameX = curX + labelWidth + 5 - label.ActualWidth;
if (ColumnWidths[i].exWidth < label.ActualWidth)
{
ColumnWidths[i] = (label.Text.Length, label.ActualWidth, labelWidth);
}
}
}

Expand Down Expand Up @@ -387,19 +370,24 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData
int splitIndex = state.Run.IndexOf(Split);
if (splitIndex < state.CurrentSplitIndex)
{
if (type is ColumnType.SplitTime or ColumnType.SegmentTime)
if (type is ColumnType.SplitTime or ColumnType.SegmentTime or ColumnType.CustomVariable)
{
label.ForeColor = Settings.OverrideTimesColor ? Settings.BeforeTimesColor : state.LayoutSettings.TextColor;

if (type == ColumnType.SplitTime)
{
label.Text = TimeFormatter.Format(Split.SplitTime[timingMethod]);
}
else //SegmentTime
else if (type == ColumnType.SegmentTime)
{
TimeSpan? segmentTime = LiveSplitStateHelper.GetPreviousSegmentTime(state, splitIndex, timingMethod);
label.Text = TimeFormatter.Format(segmentTime);
}
else if (type == ColumnType.CustomVariable)
{
Split.CustomVariableValues.TryGetValue(data.Name, out string text);
label.Text = text ?? "";
}
}

if (type is ColumnType.DeltaorSplitTime or ColumnType.Delta)
Expand Down Expand Up @@ -461,7 +449,7 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData
}
else
{
if (type is ColumnType.SplitTime or ColumnType.SegmentTime or ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime)
if (type is ColumnType.SplitTime or ColumnType.SegmentTime or ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime or ColumnType.CustomVariable)
{
if (Split == state.CurrentSplit)
{
Expand All @@ -476,7 +464,7 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData
{
label.Text = TimeFormatter.Format(Split.Comparisons[comparison][timingMethod]);
}
else //SegmentTime or SegmentTimeorSegmentDeltaTime
else if (type is ColumnType.SegmentTime or ColumnType.SegmentDeltaorSegmentTime)
{
TimeSpan previousTime = TimeSpan.Zero;
for (int index = splitIndex - 1; index >= 0; index--)
Expand All @@ -491,6 +479,17 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData

label.Text = TimeFormatter.Format(Split.Comparisons[comparison][timingMethod] - previousTime);
}
else if (type is ColumnType.CustomVariable)
{
if (splitIndex == state.CurrentSplitIndex)
{
label.Text = state.Run.Metadata.CustomVariableValue(data.Name) ?? "";
}
else if (splitIndex > state.CurrentSplitIndex)
{
label.Text = "";
}
}
}

//Live Delta
Expand All @@ -511,14 +510,9 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData

protected float CalculateLabelsWidth()
{
if (ColumnsList != null)
if (ColumnWidths != null)
{
int mixedCount = ColumnsList.Count(x => x.Type is ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime);
int deltaCount = ColumnsList.Count(x => x.Type is ColumnType.Delta or ColumnType.SegmentDelta);
int timeCount = ColumnsList.Count(x => x.Type is ColumnType.SplitTime or ColumnType.SegmentTime);
return (mixedCount * (Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth) + 5))
+ (deltaCount * (MeasureDeltaLabel.ActualWidth + 5))
+ (timeCount * (MeasureTimeLabel.ActualWidth + 5));
return ColumnWidths.Sum(e => e.width) + (5 * ColumnWidths.Count());
}

return 0f;
Expand Down Expand Up @@ -569,10 +563,15 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width,
Cache["IsActive"] = IsActive;
Cache["NameColor"] = NameLabel.ForeColor.ToArgb();
Cache["ColumnsCount"] = ColumnsList.Count();
foreach (SimpleLabel label in LabelsList)
for (int index = 0; index < LabelsList.Count; index++)
{
Cache["Columns" + LabelsList.IndexOf(label) + "Text"] = label.Text;
Cache["Columns" + LabelsList.IndexOf(label) + "Color"] = label.ForeColor.ToArgb();
SimpleLabel label = LabelsList[index];
Cache["Columns" + index + "Text"] = label.Text;
Cache["Columns" + index + "Color"] = label.ForeColor.ToArgb();
if (index < ColumnWidths.Count)
{
Cache["Columns" + index + "Width"] = ColumnWidths[index].width;
}
}

if (invalidator != null && (Cache.HasChanged || FrameCount > 1))
Expand Down
Loading