Exemplo n.º 1
0
 public async Task Invoke(IContext context, CommandParameters parameters)
 {
     if (context.TryGet("ActiveDocument", out MapDocument doc))
     {
         var gd   = doc.Map.Data.Get <GridData>().FirstOrDefault();
         var grid = gd?.Grid;
         if (grid != null)
         {
             var operation = new TrivialOperation(x => grid.Spacing++, x => x.Update(gd));
             await MapDocumentOperation.Perform(doc, operation);
         }
     }
 }
Exemplo n.º 2
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var stack = document.Map.Data.GetOne <HistoryStack>();

            if (stack == null)
            {
                return;
            }
            if (stack.CanRedo())
            {
                await MapDocumentOperation.Perform(document, stack.RedoOperation());
            }
        }
Exemplo n.º 3
0
        private void SetActiveTexture(MapDocument document, ITextured tex)
        {
            if (tex == null)
            {
                return;
            }

            var at = new ActiveTexture {
                Name = tex.Texture.Name
            };

            MapDocumentOperation.Perform(document, new TrivialOperation(x => x.Map.Data.Replace(at), x => x.Update(at)));
        }
Exemplo n.º 4
0
        private async Task CreateDecal(Vector3 origin)
        {
            var gameData = await Document.Environment.GetGameData();

            if (gameData == null)
            {
                return;
            }

            var gd = gameData.Classes.FirstOrDefault(x => x.Name == "infodecal");

            if (gd == null)
            {
                return;
            }

            var texture = Document.Map.Data.GetOne <ActiveTexture>()?.Name;

            if (String.IsNullOrWhiteSpace(texture))
            {
                return;
            }

            var tc = await Document.Environment.GetTextureCollection();

            if (tc == null)
            {
                return;
            }

            if (!tc.HasTexture(texture))
            {
                return;
            }

            var decal = new Primitives.MapObjects.Entity(Document.Map.NumberGenerator.Next("MapObject"))
            {
                Data =
                {
                    new EntityData
                    {
                        Name       = gd.Name,
                        Properties ={                  { "texture", texture } }
                    },
                    new ObjectColor(Colour.GetRandomBrushColour()),
                    new Origin(origin)
                }
            };

            await MapDocumentOperation.Perform(Document, new Attach(Document.Map.Root.ID, decal));
        }
Exemplo n.º 5
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var pf = document.Map.Data.GetOne <Pointfile>();

            if (pf == null)
            {
                return;
            }

            await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                   d => d.Map.Data.Remove(pf),
                                                   c => c.Add(c.Document.Map.Root)
                                                   ));
        }
Exemplo n.º 6
0
 private void ShowAllButtonClicked(object sender, EventArgs e)
 {
     if (_activeDocument.TryGetTarget(out MapDocument md))
     {
         var objects = md.Map.Root.Find(x => x.Data.GetOne <VisgroupHidden>()?.IsHidden == true, true).ToList();
         if (objects.Any())
         {
             MapDocumentOperation.Perform(md, new TrivialOperation(
                                              d => objects.ToList().ForEach(x => x.Data.Replace(new VisgroupHidden(false))),
                                              c => c.AddRange(objects)
                                              ));
         }
     }
 }
        public Task Fix(MapDocument document, Problem problem)
        {
            var edit = new Transaction();

            foreach (var obj in problem.Objects)
            {
                var copy = (IMapObject)obj.Copy(document.Map.NumberGenerator);

                edit.Add(new Detatch(obj.Hierarchy.Parent.ID, obj));
                edit.Add(new Attach(obj.Hierarchy.Parent.ID, copy));
            }

            return(MapDocumentOperation.Perform(document, edit));
        }
Exemplo n.º 8
0
        private async Task SelectEntity(Entity sel)
        {
            var doc = _context.Get <MapDocument>("ActiveDocument");

            if (doc == null)
            {
                return;
            }

            var currentSelection = doc.Selection.Except(sel.FindAll()).ToList();
            var tran             = new Transaction(
                new Deselect(currentSelection),
                new Select(sel.FindAll())
                );
            await MapDocumentOperation.Perform(doc, tran);
        }
