From f7a1a64db0be3099cf0b5ca7d1ed682541257ed8 Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Thu, 16 Jun 2016 22:57:20 +0000
Subject: [PATCH] Added, UDMF: Lock number is now displayed in Linedef info
 panel. Fixed, Edit Linedefs / Edit Things windows: ACS script number/name was
 applied only when the form was accepted while displaying a tab with Action
 controls.

---
 Source/Core/Controls/ArgumentsControl.cs | 110 ++++++++++++++---------
 Source/Core/Controls/LinedefInfoPanel.cs |  46 +++++++++-
 2 files changed, 114 insertions(+), 42 deletions(-)

diff --git a/Source/Core/Controls/ArgumentsControl.cs b/Source/Core/Controls/ArgumentsControl.cs
index 518214d0e..a6784b98e 100644
--- a/Source/Core/Controls/ArgumentsControl.cs
+++ b/Source/Core/Controls/ArgumentsControl.cs
@@ -26,12 +26,24 @@ namespace CodeImp.DoomBuilder.Controls
 
 		#endregion
 
+		#region ================== Enums
+
+		private enum ArgZeroMode
+		{
+			DEFAULT,
+			SCRIPT_NUMBER,
+			SCRIPT_NAME,
+		}
+
+		#endregion
+
 		#region ================== Variables
 
 		private string arg0str;
 		private bool havearg0str;
 		private int action;
 		private ArgumentInfo[] arginfo;
+		private ArgZeroMode argzeromode;
 
 		#endregion
 
