Sprites/skins: Everything except deck editor icons now in a sprite, and fully accessed using skin enums. This includes foils, creatures, and all icons in game.

Skin enums sub-categorized to allow clearer access. 
Default coordinates added to skin enums, so declaration and positioning happen simultaneously (in one place).
Removed old icons.
This commit is contained in:
Doublestrike
2012-01-30 05:29:37 +00:00
parent 311ea8322e
commit ff329b1897
219 changed files with 768 additions and 598 deletions

View File

@@ -20,6 +20,7 @@ package forge.view.toolbox;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -46,6 +47,13 @@ import forge.gui.GuiUtils;
public class FSkin {
/** Properties of various components that make up the skin. */
public interface SkinProp { }
/** Add this interface for sub-sprite components, storing their coords. */
public interface Coords {
/** */
int[] COORDS = null;
/** @return int[] */
int[] getCoords();
}
/** */
public enum Backgrounds implements SkinProp { /** */
@@ -65,74 +73,268 @@ public class FSkin {
CLR_TEXT, /** */
}
/** */
public enum ZoneIcons implements SkinProp { /** */
ICO_HAND, /** */
ICO_LIBRARY, /** */
ICO_EXILE, /** */
ICO_FLASHBACK, /** */
ICO_GRAVEYARD, /** */
ICO_POISON, /** */
/** int[] can hold [xcoord, ycoord, width, height, newwidth, newheight]. */
public enum ZoneIcons implements SkinProp, Coords { /** */
ICO_HAND (new int[] {280, 40, 40, 40}), /** */
ICO_LIBRARY (new int[] {280, 0, 40, 40}), /** */
ICO_EXILE (new int[] {320, 40, 40, 40}), /** */
ICO_FLASHBACK (new int[] {280, 80, 40, 40}), /** */
ICO_GRAVEYARD (new int[] {320, 0, 40, 40}), /** */
ICO_POISON (new int[] {320, 80, 40, 40});
private int[] coords;
/** @param xy   int[] coordinates */
ZoneIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum ManaIcons implements SkinProp { /** */
ICO_BLACK, /** */
ICO_BLUE, /** */
ICO_GREEN, /** */
ICO_RED, /** */
ICO_WHITE, /** */
ICO_COLORLESS, /** */
/** int[] can hold [xcoord, ycoord, width, height, newwidth, newheight]. */
public enum ManaIcons implements SkinProp, Coords { /** */
ICO_BLACK (new int[] {360, 160, 40, 40, 13, 13}), /** */
ICO_RED (new int[] {400, 160, 40, 40, 13, 13}), /** */
ICO_COLORLESS (new int[] {440, 160, 40, 40, 13, 13}), /** */
ICO_BLUE (new int[] {360, 200, 40, 40, 13, 13}), /** */
ICO_GREEN (new int[] {400, 200, 40, 40, 13, 13}), /** */
ICO_WHITE (new int[] {440, 200, 40, 40, 13, 13}), /** */
ICO_2B (new int[] {360, 400, 40, 40, 13, 13}), /** */
ICO_2G (new int[] {400, 400, 40, 40, 13, 13}), /** */
ICO_2R (new int[] {440, 360, 40, 40, 13, 13}), /** */
ICO_2U (new int[] {440, 360, 40, 40, 13, 13}), /** */
ICO_2W (new int[] {400, 360, 40, 40, 13, 13}), /** */
ICO_BLACK_GREEN (new int[] {360, 240, 40, 40, 13, 13}), /** */
ICO_BLACK_RED (new int[] {400, 240, 40, 40, 13, 13}), /** */
ICO_GREEN_BLUE (new int[] {360, 280, 40, 40, 13, 13}), /** */
ICO_GREEN_WHITE (new int[] {440, 280, 40, 40, 13, 13}), /** */
ICO_RED_GREEN (new int[] {360, 320, 40, 40, 13, 13}), /** */
ICO_RED_WHITE (new int[] {400, 320, 40, 40, 13, 13}), /** */
ICO_BLUE_BLACK (new int[] {440, 240, 40, 40, 13, 13}), /** */
ICO_BLUE_RED (new int[] {440, 320, 40, 40, 13, 13}), /** */
ICO_WHITE_BLACK (new int[] {400, 280, 40, 40, 13, 13}), /** */
ICO_WHITE_BLUE (new int[] {360, 360, 40, 40, 13, 13}), /** */
ICO_PHRYX_BLUE (new int[] {320, 200, 40, 40, 13, 13}), /** */
ICO_PHRYX_WHITE (new int[] {320, 240, 40, 40, 13, 13}), /** */
ICO_PHRYX_RED (new int[] {320, 280, 40, 40, 13, 13}), /** */
ICO_PHRYX_GREEN (new int[] {320, 320, 40, 40, 13, 13}), /** */
ICO_PHRYX_BLACK (new int[] {320, 360, 40, 40, 13, 13});
private int[] coords;
/** @param xy   int[] coordinates */
ManaIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** int[] can hold [xcoord, ycoord, width, height, newwidth, newheight]. */
public enum ColorlessManaIcons implements SkinProp, Coords { /** */
ICO_0 (new int[] {640, 200, 20, 20, 13, 13}), /** */
ICO_1 (new int[] {660, 200, 20, 20, 13, 13}), /** */
ICO_2 (new int[] {640, 220, 20, 20, 13, 13}), /** */
ICO_3 (new int[] {660, 220, 20, 20, 13, 13}), /** */
ICO_4 (new int[] {640, 240, 20, 20, 13, 13}), /** */
ICO_5 (new int[] {660, 240, 20, 20, 13, 13}), /** */
ICO_6 (new int[] {640, 260, 20, 20, 13, 13}), /** */
ICO_7 (new int[] {660, 260, 20, 20, 13, 13}), /** */
ICO_8 (new int[] {640, 280, 20, 20, 13, 13}), /** */
ICO_9 (new int[] {660, 280, 20, 20, 13, 13}), /** */
ICO_10 (new int[] {640, 300, 20, 20, 13, 13}), /** */
ICO_11 (new int[] {660, 300, 20, 20, 13, 13}), /** */
ICO_12 (new int[] {640, 320, 20, 20, 13, 13}), /** */
ICO_15 (new int[] {660, 340, 20, 20, 13, 13}), /** */
ICO_16 (new int[] {640, 360, 20, 20, 13, 13}), /** */
ICO_20 (new int[] {640, 400, 20, 20, 13, 13}), /** */
ICO_X (new int[] {640, 420, 20, 20, 13, 13}), /** */
ICO_Y (new int[] {660, 420, 20, 20, 13, 13}), /** */
ICO_Z (new int[] {640, 440, 20, 20, 13, 13});
private int[] coords;
/** @param xy   int[] coordinates */
ColorlessManaIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** int[] can hold [xcoord, ycoord, width, height, newwidth, newheight]. */
public enum GameplayIcons implements SkinProp, Coords { /** */
ICO_SNOW (new int[] {320, 160, 40, 40}), /** */
ICO_TAP (new int[] {660, 440, 20, 20}), /** */
ICO_UNTAP (new int[] {640, 460, 20, 20}), /** */
ICO_SLASH (new int[] {660, 400, 10, 13}), /** */
ICO_ATTACK (new int[] {160, 320, 80, 80, 32, 32}), /** */
ICO_DEFEND (new int[] {160, 400, 80, 80, 32, 32}), /** */
ICO_SUMMONSICK (new int[] {240, 400, 80, 80, 32, 32}), /** */
ICO_PHASING (new int[] {240, 320, 80, 80, 32, 32}), /** */
ICO_COUNTERS1 (new int[] {0, 320, 80, 80}), /** */
ICO_COUNTERS2 (new int[] {0, 400, 80, 80}), /** */
ICO_COUNTERS3 (new int[] {80, 320, 80, 80}), /** */
ICO_COUNTERS_MULTI (new int[] {80, 400, 80, 80});
private int[] coords;
/** @param xy   int[] coordinates */
GameplayIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum DockIcons implements SkinProp { /** */
ICO_SHORTCUTS, /** */
ICO_SETTINGS, /** */
ICO_ENDTURN, /** */
ICO_CONCEDE, /** */
ICO_DECKLIST, /** */
public enum Foils implements SkinProp, Coords { /** */
FOIL_01 (new int[] {0, 0, 400, 570}), /** */
FOIL_02 (new int[] {400, 0, 400, 570}), /** */
FOIL_03 (new int[] {0, 570, 400, 570}), /** */
FOIL_04 (new int[] {400, 570, 400, 570}), /** */
FOIL_05 (new int[] {0, 1140, 400, 570}), /** */
FOIL_06 (new int[] {400, 1140, 400, 570}), /** */
FOIL_07 (new int[] {0, 1710, 400, 570}), /** */
FOIL_08 (new int[] {400, 1710, 400, 570}), /** */
FOIL_09 (new int[] {0, 2280, 400, 570}), /** */
FOIL_10 (new int[] {400, 2280, 400, 570});
private int[] coords;
/** @param xy   int[] coordinates */
Foils(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum ForgeIcons implements SkinProp { /** */
IMG_LOGO, /** */
IMG_FAVICON, /** */
public enum DockIcons implements SkinProp, Coords { /** */
ICO_SHORTCUTS (new int[] {160, 640, 80, 80}), /** */
ICO_SETTINGS (new int[] {80, 640, 80, 80}), /** */
ICO_ENDTURN (new int[] {320, 640, 80, 80}), /** */
ICO_CONCEDE (new int[] {240, 640, 80, 80}), /** */
ICO_DECKLIST (new int[] {400, 640, 80, 80});
private int[] coords;
/** @param xy   int[] coordinates */
DockIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum ButtonImages implements SkinProp { /** */
IMG_BTN_START_UP, /** */
IMG_BTN_START_OVER, /** */
IMG_BTN_START_DOWN, /** */
public enum QuestIcons implements SkinProp, Coords { /** */
ICO_ZEP (new int[] {0, 480, 80, 80}), /** */
ICO_GEAR (new int[] {80, 480, 80, 80}), /** */
ICO_GOLD (new int[] {160, 480, 80, 80}), /** */
ICO_BOOK (new int[] {240, 480, 80, 80}), /** */
ICO_ELIXER (new int[] {320, 480, 80, 80}), /** */
ICO_BOTTLES (new int[] {400, 480, 80, 80}), /** */
ICO_BOX (new int[] {480, 480, 80, 80}), /** */
ICO_COIN (new int[] {560, 480, 80, 80}), /** */
IMG_BTN_UP_LEFT, /** */
IMG_BTN_UP_CENTER, /** */
IMG_BTN_UP_RIGHT, /** */
ICO_FOX (new int[] {0, 560, 80, 80}), /** */
ICO_LEAF (new int[] {80, 560, 80, 80}), /** */
ICO_LIFE (new int[] {160, 560, 80, 80}), /** */
ICO_COINSTACK (new int[] {240, 560, 80, 80}), /** */
ICO_MAP (new int[] {320, 560, 80, 80}), /** */
ICO_NOTES (new int[] {400, 560, 80, 80}), /** */
ICO_HEART (new int[] {480, 560, 80, 80}), /** */
IMG_BTN_OVER_LEFT, /** */
IMG_BTN_OVER_CENTER, /** */
IMG_BTN_OVER_RIGHT, /** */
ICO_MINUS (new int[] {480, 640, 80, 80}), /** */
ICO_PLUS (new int[] {560, 640, 80, 80});
IMG_BTN_DOWN_LEFT, /** */
IMG_BTN_DOWN_CENTER, /** */
IMG_BTN_DOWN_RIGHT, /** */
private int[] coords;
/** @param xy   int[] coordinates */
QuestIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
IMG_BTN_FOCUS_LEFT, /** */
IMG_BTN_FOCUS_CENTER, /** */
IMG_BTN_FOCUS_RIGHT, /** */
/** */
public enum CreatureIcons implements SkinProp, Coords { /** */
ICO_BIRD1 (new int[] {0, 2280, 400, 570}), /** */
ICO_BIRD2 (new int[] {400, 2280, 400, 570}), /** */
ICO_BIRD3 (new int[] {800, 2280, 400, 570}), /** */
ICO_BIRD4 (new int[] {1200, 2280, 400, 570}), /** */
IMG_BTN_TOGGLE_LEFT, /** */
IMG_BTN_TOGGLE_CENTER, /** */
IMG_BTN_TOGGLE_RIGHT, /** */
ICO_PLANT1 (new int[] {0, 0, 400, 570}), /** */
ICO_PLANT2 (new int[] {400, 0, 400, 570}), /** */
ICO_PLANT3 (new int[] {800, 0, 400, 570}), /** */
ICO_PLANT4 (new int[] {1200, 0, 400, 570}), /** */
ICO_PLANT5 (new int[] {0, 570, 400, 570}), /** */
ICO_PLANT6 (new int[] {400, 570, 400, 570}), /** */
IMG_BTN_DISABLED_LEFT, /** */
IMG_BTN_DISABLED_CENTER, /** */
IMG_BTN_DISABLED_RIGHT, /** */
ICO_HOUND1 (new int[] {0, 1710, 400, 570}), /** */
ICO_HOUND2 (new int[] {400, 1710, 400, 570}), /** */
ICO_HOUND3 (new int[] {800, 1710, 400, 570}), /** */
ICO_HOUND4 (new int[] {1200, 1710, 400, 570}), /** */
ICO_CROC1 (new int[] {0, 2850, 400, 570}), /** */
ICO_CROC2 (new int[] {400, 2850, 400, 570}), /** */
ICO_CROC3 (new int[] {800, 2850, 400, 570}), /** */
ICO_CROC4 (new int[] {1200, 2850, 400, 570}), /** */
ICO_WOLF1 (new int[] {0, 1140, 400, 570}), /** */
ICO_WOLF2 (new int[] {400, 1140, 400, 570}), /** */
ICO_WOLF3 (new int[] {800, 1140, 400, 570}), /** */
ICO_WOLF4 (new int[] {1200, 1140, 400, 570});
private int[] coords;
/** @param xy   int[] coordinates */
CreatureIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum ForgeIcons implements SkinProp, Coords { /** */
ICO_EDIT (new int[] {640, 500, 20, 20}), /** */
ICO_EDIT_OVER (new int[] {660, 500, 20, 20}), /** */
ICO_DELETE (new int[] {640, 480, 20, 20}), /** */
ICO_DELETE_OVER (new int[] {660, 480, 20, 20}), /** */
ICO_UNKNOWN (new int[] {80, 720, 80, 80}), /** */
ICO_LOGO (new int[] {480, 0, 200, 200}), /** */
ICO_DEFAULT_MAGE (new int[] {0, 720, 80, 80}), /** */
ICO_FAVICON (new int[] {0, 640, 80, 80});
private int[] coords;
/** @param xy   int[] coordinates */
ForgeIcons(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
/** */
public enum ButtonImages implements SkinProp, Coords { /** */
IMG_BTN_START_UP (new int[] {480, 200, 160, 80}), /** */
IMG_BTN_START_OVER (new int[] {480, 280, 160, 80}), /** */
IMG_BTN_START_DOWN (new int[] {480, 360, 160, 80}), /** */
IMG_BTN_UP_LEFT (new int[] {80, 0, 40, 40}), /** */
IMG_BTN_UP_CENTER (new int[] {120, 0, 1, 40}), /** */
IMG_BTN_UP_RIGHT (new int[] {160, 0, 40, 40}), /** */
IMG_BTN_OVER_LEFT (new int[] {80, 40, 40, 40}), /** */
IMG_BTN_OVER_CENTER (new int[] {120, 40, 1, 40}), /** */
IMG_BTN_OVER_RIGHT (new int[] {160, 40, 40, 40}), /** */
IMG_BTN_DOWN_LEFT (new int[] {80, 80, 40, 40}), /** */
IMG_BTN_DOWN_CENTER (new int[] {120, 80, 1, 40}), /** */
IMG_BTN_DOWN_RIGHT (new int[] {160, 80, 40, 40}), /** */
IMG_BTN_FOCUS_LEFT (new int[] {80, 120, 40, 40}), /** */
IMG_BTN_FOCUS_CENTER (new int[] {120, 120, 1, 40}), /** */
IMG_BTN_FOCUS_RIGHT (new int[] {160, 120, 40, 40}), /** */
IMG_BTN_TOGGLE_LEFT (new int[] {80, 160, 40, 40}), /** */
IMG_BTN_TOGGLE_CENTER (new int[] {120, 160, 1, 40}), /** */
IMG_BTN_TOGGLE_RIGHT (new int[] {160, 160, 40, 40}), /** */
IMG_BTN_DISABLED_LEFT (new int[] {80, 200, 40, 40}), /** */
IMG_BTN_DISABLED_CENTER (new int[] {120, 200, 1, 40}), /** */
IMG_BTN_DISABLED_RIGHT (new int[] {160, 200, 40, 40});
private int[] coords;
/** @param xy   int[] coordinates */
ButtonImages(int[] xy) { this.coords = xy; }
/** @return int[] */
public int[] getCoords() { return coords; }
}
private Map<SkinProp, ImageIcon> icons;
private Map<SkinProp, Image> images;
private Map<SkinProp, Color> colors;
private Map<SkinProp, Image> foils;
private Map<Integer, Font> plainFonts;
private Map<Integer, Font> boldFonts;
@@ -140,7 +342,9 @@ public class FSkin {
private static final String
FILE_SKINS_DIR = "res/images/skins/",
FILE_SPRITE = "sprite.png",
FILE_ICON_SPRITE = "sprite_icons.png",
FILE_FOIL_SPRITE = "sprite_foils.png",
FILE_CREATURE_SPRITE = "sprite_creatures.jpg",
FILE_FONT = "font1.ttf",
FILE_SPLASH = "bg_splash.png",
FILE_MATCH_BG = "bg_match.jpg",
@@ -151,8 +355,7 @@ public class FSkin {
private final String defaultDir;
private final String preferredName;
private Font font;
private BufferedImage bimDefaultSprite;
private BufferedImage bimPreferredSprite;
private BufferedImage bimDefaultSprite, bimPreferredSprite, bimFoils, bimCreatures;
private int preferredH, preferredW;
private FProgressBar barProgress;
@@ -176,7 +379,9 @@ public class FSkin {
this.preferredDir = FILE_SKINS_DIR + preferredName + "/";
this.defaultDir = FILE_SKINS_DIR + "default/";
this.icons = new HashMap<SkinProp, ImageIcon>();
this.images = new HashMap<SkinProp, Image>();
this.colors = new HashMap<SkinProp, Color>();
this.foils = new HashMap<SkinProp, Image>();
final File f = new File(preferredDir + FILE_SPLASH);
final BufferedImage img;
@@ -232,14 +437,19 @@ public class FSkin {
barProgress.setMaximum(57);
// Grab and test the two sprite files.
final File f1 = new File(defaultDir + FILE_SPRITE);
final File f2 = new File(preferredDir + FILE_SPRITE);
// Grab and test various sprite files.
final File f1 = new File(defaultDir + FILE_ICON_SPRITE);
final File f2 = new File(preferredDir + FILE_ICON_SPRITE);
final File f3 = new File(defaultDir + FILE_CREATURE_SPRITE);
final File f4 = new File(defaultDir + FILE_FOIL_SPRITE);
try {
bimDefaultSprite = ImageIO.read(f1);
bimPreferredSprite = ImageIO.read(f2);
bimCreatures = ImageIO.read(f3);
bimFoils = ImageIO.read(f4);
preferredH = bimPreferredSprite.getHeight();
preferredW = bimPreferredSprite.getWidth();
}
@@ -279,91 +489,48 @@ public class FSkin {
this.setIcon(Backgrounds.BG_TEXTURE, preferredDir + FILE_TEXTURE_BG);
this.setIcon(Backgrounds.BG_MATCH, preferredDir + FILE_MATCH_BG);
// Sprite
final File file = new File(preferredDir + FILE_SPRITE);
BufferedImage image;
this.setColor(Colors.CLR_THEME, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 10)));
this.setColor(Colors.CLR_BORDERS, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 30)));
this.setColor(Colors.CLR_ZEBRA, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 50)));
this.setColor(Colors.CLR_HOVER, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 70)));
this.setColor(Colors.CLR_ACTIVE, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 90)));
this.setColor(Colors.CLR_INACTIVE, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 110)));
this.setColor(Colors.CLR_TEXT, this.getColorFromPixel(bimPreferredSprite.getRGB(70, 130)));
try {
image = ImageIO.read(file);
// Run through enums and load their coords.
for (ZoneIcons e : ZoneIcons.values()) { this.setIcon(e); }
for (ManaIcons e : ManaIcons.values()) { this.setImage(e); }
for (ColorlessManaIcons e : ColorlessManaIcons.values()) { this.setImage(e); }
for (GameplayIcons e : GameplayIcons.values()) { this.setImage(e); }
for (DockIcons e : DockIcons.values()) { this.setIcon(e); }
for (ForgeIcons e : ForgeIcons.values()) { this.setIcon(e); }
for (ButtonImages e : ButtonImages.values()) { this.setIcon(e); }
for (QuestIcons e : QuestIcons.values()) { this.setIcon(e); }
this.setColor(Colors.CLR_THEME, this.getColorFromPixel(image.getRGB(70, 10)));
this.setColor(Colors.CLR_BORDERS, this.getColorFromPixel(image.getRGB(70, 30)));
this.setColor(Colors.CLR_ZEBRA, this.getColorFromPixel(image.getRGB(70, 50)));
this.setColor(Colors.CLR_HOVER, this.getColorFromPixel(image.getRGB(70, 70)));
this.setColor(Colors.CLR_ACTIVE, this.getColorFromPixel(image.getRGB(70, 90)));
this.setColor(Colors.CLR_INACTIVE, this.getColorFromPixel(image.getRGB(70, 110)));
this.setColor(Colors.CLR_TEXT, this.getColorFromPixel(image.getRGB(70, 130)));
} catch (final IOException e) {
System.err.println(this.notfound + preferredDir + FILE_SPRITE);
e.printStackTrace();
}
this.setIconAndIncrement(ZoneIcons.ICO_LIBRARY, 280, 0, 40, 40);
this.setIconAndIncrement(ZoneIcons.ICO_HAND, 280, 40, 40, 40);
this.setIconAndIncrement(ZoneIcons.ICO_FLASHBACK, 280, 80, 40, 40);
this.setIconAndIncrement(ZoneIcons.ICO_GRAVEYARD, 320, 0, 40, 40);
this.setIconAndIncrement(ZoneIcons.ICO_EXILE, 320, 40, 40, 40);
this.setIconAndIncrement(ZoneIcons.ICO_POISON, 320, 80, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_BLACK, 360, 160, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_BLUE, 360, 200, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_RED, 400, 160, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_GREEN, 400, 200, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_COLORLESS, 440, 160, 40, 40);
this.setIconAndIncrement(ManaIcons.ICO_WHITE, 440, 200, 40, 40);
this.setIconAndIncrement(DockIcons.ICO_SETTINGS, 80, 640, 80, 80);
this.setIconAndIncrement(DockIcons.ICO_SHORTCUTS, 160, 640, 80, 80);
this.setIconAndIncrement(DockIcons.ICO_CONCEDE, 240, 640, 80, 80);
this.setIconAndIncrement(DockIcons.ICO_ENDTURN, 320, 640, 80, 80);
this.setIconAndIncrement(DockIcons.ICO_DECKLIST, 400, 640, 80, 80);
this.setIconAndIncrement(ForgeIcons.IMG_LOGO, 480, 0, 200, 200);
this.setIconAndIncrement(ForgeIcons.IMG_FAVICON, 0, 720, 80, 80);
this.setIconAndIncrement(ButtonImages.IMG_BTN_START_UP, 480, 200, 160, 80);
this.setIconAndIncrement(ButtonImages.IMG_BTN_START_OVER, 480, 280, 160, 80);
this.setIconAndIncrement(ButtonImages.IMG_BTN_START_DOWN, 480, 360, 160, 80);
this.setIconAndIncrement(ButtonImages.IMG_BTN_UP_LEFT, 80, 0, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_UP_CENTER, 120, 0, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_UP_RIGHT, 160, 0, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_OVER_LEFT, 80, 40, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_OVER_CENTER, 120, 40, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_OVER_RIGHT, 160, 40, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DOWN_LEFT, 80, 80, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DOWN_CENTER, 120, 80, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DOWN_RIGHT, 160, 80, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_FOCUS_LEFT, 80, 120, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_FOCUS_CENTER, 120, 120, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_FOCUS_RIGHT, 160, 120, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_TOGGLE_LEFT, 80, 160, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_TOGGLE_CENTER, 120, 160, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_TOGGLE_RIGHT, 160, 160, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DISABLED_LEFT, 80, 200, 40, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DISABLED_CENTER, 120, 200, 1, 40);
this.setIconAndIncrement(ButtonImages.IMG_BTN_DISABLED_RIGHT, 160, 200, 40, 40);
// Foils and creatures have a separate sprite, so use specific methods.
for (Foils e : Foils.values()) { this.setFoil(e); }
for (CreatureIcons e : CreatureIcons.values()) { this.setCreature(e); }
}
/**
* <p>
* getColorFromPixel.
* </p>
*
* @param {@link java.lang.Integer} pixel information
*/
private Color getColorFromPixel(final int pixel) {
int r, g, b, a;
a = (pixel >> 24) & 0x000000ff;
r = (pixel >> 16) & 0x000000ff;
g = (pixel >> 8) & 0x000000ff;
b = (pixel) & 0x000000ff;
return new Color(r, g, b, a);
/** (Should) clear memory resources for this skin object. */
public void unloadSkin() {
this.icons.clear();
this.images.clear();
this.colors.clear();
this.foils.clear();
this.plainFonts.clear();
this.boldFonts.clear();
this.italicFonts.clear();
this.bimCreatures.flush();
this.bimDefaultSprite.flush();
this.bimFoils.flush();
this.bimPreferredSprite.flush();
this.bimCreatures = null;
this.bimDefaultSprite = null;
this.bimFoils = null;
this.bimPreferredSprite = null;
}
/** @return {@link java.awt.font} font */
@@ -382,20 +549,6 @@ public class FSkin {
return plainFonts.get(size);
}
private void setFontAndIncrement(int size) {
plainFonts.put(size, font.deriveFont(Font.PLAIN, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setBoldFontAndIncrement(int size) {
boldFonts.put(size, font.deriveFont(Font.BOLD, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setItalicFontAndIncrement(int size) {
italicFonts.put(size, font.deriveFont(Font.ITALIC, size));
if (barProgress != null) { barProgress.increment(); }
}
/**
* @param size - integer, pixel size
* @return {@link java.awt.font} font1
@@ -428,9 +581,19 @@ public class FSkin {
}
/**
* Gets the icon.
* Gets an image.
*
* @param s0 &emsp; String address
* @param s0 &emsp; SkinProp enum
* @return Image
*/
public Image getImage(final SkinProp s0) {
return this.images.get(s0);
}
/**
* Gets an icon.
*
* @param s0 &emsp; SkinProp enum
* @return ImageIcon
*/
public ImageIcon getIcon(final SkinProp s0) {
@@ -452,112 +615,21 @@ public class FSkin {
w0 = (w0 < 1) ? 1 : w0;
h0 = (h0 < 1) ? 1 : h0;
final BufferedImage original = (BufferedImage) this.icons.get(s0).getImage();
final Image original =
(this.icons.get(s0) == null
? this.images.get(s0)
: this.icons.get(s0).getImage());
final BufferedImage scaled = new BufferedImage(w0, h0, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = scaled.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(original, 0, 0, w0, h0, 0, 0, original.getWidth(), original.getHeight(), null);
g2d.drawImage(original, 0, 0, w0, h0, 0, 0, original.getWidth(null), original.getHeight(null), null);
g2d.dispose();
return new ImageIcon(scaled);
}
/**
* Sets an icon in this skin's icon map from a file address.
* Throws IO exception for debugging if needed.
*
* @param s0
* &emsp; Skin property (from enum)
* @param s1
* &emsp; File address
*/
private void setIcon(final SkinProp s0, final String s1) {
try {
final File file = new File(s1);
ImageIO.read(file);
} catch (IOException e) {
System.err.println(this.notfound + preferredDir + FILE_SPLASH);
e.printStackTrace();
}
this.icons.put(s0, new ImageIcon(s1));
}
/**
* Checks the preferred sprite for existence of a sub-image
* defined by X, Y, W, H.
*
* If an image is not present at those coordinates, default
* icon is substituted.
*
* The result is saved in a HashMap.
*
* @param s0 &emsp; An address in the hashmap, derived from SkinProp enum
* @param x0 &emsp; X-coord of sub-image
* @param y0 &emsp; Y-coord of sub-image
* @param w0 &emsp; Width of sub-image
* @param h0 &emsp; Height of sub-image
*/
private void setIconAndIncrement(final SkinProp s0,
final int x0, final int y0, final int w0, final int h0) {
// Test if requested sub-image in inside bounds of preferred sprite.
// (Height and width of preferred sprite were set in loadFontAndImages.)
Boolean exists = false;
if (x0 <= preferredW
&& x0 + w0 <= preferredW
&& y0 <= preferredH
&& y0 + h0 <= preferredH) {
exists = true;
}
// Test if various points of requested sub-image are transparent.
// If any return true, image exists.
if (exists) {
int x, y;
Color c;
exists = false;
// Center
x = (int) (x0 + w0 / 2);
y = (int) (y0 + h0 / 2);
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { exists = true; }
x += 2;
y += 2;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { exists = true; }
x -= 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { exists = true; }
y -= 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { exists = true; }
x += 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { exists = true; }
}
BufferedImage img = (exists ? bimPreferredSprite : bimDefaultSprite);
BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
this.icons.put(s0, new ImageIcon(bi0));
if (barProgress != null) { barProgress.increment(); }
}
/**
* Sets an icon in this skin's icon map from a buffered image.
*
* @param s0 &emsp; Skin property (from enum)
* @param bi0 &emsp; BufferedImage
*/
public void setIcon(final SkinProp s0, final BufferedImage bi0) {
this.icons.put(s0, new ImageIcon(bi0));
}
/**
* Retrieves a color from this skin's color map.
*
@@ -568,18 +640,6 @@ public class FSkin {
return this.colors.get(s0);
}
/**
* Sets a color in this skin's color map.
*
* @param s0
* &emsp; Skin property (from enum)
* @param c0
* &emsp; Color
*/
public void setColor(final SkinProp s0, final Color c0) {
this.colors.put(s0, c0);
}
/**
* Gets the skins.
*
@@ -602,4 +662,185 @@ public class FSkin {
return mySkins;
}
/**
* <p>
* getColorFromPixel.
* </p>
*
* @param {@link java.lang.Integer} pixel information
*/
private Color getColorFromPixel(final int pixel) {
int r, g, b, a;
a = (pixel >> 24) & 0x000000ff;
r = (pixel >> 16) & 0x000000ff;
g = (pixel >> 8) & 0x000000ff;
b = (pixel) & 0x000000ff;
return new Color(r, g, b, a);
}
private BufferedImage testPreferredSprite(SkinProp s0) {
int[] coords = ((Coords) s0).getCoords();
int x0 = coords[0];
int y0 = coords[1];
int w0 = coords[2];
int h0 = coords[3];
// Test if requested sub-image in inside bounds of preferred sprite.
// (Height and width of preferred sprite were set in loadFontAndImages.)
if (x0 > preferredW || x0 + w0 > preferredW
|| y0 > preferredH || y0 + h0 > preferredH) {
return bimDefaultSprite;
}
// Test if various points of requested sub-image are transparent.
// If any return true, image exists.
int x = 0, y = 0;
Color c;
// Center
x = (int) (x0 + w0 / 2);
y = (int) (y0 + h0 / 2);
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { return bimPreferredSprite; }
x += 2;
y += 2;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { return bimPreferredSprite; }
x -= 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { return bimPreferredSprite; }
y -= 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { return bimPreferredSprite; }
x += 4;
c = this.getColorFromPixel(bimPreferredSprite.getRGB(x, y));
if (c.getAlpha() != 0) { return bimPreferredSprite; }
return bimDefaultSprite;
}
private void setFoil(final SkinProp s0) {
int[] coords = ((Coords) s0).getCoords();
int x0 = coords[0];
int y0 = coords[1];
int w0 = coords[2];
int h0 = coords[3];
this.foils.put(s0, bimFoils.getSubimage(x0, y0, w0, h0));
}
private void setCreature(final SkinProp s0) {
int[] coords = ((Coords) s0).getCoords();
int x0 = coords[0];
int y0 = coords[1];
int w0 = coords[2];
int h0 = coords[3];
this.icons.put(s0, new ImageIcon(bimCreatures.getSubimage(x0, y0, w0, h0)));
}
private void setColor(final SkinProp s0, final Color c0) {
this.colors.put(s0, c0);
}
private void setFontAndIncrement(int size) {
plainFonts.put(size, font.deriveFont(Font.PLAIN, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setBoldFontAndIncrement(int size) {
boldFonts.put(size, font.deriveFont(Font.BOLD, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setItalicFontAndIncrement(int size) {
italicFonts.put(size, font.deriveFont(Font.ITALIC, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setIcon(final SkinProp s0) {
int[] coords = ((Coords) s0).getCoords();
int x0 = coords[0];
int y0 = coords[1];
int w0 = coords[2];
int h0 = coords[3];
BufferedImage img = testPreferredSprite(s0);
this.icons.put(s0, new ImageIcon(img.getSubimage(x0, y0, w0, h0)));
}
/**
* Sets an icon in this skin's icon map from a file address.
* Throws IO exception for debugging if needed.
*
* @param s0
* &emsp; Skin property (from enum)
* @param s1
* &emsp; File address
*/
private void setIcon(final SkinProp s0, final String s1) {
try {
final File file = new File(s1);
ImageIO.read(file);
} catch (IOException e) {
System.err.println(this.notfound + preferredDir + FILE_SPLASH);
e.printStackTrace();
}
this.icons.put(s0, new ImageIcon(s1));
}
/**
* Sets an icon in this skin's icon map from a buffered image.
*
* @param s0 &emsp; Skin property (from enum)
* @param bi0 &emsp; BufferedImage
*/
private void setIcon(final SkinProp s0, final BufferedImage bi0) {
this.icons.put(s0, new ImageIcon(bi0));
}
/**
* setImage, with auto-scaling assumed true.
*
* @param s0
*/
private void setImage(final SkinProp s0) {
setImage(s0, true);
}
/**
* Checks the preferred sprite for existence of a sub-image
* defined by X, Y, W, H.
*
* If an image is not present at those coordinates, default
* icon is substituted.
*
* The result is saved in a HashMap.
*
* @param s0 &emsp; An address in the hashmap, derived from SkinProp enum
*/
private void setImage(final SkinProp s0, boolean scale) {
int[] coords = ((Coords) s0).getCoords();
int x0 = coords[0];
int y0 = coords[1];
int w0 = coords[2];
int h0 = coords[3];
int newW = (coords.length == 6 ? coords[4] : 0);
int newH = (coords.length == 6 ? coords[5] : 0);
BufferedImage img = testPreferredSprite(s0);
BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
if (scale && newW != 0) {
this.images.put(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING));
}
else {
this.images.put(s0, bi0);
}
}
}