* Changed graveyard window handling to a window that can stay open.

This commit is contained in:
LevelX2 2015-06-23 00:46:27 +02:00
parent 259ef3aed5
commit 67e9ee1fa9
7 changed files with 120 additions and 81 deletions

View file

@ -34,20 +34,31 @@
package mage.client.cards; package mage.client.cards;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import mage.cards.MageCard; import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.CardsViewUtil; import mage.client.util.CardsViewUtil;
import mage.client.util.Config; import mage.client.util.Config;
import mage.view.*; import mage.view.CardView;
import mage.view.CardsView;
import mage.view.PermanentView;
import mage.view.SimpleCardsView;
import mage.view.StackAbilityView;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.card.arcane.CardPanel; import org.mage.card.arcane.CardPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.*;
import java.util.Map.Entry;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -58,7 +69,7 @@ public class Cards extends javax.swing.JPanel {
private final Map<UUID, MageCard> cards = new LinkedHashMap<>(); private final Map<UUID, MageCard> cards = new LinkedHashMap<>();
private boolean dontDisplayTapped = false; private boolean dontDisplayTapped = false;
private static final int GAP_X = 5; private static final int GAP_X = 0;
private String zone; private String zone;
private static final Border emptyBorder = new EmptyBorder(0,0,0,0); private static final Border emptyBorder = new EmptyBorder(0,0,0,0);

View file

@ -20,7 +20,7 @@ import java.util.UUID;
public class DialogManager extends JComponent implements MouseListener, public class DialogManager extends JComponent implements MouseListener,
MouseMotionListener { MouseMotionListener {
private final static Map<UUID, DialogManager> dialogManagers = new HashMap<UUID, DialogManager>(); private final static Map<UUID, DialogManager> dialogManagers = new HashMap<>();
public static DialogManager getManager(UUID gameId) { public static DialogManager getManager(UUID gameId) {
if (!dialogManagers.containsKey(gameId)) { if (!dialogManagers.containsKey(gameId)) {

View file

@ -23,7 +23,7 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="cards" alignment="1" pref="418" max="32767" attributes="0"/> <Component id="cards" alignment="1" pref="239" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">

View file

@ -34,16 +34,19 @@
package mage.client.dialog; package mage.client.dialog;
import static com.sun.java.accessibility.util.AWTEventMonitor.addWindowListener;
import java.awt.Point; import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.ImageHelper;
import mage.client.util.SettingsManager; import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil; import mage.client.util.gui.GuiDisplayUtil;
import mage.view.CardsView; import mage.view.CardsView;
@ -57,17 +60,19 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl;
*/ */
public class CardInfoWindowDialog extends MageDialog { public class CardInfoWindowDialog extends MageDialog {
public static enum ShowType { REVEAL, LOOKED_AT, EXILE, OTHER }; public static enum ShowType { REVEAL, LOOKED_AT, EXILE, GRAVEYARD, OTHER };
private ShowType showType; private ShowType showType;
private boolean positioned; private boolean positioned;
private String name;
public CardInfoWindowDialog(ShowType showType, String name) { public CardInfoWindowDialog(ShowType showType, String name) {
this.name = name;
this.title = name; this.title = name;
this.showType = showType; this.showType = showType;
this.positioned = false; this.positioned = false;
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents(); initComponents();
this.setModal(false); this.setModal(false);
switch(this.showType) { switch(this.showType) {
case LOOKED_AT: case LOOKED_AT:
@ -78,6 +83,18 @@ public class CardInfoWindowDialog extends MageDialog {
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage())); this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage()));
this.setClosable(true); this.setClosable(true);
break; break;
case GRAVEYARD:
this.setFrameIcon(new ImageIcon(ImageHelper.getImageFromResources("/info/grave.png")));
this.setIconifiable(false);
this.setClosable(true);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CardInfoWindowDialog.this.hideDialog();
}
});
break;
case EXILE: case EXILE:
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage())); this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage()));
break; break;
@ -92,71 +109,37 @@ public class CardInfoWindowDialog extends MageDialog {
} }
public void loadCards(SimpleCardsView showCards, BigCard bigCard, UUID gameId) { public void loadCards(SimpleCardsView showCards, BigCard bigCard, UUID gameId) {
cards.loadCards(showCards, bigCard, gameId);
boolean changed = cards.loadCards(showCards, bigCard, gameId); showAndPositionWindow();
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) { public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
boolean changed = cards.loadCards(showCards, bigCard, gameId, null); cards.loadCards(showCards, bigCard, gameId, null);
if (showType.equals(ShowType.GRAVEYARD)) {
if (showCards.size() > 0) { setTitle(name + "'s Graveyard (" + showCards.size() + ")");
show(); this.setTitelBarToolTip(name);
if (changed) {
try {
if (!positioned) {
this.setIcon(false);
firstWindowPosition();
} else {
}
} catch (PropertyVetoException ex) {
Logger.getLogger(CardInfoWindowDialog.class.getName()).log(Level.SEVERE, null, ex);
} }
showAndPositionWindow();
} }
} private void showAndPositionWindow() {
else {
this.hideDialog();
}
}
private void firstWindowPosition() {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!positioned) {
int width = CardInfoWindowDialog.this.getWidth(); int width = CardInfoWindowDialog.this.getWidth();
int height = CardInfoWindowDialog.this.getHeight(); int height = CardInfoWindowDialog.this.getHeight();
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
positioned = true;
Point centered = SettingsManager.getInstance().getComponentPosition(width, height); Point centered = SettingsManager.getInstance().getComponentPosition(width, height);
if (!positioned) {
positioned = true;
int xPos = centered.x / 2; int xPos = centered.x / 2;
int yPos = centered.y / 2; int yPos = centered.y / 2;
CardInfoWindowDialog.this.setLocation(xPos, yPos); CardInfoWindowDialog.this.setLocation(xPos, yPos);
show();
}
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, CardInfoWindowDialog.this); GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, CardInfoWindowDialog.this);
CardInfoWindowDialog.this.show();
} }
} }
// ShowCardsDialog.this.setVisible(true);
}
}); });
} }
@ -197,7 +180,7 @@ public class CardInfoWindowDialog extends MageDialog {
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cards, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE) .addComponent(cards, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

View file

@ -148,6 +148,8 @@ public final class GamePanel extends javax.swing.JPanel {
private final Map<UUID, CardInfoWindowDialog> exiles = new HashMap<>(); private final Map<UUID, CardInfoWindowDialog> exiles = new HashMap<>();
private final Map<String, CardInfoWindowDialog> revealed = new HashMap<>(); private final Map<String, CardInfoWindowDialog> revealed = new HashMap<>();
private final Map<String, CardInfoWindowDialog> lookedAt = new HashMap<>(); private final Map<String, CardInfoWindowDialog> lookedAt = new HashMap<>();
private final Map<String, CardInfoWindowDialog> graveyardWindows = new HashMap<>();
private final Map<String, CardsView> graveyards = new HashMap<>();
private final ArrayList<ShowCardsDialog> pickTarget = new ArrayList<>(); private final ArrayList<ShowCardsDialog> pickTarget = new ArrayList<>();
private UUID gameId; private UUID gameId;
private UUID playerId; // playerId of the player private UUID playerId; // playerId of the player
@ -261,6 +263,10 @@ public final class GamePanel extends javax.swing.JPanel {
exileDialog.cleanUp(); exileDialog.cleanUp();
exileDialog.removeDialog(); exileDialog.removeDialog();
} }
for (CardInfoWindowDialog graveyardDialog: graveyardWindows.values()) {
graveyardDialog.cleanUp();
graveyardDialog.removeDialog();
}
for (CardInfoWindowDialog revealDialog: revealed.values()) { for (CardInfoWindowDialog revealDialog: revealed.values()) {
revealDialog.cleanUp(); revealDialog.cleanUp();
revealDialog.removeDialog(); revealDialog.removeDialog();
@ -650,6 +656,17 @@ public final class GamePanel extends javax.swing.JPanel {
if (player.getPlayerId().equals(playerId)) { if (player.getPlayerId().equals(playerId)) {
updateSkipButtons(player.isPassedTurn(), player.isPassedUntilEndOfTurn(), player.isPassedUntilNextMain(), player.isPassedAllTurns(), player.isPassedUntilStackResolved()); updateSkipButtons(player.isPassedTurn(), player.isPassedUntilEndOfTurn(), player.isPassedUntilNextMain(), player.isPassedAllTurns(), player.isPassedUntilStackResolved());
} }
// update open or remove closed graveyard windows
graveyards.put(player.getName(), player.getGraveyard());
if (graveyardWindows.containsKey(player.getName())) {
CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(player.getName());
if (cardInfoWindowDialog.isClosed()) {
graveyardWindows.remove(player.getName());
} else {
cardInfoWindowDialog.loadCards(player.getGraveyard(), bigCard, gameId);
}
}
} else { } else {
logger.warn("Couldn't find player."); logger.warn("Couldn't find player.");
logger.warn(" uuid:" + player.getPlayerId()); logger.warn(" uuid:" + player.getPlayerId());
@ -691,6 +708,7 @@ public final class GamePanel extends javax.swing.JPanel {
} }
exiles.get(exile.getId()).loadCards(exile, bigCard, gameId); exiles.get(exile.getId()).loadCards(exile, bigCard, gameId);
} }
showRevealed(game); showRevealed(game);
showLookedAt(game); showLookedAt(game);
if (game.getCombat().size() > 0) { if (game.getCombat().size() > 0) {
@ -808,6 +826,24 @@ public final class GamePanel extends javax.swing.JPanel {
} }
} }
public void openGraveyardWindow(String playerName) {
if(graveyardWindows.containsKey(playerName)) {
CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(playerName);
if (cardInfoWindowDialog.isVisible()) {
cardInfoWindowDialog.hideDialog();
} else {
cardInfoWindowDialog.show();
}
// if (!cardInfoWindowDialog.isClosed()) {
return;
// }
}
CardInfoWindowDialog newGraveyard = new CardInfoWindowDialog(ShowType.GRAVEYARD, playerName);
graveyardWindows.put(playerName, newGraveyard);
MageFrame.getDesktop().add(newGraveyard, JLayeredPane.MODAL_LAYER);
newGraveyard.loadCards(graveyards.get(playerName), bigCard, gameId);
}
private void showRevealed(GameView game) { private void showRevealed(GameView game) {
for (RevealedView revealView: game.getRevealed()) { for (RevealedView revealView: game.getRevealed()) {
handleGameInfoWindow(revealed, ShowType.REVEAL, revealView.getName(), revealView.getCards()); handleGameInfoWindow(revealed, ShowType.REVEAL, revealView.getName(), revealView.getCards());

View file

@ -226,7 +226,7 @@ public class HelperPanel extends JPanel {
if (message.length() < this.getWidth() / 10) { if (message.length() < this.getWidth() / 10) {
message = getSmallText(message); message = getSmallText(message);
} else { } else {
message = "Use ability?" + getSmallText(message.substring(this.getWidth() / 10)); message = "Use ability?" + getSmallText(message.substring(0, this.getWidth() / 10));
} }
} }
textArea.setText(message); textArea.setText(message);

View file

@ -34,6 +34,28 @@
package mage.client.game; package mage.client.game;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import mage.MageException; import mage.MageException;
import mage.cards.MageCard; import mage.cards.MageCard;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
@ -60,20 +82,6 @@ import mage.view.ManaPoolView;
import mage.view.PlayerView; import mage.view.PlayerView;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
/** /**
* Enhanced player pane. * Enhanced player pane.
* *
@ -787,11 +795,12 @@ public class PlayerPanelExt extends javax.swing.JPanel {
} }
private void btnGraveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraveActionPerformed private void btnGraveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraveActionPerformed
MageFrame.getGame(gameId).openGraveyardWindow(player.getName());
/*if (graveyard == null) { /*if (graveyard == null) {
graveyard = new ShowCardsDialog(); graveyard = new ShowCardsDialog();
}*/ }*/
//graveyard.loadCards(player.getName() + " graveyard", player.getGraveyard(), bigCard, Config.dimensions, gameId, false); //graveyard.loadCards(player.getName() + " graveyard", player.getGraveyard(), bigCard, Config.dimensions, gameId, false);
DialogManager.getManager(gameId).showGraveyardDialog(player.getGraveyard(), bigCard, gameId); // DialogManager.getManager(gameId).showGraveyardDialog(player.getGraveyard(), bigCard, gameId);
} }
private void btnCommandZoneActionPerformed(java.awt.event.ActionEvent evt) { private void btnCommandZoneActionPerformed(java.awt.event.ActionEvent evt) {