-
Notifications
You must be signed in to change notification settings - Fork 16
/
InGameControlSet.cs
78 lines (67 loc) · 2.78 KB
/
InGameControlSet.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
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Factories;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Controls;
using EndlessClient.Input;
using EOLib.Localization;
using Microsoft.Xna.Framework;
using Optional;
using XNAControls;
namespace EndlessClient.ControlSets
{
public class InGameControlSet : BackButtonControlSet
{
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly IHudControlsFactory _hudControlsFactory;
private readonly IActiveDialogRepository _activeDialogRepository;
private readonly IUserInputRepository _userInputRepository;
private IReadOnlyDictionary<HudControlIdentifier, IGameComponent> _controls;
public override GameStates GameState => GameStates.PlayingTheGame;
public InGameControlSet(IMainButtonController mainButtonController,
IEOMessageBoxFactory messageBoxFactory,
IHudControlsFactory hudControlsFactory,
IActiveDialogRepository activeDialogRepository,
IUserInputRepository userInputRepository)
: base(mainButtonController)
{
_messageBoxFactory = messageBoxFactory;
_hudControlsFactory = hudControlsFactory;
_activeDialogRepository = activeDialogRepository;
_userInputRepository = userInputRepository;
_controls = new Dictionary<HudControlIdentifier, IGameComponent>();
}
public T GetHudComponent<T>(HudControlIdentifier whichControl)
where T : IGameComponent
{
return (T)_controls[whichControl];
}
protected override void InitializeControlsHelper(IControlSet currentControlSet)
{
_controls = _hudControlsFactory.CreateHud();
_allComponents.AddRange(_controls.Select(x => x.Value));
base.InitializeControlsHelper(currentControlSet);
}
protected override async void DoBackButtonClick(object sender, EventArgs e)
{
_userInputRepository.ClickHandled = true;
var messageBox = _messageBoxFactory.CreateMessageBox(
DialogResourceID.EXIT_GAME_ARE_YOU_SURE,
EODialogButtons.OkCancel);
var result = await messageBox.ShowDialogAsync();
if (result == XNADialogResult.OK)
_mainButtonController.GoToInitialStateAndDisconnect();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_activeDialogRepository.Dispose();
}
base.Dispose(disposing);
}
}
}