Skip to content

Commit

Permalink
Fix map item text label rendering when the same item is in adjacent t…
Browse files Browse the repository at this point in the history
…iles

Fix map item draw/pickup ordering when multiple items are stacked on the same tile
  • Loading branch information
ethanmoffat committed Sep 14, 2022
1 parent 1a42a74 commit 43c9729
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion EOLib/Domain/Map/MapCellStateProvider.cs
Expand Up @@ -39,7 +39,7 @@ public IMapCellState GetCellStateAt(int x, int y)
var character = _mapStateProvider.Characters.Values.Concat(new[] { _characterProvider.MainCharacter })
.FirstOrNone(c => CharacterAtCoordinates(c, x, y));
var npc = _mapStateProvider.NPCs.FirstOrNone(n => NPCAtCoordinates(n, x, y));
var items = _mapStateProvider.MapItems.Where(i => i.X == x && i.Y == y);
var items = _mapStateProvider.MapItems.Where(i => i.X == x && i.Y == y).OrderByDescending(i => i.UniqueID);

return new MapCellState
{
Expand Down
Expand Up @@ -34,7 +34,10 @@ protected override bool ElementExistsAt(int row, int col)

public override void RenderElementAt(SpriteBatch spriteBatch, int row, int col, int alpha, Vector2 additionalOffset = default)
{
var items = _currentMapStateProvider.MapItems.Where(item => item.X == col && item.Y == row);
var items = _currentMapStateProvider
.MapItems
.Where(item => item.X == col && item.Y == row)
.OrderBy(item => item.UniqueID);

foreach (var item in items)
{
Expand Down
13 changes: 8 additions & 5 deletions EndlessClient/Rendering/MouseCursorRenderer.cs
Expand Up @@ -171,14 +171,21 @@ private void UpdateCursorSourceRectangle(IMapCellState cellState)
else if (cellState.Items.Any())
{
_cursorIndex = CursorIndex.HoverItem;
UpdateMapItemLabel(Option.Some(cellState.Items.Last()));
UpdateMapItemLabel(Option.Some(cellState.Items.First()));
}
else if (cellState.TileSpec != TileSpec.None)
UpdateCursorIndexForTileSpec(cellState.TileSpec);

if (!cellState.Items.Any())
UpdateMapItemLabel(Option.None<MapItem>());

if (_mapItemText.Visible)
{
//relative to cursor DrawPosition, since this control is a parent of MapItemText
_mapItemText.DrawPosition = new Vector2(DrawArea.X + 32 - _mapItemText.ActualWidth / 2f,
DrawArea.Y + -_mapItemText.ActualHeight - 4);
}

_startClickTime.MatchSome(st =>
{
if ((DateTime.Now - st).TotalMilliseconds > 350)
Expand Down Expand Up @@ -225,10 +232,6 @@ private void UpdateMapItemLabel(Option<MapItem> item)
_mapItemText.Text = text;
_mapItemText.ResizeBasedOnText();
_mapItemText.ForeColor = _itemNameColorService.GetColorForMapDisplay(data);
//relative to cursor DrawPosition, since this control is a parent of MapItemText
_mapItemText.DrawPosition = new Vector2(DrawArea.X + 32 - _mapItemText.ActualWidth / 2f,
DrawArea.Y + -_mapItemText.ActualHeight - 4);
}
},
none: () =>
Expand Down

0 comments on commit 43c9729

Please sign in to comment.