using System; namespace NHSE.Core; public abstract class MapView(MapManager m, int scale = 16) { private const int ViewInterval = 2; public readonly MapManager Map = m; public int MapScale { get; } = 1; public int AcreScale { get; } = scale; public int TerrainScale => AcreScale * 2; // Top Left Anchor Coordinates public int X { get; set; } public int Y { get; set; } public bool CanUp => Y != 0; public bool CanDown => Y < Map.CurrentLayer.TileInfo.TotalHeight - Map.CurrentLayer.TileInfo.ViewHeight; public bool CanLeft => X != 0; public bool CanRight => X < Map.CurrentLayer.TileInfo.TotalWidth - Map.CurrentLayer.TileInfo.ViewWidth; public bool ArrowUp() { if (Y <= 0) return false; Y -= ViewInterval; return true; } public bool ArrowLeft() { if (X <= 0) return false; X -= ViewInterval; return true; } public bool ArrowRight() { if (X >= Map.CurrentLayer.TileInfo.TotalWidth - 2) return false; X += ViewInterval; return true; } public bool ArrowDown() { if (Y >= Map.CurrentLayer.TileInfo.TotalHeight - ViewInterval) return false; Y += ViewInterval; return true; } public bool SetViewTo(in int x, in int y) { var info = Map.CurrentLayer; var newX = Math.Max(0, Math.Min(x, info.TileInfo.TotalWidth - info.TileInfo.ViewWidth)); var newY = Math.Max(0, Math.Min(y, info.TileInfo.TotalHeight - info.TileInfo.ViewHeight)); bool diff = X != newX || Y != newY; X = newX; Y = newY; return diff; } public void SetViewToAcre(in int acre) { var layer = Map.Items.Layer1; layer.GetViewAnchorCoordinates(acre, out var x, out var y); SetViewTo(x, y); } public int ModifyFieldItems(Func action, in bool wholeMap) { var layer = Map.CurrentLayer; return wholeMap ? action(0, 0, layer.TileInfo.TotalWidth, layer.TileInfo.TotalHeight) : action(X, Y, layer.TileInfo.ViewWidth, layer.TileInfo.ViewHeight); } public int ReplaceFieldItems(Item oldItem, Item newItem, in bool wholeMap) { var layer = Map.CurrentLayer; return wholeMap ? layer.ReplaceAll(oldItem, newItem, 0, 0, layer.TileInfo.TotalWidth, layer.TileInfo.TotalHeight) : layer.ReplaceAll(oldItem, newItem, X, Y, layer.TileInfo.ViewWidth, layer.TileInfo.ViewHeight); } public void GetCursorCoordinates(in int mX, in int mY, out int x, out int y) { x = mX / MapScale; y = mY / MapScale; } public void GetViewAnchorCoordinates(int mX, int mY, out int x, out int y, bool centerReticle) { GetCursorCoordinates(mX, mY, out x, out y); var layer = Map.Items.Layer1; layer.TileInfo.GetViewAnchorCoordinates(ref x, ref y, centerReticle); } }