Skip to content

Commit

Permalink
Implement all areas/regions/continents map mode (#22)
Browse files Browse the repository at this point in the history
 Mode is available for EU4 and Victoria 2.
Tweaked colorss in province culture mode.
  • Loading branch information
mmyers committed Sep 2, 2021
1 parent f7bf85a commit 3341903
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 4 deletions.
24 changes: 24 additions & 0 deletions EU3_Scenario_Editor/src/editor/EditorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,21 @@ private void addFilters() {
JMenu menu = new JMenu("Areas");
addAreaFilters(menu);
viewMenu.add(menu);
} else if (view.equals("province-areas-menu") && version.hasRegions()) {
JMenu menu = new JMenu("Geography");
try {
menu.add(new AllAreasFilterAction(AllAreasMapMode.GeographyType.AREAS));
} catch (Exception ex) {}
try {
menu.add(new AllAreasFilterAction(AllAreasMapMode.GeographyType.REGIONS));
} catch (Exception ex) {}
try {
menu.add(new AllAreasFilterAction(AllAreasMapMode.GeographyType.SUPER_REGIONS));
} catch (Exception ex) {}
try {
menu.add(new AllAreasFilterAction(AllAreasMapMode.GeographyType.CONTINENTS));
} catch (Exception ex) {}
viewMenu.add(menu);
} else if (view.equals("superregions-menu") && version.hasRegions()) {
JMenu menu = new JMenu("Super regions");
addSuperRegionFilters(menu);
Expand Down Expand Up @@ -1277,6 +1292,8 @@ private void addFilters() {
viewMenu.add(menu);
} else if (view.equals("wars")) {
viewMenu.add(new WarsAction());
} else if (view.equals("---")) {
viewMenu.add(new JSeparator());
} else {
log.log(Level.WARNING, "Unknown menu item: {0}", view);
}
Expand Down Expand Up @@ -2310,6 +2327,13 @@ public AreaFilterAction(String name, String areaName) {
}
}

private class AllAreasFilterAction extends FilterAction {
public AllAreasFilterAction(AllAreasMapMode.GeographyType type) {
super("All " + type.getReadableName() + "s", new AllAreasMapMode(mapPanel, type));
putValue(SHORT_DESCRIPTION, "All map " + type.getReadableName().toLowerCase() + "s");
}
}

private class RegionFilterAction extends FilterAction {
public RegionFilterAction(String name, String regName) {
super(name, new SingleRegionMode(mapPanel, regName));
Expand Down
108 changes: 108 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/AllAreasMapMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

package editor.mapmode;

import editor.MapPanel;
import editor.ProvinceData;
import editor.Text;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.List;

/**
*
* @author Michael
*/
public class AllAreasMapMode extends ProvincePaintingMode {

private final java.util.Map<Integer, String> provinceAreas;

private final java.util.Map<String, Color> areaColors;

public enum GeographyType {
AREAS("Area"),
REGIONS("Region"),
SUPER_REGIONS("Super region"),
CONTINENTS("Continent");
private final String readableName;
private GeographyType(String readableName) {
this.readableName = readableName;
}
public String getReadableName() {
return readableName;
}
};

private final GeographyType type;

public AllAreasMapMode(MapPanel panel, GeographyType type) {
super(panel);
provinceAreas = new HashMap<>();
areaColors = new HashMap<>();

this.type = type;
java.util.Map<String, List<String>> geography = null;
switch (type) {
case AREAS: geography = mapPanel.getMap().getAreas(); break;
case REGIONS: geography = mapPanel.getMap().getRegions(); break;
case SUPER_REGIONS: geography = mapPanel.getMap().getSuperRegions(); break;
case CONTINENTS: geography = mapPanel.getMap().getContinents(); break;
}
prepareGeography(geography);
}

private void prepareGeography(java.util.Map<String, List<String>> areas) {
List<Color> colors = Utilities.getGeographyColors();
// The color index does not begin at 0 simply because EU4's colors are in such an
// order that Europe and Africa would be nearly indistinguishable in continent mode
int colorIdx = Math.min(15, colors.size()-1);
for (java.util.Map.Entry<String, List<String>> area : areas.entrySet()) {
String areaTag = area.getKey();
List<String> areaProvIds = area.getValue();
for (String provIdStr : areaProvIds) {
Integer provId = Integer.valueOf(provIdStr);
provinceAreas.put(provId, areaTag);
}
areaColors.put(areaTag, colors.get(colorIdx++));
if (colorIdx >= colors.size())
colorIdx = 0;
}
}

@Override
protected void paintProvince(Graphics2D g, int provId) {
String area = provinceAreas.get(provId);
if (area != null) {
Color c = areaColors.get(area);
if (c != null) {
mapPanel.paintProvince(g, provId, c);
}
} else if (mapPanel.getMap().isWasteland(provId)) {
mapPanel.paintProvince(g, provId, Color.BLACK);
} else {
mapPanel.paintProvince(g, provId, Utilities.COLOR_LAND_DEFAULT);
}
}

@Override
protected void paintSeaZone(Graphics2D g, int id) {
String area = provinceAreas.get(id);
if (area != null) {
Color c = areaColors.get(area);
if (c != null) {
mapPanel.paintProvince(g, id, c);
}
}
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
String area = provinceAreas.get(current.getId());
if (area != null) {
return type.getReadableName() + ": " + Text.getText(area);
} else if (mapPanel.getMap().isWasteland(current.getId())) {
return "Wasteland";
}
return "";
}
}
8 changes: 7 additions & 1 deletion EU3_Scenario_Editor/src/editor/mapmode/ProvCultureMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public ProvCultureMode(MapPanel panel) {

@Override
protected void paintProvince(final Graphics2D g, int provId) {
if (mapPanel.getMap().isWasteland(provId)) {
mapPanel.paintProvince(g, provId, Utilities.COLOR_NO_CULTURE);
return;
}

final String culture = mapPanel.getModel().getHistString(provId, "culture");
if (culture == null) {
mapPanel.paintProvince(g, provId, Utilities.COLOR_NO_HIST);
Expand All @@ -45,6 +50,7 @@ public String getTooltipExtraText(final Province current) {
final String ret = Text.getText(culture);
if (ret == null || ret.length() == 0)
return "";
return "Culture: " + ret + " (" + Text.getText(Utilities.getCultureGroup(culture)) + ")";
java.awt.Color c = Utilities.getCultureColor(culture);
return "Culture: " + ret + " (" + Text.getText(Utilities.getCultureGroup(culture)) + ")\nColor: " + c.getRed() + " " + c.getGreen() + " " + c.getBlue();
}
}
36 changes: 34 additions & 2 deletions EU3_Scenario_Editor/src/editor/mapmode/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;

/**
Expand Down Expand Up @@ -97,6 +99,8 @@ static boolean isNotACountry(final String tag) {

/** Mapping of culture to its culture group */
private static final java.util.Map<String, String> cultureGroups = new HashMap<>();

private static final List<Color> geographyColors = new ArrayList<>();

private static FilenameResolver resolver;

Expand Down Expand Up @@ -138,10 +142,13 @@ private static void initCultures() {
Color.GRAY,
Color.RED.darker().darker(),
Color.CYAN.darker().darker(),
Color.PINK.darker(),
Color.PINK.darker().darker(),
Color.GREEN.darker().darker(),
Color.YELLOW.darker().darker(),
Color.MAGENTA.darker().darker()
Color.MAGENTA.darker().darker(),
new Color(108, 70, 220), // purple
new Color(38, 180, 210), // light grayish blue
new Color(250, 125, 0), // orange
};
int colorIdx = 0;

Expand Down Expand Up @@ -175,6 +182,24 @@ private static void initCultures() {
}
}

private static void initGeographyColors() {
GenericObject colors = EUGFileIO.load(resolver.resolveFilename("common/region_colors.txt"), settings);
if (colors == null)
colors = EUGFileIO.loadAll(resolver.listFiles("common/region_colors"), settings);
if (colors == null)
colors = EUGFileIO.load(resolver.resolveFilename("common/cot_colors.txt"));
if (colors == null)
return;

for (GenericList color : colors.lists) {
if (color.getName().equalsIgnoreCase("color")) {
Color c = parseColor(color);
if (c != null)
geographyColors.add(c);
}
}
}

private static Color parseColor(GenericList color) {
if (color.size() != 3) {
log.log(Level.WARNING, "Unable to parse color: {0}", color.toString());
Expand Down Expand Up @@ -342,6 +367,13 @@ static String getCultureGroup(String culture) {
return cultureGroups.get(culture);
}

static List<Color> getGeographyColors() {
if (geographyColors.size() == 0) {
initGeographyColors();
}
return geographyColors;
}

// Our own little toUpperCase method, because every tag is converted to
// upper case before processing. This method, unlike String.toUpperCase(),
// assumes that only ASCII characters are used, so a faster algorithm can be
Expand Down
10 changes: 9 additions & 1 deletion EU3_Scenario_Editor/views.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ in_nomine = {

eu4 = { # mostly In Nomine with trade nodes swapped for COTs
provinces
override-simple-terrain
countries
country-menu
---
province-areas-menu
continents-menu
superregions-menu # EU4 1.14
regions-menu
areas-menu # EU4 1.14
provincegroups-menu # EU4 1.14
colonial-regions
---
override-simple-terrain
climates-menu
province-religions
religions
Expand All @@ -77,9 +80,11 @@ eu4 = { # mostly In Nomine with trade nodes swapped for COTs
tradenodes
capitals
hre
---
base-tax
base-production
base-manpower
---
revolt-risk
hotspots-owner
hotspots-controller
Expand All @@ -91,8 +96,11 @@ victoria2 = {
provinces
countries
country-menu
---
province-areas-menu
continents-menu
regions-menu
---
country-religions
religions-menu
#victoria-buildings-menu
Expand Down

0 comments on commit 3341903

Please sign in to comment.