Repository navigation
Expand file tree
/
Copy pathMouseInteractionSystem.cs
More file actions
112 lines (96 loc) · 3.92 KB
/
Copy pathMouseInteractionSystem.cs
File metadata and controls
112 lines (96 loc) · 3.92 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
using Controllers;
using Kitchen;
using KitchenData;
using Unity.Entities;
namespace KitchenDragNDropDesigner
{
public abstract class MouseInteractionSystem : ApplianceInteractionSystem
{
protected bool MadeChanges = default;
protected CPosition Position;
public enum MouseButton
{
None,
Left,
Right,
Middle,
Forward,
Back
}
protected bool WasMouseButtonDown { get; private set; }
protected virtual bool AllowHold => false;
protected virtual CMouseData.Action Action { get; } = CMouseData.Action.Act;
CMouseData _mouseData;
protected bool IsMouseActive => _mouseData.Active;
protected bool IsMouseButtonPressed => _mouseData.GetButtonState(Action) == ButtonState.Pressed || IsMouseButtonHeld;
protected bool IsMouseButtonHeld => _mouseData.GetButtonState(Action) == ButtonState.Held;
protected bool IsMouseButtonActive => IsMouseButtonPressed && (AllowHold || !IsMouseButtonHeld);
protected override bool BeforeRun()
{
base.BeforeRun();
if (!Has<SLayout>())
return false;
MadeChanges = false;
return true;
}
protected override void AfterRun()
{
base.AfterRun();
if (!MadeChanges)
return;
EntityManager.CreateEntity((ComponentType)typeof(CRequireStartDayWarningRecalculation));
if (!HasSingleton<SPerformTableUpdate>())
EntityManager.CreateEntity((ComponentType)typeof(SPerformTableUpdate));
}
protected abstract bool IsPossibleCondition(ref InteractionData data);
protected sealed override bool IsPossible(ref InteractionData data)
{
if (!Require(data.Interactor, out CMouseData mouseData) ||
!mouseData.Active)
return false;
return IsPossibleCondition(ref data);
}
protected override bool ShouldAct(ref InteractionData interaction_data)
{
_mouseData = default;
if (Has<CPlayer>(interaction_data.Interactor) &&
Require(interaction_data.Interactor, out CMouseData mouseData) &&
mouseData.Active)
{
_mouseData = mouseData;
}
UpdateInteractionData(ref interaction_data);
if ((RequiredType == interaction_data.Attempt.Type || (AllowActOrGrab && (interaction_data.Attempt.Type == InteractionType.Act || interaction_data.Attempt.Type == InteractionType.Grab))) &&
(!RequirePress || AllowHold || !interaction_data.Attempt.IsHeld))
{
if (RequireHold)
{
return interaction_data.Attempt.IsHeld;
}
return true;
}
return false;
}
protected virtual void UpdateInteractionData(ref InteractionData interaction_data)
{
if (!IsMouseActive)
return;
if (IsMouseButtonActive)
{
interaction_data.Attempt.Type = RequiredType;
interaction_data.Attempt.IsHeld = IsMouseButtonHeld;
}
if (RequiredType == InteractionType.Look || IsMouseButtonActive)
{
interaction_data.Attempt.Location = _mouseData.Position;
UpdateMouseTarget(ref interaction_data, OccupancyLayer.Default);
}
}
Entity UpdateMouseTarget(ref InteractionData data, OccupancyLayer layer)
{
Entity newTarget = layer != OccupancyLayer.Default ? GetOccupant(data.Attempt.Location, layer) : GetPrimaryOccupant(data.Attempt.Location);
data.Attempt.Target = (newTarget != default && Has<CIsInteractive>(newTarget)) ? newTarget : default;
return data.Attempt.Target;
}
}
}