Add special handling for diy recipe

This commit is contained in:
Kurt
2020-04-06 20:11:35 -07:00
parent e989752e34
commit 6ecf659d5e
10 changed files with 193 additions and 34 deletions

View File

@@ -5792,7 +5792,7 @@ net
message bottle
DIY recipe
geometric-print pants (Blue)
dreamy dress (Pink)
flashy kimono (Green)

View File

@@ -35,6 +35,20 @@ private List<ComboItem> CreateItemDataSource(string[] strings)
return dataSource;
}
public List<ComboItem> CreateItemDataSource(IReadOnlyCollection<KeyValuePair<ushort, ushort>> dict, bool none = true)
{
var display = itemlistdisplay;
var result = new List<ComboItem>(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<string, string> GetMap(IReadOnlyCollection<string> arr)
{
var map = new Dictionary<string, string>(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];

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace NHSE.Core.Structures
namespace NHSE.Core
{
public static class GameLists
{

View File

@@ -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];
}
}
}

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace NHSE.Core.Structures
namespace NHSE.Core
{
public static class RecipeList
{

View File

@@ -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;
}
}

View File

@@ -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<ComboItem> Recipes = GameInfo.Strings.CreateItemDataSource(RecipeList.Recipes, false);
public ItemEditor() => InitializeComponent();
private ItemKind kind;
private ushort itemID;
public void Initialize(List<ComboItem> items)
{
@@ -17,6 +20,10 @@ public void Initialize(List<ComboItem> 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;
}
}
}

View File

@@ -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)
{

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Core.Structures;
namespace NHSE.WinForms
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Core.Structures;
namespace NHSE.WinForms
{