Initial refactor of mouse handling.
parent
f9fbbc4181
commit
bd29fae9ca
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using StardewValley;
|
||||
|
||||
namespace stardew_access.Features
|
||||
{
|
||||
public class MouseHandler
|
||||
{
|
||||
|
||||
public Vector2 ViewingOffset { get; set; } = Vector2.Zero;
|
||||
|
||||
public Vector2 PlayerFacingVector
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Game1.player.FacingDirection)
|
||||
{
|
||||
case 0:
|
||||
return new Vector2(0, - Game1.tileSize);
|
||||
case 1:
|
||||
return new Vector2(Game1.tileSize, 0);
|
||||
case 2:
|
||||
return new Vector2(0, Game1.tileSize);
|
||||
case 3:
|
||||
return new Vector2(-Game1.tileSize, 0);
|
||||
default:
|
||||
return Vector2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 PlayerPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
int x = Game1.player.GetBoundingBox().Center.X - Game1.viewport.X;
|
||||
int y = Game1.player.GetBoundingBox().Center.Y - Game1.viewport.Y;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public void SnapMouseToPlayer()
|
||||
{
|
||||
Vector2 snapPosition = this.PlayerPosition + this.PlayerFacingVector + this.ViewingOffset;
|
||||
if (Utility.isOnScreen(snapPosition, 0))
|
||||
Game1.setMousePosition((int)snapPosition.X, (int)snapPosition.Y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,32 +41,6 @@ namespace stardew_access.Features
|
|||
MainClass.ScreenReader.Say($"{currentLocation.Name} Entered", true);
|
||||
}
|
||||
|
||||
public static void SnapMouseToPlayer()
|
||||
{
|
||||
int x = Game1.player.GetBoundingBox().Center.X - Game1.viewport.X;
|
||||
int y = Game1.player.GetBoundingBox().Center.Y - Game1.viewport.Y;
|
||||
|
||||
int offset = 64;
|
||||
|
||||
switch (Game1.player.FacingDirection)
|
||||
{
|
||||
case 0:
|
||||
y -= offset;
|
||||
break;
|
||||
case 1:
|
||||
x += offset;
|
||||
break;
|
||||
case 2:
|
||||
y += offset;
|
||||
break;
|
||||
case 3:
|
||||
x -= offset;
|
||||
break;
|
||||
}
|
||||
|
||||
Game1.setMousePosition(x, y);
|
||||
}
|
||||
|
||||
public static void narrateHudMessages()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace stardew_access
|
|||
private static StaticTiles? sTiles;
|
||||
private static IScreenReader? screenReader;
|
||||
private static IModHelper? modHelper;
|
||||
private static MouseHandler? mouse;
|
||||
|
||||
internal static ModConfig Config { get => config; set => config = value; }
|
||||
public static IModHelper? ModHelper { get => modHelper; }
|
||||
|
@ -62,6 +63,17 @@ namespace stardew_access
|
|||
|
||||
set => screenReader = value;
|
||||
}
|
||||
|
||||
public static MouseHandler Mouse
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mouse == null)
|
||||
mouse = new MouseHandler();
|
||||
return mouse;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/*********
|
||||
|
@ -131,7 +143,7 @@ namespace stardew_access
|
|||
Other.narrateCurrentLocation();
|
||||
|
||||
if (Config.SnapMouse)
|
||||
Other.SnapMouseToPlayer();
|
||||
Mouse.SnapMouseToPlayer();
|
||||
|
||||
if (!ReadTile.isReadingTile && Config.ReadTile)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue