Beispiel #1
0
        /*
         * Here, newSubView is set to false when adding sub views from the constructor (so the
         * view's data type is already added to ArgTypes. From outside the class the public
         * AddSubView defined above is called, always for new subviews
         */
        private void AddSubView(IBlockView v, DataType argType, int i, bool newSubView)
        {
            if (!(v is LabelView || v is EditableLabelView))
            {
                argIndexes.Add(i);
                trueArgs.Add(true);
                if (newSubView)
                {
                    ArgTypes.Add(argType);
                }
            }
            else
            {
                trueArgs.Add(false);
            }

            if (v.Parent != null)
            {
                ((ContentView)v.Parent).Detach(v);
            }
            Attach(v);
            argViews.Add(v);
            parts.Add(v.Assemble());
            Reassemble();
            Changed(this);
        }
Beispiel #2
0
    public void ShouldMoveBlockViewsWhenDropBlocks()
    {
        IBlockView blockViewOne   = Substitute.For <IBlockView>();
        IBlockView blockViewTwo   = Substitute.For <IBlockView>();
        IBlockView blockViewThree = Substitute.For <IBlockView>();
        IBlockView blockViewFour  = Substitute.For <IBlockView>();

        group.Children[0].AttachView(blockViewOne);
        group.Children[1].AttachView(blockViewTwo);
        group.Children[2].AttachView(blockViewThree);
        group.Children[3].AttachView(blockViewFour);
        Assert.IsTrue(grid.AddGroup(group));
        Assert.IsTrue(group.Location.Equals(setting.BlockSpawnPoint));
        grid.SetState(GridStates.OnFix);
        grid.OnUpdate();
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Dropping);
        blockViewOne.Received().MoveTo(group.Children[0].Location.ToVector2());
        blockViewTwo.Received().MoveTo(group.Children[1].Location.ToVector2());
        blockViewThree.Received().MoveTo(group.Children[2].Location.ToVector2());
        blockViewFour.Received().MoveTo(group.Children[3].Location.ToVector2());
        grid.OnUpdate();
        Assert.IsTrue(grid.CurrenteStateName == GridStates.Dropped);
        blockViewOne.Received().OnUpdate();
        blockViewTwo.Received().OnUpdate();
        blockViewThree.Received().OnUpdate();
        blockViewFour.Received().OnUpdate();
    }
Beispiel #3
0
 private void BodyBlockSlotOnTryToDisconnect(BlockPlug plug)
 {
     plug.BlockViewGameObject.transform.SetParent(null);
     _connectedView = null;
     Block.Next     = null;
     SizeChanged?.Invoke(FullSize);
 }
Beispiel #4
0
        void ProcDefBlock_FormalParamChanged(object sender, int index, IProcDefBit newBit)
        {
            IBlockView  v      = ViewFromBlock((VarDefBlock)newBit);
            ProcDefView parent = (ProcDefView)ViewFromBlock((IBlock)sender);

            parent.SetFormalBit(index, v);
        }
Beispiel #5
0
        public IBlockView ChildHasPoint(Point p, Point origin)
        {
            for (int i = 0; i < Contents.Count; ++i)
            {
                IBlockView v  = Contents[i];
                Point      rp = new Point(0, layoutOffsets[i * 2]); // notice that contentOffsets also holds the offset
                if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y)))     // of the "side" graphics, not just the content views
                {
                    IBlockView chp = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y));
                    if (chp == v)
                    {
                        return(this);
                    }
                    else
                    {
                        return(chp);
                    }
                }
            }

            for (int i = 0; i < Scripts.Count; ++i)
            {
                IBlockView v  = Scripts[i];
                Point      rp = scriptOffsets[i];
                if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y)))
                {
                    return(v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)));
                }
            }
            return(this);
        }
