Skip to content

Commit

Permalink
New development mapmodes
Browse files Browse the repository at this point in the history
Addresses #30
  • Loading branch information
mmyers committed Jul 2, 2024
1 parent a0ece7f commit 92554e1
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 6 deletions.
18 changes: 18 additions & 0 deletions EU3_Scenario_Editor/src/editor/MapmodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ public static void buildMapmodeMenu(JMenu viewMenu, MapPanel mapPanel, JLabel vi
DiscreteStepFilterAction actn = new DiscreteStepFilterAction("Leadership", "leadership", 0, 10, 1);
actn.setStepColors(allColors, view);
viewMenu.add(actn);
} else if (view.equals("development")) {
viewMenu.add(new DevelopmentFilterAction(0, 30, 1));
} else if (view.equals("ck3-development")) {
viewMenu.add(new CK3DevelopmentFilterAction());
} else if (view.equals("hotspots-owner")) {
viewMenu.add(new HotspotFilterAction("owner", 20, 1));
} else if (view.equals("hotspots-controller")) {
Expand Down Expand Up @@ -1313,6 +1317,20 @@ public CultureGroupFilterAction(String name, String cultureGroup) {
}
}

private static class DevelopmentFilterAction extends FilterAction {
public DevelopmentFilterAction(int min, int max, int step) {
super("Total development level", new DevelopmentMapMode(mapPanel, min, max, step));
putValue(SHORT_DESCRIPTION, "Total development level");
}
}

private static class CK3DevelopmentFilterAction extends FilterAction {
public CK3DevelopmentFilterAction() {
super("Development level", new CK3DevelopmentMapMode(mapPanel));
putValue(SHORT_DESCRIPTION, "Development level");
}
}


private static class WarsAction extends AbstractAction {
public WarsAction() {
Expand Down
48 changes: 48 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/CK3DevelopmentMapMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

package editor.mapmode;

import editor.MapPanel;
import editor.ProvinceData;
import java.awt.Color;

/**
*
* @author Michael
*/
public class CK3DevelopmentMapMode extends TitleMode {

private final Color[] colors = Utilities.createSteppedColors(0, 101, 1, Color.WHITE, Color.GREEN.darker(), Color.GREEN.darker().darker().darker());

public CK3DevelopmentMapMode(MapPanel panel) {
super(panel, TitleMode.TitleType.COUNTY);
}

@Override
protected Color getTitleColor(String title) {
String devStr = getLiegeHistString(title, "change_development_level");
if (devStr == null || devStr.isEmpty())
return getColorFromDevLevel(0);

try {
int devLevel = Integer.parseInt(devStr);
return getColorFromDevLevel(devLevel);
} catch (NumberFormatException ex) {
}
return Utilities.COLOR_NO_CTRY_DEF;
}

private Color getColorFromDevLevel(int devLevel) {
if (devLevel >= 0 && devLevel < colors.length)
return colors[devLevel];
return Utilities.COLOR_LAND_DEFAULT;
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
if (!mapPanel.getMap().isLand(current.getId()) || mapPanel.getMap().isWasteland(current.getId()))
return "";

return "Development level: " + getLiegeHistString(getLowestHistTitleHolder(current.getId()), "change_development_level");
}

}
57 changes: 57 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/DevelopmentMapMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

package editor.mapmode;

import editor.MapPanel;
import editor.ProvinceData;

/**
*
* @author Michael
*/
public class DevelopmentMapMode extends DiscreteScalingMapMode {

public DevelopmentMapMode(MapPanel panel, int min, int max, int step) {
super(panel, "", min, max, step);
setName("development");
}


@Override
protected double getProvinceValue(int provId) {
String manpower = mapPanel.getModel().getHistString(provId, "base_manpower");
String baseTax = mapPanel.getModel().getHistString(provId, "base_tax");
String production = mapPanel.getModel().getHistString(provId, "base_production");

return toInt(manpower) + toInt(baseTax) + toInt(production);
}

private int toInt(String strInt) {
if (strInt == null || strInt.isEmpty())
return 0;
try {
return Integer.parseInt(strInt);
} catch (NumberFormatException ex) {
return 0;
}
}

@Override
public String getTooltipExtraText(ProvinceData.Province current) {
final int id = current.getId();
if (!getMap().isLand(id))
return "";
if (getMap().isWasteland(id))
return "";

String manpower = mapPanel.getModel().getHistString(id, "base_manpower");
String baseTax = mapPanel.getModel().getHistString(id, "base_tax");
String production = mapPanel.getModel().getHistString(id, "base_production");

return "Base tax: " + baseTax
+ "<br>Production: " + production
+ "<br>Manpower: " + manpower
+ "<br><b>Total development: " + (int)getProvinceValue(id) + "</b>";
}


}
19 changes: 14 additions & 5 deletions EU3_Scenario_Editor/src/editor/mapmode/DiscreteScalingMapMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DiscreteScalingMapMode extends ProvincePaintingMode {

// TODO: Perhaps make it so an arbitrary number of colors could be used,
// fading from one to another?
private Color minColor = Color.RED.darker();
private Color minColor = Color.WHITE;
private Color midColor = Color.YELLOW;
private Color maxColor = Color.GREEN.darker();

Expand Down Expand Up @@ -59,19 +59,28 @@ private void initializeColors() {

@Override
protected void paintProvince(final Graphics2D g, int provId) {
String value = mapPanel.getModel().getHistString(provId, prop);

if (value == null || value.length() == 0 || value.equals("0")) {
double value = getProvinceValue(provId);
if (value < 0) {
mapPanel.paintProvince(g, provId, Utilities.COLOR_LAND_DEFAULT);
return;
}

int index = (int) ((Double.parseDouble(value) + min) / step);
int index = (int) ((value + min) / step);
index = Math.max(0, Math.min(colors.length-1, index));

mapPanel.paintProvince(g, provId, colors[index]);
}

protected double getProvinceValue(int provId) {
String value = mapPanel.getModel().getHistString(provId, prop);

if (value == null || value.length() == 0 || value.equals("0")) {
return -1;
}

return Double.parseDouble(value);
}

@Override
protected void paintSeaZone(final Graphics2D g, int id) {
// Do nothing
Expand Down
11 changes: 11 additions & 0 deletions EU3_Scenario_Editor/src/editor/mapmode/TitleMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ protected Color getTitleColor(String title) {
protected String getTitleHistString(String title, String name) {
return ClausewitzHistory.getHistString(getTitleHistory(title), name, mapPanel.getModel().getDate());
}

protected String getLiegeHistString(String title, String name) {
String ret = getTitleHistString(title, name);
while (ret == null || ret.isEmpty()) {
title = getTitleHistString(title, "liege");
if (title == null || title.isEmpty())
break;
ret = getTitleHistString(title, name);
}
return ret;
}

public String getLiege(String title) {
return getLiege(title, type);
Expand Down
4 changes: 3 additions & 1 deletion EU3_Scenario_Editor/views.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ eu4 = { # mostly In Nomine with trade nodes swapped for COTs
base-tax
base-production
base-manpower
development
---
#revolt-risk
unrest
Expand Down Expand Up @@ -197,8 +198,9 @@ ck3 = {
province-religions
#religions
#religions-menu
#capitals
#capitals
override-simple-terrain
ck3-development
---
modding-menu
}
Expand Down

0 comments on commit 92554e1

Please sign in to comment.