Пример #1
0
 public override void Paste(MapObject o, IDGenerator generator)
 {
     PasteBase(o, generator);
     var e = o as World;
     if (e == null) return;
     EntityData = e.EntityData.Clone();
     Paths.Clear();
     Paths.AddRange(e.Paths.Select(x => x.Clone()));
 }
Пример #2
0
 public void PerformOperation(MapObject mo)
 {
     var current = Extractor(mo.BoundingBox);
     var target = Extractor(_alignBox);
     var value = target - current;
     var translate = Creator(value);
     var transform = new UnitTranslate(translate);
     mo.Transform(transform, _transformFlags);
 }
Пример #3
0
        public void PerformOperation(MapObject mo)
        {
            mo.Transform(_transformation, _transformFlags);

            if (ClearVisgroups)
            {
                foreach (var o in mo.FindAll()) o.Visgroups.Clear();
            }
        }
Пример #4
0
 public override void Unclone(MapObject o)
 {
     PasteBase(o, null, true);
     var e = o as World;
     if (e == null) return;
     EntityData = e.EntityData.Clone();
     Paths.Clear();
     Paths.AddRange(e.Paths.Select(x => x.Clone()));
 }
Пример #5
0
 private static void UpdateModels(Document document, MapObject mo)
 {
     mo.Children.ForEach(x => UpdateModels(document, x));
     var e = mo as Entity;
     if (e == null || !ShouldHaveModel(e)) return;
     var model = GetModelName(e);
     var file = document.Environment.Root.TraversePath(model);
     if (file == null) return;
     SetModel(e, ModelProvider.CreateModelReference(file));
 }
Пример #6
0
 public void Render2D(Viewport2D viewport, MapObject o)
 {
     if (Sledge.Settings.Select.CenterHandlesActiveViewportOnly && !viewport.IsFocused) return;
     var center = viewport.Flatten(o.BoundingBox.Center);
     double a = 192;
     if (Sledge.Settings.Select.CenterHandlesFollowCursor)
     {
         var dist = (double) (center - _mousePos).VectorMagnitude();
         if (dist >= _fadeDistance) return;
         a = 192 * ((_fadeDistance - dist) / _fadeDistance);
     }
     GL.Color4(Color.FromArgb((int) a, o.Colour));
     GL.Vertex2(center.DX - _offset, center.DY - _offset);
     GL.Vertex2(center.DX + _offset, center.DY + _offset);
     GL.Vertex2(center.DX - _offset, center.DY + _offset);
     GL.Vertex2(center.DX + _offset, center.DY - _offset);
 }
