* Reworked handling of revealed and look at windows. Windows can stay open now and moved to a position and stay there.

This commit is contained in:
LevelX2 2015-06-21 23:49:16 +02:00
parent 3a57485501
commit 87f919ecac
12 changed files with 232 additions and 63 deletions

View file

@ -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);
}
}
}

View file

@ -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<String, Serializable> 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();

View file

@ -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<UUID, PlayAreaPanel> players = new HashMap<>();
private final Map<UUID, ExileZoneDialog> exiles = new HashMap<>();
private final Map<String, ShowCardsDialog> revealed = new HashMap<>();
private final Map<String, ShowCardsDialog> lookedAt = new HashMap<>();
private final Map<UUID, CardInfoWindowDialog> exiles = new HashMap<>();
private final Map<String, CardInfoWindowDialog> revealed = new HashMap<>();
private final Map<String, CardInfoWindowDialog> lookedAt = new HashMap<>();
private final ArrayList<ShowCardsDialog> 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<String, CardInfoWindowDialog> 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<String, CardInfoWindowDialog> windowMap) {
// Remove closed window objects from the maps
for (Iterator<Map.Entry<String, CardInfoWindowDialog>> iterator = windowMap.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, CardInfoWindowDialog> 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);

View file

@ -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");
}

View file

@ -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();

View file

@ -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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -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;
}

View file

@ -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

View file

@ -445,8 +445,12 @@ public class GameState implements Serializable, Copyable<GameState> {
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() {