-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cs
More file actions
404 lines (365 loc) · 21.7 KB
/
Settings.cs
File metadata and controls
404 lines (365 loc) · 21.7 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
using Microsoft.CSharp.RuntimeBinder;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design;
namespace StreamStartingTimer {
static class Defaults {
public const string VNyanURL = "ws://localhost:8000/vnyan";
public const string MixItUpURL = "http://localhost:8911/api/v2";
public const ContentAlignment Alignment = ContentAlignment.TopLeft;
public const MIUPlatforms MixItUpPlatform = MIUPlatforms.Twitch;
public static readonly Color FGCol = Color.Black;
public static readonly Color BGCol = Color.Lime;
public static readonly Font Font = new Font("Arial", 128);
public const bool ShowLeadingZero = true;
public static readonly TimeSpan TestTime = TimeSpan.FromMinutes(5);
public static readonly Size Dimensions = new Size(600, 300);
public static readonly Point Location = new Point((Screen.PrimaryScreen.Bounds.Size.Width - Dimensions.Width) / 2 + Screen.PrimaryScreen.Bounds.X ,
(Screen.PrimaryScreen.Bounds.Size.Height - Dimensions.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
public const bool SpoutEnabled = false;
public const string SpoutName = "StreamStartingTimer";
public static readonly string FontDir = Application.StartupPath + "\\DefaultFont";
public const int ProgressGreen = 300;
public const int ProgressYellow = 60;
public const int ProgressRed = 30;
public const bool VNyanEnabled = true;
public const bool MixItUpEnabled = true;
public const bool DoubleFrames = false;
}
public class Settings {
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Clock font")]
public virtual Font Font { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Clock font colour")]
[DisplayName("Foreground colour")]
public virtual Color FGCol { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Please remember to greenscreen this in OBS using a Chroma Key filter\r\nYou can type a custom colour using the form: 42,0,69")]
[DisplayName("Background colour")]
public virtual Color BGCol { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Please set this to match your \"Positional Alignment\" setting in the OBS transform")]
[DisplayName("Text alignment")]
public virtual ContentAlignment Alignment { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Display 04:20 or 4:20 (does not take effect until restarting the timer)")]
[DisplayName("Show Leading Zero")]
public virtual bool ShowLeadingZero { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Progress bar starts counting up when this many seconds are left")]
[DisplayName("Progress bar green time")]
public virtual int ProgressGreen { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Progress bar changes to yellow when this many seconds are left")]
[DisplayName("Progress bar yellow time")]
public virtual int ProgressYellow { get; set; }
[CategoryAttribute("Clock Appearance"), DescriptionAttribute("Progress bar changes to red when this many seconds are left")]
[DisplayName("Progress bar red time")]
public virtual int ProgressRed { get; set; }
[Browsable(false)]
public virtual Point Location { get; set; }
[Browsable(false)]
public virtual Size Dimensions { get; set; }
[DisplayName("Default MIU platform")]
[CategoryAttribute("Settings"), DescriptionAttribute("Set to your primary streaming platform. Can be overridden per-event if necessary")]
public virtual MIUPlatforms MixItUpPlatform { get; set; }
[DisplayName("Default time")]
[CategoryAttribute("Settings"), DescriptionAttribute("When the timer is reset, what do we reset to?\r\nAlso used if the app is launched without specifying a time on the commandline")]
public TimeSpan TestTime { get; set; }
[DisplayName("VNyan Enabled")]
[CategoryAttribute("Settings"), DescriptionAttribute("Enable if you are using VNyan and wish to trigger websocket nodes")]
public virtual bool VNyanEnabled { get; set; }
[DisplayName("MixItUp Enabled")]
[CategoryAttribute("Settings"), DescriptionAttribute("Enable if you are using MixItUp and wish to trigger commands via the developer API")]
public virtual bool MixItUpEnabled { get; set; }
[DisplayName("VNyan URL")]
[CategoryAttribute("Settings"), DescriptionAttribute("The URL of VNyan's websocket API")]
public virtual string VNyanURL { get; set; }
[CategoryAttribute("Settings"), DescriptionAttribute("The URL of MixItUp's HTTP API\r\nPlease remember to enable this in MIU: Settings -> Developer API -> Connect")]
[DisplayName("MixItUp URL")]
public virtual string MixItUpURL { get; set; }
[CategoryAttribute("Spout Image Font"), DescriptionAttribute("Enable output of image fonts via Spout2. Requires obs-spout to capture this")]
[DisplayName("Enable Spout2 output")]
public virtual bool SpoutEnabled { get; set; }
[CategoryAttribute("Spout Image Font"), DescriptionAttribute("Will be show in in OBS Spout2 source selector")]
[DisplayName("Spout2 sender name")]
public virtual string SpoutName { get; set; }
[CategoryAttribute("Spout Image Font"), DescriptionAttribute("Folder with a series of images named 0.png - 9.png, colon.png and space.png. All must be the same height and width (colon.png may have a different width). Once the timer has been started the application must be restarted to change this")]
[DisplayName("Font directory")]
[EditorAttribute(typeof(FolderNameEditor), typeof(UITypeEditor))]
public virtual string FontDir { get; set; }
[CategoryAttribute("Spout Image Font"), DescriptionAttribute("OBS-Spout sometimes captures one frame behind. This normally isn't noticible but at this app runs at 1FPS it is! This settings sends every frame twice as a workaround")]
[DisplayName("OBS-Spout fix")]
public virtual bool DoubleFrames { get; set; }
[CategoryAttribute("Spout Image Font"), DescriptionAttribute("Show memory writes in real-time (this setting is not saved)")]
public virtual bool Debug { get; set; }
private void Init() {
Font = Defaults.Font;
BGCol = Defaults.BGCol;
FGCol = Defaults.FGCol;
Alignment = Defaults.Alignment;
ShowLeadingZero = Defaults.ShowLeadingZero;
VNyanURL = Defaults.VNyanURL;
MixItUpURL = Defaults.MixItUpURL;
MixItUpPlatform = Defaults.MixItUpPlatform;
TestTime = Defaults.TestTime;
Location = Defaults.Location;
Dimensions = Defaults.Dimensions;
SpoutEnabled = Defaults.SpoutEnabled;
SpoutName = Defaults.SpoutName;
FontDir = Defaults.FontDir;
ProgressGreen = Defaults.ProgressGreen;
ProgressYellow = Defaults.ProgressYellow;
ProgressRed = Defaults.ProgressRed;
DoubleFrames = Defaults.DoubleFrames;
Debug = false;
}
public Settings() {
Init();
}
public string GetDisplayName(string Setting) {
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this);
foreach (PropertyDescriptor property in properties) {
if (property.Name == Setting) {
return property.DisplayName; // Something To Name
}
}
return Setting;
}
public void LoadConfig(string ConfigFile) {
if (File.Exists(ConfigFile)) {
string MissingSettings = "";
dynamic Config = JsonConvert.DeserializeObject<dynamic>(File.ReadAllText(ConfigFile));
try {
if ((int)Config.X < SystemInformation.VirtualScreen.Width - 5 && // Safety in case monitor
(int)Config.Y < SystemInformation.VirtualScreen.Height - 5) { // size has changed
Location = new Point((int)Config.X, (int)Config.Y);
}
} catch (RuntimeBinderException) { }
try { Dimensions = new Size((int)Config.Width, (int)Config.Height); } catch { MissingSettings += ", " + GetDisplayName("Dimensions"); Dimensions = Defaults.Dimensions; }
try { BGCol = ColorTranslator.FromHtml((string)Config.BackgroundColor); if (BGCol == Color.Empty) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("BGCol"); BGCol = Defaults.BGCol; }
try { FGCol = ColorTranslator.FromHtml((string)Config.ForegroundColor); if (FGCol == Color.Empty) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("FGCol"); FGCol = Defaults.FGCol; }
try { Alignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), (string)Config.Alignment); } catch { MissingSettings += ", " + GetDisplayName("Alignment"); Alignment = Defaults.Alignment; }
try { Font = new Font((string)Config.FontName, (int)Config.FontSize, (FontStyle)Config.FontStyle); } catch { MissingSettings += ", " + GetDisplayName("Font"); Font = Defaults.Font; }
try { ShowLeadingZero = Config.ShowLeadingZero; } catch { MissingSettings += ", " + GetDisplayName("ShowLeadingZero"); ShowLeadingZero = Defaults.ShowLeadingZero; }
try { VNyanEnabled = Config.VNyanEnabled; } catch { MissingSettings += ", " + GetDisplayName("VNyanEnabled"); VNyanEnabled = Defaults.VNyanEnabled; }
try { MixItUpEnabled = Config.MixItUpEnabled; } catch { MissingSettings += ", " + GetDisplayName("MixItUpEnabled"); MixItUpEnabled = Defaults.MixItUpEnabled; }
try { VNyanURL = Config.VNyanURL; if (VNyanURL == null) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("VNyanURL"); VNyanURL = Defaults.VNyanURL; }
try { MixItUpURL = Config.MixItUpURL; if (MixItUpURL == null) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("MixItUpURL"); MixItUpURL = Defaults.MixItUpURL; }
try { MixItUpPlatform = (MIUPlatforms)Enum.Parse(typeof(MIUPlatforms), (string)Config.MixItUpPlatform); } catch { MissingSettings += ", " + GetDisplayName("MixItUpPlatform"); MixItUpPlatform = Defaults.MixItUpPlatform; }
try { TestTime = TimeSpan.FromSeconds((int)Config.TestTime); } catch { MissingSettings += ", " + GetDisplayName("TestTime"); TestTime = Defaults.TestTime; }
try { SpoutEnabled = Config.SpoutEnabled; } catch { MissingSettings += ", " + GetDisplayName("SpoutEnabled"); SpoutEnabled = Defaults.SpoutEnabled; }
try { SpoutName = Config.SpoutName; if (SpoutName == null) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("SpoutName"); SpoutName = Defaults.SpoutName; }
try { FontDir = Config.FontDir; if (FontDir == null) { throw new Exception("null"); } } catch { MissingSettings += ", " + GetDisplayName("FontDir"); FontDir = Defaults.FontDir; }
try { DoubleFrames = Config.SpoutEnabled; } catch { MissingSettings += ", " + GetDisplayName("DoubleFrames"); DoubleFrames = Defaults.DoubleFrames; }
try { ProgressYellow = Config.ProgressGreen; } catch { MissingSettings += ", " + GetDisplayName("ProgressGreen"); ProgressGreen = Defaults.ProgressGreen; }
try { ProgressYellow = Config.ProgressYellow; } catch { MissingSettings += ", " + GetDisplayName("ProgressYellow"); ProgressYellow = Defaults.ProgressYellow; }
try { ProgressRed = Config.ProgressRed; } catch { MissingSettings += ", " + GetDisplayName("ProgressRed"); ProgressRed = Defaults.ProgressRed; }
if (MissingSettings.Length > 0) {
Task.Run(() => {
Shared.AutoClosingMessageBox.Show("The following settings are either new or corrupt and have been reset to defaults:\r\n" + MissingSettings.Substring(2) +
"\r\nPlease go to the config screen, check these settings and save a new config file:\r\n" + ConfigFile, "Error loading settings", 60000);
});
}
}
}
public void SaveConfig(string ConfigFile, Point Location, Size Dimensions) {
JObject Config = new JObject(
new JProperty("FontName", Font.Name),
new JProperty("FontSize", Font.Size),
new JProperty("FontStyle", Font.Style.ToString()),
new JProperty("BackgroundColor", ColorTranslator.ToHtml(BGCol)),
new JProperty("ForegroundColor", ColorTranslator.ToHtml(FGCol)),
new JProperty("Alignment", Alignment.ToString()),
new JProperty("X", Location.X),
new JProperty("Y", Location.Y),
new JProperty("Width", Dimensions.Width),
new JProperty("Height", Dimensions.Height),
new JProperty("ShowLeadingZero", ShowLeadingZero),
new JProperty("VNyanEnabled", VNyanEnabled),
new JProperty("MixItUpEnabled", MixItUpEnabled),
new JProperty("VNyanURL", VNyanURL),
new JProperty("MixItUpURL", MixItUpURL),
new JProperty("MixItUpPlatform", MixItUpPlatform.ToString()),
new JProperty("TestTime", (int)TestTime.TotalSeconds),
new JProperty("SpoutEnabled", SpoutEnabled),
new JProperty("SpoutName", SpoutName),
new JProperty("FontDir", FontDir),
new JProperty("ProgressGreen", ProgressGreen),
new JProperty("ProgressYellow", ProgressYellow),
new JProperty("ProgressRed", ProgressRed)
);
File.WriteAllText(ConfigFile, Config.ToString());
}
public Settings Clone() {
Settings TempSettings = new Settings();
TempSettings.Font = this.Font;
TempSettings.BGCol = this.BGCol;
TempSettings.FGCol = this.FGCol;
TempSettings.Alignment = this.Alignment;
TempSettings.ShowLeadingZero = this.ShowLeadingZero;
TempSettings.VNyanURL = this.VNyanURL;
TempSettings.MixItUpURL = this.MixItUpURL;
TempSettings.MixItUpPlatform = this.MixItUpPlatform;
TempSettings.TestTime = this.TestTime;
TempSettings.Location = this.Location;
TempSettings.Dimensions = this.Dimensions;
TempSettings.SpoutEnabled = this.SpoutEnabled;
TempSettings.FontDir = this.FontDir;
TempSettings.ProgressGreen = this.ProgressGreen;
TempSettings.ProgressYellow = this.ProgressYellow;
TempSettings.ProgressRed = this.ProgressRed;
TempSettings.DoubleFrames = this.DoubleFrames;
TempSettings.Debug = this.Debug;
return TempSettings;
}
}
public class CSettings : Settings, INotifyPropertyChanged {
private static Settings _Settings = new Settings();
public CSettings() {
//_Settings = new Settings();
}
public CSettings(string ConfigFile) {
_Settings.LoadConfig(ConfigFile);
}
public override bool VNyanEnabled {
get { return _Settings.VNyanEnabled; }
set {
if (_Settings.VNyanEnabled == value) return;
_Settings.VNyanEnabled = value;
RaisePropertyChanged("VNyanEnabled");
}
}
public override bool MixItUpEnabled {
get { return _Settings.MixItUpEnabled; }
set {
if (_Settings.MixItUpEnabled == value) return;
_Settings.MixItUpEnabled = value;
RaisePropertyChanged("MixItUpEnabled");
}
}
public override string VNyanURL {
get { return _Settings.VNyanURL; }
set {
if (_Settings.VNyanURL == value) return;
_Settings.VNyanURL = value;
RaisePropertyChanged("VNyanURL");
}
}
public override string MixItUpURL {
get { return _Settings.MixItUpURL; }
set {
if (_Settings.MixItUpURL == value) return;
_Settings.MixItUpURL = value;
RaisePropertyChanged("MixItUpURL");
}
}
public override Font Font {
get { return _Settings.Font; }
set {
if (_Settings.Font == value) return;
_Settings.Font = value;
RaisePropertyChanged("Font");
}
}
public override Color FGCol {
get { return _Settings.FGCol; }
set {
if (_Settings.FGCol == value) return;
_Settings.FGCol = value;
RaisePropertyChanged("FGCol");
}
}
public override Color BGCol {
get { return _Settings.BGCol; }
set {
if (_Settings.BGCol == value) return;
_Settings.BGCol = value;
RaisePropertyChanged("BGCol");
}
}
public override bool ShowLeadingZero {
get { return _Settings.ShowLeadingZero; }
set {
if (_Settings.ShowLeadingZero == value) return;
_Settings.ShowLeadingZero = value;
RaisePropertyChanged("BGCol");
}
}
public override ContentAlignment Alignment {
get { return _Settings.Alignment; }
set {
if (_Settings.Alignment == value) return;
_Settings.Alignment = value;
RaisePropertyChanged("Alignment");
}
}
public override Point Location {
get { return _Settings.Location; }
set {
if (_Settings.Location == value) return;
_Settings.Location = value;
RaisePropertyChanged("Location");
}
}
public override Size Dimensions {
get { return _Settings.Dimensions; }
set {
if (_Settings.Dimensions == value) return;
_Settings.Dimensions = value;
RaisePropertyChanged("Dimensions");
}
}
public override MIUPlatforms MixItUpPlatform {
get { return _Settings.MixItUpPlatform; }
set {
if (_Settings.MixItUpPlatform == value) return;
_Settings.MixItUpPlatform = value;
RaisePropertyChanged("MixItUpPlatform");
}
}
public override bool SpoutEnabled {
get { return _Settings.SpoutEnabled; }
set {
if (Shared.GetROStatus() && _Settings.SpoutEnabled != value) {
MessageBox.Show("Cannot change this setting while the timer is running", GetDisplayName("SpoutEnabled"), MessageBoxButtons.OK, MessageBoxIcon.Error);
} else {
_Settings.SpoutEnabled = value;
}
}
}
public override string SpoutName {
get { return _Settings.SpoutName; }
set {
if (Shared.GetROStatus() && _Settings.SpoutName != value) {
MessageBox.Show("This setting will not take effect until you restart the timer", GetDisplayName("SpoutName"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
_Settings.SpoutName = value;
}
}
public override string FontDir {
get { return _Settings.FontDir; }
set {
if (Shared.GetROStatus() && _Settings.FontDir != value) {
MessageBox.Show("This setting will not take effect until you restart the timer", GetDisplayName("FontDir"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
_Settings.FontDir = value;
}
}
public override int ProgressGreen {
get { return _Settings.ProgressGreen; }
set {
if (_Settings.ProgressGreen == value) { return; }
_Settings.ProgressGreen = value;
RaisePropertyChanged("ProgressGreen");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName) {
var handler = PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}