Пример #7
0
        public void Render3D(Viewport3D vp, MapObject o)
        {
            var right = vp.Camera.GetRight();
            var up = Vector3.Cross(right, (vp.Camera.LookAt - vp.Camera.Location).Normalized());
            var entity = (Entity) o;

            var orig = new Vector3((float)entity.Origin.X, (float)entity.Origin.Y, (float)entity.Origin.Z);
            if (entity.IsSelected)
            {
                orig = Vector3.TransformPosition(orig, Document.SelectListTransform);
            }
            var normal = Vector3.Subtract(vp.Camera.Location, orig);

            var tex = entity.Sprite;
            GL.Color3(Color.White);
            tex.Bind();

            if (entity.GameData != null)
            {
                var col = entity.GameData.Properties.FirstOrDefault(x => x.VariableType == VariableType.Color255);
                if (col != null)
                {
                    var val = entity.EntityData.Properties.FirstOrDefault(x => x.Key == col.Name);
                    if (val != null)
                    {
                        GL.Color3(val.GetColour(Color.White));
                    }
                }
            }

            var tup = Vector3.Multiply(up, (float)entity.BoundingBox.Height / 2f);
            var tright = Vector3.Multiply(right, (float)entity.BoundingBox.Width / 2f);

            GL.Begin(PrimitiveType.Quads);

            GL.Normal3(normal); GL.TexCoord2(1, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(1, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Subtract(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Subtract(tup, tright)));

            GL.End();
        }
Пример #8
0
        public void Render3D(Viewport3D vp, MapObject o)
        {
            // These billboards aren't perfect but they'll do (they rotate with the lookat vector rather than the location vector)

            var right = vp.Camera.GetRight();
            var up = vp.Camera.GetUp();
            var entity = (Entity) o;

            var orig = new Vector3((float)entity.Origin.X, (float)entity.Origin.Y, (float)entity.Origin.Z);
            var normal = Vector3.Subtract(vp.Camera.Location, orig);

            var tex = entity.Sprite;
            TextureHelper.EnableTexturing();
            GL.Color3(Color.White);
            tex.Bind();

            if (entity.GameData != null)
            {
                var col = entity.GameData.Properties.FirstOrDefault(x => x.VariableType == VariableType.Color255);
                if (col != null)
                {
                    var val = entity.EntityData.Properties.FirstOrDefault(x => x.Key == col.Name);
                    if (val != null)
                    {
                        GL.Color3(val.GetColour(Color.White));
                    }
                }
            }

            var tup = Vector3.Multiply(up, (float)entity.BoundingBox.Height / 2f);
            var tright = Vector3.Multiply(right, (float)entity.BoundingBox.Width / 2f);

            GL.Begin(BeginMode.Quads);

            GL.Normal3(normal); GL.TexCoord2(1, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(1, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Subtract(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Subtract(tup, tright)));

            GL.End();
        }
Пример #9
0
 public CreateReference(long parentID, MapObject mapObject)
 {
     ParentID = parentID;
     IsSelected = mapObject.IsSelected;
     MapObject = mapObject;
 }
Пример #10
0
 /// <summary>
 /// For use in the <code>MapObject.Find</code> method.
 /// Returns solids with displacements that are sewable with this one.
 /// </summary>
 /// <param name="obj">MapObject to test</param>
 /// <returns>True if the given object contains a sewable displacement.</returns>
 private bool HasSewableDisplacement(MapObject obj)
 {
     return((obj is Solid) && ((Solid)obj).Faces.OfType <Displacement>().Any(IsSewableTo));
 }
Пример #11
0
 public bool IsValidFor(MapObject o)
 {
     return false;
 }
Пример #12
0
        /// <summary>
        /// Deselect (first) a list of objects and then select (second) another list.
        /// </summary>
        /// <param name="objectsToDeselect">The objects to deselect</param>
        /// <param name="objectsToSelect">The objects to select</param>
        /// <param name="deselectAll">If true, this will ignore the objectToDeselect parameter and just deselect everything</param>
        /// <param name="ignoreGrouping">If true, object groups will be ignored</param>
        private void SetSelected(IEnumerable<MapObject> objectsToDeselect, IEnumerable<MapObject> objectsToSelect, bool deselectAll, bool ignoreGrouping)
        {
            if (objectsToDeselect == null) objectsToDeselect = new MapObject[0];
            if (objectsToSelect == null) objectsToSelect = new MapObject[0];

            if (deselectAll)
            {
                objectsToDeselect = Document.Selection.GetSelectedObjects();
                _lastTool = null;
            }

            // Normalise selections
            objectsToDeselect = NormaliseSelection(objectsToDeselect.Where(x => x != null), ignoreGrouping);
            objectsToSelect = NormaliseSelection(objectsToSelect.Where(x => x != null), ignoreGrouping);

            // Don't bother deselecting the objects we're about to select
            objectsToDeselect = objectsToDeselect.Where(x => !objectsToSelect.Contains(x));

            // Perform selections
            var deselected = objectsToDeselect.ToList();
            var selected = objectsToSelect.ToList();

            Document.PerformAction("Selection changed", new ChangeSelection(selected, deselected));
        }
Пример #13
0
 public override void Paste(MapObject o, IDGenerator generator)
 {
     PasteBase(o, generator);
     var e = o as Solid;
     if (e == null) return;
     Faces.Clear();
     foreach (var f in e.Faces.Select(x => x.Copy(generator)))
     {
         f.Parent = this;
         Faces.Add(f);
         f.UpdateBoundingBox();
     }
 }
Пример #14
0
 public bool IsValidFor(MapObject o)
 {
     return o is Entity;
 }
Пример #15
0
 public override void Paste(MapObject o, IDGenerator generator)
 {
     PasteBase(o, generator);
     var e = o as Entity;
     if (e == null) return;
     GameData = e.GameData;
     Origin = e.Origin.Clone();
     EntityData = e.EntityData.Clone();
 }
Пример #16
0
        private void MouseDown(Viewport3D vp, ViewportEvent e)
        {
            if (!_currentTool.NoSelection())
            {
                var vtxs = _currentTool.GetVerticesAtPoint(e.X, vp.Height - e.Y, vp);

                if (vtxs.Any())
                {
                    // Use the topmost vertex as the control point
                    var vtx = vtxs.First();

                    // Mouse down on a point
                    if (vtx.IsSelected && KeyboardState.Ctrl && _currentTool.ShouldDeselect(vtxs))
                    {
                        // If the vertex is selected and ctrl is down, deselect the vertices
                        vtxs.ForEach(x => x.IsSelected = false);
                    }
                    else
                    {
                        if (!vtx.IsSelected && !KeyboardState.Ctrl && _currentTool.ShouldDeselect(vtxs))
                        {
                            // If we aren't clicking on a selected point and ctrl is not down, deselect the others
                            Points.ForEach(x => x.IsSelected = false);
                            // If this point is already selected, don't deselect others. This is the same behaviour as 2D selection.
                        }
                        vtxs.ForEach(x => x.IsSelected = true);
                    }
                    VertexSelectionChanged();

                    // Don't do other click operations
                    return;
                }

                // Nothing clicked
                if (!KeyboardState.Ctrl)
                {
                    // Deselect all the points if not ctrl-ing
                    Points.ForEach(x => x.IsSelected = false);
                }
            }
            if (!_currentTool.No3DSelection())
            {
                // Do selection
                var ray = vp.CastRayFromScreen(e.X, e.Y);
                var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray, true);
                var solid = hits
                    .OfType<Solid>()
                    .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                    .Where(x => x.Intersection != null)
                    .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                    .Select(x => x.Item)
                    .FirstOrDefault();

                if (solid != null)
                {
                    if (solid.IsSelected && KeyboardState.Ctrl)
                    {
                        // deselect solid
                        var select = new MapObject[0];
                        var deselect = new[] {solid};
                        Document.PerformAction("Deselect VM solid", new ChangeSelection(select, deselect));
                    }
                    else if (!solid.IsSelected)
                    {
                        // select solid
                        var select = new[] {solid};
                        var deselect = !KeyboardState.Ctrl ? Document.Selection.GetSelectedObjects() : new MapObject[0];
                        Document.PerformAction("Select VM solid", new ChangeSelection(select, deselect));
                    }

                    // Don't do other click operations
                    return;
                }
            }

            base.MouseDown(vp, e);
        }
Пример #17
0
 public void Edit(MapObject before, MapObject after)
 {
     _editObjects.Add(new EditReference(before, new CopyPropertiesEditOperation(after)));
 }
Пример #18
0
 public void Edit(MapObject before, IEditOperation editOperation)
 {
     _editObjects.Add(new EditReference(before, editOperation));
 }
Пример #19
0
 protected void Edit(MapObject before, Action<Document, MapObject> action)
 {
     _editObjects.Add(new EditReference(before, action));
 }
Пример #20
0
        public void Render2D(Viewport2D viewport, MapObject o)
        {
            if (viewport.Zoom < 1) return;

            var entityData = o.GetEntityData();
            if (entityData == null) return;

            var start = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.Start));
            var end = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.End));
            if (start.X >= viewport.Width || end.X <= 0 || start.Y >= viewport.Height || end.Y <= 0) return;

            var text = entityData.Name;
            var nameProp = entityData.GetPropertyValue("targetname");
            if (!String.IsNullOrWhiteSpace(nameProp)) text += ": " + nameProp;

            // Center the text horizontally
            var wid = _printer.Measure(text, _printerFont, new RectangleF(0, 0, viewport.Width, viewport.Height));
            var cx = (float)(start.X + (end.X - start.X) / 2);
            var bounds = new RectangleF(cx - wid.BoundingBox.Width / 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height);

            _printer.Print(text, _printerFont, o.Colour, bounds);
        }
