Example #1
0
    public BuildingCoverMaskGroup[,] BuildingCoverMaskMatrix_IncludingPreview; // column, row

    public CityInventory(
        string inventoryName,
        DragAreaIndicator dragAreaIndicator,
        DragProcessor dragProcessor,
        int gridSize,
        int rows,
        int columns,
        bool x_Mirror,
        bool z_Mirror,
        bool unlockedPartialGrids,
        int unlockedGridCount,
        bool dragOutDrop,
        KeyDownDelegate rotateItemKeyDownHandler,
        InstantiatePrefabDelegate instantiateCityInventoryGridHandler,
        InstantiatePrefabDelegate instantiateCityInventoryVirtualOccupationQuadHandler
        ) : base(inventoryName, dragAreaIndicator, gridSize, rows, columns, x_Mirror, z_Mirror, unlockedPartialGrids, unlockedGridCount, dragOutDrop,
                 rotateItemKeyDownHandler,
                 (gridPos) => new GridPosR(gridPos.x + columns / 2, gridPos.z + rows / 2, gridPos.orientation),
                 (gp_matrix) => new GridPosR(gp_matrix.x - columns / 2, gp_matrix.z - rows / 2, gp_matrix.orientation),
                 (gridPos) => new GridPos(gridPos.x, gridPos.z),
                 (gp_matrix) => new GridPos(gp_matrix.x, gp_matrix.z)
                 )
    {
        DragProcessor = dragProcessor;
        InstantiateCityInventoryGridHandler = instantiateCityInventoryGridHandler;
        InstantiateCityInventoryVirtualOccupationQuadHandler = instantiateCityInventoryVirtualOccupationQuadHandler;
        InventoryValidMatrix    = new bool[columns, rows];
        BuildingCoverMaskMatrix = new BuildingCoverMaskGroup[columns, rows];
        BuildingCoverMaskMatrix_IncludingPreview = new BuildingCoverMaskGroup[columns, rows];
    }
 public void Draggable_OnMouseDown(DragAreaIndicator dragAreaIndicator, Collider collider)
 {
     dragStartLocalPos = RectTransform.anchoredPosition;
     dragStartOccupiedPositions_Matrix = InventoryItem.OccupiedGridPositions_Matrix.Clone();
     dragStartGridPos_Matrix           = InventoryItem.GridPos_Matrix;
     InventoryItem.Inventory.PickUpItem(InventoryItem);
 }
