Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/rotp/model/empires/Empire.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public final class Empire implements Base, NamedObject, Serializable {
private transient BufferedImage shipImageHuge;
private transient BufferedImage scoutImage;
private transient BufferedImage transportImage;
private transient BufferedImage raceBackImage;
private transient Color ownershipColor;
private transient Color selectionColor;
private transient Color reachColor;
Expand Down Expand Up @@ -234,6 +235,15 @@ public BufferedImage transportImage() {
transportImage = ShipLibrary.current().transportImage(shipColorId());
return transportImage;
}

public BufferedImage raceBackImage() {
return raceBackImage;
}

public void setRaceBackImage(BufferedImage image) {
raceBackImage = image;
}

public Color ownershipColor() {
if (ownershipColor == null) {
Color c = color();
Expand Down
69 changes: 56 additions & 13 deletions src/rotp/ui/races/RacesUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public class RacesUI extends BasePanel {
public static final Color darkBrown = new Color(112,85,68);
public static final Color darkerBrown = new Color(75,55,39);
public static final Color gradientBottom = new Color(110,79,56);
private static final Color raceEdgeColor = new Color(114,75,49);
private static final Color raceCenterColor = new Color(179,117,77);
private static final Color raceEdgeColor = new Color(8, 8, 8);
private static final Color raceCenterColor = new Color(255, 255, 255);
static Color[] relationsC = new Color[40];
public static BufferedImage raceBackImg;
public static BufferedImage raceIconBackImg;

private final List<Empire> empires = new ArrayList<>();
Expand Down Expand Up @@ -555,7 +554,7 @@ private void drawContact(Graphics2D g, Empire emp, int x, int y, int w, int h) {
boxFor(emp).setBounds(x0,y0,w0,h0);
g.setColor(darkBrown);
g.fillRect(x0, y0, w0, h0);
BufferedImage back = raceBackImg();
BufferedImage back = raceBackImg(emp);
int w1 = back.getWidth();
int h1 = back.getHeight();
int mgn = (h-h1)/2;
Expand Down Expand Up @@ -660,26 +659,70 @@ else if (otherDipGone)
}
}
}
public BufferedImage raceBackImg() {
if (raceBackImg == null)
initRaceBackImg();
return raceBackImg;
public BufferedImage raceBackImg(Empire emp) {

if (emp.raceBackImage() == null )
initRaceBackImg(emp);
return emp.raceBackImage();

}
private void initRaceBackImg() {
private void initRaceBackImg(Empire emp) {
int w = s76;
int h = s82;
raceBackImg = gc().createCompatibleImage(w, h);

emp.setRaceBackImage(gc().createCompatibleImage(w, h));
Point2D center = new Point2D.Float(w/2, h/2);
float radius = s78;
float[] dist = {0.0f, 0.1f, 0.5f, 1.0f};
Color[] colors = {raceCenterColor, raceCenterColor, raceEdgeColor, raceEdgeColor};
// gradient - method 1 (less flexible)
// Color[] colors = {
// emp.color().brighter().brighter(),
// emp.color().brighter().brighter(),
// emp.color().darker().darker(),
// emp.color().darker().darker()
// };
// gradient - method 2 - blending colors (more flexible)
Color[] colors = {
blendColor(raceCenterColor,emp.color(), 0.6f),
blendColor(raceCenterColor,emp.color(), 0.6f),
blendColor(raceEdgeColor,emp.color(), 0.6f),
blendColor(raceEdgeColor,emp.color(), 0.6f)
};


RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
Graphics2D g = (Graphics2D) raceBackImg.getGraphics();
Graphics2D g = (Graphics2D) emp.raceBackImage().getGraphics();
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
}

private Color blendColor( Color c1, Color c2, float ratio ) {
if ( ratio > 1f ) ratio = 1f;
else if ( ratio < 0f ) ratio = 0f;
float iRatio = 1.0f - ratio;

int i1 = c1.getRGB();
int i2 = c2.getRGB();

int a1 = (i1 >> 24 & 0xff);
int r1 = ((i1 & 0xff0000) >> 16);
int g1 = ((i1 & 0xff00) >> 8);
int b1 = (i1 & 0xff);

int a2 = (i2 >> 24 & 0xff);
int r2 = ((i2 & 0xff0000) >> 16);
int g2 = ((i2 & 0xff00) >> 8);
int b2 = (i2 & 0xff);

int a = (int)((a1 * iRatio) + (a2 * ratio));
int r = (int)((r1 * iRatio) + (r2 * ratio));
int g = (int)((g1 * iRatio) + (g2 * ratio));
int b = (int)((b1 * iRatio) + (b2 * ratio));

return new Color( a << 24 | r << 16 | g << 8 | b );
}
Comment on lines +700 to +724
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, if the "blending" option is used, this method really should not be here


private Rectangle boxFor(Empire emp) {
if (!contactBoxes.containsKey(emp))
contactBoxes.put(emp, new Rectangle());
Expand Down