Abstract Flag1 for wrapping in GUI

MessageBottle uses Flag1 for different purposes
This commit is contained in:
Kurt
2020-05-18 11:29:38 -07:00
parent 0be1bb87a1
commit f05f59736b
5 changed files with 175 additions and 55 deletions

View File

@@ -31,9 +31,42 @@ public class Item : ICopyableItem<Item>
public bool Is_40 => (SystemParam & 0x40) != 0;
public bool Is_80 => (SystemParam & 0x80) != 0;
public ItemWrapping WrappingType => (ItemWrapping)(AdditionalParam & 3);
public int WrappingPaper => (AdditionalParam >> 2) & 0xF;
#region Flag1 (Wrapping / Etc)
public bool IsWrapped
{
get
{
if (AdditionalParam == 0)
return false;
var id = DisplayItemId;
return id != MessageBottle && id != MessageBottleEgg;
}
}
public ItemWrapping WrappingType
{
get => (ItemWrapping) (AdditionalParam & 3);
set => AdditionalParam = (byte)((AdditionalParam & ~3) | ((byte)value & 3));
}
public ItemWrappingPaper WrappingPaper
{
get => (ItemWrappingPaper) ((AdditionalParam >> 2) & 0xF);
set => AdditionalParam = (byte)((AdditionalParam & 3) | ((byte)value & 0xF) << 2);
}
public void SetWrapping(ItemWrapping wrap, ItemWrappingPaper color)
{
if (wrap == ItemWrapping.Nothing || wrap > ItemWrapping.Delivery)
{
AdditionalParam = 0;
return;
}
WrappingType = wrap;
WrappingPaper = wrap == ItemWrapping.WrappingPaper ? color : 0;
}
// 2 bits ???
#endregion
#region Stackable Items
[field: FieldOffset(4)] public ushort Count { get; set; }
@@ -175,7 +208,7 @@ public ushort GetWrappedItemName()
{
return WrappingType switch
{
ItemWrapping.WrappingPaper => (ushort) (0x1E13 + WrappingPaper),
ItemWrapping.WrappingPaper => (ushort) (0x1E13 + (ushort)WrappingPaper),
ItemWrapping.Present => 0x1180,
ItemWrapping.Delivery => 0x1225,
_ => ItemId,

View File

@@ -112,7 +112,6 @@ private static void DrawDirectionals(int[] data, ItemLayer layer, int w, int x0,
private static void DrawGene(int[] data, int x0, int y0, int scale, int w, uint geneValue, int geneIndex)
{
var c = ShiftToGeneCoordinate(ref x0, ref y0, scale, geneIndex);
FillSquare(data, x0, y0, scale / 2, w, c, geneValue == 3 ? 1 : 2);
}

View File

@@ -28,7 +28,6 @@ protected override void Dispose(bool disposing)
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.CB_ItemID = new System.Windows.Forms.ComboBox();
this.NUD_Count = new System.Windows.Forms.NumericUpDown();
this.L_Count = new System.Windows.Forms.Label();
@@ -38,10 +37,6 @@ private void InitializeComponent()
this.NUD_Flag0 = new System.Windows.Forms.NumericUpDown();
this.L_Flag1 = new System.Windows.Forms.Label();
this.NUD_Flag1 = new System.Windows.Forms.NumericUpDown();
this.CM_Hand = new System.Windows.Forms.ContextMenuStrip(this.components);
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_Recipe = new System.Windows.Forms.ComboBox();
this.FLP_Controls = new System.Windows.Forms.FlowLayoutPanel();
this.PB_Item = new System.Windows.Forms.PictureBox();
@@ -88,11 +83,15 @@ private void InitializeComponent()
this.CHK_WV6 = new System.Windows.Forms.CheckBox();
this.CHK_WV9 = new System.Windows.Forms.CheckBox();
this.CHK_Gold = new System.Windows.Forms.CheckBox();
this.FLP_Flag1Group = new System.Windows.Forms.FlowLayoutPanel();
this.CHK_Wrapped = new System.Windows.Forms.CheckBox();
this.FLP_Wrapped = new System.Windows.Forms.FlowLayoutPanel();
this.CB_WrapType = new System.Windows.Forms.ComboBox();
this.CB_WrapColor = new System.Windows.Forms.ComboBox();
((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.FLP_Controls.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_Item)).BeginInit();
this.FLP_Meta.SuspendLayout();
@@ -108,6 +107,8 @@ private void InitializeComponent()
this.FLP_Genetics.SuspendLayout();
this.FLP_FlowerFlags.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_WaterDays)).BeginInit();
this.FLP_Flag1Group.SuspendLayout();
this.FLP_Wrapped.SuspendLayout();
this.SuspendLayout();
//
// CB_ItemID
@@ -216,33 +217,6 @@ private void InitializeComponent()
this.NUD_Flag1.Size = new System.Drawing.Size(56, 20);
this.NUD_Flag1.TabIndex = 12;
//
// CM_Hand
//
this.CM_Hand.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.Menu_View,
this.Menu_Set,
this.Menu_Delete});
this.CM_Hand.Name = "CM_Hand";
this.CM_Hand.Size = new System.Drawing.Size(108, 70);
//
// Menu_View
//
this.Menu_View.Name = "Menu_View";
this.Menu_View.Size = new System.Drawing.Size(107, 22);
this.Menu_View.Text = "View";
//
// Menu_Set
//
this.Menu_Set.Name = "Menu_Set";
this.Menu_Set.Size = new System.Drawing.Size(107, 22);
this.Menu_Set.Text = "Set";
//
// Menu_Delete
//
this.Menu_Delete.Name = "Menu_Delete";
this.Menu_Delete.Size = new System.Drawing.Size(107, 22);
this.Menu_Delete.Text = "Delete";
//
// CB_Recipe
//
this.CB_Recipe.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
@@ -266,6 +240,7 @@ private void InitializeComponent()
this.FLP_Controls.Controls.Add(this.PB_Item);
this.FLP_Controls.Controls.Add(this.FLP_Meta);
this.FLP_Controls.Controls.Add(this.FLP_Item);
this.FLP_Controls.Controls.Add(this.FLP_Flag1Group);
this.FLP_Controls.Dock = System.Windows.Forms.DockStyle.Fill;
this.FLP_Controls.Location = new System.Drawing.Point(0, 0);
this.FLP_Controls.Margin = new System.Windows.Forms.Padding(0);
@@ -407,12 +382,11 @@ private void InitializeComponent()
this.FLP_Item.Controls.Add(this.FLP_Count);
this.FLP_Item.Controls.Add(this.FLP_Uses);
this.FLP_Item.Controls.Add(this.FLP_Flag0);
this.FLP_Item.Controls.Add(this.FLP_Flag1);
this.FLP_Item.Controls.Add(this.FLP_Flower);
this.FLP_Item.Location = new System.Drawing.Point(0, 204);
this.FLP_Item.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Item.Name = "FLP_Item";
this.FLP_Item.Size = new System.Drawing.Size(152, 324);
this.FLP_Item.Size = new System.Drawing.Size(152, 298);
this.FLP_Item.TabIndex = 25;
//
// FLP_Count
@@ -486,7 +460,7 @@ private void InitializeComponent()
//
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, 128);
this.FLP_Flag1.Location = new System.Drawing.Point(0, 0);
this.FLP_Flag1.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Flag1.Name = "FLP_Flag1";
this.FLP_Flag1.Size = new System.Drawing.Size(152, 26);
@@ -498,7 +472,7 @@ private void InitializeComponent()
this.FLP_Flower.Controls.Add(this.FLP_Genetics);
this.FLP_Flower.Controls.Add(this.PAN_DummyFlower);
this.FLP_Flower.Controls.Add(this.FLP_FlowerFlags);
this.FLP_Flower.Location = new System.Drawing.Point(0, 154);
this.FLP_Flower.Location = new System.Drawing.Point(0, 128);
this.FLP_Flower.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Flower.Name = "FLP_Flower";
this.FLP_Flower.Size = new System.Drawing.Size(152, 170);
@@ -843,6 +817,67 @@ private void InitializeComponent()
this.CHK_Gold.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.CHK_Gold.UseVisualStyleBackColor = true;
//
// FLP_Flag1Group
//
this.FLP_Flag1Group.AutoSize = true;
this.FLP_Flag1Group.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.FLP_Flag1Group.Controls.Add(this.FLP_Flag1);
this.FLP_Flag1Group.Controls.Add(this.CHK_Wrapped);
this.FLP_Flag1Group.Controls.Add(this.FLP_Wrapped);
this.FLP_Flag1Group.Location = new System.Drawing.Point(0, 502);
this.FLP_Flag1Group.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Flag1Group.Name = "FLP_Flag1Group";
this.FLP_Flag1Group.Size = new System.Drawing.Size(152, 91);
this.FLP_Flag1Group.TabIndex = 31;
//
// CHK_Wrapped
//
this.CHK_Wrapped.AutoSize = true;
this.FLP_Flag1Group.SetFlowBreak(this.CHK_Wrapped, true);
this.CHK_Wrapped.Location = new System.Drawing.Point(17, 29);
this.CHK_Wrapped.Margin = new System.Windows.Forms.Padding(17, 3, 3, 3);
this.CHK_Wrapped.Name = "CHK_Wrapped";
this.CHK_Wrapped.Size = new System.Drawing.Size(70, 17);
this.CHK_Wrapped.TabIndex = 27;
this.CHK_Wrapped.Text = "Wrapped";
this.CHK_Wrapped.UseVisualStyleBackColor = true;
this.CHK_Wrapped.CheckedChanged += new System.EventHandler(this.CHK_Wrapped_CheckedChanged);
//
// FLP_Wrapped
//
this.FLP_Wrapped.AutoSize = true;
this.FLP_Wrapped.Controls.Add(this.CB_WrapType);
this.FLP_Wrapped.Controls.Add(this.CB_WrapColor);
this.FLP_Flag1Group.SetFlowBreak(this.FLP_Wrapped, true);
this.FLP_Wrapped.Location = new System.Drawing.Point(0, 49);
this.FLP_Wrapped.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Wrapped.Name = "FLP_Wrapped";
this.FLP_Wrapped.Size = new System.Drawing.Size(121, 42);
this.FLP_Wrapped.TabIndex = 24;
this.FLP_Wrapped.Visible = false;
//
// CB_WrapType
//
this.CB_WrapType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_WrapType.FormattingEnabled = true;
this.CB_WrapType.Location = new System.Drawing.Point(0, 0);
this.CB_WrapType.Margin = new System.Windows.Forms.Padding(0);
this.CB_WrapType.Name = "CB_WrapType";
this.CB_WrapType.Size = new System.Drawing.Size(121, 21);
this.CB_WrapType.TabIndex = 27;
this.CB_WrapType.SelectedIndexChanged += new System.EventHandler(this.CB_WrapType_SelectedIndexChanged);
//
// CB_WrapColor
//
this.CB_WrapColor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_WrapColor.FormattingEnabled = true;
this.CB_WrapColor.Location = new System.Drawing.Point(0, 21);
this.CB_WrapColor.Margin = new System.Windows.Forms.Padding(0);
this.CB_WrapColor.Name = "CB_WrapColor";
this.CB_WrapColor.Size = new System.Drawing.Size(121, 21);
this.CB_WrapColor.TabIndex = 28;
this.CB_WrapColor.Visible = false;
//
// ItemEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -854,7 +889,6 @@ private void InitializeComponent()
((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.FLP_Controls.ResumeLayout(false);
this.FLP_Controls.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_Item)).EndInit();
@@ -876,6 +910,9 @@ private void InitializeComponent()
this.FLP_FlowerFlags.ResumeLayout(false);
this.FLP_FlowerFlags.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_WaterDays)).EndInit();
this.FLP_Flag1Group.ResumeLayout(false);
this.FLP_Flag1Group.PerformLayout();
this.FLP_Wrapped.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -891,10 +928,6 @@ private void InitializeComponent()
private System.Windows.Forms.NumericUpDown NUD_Flag0;
private System.Windows.Forms.Label L_Flag1;
private System.Windows.Forms.NumericUpDown NUD_Flag1;
private System.Windows.Forms.ContextMenuStrip CM_Hand;
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_Recipe;
private System.Windows.Forms.FlowLayoutPanel FLP_Controls;
private System.Windows.Forms.FlowLayoutPanel FLP_Count;
@@ -941,5 +974,10 @@ private void InitializeComponent()
private System.Windows.Forms.Panel PAN_DummyExtension;
private System.Windows.Forms.FlowLayoutPanel FLP_Meta;
private System.Windows.Forms.Panel PAN_DummyFlower;
private System.Windows.Forms.FlowLayoutPanel FLP_Flag1Group;
private System.Windows.Forms.CheckBox CHK_Wrapped;
private System.Windows.Forms.FlowLayoutPanel FLP_Wrapped;
private System.Windows.Forms.ComboBox CB_WrapType;
private System.Windows.Forms.ComboBox CB_WrapColor;
}
}

