mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-28 22:04:11 -05:00
98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using NHSE.Core;
|
|
|
|
namespace NHSE.Sprites;
|
|
|
|
/// <summary>
|
|
/// Produces bitmaps for viewing map acres and full maps.
|
|
/// </summary>
|
|
public sealed class MapViewer : MapView, IDisposable
|
|
{
|
|
private const byte ScaleAsMap = 2;
|
|
private const byte FieldItemWidthOld = 7;
|
|
private const byte FieldItemWidthNew = 9;
|
|
|
|
// Cached acre view objects to remove allocation/GC
|
|
private readonly int[] PixelsItemAcre1;
|
|
private readonly int[] PixelsItemAcreX;
|
|
private readonly Bitmap ScaleAcre;
|
|
private readonly int[] PixelsItemMap;
|
|
private readonly Bitmap MapReticle;
|
|
|
|
private readonly int[] PixelsBackgroundAcre1;
|
|
private readonly int[] PixelsBackgroundAcreX;
|
|
private readonly Bitmap BackgroundAcre;
|
|
private readonly int[] PixelsBackgroundMap1;
|
|
private readonly int[] PixelsBackgroundMapX;
|
|
private readonly Bitmap BackgroundMap;
|
|
|
|
public MapViewer(MapManager m, int scale) : base(m, scale)
|
|
{
|
|
var l1 = m.Items.Layer1;
|
|
var info = l1.TileInfo;
|
|
PixelsItemAcre1 = new int[info.ViewWidth * info.ViewHeight];
|
|
PixelsItemAcreX = new int[PixelsItemAcre1.Length * AcreScale * AcreScale];
|
|
ScaleAcre = new Bitmap(info.ViewWidth * AcreScale, info.ViewHeight * AcreScale);
|
|
|
|
PixelsItemMap = new int[info.TotalWidth * info.TotalHeight * MapScale * MapScale];
|
|
MapReticle = new Bitmap(info.TotalWidth * MapScale, info.TotalHeight * MapScale);
|
|
|
|
PixelsBackgroundAcre1 = new int[(int)Math.Pow(16, 4)];
|
|
PixelsBackgroundAcreX = new int[PixelsItemAcreX.Length];
|
|
BackgroundAcre = new Bitmap(ScaleAcre.Width, ScaleAcre.Height);
|
|
|
|
PixelsBackgroundMap1 = new int[PixelsItemMap.Length / 4];
|
|
PixelsBackgroundMapX = new int[PixelsItemMap.Length];
|
|
BackgroundMap = new Bitmap(MapReticle.Width, MapReticle.Height);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
ScaleAcre.Dispose();
|
|
MapReticle.Dispose();
|
|
BackgroundAcre.Dispose();
|
|
BackgroundMap.Dispose();
|
|
}
|
|
|
|
public Bitmap GetLayerAcre(int t) => GetLayerAcre(X, Y, t);
|
|
public Bitmap GetMapWithReticle(int t) => GetMapWithReticle(X, Y, t, Map.CurrentLayer);
|
|
|
|
public Bitmap GetBackgroundTerrain(int index = -1)
|
|
{
|
|
return TerrainSprite.GetMapWithBuildings(Map, null, PixelsBackgroundMap1, PixelsBackgroundMapX, BackgroundMap, ScaleAsMap, index);
|
|
}
|
|
|
|
public Bitmap GetInflatedImage(Bitmap regular)
|
|
{
|
|
// Insert 1 acre on each side
|
|
int columnWidth = (regular.Width / FieldItemWidthOld);
|
|
var newWidth = columnWidth * FieldItemWidthNew;
|
|
var bmp = new Bitmap(newWidth, regular.Height);
|
|
using var g = Graphics.FromImage(bmp);
|
|
|
|
// Fill with blue
|
|
// g.Clear(Color.FromArgb(100, 149, 237));
|
|
|
|
// Draw regular centered to new bitmap
|
|
g.DrawImage(regular, columnWidth, 0, regular.Width, regular.Height);
|
|
|
|
return bmp;
|
|
}
|
|
|
|
private Bitmap GetLayerAcre(int topX, int topY, int transparency)
|
|
{
|
|
var layer = Map.CurrentLayer;
|
|
return ItemLayerSprite.GetBitmapItemLayerViewGrid(layer, topX, topY, AcreScale, PixelsItemAcre1, PixelsItemAcreX, ScaleAcre, transparency);
|
|
}
|
|
|
|
public Bitmap GetBackgroundAcre(Font f, byte transparencyBuilding, byte transparencyTerrain, int index = -1)
|
|
{
|
|
return TerrainSprite.GetAcre(this, f, PixelsBackgroundAcre1, PixelsBackgroundAcreX, BackgroundAcre, index, transparencyBuilding, transparencyTerrain);
|
|
}
|
|
|
|
private Bitmap GetMapWithReticle(int topX, int topY, int t, FieldItemLayer layer)
|
|
{
|
|
return ItemLayerSprite.GetBitmapItemLayer(layer, topX, topY, PixelsItemMap, MapReticle, t);
|
|
}
|
|
} |