public void Draggable_OnMousePressed(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            if (dragArea.Equals(DragAreaDefines.BattleInventory))
            {
                ReturnToBackpack(true, true);
                return;
            }

            if (dragArea.Equals(Inventory.DragArea))
            {
                if (Mecha && Mecha.MechaInfo.MechaCamp == MechaCamp.Player)
                {
                    if (Inventory.RotateItemKeyDownHandler != null && Inventory.RotateItemKeyDownHandler.Invoke())
                    {
                        MechaComponentInfo.InventoryItem.Rotate();
                    }

                    if (diffFromStart.magnitude <= Draggable_DragMinDistance)
                    {
                        //不动
                    }
                    else
                    {
                        Vector3  currentLocalPos = dragStartLocalPos + transform.parent.InverseTransformVector(diffFromStart);
                        GridPosR gp_world        = GridPos.GetGridPosByPointXZ(currentLocalPos, Inventory.GridSize);
                        gp_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                        GridPosR gp_matrix = Inventory.CoordinateTransformationHandler_FromPosToMatrixIndex(gp_world);
                        MechaComponentInfo.InventoryItem.SetGridPosition(gp_matrix);
                    }
                }
            }
        }
예제 #2
0
 public void Draggable_OnMouseDown(DragArea dragArea, Collider collider)
 {
     dragStartLocalPos = RectTransform.anchoredPosition;
     dragStartOccupiedPositions_Matrix = InventoryItem.OccupiedGridPositions_Matrix.Clone();
     dragStartGridPos_Matrix           = InventoryItem.GridPos_Matrix;
     InventoryItem.Inventory.PickUpItem(InventoryItem);
 }
예제 #3
0
        void Window_OnPressed()
        {
            if (IsDragging || IsResizing)
            {
                return;
            }

            MouseState mouseState = Mouse.GetState();

            if (mouseState.LeftButton != ButtonState.Pressed)
            {
                return;
            }

            if (DragArea.Contains(mouseState.X, mouseState.Y))
            {
                IsDragging = true;
                DragStart  = new Point(-LocalBounds.X + mouseState.X, -LocalBounds.Y + mouseState.Y);
            }
            else if (ResizeArea.Contains(mouseState.X, mouseState.Y))
            {
                IsResizing          = true;
                ResizeStartSize     = new Point(LocalBounds.Width, LocalBounds.Height);
                ResizeStartPosition = new Point(mouseState.X, mouseState.Y);
            }
        }
예제 #4
0
        public void Draggable_OnMouseUp(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            Backpack.BackpackPanel.BackpackItemVirtualOccupationRoot.Clear();
            if (dragArea.Equals(Backpack.DragArea))
            {
                if (Backpack.CheckSpaceAvailable(dragStartOccupiedPositions_Matrix))
                {
                    Backpack.ResetGrids(dragStartOccupiedPositions_Matrix);
                }
                else
                {
                    // indicates that this is dragged in from outside, and conflict at the first position with another item.
                }

                if (!Backpack.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix))
                {
                    InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                }

                if (!Backpack.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix))
                {
                    if (Backpack.FindSpaceToPutItem(InventoryItem))
                    {
                    }
                    else
                    {
                        Debug.LogError("No space in bag but suc drag in");
                    }
                }

                Backpack.PutDownItem(InventoryItem);
                RefreshView();
            }
        }
