-
Notifications
You must be signed in to change notification settings - Fork 16
/
HudControlsFactory.cs
447 lines (395 loc) · 21.6 KB
/
HudControlsFactory.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AutomaticTypeMapper;
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.ControlSets;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Chat;
using EndlessClient.HUD.Panels;
using EndlessClient.HUD.StatusBars;
using EndlessClient.Input;
using EndlessClient.Network;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Factories;
using EndlessClient.Rendering.NPC;
using EndlessClient.UIControls;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.Graphics;
using EOLib.Localization;
using EOLib.Net.Communication;
using Microsoft.Xna.Framework;
using XNAControls;
namespace EndlessClient.HUD.Controls
{
//todo: this class is doing a lot. Might be a good idea to split it into multiple factories.
[MappedType(BaseType = typeof(IHudControlsFactory), IsSingleton = true)]
public class HudControlsFactory : IHudControlsFactory
{
private const int HUD_BASE_LAYER = 100;
private const int HUD_CONTROL_LAYER = 130;
private readonly IHudButtonController _hudButtonController;
private readonly IHudPanelFactory _hudPanelFactory;
private readonly IMapRendererFactory _mapRendererFactory;
private readonly IUserInputHandlerFactory _userInputHandlerFactory;
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IGraphicsDeviceProvider _graphicsDeviceProvider;
private readonly IClientWindowSizeProvider _clientWindowSizeProvider;
private readonly IEndlessGameProvider _endlessGameProvider;
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IUserInputRepository _userInputRepository;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IStatusLabelTextProvider _statusLabelTextProvider;
private readonly IContentProvider _contentProvider;
private readonly IHudControlProvider _hudControlProvider;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly IChatModeCalculator _chatModeCalculator;
private readonly IExperienceTableProvider _experienceTableProvider;
private readonly IArrowKeyController _arrowKeyController;
private readonly IPathFinder _pathFinder;
private readonly ICharacterActions _characterActions;
private readonly IWalkValidationActions _walkValidationActions;
private readonly IPacketSendService _packetSendService;
private readonly IUserInputTimeProvider _userInputTimeProvider;
private IChatController _chatController;
public HudControlsFactory(IHudButtonController hudButtonController,
IHudPanelFactory hudPanelFactory,
IMapRendererFactory mapRendererFactory,
IUserInputHandlerFactory userInputHandlerFactory,
INativeGraphicsManager nativeGraphicsManager,
IGraphicsDeviceProvider graphicsDeviceProvider,
IClientWindowSizeProvider clientWindowSizeProvider,
IEndlessGameProvider endlessGameProvider,
ICharacterRepository characterRepository,
ICurrentMapStateRepository currentMapStateRepository,
IUserInputRepository userInputRepository,
IStatusLabelSetter statusLabelSetter,
IStatusLabelTextProvider statusLabelTextProvider,
IContentProvider contentProvider,
IHudControlProvider hudControlProvider,
ICurrentMapProvider currentMapProvider,
IChatModeCalculator chatModeCalculator,
IExperienceTableProvider experienceTableProvider,
IArrowKeyController arrowKeyController,
IPathFinder pathFinder,
ICharacterActions characterActions,
IWalkValidationActions walkValidationActions,
IPacketSendService packetSendService,
IUserInputTimeProvider userInputTimeProvider)
{
_hudButtonController = hudButtonController;
_hudPanelFactory = hudPanelFactory;
_mapRendererFactory = mapRendererFactory;
_userInputHandlerFactory = userInputHandlerFactory;
_nativeGraphicsManager = nativeGraphicsManager;
_graphicsDeviceProvider = graphicsDeviceProvider;
_clientWindowSizeProvider = clientWindowSizeProvider;
_endlessGameProvider = endlessGameProvider;
_characterRepository = characterRepository;
_currentMapStateRepository = currentMapStateRepository;
_userInputRepository = userInputRepository;
_statusLabelSetter = statusLabelSetter;
_statusLabelTextProvider = statusLabelTextProvider;
_contentProvider = contentProvider;
_hudControlProvider = hudControlProvider;
_currentMapProvider = currentMapProvider;
_chatModeCalculator = chatModeCalculator;
_experienceTableProvider = experienceTableProvider;
_arrowKeyController = arrowKeyController;
_pathFinder = pathFinder;
_characterActions = characterActions;
_walkValidationActions = walkValidationActions;
_packetSendService = packetSendService;
_userInputTimeProvider = userInputTimeProvider;
}
public void InjectChatController(IChatController chatController)
{
_chatController = chatController;
}
public IReadOnlyDictionary<HudControlIdentifier, IGameComponent> CreateHud()
{
var characterAnimator = CreateCharacterAnimator();
var controls = new Dictionary<HudControlIdentifier, IGameComponent>
{
{HudControlIdentifier.CurrentUserInputTracker, CreateCurrentUserInputTracker()},
{HudControlIdentifier.MapRenderer, _mapRendererFactory.CreateMapRenderer()},
{HudControlIdentifier.HudBackground, CreateHudBackground()},
{HudControlIdentifier.InventoryButton, CreateStateChangeButton(InGameStates.Inventory)},
{HudControlIdentifier.ViewMapButton, CreateStateChangeButton(InGameStates.ViewMapToggle)},
{HudControlIdentifier.ActiveSpellsButton, CreateStateChangeButton(InGameStates.ActiveSpells)},
{HudControlIdentifier.PassiveSpellsButton, CreateStateChangeButton(InGameStates.PassiveSpells)},
{HudControlIdentifier.ChatButton, CreateStateChangeButton(InGameStates.Chat)},
{HudControlIdentifier.StatsButton, CreateStateChangeButton(InGameStates.Stats)},
{HudControlIdentifier.OnlineListButton, CreateStateChangeButton(InGameStates.OnlineList)},
{HudControlIdentifier.PartyButton, CreateStateChangeButton(InGameStates.Party)},
{HudControlIdentifier.MacroButton, CreateStateChangeButton(InGameStates.Macro)},
{HudControlIdentifier.SettingsButton, CreateStateChangeButton(InGameStates.Settings)},
{HudControlIdentifier.HelpButton, CreateStateChangeButton(InGameStates.Help)},
{HudControlIdentifier.FriendList, CreateFriendListButton()},
{HudControlIdentifier.IgnoreList, CreateIgnoreListButton()},
{HudControlIdentifier.NewsPanel, CreateStatePanel(InGameStates.News)},
{HudControlIdentifier.InventoryPanel, CreateStatePanel(InGameStates.Inventory)},
{HudControlIdentifier.ActiveSpellsPanel, CreateStatePanel(InGameStates.ActiveSpells)},
{HudControlIdentifier.PassiveSpellsPanel, CreateStatePanel(InGameStates.PassiveSpells)},
{HudControlIdentifier.ChatPanel, CreateStatePanel(InGameStates.Chat)},
{HudControlIdentifier.StatsPanel, CreateStatePanel(InGameStates.Stats)},
{HudControlIdentifier.OnlineListPanel, CreateStatePanel(InGameStates.OnlineList)},
{HudControlIdentifier.PartyPanel, CreateStatePanel(InGameStates.Party)},
//macro panel
{HudControlIdentifier.SettingsPanel, CreateStatePanel(InGameStates.Settings)},
{HudControlIdentifier.HelpPanel, CreateStatePanel(InGameStates.Help)},
{HudControlIdentifier.SessionExpButton, CreateSessionExpButton()},
{HudControlIdentifier.QuestsButton, CreateQuestButton()},
{HudControlIdentifier.HPStatusBar, CreateHPStatusBar()},
{HudControlIdentifier.TPStatusBar, CreateTPStatusBar()},
{HudControlIdentifier.SPStatusBar, CreateSPStatusBar()},
{HudControlIdentifier.TNLStatusBar, CreateTNLStatusBar()},
{HudControlIdentifier.ChatModePictureBox, CreateChatModePictureBox()},
{HudControlIdentifier.ChatTextBox, CreateChatTextBox()},
{HudControlIdentifier.ClockLabel, CreateClockLabel()},
{HudControlIdentifier.StatusLabel, CreateStatusLabel()},
{HudControlIdentifier.UsageTracker, CreateUsageTracker()},
{HudControlIdentifier.UserInputHandler, CreateUserInputHandler()},
{HudControlIdentifier.CharacterAnimator, characterAnimator},
{HudControlIdentifier.NPCAnimator, CreateNPCAnimator()},
{HudControlIdentifier.UnknownEntitiesRequester, CreateUnknownEntitiesRequester()},
{HudControlIdentifier.PeriodicEmoteHandler, CreatePeriodicEmoteHandler(characterAnimator)},
{HudControlIdentifier.PreviousUserInputTracker, CreatePreviousUserInputTracker()}
};
return controls;
}
private HudBackgroundFrame CreateHudBackground()
{
return new HudBackgroundFrame(_nativeGraphicsManager, _graphicsDeviceProvider)
{
DrawOrder = HUD_BASE_LAYER
};
}
private IXNAButton CreateStateChangeButton(InGameStates whichState)
{
if (whichState == InGameStates.News)
throw new ArgumentOutOfRangeException(nameof(whichState), "News state does not have a button associated with it");
var buttonIndex = (int) whichState;
var mainButtonTexture = _nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 25);
var widthDelta = mainButtonTexture.Width/2;
var heightDelta = mainButtonTexture.Height/11;
var xPosition = buttonIndex < 6 ? 62 : 590;
var yPosition = (buttonIndex < 6 ? 330 : 350) + (buttonIndex < 6 ? buttonIndex : buttonIndex - 6)*20;
var retButton = new XNAButton(
mainButtonTexture,
new Vector2(xPosition, yPosition),
new Rectangle(0, heightDelta * buttonIndex, widthDelta, heightDelta),
new Rectangle(widthDelta, heightDelta * buttonIndex, widthDelta, heightDelta))
{
DrawOrder = HUD_CONTROL_LAYER
};
retButton.OnClick += async (o, e) => await DoHudStateChangeClick(whichState);
retButton.OnMouseEnter += (o, e) => _statusLabelSetter.SetStatusLabel(
EOResourceID.STATUS_LABEL_TYPE_BUTTON,
EOResourceID.STATUS_LABEL_HUD_BUTTON_HOVER_FIRST + buttonIndex);
return retButton;
}
private IXNAButton CreateFriendListButton()
{
var button = new XNAButton(
_nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 27, false),
new Vector2(592, 312),
new Rectangle(0, 260, 17, 15),
new Rectangle(0, 276, 17, 15))
{
DrawOrder = HUD_CONTROL_LAYER
};
button.OnClick += async (o, e) => await _hudButtonController.ClickFriendList();
button.OnMouseOver += (o, e) => _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_BUTTON, EOResourceID.STATUS_LABEL_FRIEND_LIST);
return button;
}
private IXNAButton CreateIgnoreListButton()
{
var button = new XNAButton(
_nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 27, false),
new Vector2(609, 312),
new Rectangle(17, 260, 17, 15),
new Rectangle(17, 276, 17, 15))
{
DrawOrder = HUD_CONTROL_LAYER
};
button.OnClick += async (o, e) => await _hudButtonController.ClickIgnoreList();
button.OnMouseOver += (o, e) => _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_BUTTON, EOResourceID.STATUS_LABEL_IGNORE_LIST);
return button;
}
private async Task DoHudStateChangeClick(InGameStates whichState)
{
switch (whichState)
{
case InGameStates.Inventory: _hudButtonController.ClickInventory(); break;
case InGameStates.ViewMapToggle: _hudButtonController.ClickViewMapToggle(); break;
case InGameStates.ActiveSpells: _hudButtonController.ClickActiveSpells(); break;
case InGameStates.PassiveSpells: _hudButtonController.ClickPassiveSpells(); break;
case InGameStates.Chat:
_hudButtonController.ClickChat();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_CHAT_PANEL_NOW_VIEWED);
break;
case InGameStates.Stats:
_hudButtonController.ClickStats();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_STATS_PANEL_NOW_VIEWED);
break;
case InGameStates.OnlineList:
await _hudButtonController.ClickOnlineList();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_ONLINE_PLAYERS_NOW_VIEWED);
break;
case InGameStates.Party: _hudButtonController.ClickParty(); break;
case InGameStates.Macro: break;
case InGameStates.Settings: _hudButtonController.ClickSettings(); break;
case InGameStates.Help:
_hudButtonController.ClickHelp();
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_HUD_BUTTON_HOVER_LAST);
break;
default: throw new ArgumentOutOfRangeException(nameof(whichState), whichState, null);
}
}
private IGameComponent CreateStatePanel(InGameStates whichState)
{
IHudPanel retPanel;
switch (whichState)
{
case InGameStates.Inventory: retPanel = _hudPanelFactory.CreateInventoryPanel(); break;
case InGameStates.ActiveSpells: retPanel = _hudPanelFactory.CreateActiveSpellsPanel(); break;
case InGameStates.PassiveSpells: retPanel = _hudPanelFactory.CreatePassiveSpellsPanel(); break;
case InGameStates.Chat: retPanel = _hudPanelFactory.CreateChatPanel(); break;
case InGameStates.Stats: retPanel = _hudPanelFactory.CreateStatsPanel(); break;
case InGameStates.OnlineList: retPanel = _hudPanelFactory.CreateOnlineListPanel(); break;
case InGameStates.Party: retPanel = _hudPanelFactory.CreatePartyPanel(); break;
case InGameStates.Settings: retPanel = _hudPanelFactory.CreateSettingsPanel(); break;
case InGameStates.Help: retPanel = _hudPanelFactory.CreateHelpPanel(); break;
case InGameStates.News: retPanel = _hudPanelFactory.CreateNewsPanel(); break;
default: throw new ArgumentOutOfRangeException(nameof(whichState), whichState, "Panel specification is out of range.");
}
//news is visible by default when loading the game
if (whichState != InGameStates.News)
retPanel.Visible = false;
return retPanel;
}
private IGameComponent CreateSessionExpButton()
{
var btn = new XNAButton(
_nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 58, transparent: true),
new Vector2(55, 0),
new Rectangle(331, 30, 22, 14),
new Rectangle(331, 30, 22, 14))
{
DrawOrder = HUD_CONTROL_LAYER
};
btn.OnClick += (_, _) => _hudButtonController.ClickSessionExp();
return btn;
}
private IGameComponent CreateQuestButton()
{
var btn = new XNAButton(
_nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 58, transparent: true),
new Vector2(77, 0),
new Rectangle(353, 30, 22, 14),
new Rectangle(353, 30, 22, 14))
{
DrawOrder = HUD_CONTROL_LAYER
};
btn.OnClick += (_, _) => _hudButtonController.ClickQuestStatus();
return btn;
}
private IGameComponent CreateHPStatusBar()
{
return new HPStatusBar(_nativeGraphicsManager, (ICharacterProvider)_characterRepository, _userInputRepository)
{
DrawOrder = HUD_CONTROL_LAYER
};
}
private IGameComponent CreateTPStatusBar()
{
return new TPStatusBar(_nativeGraphicsManager, (ICharacterProvider)_characterRepository, _userInputRepository)
{
DrawOrder = HUD_CONTROL_LAYER
};
}
private IGameComponent CreateSPStatusBar()
{
return new SPStatusBar(_nativeGraphicsManager, (ICharacterProvider)_characterRepository, _userInputRepository)
{
DrawOrder = HUD_CONTROL_LAYER
};
}
private IGameComponent CreateTNLStatusBar()
{
return new TNLStatusBar(_nativeGraphicsManager, (ICharacterProvider)_characterRepository, _userInputRepository, _experienceTableProvider)
{
DrawOrder = HUD_CONTROL_LAYER
};
}
private ChatModePictureBox CreateChatModePictureBox()
{
var chatModesTexture = _nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 31);
var pictureBox = new ChatModePictureBox(_chatModeCalculator, _hudControlProvider, chatModesTexture)
{
DrawArea = new Rectangle(16, 309, chatModesTexture.Width, chatModesTexture.Height / 8),
SourceRectangle = new Rectangle(0, 0, chatModesTexture.Width, chatModesTexture.Height / 8),
DrawOrder = HUD_CONTROL_LAYER
};
return pictureBox;
}
private ChatTextBox CreateChatTextBox()
{
var chatTextBox = new ChatTextBox(_contentProvider)
{
Text = "",
Selected = true,
Visible = true,
DrawOrder = HUD_CONTROL_LAYER
};
chatTextBox.OnEnterPressed += (_, _) => _chatController.SendChatAndClearTextBox();
chatTextBox.OnClicked += (_, _) => _chatController.SelectChatTextBox();
return chatTextBox;
}
private TimeLabel CreateClockLabel()
{
return new TimeLabel(_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}
private UsageTrackerComponent CreateUsageTracker()
{
return new UsageTrackerComponent(_endlessGameProvider, _characterRepository);
}
private UnknownEntitiesRequester CreateUnknownEntitiesRequester()
{
return new UnknownEntitiesRequester(_endlessGameProvider, _currentMapStateRepository, _packetSendService);
}
private StatusBarLabel CreateStatusLabel()
{
return new StatusBarLabel(_clientWindowSizeProvider, _statusLabelTextProvider) { DrawOrder = HUD_CONTROL_LAYER };
}
private CurrentUserInputTracker CreateCurrentUserInputTracker()
{
return new CurrentUserInputTracker(_endlessGameProvider, _userInputRepository);
}
private IUserInputHandler CreateUserInputHandler()
{
return _userInputHandlerFactory.CreateUserInputHandler();
}
private ICharacterAnimator CreateCharacterAnimator()
{
return new CharacterAnimator(_endlessGameProvider, _characterRepository, _currentMapStateRepository, _currentMapProvider, _characterActions, _walkValidationActions, _pathFinder);
}
private INPCAnimator CreateNPCAnimator()
{
return new NPCAnimator(_endlessGameProvider, _currentMapStateRepository);
}
private IPeriodicEmoteHandler CreatePeriodicEmoteHandler(ICharacterAnimator characterAnimator)
{
return new PeriodicEmoteHandler(_endlessGameProvider, _characterActions, _userInputTimeProvider, _characterRepository, characterAnimator);
}
private PreviousUserInputTracker CreatePreviousUserInputTracker()
{
return new PreviousUserInputTracker(_endlessGameProvider, _userInputRepository);
}
}
}