Inheritance: Element, Draggable
Example #1
0
    // public void IsValidRecipe(DraggableElement e1, ref DraggableElement e2)
    // {
    //  // return ocean
    //  if(e1.elementID==3&&e2.elementID==3)
    //  {
    //      e2.element = elDic.allElements[35];
    //      e2.elementID = elDic.allElements[35].elementID;
    //      e2.nameText.text = elDic.allElements[35].elementName;

    //  }
    //  // return heat
    //  else if(e1.elementID==2&&e2.elementID==2)
    //  {
    //      e2.element = elDic.allElements[34];
    //      e2.elementID = elDic.allElements[34].elementID;
    //      e2.nameText.text = elDic.allElements[34].elementName;

    //  }
    //  // return cloud
    //  else if((e1.elementID==0&&e2.elementID==3)||(e2.elementID==3&&e2.elementID==0))
    //  {
    //      e2.element = elDic.allElements[38];
    //      e2.elementID = elDic.allElements[38].elementID;
    //      e2.nameText.text = elDic.allElements[38].elementName;
    //  }
    // }

    public int IsValidRecipe(DraggableElement e1, DraggableElement e2)
    {
        Pair p = new Pair(e1.elementID, e2.elementID);

        if (m_rContainer.RecipeDictionary.ContainsKey(p))
        {
            return(34);
        }
        return(32);
    }
    public void OnPointerDown(PointerEventData eventData)
    {
        Debug.Log("OnPointerDown called.");
        objectInstance         = DraggableElement.InstantiateFromPrefab(prefab);
        draggableElementScript = objectInstance.GetComponent <DraggableElement>();

        eventData.pointerDrag = objectInstance;
        ExecuteEvents.Execute(objectInstance, eventData, ExecuteEvents.initializePotentialDrag);
        ExecuteEvents.Execute(objectInstance, eventData, ExecuteEvents.pointerDownHandler);
    }
Example #3
0
        private void InitializeDraggingOperation()
        {
            // hook to mouse events to execute the drag operation
            var isDragging = false;
            var offset     = new Point(0, 0);
            var initialPos = new Point(0, 0);

            DraggableElement.MouseDown += (sender, args) =>
            {
                if (DraggableElement.IsMouseCaptureWithin == false)
                {
                    DraggableElement.CaptureMouse();
                    offset     = args.GetPosition(DraggableElement);
                    initialPos = args.GetPosition(null);
                    isDragging = true;
                }
            };

            DraggableElement.MouseMove += (sender, args) =>
            {
                if (isDragging && DraggableElement.IsMouseCaptured)
                {
                    var currentPos = args.GetPosition(null);
                    if (Math.Abs(currentPos.X - initialPos.X) >= SystemParameters.MinimumHorizontalDragDistance ||
                        Math.Abs(currentPos.Y - initialPos.Y) >= SystemParameters.MinimumVerticalDragDistance)
                    {
                        var newPos = args.GetPosition(ParentPanel);
                        var left   = newPos.X - offset.X;
                        var top    = newPos.Y - offset.Y;

                        double computedLeft;
                        double computeTop;

                        ComputePosition(left, top, out computedLeft, out computeTop);

                        Canvas.SetTop(DraggableElement, computeTop);
                        Canvas.SetLeft(DraggableElement, computedLeft);
                    }
                }
            };

            DraggableElement.MouseUp += (sender, args) =>
            {
                isDragging = false;

                if (DraggableElement.IsMouseCaptured)
                {
                    DraggableElement.ReleaseMouseCapture();
                }
            };
        }
Example #4
0
 public CaptainBundle(Screen screen, Renderer renderer, PuppetBundle bundle, BattlePuppetSquad squad)
 {
     puppetBundle  = bundle;
     captainButton = new DraggableElement(screen, renderer, bundle.puppet.ImageBox);
     captainButton.DragOrigin.setVisibility(false);
     captainButton.DragIcon.Texture = TextureName.BasicButtonHover;
     captainButton.OriginIcon.setVisibility(false);
     captainButton.setOnDragRelease(() => {
         foreach (BattlePuppet puppet in squad.puppets)
         {
             puppet.overrideTarget(screen.mousePosition);
         }
         return(true);
     });
 }
    public static GameObject InstantiateFromPrefab(GameObject prefab)
    {
        Vector3    initialInstancePosition = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0f);
        GameObject elementInstance         = Instantiate(prefab, initialInstancePosition, Quaternion.identity);

        elementInstance.layer = 8;

        foreach (GamePlayElement gamePlayElement in FindObjectsOfType <GamePlayElement>())
        {
            Destroy(gamePlayElement);
        }

        DraggableElement draggableElement = elementInstance.AddComponent <DraggableElement>();

        draggableElement.linkedPrefab = prefab;

        return(elementInstance);
    }
    public int IsValidRecipe(DraggableElement e1, DraggableElement e2)
    {
        Pair p   = new Pair(e1.elementID, e2.elementID);
        int  key = -99;

        foreach (Pair v in m_rContainer.RecipeDictionary.Keys)
        {
            if ((v.first == p.first && v.second == p.second) || (v.first == p.second && v.second == p.first))
            {
                key = m_rContainer.RecipeDictionary[v];
                break;
            }
        }
        //Debug.Log(key);

        // if(m_rContainer.RecipeDictionary.ContainsKey(new Pair(e1.elementID,e2.elementID)))
        // {
        //  return 36;
        // }
        return(key);
    }
 /// <summary>
 /// Informs whether the given <see cref="Element"/> is the <see cref="DraggableElement"/> bound the this <see cref="MenuButton"/>.
 /// </summary>
 /// <param name="draggableElement">The Element to test.</param>
 /// <returns>true = it is the right element || false = it is not the right element</returns>
 protected override bool IsRightMovementAction(DraggableElement draggableElement)
 {
     if (draggableElement.gameObject.name.Contains("LeftArrow"))
         return true;
     return false;
 }
Example #8
0
 public static void DisposeDragListener(this IDragListener Listener)
 {
     DraggableElement.DisposeDragListener(Listener);
 }
Example #9
0
 public static void RegisterDragListener(this IDragListener Listener)
 {
     DraggableElement.RegisterDragListener(Listener);
 }
 /// <summary>
 /// Informs whether the given <see cref="Element"/> is the <see cref="DraggableElement"/> bound the this MenuButton.
 /// </summary>
 /// <param name="draggableElement">The Element to test.</param>
 /// <returns>true = it is the right element || false = it is not the right element</returns>
 protected abstract bool IsRightMovementAction(DraggableElement draggableElement);