diff --git a/res/gui/display_layout.xml b/res/gui/display_layout.xml index 766def5a98a..8fcaaa96135 100644 --- a/res/gui/display_layout.xml +++ b/res/gui/display_layout.xml @@ -5,8 +5,8 @@ 0 0 - 1018 - 693 + 1280 + 707 @@ -16,8 +16,8 @@ 0 0 - 249 - 693 + 276 + 707 @@ -27,8 +27,8 @@ 0 0 - 249 - 96 + 276 + 135 @@ -47,8 +47,8 @@ 0 - 96 - 249 + 135 + 276 10 @@ -62,9 +62,9 @@ 0 - 106 - 249 - 177 + 145 + 276 + 132 @@ -83,8 +83,8 @@ 0 - 283 - 249 + 277 + 276 10 @@ -98,9 +98,9 @@ 0 - 293 - 249 - 84 + 287 + 276 + 107 @@ -119,8 +119,8 @@ 0 - 377 - 249 + 394 + 276 10 @@ -134,9 +134,9 @@ 0 - 387 - 249 - 96 + 404 + 276 + 141 @@ -155,8 +155,8 @@ 0 - 483 - 249 + 545 + 276 10 @@ -170,9 +170,9 @@ 0 - 493 - 249 - 200 + 555 + 276 + 152 @@ -202,10 +202,10 @@ - 249 + 276 0 10 - 693 + 707 @@ -217,10 +217,10 @@ - 259 + 286 0 - 470 - 693 + 765 + 707 @@ -228,10 +228,10 @@ - 259 + 286 0 - 470 - 119 + 765 + 124 @@ -249,9 +249,9 @@ - 259 - 119 - 470 + 286 + 124 + 765 10 @@ -264,10 +264,10 @@ - 259 - 129 - 470 - 120 + 286 + 134 + 765 + 121 @@ -285,9 +285,9 @@ - 259 - 249 - 470 + 286 + 255 + 765 10 @@ -300,10 +300,10 @@ - 259 - 259 - 470 - 135 + 286 + 265 + 765 + 162 @@ -321,9 +321,9 @@ - 259 - 394 - 470 + 286 + 427 + 765 10 @@ -336,10 +336,10 @@ - 259 - 404 - 470 - 143 + 286 + 437 + 765 + 122 @@ -357,9 +357,9 @@ - 259 - 547 - 470 + 286 + 559 + 765 10 @@ -372,10 +372,10 @@ - 259 - 557 - 470 - 136 + 286 + 569 + 765 + 138 @@ -408,10 +408,10 @@ - 729 + 1051 0 10 - 693 + 707 @@ -423,10 +423,10 @@ - 739 + 1061 0 - 279 - 693 + 219 + 707 @@ -434,10 +434,10 @@ - 739 + 1061 0 - 279 - 469 + 219 + 396 @@ -455,9 +455,9 @@ - 739 - 469 - 279 + 1061 + 396 + 219 10 @@ -470,10 +470,10 @@ - 739 - 479 - 279 - 214 + 1061 + 406 + 219 + 301 diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index b2fd17b8316..50c359fa3fa 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -9,6 +9,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.Vector; @@ -2877,7 +2878,6 @@ public class CardFactory implements NewConstants { public void execute() { PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController()); - CardList creatsToSac = new CardList(); CardList creats = new CardList(play.getCards()); creats = creats.filter(new CardListFilter() { public boolean addCard(Card c) { @@ -2888,23 +2888,12 @@ public class CardFactory implements NewConstants { //System.out.println("Creats size: " + creats.size()); if(card.getController().equals(Constant.Player.Human)) { - Object o = null; - int creatsSize = creats.size(); + List selection = AllZone.Display.getChoices("Select creature to sacrifice", + creats.toArray()); - for(int k = 0; k < creatsSize; k++) { - o = AllZone.Display.getChoiceOptional("Select creature to sacrifice", - creats.toArray()); - - if(o == null) break; - - Card c = (Card) o; - creatsToSac.add(c); - creats.remove(c); - } - - numCreatures[0] = creatsToSac.size(); - for(int m = 0; m < creatsToSac.size(); m++) { - AllZone.GameAction.sacrifice(creatsToSac.get(m)); + numCreatures[0] = selection.size(); + for(int m = 0; m < selection.size(); m++) { + AllZone.GameAction.sacrifice(selection.get(m)); } }//human diff --git a/src/forge/Display.java b/src/forge/Display.java index 854a5d637ec..82fa09a57f7 100644 --- a/src/forge/Display.java +++ b/src/forge/Display.java @@ -1,19 +1,32 @@ + package forge; + + +import java.util.List; + + public interface Display { - public T getChoice(String message, T[] choices); + public T getChoice(String message, T... choices); - public T getChoiceOptional(String message, T[] choices); + public T getChoiceOptional(String message, T... choices); + + public List getChoices(String message, T... choices); + + public List getChoicesOptional(String message, T... choices); public void showMessage(String s); + public MyButton getButtonOK(); + public MyButton getButtonCancel(); + // public void showStatus(String message); public void showCombat(String message); public void setVisible(boolean b); public boolean stopEOT(); - + //assigns combat damage, used by Combat.setAssignedDamage() public void assignDamage(Card attacker, CardList blockers, int damage); //public void addAssignDamage(Card attacker, Card blocker, int damage); diff --git a/src/forge/GuiDisplay2.java b/src/forge/GuiDisplay2.java index 6ec1a991a7e..85daf67e5c4 100644 --- a/src/forge/GuiDisplay2.java +++ b/src/forge/GuiDisplay2.java @@ -9,6 +9,7 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; +import java.util.List; import java.util.Observable; import java.util.Observer; @@ -198,34 +199,42 @@ public class GuiDisplay2 extends javax.swing.JFrame implements CardContainer, Di } //returned Object could be null - public T getChoiceOptional(String message, T[] choices) { - ListChooser c = new ListChooser(message, 0, 1, choices); - final JList list = c.getJList(); - if(choices[0] instanceof Card) { - list.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent ev) { - if(list.getSelectedValue() instanceof Card) setCard((Card) list.getSelectedValue()); - } - }); - } - if(!c.show()) return null; - - return c.getSelectedValue(); + public T getChoiceOptional(String message, T... choices) { + if(choices == null || choices.length == 0) return null; + List choice = getChoices(message, 0, 1, choices); + return choice.isEmpty()? null:choice.get(0); }//getChoiceOptional() // returned Object will never be null - public T getChoice(String message, T[] choices) { - ListChooser c = new ListChooser(message, 1, choices); + public T getChoice(String message, T... choices) { + List choice = getChoices(message, 1, 1, choices); + assert choice.size() == 1; + return choice.get(0); + }//getChoice() + + // returned Object will never be null + public List getChoicesOptional(String message, T... choices) { + return getChoices(message, 0, choices.length, choices); + }//getChoice() + + // returned Object will never be null + public List getChoices(String message, T... choices) { + return getChoices(message, 1, choices.length, choices); + }//getChoice() + + // returned Object will never be null + public List getChoices(String message, int min, int max, T... choices) { + ListChooser c = new ListChooser(message, min, max, choices); final JList list = c.getJList(); - if(choices[0] instanceof Card) { - list.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent ev) { - if(list.getSelectedValue() instanceof Card) setCard((Card) list.getSelectedValue()); + list.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent ev) { + if(list.getSelectedValue() instanceof Card) { + setCard((Card) list.getSelectedValue()); } - }); - } + } + }); c.show(); - return c.getSelectedValue(); + return c.getSelectedValues(); }//getChoice() private void addListeners() { diff --git a/src/forge/GuiDisplay3.java b/src/forge/GuiDisplay3.java index 601aa2b5a70..fe0bba88087 100644 --- a/src/forge/GuiDisplay3.java +++ b/src/forge/GuiDisplay3.java @@ -31,6 +31,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.List; import java.util.Observable; import java.util.Observer; @@ -256,39 +257,42 @@ public class GuiDisplay3 extends JFrame implements CardContainer, Display, NewCo } //returned Object could be null - public T getChoiceOptional(String message, T[] choices) { + public T getChoiceOptional(String message, T... choices) { if(choices == null || choices.length == 0) return null; - ListChooser c = new ListChooser(message, 0, 1, choices); - final JList list = c.getJList(); - if(choices[0] instanceof Card) { - list.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent ev) { - if(list.getSelectedValue() instanceof Card) { - setCard((Card) list.getSelectedValue()); - } - } - }); - } - if(!c.show()) return null; - - return c.getSelectedValue(); + List choice = getChoices(message, 0, 1, choices); + return choice.isEmpty()? null:choice.get(0); }//getChoiceOptional() // returned Object will never be null - public T getChoice(String message, T[] choices) { - ListChooser c = new ListChooser(message, 1, choices); + public T getChoice(String message, T... choices) { + List choice = getChoices(message, 1, 1, choices); + assert choice.size() == 1; + return choice.get(0); + }//getChoice() + + // returned Object will never be null + public List getChoicesOptional(String message, T... choices) { + return getChoices(message, 0, choices.length, choices); + }//getChoice() + + // returned Object will never be null + public List getChoices(String message, T... choices) { + return getChoices(message, 1, choices.length, choices); + }//getChoice() + + // returned Object will never be null + public List getChoices(String message, int min, int max, T... choices) { + ListChooser c = new ListChooser(message, min, max, choices); final JList list = c.getJList(); - if(choices[0] instanceof Card) { - list.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent ev) { - if(list.getSelectedValue() instanceof Card) { - setCard((Card) list.getSelectedValue()); - } + list.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent ev) { + if(list.getSelectedValue() instanceof Card) { + setCard((Card) list.getSelectedValue()); } - }); - } + } + }); c.show(); - return c.getSelectedValue(); + return c.getSelectedValues(); }//getChoice() private void addListeners() { diff --git a/src/forge/ImageCache.java b/src/forge/ImageCache.java index 874cefccf48..5e3e7c7eecb 100644 --- a/src/forge/ImageCache.java +++ b/src/forge/ImageCache.java @@ -72,11 +72,10 @@ public class ImageCache implements NewConstants { if(key.endsWith(TOKEN)) { key = key.substring(0, key.length() - TOKEN.length()); path = ForgeProps.getFile(IMAGE_TOKEN); - System.out.println("path + key: "+ path + " " + key); } else path = ForgeProps.getFile(IMAGE_BASE); File file = new File(path, key + ".jpg"); if(!file.exists()) { - System.out.println("File not found, no image created"); + System.out.println("File not found, no image created: " + file); return null; } BufferedImage image = ImageUtil.getImage(file); @@ -164,8 +163,9 @@ public class ImageCache implements NewConstants { private static String getKey(Card card) { String key = card.getImageName(); if(card.isBasicLand() && card.getRandomPicture() != 0) key += card.getRandomPicture(); + key = GuiDisplayUtil.cleanString(key); if(card.isToken()) key += TOKEN; - return GuiDisplayUtil.cleanString(key); + return key; } /** @@ -180,18 +180,18 @@ public class ImageCache implements NewConstants { if(srcWidth == tgtWidth && srcHeight == tgtHeight) return original; - /*AffineTransform at = new AffineTransform(); - at.scale((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); -// at.translate(srcHeight, 0); -// at.rotate(PI / 2); - double scale = min((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); - - BufferedImage image = new BufferedImage(tgtWidth, tgtHeight, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = (Graphics2D) image.getGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); - g2d.dispose();*/ - ResampleOp resampleOp = new ResampleOp (tgtWidth, tgtHeight); //defaults to Lanczos3 +// AffineTransform at = new AffineTransform(); +// at.scale((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); +//// at.translate(srcHeight, 0); +//// at.rotate(PI / 2); +// double scale = min((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); +// +// BufferedImage image = new BufferedImage(tgtWidth, tgtHeight, BufferedImage.TYPE_INT_ARGB); +// Graphics2D g2d = (Graphics2D) image.getGraphics(); +// g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); +// g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); +// g2d.dispose(); + ResampleOp resampleOp = new ResampleOp(tgtWidth, tgtHeight); //defaults to Lanczos3 BufferedImage image = resampleOp.filter(original, null); return image; } @@ -205,19 +205,19 @@ public class ImageCache implements NewConstants { int tgtWidth = Constant.Runtime.width[0]; int tgtHeight = Constant.Runtime.height[0]; - /*AffineTransform at = new AffineTransform(); - at.scale((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); - at.translate(srcHeight, 0); - at.rotate(Math.PI / 2); - - double scale = min((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); - - BufferedImage image = new BufferedImage(tgtHeight, tgtWidth, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = (Graphics2D) image.getGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); - g2d.dispose();*/ - ResampleOp resampleOp = new ResampleOp (tgtWidth, tgtHeight); //defaults to Lanczos3 +// AffineTransform at = new AffineTransform(); +// at.scale((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); +// at.translate(srcHeight, 0); +// at.rotate(Math.PI / 2); +// +// double scale = min((double) tgtWidth / srcWidth, (double) tgtHeight / srcHeight); +// +// BufferedImage image = new BufferedImage(tgtHeight, tgtWidth, BufferedImage.TYPE_INT_ARGB); +// Graphics2D g2d = (Graphics2D) image.getGraphics(); +// g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); +// g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); +// g2d.dispose(); + ResampleOp resampleOp = new ResampleOp(tgtWidth, tgtHeight); //defaults to Lanczos3 BufferedImage image = resampleOp.filter(original, null); return image; } @@ -228,16 +228,17 @@ public class ImageCache implements NewConstants { private static BufferedImage getFullSizeImage(BufferedImage original, double scale) { if(scale == 1) return original; - /*AffineTransform at = new AffineTransform(); - at.scale(scale, scale); - - BufferedImage image = new BufferedImage((int) (original.getWidth() * scale), - (int) (original.getHeight() * scale), BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = (Graphics2D) image.getGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); - g2d.dispose();*/ - ResampleOp resampleOp = new ResampleOp ((int) (original.getWidth() * scale), (int) (original.getHeight() * scale)); //defaults to Lanczos3 +// AffineTransform at = new AffineTransform(); +// at.scale(scale, scale); +// +// BufferedImage image = new BufferedImage((int) (original.getWidth() * scale), +// (int) (original.getHeight() * scale), BufferedImage.TYPE_INT_ARGB); +// Graphics2D g2d = (Graphics2D) image.getGraphics(); +// g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); +// g2d.drawImage(scale < 0.5? ImageUtil.getBlurredImage(original, 6, 1.0f):original, at, null); +// g2d.dispose(); + ResampleOp resampleOp = new ResampleOp((int) (original.getWidth() * scale), + (int) (original.getHeight() * scale)); //defaults to Lanczos3 BufferedImage image = resampleOp.filter(original, null); return image; } diff --git a/src/forge/gui/ListChooser.java b/src/forge/gui/ListChooser.java index 430a8f22a8a..90284b4573d 100644 --- a/src/forge/gui/ListChooser.java +++ b/src/forge/gui/ListChooser.java @@ -119,7 +119,6 @@ public class ListChooser { this.maxChoices = maxChoices; this.list = unmodifiableList(list); jList = new JList(new ChooserListModel()); - jList.getSelectionModel().addListSelectionListener(null); ok = new CloseAction(OK_OPTION, "OK"); ok.setEnabled(minChoices == 0); cancel = new CloseAction(CANCEL_OPTION, "Cancel"); @@ -134,6 +133,10 @@ public class ListChooser { jList.addMouseListener(new DblListener()); } + public List getChoices() { + return list; + } + /** * Returns the JList used in the list chooser. this is useful for registering listeners before showing the * dialog. @@ -158,19 +161,6 @@ public class ListChooser { if(value != OK_OPTION) jList.clearSelection(); //can't stop closing by ESC, so repeat if cancelled } while(minChoices != 0 && value != OK_OPTION); - /* an assertion checks if some condition is true. if not, an AssertionError is thrown, signaling an - * error in the program's logic - * by default, assertions are disabled at runtime, meaning the boolean expression is not evaluated. - * that is why you should NEVER do critical operations in the assert statement. - * instead of - * - * assert showConfirmDialog(...) == OK_OPTION; - * - * write - * - * int value = showConfirmDialog(...); - * assert value == OK_OPTION; - */ //this assert checks if we really don't return on a cancel if input is mandatory assert minChoices == 0 || value == OK_OPTION; called = true; diff --git a/src/forge/gui/game/CardDetailPanel.java b/src/forge/gui/game/CardDetailPanel.java index 5b8e9b8be54..e48844d792c 100644 --- a/src/forge/gui/game/CardDetailPanel.java +++ b/src/forge/gui/game/CardDetailPanel.java @@ -113,10 +113,11 @@ public class CardDetailPanel extends JPanel implements CardContainer { StringBuilder area = new StringBuilder(); //Token - if(card.isToken()) area.append("Token\n"); + if(card.isToken()) area.append("Token"); if(!faceDown) { //card text + if(area.length() != 0) area.append("\n"); area.append(card.getText()); } @@ -124,14 +125,15 @@ public class CardDetailPanel extends JPanel implements CardContainer { Counters[] counters = Counters.values(); for(Counters counter:counters) { if(card.getCounters(counter) != 0) { + if(area.length() != 0) area.append("\n"); area.append(counter.getName() + " counters: "); area.append(card.getCounters(counter)); - area.append("\n"); } } //chosen type if(card.getChosenType() != "") { + if(area.length() != 0) area.append("\n"); area.append("(chosen type: "); area.append(card.getChosenType()); area.append(")"); @@ -139,6 +141,7 @@ public class CardDetailPanel extends JPanel implements CardContainer { //chosen color if(card.getChosenColor() != "") { + if(area.length() != 0) area.append("\n"); area.append("(chosen color: "); area.append(card.getChosenColor()); area.append(")"); @@ -146,6 +149,7 @@ public class CardDetailPanel extends JPanel implements CardContainer { //named card if(card.getNamedCard() != "") { + if(area.length() != 0) area.append("\n"); area.append("(named card: "); area.append(card.getNamedCard()); area.append(")"); @@ -153,6 +157,7 @@ public class CardDetailPanel extends JPanel implements CardContainer { //equipping if(card.getEquipping().size() > 0) { + if(area.length() != 0) area.append("\n"); area.append("=Equipping "); area.append(card.getEquipping().get(0)); area.append("="); @@ -160,6 +165,7 @@ public class CardDetailPanel extends JPanel implements CardContainer { //equipped by if(card.getEquippedBy().size() > 0) { + if(area.length() != 0) area.append("\n"); area.append("=Equipped by "); for(Iterator it = card.getEquippedBy().iterator(); it.hasNext();) { area.append(it.next()); @@ -170,6 +176,7 @@ public class CardDetailPanel extends JPanel implements CardContainer { //enchanting if(card.getEnchanting().size() > 0) { + if(area.length() != 0) area.append("\n"); area.append("*Enchanting "); area.append(card.getEnchanting().get(0)); area.append("*"); @@ -186,7 +193,10 @@ public class CardDetailPanel extends JPanel implements CardContainer { } //uncastable - if(card.isUnCastable()) area.append("This card can't be cast."); + if(card.isUnCastable()) { + if(area.length() != 0) area.append("\n"); + area.append("This card can't be cast."); + } cdArea.setText(area.toString()); }