From 639c4fab13c237967622ec6da0f6ca7bd6805eb2 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 14 May 2019 15:14:40 +0400 Subject: [PATCH] Improved card render modes dialog (emblems and planes support); --- .../src/main/java/mage/client/MageFrame.java | 22 +++++++++------ .../src/main/java/mage/client/cards/Card.java | 22 +++++---------- .../mage/client/combat/CombatManager.java | 10 +++---- .../client/dialog/TestCardRenderDialog.java | 27 ++++++++++++++++--- .../plugins/adapters/MageActionCallback.java | 2 -- .../java/mage/client/util/gui/ArrowUtil.java | 19 ++++++------- .../plugins/card/utils/CardImageUtils.java | 2 +- 7 files changed, 60 insertions(+), 44 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 08c29ba8ad..d27f510ea8 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -20,6 +20,7 @@ import mage.client.draft.DraftPane; import mage.client.draft.DraftPanel; import mage.client.game.GamePane; import mage.client.game.GamePanel; +import mage.client.game.PlayAreaPanel; import mage.client.plugins.adapters.MageActionCallback; import mage.client.plugins.impl.Plugins; import mage.client.preference.MagePreferences; @@ -1004,16 +1005,16 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 838, Short.MAX_VALUE) - .addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 838, Short.MAX_VALUE) + .addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(2, 2, 2) - .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)) + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2, 2, 2) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)) ); pack(); @@ -1387,6 +1388,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { return GAMES.get(gameId); } + public static Map getGamePlayers(UUID gameId) { + GamePanel p = GAMES.get(gameId); + return p != null ? p.getPlayers() : new HashMap<>(); + } + public static void removeGame(UUID gameId) { GAMES.remove(gameId); } diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.java b/Mage.Client/src/main/java/mage/client/cards/Card.java index 9cd5b3bc87..cde4acf2de 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -1,10 +1,3 @@ - - - /* - * Card.java - * - * Created on 17-Dec-2009, 9:20:50 PM - */ package mage.client.cards; import mage.cards.CardDimensions; @@ -37,7 +30,6 @@ import java.util.UUID; import static mage.client.constants.Constants.*; /** - * * @author BetaSteward_at_googlemail.com */ @SuppressWarnings("serial") @@ -132,7 +124,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gSmall.drawImage(ImageHelper.scaleImage(image, Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight()), 0, 0, this); gImage.setFont(new Font("Arial", Font.PLAIN, NAME_FONT_MAX_SIZE)); - gImage.drawString(card.getName()+"TEST", CONTENT_MAX_XOFFSET, NAME_MAX_YOFFSET); + gImage.drawString(card.getName() + "TEST", CONTENT_MAX_XOFFSET, NAME_MAX_YOFFSET); if (card.isCreature()) { gImage.drawString(card.getPower() + '/' + card.getToughness(), POWBOX_TEXT_MAX_LEFT, POWBOX_TEXT_MAX_TOP); } else if (card.isPlanesWalker()) { @@ -146,7 +138,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gImage.dispose(); gSmall.setFont(new Font("Arial", Font.PLAIN, Config.dimensions.getNameFontSize())); - gSmall.drawString(card.getName()+"TEST2", Config.dimensions.getContentXOffset(), Config.dimensions.getNameYOffset()); + gSmall.drawString(card.getName() + "TEST2", Config.dimensions.getContentXOffset(), Config.dimensions.getNameYOffset()); if (card.isCreature()) { gSmall.drawString(card.getPower() + "/-/" + card.getToughness(), Config.dimensions.getPowBoxTextLeft(), Config.dimensions.getPowBoxTextTop()); } else if (card.isPlanesWalker()) { @@ -259,12 +251,12 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis return sbType.toString(); } - + protected void drawDetailed(Graphics2D g) { // Get the size of the card int width = getWidth(); int height = getHeight(); - + g.setColor(Color.black); g.drawRoundRect(0, 0, width, height, 4, 4); g.setColor(Color.white); @@ -309,7 +301,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void paintComponent(Graphics graphics) { - drawDetailed((Graphics2D)graphics); + drawDetailed((Graphics2D) graphics); /* Graphics2D g2 = (Graphics2D) graphics; g2.drawImage(small, 0, 0, this); @@ -367,13 +359,13 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis List targets = card.getTargets(); if (targets != null) { for (UUID uuid : targets) { - PlayAreaPanel playAreaPanel = MageFrame.getGame(gameId).getPlayers().get(uuid); + PlayAreaPanel playAreaPanel = MageFrame.getGamePlayers(gameId).get(uuid); if (playAreaPanel != null) { Point target = playAreaPanel.getLocationOnScreen(); Point me = this.getLocationOnScreen(); ArrowBuilder.getBuilder().addArrow(gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET); } else { - for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(gameId).values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point target = permanent.getLocationOnScreen(); diff --git a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java index b9be142a83..6c80cbd74a 100644 --- a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java +++ b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java @@ -3,8 +3,8 @@ package mage.client.combat; import mage.cards.MagePermanent; import mage.client.MageFrame; import mage.client.game.PlayAreaPanel; -import mage.client.util.audio.AudioManager; import mage.client.util.SettingsManager; +import mage.client.util.audio.AudioManager; import mage.client.util.gui.ArrowBuilder; import mage.view.CardView; import mage.view.CombatGroupView; @@ -67,7 +67,7 @@ public enum CombatManager { } private void drawAttacker(CombatGroupView group, CardView attacker, UUID gameId) { - for (PlayAreaPanel pa2 : MageFrame.getGame(gameId).getPlayers().values()) { + for (PlayAreaPanel pa2 : MageFrame.getGamePlayers(gameId).values()) { MagePermanent attackerCard = pa2.getBattlefieldPanel().getPermanents().get(attacker.getId()); if (attackerCard != null) { drawDefender(group, attackerCard, gameId); @@ -80,7 +80,7 @@ public enum CombatManager { UUID defenderId = group.getDefenderId(); if (defenderId != null) { parentPoint = getParentPoint(attackerCard); - PlayAreaPanel p = MageFrame.getGame(gameId).getPlayers().get(defenderId); + PlayAreaPanel p = MageFrame.getGamePlayers(gameId).get(defenderId); if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); @@ -88,7 +88,7 @@ public enum CombatManager { attackerPoint.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() - 20, Color.red, ArrowBuilder.Type.COMBAT); } else { - for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(gameId).values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(defenderId); if (permanent != null) { Point target = permanent.getLocationOnScreen(); @@ -104,7 +104,7 @@ public enum CombatManager { private void drawBlockers(CombatGroupView group, MagePermanent attackerCard, UUID gameId) { for (CardView blocker : group.getBlockers().values()) { - for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(gameId).values()) { MagePermanent blockerCard = pa.getBattlefieldPanel().getPermanents().get(blocker.getId()); if (blockerCard != null) { parentPoint = getParentPoint(blockerCard); diff --git a/Mage.Client/src/main/java/mage/client/dialog/TestCardRenderDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TestCardRenderDialog.java index e306d28bd5..29b37987a6 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TestCardRenderDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TestCardRenderDialog.java @@ -16,14 +16,17 @@ import mage.constants.MultiplayerAttackOption; import mage.constants.RangeOfInfluence; import mage.game.Game; import mage.game.GameImpl; +import mage.game.command.Emblem; +import mage.game.command.Plane; +import mage.game.command.emblems.AjaniAdversaryOfTyrantsEmblem; +import mage.game.command.planes.AkoumPlane; import mage.game.match.MatchType; import mage.game.mulligan.Mulligan; import mage.game.mulligan.VancouverMulligan; import mage.game.permanent.PermanentCard; import mage.players.Player; import mage.players.StubPlayer; -import mage.view.CardsView; -import mage.view.PermanentView; +import mage.view.*; import org.apache.log4j.Logger; import javax.swing.*; @@ -94,6 +97,18 @@ public class TestCardRenderDialog extends MageDialog { return cardView; } + private AbilityView createEmblem(Emblem emblem) { + AbilityView emblemView = new AbilityView(emblem.getAbilities().get(0), emblem.getName(), new CardView(new EmblemView(emblem))); + emblemView.setName(emblem.getName()); + return emblemView; + } + + private AbilityView createPlane(Plane plane) { + AbilityView planeView = new AbilityView(plane.getAbilities().get(0), plane.getName(), new CardView(new PlaneView(plane))); + planeView.setName(plane.getName()); + return planeView; + } + private void reloadCards() { cardsPanel.cleanUp(); cardsPanel.setCustomRenderMode(comboRenderMode.getSelectedIndex()); @@ -105,7 +120,7 @@ public class TestCardRenderDialog extends MageDialog { BigCard big = new BigCard(); CardsView view = new CardsView(); - PermanentView card; + CardView card; card = createCard(game, player.getId(), "RNA", "263", 0, 0, 0); // mountain view.put(card.getId(), card); card = createCard(game, player.getId(), "RNA", "185", 0, 0, 0); // Judith, the Scourge Diva @@ -120,11 +135,15 @@ public class TestCardRenderDialog extends MageDialog { view.put(card.getId(), card); card = createCard(game, player.getId(), "XLN", "234", 0, 0, 0); // Conqueror's Galleon view.put(card.getId(), card); + card = createEmblem(new AjaniAdversaryOfTyrantsEmblem()); // Emblem Ajani + view.put(card.getId(), card); + card = createPlane(new AkoumPlane()); // Plane - Akoum + view.put(card.getId(), card); cardsPanel.setCustomCardSize(new Dimension(getCardWidth(), getCardHeight())); cardsPanel.changeGUISize(); - cardsPanel.loadCards(view, big, null); + cardsPanel.loadCards(view, big, game.getId()); } private int getCardWidth() { diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index bd3d34052b..cf5a65eee0 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -363,8 +363,6 @@ public class MageActionCallback implements ActionCallback { if (!((GamePane) topPane).getGameId().equals(data.getGameId())) { return; } - } else if (data.getGameId() != null) { - return; } hideTooltipPopup(); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/ArrowUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/ArrowUtil.java index c6088f2089..243b47dc7c 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/ArrowUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/ArrowUtil.java @@ -16,14 +16,15 @@ import java.util.UUID; */ public final class ArrowUtil { - private ArrowUtil() {} + private ArrowUtil() { + } public static void drawArrowsForPairedCards(TransferData data, Point parentPoint) { if (data.getCard().getPairedCard() != null) { Point me = new Point(data.getLocationOnScreen()); me.translate(-parentPoint.x, -parentPoint.y); UUID uuid = data.getCard().getPairedCard(); - for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point target = permanent.getLocationOnScreen(); @@ -38,7 +39,7 @@ public final class ArrowUtil { if (data.getCard().getBandedCards() != null && !data.getCard().getBandedCards().isEmpty()) { Point me = new Point(data.getLocationOnScreen()); me.translate(-parentPoint.x, -parentPoint.y); - for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) { for (UUID uuid : data.getCard().getBandedCards()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { @@ -53,7 +54,7 @@ public final class ArrowUtil { public static void drawArrowsForEnchantPlayers(TransferData data, Point parentPoint) { if (data.getGameId() != null && MageFrame.getGame(data.getGameId()) != null) { - for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) { PlayerPanelExt playAreaPanel = pa.getPlayerPanel(); if (playAreaPanel != null && playAreaPanel.getPlayer() != null && playAreaPanel.getPlayer().hasAttachments()) { Point me = new Point(data.getLocationOnScreen()); @@ -62,7 +63,7 @@ public final class ArrowUtil { if (attachmentId.equals(data.getCard().getId())) { Point player = pa.getLocationOnScreen(); player.translate(-parentPoint.x, -parentPoint.y); - ArrowBuilder.getBuilder().addArrow(data.getGameId(),(int) me.getX() + 35, (int) me.getY(), (int) player.getX() + 40, (int) player.getY() - 40, Color.magenta, ArrowBuilder.Type.ENCHANT_PLAYERS); + ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) player.getX() + 40, (int) player.getY() - 40, Color.magenta, ArrowBuilder.Type.ENCHANT_PLAYERS); } } } @@ -75,7 +76,7 @@ public final class ArrowUtil { Point me = new Point(data.getLocationOnScreen()); me.translate(-parentPoint.x, -parentPoint.y); UUID uuid = data.getCard().getParentId(); - for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) { + for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point source = permanent.getLocationOnScreen(); @@ -96,7 +97,7 @@ public final class ArrowUtil { me.translate(-parentPoint.x, -parentPoint.y); for (UUID uuid : targets) { - PlayAreaPanel p = MageFrame.getGame(data.getGameId()).getPlayers().get(uuid); + PlayAreaPanel p = MageFrame.getGamePlayers(data.getGameId()).get(uuid); if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); @@ -104,7 +105,7 @@ public final class ArrowUtil { continue; } - for (PlayAreaPanel panel : MageFrame.getGame(data.getGameId()).getPlayers().values()) { + for (PlayAreaPanel panel : MageFrame.getGamePlayers(data.getGameId()).values()) { MagePermanent permanent = panel.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point target = permanent.getLocationOnScreen(); @@ -117,7 +118,7 @@ public final class ArrowUtil { if (view != null) { CardsView graveyard = view.getGraveyard(); if (graveyard.containsKey(uuid)) { - p = MageFrame.getGame(data.getGameId()).getPlayers().get(view.getPlayerId()); + p = MageFrame.getGamePlayers(data.getGameId()).get(view.getPlayerId()); if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java index c7dae39355..a22e0667b3 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java @@ -52,7 +52,7 @@ public final class CardImageUtils { return filePath; } - log.warn("Token image file not found. Set: " + card.getSet() + " Token Set Code: " + card.getTokenSetCode() + " Name: " + card.getName() + " File path: " + getTokenImagePath(card)); + //log.warn("Token image file not found. Set: " + card.getSet() + " Token Set Code: " + card.getTokenSetCode() + " Name: " + card.getName() + " File path: " + getTokenImagePath(card)); } else { log.warn("Trying to get token path for non token card. Set: " + card.getSet() + " Set Code: " + card.getTokenSetCode() + " Name: " + card.getName()); }