コード例 #1
0
        private void VerticeControl_InputStateChanged(object sender, RoutedPropertyChangedEventArgs <InputState> e)
        {
            var vertice = sender as VerticeControl;

            switch (e.NewValue)
            {
            case InputState.Clicked:
                //vertice.PreviewColor = pickedColor;
                break;

            case InputState.Dragged:
                if (verticeOrigin == null)
                {
                    // transisi dari ORIGIN ke PICKED
                    verticeOrigin          = vertice;
                    supportLine.X1         = vertice.CanvasLeft;
                    supportLine.Y1         = vertice.CanvasTop;
                    supportLine.X2         = vertice.CanvasLeft;
                    supportLine.Y2         = vertice.CanvasTop;
                    supportLine.Visibility = Visibility.Visible;
                }
                break;

            case InputState.Hovered:
                if (verticeOrigin != null && verticeOrigin != vertice)
                {
                    // transisi dari PICKED ke NODE_HOVERED
                    vertice.InputState = InputState.Dragged;
                    supportLine.X2     = vertice.CanvasLeft;
                    supportLine.Y2     = vertice.CanvasTop;
                    Snap(vertice);
                }
                break;
            }
        }
コード例 #2
0
 protected override void VerticeDrop(VerticeControl origin, VerticeControl adjacent)
 {
     base.VerticeDrop(origin, adjacent);
     if (this.FindEdge(origin, adjacent) is EdgeControl edge)
     {
         edge.Cost = IsPlayer1Turn ? 1 : 2;
     }
 }
コード例 #3
0
        public EdgeControl(VerticeControl verticeA, VerticeControl verticeB, int cost)
            : this()
        {
            this.verticeA = verticeA;
            this.verticeB = verticeB;
            var id = verticeA.ID[0] < verticeB.ID[0] ? verticeA.ID : verticeB.ID;

            id     += VerticeA.ID == id ? verticeA.ID : verticeA.ID;
            Cost    = cost;
            this.id = id;
        }
コード例 #4
0
 private void ReleaseSnap()
 {
     if (verticeOrigin != null)
     {
         snapped = false;
         if (this.FindEdge(verticeAdjacent, verticeOrigin) is EdgeControl edge)
         {
             edge.Highlighted = false;
         }
         verticeAdjacent = null;
     }
 }
コード例 #5
0
 private void Snap(VerticeControl vertice)
 {
     if (verticeOrigin != null)
     {
         snapped = true;
         if (this.FindEdge(vertice, verticeOrigin) is EdgeControl edge)
         {
             edge.Highlighted = true;
         }
         verticeAdjacent = vertice;
     }
 }
コード例 #6
0
        private void Origin()
        {
            verticeOrigin.InputState = InputState.Origin;
            verticeOrigin            = null;

            supportLine.X1         = 0;
            supportLine.X2         = 0;
            supportLine.Y1         = 0;
            supportLine.Y2         = 0;
            supportLine.Visibility = Visibility.Hidden;
            //verticeAdjacent = null;
        }
コード例 #7
0
        private Storyboard DrawLineAnima(VerticeControl v2)
        {
            var sb       = new Storyboard();
            var trXAnima = new DoubleAnimation();

            trXAnima.To = v2.CanvasLeft;
            trXAnima.By = 1;
            Storyboard.SetTarget(trXAnima, supportLine);
            Storyboard.SetTargetProperty(trXAnima, new PropertyPath("X2"));
            var trYAnima = new DoubleAnimation();

            trYAnima.To = v2.CanvasTop;
            trYAnima.By = 1;
            Storyboard.SetTarget(trYAnima, supportLine);
            Storyboard.SetTargetProperty(trYAnima, new PropertyPath("Y2"));
            sb.Children.Add(trXAnima);
            sb.Children.Add(trYAnima);
            return(sb);
        }
コード例 #8
0
 protected virtual void VerticeDrop(VerticeControl origin, VerticeControl adjacent)
 {
 }