Example #3
0
 /// <summary>
 /// Initialize the uiInventory manager.
 /// </summary>
 /// <param name="inventoryName">The inventory name</param>
 /// <param name="dragAreaIndicator"></param>
 /// <param name="dragProcessor"></param>
 /// <param name="canvasDistance">the distance of canvas</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="dragOutDrop">allows item to be dragged and dropped outside inventory</param>
 /// <param name="enableScreenClamp">enable inventory UI panel's screen-clamping</param>
 /// <param name="enableLog">enable inventory log</param>
 /// <param name="toggleUIInventoryKeyDownHandler">This handler should return a signal which toggles the uiInventory(e.g. return Input.GetKeyDown(KeyCode.B);)</param>
 /// <param name="rotateItemKeyDownHandler">This handler should return a signal which rotates the uiInventory item(e.g. return Input.GetKeyDown(KeyCode.R);)</param>
 /// <param name="instantiateUIInventoryGridHandler">This handler should instantiate a prefab with UIInventoryGrid component.</param>
 /// <param name="instantiateUIInventoryItemHandler">This handler should instantiate a prefab with UIInventoryItem component.</param>
 /// <param name="instantiateUIInventoryItemGridHandler">This handler should instantiate a prefab with UIInventoryItemGrid component.</param>
 /// <param name="instantiateUIInventoryItemVirtualOccupationQuadHandler">This handler should instantiate a image for indicating the occupation.</param>
 public UIInventory(
     string inventoryName,
     DragAreaIndicator dragAreaIndicator,
     DragProcessor dragProcessor,
     float canvasDistance,
     int gridSize, int rows, int columns, bool x_Mirror, bool z_Mirror,
     bool unlockedPartialGrids, int unlockedGridCount, bool dragOutDrop, bool enableScreenClamp, bool enableLog,
     KeyDownDelegate toggleUIInventoryKeyDownHandler,
     KeyDownDelegate rotateItemKeyDownHandler,
     InstantiatePrefabDelegate instantiateUIInventoryGridHandler,
     InstantiatePrefabDelegate instantiateUIInventoryItemHandler,
     InstantiatePrefabDelegate instantiateUIInventoryItemGridHandler,
     InstantiatePrefabDelegate instantiateUIInventoryItemVirtualOccupationQuadHandler
     ) : base(inventoryName, dragAreaIndicator, gridSize, rows, columns, x_Mirror, z_Mirror, unlockedPartialGrids, unlockedGridCount, dragOutDrop, enableLog, 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))
 {
     DragProcessor  = dragProcessor;
     CanvasDistance = canvasDistance;
     ToggleUIInventoryKeyDownHandler       = toggleUIInventoryKeyDownHandler;
     InstantiateUIInventoryGridHandler     = instantiateUIInventoryGridHandler;
     InstantiateUIInventoryItemHandler     = instantiateUIInventoryItemHandler;
     InstantiateUIInventoryItemGridHandler = instantiateUIInventoryItemGridHandler;
     InstantiateUIInventoryItemVirtualOccupationQuadHandler = instantiateUIInventoryItemVirtualOccupationQuadHandler;
     EnableScreenClamp = enableScreenClamp;
 }
Example #4
0
        /// <summary>
        /// Create a new inventory
        /// </summary>
        /// <param name="inventoryName">The inventory name</param>
        /// <param name="dragAreaIndicator"></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="dragOutDrop">allows item to be dragged and dropped outside inventory</param>
        /// <param name="enableLog">enable inventory log</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>
        protected Inventory(
            string inventoryName,
            DragAreaIndicator dragAreaIndicator,
            int gridSize,
            int rows,
            int columns,
            bool x_Mirror,
            bool z_Mirror,
            bool unlockedPartialGrids,
            int unlockedGridCount,
            bool dragOutDrop,
            bool enableLog,
            KeyDownDelegate rotateItemKeyDownHandler,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromPosToMatrixIndex,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromMatrixIndexToPos,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromPosToMatrixIndex_Diff,
            CoordinateTransformationDelegate coordinateTransformationHandler_FromMatrixIndexToPos_Diff
            )
        {
            InventoryName     = inventoryName;
            DragAreaIndicator = dragAreaIndicator;
            GridSize          = gridSize;
            Rows                   = rows;
            Columns                = columns;
            X_Mirror               = x_Mirror;
            Z_Mirror               = z_Mirror;
            UnlockedPartialGrids   = unlockedPartialGrids;
            this.unlockedGridCount = unlockedGridCount;
            DragOutDrop            = dragOutDrop;
            EnableLog              = enableLog;

            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];
        }
Example #5
0
 public void Draggable_SetStates(ref bool canDrag, ref DragAreaIndicator dragFromDragAreaIndicator)
 {
 }