Beispiel #6
0
        public IBlockView ChildHasPoint(Point p, Point origin)
        {
            int y = 0;

            for (int i = 0; i < elements.Count; ++i)
            {
                IBlockView v  = elements[i];
                Point      rp = new Point(0, y);

                if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y)))
                {
                    IBlockView c = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y));
                    if (i == 0 && c == v)
                    {
                        // selecting the first block-> select whole stack
                        // but selecting a proper child of the first block should
                        // go normally
                        return(this);
                    }
                    else
                    {
                        return(c);
                    }
                }
                y += elementBitmaps[i].Height - BlockStackView.NotchHeight;
            }
            return(this);
        }
Beispiel #7
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                currentBlockView = hit.collider.gameObject.GetComponent <IBlockView>();
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            currentBlockView?.TryToConnect();

            currentBlockView = null;
        }

        if (currentBlockView != null)
        {
            var   plane = new Plane(Vector3.forward, Vector3.zero);
            float distance;
            var   ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (plane.Raycast(ray, out distance))
            {
                currentBlockView.Position = ray.GetPoint(distance);
            }
        }
    }
Beispiel #8
0
        private void GenerateShape(bool[,] shape, ShapeView shapeView, Color shapeColor)
        {
            var height = shape.GetLength(0);
            var width  = shape.GetLength(1);

            var blockViews = new IBlockView[height, width];

            shapeView.Shape = shape;

            for (var i = 0; i < height; i++)
            {
                for (var j = 0; j < width; j++)
                {
                    if (shape[i, j])
                    {
                        var blockView = BlockPool.Pop();
                        blockView.SetParent(shapeView.BlockContainer);
                        blockView.SetLocalPosition(new Vector3(j - width / 2f + 0.5f, height / 2f - i - 0.5f));
                        blockViews[i, j] = blockView;
                        blockView.SetColor(shapeColor);
                    }
                }
            }
            shapeView.BlockViews = blockViews;
            shapeView.MininimazeScale();
        }
Beispiel #9
0
        void blockstack_OnInsert(object sender, int i, IBlock b)
        {
            IBlockView     v      = ViewFromBlock(b);
            BlockStackView parent = (BlockStackView)ViewFromBlock((IBlock)sender);

            parent.InsertView(i, v);
            modified();
        }
Beispiel #10
0
        void InvokationBlock_ArgChanged(object sender, int arg, IBlock _old, IBlock _new)
        {
            IBlockView           v      = ViewFromBlock(_new);
            IInvokationBlockView parent = (IInvokationBlockView)ViewFromBlock((IBlock)sender);

            parent.SetArgView(arg, v);
            modified();
        }
Beispiel #11
0
        void ProcDefBlock_FormalParamRemoved(object sender, IProcDefBit bit)
        {
            ProcDefBlock b       = (ProcDefBlock)sender;
            ProcDefView  v       = (ProcDefView)ViewFromBlock(b);
            IBlockView   bitView = ViewFromBlock((IBlock)bit);

            v.RemoveFormalBit(bitView);
        }
Beispiel #12
0
 private Rectangle ViewBounds(IBlockView v)
 {
     if (!allViews.ContainsKey(v))
     {
         return(Rectangle.Empty);
     }
     return(new Rectangle(allViews[v], v.Assemble().Size));
 }
Beispiel #13
0
    public void ViewReceivesDeleteWhenDeleteBlock()
    {
        IBlockView blockView = Substitute.For <IBlockView>();

        block.AttachView(blockView);
        block.StartDeleting();
        blockView.Received().Delete();
    }
Beispiel #14
0
 public static IBlockView AbsoluteAncestor(this IBlockView v)
 {
     while (v.Parent != null)
     {
         v = v.Parent;
     }
     return(v);
 }
Beispiel #15
0
 private void Detach(IBlockView v)
 {
     if (!(v.Parent == this))
     {
         throw new InvalidOperationException("How did the parent of my arg not be me??");
     }
     v.Parent   = null;
     v.Changed -= ArgView_Changed;
 }
