diff --git a/NHSE.WinForms/Subforms/Map/BulkSpawn.Designer.cs b/NHSE.WinForms/Subforms/Map/BulkSpawn.Designer.cs index 97e94f8..de2e57e 100644 --- a/NHSE.WinForms/Subforms/Map/BulkSpawn.Designer.cs +++ b/NHSE.WinForms/Subforms/Map/BulkSpawn.Designer.cs @@ -40,6 +40,8 @@ private void InitializeComponent() this.NUD_DIYStart = new System.Windows.Forms.NumericUpDown(); this.L_DIYStop = new System.Windows.Forms.Label(); this.NUD_DIYStop = new System.Windows.Forms.NumericUpDown(); + this.L_NHI = new System.Windows.Forms.Label(); + this.L_NHIFileName = new System.Windows.Forms.Label(); this.CB_SpawnArrange = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.NUD_SpawnX)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_SpawnY)).BeginInit(); @@ -189,6 +191,25 @@ private void InitializeComponent() 0, 0, 0}); + // + // L_NHI + // + this.L_NHI.Location = new System.Drawing.Point(14, 141); + this.L_NHI.Name = "L_NHI"; + this.L_NHI.Size = new System.Drawing.Size(108, 20); + this.L_NHI.TabIndex = 24; + this.L_NHI.Text = "NHI:"; + this.L_NHI.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // L_NHIFileName + // + this.L_NHIFileName.Location = new System.Drawing.Point(14, 161); + this.L_NHIFileName.Name = "L_NHIFileName"; + this.L_NHIFileName.Size = new System.Drawing.Size(108, 20); + this.L_NHIFileName.TabIndex = 25; + this.L_NHIFileName.Text = ""; + this.L_NHIFileName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.L_NHIFileName.Click += new System.EventHandler(this.L_NHIFileName_Click); // // CB_SpawnArrange // @@ -209,6 +230,8 @@ private void InitializeComponent() this.Controls.Add(this.NUD_DIYStop); this.Controls.Add(this.L_DIYStart); this.Controls.Add(this.NUD_DIYStart); + this.Controls.Add(this.L_NHI); + this.Controls.Add(this.L_NHIFileName); this.Controls.Add(this.L_SpawnCount); this.Controls.Add(this.NUD_SpawnCount); this.Controls.Add(this.CB_SpawnType); @@ -246,6 +269,8 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown NUD_DIYStart; private System.Windows.Forms.Label L_DIYStop; private System.Windows.Forms.NumericUpDown NUD_DIYStop; + private System.Windows.Forms.Label L_NHI; + private System.Windows.Forms.Label L_NHIFileName; private System.Windows.Forms.ComboBox CB_SpawnArrange; } } \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/Map/BulkSpawn.cs b/NHSE.WinForms/Subforms/Map/BulkSpawn.cs index a578904..31d635a 100644 --- a/NHSE.WinForms/Subforms/Map/BulkSpawn.cs +++ b/NHSE.WinForms/Subforms/Map/BulkSpawn.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Windows.Forms; using NHSE.Core; @@ -9,6 +11,7 @@ namespace NHSE.WinForms public partial class BulkSpawn : Form { private readonly IItemLayerEditor Editor; + private string NHIFilePath = ""; public BulkSpawn(IItemLayerEditor editor, int x = 0, int y = 0) { @@ -49,6 +52,27 @@ private void B_Apply_Click(object sender, EventArgs e) items = Enumerable.Repeat(diy, count).SelectMany(z => z); sizeX = sizeY = 2; } + else if (type == SpawnType.ItemsFromNHI) + { + if (this.NHIFilePath == "") + { + WinFormsUtil.Alert(MessageStrings.MsgFieldItemNoNHI); + return; + } + + + // read non-empty slots into item array + var data = File.ReadAllBytes(this.NHIFilePath); + var array = data.GetArray(Item.SIZE).Where(item => !item.IsNone); + items = Enumerable.Repeat(array, count).SelectMany(x => x); + + // set flag0 = 0x20 for each item to ensure it gets dropped + // this also forces a 2x2 item size + foreach (Item item in items) + item.SystemParam = 0x20; + + sizeX = sizeY = 2; + } else { var item = Editor.ItemProvider.SetItem(new Item()); @@ -118,17 +142,40 @@ private void CB_SpawnType_SelectedIndexChanged(object sender, EventArgs e) { var index = (SpawnType)CB_SpawnType.SelectedIndex; L_DIYStart.Visible = L_DIYStop.Visible = NUD_DIYStart.Visible = NUD_DIYStop.Visible = index == SpawnType.SequentialDIY; + L_NHI.Visible = L_NHIFileName.Visible = index == SpawnType.ItemsFromNHI; NUD_SpawnCount.Value = index switch { SpawnType.SequentialDIY => 1, + SpawnType.ItemsFromNHI => 1, _ => 8, }; + + if (index == SpawnType.ItemsFromNHI) + { + L_NHIFileName_Click(null, null); + } + } + + private void L_NHIFileName_Click(object sender, EventArgs e) + { + using var ofd = new OpenFileDialog + { + Filter = "New Horizons Inventory (*.nhi)|*.nhi|All files (*.*)|*.*", + FileName = "items.nhi", + }; + + if (ofd.ShowDialog() != DialogResult.OK) + return; + + L_NHIFileName.Text = ofd.SafeFileName; + this.NHIFilePath = ofd.FileName; } private enum SpawnType { ItemFromEditor, SequentialDIY, + ItemsFromNHI, } private enum SpawnArrangement diff --git a/NHSE.WinForms/Util/MessageStrings.cs b/NHSE.WinForms/Util/MessageStrings.cs index 9cb81db..f9e2833 100644 --- a/NHSE.WinForms/Util/MessageStrings.cs +++ b/NHSE.WinForms/Util/MessageStrings.cs @@ -37,6 +37,7 @@ public static class MessageStrings public static string MsgFieldItemModifyNone { get; set; } = "Nothing modified (none found)."; public static string MsgFieldItemModifyCount { get; set; } = "Modified {0} tiles on the map."; public static string MsgFieldItemUnsupportedLayer2Tile { get; set; } = "Unsupported Layer2 items detected."; + public static string MsgFieldItemNoNHI { get; set; } = "No .nhi file selected to import!"; public static string MsgSysBotInfo { get; set; } = "This SysBot reads and writes RAM directly to your game when called to Read/Write."; public static string MsgSysBotRequired { get; set; } = "Using this functionality requires the sys-botbase sysmodule running on the console. Your console must be on the same network as the PC running this program.";