mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-26 00:28:28 -05:00
Minor clean
remove some unused logic (program growth = no longer needed)
This commit is contained in:
parent
b884973919
commit
d78b0e0e1f
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = SIZE, Pack = 1)]
|
||||
public class Building : INamedObject
|
||||
public class Building
|
||||
{
|
||||
public const int SIZE = 0x14;
|
||||
|
||||
|
|
@ -47,7 +46,6 @@ public void CopyFrom(Building building)
|
|||
|
||||
public static Building[] GetArray(byte[] data) => data.GetArray<Building>(SIZE);
|
||||
public static byte[] SetArray(IReadOnlyList<Building> data) => data.SetArray(SIZE);
|
||||
public override string ToString() => ToString(Array.Empty<string>());
|
||||
public string ToString(IReadOnlyList<string> names) => $"{X:000},{Y:000} - {BuildingType}";
|
||||
public override string ToString() => $"{X:000},{Y:000} - {BuildingType}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
public interface INamedObject
|
||||
{
|
||||
string ToString(IReadOnlyList<string> names);
|
||||
}
|
||||
}
|
||||
21
NHSE.Sprites/Field/FieldItemColor.cs
Normal file
21
NHSE.Sprites/Field/FieldItemColor.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using NHSE.Core;
|
||||
|
||||
namespace NHSE.Sprites
|
||||
{
|
||||
public static class FieldItemColor
|
||||
{
|
||||
public static Color GetItemColor(FieldItem item)
|
||||
{
|
||||
var kind = ItemInfo.GetItemKind(item);
|
||||
if (kind == ItemKind.Unknown)
|
||||
return item.DisplayItemId == FieldItem.NONE ? Color.Transparent : Color.DarkGreen;
|
||||
return Colors[(int)kind];
|
||||
}
|
||||
|
||||
private static readonly Color[] Colors = ((KnownColor[])Enum.GetValues(typeof(KnownColor)))
|
||||
.Select(Color.FromKnownColor).Select(z => ColorUtil.Blend(Color.White, z, 0.5d)).ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using NHSE.Core;
|
||||
|
||||
namespace NHSE.Sprites
|
||||
{
|
||||
public static class FieldItemSprite
|
||||
{
|
||||
public static Bitmap GetImage(FieldItem item, int width, int height)
|
||||
{
|
||||
if (item.ItemId == Item.NONE)
|
||||
return GetNone(width, height);
|
||||
|
||||
return CreateFake(item, width, height);
|
||||
}
|
||||
|
||||
private static Bitmap GetNone(int w, int h) => new Bitmap(w, h);
|
||||
|
||||
public static Bitmap CreateFake(FieldItem item, int width, int height, bool slash = false)
|
||||
{
|
||||
var bmp = new Bitmap(width, height);
|
||||
|
||||
const int x1 = 0;
|
||||
const int y1 = 0;
|
||||
int x2 = width - 1;
|
||||
int y2 = height - 1;
|
||||
using var gfx = Graphics.FromImage(bmp);
|
||||
DrawItemAt(gfx, item, x1, y1, x2, y2, slash);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public static void DrawItemAt(Graphics gfx, FieldItem item, int x1, int y1, int x2, int y2, bool slash = false)
|
||||
{
|
||||
var color = GetItemColor(item);
|
||||
using var brush = new SolidBrush(color);
|
||||
DrawItem(gfx, x1, y1, x2, y2, brush);
|
||||
|
||||
if (slash)
|
||||
DrawX(gfx, x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
private static void DrawX(Graphics gfx, int x1, int y1, int x2, int y2, Color color)
|
||||
{
|
||||
var icolor = Color.FromArgb(color.R ^ 0xFF, color.G ^ 0xFF, color.B ^ 0xFF);
|
||||
using var ipen = new Pen(icolor);
|
||||
DrawForwardSlash(gfx, x1, y1, x2, y2, ipen);
|
||||
DrawBackwardSlash(gfx, x1, y1, x2, y2, ipen);
|
||||
}
|
||||
|
||||
private static void DrawItem(Graphics gfx, int x1, int y1, int x2, int y2, Brush brush) => gfx.FillRectangle(brush, x1, y1, x2 + 1, y2 + 1);
|
||||
private static void DrawForwardSlash(Graphics gfx, int x1, int y1, int x2, int y2, Pen ipen) => gfx.DrawLine(ipen, x2, y1, x1, y2);
|
||||
private static void DrawBackwardSlash(Graphics gfx, int x1, int y1, int x2, int y2, Pen ipen) => gfx.DrawLine(ipen, x1, y1, x2, y2);
|
||||
|
||||
public static Color GetItemColor(FieldItem item)
|
||||
{
|
||||
var kind = ItemInfo.GetItemKind(item);
|
||||
if (kind == ItemKind.Unknown)
|
||||
return item.DisplayItemId == FieldItem.NONE ? Color.Transparent : Color.DarkGreen;
|
||||
return Colors[(int)kind];
|
||||
}
|
||||
|
||||
private static readonly Color[] Colors = ((KnownColor[])Enum.GetValues(typeof(KnownColor)))
|
||||
.Select(Color.FromKnownColor).Select(z => ColorUtil.Blend(Color.White, z, 0.5d)).ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ private static void LoadBitmapLayer(FieldItem[] items, int[] bmpData, int width,
|
|||
{
|
||||
var index = ix + y;
|
||||
var tile = items[index];
|
||||
bmpData[(y * width) + x] = FieldItemSprite.GetItemColor(tile).ToArgb();
|
||||
bmpData[(y * width) + x] = FieldItemColor.GetItemColor(tile).ToArgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ private static void LoadPixelsFromLayer(FieldItemLayer layer, int x0, int y0, in
|
|||
for (int x = 0; x < stride; x++)
|
||||
{
|
||||
var tile = layer.GetTile(x + x0, y + y0);
|
||||
var color = FieldItemSprite.GetItemColor(tile).ToArgb();
|
||||
var color = FieldItemColor.GetItemColor(tile).ToArgb();
|
||||
var index = baseIndex + x;
|
||||
bmpData[index] = color;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user