Beispiel #16
0
 private void BodyBlockSlotOnTryToConnect(BlockPlug plug)
 {
     plug.BlockViewGameObject.transform.SetParent(ChildSlot.transform);
     plug.BlockViewGameObject.transform.localPosition = Vector3.zero;
     _connectedView = plug.BlockView;
     SizeChanged?.Invoke(FullSize);
     plug.BlockView.SizeChanged += BlockViewOnSizeChanged;
     Block.Next = plug.BlockView.Block;
 }
 private void OnBlockRemoved(IBlockModel block)
 {
     _rotationAnimator.StopAnimation(_ghostBlockView);
     _movementAnimator.StopAnimation(_ghostBlockView);
     _ghostBlockView?.Dispose();
     _ghostBlockView          = null;
     block.OnPositionChanged -= UpdateGhostPositionRotation;
     block.OnRotationChanged -= UpdateGhostPositionRotation;
 }
Beispiel #18
0
        void blockSpace_OnTopLevelDeleted(object sender, TopLevelScript tl)
        {
            IBlockView v      = blockViews[tl.Block];
            Rectangle  bounds = ViewBounds(v);

            allViews.Remove(v);
            Modified(this);
            Update(bounds);
        }
 public void StopAnimation(IBlockView view)
 {
     for (var i = _animations.Count - 1; i >= 0; i--)
     {
         if (view == _animations[i].View)
         {
             _animations.RemoveAt(i);
         }
     }
 }
Beispiel #20
0
        internal void RemoveSubView(IBlockView v)
        {
            int index = argViews.IndexOf(v);

            if (index == -1)
            {
                throw new ArgumentException("ContentView.RemoveSubView: view doesn't exist");
            }
            RemoveSubView(index);
        }
Beispiel #21
0
        public static Point AbsolutePos(this IBlockView v)
        {
            Point p = v.RelativePos;

            while (v.Parent != null)
            {
                p = p.Offseted(v.Parent.RelativePos);
                v = v.Parent;
            }
            return(p);
        }
Beispiel #22
0
    public void ShouldReturnTrueWhenBlockViewIsOnMove()
    {
        Assert.IsFalse(block.IsOnMove);

        IBlockView blockView = Substitute.For <IBlockView>();

        blockView.IsOnMove.Returns(true);
        block.AttachView(blockView);

        Assert.IsTrue(block.IsOnMove);
    }
Beispiel #23
0
        public void RemoveSubView(int index)
        {
            IBlockView v = argViews[index];

            Detach(v);
            argViews.RemoveAt(index);
            parts.RemoveAt(index);

            Reassemble();
            Changed(this);
        }
Beispiel #24
0
        void blockSpace_OnTopLevelAdded(object sender, TopLevelScript tl)
        {
            IBlockView v = viewFactory.ViewFromBlock(tl.Block);

            allViews[v]   = tl.Location;
            v.RelativePos = tl.Location;
            v.Parent      = null;

            Update(ViewBounds(v));
            Modified(this);
        }
Beispiel #25
0
    public void ViewShouldReceiveMoveTo()
    {
        IBlockView blockView = Substitute.For <IBlockView>();

        block.AttachView(blockView);
        Coord coord = new Coord(2, 2);

        block.Move(coord);

        blockView.Received().MoveTo(Arg.Any <Vector2>());
    }
Beispiel #26
0
        private IBlockView HitTest(Point p)
        {
            IBlockView hit      = null;
            Point      location = view.RelativePos;

            if (view.HasPoint(p, location))
            {
                hit = view.ChildHasPoint(p, location);
            }

            return(hit);
        }
Beispiel #27
0
        void blockSpace_OnTopLevelMoved(object sender, TopLevelScript tl)
        {
            IBlockView v  = blockViews[tl.Block];
            Rectangle  r1 = ViewBounds(v);

            v.RelativePos = tl.Location;
            allViews[v]   = tl.Location;
            Rectangle r2 = ViewBounds(v);

            Modified(this);
            Update(Rectangle.Union(r1, r2));
        }
