diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 4d98646a..9e29256c 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -682,6 +682,12 @@ ScriptFindReplaceForm.cs + + Form + + + VertexEditForm.cs + @@ -827,6 +833,10 @@ + + Designer + VertexEditForm.cs + "$(SolutionDir)VersionFromSVN.exe" "$(ProjectDir)Properties\AssemblyInfo.cs" -F 0 -M "Debug" "$(ConfigurationName)" diff --git a/Source/BuilderModes/ClassicModes/VerticesMode.cs b/Source/BuilderModes/ClassicModes/VerticesMode.cs index fb51df83..d14a9328 100644 --- a/Source/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/BuilderModes/ClassicModes/VerticesMode.cs @@ -246,6 +246,24 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Edit pressed in this mode editpressed = true; + + // Highlighted item not selected? + if(!highlighted.Selected) + { + // Make this the only selection + General.Map.Map.ClearSelectedVertices(); + highlighted.Selected = true; + General.Interface.RedrawDisplay(); + } + + // Update display + if(renderer.StartPlotter(false)) + { + // Redraw highlight to show selection + renderer.PlotVertex(highlighted, renderer.DetermineVertexColor(highlighted)); + renderer.Finish(); + renderer.Present(); + } } else { @@ -315,6 +333,28 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done editing protected override void OnEditEnd() { + // Edit pressed in this mode? + if(editpressed) + { + // Anything selected? + ICollection selected = General.Map.Map.GetSelectedVertices(true); + if(selected.Count > 0) + { + if(General.Interface.IsActiveWindow) + { + // Show line edit dialog + General.Interface.ShowEditVertices(selected); + General.Map.Map.Update(); + + // When a single vertex was selected, deselect it now + if(selected.Count == 1) General.Map.Map.ClearSelectedVertices(); + + // Update entire display + General.Interface.RedrawDisplay(); + } + } + } + editpressed = false; base.OnEditEnd(); } diff --git a/Source/BuilderModes/FindReplace/FindVertexNumber.cs b/Source/BuilderModes/FindReplace/FindVertexNumber.cs index adee8290..123f2d71 100644 --- a/Source/BuilderModes/FindReplace/FindVertexNumber.cs +++ b/Source/BuilderModes/FindReplace/FindVertexNumber.cs @@ -123,7 +123,8 @@ namespace CodeImp.DoomBuilder.BuilderModes { List vertices = new List(selection.Length); foreach(FindReplaceObject o in selection) vertices.Add(o.Vertex); - // TODO: General.Interface.ShowEditVertices(vertices); + General.Interface.ShowEditVertices(vertices); + General.Map.Map.Update(); } #endregion diff --git a/Source/Controls/FieldsEditorControl.cs b/Source/Controls/FieldsEditorControl.cs index a3501f4b..a85ee327 100644 --- a/Source/Controls/FieldsEditorControl.cs +++ b/Source/Controls/FieldsEditorControl.cs @@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Controls public FieldsEditorControl() { InitializeComponent(); + enumscombo.Visible = false; } #endregion diff --git a/Source/Controls/NumericTextbox.cs b/Source/Controls/NumericTextbox.cs index 32740335..85992edc 100644 --- a/Source/Controls/NumericTextbox.cs +++ b/Source/Controls/NumericTextbox.cs @@ -42,6 +42,7 @@ namespace CodeImp.DoomBuilder.Controls private bool allownegative = false; // Allow negative numbers private bool allowrelative = false; // Allow ++ and -- prefix for relative changes + private bool allowdecimal = false; // Allow decimal (float) numbers private bool controlpressed = false; #endregion @@ -50,6 +51,7 @@ namespace CodeImp.DoomBuilder.Controls public bool AllowNegative { get { return allownegative; } set { allownegative = value; } } public bool AllowRelative { get { return allowrelative; } set { allowrelative = value; } } + public bool AllowDecimal { get { return allowdecimal; } set { allowdecimal = value; } } #endregion @@ -90,9 +92,10 @@ namespace CodeImp.DoomBuilder.Controls char otherprefix; // Determine allowed chars - if(allownegative) allowedchars += "-"; + if(allownegative) allowedchars += CultureInfo.CurrentUICulture.NumberFormat.NegativeSign; if(allowrelative) allowedchars += "+-"; if(controlpressed) allowedchars += "\u0018\u0003\u0016"; + if(allowdecimal) allowedchars += CultureInfo.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator; // Check if key is not allowed if(allowedchars.IndexOf(e.KeyChar) == -1) @@ -169,7 +172,7 @@ namespace CodeImp.DoomBuilder.Controls // Strip prefixes textpart = textpart.Replace("+", ""); - textpart = textpart.Replace("-", ""); + if(!allownegative) textpart = textpart.Replace("-", ""); // No numbers left? if(textpart.Length == 0) @@ -186,11 +189,11 @@ namespace CodeImp.DoomBuilder.Controls public int GetResult(int original) { string textpart = this.Text; - int result = 0; + int result; // Strip prefixes textpart = textpart.Replace("+", ""); - textpart = textpart.Replace("-", ""); + if(!allownegative) textpart = textpart.Replace("-", ""); // Any numbers left? if(textpart.Length > 0) @@ -212,7 +215,47 @@ namespace CodeImp.DoomBuilder.Controls else { // Return the new value - if(int.TryParse(this.Text, out result)) return result; else return 0; + return int.TryParse(this.Text, out result) ? result : 0; + } + } + else + { + // Nothing given, keep original value + return original; + } + } + + // This determines the result value + public float GetResultFloat(float original) + { + string textpart = this.Text; + float result; + + // Strip prefixes + textpart = textpart.Replace("+", ""); + if(!allownegative) textpart = textpart.Replace("-", ""); + + // Any numbers left? + if(textpart.Length > 0) + { + // Prefixed with ++? + if(this.Text.StartsWith("++")) + { + // Add number to original + if(!float.TryParse(textpart, out result)) result = 0; + return original + result; + } + // Prefixed with --? + else if(this.Text.StartsWith("--")) + { + // Subtract number from original + if(!float.TryParse(textpart, out result)) result = 0; + return original - result; + } + else + { + // Return the new value + return float.TryParse(this.Text, out result) ? result : 0; } } else diff --git a/Source/Windows/IMainForm.cs b/Source/Windows/IMainForm.cs index 2a5d1479..d7e22f8d 100644 --- a/Source/Windows/IMainForm.cs +++ b/Source/Windows/IMainForm.cs @@ -57,6 +57,7 @@ namespace CodeImp.DoomBuilder.Windows void DisplayStatus(StatusType type, string message); void DisplayStatus(StatusInfo newstatus); void RedrawDisplay(); + DialogResult ShowEditVertices(ICollection vertices); DialogResult ShowEditLinedefs(ICollection lines); DialogResult ShowEditSectors(ICollection sectors); DialogResult ShowEditThings(ICollection things); diff --git a/Source/Windows/MainForm.cs b/Source/Windows/MainForm.cs index 61b4b2af..cfeb67b1 100644 --- a/Source/Windows/MainForm.cs +++ b/Source/Windows/MainForm.cs @@ -2139,6 +2139,20 @@ namespace CodeImp.DoomBuilder.Windows { return EffectBrowserForm.BrowseEffect(owner, initialvalue); } + + // This shows the dialog to edit vertices + public DialogResult ShowEditVertices(ICollection vertices) + { + DialogResult result; + + // Show sector edit dialog + VertexEditForm f = new VertexEditForm(); + f.Setup(vertices); + result = f.ShowDialog(this); + f.Dispose(); + + return result; + } // This shows the dialog to edit lines public DialogResult ShowEditLinedefs(ICollection lines) diff --git a/Source/Windows/SectorEditForm.resx b/Source/Windows/SectorEditForm.resx index 62ad1db5..eed4e6d9 100644 --- a/Source/Windows/SectorEditForm.resx +++ b/Source/Windows/SectorEditForm.resx @@ -129,6 +129,9 @@ False + + False + False @@ -138,6 +141,12 @@ False + + False + + + False + False @@ -153,4 +162,16 @@ False + + False + + + False + + + False + + + False + \ No newline at end of file diff --git a/Source/Windows/VertexEditForm.Designer.cs b/Source/Windows/VertexEditForm.Designer.cs new file mode 100644 index 00000000..bb1aca58 --- /dev/null +++ b/Source/Windows/VertexEditForm.Designer.cs @@ -0,0 +1,221 @@ +namespace CodeImp.DoomBuilder.Windows +{ + partial class VertexEditForm + { + /// + /// 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 Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.TabPage tabproperties; + System.Windows.Forms.Label label1; + System.Windows.Forms.Label label6; + this.groupposition = new System.Windows.Forms.GroupBox(); + this.positiony = new CodeImp.DoomBuilder.Controls.NumericTextbox(); + this.positionx = new CodeImp.DoomBuilder.Controls.NumericTextbox(); + this.tabs = new System.Windows.Forms.TabControl(); + this.tabcustom = new System.Windows.Forms.TabPage(); + this.fieldslist = new CodeImp.DoomBuilder.Controls.FieldsEditorControl(); + this.cancel = new System.Windows.Forms.Button(); + this.apply = new System.Windows.Forms.Button(); + tabproperties = new System.Windows.Forms.TabPage(); + label1 = new System.Windows.Forms.Label(); + label6 = new System.Windows.Forms.Label(); + tabproperties.SuspendLayout(); + this.groupposition.SuspendLayout(); + this.tabs.SuspendLayout(); + this.tabcustom.SuspendLayout(); + this.SuspendLayout(); + // + // tabproperties + // + tabproperties.Controls.Add(this.groupposition); + tabproperties.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + tabproperties.Location = new System.Drawing.Point(4, 23); + tabproperties.Name = "tabproperties"; + tabproperties.Padding = new System.Windows.Forms.Padding(3); + tabproperties.Size = new System.Drawing.Size(428, 206); + tabproperties.TabIndex = 0; + tabproperties.Text = "Properties"; + tabproperties.UseVisualStyleBackColor = true; + // + // groupposition + // + this.groupposition.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupposition.Controls.Add(label1); + this.groupposition.Controls.Add(this.positiony); + this.groupposition.Controls.Add(label6); + this.groupposition.Controls.Add(this.positionx); + this.groupposition.Location = new System.Drawing.Point(7, 6); + this.groupposition.Name = "groupposition"; + this.groupposition.Size = new System.Drawing.Size(415, 194); + this.groupposition.TabIndex = 24; + this.groupposition.TabStop = false; + this.groupposition.Text = " Position "; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new System.Drawing.Point(188, 39); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(18, 14); + label1.TabIndex = 23; + label1.Text = "Y:"; + // + // positiony + // + this.positiony.AllowDecimal = false; + this.positiony.AllowNegative = true; + this.positiony.AllowRelative = true; + this.positiony.ImeMode = System.Windows.Forms.ImeMode.Off; + this.positiony.Location = new System.Drawing.Point(211, 36); + this.positiony.Name = "positiony"; + this.positiony.Size = new System.Drawing.Size(95, 20); + this.positiony.TabIndex = 22; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new System.Drawing.Point(45, 39); + label6.Name = "label6"; + label6.Size = new System.Drawing.Size(17, 14); + label6.TabIndex = 21; + label6.Text = "X:"; + // + // positionx + // + this.positionx.AllowDecimal = false; + this.positionx.AllowNegative = true; + this.positionx.AllowRelative = true; + this.positionx.ImeMode = System.Windows.Forms.ImeMode.Off; + this.positionx.Location = new System.Drawing.Point(68, 36); + this.positionx.Name = "positionx"; + this.positionx.Size = new System.Drawing.Size(95, 20); + this.positionx.TabIndex = 20; + // + // tabs + // + this.tabs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabs.Controls.Add(tabproperties); + this.tabs.Controls.Add(this.tabcustom); + this.tabs.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tabs.Location = new System.Drawing.Point(10, 10); + this.tabs.Margin = new System.Windows.Forms.Padding(1); + this.tabs.Name = "tabs"; + this.tabs.SelectedIndex = 0; + this.tabs.Size = new System.Drawing.Size(436, 233); + this.tabs.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; + this.tabs.TabIndex = 0; + // + // tabcustom + // + this.tabcustom.Controls.Add(this.fieldslist); + this.tabcustom.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tabcustom.Location = new System.Drawing.Point(4, 23); + this.tabcustom.Name = "tabcustom"; + this.tabcustom.Padding = new System.Windows.Forms.Padding(3); + this.tabcustom.Size = new System.Drawing.Size(428, 206); + this.tabcustom.TabIndex = 1; + this.tabcustom.Text = "Custom"; + this.tabcustom.UseVisualStyleBackColor = true; + // + // fieldslist + // + this.fieldslist.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.fieldslist.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.fieldslist.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.fieldslist.Location = new System.Drawing.Point(11, 11); + this.fieldslist.Margin = new System.Windows.Forms.Padding(8); + this.fieldslist.Name = "fieldslist"; + this.fieldslist.Size = new System.Drawing.Size(406, 187); + this.fieldslist.TabIndex = 2; + // + // cancel + // + this.cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancel.Location = new System.Drawing.Point(334, 259); + this.cancel.Name = "cancel"; + this.cancel.Size = new System.Drawing.Size(112, 25); + this.cancel.TabIndex = 21; + this.cancel.Text = "Cancel"; + this.cancel.UseVisualStyleBackColor = true; + this.cancel.Click += new System.EventHandler(this.cancel_Click); + // + // apply + // + this.apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.apply.Location = new System.Drawing.Point(215, 259); + this.apply.Name = "apply"; + this.apply.Size = new System.Drawing.Size(112, 25); + this.apply.TabIndex = 20; + this.apply.Text = "OK"; + this.apply.UseVisualStyleBackColor = true; + this.apply.Click += new System.EventHandler(this.apply_Click); + // + // VertexEditForm + // + this.AcceptButton = this.apply; + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.CancelButton = this.cancel; + this.ClientSize = new System.Drawing.Size(456, 294); + this.Controls.Add(this.cancel); + this.Controls.Add(this.apply); + this.Controls.Add(this.tabs); + this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "VertexEditForm"; + this.Opacity = 0; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Edit Vertex"; + tabproperties.ResumeLayout(false); + this.groupposition.ResumeLayout(false); + this.groupposition.PerformLayout(); + this.tabs.ResumeLayout(false); + this.tabcustom.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabs; + private System.Windows.Forms.TabPage tabcustom; + private System.Windows.Forms.Button cancel; + private System.Windows.Forms.Button apply; + private CodeImp.DoomBuilder.Controls.FieldsEditorControl fieldslist; + private CodeImp.DoomBuilder.Controls.NumericTextbox positiony; + private System.Windows.Forms.GroupBox groupposition; + private CodeImp.DoomBuilder.Controls.NumericTextbox positionx; + } +} \ No newline at end of file diff --git a/Source/Windows/VertexEditForm.cs b/Source/Windows/VertexEditForm.cs new file mode 100644 index 00000000..6a71e546 --- /dev/null +++ b/Source/Windows/VertexEditForm.cs @@ -0,0 +1,164 @@ + +#region ================== Copyright (c) 2007 Pascal vd Heiden + +/* + * Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com + * This program is released under GNU General Public License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#endregion + +#region ================== Namespaces + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.IO; +using System.IO; +using CodeImp.DoomBuilder.Config; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.Controls; + +#endregion + +namespace CodeImp.DoomBuilder.Windows +{ + public partial class VertexEditForm : DelayedForm + { + #region ================== Constants + + #endregion + + #region ================== Variables + + private ICollection vertices; + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor + + // Constructor + public VertexEditForm() + { + InitializeComponent(); + + // Fill universal fields list + fieldslist.ListFixedFields(General.Map.Config.VertexFields); + + // Not a UDMF map? + if(!General.Map.IsType(typeof(UniversalMapSetIO))) + { + tabs.TabPages.Remove(tabcustom); + } + + // Decimals allowed? + if(General.Map.FormatInterface.VertexDecimals > 0) + { + positionx.AllowDecimal = true; + positiony.AllowDecimal = true; + } + + // Initialize custom fields editor + fieldslist.Setup("vertex"); + } + + #endregion + + #region ================== Methods + + // This sets up the form to edit the given vertices + public void Setup(ICollection vertices) + { + // Keep this list + this.vertices = vertices; + if(vertices.Count > 1) this.Text = "Edit Vertices (" + vertices.Count + ")"; + + //////////////////////////////////////////////////////////////////////// + // Set all options to the first vertex properties + //////////////////////////////////////////////////////////////////////// + + // Get first vertex + Vertex vc = General.GetByIndex(vertices, 0); + + // Position + positionx.Text = vc.Position.x.ToString(); + positiony.Text = vc.Position.y.ToString(); + + // Custom fields + fieldslist.SetValues(vc.Fields, true); + + //////////////////////////////////////////////////////////////////////// + // Now go for all sectors and change the options when a setting is different + //////////////////////////////////////////////////////////////////////// + + // Go for all vertices + foreach(Vertex v in vertices) + { + // Position + if(positionx.Text != v.Position.x.ToString()) positionx.Text = ""; + if(positiony.Text != v.Position.y.ToString()) positiony.Text = ""; + + // Custom fields + fieldslist.SetValues(v.Fields, false); + } + } + + #endregion + + #region ================== Events + + // OK clicked + private void apply_Click(object sender, EventArgs e) + { + string undodesc = "vertex"; + + // Make undo + if(vertices.Count > 1) undodesc = vertices.Count + " vertices"; + General.Map.UndoRedo.CreateUndo("Edit " + undodesc); + + // Go for all vertices + foreach(Vertex v in vertices) + { + // Apply position + Vector2D p = new Vector2D(); + p.x = positionx.GetResultFloat(v.Position.x); + p.y = positiony.GetResultFloat(v.Position.y); + v.Move(p); + + // Custom fields + fieldslist.Apply(v.Fields); + } + + // Done + General.Map.IsChanged = true; + this.DialogResult = DialogResult.OK; + this.Close(); + } + + // Cancel clicked + private void cancel_Click(object sender, EventArgs e) + { + // Just close + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + #endregion + } +} \ No newline at end of file diff --git a/Source/Windows/VertexEditForm.resx b/Source/Windows/VertexEditForm.resx new file mode 100644 index 00000000..62f3e6c6 --- /dev/null +++ b/Source/Windows/VertexEditForm.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + False + + + False + + + False + + + False + + \ No newline at end of file