mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
[UI]Alt+E:enlarge card. New game panel layout (experimental).
This commit is contained in:
parent
01f57aa06e
commit
fc2283898c
7 changed files with 209 additions and 48 deletions
|
@ -36,12 +36,10 @@ package mage.client;
|
|||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardsStorage;
|
||||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.MageJDesktop;
|
||||
import mage.client.components.MageRoundPane;
|
||||
import mage.client.components.MageUI;
|
||||
import mage.client.components.*;
|
||||
import mage.client.components.ext.dlg.DialogManager;
|
||||
import mage.client.constants.Constants.DeckEditorMode;
|
||||
import mage.client.deckeditor.DeckEditorPane;
|
||||
|
@ -337,6 +335,23 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
ui.addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane);
|
||||
ui.addComponent(MageComponents.POPUP_CONTAINER, popupContainer);
|
||||
|
||||
JPanel cardPreviewContainer = new JPanel();
|
||||
cardPreviewContainer.setOpaque(false);
|
||||
cardPreviewContainer.setLayout(null);
|
||||
BigCard bigCard = new BigCard();
|
||||
bigCard.setSize(320, 500);
|
||||
bigCard.setLocation(40, 40);
|
||||
bigCard.setBackground(new Color(0, 0, 0, 0));
|
||||
|
||||
cardPreviewContainer.add(bigCard);
|
||||
cardPreviewContainer.setVisible(false);
|
||||
cardPreviewContainer.setBounds(0, 0, 320 + 80, 500 + 30);
|
||||
|
||||
ui.addComponent(MageComponents.CARD_PREVIEW_PANE, bigCard);
|
||||
ui.addComponent(MageComponents.CARD_PREVIEW_CONTAINER, cardPreviewContainer);
|
||||
|
||||
desktopPane.add(cardPreviewContainer, JLayeredPane.POPUP_LAYER);
|
||||
}
|
||||
|
||||
private void setBackground() {
|
||||
|
|
|
@ -80,6 +80,8 @@ public class BigCard extends JComponent {
|
|||
initBounds();
|
||||
}
|
||||
setDoubleBuffered(true);
|
||||
setOpaque(true);
|
||||
scrollPane.setOpaque(true);
|
||||
}
|
||||
|
||||
protected void initBounds() {
|
||||
|
|
|
@ -7,7 +7,9 @@ public enum MageComponents {
|
|||
TABLE_WAITING_START_BUTTON("btnStart"),
|
||||
DESKTOP_PANE("desktopPane"),
|
||||
CARD_INFO_PANE("cardInfoPane"),
|
||||
POPUP_CONTAINER("popupContainer");
|
||||
POPUP_CONTAINER("popupContainer"),
|
||||
CARD_PREVIEW_PANE("cardPreviewPane"),
|
||||
CARD_PREVIEW_CONTAINER("cardPreviewContainer");
|
||||
|
||||
private String name;
|
||||
MageComponents(String name) {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
package mage.client.game;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.chat.ChatPanel;
|
||||
|
@ -43,6 +44,7 @@ import mage.client.components.MageComponents;
|
|||
import mage.client.components.ext.dlg.DialogManager;
|
||||
import mage.client.dialog.*;
|
||||
import mage.client.game.FeedbackPanel.FeedbackMode;
|
||||
import mage.client.plugins.adapters.MageActionCallback;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.GameManager;
|
||||
|
@ -53,7 +55,6 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import javax.swing.*;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
@ -129,12 +130,12 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
/*SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bigCard.setDefaultImage();
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
private Map<String, JComponent> getUIComponents(JLayeredPane jLayeredPane) {
|
||||
|
@ -736,14 +737,34 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
|
||||
|
||||
this.getInputMap(c).put(ks, "PRESS");
|
||||
this.getActionMap().put("PRESS", new AbstractAction() {
|
||||
this.getInputMap(c).put(ks, "F4_PRESS");
|
||||
this.getActionMap().put("F4_PRESS", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
btnEndTurnActionPerformed(null);
|
||||
}
|
||||
});
|
||||
|
||||
KeyStroke ksAltShift = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK);
|
||||
this.getInputMap(c).put(ksAltShift, "ENLARGE");
|
||||
this.getActionMap().put("ENLARGE", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
((MageActionCallback)callback).enlargeCard();
|
||||
}
|
||||
});
|
||||
|
||||
KeyStroke ksAltShiftReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true);
|
||||
this.getInputMap(c).put(ksAltShiftReleased, "ENLARGE_RELEASE");
|
||||
this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
((MageActionCallback)callback).hideCard();
|
||||
}
|
||||
});
|
||||
|
||||
btnSwitchHands.setText("Switch Hands");
|
||||
btnSwitchHands.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
|
@ -835,7 +856,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnStopWatching)
|
||||
.addContainerGap(62, Short.MAX_VALUE))
|
||||
.addComponent(bigCard, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
|
||||
//.addComponent(bigCard, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
|
||||
//.addComponent(feedbackPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
|
||||
.addComponent(stack, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
|
||||
.addGroup(gl_pnlGameInfo.createSequentialGroup()
|
||||
|
@ -846,8 +867,8 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
gl_pnlGameInfo.setVerticalGroup(
|
||||
gl_pnlGameInfo.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(gl_pnlGameInfo.createSequentialGroup()
|
||||
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(1, 1, 1)
|
||||
//.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
//.addGap(1, 1, 1)
|
||||
//.addComponent(feedbackPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(stack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE)
|
||||
|
@ -923,12 +944,19 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
gl_jPanel3.setHorizontalGroup(
|
||||
gl_jPanel3.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addComponent(pnlGameInfo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0)
|
||||
//.addComponent(pnlGameInfo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
//.addGap(0)
|
||||
.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(handContainer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
//.addComponent(jPhases, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(helper, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(handContainer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
)
|
||||
.addComponent(stack, GroupLayout.DEFAULT_SIZE, 400, 400)
|
||||
|
||||
)
|
||||
.addGap(0)
|
||||
//.addComponent(jPhases, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
|
||||
)))
|
||||
|
@ -937,16 +965,24 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
gl_jPanel3.createParallelGroup(Alignment.TRAILING)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
//.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addGap(85)
|
||||
.addComponent(stack, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
)
|
||||
.addGroup(gl_jPanel3.createSequentialGroup()
|
||||
.addComponent(helper, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(handContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
)
|
||||
)
|
||||
//.addComponent(jPhases, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
)
|
||||
.addComponent(pnlGameInfo, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||
//.addComponent(pnlGameInfo, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||
);
|
||||
jPanel3.setLayout(gl_jPanel3);
|
||||
//helper.setBorder(BorderFactory.createLineBorder(Color.ORANGE));
|
||||
|
||||
// jPanel3.setMinimumSize(new Dimension(400, 400));
|
||||
jSplitPane1.setLeftComponent(jPanel3);
|
||||
|
||||
gameChatPanel.setMinimumSize(new java.awt.Dimension(100, 48));
|
||||
|
@ -1092,6 +1128,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
private JLabel endButtonTip;
|
||||
|
||||
}
|
||||
|
||||
class ReplayTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
|
||||
private Session session;
|
||||
|
|
|
@ -36,8 +36,10 @@ public class MageActionCallback implements ActionCallback {
|
|||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
protected static Session session = MageFrame.getSession();
|
||||
private CardView popupCard;
|
||||
private TransferData popupData;
|
||||
private JComponent cardInfoPane;
|
||||
private volatile boolean state = false;
|
||||
private boolean enlarged = false;
|
||||
|
||||
public MageActionCallback() {
|
||||
}
|
||||
|
@ -69,6 +71,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
this.popupCard = data.card;
|
||||
this.popupData = data;
|
||||
|
||||
Component parentComponent = SwingUtilities.getRoot(data.component);
|
||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||
|
@ -79,7 +82,6 @@ public class MageActionCallback implements ActionCallback {
|
|||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
for (UUID uuid : targets) {
|
||||
//System.out.println("Getting play area panel for uuid: " + uuid);
|
||||
|
||||
PlayAreaPanel p = MageFrame.getGame(data.gameId).getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
|
@ -169,7 +171,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
|
||||
try {
|
||||
if (session == null || !state) {
|
||||
if (session == null || !state || enlarged) {
|
||||
return;
|
||||
}
|
||||
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
|
@ -184,7 +186,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!state) {
|
||||
if (!state || enlarged) {
|
||||
return;
|
||||
}
|
||||
popupContainer.setVisible(true);
|
||||
|
@ -212,12 +214,12 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
MageCard card = (MageCard) data.component;
|
||||
if (!state || card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
if (bigCard.getWidth() > 0) {
|
||||
synchronized (MageActionCallback.class) {
|
||||
if (!state || card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
if (!state) {
|
||||
bigCard.resetCardId();
|
||||
}
|
||||
state = true;
|
||||
Image image = card.getImage();
|
||||
if (image != null && image instanceof BufferedImage) {
|
||||
// XXX: scaled to fit width
|
||||
|
@ -236,6 +238,12 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state = true;
|
||||
}
|
||||
displayCard(card.getOriginal(), data);
|
||||
} else {
|
||||
hideCard();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,4 +276,101 @@ public class MageActionCallback implements ActionCallback {
|
|||
ArrowBuilder.removeArrowsByType(ArrowBuilder.Type.SOURCE);
|
||||
}
|
||||
|
||||
public void enlargeCard() {
|
||||
if (!enlarged) {
|
||||
enlarged = true;
|
||||
CardView card = null;
|
||||
if (popupData != null) {
|
||||
card = popupData.card;
|
||||
|
||||
}
|
||||
if (this.state) {
|
||||
hidePopup();
|
||||
}
|
||||
if (card != null) {
|
||||
displayCard(card, popupData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hideCard() {
|
||||
if (enlarged) {
|
||||
enlarged = false;
|
||||
try {
|
||||
Component cardPreviewContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER);
|
||||
cardPreviewContainer.setVisible(false);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayCard(final CardView card, final TransferData data) {
|
||||
if (!enlarged) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ThreadUtils.threadPool2.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (card == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!enlarged) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component parentComponent = SwingUtilities.getRoot(data.component);
|
||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||
|
||||
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER);
|
||||
Component cardPreview = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_PANE);
|
||||
//((CardInfoPaneImplExt) cardPreview).setCard(data.card);
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreview, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
|
||||
MageCard card = (MageCard) data.component;
|
||||
Image image = card.getImage();
|
||||
BigCard bigCard = (BigCard)cardPreview;
|
||||
if (image != null && image instanceof BufferedImage) {
|
||||
// XXX: scaled to fit width
|
||||
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
|
||||
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules(), card.isFoil());
|
||||
if (card.getOriginal().isAbility()) {
|
||||
bigCard.showTextComponent();
|
||||
} else {
|
||||
bigCard.hideTextComponent();
|
||||
}
|
||||
} else {
|
||||
JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight());
|
||||
panel.setVisible(true);
|
||||
bigCard.hideTextComponent();
|
||||
bigCard.addJXPanel(card.getOriginal().getId(), panel);
|
||||
}
|
||||
|
||||
/*final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!enlarged) {
|
||||
return;
|
||||
}
|
||||
popupContainer.setVisible(true);
|
||||
c.repaint();
|
||||
}
|
||||
}
|
||||
);*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
}
|
||||
}
|
||||
|
||||
boolean smallImages = true;
|
||||
int fontSize = 11;
|
||||
|
||||
String fontFamily = "tahoma";
|
||||
|
@ -94,7 +93,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
fontFamily = "verdana";
|
||||
}*/
|
||||
|
||||
final StringBuffer buffer = new StringBuffer(512);
|
||||
final StringBuilder buffer = new StringBuilder(512);
|
||||
buffer.append("<html><body style='font-family:");
|
||||
buffer.append(fontFamily);
|
||||
buffer.append(";font-size:");
|
||||
|
|
|
@ -9,4 +9,5 @@ public interface ActionCallback {
|
|||
void mouseEntered(MouseEvent e, TransferData data);
|
||||
void mouseExited(MouseEvent e, TransferData dat);
|
||||
void hidePopup();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue