Add villager crafting editing functionality (#433)

* Add villager crafting editing functionality

* Add legacy villager1 support
This commit is contained in:
berichan 2020-12-02 20:42:32 +00:00 committed by GitHub
parent eb554a623b
commit 70fe4834da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 382 additions and 1 deletions

View File

@ -25,6 +25,11 @@ public interface IVillager : IVillagerOrigin
GSaveRoomFloorWall Room { get; set; }
DesignPatternPRO Design { get; set; }
public byte DIYEndHour { get; set; }
public byte DIYEndMinute { get; set; }
public byte DIYEndSecond { get; set; }
public ushort DIYRecipeIndex { get; set; }
GSaveMemory GetMemory(int index);
GSaveMemory[] GetMemories();
void SetMemory(GSaveMemory memory, int index);

View File

@ -116,6 +116,11 @@ public DesignPatternPRO Design
set => value.Data.CopyTo(Data, 0x12128);
}
public byte DIYEndHour { get => Data[0x129D1]; set => Data[0x129D1] = value; }
public byte DIYEndMinute { get => Data[0x129D2]; set => Data[0x129D2] = value; }
public byte DIYEndSecond { get => Data[0x129D3]; set => Data[0x129D3] = value; }
public ushort DIYRecipeIndex { get => Data.Slice(0x129D4, sizeof(ushort)).ToStructure<ushort>(); set => value.ToBytes().CopyTo(Data, 0x129D4); }
public void SetFriendshipAll(byte value = byte.MaxValue)
{
for (int i = 0; i < PlayerMemoryCount; i++)

View File

@ -116,6 +116,11 @@ public DesignPatternPRO Design
set => value.Data.CopyTo(Data, 0x128a8);
}
public byte DIYEndHour { get => Data[0x13151]; set => Data[0x13151] = value; }
public byte DIYEndMinute { get => Data[0x13152]; set => Data[0x13152] = value; }
public byte DIYEndSecond { get => Data[0x13153]; set => Data[0x13153] = value; }
public ushort DIYRecipeIndex { get => Data.Slice(0x13154, sizeof(ushort)).ToStructure<ushort>(); set => value.ToBytes().CopyTo(Data, 0x13154); }
public void SetFriendshipAll(byte value = byte.MaxValue)
{
for (int i = 0; i < PlayerMemoryCount; i++)

View File

@ -57,6 +57,7 @@ private void InitializeComponent()
this.NUD_Villager = new System.Windows.Forms.NumericUpDown();
this.B_EditHouses = new System.Windows.Forms.Button();
this.B_SetPhraseOriginal = new System.Windows.Forms.Button();
this.B_EditDIYTimer = new System.Windows.Forms.ToolStripMenuItem();
this.CM_EditVillager.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_Variant)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_Species)).BeginInit();
@ -104,10 +105,11 @@ private void InitializeComponent()
this.B_EditVillagerRoom,
this.B_EditVillagerDesign,
this.B_EditVillagerPlayerMemories,
this.B_EditDIYTimer,
this.TSS_toolStripSeparator1,
this.B_MoveOutAllVillagers});
this.CM_EditVillager.Name = "CM_EditPlayer";
this.CM_EditVillager.Size = new System.Drawing.Size(186, 114);
this.CM_EditVillager.Size = new System.Drawing.Size(186, 186);
//
// B_EditFurniture
//
@ -144,6 +146,11 @@ private void InitializeComponent()
this.B_EditVillagerPlayerMemories.Text = "Edit Player Memories";
this.B_EditVillagerPlayerMemories.Click += new System.EventHandler(this.B_EditVillagerPlayerMemories_Click);
//
// TSS_toolStripSeparator1
//
this.TSS_toolStripSeparator1.Name = "TSS_toolStripSeparator1";
this.TSS_toolStripSeparator1.Size = new System.Drawing.Size(182, 6);
//
// B_MoveOutAllVillagers
//
this.B_MoveOutAllVillagers.Name = "B_MoveOutAllVillagers";
@ -321,6 +328,13 @@ private void InitializeComponent()
this.B_SetPhraseOriginal.UseVisualStyleBackColor = true;
this.B_SetPhraseOriginal.Click += new System.EventHandler(this.B_SetPhraseOriginal_Click);
//
// B_EditDIYTimer
//
this.B_EditDIYTimer.Name = "B_EditDIYTimer";
this.B_EditDIYTimer.Size = new System.Drawing.Size(185, 22);
this.B_EditDIYTimer.Text = "Edit DIY Timer";
this.B_EditDIYTimer.Click += new System.EventHandler(this.B_EditDIYTimer_Click);
//
// VillagerEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -387,5 +401,6 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem B_MoveOutAllVillagers;
private System.Windows.Forms.ToolStripMenuItem B_EditWear;
private System.Windows.Forms.Button B_SetPhraseOriginal;
private System.Windows.Forms.ToolStripMenuItem B_EditDIYTimer;
}
}

