Ejemplo n.º 1
0
        private void InitializePilesOnGameCreated(Game game)
        {
            var numPlayers = game.Players.Count;
            m_playerLibraryPiles = new UI.CardControl[numPlayers];
            m_playerLibraryPileCountEvaluators = new GameEvaluator<int>[numPlayers];
            for (int i = 0; i < numPlayers; ++i)
            {
                var ccStyle = new Style.CardControlStyle(GameApp.Service<Styler>().GetCardStyle("PileBack"), -1);
                ccStyle.Initialize();
                m_playerLibraryPiles[i] = ccStyle.TypedTarget;
                m_playerLibraryPiles[i].CardData = GameApp.Service<CardDataManager>().CreateDummyCardData(i);
                m_playerLibraryPiles[i].EnableDepth = true;

                int pid = i; // to force creating new lambdas based on the current value of i
                m_playerLibraryPileCountEvaluators[i] = GameApp.Service<GameManager>().CreateGameEvaluator(g => g.Players[pid].Library.Count, 0);
                m_playerLibraryPiles[i].Addins.Add(new UI.CardControlAddins.InstantRotation(m_playerLibraryPiles[i]));
                m_playerLibraryPiles[i].Addins.Add(new UI.CardControlAddins.Pile(m_playerLibraryPiles[i],
                    () => m_playerLibraryPileCountEvaluators[pid].Value));
                m_playerLibraryPiles[i].Dispatcher = m_playerZones[i].Library.Container;
            }

            // graveyard piles are created only when there are more than 1 cards in the graveyard
            // the last card entering graveyard will be displayed on the top
            m_playerGraveyardPiles = new UI.CardControl[numPlayers];
            m_graveyardCounters = new GraveyardCounters[numPlayers];
        }
        private CardControl TakeCardControl()
        {
            CardControl cc;
            if (m_cardControlPool.Count != 0)
            {
                cc = m_cardControlPool[m_cardControlPool.Count - 1];
                m_cardControlPool.RemoveAt(m_cardControlPool.Count - 1);
            }
            else
            {
                var cardStyle = GameApp.Service<Services.Styler>().GetCardStyle("Normal");
                var ccStyle = new Style.CardControlStyle(cardStyle, -1);
                ccStyle.Initialize();

                cc = ccStyle.TypedTarget;
                cc.Addins.Add(new CardControlAddins.SelectorLocationAnimation(cc, this));
                cc.Addins.Add(new CardControlAddins.SelectorHighlight(cc, this));
                cc.MouseTracked.MouseEnter += (s, e) =>
                {
                    m_mouseHoverControl = cc;
                };
                cc.MouseTracked.MouseLeave += (s, e) =>
                {
                    if (m_mouseHoverControl == cc)
                    {
                        m_mouseHoverControl = null;
                    }
                };
                cc.MouseTracked.MouseButton1Down += (s, e) =>
                {
                    Center = cc.GetAddin<CardControlAddins.SelectorLocationAnimation>().LocationIndex;
                };
            }

            return cc;
        }
Ejemplo n.º 3
0
        private void UpdateCardControls(float deltaTime)
        {
            var newCards = GameApp.Service<CardDataManager>().Collection;

            for (int i = 0; i < m_cardControls.Count; ++i)
            {
                var cc = m_cardControls[i];
                var data = newCards.FirstOrDefault(cardData => cardData.Guid == cc.CardGuid);
                if (data == null)
                {
                    m_cardControls.RemoveAt(i--);
                    PutToGraveyard(cc);
                    continue;
                }

                cc.CardData = data;
                var locationAnim = cc.GetAddin<UI.CardControlAddins.LocationAnimation>();
                var newDesignName = "Normal";

                if (cc == ZoomedInCard)
                {
                    locationAnim.SetNextLocation(m_zoomedInZone, 0);
                    newDesignName = "Full";
                }
                else if (data.Zone == SystemZone.Battlefield)
                {
                    locationAnim.SetNextLocation(m_playerZones[data.OwnerPlayerIndex].Battlefield, data.ZonePosition);
                    newDesignName = "NoResource";
                }
                else if (data.Zone == SystemZone.Sacrifice)
                {
                    locationAnim.SetNextLocation(m_playerZones[data.OwnerPlayerIndex].Sacrifice, data.ZonePosition);
                    newDesignName = "NoResource";
                }
                else if (data.Zone == SystemZone.Hand)
                {
                    if (ShallCardBeRevealed(data))
                    {
                        locationAnim.SetNextLocation(m_actingLocalPlayerHandZone, data.ZonePosition);
                    }
                    else
                    {
                        locationAnim.SetNextLocation(m_playerZones[data.OwnerPlayerIndex].Hand, data.ZonePosition);
                    }
                }
                else if (data.Zone == SystemZone.Assist)
                {
                    locationAnim.SetNextLocation(m_playerZones[data.OwnerPlayerIndex].Assists, data.ZonePosition);
                    newDesignName = "NoResource";
                }

                cc.SetCardDesign(newDesignName);
            }

            foreach (var cardData in newCards)
            {
                if (m_cardControls.Any(cc => cc.CardGuid == cardData.Guid))
                {
                    continue;
                }

                var ccStyle = new Style.CardControlStyle(GameApp.Service<Styler>().GetCardStyle("Normal"), cardData.Guid);
                ccStyle.Initialize();

                var cardControl = ccStyle.TypedTarget;
                cardControl.CardData = cardData;
                cardControl.MouseTracked.MouseButton1Up += CardControl_MouseButton1Up;
                cardControl.MouseTracked.MouseButton2Down += CardControl_MouseButton2Down;
                cardControl.Addins.Add(new UI.CardControlAddins.Highlight(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.DamageIndicator(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.InstantRotation(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.Flip(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.LocationAnimation(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.ToneAnimation(cardControl));
                cardControl.Addins.Add(new UI.CardControlAddins.CardIcons(cardControl));
                m_cardControls.Add(cardControl);

                if (cardData.Zone == SystemZone.Hand)
                {
                    PutToLibrary(cardControl);
                }
            }

            m_cardData = newCards;

            foreach (var pz in m_playerZones)
            {
                pz.Hand.Rearrange();
                pz.Battlefield.Rearrange();
                pz.Sacrifice.Rearrange();
            }
            m_actingLocalPlayerHandZone.Rearrange();

            m_cardControls.ForEach(cc => cc.Update(deltaTime));
        }