From 4cf21739c488046196daa525ae70504306e9a465 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 6 May 2015 16:58:14 +0200 Subject: [PATCH] * Saved position and size of choice window during a game session. --- .../mage/client/dialog/PickChoiceDialog.java | 16 ++++-- .../main/java/mage/client/game/GamePanel.java | 26 +++------ .../mage/client/util/gui/GuiDisplayUtil.java | 5 +- .../mage/client/util/gui/MageDialogState.java | 56 +++++++++++++++++++ 4 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 Mage.Client/src/main/java/mage/client/util/gui/MageDialogState.java diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java index 818dc2fd96..dbf884f23d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java @@ -42,6 +42,7 @@ import mage.choices.Choice; import mage.client.MageFrame; import mage.client.util.SettingsManager; import mage.client.util.gui.GuiDisplayUtil; +import mage.client.util.gui.MageDialogState; /** * @@ -57,7 +58,7 @@ public class PickChoiceDialog extends MageDialog { Choice choice; boolean autoSelect; - public void showDialog(Choice choice, UUID objectId) { + public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) { this.lblMessage.setText("" + choice.getMessage()); this.choice = choice; this.autoSelect = false; @@ -77,10 +78,15 @@ public class PickChoiceDialog extends MageDialog { } MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER); - - Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); - this.setLocation(centered.x, centered.y); - GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); + if (mageDialogState != null) { + mageDialogState.setStateToDialog(this); + + } else { + Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); + this.setLocation(centered.x, centered.y); + GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); + } + this.setVisible(true); } 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 a1ba349b4e..396ae4a322 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -99,6 +99,7 @@ import mage.client.util.Config; import mage.client.util.GameManager; import mage.client.util.audio.AudioManager; import mage.client.util.gui.ArrowBuilder; +import mage.client.util.gui.MageDialogState; import mage.constants.Constants; import mage.constants.EnlargeMode; import mage.constants.PhaseStep; @@ -154,15 +155,16 @@ public final class GamePanel extends javax.swing.JPanel { private String chosenHandKey = "You"; private boolean smallMode = false; private boolean initialized = false; - private int lastUpdatedTurn; + private boolean menuNameSet = false; private boolean handCardsOfOpponentAvailable = false; private Map loadedCards = new HashMap<>(); - private int storedHeight; - + private int storedHeight; private Map hoverButtons; + + private MageDialogState choiceWindowState; public GamePanel() { initComponents(); @@ -455,7 +457,6 @@ public final class GamePanel extends javax.swing.JPanel { public synchronized void init(GameView game) { addPlayers(game); updateGame(game); - lastUpdatedTurn = game.getTurn(); } private void addPlayers(GameView game) { @@ -795,27 +796,13 @@ public final class GamePanel extends javax.swing.JPanel { } private void showRevealed(GameView game) { -// List toRemove = new ArrayList(); -// toRemove.addAll(revealed.keySet()); -// for (ShowCardsDialog reveal: revealed.values()) { -// reveal.clearReloaded(); // seems not to be used -// } 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(), CardsViewUtil.convertSimple(reveal.getCards(), loadedCards), bigCard, Config.dimensions, gameId, false); -// toRemove.add(reveal.getName()); } -// for (String revealName: toRemove) { -// ShowCardsDialog revealDialog = revealed.get(revealName); -// if (revealDialog != null) { -// revealed.remove(revealName); -// revealDialog.cleanUp(); -// revealDialog.removeDialog(); -// } -// } } private void showLookedAt(GameView game) { @@ -967,7 +954,7 @@ public final class GamePanel extends javax.swing.JPanel { public void getChoice(Choice choice, UUID objectId) { hideAll(); PickChoiceDialog pickChoice = new PickChoiceDialog(); - pickChoice.showDialog(choice, objectId); + pickChoice.showDialog(choice, objectId,choiceWindowState); if (choice.isKeyChoice()) { if (pickChoice.isAutoSelect()) { session.sendPlayerString(gameId, "#" + choice.getChoiceKey()); @@ -977,6 +964,7 @@ public final class GamePanel extends javax.swing.JPanel { } else { session.sendPlayerString(gameId, choice.getChoice()); } + choiceWindowState = new MageDialogState(pickChoice); pickChoice.removeDialog(); } 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 51be991cda..17e64cc600 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 @@ -12,10 +12,9 @@ import org.mage.card.arcane.UI; import javax.swing.*; import java.awt.*; -import java.net.URL; import java.util.ArrayList; +import mage.client.dialog.MageDialog; import mage.constants.Rarity; -import org.mage.plugins.card.utils.impl.ImageManagerImpl; public class GuiDisplayUtil { private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15); @@ -27,7 +26,7 @@ public class GuiDisplayUtil { public int basicTextLength; public ArrayList lines; } - + public static JXPanel getDescription(CardView card, int width, int height) { JXPanel descriptionPanel = new JXPanel(); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/MageDialogState.java b/Mage.Client/src/main/java/mage/client/util/gui/MageDialogState.java new file mode 100644 index 0000000000..41b40a8d69 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/util/gui/MageDialogState.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.client.util.gui; + +import java.awt.Dimension; +import mage.client.dialog.MageDialog; + +/** + * Holds the position and size of MageDialogs. + * + * @author LevelX2 + */ +public class MageDialogState { + + Dimension dimension; + int xPos; + int yPos; + + public MageDialogState(MageDialog mageDialog) { + this.dimension = mageDialog.getSize(); + this.xPos = mageDialog.getX(); + this.yPos = mageDialog.getY(); + } + + public boolean setStateToDialog(MageDialog mageDialog) { + mageDialog.setSize(dimension); + mageDialog.setLocation(xPos, yPos); + GuiDisplayUtil.keepComponentInsideScreen(xPos, yPos, mageDialog); + return true; + } +} \ No newline at end of file