// -------------------------------------------------------------------------------------------- private void OnPlayerDiscardedCard(object sender, Card.CardEventArgs e) { List <Card> toRemove = new List <Card>(); foreach (Card card in _cardToUICard.Keys) { bool isCardInHand = false; foreach (Card cardInHand in _player.Hand.Cards) { isCardInHand |= cardInHand == card; } if (!isCardInHand) { toRemove.Add(card); } } foreach (Card card in toRemove) { MainPanel.RemoveChild(_cardToUICard[card], true); UICard uiCard = _cardToUICard[card]; _cardToUICard.Remove(card); _uiCardToCard.Remove(uiCard); } PositionCards(true); }
// -------------------------------------------------------------------------------------------- private void OnPlayerDrewCard(object sender, Card.CardEventArgs e) { int numLoadCalls = 0; int numLoadCallsCompleted = 0; foreach (Card card in _player.Hand.Cards) { if (!_cardToUICard.ContainsKey(card)) { numLoadCalls++; UICard.LoadRequiredAssets(card.cardData, () => { numLoadCallsCompleted++; UICard uiCard = new UICard(card.cardData); _cardToUICard.Add(card, uiCard); _uiCardToCard.Add(uiCard, card); MainPanel.AddChild(uiCard); uiCard.SubscribeToEvent(EEventType.PointerEnter, (object eSender, EventSystemEventArgs eventArgs) => { UICard_OnPointerEnter(uiCard, eventArgs.eventData as PointerEventData); }); uiCard.SubscribeToEvent(EEventType.PointerExit, (object eSender, EventSystemEventArgs eventArgs) => { UICard_OnPointerExit(uiCard); }); uiCard.SubscribeToEvent(EEventType.PointerDown, (object eSender, EventSystemEventArgs eventArgs) => { UICard_OnPointerDown(uiCard, eventArgs.eventData as PointerEventData); }); uiCard.SubscribeToEvent(EEventType.Drag, (object eSender, EventSystemEventArgs eventArgs) => { UICard_OnDrag(uiCard, eventArgs.eventData as PointerEventData); }); uiCard.SubscribeToEvent(EEventType.PointerUp, (object eSender, EventSystemEventArgs eventArgs) => { UICard_OnPointerUp(uiCard, eventArgs.eventData as PointerEventData); }); if (numLoadCalls == numLoadCallsCompleted) { PositionCards(true); } }); } } }