Skip to content

Commit

Permalink
Do character login by pressing number for character
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokya committed Mar 27, 2022
1 parent 8a7a7f3 commit 2231663
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
12 changes: 10 additions & 2 deletions EndlessClient/ControlSets/ControlSetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ControlSetFactory : IControlSetFactory
private readonly IConfigurationProvider _configProvider;
private readonly ICharacterInfoPanelFactory _characterInfoPanelFactory;
private readonly ICharacterSelectorProvider _characterSelectorProvider;
private readonly IEndlessGameProvider _endlessGameProvider;
private readonly IUserInputRepository _userInputRepository;
private IMainButtonController _mainButtonController;
private IAccountController _accountController;
private ILoginController _loginController;
Expand All @@ -36,7 +38,9 @@ public ControlSetFactory(INativeGraphicsManager nativeGraphicsManager,
IKeyboardDispatcherProvider keyboardDispatcherProvider,
IConfigurationProvider configProvider,
ICharacterInfoPanelFactory characterInfoPanelFactory,
ICharacterSelectorProvider characterSelectorProvider)
ICharacterSelectorProvider characterSelectorProvider,
IEndlessGameProvider endlessGameProvider,
IUserInputRepository userInputRepository)
{
_nativeGraphicsManager = nativeGraphicsManager;
_messageBoxFactory = messageBoxFactory;
Expand All @@ -46,6 +50,8 @@ public ControlSetFactory(INativeGraphicsManager nativeGraphicsManager,
_configProvider = configProvider;
_characterInfoPanelFactory = characterInfoPanelFactory;
_characterSelectorProvider = characterSelectorProvider;
_endlessGameProvider = endlessGameProvider;
_userInputRepository = userInputRepository;
}

public IControlSet CreateControlsForState(GameStates newState, IControlSet currentControlSet)
Expand Down Expand Up @@ -95,7 +101,9 @@ private IControlSet GetSetBasedOnState(GameStates newState)
_characterInfoPanelFactory,
_characterSelectorProvider,
_characterManagementController,
_accountController);
_accountController,
_endlessGameProvider,
_userInputRepository);
case GameStates.PlayingTheGame:
return new InGameControlSet(_mainButtonController, _messageBoxFactory, _hudControlsFactory);
default: throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
Expand Down
10 changes: 9 additions & 1 deletion EndlessClient/ControlSets/LoggedInControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Input;
using EndlessClient.UIControls;
using EOLib.Domain.Login;
using Microsoft.Xna.Framework;
Expand All @@ -16,6 +17,8 @@ public class LoggedInControlSet : IntermediateControlSet
private readonly ICharacterSelectorProvider _characterSelectorProvider;
private readonly ICharacterManagementController _characterManagementController;
private readonly IAccountController _accountController;
private readonly IEndlessGameProvider _endlessGameProvider;
private readonly IUserInputRepository _userInputRepository;
private readonly List<CharacterInfoPanel> _characterInfoPanels;

private IXNAButton _changePasswordButton;
Expand All @@ -29,13 +32,17 @@ public LoggedInControlSet(KeyboardDispatcher dispatcher,
ICharacterInfoPanelFactory characterInfoPanelFactory,
ICharacterSelectorProvider characterSelectorProvider,
ICharacterManagementController characterManagementController,
IAccountController accountController)
IAccountController accountController,
IEndlessGameProvider endlessGameProvider,
IUserInputRepository userInputRepository)
: base(dispatcher, mainButtonController)
{
_characterInfoPanelFactory = characterInfoPanelFactory;
_characterSelectorProvider = characterSelectorProvider;
_characterManagementController = characterManagementController;
_accountController = accountController;
_endlessGameProvider = endlessGameProvider;
_userInputRepository = userInputRepository;
_characterInfoPanels = new List<CharacterInfoPanel>();
}

Expand All @@ -46,6 +53,7 @@ protected override void InitializeControlsHelper(IControlSet currentControlSet)
_changePasswordButton = GetControl(currentControlSet, GameControlIdentifier.ChangePasswordButton, GetPasswordButton);
_characterInfoPanels.AddRange(_characterInfoPanelFactory.CreatePanels(_characterSelectorProvider.Characters));