Пример #21
0
 public EditReference(long id, MapObject before, MapObject after)
 {
     ID = id;
     Before = before.Clone();
     After = after.Clone();
     Action = null;
 }
Пример #22
0
 public override void Unclone(MapObject o)
 {
     PasteBase(o, null, true);
     var e = o as Entity;
     if (e == null) return;
     GameData = e.GameData;
     Origin = e.Origin.Clone();
     EntityData = e.EntityData.Clone();
 }
Пример #23
0
 public EditReference(MapObject obj, Action<Document, MapObject> action)
 {
     ID = obj.ID;
     Before = obj.Clone();
     After = null;
     Action = action;
 }
Пример #24
0
        public void Render2D(Viewport2D viewport, MapObject o)
        {
            if (viewport.Zoom < 1) return;

            var entityData = o.GetEntityData();
            if (entityData == null) return;

            var start = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.Start));
            var end = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.End));
            if (start.X >= viewport.Width || end.X <= 0 || start.Y >= viewport.Height || end.Y <= 0) return;

            var text = entityData.Name;
            var nameProp = entityData.GetPropertyValue("targetname");
            if (!String.IsNullOrWhiteSpace(nameProp)) text += ": " + nameProp;

            _printer.Print(text, _printerFont, o.Colour, new RectangleF((float)start.X + 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height));
        }
Пример #25
0
 public override void Paste(MapObject o, IDGenerator generator)
 {
     PasteBase(o, generator);
 }
Пример #26
0
 public override void Unclone(MapObject o)
 {
     PasteBase(o, null, true);
     var e = o as Solid;
     if (e == null) return;
     Faces.Clear();
     foreach (var f in e.Faces.Select(x => x.Clone()))
     {
         f.Parent = this;
         Faces.Add(f);
         f.UpdateBoundingBox();
     }
     UpdateBoundingBox();
 }
Пример #27
0
 public override void Unclone(MapObject o)
 {
     PasteBase(o, null, true);
 }
Пример #28
0
 /// <summary>
 /// For use in the <code>MapObject.Find</code> method.
 /// Returns solids with displacements that are sewable with this one.
 /// </summary>
 /// <param name="obj">MapObject to test</param>
 /// <returns>True if the given object contains a sewable displacement.</returns>
 private bool HasSewableDisplacement(MapObject obj)
 {
     return (obj is Solid) && ((Solid) obj).Faces.OfType<Displacement>().Any(IsSewableTo);
 }
Пример #29
0
 public DeleteReference(MapObject o, long parentID, bool isSelected, bool topMost)
 {
     Object = o;
     ParentID = parentID;
     IsSelected = isSelected;
     TopMost = topMost;
 }
Пример #30
0
 public void Render3D(Viewport3D viewport, MapObject o)
 {
     throw new NotImplementedException();
 }
Пример #31
0
 public EditReference(MapObject obj, IEditOperation editOperation)
 {
     ID = obj.ID;
     Before = obj.Clone();
     EditOperation = editOperation;
 }