Add custom picker for specialty fruit

Closes #181
This commit is contained in:
Kurt
2020-05-09 10:58:19 -07:00
parent 6eff348fa5
commit 0085c453d4
7 changed files with 318 additions and 26 deletions

View File

@@ -4,6 +4,15 @@ namespace NHSE.Core
{
public static class GameLists
{
public static readonly IReadOnlyList<ushort> Fruits = new ushort[]
{
2213, // apple
2287, // Cherry
2214, // Orange
2286, // Peach
2285, // Pear
};
public static readonly IReadOnlyList<ushort> Bugs = new ushort[]
{
00582, // brown cicada

View File

@@ -42,6 +42,19 @@ public static List<ComboItem> GetArray(string[] items)
return result;
}
public static List<ComboItem> GetArray(IReadOnlyList<ushort> values, string[] names)
{
var result = new List<ComboItem>(values.Count);
foreach (var value in values)
{
var text = names[value];
var item = new ComboItem(text, value);
result.Add(item);
}
return result;
}
public static void Add(this List<ComboItem> storage, IReadOnlyList<INamedValue> tuples, Dictionary<string, string> translate)
{
int initial = storage.Count;

View File

@@ -0,0 +1,99 @@
namespace NHSE.WinForms
{
partial class RestrictedItemSelect
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CB_ItemID = new System.Windows.Forms.ComboBox();
this.NUD_CustomItem = new System.Windows.Forms.NumericUpDown();
this.CHK_CustomItem = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.NUD_CustomItem)).BeginInit();
this.SuspendLayout();
//
// CB_ItemID
//
this.CB_ItemID.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
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(0, 0);
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 = 2;
this.CB_ItemID.SelectedValueChanged += new System.EventHandler(this.CB_ItemID_SelectedValueChanged);
//
// numericUpDown1
//
this.NUD_CustomItem.Location = new System.Drawing.Point(91, 25);
this.NUD_CustomItem.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.NUD_CustomItem.Name = "NUD_CustomItem";
this.NUD_CustomItem.Size = new System.Drawing.Size(50, 20);
this.NUD_CustomItem.TabIndex = 3;
this.NUD_CustomItem.Value = new decimal(new int[] {
65535,
0,
0,
0});
//
// CHK_Custom
//
this.CHK_CustomItem.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.CHK_CustomItem.Location = new System.Drawing.Point(5, 25);
this.CHK_CustomItem.Name = "CHK_CustomItem";
this.CHK_CustomItem.Size = new System.Drawing.Size(80, 20);
this.CHK_CustomItem.TabIndex = 4;
this.CHK_CustomItem.Text = "Custom";
this.CHK_CustomItem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.CHK_CustomItem.UseVisualStyleBackColor = true;
this.CHK_CustomItem.CheckedChanged += new System.EventHandler(this.CHK_Custom_CheckedChanged);
//
// RestrictedItemSelect
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.CHK_CustomItem);
this.Controls.Add(this.NUD_CustomItem);
this.Controls.Add(this.CB_ItemID);
this.Name = "RestrictedItemSelect";
this.Size = new System.Drawing.Size(143, 48);
((System.ComponentModel.ISupportInitialize)(this.NUD_CustomItem)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox CB_ItemID;
private System.Windows.Forms.NumericUpDown NUD_CustomItem;
private System.Windows.Forms.CheckBox CHK_CustomItem;
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NHSE.Core;
namespace NHSE.WinForms
{
public partial class RestrictedItemSelect : UserControl
{
private IList<ComboItem> DataSource = Array.Empty<ComboItem>();
public RestrictedItemSelect() => InitializeComponent();
public void Initialize(IList<ComboItem> items, bool canType = false)
{
CB_ItemID.DisplayMember = nameof(ComboItem.Text);
CB_ItemID.ValueMember = nameof(ComboItem.Value);
CB_ItemID.DataSource = DataSource = items;
if (!canType)
CB_ItemID.DropDownStyle = ComboBoxStyle.DropDownList;
}
public ushort Value
{
get => CHK_CustomItem.Checked ? (ushort) NUD_CustomItem.Value : (ushort) WinFormsUtil.GetIndex(CB_ItemID);
set
{
if (DataSource.Any(z => z.Value == value))
{
CHK_CustomItem.Checked = false;
CB_ItemID.SelectedValue = (int)value;
}
else
{
CHK_CustomItem.Checked = true;
NUD_CustomItem.Value = value;
}
}
}
private void CHK_Custom_CheckedChanged(object sender, EventArgs e)
{
CB_ItemID.Enabled = !CHK_CustomItem.Checked;
NUD_CustomItem.Enabled = CHK_CustomItem.Checked;
}
private void CB_ItemID_SelectedValueChanged(object sender, EventArgs e)
{
NUD_CustomItem.Value = WinFormsUtil.GetIndex(CB_ItemID);
}
}
}

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>

View File

@@ -36,23 +36,22 @@ private void InitializeComponent()
this.tabControl1 = new System.Windows.Forms.TabControl();
this.Tab_Misc = new System.Windows.Forms.TabPage();
this.Tab_Profile = new System.Windows.Forms.TabPage();
this.ProfileFruit = new NHSE.WinForms.RestrictedItemSelect();
this.CAL_ProfileTimestamp = new System.Windows.Forms.DateTimePicker();
this.CHK_ProfileMadeVillage = new System.Windows.Forms.CheckBox();
this.L_ProfileSpecialtyFruit = new System.Windows.Forms.Label();
this.NUD_ProfileFruit = new System.Windows.Forms.NumericUpDown();
this.L_ProfileTimestamp = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.NUD_BirthMonth)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_BirthDay)).BeginInit();
this.tabControl1.SuspendLayout();
this.Tab_Misc.SuspendLayout();
this.Tab_Profile.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_ProfileFruit)).BeginInit();
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(92, 156);
this.B_Cancel.Location = new System.Drawing.Point(133, 181);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(72, 23);
this.B_Cancel.TabIndex = 7;
@@ -63,7 +62,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(170, 156);
this.B_Save.Location = new System.Drawing.Point(211, 181);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(72, 23);
this.B_Save.TabIndex = 6;
@@ -116,7 +115,7 @@ private void InitializeComponent()
this.tabControl1.Location = new System.Drawing.Point(12, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(230, 138);
this.tabControl1.Size = new System.Drawing.Size(271, 163);
this.tabControl1.TabIndex = 12;
//
// Tab_Misc
@@ -134,19 +133,27 @@ private void InitializeComponent()
//
// Tab_Profile
//
this.Tab_Profile.Controls.Add(this.ProfileFruit);
this.Tab_Profile.Controls.Add(this.CAL_ProfileTimestamp);
this.Tab_Profile.Controls.Add(this.CHK_ProfileMadeVillage);
this.Tab_Profile.Controls.Add(this.L_ProfileSpecialtyFruit);
this.Tab_Profile.Controls.Add(this.NUD_ProfileFruit);
this.Tab_Profile.Controls.Add(this.L_ProfileTimestamp);
this.Tab_Profile.Location = new System.Drawing.Point(4, 22);
this.Tab_Profile.Name = "Tab_Profile";
this.Tab_Profile.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Profile.Size = new System.Drawing.Size(222, 112);
this.Tab_Profile.Size = new System.Drawing.Size(263, 137);
this.Tab_Profile.TabIndex = 1;
this.Tab_Profile.Text = "Profile";
this.Tab_Profile.UseVisualStyleBackColor = true;
//
// restrictedItemSelect1
//
this.ProfileFruit.Location = new System.Drawing.Point(9, 61);
this.ProfileFruit.Name = "ProfileFruit";
this.ProfileFruit.Size = new System.Drawing.Size(143, 48);
this.ProfileFruit.TabIndex = 17;
this.ProfileFruit.Value = ((ushort)(0));
//
// CAL_ProfileTimestamp
//
this.CAL_ProfileTimestamp.Location = new System.Drawing.Point(9, 22);
@@ -157,7 +164,7 @@ private void InitializeComponent()
// CHK_ProfileMadeVillage
//
this.CHK_ProfileMadeVillage.AutoSize = true;
this.CHK_ProfileMadeVillage.Location = new System.Drawing.Point(9, 87);
this.CHK_ProfileMadeVillage.Location = new System.Drawing.Point(9, 115);
this.CHK_ProfileMadeVillage.Name = "CHK_ProfileMadeVillage";
this.CHK_ProfileMadeVillage.Size = new System.Drawing.Size(87, 17);
this.CHK_ProfileMadeVillage.TabIndex = 15;
@@ -173,18 +180,6 @@ private void InitializeComponent()
this.L_ProfileSpecialtyFruit.TabIndex = 14;
this.L_ProfileSpecialtyFruit.Text = "Fruit";
//
// NUD_ProfileFruit
//
this.NUD_ProfileFruit.Location = new System.Drawing.Point(9, 61);
this.NUD_ProfileFruit.Maximum = new decimal(new int[] {
65534,
0,
0,
0});
this.NUD_ProfileFruit.Name = "NUD_ProfileFruit";
this.NUD_ProfileFruit.Size = new System.Drawing.Size(58, 20);
this.NUD_ProfileFruit.TabIndex = 13;
//
// L_ProfileTimestamp
//
this.L_ProfileTimestamp.AutoSize = true;
@@ -198,7 +193,7 @@ private void InitializeComponent()
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(254, 191);
this.ClientSize = new System.Drawing.Size(295, 216);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.B_Cancel);
this.Controls.Add(this.B_Save);
@@ -215,7 +210,6 @@ private void InitializeComponent()
this.Tab_Misc.ResumeLayout(false);
this.Tab_Profile.ResumeLayout(false);
this.Tab_Profile.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_ProfileFruit)).EndInit();
this.ResumeLayout(false);
}
@@ -232,8 +226,8 @@ private void InitializeComponent()
private System.Windows.Forms.TabPage Tab_Profile;
private System.Windows.Forms.Label L_ProfileTimestamp;
private System.Windows.Forms.Label L_ProfileSpecialtyFruit;
private System.Windows.Forms.NumericUpDown NUD_ProfileFruit;
private System.Windows.Forms.CheckBox CHK_ProfileMadeVillage;
private System.Windows.Forms.DateTimePicker CAL_ProfileTimestamp;
private RestrictedItemSelect ProfileFruit;
}
}
}

View File

@@ -14,6 +14,9 @@ public MiscPlayerEditor(Player p)
this.TranslateInterface(GameInfo.CurrentLanguage);
Player = p;
var fruits = ComboItemUtil.GetArray(GameLists.Fruits, GameInfo.Strings.itemlistdisplay);
ProfileFruit.Initialize(fruits);
LoadPlayer();
}
@@ -27,7 +30,7 @@ private void LoadPlayer()
NUD_BirthMonth.Value = bd.Month;
CHK_ProfileMadeVillage.Checked = pers.ProfileIsMakeVillage;
NUD_ProfileFruit.Value = pers.ProfileFruit;
ProfileFruit.Value = pers.ProfileFruit;
CAL_ProfileTimestamp.Value = pers.ProfileTimestamp;
}
@@ -51,7 +54,7 @@ private void SavePlayer()
pers.Birthday = bd;
pers.ProfileBirthday = bd;
pers.ProfileIsMakeVillage = CHK_ProfileMadeVillage.Checked;
pers.ProfileFruit = (ushort)NUD_ProfileFruit.Value;
pers.ProfileFruit = ProfileFruit.Value;
pers.ProfileTimestamp = CAL_ProfileTimestamp.Value;
}
}