示例#1
0
        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);

            objects.ForEach(x => x.SetParent(group));
            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);
        }
示例#2
0
        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);
        }