-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTGMT.cs
70 lines (59 loc) · 2.17 KB
/
TGMT.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
using BveEx.Extensions.MapStatements;
using BveEx.PluginHost;
using BveEx.PluginHost.Plugins;
using BveEx.PluginHost.Plugins.Extensions;
using BveTypes.ClassWrappers;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using TGMT_CBTC.HMI;
using TGMT_CBTC.OBCU;
namespace TGMT_CBTC {
[Plugin(PluginType.Extension)]
public class TGMT : AssemblyPluginBase, IExtension {
private Scenario Scenario { get; set; }
public OBCU.OBCU OBCU { get; private set; }
private HMIWindow hmiWindow;
private KeyHandler keyHandler = new KeyHandler();
public TGMT(PluginBuilder builder) : base(builder) {
BveHacker.ScenarioCreated += OnScenarioCreated;
BveHacker.ScenarioClosed += OnScenarioClosed;
TGMTPainter.Initialize();
keyHandler.Init(BveHacker);
keyHandler.AtoStartPressed += OnAtoStartPressed;
}
private void OnScenarioCreated(ScenarioCreatedEventArgs e) {
Scenario = e.Scenario;
OBCU = new OBCU.OBCU(Scenario);
hmiWindow = new HMIWindow();
hmiWindow.Show();
}
private void OnScenarioClosed(EventArgs e) {
Scenario = null;
OBCU = null;
if (hmiWindow != null) hmiWindow.Close();
hmiWindow = null;
}
TimeSpan paintTimeDelay = TimeSpan.FromMilliseconds(1000);
public override void Tick(TimeSpan elapsed) {
if (OBCU == null) return;
OBCU.Tick(elapsed, Scenario);
paintTimeDelay += elapsed;
if (paintTimeDelay >= TimeSpan.FromMilliseconds(1000 / 8)) {
Bitmap hmiBitmap = TGMTPainter.PaintHMI(OBCU).Bitmap;
hmiWindow.DrawBitmap(hmiBitmap);
hmiWindow.HandleHMIInfo(OBCU);
paintTimeDelay = TimeSpan.Zero;
}
}
private void OnAtoStartPressed(object sender, EventArgs e) {
OBCU.OnAtoStartPressed(Scenario);
}
public override void Dispose() {
TGMTPainter.Dispose();
if (hmiWindow != null) hmiWindow.Dispose();
}
}
}