diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form index 03ed4e96b4b..f63a94fad9e 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form @@ -230,7 +230,8 @@ - + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index a949990fc88..78a7e72f45e 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -574,7 +574,8 @@ public class PreferencesDialog extends javax.swing.JDialog { main_game.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Game")); nonLandPermanentsInOnePile.setSelected(true); - nonLandPermanentsInOnePile.setLabel("Put non-land permanents in one pile"); + nonLandPermanentsInOnePile.setText("Put non-land permanents in same row as creatures"); + nonLandPermanentsInOnePile.setToolTipText("If activated, all non land permanents are shown in one row.
\nFirst creatures than other permanents. If not activated, creatures are
\nshown in a separate row."); nonLandPermanentsInOnePile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nonLandPermanentsInOnePileActionPerformed(evt); diff --git a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java index e23e22887e0..908a25dc4f8 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -82,6 +82,8 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { private boolean addedCreature; private boolean removedCreature; + // defines if the battlefield is within a top (means top row of player panels) or a bottom player panel + private boolean topPanelBattlefield; /** * Creates new form BattlefieldPanel @@ -131,6 +133,14 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { cardDimension = GUISizeHelper.battlefieldCardMaxDimension; } + public boolean isTopPanelBattlefield() { + return topPanelBattlefield; + } + + public void setTopPanelBattlefield(boolean topPanelBattlefield) { + this.topPanelBattlefield = topPanelBattlefield; + } + public void update(Map battlefield) { boolean changed = false; 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 a7ab2aad802..d916871a9cc 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -619,7 +619,7 @@ public final class GamePanel extends javax.swing.JPanel { } PlayerView player = game.getPlayers().get(playerSeat); PlayAreaPanel playAreaPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, - new PlayAreaPanelOptions(game.isPlayer(), game.isPlayer(), game.isRollbackTurnsAllowed())); + new PlayAreaPanelOptions(game.isPlayer(), game.isPlayer(), game.isRollbackTurnsAllowed(), row == 0)); players.put(player.getPlayerId(), playAreaPanel); playersWhoLeft.put(player.getPlayerId(), false); GridBagConstraints c = new GridBagConstraints(); @@ -663,7 +663,7 @@ public final class GamePanel extends javax.swing.JPanel { } player = game.getPlayers().get(playerNum); PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, - new PlayAreaPanelOptions(game.isPlayer(), false, game.isRollbackTurnsAllowed())); + new PlayAreaPanelOptions(game.isPlayer(), false, game.isRollbackTurnsAllowed(), row == 0)); players.put(player.getPlayerId(), playerPanel); playersWhoLeft.put(player.getPlayerId(), false); c = new GridBagConstraints(); @@ -1207,10 +1207,10 @@ public final class GamePanel extends javax.swing.JPanel { holdingPriority = false; txtHoldPriority.setVisible(false); setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - false); + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + false); updateGame(gameView, options); boolean controllingPlayer = false; @@ -2370,26 +2370,26 @@ public final class GamePanel extends javax.swing.JPanel { private static int holdPriorityMask = System.getProperty("os.name").contains("Mac OS X") ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK; public void handleEvent(AWTEvent event) { - if(event instanceof InputEvent) { + if (event instanceof InputEvent) { int id = event.getID(); boolean isActionEvent = false; - if(id == MouseEvent.MOUSE_PRESSED) + if (id == MouseEvent.MOUSE_PRESSED) { isActionEvent = true; - else if(id == KeyEvent.KEY_PRESSED) - { - KeyEvent key = (KeyEvent)event; + } else if (id == KeyEvent.KEY_PRESSED) { + KeyEvent key = (KeyEvent) event; int keyCode = key.getKeyCode(); - if(keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE) + if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE) { isActionEvent = true; + } } - if(isActionEvent) { - InputEvent input = (InputEvent)event; - if((input.getModifiersEx() & holdPriorityMask) != 0) { + if (isActionEvent) { + InputEvent input = (InputEvent) event; + if ((input.getModifiersEx() & holdPriorityMask) != 0) { setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - true); + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + true); holdPriority(true); } } @@ -2397,13 +2397,14 @@ public final class GamePanel extends javax.swing.JPanel { } public void holdPriority(boolean holdPriority) { - if(holdingPriority != holdPriority) { + if (holdingPriority != holdPriority) { holdingPriority = holdPriority; txtHoldPriority.setVisible(holdPriority); - if(holdPriority) + if (holdPriority) { session.sendPlayerAction(PlayerAction.HOLD_PRIORITY, gameId, null); - else + } else { session.sendPlayerAction(PlayerAction.UNHOLD_PRIORITY, gameId, null); + } } } diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java index 9568d51b13c..c4ff4264f39 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -218,7 +218,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { holdPriorityMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - boolean holdPriority = ((JCheckBoxMenuItem)e.getSource()).getState(); + boolean holdPriority = ((JCheckBoxMenuItem) e.getSource()).getState(); gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolMenuItem2.getState(), useFirstManaAbilityItem.getState(), holdPriority); gamePanel.holdPriority(holdPriority); } @@ -264,7 +264,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { menuItem.setMnemonic(KeyEvent.VK_V); skipMenu.add(menuItem); menuItem.addActionListener(skipListener); - + menuItem = new JMenuItem("F11 - Everything until end step prior to your own next turn"); menuItem.setActionCommand("F11"); menuItem.setToolTipText(everythingTooltipText); @@ -312,8 +312,8 @@ public class PlayAreaPanel extends javax.swing.JPanel { gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolAutomaticRestricted, useFirstManaAbilityItem.getState(), holdPriorityMenuItem.getState()); gamePanel.getSession().sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON : PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null); } - }); - + }); + useFirstManaAbilityItem = new JCheckBoxMenuItem("Use first mana ability when tapping lands", false); useFirstManaAbilityItem.setMnemonic(KeyEvent.VK_F); useFirstManaAbilityItem.setToolTipText("Use the first mana ability when
" @@ -328,7 +328,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { boolean useFirstManaAbility = ((JCheckBoxMenuItem) e.getSource()).getState(); PreferencesDialog.saveValue(KEY_USE_FIRST_MANA_ABILITY, useFirstManaAbility ? "true" : "false"); gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolMenuItem2.getState(), useFirstManaAbility, holdPriorityMenuItem.getState()); - gamePanel.getSession().sendPlayerAction(useFirstManaAbility ? PlayerAction.USE_FIRST_MANA_ABILITY_ON: PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null); + gamePanel.getSession().sendPlayerAction(useFirstManaAbility ? PlayerAction.USE_FIRST_MANA_ABILITY_ON : PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null); } }); @@ -606,6 +606,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { playerPanel = new PlayerPanelExt(); btnCheat = new javax.swing.JButton(); battlefieldPanel = new mage.client.game.BattlefieldPanel(); + battlefieldPanel.setTopPanelBattlefield(options.topRow); btnCheat.setText("Cheat"); btnCheat.addActionListener(new java.awt.event.ActionListener() { @@ -663,7 +664,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { if (manaPoolMenuItem2 != null) { manaPoolMenuItem2.setSelected(manaPoolAutomaticRestricted); } - if (useFirstManaAbilityItem != null) { + if (useFirstManaAbilityItem != null) { useFirstManaAbilityItem.setSelected(useFirstManaAbility); } if (holdPriorityMenuItem != null) { diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanelOptions.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanelOptions.java index 680e8ab40e2..3d99e8360f5 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanelOptions.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanelOptions.java @@ -34,10 +34,11 @@ package mage.client.game; */ public class PlayAreaPanelOptions { - public PlayAreaPanelOptions(boolean isPlayer, boolean playerItself, boolean rollbackTurnsAllowed) { + public PlayAreaPanelOptions(boolean isPlayer, boolean playerItself, boolean rollbackTurnsAllowed, boolean topRow) { this.isPlayer = isPlayer; this.playerItself = playerItself; this.rollbackTurnsAllowed = rollbackTurnsAllowed; + this.topRow = topRow; } /** @@ -56,4 +57,9 @@ public class PlayAreaPanelOptions { */ public boolean rollbackTurnsAllowed = false; + /** + * true if the battlefield is on the top row of player areas + */ + public boolean topRow = false; + } diff --git a/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java b/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java index 2c0b20cacde..b04ea767242 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/MagePlugins.java @@ -33,7 +33,7 @@ public interface MagePlugins { boolean isCounterPluginLoaded(); - int sortPermanents(Map ui, Collection permanents); + int sortPermanents(Map ui, Collection permanents, boolean topRow); void downloadSymbols(); diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index a9de2dd6d02..054e6aaa52f 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -123,10 +123,9 @@ public class Plugins implements MagePlugins { } @Override - public int sortPermanents(Map ui, Collection permanents) { - sortingOptions.put("nonLandPermanentsInOnePile", PreferencesDialog.getCachedValue("nonLandPermanentsInOnePile", "false")); + public int sortPermanents(Map ui, Collection permanents, boolean topRow) { if (this.cardPlugin != null) { - return this.cardPlugin.sortPermanents(ui, permanents, sortingOptions); + return this.cardPlugin.sortPermanents(ui, permanents, PreferencesDialog.getCachedValue("nonLandPermanentsInOnePile", "false").equals("true"), topRow); } return -1; } diff --git a/Mage.Client/src/main/java/mage/client/util/layout/CardLayoutStrategy.java b/Mage.Client/src/main/java/mage/client/util/layout/CardLayoutStrategy.java index 9e3615f6f69..40d9677ceff 100644 --- a/Mage.Client/src/main/java/mage/client/util/layout/CardLayoutStrategy.java +++ b/Mage.Client/src/main/java/mage/client/util/layout/CardLayoutStrategy.java @@ -1,6 +1,6 @@ package mage.client.util.layout; -import javax.swing.JLayeredPane; +import mage.client.game.BattlefieldPanel; /** * Interface for operations that modify cards' layout @@ -11,7 +11,7 @@ public interface CardLayoutStrategy { int getDefaultZOrder(); - void onAdd(JLayeredPane jLayeredPane); + void onAdd(BattlefieldPanel jLayeredPane); - void doLayout(JLayeredPane jLayeredPane, int battlefieldWidth); + void doLayout(BattlefieldPanel jLayeredPane, int battlefieldWidth); } diff --git a/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java b/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java index 517bab9508c..84201c31892 100644 --- a/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java +++ b/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java @@ -31,16 +31,16 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy { private static final int ATTACHMENT_MIN_DY_OFFSET = 12; @Override - public void doLayout(JLayeredPane jLayeredPane, int width) { - Map permanents = ((BattlefieldPanel) jLayeredPane).getPermanents(); - JLayeredPane jPanel = ((BattlefieldPanel) jLayeredPane).getMainPanel(); + public void doLayout(BattlefieldPanel battlefieldPanel, int width) { + Map permanents = battlefieldPanel.getPermanents(); + JLayeredPane jPanel = battlefieldPanel.getMainPanel(); - int height = Plugins.getInstance().sortPermanents(((BattlefieldPanel) jLayeredPane).getUiComponentsList(), permanents.values()); + int height = Plugins.getInstance().sortPermanents(battlefieldPanel.getUiComponentsList(), permanents.values(), battlefieldPanel.isTopPanelBattlefield()); jPanel.setPreferredSize(new Dimension(width - 30, height)); - for (PermanentView permanent : ((BattlefieldPanel) jLayeredPane).getBattlefield().values()) { + for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) { if (permanent.getAttachments() != null) { - groupAttachments(jLayeredPane, jPanel, permanents, permanent); + groupAttachments(battlefieldPanel, jPanel, permanents, permanent); } } @@ -95,7 +95,7 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy { } @Override - public void onAdd(JLayeredPane jLayeredPane) { + public void onAdd(BattlefieldPanel jLayeredPane) { throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java index 7a9f4950db9..4be38a34567 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java @@ -123,7 +123,7 @@ public class CardPluginImpl implements CardPlugin { } @Override - public int sortPermanents(Map ui, Collection permanents, Map options) { + public int sortPermanents(Map ui, Collection permanents, boolean nonPermanentsOwnRow, boolean topPanel) { //TODO: add caching //requires to find out is position have been changed that includes: //adding/removing permanents, type change @@ -151,7 +151,7 @@ public class CardPluginImpl implements CardPlugin { int insertIndex = -1; - // Find lands with the same name. + // Find already added lands with the same name. for (int i = 0, n = rowAllLands.size(); i < n; i++) { Stack stack = rowAllLands.get(i); MagePermanent firstPanel = stack.get(0); @@ -204,12 +204,10 @@ public class CardPluginImpl implements CardPlugin { Row rowAllAttached = new Row(permanents, RowType.attached); boolean othersOnTheRight = true; - if (options != null && options.containsKey("nonLandPermanentsInOnePile")) { - if (options.get("nonLandPermanentsInOnePile").equals("true")) { - othersOnTheRight = false; - rowAllCreatures.addAll(rowAllOthers); - rowAllOthers.clear(); - } + if (nonPermanentsOwnRow) { + othersOnTheRight = false; + rowAllCreatures.addAll(rowAllOthers); + rowAllOthers.clear(); } cardWidth = cardWidthMax; @@ -218,6 +216,7 @@ public class CardPluginImpl implements CardPlugin { playAreaHeight = rect.height; while (true) { rows.clear(); + // calculate values based on the card size that is changing with every iteration cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO); extraCardSpacingX = Math.round(cardWidth * EXTRA_CARD_SPACING_X); cardSpacingX = cardHeight - cardWidth + extraCardSpacingX; @@ -225,15 +224,26 @@ public class CardPluginImpl implements CardPlugin { stackSpacingX = stackVertical ? 0 : Math.round(cardWidth * STACK_SPACING_X); stackSpacingY = Math.round(cardHeight * STACK_SPACING_Y); attachmentSpacingY = Math.round(cardHeight * ATTACHMENT_SPACING_Y); + // clone data Row creatures = (Row) rowAllCreatures.clone(); Row lands = (Row) rowAllLands.clone(); Row others = (Row) rowAllOthers.clone(); + // Wrap all creatures and lands. - wrap(creatures, rows, -1); - int afterCreaturesIndex = rows.size(); - wrap(lands, rows, afterCreaturesIndex); - int afterLandsIndex = rows.size(); - wrap(others, rows, afterLandsIndex); + int addOthersIndex; + if (topPanel) { + wrap(lands, rows, -1); + wrap(others, rows, rows.size()); + addOthersIndex = rows.size(); + wrap(creatures, rows, addOthersIndex); + } else { + wrap(creatures, rows, -1); + addOthersIndex = rows.size(); + wrap(lands, rows, rows.size()); + wrap(others, rows, rows.size()); + + } + // Store the current rows and others. List storedRows = new ArrayList<>(rows.size()); for (Row row : rows) { @@ -252,7 +262,7 @@ public class CardPluginImpl implements CardPlugin { rows = storedRows; others = storedOthers; // Try to put others on their own row(s) and fill in the rest. - wrap(others, rows, afterCreaturesIndex); + wrap(others, rows, addOthersIndex); for (Row row : rows) { fillRow(others, rows, row); } diff --git a/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java b/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java index 98183d520f2..b1c43b508a1 100644 --- a/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java +++ b/Mage.Common/src/mage/interfaces/plugin/CardPlugin.java @@ -27,7 +27,7 @@ public interface CardPlugin extends Plugin { MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage); - int sortPermanents(Map ui, Collection cards, Map options); + int sortPermanents(Map ui, Collection cards, boolean nonPermanentsOwnRow, boolean topPanel); /** * Download various symbols (mana, tap, set).