Example #1
0
        private UICardView FindCard(Transform parent, ICard card)
        {
            foreach (Transform child in parent)
            {
                UICardView uiCard = child.GetComponent <UICardView>();
                if (uiCard == null)
                {
                    Debug.LogWarning("Found object in hand that didn't have a UICardView component. Disregarding...");
                    continue;
                }

                if (uiCard.CardRemoved)
                {
                    continue;
                }
                if (uiCard.GetCard() == card)
                {
                    if (uiCard.GetCard().GUID == card.GUID)
                    {
                        //queue card destroy
                        return(uiCard);
                    }
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Queue an animation to show a card being exhausted from the player's hand.
        /// </summary>
        public void AnimateExhaust(ICard card, Chase newState)
        {
            // Remove the first matching card from the player's hand.
            UICardView uiCard = FindCard(this.Hand.transform, card);

            if (uiCard != null)
            {
                uiCard.CardRemoved = true;
                AddAnimationToQueue(new QueuedAnimation(null, null, () => { Destroy(uiCard.gameObject); }, null));
                return;
            }
            uiCard = FindCard(this.Route.transform, card);
            if (uiCard != null)
            {
                uiCard.CardRemoved = true;
                AddAnimationToQueue(new QueuedAnimation(null, null, () => { Destroy(uiCard.gameObject); }, null));
                return;
            }
            uiCard = FindCard(this.Pursuit.transform, card);
            if (uiCard != null)
            {
                uiCard.CardRemoved = true;
                AddAnimationToQueue(new QueuedAnimation(null, null, () => { Destroy(uiCard.gameObject); }, null));
                return;
            }
        }
Example #3
0
        private void OnCardClicked(object sender, EventArgs e)
        {
            UICardView clickedCard = (sender as GameObject)
                                     ?.GetComponent <UICardView>();

            this.CardClicked?.Invoke(clickedCard);
        }
Example #4
0
        /// <summary>
        /// Queue an animation to show the drawing of a card into the player's hand.
        /// </summary>
        public void AnimateCardDraw(IPlayerCard card, Chase newState)
        {
            GameObject newCard    = this.SpawnCard(card, CardSpawnLocation.Hand);
            UICardView uiCardView = newCard.GetComponent <UICardView>();

            uiCardView.Anim.SetTrigger("PreDraw");
            AddAnimationToQueue(new QueuedAnimation(uiCardView.Anim, "Draw", null, null));
            this.PlayerDeckCountLabel.text = newState.PlayerDeck.Count.ToString("N0");
        }
Example #5
0
        /// <summary>
        /// Spawn a new card prefab at the specified location.
        /// </summary>
        public GameObject SpawnCard <TCard>(TCard card, CardSpawnLocation location)
            where TCard : ICard
        {
            GameObject parent        = this.CardSpawnParents[location];
            GameObject newCard       = Instantiate(UICardPrefab, parent.transform);
            UICardView cardComponent = newCard.GetComponent <UICardView>();

            newCard.GetComponent <AnimationEndedTrigger>().SetUIManager(this);

            PlayerCard playerCard = card as PlayerCard;

            if (playerCard != null)
            {
                cardComponent.Setup(playerCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnPlayerCardClicked;
                }
                return(newCard);
            }

            RouteCard routeCard = card as RouteCard;

            if (routeCard != null)
            {
                cardComponent.Setup(routeCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnRouteCardClicked;
                }
                return(newCard);
            }

            PursuitCard pursuitCard = card as PursuitCard;

            if (pursuitCard != null)
            {
                cardComponent.Setup(pursuitCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnPursuitCardClicked;
                }
                return(newCard);
            }

            throw new ArgumentException($"Don't know how to set up a UI card object for a {card.GetType().FullName}.");
        }
Example #6
0
        /// <summary>
        /// Queue an animation to show a card being removed from the current route.
        /// </summary>
        public void AnimateRouteDiscard(IRouteCard card, Chase newState)
        {
            // Remove the first matching card from the current route.
            UICardView uiCard = FindCard(this.Route.transform, card);

            if (uiCard != null)
            {
                //queue card destroy
                AddAnimationToQueue(new QueuedAnimation(null, null, () => {
                    if (uiCard != null && uiCard.gameObject != null)
                    {
                        Destroy(uiCard.gameObject);
                    }
                }, null));
            }
        }
Example #7
0
        /// <summary>
        /// Queue an animation to show a card being discarded from the player's hand.
        /// </summary>
        public void AnimateDiscard(IPlayerCard card, Chase newState)
        {
            UICardView uiCard = FindCard(this.Hand.transform, card);

            if (uiCard != null)
            {
                uiCard.CardRemoved = true;
                //queue card destroy
                AddAnimationToQueue(new QueuedAnimation(null, null, () => {
                    if (uiCard != null && uiCard.gameObject != null)
                    {
                        Destroy(uiCard.gameObject);
                    }
                    this.PlayerDiscardCountLabel.text = newState.PlayerDiscard.Count.ToString("N0");
                }, null));
            }
        }
Example #8
0
        /// <summary>
        /// Queue an animation to show a card being exhausted from the player's hand.
        /// </summary>
        public void AnimateActivation(ICard card, Chase newState)
        {
            // Remove the first matching card from the player's hand.
            UICardView uiCard = FindCard(this.Hand.transform, card);

            if (uiCard != null)
            {
                AddAnimationToQueue(new QueuedAnimation(uiCard.Anim, "Activate", null, null));
                return;
            }
            uiCard = FindCard(this.Route.transform, card);
            if (uiCard != null)
            {
                AddAnimationToQueue(new QueuedAnimation(uiCard.Anim, "Activate", null, null));
                return;
            }
            uiCard = FindCard(this.Pursuit.transform, card);
            if (uiCard != null)
            {
                AddAnimationToQueue(new QueuedAnimation(uiCard.Anim, "Activate", null, null));
                return;
            }
        }