@@ -80,8 +80,7 @@ public override void performHoverAction(int x, int y)
8080 string [ ] hoveredNames ;
8181 bool hasIndoorCharacters ;
8282 {
83- const int markerWidth = 32 ;
84- const int markerHeight = 30 ;
83+ Point markerSize = this . GetNpcIconSize ( ) ;
8584
8685 string regionId = this . RegionId ;
8786 Point mousePos = Game1 . getMousePosition ( ) ;
@@ -94,7 +93,7 @@ public override void performHoverAction(int x, int y)
9493 {
9594 foreach ( ( string npcName , NpcMarker npcMarker ) in this . NpcMarkers )
9695 {
97- if ( npcMarker . IsHidden || npcMarker . WorldMapRegionId != regionId || ! this . IsMapPixelUnderCursor ( mousePos , npcMarker . WorldMapX , npcMarker . WorldMapY , markerWidth , markerHeight ) )
96+ if ( npcMarker . IsHidden || npcMarker . WorldMapRegionId != regionId || ! this . IsMapPixelUnderCursor ( mousePos , npcMarker . WorldMapX , npcMarker . WorldMapY , markerSize . X , markerSize . Y ) )
9897 continue ;
9998
10099 newHoveredNames . Add ( this . GetNpcDisplayName ( npcMarker . DisplayName ?? npcName ) ) ;
@@ -107,7 +106,7 @@ public override void performHoverAction(int x, int y)
107106 {
108107 foreach ( FarmerMarker farmerMarker in this . FarmerMarkers . Values )
109108 {
110- if ( farmerMarker . WorldMapRegionId != regionId || ! this . IsMapPixelUnderCursor ( mousePos , farmerMarker . WorldMapX , farmerMarker . WorldMapY , markerWidth / 2 , markerHeight / 2 ) )
109+ if ( farmerMarker . WorldMapRegionId != regionId || ! this . IsMapPixelUnderCursor ( mousePos , farmerMarker . WorldMapX , farmerMarker . WorldMapY , markerSize . X , markerSize . Y ) )
111110 continue ;
112111
113112 newHoveredNames . Add ( farmerMarker . Name ) ;
@@ -124,7 +123,7 @@ public override void performHoverAction(int x, int y)
124123 {
125124 foreach ( ( string npcName , NpcMarker npcMarker ) in this . NpcMarkers )
126125 {
127- if ( ! npcMarker . IsHidden && npcMarker . LocationName != null && indoorLocationNames . Contains ( npcMarker . LocationName ) )
126+ if ( npcMarker is { IsHidden : false , LocationName : not null } && indoorLocationNames . Contains ( npcMarker . LocationName ) )
128127 newHoveredNames . Add ( this . GetNpcDisplayName ( npcMarker . DisplayName ?? npcName ) ) ;
129128 }
130129 }
@@ -254,8 +253,7 @@ public override void drawTooltip(SpriteBatch b)
254253
255254 // Draw indoor icon
256255 if ( this . HasIndoorCharacter && ! string . IsNullOrEmpty ( this . HoveredNames ) )
257- b . Draw ( Game1 . mouseCursors , this . IndoorIconVector , new Rectangle ( 448 , 64 , 32 , 32 ) , Color . White , 0f ,
258- Vector2 . Zero , 0.75f , SpriteEffects . None , 0f ) ;
256+ b . Draw ( Game1 . mouseCursors , this . IndoorIconVector , new Rectangle ( 448 , 64 , 32 , 32 ) , Color . White , 0f , Vector2 . Zero , 0.75f , SpriteEffects . None , 0f ) ;
259257 }
260258
261259
@@ -299,6 +297,8 @@ private void DrawMarkers(SpriteBatch b, float alpha)
299297 . Where ( p => p . Value . WorldMapRegionId == regionId )
300298 . OrderBy ( p => p . Value . Layer ) ;
301299
300+ Point markerSize = this . GetNpcIconSize ( ) ;
301+
302302 foreach ( ( string name , NpcMarker marker ) in sortedMarkers )
303303 {
304304 // skip if invalid
@@ -326,22 +326,11 @@ private void DrawMarkers(SpriteBatch b, float alpha)
326326 Rectangle iconDestinationRect ;
327327 {
328328 Rectangle iconSpriteRect = marker . GetSpriteSourceRect ( ) ;
329- float iconScale ;
329+ float iconScale = iconSpriteRect . Width > iconSpriteRect . Height
330+ ? markerSize . X / ( ( float ) iconSpriteRect . Width )
331+ : markerSize . Y / ( ( float ) iconSpriteRect . Height ) ;
330332
331- if ( ModEntry . Config . NpcIconStyle == NpcIconStyle . Vanilla )
332- {
333- iconScale = iconSpriteRect . Width > iconSpriteRect . Height
334- ? 36f / iconSpriteRect . Width
335- : 34f / iconSpriteRect . Height ;
336- }
337- else
338- {
339- iconScale = iconSpriteRect . Width > iconSpriteRect . Height
340- ? 32f / iconSpriteRect . Width
341- : 30f / iconSpriteRect . Height ;
342- }
343-
344- float iconWidth = ( int ) ( iconSpriteRect . Width * iconScale * scaleMultiplier ) ;
333+ float iconWidth = ( int ) ( iconSpriteRect . Width * iconScale * scaleMultiplier ) ;
345334 float iconHeight = ( int ) ( iconSpriteRect . Height * iconScale * scaleMultiplier ) ;
346335
347336 iconDestinationRect = new Rectangle (
@@ -505,9 +494,17 @@ private bool IsMapPixelUnderCursor(Point mousePos, int worldMapX, int worldMapY,
505494 int y = this . mapBounds . Y + worldMapY ;
506495
507496 return
508- mousePos . X >= x
509- && mousePos . X <= x + markerWidth
510- && mousePos . Y >= y
511- && mousePos . Y <= y + markerHeight ;
497+ mousePos . X >= x - ( markerWidth / 2 )
498+ && mousePos . X <= x + ( markerWidth / 2 )
499+ && mousePos . Y >= y - ( markerHeight / 2 )
500+ && mousePos . Y <= y + ( markerHeight / 2 ) ;
501+ }
502+
503+ /// <summary>Get the NPC icon sprite size, before scaling.</summary>
504+ private Point GetNpcIconSize ( )
505+ {
506+ return ModEntry . Config . NpcIconStyle == NpcIconStyle . Vanilla
507+ ? new Point ( 36 , 34 )
508+ : new Point ( 32 , 30 ) ;
512509 }
513510}
0 commit comments