View File

@ -247,6 +247,14 @@ private void B_EditVillagerPlayerMemories_Click(object sender, EventArgs e)
{ } // editor saves our changes
}
private void B_EditDIYTimer_Click(object sender, EventArgs e)
{
var v = Villagers[VillagerIndex];
using var editor = new VillagerDIYTimerEditor(v);
if (editor.ShowDialog() == DialogResult.OK)
{ } // editor saves our changes
}
private void B_MoveOutAllVillagers_Click(object sender, EventArgs e)
{
if (Loading)

View File

@ -0,0 +1,144 @@

namespace NHSE.WinForms
{
partial class VillagerDIYTimerEditor
{
/// <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 Windows Form 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.CHK_Crafting = new System.Windows.Forms.CheckBox();
this.DT_Time = new System.Windows.Forms.DateTimePicker();
this.L_EndTime = new System.Windows.Forms.Label();
this.L_Recipe = new System.Windows.Forms.Label();
this.CB_Recipe = new System.Windows.Forms.ComboBox();
this.B_Save = new System.Windows.Forms.Button();
this.B_Cancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// CHK_Crafting
//
this.CHK_Crafting.AutoSize = true;
this.CHK_Crafting.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.CHK_Crafting.Location = new System.Drawing.Point(21, 13);
this.CHK_Crafting.Name = "CHK_Crafting";
this.CHK_Crafting.Size = new System.Drawing.Size(78, 17);
this.CHK_Crafting.TabIndex = 1;
this.CHK_Crafting.Text = "Is crafting?";
this.CHK_Crafting.UseVisualStyleBackColor = true;
this.CHK_Crafting.CheckedChanged += new System.EventHandler(this.CHK_Crafting_CheckedChanged);
//
// DT_Time
//
this.DT_Time.Format = System.Windows.Forms.DateTimePickerFormat.Time;
this.DT_Time.Location = new System.Drawing.Point(91, 38);
this.DT_Time.Name = "DT_Time";
this.DT_Time.ShowUpDown = true;
this.DT_Time.Size = new System.Drawing.Size(78, 20);
this.DT_Time.TabIndex = 2;
this.DT_Time.ValueChanged += new System.EventHandler(this.DT_Time_ValueChanged);
//
// L_EndTime
//
this.L_EndTime.AutoSize = true;
this.L_EndTime.Location = new System.Drawing.Point(21, 41);
this.L_EndTime.Name = "L_EndTime";
this.L_EndTime.Size = new System.Drawing.Size(68, 13);
this.L_EndTime.TabIndex = 3;
this.L_EndTime.Text = "Crafting until:";
//
// L_Recipe
//
this.L_Recipe.AutoSize = true;
this.L_Recipe.Location = new System.Drawing.Point(20, 68);
this.L_Recipe.Name = "L_Recipe";
this.L_Recipe.Size = new System.Drawing.Size(44, 13);
this.L_Recipe.TabIndex = 4;
this.L_Recipe.Text = "Recipe:";
//
// CB_Recipe
//
this.CB_Recipe.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Recipe.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Recipe.DropDownWidth = 322;
this.CB_Recipe.FormattingEnabled = true;
this.CB_Recipe.Location = new System.Drawing.Point(65, 66);
this.CB_Recipe.Name = "CB_Recipe";
this.CB_Recipe.Size = new System.Drawing.Size(160, 21);
this.CB_Recipe.TabIndex = 5;
this.CB_Recipe.SelectedIndexChanged += new System.EventHandler(this.CB_Recipe_SelectedIndexChanged);
//
// B_Save
//
this.B_Save.Location = new System.Drawing.Point(21, 100);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(92, 23);
this.B_Save.TabIndex = 6;
this.B_Save.Text = "Save";
this.B_Save.UseVisualStyleBackColor = true;
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
//
// B_Cancel
//
this.B_Cancel.Location = new System.Drawing.Point(133, 100);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(92, 23);
this.B_Cancel.TabIndex = 7;
this.B_Cancel.Text = "Cancel";
this.B_Cancel.UseVisualStyleBackColor = true;
this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click);
//
// VillagerDIYTimerEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(245, 142);
this.Controls.Add(this.B_Cancel);
this.Controls.Add(this.B_Save);
this.Controls.Add(this.CB_Recipe);
this.Controls.Add(this.L_Recipe);
this.Controls.Add(this.L_EndTime);
this.Controls.Add(this.DT_Time);
this.Controls.Add(this.CHK_Crafting);
this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
this.Name = "VillagerDIYTimerEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Villager DIY Editor";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.CheckBox CHK_Crafting;
private System.Windows.Forms.DateTimePicker DT_Time;
private System.Windows.Forms.Label L_EndTime;
private System.Windows.Forms.Label L_Recipe;
private System.Windows.Forms.ComboBox CB_Recipe;
private System.Windows.Forms.Button B_Save;
private System.Windows.Forms.Button B_Cancel;
}
}

