From 0fb187fcbeac62a1a46de5ae68cfa9d6868e8faf Mon Sep 17 00:00:00 2001
From: biwa <6475593+biwa@users.noreply.github.com>
Date: Tue, 24 Aug 2021 22:21:14 +0200
Subject: [PATCH] Stair Sector Builder Mode: current settings can be now be
 saved as a default prefab that will always be loaded when using the Stair
 Sector Builder Mode

---
 .../StairSectorBuilderForm.cs                 | 45 ++++++++++++++++---
 .../StairSectorBuilderForm.designer.cs        | 35 ++++++++++-----
 2 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.cs b/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.cs
index d42faabb3..f6213fe91 100755
--- a/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.cs
+++ b/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.cs
@@ -278,8 +278,18 @@ namespace CodeImp.DoomBuilder.StairSectorBuilderMode
 				}
 			}
 
-            // Show window
-            base.Show(owner);
+			// Check if there's a "[Default]" prefab and load it if so
+			foreach (BuilderPlug.Prefab p in BuilderPlug.Me.Prefabs)
+			{
+				if(p.name == "[Default]")
+				{
+					LoadPrefab(p);
+					break;
+				}
+			}
+
+			// Show window
+			base.Show(owner);
         }
 
 		private void ComputeHeights()
@@ -318,7 +328,21 @@ namespace CodeImp.DoomBuilder.StairSectorBuilderMode
 
 		private void btnOK_Click(object sender, EventArgs e)
 		{
-			SavePrefab("[Previous]", true, 0);
+			int position = 0;
+
+			// We always want to have the "[Default]" prefab on top, so look for it and add "[Previous]" after that
+			for (int i = 0; i < BuilderPlug.Me.Prefabs.Count; i++)
+			{
+				BuilderPlug.Prefab p = BuilderPlug.Me.Prefabs[i];
+
+				if (p.name == "[Default]")
+				{
+					position = i+1;
+					break;
+				}
+			}
+
+			SavePrefab("[Previous]", true, position);
 
 			General.Editing.AcceptMode();
 		}
@@ -638,10 +662,18 @@ namespace CodeImp.DoomBuilder.StairSectorBuilderMode
 
 			if(name == "[Previous]")
 				MessageBox.Show(Owner, "The prefab name \"[Previous]\" is reserved and can not be overwritten.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+			else if (name == "[Default]")
+				MessageBox.Show(Owner, "The prefab name \"[Default]\" is reserved and can not be overwritten manually.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 			else
 				SavePrefab(prefabname.Text.Trim(), false, -1);
 		}
 
+
+		private void prefabdefault_Click(object sender, EventArgs e)
+		{
+			SavePrefab("[Default]", true, 0);
+		}
+
 		private void SavePrefab(string name, bool forceoverwrite, int position)
 		{
             int overwrite = -1;
@@ -751,9 +783,12 @@ namespace CodeImp.DoomBuilder.StairSectorBuilderMode
 
 		private void LoadPrefab(int position)
 		{
-			loadingprefab = true;
+			LoadPrefab(BuilderPlug.Me.Prefabs[position]);
+		}
 
-			BuilderPlug.Prefab p = BuilderPlug.Me.Prefabs[position];
+		private void LoadPrefab(BuilderPlug.Prefab p)
+		{
+			loadingprefab = true;
 
 			prefabname.Text = p.name;
 
diff --git a/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.designer.cs b/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.designer.cs
index f115ee8b4..9cf60a887 100755
--- a/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.designer.cs
+++ b/Source/Plugins/StairSectorBuilder/StairSectorBuilderForm.designer.cs
@@ -39,6 +39,7 @@
 			this.spacing = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
 			this.label11 = new System.Windows.Forms.Label();
 			this.groupBox3 = new System.Windows.Forms.GroupBox();
+			this.distinctsectors = new System.Windows.Forms.CheckBox();
 			this.singledirection = new System.Windows.Forms.CheckBox();
 			this.singlesteps = new System.Windows.Forms.CheckBox();
 			this.groupBox2 = new System.Windows.Forms.GroupBox();
@@ -107,7 +108,7 @@
 			this.groupBox10 = new System.Windows.Forms.GroupBox();
 			this.middletexturetexture = new CodeImp.DoomBuilder.Controls.TextureSelectorControl();
 			this.middletexture = new System.Windows.Forms.CheckBox();
-			this.distinctsectors = new System.Windows.Forms.CheckBox();
+			this.prefabdefault = new System.Windows.Forms.Button();
 			this.groupBox1.SuspendLayout();
 			this.tabcontrol.SuspendLayout();
 			this.tabPage1.SuspendLayout();
@@ -265,6 +266,18 @@
 			this.groupBox3.TabStop = false;
 			this.groupBox3.Text = "Appearance";
 			// 
+			// distinctsectors
+			// 
+			this.distinctsectors.AutoSize = true;
+			this.distinctsectors.Enabled = false;
+			this.distinctsectors.Location = new System.Drawing.Point(10, 43);
+			this.distinctsectors.Name = "distinctsectors";
+			this.distinctsectors.Size = new System.Drawing.Size(101, 18);
+			this.distinctsectors.TabIndex = 2;
+			this.distinctsectors.Text = "Distinct sectors";
+			this.distinctsectors.UseVisualStyleBackColor = true;
+			this.distinctsectors.CheckedChanged += new System.EventHandler(this.distinctsectors_CheckedChanged);
+			// 
 			// singledirection
 			// 
 			this.singledirection.AutoSize = true;
@@ -975,6 +988,7 @@
 			// 
 			// groupBox11
 			// 
+			this.groupBox11.Controls.Add(this.prefabdefault);
 			this.groupBox11.Controls.Add(this.prefabload);
 			this.groupBox11.Controls.Add(this.prefabdelete);
 			this.groupBox11.Controls.Add(this.prefabsave);
@@ -1081,17 +1095,15 @@
 			this.middletexture.UseVisualStyleBackColor = true;
 			this.middletexture.CheckedChanged += new System.EventHandler(this.middletexture_CheckedChanged);
 			// 
-			// distinctsectors
+			// prefabdefault
 			// 
-			this.distinctsectors.AutoSize = true;
-			this.distinctsectors.Enabled = false;
-			this.distinctsectors.Location = new System.Drawing.Point(10, 43);
-			this.distinctsectors.Name = "distinctsectors";
-			this.distinctsectors.Size = new System.Drawing.Size(101, 18);
-			this.distinctsectors.TabIndex = 2;
-			this.distinctsectors.Text = "Distinct sectors";
-			this.distinctsectors.UseVisualStyleBackColor = true;
-			this.distinctsectors.CheckedChanged += new System.EventHandler(this.distinctsectors_CheckedChanged);
+			this.prefabdefault.Location = new System.Drawing.Point(247, 156);
+			this.prefabdefault.Name = "prefabdefault";
+			this.prefabdefault.Size = new System.Drawing.Size(70, 23);
+			this.prefabdefault.TabIndex = 29;
+			this.prefabdefault.Text = "Set default";
+			this.prefabdefault.UseVisualStyleBackColor = true;
+			this.prefabdefault.Click += new System.EventHandler(this.prefabdefault_Click);
 			// 
 			// StairSectorBuilderForm
 			// 
@@ -1240,5 +1252,6 @@
 		private CodeImp.DoomBuilder.Controls.TextureSelectorControl middletexturetexture;
 		private System.Windows.Forms.CheckBox middletexture;
 		private System.Windows.Forms.CheckBox distinctsectors;
+		private System.Windows.Forms.Button prefabdefault;
 	}
 }
\ No newline at end of file
-- 
GitLab