Merge branch 'fixEditorCards' into 'master'

improvements for alternate state cards in editors (desktop)

See merge request core-developers/forge!3613
This commit is contained in:
Michael Kamensky
2021-01-31 05:13:09 +00:00
5 changed files with 36 additions and 5 deletions

View File

@@ -350,7 +350,11 @@ public final class CardRulesPredicates {
boolean shouldContain;
switch (this.field) {
case NAME:
return op(card.getName(), this.operand);
boolean otherName = false;
if (card.getOtherPart() != null) {
otherName = op(card.getOtherPart().getName(), this.operand);
}
return otherName || op(card.getName(), this.operand);
case SUBTYPE:
shouldContain = (this.getOperator() == StringOp.CONTAINS) || (this.getOperator() == StringOp.EQUALS);
return shouldContain == card.getType().hasSubtype(this.operand);

View File

@@ -107,7 +107,10 @@ public class ImageCache {
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
*/
public static BufferedImage getImage(InventoryItem ii, int width, int height) {
return scaleImage(ii.getImageKey(false), width, height, true);
return getImage(ii, width, height, false);
}
public static BufferedImage getImage(InventoryItem ii, int width, int height, boolean altState) {
return scaleImage(ii.getImageKey(altState), width, height, true);
}
/**

View File

@@ -37,6 +37,7 @@ import forge.game.card.CardView;
import forge.gui.framework.ILocalRepaint;
import forge.item.IPaperCard;
import forge.item.InventoryItem;
import forge.item.PaperCard;
import forge.itemmanager.ColumnDef;
import forge.itemmanager.GroupDef;
import forge.itemmanager.ItemManager;
@@ -79,6 +80,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
private ItemInfo hoveredItem;
private ItemInfo focalItem;
private boolean panelOptionsCreated = false;
// cards with alternate states are added twice for displaying
private InventoryItem lastAltCard = null;
private final List<ItemInfo> orderedItems = new ArrayList<>();
private final List<Group> groups = new ArrayList<>();
@@ -1141,7 +1144,27 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, cornerSize, cornerSize);
InventoryItem item = itemInfo.item;
BufferedImage img = ImageCache.getImage(itemInfo.item, bounds.width - 2 * borderSize, bounds.height - 2 * borderSize);
boolean tryAltState = false;
if (hoveredItem == null || hoveredItem.item != item) {
if (item instanceof PaperCard) {
if (((PaperCard)item).getRules().getOtherPart() != null) {
if (item.equals(lastAltCard)) {
tryAltState = true;
lastAltCard = null;
}
else {
lastAltCard = item;
}
}
else {
lastAltCard = null;
}
}
}
BufferedImage img = ImageCache.getImage(item, bounds.width - 2 * borderSize, bounds.height - 2 * borderSize, tryAltState);
if (img != null) {
g.drawImage(img, null, bounds.x + borderSize, bounds.y + borderSize);
}
@@ -1149,7 +1172,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
g.setColor(Color.white);
Shape clip = g.getClip();
g.setClip(bounds);
g.drawString(itemInfo.item.getName(), bounds.x + 10, bounds.y + 20);
g.drawString(item.getName(), bounds.x + 10, bounds.y + 20);
g.setClip(clip);
}

View File

@@ -286,7 +286,7 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
break; //no other sections should support toAlternate
}
}
else {
else if (!editor.getCatalogManager().isInfinite()) {
editor.getCatalogManager().addItems(items);
}
editor.getDeckManager().removeItems(items);

View File

@@ -484,6 +484,7 @@ public class QuestController {
}
public HashSet<StarRating> GetRating() {
if (model == null) return null;
return model.Ratings;
}