コード例 #1
0
        /// <summary>
        /// Calculates the position of the square grid that the pointer (mouse or finger) is over, displays a fruiton on that position with lower opacity.
        /// </summary>
        /// <param name="pointerPosition">position of the pointer</param>
        /// <param name="fruiton">fruiton to display on the square</param>
        /// <param name="swapPosition">true if given fruiton is being swapped in the team</param>
        /// <returns>position of the square grid that pointer is over, null if pointer isn't ovet the grid</returns>
        public Position SuggestFruitonAtMousePosition(Vector3 pointerPosition, Fruiton fruiton,
                                                      Position swapPosition = null)
        {
            // pointer position is in non-scaled world coordinates
            // we need to calculate square size in world coordinates
            Vector3[] corners = new Vector3[4];
            gridSquares[0, 0].RectTransform.GetWorldCorners(corners);
            var scaledSquareSize = corners[2].x;

            var x = (int)(pointerPosition.x / scaledSquareSize);
            var y = 4 - (int)(pointerPosition.y / scaledSquareSize);

            ClearSuggestions();

            if (x >= 0 && x < 2 && y >= 0 && y < 5 &&
                (gridSquares[x, y].IsEmpty || swapPosition != null) &&
                gridSquares[x, y].FruitonType == fruiton.type)
            {
                gridSquares[x, y].SuggestFruiton(fruiton);
                if (swapPosition != null && gridSquares[x, y].KernelFruiton != null)
                {
                    gridSquares[swapPosition.Y, swapPosition.X - 2].SuggestFruiton(gridSquares[x, y].KernelFruiton);
                }
                return(GetBattlePositionFromGridPosition(x, y));
            }
            return(null);
        }
コード例 #2
0
 private void AddFruitonToTeam(KFruiton fruiton, Position position, FruitonTeam team)
 {
     if (isMyTurnToDraft)
     {
         FridgeFruiton fridgeFruiton = dbFridgeMapping[fruiton.dbId];
         fridgeFruiton.Count--;
         team.FruitonIDs.Add(fruiton.dbId);
         team.Positions.Add(position);
         MyTeamGrid.AddFruitonAt(fruiton, position);
         draftHandler.SendDraftResponse(fruiton.dbId);
     }
 }
コード例 #3
0
        protected override void InitializeFridgeFruiton(FridgeFruiton fFruiton, Fruiton kFruiton, int fridgeIndex)
        {
            base.InitializeFridgeFruiton(fFruiton, kFruiton, fridgeIndex);
            var button = fFruiton.GetComponent <Button>();

            button.onClick.AddListener(() =>
            {
                UnselectFruiton();
                selectedFruiton = fFruiton;
                button.GetComponent <Image>().color = SELECTED_COLOR;
                ShowTooltip(kFruiton);
            });
        }
コード例 #4
0
        /// <summary>
        /// Shows fruiton tooltip on a given position.
        /// </summary>
        /// <param name="fruiton">fruiton to show tooltip of</param>
        /// <param name="positionIndex">index of the position in <see cref="TooltipPanelPositions"/></param>
        protected void ShowTooltip(KFruiton fruiton, int positionIndex = 0)
        {
            RectTransform targetTransform  = TooltipPanelPositions[positionIndex];
            var           tooltipTransform = PanelTooltip.GetComponent <RectTransform>();

            PanelTooltip.SetActive(true);
            PanelTooltip.transform.SetParent(targetTransform.parent);
            tooltipTransform.pivot            = targetTransform.pivot;
            tooltipTransform.anchorMin        = targetTransform.anchorMin;
            tooltipTransform.anchorMax        = targetTransform.anchorMax;
            tooltipTransform.anchoredPosition = targetTransform.anchoredPosition;
            PanelTooltip.GetComponentInChildren <Text>().text = TooltipUtil.GenerateTooltip(fruiton);
        }
コード例 #5
0
        /// <summary>
        /// Initializes drag and drop mode, displays info to user.
        /// </summary>
        /// <param name="fruiton">fruiton that is being dragged</param>
        /// <param name="teamPosition">position in a team grid from the fruiton is being dragged, null if fruiton isn't being dragged from the team</param>
        protected void BeginFruitonDrag(KFruiton fruiton, Position teamPosition = null)
        {
            draggedFruiton = fruiton;
            DragAndDropBarrier.gameObject.SetActive(true);
            DragAndDropFruiton.gameObject.SetActive(true);
            DragAndDropFruiton.SetSkin(fruiton.model);
            ScrollRect.horizontal = false;
            teamDragGridPosition  = teamPosition;
            isDragging            = true;
            isDraggingFromTeam    = teamPosition != null;
#if UNITY_ANDROID && !UNITY_EDITOR
            ShowTooltip(fruiton, 2);
# else
コード例 #6
0
        /// <param name="fruiton">fruiton to place in the team</param>
        /// <returns>List of available position on the grid where a fruiton can be placed</returns>
        public List <Position> GetAvailableSquares(Fruiton fruiton)
        {
            var result = new List <Position>();

            for (int x = 0; x < gridSquares.GetLength(0); x++)
            {
                for (int y = 0; y < gridSquares.GetLength(1); y++)
                {
                    if (gridSquares[x, y].IsEmpty &&
                        gridSquares[x, y].FruitonType == fruiton.type &&
                        (AvailablePositions == null || AvailablePositions.Contains(GetBattlePositionFromGridPosition(x, y))))
                    {
                        result.Add(GetBattlePositionFromGridPosition(x, y));
                    }
                }
            }
            return(result);
        }
コード例 #7
0
 /// <summary>
 /// Adds a fruiton to a grid square.
 /// </summary>
 /// <param name="fruiton">fruiton to add</param>
 /// <param name="position">position of a square grid to add fruiton to</param>
 public void AddFruitonAt(Fruiton fruiton, Position position)
 {
     gridSquares[position.Y, position.X - 2].SetFruiton(fruiton);
 }
コード例 #8
0
 protected override void OnBeginDragFromTeamListener(KFruiton fruiton, Position position)
 {
     // Dragging from team is disabled in draft mode
 }
コード例 #9
0
 /// <summary>
 /// Initializes fridge fruiton game object data.
 /// </summary>
 /// <param name="fFruiton">game object to initialize</param>
 /// <param name="kFruiton">kernel fruiton to load data from</param>
 /// <param name="fridgeIndex">index of the fridge fruiton in the scene</param>
 protected virtual void InitializeFridgeFruiton(FridgeFruiton fFruiton, KFruiton kFruiton, int fridgeIndex)
 {
     fFruiton.SetKernelFruiton(kFruiton);
     fFruiton.FridgeIndex = fridgeIndex;
     fridgeFruitons.Add(fFruiton);
 }
コード例 #10
0
 /// <summary> Invoked whenever drag and drop is initiated on a fruiton from the team grid. </summary>
 /// <param name="fruiton">fruiton being dragged</param>
 /// <param name="position">position in a team from which the fruiton is dragged</param>
 protected abstract void OnBeginDragFromTeamListener(KFruiton fruiton, Position position);