- removed some unneeded code

- finished CurveLinedefsMode (except for Anders_A's code)
- added public method to cancel editing modes
This commit is contained in:
codeimp 2008-05-16 10:55:25 +00:00
parent df4ad6d2e0
commit d72ebc4330
7 changed files with 88 additions and 27 deletions

View file

@ -100,7 +100,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Cancel base class // Cancel base class
base.OnCancel(); base.OnCancel();
// Return to vertices mode // Return to base mode
General.Map.ChangeMode(basemode); General.Map.ChangeMode(basemode);
} }
@ -110,10 +110,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
base.OnEngage(); base.OnEngage();
// Show toolbox window // Show toolbox window
BuilderPlug.Me.CurveLinedefsForm.Show(General.Interface); BuilderPlug.Me.CurveLinedefsForm.Show((Form)General.Interface, this);
// Keep focus on main window
General.Interface.Focus();
} }
// Disenagaging // Disenagaging
@ -123,11 +120,47 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Hide toolbox window // Hide toolbox window
BuilderPlug.Me.CurveLinedefsForm.Hide(); BuilderPlug.Me.CurveLinedefsForm.Hide();
// Hide highlight info
General.Interface.HideInfo();
} }
// This applies the curves and returns to the base mode
public void Apply()
{
// Create undo
General.Map.UndoRedo.CreateUndo("Curve linedefs", UndoGroup.None, 0);
// Go for all selected lines
foreach(Linedef ld in selectedlines)
{
// Make curve for line
List<Vector2D> points = GenerateCurve(ld);
if(points.Count > 0)
{
// TODO: We may want some sector create/join code in here
// to allow curves that overlap lines and some geometry merging
// Go for all points to split the line
Linedef splitline = ld;
for(int i = 0; i < points.Count; i++)
{
// Make vertex
Vertex v = General.Map.Map.CreateVertex(points[i]);
// Split the line and move on with this line
splitline = splitline.Split(v);
}
}
}
// Snap to map format accuracy
General.Map.Map.SnapAllToAccuracy();
// Update caches
General.Map.Map.Update();
// Return to base mode
General.Map.ChangeMode(basemode);
}
// This generates the vertices to split the line with, from start to end // This generates the vertices to split the line with, from start to end
private List<Vector2D> GenerateCurve(Linedef line) private List<Vector2D> GenerateCurve(Linedef line)
{ {

View file

@ -330,9 +330,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
General.Map.IsChanged = true; General.Map.IsChanged = true;
} }
// Hide highlight info
General.Interface.HideInfo();
} }
// This checks if the view offset/zoom changed and updates the check // This checks if the view offset/zoom changed and updates the check

View file

@ -521,9 +521,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.IsChanged = true; General.Map.IsChanged = true;
} }
// Hide highlight info
General.Interface.HideInfo();
// Done // Done
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }

View file

@ -151,6 +151,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.cancel.TabIndex = 22; this.cancel.TabIndex = 22;
this.cancel.Text = "Cancel"; this.cancel.Text = "Cancel";
this.cancel.UseVisualStyleBackColor = true; this.cancel.UseVisualStyleBackColor = true;
this.cancel.Click += new System.EventHandler(this.cancel_Click);
// //
// apply // apply
// //
@ -161,6 +162,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.apply.TabIndex = 21; this.apply.TabIndex = 21;
this.apply.Text = "OK"; this.apply.Text = "OK";
this.apply.UseVisualStyleBackColor = true; this.apply.UseVisualStyleBackColor = true;
this.apply.Click += new System.EventHandler(this.apply_Click);
// //
// circular // circular
// //

View file

@ -38,6 +38,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
public partial class CurveLinedefsForm : DelayedForm public partial class CurveLinedefsForm : DelayedForm
{ {
#region ================== Variables
private CurveLinedefsMode mode;
#endregion
#region ================== Properties #region ================== Properties
public int Vertices { get { return verticesbar.Value; } } public int Vertices { get { return verticesbar.Value; } }
@ -67,24 +73,27 @@ namespace CodeImp.DoomBuilder.BuilderModes
// User closing the window? // User closing the window?
if(e.CloseReason == CloseReason.UserClosing) if(e.CloseReason == CloseReason.UserClosing)
{ {
// Just return to linedefs mode // Just cancel
General.Map.ChangeMode(new LinedefsMode()); General.Map.CancelMode();
e.Cancel = true; e.Cancel = true;
} }
} }
// Window is shown // This shows the window
protected override void OnShown(EventArgs e) public void Show(Form owner, CurveLinedefsMode mode)
{ {
// First time showing? // Keep reference to mode
if((this.Location.X == 0) && (this.Location.Y == 0)) this.mode = mode;
{
// Position in left-top of owner
this.Location = new Point(this.Owner.Location.X + 20, this.Owner.Location.Y + 80);
}
// Continue // First time showing?
base.OnShown(e); //if((this.Location.X == 0) && (this.Location.Y == 0))
{
// Position at left-top of owner
this.Location = new Point(owner.Location.X + 20, owner.Location.Y + 90);
}
// Show window
base.Show(owner);
} }
// Vertices bar changed // Vertices bar changed
@ -162,7 +171,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
// Cancel clicked
private void cancel_Click(object sender, EventArgs e)
{
// Cancel now
General.Map.CancelMode();
}
// Apply clicked
private void apply_Click(object sender, EventArgs e)
{
// Apply now
mode.Apply();
}
#endregion #endregion
} }
} }

View file

@ -161,7 +161,6 @@ namespace CodeImp.DoomBuilder.Editing
} }
// This forces the mode to cancel and return to the "parent" mode // This forces the mode to cancel and return to the "parent" mode
[BeginAction("cancelmode", BaseAction = true)]
public virtual void OnCancel() { } public virtual void OnCancel() { }
// Interface events // Interface events

View file

@ -823,6 +823,16 @@ namespace CodeImp.DoomBuilder
#region ================== Editing Modes #region ================== Editing Modes
/// <summary>
/// This cancels the current mode.
/// </summary>
[BeginAction("cancelmode")]
public void CancelMode()
{
// Let the mode know
mode.OnCancel();
}
// //
// This changes the editing mode. // This changes the editing mode.
// Order in which events occur for the old and new modes: // Order in which events occur for the old and new modes: