-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimulatorWindow.cs
More file actions
88 lines (71 loc) · 3.28 KB
/
Copy pathSimulatorWindow.cs
File metadata and controls
88 lines (71 loc) · 3.28 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
using System;
using System.Linq;
using System.Windows.Forms;
using vatsys;
namespace Simulator.Plugin
{
public partial class SimulatorWindow : BaseForm
{
/// <summary>
/// Refreshes the status lines. A WinForms timer, so it ticks on the UI thread and can touch the
/// label directly. Only runs while the window is open - there's nothing to show otherwise.
/// </summary>
private readonly Timer _statusTimer = new Timer { Interval = 1000 };
public SimulatorWindow()
{
InitializeComponent();
BackColor = Colours.GetColour(Colours.Identities.WindowBackground);
ForeColor = Colours.GetColour(Colours.Identities.InteractiveText);
_statusTimer.Tick += (s, e) => ShowStatus();
FormClosed += (s, e) => _statusTimer.Stop();
}
/// <summary>
/// Says plainly what the plugin is doing, because every way it can do nothing looks identical from
/// the outside. Not selecting a server is the default state and silent, and it cost a whole
/// evening of testing a freeze that was never armed.
/// </summary>
private void ShowStatus()
{
string session;
switch (SimulatorPlugin.Status)
{
case SessionStatus.NoServer: session = "select a server above"; break;
case SessionStatus.OfficialNetwork: session = "live network - inactive"; break;
case SessionStatus.NotConnected: session = "vatSys not connected"; break;
case SessionStatus.Unreachable: session = "server not responding"; break;
case SessionStatus.NoSession: session = "no session for this CID"; break;
case SessionStatus.NoScenario: session = "no scenario loaded"; break;
case SessionStatus.Running: session = "running"; break;
case SessionStatus.Paused: session = "PAUSED"; break;
default: session = "-"; break;
}
var radar = RadarFreeze.Frozen
? "held"
: RadarFreeze.Available ? "live" : "hold unavailable";
labelStatus.Text = string.Join(Environment.NewLine, new[]
{
"Session: " + session,
"Radar: " + radar,
});
}
private void ComboBoxDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
var server = SimulatorPlugin.Servers.FirstOrDefault(x => x.Name == comboBoxDisplay.Text);
SimulatorPlugin._server = server == null ? string.Empty : server.Url;
}
private void SimulatorWindow_Load(object sender, EventArgs e)
{
comboBoxDisplay.Items.Clear();
// The blank first entry is "no server" - selecting it stops anything being sent.
comboBoxDisplay.Items.Add(string.Empty);
foreach (var server in SimulatorPlugin.Servers)
{
comboBoxDisplay.Items.Add(server.Name);
}
var selected = SimulatorPlugin.Servers.FirstOrDefault(x => x.Url == SimulatorPlugin._server);
comboBoxDisplay.Text = selected == null ? string.Empty : selected.Name;
ShowStatus();
_statusTimer.Start();
}
}
}