Enhance extension item visualization

Mark class as static

Draws directional lines trying to point back to the root item
This commit is contained in:
Kurt
2020-04-09 12:52:07 -07:00
parent 9d2010a285
commit 91418e9c66
3 changed files with 40 additions and 14 deletions

View File

@@ -3,14 +3,9 @@
namespace NHSE.Sprites
{
public class FieldItemSpriteDrawer
public static class FieldItemSpriteDrawer
{
public int Width { get; set; } = 8;
public int Height { get; set; } = 8;
public Bitmap GetImage(FieldItem item) => FieldItemSprite.GetImage(item, Width, Height);
public Bitmap GetBitmapLayer(FieldItemLayer layer)
public static Bitmap GetBitmapLayer(FieldItemLayer layer)
{
var items = layer.Tiles;
var height = layer.MapHeight;
@@ -53,12 +48,13 @@ private static int[] GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, ou
return bmpData;
}
public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale)
public static Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale)
{
var map = GetBitmapLayerAcre(layer, x0, y0, out int mh, out int mw);
var data = ImageUtil.ScalePixelImage(map, scale, mw, mh, out var w, out var h);
// draw symbols over special items now?
DrawDirectionals(data, layer, w, x0, y0, scale);
// Slap on a grid
DrawGrid(data, w, h, scale);
@@ -67,6 +63,37 @@ public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale
return ImageUtil.GetBitmap(data, w, h);
}
private static void DrawDirectionals(int[] data, FieldItemLayer layer, int w, int x0, int y0, int scale)
{
for (int x = x0; x < x0 + layer.GridWidth; x++)
{
for (int y = y0; y < y0 + layer.GridHeight; y++)
{
var tile = layer.GetTile(x, y);
if (!tile.IsExtension)
continue;
DrawDirectional(data, tile, (x - x0) * scale, (y - y0) * scale, scale, w);
}
}
}
private static void DrawDirectional(int[] data, FieldItem tile, int x0, int y0, int scale, int w)
{
var eX = tile.ExtensionX;
var eY = tile.ExtensionY;
var sum = eX + eY;
var start = scale / (sum + 1);
var startX = eX >= eY ? 0 : start;
var startY = eX <= eY ? 0 : start;
var baseIndex = (w * y0) + x0;
for (int x = startX, y = startY; x < scale && y < scale; x += eX, y += eY)
{
var index = baseIndex + (w * y) + x;
data[index] ^= 0x808080;
}
}
private static void DrawGrid(int[] data, int w, int h, int scale)
{
const int grid = -0x777778; // 0xFF888888u
@@ -92,7 +119,7 @@ private static void DrawGrid(int[] data, int w, int h, int scale)
}
}
public Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int scale = 1)
public static Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int scale = 1)
{
var map = GetBitmapLayer(layer);
if (scale > 1)

View File

@@ -3,6 +3,5 @@
public static class SpriteUtil
{
public static readonly ItemSpriteDrawer Items = new ItemSpriteDrawer();
public static readonly FieldItemSpriteDrawer FieldItems = new FieldItemSpriteDrawer();
}
}
}

View File

@@ -47,7 +47,7 @@ private void ChangeViewToAcre(int acre)
private void ReloadMap()
{
PB_Map.Image = SpriteUtil.FieldItems.GetBitmapLayer(Layer, X, Y);
PB_Map.Image = FieldItemSpriteDrawer.GetBitmapLayer(Layer, X, Y);
}
private void LoadGrid(int topX, int topY)
@@ -59,7 +59,7 @@ private void LoadGrid(int topX, int topY)
private void ReloadGrid(FieldItemLayer layer, int topX, int topY)
{
PB_Acre.Image = SpriteUtil.FieldItems.GetBitmapLayerAcre(layer, topX, topY, AcreScale);
PB_Acre.Image = FieldItemSpriteDrawer.GetBitmapLayerAcre(layer, topX, topY, AcreScale);
}
private void UpdateArrowVisibility()
@@ -301,7 +301,7 @@ private void Menu_SavePNG_Click(object sender, EventArgs e)
}
const string name = "map";
var bmp = SpriteUtil.FieldItems.GetBitmapLayer(Items.Layer1);
var bmp = FieldItemSpriteDrawer.GetBitmapLayer(Items.Layer1);
using var sfd = new SaveFileDialog
{
Filter = "png file (*.png)|*.png|All files (*.*)|*.*",