Add Outside Acre editing

what a busy form (so many controls)

Has option to import/export bytes so people can share their exterior acre layouts
This commit is contained in:
Kurt 2020-04-02 10:42:40 -07:00
parent e70d2b71d8
commit 99e4f59d2f
11 changed files with 2188 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace NHSE.Core
{
@ -32,5 +33,33 @@ public TurnipStonk Turnips
get => Data.Slice(Offsets.TurnipExchange, TurnipStonk.SIZE).ToClass<TurnipStonk>();
set => value.ToBytesClass().CopyTo(Data, Offsets.TurnipExchange);
}
public const int AcreWidth = 7 + (2 * 1); // 1 on each side cannot be traversed
private const int AcreHeight = 6 + (2 * 1); // 1 on each side cannot be traversed
private const int AcreMax = AcreWidth * AcreHeight;
private const int AcreSizeAll = AcreMax * 2;
public ushort GetAcre(int index)
{
if ((uint)index > AcreMax)
throw new ArgumentOutOfRangeException(nameof(index));
return BitConverter.ToUInt16(Data, Offsets.Acres + (index * 2));
}
public void SetAcre(int index, ushort value)
{
if ((uint)index > AcreMax)
throw new ArgumentOutOfRangeException(nameof(index));
BitConverter.GetBytes(value).CopyTo(Data, Offsets.Acres + (index * 2));
}
public byte[] GetAcreBytes() => Data.Slice(Offsets.Acres, AcreSizeAll);
public void SetAcreBytes(byte[] data)
{
if (data.Length != AcreSizeAll)
throw new ArgumentOutOfRangeException(nameof(data.Length));
data.CopyTo(Data, Offsets.Acres);
}
}
}

View File

@ -22,6 +22,8 @@ public abstract class MainSaveOffsets
public abstract int TurnipExchange { get; }
public abstract int Acres { get; }
public static MainSaveOffsets GetOffsets(FileHeaderInfo Info)
{
var rev = Info.GetKnownRevisionIndex();

View File

@ -8,6 +8,7 @@ public class MainSaveOffsets10 : MainSaveOffsets
public override int Villager => 0x110;
public override int Patterns => 0x1D72F0;
public override int Buildings => 0x2D0EFC;
public override int Acres => 0x2D1294;
public override int TurnipExchange => 0x4118C0;
public override int RecycleBin => 0xABC000; // yep.
}

View File

@ -8,6 +8,7 @@ public class MainSaveOffsets11 : MainSaveOffsets
public override int Villager => 0x120;
public override int Patterns => 0x1D7310; // +0x20 from v1.0
public override int Buildings => 0x2D0F1C; // +0x20 from v1.0
public override int Acres => 0x2D12B4; // +0x20 from v1.0
public override int TurnipExchange => 0x412060; // +0x7A0 from v1.0
public override int RecycleBin => 0xABDE70; // +0x1E70 from v1.0
}

View File

