public void Reverse(Document document) { foreach (var gp in _groupsAndParents) { var group = new Group(gp.Key) {Colour = Colour.GetRandomGroupColour()}; var parent = document.Map.WorldSpawn.FindByID(gp.Value); group.SetParent(parent); } foreach (var cp in _childrenAndParents) { var child = document.Map.WorldSpawn.FindByID(cp.Key); var parent = document.Map.WorldSpawn.FindByID(cp.Value); child.SetParent(parent); child.UpdateBoundingBox(); child.Colour = parent.Colour.Vary(); } foreach (var gp in _groupsAndParents) { var group = document.Map.WorldSpawn.FindByID(gp.Key); if (group.GetChildren().All(x => x.IsSelected)) document.Selection.Select(group); } Mediator.Publish(EditorMediator.SelectionChanged); Mediator.Publish(EditorMediator.DocumentTreeStructureChanged); }
public override void Perform(Documents.Document document) { if (_firstRun) { var origin = GetPasteOrigin(document); var objects = new List<MapObject>(); if (_objectsToPaste.Count() == 1) { // Only one object - no need to group. _grouping = PasteSpecialGrouping.None; } Group allGroup = null; if (_grouping == PasteSpecialGrouping.All) { // Use one group for all copies allGroup = new Group(document.Map.IDGenerator.GetNextObjectID()); // Add the group to the tree objects.Add(allGroup); } // Get a list of all entity names if needed var names = new List<string>(); if (_makeEntitesUnique) { names = document.Map.WorldSpawn.Find(x => x is Entity) .Select(x => x.GetEntityData()) .Where(x => x != null) .Select(x => x.Properties.FirstOrDefault(y => y.Key == "targetname")) .Where(x => x != null) .Select(x => x.Value) .ToList(); } // Start at i = 1 so the original isn't duped with no offets for (var i = 1; i <= _numCopies; i++) { var copyOrigin = origin + (_offset * i); var copyRotation = _rotation * i; var copy = CreateCopy(document.Map.IDGenerator, copyOrigin, copyRotation, names, document.Map.GetTransformFlags()).ToList(); var grouped = GroupCopy(document.Map.IDGenerator, allGroup, copy); objects.AddRange(grouped); } // Mark the objects to be created Create(objects); // We don't need to calculate this again. _firstRun = false; _objectsToPaste = null; } base.Perform(document); }
public void Perform(Document document) { var objects = _groupedObjects .Select(x => document.Map.WorldSpawn.FindByID(x)) .Where(x => x != null && x.Parent != null) .ToList(); _originalChildParents = objects.ToDictionary(x => x.ID, x => x.Parent.ID); _groupId = document.Map.IDGenerator.GetNextObjectID(); var group = new Group(_groupId); objects.ForEach(x => x.SetParent(group)); group.SetParent(document.Map.WorldSpawn); group.UpdateBoundingBox(); Mediator.Publish(EditorMediator.DocumentTreeStructureChanged); }
public void Perform(Document document) { var objects = _groupedObjects .Select(x => document.Map.WorldSpawn.FindByID(x)) .Where(x => x != null && x.Parent != null) .ToList(); _originalChildParents = objects.ToDictionary(x => x.ID, x => x.Parent.ID); if (_groupId == 0) _groupId = document.Map.IDGenerator.GetNextObjectID(); var group = new Group(_groupId) {Colour = Colour.GetRandomGroupColour()}; objects.ForEach(x => x.SetParent(group)); objects.ForEach(x => x.Colour = group.Colour.Vary()); group.SetParent(document.Map.WorldSpawn); group.UpdateBoundingBox(); if (group.GetChildren().All(x => x.IsSelected)) { document.Selection.Select(group); Mediator.Publish(EditorMediator.SelectionChanged); } Mediator.Publish(EditorMediator.DocumentTreeStructureChanged); }
private MapObject GetBrush(Box bounds, IDGenerator idg) { var brush = BrushManager.CurrentBrush; var ti = Document.TextureCollection.SelectedTexture; var texture = ti != null ? ti.GetTexture() : null; var created = brush.Create(idg, bounds, texture, BrushManager.RoundCreatedVertices ? 0 : 2).ToList(); if (created.Count > 1) { var g = new Group(idg.GetNextObjectID()); created.ForEach(x => x.SetParent(g)); g.UpdateBoundingBox(); return g; } return created.FirstOrDefault(); }
public override MapObject Copy(IDGenerator generator) { var group = new Group(generator.GetNextObjectID()); CopyBase(group, generator); return group; }
public override MapObject Clone() { var group = new Group(ID); CopyBase(group, null, true); return group; }
private static void WriteMapGroup(BinaryWriter bw, Group g) { bw.WriteCString("CMapGroup"); WriteMapBase(bw, g); }
private static Group ReadMapGroup(BinaryReader br, List<Visgroup> visgroups, IDGenerator generator) { var grp = new Group(generator.GetNextObjectID()); ReadMapBase(br, grp, visgroups, generator); grp.UpdateBoundingBox(false); return grp; }
private static GenericStructure WriteGroup(Group group) { var ret = new GenericStructure("group"); ret["id"] = group.ID.ToString(CultureInfo.InvariantCulture); var editor = WriteEditor(group); ret.Children.Add(editor); return ret; }
private static Group ReadGroup(GenericStructure group, IDGenerator generator) { var g = new Group(GetObjectID(group, generator)); var editor = group.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor"); g.Colour = editor.PropertyColour("color", Colour.GetRandomBrushColour()); g.Visgroups.AddRange(editor.GetAllPropertyValues("visgroupid").Select(int.Parse)); return g; }
private IEnumerable<MapObject> GroupCopy(IDGenerator gen, MapObject allGroup, List<MapObject> copy) { switch (_grouping) { case PasteSpecialGrouping.None: // No grouping - add directly to tree return copy; case PasteSpecialGrouping.Individual: // Use one group per copy var group = new Group(gen.GetNextObjectID()); copy.ForEach(x => x.SetParent(group)); return new List<MapObject> {group}; case PasteSpecialGrouping.All: // Use one group for all copies copy.ForEach(x => x.SetParent(allGroup)); return new MapObject[0]; default: throw new ArgumentOutOfRangeException(); } }