Things can now be moved, insterted and deleted in Visual modes.

"Place thing at cursor position" Action places Things much more precisely now.
This commit is contained in:
MaxED 2012-07-05 13:48:08 +00:00
parent 24e1fcad6a
commit fcd29375c8
9 changed files with 154 additions and 44 deletions

View file

@ -959,6 +959,40 @@ namespace CodeImp.DoomBuilder.BuilderModes
return new NullVisualEventReceiver();
}
}
//mxd. Copied from BuilderModes.ThingsMode
// This creates a new thing
private Thing InsertThing(Vector2D pos) {
if (pos.x < General.Map.Config.LeftBoundary || pos.x > General.Map.Config.RightBoundary ||
pos.y > General.Map.Config.TopBoundary || pos.y < General.Map.Config.BottomBoundary) {
General.Interface.DisplayStatus(StatusType.Warning, "Failed to insert thing: outside of map boundaries.");
return null;
}
// Create thing
Thing t = General.Map.Map.CreateThing();
if (t != null) {
General.Settings.ApplyDefaultThingSettings(t);
t.Move(pos);
t.UpdateConfiguration();
General.Map.IsChanged = true;
// Update things filter so that it includes this thing
General.Map.ThingsFilter.Update();
// Snap to grid enabled?
if (General.Interface.SnapToGrid) {
// Snap to grid
t.SnapToGrid();
}
else {
// Snap to map format accuracy
t.SnapToAccuracy();
}
}
return t;
}
#endregion
@ -1308,24 +1342,62 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach(IVisualEventReceiver i in objs) i.OnPasteProperties();
PostAction();
}
[BeginAction("insertitem", BaseAction = true)]
public void Insert()
{
PreAction(UndoGroup.None);
List<IVisualEventReceiver> objs = GetSelectedObjects(true, true, true);
foreach(IVisualEventReceiver i in objs) i.OnInsert();
PostAction();
}
[BeginAction("deleteitem", BaseAction = true)]
public void Delete()
{
PreAction(UndoGroup.None);
List<IVisualEventReceiver> objs = GetSelectedObjects(true, true, true);
foreach(IVisualEventReceiver i in objs) i.OnDelete();
PostAction();
}
//mxd. now we can actually insert things in Visual modes
[BeginAction("insertitem", BaseAction = true)]
public void Insert() {
Vector2D hitpos = getHitPosition();
if (!hitpos.IsFinite()) {
General.Interface.DisplayStatus(StatusType.Warning, "Cannot insert item here!");
return;
}
ClearSelection();
PreActionNoChange();
General.Map.UndoRedo.CreateUndo("Insert thing");
Thing t = InsertThing(new Vector2D(hitpos.x, hitpos.y));
if (t == null) {
General.Map.UndoRedo.WithdrawUndo();
return;
}
// Edit the thing?
if (BuilderPlug.Me.EditNewThing)
General.Interface.ShowEditThings(new List<Thing> { t });
//add thing to blockmap
blockmap.AddThing(t);
General.Interface.DisplayStatus(StatusType.Action, "Inserted a new thing.");
General.Map.IsChanged = true;
General.Map.ThingsFilter.Update();
PostAction();
}
[BeginAction("deleteitem", BaseAction = true)] //mxd. now we can actually delete things in Visual modes
public void Delete() {
List<IVisualEventReceiver> objs = GetSelectedObjects(false, false, true);
if (objs.Count == 0) return;
string rest = objs.Count + " thing" + (objs.Count > 1 ? "s." : ".");
//make undo
General.Map.UndoRedo.CreateUndo("Delete " + rest);
General.Interface.DisplayStatus(StatusType.Info, "Deleted " + rest);
PreActionNoChange();
foreach (IVisualEventReceiver i in objs) i.OnDelete(); //are they deleted from BlockMap automatically?..
// Update cache values
General.Map.IsChanged = true;
General.Map.ThingsFilter.Update();
PostAction();
}
#endregion
}