@ -0,0 +1,151 @@
using System.Collections.Generic;
namespace NHSE.Core
{
public static class OutsideAcreList
{
public static string GetName(ushort acre) => Names.TryGetValue(acre, out var name) ? name : "???";
public static readonly IReadOnlyDictionary<ushort, string> Names = new Dictionary<ushort, string>
{
{0x00, "Flat"}, // 00
{0x10, "FldOutNShip00"}, // 16
{0x14, "FldOutW00"}, // 20
{0x15, "FldOutW01"}, // 21
{0x16, "FldOutW02"}, // 22
{0x17, "FldOutW03"}, // 23
{0x1B, "FldOutWRiver00"}, // 27
{0x1D, "FldOutE00"}, // 29
{0x1E, "FldOutE01"}, // 30
{0x1F, "FldOutE02"}, // 31
{0x20, "FldOutE03"}, // 32
{0x26, "FldOutSW00"}, // 38
{0x27, "FldOutS00"}, // 39
{0x28, "FldOutSRiver00"}, // 40
{0x29, "FldOutSAirPortLeft00"}, // 41
{0x2A, "FldOutSE00"}, // 42
{0x2B, "FldOutSeaN00"}, // 43
{0x2C, "FldOutSeaNW00"}, // 44
{0x2D, "FldOutSeaNE00"}, // 45
{0x2E, "FldOutSeaW00"}, // 46
{0x30, "FldOutSeaE00"}, // 48
{0x32, "FldOutSeaSW00"}, // 50
{0x33, "FldOutSeaS00"}, // 51
{0x34, "FldOutSeaSE00"}, // 52
{0x3E, "FldOutE04"}, // 62
{0x5B, "FldOutERiver00"}, // 91
{0x5C, "FldOutSW01"}, // 92
{0x5D, "FldOutSAirPortRight00"}, // 93
{0x61, "FldOutS01"}, // 97
{0x62, "FldOutSE01"}, // 98
{0x63, "FldOutSE03"}, // 99
{0x64, "FldOutSE02"}, // 100
{0x65, "FldOutSW03"}, // 101
{0x66, "FldOutSW02"}, // 102
{0x67, "FldOutS03"}, // 103
{0x68, "FldOutS02"}, // 104
{0x69, "FldOutS04"}, // 105
{0x6A, "FldOutNEStone00"}, // 106
{0x6B, "FldOutNStone03"}, // 107
{0x6C, "FldOutNStone02"}, // 108
{0x6D, "FldOutNStone01"}, // 109
{0x6E, "FldOutNStoneR00"}, // 110
{0x6F, "FldOutNStoneL00"}, // 111
{0x70, "FldOutNStone00"}, // 112
{0x71, "FldOutNStone04"}, // 113
{0x73, "FldOutEIslandDown01"}, // 115
{0x74, "FldOutEIslandDown00"}, // 116
{0x75, "FldOutEIslandUp00"}, // 117
{0x76, "FldOutEIslandUp01"}, // 118
{0x77, "FldOutWStone01"}, // 119
{0x78, "FldOutWStone00"}, // 120
{0x79, "FldOutEStone00"}, // 121
{0x7A, "FldOutEStone01"}, // 122
{0x7B, "FldOutNEStone01"}, // 123
{0x7C, "FldOutNWStone01"}, // 124
{0x7D, "FldOutNWStone00"}, // 125
{0x7E, "FldOutWCliff00"}, // 126
{0x7F, "FldOutW04"}, // 127
{0x80, "FldOutNShip02"}, // 128
{0x81, "FldOutNShip01"}, // 129
{0x83, "FldOutWCliff01"}, // 131
{0x84, "FldOutSRiver01"}, // 132
{0x85, "FldOutWRiver01"}, // 133
{0x86, "FldOutERiver01"}, // 134
{0x87, "FldOutSWBridge01"}, // 135
{0x88, "FldOutSWBridge00"}, // 136
{0x89, "FldOutSEBridge01"}, // 137
{0x8A, "FldOutSEBridge00"}, // 138
{0x8B, "FldOutECliff01"}, // 139
{0x8C, "FldOutECliff00"}, // 140
{0x8D, "FldOutWIslandDown00"}, // 141
{0x8E, "FldOutWIslandDown01"}, // 142
{0x8F, "FldOutWIslandUp00"}, // 143
{0x90, "FldOutWIslandUp01"}, // 144
{0x91, "FldOutEStone02"}, // 145
{0x92, "FldOutWStone02"}, // 146
{0x93, "FldOutSeaN02"}, // 147
{0x94, "FldOutSeaN01"}, // 148
{0x97, "FldOutSeaW02"}, // 151
{0x98, "FldOutSeaW01"}, // 152
{0x9B, "FldOutSeaS02"}, // 155
{0x9C, "FldOutSeaS01"}, // 156
{0x9D, "FldOutSeaSW02"}, // 157
{0x9E, "FldOutSeaSW01"}, // 158
{0x9F, "FldOutSeaNW02"}, // 159
{0xA0, "FldOutSeaNW01"}, // 160
{0xA1, "FldOutSeaN05"}, // 161
{0xA2, "FldOutSeaN04"}, // 162
{0xA3, "FldOutSeaN03"}, // 163
{0xA4, "FldOutSeaN08"}, // 164
{0xA5, "FldOutSeaN07"}, // 165
{0xA6, "FldOutSeaN06"}, // 166
{0xAC, "FldOutSeaNW03"}, // 172
{0xAD, "FldOutSeaW08"}, // 173
{0xAE, "FldOutSeaW07"}, // 174
{0xAF, "FldOutSeaW06"}, // 175
{0xB0, "FldOutSeaW04"}, // 176
{0xB1, "FldOutSeaW05"}, // 177
{0xB2, "FldOutSeaW03"}, // 178
{0xB8, "FldOutSeaSW03"}, // 184
{0xBF, "FldOutSeaS05"}, // 191
{0xC0, "FldOutSeaS04"}, // 192
{0xC1, "FldOutSeaS03"}, // 193
{0xC2, "FldOutSeaS08"}, // 194
{0xC3, "FldOutSeaS07"}, // 195
{0xC4, "FldOutSeaS06"}, // 196
{0xC5, "FldOutSeaSE02"}, // 197
{0xC6, "FldOutSeaSE01"}, // 198
{0xC8, "FldOutSeaSE03"}, // 200
{0xCD, "FldOutSeaE05"}, // 205
{0xCE, "FldOutSeaE04"}, // 206
{0xCF, "FldOutSeaE03"}, // 207
{0xD0, "FldOutSeaE01"}, // 208
{0xD1, "FldOutSeaE02"}, // 209
{0xD2, "FldOutSeaE08"}, // 210
{0xD3, "FldOutSeaE06"}, // 211
{0xD4, "FldOutSeaE07"}, // 212
{0xD8, "FldOutSeaNE03"}, // 216
{0xDB, "FldOutSeaNE01"}, // 219
{0xDC, "FldOutSeaNE02"}, // 220
{0xDE, "FldOutSBridge00"}, // 222
{0xDF, "FldOutWIslandDown02"}, // 223
{0xE0, "FldOutWIslandUp02"}, // 224
{0xE1, "FldOutEIslandDown02"}, // 225
{0xE2, "FldOutEIslandUp02"}, // 226
{0xE3, "FldOutECliff02"}, // 227
{0xE4, "FldOutWCliff02"}, // 228
{0xE5, "FldOutNEStone02"}, // 229
{0xE6, "FldOutNWStone02"}, // 230
{0xE7, "FldOutEStone03"}, // 231
{0xE8, "FldOutWStone03"}, // 232
{0xE9, "FldOutSRiver02"}, // 233
{0xF0, "FldOutPhotoSBridge00"}, // 240
{0xF1, "FldOutPhotoSE00"}, // 241
{0xF2, "FldOutPhotoSW00"}, // 242
{0xF3, "FldOutSBridge02"}, // 243
{0xF4, "FldOutSBridge01"}, // 244
};
}
}

View File

@ -36,6 +36,7 @@ void DumpB(string fn, byte[] bytes)
DumpS("milestones.txt", GetMilestoneList(pathBCSV));
DumpS("recipeDictionary.txt", GetRecipeList(pathBCSV));
DumpS("outsideAcres.txt", GetAcreNames(pathBCSV));
DumpS("fish.txt", GetFishList(pathBCSV, itemNames));
DumpS("bugs.txt", GetInsectList(pathBCSV, itemNames));
@ -196,5 +197,28 @@ private static IEnumerable<ushort> GetItemList(string pathBCSV, string fn, uint
result.Sort();
return result;
}
private static IEnumerable<string> GetAcreNames(string pathBCSV, string fn = "FieldOutsideParts.bcsv")
{
var bcsv = BCSVConverter.GetBCSV(pathBCSV, fn);
var dict = bcsv.GetFieldDictionary();
var findex = dict[0x54706054];
var fname = dict[0x39B5A93D];
var result = new List<string>();
for (int i = 0; i < bcsv.EntryCount; i++)
{
var iid = bcsv.ReadValue(i, findex);
var ival = ushort.Parse(iid);
var name = bcsv.ReadValue(i, fname).TrimEnd('\0');
var kvp = $"{{0x{ival:X2}, \"{name}\"}}, // {ival}";
result.Add(kvp);
}
result.Sort();
return result;
}
}
}

View File

@ -88,6 +88,7 @@ private void InitializeComponent()
this.B_EditBuildings = new System.Windows.Forms.Button();
this.B_RecycleBin = new System.Windows.Forms.Button();
this.B_EditTurnipExchange = new System.Windows.Forms.Button();
this.B_EditAcres = new System.Windows.Forms.Button();
this.Menu_Editor.SuspendLayout();
this.TC_Editors.SuspendLayout();
this.Tab_Players.SuspendLayout();
@ -710,6 +711,7 @@ private void InitializeComponent()
//
// Tab_Map
//
this.Tab_Map.Controls.Add(this.B_EditAcres);
this.Tab_Map.Controls.Add(this.B_EditTurnipExchange);
this.Tab_Map.Controls.Add(this.B_EditBuildings);
this.Tab_Map.Controls.Add(this.B_RecycleBin);
@ -751,6 +753,16 @@ private void InitializeComponent()
this.B_EditTurnipExchange.UseVisualStyleBackColor = true;
this.B_EditTurnipExchange.Click += new System.EventHandler(this.B_EditTurnipExchange_Click);
//
// B_EditAcres
//
this.B_EditAcres.Location = new System.Drawing.Point(300, 168);
this.B_EditAcres.Name = "B_EditAcres";
this.B_EditAcres.Size = new System.Drawing.Size(92, 40);
this.B_EditAcres.TabIndex = 16;
this.B_EditAcres.Text = "Edit Acres";
this.B_EditAcres.UseVisualStyleBackColor = true;
this.B_EditAcres.Click += new System.EventHandler(this.B_EditAcres_Click);
//
// Editor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -852,6 +864,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_EditActivities;
private System.Windows.Forms.ToolStripMenuItem Menu_RAMEdit;
private System.Windows.Forms.Button B_EditTurnipExchange;
private System.Windows.Forms.Button B_EditAcres;
}
}