예제 #5
0
        private void MouseDown(Vector2 p)
        {
            InputHelper inputHelper = game.inputManager.inputHelper;

            if (_fixedMouseJoint != null)
            {
                return;
            }

            savedFixture = game.farseerManager.world.TestPoint(p);

            if (savedFixture != null)
            {
                Body body = savedFixture.Body;
                if (!body.IsStatic)
                {
                    _fixedMouseJoint          = new FixedMouseJoint(body, p);
                    _fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    game.farseerManager.world.AddJoint(_fixedMouseJoint);
                    body.Awake = true;
                }
                else
                {
                    dragging = true;
                }
            }
            else // start a selection rectangle
            {
                dragStartWorld     = p;
                dragStartPixel     = inputHelper.MousePosition;
                selectingRectangle = true;
                dragArea           = new DragArea(dragStartPixel, dragStartPixel);
            }
        }
            public void OnDrag(View view, DragArea.DragEvent e)
            {
                switch (e.Action)
                {
                    case DragArea.DragEvent.ACTION_DRAG_STARTED:
                        mDraggableDot.SetBackgroundDrawable(mDraggableDot.mGreenDot);
                        break;
                    case DragArea.DragEvent.ACTION_DRAG_ENTERED:
                        mDraggableDot.SetBackgroundDrawable(mDraggableDot.mWhiteDot);
                        break;
                    case DragArea.DragEvent.ACTION_DRAG_EXITED:
                        mDraggableDot.SetBackgroundDrawable(mDraggableDot.mGreenDot);
                        break;
                    case DragArea.DragEvent.ACTION_DROP:
                        Bundle data = e.Data;
                        string dropText = data.GetCharSequence("number");

                        int a = int.Parse(dropText);
                        int b = int.Parse(mDraggableDot.Text);
                        mDraggableDot.SetBackgroundDrawable(mDraggableDot.mRedDot);
                        break;
                    case DragArea.DragEvent.ACTION_DRAG_ENDED:
                        mDraggableDot.SetBackgroundDrawable(mDraggableDot.mRedDot);
                        break;
                    default:
                        break;
                }
            }
예제 #7
0
        public override bool IsMouseOverRecursive()
        {
            MouseState mouseState = Mouse.GetState();
            Rectangle  expanded   = GlobalBounds;

            expanded.Inflate(32, 32);
            return(IsVisible && (expanded.Contains(mouseState.X, mouseState.Y) || DragArea.Contains(mouseState.X, mouseState.Y) || ResizeArea.Contains(mouseState.X, mouseState.Y) || base.IsMouseOverRecursive()));
        }
예제 #8
0
        protected override Fixture CreateFixture(DragArea d)
        {
            Fixture f = FixtureFactory.AttachRectangle(d.width, d.height, 1, Vector2.Zero, new Body(game.farseerManager.world));

            f.Body.Position = d.center;
            FarseerTextures.ApplyTexture(f, FarseerTextures.TextureType.Normal);
            return(f);
        }
예제 #9
0
        protected override Fixture CreateFixture(DragArea d)
        {
            Fixture f = FixtureFactory.AttachCircle(d.diagonal, 1, new Body(game.farseerManager.world));

            f.Body.Position = worldStart;
            FarseerTextures.ApplyTexture(f, FarseerTextures.TextureType.Normal);

            return(f);
        }
예제 #10
0
        public override void HandleInput()
        {
            InputHelper inputHelper = game.inputManager.inputHelper;

            if (selectingRectangle)
            {
                dragArea = new DragArea(dragStartPixel, inputHelper.MousePosition);
            }

            Mouse();
        }
예제 #11
0
    public bool IsWithin(Vector3 worldPos)
    {
        Vector3 screenPos     = Camera.main.WorldToScreenPoint(worldPos);
        Vector3 realScreenPos = new Vector3(screenPos.x, Screen.height - screenPos.y, screenPos.z);

        if (DragArea.Contains(realScreenPos))
        {
            return(true);
        }

        return(false);
    }
