private void Start()
    {
        toolhandle = GetComponent <ToolHandle>();
        tool       = toolhandle.pickaxePicked;
        Quaternion quat = new Quaternion(0, 0, 0, 0);

        currentBuildBlock = buildGrassBlock;
        checkTools();
    }
Example #2
0
        /// <summary>
        /// Show an <see cref="Adornment"/> with <see cref="ToolHandle"/>s at each end of the link's route,
        /// if the link is selected and visible.
        /// </summary>
        /// <param name="part"></param>
        /// <remarks>
        /// </remarks>
        public override void UpdateAdornments(Part part)
        {
            Link link = part as Link;

            if (link == null)
            {
                return;          // no Nodes
            }
            Adornment adornment = null;

            if (link.IsSelected)
            {
                FrameworkElement selelt = link.Path;
                if (selelt != null && Part.IsVisibleElement(selelt))
                {
                    adornment = link.GetAdornment(ToolCategory);
                    if (adornment == null)
                    {
                        Route route = link.Route;
                        if (route != null)
                        {
                            IList <Point> pts    = route.Points;
                            int           numpts = route.PointsCount;
                            if (pts != null && numpts > 2)
                            {
                                // This tool's Adornments consists of a LinkPanel containing two ToolHandles.
                                LinkPanel panel = new LinkPanel();
#if SILVERLIGHT
                                var h = new System.Windows.Shapes.Path();
#else
                                var h = new ToolHandle();
#endif
                                // of course you can customize the appearance of the shift handles here...
                                NodePanel.SetFigure(h, NodeFigure.Rectangle);
                                h.Width  = 6;
                                h.Height = 6;
                                h.Fill   = new SolidColorBrush(Colors.Orange);
                                LinkPanel.SetIndex(h, 0);
                                LinkPanel.SetFraction(h, 0.5);
                                if (pts[0].X == pts[1].X && pts[0].Y != pts[1].Y)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Horizontal);
                                    h.Cursor = System.Windows.Input.Cursors.SizeWE;
                                }
                                else if (pts[0].Y == pts[1].Y && pts[0].X != pts[1].X)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Vertical);
                                    h.Cursor = System.Windows.Input.Cursors.SizeNS;
                                }
                                else
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.All);
#if !SILVERLIGHT
                                    h.Cursor = System.Windows.Input.Cursors.SizeAll;
#endif
                                }
                                panel.Children.Add(h);

#if SILVERLIGHT
                                h = new System.Windows.Shapes.Path();
#else
                                h = new ToolHandle();
#endif
                                NodePanel.SetFigure(h, NodeFigure.Rectangle);
                                h.Width  = 6;
                                h.Height = 6;
                                h.Fill   = new SolidColorBrush(Colors.Orange);
                                LinkPanel.SetIndex(h, -1);
                                LinkPanel.SetFraction(h, 0.5);
                                SetReshapeBehavior(h, ReshapeBehavior.All);
                                if (pts[numpts - 1].X == pts[numpts - 2].X && pts[numpts - 1].Y != pts[numpts - 2].Y)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Horizontal);
                                    h.Cursor = System.Windows.Input.Cursors.SizeWE;
                                }
                                else if (pts[numpts - 1].Y == pts[numpts - 2].Y && pts[numpts - 1].X != pts[numpts - 2].X)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Vertical);
                                    h.Cursor = System.Windows.Input.Cursors.SizeNS;
                                }
                                else
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.All);
#if !SILVERLIGHT
                                    h.Cursor = System.Windows.Input.Cursors.SizeAll;
#endif
                                }
                                panel.Children.Add(h);

                                adornment = new Adornment();
                                adornment.AdornedElement = selelt;
                                adornment.Category       = ToolCategory;
                                adornment.Content        = panel; // just provide the FrameworkElement as the Content and as the Visual Child
                                adornment.LocationSpot   = Spot.TopLeft;
                            }
                        }
                    }
                    if (adornment != null)
                    {
                        Point loc = link.GetElementPoint(selelt, Spot.TopLeft);
                        adornment.Location      = loc;
                        adornment.RotationAngle = link.GetAngle(selelt);
                        adornment.Remeasure();
                    }
                }
            }
            link.SetAdornment(ToolCategory, adornment);
        }