From 6ecf659d5e78f32ff5dc2389f651258355407056 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 Apr 2020 20:11:35 -0700 Subject: [PATCH] Add special handling for diy recipe --- NHSE.Core/Resources/text/en/text_item_en.txt | 2 +- NHSE.Core/Strings/GameStrings.cs | 33 ++++- NHSE.Core/Structures/GameLists.cs | 2 +- NHSE.Core/Structures/Item/ItemInfo.cs | 7 +- NHSE.Core/Structures/RecipeList.cs | 2 +- NHSE.WinForms/Controls/ItemEditor.Designer.cs | 127 +++++++++++++++--- NHSE.WinForms/Controls/ItemEditor.cs | 50 ++++++- NHSE.WinForms/Controls/ItemGridEditor.cs | 2 +- NHSE.WinForms/Subforms/ItemReceivedEditor.cs | 1 - NHSE.WinForms/Subforms/RecipeListEditor.cs | 1 - 10 files changed, 193 insertions(+), 34 deletions(-) diff --git a/NHSE.Core/Resources/text/en/text_item_en.txt b/NHSE.Core/Resources/text/en/text_item_en.txt index 441d0ac..744f316 100644 --- a/NHSE.Core/Resources/text/en/text_item_en.txt +++ b/NHSE.Core/Resources/text/en/text_item_en.txt @@ -5792,7 +5792,7 @@ net message bottle - +DIY recipe geometric-print pants (Blue) dreamy dress (Pink) flashy kimono (Green) diff --git a/NHSE.Core/Strings/GameStrings.cs b/NHSE.Core/Strings/GameStrings.cs index e009c98..de22e15 100644 --- a/NHSE.Core/Strings/GameStrings.cs +++ b/NHSE.Core/Strings/GameStrings.cs @@ -35,6 +35,20 @@ private List CreateItemDataSource(string[] strings) return dataSource; } + public List CreateItemDataSource(IReadOnlyCollection> dict, bool none = true) + { + var display = itemlistdisplay; + var result = new List(dict.Count); + foreach (var x in dict) + result.Add(new ComboItem(display[x.Value], x.Key)); + + if (none) + result.Add(new ComboItem(itemlist[0], Item.NONE)); + + result.SortByText(); + return result; + } + private static Dictionary GetMap(IReadOnlyCollection arr) { var map = new Dictionary(arr.Count); @@ -69,10 +83,27 @@ public static string[] GetItemDisplayList(string[] items) return items; } - public string GetItemName(ushort index) + public string GetItemName(Item item) { + var index = item.ItemId; if (index == Item.NONE) return itemlist[0]; + var kind = ItemInfo.GetItemKind(index); + + if (kind == ItemKind.Kind_DIYRecipe) + { + var display = itemlistdisplay[index]; + var recipeID = item.Count; + var isKnown = RecipeList.Recipes.TryGetValue(recipeID, out var result); + var makes = isKnown ? GetItemName(result) : recipeID.ToString("000"); + return $"{display} - {makes}"; + } + + return GetItemName(index); + } + + private string GetItemName(ushort index) + { if (index >= itemlistdisplay.Length) return "???"; return itemlistdisplay[index]; diff --git a/NHSE.Core/Structures/GameLists.cs b/NHSE.Core/Structures/GameLists.cs index 592a694..ddfe9bd 100644 --- a/NHSE.Core/Structures/GameLists.cs +++ b/NHSE.Core/Structures/GameLists.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace NHSE.Core.Structures +namespace NHSE.Core { public static class GameLists { diff --git a/NHSE.Core/Structures/Item/ItemInfo.cs b/NHSE.Core/Structures/Item/ItemInfo.cs index ddf6fc0..37a2b54 100644 --- a/NHSE.Core/Structures/Item/ItemInfo.cs +++ b/NHSE.Core/Structures/Item/ItemInfo.cs @@ -4,12 +4,13 @@ public static class ItemInfo { private static readonly byte[] ItemKinds = ResourceUtil.GetBinaryResource("item_kind.bin"); - public static ItemKind GetItemKind(Item item) + public static ItemKind GetItemKind(Item item) => GetItemKind(item.ItemId); + + public static ItemKind GetItemKind(ushort id) { - var id = item.ItemId; if (id > ItemKinds.Length) return ItemKind.Unknown; - return (ItemKind)ItemKinds[id]; + return (ItemKind) ItemKinds[id]; } } } \ No newline at end of file diff --git a/NHSE.Core/Structures/RecipeList.cs b/NHSE.Core/Structures/RecipeList.cs index c69220a..25a04b4 100644 --- a/NHSE.Core/Structures/RecipeList.cs +++ b/NHSE.Core/Structures/RecipeList.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace NHSE.Core.Structures +namespace NHSE.Core { public static class RecipeList { diff --git a/NHSE.WinForms/Controls/ItemEditor.Designer.cs b/NHSE.WinForms/Controls/ItemEditor.Designer.cs index 21da38c..b8809a4 100644 --- a/NHSE.WinForms/Controls/ItemEditor.Designer.cs +++ b/NHSE.WinForms/Controls/ItemEditor.Designer.cs @@ -42,11 +42,22 @@ private void InitializeComponent() this.Menu_View = new System.Windows.Forms.ToolStripMenuItem(); this.Menu_Set = new System.Windows.Forms.ToolStripMenuItem(); this.Menu_Delete = new System.Windows.Forms.ToolStripMenuItem(); + this.CB_NamedItemArgument = new System.Windows.Forms.ComboBox(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.FLP_Count = new System.Windows.Forms.FlowLayoutPanel(); + this.FLP_Uses = new System.Windows.Forms.FlowLayoutPanel(); + this.FLP_Flag0 = new System.Windows.Forms.FlowLayoutPanel(); + this.FLP_Flag1 = new System.Windows.Forms.FlowLayoutPanel(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Uses)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Flag0)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Flag1)).BeginInit(); this.CM_Hand.SuspendLayout(); + this.flowLayoutPanel1.SuspendLayout(); + this.FLP_Count.SuspendLayout(); + this.FLP_Uses.SuspendLayout(); + this.FLP_Flag0.SuspendLayout(); + this.FLP_Flag1.SuspendLayout(); this.SuspendLayout(); // // CB_ItemID @@ -55,14 +66,16 @@ private void InitializeComponent() this.CB_ItemID.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_ItemID.DropDownWidth = 322; this.CB_ItemID.FormattingEnabled = true; - this.CB_ItemID.Location = new System.Drawing.Point(3, 3); + this.CB_ItemID.Location = new System.Drawing.Point(3, 1); + this.CB_ItemID.Margin = new System.Windows.Forms.Padding(3, 1, 3, 1); this.CB_ItemID.Name = "CB_ItemID"; this.CB_ItemID.Size = new System.Drawing.Size(141, 21); this.CB_ItemID.TabIndex = 1; + this.CB_ItemID.SelectedValueChanged += new System.EventHandler(this.CB_ItemID_SelectedValueChanged); // // NUD_Count // - this.NUD_Count.Location = new System.Drawing.Point(88, 28); + this.NUD_Count.Location = new System.Drawing.Point(88, 3); this.NUD_Count.Maximum = new decimal(new int[] { 65535, 0, @@ -71,10 +84,12 @@ private void InitializeComponent() this.NUD_Count.Name = "NUD_Count"; this.NUD_Count.Size = new System.Drawing.Size(56, 20); this.NUD_Count.TabIndex = 2; + this.NUD_Count.ValueChanged += new System.EventHandler(this.NUD_Count_ValueChanged); // // L_Count // - this.L_Count.Location = new System.Drawing.Point(3, 27); + this.L_Count.Location = new System.Drawing.Point(3, 3); + this.L_Count.Margin = new System.Windows.Forms.Padding(3); this.L_Count.Name = "L_Count"; this.L_Count.Size = new System.Drawing.Size(79, 20); this.L_Count.TabIndex = 7; @@ -83,7 +98,8 @@ private void InitializeComponent() // // L_Uses // - this.L_Uses.Location = new System.Drawing.Point(3, 50); + this.L_Uses.Location = new System.Drawing.Point(3, 3); + this.L_Uses.Margin = new System.Windows.Forms.Padding(3); this.L_Uses.Name = "L_Uses"; this.L_Uses.Size = new System.Drawing.Size(79, 20); this.L_Uses.TabIndex = 9; @@ -92,7 +108,7 @@ private void InitializeComponent() // // NUD_Uses // - this.NUD_Uses.Location = new System.Drawing.Point(88, 51); + this.NUD_Uses.Location = new System.Drawing.Point(88, 3); this.NUD_Uses.Maximum = new decimal(new int[] { 65535, 0, @@ -104,7 +120,8 @@ private void InitializeComponent() // // L_Flag0 // - this.L_Flag0.Location = new System.Drawing.Point(3, 73); + this.L_Flag0.Location = new System.Drawing.Point(3, 3); + this.L_Flag0.Margin = new System.Windows.Forms.Padding(3); this.L_Flag0.Name = "L_Flag0"; this.L_Flag0.Size = new System.Drawing.Size(79, 20); this.L_Flag0.TabIndex = 11; @@ -114,7 +131,7 @@ private void InitializeComponent() // NUD_Flag0 // this.NUD_Flag0.Hexadecimal = true; - this.NUD_Flag0.Location = new System.Drawing.Point(88, 74); + this.NUD_Flag0.Location = new System.Drawing.Point(88, 3); this.NUD_Flag0.Maximum = new decimal(new int[] { 255, 0, @@ -126,7 +143,8 @@ private void InitializeComponent() // // L_Flag1 // - this.L_Flag1.Location = new System.Drawing.Point(3, 96); + this.L_Flag1.Location = new System.Drawing.Point(3, 3); + this.L_Flag1.Margin = new System.Windows.Forms.Padding(3); this.L_Flag1.Name = "L_Flag1"; this.L_Flag1.Size = new System.Drawing.Size(79, 20); this.L_Flag1.TabIndex = 13; @@ -136,7 +154,7 @@ private void InitializeComponent() // NUD_Flag1 // this.NUD_Flag1.Hexadecimal = true; - this.NUD_Flag1.Location = new System.Drawing.Point(88, 97); + this.NUD_Flag1.Location = new System.Drawing.Point(88, 3); this.NUD_Flag1.Maximum = new decimal(new int[] { 255, 0, @@ -173,26 +191,91 @@ private void InitializeComponent() this.Menu_Delete.Size = new System.Drawing.Size(107, 22); this.Menu_Delete.Text = "Delete"; // + // CB_NamedItemArgument + // + this.CB_NamedItemArgument.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; + this.CB_NamedItemArgument.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; + this.CB_NamedItemArgument.DropDownWidth = 322; + this.CB_NamedItemArgument.FormattingEnabled = true; + this.CB_NamedItemArgument.Location = new System.Drawing.Point(3, 24); + this.CB_NamedItemArgument.Margin = new System.Windows.Forms.Padding(3, 1, 3, 1); + this.CB_NamedItemArgument.Name = "CB_NamedItemArgument"; + this.CB_NamedItemArgument.Size = new System.Drawing.Size(141, 21); + this.CB_NamedItemArgument.TabIndex = 14; + this.CB_NamedItemArgument.Visible = false; + this.CB_NamedItemArgument.SelectedValueChanged += new System.EventHandler(this.CB_NamedItemArgument_SelectedValueChanged); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.Controls.Add(this.CB_ItemID); + this.flowLayoutPanel1.Controls.Add(this.CB_NamedItemArgument); + this.flowLayoutPanel1.Controls.Add(this.FLP_Count); + this.flowLayoutPanel1.Controls.Add(this.FLP_Uses); + this.flowLayoutPanel1.Controls.Add(this.FLP_Flag0); + this.flowLayoutPanel1.Controls.Add(this.FLP_Flag1); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(228, 208); + this.flowLayoutPanel1.TabIndex = 15; + // + // FLP_Count + // + this.FLP_Count.Controls.Add(this.L_Count); + this.FLP_Count.Controls.Add(this.NUD_Count); + this.FLP_Count.Location = new System.Drawing.Point(0, 46); + this.FLP_Count.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Count.Name = "FLP_Count"; + this.FLP_Count.Size = new System.Drawing.Size(147, 26); + this.FLP_Count.TabIndex = 16; + // + // FLP_Uses + // + this.FLP_Uses.Controls.Add(this.L_Uses); + this.FLP_Uses.Controls.Add(this.NUD_Uses); + this.FLP_Uses.Location = new System.Drawing.Point(0, 72); + this.FLP_Uses.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Uses.Name = "FLP_Uses"; + this.FLP_Uses.Size = new System.Drawing.Size(147, 26); + this.FLP_Uses.TabIndex = 17; + // + // FLP_Flag0 + // + this.FLP_Flag0.Controls.Add(this.L_Flag0); + this.FLP_Flag0.Controls.Add(this.NUD_Flag0); + this.FLP_Flag0.Location = new System.Drawing.Point(0, 98); + this.FLP_Flag0.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Flag0.Name = "FLP_Flag0"; + this.FLP_Flag0.Size = new System.Drawing.Size(147, 26); + this.FLP_Flag0.TabIndex = 17; + // + // FLP_Flag1 + // + this.FLP_Flag1.Controls.Add(this.L_Flag1); + this.FLP_Flag1.Controls.Add(this.NUD_Flag1); + this.FLP_Flag1.Location = new System.Drawing.Point(0, 124); + this.FLP_Flag1.Margin = new System.Windows.Forms.Padding(0); + this.FLP_Flag1.Name = "FLP_Flag1"; + this.FLP_Flag1.Size = new System.Drawing.Size(147, 26); + this.FLP_Flag1.TabIndex = 17; + // // ItemEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.L_Flag1); - this.Controls.Add(this.NUD_Flag1); - this.Controls.Add(this.L_Flag0); - this.Controls.Add(this.NUD_Flag0); - this.Controls.Add(this.L_Uses); - this.Controls.Add(this.NUD_Uses); - this.Controls.Add(this.L_Count); - this.Controls.Add(this.NUD_Count); - this.Controls.Add(this.CB_ItemID); + this.Controls.Add(this.flowLayoutPanel1); this.Name = "ItemEditor"; - this.Size = new System.Drawing.Size(148, 144); + this.Size = new System.Drawing.Size(228, 208); ((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Uses)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Flag0)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Flag1)).EndInit(); this.CM_Hand.ResumeLayout(false); + this.flowLayoutPanel1.ResumeLayout(false); + this.FLP_Count.ResumeLayout(false); + this.FLP_Uses.ResumeLayout(false); + this.FLP_Flag0.ResumeLayout(false); + this.FLP_Flag1.ResumeLayout(false); this.ResumeLayout(false); } @@ -211,5 +294,11 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem Menu_View; private System.Windows.Forms.ToolStripMenuItem Menu_Set; private System.Windows.Forms.ToolStripMenuItem Menu_Delete; + private System.Windows.Forms.ComboBox CB_NamedItemArgument; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.FlowLayoutPanel FLP_Count; + private System.Windows.Forms.FlowLayoutPanel FLP_Uses; + private System.Windows.Forms.FlowLayoutPanel FLP_Flag0; + private System.Windows.Forms.FlowLayoutPanel FLP_Flag1; } } diff --git a/NHSE.WinForms/Controls/ItemEditor.cs b/NHSE.WinForms/Controls/ItemEditor.cs index 8f752d2..6a91312 100644 --- a/NHSE.WinForms/Controls/ItemEditor.cs +++ b/NHSE.WinForms/Controls/ItemEditor.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Windows.Forms; using NHSE.Core; @@ -6,10 +7,12 @@ namespace NHSE.WinForms { public partial class ItemEditor : UserControl { - public ItemEditor() - { - InitializeComponent(); - } + private readonly List Recipes = GameInfo.Strings.CreateItemDataSource(RecipeList.Recipes, false); + + public ItemEditor() => InitializeComponent(); + + private ItemKind kind; + private ushort itemID; public void Initialize(List items) { @@ -17,6 +20,10 @@ public void Initialize(List items) CB_ItemID.ValueMember = nameof(ComboItem.Value); CB_ItemID.DataSource = items; + CB_NamedItemArgument.DisplayMember = nameof(ComboItem.Text); + CB_NamedItemArgument.ValueMember = nameof(ComboItem.Value); + CB_NamedItemArgument.DataSource = Recipes; + LoadItem(Item.NO_ITEM); } @@ -40,5 +47,38 @@ public Item SetItem(Item item) item.Flags1 = (byte) NUD_Flag1.Value; return item; } + + private void CB_ItemID_SelectedValueChanged(object sender, EventArgs e) + { + itemID = (ushort)WinFormsUtil.GetIndex(CB_ItemID); + kind = ItemInfo.GetItemKind(itemID); + + switch (kind) + { + case ItemKind.Kind_DIYRecipe: + CB_NamedItemArgument.SelectedValue = (int) NUD_Count.Value; + + CB_NamedItemArgument.Visible = true; + FLP_Uses.Visible = FLP_Count.Visible = FLP_Flag0.Visible = FLP_Flag1.Visible = false; + break; + + default: + CB_NamedItemArgument.Visible = false; + FLP_Uses.Visible = FLP_Count.Visible = FLP_Flag0.Visible = FLP_Flag1.Visible = true; + break; + } + } + + private void CB_NamedItemArgument_SelectedValueChanged(object sender,EventArgs e) + { + var val = WinFormsUtil.GetIndex(CB_NamedItemArgument); + NUD_Count.Value = Math.Max(0, Math.Min(NUD_Count.Maximum, val)); + } + + private void NUD_Count_ValueChanged(object sender, EventArgs e) + { + if (kind == ItemKind.Kind_DIYRecipe) + CB_NamedItemArgument.SelectedValue = (int) NUD_Count.Value; + } } } diff --git a/NHSE.WinForms/Controls/ItemGridEditor.cs b/NHSE.WinForms/Controls/ItemGridEditor.cs index 0c1e1d9..61db0a2 100644 --- a/NHSE.WinForms/Controls/ItemGridEditor.cs +++ b/NHSE.WinForms/Controls/ItemGridEditor.cs @@ -81,7 +81,7 @@ public void Slot_MouseLeave(object? sender, EventArgs e) HoverTip.RemoveAll(); } - public static string GetItemText(Item item) => GameInfo.Strings.GetItemName(item.ItemId); + public static string GetItemText(Item item) => GameInfo.Strings.GetItemName(item); public void Slot_MouseClick(object sender, MouseEventArgs e) { diff --git a/NHSE.WinForms/Subforms/ItemReceivedEditor.cs b/NHSE.WinForms/Subforms/ItemReceivedEditor.cs index d104535..adf11ea 100644 --- a/NHSE.WinForms/Subforms/ItemReceivedEditor.cs +++ b/NHSE.WinForms/Subforms/ItemReceivedEditor.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Windows.Forms; using NHSE.Core; -using NHSE.Core.Structures; namespace NHSE.WinForms { diff --git a/NHSE.WinForms/Subforms/RecipeListEditor.cs b/NHSE.WinForms/Subforms/RecipeListEditor.cs index bb77e39..1ddc518 100644 --- a/NHSE.WinForms/Subforms/RecipeListEditor.cs +++ b/NHSE.WinForms/Subforms/RecipeListEditor.cs @@ -1,7 +1,6 @@ using System; using System.Windows.Forms; using NHSE.Core; -using NHSE.Core.Structures; namespace NHSE.WinForms {