コード例 #9
0
        public virtual void Render()
        {
            if (!rendered)
            {
                vertices = new List <IVertice <int> >(VerticesCount);
                var idx = 0;
                foreach (var pt in SpreadPoints())
                {
                    var vertice = new VerticeControl((char)(idx + 'A'));
                    vertice.MouseLeave += VerticeControl_MouseLeave;
                    vertice.PreviewMouseLeftButtonUp += VerticeControl_PreviewMouseLeftButtonUp;
                    vertice.MouseLeftButtonUp        += VerticeControl_MouseLeftButtonUp;
                    vertice.InputStateChanged        += VerticeControl_InputStateChanged;
                    vertice.IsEnabledChanged         += VerticeControl_IsEnabledChanged;
                    vertice.CanvasLeft = pt.X;
                    vertice.CanvasTop  = pt.Y;
                    Panel.SetZIndex(vertice, VerticeZIndex);
                    vertice.SetBinding(VerticeControl.BackgroundProperty, new Binding("Background")
                    {
                        Source = this, Mode = BindingMode.OneTime
                    });
                    vertice.SetBinding(VerticeControl.ForegroundProperty, new Binding("Foreground")
                    {
                        Source = this, Mode = BindingMode.OneTime, Converter = new CloneConverter()
                    });
                    vertice.SetBinding(VerticeControl.SizeProperty, new Binding("VerticesSize")
                    {
                        Source = this, Mode = BindingMode.OneTime
                    });
                    vertice.SetBinding(VerticeControl.PreviewColorProperty, new Binding("PreviewColor")
                    {
                        Source = this
                    });
                    vertices.Add(vertice);
                    canvas.Children.Add(vertice);
                    idx++;
                }

                edges = new List <IEdge <int> >((VerticesCount * (VerticesCount - 1)) / 2);
                for (int i = 1; i < VerticesCount; i++)
                {
                    var v1 = Vertices[i] as VerticeControl;
                    for (int j = 0; j < i; j++)
                    {
                        var v2 = Vertices[j] as VerticeControl;
                        if (v1.Connect(v2, 0) is EdgeControl edgeControl)
                        {
                            edgeControl.X1 = v1.CanvasLeft;
                            edgeControl.Y1 = v1.CanvasTop;
                            edgeControl.X2 = v2.CanvasLeft;
                            edgeControl.Y2 = v2.CanvasTop;
                            edgeControl.MouseLeftButtonUp += Grid_MouseLeftButtonUp;
                            edgeControl.MouseMove         += Grid_MouseMove;
                            Panel.SetZIndex(edgeControl, EdgesZIndex);
                            var binding = new Binding("VerticesSize")
                            {
                                Source    = this,
                                Mode      = BindingMode.OneTime,
                                Converter = new SizeRatioConverter()
                                {
                                    Ratio = 0.2
                                }
                            };
                            edgeControl.SetBinding(EdgeControl.SizeProperty, binding);
                            edgeControl.SetBinding(EdgeControl.ForegroundProperty, new Binding("Foreground")
                            {
                                Source = this, Mode = BindingMode.OneTime, Converter = new CloneConverter()
                            });
                            //edgeControl.CostChanged += Edge_CostChanged;
                            canvas.Children.Add(edgeControl);
                            edges.Add(edgeControl);
                        }
                    }
                }
                {
                    supportLine = new EdgeControl();
                    supportLine.MouseLeftButtonUp += Grid_MouseLeftButtonUp;
                    supportLine.MouseMove         += Grid_MouseMove;
                    Panel.SetZIndex(supportLine, SupportLineZIndex);
                    var binding = new Binding("VerticesSize")
                    {
                        Source    = this,
                        Converter = new SizeRatioConverter()
                        {
                            Ratio = 0.2
                        }
                    };
                    supportLine.SetBinding(EdgeControl.SizeProperty, binding);
                    supportLine.SetBinding(EdgeControl.ForegroundProperty, new Binding("PreviewBrush")
                    {
                        Source = this
                    });
                    supportLine.Highlighted = true;
                    supportLine.Visibility  = Visibility.Hidden;
                    canvas.Children.Add(supportLine);
                }
                rendered = true;
            }
        }
コード例 #10
0
        protected virtual void OnGamesEnd(GameResult gameResult)
        {
            if (gameResult.GameStatus == GameStatus.Draw)
            {
                RaiseEvent(new GamesEndEventArgs(GamesEndEvent, this, gameResult));
                return;
            }
            var set = new HashSet <VerticeControl>();

            IsEnabled = false;
            var fgColor = Colors.Black;

            if (gameResult.Edges != null)
            {
                foreach (EdgeControl f in gameResult.Edges)
                {
                    var v1 = f.VerticeA as VerticeControl;
                    var v2 = f.VerticeB as VerticeControl;
                    set.Add(v1);
                    set.Add(v2);
                    fgColor       = (f.Foreground as SolidColorBrush).Color;
                    f.Highlighted = true;
                    Panel.SetZIndex(f, 85);
                }
            }
            var boomAnima = new Storyboard();

            foreach (var v in set)
            {
                v.Visibility = Visibility.Hidden;
                var nv = new VerticeControl(v.ID[0]);
                nv.Size       = v.Size;
                nv.Foreground = new SolidColorBrush(fgColor);
                nv.Background = v.Background;
                nv.CanvasLeft = v.CanvasLeft;
                nv.CanvasTop  = v.CanvasTop;
                Panel.SetZIndex(nv, 100);
                nv.InputState = InputState.Dragged;
                nv.IsEnabled  = false;
                canvas.Children.Add(nv);

                var ell = new Ellipse();
                ell.Stroke = new SolidColorBrush(fgColor);
                ell.Width  = 2;
                ell.Height = 2;
                ell.RenderTransformOrigin = new Point(0.5, 0.5);
                ell.RenderTransform       = new ScaleTransform();
                Canvas.SetLeft(ell, -1 + v.CanvasLeft);
                Canvas.SetTop(ell, -1 + v.CanvasTop);
                canvas.Children.Add(ell);
                var sx = new DoubleAnimation(200, Anima.ShortDuration);
                var sy = new DoubleAnimation(200, Anima.ShortDuration);
                var op = new DoubleAnimation(0, Anima.ShortDuration);
                sx.FillBehavior = FillBehavior.Stop;
                sy.FillBehavior = FillBehavior.Stop;
                //op.FillBehavior = FillBehavior.Stop;
                Storyboard.SetTarget(sx, ell);
                Storyboard.SetTarget(sy, ell);
                Storyboard.SetTarget(op, ell);
                Storyboard.SetTargetProperty(sx, new PropertyPath("RenderTransform.ScaleX"));
                Storyboard.SetTargetProperty(sy, new PropertyPath("RenderTransform.ScaleY"));
                Storyboard.SetTargetProperty(op, new PropertyPath("Opacity"));
                boomAnima.Children.Add(sy);
                boomAnima.Children.Add(sx);
                boomAnima.Children.Add(op);
            }
            boomAnima.Completed += (o, e) => RaiseEvent(new GamesEndEventArgs(GamesEndEvent, this, gameResult));
            boomAnima.Begin();
        }