mirror of https://github.com/FreeCol/freecol.git
Allows areas to be separately hidden from view.
This commit is contained in:
parent
7dfa486570
commit
53dc415abe
|
@ -25,6 +25,7 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -80,6 +81,7 @@ public final class MapEditorController extends FreeColClientHolder {
|
|||
private Area currentArea = null;
|
||||
|
||||
private boolean displayAreas = false;
|
||||
private java.util.Map<Area, Boolean> visibleAreas = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -233,6 +235,15 @@ public final class MapEditorController extends FreeColClientHolder {
|
|||
return currentArea;
|
||||
}
|
||||
|
||||
public boolean isAreaVisible(Area area) {
|
||||
final Boolean b = visibleAreas.get(area);
|
||||
return (b == null || b);
|
||||
}
|
||||
|
||||
public void setAreaVisible(Area area, boolean visible) {
|
||||
visibleAreas.put(area, visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if areas should be displayed while editing.
|
||||
* @return {@code true} if the areas should be displayed.
|
||||
|
|
|
@ -58,6 +58,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
import net.sf.freecol.client.ClientOptions;
|
||||
import net.sf.freecol.client.FreeColClient;
|
||||
import net.sf.freecol.client.control.FreeColClientHolder;
|
||||
import net.sf.freecol.client.control.MapEditorController;
|
||||
import net.sf.freecol.client.gui.Canvas;
|
||||
import net.sf.freecol.client.gui.GUI;
|
||||
import net.sf.freecol.client.gui.GUI.ViewMode;
|
||||
|
@ -764,7 +765,8 @@ public final class MapViewer extends FreeColClientHolder {
|
|||
if (!getFreeColClient().isMapEditor()) {
|
||||
return;
|
||||
}
|
||||
if (!getFreeColClient().getMapEditorController().isDisplayAreas()) {
|
||||
final MapEditorController mec = getFreeColClient().getMapEditorController();
|
||||
if (!mec.isDisplayAreas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -782,6 +784,7 @@ public final class MapViewer extends FreeColClientHolder {
|
|||
// This can easily be optimized if slow on some systems.
|
||||
final List<Area> areas = getGame().getAreas().stream()
|
||||
.filter(a -> a.containsTile(tile))
|
||||
.filter(a -> mec.isAreaVisible(a))
|
||||
.collect(Collectors.toList());
|
||||
if (areas.isEmpty()) {
|
||||
return;
|
||||
|
|
|
@ -19,16 +19,19 @@
|
|||
|
||||
package net.sf.freecol.client.gui.panel.mapeditor;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.freecol.client.FreeColClient;
|
||||
import net.sf.freecol.client.control.MapEditorController;
|
||||
import net.sf.freecol.client.gui.DialogHandler;
|
||||
import net.sf.freecol.client.gui.panel.FreeColPanel;
|
||||
import net.sf.freecol.client.gui.panel.WrapLayout;
|
||||
|
@ -58,23 +61,38 @@ public final class ChooseAreaModificationPanel extends FreeColPanel {
|
|||
|
||||
final JPanel areasPanel = new JPanel(new WrapLayout()
|
||||
.withHorizontalAlignment(HorizontalAlignment.CENTER)
|
||||
.withAllComponentsWithTheSameSize(true)
|
||||
) {
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(1, 1);
|
||||
}
|
||||
};
|
||||
areasPanel.setOpaque(false);
|
||||
areasPanel.setOpaque(false);
|
||||
|
||||
final MapEditorController ctlr = getFreeColClient().getMapEditorController();
|
||||
final ButtonGroup bg = new ButtonGroup();
|
||||
for (Area a : freeColClient.getGame().getAreas()) {
|
||||
final JPanel areaPanel = new JPanel(new BorderLayout());
|
||||
areaPanel.setOpaque(false);
|
||||
|
||||
final String title = (a.getNameKey() != null) ? Messages.message(a.getNameKey()) : a.getName();
|
||||
final JToggleButton areaButton = new JToggleButton(title);
|
||||
areaButton.addActionListener((e) -> {
|
||||
dialogHandler.handle(a);
|
||||
});
|
||||
bg.add(areaButton);
|
||||
areasPanel.add(areaButton);
|
||||
areaPanel.add(areaButton, BorderLayout.NORTH);
|
||||
final JCheckBox visible = new JCheckBox();
|
||||
visible.setSelected(ctlr.isAreaVisible(a));
|
||||
visible.setHorizontalAlignment(JCheckBox.CENTER);
|
||||
visible.addActionListener((e) -> {
|
||||
ctlr.setAreaVisible(a, visible.isSelected());
|
||||
getGUI().refresh();
|
||||
});
|
||||
|
||||
areaPanel.add(visible, BorderLayout.SOUTH);
|
||||
areasPanel.add(areaPanel);
|
||||
}
|
||||
|
||||
add(areasPanel, "grow, shrink");
|
||||
|
|
Loading…
Reference in New Issue