示例#1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UndertalePath path = value as UndertalePath;

            if (path == null)
            {
                return(null);
            }

            List <UndertalePathEditor.LineData> target = new List <UndertalePathEditor.LineData>();

            for (int i = 0; i < path.Points.Count - 1; i++)
            {
                target.Add(new UndertalePathEditor.LineData()
                {
                    From = new Point(path.Points[i].X, path.Points[i].Y),
                    To   = new Point(path.Points[i + 1].X, path.Points[i + 1].Y)
                });
            }
            if (path.IsClosed && path.Points.Count > 0)
            {
                target.Add(new UndertalePathEditor.LineData()
                {
                    From = new Point(path.Points[path.Points.Count - 1].X, path.Points[path.Points.Count - 1].Y),
                    To   = new Point(path.Points[0].X, path.Points[0].Y)
                });
            }

            return(target);
        }
示例#2
0
        private void Canvas_Drop(object sender, DragEventArgs e)
        {
            UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[e.Data.GetFormats().Length - 1]) as UndertaleObject;

            e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && (sourceItem is UndertaleGameObject || sourceItem is UndertalePath) ? DragDropEffects.Link : DragDropEffects.None;
            if (e.Effects == DragDropEffects.Link)
            {
                if (sourceItem is UndertaleGameObject)
                {
                    UndertaleGameObject droppedObject = sourceItem as UndertaleGameObject;
                    var mousePos = e.GetPosition(RoomGraphics);

                    UndertaleRoom room = this.DataContext as UndertaleRoom;
                    var           obj  = new UndertaleRoom.GameObject()
                    {
                        X = (int)mousePos.X,
                        Y = (int)mousePos.Y,
                        ObjectDefinition = droppedObject,
                        InstanceID       = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++
                    };
                    room.GameObjects.Add(obj);

                    SelectObject(obj);
                }

                if (sourceItem is UndertalePath)
                {
                    PreviewPath = sourceItem as UndertalePath;
                }
            }
            e.Handled = true;
        }
示例#3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UndertalePath path = value as UndertalePath;

            if (path == null)
            {
                return(null);
            }
            if (path.Points.Count == 0)
            {
                return(null);
            }

            Point boundingLow  = new Point(Double.PositiveInfinity, Double.PositiveInfinity);
            Point boundingHigh = new Point(Double.NegativeInfinity, Double.NegativeInfinity);

            foreach (var point in path.Points)
            {
                if (point.X < boundingLow.X)
                {
                    boundingLow.X = point.X;
                }
                if (point.Y < boundingLow.Y)
                {
                    boundingLow.Y = point.Y;
                }
                if (point.X > boundingHigh.X)
                {
                    boundingHigh.X = point.X;
                }
                if (point.Y > boundingHigh.Y)
                {
                    boundingHigh.Y = point.Y;
                }
            }

            PathFigure target = new PathFigure();

            target.StartPoint = new Point(path.Points[0].X, path.Points[0].Y);
            target.Segments   = new PathSegmentCollection();
            for (int i = 1; i < path.Points.Count; i++)
            {
                LineSegment segment = new LineSegment();
                segment.Point = new Point(path.Points[i].X, path.Points[i].Y);
                target.Segments.Add(segment);
            }
            target.IsClosed = path.IsClosed;
            target.Freeze();

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = new PathFigureCollection();
            myPathGeometry.Figures.Add(target);
            myPathGeometry.Freeze();

            return(myPathGeometry);
        }
        private void Canvas_Drop(object sender, DragEventArgs e)
        {
            UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[e.Data.GetFormats().Length - 1]) as UndertaleObject;

            e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && (sourceItem is UndertaleGameObject || sourceItem is UndertalePath) ? DragDropEffects.Link : DragDropEffects.None;
            if (e.Effects == DragDropEffects.Link)
            {
                if (sourceItem is UndertaleBackground)
                {
                }
                else if (sourceItem is UndertaleGameObject)
                {
                    UndertaleGameObject droppedObject = sourceItem as UndertaleGameObject;
                    var mousePos = e.GetPosition(RoomGraphics);

                    UndertaleRoom       room  = this.DataContext as UndertaleRoom;
                    UndertaleRoom.Layer layer = ObjectEditor.Content as UndertaleRoom.Layer;
                    if ((Application.Current.MainWindow as MainWindow).IsGMS2 == Visibility.Visible && layer == null)
                    {
                        MessageBox.Show("Must have a layer selected", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    if (layer != null && layer.InstancesData == null)
                    {
                        MessageBox.Show("Must be on an instances layer", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    var obj = new UndertaleRoom.GameObject()
                    {
                        X = (int)mousePos.X,
                        Y = (int)mousePos.Y,
                        ObjectDefinition = droppedObject,
                        InstanceID       = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++
                    };
                    room.GameObjects.Add(obj);
                    if (layer != null)
                    {
                        layer.InstancesData.Instances.Add(obj);
                    }

                    SelectObject(obj);
                }

                if (sourceItem is UndertalePath)
                {
                    PreviewPath = sourceItem as UndertalePath;
                }
            }
            e.Handled = true;

            (this.DataContext as UndertaleRoom)?.SetupRoom();
        }