View File

@ -508,5 +508,11 @@ private void B_EditTurnipExchange_Click(object sender, EventArgs e)
if (editor.ShowDialog() == DialogResult.OK)
SAV.Main.Turnips = turnips;
}
private void B_EditAcres_Click(object sender, EventArgs e)
{
using var editor = new AcreEditor(SAV.Main);
editor.ShowDialog();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,118 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using NHSE.Core;
namespace NHSE.WinForms
{
public partial class AcreEditor : Form
{
private readonly NumericUpDown[] Acres;
private readonly MainSave SAV;
public AcreEditor(MainSave sav)
{
InitializeComponent();
SAV = sav;
Acres = new[]
{
NUD_00, NUD_01, NUD_02, NUD_03, NUD_04, NUD_05, NUD_06, NUD_07, NUD_08,
NUD_09, NUD_0A, NUD_0B, NUD_0C, NUD_0D, NUD_0E, NUD_0F, NUD_10, NUD_11,
NUD_12, NUD_13, NUD_14, NUD_15, NUD_16, NUD_17, NUD_18, NUD_19, NUD_1A,
NUD_1B, NUD_1C, NUD_1D, NUD_1E, NUD_1F, NUD_20, NUD_21, NUD_22, NUD_23,
NUD_24, NUD_25, NUD_26, NUD_27, NUD_28, NUD_29, NUD_2A, NUD_2B, NUD_2C,
NUD_2D, NUD_2E, NUD_2F, NUD_30, NUD_31, NUD_32, NUD_33, NUD_34, NUD_35,
NUD_36, NUD_37, NUD_38, NUD_39, NUD_3A, NUD_3B, NUD_3C, NUD_3D, NUD_3E,
NUD_3F, NUD_40, NUD_41, NUD_42, NUD_43, NUD_44, NUD_45, NUD_46, NUD_47,
};
LoadAcres();
LoadHintComboBox();
for (var i = 0; i < Acres.Length; i++)
{
var a = Acres[i];
var x = i % MainSave.AcreWidth;
var y = i / MainSave.AcreWidth;
a.MouseEnter += (sender, args) => UpdateAcre((ushort)a.Value, x, y);
a.ValueChanged += (sender, args) => UpdateAcre((ushort)a.Value, x, y);
}
}
private void UpdateAcre(ushort val, int x, int y)
{
var name = OutsideAcreList.GetName(val);
L_Hovered.Text = $"{x},{y} - 0x{val:X3} = {name}";
L_Hovered.Visible = true;
}
private void LoadHintComboBox()
{
var acres = OutsideAcreList.Names.Select(z => $"{z.Value} - {z.Key:X}").ToList();
acres.Sort();
foreach (var name in acres)
CB_AcreNames.Items.Add(name);
}
private void LoadAcres()
{
for (int i = 0; i < Acres.Length; i++)
Acres[i].Value = SAV.GetAcre(i);
}
private void SaveAcres()
{
for (int i = 0; i < Acres.Length; i++)
SAV.SetAcre(i, (ushort)Acres[i].Value);
}
private void B_Save_Click(object sender, EventArgs e) { SaveAcres(); Close(); }
private void B_Cancel_Click(object sender, EventArgs e) => Close();
private void B_Export_Click(object sender, EventArgs e)
{
using var sfd = new SaveFileDialog
{
Filter = "New Horizons Acres (*.nha)|*.nha|All files (*.*)|*.*",
FileName = "acres.nha",
};
if (sfd.ShowDialog() != DialogResult.OK)
return;
var original = SAV.GetAcreBytes();
SaveAcres();
var modified = SAV.GetAcreBytes();
SAV.SetAcreBytes(original);
File.WriteAllBytes(sfd.FileName, modified);
}
private void B_Import_Click(object sender, EventArgs e)
{
using var ofd = new OpenFileDialog
{
Filter = "New Horizons Acres (*.nha)|*.nha|All files (*.*)|*.*",
FileName = "acres.nha",
};
if (ofd.ShowDialog() != DialogResult.OK)
return;
var original = SAV.GetAcreBytes();
var modified = File.ReadAllBytes(ofd.FileName);
if (original.Length != modified.Length)
{
WinFormsUtil.Error(
$"Imported size (0x{modified.Length}) does not match expected size (0x{original.Length:X}).",
"Aborting the import operation.");
return;
}
SAV.SetAcreBytes(modified);
LoadAcres();
SAV.SetAcreBytes(original);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>