public override bool AddVariable(LooseDragDropLink link)
        {
            if (link.GetElement() is NumberTextbox)
            {
                this.varLink = link;

                return true;
            }

            if(link.GetElement() is SingleReturnMethodElement && ((SingleReturnMethodElement)link.GetElement()).GetReturnType() == "Number")
            {
                this.varLink = link;
                return true;
            }

            return false;
        }
        public override bool AddVariable(LooseDragDropLink link)
        {
            if (varLink != null) return false;

            if(link.GetElement() is BooleanDragDrop)
            {
                this.varLink = link;

                return true;
            }

            if(link.GetElement() is SingleReturnMethodElement)
            {
                if (((SingleReturnMethodElement)link.GetElement()).GetReturnType().Equals("Boolean"))
                {
                    this.varLink = link;
                    return true;
                }
            }

            return false;
        }
 public override void SetLooseLink(LooseDragDropLink link)
 {
     this.link = link;
 }
 public abstract void SetLooseLink(LooseDragDropLink link);
 public override void SetLooseLink(LooseDragDropLink link)
 {
     return;
 }
 public abstract Boolean AddVariable(LooseDragDropLink link);
 internal LooseDragDropLink PopVariable()
 {
     LooseDragDropLink temp = varLink;
     varLink = null;
     return temp;
 }
        private void UpdateSuggestions(InputHandler handler)
        {
            if (draggedElement != null) return;

            if(handler.CheckLeftMouseJustPressed())
            foreach(LooseDragDropLink link in suggestions)
            {
                if(handler.CheckMouseIn(link))
                {
                    suggestedElement = link;
                    break;
                }
            }

            if (handler.CheckLeftMouseJustReleased())
            {
                suggestedElement = null;
            }

            if(suggestedElement != null)
            if (!(handler.LeftMouseDraggedBy().X == 0 && handler.LeftMouseDraggedBy().Y == 0))
            {
                elements.Add(new LooseDragDropLink(suggestedElement.GetElement().Clone()));
                draggedElement = elements[elements.Count - 1];
                Point XY = handler.GetMouseXY();
                originalPoint = XY;
                elements[elements.Count - 1].SetPoint(ref XY);
            }
        }
        private void UpdateInteraction(InputHandler handler)
        {
            #region Check if released element is in the same area as another element
            foreach (LooseDragDropLink element in elements)
            {

                if (element == draggedElement) continue;

                if (handler.CheckMouseIn(element))
                {
                    #region If the Current Element Dropped in is a Variable Placeholder
                    if (element.GetElement() is DragDropVariablePlaceholder)
                    {
                        bool rep = ((DragDropVariablePlaceholder)element.GetElement()).AddVariable(draggedElement);
                        if (rep)
                        {
                            elements.Remove(draggedElement);
                            draggedElement = null;
                        }

                    }
                    #endregion
                    else
                    #region If the Current Element being Interacted with is a Variable Placeholder
                    if (element.GetElement().GetInteracting(handler) is DragDropVariablePlaceholder)
                    {
                        bool rep = ((DragDropVariablePlaceholder)element.GetElement().GetInteracting(handler)).AddVariable(draggedElement);
                        if (rep)
                        {
                            elements.Remove(draggedElement);
                            draggedElement = null;
                        }
                    }
                    #endregion
                    break;
                }
            }
            #endregion
        }
        private void UpdateElements(InputHandler handler)
        {
            if (draggedElement == null)
            {
                #region If Mouse Pressed
                if (handler.CheckLeftMouseJustPressed())
                {
                    #region Check if an Element was Clicked
                    for (int i = 0;i < elements.Count; i++)
                    {
                        var element = elements[elements.Count - i - 1];
                        if (handler.CheckMouseIn(element))
                        {
                            #region Set as Dragged Object
                            draggedElement = element;
                            originalPoint = element.GetPoint();
                            elements.Remove(element);
                            elements.Add(element);
                            #endregion
                            break;
                        }
                    }
                    #endregion

                }
                #endregion
            }
            else
            {
                if (dragging)
                {

                    if (handler.CheckLeftMouseJustReleased())
                    {
                        //Just in case stuff needs to be done.
                        #region Release Dragged Object
                        UpdateInteraction(handler);
                        if (draggedElement != null && draggedElement.GetX() < widthOfMenu)
                        {
                            RemoveElement(draggedElement);
                        }
                        draggedElement = null;
                        dragging = false;

                        #endregion
                    }
                    else
                    {
                        #region Set the X and Y of the Dragged Object
                        draggedElement.SetX(originalPoint.X + handler.LeftMouseDraggedBy().X);
                        draggedElement.SetY(originalPoint.Y + handler.LeftMouseDraggedBy().Y);
                        #endregion
                    }
                }
                else
                {
                    #region Detect if Dragged Piece was actually moved.
                    if (!(handler.LeftMouseDraggedBy().X == 0 && handler.LeftMouseDraggedBy().Y == 0))
                    {
                        dragging = true;
                        #region Removes the element from a slot.
                        if (draggedElement.GetElement() is DragDropVariablePlaceholder)
                        {
                            if (((DragDropVariablePlaceholder)draggedElement.GetElement()).HasVariable())
                            {
                                elements.Add(((DragDropVariablePlaceholder)draggedElement.GetElement()).PopVariable());
                                draggedElement = elements[elements.Count - 1];
                                originalPoint = handler.GetMouseXY();
                            }
                        }
                        #endregion
                        else
                        #region Removes the element from a slot that is contained in another piece
                        if (draggedElement.GetElement().GetTopInteracting(handler) is DragDropVariablePlaceholder)
                        {
                            DragDropVariablePlaceholder slot = (DragDropVariablePlaceholder)((DragDropVariablePlaceholder)draggedElement.GetElement().GetTopInteracting(handler)).GetInnerMostDragDrop(handler);

                            if ((slot).HasVariable())
                            {
                                elements.Add((slot).PopVariable());
                                draggedElement = elements[elements.Count - 1];

                                originalPoint = handler.GetMouseXY();
                            }
                        }
                        #endregion
                    }
                    #endregion
                    else
                    #region If the piece is released, select it.
                        if (handler.CheckLeftMouseJustReleased())
                        {
                            if (selectedElement != null && selectedElement != draggedElement) selectedElement.GetElement().TellSelected(false);
                            draggedElement.GetElement().GetInteracting(handler).TellSelected(true);
                            selectedElement = draggedElement;
                            draggedElement = null;
                        }
                    #endregion
                }

            }
        }
 /// <summary>
 /// Removes the link from the interface
 /// </summary>
 /// <param name="link"></param>
 public void RemoveElement(LooseDragDropLink link)
 {
     elements.Remove(link);
 }
Ejemplo n.º 12
0
 public override void SetLooseLink(LooseDragDropLink link)
 {
     Logger.WriteLine("Someone set a loose link to a toggle button. I hope that was for debugging purposes");
 }