Beispiel #28
0
    public void ShouldReturnIsToDeleteTrueWhenViewReturnsTrue()
    {
        IBlockView blockView = Substitute.For <IBlockView>();

        blockView.IsDeleting.Returns(true);
        block.AttachView(blockView);

        block.IsToDelete.Returns(true);

        blockView.IsToDelete.Returns(false);
        block.IsToDelete.Returns(false);
    }
Beispiel #29
0
        public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination, object extraInfo, DataType argType)
        {
            this.DropType = DropType;
            this.Rectangle = Rectangle;
            this.Destination = destination;
            this.ExtraInfo = extraInfo;
            this.ArgType = argType;

            if (argType == DataType.Invalid && DropType == DropType.AsArgument)
            {
                throw new ArgumentException("DropRegion constructor: if DropType is argument, you must supply a valid argument type", "argType");
            }
        }
Beispiel #30
0
 internal void InsertView(int i, IBlockView v)
 {
     if (v.Parent != null)
     {
         // We don't want to deal here with deataching v from its parent
         // it should be already detached
         throw new InvalidOperationException();
     }
     Attach(v);
     elements.Insert(i, v);
     Reassemble();
     Changed(this);
 }
Beispiel #31
0
        public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination, object extraInfo, DataType argType)
        {
            this.DropType    = DropType;
            this.Rectangle   = Rectangle;
            this.Destination = destination;
            this.ExtraInfo   = extraInfo;
            this.ArgType     = argType;

            if (argType == DataType.Invalid && DropType == DropType.AsArgument)
            {
                throw new ArgumentException("DropRegion constructor: if DropType is argument, you must supply a valid argument type", "argType");
            }
        }
Beispiel #32
0
 internal void InsertView(int i, IBlockView v)
 {
     if (v.Parent != null)
     {
         // We don't want to deal here with deataching v from its parent
         // it should be already detached
         throw new InvalidOperationException();
     }
     Attach(v);
     elements.Insert(i, v);
     Reassemble();
     Changed(this);
 }
Beispiel #33
0
 private void Attach(IBlockView v)
 {
     v.Parent = this;
     v.Changed += new ViewChangedEvent(subView_Changed);
 }
Beispiel #34
0
 public void AddFormalBit(IBlockView bit, DataType type)
 {
     invokationContent.AddSubView(bit, type);
 }
Beispiel #35
0
 public void SetFormalBit(int index, IBlockView v)
 {
     invokationContent.SetSubView(index, v);
 }
Beispiel #36
0
 public void RemoveFormalBit(IBlockView bit)
 {
     invokationContent.RemoveSubView(bit);
 }
Beispiel #37
0
 private Rectangle ViewBounds(IBlockView v)
 {
     if (!allViews.ContainsKey(v))
         return Rectangle.Empty;
     return new Rectangle(allViews[v], v.Assemble().Size);
 }