@@ -124,29 +136,36 @@ namespace CodeImp.DoomBuilder.Controls
 		public void Apply(Linedef l)
 		{
 			//mxd. Script name/number handling
-			if(scriptnumbers.Visible)
+			// We can't rely on control visibility here, because all controlls will be invisible if ArgumentsControl is invisible
+			// (for example, when a different tab is selected)
+			switch(argzeromode)
 			{
-				//apply script number
-				if(!string.IsNullOrEmpty(scriptnumbers.Text))
-				{
-					if(scriptnumbers.SelectedItem != null)
-						l.Args[0] = ((ScriptItem)((ColoredComboBoxItem)scriptnumbers.SelectedItem).Value).Index;
-					else if(!int.TryParse(scriptnumbers.Text.Trim(), out l.Args[0]))
-						l.Args[0] = 0;
+				// Apply arg0str
+				case ArgZeroMode.SCRIPT_NAME:
+					if(!string.IsNullOrEmpty(scriptnames.Text))
+						l.Fields["arg0str"] = new UniValue(UniversalType.String, scriptnames.Text);
+					break;
+
+				// Apply script number
+				case ArgZeroMode.SCRIPT_NUMBER:
+					if(!string.IsNullOrEmpty(scriptnumbers.Text))
+					{
+						if(scriptnumbers.SelectedItem != null)
+							l.Args[0] = ((ScriptItem)((ColoredComboBoxItem)scriptnumbers.SelectedItem).Value).Index;
+						else if(!int.TryParse(scriptnumbers.Text.Trim(), out l.Args[0]))
+							l.Args[0] = 0;
+
+						if(l.Fields.ContainsKey("arg0str")) l.Fields.Remove("arg0str");
+					}
+					break;
 
+				// Apply classic arg
+				case ArgZeroMode.DEFAULT:
+					l.Args[0] = arg0.GetResult(l.Args[0]);
 					if(l.Fields.ContainsKey("arg0str")) l.Fields.Remove("arg0str");
-				}
-			}
-			else if(scriptnames.Visible)
-			{
-				// Apply arg0str
-				if(!string.IsNullOrEmpty(scriptnames.Text))
-					l.Fields["arg0str"] = new UniValue(UniversalType.String, scriptnames.Text);
-			}
-			else
-			{
-				l.Args[0] = arg0.GetResult(l.Args[0]);
-				if(l.Fields.ContainsKey("arg0str")) l.Fields.Remove("arg0str");
+					break;
+
+				default: throw new NotImplementedException("Unknown ArgZeroMode");
 			}
 
 			// Apply the rest of args
@@ -159,29 +178,36 @@ namespace CodeImp.DoomBuilder.Controls
 		public void Apply(Thing t)
 		{
 			//mxd. Script name/number handling
-			if(scriptnumbers.Visible)
+			// We can't rely on control visibility here, because all controlls will be invisible if ArgumentsControl is invisible
+			// (for example, when a different tab is selected)
+			switch(argzeromode)
 			{
-				//apply script number
-				if(!string.IsNullOrEmpty(scriptnumbers.Text))
-				{
-					if(scriptnumbers.SelectedItem != null)
-						t.Args[0] = ((ScriptItem)((ColoredComboBoxItem)scriptnumbers.SelectedItem).Value).Index;
-					else if(!int.TryParse(scriptnumbers.Text.Trim(), out t.Args[0]))
-						t.Args[0] = 0;
+				// Apply arg0str
+				case ArgZeroMode.SCRIPT_NAME:
+					if(!string.IsNullOrEmpty(scriptnames.Text))
+						t.Fields["arg0str"] = new UniValue(UniversalType.String, scriptnames.Text);
+					break;
+
+				// Apply script number
+				case ArgZeroMode.SCRIPT_NUMBER:
+					if(!string.IsNullOrEmpty(scriptnumbers.Text))
+					{
+						if(scriptnumbers.SelectedItem != null)
+							t.Args[0] = ((ScriptItem)((ColoredComboBoxItem)scriptnumbers.SelectedItem).Value).Index;
+						else if(!int.TryParse(scriptnumbers.Text.Trim(), out t.Args[0]))
+							t.Args[0] = 0;
+
+						if(t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
+					}
+					break;
 
+				// Apply classic arg
+				case ArgZeroMode.DEFAULT:
+					t.Args[0] = arg0.GetResult(t.Args[0]);
 					if(t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
-				}
-			}
-			else if(scriptnames.Visible)
-			{
-				// Apply arg0str
-				if(!string.IsNullOrEmpty(scriptnames.Text))
-					t.Fields["arg0str"] = new UniValue(UniversalType.String, scriptnames.Text);
-			}
-			else
-			{
-				t.Args[0] = arg0.GetResult(t.Args[0]);
-				if(t.Fields.ContainsKey("arg0str")) t.Fields.Remove("arg0str");
+					break;
+
+				default: throw new NotImplementedException("Unknown ArgZeroMode");
 			}
 
 			// Apply the rest of args
@@ -270,6 +296,7 @@ namespace CodeImp.DoomBuilder.Controls
 				// Update named script name
 				if(shownamedscripts)
 				{
+					argzeromode = ArgZeroMode.SCRIPT_NAME;
 					if(General.Map.NamedScripts.ContainsKey(arg0str))
 					{
 						int i = 0;
@@ -293,6 +320,7 @@ namespace CodeImp.DoomBuilder.Controls
 				else
 				{
 					// Update numbered script name
+					argzeromode = ArgZeroMode.SCRIPT_NUMBER;
 					int a0 = arg0.GetResult(0);
 					if(General.Map.NumberedScripts.ContainsKey(a0))
 					{
@@ -322,6 +350,7 @@ namespace CodeImp.DoomBuilder.Controls
 				scriptnames.Visible = false;
 				scriptnumbers.Visible = false;
 				cbuseargstr.Checked = false;
+				argzeromode = ArgZeroMode.DEFAULT;
 			}
 
 			arg0.Visible = (!scriptnames.Visible && !scriptnumbers.Visible);
@@ -436,6 +465,7 @@ namespace CodeImp.DoomBuilder.Controls
 			scriptnames.Visible = cbuseargstr.Checked;
 			scriptnumbers.Visible = !cbuseargstr.Checked;
 			arg0label.Text = (cbuseargstr.Checked ? "Script Name:" : "Script Number:");
+			argzeromode = (cbuseargstr.Checked ? ArgZeroMode.SCRIPT_NAME : ArgZeroMode.SCRIPT_NUMBER);
 		}
 
 		private void scriptnumbers_TextChanged(object sender, EventArgs e)
diff --git a/Source/Core/Controls/LinedefInfoPanel.cs b/Source/Core/Controls/LinedefInfoPanel.cs
index 4155cfbc3..bd717cf39 100644
--- a/Source/Core/Controls/LinedefInfoPanel.cs
+++ b/Source/Core/Controls/LinedefInfoPanel.cs
@@ -96,6 +96,7 @@ namespace CodeImp.DoomBuilder.Controls
 			if(!General.Map.FormatInterface.HasBuiltInActivations && General.Map.FormatInterface.HasNumericLinedefActivations) //Hexen map format?
 			{ 
 				activation.Visible = true;
+				activationlabel.Text = "Activation:";
 				activationlabel.Visible = true;
 				taglabel.Visible = false;
 				tag.Visible = false;
@@ -115,8 +116,49 @@ namespace CodeImp.DoomBuilder.Controls
 			} 
 			else 
 			{
-				activation.Visible = false;
-				activationlabel.Visible = false;
+				if(General.Map.UDMF)
+				{
+					// Hijack activation labels to show lock numer...
+					activationlabel.Text = "Lock:";
+					activationlabel.Visible = true;
+					activation.Visible = true;
+
+					int locknum = l.Fields.GetValue("locknumber", 0);
+					if(locknum != 0)
+					{
+						activationlabel.Enabled = true;
+						activation.Enabled = true;
+
+						if(General.Map.Config.Enums.ContainsKey("keys"))
+						{
+							foreach(EnumItem item in General.Map.Config.Enums["keys"])
+							{
+								if(item.GetIntValue() == locknum)
+								{
+									activation.Text = locknum + " - " + item.Title;
+									break;
+								}
+							}
+						}
+						else
+						{
+							activation.Text = locknum.ToString();
+						}
+					}
+					else
+					{
+						activationlabel.Enabled = false;
+						activation.Enabled = false;
+						activation.Text = "None";
+					}
+				}
+				else
+				{
+					// Should be Doom map format 
+					activationlabel.Visible = false;
+					activation.Visible = false;
+				}
+				
 				taglabel.Visible = true;
 				tag.Visible = true;
 
-- 
GitLab