Example #6
0
 public void Draggable_OnMouseUp(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
 {
 }
Example #7
0
 public void Draggable_OnMouseDown(DragAreaIndicator dragAreaIndicator, Collider collider)
 {
 }
 public void Draggable_SetStates(ref bool canDrag, ref DragAreaIndicator dragFromDragAreaIndicator)
 {
     canDrag = true;
     dragFromDragAreaIndicator = UIInventory.DragAreaIndicator;
 }
        public void Draggable_OnMouseUp(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            void ReturnItemToOriginalPlace()
            {
                UIInventory.ClearTempUnavailableGridState();
                InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                UIInventory.PutDownItem(InventoryItem);
                RefreshView();
            }

            if (dragAreaIndicator == UIInventory.DragAreaIndicator)
            {
                bool validPutDown = true;
                UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear();
                if (UIInventory.CheckSpaceAvailable(dragStartOccupiedPositions_Matrix))
                {
                    UIInventory.ResetGrids(dragStartOccupiedPositions_Matrix);
                }
                else
                {
                    // indicates that this is dragged in from outside, and conflict at the first position with another item.
                }

                // if the dropping grids are not available, then try the original drag position
                if (!UIInventory.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix))
                {
                    InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                }

                // if the original drag position is not available, then search a position for this item
                if (!UIInventory.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix))
                {
                    if (!UIInventory.FindSpaceToPutItem(InventoryItem, false)) // if this function returns true, it will also change the item's position/rotation
                    {
                        // but if failed, interrupt this move
                        UIInventory.RemoveItem(InventoryItem, true);
                        Destroy(gameObject);
                        DragManager.Instance.ResumePausedDrag();
                        DragManager.Instance.CurrentDrag = null;
                        validPutDown = false;
                    }
                }

                if (validPutDown)
                {
                    UIInventory.PutDownItem(InventoryItem);
                    RefreshView();
                    DragManager.Instance.SucceedPausedDrag();
                }
            }
            else if (dragAreaIndicator != null) // drag to other DragAreas
            {
                // this will always occur when other dragArea doesn't have enough space for this item
                ReturnItemToOriginalPlace();
            }
            else // drag to non-DragArea
            {
                if (DragManager.Instance.PausedDrag == null)
                {
                    if (UIInventory.DragOutDrop)
                    {
                        InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                        UIInventory.DragItemOutUIInventoryCallback = () =>
                        {
                            UIInventory.RemoveItem(InventoryItem, true);
                            Destroy(gameObject);
                        };

                        UIInventory.DragItemOutUIInventoryCallback?.Invoke();
                        UIInventory.DragItemOutUIInventoryCallback = null;

                        // todo confirm panel
                    }
                    else
                    {
                        ReturnItemToOriginalPlace();
                    }
                }
            }
        }
Example #10
0
        public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            void ResumePausedDrag()
            {
                InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                UIInventory.RemoveItem(InventoryItem, true);
                Destroy(gameObject);
                DragManager.Instance.ResumePausedDrag();
            }

            if (dragAreaIndicator == UIInventory.DragAreaIndicator)
            {
                if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke())
                {
                    Rotate();
                }

                if (diffFromStart.magnitude > Draggable_DragMinDistance)
                {
                    Vector2  diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                    Vector2  currentLocalPos = dragStartLocalPos + diffLocal;
                    GridPosR diff_world      = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize);
                    diff_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                    GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world);
                    GridPosR gp_matrix   = dragStartGridPos_Matrix + diff_matrix;
                    gp_matrix.orientation        = InventoryItem.GridPos_Matrix.orientation;
                    InventoryItem.GridPos_Matrix = gp_matrix;
                    SetVirtualGridPos(InventoryItem.GridPos_World);
                    RectTransform.anchoredPosition = currentLocalPos;
                }
            }
            else
            {
                Vector2 diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                Vector2 currentLocalPos = dragStartLocalPos + diffLocal;
                RectTransform.anchoredPosition = currentLocalPos;
                UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear();
                if (dragAreaIndicator != null) // drag to other DragAreas
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                    else
                    {
                        // only when mouse move to available grid then generate previewItem
                        if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI)
                        {
                            uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix);
                            GridPosR gpr = gp_matrix;
                            gpr.orientation = InventoryItem.GridPos_Matrix.orientation;
                            InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr);
                            uiDAI.UIInventory.AddPreviewItem(previewItem);
                            UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID);
                            DragManager.Instance.PauseDrag();
                            DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable;
                            uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor);
                        }
                    }
                }
                else // drag to non-DragArea
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                }
            }
        }