parent
9472b078d5
commit
85504af5c4
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,86 +0,0 @@
|
|||
package magic.data;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import magic.MagicMain;
|
||||
|
||||
public class PlayerImages {
|
||||
|
||||
private static final PlayerImages INSTANCE=new PlayerImages();
|
||||
|
||||
private final File files[];
|
||||
private final int nrOfImages;
|
||||
private final boolean[] loaded;
|
||||
private final ImageIcon[] largeImages;
|
||||
private final ImageIcon[] mediumImages;
|
||||
private final ImageIcon[] smallImages;
|
||||
|
||||
private PlayerImages() {
|
||||
|
||||
files=new File(MagicMain.getGamePath()+File.separator+"avatars").listFiles();
|
||||
nrOfImages=files==null?2:Math.max(2,files.length);
|
||||
loaded=new boolean[nrOfImages];
|
||||
largeImages=new ImageIcon[nrOfImages];
|
||||
mediumImages=new ImageIcon[nrOfImages];
|
||||
smallImages=new ImageIcon[nrOfImages];
|
||||
}
|
||||
|
||||
public int getNrOfImages() {
|
||||
|
||||
return nrOfImages;
|
||||
}
|
||||
|
||||
public List<Integer> getImageIndices() {
|
||||
|
||||
final List<Integer> indices=new ArrayList<Integer>();
|
||||
for (int index=0;index<nrOfImages;index++) {
|
||||
|
||||
indices.add(index);
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
private void loadIcon(final int index) {
|
||||
|
||||
loaded[index]=true;
|
||||
BufferedImage image;
|
||||
try {
|
||||
final InputStream stream=new FileInputStream(files[index]);
|
||||
image=ImageIO.read(stream);
|
||||
stream.close();
|
||||
} catch (final Exception ex) {
|
||||
image=IconImages.MISSING;
|
||||
}
|
||||
largeImages[index]=new ImageIcon(image);
|
||||
final Image mediumImage=image.getScaledInstance(image.getWidth()/2,image.getHeight()/2,Image.SCALE_SMOOTH);
|
||||
mediumImages[index]=new ImageIcon(mediumImage);
|
||||
final Image smallImage=image.getScaledInstance(image.getWidth()/4,image.getHeight()/4,Image.SCALE_SMOOTH);
|
||||
smallImages[index]=new ImageIcon(smallImage);
|
||||
}
|
||||
|
||||
public synchronized ImageIcon getIcon(final int index,final int size) {
|
||||
|
||||
if (!loaded[index]) {
|
||||
loadIcon(index);
|
||||
}
|
||||
switch (size) {
|
||||
case 2: return mediumImages[index];
|
||||
case 3: return largeImages[index];
|
||||
default: return smallImages[index];
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerImages getInstance() {
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -11,9 +12,10 @@ import magic.MagicMain;
|
|||
import magic.data.BoosterPackGenerator;
|
||||
import magic.data.CubeDefinitions;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.data.PlayerImages;
|
||||
import magic.data.TournamentConfig;
|
||||
import magic.model.phase.MagicDefaultGameplay;
|
||||
import magic.ui.theme.Theme;
|
||||
import magic.ui.theme.ThemeFactory;
|
||||
|
||||
public class MagicTournament {
|
||||
|
||||
|
@ -136,19 +138,30 @@ public class MagicTournament {
|
|||
determineStartPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> getAvatarIndices(final int avatars) {
|
||||
|
||||
final List<Integer> indices=new ArrayList<Integer>();
|
||||
for (int index=0;index<avatars;index++) {
|
||||
|
||||
indices.add(index);
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
private MagicPlayerDefinition[] createPlayers() {
|
||||
|
||||
final List<Integer> faces=PlayerImages.getInstance().getImageIndices();
|
||||
final Theme theme=ThemeFactory.getInstance().getCurrentTheme();
|
||||
final List<Integer> avatars=getAvatarIndices(theme.getNumberOfAvatars());
|
||||
|
||||
final MagicPlayerDefinition players[]=new MagicPlayerDefinition[2];
|
||||
|
||||
final MagicPlayerDefinition player=new MagicPlayerDefinition(configuration.getName(),false,configuration.getPlayerProfile(),configuration.getAvatar());
|
||||
players[0]=player;
|
||||
faces.remove(player.getFace());
|
||||
avatars.remove(player.getFace());
|
||||
|
||||
final int findex=MagicRandom.nextInt(faces.size());
|
||||
final Integer face=faces.get(findex);
|
||||
final int findex=MagicRandom.nextInt(avatars.size());
|
||||
final Integer face=avatars.get(findex);
|
||||
players[1]=new MagicPlayerDefinition(COMPUTER,true,configuration.getOpponentProfile(),face);
|
||||
|
||||
return players;
|
||||
|
|
|
@ -24,7 +24,6 @@ import javax.swing.ListCellRenderer;
|
|||
|
||||
import magic.data.CubeDefinitions;
|
||||
import magic.data.IconImages;
|
||||
import magic.data.PlayerImages;
|
||||
import magic.data.TournamentConfig;
|
||||
import magic.model.MagicColor;
|
||||
import magic.ui.theme.Theme;
|
||||
|
@ -47,6 +46,7 @@ public class TournamentDialog extends JDialog implements ActionListener {
|
|||
private final JComboBox cubeComboBox;
|
||||
private final JButton okButton;
|
||||
private final JButton cancelButton;
|
||||
private final Theme theme;
|
||||
|
||||
public TournamentDialog(final MagicFrame frame) {
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class TournamentDialog extends JDialog implements ActionListener {
|
|||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
final Theme theme=ThemeFactory.getInstance().getCurrentTheme();
|
||||
theme=ThemeFactory.getInstance().getCurrentTheme();
|
||||
|
||||
final TournamentConfig config=TournamentConfig.getInstance();
|
||||
config.load();
|
||||
|
@ -157,7 +157,7 @@ public class TournamentDialog extends JDialog implements ActionListener {
|
|||
}
|
||||
}
|
||||
|
||||
private static class AvatarPanel extends JPanel implements ActionListener {
|
||||
private class AvatarPanel extends JPanel implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -173,7 +173,7 @@ public class TournamentDialog extends JDialog implements ActionListener {
|
|||
setLayout(new BorderLayout(0,5));
|
||||
|
||||
avatarLabel=new JLabel();
|
||||
avatarLabel.setIcon(PlayerImages.getInstance().getIcon(avatar,3));
|
||||
avatarLabel.setIcon(theme.getAvatarIcon(avatar,3));
|
||||
add(avatarLabel,BorderLayout.CENTER);
|
||||
|
||||
final JPanel buttonPanel=new JPanel();
|
||||
|
@ -202,15 +202,15 @@ public class TournamentDialog extends JDialog implements ActionListener {
|
|||
if (source==leftButton) {
|
||||
avatar--;
|
||||
if (avatar<0) {
|
||||
avatar=PlayerImages.getInstance().getNrOfImages()-1;
|
||||
avatar=theme.getNumberOfAvatars()-1;
|
||||
}
|
||||
} else {
|
||||
avatar++;
|
||||
if (avatar==PlayerImages.getInstance().getNrOfImages()) {
|
||||
if (avatar==theme.getNumberOfAvatars()) {
|
||||
avatar=0;
|
||||
}
|
||||
}
|
||||
avatarLabel.setIcon(PlayerImages.getInstance().getIcon(avatar,3));
|
||||
avatarLabel.setIcon(theme.getAvatarIcon(avatar,3));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,20 @@ package magic.ui.theme;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import magic.MagicMain;
|
||||
import magic.data.IconImages;
|
||||
import magic.ui.widget.FontsAndBorders;
|
||||
|
||||
|
@ -14,11 +23,15 @@ public abstract class AbstractTheme implements Theme {
|
|||
|
||||
private final String name;
|
||||
private final Map<String,Object> themeMap;
|
||||
private final List<File> avatarFiles;
|
||||
private final PlayerAvatar avatars[];
|
||||
|
||||
public AbstractTheme(final String name) {
|
||||
|
||||
this.name=name;
|
||||
themeMap=new HashMap<String,Object>();
|
||||
avatarFiles=new ArrayList<File>();
|
||||
avatars=loadAvatars(avatarFiles);
|
||||
|
||||
addToTheme(TEXTURE_LOGO,null);
|
||||
|
||||
|
@ -120,4 +133,45 @@ public abstract class AbstractTheme implements Theme {
|
|||
final Object value=themeMap.get(name);
|
||||
return value==null?0:(Integer)value;
|
||||
}
|
||||
|
||||
private PlayerAvatar[] loadAvatars(final List<File> avatarFiles) {
|
||||
|
||||
final File files[]=new File(MagicMain.getGamePath()+File.separator+"avatars").listFiles();
|
||||
if (files==null||files.length<2) {
|
||||
avatarFiles.add(new File("unknown"));
|
||||
avatarFiles.add(new File("unknown"));
|
||||
} else {
|
||||
avatarFiles.addAll(Arrays.asList(files));
|
||||
}
|
||||
Collections.sort(avatarFiles);
|
||||
return new PlayerAvatar[avatarFiles.size()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfAvatars() {
|
||||
|
||||
return avatars.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized ImageIcon getAvatarIcon(int index,final int size) {
|
||||
|
||||
if (index<0||index>=avatars.length) {
|
||||
index=0;
|
||||
}
|
||||
PlayerAvatar avatar=avatars[index];
|
||||
if (avatar==null) {
|
||||
BufferedImage image;
|
||||
try {
|
||||
final InputStream stream=new FileInputStream(avatarFiles.get(index));
|
||||
image=ImageIO.read(stream);
|
||||
stream.close();
|
||||
} catch (final Exception ex) {
|
||||
image=IconImages.MISSING;
|
||||
}
|
||||
avatar=new PlayerAvatar(image);
|
||||
avatars[index]=avatar;
|
||||
}
|
||||
return avatar.getIcon(index,size);
|
||||
}
|
||||
}
|
|
@ -19,17 +19,40 @@ import magic.data.IconImages;
|
|||
public class CustomTheme extends AbstractTheme {
|
||||
|
||||
private static final String THEME_PROPERTIES_FILE="theme.properties";
|
||||
|
||||
private static final int MAX_AVATARS=100;
|
||||
|
||||
private final File file;
|
||||
private ZipFile zipFile=null;
|
||||
private boolean loaded=false;
|
||||
private PlayerAvatar playerAvatars[];
|
||||
private int nrOfAvatars=0;
|
||||
|
||||
public CustomTheme(final File file,final String name) {
|
||||
|
||||
super(name);
|
||||
this.file=file;
|
||||
playerAvatars=new PlayerAvatar[MAX_AVATARS];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfAvatars() {
|
||||
|
||||
if (nrOfAvatars==0) {
|
||||
return super.getNumberOfAvatars();
|
||||
}
|
||||
return nrOfAvatars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageIcon getAvatarIcon(final int index,final int size) {
|
||||
|
||||
if (index>=nrOfAvatars) {
|
||||
return super.getAvatarIcon(index, size);
|
||||
}
|
||||
return playerAvatars[index].getIcon(index,size);
|
||||
}
|
||||
|
||||
private void parseEntry(final String key,final String value) {
|
||||
|
||||
if (value.isEmpty()) {
|
||||
|
@ -41,6 +64,15 @@ public class CustomTheme extends AbstractTheme {
|
|||
}
|
||||
Object typeValue=null;
|
||||
final String type=key.substring(0,index);
|
||||
if ("avatar".equals(type)) {
|
||||
final int avatarIndex=Integer.parseInt(key.substring(index+1));
|
||||
if (avatarIndex>0&&avatarIndex<=MAX_AVATARS) {
|
||||
final BufferedImage image=loadImage("avatars/"+value);
|
||||
playerAvatars[avatarIndex-1]=new PlayerAvatar(image);
|
||||
nrOfAvatars=Math.max(avatarIndex,nrOfAvatars);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ("value".equals(type)) {
|
||||
typeValue=Integer.parseInt(value);
|
||||
} else if ("color".equals(type)) {
|
||||
|
@ -105,7 +137,7 @@ public class CustomTheme extends AbstractTheme {
|
|||
for (final Map.Entry<Object,Object> entry : properties.entrySet()) {
|
||||
|
||||
parseEntry(entry.getKey().toString(),entry.getValue().toString().trim());
|
||||
}
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
} finally {
|
||||
if (zipFile!=null) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package magic.ui.theme;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class PlayerAvatar {
|
||||
|
||||
private static final int LARGE_SIZE=120;
|
||||
private static final int MEDIUM_SIZE=LARGE_SIZE/2;
|
||||
private static final int SMALL_SIZE=LARGE_SIZE/4;
|
||||
|
||||
private final ImageIcon largeIcon;
|
||||
private final ImageIcon mediumIcon;
|
||||
private final ImageIcon smallIcon;
|
||||
|
||||
public PlayerAvatar(final BufferedImage image) {
|
||||
|
||||
final Image largeImage=image.getScaledInstance(LARGE_SIZE,LARGE_SIZE,Image.SCALE_SMOOTH);
|
||||
largeIcon=new ImageIcon(largeImage);
|
||||
final Image mediumImage=image.getScaledInstance(MEDIUM_SIZE,MEDIUM_SIZE,Image.SCALE_SMOOTH);
|
||||
mediumIcon=new ImageIcon(mediumImage);
|
||||
final Image smallImage=image.getScaledInstance(SMALL_SIZE,SMALL_SIZE,Image.SCALE_SMOOTH);
|
||||
smallIcon=new ImageIcon(smallImage);
|
||||
}
|
||||
|
||||
public ImageIcon getIcon(final int index,final int size) {
|
||||
|
||||
switch (size) {
|
||||
case 2: return mediumIcon;
|
||||
case 3: return largeIcon;
|
||||
default: return smallIcon;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -65,4 +65,8 @@ public interface Theme {
|
|||
public Color getChoiceColor();
|
||||
|
||||
public int getValue(final String name);
|
||||
|
||||
public int getNumberOfAvatars();
|
||||
|
||||
public ImageIcon getAvatarIcon(final int index,final int size);
|
||||
}
|
|
@ -8,8 +8,9 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JPanel;
|
||||
|
||||
import magic.data.IconImages;
|
||||
import magic.data.PlayerImages;
|
||||
import magic.model.MagicMessage;
|
||||
import magic.ui.theme.Theme;
|
||||
import magic.ui.theme.ThemeFactory;
|
||||
|
||||
public class MessagePanel extends JPanel {
|
||||
|
||||
|
@ -27,9 +28,10 @@ public class MessagePanel extends JPanel {
|
|||
final JPanel leftPanel=new JPanel(new BorderLayout(2,0));
|
||||
leftPanel.setOpaque(false);
|
||||
add(leftPanel,BorderLayout.WEST);
|
||||
|
||||
|
||||
final Theme theme=ThemeFactory.getInstance().getCurrentTheme();
|
||||
final int face=message.getPlayer().getPlayerDefinition().getFace();
|
||||
final JLabel playerLabel=new JLabel(PlayerImages.getInstance().getIcon(face,1));
|
||||
final JLabel playerLabel=new JLabel(theme.getAvatarIcon(face,1));
|
||||
leftPanel.add(playerLabel,BorderLayout.WEST);
|
||||
|
||||
final int life=message.getLife();
|
||||
|
|
|
@ -8,7 +8,6 @@ import javax.swing.ImageIcon;
|
|||
import javax.swing.JLabel;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import magic.data.PlayerImages;
|
||||
import magic.model.MagicPlayerDefinition;
|
||||
import magic.ui.theme.Theme;
|
||||
import magic.ui.theme.ThemeFactory;
|
||||
|
@ -79,7 +78,8 @@ public class PlayerAvatarPanel extends TexturedPanel {
|
|||
|
||||
public void update() {
|
||||
|
||||
final ImageIcon faceIcon=PlayerImages.getInstance().getIcon(playerDefinition.getFace(),small?2:3);
|
||||
final Theme theme=ThemeFactory.getInstance().getCurrentTheme();
|
||||
final ImageIcon faceIcon=theme.getAvatarIcon(playerDefinition.getFace(),small?2:3);
|
||||
faceLabel.setIcon(faceIcon);
|
||||
titleBar.setText(playerDefinition.getName());
|
||||
if (small) {
|
||||
|
|
Loading…
Reference in New Issue