Skip to content

Commit

Permalink
Merge branch 'master' into slim
Browse files Browse the repository at this point in the history
  • Loading branch information
wintertime committed Jul 4, 2020
2 parents a5c366c + 0ea8de9 commit 7b305b8
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 507 deletions.
43 changes: 42 additions & 1 deletion src/net/sf/freecol/client/control/MapEditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package net.sf.freecol.client.control;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -31,6 +32,7 @@
import net.sf.freecol.FreeCol;
import net.sf.freecol.client.FreeColClient;
import net.sf.freecol.client.gui.GUI;
import net.sf.freecol.client.gui.panel.MiniMap; // FIXME: should go away
import net.sf.freecol.common.FreeColException;
import net.sf.freecol.common.i18n.Messages;
import net.sf.freecol.common.io.FreeColDirectories;
Expand Down Expand Up @@ -59,6 +61,9 @@ public final class MapEditorController extends FreeColClientHolder {
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(MapEditorController.class.getName());

/** Map height in MapGeneratorOptionsDialog. */
private static final int MINI_MAP_THUMBNAIL_FINAL_HEIGHT = 64;

/**
* The transform that should be applied to a {@code Tile}
* that is clicked on the map.
Expand All @@ -76,6 +81,42 @@ public MapEditorController(FreeColClient freeColClient) {
}


/**
* Create a thumbnail for the minimap.
*
* FIXME: Delete all code inside this method and replace it with
* sensible code directly drawing in necessary size,
* without creating a throwaway GUI panel, drawing in wrong
* size and immediately resizing.
* Consider moving to ImageLibrary in due course, but not
* until the MiniMap dependency is gone.
*
* @return The created {@code BufferedImage}.
*/
private BufferedImage createMiniMapThumbNail() {
MiniMap miniMap = new MiniMap(getFreeColClient());
miniMap.setTileSize(MiniMap.MAX_TILE_SIZE);
Game game = getGame();
int width = game.getMap().getWidth() * MiniMap.MAX_TILE_SIZE
+ MiniMap.MAX_TILE_SIZE / 2;
int height = game.getMap().getHeight() * MiniMap.MAX_TILE_SIZE / 4;
miniMap.setSize(width, height);
BufferedImage image = new BufferedImage(
width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g1 = image.createGraphics();
miniMap.paintMap(g1);
g1.dispose();

int scaledWidth = Math.min((int)((64 * width) / (float)height), 128);
BufferedImage scaledImage = new BufferedImage(scaledWidth,
MINI_MAP_THUMBNAIL_FINAL_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = scaledImage.createGraphics();
g2.drawImage(image, 0, 0, scaledWidth, MINI_MAP_THUMBNAIL_FINAL_HEIGHT,
null);
g2.dispose();
return scaledImage;
}

/**
* Require all native nation players to be present in a game.
*
Expand Down Expand Up @@ -220,7 +261,7 @@ public void saveMapEditorGame(final File file) {
@Override
public void run() {
try {
BufferedImage thumb = gui.createMiniMapThumbNail();
BufferedImage thumb = createMiniMapThumbNail();
getFreeColServer().saveMapEditorGame(file, thumb);
SwingUtilities.invokeLater(() -> {
gui.closeStatusPanel();
Expand Down
3 changes: 0 additions & 3 deletions src/net/sf/freecol/client/control/PreGameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public void setAvailable(Nation nation, NationState state) {
*/
public void setAvailableHandler(Nation nation, NationState nationState) {
getGame().getNationOptions().setNationState(nation, nationState);
getGUI().refreshPlayersTable();
}

/**
Expand All @@ -196,7 +195,6 @@ public void setColor(Nation nation, Color color) {
*/
public void setColorHandler(Nation nation, Color color) {
nation.setColor(color);
getGUI().refreshPlayersTable();
}

/**
Expand Down Expand Up @@ -228,7 +226,6 @@ public void setNationType(NationType nationType) {
*/
public void setNationTypeHandler(NationType nationType) {
getMyPlayer().changeNationType(nationType);
getGUI().refreshPlayersTable();
}

/**
Expand Down
Loading

0 comments on commit 7b305b8

Please sign in to comment.