Skip to content
Merged
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
86 changes: 76 additions & 10 deletions EU3_Scenario_Editor/src/editor/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public class MapPanel extends javax.swing.JPanel implements Scrollable {
private transient java.util.Map<Integer, Color> overrides;

/** @since 0.5pre3 */
private boolean paintBorders;
private boolean paintInternalBorders;

private boolean paintExternalBorders;

/** @since 0.7.5 */
private boolean isMapInverted;
Expand Down Expand Up @@ -101,7 +103,8 @@ public void initialize(Map map, FilenameResolver resolver, ProvinceData provData

mode = new ProvinceMode(this);

paintBorders = true;
paintInternalBorders = true;
paintExternalBorders = true;
}

private void createMapImage(Map map, FilenameResolver resolver) {
Expand Down Expand Up @@ -170,7 +173,7 @@ private void paintBuffer() {
try {
mode.paint(g);

if (paintBorders && mode.paintsBorders()) {
if ((paintInternalBorders || paintExternalBorders) && mode.paintsBorders()) {
paintBorders((Graphics2D) g);
}
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -244,6 +247,8 @@ private void paintBorders(final Graphics2D g) {
g.setColor(Color.BLACK);

final double scale = scaleFactor/DEFAULT_SCALE_FACTOR;
final java.util.Map<Integer, Integer> provIdByRgb = new java.util.HashMap<>();
final java.util.Map<Integer, Object> groupByProvId = new java.util.HashMap<>();

double x, y;

Expand All @@ -254,14 +259,56 @@ private void paintBorders(final Graphics2D g) {
pixelSize = 3;
if (scale > 3)
pixelSize = 4;

for (Integer[] pt : model.getMapData().getBorderPixels()) {
x = ((double) pt[0]) * scale;
y = ((double) pt[1]) * scale;

final int basePixelSize = pixelSize;

for (MapPixelData.BorderPixel pt : model.getMapData().getBorderPixels()) {
final int provId1 = getProvinceIdForRgb(pt.getRgb1(), provIdByRgb);
final int provId2 = getProvinceIdForRgb(pt.getRgb2(), provIdByRgb);
if (provId1 < 0 || provId2 < 0)
continue;

final Object group1 = groupByProvId.computeIfAbsent(provId1, mode::getBorderGroup);
final Object group2 = groupByProvId.computeIfAbsent(provId2, mode::getBorderGroup);
final boolean isExternal = !java.util.Objects.equals(group1, group2);

if (!paintInternalBorders && !paintExternalBorders)
continue;

final float thicknessMultiplier;
if (isExternal) {
if (paintExternalBorders) {
thicknessMultiplier = Math.max(1.0f, mode.getBorderThicknessMultiplier(provId1, provId2, group1, group2));
} else if (paintInternalBorders) {
thicknessMultiplier = 1.0f;
} else {
continue;
}
} else {
if (!paintInternalBorders)
continue;
thicknessMultiplier = Math.max(1.0f, mode.getBorderThicknessMultiplier(provId1, provId2, group1, group2));
}

final int drawPixelSize = Math.max(1, Math.round(basePixelSize * thicknessMultiplier));

x = ((double) pt.getX()) * scale;
y = ((double) pt.getY()) * scale;

g.fillRect((int)x, (int)y, pixelSize, pixelSize);
g.fillRect((int)x, (int)y, drawPixelSize, drawPixelSize);
}
}

private int getProvinceIdForRgb(final int rgb, final java.util.Map<Integer, Integer> cache) {
final Integer cached = cache.get(rgb);
if (cached != null)
return cached;

final ProvinceData.Province province = model.getProvinceData().getProv(rgb);
final int id = (province == null) ? -1 : province.getId();
cache.put(rgb, id);
return id;
}

@Override
public Dimension getPreferredSize() {
Expand Down Expand Up @@ -583,12 +630,31 @@ public void setDataSource(ClausewitzDataSource dataSource) {

/** @since 0.5pre3 */
public boolean isPaintBorders() {
return paintBorders;
return paintInternalBorders || paintExternalBorders;
}

/** @since 0.5pre3 */
public void setPaintBorders(boolean paintBorders) {
this.paintBorders = paintBorders;
paintInternalBorders = paintBorders;
paintExternalBorders = paintBorders;
isDirty = true;
}

public boolean isPaintInternalBorders() {
return paintInternalBorders;
}

public void setPaintInternalBorders(boolean paintInternalBorders) {
this.paintInternalBorders = paintInternalBorders;
isDirty = true;
}

public boolean isPaintExternalBorders() {
return paintExternalBorders;
}

public void setPaintExternalBorders(boolean paintExternalBorders) {
this.paintExternalBorders = paintExternalBorders;
isDirty = true;
}

Expand Down
54 changes: 45 additions & 9 deletions EU3_Scenario_Editor/src/editor/MapPixelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
/** @since 0.3pre1 */
public final class MapPixelData {

public static final class BorderPixel {
private final int x;
private final int y;
private final int rgb1;
private final int rgb2;

public BorderPixel(int x, int y, int rgb1, int rgb2) {
this.x = x;
this.y = y;
this.rgb1 = rgb1;
this.rgb2 = rgb2;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

public int getRgb1() {
return rgb1;
}

public int getRgb2() {
return rgb2;
}
}

/**
* Mapping of rgb value to a list of horizontal lines in the province.
* Each line is kept in an array of size 3.
Expand All @@ -24,16 +54,16 @@ public final class MapPixelData {
private final java.util.Map<Integer, List<Integer[]>> provLines;

/**
* List of two-element arrays holding coordinates of border pixels.
* List of border pixels and the two province colors the border divides.
* @since 0.5pre3
*/
private final List<Integer[]> borders;
private final List<BorderPixel> borders;

private static final int BLACK = 0xFF000000; // java.awt.Color.BLACK.getRGB();

public MapPixelData(final BufferedImage img, final int numProvs) {
provLines = new HashMap<>(numProvs);
java.util.Map<Integer[], Object> tmpBorders = new HashMap<>(numProvs*32);
java.util.List<BorderPixel> tmpBorders = new ArrayList<>(numProvs*32);

int rgb;

Expand Down Expand Up @@ -63,8 +93,11 @@ public MapPixelData(final BufferedImage img, final int numProvs) {
points[2] = x;

provLines.get(rgb).add(points);
if (rgb != BLACK && x < width && rgbLine[x] != BLACK) { // it's PTI, so don't bother with a border
tmpBorders.put(new Integer[] {x,y}, null);
if (x < width) {
int rgb2 = rgbLine[x];
if (rgb != BLACK && rgb2 != BLACK) { // it's PTI, so don't bother with a border
tmpBorders.add(new BorderPixel(x, y, rgb, rgb2));
}
}

x--;
Expand All @@ -81,20 +114,23 @@ public MapPixelData(final BufferedImage img, final int numProvs) {
do {
y++;
} while (y < height && rgb == rgbCol[y]);
if (rgb != BLACK && y < height && rgbCol[y] != BLACK) { // it's PTI, so don't bother with a border
tmpBorders.put(new Integer[] {x,y}, null);
if (y < height) {
int rgb2 = rgbCol[y];
if (rgb != BLACK && rgb2 != BLACK) { // it's PTI, so don't bother with a border
tmpBorders.add(new BorderPixel(x, y, rgb, rgb2));
}
}
}
}

borders = new ArrayList<>(tmpBorders.keySet());
borders = tmpBorders;
}

public List<Integer[]> getLinesInProv(int rgb) {
return provLines.get(rgb);
}

public List<Integer[]> getBorderPixels() {
public List<BorderPixel> getBorderPixels() {
return borders;
}
}
23 changes: 18 additions & 5 deletions EU3_Scenario_Editor/src/editor/MapmodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ public static void buildMapmodeMenu(JMenu viewMenu, MapPanel mapPanel, JLabel vi
viewMenu.add(new JSeparator());
viewMenu.add(new CustomMapModeAction());
viewMenu.add(new CustomScalingMapModeAction());
viewMenu.add(new PaintBordersAction());
viewMenu.add(new PaintInternalBordersAction());
viewMenu.add(new PaintExternalBordersAction());

log.log(Level.INFO, "Done in {0} ms.", System.currentTimeMillis() - startTime);
}
Expand Down Expand Up @@ -1379,14 +1380,26 @@ public void actionPerformed(ActionEvent e) {
}
}

private static class PaintBordersAction extends AbstractAction {
PaintBordersAction() {
super("Toggle borders");
private static class PaintInternalBordersAction extends AbstractAction {
PaintInternalBordersAction() {
super("Toggle internal borders");
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke('B', InputEvent.CTRL_DOWN_MASK));
}
@Override
public void actionPerformed(ActionEvent e) {
mapPanel.setPaintBorders(!mapPanel.isPaintBorders());
mapPanel.setPaintInternalBorders(!mapPanel.isPaintInternalBorders());
mapPanel.repaint();
}
}

private static class PaintExternalBordersAction extends AbstractAction {
PaintExternalBordersAction() {
super("Toggle external borders");
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke('B', InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK));
}
@Override
public void actionPerformed(ActionEvent e) {
mapPanel.setPaintExternalBorders(!mapPanel.isPaintExternalBorders());
mapPanel.repaint();
}
}
Expand Down
12 changes: 12 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/AllAreasMapMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ protected void paintSeaZone(Graphics2D g, int id) {
}
}

@Override
public Object getBorderGroup(final int provId) {
String area = provinceAreas.get(provId);
if (area != null)
return area;
if (mapPanel.getMap().isWasteland(provId))
return "WASTELAND";
if (!mapPanel.getMap().isLand(provId))
return "SEA_ZONE";
return "DEFAULT";
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
String area = provinceAreas.get(current.getId());
Expand Down
19 changes: 19 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/AllClimatesMapMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ protected void paintSeaZone(Graphics2D g, int id) {
mapPanel.paintProvince(g, id, c);
}

@Override
public Object getBorderGroup(final int provId) {
final String climate = provinceClimates.get(provId);
final String winter = provinceWinters.get(provId);
final String monsoon = provinceMonsoons.get(provId);

if (climateType == ClimateType.CLIMATE)
return climate == null ? "DEFAULT" : climate;
if (climateType == ClimateType.WINTER)
return winter == null ? "DEFAULT" : winter;
if (climateType == ClimateType.MONSOON)
return monsoon == null ? "DEFAULT" : monsoon;

String c = (climate == null) ? "-" : climate;
String w = (winter == null) ? "-" : winter;
String m = (monsoon == null) ? "-" : monsoon;
return c + "|" + w + "|" + m;
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
StringBuilder ret = new StringBuilder();
Expand Down
10 changes: 10 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/CapitalsMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ protected void paintSeaZone(final Graphics2D g, int id) {
// do nothing
}

@Override
public Object getBorderGroup(final int provId) {
if (!getMap().isLand(provId))
return "SEA_ZONE";
String country = capitals.get(provId);
if (country == null)
return "NOT_CAPITAL";
return "CAPITAL:" + country;
}

@Override
public String getTooltipExtraText(final Province current) {
if (capitals.containsKey(current.getId()))
Expand Down
12 changes: 12 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/ColonialRegionsMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ protected void paintSeaZone(Graphics2D g, int id) {
}
}

@Override
public Object getBorderGroup(final int provId) {
ColonialRegion cr = regions.get(provId);
if (cr != null)
return cr.getName();
if (mapPanel.getMap().isWasteland(provId))
return "WASTELAND";
if (!mapPanel.getMap().isLand(provId))
return "SEA_ZONE";
return "DEFAULT";
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
ColonialRegion cr = regions.get(current.getId());
Expand Down
10 changes: 10 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/CoreMapMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ protected void paintSeaZone(final Graphics2D g, int id) {
// Sea zones can't be cores.
return;
}

@Override
public Object getBorderGroup(final int provId) {
if (!getMap().isLand(provId))
return "SEA_ZONE";
final List<String> coreOf = mapPanel.getModel().isCoreOf(provId);
if (coreOf != null && coreOf.contains(tag))
return "CORE";
return "NOT_CORE";
}

@Override
public String getTooltipExtraText(Province current) {
Expand Down
7 changes: 7 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/CountryFlagMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ protected Color getCtryColor(String country) {
return flag ? Color.GREEN : Color.DARK_GRAY;
}

@Override
protected Object getCountryBorderGroup(String country) {
if (country == null || country.isEmpty() || Utilities.isNotACountry(country))
return "NO_COUNTRY";
return mapPanel.getModel().isRhsSet(country, SET_COUNTRY_FLAG, CLR_COUNTRY_FLAG, flagName);
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
String owner = mapPanel.getModel().getOwner(current.getId());
Expand Down
Loading
Loading