-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlWindow.xaml.cs
219 lines (179 loc) · 6.23 KB
/
ControlWindow.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.Windows.Threading;
namespace ScheduleRevealTool
{
/// <summary>
/// Interaction logic for ControlWindow.xaml
/// </summary>
public partial class ControlWindow : Window
{
private readonly MainWindow mainWindow;
private readonly DispatcherTimer timer = new DispatcherTimer();
public ControlWindow(MainWindow mainWindow)
{
InitializeComponent();
this.mainWindow = mainWindow;
timer.Tick += Timer_Tick;
}
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
}
public ObservableCollection<Run> RunCollection { get; set; } = new ObservableCollection<Run>();
private void LoadSchedule_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog
{
Filter = "Tab Seperated Values|*.tsv"
};
bool? res = dialog.ShowDialog();
if (res != true)
return;
mainWindow.Clear();
RunCollection.Clear();
IEnumerable<string> lines = File.ReadAllLines(dialog.FileName);
// Skip Header Line
lines = lines.Skip(1);
foreach (string line in lines)
{
string[] elements = line.Split('\t');
if (elements.Length != 7)
{
MessageBox.Show("Invalid data line in run tsv.");
RunCollection.Clear();
return;
}
Run run = new Run()
{
Time = elements[0].Trim(),
Runners = elements[1].Trim(),
Game = elements[2].Trim(),
Category = elements[3].Trim(),
Estimate = elements[5].Trim(),
Platform = elements[6].Trim(),
Presented = false
};
if (elements[4].Trim() != "")
run.Category += " (" + elements[4].Trim() + ")";
if (run.Game == "")
continue;
RunCollection.Add(run);
Console.WriteLine(run.Game);
}
}
private void PresentNextRun_Click(object sender, RoutedEventArgs e)
{
if (timer.IsEnabled)
{
timer.Stop();
timer.Start();
}
RevealNextRun();
}
private void PreviewIntegerEnforce(object sender, TextCompositionEventArgs e)
{
TextBox tb = (TextBox)sender;
e.Handled = !int.TryParse(tb.Text + e.Text, out int _);
}
private void PreviewDoubleEnforce(object sender, TextCompositionEventArgs e)
{
TextBox tb = (TextBox)sender;
e.Handled = !double.TryParse(tb.Text + e.Text, out double _);
}
private void TimerInputText_TextChanged(object sender, TextChangedEventArgs e)
{
if (TimerStatusLabel == null)
return;
string txt = TimerInputText.Text;
if (txt == "" || txt == "0" || !int.TryParse(txt, out int interval))
{
timer.Stop();
TimerStatusLabel.Content = "Stopped";
}
else
{
TimerStatusLabel.Content = "Running every " + interval + "s";
timer.Stop();
timer.Interval = TimeSpan.FromSeconds(interval);
timer.Start();
}
}
private double SpeedMul { get; set; } = 1.0;
private void SpeedInputText_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(SpeedInputText.Text, out double speed))
SpeedMul = 1.0 / speed;
else
SpeedMul = 1.0;
// Safety, someone puts in 100, and it will take forever to be ready again.
if (SpeedMul > 2.0)
SpeedMul = 2.0;
}
private void Timer_Tick(object sender, EventArgs e)
{
RevealNextRun();
}
private void RevealNextRun()
{
foreach (Run run in RunCollection)
{
if (!run.Presented)
{
if (mainWindow.RevealNextRun(run, SpeedMul))
run.Presented = true;
return;
}
}
mainWindow.RevealNextRun(null, SpeedMul);
TimerStatusLabel.Content = "Finished";
timer.Stop();
}
private void OmnibarTextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
e.Handled = true;
mainWindow.UpdateOmniBar(OmnibarTextBox.Text);
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Really Exit?", "Exit?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
Application.Current.Shutdown();
}
private void ScrollOverList_Click(object sender, RoutedEventArgs e)
{
if (!double.TryParse(ScrollDurationText.Text, out double duration))
duration = 120.0;
mainWindow.ScrollOverList(duration, 5.0);
}
private void StopTimer_Click(object sender, RoutedEventArgs e)
{
timer.Stop();
TimerStatusLabel.Content = "Stopped";
}
private void StartCountdown_Click(object sender, RoutedEventArgs e)
{
double v = 0.0;
if (CountdownTimerText.Text != "")
v = double.Parse(CountdownTimerText.Text);
mainWindow.SetCountdown(v);
}
}
}