Exemplo n.º 9
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var transaction = new Transaction();

            foreach (var mo in document.Map.Root.FindAll().Except(document.Selection).Where(x => !(x is Root)).ToList())
            {
                var ex = mo.Data.GetOne <QuickHidden>();
                if (ex != null)
                {
                    transaction.Add(new RemoveMapObjectData(mo.ID, ex));
                }
                transaction.Add(new AddMapObjectData(mo.ID, new QuickHidden()));
            }

            await MapDocumentOperation.Perform(document, transaction);
        }
Exemplo n.º 10
0
        private void DeleteSelectedEntity(object sender, EventArgs e)
        {
            var doc = _context.Get <MapDocument>("ActiveDocument");

            if (doc == null)
            {
                return;
            }

            var selected = GetSelected();

            if (selected == null)
            {
                return;
            }
            MapDocumentOperation.Perform(doc, new Detatch(selected.Hierarchy.Parent.ID, selected));
        }
        public Task Fix(MapDocument document, Problem problem)
        {
            var edit = new Transaction();

            var obj = problem.Objects[0];

            foreach (var face in problem.ObjectData.OfType <Face>())
            {
                var clone = (Face)face.Clone();
                clone.Texture.AlignToNormal(face.Plane.Normal);

                edit.Add(new RemoveMapObjectData(obj.ID, face));
                edit.Add(new AddMapObjectData(obj.ID, clone));
            }

            return(MapDocumentOperation.Perform(document, edit));
        }
Exemplo n.º 12
0
        public Task Fix(MapDocument document, Problem problem)
        {
            var edit = new Transaction();

            foreach (var obj in problem.Objects)
            {
                foreach (var face in obj.Data.Intersect(problem.ObjectData).OfType <Face>())
                {
                    var copy = (Face)face.Copy(document.Map.NumberGenerator);

                    edit.Add(new RemoveMapObjectData(obj.ID, face));
                    edit.Add(new AddMapObjectData(obj.ID, copy));
                }
            }

            return(MapDocumentOperation.Perform(document, edit));
        }
Exemplo n.º 13
0
        private void CordonBoxChanged(object sender, EventArgs e)
        {
            // Only commit changes after the resize has finished
            if (_cordonBox.State.Action != BoxAction.Drawn)
            {
                return;
            }

            var bounds = new Box(_cordonBox.State.Start, _cordonBox.State.End);
            var cb     = new CordonBounds
            {
                Box     = bounds,
                Enabled = Document.Map.Data.GetOne <CordonBounds>()?.Enabled == true
            };

            MapDocumentOperation.Perform(Document, new TrivialOperation(x => x.Map.Data.Replace(cb), x => x.Update(cb)));
        }
Exemplo n.º 14
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var sel = document.Selection.GetSelectedParents().OfType <Primitives.MapObjects.Group>().ToList();

            if (sel.Count > 0)
            {
                var tns = new Transaction();
                foreach (var grp in sel)
                {
                    var list = grp.Hierarchy.ToList();
                    tns.Add(new Detatch(grp.ID, list));
                    tns.Add(new Attach(document.Map.Root.ID, list));
                    tns.Add(new Detatch(grp.Hierarchy.Parent.ID, grp));
                }
                await MapDocumentOperation.Perform(document, tns);
            }
        }
Exemplo n.º 15
0
        private void VisgroupToggled(object sender, VisgroupItem visgroup, CheckState state)
        {
            if (state == CheckState.Indeterminate)
            {
                return;
            }
            var visible = state == CheckState.Checked;
            var objects = GetVisgroupObjects(visgroup).SelectMany(x => x.FindAll()).ToList();

            if (objects.Any() && _activeDocument.TryGetTarget(out MapDocument md))
            {
                MapDocumentOperation.Perform(md, new TrivialOperation(
                                                 d => objects.ForEach(x => x.Data.Replace(new VisgroupHidden(!visible))),
                                                 c => c.AddRange(objects)
                                                 ));
            }
        }
