From a828050ae158a4febb22e32a0e772db383842388 Mon Sep 17 00:00:00 2001 From: spjspj Date: Sat, 14 Apr 2018 23:09:37 +1000 Subject: [PATCH] Continuing implementation of Planechase. --- .../collection/viewer/MageBook.java | 125 ++++++++++++++---- .../src/main/resources/card-pictures-tok.txt | 2 +- .../java/mage/server/game/GameController.java | 2 +- .../common/MainPhaseStackEmptyCondition.java | 2 +- Mage/src/main/java/mage/game/GameState.java | 11 ++ 5 files changed, 113 insertions(+), 29 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java index 180cc2d5d5..f8a2b971d3 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java @@ -204,8 +204,6 @@ public class MageBook extends JComponent { Image setImage = ManaSymbols.getSetSymbolImage(set); if (setImage != null) { tab.setOverlayImage(setImage); - } else { - System.out.println("Couldn't find symbol image: " + set + "-C.jpg"); } tab.setSet(set); tab.setBounds(0, y, 39, 120); @@ -254,7 +252,7 @@ public class MageBook extends JComponent { updateCardStats(currentSet, false); int numTokens = showTokens(); int numTokensEmblems = numTokens + showEmblems(numTokens); - showPlanes(numTokensEmblems); + int numTokensEmblemsPlanes = numTokens + showPlanes(numTokensEmblems); } } @@ -315,14 +313,13 @@ public class MageBook extends JComponent { } jLayeredPane.repaint(); + return tokens.size(); } - - return tokens.size(); + return 0; } public int showEmblems(int numTokens) { List emblems = getEmblems(currentPage, currentSet, numTokens); - // System.out.println ("Size of origins in " + currentSet + " = " + emblems.size()); int numEmblems = 0; if (emblems != null && emblems.size() > 0) { int size = emblems.size(); @@ -354,6 +351,7 @@ public class MageBook extends JComponent { lastI++; } + rectangle.setLocation(second_page_x, OFFSET_Y); if (size + numTokens > conf.CARDS_PER_PAGE / 2) { for (int i = lastI; i < size && i + numTokens < conf.CARDS_PER_PAGE; i++) { Emblem emblem = emblems.get(i); @@ -367,10 +365,13 @@ public class MageBook extends JComponent { return numEmblems; } - public void showPlanes(int numTokensEmblems) { + public int showPlanes(int numTokensEmblems) { List planes = getPlanes(currentPage, currentSet, numTokensEmblems); + int numPlanes = 0; + if (planes != null && planes.size() > 0) { int size = planes.size(); + numPlanes = size; Rectangle rectangle = new Rectangle(); rectangle.translate(OFFSET_X, OFFSET_Y); @@ -397,6 +398,7 @@ public class MageBook extends JComponent { lastI++; } + rectangle.setLocation(second_page_x, OFFSET_Y); if (size + numTokensEmblems > conf.CARDS_PER_PAGE / 2) { for (int i = lastI; i < size && i + numTokensEmblems < conf.CARDS_PER_PAGE; i++) { Plane plane = planes.get(i); @@ -407,6 +409,7 @@ public class MageBook extends JComponent { jLayeredPane.repaint(); } + return numPlanes; } private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) { @@ -578,16 +581,25 @@ public class MageBook extends JComponent { } int start = page * conf.CARDS_PER_PAGE; int end = page * conf.CARDS_PER_PAGE + conf.CARDS_PER_PAGE; - if (end > tokens.size()) { - end = tokens.size(); + int ttokens = getTotalNumTokens(set); + int temblems = getTotalNumEmblems(set); + int tplanes = getTotalNumPlanes(set); + int numTokensEmblemsPlanes = ttokens + temblems + tplanes; + if (end > numTokensEmblemsPlanes) { + end = numTokensEmblemsPlanes; } - if (tokens.size() > end) { + if (numTokensEmblemsPlanes > end) { pageRight.setVisible(true); } - return tokens.subList(start, end); + + end = Math.min(end, ttokens); + if (start < ttokens) { + return tokens.subList(start, end); + } + return null; } - private List getEmblems(int page, String set, int numTokens) { + private List getEmblems(int page, String set, int numTokensEmblems) { ArrayList allEmblems = getTokenCardUrls(); ArrayList emblems = new ArrayList<>(); @@ -628,22 +640,23 @@ public class MageBook extends JComponent { } } } + + int totalTokens = getTotalNumTokens(set); int start = 0; + if (!(page * conf.CARDS_PER_PAGE <= totalTokens && (page + 1) * conf.CARDS_PER_PAGE >= totalTokens)) { + start = page * conf.CARDS_PER_PAGE - totalTokens; + } + int end = emblems.size(); - - if ((page + 1) * conf.CARDS_PER_PAGE < numTokens + emblems.size()) { - end = (page + 1) * conf.CARDS_PER_PAGE - numTokens; - pageRight.setVisible(true); + if ((page + 1) * conf.CARDS_PER_PAGE < totalTokens + emblems.size()) { + end = (page + 1) * conf.CARDS_PER_PAGE - totalTokens; } - if (emblems.size() > conf.CARDS_PER_PAGE) { - pageLeft.setVisible(true); - pageRight.setVisible(true); - } + start = Math.min(start, end); return emblems.subList(start, end); } - private List getPlanes(int page, String set, int numTokens) { + private List getPlanes(int page, String set, int numTokensEmblems) { ArrayList allPlanes = getTokenCardUrls(); ArrayList planes = new ArrayList<>(); @@ -684,21 +697,81 @@ public class MageBook extends JComponent { } } } + + int totalTokens = getTotalNumTokens(set); + int totalTokensEmblems = totalTokens + getTotalNumEmblems(set); int start = 0; + if (!(page * conf.CARDS_PER_PAGE <= totalTokensEmblems && (page + 1) * conf.CARDS_PER_PAGE >= totalTokensEmblems)) { + start = page * conf.CARDS_PER_PAGE - totalTokensEmblems; + pageRight.setVisible(true); + } + int end = planes.size(); - - if ((page + 1) * conf.CARDS_PER_PAGE < numTokens + planes.size()) { - end = (page + 1) * conf.CARDS_PER_PAGE - numTokens; + if ((page + 1) * conf.CARDS_PER_PAGE < totalTokensEmblems + planes.size()) { + end = (page + 1) * conf.CARDS_PER_PAGE - totalTokensEmblems; pageRight.setVisible(true); + } else { + pageRight.setVisible(false); } - if (planes.size() > conf.CARDS_PER_PAGE) { + if (numTokensEmblems + planes.size() > conf.CARDS_PER_PAGE && page > 0) { pageLeft.setVisible(true); - pageRight.setVisible(true); } + start = Math.min(start, end); return planes.subList(start, end); } + private int getTotalNumTokens(String set) { + ArrayList allTokens = getTokenCardUrls(); + int numTokens = 0; + + for (CardDownloadData token : allTokens) { + if (token.getSet().equals(set)) { + String className = token.getName(); + if (token.getTokenClassName() != null && token.getTokenClassName().length() > 0) { + if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*token.*")) { + numTokens++; + } + } + } + } + return numTokens; + } + + private int getTotalNumEmblems(String set) { + ArrayList allEmblems = getTokenCardUrls(); + int numEmblems = 0; + + for (CardDownloadData emblem : allEmblems) { + if (emblem.getSet().equals(set)) { + String className = emblem.getName(); + if (emblem.getTokenClassName() != null && emblem.getTokenClassName().length() > 0) { + if (emblem.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) { + numEmblems++; + } + } + } + } + return numEmblems; + } + + private int getTotalNumPlanes(String set) { + ArrayList allPlanes = getTokenCardUrls(); + int numPlanes = 0; + + for (CardDownloadData plane : allPlanes) { + if (plane.getSet().equals(set)) { + String className = plane.getName(); + if (plane.getTokenClassName() != null && plane.getTokenClassName().length() > 0) { + if (plane.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*plane.*")) { + numPlanes++; + } + } + } + } + return numPlanes; + } + private ImagePanel getImagePanel(String filename, ImagePanelStyle type) { try { InputStream is = this.getClass().getResourceAsStream(filename); diff --git a/Mage.Client/src/main/resources/card-pictures-tok.txt b/Mage.Client/src/main/resources/card-pictures-tok.txt index 270ecc6e7e..170748ea9c 100644 --- a/Mage.Client/src/main/resources/card-pictures-tok.txt +++ b/Mage.Client/src/main/resources/card-pictures-tok.txt @@ -96,8 +96,8 @@ |Generate|PLANE:PCA|Plane - Hedron Fields of Agadeem|||HedronFieldsOfAgadeemPlane| |Generate|PLANE:PCA|Plane - Lethe Lake|||LetheLakePlane| |Generate|PLANE:PCA|Plane - Naya|||NayaPlane| -|Generate|PLANE:PCA|Plane - The Dark Barony|||TheDarkBaronyPlane| |Generate|PLANE:PCA|Plane - Tazeem|||TazeemPlane| +|Generate|PLANE:PCA|Plane - The Dark Barony|||TheDarkBaronyPlane| |Generate|PLANE:PCA|Plane - The Eon Fog|||TheEonFogPlane| |Generate|PLANE:PCA|Plane - Truga Jungle|||TrugaJunglePlane| |Generate|PLANE:PCA|Plane - Turri Island|||TurriIslandPlane| diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index 3b18789ecf..1eb22a8bec 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -934,7 +934,7 @@ public class GameController implements GameCallback { } /** - * Performas a request to a player + * Performs a request to a player * * @param playerId * @param command diff --git a/Mage/src/main/java/mage/abilities/condition/common/MainPhaseStackEmptyCondition.java b/Mage/src/main/java/mage/abilities/condition/common/MainPhaseStackEmptyCondition.java index ed50f9a254..7f8922c7e3 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/MainPhaseStackEmptyCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/MainPhaseStackEmptyCondition.java @@ -51,6 +51,6 @@ public enum MainPhaseStackEmptyCondition implements Condition { @Override public String toString() { - return "during the main phase when the stack is empty"; + return "during your main phase when the stack is empty"; } } diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index ee56576ca3..994f62c4a9 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -457,6 +457,17 @@ public class GameState implements Serializable, Copyable { return designations; } + public Plane getCurrentPlane() { + if (command != null && command.size() > 0) { + for (CommandObject cobject : command) { + if (cobject instanceof Plane) { + return (Plane) cobject; + } + } + } + return null; + } + public List getSeenPlanes() { return seenPlanes; }