_allComponents.Add(new CurrentUserInputTracker(_endlessGameProvider, _userInputRepository));
_allComponents.Add(_changePasswordButton);
_allComponents.AddRange(_characterInfoPanels);
}
Expand Down
14 changes: 13 additions & 1 deletion EndlessClient/UIControls/CharacterInfoPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using EndlessClient.Controllers;
using EndlessClient.Dialogs.Services;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Factories;
using EndlessClient.Rendering.Sprites;
Expand All @@ -24,19 +25,22 @@ public class CharacterInfoPanel : XNAControl
private readonly IRendererRepositoryResetter _rendererRepositoryResetter;
private readonly CharacterControl _characterControl;
private readonly ISpriteSheet _adminGraphic;
private readonly IUserInputProvider _userInputProvider;

private readonly Texture2D _backgroundImage;

private readonly IXNAButton _loginButton, _deleteButton;
private readonly IXNALabel _nameLabel, _levelLabel;

private int _clickRequests;
private readonly int _characterIndex;

//top left - 334, 36 + ndx*124
protected CharacterInfoPanel(int characterIndex,
INativeGraphicsManager gfxManager,
IEODialogButtonService dialogButtonService)
{
_characterIndex = characterIndex;
_gfxManager = gfxManager;
DrawPosition = new Vector2(334, 36 + characterIndex*124);

Expand Down Expand Up @@ -64,13 +68,15 @@ public CharacterInfoPanel(int characterIndex,
ILoginController loginController,
ICharacterManagementController characterManagementController,
ICharacterRendererFactory rendererFactory,
IRendererRepositoryResetter rendererRepositoryResetter)
IRendererRepositoryResetter rendererRepositoryResetter,
IUserInputProvider userInputProvider)
: this(characterIndex, gfxManager, dialogButtonService)
{
_character = character;
_loginController = loginController;
_characterManagementController = characterManagementController;
_rendererRepositoryResetter = rendererRepositoryResetter;
_userInputProvider = userInputProvider;

_characterControl = new CharacterControl(character, rendererFactory)
{
Expand Down Expand Up @@ -168,6 +174,12 @@ protected virtual async Task DeleteButtonClick()
protected virtual void DoUpdateLogic(GameTime gameTime)
{
_characterControl.Update(gameTime);

var keyboardState = _userInputProvider.CurrentKeyState;
if (keyboardState.IsKeyDown((Microsoft.Xna.Framework.Input.Keys)49+_characterIndex))
{
Task.Run(async () => await LoginButtonClick());
}
}

protected virtual void DoDrawLogic(GameTime gameTime)
Expand Down
15 changes: 8 additions & 7 deletions EndlessClient/UIControls/CharacterInfoPanelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
using AutomaticTypeMapper;
using EndlessClient.Controllers;
using EndlessClient.Dialogs.Services;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Factories;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Graphics;

namespace EndlessClient.UIControls
{
[AutoMappedType(IsSingleton = true)]
public class CharacterInfoPanelFactory : ICharacterInfoPanelFactory
{
private readonly ICharacterSelectorProvider _characterProvider;
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly ICharacterRendererFactory _characterRendererFactory;
private readonly IRendererRepositoryResetter _rendererRepositoryResetter;
private readonly IEODialogButtonService _eoDialogButtonService;
private readonly IUserInputProvider _userInputProvider;

private ILoginController _loginController;
private ICharacterManagementController _characterManagementController;

public CharacterInfoPanelFactory(ICharacterSelectorProvider characterProvider,
INativeGraphicsManager nativeGraphicsManager,
public CharacterInfoPanelFactory(INativeGraphicsManager nativeGraphicsManager,
ICharacterRendererFactory characterRendererFactory,
IRendererRepositoryResetter rendererRepositoryResetter,
IEODialogButtonService eoDialogButtonService)
IEODialogButtonService eoDialogButtonService,
IUserInputProvider userInputProvider)
{
_characterProvider = characterProvider;
_nativeGraphicsManager = nativeGraphicsManager;
_characterRendererFactory = characterRendererFactory;
_rendererRepositoryResetter = rendererRepositoryResetter;
_eoDialogButtonService = eoDialogButtonService;
_userInputProvider = userInputProvider;
}

public void InjectLoginController(ILoginController loginController)
Expand Down Expand Up @@ -61,7 +61,8 @@ public IEnumerable<CharacterInfoPanel> CreatePanels(IEnumerable<ICharacter> char
_loginController,
_characterManagementController,
_characterRendererFactory,
_rendererRepositoryResetter);
_rendererRepositoryResetter,
_userInputProvider);
}

for (; i < 3; ++i)
Expand Down

0 comments on commit 2231663

Please sign in to comment.