Exemplo n.º 16
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var entities = document.Selection.OfType <Entity>().ToList();

            if (!entities.Any())
            {
                return;
            }

            // Deselect the entities we're about to delete
            var ops = new List <IOperation>
            {
                new Deselect(entities)
            };

            // Remove the children
            foreach (var entity in entities)
            {
                var children = entity.Hierarchy.Where(x => !(x is Entity)).ToList();

                if (children.Any())
                {
                    // Make sure we don't try and attach the solids back to an entity
                    var newParentId = entities.Contains(entity.Hierarchy.Parent)
                        ? document.Map.Root.ID
                        : entity.Hierarchy.Parent.ID;

                    // Move the entity's children to the new parent before removing the entity
                    ops.Add(new Detatch(entity.ID, children));
                    ops.Add(new Attach(newParentId, children));
                }
            }

            // Remove the parents
            foreach (var entity in entities)
            {
                // If the parent is a selected entity then we don't need to detach this one as the parent will be detatched
                if (!entities.Contains(entity.Hierarchy.Parent))
                {
                    ops.Add(new Detatch(entity.Hierarchy.Parent.ID, entity));
                }
            }

            await MapDocumentOperation.Perform(document, new Transaction(ops));
        }
Exemplo n.º 17
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var objects = document.Selection.GetSelectedParents().ToList();
            var box     = document.Selection.GetSelectionBoundingBox();

            using (var dialog = new TransformDialog(box))
            {
                _translator.Value.Translate(dialog);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        var transaction = new Transaction();

                        // Add the operation
                        var transform          = dialog.GetTransformation(box);
                        var transformOperation = new BspEditor.Modification.Operations.Mutation.Transform(transform, objects);
                        transaction.Add(transformOperation);

                        // Check for texture transform
                        var tl = document.Map.Data.GetOne <TransformationFlags>() ?? new TransformationFlags();
                        if (dialog.Type == TransformDialog.TransformType.Rotate || dialog.Type == TransformDialog.TransformType.Translate)
                        {
                            if (tl.TextureLock)
                            {
                                transaction.Add(new TransformTexturesUniform(transform, objects.SelectMany(x => x.FindAll())));
                            }
                        }
                        else if (dialog.Type == TransformDialog.TransformType.Scale)
                        {
                            if (tl.TextureScaleLock)
                            {
                                transaction.Add(new TransformTexturesScale(transform, objects.SelectMany(x => x.FindAll())));
                            }
                        }

                        await MapDocumentOperation.Perform(document, transaction);
                    }
                    catch (TransformDialog.CannotScaleByZeroException)
                    {
                        MessageBox.Show(ErrorCannotScaleByZeroMessage, ErrorCannotScaleByZeroTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemplo n.º 18
0
        public async Task Fix(MapDocument document, Problem problem)
        {
            var entity = new Entity(document.Map.NumberGenerator.Next("MapObject"))
            {
                Data =
                {
                    new EntityData {
                        Name = "info_player_start"
                    },
                    new ObjectColor(Colour.GetDefaultEntityColour()),
                    new Origin(Vector3.Zero),
                },
                IsSelected = false
            };

            var action = new Attach(document.Map.Root.ID, entity);
            await MapDocumentOperation.Perform(document, action);
        }
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var tl = document.Map.Data.GetOne <DisplayFlags>() ?? new DisplayFlags();

            tl.HideNullTextures = !tl.HideNullTextures;

            var tc = await document.Environment.GetTextureCollection();

            await MapDocumentOperation.Perform(document,
                                               new TrivialOperation(
                                                   x => x.Map.Data.Replace(tl),
                                                   x =>
            {
                x.Update(tl);
                x.UpdateRange(x.Document.Map.Root.Find(s => s is Solid).Where(s => s.Data.Get <Face>().Any(f => tc.IsNullTexture(f.Texture.Name))));
            })
                                               );
        }
Exemplo n.º 20
0
        private void SelectButtonClicked(object sender, EventArgs e)
        {
            var textures = _textureList.GetHighlightedTextures().ToHashSet(StringComparer.InvariantCultureIgnoreCase);

            if (!textures.Any())
            {
                return;
            }

            var sel = _document.Map.Root.Find(x => x.Data.OfType <ITextured>().Any(t => textures.Contains(t.Texture.Name))).ToList();
            var des = _document.Selection.Except(sel).ToList();

            var transaction = new Transaction(new Select(sel), new Deselect(des));

            MapDocumentOperation.Perform(_document, transaction);

            Close();
        }
Exemplo n.º 21
0
        private async Task ExecuteReplace()
        {
            var doc = GetDocument();

            if (doc == null)
            {
                return;
            }

            var op = await GetOperation(doc);

            if (op == null)
            {
                return;
            }

            await MapDocumentOperation.Perform(doc, op);
        }
Exemplo n.º 22
0
        public async Task Commit(MapDocument document)
        {
            var tran = new Transaction();

            lock (_lock)
            {
                foreach (var solid in _selectedSolids.Where(x => x.IsDirty))
                {
                    tran.Add(new RemoveMapObjectData(solid.Real.ID, solid.Real.Faces));
                    tran.Add(new AddMapObjectData(solid.Real.ID, solid.Copy.Faces.Select(x => x.ToFace(document.Map.NumberGenerator))));
                    solid.Reset();
                }
            }

            if (!tran.IsEmpty)
            {
                await MapDocumentOperation.Perform(document, tran);
            }
        }
Exemplo n.º 23
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            var grid = document.Map.Data.GetOne <GridData>();

            if (grid == null)
            {
                return;
            }

            var tl = document.Map.Data.GetOne <TransformationFlags>() ?? new TransformationFlags();

            var transaction = new Transaction();

            foreach (var mo in document.Selection.GetSelectedParents().ToList())
            {
                var box = mo.BoundingBox;

                var start   = box.Start;
                var snapped = grid.Grid.Snap(start);
                var trans   = snapped - start;
                if (trans == Vector3.Zero)
                {
                    continue;
                }

                var tform = Matrix4x4.CreateTranslation(trans);

                var transformOperation = new BspEditor.Modification.Operations.Mutation.Transform(tform, mo);
                transaction.Add(transformOperation);

                // Check for texture transform
                if (tl.TextureLock)
                {
                    transaction.Add(new TransformTexturesUniform(tform, mo.FindAll()));
                }
            }

            if (!transaction.IsEmpty)
            {
                await MapDocumentOperation.Perform(document, transaction);
            }
        }
