From 02bb18249976e52fab08f96529be25f592c288b6 Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Fri, 16 Sep 2022 14:11:14 -0700 Subject: [PATCH] Update detection for stacked characters to consider character draw area rather than mouse cursor's cell state --- .../CharacterRenderPropertiesExtensions.cs | 3 ++ .../Rendering/Character/CharacterRenderer.cs | 6 ++- EndlessClient/Rendering/IMapActor.cs | 4 ++ .../Rendering/Map/DynamicMapObjectUpdater.cs | 38 +++++++++++++++++++ .../Rendering/MouseCursorRenderer.cs | 33 ---------------- EndlessClient/Rendering/NPC/NPCRenderer.cs | 4 ++ 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs b/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs index 077b94f1f..fd72df3d4 100644 --- a/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs +++ b/EOLib/Domain/Extensions/CharacterRenderPropertiesExtensions.cs @@ -1,5 +1,6 @@ using System.Linq; using EOLib.Domain.Character; +using EOLib.Domain.Map; namespace EOLib.Domain.Extensions { @@ -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); } } diff --git a/EndlessClient/Rendering/Character/CharacterRenderer.cs b/EndlessClient/Rendering/Character/CharacterRenderer.cs index b1bcde8a8..5083fc7c6 100644 --- a/EndlessClient/Rendering/Character/CharacterRenderer.cs +++ b/EndlessClient/Rendering/Character/CharacterRenderer.cs @@ -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)); @@ -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) diff --git a/EndlessClient/Rendering/IMapActor.cs b/EndlessClient/Rendering/IMapActor.cs index c7148e562..0e2105772 100644 --- a/EndlessClient/Rendering/IMapActor.cs +++ b/EndlessClient/Rendering/IMapActor.cs @@ -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); diff --git a/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs b/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs index 57ee953af..224a2e164 100644 --- a/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs +++ b/EndlessClient/Rendering/Map/DynamicMapObjectUpdater.cs @@ -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; @@ -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; @@ -41,6 +43,7 @@ private class DoorTimePair private List _ambientSounds; public DynamicMapObjectUpdater(ICharacterProvider characterProvider, + ICharacterRendererProvider characterRendererProvider, ICurrentMapStateRepository currentMapStateRepository, IUserInputRepository userInputRepository, ICurrentMapProvider currentMapProvider, @@ -50,6 +53,7 @@ public DynamicMapObjectUpdater(ICharacterProvider characterProvider, ISfxPlayer sfxPlayer) { _characterProvider = characterProvider; + _characterRendererProvider = characterRendererProvider; _currentMapStateRepository = currentMapStateRepository; _userInputRepository = userInputRepository; _currentMapProvider = currentMapProvider; @@ -78,6 +82,7 @@ public void UpdateMapObjects(GameTime gameTime) UpdateAmbientNoiseVolume(); CheckForObjectClicks(); + HideStackedCharacterNames(); } private void OpenNewDoors(DateTime now) @@ -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 diff --git a/EndlessClient/Rendering/MouseCursorRenderer.cs b/EndlessClient/Rendering/MouseCursorRenderer.cs index 55767f00e..954a72b0d 100644 --- a/EndlessClient/Rendering/MouseCursorRenderer.cs +++ b/EndlessClient/Rendering/MouseCursorRenderer.cs @@ -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; @@ -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; @@ -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) diff --git a/EndlessClient/Rendering/NPC/NPCRenderer.cs b/EndlessClient/Rendering/NPC/NPCRenderer.cs index 2b3a8a3c1..85f6bad43 100644 --- a/EndlessClient/Rendering/NPC/NPCRenderer.cs +++ b/EndlessClient/Rendering/NPC/NPCRenderer.cs @@ -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; }