* 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;
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.client.plugins.impl.Plugins;
import mage.client.util.CardsViewUtil;
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.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
@ -58,7 +69,7 @@ public class Cards extends javax.swing.JPanel {
private final Map<UUID, MageCard> cards = new LinkedHashMap<>();
private boolean dontDisplayTapped = false;
private static final int GAP_X = 5;
private static final int GAP_X = 0;
private String zone;
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,
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) {
if (!dialogManagers.containsKey(gameId)) {

View file

@ -23,7 +23,7 @@
<Layout>
<DimensionLayout dim="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>
</DimensionLayout>
<DimensionLayout dim="1">

View file

@ -34,16 +34,19 @@
package mage.client.dialog;
import static com.sun.java.accessibility.util.AWTEventMonitor.addWindowListener;
import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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.ImageHelper;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.view.CardsView;
@ -57,17 +60,19 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl;
*/
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 boolean positioned;
private String name;
public CardInfoWindowDialog(ShowType showType, String name) {
this.name = 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:
@ -78,6 +83,18 @@ public class CardInfoWindowDialog extends MageDialog {
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage()));
this.setClosable(true);
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:
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage()));
break;
@ -92,72 +109,38 @@ public class CardInfoWindowDialog extends MageDialog {
}
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();
}
cards.loadCards(showCards, bigCard, gameId);
showAndPositionWindow();
}
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);
}
}
cards.loadCards(showCards, bigCard, gameId, null);
if (showType.equals(ShowType.GRAVEYARD)) {
setTitle(name + "'s Graveyard (" + showCards.size() + ")");
this.setTitelBarToolTip(name);
}
else {
this.hideDialog();
}
showAndPositionWindow();
}
private void firstWindowPosition() {
private void showAndPositionWindow() {
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) {
int width = CardInfoWindowDialog.this.getWidth();
int height = CardInfoWindowDialog.this.getHeight();
if (width > 0 && height > 0) {
Point centered = SettingsManager.getInstance().getComponentPosition(width, height);
if (!positioned) {
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();
}
show();
}
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, CardInfoWindowDialog.this);
}
// ShowCardsDialog.this.setVisible(true);
}
});
});
}
public void loadCards(ExileView exile, BigCard bigCard, UUID gameId) {
@ -197,7 +180,7 @@ public class CardInfoWindowDialog extends MageDialog {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
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.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<String, CardInfoWindowDialog> revealed = 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 UUID gameId;
private UUID playerId; // playerId of the player
@ -261,6 +263,10 @@ public final class GamePanel extends javax.swing.JPanel {
exileDialog.cleanUp();
exileDialog.removeDialog();
}
for (CardInfoWindowDialog graveyardDialog: graveyardWindows.values()) {
graveyardDialog.cleanUp();
graveyardDialog.removeDialog();
}
for (CardInfoWindowDialog revealDialog: revealed.values()) {
revealDialog.cleanUp();
revealDialog.removeDialog();
@ -650,6 +656,17 @@ public final class GamePanel extends javax.swing.JPanel {
if (player.getPlayerId().equals(playerId)) {
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 {
logger.warn("Couldn't find player.");
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);
}
showRevealed(game);
showLookedAt(game);
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) {
for (RevealedView revealView: game.getRevealed()) {
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) {
message = getSmallText(message);
} else {
message = "Use ability?" + getSmallText(message.substring(this.getWidth() / 10));
message = "Use ability?" + getSmallText(message.substring(0, this.getWidth() / 10));
}
}
textArea.setText(message);

View file

@ -34,6 +34,28 @@
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.cards.MageCard;
import mage.cards.action.ActionCallback;
@ -60,20 +82,6 @@ import mage.view.ManaPoolView;
import mage.view.PlayerView;
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.
*
@ -787,11 +795,12 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}
private void btnGraveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraveActionPerformed
MageFrame.getGame(gameId).openGraveyardWindow(player.getName());
/*if (graveyard == null) {
graveyard = new ShowCardsDialog();
}*/
//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) {