-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDXTFComponent.cs
More file actions
128 lines (105 loc) · 3.73 KB
/
Copy pathDXTFComponent.cs
File metadata and controls
128 lines (105 loc) · 3.73 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
using LiveSplit.Model;
using LiveSplit.UI.Components;
using LiveSplit.UI;
using System;
using System.Xml;
using System.Windows.Forms;
using System.Diagnostics;
namespace LiveSplit.DXTF
{
class DXTFComponent : LogicComponent
{
public override string ComponentName
{
get { return "DXTF"; }
}
public DXTFSettings Settings { get; set; }
public bool Disposed { get; private set; }
public bool IsLayoutComponent { get; private set; }
private TimerModel _timer;
private GameMemory _gameMemory;
private LiveSplitState _state;
public DXTFComponent(LiveSplitState state, bool isLayoutComponent)
{
_state = state;
this.IsLayoutComponent = isLayoutComponent;
_timer = new TimerModel { CurrentState = state };
_timer.CurrentState.OnStart += timer_OnStart;
this.Settings = new DXTFSettings();
_gameMemory = new GameMemory(this.Settings);
_gameMemory.OnFirstLevelAutostart += _gameMemory_OnFirstLevelAutostart;
_gameMemory.OnLoadStarted += gameMemory_OnLoadStarted;
_gameMemory.OnLoadFinished += gameMemory_OnLoadFinished;
_gameMemory.OnLevelChanged += _gameMemory_OnLevelChanged;
_gameMemory.OnFirstLevelLoad += _gameMemory_OnFirstLevelLoad;
state.OnStart += State_OnStart;
_gameMemory.StartMonitoring();
}
private void _gameMemory_OnFirstLevelAutostart(object sender, EventArgs e)
{
if(this.Settings.AutorestartOnFirstLevel)
{
_timer.Reset();
}
}
public override void Dispose()
{
this.Disposed = true;
_timer.CurrentState.OnStart -= timer_OnStart;
_gameMemory.OnFirstLevelAutostart -= _gameMemory_OnFirstLevelAutostart;
_gameMemory.OnLoadStarted -= gameMemory_OnLoadStarted;
_gameMemory.OnLoadFinished -= gameMemory_OnLoadFinished;
_gameMemory.OnLevelChanged -= _gameMemory_OnLevelChanged;
_gameMemory.OnFirstLevelLoad -= _gameMemory_OnFirstLevelLoad;
_state.OnStart -= State_OnStart;
if (_gameMemory != null)
{
_gameMemory.Stop();
}
}
private void timer_OnStart(object sender, EventArgs e)
{
_timer.InitializeGameTime();
}
private void _gameMemory_OnLevelChanged(object sender, EventArgs e)
{
if(this.Settings.SplitOnLevelChange)
{
_timer.Split();
}
}
private void _gameMemory_OnFirstLevelLoad(object sender, EventArgs e)
{
if (this.Settings.StartOnFirstLevelLoad)
{
_timer.Start();
}
}
void State_OnStart(object sender, EventArgs e)
{
_gameMemory.resetSplitStates();
}
void gameMemory_OnLoadStarted(object sender, EventArgs e)
{
_state.IsGameTimePaused = true;
}
void gameMemory_OnLoadFinished(object sender, EventArgs e)
{
_state.IsGameTimePaused = false;
}
public override XmlNode GetSettings(XmlDocument document)
{
return this.Settings.GetSettings(document);
}
public override Control GetSettingsControl(LayoutMode mode)
{
return this.Settings;
}
public override void SetSettings(XmlNode settings)
{
this.Settings.SetSettings(settings);
}
public override void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) { }
//public override void RenameComparison(string oldName, string newName) { }
}
}