Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColumnType: CustomVariable #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
36 changes: 33 additions & 3 deletions src/LiveSplit.Splits/UI/Components/SplitComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class SplitComponent : IComponent
public IEnumerable<ColumnData> ColumnsList { get; set; }
public IList<SimpleLabel> LabelsList { get; set; }

protected IList<Dictionary<string, string>> CustomVariableValues { get; }

public float VerticalHeight { get; set; }

public float MinimumWidth
Expand All @@ -60,7 +62,7 @@ public float HorizontalWidth

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

public SplitComponent(SplitsSettings settings, IEnumerable<ColumnData> columnsList)
public SplitComponent(SplitsSettings settings, IEnumerable<ColumnData> columnsList, IList<Dictionary<string, string>> customVariableValues)
{
NameLabel = new SimpleLabel()
{
Expand All @@ -71,6 +73,7 @@ public SplitComponent(SplitsSettings settings, IEnumerable<ColumnData> columnsLi
MeasureDeltaLabel = new SimpleLabel();
Settings = settings;
ColumnsList = columnsList;
CustomVariableValues = customVariableValues;
TimeFormatter = new SplitTimeFormatter(Settings.SplitTimesAccuracy);
DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals);
MinimumHeight = 25;
Expand Down Expand Up @@ -458,10 +461,25 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData
label.Text = DeltaTimeFormatter.Format(segmentDelta);
}
}

else if (type is ColumnType.CustomVariable)
{
// if the split was skipped, wipe the custom variable column entry for the split
if (Split.SplitTime[timingMethod] == null)
{
label.Text = "";
CustomVariableValues[splitIndex].Clear();
}
else
{
CustomVariableValues[splitIndex].TryGetValue(data.Name, out string text);
label.Text = text ?? "";
}
}
}
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 +494,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 Down Expand Up @@ -506,6 +524,18 @@ protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData
{
label.Text = "";
}
else if (type is ColumnType.CustomVariable)
{
if (Split == state.CurrentSplit)
{
CustomVariableValues[splitIndex].TryGetValue(data.Name, out string text);
label.Text = text ?? "";
}
else
{
label.Text = "";
}
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/LiveSplit.Splits/UI/Components/SplitsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Forms;

using LiveSplit.Model;
using LiveSplit.TimeFormatters;

namespace LiveSplit.UI.Components;

Expand All @@ -20,6 +21,7 @@ public class SplitsComponent : IComponent

protected IList<IComponent> Components { get; set; }
protected IList<SplitComponent> SplitComponents { get; set; }
protected IList<Dictionary<string, string>> CustomVariableValues { get; }

protected SplitsSettings Settings { get; set; }

Expand Down Expand Up @@ -56,6 +58,7 @@ public SplitsComponent(LiveSplitState state)
{
CurrentState = state;
Settings = new SplitsSettings(state);
CustomVariableValues = [];
InternalComponent = new ComponentRendererComponent();
ShadowImages = [];
visualSplitCount = Settings.VisualSplitCount;
Expand Down Expand Up @@ -113,7 +116,7 @@ private void RebuildVisualSplits()
}
}

var splitComponent = new SplitComponent(Settings, ColumnsList);
var splitComponent = new SplitComponent(Settings, ColumnsList, CustomVariableValues);
Components.Add(splitComponent);
if (i < visualSplitCount - 1 || i == (Settings.LockLastSplit ? totalSplits - 1 : visualSplitCount - 1))
{
Expand Down Expand Up @@ -338,6 +341,22 @@ public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document)

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
if (state.CurrentPhase is TimerPhase.Running or TimerPhase.Paused)
{
while (CustomVariableValues.Count <= state.CurrentSplitIndex)
{
CustomVariableValues.Add([]);
}

foreach (ColumnData column in ColumnsList)
{
if (column.Type is ColumnType.CustomVariable)
{
CustomVariableValues[state.CurrentSplitIndex][column.Name] = state.Run.Metadata.CustomVariableValue(column.Name) ?? TimeFormatConstants.DASH;
}
}
}

int skipCount = Math.Min(
Math.Max(
0,
Expand Down