示例#1
0
    private void InitializeCards(int amountOfSlots)
    {
        cards = PlayerAndEnemyDeckHolder.GetPreparedCardsForThePlayerWithTheRandomCards();

        for (int i = 0; i < amountOfSlots; i++)
        {
            PutCardInIndexWithSmoothMovement(cards[i], i);

            ChildMaker.CopySizeDelta(slots[i], cards[i].GetRectTransform());
        }
    }
示例#2
0
 private void GiveHandBackToDeck()
 {
     for (int i = 0; i < hand.GetSize(); i++)
     {
         Card card = hand.RemoveCardOrGetNull(i);
         if (card != null)
         {
             deck.PutCardInTop(card);
             const float TIME_GOING_TO_HAND = 0.25f;
             ChildMaker.AdoptAndScaleAndSmoothlyMoveToParent(deck.transform, card.GetRectTransform(), TIME_GOING_TO_HAND);
         }
     }
 }
示例#3
0
 private void Awake()
 {
     if (instance == null)
     {
         instance         = this;
         transform.parent = null;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
示例#4
0
    private void PopulateSlotsWithCards()
    {
        for (int i = 0; i < cards.Length; i++)
        {
            // Background
            Card slotBackground = cards[i].GetClone();
            slotBackground.MakeColorGray();
            ChildMaker.AdoptTeleportAndScale(slots[i], slotBackground.GetRectTransform());
            ChildMaker.CopySizeDelta(slots[i], slotBackground.GetRectTransform());

            // The actual card
            ChildMaker.AdoptTeleportAndScale(slots[i], cards[i].GetRectTransform());
            ChildMaker.CopySizeDelta(slots[i], cards[i].GetRectTransform());
        }
    }
示例#5
0
    public void GiveCardBack(Card card)
    {
        for (int slot = 0; slot < cards.Length; slot++)
        {
            Card cardInSlot = GetReferenceToCardAt(slot);
            if (card.IsAnotherInstanceOf(cardInSlot))
            {
                amountOfEachCard[slot]++;
                UpdateCardColorAndAmountText(slot);
                ChildMaker.AdoptAndScaleAndSmoothlyMoveToParent
                    (slots[slot], card.GetRectTransform(), repositionAnimationDurationInSeconds);
                const float DELAY_FROM_ANIMATION_END_TO_DESTRUCTION = 0.2f;
                ObjectDestroyer.DestroyObjectInTime(card.gameObject, repositionAnimationDurationInSeconds + DELAY_FROM_ANIMATION_END_TO_DESTRUCTION);
                return;
            }
        }

        L.ogError("Couldn't find card of same type to give the card back.", this);
    }
示例#6
0
    private void PutCardInIndex(Card card, int index, bool smooth)
    {
        RectTransform cardRect = card.GetRectTransform();

        cards[index]      = card;
        cardRect.rotation = transform.rotation;

        if (smooth)
        {
            ChildMaker.AdoptAndScaleAndSmoothlyMoveToParent(cardPositions[index].transform, card.GetRectTransform(), repositionAnimationDurationInSeconds);
        }
        else
        {
            ChildMaker.AdoptAndTeleport(cardPositions[index].transform, card.GetRectTransform());
        }

        cardRect.localScale = new Vector3(1, 1, 1);
        Rect slotRect = cardPositions[index].rect;

        cardRect.sizeDelta = new Vector2(slotRect.width, slotRect.height);
    }
示例#7
0
    private IEnumerator DragHistory(CardsHolder cardsHolder, int index)
    {
        isRunningDragHistoryCoroutine = true;
        isDragging            = true;
        wasDroppedInValidSpot = false;

        ClearSelections(new CardsHolder[] { cardsHolder });

        cardBeingDragged            = null;
        cardsHolderBelowMouseOnDrop = null;
        indexOfSlotBelowMouseOnDrop = -1;

        // Wait for the BattleFSM to recognize that the variables ware cleared
        yield return(null);

        cardsHolder.SetSelectedIndex(index);
        cardBeingDragged = cardsHolder.GetReferenceToCardAt(index);
        cardBeingDragged.cardDragAndDrop.StartDragging();

        ShowTipAboutCardBeingDragged();

        while (isDragging)
        {
            if (!PlayerInput.GetMouseButton0())
            {
                // NOTE: this is an attempt to solve a bug in which the card
                // was not ending the dragging properly, but it was hard to reproduce.
                this.isDragging = false;
                Debug.LogError("[UICardsHolderEventHandler] Mouse is not " +
                               "dragging, but this script believes it is dragging.", cardBeingDragged);
            }
            yield return(null);
        }

        if (!wasDroppedInValidSpot)
        {
            // Wait one more frame for the drop event to be called.
            yield return(null);
        }

        if (wasDroppedInValidSpot)
        {
            cardsHolderBelowMouseOnDrop.SetSelectedIndex(indexOfSlotBelowMouseOnDrop);

            // Wait for battleFSM to do it's job (like set the parent of the card).
            yield return(null);

            yield return(null);

            while (cardBeingDragged != null && ChildMaker.IsRectTransformBeingMoved(cardBeingDragged.GetRectTransform()))
            {
                yield return(null);
            }

            // A card can be null because to make the card go back instantly, a controller script should delete
            // this card, and put a clone in the place the original was.
            if (cardBeingDragged != null)
            {
                ChildMaker.AdoptAndScaleAndSmoothlyMoveToParent
                (
                    cardBeingDragged.RectTransform.parent,
                    cardBeingDragged.RectTransform,
                    delayToComeBackFromOtherSpot
                );
            }
        }

        HideCardsBeingDraggedTip();

        if (cardsHolderBelowMouseOnDrop == null)
        {
            ClearSelections(new CardsHolder[] { cardsHolder });
        }
        else
        {
            ClearSelections(new CardsHolder[] { cardsHolder, cardsHolderBelowMouseOnDrop });
        }

        if (wasDroppedInValidSpot && cardBeingDragged != null)
        {
            yield return(new WaitForSeconds(delayToComeBackFromOtherSpot));
        }

        isRunningDragHistoryCoroutine = false;
    }
示例#8
0
    private void InstantiateObjAsSonOf(GameObject toInstantiate, Transform parent)
    {
        RectTransform instantiated = Instantiate(toInstantiate).GetComponent <RectTransform>();

        ChildMaker.AdoptAndTeleport(parent, instantiated);
    }