View File

@@ -19,6 +19,9 @@ public ItemEditor()
{
InitializeComponent();
CB_WrapColor.Items.AddRange(Enum.GetNames(typeof(ItemWrappingPaper)));
CB_WrapType.Items.AddRange(Enum.GetNames(typeof(ItemWrapping)));
Watered = new[]
{
CHK_WV0, CHK_WV1,
@@ -73,9 +76,19 @@ public Item LoadItem(Item item)
NUD_Count.Value = item.Count;
NUD_Uses.Value = item.UseCount;
NUD_Flag0.Value = item.SystemParam;
NUD_Flag1.Value = item.AdditionalParam;
LoadItemTypeValues(kind);
if (kind == ItemKind.Kind_MessageBottle || id >= 60_000)
{
NUD_Flag1.Value = item.AdditionalParam;
}
else
{
CHK_Wrapped.Checked = item.WrappingType != 0;
CB_WrapType.SelectedIndex = (int)item.WrappingType;
CB_WrapColor.SelectedIndex = (int)item.WrappingPaper;
}
LoadItemTypeValues(kind, id);
}
Loading = false;
@@ -108,13 +121,27 @@ public Item SetItem(Item item)
item.IsWatered = CHK_IsWatered.Checked;
for (int i = 0; i < Watered.Length; i++)
item.SetIsWateredByVisitor(i, Watered[i].Checked);
item.SystemParam = 0;
item.AdditionalParam = 0;
}
else
{
item.Count = (ushort)NUD_Count.Value;
item.UseCount = (ushort)NUD_Uses.Value;
item.SystemParam = (byte)NUD_Flag0.Value;
item.AdditionalParam = (byte)NUD_Flag1.Value;
if (kind == ItemKind.Kind_MessageBottle)
{
item.AdditionalParam = (byte)NUD_Flag1.Value;
}
else
{
if (CHK_Wrapped.Checked)
item.SetWrapping((ItemWrapping)CB_WrapType.SelectedIndex, (ItemWrappingPaper)CB_WrapColor.SelectedIndex);
else
item.SetWrapping(0, 0);
}
}
return item;
}
@@ -137,7 +164,7 @@ private void CB_ItemID_SelectedValueChanged(object sender, EventArgs e)
ToggleEditorVisibility(kind);
if (!Loading)
LoadItemTypeValues(kind);
LoadItemTypeValues(kind, itemID);
var remake = ItemRemakeUtil.GetRemakeIndex(itemID);
if (remake < 0)
@@ -158,8 +185,16 @@ private void CB_ItemID_SelectedValueChanged(object sender, EventArgs e)
}
}
private void LoadItemTypeValues(ItemKind k)
private void LoadItemTypeValues(ItemKind k, ushort index)
{
if (index >= 60_000)
{
CHK_Wrapped.Checked = false;
CHK_Wrapped.Visible = CHK_Wrapped.Checked = false;
FLP_Flag1.Visible = true;
return;
}
switch (k)
{
case ItemKind.Kind_FossilUnknown:
@@ -167,10 +202,19 @@ private void LoadItemTypeValues(ItemKind k)
break;
case ItemKind.Kind_DIYRecipe:
CB_Recipe.SelectedValue = (int)NUD_Count.Value;
break;
case ItemKind.Kind_MessageBottle:
CB_Recipe.SelectedValue = (int) NUD_Count.Value;
break;
CHK_Wrapped.Checked = false;
CHK_Wrapped.Visible = CHK_Wrapped.Checked = false;
FLP_Flag1.Visible = true;
return;
}
CHK_Wrapped.Visible = true;
FLP_Flag1.Visible = false;
}
private void ToggleEditorVisibility(ItemKind k)
@@ -283,5 +327,14 @@ private void ChangeItem(ushort item)
pb.BackColor = ItemColor.GetItemColor(item);
pb.BackgroundImage = ItemSprite.GetItemSprite(item);
}
private void CHK_Wrapped_CheckedChanged(object sender, EventArgs e)
{
FLP_Wrapped.Visible = CHK_Wrapped.Checked;
if (CHK_Wrapped.Checked && CB_WrapType.SelectedIndex == 0)
CB_WrapType.SelectedIndex = (int)ItemWrapping.WrappingPaper;
}
private void CB_WrapType_SelectedIndexChanged(object sender, EventArgs e) => CB_WrapColor.Visible = (ItemWrapping)CB_WrapType.SelectedIndex == ItemWrapping.WrappingPaper;
}
}

View File

@@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="CM_Hand.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>