Skip to content

Commit

Permalink
This allows to specify the default Light (Vision Type) which should b…
Browse files Browse the repository at this point in the history
…e used in new maps.

The Light value can be edited also when a new map is created or an existing one modified.

RPTools#1062
  • Loading branch information
emmebi committed Jan 18, 2020
1 parent 48e8209 commit bac3a19
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 94 deletions.
16 changes: 16 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public static int getFogOverlayOpacity() {
private static final String KEY_DEFAULT_VISION_DISTANCE = "defaultVisionDistance";
private static final int DEFAULT_DEFAULT_VISION_DISTANCE = 1000;

private static final String KEY_DEFAULT_VISION_TYPE = "defaultVisionType";
private static final Zone.VisionType DEFAULT_VISION_TYPE = Zone.VisionType.OFF;

private static final String KEY_FONT_SIZE = "fontSize";
private static final int DEFAULT_FONT_SIZE = 12;

Expand Down Expand Up @@ -676,6 +679,19 @@ public static int getDefaultVisionDistance() {
return prefs.getInt(KEY_DEFAULT_VISION_DISTANCE, DEFAULT_DEFAULT_VISION_DISTANCE);
}

public static void setDefaultVisionType(Zone.VisionType visionType) {
prefs.put(KEY_DEFAULT_VISION_TYPE, visionType.toString());
}

public static Zone.VisionType getDefaultVisionType() {
try {
return Zone.VisionType.valueOf(
prefs.get(KEY_DEFAULT_VISION_TYPE, DEFAULT_VISION_TYPE.toString()));
} catch (Exception e) {
return DEFAULT_VISION_TYPE;
}
}

public static void setUseSoftFogEdges(boolean flag) {
prefs.putBoolean(KEY_USE_SOFT_FOG_EDGES, flag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,7 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import net.rptools.lib.swing.PaintChooser;
import net.rptools.lib.swing.SelectionListener;
Expand Down Expand Up @@ -132,6 +120,7 @@ private void initialize() {
initDistanceTextField();
initPixelsPerCellTextField();
initDefaultVisionTextField();
initVisionTypeCombo();

initIsometricRadio();
initHexHoriRadio();
Expand Down Expand Up @@ -214,6 +203,10 @@ public JRadioButton getIsometricHexRadio() {
return formPanel.getRadioButton("isoHexRadio");
}

public JComboBox getVisionTypeCombo() {
return formPanel.getComboBox("visionType");
}

public void setZone(Zone zone) {
this.zone = zone;
copyZoneToUI();
Expand All @@ -229,6 +222,7 @@ private void copyZoneToUI() {
getHexHorizontalRadio().setSelected(zone.getGrid() instanceof HexGridHorizontal);
getSquareRadio().setSelected(zone.getGrid() instanceof SquareGrid);
getNoGridRadio().setSelected(zone.getGrid() instanceof GridlessGrid);
getVisionTypeCombo().setSelectedItem(zone.getVisionType());

gridOffsetX = zone.getGrid().getOffsetX();
gridOffsetY = zone.getGrid().getOffsetY();
Expand All @@ -247,6 +241,8 @@ private void copyUIToZone() {
StringUtil.parseInteger(
getDefaultVisionTextField().getText(), zone.getTokenVisionDistance()));

zone.setVisionType((Zone.VisionType) getVisionTypeCombo().getSelectedItem());

zone.setFogPaint(fogPaint);
zone.setBackgroundPaint(backgroundPaint);
zone.setMapAsset(mapAsset != null ? mapAsset.getId() : null);
Expand Down Expand Up @@ -441,6 +437,15 @@ private void initDefaultVisionTextField() {
.setText(Integer.toString(AppPreferences.getDefaultVisionDistance()));
}

private void initVisionTypeCombo() {
DefaultComboBoxModel<Zone.VisionType> model = new DefaultComboBoxModel<>();
for (Zone.VisionType vt : Zone.VisionType.values()) {
model.addElement(vt);
}
model.setSelectedItem(AppPreferences.getDefaultVisionType());
getVisionTypeCombo().setModel(model);
}

public String getZoneName() {
return getNameTextField().getText();
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/rptools/maptool/client/ui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void stateChanged(ChangeEvent ce) {
private final JComboBox tokenNamingCombo;
private final JComboBox showNumberingCombo;
private final JComboBox movementMetricCombo;
private final JComboBox<Zone.VisionType> visionTypeCombo;
private final JCheckBox showStatSheetCheckBox;
private final JCheckBox showPortraitCheckBox;
private final JCheckBox showStatSheetModifierCheckBox;
Expand Down Expand Up @@ -296,6 +297,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
syrinscapeActiveCheckBox = panel.getCheckBox("syrinscapeActive");
showAvatarInChat = panel.getCheckBox("showChatAvatar");
showDialogOnNewToken = panel.getCheckBox("showDialogOnNewToken");
visionTypeCombo = panel.getComboBox("defaultVisionType");
movementMetricCombo = panel.getComboBox("movementMetric");
allowPlayerMacroEditsDefault = panel.getCheckBox("allowPlayerMacroEditsDefault");
toolTipInlineRolls = panel.getCheckBox("toolTipInlineRolls");
Expand Down Expand Up @@ -1110,6 +1112,22 @@ public void itemStateChanged(ItemEvent e) {
}
});

DefaultComboBoxModel<Zone.VisionType> visionTypeModel = new DefaultComboBoxModel<>();
for (Zone.VisionType vt : Zone.VisionType.values()) {
visionTypeModel.addElement(vt);
}
visionTypeModel.setSelectedItem(AppPreferences.getDefaultVisionType());

visionTypeCombo.setModel(visionTypeModel);
visionTypeCombo.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
AppPreferences.setDefaultVisionType(
(Zone.VisionType) visionTypeCombo.getSelectedItem());
}
});

DefaultComboBoxModel macroEditorThemeModel = new DefaultComboBoxModel();
try (Stream<Path> paths = Files.list(AppConstants.THEMES_DIR.toPath())) {
paths
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/rptools/maptool/model/ZoneFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static Zone createZone() {
zone.setHasFog(AppPreferences.getNewMapsHaveFOW());
zone.setUnitsPerCell(AppPreferences.getDefaultUnitsPerCell());
zone.setTokenVisionDistance(AppPreferences.getDefaultVisionDistance());
zone.setVisionType(AppPreferences.getDefaultVisionType());

zone.setGrid(
GridFactory.createGrid(
Expand Down
Loading

0 comments on commit bac3a19

Please sign in to comment.