Beispiel #38
0
        internal void MouseDown(Point p)
        {
            if (state == CanvasState.TextEditing)
            {
                // Since the mousedown registered, we've clicked outside the textbox
                ResetTextEditState();
            }
            else if (state == CanvasState.Ready)
            {
                if (canvasView.PaletteRect.Contains(p))
                {
                    int x = canvasView.PaletteRect.Left;
                    int y = canvasView.PaletteRect.Top;
                    IBlock[] defaultArgs;
                    string funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs);
                    if (funcName != "")
                    {
                        IBlock b = blockSpace.makeNewBlock(funcName,defaultArgs);
                        TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5));

                        dragged = blockViews[b];
                        draggingOrigin = p;
                        draggedModel = s;
                        state = CanvasState.Dragging;
                        PrepareDropRegions(b);
                        Update(ViewBounds(dragged));
                        return;
                    }
                }
                IBlockView hit = HitTest(p);
                if (hit == null)
                    return;
                if (!allViews.ContainsKey(hit))
                {
                    if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack)
                    {

                        int i = hit.Model.ParentRelationship.Index;

                        Point np = hit.AbsolutePos();
                        Rectangle bounds = ViewBounds(hit.AbsoluteAncestor());
                        BlockStack parent = (BlockStack)hit.Model.ParentRelationship.Parent;
                        TopLevelScript splitted = SplitBlockStack(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg)
                    {
                        if (hit is ITextualView)
                        {
                            // We shouldn't detach e.g a number argument from its block
                            // but we should enable the user to edit it

                            SetEditState((ITextualView) hit);
                            return;
                        }
                        int i = hit.Model.ParentRelationship.Index;

                        Point np = hit.AbsolutePos();
                        Rectangle bounds = ViewBounds(hit.AbsoluteAncestor());
                        InvokationBlock parent = (InvokationBlock)hit.Model.ParentRelationship.Parent;
                        TopLevelScript splitted = TakeoutBlockArgument(parent, i, np);
                        Update(bounds);
                        draggedModel = splitted;
                        hit = blockViews[splitted.Block];
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter)
                    {
                        ProcDefBlock pd = (ProcDefBlock ) hit.Model.ParentRelationship.Parent;
                        VarAccessBlock va = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]);
                        TopLevelScript tls = AddTopLevel(va, p);
                        hit = ViewFromBlock(va);
                        draggedModel = tls;
                    }
                    else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None)
                    {
                        hit = null;
                        draggedModel = null;
                    }
                }
                else
                {
                    draggedModel = blockSpace.FindScript(hit.Model);
                }
                if (hit != null)
                {
                    dragged = hit;
                    draggingOrigin = p;
                    state = CanvasState.Dragging;
                    PrepareDropRegions(hit.Model);
                }
                Update();
            }
        }
Beispiel #39
0
 public void Mark(IBlockView v)
 {
     canvasView.Marked = v;
 }
Beispiel #40
0
 public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination, object extraInfo)
     : this(DropType, Rectangle, destination, extraInfo, DataType.Invalid)
 {
 }
Beispiel #41
0
 public Block()
 {
     _view = new NullBlockView();
 }
Beispiel #42
0
 public void AttachView(IBlockView view)
 {
     _view = view;
 }
Beispiel #43
0
 public void SetArgView(int i, IBlockView v)
 {
     int iContent = 0, iScript = 0;
     ArgViewType resultViewType = ArgViewType.Unknown;
     for (int j = 0; j < ArgPartitions.Count; ++j)
     {
         ArgumentPartition p = ArgPartitions[j];
         if (p.Type == ArgViewType.Content)
         {
             if (i < p.N)
             {
                 resultViewType = ArgViewType.Content;
                 break;
             }
             else
             {
                 i -= p.N;
                 iContent++;
             }
         }
         else if (p.Type == ArgViewType.Script)
         {
             if (i < p.N)
             {
                 resultViewType = ArgViewType.Script;
                 break;
             }
             else
             {
                 i -= p.N;
                 iScript++;
             }
         }
     }
     // Now we can use resultViewType and i to determine the arg
     if (resultViewType == ArgViewType.Content)
     {
         Contents[iContent].SetArgView(i, v);
     }
     else if (resultViewType == ArgViewType.Script)
     {
         SetScriptView(iScript, (IStackableBlockView) v);
     }
     else
     {
         throw new InvalidOperationException("Error in view search algorithm in CBlockView.SetArgView(...)");
     }
 }
 public void SetArgView(int i, IBlockView v)
 {
     content.SetArgView(i, v);
 }
 internal void AddArgView(IBlockView v, DataType type)
 {
     content.AddSubView(v, type);
 }
 private void ShowEraseButton(IBlockView hit)
 {
     eraseButton.Location = new Point(hit.AbsolutePos().X, 2);
     eraseButton.Show();
 }
Beispiel #47
0
 public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination)
     : this(DropType, Rectangle, destination, null)
 {
 }