* GUI: fixed that look at and reveals dialogs doesn't show card's playable status;

This commit is contained in:
Oleg Agafonov 2021-07-21 03:34:43 +04:00
parent 96ca260109
commit f48da4c923
4 changed files with 73 additions and 24 deletions

View file

@ -20,7 +20,7 @@
import java.util.*; import java.util.*;
/** /**
* Panel for stack and hand zones * Panel for stack and hand zones, component for lookAt and reveal windows (CardInfoWindowDialog)
* *
* @author BetaSteward_at_googlemail.com, JayDi85 * @author BetaSteward_at_googlemail.com, JayDi85
*/ */
@ -386,4 +386,14 @@
public void setZone(Zone zone) { public void setZone(Zone zone) {
this.zone = zone; this.zone = zone;
} }
/**
* For GUI: get mage card components for update (example: change playable status)
* Warning, do not change the list
*
* @return
*/
public Map<UUID, MageCard> getMageCardsForUpdate() {
return this.cards;
}
} }

View file

@ -4,15 +4,13 @@ import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import java.util.EnumSet; import java.util.*;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameEvent;
import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.plaf.basic.BasicInternalFrameUI;
import mage.cards.MageCard;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
@ -160,6 +158,16 @@ public class CardInfoWindowDialog extends MageDialog {
showAndPositionWindow(); showAndPositionWindow();
} }
/**
* For GUI: get mage card components for update (example: change playable status)
* Warning, do not change the list
*
* @return
*/
public Map<UUID, MageCard> getMageCardsForUpdate() {
return this.cards.getMageCardsForUpdate();
}
@Override @Override
public void show() { public void show() {
if (showType == ShowType.EXILE) { if (showType == ShowType.EXILE) {

View file

@ -26,6 +26,7 @@ import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.MageDialogState; import mage.client.util.gui.MageDialogState;
import mage.constants.*; import mage.constants.*;
import mage.game.events.PlayerQueryEvent; import mage.game.events.PlayerQueryEvent;
import mage.players.PlayableObjectStats;
import mage.players.PlayableObjectsList; import mage.players.PlayableObjectsList;
import mage.view.*; import mage.view.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -1435,21 +1436,6 @@ public final class GamePanel extends javax.swing.JPanel {
} }
} }
// revealed
for (RevealedView rev : lastGameData.game.getRevealed()) {
for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
if (needSelectable.contains(card.getKey())) {
card.getValue().setChoosable(true);
}
if (needChoosen.contains(card.getKey())) {
card.getValue().setSelected(true);
}
if (needPlayable.containsObject(card.getKey())) {
card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
}
}
}
// companion // companion
for (RevealedView rev : lastGameData.game.getCompanion()) { for (RevealedView rev : lastGameData.game.getCompanion()) {
for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) { for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
@ -1465,7 +1451,24 @@ public final class GamePanel extends javax.swing.JPanel {
} }
} }
// looked at // revealed (current cards)
for (RevealedView rev : lastGameData.game.getRevealed()) {
for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
if (needSelectable.contains(card.getKey())) {
card.getValue().setChoosable(true);
}
if (needChoosen.contains(card.getKey())) {
card.getValue().setSelected(true);
}
if (needPlayable.containsObject(card.getKey())) {
card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
}
}
}
// revealed (old windows)
prepareSelectableWindows(revealed.values(), needSelectable, needChoosen, needPlayable);
// looked at (current cards)
for (LookedAtView look : lastGameData.game.getLookedAt()) { for (LookedAtView look : lastGameData.game.getLookedAt()) {
for (Map.Entry<UUID, SimpleCardView> card : look.getCards().entrySet()) { for (Map.Entry<UUID, SimpleCardView> card : look.getCards().entrySet()) {
if (needPlayable.containsObject(card.getKey())) { if (needPlayable.containsObject(card.getKey())) {
@ -1473,6 +1476,32 @@ public final class GamePanel extends javax.swing.JPanel {
} }
} }
} }
// looked at (old windows)
prepareSelectableWindows(lookedAt.values(), needSelectable, needChoosen, needPlayable);
}
private void prepareSelectableWindows(
Collection<CardInfoWindowDialog> windows,
Set<UUID> needSelectable,
List<UUID> needChoosen,
PlayableObjectsList needPlayable
) {
// lookAt or reveals windows clean up on next priority, so users can see dialogs, but xmage can't restore it
// so it must be updated manually (it's ok to keep outdated cards in dialog, but not ok to show wrong selections)
for (CardInfoWindowDialog window : windows) {
for (MageCard mageCard : window.getMageCardsForUpdate().values()) {
CardView cardView = mageCard.getOriginal();
cardView.setChoosable(needSelectable.contains(cardView.getId()));
cardView.setSelected(needChoosen.contains(cardView.getId()));
if (needPlayable.containsObject(cardView.getId())) {
cardView.setPlayableStats(needPlayable.getStats(cardView.getId()));
} else {
cardView.setPlayableStats(new PlayableObjectStats());
}
// TODO: little bug with toggled night card after update/clicks, but that's ok (can't click on second side)
mageCard.update(cardView);
}
}
} }
/** /**

View file

@ -3646,15 +3646,17 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
} }
// check to play companion cards // outside cards
if (fromAll || fromZone == Zone.OUTSIDE) { if (fromAll || fromZone == Zone.OUTSIDE) {
// companion cards
for (Cards companionCards : game.getState().getCompanion().values()) { for (Cards companionCards : game.getState().getCompanion().values()) {
for (Card card : companionCards.getCards(game)) { for (Card card : companionCards.getCards(game)) {
getPlayableFromObjectAll(game, Zone.OUTSIDE, card, availableMana, playable); getPlayableFromObjectAll(game, Zone.OUTSIDE, card, availableMana, playable);
} }
} }
// Check sideboard. Ex: Wish lets player play cards directly from sideboard.
for (UUID sideboardCardId : getSideboard()) { // sideboard cards (example: Wish)
for (UUID sideboardCardId : this.getSideboard()) {
Card sideboardCard = game.getCard(sideboardCardId); Card sideboardCard = game.getCard(sideboardCardId);
if (sideboardCard != null) { if (sideboardCard != null) {
getPlayableFromObjectAll(game, Zone.OUTSIDE, sideboardCard, availableMana, playable); getPlayableFromObjectAll(game, Zone.OUTSIDE, sideboardCard, availableMana, playable);