Skip to content

Commit

Permalink
Move right-click detection to character renderer. Makes it easier to …
Browse files Browse the repository at this point in the history
…get a right-click action
  • Loading branch information
ethanmoffat committed Mar 24, 2022
1 parent cf4c2c3 commit d93c57c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions EndlessClient/Rendering/Character/CharacterRenderer.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Rendering.CharacterProperties;
using EndlessClient.Rendering.Chat;
Expand All @@ -23,6 +24,7 @@ namespace EndlessClient.Rendering.Character
{
public class CharacterRenderer : DrawableGameComponent, ICharacterRenderer
{
private readonly IMapInteractionController _mapInteractionController;
private readonly IRenderTargetFactory _renderTargetFactory;
private readonly IHealthBarRendererFactory _healthBarRendererFactory;
private readonly IChatBubbleFactory _chatBubbleFactory;
Expand Down Expand Up @@ -78,6 +80,7 @@ public Rectangle EffectTargetArea

public CharacterRenderer(INativeGraphicsManager nativeGraphicsmanager,
Game game,
IMapInteractionController mapInteractionController,
IRenderTargetFactory renderTargetFactory,
IHealthBarRendererFactory healthBarRendererFactory,
IChatBubbleFactory chatBubbleFactory,
Expand All @@ -91,6 +94,7 @@ public Rectangle EffectTargetArea
ICurrentMapProvider currentMapProvider)
: base(game)
{
_mapInteractionController = mapInteractionController;
_renderTargetFactory = renderTargetFactory;
_healthBarRendererFactory = healthBarRendererFactory;
_chatBubbleFactory = chatBubbleFactory;
Expand Down Expand Up @@ -171,8 +175,17 @@ public override void Update(GameTime gameTime)
SetGridCoordinatePosition();

if (_gameStateProvider.CurrentState == GameStates.PlayingTheGame)
{
UpdateNameLabel(gameTime);

if (DrawArea.ContainsPoint(_currentMouseState.X, _currentMouseState.Y) &&
_currentMouseState.RightButton == ButtonState.Released &&
_previousMouseState.RightButton == ButtonState.Pressed)
{
_mapInteractionController.RightClick(new MapCellState { Character = Option.Some(Character) });
}
}

_healthBarRenderer.Update(gameTime);

_previousMouseState = _currentMouseState;
Expand Down
5 changes: 5 additions & 0 deletions EndlessClient/Rendering/Factories/CharacterRendererFactory.cs
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.CharacterProperties;
Expand All @@ -16,6 +17,7 @@ public class CharacterRendererFactory : ICharacterRendererFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEndlessGameProvider _gameProvider;
private readonly IMapInteractionController _mapInteractionController;
private readonly IRenderTargetFactory _renderTargetFactory;
private readonly IHealthBarRendererFactory _healthBarRendererFactory;
private readonly IChatBubbleFactory _chatBubbleFactory;
Expand All @@ -29,6 +31,7 @@ public class CharacterRendererFactory : ICharacterRendererFactory

public CharacterRendererFactory(INativeGraphicsManager nativeGraphicsManager,
IEndlessGameProvider gameProvider,
IMapInteractionController mapInteractionController,
IRenderTargetFactory renderTargetFactory,
IHealthBarRendererFactory healthBarRendererFactory,
IChatBubbleFactory chatBubbleFactory,
Expand All @@ -42,6 +45,7 @@ public class CharacterRendererFactory : ICharacterRendererFactory
{
_nativeGraphicsManager = nativeGraphicsManager;
_gameProvider = gameProvider;
_mapInteractionController = mapInteractionController;
_renderTargetFactory = renderTargetFactory;
_healthBarRendererFactory = healthBarRendererFactory;
_chatBubbleFactory = chatBubbleFactory;
Expand All @@ -59,6 +63,7 @@ public ICharacterRenderer CreateCharacterRenderer(ICharacter character)
return new CharacterRenderer(
_nativeGraphicsManager,
(Game) _gameProvider.Game,
_mapInteractionController,
_renderTargetFactory,
_healthBarRendererFactory,
_chatBubbleFactory,
Expand Down
7 changes: 1 addition & 6 deletions EndlessClient/Rendering/MouseCursorRenderer.cs
Expand Up @@ -298,17 +298,12 @@ private async Task CheckForClicks(IMapCellState cellState)
var currentMouseState = _userInputProvider.CurrentMouseState;
var previousMouseState = _userInputProvider.PreviousMouseState;

// todo: some left clicks should be on the graphic itself instead of based on the grid where the cursor is (NPC, map sign, board, etc.)
if (currentMouseState.LeftButton == ButtonState.Released &&
previousMouseState.LeftButton == ButtonState.Pressed)
{
await _mapInteractionController.LeftClickAsync(cellState, this);
}
else if (currentMouseState.RightButton == ButtonState.Released &&
previousMouseState.RightButton == ButtonState.Pressed)
{
// todo: right click should be called from character renderer, not MouseCursorRenderer
_mapInteractionController.RightClick(cellState);
}
}

#endregion
Expand Down

0 comments on commit d93c57c

Please sign in to comment.