📄 picturepanel.java
字号:
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 100);
}
else if (view == VIEW_BORDER_THREAT) {
Player player = ((Country)game.getCountryInt( c+1 )).getOwner();
if (player != game.getCurrentPlayer() ) {
val = Color.gray;
}
else {
Vector neighbours = ((Country)game.getCountryInt( c+1 )).getNeighbours();
int threat=0; // max of about 6
for (int j = 0; j < neighbours.size() ; j++) {
if ( ((Country)neighbours.elementAt(j)).getOwner() != player ) {
threat++;
}
}
threat=threat*40;
if (threat > 255) { threat=255; }
val = (new Color( threat, 0, 0));
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 200);
}
else if (view == VIEW_CARD_OWNERSHIP) {
if ( game.getCurrentPlayer()==null || ((Country)game.getCountryInt(c+1)).getOwner() != (Player)game.getCurrentPlayer()) {
val = Color.lightGray;
}
else {
Vector cards = ((Player)game.getCurrentPlayer()).getCards();
for (int j = 0; j < cards.size() ; j++) {
if ( ((Card)cards.elementAt(j)).getCountry() == (Country)game.getCountryInt(c+1) ) {
val = Color.blue;
}
}
if (val == null) val = Color.darkGray;
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 100);
}
else if (view == VIEW_TROOP_STRENGTH) {
if (((Country)game.getCountryInt(c+1)).getOwner() != (Player)game.getCurrentPlayer()) {
val = Color.gray;
}
else {
int armies = ((Country)game.getCountryInt(c+1)).getArmies();
armies=armies*25;
if (armies > 255) { armies=255; }
val = (new Color( 0 , armies, 0));
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 200);
}
else if (view == VIEW_CONNECTED_EMPIRE) {
Country thecountry = game.getCountryInt( c+1 );
if ( thecountry.getOwner() == null ) {
val = Color.LIGHT_GRAY;
}
else if ( b.contains( thecountry ) ) {
val = ((Player)thecountry.getOwner()).getColor();
}
else {
val = Color.DARK_GRAY;
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 100);
/*
Country thecountry = ((Country)game.getCountryInt(c+1));
if ( b != null && b.contains( thecountry ) ) {
val = ((Player)game.getCurrentPlayer()).getColor();
}
else if (((Country)game.getCountryInt(c+1)).getOwner() == (Player)game.getCurrentPlayer()) {
val = Color.darkGray;
}
else {
val = Color.lightGray;
}
val = new Color(val.getRed(), val.getGreen(), val.getBlue(), 100);
*/
}
countryImage ci = CountryImages[c];
int x1=ci.getX1();
int y1=ci.getY1();
BufferedImage normalB = ci.getNormalImage(); // new BufferedImage( w ,h, java.awt.image.BufferedImage.TYPE_INT_ARGB );
if ( ci.checkChange(val) ) {
int y2=ci.getY2();
int w=ci.getWidth();
int h=ci.getHeight();
BufferedImage normalA = ci.getTemp1(); // new BufferedImage( w ,h, java.awt.image.BufferedImage.TYPE_INT_RGB );
BufferedImage highlightA = ci.getTemp2(); // new BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_RGB );
BufferedImage highlightB = ci.getHighLightImage(); // new BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB );
Graphics tempg = normalA.getGraphics();
if (view == VIEW_CONTINENTS) {
tempg.drawImage( ci.getSourceImage() ,0,0,this );
}
else {
tempg.drawImage( ci.getGrayImage(), 0, 0, this);
tempg.setColor( val );
tempg.fillRect(0,0,w,h);
}
tempg.dispose();
HighLight.filter( normalA , highlightA );
if (view != VIEW_CONTINENTS) { Graphics zg = normalB.getGraphics(); zg.drawImage(normalA,0,0,this); zg.dispose(); }
{ Graphics zg = highlightB.getGraphics(); zg.drawImage(highlightA,0,0,this); zg.dispose(); }
for(int y=y1; y <= y2; y++) {
for(int x=0; x < w; x++) {
if (map[x+x1][y] != (c+1) ) {
normalB.setRGB( x, (y-y1), 0); // clear the un-needed area!
highlightB.setRGB( x, (y-y1), 0); // clear the un-needed area!
}
}
}
}
if (view != VIEW_CONTINENTS) { Graphics zg = tempimg.getGraphics(); zg.drawImage(normalB ,x1 ,y1 ,this); zg.dispose(); }
}
BufferedImage newback = img;
img = tempimg;
tempimg = newback;
}
/**
* Gets the unique identifier of a country from its position on the map
* @param x x co-ordinate on the map
* @param y y co-ordinate on the map
*/
public int getCountryNumber(int x, int y) {
double s = getScale();
x = x - getDrawImageX(s);
y = y - getDrawImageY(s);
x = (int)(x / s);
y = (int)(y / s);
if (x<0 || y<0 || x>=map.length || y>=map[0].length) {
return NO_COUNTRY;
}
return map[x][y];
}
/**
* Sets which country to hilight
* @param a number of the country
*/
public void setHighLight(int a) {
cc=a;
}
/**
* Returns which country is hilighted
* @return int Returns which country is hilighted
*/
public int getHighLight() {
return cc;
}
/**
* Sets the attacking country
* @param a number of the country
*/
public void setC1(int a) {
c1=a;
}
/**
* Sets the defensive country
* @param a number of the country
*/
public void setC2(int a) {
c2=a;
}
/**
* Returns the attacking country
* @return int number of the country
*/
public int getC1() {
return c1;
}
public int getC2() {
return c2;
}
// Subclass countryImage - holds all the image information
class countryImage {
private int x1;
private int y1;
private int x2;
private int y2;
private BufferedImage SourceImage;
private BufferedImage GrayImage;
private BufferedImage normalImage;
private BufferedImage HighLightImage;
private BufferedImage temp1;
private BufferedImage temp2;
private Color color;
public countryImage() {
x1=map.length;
y1=map[0].length;
x2=0;
y2=0;
SourceImage=null;
GrayImage=null;
HighLightImage=null;
normalImage=null;
}
public boolean checkChange(Color b) {
if (!b.equals(color) ) {
color = b;
return true;
}
return false;
}
public void setTemp1(BufferedImage a) {
temp1=a;
}
public void setTemp2(BufferedImage a) {
temp2=a;
}
public BufferedImage getTemp1() {
return temp1;
}
public BufferedImage getTemp2() {
return temp2;
}
/**
* Sets the source image
* @param a Image buffered
*/
public void setSourceImage(BufferedImage a) {
SourceImage=a;
}
/**
* Sets the gray image
* @param a Image buffered
*/
public void setGrayImage(BufferedImage a) {
GrayImage=a;
}
/**
* Sets the hilighted image
* @param a Image buffered
*/
public void setHighLightImage(BufferedImage a) {
HighLightImage=a;
}
public void setNormalImage(BufferedImage a) {
normalImage=a;
}
/**
* Sets the top left corner of a country
* @param a coordinate
*/
public void setX1(int a) {
x1=a;
}
/**
* Sets the bottom left corner of a country
* @param a coordinate
*/
public void setY1(int a) {
y1=a;
}
/**
* Sets the top right corner of a country
* @param a coordinate
*/
public void setX2(int a) {
x2=a;
}
/**
* Sets the bottom right corner of a country
* @param a coordinate
*/
public void setY2(int a) {
y2=a;
}
/**
* Gets the source image
* @return BufferedImage Returns the source image
*/
public BufferedImage getSourceImage() {
return SourceImage;
}
/**
* Gets the gray image
* @return BufferedImage Returns the gray image
*/
public BufferedImage getGrayImage() {
return GrayImage;
}
/**
* Gets the hilighted image
* @return BufferedImage Returns the hilighted image
*/
public BufferedImage getHighLightImage() {
return HighLightImage;
}
public BufferedImage getNormalImage() {
return normalImage;
}
/**
* Gets the top left corner of a country
* @return int coordinate
*/
public int getX1() {
return x1;
}
/**
* Gets the bottom left corner of a country
* @return int coordinate
*/
public int getY1() {
return y1;
}
/**
* Gets the top right corner of a country
* @return int coordinate
*/
public int getX2() {
return x2;
}
/**
* Gets the bottom right corner of a country
* @return int coordinate
*/
public int getY2() {
return y2;
}
/**
* Gets the width of a country
* @return int width of a country
*/
public int getWidth() {
return (x2-x1+1);
}
/**
* Gets the height of a country
* @return int height of a country
*/
public int getHeight() {
return (y2-y1+1);
}
}
/**
* Gets the image of a country
* @param num the index of a country
* @param incolor whether the image of a country is in colour or greyscale
* @return BufferedImage Image buffered of a country
*/
public BufferedImage getCountryImage(int num, boolean incolor) {
int i = num-1;
countryImage ci = CountryImages[i];
int x1=ci.getX1();
// int x2=ci.getX2();
int y1=ci.getY1();
int y2=ci.getY2();
int w=ci.getWidth();
int h=ci.getHeight();
BufferedImage pictureA = new BufferedImage( w ,h, java.awt.image.BufferedImage.TYPE_INT_RGB );
RescaleOp HighLight = new RescaleOp( 0.5f, -1.0f, null);
HighLight.filter( ci.getGrayImage() , pictureA );
BufferedImage pictureB = new BufferedImage( w ,h, java.awt.image.BufferedImage.TYPE_INT_ARGB );
Graphics g = pictureB.getGraphics();
g.drawImage( pictureA ,0 ,0 ,this);
if (incolor) {
Color ownerColor = ((Player) ((Country) ((RiskGame)myrisk.getGame()) .getCountryInt( num )) .getOwner()).getColor();
g.setColor( new Color(ownerColor.getRed(), ownerColor.getGreen(), ownerColor.getBlue(), 100) );
g.fillRect(0,0,w,h);
}
for(int y=y1; y <= y2; y++) {
for(int x=0; x <= w-1; x++) {
if (map[x+x1][y] != (i+1) ) {
pictureB.setRGB( x, (y-y1), 0); // clear the un-needed area!
}
}
}
g.dispose();
return pictureB;
}
public static Image getImage(RiskGame game) throws Exception {
// attempt to get the preview as its smaller
String imagename = game.getPreviewPic();
if (imagename==null) {
return Toolkit.getDefaultToolkit().getImage( new URL(RiskUtil.mapsdir,game.getImagePic() ) ).getScaledInstance(203,127, java.awt.Image.SCALE_SMOOTH );
}
else {
BufferedImage s = ImageIO.read(RiskUtil.openMapStream("preview/"+imagename) );
String name = game.getMapName();
BufferedImage tmpimg = new BufferedImage( 203,127, java.awt.image.BufferedImage.TYPE_INT_RGB );
Graphics2D g = tmpimg.createGraphics();
//g.drawImage(s.getScaledInstance(203,127, java.awt.Image.SCALE_SMOOTH ),0,0,null );
g.drawImage(s,0,0,203,127,0,0,s.getWidth(),s.getHeight(),null);
//AffineTransform at = AffineTransform.getScaleInstance((double)203/s.getWidth(),(double)127/s.getHeight());
//g.drawRenderedImage(s,at);
if (name!=null) {
g.setColor( new Color(255,255,255, 150) );
g.fillRect(0,0,203,20);
g.setColor( Color.BLACK );
g.drawString(name,5,15);
}
g.dispose();
return tmpimg;
}
}
public Image getImage() {
return img;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -