-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTimerSettings.cs
More file actions
248 lines (219 loc) · 10.8 KB
/
TimerSettings.cs
File metadata and controls
248 lines (219 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using LiveSplit.TimeFormatters;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
namespace LiveSplit.UI.Components
{
public partial class TimerSettings : UserControl
{
public float TimerHeight { get; set; }
public float TimerWidth { get; set; }
public float DecimalsSize { get; set; }
private string timerFormat
{
get
{
return DigitsFormat + Accuracy;
}
set
{
var decimalIndex = value.IndexOf('.');
if (decimalIndex < 0)
{
DigitsFormat = value;
Accuracy = "";
}
else
{
DigitsFormat = value.Substring(0, decimalIndex);
Accuracy = value.Substring(decimalIndex);
}
}
}
public string DigitsFormat { get; set; }
public string Accuracy { get; set; }
public LayoutMode Mode { get; set; }
public Color TimerColor { get; set; }
public bool OverrideSplitColors { get; set; }
public bool CenterTimer { get; set; }
public bool AlignLeft { get; set; }
public bool ShowGradient { get; set; }
public string TimingMethod { get; set; }
public Color BackgroundColor { get; set; }
public Color BackgroundColor2 { get; set; }
public DeltasGradientType BackgroundGradient { get; set; }
public string GradientString
{
get { return GetBackgroundTypeString(BackgroundGradient); }
set { BackgroundGradient = (DeltasGradientType)Enum.Parse(typeof(DeltasGradientType), value.Replace(" ", "")); }
}
public TimerSettings()
{
InitializeComponent();
TimerWidth = 225;
TimerHeight = 50;
DigitsFormat = "1";
Accuracy = ".23";
TimerColor = Color.FromArgb(170, 170, 170);
OverrideSplitColors = false;
ShowGradient = true;
BackgroundColor = Color.Transparent;
BackgroundColor2 = Color.Transparent;
BackgroundGradient = DeltasGradientType.Plain;
CenterTimer = false;
TimingMethod = "Current Timing Method";
DecimalsSize = 35f;
btnTimerColor.DataBindings.Add("BackColor", this, "TimerColor", false, DataSourceUpdateMode.OnPropertyChanged);
chkOverrideTimerColors.DataBindings.Add("Checked", this, "OverrideSplitColors", false, DataSourceUpdateMode.OnPropertyChanged);
chkGradient.DataBindings.Add("Checked", this, "ShowGradient", false, DataSourceUpdateMode.OnPropertyChanged);
cmbGradientType.DataBindings.Add("SelectedItem", this, "GradientString", false, DataSourceUpdateMode.OnPropertyChanged);
btnColor1.DataBindings.Add("BackColor", this, "BackgroundColor", false, DataSourceUpdateMode.OnPropertyChanged);
btnColor2.DataBindings.Add("BackColor", this, "BackgroundColor2", false, DataSourceUpdateMode.OnPropertyChanged);
chkCenterTimer.DataBindings.Add("Checked", this, "CenterTimer", false, DataSourceUpdateMode.OnPropertyChanged);
chkAlignTimerLeft.DataBindings.Add("Checked", this, "AlignLeft", false, DataSourceUpdateMode.OnPropertyChanged);
cmbTimingMethod.DataBindings.Add("SelectedItem", this, "TimingMethod", false, DataSourceUpdateMode.OnPropertyChanged);
trkDecimalsSize.DataBindings.Add("Value", this, "DecimalsSize", false, DataSourceUpdateMode.OnPropertyChanged);
cmbDigitsFormat.DataBindings.Add("SelectedItem", this, "DigitsFormat", false, DataSourceUpdateMode.OnPropertyChanged);
cmbAccuracy.DataBindings.Add("SelectedItem", this, "Accuracy", false, DataSourceUpdateMode.OnPropertyChanged);
}
void cmbTimerFormat_SelectedIndexChanged(object sender, EventArgs e)
{
DigitsFormat = cmbDigitsFormat.SelectedItem.ToString();
}
private void cmbAccuracy_SelectedIndexChanged(object sender, EventArgs e)
{
Accuracy = cmbAccuracy.SelectedItem.ToString();
}
void cmbTimingMethod_SelectedIndexChanged(object sender, EventArgs e)
{
TimingMethod = cmbTimingMethod.SelectedItem.ToString();
}
void chkOverrideTimerColors_CheckedChanged(object sender, EventArgs e)
{
label1.Enabled = btnTimerColor.Enabled = chkOverrideTimerColors.Checked;
}
void cmbGradientType_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedText = cmbGradientType.SelectedItem.ToString();
btnColor1.Visible = selectedText != "Plain" && !selectedText.Contains("Delta");
btnColor2.Visible = !selectedText.Contains("Delta");
btnColor2.DataBindings.Clear();
btnColor2.DataBindings.Add("BackColor", this, btnColor1.Visible ? "BackgroundColor2" : "BackgroundColor", false, DataSourceUpdateMode.OnPropertyChanged);
GradientString = cmbGradientType.SelectedItem.ToString();
}
public static string GetBackgroundTypeString(DeltasGradientType type)
{
switch (type)
{
case DeltasGradientType.Horizontal:
return "Horizontal Gradient";
case DeltasGradientType.HorizontalWithDeltaColor:
return "Horizontal With Delta Color";
case DeltasGradientType.PlainWithDeltaColor:
return "Plain With Delta Color";
case DeltasGradientType.Vertical:
return "Vertical";
case DeltasGradientType.VerticalWithDeltaColor:
return "Vertical With Delta Color";
case DeltasGradientType.Plain:
default:
return "Plain";
}
}
void TimerSettings_Load(object sender, EventArgs e)
{
chkOverrideTimerColors_CheckedChanged(null, null);
if (Mode == LayoutMode.Horizontal)
{
trkSize.DataBindings.Clear();
trkSize.Minimum = 50;
trkSize.Maximum = 500;
trkSize.DataBindings.Add("Value", this, "TimerWidth", false, DataSourceUpdateMode.OnPropertyChanged);
lblSize.Text = "Width:";
}
else
{
trkSize.DataBindings.Clear();
trkSize.Minimum = 20;
trkSize.Maximum = 150;
trkSize.DataBindings.Add("Value", this, "TimerHeight", false, DataSourceUpdateMode.OnPropertyChanged);
lblSize.Text = "Height:";
}
}
public void SetSettings(XmlNode node)
{
var element = (XmlElement)node;
Version version = SettingsHelper.ParseVersion(element["Version"]);
TimerHeight = SettingsHelper.ParseFloat(element["TimerHeight"]);
TimerWidth = SettingsHelper.ParseFloat(element["TimerWidth"]);
ShowGradient = SettingsHelper.ParseBool(element["ShowGradient"], true);
TimerColor = SettingsHelper.ParseColor(element["TimerColor"], Color.FromArgb(170, 170, 170));
DecimalsSize = SettingsHelper.ParseFloat(element["DecimalsSize"], 35f);
BackgroundColor = SettingsHelper.ParseColor(element["BackgroundColor"], Color.Transparent);
BackgroundColor2 = SettingsHelper.ParseColor(element["BackgroundColor2"], Color.Transparent);
GradientString = SettingsHelper.ParseString(element["BackgroundGradient"], DeltasGradientType.Plain.ToString());
CenterTimer = SettingsHelper.ParseBool(element["CenterTimer"], false);
AlignLeft = SettingsHelper.ParseBool(element["AlignLeft"], false);
TimingMethod = SettingsHelper.ParseString(element["TimingMethod"], "Current Timing Method");
if (version >= new Version(1, 3))
OverrideSplitColors = SettingsHelper.ParseBool(element["OverrideSplitColors"]);
else
OverrideSplitColors = !SettingsHelper.ParseBool(element["UseSplitColors"], true);
if (version >= new Version(1, 2))
{
if (version >= new Version(1, 5))
{
timerFormat = SettingsHelper.ParseString(element["TimerFormat"]);
}
else
{
var accuracy = SettingsHelper.ParseEnum<TimeAccuracy>(element["TimerAccuracy"]);
DigitsFormat = "1";
if (accuracy == TimeAccuracy.Hundredths)
Accuracy = ".23";
else if (accuracy == TimeAccuracy.Tenths)
Accuracy = ".2";
else
Accuracy = "";
}
}
else
{
DigitsFormat = "1";
Accuracy = ".23";
}
}
public XmlNode GetSettings(XmlDocument document)
{
var parent = document.CreateElement("Settings");
CreateSettingsNode(document, parent);
return parent;
}
public int GetSettingsHashCode()
{
return CreateSettingsNode(null, null);
}
private int CreateSettingsNode(XmlDocument document, XmlElement parent)
{
return SettingsHelper.CreateSetting(document, parent, "Version", "1.5") ^
SettingsHelper.CreateSetting(document, parent, "TimerHeight", TimerHeight) ^
SettingsHelper.CreateSetting(document, parent, "TimerWidth", TimerWidth) ^
SettingsHelper.CreateSetting(document, parent, "TimerFormat", timerFormat) ^
SettingsHelper.CreateSetting(document, parent, "OverrideSplitColors", OverrideSplitColors) ^
SettingsHelper.CreateSetting(document, parent, "ShowGradient", ShowGradient) ^
SettingsHelper.CreateSetting(document, parent, "TimerColor", TimerColor) ^
SettingsHelper.CreateSetting(document, parent, "BackgroundColor", BackgroundColor) ^
SettingsHelper.CreateSetting(document, parent, "BackgroundColor2", BackgroundColor2) ^
SettingsHelper.CreateSetting(document, parent, "BackgroundGradient", BackgroundGradient) ^
SettingsHelper.CreateSetting(document, parent, "CenterTimer", CenterTimer) ^
SettingsHelper.CreateSetting(document, parent, "AlignLeft", AlignLeft) ^
SettingsHelper.CreateSetting(document, parent, "TimingMethod", TimingMethod) ^
SettingsHelper.CreateSetting(document, parent, "DecimalsSize", DecimalsSize);
}
private void ColorButtonClick(object sender, EventArgs e)
{
SettingsHelper.ColorButtonClick((Button)sender, this);
}
}
}