public void Draw(SpriteBatch spriteBatch, GameState playState, UISelectionState selectionState) { int cardListIdx = 0; int visibleCardIdx = 0; // int selectSize = 5; if (cardList == null) return; foreach (Card baseCard in cardList) { if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet)) { cardListIdx++; continue; } Card c = GetUpgrade(baseCard); bool canUpgrade = CanUpgrade(baseCard); CardState state = selectionState.GetCardState(c); Rectangle frameRect = new Rectangle(rect.Left, rect.Top + visibleCardIdx * cardHeight, c.frameTexture.Width - (canUpgrade ? 16 : 0), cardHeight); c.Draw(spriteBatch, frameRect, state, (selectedCardIdx == cardListIdx)); if (canUpgrade) { Rectangle upgradeRect = new Rectangle(rect.Right-16, rect.Top + visibleCardIdx * cardHeight, 16, cardHeight); bool selectedThisUpgrade = selectedCardUpgrade && (selectedCardIdx == cardListIdx); spriteBatch.Draw(Game1.upgradeTexture, upgradeRect, selectedThisUpgrade? Color.Red: Color.White); } if (selectedCardIdx == cardListIdx && !selectedCardUpgrade) { Card baseSelectedCard = cardList[selectedCardIdx]; Card selectedCard = GetUpgrade(baseSelectedCard); TextChanges changes = playState.getTextChanges(baseSelectedCard); Vector2 tooltipPos; Tooltip.Align alignment; if(rect.Left == 0) { tooltipPos = new Vector2(rect.Left + selectedCard.frameTexture.Width, rect.Top + visibleCardIdx * cardHeight); alignment = Tooltip.Align.LEFT; } else { tooltipPos = new Vector2(rect.Left, rect.Top + visibleCardIdx * cardHeight); alignment = Tooltip.Align.RIGHT; } Tooltip.DrawTooltip(spriteBatch, Game1.font, Game1.tooltipBG, changes.Apply(selectedCard.description), tooltipPos, alignment); } visibleCardIdx++; cardListIdx++; } }
public void Update(GameState playState, UISelectionState selectionState) { selectedCardUpgrade = false; if (cardList == null || !rect.Contains(Game1.inputState.MousePos)) { selectedCardIdx = -1; } else { int cardListIdx = 0; int cardBottom = rect.Top; foreach (Card baseCard in cardList) { if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet)) { cardListIdx++; continue; } Card c = GetUpgrade(baseCard); cardBottom += cardHeight; if (Game1.inputState.MousePos.Y < cardBottom) { selectedCardIdx = cardListIdx; if ( Game1.inputState.MousePos.X > rect.Right - 16 && CanUpgrade(baseCard) ) { selectedCardUpgrade = true; } break; } cardListIdx++; } if (Game1.inputState.MousePos.Y > cardBottom) { selectedCardIdx = -1; } } if (Game1.inputState.WasMouseLeftJustPressed()) { if (selectedCardIdx != -1) { selectionState.ClickedCard(cardList[selectedCardIdx], selectedCardUpgrade); } else { selectionState.ClickedPosition(); } } }