예제 #12
0
        private void MouseUp(Vector2 p)
        {
            InputHelper inputHelper = game.inputManager.inputHelper;

            prevWorldLoc = new Vector2();

            dragging = false;

            if (_fixedMouseJoint != null)
            {
                game.farseerManager.world.RemoveJoint(_fixedMouseJoint);
                _fixedMouseJoint = null;
            }

            if (selectingRectangle)
            {
                selectingRectangle = false;
                if (!ProjectionHelper.InsidePixelBounds(inputHelper.MousePosition))
                {
                    return;
                }
                DragArea      d        = new DragArea(dragStartWorld, p);
                List <Object> selected = new List <object>();
                foreach (Body b in game.farseerManager.world.BodyList)
                {
                    if (d.ContainsPixel(b.Position))
                    {
                        selected.Add(b);
                    }
                }

                foreach (Joint j in game.farseerManager.world.JointList)
                {
                    if (d.ContainsPixel(j.WorldAnchorA))
                    {
                        selected.Add(j);
                    }
                }

                if (selected.Count > 0)
                {
                    FormManager.Property.setPendingObjects(selected);
                    //if (!FormManager.Property.Visible)
                    //    FormManager.Property.Show();
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Create a new inventory
        /// </summary>
        /// <param name="inventoryName">The inventory name</param>
        /// <param name="dragArea"></param>
        /// <param name="gridSize">the gridSize of inventory</param>
        /// <param name="rows">how many rows in total</param>
        /// <param name="columns">how many columns in total</param>
        /// <param name="x_Mirror">is X axis mirrored</param>
        /// <param name="z_Mirror">is Z axis mirrored</param>
        /// <param name="unlockedPartialGrids">is there any grid locked at the beginning</param>
        /// <param name="unlockedGridCount">how many grids are locked at the beginning</param>
        /// <param name="rotateItemKeyDownHandler">this delegate should return a bool whether the rotate item key is pressed down</param>
        /// <param name="coordinateTransformationHandler_FromPosToMatrixIndex"></param>
        /// <param name="coordinateTransformationHandler_FromMatrixIndexToPos"></param>
        /// <param name="coordinateTransformationHandler_FromPosToMatrixIndex_Diff"></param>
        /// <param name="coordinateTransformationHandler_FromMatrixIndexToPos_Diff"></param>
        public Inventory(
            string inventoryName,
            DragArea dragArea,
            int gridSize,
            int rows,
            int columns,
            bool x_Mirror,
            bool z_Mirror,
            bool unlockedPartialGrids,
            int unlockedGridCount,
            KeyDownDelegate rotateItemKeyDownHandler,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromPosToMatrixIndex,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromMatrixIndexToPos,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromPosToMatrixIndex_Diff,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromMatrixIndexToPos_Diff
            )
        {
            InventoryName          = inventoryName;
            DragArea               = dragArea;
            GridSize               = gridSize;
            Rows                   = rows;
            Columns                = columns;
            X_Mirror               = x_Mirror;
            Z_Mirror               = z_Mirror;
            UnlockedPartialGrids   = unlockedPartialGrids;
            this.unlockedGridCount = unlockedGridCount;

            RotateItemKeyDownHandler = rotateItemKeyDownHandler;
            CoordinateTransformationHandler_FromPosToMatrixIndex      = coordinateTransformationHandler_FromPosToMatrixIndex;
            CoordinateTransformationHandler_FromMatrixIndexToPos      = coordinateTransformationHandler_FromMatrixIndexToPos;
            CoordinateTransformationHandler_FromPosToMatrixIndex_Diff = coordinateTransformationHandler_FromPosToMatrixIndex_Diff;
            CoordinateTransformationHandler_FromMatrixIndexToPos_Diff = coordinateTransformationHandler_FromMatrixIndexToPos_Diff;

            InventoryGridMatrix = new InventoryGrid[Columns, Rows];
            for (int row = 0; row < Rows; row++)
            {
                for (int col = 0; col < Columns; col++)
                {
                    InventoryGrid ig = new InventoryGrid();
                    ig.State = InventoryGrid.States.Unavailable;
                    InventoryGridMatrix[col, row] = ig;
                }
            }

            InventoryItemMatrix = new InventoryItem[Columns, Rows];
        }
 public MechaEditorInventory(
     string inventoryName,
     DragArea dragArea,
     int gridSize,
     int rows,
     int columns,
     bool x_Mirror,
     bool z_Mirror,
     bool unlockedPartialGrids,
     int unlockedGridCount,
     KeyDownDelegate rotateItemKeyDownHandler
     ) : base(inventoryName, dragArea, gridSize, rows, columns, x_Mirror, z_Mirror, unlockedPartialGrids, unlockedGridCount, rotateItemKeyDownHandler,
              (gridPos) => new GridPosR(gridPos.x + ConfigManager.EDIT_AREA_HALF_SIZE, gridPos.z + ConfigManager.EDIT_AREA_HALF_SIZE, gridPos.orientation),
              (gp_matrix) => new GridPosR(gp_matrix.x - ConfigManager.EDIT_AREA_HALF_SIZE, gp_matrix.z - ConfigManager.EDIT_AREA_HALF_SIZE, gp_matrix.orientation),
              (gridPos) => new GridPos(gridPos.x, gridPos.z),
              (gp_matrix) => new GridPos(gp_matrix.x, gp_matrix.z)
              )
 {
 }
예제 #15
0
 /// <summary>
 /// Initialize the backpack manager.
 /// </summary>
 /// <param name="inventoryName">the name of the backpack</param>
 /// <param name="gridSize">the size (in pixel) of each grid of backpack items in UI panels.</param>
 /// <param name="toggleBackpackKeyDownHandler">This handler should return a signal which toggles the backpack(e.g. return Input.GetKeyDown(KeyCode.B);)</param>
 /// <param name="rotateItemKeyDownHandler">This handler should return a signal which rotates the backpack item(e.g. return Input.GetKeyDown(KeyCode.R);)</param>
 /// <param name="instantiateBackpackGridHandler">This handler should instantiate a prefab with BackpackGrid component.</param>
 /// <param name="instantiateBackpackItemHandler">This handler should instantiate a prefab with BackpackItem component.</param>
 /// <param name="instantiateBackpackItemGridHandler">This handler should instantiate a prefab with BackpackItemGrid component.</param>
 /// <param name="instantiateBackpackItemVirtualOccupationQuadHandler">This handler should instantiate a image for indicating the occupation.</param>
 public Backpack(
     string inventoryName, DragArea dragArea, int gridSize, int rows, int columns, bool x_Mirror, bool z_Mirror, bool unlockPartialGrids, int unlockedGridCount,
     KeyDownDelegate toggleBackpackKeyDownHandler,
     KeyDownDelegate rotateItemKeyDownHandler,
     InstantiatePrefabDelegate instantiateBackpackGridHandler,
     InstantiatePrefabDelegate instantiateBackpackItemHandler,
     InstantiatePrefabDelegate instantiateBackpackItemGridHandler,
     InstantiatePrefabDelegate instantiateBackpackItemVirtualOccupationQuadHandler
     ) : base(inventoryName, dragArea, gridSize, rows, columns, x_Mirror, z_Mirror, unlockPartialGrids, unlockedGridCount, rotateItemKeyDownHandler,
              (gridPos) => new GridPosR(gridPos.x, -gridPos.z),
              (gridPos_matrix) => new GridPosR(gridPos_matrix.x, -gridPos_matrix.z),
              (gridPos) => new GridPosR(gridPos.x, -gridPos.z),
              (gridPos_matrix) => new GridPosR(gridPos_matrix.x, -gridPos_matrix.z))
 {
     ToggleBackpackKeyDownHandler       = toggleBackpackKeyDownHandler;
     InstantiateBackpackGridHandler     = instantiateBackpackGridHandler;
     InstantiateBackpackItemHandler     = instantiateBackpackItemHandler;
     InstantiateBackpackItemGridHandler = instantiateBackpackItemGridHandler;
     InstantiateBackpackItemVirtualOccupationQuadHandler = instantiateBackpackItemVirtualOccupationQuadHandler;
 }
예제 #16
0
    public DragAreaTypes CheckMoveToArea()
    {
        if (DragManager.Instance.IsMouseInsideBag)
        {
            return(DragAreaTypes.Bag);
        }
        Ray ray = GameManager.Instance.MainCamera.ScreenPointToRay(Input.mousePosition);

        Physics.Raycast(ray, out RaycastHit raycast, 1000f, GameManager.Instance.LayerMask_DragAreas);
        if (raycast.collider)
        {
            DragArea da = raycast.collider.gameObject.GetComponentInParent <DragArea>();
            if (da)
            {
                return(da.DragAreaTypes);
            }
        }

        return(DragAreaTypes.None);
    }
예제 #17
0
        public void Draggable_OnMousePressed(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            if (dragArea.Equals(Backpack.DragArea))
            {
                if (Backpack.RotateItemKeyDownHandler != null && Backpack.RotateItemKeyDownHandler.Invoke())
                {
                    Rotate();
                }

                if (diffFromStart.magnitude <= Draggable_DragMinDistance)
                {
                    // stay
                }
                else
                {
                    Vector2  diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                    Vector2  currentLocalPos = dragStartLocalPos + diffLocal;
                    GridPosR diff_world      = GridPos.GetGridPosByPointXY(diffLocal, Backpack.GridSize);
                    diff_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                    GridPosR diff_matrix = Backpack.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world);
                    GridPosR gp_matrix   = dragStartGridPos_Matrix + diff_matrix;
                    gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation;
                    InventoryItem.SetGridPosition(gp_matrix);
                    RectTransform.anchoredPosition = currentLocalPos;
                }
            }
            else
            {
                if (Backpack.DragItemOutBackpackCallback != null)
                {
                    Backpack.BackpackPanel.BackpackItemVirtualOccupationRoot.Clear();
                    if (Backpack.DragItemOutBackpackCallback.Invoke(this))
                    {
                        InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                        Backpack.RemoveItem(InventoryItem, true);
                        PoolRecycle();
                    }
                }
            }
        }
예제 #18
0
        public override void HandleInput()
        {
            InputHelper input = game.inputManager.inputHelper;
            Vector2     pixel = input.MousePosition;

            worldLoc = ProjectionHelper.PixelToFarseer(pixel);

            if (input.IsNewButtonPress(MouseButtons.LeftButton) && !drawing)
            {
                drawing    = true;
                worldStart = worldLoc;
                //pixelStart = pixel;
                //d = new DragArea(worldStart, worldStart);
            }
            else if (input.IsOldButtonPress(MouseButtons.LeftButton) && drawing)
            {
                drawing = false;
                DragArea d = new DragArea(worldStart, worldLoc);
                if (d.width > 0 && d.height > 0)
                {
                    Fixture f = CreateFixture(d);

                    FormManager.Property.setPendingObjects(new List <object>()
                    {
                        f.Body
                    });
                    //FormManager.Property.setSelectedObject(f.Body);

                    f.Restitution = .3f;

                    if (input.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
                    {
                        f.Body.BodyType = BodyType.Dynamic;
                        FarseerTextures.ApplyTexture(f, FarseerTextures.TextureType.Normal);
                    }
                }
            }
        }
예제 #19
0
        public void Draggable_OnMouseUp(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            if (IsRecycled)
            {
                return;
            }
            if (dragArea.Equals(DragAreaDefines.BattleInventory))
            {
                if (!isReturningToBackpack)
                {
                    bool suc = ReturnToBackpack(false, false);
                    if (!suc)
                    {
                        //DragManager.Instance.CurrentDrag.ResetToOriginalPositionRotation();
                    }
                }

                return;
            }

            if (dragArea.Equals(DragAreaDefines.MechaEditorArea))
            {
                return;
            }

            if (dragArea.Equals(BiangStudio.DragHover.DragAreaDefines.None))
            {
                bool suc = ReturnToBackpack(false, false);
                if (!suc)
                {
                    //DragManager.Instance.CurrentDrag.ResetToOriginalPositionRotation();
                }

                return;
            }
        }
예제 #20
0
 void Start()
 {
     dragArea = transform.parent.GetComponent <DragArea>();
 }
예제 #21
0
 public void Draggable_SetStates(ref bool canDrag, ref DragArea dragFrom)
 {
     canDrag  = true;
     dragFrom = Backpack.DragArea;
 }
예제 #22
0
 void Init(DragArea area)
 {
     dragArea = area;
     dragArea.OnPinchChanged.AddListener(x => UpdateView());
     dragArea.OnSwipeChanged.AddListener(x => UpdateView());
 }
예제 #23
0
 public void Draggable_SetStates(ref bool canDrag, ref DragArea dragFrom)
 {
     canDrag  = true;
     dragFrom = DragAreaDefines.MechaEditorArea;
 }
예제 #24
0
 public void Draggable_OnMouseDown(DragArea dragArea, Collider collider)
 {
     dragStartLocalPos = transform.localPosition;
 }
 public void Init(Backpack backpack)
 {
     Backpack      = backpack;
     DragArea      = new DragArea(backpack.DragArea.DragAreaName);
     DragProcessor = DragManager.Instance.GetDragProcessor <BackpackItem>();
 }
예제 #26
0
 protected abstract Fixture CreateFixture(DragArea d);