mirror of
https://github.com/correl/mage.git
synced 2025-04-02 03:18:09 -09:00
Finished ability picker. +even dispatching. +fixed bug in horizontal scrool bar.
This commit is contained in:
parent
d25425e782
commit
cc5a76e62b
7 changed files with 179 additions and 72 deletions
Mage.Client/src/main/java/mage/client
components/ability
game
Mage.Server/src/main/java/mage/server/game
|
@ -1,10 +1,12 @@
|
|||
package mage.client.components.ability;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.CPInstruction;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.SettingsManager;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.remote.Session;
|
||||
import mage.view.AbilityPickerView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdesktop.layout.GroupLayout;
|
||||
import org.jdesktop.layout.LayoutStyle;
|
||||
import org.jdesktop.swingx.JXPanel;
|
||||
|
@ -24,9 +26,11 @@ import java.util.UUID;
|
|||
*/
|
||||
public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
||||
|
||||
private static final String DEFAULT_MESSAGE = "Choose spell or ability to play (double-click)";;
|
||||
private static final int DIALOG_WIDTH = 320;
|
||||
private static final int DIALOG_HEIGHT = 240;
|
||||
private static final String DEFAULT_MESSAGE = "Choose spell or ability to play (double-click)";
|
||||
private static final int DIALOG_WIDTH = 440;
|
||||
private static final int DIALOG_HEIGHT = 260;
|
||||
|
||||
private transient static final Logger log = Logger.getLogger(AbilityPicker.class);
|
||||
|
||||
private JList rows;
|
||||
private List<Object> choices;
|
||||
|
@ -48,34 +52,31 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
private static Color SELECTED_COLOR = new Color(64,147,208);
|
||||
private static Color BORDER_COLOR = new Color(0,0,0,50);
|
||||
|
||||
public AbilityPicker() {
|
||||
initComponents();
|
||||
addMouseWheelListener(this);
|
||||
setSize(320, 240);
|
||||
private boolean selected = false;
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
jScrollPane2.setOpaque(false);
|
||||
jScrollPane2.getViewport().setOpaque(false);
|
||||
//jScrollPane2.getHorizontalScrollBar().setUI(new MageScrollbarUI());
|
||||
//jScrollPane2.getVerticalScrollBar().setUI(new MageScrollbarUI());
|
||||
}
|
||||
});
|
||||
public AbilityPicker() {
|
||||
setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
initComponents();
|
||||
|
||||
jScrollPane2.setOpaque(false);
|
||||
jScrollPane2.getViewport().setOpaque(false);
|
||||
UIManager.put( "ScrollBar.width", 17);
|
||||
jScrollPane2.getHorizontalScrollBar().setUI(new MageScrollbarUI());
|
||||
jScrollPane2.getVerticalScrollBar().setUI(new MageScrollbarUI());
|
||||
}
|
||||
|
||||
public AbilityPicker(List<Object> choices, String message) {
|
||||
this.choices = choices;
|
||||
setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
if (message!= null) {
|
||||
this.message = message + " (double-click)";
|
||||
}
|
||||
initComponents();
|
||||
jScrollPane2.setOpaque(false);
|
||||
jScrollPane2.getViewport().setOpaque(false);
|
||||
UIManager.put( "ScrollBar.width", 17);
|
||||
jScrollPane2.getHorizontalScrollBar().setUI(new MageScrollbarUI());
|
||||
jScrollPane2.getVerticalScrollBar().setUI(new MageScrollbarUI());
|
||||
|
||||
addMouseWheelListener(this);
|
||||
}
|
||||
|
||||
public void init(Session session, UUID gameId) {
|
||||
|
@ -84,17 +85,31 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
}
|
||||
|
||||
public void show(AbilityPickerView choices, Point p) {
|
||||
if (p == null) return;
|
||||
this.choices = new ArrayList<Object>();
|
||||
this.selected = true; // to stop previous modal
|
||||
|
||||
for (Map.Entry<UUID, String> choice: choices.getChoices().entrySet()) {
|
||||
this.choices.add(new AbilityPickerAction(choice.getKey(), choice.getValue()));
|
||||
}
|
||||
this.choices.add(new AbilityPickerAction(null, "Cancel"));
|
||||
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(320, 240);
|
||||
show(this.choices);
|
||||
}
|
||||
|
||||
private void show(List<Object> choices) {
|
||||
this.choices = choices;
|
||||
this.selected = true; // to stop previous modal
|
||||
|
||||
rows.setListData(this.choices.toArray());
|
||||
this.rows.setSelectedIndex(0);
|
||||
this.selected = false; // back to false - waiting for selection
|
||||
setVisible(true);
|
||||
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
this.setLocation(centered.x, centered.y);
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
|
||||
|
||||
//startModal();
|
||||
}
|
||||
|
||||
public void initComponents() {
|
||||
|
@ -130,20 +145,9 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
rightImage = ImageHelper.loadImage(IMAGE_RIGHT_PATH);
|
||||
rightImageHovered = ImageHelper.loadImage(IMAGE_RIGHT_HOVERED_PATH);
|
||||
|
||||
//BufferedImage[] images = new BufferedImage[choices.size()];
|
||||
//rows = new JList(images);
|
||||
setOpaque(false);
|
||||
|
||||
rows = new JList();
|
||||
rows.setModel (
|
||||
new AbstractListModel() {
|
||||
public int getSize() {
|
||||
if (AbilityPicker.this.choices == null) {
|
||||
return 0;
|
||||
}
|
||||
return AbilityPicker.this.choices.size();
|
||||
}
|
||||
public Object getElementAt(int i) { return AbilityPicker.this.choices.get(i); }
|
||||
}
|
||||
);
|
||||
|
||||
rows.setBackground(textColor);
|
||||
rows.setCellRenderer(new ImageRenderer());
|
||||
|
@ -162,10 +166,11 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
});
|
||||
rows.setSelectedIndex(0);
|
||||
rows.setFont(new Font("Times New Roman", 1, 17));
|
||||
|
||||
rows.setBorder(BorderFactory.createEmptyBorder());
|
||||
rows.addMouseWheelListener(this);
|
||||
|
||||
jScrollPane2.setViewportView(rows);
|
||||
jScrollPane2.setViewportBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
GroupLayout layout = new GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
|
@ -217,7 +222,8 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
}
|
||||
|
||||
private void objectMouseClicked(MouseEvent event) {
|
||||
AbilityPickerAction action = (AbilityPickerAction)choices.get(rows.getSelectedIndex());
|
||||
int index = rows.getSelectedIndex();
|
||||
AbilityPickerAction action = (AbilityPickerAction)choices.get(index);
|
||||
action.actionPerformed(null);
|
||||
}
|
||||
|
||||
|
@ -239,7 +245,8 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
if (isSelected) {
|
||||
label.setIcon(new ImageIcon(rightImageHovered));
|
||||
label.setForeground(SELECTED_COLOR);
|
||||
label.setBorder(BorderFactory.createLineBorder(BORDER_COLOR));
|
||||
//label.setBorder(BorderFactory.createLineBorder(BORDER_COLOR));
|
||||
label.setBorder(BorderFactory.createEmptyBorder());
|
||||
} else {
|
||||
label.setIcon(new ImageIcon(rightImage));
|
||||
}
|
||||
|
@ -250,16 +257,87 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
private static final long serialVersionUID = 7689696087189956997L;
|
||||
}
|
||||
|
||||
private synchronized void startModal() {
|
||||
try {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
EventQueue theQueue = getToolkit().getSystemEventQueue();
|
||||
while (!selected) {
|
||||
AWTEvent event = theQueue.getNextEvent();
|
||||
Object source = event.getSource();
|
||||
boolean dispatch = true;
|
||||
|
||||
/*if (event instanceof MouseEvent) {
|
||||
MouseEvent e = (MouseEvent) event;
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_CLICKED) {
|
||||
MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
|
||||
if (!this.contains(m.getPoint())) {
|
||||
selected = true;
|
||||
cancel();
|
||||
setVisible(false);
|
||||
dispatch = false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (event instanceof MouseEvent) {
|
||||
MouseEvent e = (MouseEvent) event;
|
||||
MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
|
||||
if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) {
|
||||
dispatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
if (event instanceof ActiveEvent) {
|
||||
((ActiveEvent) event).dispatch();
|
||||
} else if (source instanceof Component) {
|
||||
((Component) source).dispatchEvent(event);
|
||||
} else if (source instanceof MenuComponent) {
|
||||
((MenuComponent) source).dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (!selected) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
JFrame jframe = new JFrame("Test");
|
||||
|
||||
List<Object> objectList = new ArrayList<Object>();
|
||||
objectList.add("T: add {R} to your mana pool");
|
||||
objectList.add("T: add {R} to your mana pool. 111111111111111111111111111");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("T: add {B} to your mana pool");
|
||||
objectList.add("Cancel");
|
||||
AbilityPicker panel = new AbilityPicker(objectList, "Choose ability");
|
||||
jframe.add(panel);
|
||||
jframe.setSize(640, 480);
|
||||
panel.show(objectList);
|
||||
jframe.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
jframe.setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -276,11 +354,12 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
// cancel
|
||||
if (id == null) {
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
cancel();
|
||||
} else {
|
||||
session.sendPlayerUUID(gameId, id);
|
||||
}
|
||||
setVisible(false);
|
||||
AbilityPicker.this.selected = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -289,4 +368,12 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
try {
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
} catch (Exception e) {
|
||||
log.error("Couldn't cancel choose dialog: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class BackgroundPainter extends AbstractPainter {
|
|||
|
||||
private Color bgColor = Color.black;
|
||||
|
||||
float bgalpha = 0.8f;
|
||||
float bgalpha = 0.6f;
|
||||
|
||||
public BackgroundPainter() {
|
||||
super();
|
||||
|
|
|
@ -18,8 +18,8 @@ import javax.swing.plaf.metal.MetalScrollButton;
|
|||
*/
|
||||
public class MageScrollButton extends MetalScrollButton {
|
||||
|
||||
private static Icon buttonLeft;
|
||||
private static Icon buttonRight;
|
||||
private static ImageIcon buttonLeft;
|
||||
private static ImageIcon buttonRight;
|
||||
private static ImageIcon buttonUp;
|
||||
private static ImageIcon buttonDown;
|
||||
|
||||
|
@ -38,6 +38,8 @@ public class MageScrollButton extends MetalScrollButton {
|
|||
this.width = width;
|
||||
buttonUp.setImage(buttonUp.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
|
||||
buttonDown.setImage(buttonDown.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
|
||||
buttonLeft.setImage(buttonLeft.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
|
||||
buttonRight.setImage(buttonRight.getImage().getScaledInstance(width, width, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,7 +84,7 @@ public class MageScrollbarUI extends MetalScrollBarUI {
|
|||
g2.translate(-trackBounds.x - 2, -trackBounds.y);
|
||||
} else {
|
||||
int width = trackBounds.width;
|
||||
int height = trackBounds.height - 4;
|
||||
int height = trackBounds.height - 4 + ANTI_WIDTH;
|
||||
|
||||
g2.translate(trackBounds.x, trackBounds.y + 2);
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class MageScrollbarUI extends MetalScrollBarUI {
|
|||
g2.translate(thumbBounds.x + 2, thumbBounds.y + 1);
|
||||
|
||||
int width = thumbBounds.width - 4;
|
||||
int height = thumbBounds.height - 3;
|
||||
int height = thumbBounds.height - 3 + ANTI_WIDTH;
|
||||
|
||||
RoundRectangle2D casing = new RoundRectangle2D.Double(0, 0, width, height, height, height);
|
||||
g2.setColor(Color.BLACK);
|
||||
|
|
|
@ -48,6 +48,14 @@ public class GamePane extends MagePane {
|
|||
/** Creates new form GamePane */
|
||||
public GamePane() {
|
||||
initComponents();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gamePanel.setJLayeredPane(getLayeredPane());
|
||||
gamePanel.installComponents();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void showGame(UUID gameId, UUID playerId) {
|
||||
|
|
|
@ -34,21 +34,6 @@
|
|||
|
||||
package mage.client.game;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.Cards;
|
||||
|
@ -56,13 +41,25 @@ import mage.client.chat.ChatPanel;
|
|||
import mage.client.dialog.*;
|
||||
import mage.client.game.FeedbackPanel.FeedbackMode;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.GameManager;
|
||||
import mage.client.util.PhaseManager;
|
||||
import mage.remote.Session;
|
||||
import mage.view.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com, nantuko8
|
||||
|
@ -80,6 +77,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
private Session session;
|
||||
private CombatDialog combat;
|
||||
private PickNumberDialog pickNumber;
|
||||
private JLayeredPane jLayeredPane;
|
||||
|
||||
private static final int HAND_CARD_WIDTH = 75;
|
||||
private static final Dimension handCardDimension = new Dimension(HAND_CARD_WIDTH, (int)(HAND_CARD_WIDTH * 3.5f / 2.5f));
|
||||
|
@ -96,7 +94,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
/** Creates new form GamePanel */
|
||||
public GamePanel() {
|
||||
initComponents();
|
||||
|
||||
|
||||
hand.setHScrollSpeed(8);
|
||||
hand.setBackgroundColor(new Color(0, 0, 0, 100));
|
||||
hand.setVisibleIfEmpty(false);
|
||||
|
@ -137,7 +135,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
private Map<String, JComponent> getUIComponents(JLayeredPane jLayeredPane) {
|
||||
Map<String, JComponent> components = new HashMap<String, JComponent>();
|
||||
|
||||
|
||||
components.put("jSplitPane1", jSplitPane1);
|
||||
components.put("pnlBattlefield", pnlBattlefield);
|
||||
components.put("jPanel3", jPanel3);
|
||||
|
@ -146,10 +144,10 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
components.put("userChatPanel", userChatPanel);
|
||||
components.put("jLayeredPane", jLayeredPane);
|
||||
components.put("gamePanel", this);
|
||||
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
|
||||
public void cleanUp() {
|
||||
this.gameChatPanel.disconnect();
|
||||
this.players.clear();
|
||||
|
@ -325,10 +323,10 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.stack.loadCards(game.getStack(), bigCard, gameId);
|
||||
GameManager.getInstance().setStackSize(game.getStack().size());
|
||||
|
||||
|
||||
for (ExileView exile: game.getExile()) {
|
||||
if (!exiles.containsKey(exile.getId())) {
|
||||
ExileZoneDialog newExile = new ExileZoneDialog();
|
||||
|
@ -489,11 +487,11 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
pickChoice.showDialog(message, choices);
|
||||
session.sendPlayerString(gameId, pickChoice.getChoice());
|
||||
}
|
||||
|
||||
|
||||
public Map<UUID, PlayAreaPanel> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
|
||||
/*public javax.swing.JPanel getBattlefield() {
|
||||
return pnlBattlefield;
|
||||
}*/
|
||||
|
@ -508,7 +506,8 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
// </editor-fold>//GEN-END:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
abilityPicker = new mage.client.game.AbilityPicker();
|
||||
//abilityPicker = new mage.client.game.AbilityPicker();
|
||||
abilityPicker = new mage.client.components.ability.AbilityPicker();
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
jPanel3 = new javax.swing.JPanel();
|
||||
pnlGameInfo = new javax.swing.JPanel();
|
||||
|
@ -542,7 +541,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
gameChatPanel.disableInput();
|
||||
jTabbedPane1 = new JTabbedPane();
|
||||
|
||||
hand.setCardDimension(getHandCardDimension());
|
||||
hand.setCardDimension(getHandCardDimension());
|
||||
|
||||
jSplitPane1.setBorder(null);
|
||||
jSplitPane1.setDividerSize(7);
|
||||
|
@ -893,8 +892,19 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
private javax.swing.JScrollPane jScrollPane1;
|
||||
}
|
||||
|
||||
public void setJLayeredPane(JLayeredPane jLayeredPane) {
|
||||
this.jLayeredPane = jLayeredPane;
|
||||
}
|
||||
|
||||
public void installComponents() {
|
||||
jLayeredPane.setOpaque(false);
|
||||
jLayeredPane.add(abilityPicker);
|
||||
abilityPicker.setVisible(false);
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private mage.client.game.AbilityPicker abilityPicker;
|
||||
//private mage.client.game.AbilityPicker abilityPicker;
|
||||
private mage.client.components.ability.AbilityPicker abilityPicker;
|
||||
private mage.client.cards.BigCard bigCard;
|
||||
private javax.swing.JButton btnConcede;
|
||||
private javax.swing.JButton btnNextPlay;
|
||||
|
|
|
@ -279,7 +279,7 @@ public class GameController implements GameCallback {
|
|||
public void kill(UUID sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
GameSession session = gameSessions.get(sessionPlayerMap.get(sessionId));
|
||||
session.destroy();
|
||||
if (session != null) session.destroy();
|
||||
gameSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
leave(sessionId);
|
||||
sessionPlayerMap.remove(sessionId);
|
||||
|
|
Loading…
Add table
Reference in a new issue