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.Subsplits/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
}

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.Subsplits/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.Subsplits/UI/Components/LabelsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
using System.Windows.Forms;

using LiveSplit.Model;
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 @@ -44,19 +34,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 @@ -68,30 +54,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 @@ -104,24 +66,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 @@ -203,9 +156,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
Loading