* Saved position and size of choice window during a game session.

This commit is contained in:
LevelX2 2015-05-06 16:58:14 +02:00
parent bc990ad24a
commit 4cf21739c4
4 changed files with 76 additions and 27 deletions

View file

@ -42,6 +42,7 @@ import mage.choices.Choice;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.util.SettingsManager; import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil; import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.MageDialogState;
/** /**
* *
@ -57,7 +58,7 @@ public class PickChoiceDialog extends MageDialog {
Choice choice; Choice choice;
boolean autoSelect; boolean autoSelect;
public void showDialog(Choice choice, UUID objectId) { public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) {
this.lblMessage.setText("<html>" + choice.getMessage()); this.lblMessage.setText("<html>" + choice.getMessage());
this.choice = choice; this.choice = choice;
this.autoSelect = false; this.autoSelect = false;
@ -77,10 +78,15 @@ public class PickChoiceDialog extends MageDialog {
} }
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER); MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
if (mageDialogState != null) {
Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); mageDialogState.setStateToDialog(this);
this.setLocation(centered.x, centered.y);
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, 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); this.setVisible(true);
} }

View file

@ -99,6 +99,7 @@ import mage.client.util.Config;
import mage.client.util.GameManager; import mage.client.util.GameManager;
import mage.client.util.audio.AudioManager; import mage.client.util.audio.AudioManager;
import mage.client.util.gui.ArrowBuilder; import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.MageDialogState;
import mage.constants.Constants; import mage.constants.Constants;
import mage.constants.EnlargeMode; import mage.constants.EnlargeMode;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
@ -154,15 +155,16 @@ public final class GamePanel extends javax.swing.JPanel {
private String chosenHandKey = "You"; private String chosenHandKey = "You";
private boolean smallMode = false; private boolean smallMode = false;
private boolean initialized = false; private boolean initialized = false;
private int lastUpdatedTurn;
private boolean menuNameSet = false; private boolean menuNameSet = false;
private boolean handCardsOfOpponentAvailable = false; private boolean handCardsOfOpponentAvailable = false;
private Map<String, Card> loadedCards = new HashMap<>(); private Map<String, Card> loadedCards = new HashMap<>();
private int storedHeight; private int storedHeight;
private Map<String, HoverButton> hoverButtons; private Map<String, HoverButton> hoverButtons;
private MageDialogState choiceWindowState;
public GamePanel() { public GamePanel() {
initComponents(); initComponents();
@ -455,7 +457,6 @@ public final class GamePanel extends javax.swing.JPanel {
public synchronized void init(GameView game) { public synchronized void init(GameView game) {
addPlayers(game); addPlayers(game);
updateGame(game); updateGame(game);
lastUpdatedTurn = game.getTurn();
} }
private void addPlayers(GameView game) { private void addPlayers(GameView game) {
@ -795,27 +796,13 @@ public final class GamePanel extends javax.swing.JPanel {
} }
private void showRevealed(GameView game) { private void showRevealed(GameView game) {
// List<String> toRemove = new ArrayList<String>();
// toRemove.addAll(revealed.keySet());
// for (ShowCardsDialog reveal: revealed.values()) {
// reveal.clearReloaded(); // seems not to be used
// }
for (RevealedView reveal: game.getRevealed()) { for (RevealedView reveal: game.getRevealed()) {
if (!revealed.containsKey(reveal.getName())) { if (!revealed.containsKey(reveal.getName())) {
ShowCardsDialog newReveal = new ShowCardsDialog(); ShowCardsDialog newReveal = new ShowCardsDialog();
revealed.put(reveal.getName(), newReveal); revealed.put(reveal.getName(), newReveal);
} }
revealed.get(reveal.getName()).loadCards("Revealed " + reveal.getName(), CardsViewUtil.convertSimple(reveal.getCards(), loadedCards), bigCard, Config.dimensions, gameId, false); 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) { private void showLookedAt(GameView game) {
@ -967,7 +954,7 @@ public final class GamePanel extends javax.swing.JPanel {
public void getChoice(Choice choice, UUID objectId) { public void getChoice(Choice choice, UUID objectId) {
hideAll(); hideAll();
PickChoiceDialog pickChoice = new PickChoiceDialog(); PickChoiceDialog pickChoice = new PickChoiceDialog();
pickChoice.showDialog(choice, objectId); pickChoice.showDialog(choice, objectId,choiceWindowState);
if (choice.isKeyChoice()) { if (choice.isKeyChoice()) {
if (pickChoice.isAutoSelect()) { if (pickChoice.isAutoSelect()) {
session.sendPlayerString(gameId, "#" + choice.getChoiceKey()); session.sendPlayerString(gameId, "#" + choice.getChoiceKey());
@ -977,6 +964,7 @@ public final class GamePanel extends javax.swing.JPanel {
} else { } else {
session.sendPlayerString(gameId, choice.getChoice()); session.sendPlayerString(gameId, choice.getChoice());
} }
choiceWindowState = new MageDialogState(pickChoice);
pickChoice.removeDialog(); pickChoice.removeDialog();
} }

View file

@ -12,10 +12,9 @@ import org.mage.card.arcane.UI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import mage.client.dialog.MageDialog;
import mage.constants.Rarity; import mage.constants.Rarity;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
public class GuiDisplayUtil { public class GuiDisplayUtil {
private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15); private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15);
@ -27,7 +26,7 @@ public class GuiDisplayUtil {
public int basicTextLength; public int basicTextLength;
public ArrayList<String> lines; public ArrayList<String> lines;
} }
public static JXPanel getDescription(CardView card, int width, int height) { public static JXPanel getDescription(CardView card, int width, int height) {
JXPanel descriptionPanel = new JXPanel(); JXPanel descriptionPanel = new JXPanel();

View file

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