-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
306 lines (241 loc) · 10.6 KB
/
MainWindow.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// Copyright (c) 2024, Todd Taylor (https://github.com/zxeltor)
// All rights reserved.
//
// This source code is licensed under the Apache-2.0-style license found in the
// LICENSE file in the root directory of this source tree.
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using log4net;
using zxeltor.StoCombat.Lib.Classes;
using zxeltor.StoCombat.Realtime.Classes;
using zxeltor.StoCombat.Realtime.Controls;
using zxeltor.Types.Lib.Helpers;
using zxeltor.Types.Lib.Result;
namespace zxeltor.StoCombat.Realtime;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
#region Private Fields
//private AchievementOverlayWindowContext _achievementOverlayWindowContext;
private readonly AchievementPlaybackManager? _achievementPlaybackManager;
private readonly ILog _log = LogManager.GetLogger(typeof(MainWindow));
//private readonly RealtimeCombatLogParseSettings _parserSettings;
private readonly RealtimeCombatLogMonitor _realtimeCombatLogMonitor;
private AchievementOverlayWindow? _testAchievementOverlayWindow;
private MetricsOverlayWindow? _testMetricsOverlayWindow;
#endregion
#region Constructors
public MainWindow()
{
if (LoggingHelper.TryConfigureLog4NetLogging(out var isUsingDevelopmentConfig))
AppCommunicationsManager.Instance.SendNotification(this,
isUsingDevelopmentConfig
? "Logging has been configured using Log4Net.Development.config."
: "Logging has been configured.",
ResultLevel.Debug);
else
AppCommunicationsManager.Instance.SendNotification(this, "Logging configuration failed.",
ResultLevel.Error);
this.InitializeComponent();
this.Title = $"STO Realtime Combat Log Analyzer {this.ApplicationVersionInfoString}";
this.DataContext = this._realtimeCombatLogMonitor = new RealtimeCombatLogMonitor(this.Dispatcher);
this._achievementPlaybackManager = new AchievementPlaybackManager(this.Dispatcher);
StoCombatRealtimeSettings.Instance.MetricsOverlayWindowContext.CurrentRealtimeCombat =
this._realtimeCombatLogMonitor.CurrentRealtimeCombat;
this.Loaded += this.OnLoaded;
this.Unloaded += this.OnUnloaded;
this._log.Info("Application Started.");
}
#endregion
#region Public Properties
//private MetricsOverlayWindowContext _metricsOverlayWindowContext;
public MetricsOverlayWindow? MetricsOverlayWindow { get; private set; }
//public AchievementOverlayWindowContext AchievementOverlayWindowContext
//{
// get => this._achievementOverlayWindowContext;
// private set => this.SetField(ref this._achievementOverlayWindowContext, value);
//}
//public MetricsOverlayWindowContext MetricsOverlayWindowContext
//{
// get => this._metricsMetricsOverlayWindowContext;
// private set => this.SetField(ref this._metricsMetricsOverlayWindowContext, value);
//}
private string ApplicationVersionInfoString
{
get
{
var version = AssemblyInfoHelper.GetApplicationVersionFromAssembly();
return $"{version.Major}.{version.Minor}.{version.Revision}";
}
}
#endregion
#region Public Members
public event PropertyChangedEventHandler? PropertyChanged;
#endregion
#region Other Members
private void ColorButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (sender is not Button buttonResult) return;
var colorPicker = new ColorPickerWindow();
colorPicker.Owner = this;
colorPicker.WindowStartupLocation = WindowStartupLocation.CenterOwner;
if (buttonResult.Background is SolidColorBrush brushResult)
colorPicker.SelectedColor = brushResult.Color;
var dialogResult = colorPicker.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
buttonResult.Background = new SolidColorBrush(colorPicker.SelectedColor);
}
private void InstanceOnNotification(object? sender, DataGridRowContext e)
{
if (e.ResultLevel == ResultLevel.Halt)
if (this.MetricsOverlayWindow != null)
this.Dispatcher.Invoke(() =>
{
this.MetricsOverlayWindow?.Close();
this.MetricsOverlayWindow = null;
});
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
this.Loaded -= this.OnLoaded;
this.SetLoggingLevel();
StoCombatRealtimeSettings.Instance.PropertyChanged += this.Instance_PropertyChanged;
this._realtimeCombatLogMonitor.PropertyChanged += this.RealtimeCombatLogMonitorOnPropertyChanged;
AppCommunicationsManager.Instance.Notification += this.InstanceOnNotification;
if (StoCombatRealtimeSettings.Instance.ParseSettings.IsUnrealAnnouncementsEnabled)
this._achievementPlaybackManager?.Start();
}
private void Instance_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != null && e.PropertyName.Equals(nameof(StoCombatRealtimeSettings.IsEnableDebugLogging)))
{
this.SetLoggingLevel();
}
}
private void SetLoggingLevel()
{
LoggingHelper.TrySettingLog4NetLogLevel(StoCombatRealtimeSettings.Instance.IsEnableDebugLogging);
}
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
this.Unloaded -= this.OnUnloaded;
this._testAchievementOverlayWindow?.Close();
this._testAchievementOverlayWindow = null;
this._testMetricsOverlayWindow?.Close();
this._testMetricsOverlayWindow = null;
this.MetricsOverlayWindow?.Close();
this.MetricsOverlayWindow = null;
this._testAchievementOverlayWindow?.Close();
this._testAchievementOverlayWindow = null;
//this._parserSettings.PropertyChanged -= this.ParserSettingsOnPropertyChanged;
this._realtimeCombatLogMonitor?.Dispose();
this._achievementPlaybackManager?.Dispose();
}
//private void ParserSettingsOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
//{
// if (e.PropertyName != null && e.PropertyName.Equals(nameof(this._parserSettings.IsUnrealAnnouncementsEnabled)))
// if (this._parserSettings.IsUnrealAnnouncementsEnabled) this._achievementPlaybackManager?.Start();
// else this._achievementPlaybackManager?.Dispose();
//}
private void RealtimeCombatLogMonitorOnAccountPlayerEvents(object? sender, AchievementEvent e)
{
this.Dispatcher.Invoke(() => this._achievementPlaybackManager?.ProcessEvent(e));
}
private void RealtimeCombatLogMonitorOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != null &&
e.PropertyName.Equals(nameof(this._realtimeCombatLogMonitor.CurrentRealtimeCombat)))
StoCombatRealtimeSettings.Instance.MetricsOverlayWindowContext.CurrentRealtimeCombat =
this._realtimeCombatLogMonitor.CurrentRealtimeCombat;
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
this.OnPropertyChanged(propertyName);
return true;
}
private void UiButtonDisplayOverlay_OnClick(object sender, RoutedEventArgs e)
{
if (this.MetricsOverlayWindow == null)
{
this._testMetricsOverlayWindow?.Close();
this._testMetricsOverlayWindow = null;
this.MetricsOverlayWindow =
new MetricsOverlayWindow(StoCombatRealtimeSettings.Instance.MetricsOverlayWindowContext);
this.MetricsOverlayWindow.ShowOverlay();
}
else
{
this._testMetricsOverlayWindow?.Close();
this._testMetricsOverlayWindow = null;
this.MetricsOverlayWindow.Close();
this.MetricsOverlayWindow = null;
}
}
private void UiButtonEnd_OnClick(object sender, RoutedEventArgs e)
{
this._realtimeCombatLogMonitor?.Dispose();
}
//private void UiButtonOpenLog_OnClick(object sender, RoutedEventArgs e)
//{
// this.uiTabItemLogging.IsSelected = true;
//}
private void UiButtonPlayAudio_OnClick(object sender, RoutedEventArgs e)
{
this._log.Error("Playing audio file");
this._achievementPlaybackManager?.PlayAudio(AchievementPlaybackEnum.MONSTER);
}
private void UiButtonRefreshCombat_OnClick(object sender, RoutedEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftAlt))
{
StoCombatRealtimeSettings.Instance.IsDisplayToolsTab =
!StoCombatRealtimeSettings.Instance.IsDisplayToolsTab;
return;
}
try
{
this._realtimeCombatLogMonitor.Stop();
this._realtimeCombatLogMonitor.CurrentRealtimeCombat = null;
}
catch (Exception exception)
{
this._log.Error("Failed to stop and clear combat.", exception);
}
}
private void UiButtonStart_OnClick(object sender, RoutedEventArgs e)
{
this._realtimeCombatLogMonitor?.Dispose();
this._realtimeCombatLogMonitor?.Start(this.Dispatcher);
}
private void UiButtonToggleAchievementOverlayMode_OnClick(object sender, RoutedEventArgs e)
{
this._testAchievementOverlayWindow?.Close();
this._testAchievementOverlayWindow = null;
this._testAchievementOverlayWindow =
new AchievementOverlayWindow(StoCombatRealtimeSettings.Instance.AchievementOverlayWindowContext,
"ULTRA MEGA KILL", true);
this._testAchievementOverlayWindow.ShowOverlay();
}
private void UiButtonToggleOverlayMode_OnClick(object sender, RoutedEventArgs e)
{
this.MetricsOverlayWindow?.Close();
this.MetricsOverlayWindow = null;
this._testMetricsOverlayWindow?.Close();
this._testMetricsOverlayWindow =
new MetricsOverlayWindow(StoCombatRealtimeSettings.Instance.MetricsOverlayWindowContext, true);
this._testMetricsOverlayWindow.ShowOverlay();
}
#endregion
}