-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardSection.cs
61 lines (54 loc) · 1.26 KB
/
StandardSection.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
using System;
using System.Text.RegularExpressions;
using System.Threading;
namespace InputMaster
{
public class StandardSection : Section
{
private static int _idCounter;
private readonly StandardSection _parent;
private readonly int _id;
private bool _enabled;
private int _counter = -1;
protected StandardSection(StandardSection parent)
{
_parent = parent;
_id = Interlocked.Increment(ref _idCounter);
}
public StandardSection()
{
Column = 1;
_id = Interlocked.Increment(ref _idCounter);
}
private bool IsTopLevel => _parent == null;
public bool IsEnabled
{
get
{
if (_counter < Env.StateCounter)
{
_counter = Env.StateCounter;
_enabled = (IsTopLevel || _parent.IsEnabled) && ComputeEnabled();
}
return _enabled;
}
}
protected virtual bool ComputeEnabled()
{
return true;
}
private int GetDepth(int d = 0)
{
if (IsTopLevel)
return d;
return _parent.GetDepth(d + 1);
}
public int CompareTo(StandardSection other)
{
if (other == null)
return 1;
var x = GetDepth() - other.GetDepth();
return x == 0 ? _id - other._id : x;
}
}
}