Exemplo n.º 24
0
        public Task Fix(MapDocument document, Problem problem)
        {
            var transaction = new Transaction();

            foreach (var obj in problem.Objects)
            {
                var data = obj.Data.GetOne <EntityData>();
                if (data == null)
                {
                    continue;
                }

                var vals = new Dictionary <string, string> {
                    ["target"] = null
                };
                transaction.Add(new EditEntityDataProperties(obj.ID, vals));
            }

            return(MapDocumentOperation.Perform(document, transaction));
        }
Exemplo n.º 25
0
        public async Task Update(MapDocument document)
        {
            if (document == null)
            {
                return;
            }

            var tran = new Transaction();

            lock (_lock)
            {
                var selection  = new HashSet <Solid>(document.Selection.OfType <Solid>());
                var toSelect   = selection.Except(_selectedSolids.Select(x => x.Real)).ToList();
                var toDeselect = _selectedSolids.Select(x => x.Real).Except(selection).ToList();

                if (toSelect.Any())
                {
                    tran.Add(new TrivialOperation(
                                 d => toSelect.ForEach(x => x.Data.Add(new VertexHidden())),
                                 c => c.UpdateRange(toSelect)
                                 ));
                }

                if (toDeselect.Any())
                {
                    tran.Add(new TrivialOperation(
                                 d => toDeselect.ForEach(x => x.Data.Remove(o => o is VertexHidden)),
                                 c => c.UpdateRange(toDeselect)
                                 ));
                }

                var rem = _selectedSolids.Where(s => toDeselect.Contains(s.Real));
                _selectedSolids.ExceptWith(rem);
                _selectedSolids.UnionWith(toSelect.Select(s => new VertexSolid(s)));
            }

            if (!tran.IsEmpty)
            {
                await MapDocumentOperation.Perform(document, tran);
            }
        }
