diff --git a/Mage.Client/src/main/java/mage/client/dialog/ExileZoneDialog.form b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.form similarity index 100% rename from Mage.Client/src/main/java/mage/client/dialog/ExileZoneDialog.form rename to Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.form diff --git a/Mage.Client/src/main/java/mage/client/dialog/ExileZoneDialog.java b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java similarity index 51% rename from Mage.Client/src/main/java/mage/client/dialog/ExileZoneDialog.java rename to Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java index d85e8d2ee6..67e8fa7401 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ExileZoneDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java @@ -27,42 +27,140 @@ */ /* - * ExileZoneDialog.java + * CardInfoWindowDialog.java * * Created on Feb 1, 2010, 3:00:35 PM */ package mage.client.dialog; +import java.awt.Point; import java.beans.PropertyVetoException; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.ImageIcon; +import javax.swing.SwingUtilities; import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; import mage.client.cards.BigCard; import mage.client.util.Config; +import mage.client.util.SettingsManager; +import mage.client.util.gui.GuiDisplayUtil; +import mage.view.CardsView; import mage.view.ExileView; +import mage.view.SimpleCardsView; +import org.mage.plugins.card.utils.impl.ImageManagerImpl; /** * * @author BetaSteward_at_googlemail.com */ -public class ExileZoneDialog extends MageDialog { +public class CardInfoWindowDialog extends MageDialog { - /** Creates new form ExileZoneDialog */ - public ExileZoneDialog() { + public static enum ShowType { REVEAL, LOOKED_AT, EXILE, OTHER }; + + private ShowType showType; + private boolean positioned; + + public CardInfoWindowDialog(ShowType showType, String name) { + this.title = name; + this.showType = showType; + this.positioned = false; this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); initComponents(); this.setModal(false); + switch(this.showType) { + case LOOKED_AT: + this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getLookedAtImage())); + this.setClosable(true); + break; + case REVEAL: + this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage())); + this.setClosable(true); + break; + case EXILE: + this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage())); + break; + default: + // no icon yet + } + this.setTitelBarToolTip(name); } public void cleanUp() { cards.cleanUp(); } + public void loadCards(SimpleCardsView showCards, BigCard bigCard, UUID gameId) { + + boolean changed = cards.loadCards(showCards, bigCard, gameId); + if (showCards.size() > 0) { + show(); + if (changed) { + try { + if (!positioned) { + this.setIcon(false); + firstWindowPosition(); + } + } catch (PropertyVetoException ex) { + Logger.getLogger(CardInfoWindowDialog.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + else { + this.hideDialog(); + } + } + + public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) { + boolean changed = cards.loadCards(showCards, bigCard, gameId, null); + + if (showCards.size() > 0) { + show(); + if (changed) { + try { + if (!positioned) { + this.setIcon(false); + firstWindowPosition(); + } else { + + } + } catch (PropertyVetoException ex) { + Logger.getLogger(CardInfoWindowDialog.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } + else { + this.hideDialog(); + } + } + + private void firstWindowPosition() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (!positioned) { + int width = CardInfoWindowDialog.this.getWidth(); + int height = CardInfoWindowDialog.this.getHeight(); + if (width > 0 && height > 0) { + positioned = true; + Point centered = SettingsManager.getInstance().getComponentPosition(width, height); + int xPos = centered.x / 2; + int yPos = centered.y / 2; + CardInfoWindowDialog.this.setLocation(xPos, yPos); + GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, CardInfoWindowDialog.this); + CardInfoWindowDialog.this.show(); + } + } + + + // ShowCardsDialog.this.setVisible(true); + } + }); + } + public void loadCards(ExileView exile, BigCard bigCard, UUID gameId) { - this.title = exile.getName(); - this.setTitelBarToolTip(exile.getName()); boolean changed = cards.loadCards(exile, bigCard, gameId, null); if (exile.size() > 0) { show(); @@ -70,7 +168,7 @@ public class ExileZoneDialog extends MageDialog { try { this.setIcon(false); } catch (PropertyVetoException ex) { - Logger.getLogger(ExileZoneDialog.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(CardInfoWindowDialog.class.getName()).log(Level.SEVERE, null, ex); } } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java index 7e221e11e7..433aecd21c 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java @@ -34,6 +34,16 @@ package mage.client.dialog; +import java.awt.Component; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.Serializable; +import java.util.Map; +import java.util.UUID; +import javax.swing.ImageIcon; +import javax.swing.JLayeredPane; +import javax.swing.SwingUtilities; import mage.cards.CardDimensions; import mage.client.MageFrame; import mage.client.cards.BigCard; @@ -44,29 +54,29 @@ import mage.client.util.gui.GuiDisplayUtil; import mage.view.CardsView; import mage.view.SimpleCardsView; import org.mage.card.arcane.CardPanel; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.io.Serializable; -import java.util.Map; -import java.util.UUID; +import org.mage.plugins.card.utils.impl.ImageManagerImpl; /** * @author BetaSteward_at_googlemail.com */ public class ShowCardsDialog extends MageDialog implements MouseListener { - private boolean reloaded = false; + + + // remember if this dialog was already auto positioned, so don't do it after the first time + private boolean positioned; + /** * Creates new form ShowCardsDialog */ public ShowCardsDialog() { + this.positioned = false; + this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); initComponents(); this.setModal(false); + } public void cleanUp() { @@ -88,7 +98,6 @@ public class ShowCardsDialog extends MageDialog implements MouseListener { } public void loadCards(String name, CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal, Map options) { - this.reloaded = true; this.title = name; this.setTitelBarToolTip(name); cardArea.loadCards(showCards, bigCard, dimension, gameId, this); @@ -106,7 +115,7 @@ public class ShowCardsDialog extends MageDialog implements MouseListener { if (getParent() != MageFrame.getDesktop() /*|| this.isClosed*/) { MageFrame.getDesktop().add(this, JLayeredPane.DEFAULT_LAYER); } - pack(); + pack(); this.revalidate(); this.repaint(); @@ -115,26 +124,21 @@ public class ShowCardsDialog extends MageDialog implements MouseListener { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - int width = ShowCardsDialog.this.getWidth(); - int height = ShowCardsDialog.this.getWidth(); - if (width > 0 && height > 0) { - Point centered = SettingsManager.getInstance().getComponentPosition(width, height); - ShowCardsDialog.this.setLocation(centered.x, centered.y); - GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this); + if (!positioned) { + int width = ShowCardsDialog.this.getWidth(); + int height = ShowCardsDialog.this.getHeight(); + if (width > 0 && height > 0) { + Point centered = SettingsManager.getInstance().getComponentPosition(width, height); + ShowCardsDialog.this.setLocation(centered.x, centered.y); + positioned = true; + GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this); + } } ShowCardsDialog.this.setVisible(true); } }); } - public boolean isReloaded() { - return this.reloaded; - } - - public void clearReloaded() { - this.reloaded = false; - } - private void initComponents() { cardArea = new CardArea(); diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 029e928fd7..6837a7ed6e 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -50,6 +50,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -85,7 +86,8 @@ import mage.client.components.HoverButton; import mage.client.components.MageComponents; import mage.client.components.ext.dlg.DialogManager; import mage.client.components.layout.RelativeLayout; -import mage.client.dialog.ExileZoneDialog; +import mage.client.dialog.CardInfoWindowDialog; +import mage.client.dialog.CardInfoWindowDialog.ShowType; import mage.client.dialog.PickChoiceDialog; import mage.client.dialog.PickNumberDialog; import mage.client.dialog.PickPileDialog; @@ -143,9 +145,9 @@ public final class GamePanel extends javax.swing.JPanel { private static final int X_PHASE_WIDTH = 55; private static final int STACK_MIN_CARDS_OFFSET_Y = 7; private final Map players = new HashMap<>(); - private final Map exiles = new HashMap<>(); - private final Map revealed = new HashMap<>(); - private final Map lookedAt = new HashMap<>(); + private final Map exiles = new HashMap<>(); + private final Map revealed = new HashMap<>(); + private final Map lookedAt = new HashMap<>(); private final ArrayList pickTarget = new ArrayList<>(); private UUID gameId; private UUID playerId; // playerId of the player @@ -255,15 +257,15 @@ public final class GamePanel extends javax.swing.JPanel { if (pickNumber != null) { pickNumber.removeDialog(); } - for (ExileZoneDialog exileDialog: exiles.values()) { + for (CardInfoWindowDialog exileDialog: exiles.values()) { exileDialog.cleanUp(); exileDialog.removeDialog(); } - for (ShowCardsDialog revealDialog: revealed.values()) { + for (CardInfoWindowDialog revealDialog: revealed.values()) { revealDialog.cleanUp(); revealDialog.removeDialog(); } - for (ShowCardsDialog lookedAtDialog: lookedAt.values()) { + for (CardInfoWindowDialog lookedAtDialog: lookedAt.values()) { lookedAtDialog.cleanUp(); lookedAtDialog.removeDialog(); } @@ -682,7 +684,7 @@ public final class GamePanel extends javax.swing.JPanel { for (ExileView exile: game.getExile()) { if (!exiles.containsKey(exile.getId())) { - ExileZoneDialog newExile = new ExileZoneDialog(); + CardInfoWindowDialog newExile = new CardInfoWindowDialog(ShowType.EXILE, exile.getName()); exiles.put(exile.getId(), newExile); MageFrame.getDesktop().add(newExile, JLayeredPane.MODAL_LAYER); newExile.show(); @@ -805,30 +807,53 @@ public final class GamePanel extends javax.swing.JPanel { currentStep.setLocation(prevPoint.x - 15, prevPoint.y); } } - + private void showRevealed(GameView game) { - for (RevealedView reveal: game.getRevealed()) { - if (!revealed.containsKey(reveal.getName())) { - ShowCardsDialog newReveal = new ShowCardsDialog(); - revealed.put(reveal.getName(), newReveal); - } - revealed.get(reveal.getName()).loadCards("Revealed " + reveal.getName(), reveal.getCards(), bigCard, Config.dimensions, gameId, false); + for (RevealedView revealView: game.getRevealed()) { + handleGameInfoWindow(revealed, ShowType.REVEAL, revealView.getName(), revealView.getCards()); } + removeClosedCardInfoWindows(revealed); } private void showLookedAt(GameView game) { - for (ShowCardsDialog looked: lookedAt.values()) { - looked.clearReloaded(); + for (LookedAtView lookedAtView: game.getLookedAt()) { + handleGameInfoWindow(lookedAt, ShowType.LOOKED_AT, lookedAtView.getName(), lookedAtView.getCards()); } - for (LookedAtView looked: game.getLookedAt()) { - if (!lookedAt.containsKey(looked.getName())) { - ShowCardsDialog newLookedAt = new ShowCardsDialog(); - lookedAt.put(looked.getName(), newLookedAt); + removeClosedCardInfoWindows(lookedAt); + } + + private void handleGameInfoWindow(Map windowMap, ShowType showType, String name, LinkedHashMap cardsView) { + CardInfoWindowDialog cardInfoWindowDialog; + if (!windowMap.containsKey(name)) { + cardInfoWindowDialog = new CardInfoWindowDialog(showType, name); + windowMap.put(name, cardInfoWindowDialog); + MageFrame.getDesktop().add(cardInfoWindowDialog, JLayeredPane.MODAL_LAYER); + } else { + cardInfoWindowDialog = windowMap.get(name); + } + + if (cardInfoWindowDialog != null && !cardInfoWindowDialog.isClosed()) { + switch(showType) { + case REVEAL: + cardInfoWindowDialog.loadCards((CardsView) cardsView, bigCard, gameId); + break; + case LOOKED_AT: + cardInfoWindowDialog.loadCards((SimpleCardsView) cardsView, bigCard, gameId); + break; } - lookedAt.get(looked.getName()).loadCards("Looked at by " + looked.getName(), looked.getCards(), bigCard, Config.dimensions, gameId, false); } } - + + private void removeClosedCardInfoWindows(Map windowMap) { + // Remove closed window objects from the maps + for (Iterator> iterator = windowMap.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = iterator.next(); + if (entry.getValue().isClosed()) { + iterator.remove(); + } + } + } + public void ask(String question, GameView gameView, int messageId) { updateGame(gameView); this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, false, null, messageId); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index 8252189c8c..72847cca1a 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -75,21 +75,26 @@ public class GuiDisplayUtil { Dimension screenDim = c.getToolkit().getScreenSize(); GraphicsConfiguration g = c.getGraphicsConfiguration(); if (g != null) { - Insets insets = c.getToolkit().getScreenInsets(g); - + Insets insets = c.getToolkit().getScreenInsets(g); + boolean setLocation = false; if (x + c.getWidth() > screenDim.width - insets.right) { x = (screenDim.width - insets.right) - c.getWidth(); + setLocation = true; } else if (x < insets.left) { x = insets.left; + setLocation = true; } if (y + c.getHeight() > screenDim.height - insets.bottom) { y = (screenDim.height - insets.bottom) - c.getHeight(); + setLocation = true; } else if (y < insets.top) { y = insets.top; + setLocation = true; + } + if (setLocation) { + c.setLocation(x, y); } - - c.setLocation(x, y); } else { System.out.println("GuiDisplayUtil::keepComponentInsideScreen -> no GraphicsConfiguration"); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java index 52138aa996..63f2dcf900 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java @@ -15,6 +15,9 @@ public interface ImageManager { Image getTokenIconImage(); Image getTriggeredAbilityImage(); Image getActivatedAbilityImage(); + Image getLookedAtImage(); + Image getRevealedImage(); + Image getExileImage(); Image getCopyInformIconImage(); Image getCounterImageViolet(); Image getCounterImageRed(); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java index 4ec5ac433d..9209be5d87 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java @@ -110,6 +110,33 @@ public class ImageManagerImpl implements ImageManager { return imageTokenIcon; } + @Override + public Image getLookedAtImage() { + if (lookedAtIcon == null) { + Image image = getImageFromResourceTransparent("/game/looked_at.png", Color.WHITE, new Rectangle(20, 20)); + lookedAtIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return lookedAtIcon; + } + + @Override + public Image getRevealedImage() { + if (revealedIcon == null) { + Image image = getImageFromResourceTransparent("/game/revealed.png", Color.WHITE, new Rectangle(20, 20)); + revealedIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return revealedIcon; + } + + @Override + public Image getExileImage() { + if (exileIcon == null) { + Image image = getImageFromResourceTransparent("/info/exile.png", Color.WHITE, new Rectangle(20, 20)); + exileIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return exileIcon; + } + @Override public BufferedImage getTriggeredAbilityImage() { if (triggeredAbilityIcon == null) { @@ -374,6 +401,9 @@ public class ImageManagerImpl implements ImageManager { private static BufferedImage imageTokenIcon; private static BufferedImage triggeredAbilityIcon; private static BufferedImage activatedAbilityIcon; + private static BufferedImage lookedAtIcon; + private static BufferedImage revealedIcon; + private static BufferedImage exileIcon; private static BufferedImage imageCopyIcon; private static BufferedImage imageCounterGreen; private static BufferedImage imageCounterGrey; diff --git a/Mage.Client/src/main/resources/game/looked_at.png b/Mage.Client/src/main/resources/game/looked_at.png new file mode 100644 index 0000000000..0f679faa85 Binary files /dev/null and b/Mage.Client/src/main/resources/game/looked_at.png differ diff --git a/Mage.Client/src/main/resources/game/revealed.png b/Mage.Client/src/main/resources/game/revealed.png new file mode 100644 index 0000000000..c004949400 Binary files /dev/null and b/Mage.Client/src/main/resources/game/revealed.png differ diff --git a/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java b/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java index 0b43412b38..cafa72133a 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java +++ b/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java @@ -255,7 +255,6 @@ public class GameSessionPlayer extends GameSessionWatcher { list.add(new LookedAtView(entry.getKey(), entry.getValue(), game)); } gameView.setLookedAt(list); - game.getState().clearLookedAt(playerId); return gameView; } diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 49aa03847d..f9a2930de5 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1201,7 +1201,6 @@ public abstract class GameImpl implements Game, Serializable { applyEffects(); state.getPlayers().resetPassed(); fireUpdatePlayersEvent(); - state.getRevealed().reset(); resetShortLivingLKI(); break; } else { @@ -1980,6 +1979,8 @@ public abstract class GameImpl implements Game, Serializable { } logger.trace("fireUpdatePlayersEvent"); tableEventSource.fireTableEvent(EventType.UPDATE, null, this); + getState().clearLookedAt(); + getState().clearRevealed(); } @Override diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index 83236ef4e6..6f5db885c1 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -445,8 +445,12 @@ public class GameState implements Serializable, Copyable { return lookedAt.get(playerId); } - public void clearLookedAt(UUID playerId) { - lookedAt.remove(playerId); + public void clearRevealed() { + revealed.clear(); + } + + public void clearLookedAt() { + lookedAt.clear(); } public Turn getTurn() {