* Added logic to auto select replacement effects. Some changes to counter size and font size handling.

This commit is contained in:
LevelX2 2014-10-30 20:40:23 +01:00
parent ab9c0ae893
commit df71237f46
28 changed files with 445 additions and 140 deletions

View file

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
<Property name="resizable" type="boolean" value="true"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[280, 200]"/>
</Property>
<Property name="name" type="java.lang.String" value="" noResource="true"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
@ -24,6 +31,9 @@
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="335" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="btnAutoSelect" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
@ -37,21 +47,31 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<Component id="lblMessage" min="-2" pref="37" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblMessage" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="165" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="158" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnAutoSelect" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="btnAutoSelect">
<Properties>
<Property name="text" type="java.lang.String" value="Auto select"/>
<Property name="toolTipText" type="java.lang.String" value="If you select an effect with &quot;Auto select&quot;, this effect will be selected the next time automatically first."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAutoSelectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>

View file

@ -34,13 +34,15 @@
package mage.client.dialog;
import java.awt.Point;
import java.util.Map;
import java.util.UUID;
import javax.swing.JLayeredPane;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import javax.swing.*;
import java.awt.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -52,10 +54,28 @@ public class PickChoiceDialog extends MageDialog {
initComponents();
this.setModal(true);
}
Choice choice;
boolean autoSelect;
public void showDialog(String message, String[] choices) {
this.lblMessage.setText(message);
this.lstChoices.setListData(choices);
public void showDialog(Choice choice, UUID objectId) {
this.lblMessage.setText("<html>" + choice.getMessage());
this.choice = choice;
this.autoSelect = false;
btnAutoSelect.setVisible(choice.isKeyChoice());
if (choice.isKeyChoice()){
ComboItem[] comboItems = new ComboItem[choice.getKeyChoices().size()];
int count = 0;
for (Map.Entry<String, String> entry : choice.getKeyChoices().entrySet()) {
comboItems[count] = new ComboItem(entry.getKey(), entry.getValue());
count++;
}
this.lstChoices.setListData(comboItems);
} else {
this.lstChoices.setListData(choice.getChoices().toArray());
}
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight());
@ -65,8 +85,21 @@ public class PickChoiceDialog extends MageDialog {
this.setVisible(true);
}
public String getChoice() {
return (String)this.lstChoices.getSelectedValue();
public boolean isAutoSelect() {
return autoSelect;
}
public void setChoice() {
if (this.lstChoices.getSelectedValue() == null) {
choice.clearChoice();
}
if (choice.isKeyChoice()) {
ComboItem item = (ComboItem)this.lstChoices.getSelectedValue();
choice.setChoiceByKey(item.getValue());
} else {
choice.setChoice((String)this.lstChoices.getSelectedValue());
}
}
/** This method is called from within the constructor to
@ -78,12 +111,25 @@ public class PickChoiceDialog extends MageDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
btnAutoSelect = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
btnOk = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
lstChoices = new javax.swing.JList();
lblMessage = new javax.swing.JLabel();
setResizable(true);
setMinimumSize(new java.awt.Dimension(280, 200));
setName(""); // NOI18N
btnAutoSelect.setText("Auto select");
btnAutoSelect.setToolTipText("If you select an effect with \"Auto select\", this effect will be selected the next time automatically first.");
btnAutoSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAutoSelectActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -117,6 +163,9 @@ public class PickChoiceDialog extends MageDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(btnAutoSelect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
@ -126,30 +175,40 @@ public class PickChoiceDialog extends MageDialog {
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblMessage)
.addGap(6, 6, 6)
.addComponent(lblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnOk))
.addContainerGap())
.addComponent(btnOk)
.addComponent(btnAutoSelect))
.addGap(10, 10, 10))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
setChoice();
this.hideDialog();
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.lstChoices.clearSelection();
this.choice.clearChoice();
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnAutoSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSelectActionPerformed
this.autoSelect = true;
setChoice();
this.hideDialog();
}//GEN-LAST:event_btnAutoSelectActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAutoSelect;
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOk;
private javax.swing.JScrollPane jScrollPane1;
@ -158,3 +217,26 @@ public class PickChoiceDialog extends MageDialog {
// End of variables declaration//GEN-END:variables
}
class ComboItem {
private final String value;
private final String label;
public ComboItem(String value, String label) {
this.value = value;
this.label = label;
}
public String getValue() {
return this.value;
}
public String getLabel() {
return this.label;
}
@Override
public String toString() {
return label;
}
}

View file

@ -27,8 +27,53 @@
*/
package mage.client.game;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import mage.cards.Card;
import mage.cards.action.ActionCallback;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.chat.ChatPanel;
@ -37,7 +82,12 @@ 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.*;
import mage.client.dialog.ExileZoneDialog;
import mage.client.dialog.PickChoiceDialog;
import mage.client.dialog.PickNumberDialog;
import mage.client.dialog.PickPileDialog;
import mage.client.dialog.PreferencesDialog;
import mage.client.dialog.ShowCardsDialog;
import mage.client.game.FeedbackPanel.FeedbackMode;
import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins;
@ -48,25 +98,31 @@ import mage.client.util.gui.ArrowBuilder;
import mage.constants.Constants;
import mage.constants.EnlargeMode;
import mage.constants.PhaseStep;
import static mage.constants.PhaseStep.BEGIN_COMBAT;
import static mage.constants.PhaseStep.COMBAT_DAMAGE;
import static mage.constants.PhaseStep.DECLARE_ATTACKERS;
import static mage.constants.PhaseStep.DECLARE_BLOCKERS;
import static mage.constants.PhaseStep.DRAW;
import static mage.constants.PhaseStep.END_COMBAT;
import static mage.constants.PhaseStep.END_TURN;
import static mage.constants.PhaseStep.FIRST_COMBAT_DAMAGE;
import static mage.constants.PhaseStep.UNTAP;
import static mage.constants.PhaseStep.UPKEEP;
import mage.constants.PlayerAction;
import mage.remote.Session;
import mage.view.*;
import mage.view.AbilityPickerView;
import mage.view.CardView;
import mage.view.CardsView;
import mage.view.ExileView;
import mage.view.GameView;
import mage.view.LookedAtView;
import mage.view.MatchView;
import mage.view.PlayerView;
import mage.view.RevealedView;
import mage.view.SimpleCardsView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
import java.util.*;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.border.EmptyBorder;
import mage.constants.PlayerAction;
/**
*
@ -797,11 +853,19 @@ public final class GamePanel extends javax.swing.JPanel {
}
}
public void getChoice(String message, String[] choices) {
public void getChoice(Choice choice, UUID objectId) {
hideAll();
PickChoiceDialog pickChoice = new PickChoiceDialog();
pickChoice.showDialog(message, choices);
session.sendPlayerString(gameId, pickChoice.getChoice());
pickChoice.showDialog(choice, objectId);
if (choice.isKeyChoice()) {
if (pickChoice.isAutoSelect()) {
session.sendPlayerString(gameId, "#" + choice.getChoiceKey());
} else {
session.sendPlayerString(gameId, choice.getChoiceKey());
}
} else {
session.sendPlayerString(gameId, choice.getChoice());
}
pickChoice.removeDialog();
}
@ -1367,7 +1431,7 @@ public final class GamePanel extends javax.swing.JPanel {
.addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
)
//.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
.addGroup(gl_jPanel3.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_jPanel3.createSequentialGroup()
.addComponent(pnlShortCuts, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(0)

View file

@ -216,6 +216,19 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
});
menuItem = new JMenuItem("Replacement effects - reset auto select");
menuItem.setMnemonic(KeyEvent.VK_R);
menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game.");
popupMenu.add(menuItem);
// Reset the replacement effcts that were auto selected for the game
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gamePanel.getSession().sendPlayerAction(PlayerAction.RESET_AUTO_SELECT_REPLACEMENT_EFFECTS, gameId);
}
});
popupMenu.addSeparator();
menuItem = new JMenuItem("Concede game");

View file

@ -32,6 +32,7 @@ import java.util.UUID;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import static mage.client.chat.ChatPanel.ChatType.TABLES;
@ -72,7 +73,7 @@ public class CallbackClientImpl implements CallbackClient {
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
private final MageFrame frame;
private int messageId = 0;
// private int gameInformMessageId = 0;
private int gameInformMessageId = 0;
public CallbackClientImpl(MageFrame frame) {
this.frame = frame;
@ -244,12 +245,13 @@ public class CallbackClientImpl implements CallbackClient {
panel.pickPile(message.getMessage(), message.getPile1(), message.getPile2());
} break;
}
case "gameChoose":
case "gameChooseChoice":
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.getChoice(message.getMessage(), message.getStrings());
panel.getChoice(message.getChoice(), callback.getObjectId());
} break;
}
case "gamePlayMana":
@ -292,20 +294,20 @@ public class CallbackClientImpl implements CallbackClient {
JOptionPane.showMessageDialog(null, messageData.get(1), messageData.get(0), JOptionPane.WARNING_MESSAGE);
} break;
case "gameInform":
// if (callback.getMessageId() > gameInformMessageId) {
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId());
if (callback.getMessageId() > gameInformMessageId) {
{
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId());
}
}
}
// no longer needed because phase skip handling on server side now
// } else {
// logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod()));
// //logger.warn("message out of sequence - ignoring");
// }
// gameInformMessageId = messageId;
} else {
logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod()));
//logger.warn("message out of sequence - ignoring");
}
gameInformMessageId = messageId;
break;
case "gameInformPersonal":
{

View file

@ -12,6 +12,8 @@ import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
@ -60,7 +62,7 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl;
* @author arcane, nantuko, noxx
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener, MouseWheelListener {
public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener {
private static final long serialVersionUID = -3272134219262184410L;
private static final Logger log = Logger.getLogger(CardPanel.class);
@ -83,6 +85,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private static final float ROT_CENTER_TO_BOTTOM_CORNER = 0.7071067811865475244008443621048f;
public CardView gameCard;
public CardView updateCard;
// for two faced cards
public CardView temporary;
@ -259,7 +262,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
addMouseListener(this);
addMouseMotionListener(this);
addMouseWheelListener(this);
addComponentListener(this);
displayTitleAnyway = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_CARD_NAMES, "true").equals("true");
titleText = new GlowText();
setText(gameCard);
@ -532,7 +536,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
}
@Override
public void layout() {
public void doLayout() {
int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE);
imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
@ -764,6 +768,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
@Override
public void update(CardView card) {
this.updateCard = card;
if (isPermanent && (card instanceof PermanentView)) {
boolean needsTapping = isTapped() != ((PermanentView) card).isTapped();
boolean needsFlipping = isFlipped() != ((PermanentView) card).isFlipped();
@ -886,7 +891,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private static ImageIcon getCounterImageWithAmount(int amount, BufferedImage image, int cardWidth) {
int factor = cardWidth > WIDTH_LIMIT ? 2 :1;
int xOffset = amount > 9 ? 2 : 5;
int fontSize = amount < 10 ? 9 : amount < 100 ? 9 : 8;
int fontSize = factor == 1 ? amount < 10 ? 12 : amount < 100 ? 10 : amount < 1000 ? 7: 6
:amount < 10 ? 19 : amount < 100 ? 15 : amount < 1000 ? 12: amount < 10000 ?9 : 8;
BufferedImage newImage;
if (cardWidth > WIDTH_LIMIT) {
newImage = ImageManagerImpl.deepCopy(image);
@ -895,7 +901,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
}
Graphics graphics = newImage.getGraphics();
graphics.setColor(Color.BLACK);
graphics.setFont(new Font("Arial Black", Font.BOLD, factor * fontSize ));
graphics.setFont(new Font("Arial Black", amount > 100 ? Font.PLAIN : Font.BOLD, fontSize ));
graphics.drawString(Integer.toString(amount), xOffset * factor, 11 * factor);
return new ImageIcon(newImage);
}
@ -1151,4 +1157,26 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public JPanel getCardArea() {
return cardArea;
}
@Override
public void componentResized(ComponentEvent ce) {
doLayout();
if (updateCard != null) {
update(updateCard);
}
}
@Override
public void componentMoved(ComponentEvent ce) {
}
@Override
public void componentShown(ComponentEvent ce) {
}
@Override
public void componentHidden(ComponentEvent ce) {
}
}