Exemplo n.º 26
0
        private void CreateBrush(MapDocument document, Box bounds)
        {
            var brush = GetBrush(document, bounds, document.Map.NumberGenerator);

            if (brush == null)
            {
                return;
            }

            var transaction = new Transaction();

            transaction.Add(new Attach(document.Map.Root.ID, brush));

            if (_selectCreatedBrush)
            {
                transaction.Add(new Deselect(document.Selection));
                transaction.Add(new Select(brush.FindAll()));
            }

            MapDocumentOperation.Perform(document, transaction);
        }
Exemplo n.º 27
0
        public async Task Invoke(IContext context, CommandParameters parameters)
        {
            if (context.TryGet("ActiveDocument", out MapDocument doc))
            {
                if (!_grids.Any())
                {
                    return;
                }

                var current = doc.Map.Data.GetOne <GridData>()?.Grid;
                var idx     = current == null ? -1 : Array.FindIndex(_grids, x => x.IsInstance(current));
                idx = (idx + 1) % _grids.Length;

                var grid = await _grids[idx].Create(doc.Environment);

                var gd        = new GridData(grid);
                var operation = new TrivialOperation(x => doc.Map.Data.Replace(gd), x => x.Update(gd));

                await MapDocumentOperation.Perform(doc, operation);
            }
        }
Exemplo n.º 28
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            using (var qf = new QuickForm(Title)
            {
                UseShortcutKeys = true
            }.TextBox("ObjectID", ObjectID).OkCancel(OK, Cancel))
            {
                qf.ClientSize = new Size(230, qf.ClientSize.Height);

                if (await qf.ShowDialogAsync() != DialogResult.OK)
                {
                    return;
                }

                if (!long.TryParse(qf.String("ObjectID"), out var id))
                {
                    return;
                }

                var obj = document.Map.Root.FindByID(id);
                if (obj == null)
                {
                    return;
                }

                var tran = new Transaction(
                    new Deselect(document.Selection),
                    new Select(obj)
                    );

                await MapDocumentOperation.Perform(document, tran);

                var box = obj.BoundingBox;

                await Task.WhenAll(
                    Oy.Publish("MapDocument:Viewport:Focus3D", box),
                    Oy.Publish("MapDocument:Viewport:Focus2D", box)
                    );
            }
        }
Exemplo n.º 29
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            using (var vg = new VisgroupEditForm(document))
            {
                _translator.Value.Translate(vg);
                if (vg.ShowDialog() == DialogResult.OK)
                {
                    var nv = new List <Visgroup>();
                    var cv = new List <Visgroup>();
                    var dv = new List <Visgroup>();

                    vg.PopulateChangeLists(document, nv, cv, dv);

                    if (nv.Any() || cv.Any() || dv.Any())
                    {
                        var tns = new Transaction();

                        if (dv.Any())
                        {
                            var ids = dv.Select(x => x.ID).ToList();
                            tns.Add(new RemoveMapData(document.Map.Data.Get <Visgroup>().Where(x => ids.Contains(x.ID))));
                        }

                        if (cv.Any())
                        {
                            var ids = cv.Select(x => x.ID).ToList();
                            tns.Add(new RemoveMapData(document.Map.Data.Get <Visgroup>().Where(x => ids.Contains(x.ID))));
                            tns.Add(new AddMapData(cv));
                        }

                        if (nv.Any())
                        {
                            tns.Add(new AddMapData(nv));
                        }

                        await MapDocumentOperation.Perform(document, tns);
                    }
                }
            }
        }
Exemplo n.º 30
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter           = "Pointfiles (*.lin, *.pts)|*.lin;*.pts";
                ofd.InitialDirectory = Path.GetDirectoryName(document.FileName);
                ofd.Multiselect      = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var       file = ofd.FileName;
                var       text = File.ReadAllLines(file);
                Pointfile point;
                try
                {
                    point = Pointfile.Parse(text);
                }
                catch
                {
                    MessageBox.Show(String.Format(InvalidPointfile, Path.GetFileName(file)));
                    return;
                }

                await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                       d => d.Map.Data.Replace(point),
                                                       c => c.Add(c.Document.Map.Root)
                                                       ));

                if (point.Lines.Any())
                {
                    var start = point.Lines[0].Start;
                    await Oy.Publish("MapDocument:Viewport:Focus2D", start);

                    await Oy.Publish("MapDocument:Viewport:Focus3D", start);
                }
            }
        }