forked from ToadsworthLP/desktoptale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractionManager.cs
70 lines (55 loc) · 2.49 KB
/
InteractionManager.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
using Desktoptale.Messages;
using Desktoptale.Messaging;
using Microsoft.Xna.Framework;
namespace Desktoptale
{
public class InteractionManager
{
private MonitorManager monitorManager;
private GameWindow mainWindow;
private InputManager inputManager;
private bool clickthrough;
private bool interactionEnabled;
public InteractionManager(MonitorManager monitorManager, GameWindow mainWindow, InputManager inputManager)
{
this.monitorManager = monitorManager;
this.mainWindow = mainWindow;
this.inputManager = inputManager;
MessageBus.Subscribe<StartInteractionMessage>(OnStartInteractionMessage);
MessageBus.Subscribe<ClickThroughChangedMessage>(OnClickThroughChangedMessage);
MessageBus.Subscribe<InteractionButtonChangedMessage>(OnInteractionButtonChangedMessage);
}
private void OnStartInteractionMessage(StartInteractionMessage message)
{
if (!interactionEnabled) return;
Point previousPosition = WindowsUtils.GetCursorPosition();
if(!clickthrough) WindowsUtils.MakeClickthrough(mainWindow);
Point hitboxCenter = message.Target.HitBox.Center;
Point clickPosition = monitorManager
.ToVirtualScreenCoordinates(new Vector2(hitboxCenter.X, MathHelper.Lerp(hitboxCenter.Y, message.Target.HitBox.Bottom, 0.9f)))
.ToPoint();
WindowsUtils.SetCursorPosition(clickPosition);
if (inputManager.ShiftPressed)
{
WindowsUtils.SendRightMouseButtonDown();
WindowsUtils.SendRightMouseButtonUp();
}
else
{
WindowsUtils.SendLeftMouseButtonDown();
WindowsUtils.SendLeftMouseButtonUp();
}
WindowsUtils.SetCursorPosition(previousPosition);
if(!clickthrough) WindowsUtils.MakeClickable(mainWindow);
MessageBus.Send(new FocusCharacterMessage() { Character = message.Target });
}
private void OnClickThroughChangedMessage(ClickThroughChangedMessage message)
{
clickthrough = message.Enabled;
}
private void OnInteractionButtonChangedMessage(InteractionButtonChangedMessage message)
{
interactionEnabled = message.Enabled;
}
}
}