Make item editor generic for all item types

This commit is contained in:
Kurt 2020-03-29 18:44:34 -07:00
parent 533b9a914c
commit bb417bd798
3 changed files with 10 additions and 10 deletions

View File

@ -114,7 +114,7 @@ private void B_EditPlayerItems_Click(object sender, EventArgs e)
var p1 = pers.Pocket1;
var p2 = pers.Pocket2;
var items = p2.Concat(p1).ToArray();
using var editor = new PlayerItemEditor(items, 10, 4);
using var editor = new PlayerItemEditor<Item>(items, 10, 4);
if (editor.ShowDialog() != DialogResult.OK)
return;
@ -128,7 +128,7 @@ private void B_Storage_Click(object sender, EventArgs e)
var player = SAV.Players[PlayerIndex];
var pers = player.Personal;
var p1 = pers.Storage;
using var editor = new PlayerItemEditor(p1, 10, 5);
using var editor = new PlayerItemEditor<Item>(p1, 10, 5);
if (editor.ShowDialog() == DialogResult.OK)
pers.Storage = p1;
}
@ -136,7 +136,7 @@ private void B_Storage_Click(object sender, EventArgs e)
private void B_RecycleBin_Click(object sender, EventArgs e)
{
var items = SAV.Main.RecycleBin;
using var editor = new PlayerItemEditor(items, 10, 4);
using var editor = new PlayerItemEditor<Item>(items, 10, 4);
if (editor.ShowDialog() == DialogResult.OK)
SAV.Main.RecycleBin = items;
}
@ -360,7 +360,7 @@ private void B_EditFurniture_Click(object sender, EventArgs e)
{
var v = SAV.Main.GetVillager(VillagerIndex);
var items = v.Furniture;
using var editor = new PlayerItemEditor(items, 8, 2);
using var editor = new PlayerItemEditor<VillagerItem>(items, 8, 2);
if (editor.ShowDialog() != DialogResult.OK)
return;

View File

@ -1,6 +1,6 @@
namespace NHSE.WinForms
{
partial class PlayerItemEditor
partial class PlayerItemEditor<T>
{
/// <summary>
/// Required designer variable.

View File

@ -7,12 +7,12 @@
namespace NHSE.WinForms
{
public partial class PlayerItemEditor : Form
public partial class PlayerItemEditor<T> : Form where T : Item
{
private readonly IReadOnlyList<Item> Items;
private readonly IReadOnlyList<T> Items;
private readonly Action LoadItems;
public PlayerItemEditor(IReadOnlyList<Item> array, int width, int height)
public PlayerItemEditor(IReadOnlyList<T> array, int width, int height)
{
InitializeComponent();
Items = array;
@ -58,7 +58,7 @@ private void B_Dump_Click(object sender, EventArgs e)
};
if (sfd.ShowDialog() != DialogResult.OK)
return;
var bytes = Item.SetArray(Items);
var bytes = Items.SetArray(Items[0].ToBytesClass().Length);
File.WriteAllBytes(sfd.FileName, bytes);
}
@ -73,7 +73,7 @@ private void B_Load_Click(object sender, EventArgs e)
return;
var data = File.ReadAllBytes(sfd.FileName);
var import = Item.GetArray(data);
var import = data.GetArray<T>(Items[0].ToBytesClass().Length);
for (int i = 0; i < Items.Count && i < import.Length ; i++)
Items[i].CopyFrom(import[i]);