diff --git a/NHSE.Core/Structures/GameLists.cs b/NHSE.Core/Structures/GameLists.cs index 687a4ab..16dbcda 100644 --- a/NHSE.Core/Structures/GameLists.cs +++ b/NHSE.Core/Structures/GameLists.cs @@ -4,6 +4,15 @@ namespace NHSE.Core { public static class GameLists { + public static readonly IReadOnlyList Fruits = new ushort[] + { + 2213, // apple + 2287, // Cherry + 2214, // Orange + 2286, // Peach + 2285, // Pear + }; + public static readonly IReadOnlyList Bugs = new ushort[] { 00582, // brown cicada diff --git a/NHSE.Core/Util/ComboItem.cs b/NHSE.Core/Util/ComboItem.cs index 0805908..3151571 100644 --- a/NHSE.Core/Util/ComboItem.cs +++ b/NHSE.Core/Util/ComboItem.cs @@ -42,6 +42,19 @@ public static List GetArray(string[] items) return result; } + public static List GetArray(IReadOnlyList values, string[] names) + { + var result = new List(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 storage, IReadOnlyList tuples, Dictionary translate) { int initial = storage.Count; diff --git a/NHSE.WinForms/Controls/RestrictedItemSelect.Designer.cs b/NHSE.WinForms/Controls/RestrictedItemSelect.Designer.cs new file mode 100644 index 0000000..b719815 --- /dev/null +++ b/NHSE.WinForms/Controls/RestrictedItemSelect.Designer.cs @@ -0,0 +1,99 @@ +namespace NHSE.WinForms +{ + partial class RestrictedItemSelect + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} diff --git a/NHSE.WinForms/Controls/RestrictedItemSelect.cs b/NHSE.WinForms/Controls/RestrictedItemSelect.cs new file mode 100644 index 0000000..cb0d8f7 --- /dev/null +++ b/NHSE.WinForms/Controls/RestrictedItemSelect.cs @@ -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 DataSource = Array.Empty(); + + public RestrictedItemSelect() => InitializeComponent(); + + public void Initialize(IList 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); + } + } +} diff --git a/NHSE.WinForms/Controls/RestrictedItemSelect.resx b/NHSE.WinForms/Controls/RestrictedItemSelect.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/NHSE.WinForms/Controls/RestrictedItemSelect.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs index 15c1aad..4224373 100644 --- a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs +++ b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs @@ -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; } -} \ No newline at end of file +} diff --git a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs index ede8a6c..d18ddac 100644 --- a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs +++ b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs @@ -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; } }