forked from AdamPrimer/LiveSplit.OriAndTheBlindForest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.cs
188 lines (159 loc) · 7.57 KB
/
Component.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
using LiveSplit.Model;
using LiveSplit.OriAndTheBlindForest.Debugging;
using LiveSplit.OriAndTheBlindForest.Settings;
using LiveSplit.OriAndTheBlindForest.State;
using LiveSplit.UI;
using LiveSplit.UI.Components;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
namespace LiveSplit.OriAndTheBlindForest
{
public class OriComponent : IComponent
{
public OriAndTheBlindForestSettings Settings { get; set; }
private InfoTextComponent textInfo;
public string ComponentName {
get { return "Ori and the Blind Forest Autosplitter"; }
}
public OriState oriState;
protected TimerModel Model { get; set; }
public float PaddingTop { get { return Settings.showMapDisplay ? textInfo.PaddingTop : 0; } }
public float PaddingLeft { get { return Settings.showMapDisplay ? textInfo.PaddingLeft : 0; } }
public float PaddingBottom { get { return Settings.showMapDisplay ? textInfo.PaddingBottom : 0; } }
public float PaddingRight { get { return Settings.showMapDisplay ? textInfo.PaddingRight : 0; } }
public IDictionary<string, Action> ContextMenuControls { get { return null; } }
public OriComponent() {
textInfo = new InfoTextComponent("0%", "Swamp 0.00%");
oriState = new OriState();
Settings = new OriAndTheBlindForestSettings(this);
oriState.oriTriggers.OnSplit += OnSplitTriggered;
}
private void PrepareDraw(LiveSplitState state, LayoutMode mode) {
textInfo.DisplayTwoRows = true;
textInfo.NameLabel.HasShadow = textInfo.ValueLabel.HasShadow = state.LayoutSettings.DropShadows;
textInfo.NameLabel.HorizontalAlignment = StringAlignment.Far;
textInfo.ValueLabel.HorizontalAlignment = StringAlignment.Far;
textInfo.NameLabel.VerticalAlignment = StringAlignment.Near;
textInfo.ValueLabel.VerticalAlignment = StringAlignment.Near;
textInfo.NameLabel.ForeColor = state.LayoutSettings.TextColor;
textInfo.ValueLabel.ForeColor = state.LayoutSettings.TextColor;
}
public void DrawVertical(Graphics g, LiveSplitState state, float width, Region clipRegion) {
if (Settings.showMapDisplay) {
if (state.LayoutSettings.BackgroundColor.ToArgb() != Color.Transparent.ToArgb()) {
g.FillRectangle(new SolidBrush(state.LayoutSettings.BackgroundColor), 0, 0, width, VerticalHeight);
}
PrepareDraw(state, LayoutMode.Vertical);
textInfo.DrawVertical(g, state, width, clipRegion);
}
}
public void DrawHorizontal(Graphics g, LiveSplitState state, float height, Region clipRegion) {
if (Settings.showMapDisplay) {
if (state.LayoutSettings.BackgroundColor.ToArgb() != Color.Transparent.ToArgb()) {
g.FillRectangle(new SolidBrush(state.LayoutSettings.BackgroundColor), 0, 0, HorizontalWidth, height);
}
PrepareDraw(state, LayoutMode.Horizontal);
textInfo.DrawHorizontal(g, state, height, clipRegion);
}
}
public float VerticalHeight {
get { return Settings.showMapDisplay ? textInfo.VerticalHeight : 0; }
}
public float MinimumWidth {
get { return Settings.showMapDisplay ? textInfo.MinimumWidth : 0; }
}
public float HorizontalWidth {
get { return Settings.showMapDisplay ? textInfo.HorizontalWidth : 0; }
}
public float MinimumHeight {
get { return Settings.showMapDisplay ? textInfo.MinimumHeight : 0; }
}
public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) {
if (Model == null) {
Model = new TimerModel() { CurrentState = state };
state.OnReset += OnReset;
state.OnPause += OnPause;
state.OnResume += OnResume;
state.OnStart += OnStart;
state.OnSplit += OnSplit;
state.OnUndoSplit += OnUndoSplit;
state.OnSkipSplit += OnSkipSplit;
}
oriState.Loop();
oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);
if (Settings.showMapDisplay) {
textInfo.InformationName = "Total Map: " + oriState.sMapCompletion.ToString("0.00") + "%";
textInfo.InformationValue = oriState.sCurrentArea.ToString();
textInfo.LongestString = "Valley Of The Wind - 100.00%";
textInfo.Update(invalidator, state, width, height, mode);
if (invalidator != null) {
invalidator.Invalidate(0, 0, width, height);
}
}
}
public void Dispose() {
Settings.CloseDisplay();
}
public void OnSplitTriggered(object sender, OriTriggers.SplitEventArgs e) {
if (e.name == "Start") {
if (!oriState.oriTriggers.timerRunning && oriState.oriTriggers.autoReset) {
Model.Reset();
}
LogWriter.WriteLine("[OriSplitter] Start.");
Model.Start();
} else if (e.name == "End") {
LogWriter.WriteLine("[OriSplitter] Final Split.");
Model.Split();
} else {
LogWriter.WriteLine("[OriSplitter] Split.");
if (oriState.oriTriggers.autoStart && !oriState.oriTriggers.timerRunning) {
if (oriState.oriTriggers.autoReset) {
Model.Reset();
}
Model.Start();
} else {
Model.Split();
}
}
}
public void OnReset(object sender, TimerPhase e) {
LogWriter.WriteLine("[LiveSplit] Reset.");
oriState.Reset();
oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);
}
public void OnResume(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Resume.");
oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);
}
public void OnPause(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Pause.");
oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);
}
public void OnStart(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Start.");
oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);
}
public void OnUndoSplit(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Undo Split.");
}
public void OnSkipSplit(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Skip Split.");
}
public void OnSplit(object sender, EventArgs e) {
LogWriter.WriteLine("[LiveSplit] Split.");
}
public Control GetSettingsControl(LayoutMode mode) {
return Settings;
}
public void SetSettings(XmlNode settings) {
Settings.SetSettings(settings);
oriState.UpdateSplits(Settings.splitsState);
}
public XmlNode GetSettings(XmlDocument document) {
return Settings.GetSettings(document);
}
}
}