Add dropdown to jump to specific recipe

This commit is contained in:
Kurt 2020-04-15 09:56:14 -07:00
parent 7e3003687b
commit 1af352dae5
2 changed files with 48 additions and 8 deletions

View File

@ -32,12 +32,14 @@ private void InitializeComponent()
this.B_Save = new System.Windows.Forms.Button();
this.CLB_Recipes = new System.Windows.Forms.CheckedListBox();
this.B_All = new System.Windows.Forms.Button();
this.CB_Goto = new System.Windows.Forms.ComboBox();
this.L_Goto = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// B_Cancel
//
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Cancel.Location = new System.Drawing.Point(130, 246);
this.B_Cancel.Location = new System.Drawing.Point(130, 326);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(72, 23);
this.B_Cancel.TabIndex = 7;
@ -48,7 +50,7 @@ private void InitializeComponent()
// B_Save
//
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Save.Location = new System.Drawing.Point(208, 246);
this.B_Save.Location = new System.Drawing.Point(208, 326);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(72, 23);
this.B_Save.TabIndex = 6;
@ -63,15 +65,15 @@ private void InitializeComponent()
| System.Windows.Forms.AnchorStyles.Right)));
this.CLB_Recipes.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.CLB_Recipes.FormattingEnabled = true;
this.CLB_Recipes.Location = new System.Drawing.Point(12, 12);
this.CLB_Recipes.Location = new System.Drawing.Point(12, 39);
this.CLB_Recipes.Name = "CLB_Recipes";
this.CLB_Recipes.Size = new System.Drawing.Size(268, 229);
this.CLB_Recipes.Size = new System.Drawing.Size(268, 274);
this.CLB_Recipes.TabIndex = 8;
//
// B_All
//
this.B_All.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_All.Location = new System.Drawing.Point(12, 247);
this.B_All.Location = new System.Drawing.Point(12, 327);
this.B_All.Name = "B_All";
this.B_All.Size = new System.Drawing.Size(82, 23);
this.B_All.TabIndex = 10;
@ -79,11 +81,35 @@ private void InitializeComponent()
this.B_All.UseVisualStyleBackColor = true;
this.B_All.Click += new System.EventHandler(this.B_All_Click);
//
// CB_Goto
//
this.CB_Goto.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CB_Goto.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Goto.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Goto.FormattingEnabled = true;
this.CB_Goto.Location = new System.Drawing.Point(78, 12);
this.CB_Goto.Name = "CB_Goto";
this.CB_Goto.Size = new System.Drawing.Size(202, 21);
this.CB_Goto.TabIndex = 11;
this.CB_Goto.SelectedValueChanged += new System.EventHandler(this.CB_Goto_SelectedValueChanged);
//
// L_Goto
//
this.L_Goto.Location = new System.Drawing.Point(12, 12);
this.L_Goto.Name = "L_Goto";
this.L_Goto.Size = new System.Drawing.Size(60, 21);
this.L_Goto.TabIndex = 12;
this.L_Goto.Text = "goto:";
this.L_Goto.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// RecipeListEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 281);
this.ClientSize = new System.Drawing.Size(292, 361);
this.Controls.Add(this.L_Goto);
this.Controls.Add(this.CB_Goto);
this.Controls.Add(this.B_All);
this.Controls.Add(this.CLB_Recipes);
this.Controls.Add(this.B_Cancel);
@ -104,5 +130,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_Save;
private System.Windows.Forms.CheckedListBox CLB_Recipes;
private System.Windows.Forms.Button B_All;
private System.Windows.Forms.ComboBox CB_Goto;
private System.Windows.Forms.Label L_Goto;
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NHSE.Core;
@ -15,15 +16,21 @@ public RecipeListEditor(Player player)
Player = player;
Known = Player.Personal.GetRecipeList();
InitializeComponent();
FillCheckBoxes();
var gotoSource = FillCheckBoxes();
gotoSource.SortByText();
CB_Goto.DisplayMember = nameof(ComboItem.Text);
CB_Goto.ValueMember = nameof(ComboItem.Value);
CB_Goto.DataSource = new BindingSource(gotoSource, null);
}
private void FillCheckBoxes()
private List<ComboItem> FillCheckBoxes()
{
var recipes = RecipeList.Recipes;
var max = (ushort)Known.Length - 1;
var strings = GameInfo.Strings.itemlist;
var gotoSource = new List<ComboItem>();
for (ushort i = 0; i <= max; i++)
{
bool exists = recipes.TryGetValue(i, out var value);
@ -32,7 +39,10 @@ private void FillCheckBoxes()
item = value.ToString();
string name = $"0x{i:X3} - {item}";
CLB_Recipes.Items.Add(name, Known[i]);
if (exists)
gotoSource.Add(new ComboItem(item, i));
}
return gotoSource;
}
private void B_All_Click(object sender, EventArgs e)
@ -54,5 +64,7 @@ private void B_Save_Click(object sender, EventArgs e)
Player.Personal.SetRecipeList(Known);
Close();
}
private void CB_Goto_SelectedValueChanged(object sender, EventArgs e) => CLB_Recipes.SelectedIndex = WinFormsUtil.GetIndex(CB_Goto);
}
}