Skip to content

Commit 23fb737

Browse files
committed
Inspector: Added Skill and Damage event filters, refactoring
1 parent 3ff9da9 commit 23fb737

File tree

1 file changed

+63
-56
lines changed

1 file changed

+63
-56
lines changed

EVTCInspector/EventContentFilterControl.cs

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
2-
using System.Linq;
31
using Eto.Forms;
42
using GW2Scratch.EVTCAnalytics.Events;
3+
using System;
4+
using System.Linq;
5+
using System.Linq.Expressions;
56

67
namespace GW2Scratch.EVTCInspector
78
{
@@ -11,19 +12,49 @@ public class EventContentFilterControl : Panel
1112
private bool BuffIdEnabled { get; set; }
1213
private uint BuffDamageId { get; set; }
1314
private bool BuffDamageIdEnabled { get; set; }
15+
private uint CastSkillId { get; set; }
16+
private bool CastSkillIdEnabled { get; set; }
17+
private uint DamageSkillId { get; set; }
18+
private bool DamageSkillIdEnabled { get; set; }
1419

15-
private readonly Control buffLayout;
16-
private readonly Control buffDamageLayout;
20+
private readonly DynamicLayout buffLayout;
21+
private readonly DynamicLayout buffDamageLayout;
22+
private readonly DynamicLayout castSkillLayout;
23+
private readonly DynamicLayout damageSkillLayout;
1724

1825
public EventContentFilterControl()
1926
{
20-
buffLayout = ConstructBuffLayout();
21-
buffDamageLayout = ConstructBuffDamageLayout();
27+
buffLayout = ConstructLayout(
28+
() => BuffId, x => BuffId = x,
29+
() => BuffIdEnabled, x => BuffIdEnabled = x ?? false,
30+
"Buff Events",
31+
"Buff ID"
32+
);
33+
buffDamageLayout = ConstructLayout(
34+
() => BuffDamageId, x => BuffDamageId = x,
35+
() => BuffDamageIdEnabled, x => BuffDamageIdEnabled = x ?? false,
36+
"Buff Damage Events",
37+
"Buff ID"
38+
);
39+
castSkillLayout = ConstructLayout(
40+
() => CastSkillId, x => CastSkillId = x,
41+
() => CastSkillIdEnabled, x => CastSkillIdEnabled = x ?? false,
42+
"Skill Cast Events",
43+
"Skill ID"
44+
);
45+
damageSkillLayout = ConstructLayout(
46+
() => DamageSkillId, x => DamageSkillId = x,
47+
() => DamageSkillIdEnabled, x => DamageSkillIdEnabled = x ?? false,
48+
"Damage Events",
49+
"Skill ID"
50+
);
2251
var layout = new DynamicLayout();
2352
layout.BeginVertical();
2453
{
2554
layout.Add(buffLayout);
2655
layout.Add(buffDamageLayout);
56+
layout.Add(castSkillLayout);
57+
layout.Add(damageSkillLayout);
2758
}
2859
layout.EndVertical();
2960
Content = layout;
@@ -74,69 +105,45 @@ public void UpdateContent(EventListControl eventList)
74105
*/
75106
}
76107

77-
private Control ConstructBuffLayout()
108+
private static DynamicLayout ConstructLayout<TValue>(
109+
Expression<Func<TValue>> valueGetterExpr, Action<TValue> valueSetter,
110+
Expression<Func<bool?>> enabledGetterExpr, Action<bool?> enabledSetter,
111+
string groupTitle, string labelText)
78112
{
79-
var buffIdTextBox = new NumericMaskedTextBox<uint> {Value = 0};
80-
buffIdTextBox.ValueBinding.Bind(() => BuffId, x => BuffId = x);
81-
82-
var buffIdCheckbox = new CheckBox {Checked = false};
83-
buffIdCheckbox.CheckedBinding.Bind(() => BuffIdEnabled, x => BuffIdEnabled = x ?? false);
84-
85-
var filterLayout = new DynamicLayout();
86-
filterLayout.BeginHorizontal();
87-
{
88-
filterLayout.BeginGroup("Buff");
89-
{
90-
filterLayout.AddRow("Buff ID", buffIdTextBox, buffIdCheckbox, null);
91-
}
92-
filterLayout.EndGroup();
93-
filterLayout.AddRow(null);
94-
}
95-
filterLayout.EndHorizontal();
96-
return filterLayout;
97-
}
113+
var valueGetter = valueGetterExpr.Compile();
114+
var enabledGetter = enabledGetterExpr.Compile();
98115

99-
private Control ConstructBuffDamageLayout()
100-
{
101-
var buffIdTextBox = new NumericMaskedTextBox<uint> {Value = 0};
102-
buffIdTextBox.ValueBinding.Bind(() => BuffDamageId, x => BuffDamageId = x);
116+
var valueTextBox = new NumericMaskedTextBox<TValue>();
117+
valueTextBox.ValueBinding.Bind(valueGetter, valueSetter);
103118

104-
var buffIdCheckbox = new CheckBox {Checked = false};
105-
buffIdCheckbox.CheckedBinding.Bind(() => BuffDamageIdEnabled, x => BuffDamageIdEnabled = x ?? false);
119+
var enabledCheckbox = new CheckBox();
120+
enabledCheckbox.CheckedBinding.Bind(enabledGetter, enabledSetter);
106121

107-
var filterLayout = new DynamicLayout();
108-
filterLayout.BeginHorizontal();
122+
var layout = new DynamicLayout();
123+
layout.BeginHorizontal();
109124
{
110-
filterLayout.BeginGroup("Buff damage");
125+
layout.BeginGroup(groupTitle);
111126
{
112-
filterLayout.AddRow("Buff ID", buffIdTextBox, buffIdCheckbox, null);
127+
layout.AddRow(labelText, valueTextBox, enabledCheckbox, null);
113128
}
114-
filterLayout.EndGroup();
115-
filterLayout.AddRow(null);
129+
layout.EndGroup();
130+
layout.AddRow(null);
116131
}
117-
filterLayout.EndHorizontal();
118-
return filterLayout;
132+
layout.EndHorizontal();
133+
134+
return layout;
119135
}
120136

121137
public bool FilterEvent(Event e)
122138
{
123-
if (e is BuffEvent buffEvent)
139+
return e switch
124140
{
125-
if (BuffIdEnabled)
126-
{
127-
return buffEvent.Buff.Id == BuffId;
128-
}
129-
}
130-
131-
if (e is BuffDamageEvent buffDamage)
132-
{
133-
if (BuffDamageIdEnabled)
134-
{
135-
return buffDamage.Skill.Id == BuffDamageId;
136-
}
137-
}
138-
139-
return true;
141+
BuffEvent buffEvent when BuffIdEnabled => buffEvent.Buff.Id == BuffId,
142+
BuffDamageEvent buffDamage when BuffDamageIdEnabled => buffDamage.Skill.Id == BuffDamageId,
143+
SkillCastEvent skillEvent when CastSkillIdEnabled => skillEvent.Skill.Id == CastSkillId,
144+
DamageEvent damageEvent when DamageSkillIdEnabled => damageEvent.Skill.Id == DamageSkillId,
145+
_ => true,
146+
};
140147
}
141148

142149
private Type GetClosestType(Type a, Type b)

0 commit comments

Comments
 (0)