mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-26 12:55:33 -05:00
Make item editor generic for all item types
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace NHSE.WinForms
|
||||
{
|
||||
partial class PlayerItemEditor
|
||||
partial class PlayerItemEditor<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user