Skip to content

Commit

Permalink
Clean up ReligionMode and don't cache there
Browse files Browse the repository at this point in the history
Since MapPanel now only paints when necessary, ReligionMode should always paint when asked to
  • Loading branch information
mmyers committed Jun 20, 2024
1 parent eaf0a1f commit 6eaa837
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions EU3_Scenario_Editor/src/editor/mapmode/ReligionMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*/
public final class ReligionMode extends ProvincePaintingMode {

private String lastDate = null;
private final java.util.Map<String, String> ctryReligions =
new HashMap<String, String>();
private final java.util.Map<String, String> ctryReligions = new HashMap<>();

/**
* Creates a new instance of ReligionMode.
Expand All @@ -39,45 +37,41 @@ public ReligionMode(MapPanel panel) {
@Override
protected void paintingStarted(final Graphics2D g) {
final MapPanelDataModel model = mapPanel.getModel();
if (lastDate != null && lastDate.equals(model.getDate()))
return;

ctryReligions.clear();

final List<String> tags = model.getTags();
for (String tag : tags) {
ctryReligions.put(tag.toUpperCase(), model.getHistString(tag, "religion"));
}

lastDate = model.getDate();
}

protected void paintProvince(final Graphics2D g, int provId) {
if (getMap().isWasteland(provId)) {
mapPanel.paintProvince(g, provId, java.awt.Color.BLACK);
return;
}

final String religion = mapPanel.getModel().getHistString(provId, "religion");

if (getMap().isWasteland(provId))
mapPanel.paintProvince(g, provId, java.awt.Color.BLACK);
else if (religion == null) {
if (religion == null) {
mapPanel.paintProvince(g, provId, Utilities.COLOR_NO_HIST);
} else if (religion.length() == 0 || religion.equalsIgnoreCase("none")) {
mapPanel.paintProvince(g, provId, Utilities.COLOR_NO_RELIGION);
} else {
final String owner = mapPanel.getModel().getOwner(provId).toUpperCase();
//final String ownerRel = (Utilities.isNotACountry(owner) ? null : mapPanel.getModel().getHistString(owner, "religion"));
final String ownerRel = ctryReligions.get(owner);

if (ownerRel == null || religion.equalsIgnoreCase(ownerRel)) {
mapPanel.paintProvince(g, provId, Utilities.getReligionColor(religion));
} else {
final Paint p = Utilities.createPaint(Utilities.getReligionColor(religion), Utilities.getReligionColor(ownerRel));
// if (p != null)
mapPanel.paintProvince(g, provId, p);
// else
// System.err.println("Unknown problem in ReligionMode.java");
mapPanel.paintProvince(g, provId, p);
}
}
}

@Override
protected void paintSeaZone(final Graphics2D g, int id) {
// do nothing
}
Expand All @@ -97,7 +91,7 @@ public String getTooltipExtraText(final Province current) {
String ctryRel = null;

if (owner != null) {
if (Utilities.isNotACountry(owner) /*noCountryPattern.matcher(owner).matches()*/) {
if (Utilities.isNotACountry(owner)) {
// don't add anything
owner = "-";
} else {
Expand Down

0 comments on commit 6eaa837

Please sign in to comment.