-
Notifications
You must be signed in to change notification settings - Fork 16
/
UserInputHandler.cs
71 lines (64 loc) · 2.65 KB
/
UserInputHandler.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
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.GameExecution;
using EOLib.Domain.Map;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using XNAControls;
namespace EndlessClient.Input
{
public class UserInputHandler : XNAControl, IUserInputHandler
{
private readonly List<IInputHandler> _handlers;
private readonly IActiveDialogProvider _activeDialogProvider;
public UserInputHandler(IEndlessGameProvider endlessGameProvider,
IUserInputProvider userInputProvider,
IUserInputTimeRepository userInputTimeRepository,
IArrowKeyController arrowKeyController,
IControlKeyController controlKeyController,
IFunctionKeyController functionKeyController,
INumPadController numPadController,
ICurrentMapStateRepository currentMapStateRepository,
IActiveDialogProvider activeDialogProvider)
{
_handlers = new List<IInputHandler>
{
new ArrowKeyHandler(endlessGameProvider,
userInputProvider,
userInputTimeRepository,
arrowKeyController,
currentMapStateRepository),
new ControlKeyHandler(endlessGameProvider,
userInputProvider,
userInputTimeRepository,
controlKeyController,
currentMapStateRepository),
new FunctionKeyHandler(endlessGameProvider,
userInputProvider,
userInputTimeRepository,
functionKeyController,
currentMapStateRepository),
new NumPadHandler(endlessGameProvider,
userInputProvider,
userInputTimeRepository,
currentMapStateRepository,
numPadController),
};
_activeDialogProvider = activeDialogProvider;
}
protected override void OnUpdateControl(GameTime gameTime)
{
if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue))
return;
var timeAtBeginningOfUpdate = DateTime.Now;
foreach (var handler in _handlers)
handler.HandleKeyboardInput(timeAtBeginningOfUpdate);
base.OnUpdateControl(gameTime);
}
}
public interface IUserInputHandler : IGameComponent
{
}
}