Skip to content

Commit

Permalink
Update detection for stacked characters to consider character draw ar…
Browse files Browse the repository at this point in the history
…ea rather than mouse cursor's cell state
  • Loading branch information
ethanmoffat committed Sep 16, 2022
1 parent c47e2d6 commit 02bb182
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using EOLib.Domain.Character;
using EOLib.Domain.Map;

namespace EOLib.Domain.Extensions
{
Expand Down Expand Up @@ -113,5 +114,7 @@ public static CharacterRenderProperties ResetAnimationFrames(this CharacterRende
props.CurrentAction = props.SitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting;
return props.ToImmutable();
}

public static MapCoordinate Coordinates(this CharacterRenderProperties rp) => new MapCoordinate(rp.MapX, rp.MapY);
}
}
6 changes: 5 additions & 1 deletion EndlessClient/Rendering/Character/CharacterRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public EOLib.Domain.Character.Character Character

public int TopPixelWithOffset => TopPixel + DrawArea.Y;

public bool MouseOver => DrawArea.Contains(_userInputProvider.CurrentMouseState.Position);

public bool MouseOverPreviously => DrawArea.Contains(_userInputProvider.PreviousMouseState.Position);

public Rectangle EffectTargetArea
=> DrawArea.WithPosition(new Vector2(DrawArea.X, DrawArea.Y - 8));

Expand Down Expand Up @@ -190,7 +194,7 @@ public override void Update(GameTime gameTime)
{
UpdateNameLabel();

if (DrawArea.Contains(_userInputProvider.CurrentMouseState.Position))
if (MouseOver)
{
if (_userInputProvider.CurrentMouseState.RightButton == ButtonState.Released &&
_userInputProvider.PreviousMouseState.RightButton == ButtonState.Pressed)
Expand Down
4 changes: 4 additions & 0 deletions EndlessClient/Rendering/IMapActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface IMapActor

Rectangle MapProjectedDrawArea { get; }

bool MouseOver { get; }

bool MouseOverPreviously { get; }

void ShowDamageCounter(int damage, int percentHealth, bool isHeal);

void ShowChatBubble(string text, bool isGroupChat = false);
Expand Down
38 changes: 38 additions & 0 deletions EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EndlessClient.Audio;
using EndlessClient.Controllers;
using EndlessClient.Input;
using EndlessClient.Rendering.Character;
using EOLib.Config;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
Expand All @@ -28,6 +29,7 @@ private class DoorTimePair
}

private readonly ICharacterProvider _characterProvider;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IUserInputRepository _userInputRepository;
private readonly ICurrentMapProvider _currentMapProvider;
Expand All @@ -41,6 +43,7 @@ private class DoorTimePair
private List<MapCoordinate> _ambientSounds;

public DynamicMapObjectUpdater(ICharacterProvider characterProvider,
ICharacterRendererProvider characterRendererProvider,
ICurrentMapStateRepository currentMapStateRepository,
IUserInputRepository userInputRepository,
ICurrentMapProvider currentMapProvider,
Expand All @@ -50,6 +53,7 @@ public DynamicMapObjectUpdater(ICharacterProvider characterProvider,
ISfxPlayer sfxPlayer)
{
_characterProvider = characterProvider;
_characterRendererProvider = characterRendererProvider;
_currentMapStateRepository = currentMapStateRepository;
_userInputRepository = userInputRepository;
_currentMapProvider = currentMapProvider;
Expand Down Expand Up @@ -78,6 +82,7 @@ public void UpdateMapObjects(GameTime gameTime)
UpdateAmbientNoiseVolume();

CheckForObjectClicks();
HideStackedCharacterNames();
}

private void OpenNewDoors(DateTime now)
Expand Down Expand Up @@ -177,6 +182,39 @@ private void CheckForObjectClicks()
// todo: check for board object clicks
}
}

private void HideStackedCharacterNames()
{
var characters = _characterRendererProvider.CharacterRenderers.Values
.Where(x => x.MouseOver)
.GroupBy(x => x.Character.RenderProperties.Coordinates());

foreach (var grouping in characters)
{
if (grouping.Count() > 1)
{
var isFirst = true;
foreach (var character in grouping.Reverse())
{
if (isFirst)
{
character.ShowName();
}
else
{
character.HideName();
}

isFirst = false;
}
}
else
{
foreach (var character in grouping)
character.ShowName();
}
}
}
}

public interface IDynamicMapObjectUpdater
Expand Down
33 changes: 0 additions & 33 deletions EndlessClient/Rendering/MouseCursorRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private enum CursorIndex

private readonly Texture2D _mouseCursorTexture;
private readonly ICharacterProvider _characterProvider;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly IRenderOffsetCalculator _renderOffsetCalculator;
private readonly IMapCellStateProvider _mapCellStateProvider;
private readonly IItemStringService _itemStringService;
Expand Down Expand Up @@ -80,7 +79,6 @@ public MouseCursorRenderer(INativeGraphicsManager nativeGraphicsManager,
{
_mouseCursorTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 24, true);
_characterProvider = characterProvider;
_characterRendererProvider = characterRendererProvider;
_renderOffsetCalculator = renderOffsetCalculator;
_mapCellStateProvider = mapCellStateProvider;
_itemStringService = itemStringService;
Expand Down Expand Up @@ -191,37 +189,6 @@ private void UpdateCursorSourceRectangle(IMapCellState cellState)
DrawArea.Y + -_mapItemText.ActualHeight - 4);
}

if (cellState.Characters.Count > 1)
{
var isFirst = true;
foreach (var character in cellState.Characters.Reverse())
{
if (_characterRendererProvider.CharacterRenderers.ContainsKey(character.ID))
{
if (isFirst)
{
_characterRendererProvider.CharacterRenderers[character.ID].ShowName();
}
else
{
_characterRendererProvider.CharacterRenderers[character.ID].HideName();
}
}

isFirst = false;
}
}
else
{
foreach (var character in cellState.Characters)
{
if (_characterRendererProvider.CharacterRenderers.ContainsKey(character.ID))
{
_characterRendererProvider.CharacterRenderers[character.ID].ShowName();
}
}
}

_startClickTime.MatchSome(st =>
{
if ((DateTime.Now - st).TotalMilliseconds > 350)
Expand Down
4 changes: 4 additions & 0 deletions EndlessClient/Rendering/NPC/NPCRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public class NPCRenderer : DrawableGameComponent, INPCRenderer

public Rectangle MapProjectedDrawArea { get; private set; }

public bool MouseOver => DrawArea.Contains(_userInputProvider.CurrentMouseState.Position);

public bool MouseOverPreviously => DrawArea.Contains(_userInputProvider.PreviousMouseState.Position);

public EOLib.Domain.NPC.NPC NPC { get; set; }

public bool IsDead { get; private set; }
Expand Down

0 comments on commit 02bb182

Please sign in to comment.