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

Support displaying a Custom Variable #10

Open
wants to merge 1 commit 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
10 changes: 7 additions & 3 deletions src/LiveSplit.Text/UI/Components/TextComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Forms;

using LiveSplit.Model;
using LiveSplit.TimeFormatters;

namespace LiveSplit.UI.Components;

Expand Down Expand Up @@ -119,11 +120,14 @@ public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document)

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
string text2Value = Settings.CustomVariable
? (state.Run.Metadata.CustomVariableValue(Settings.Text2) ?? TimeFormatConstants.DASH)
: Settings.Text2;
InternalComponent.InformationName = Settings.Text1;
InternalComponent.InformationValue = Settings.Text2;
InternalComponent.LongestString = Settings.Text1.Length > Settings.Text2.Length
InternalComponent.InformationValue = text2Value;
InternalComponent.LongestString = Settings.Text1.Length > text2Value.Length
? Settings.Text1
: Settings.Text2;
: text2Value;

InternalComponent.Update(invalidator, state, width, height, mode);
}
Expand Down
27 changes: 22 additions & 5 deletions src/LiveSplit.Text/UI/Components/TextComponentSettings.Designer.cs

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

13 changes: 12 additions & 1 deletion src/LiveSplit.Text/UI/Components/TextComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public string GradientString

public LayoutMode Mode { get; set; }
public bool Display2Rows { get; set; }
public bool CustomVariable { get; set; }

public LiveSplitState CurrentState { get; set; }

Expand All @@ -56,6 +57,8 @@ public TextComponentSettings()
Font1 = new Font("Segoe UI", 16, FontStyle.Regular, GraphicsUnit.Pixel);
Font2 = new Font("Segoe UI", 16, FontStyle.Regular, GraphicsUnit.Pixel);

chkCustomVariable.DataBindings.Add("Checked", this, "CustomVariable", false, DataSourceUpdateMode.OnPropertyChanged);

chkOverrideTextColor.DataBindings.Add("Checked", this, "OverrideTextColor", false, DataSourceUpdateMode.OnPropertyChanged);
btnTextColor.DataBindings.Add("BackColor", this, "TextColor", false, DataSourceUpdateMode.OnPropertyChanged);
chkOverrideTimeColor.DataBindings.Add("Checked", this, "OverrideTimeColor", false, DataSourceUpdateMode.OnPropertyChanged);
Expand Down Expand Up @@ -95,6 +98,7 @@ private void chkOverrideTextColor_CheckedChanged(object sender, EventArgs e)

private void TextComponentSettings_Load(object sender, EventArgs e)
{
chkCustomVariable_CheckedChanged(null, null);
chkOverrideTextColor_CheckedChanged(null, null);
chkOverrideTimeColor_CheckedChanged(null, null);
chkFont_CheckedChanged(null, null);
Expand All @@ -113,6 +117,11 @@ private void TextComponentSettings_Load(object sender, EventArgs e)
}
}

private void chkCustomVariable_CheckedChanged(object sender, EventArgs e)
{
CustomVariable = chkCustomVariable.Checked;
}

private void cmbGradientType_SelectedIndexChanged(object sender, EventArgs e)
{
btnColor1.Visible = cmbGradientType.SelectedItem.ToString() != "Plain";
Expand All @@ -138,6 +147,7 @@ public void SetSettings(XmlNode node)
OverrideFont1 = SettingsHelper.ParseBool(element["OverrideFont1"]);
OverrideFont2 = SettingsHelper.ParseBool(element["OverrideFont2"]);
Display2Rows = SettingsHelper.ParseBool(element["Display2Rows"], false);
CustomVariable = SettingsHelper.ParseBool(element["CustomVariable"], false);
}

public XmlNode GetSettings(XmlDocument document)
Expand Down Expand Up @@ -168,7 +178,8 @@ private int CreateSettingsNode(XmlDocument document, XmlElement parent)
SettingsHelper.CreateSetting(document, parent, "Font2", Font2) ^
SettingsHelper.CreateSetting(document, parent, "OverrideFont1", OverrideFont1) ^
SettingsHelper.CreateSetting(document, parent, "OverrideFont2", OverrideFont2) ^
SettingsHelper.CreateSetting(document, parent, "Display2Rows", Display2Rows);
SettingsHelper.CreateSetting(document, parent, "Display2Rows", Display2Rows) ^
SettingsHelper.CreateSetting(document, parent, "CustomVariable", CustomVariable);
}

private void ColorButtonClick(object sender, EventArgs e)
Expand Down