View File

@ -0,0 +1,79 @@
using NHSE.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NHSE.WinForms
{
public partial class VillagerDIYTimerEditor : Form
{
private readonly List<ComboItem> Recipes = GameInfo.Strings.CreateItemDataSource(RecipeList.Recipes, false);
private readonly IVillager Villager;
private byte Hour, Minute, Second;
private ushort RecipeIndex;
public VillagerDIYTimerEditor(IVillager v)
{
Villager = v;
Hour = Villager.DIYEndHour;
Minute = Villager.DIYEndMinute;
Second = Villager.DIYEndSecond;
InitializeComponent();
// Both hour and minute will be 255 in most cases when villager is idling.
// If another villager's end time is earlier, this villager will not craft UNLESS the villager is crafting an "event" item, in which case it seems it will take priority.
bool idleState = Hour == byte.MaxValue || Minute == byte.MaxValue;
DT_Time.Value = idleState ? new DateTime(1970, 01, 01, 0, 0, 0) : new DateTime(1970, 01, 01, Hour, Minute, Second);
CHK_Crafting.Checked = DT_Time.Enabled = !idleState;
CB_Recipe.DisplayMember = nameof(ComboItem.Text);
CB_Recipe.ValueMember = nameof(ComboItem.Value);
CB_Recipe.DataSource = Recipes;
RecipeIndex = Villager.DIYRecipeIndex;
CB_Recipe.SelectedValue = (int)RecipeIndex;
}
private void CB_Recipe_SelectedIndexChanged(object sender, EventArgs e)
{
var val = WinFormsUtil.GetIndex((ComboBox)sender);
RecipeIndex = (ushort)Math.Max(0, Math.Min(ushort.MaxValue, val));
}
private void B_Cancel_Click(object sender, EventArgs e) => Close();
private void B_Save_Click(object sender, EventArgs e)
{
Villager.DIYEndHour = Hour;
Villager.DIYEndMinute = Minute;
Villager.DIYEndSecond = Second;
Villager.DIYRecipeIndex = RecipeIndex;
DialogResult = DialogResult.OK;
Close();
}
private void CHK_Crafting_CheckedChanged(object sender, EventArgs e)
{
Hour = CHK_Crafting.Checked ? (byte)DT_Time.Value.Hour : byte.MaxValue;
Minute = CHK_Crafting.Checked ? (byte)DT_Time.Value.Minute : byte.MaxValue;
DT_Time.Enabled = CHK_Crafting.Checked;
}
private void DT_Time_ValueChanged(object sender, EventArgs e)
{
Hour = (byte)DT_Time.Value.Hour;
Minute = (byte)DT_Time.Value.Minute;
Second = (byte)DT_Time.Value.Second;
}
}
}

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>