use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.
the class App method createBiomesPanel.
private JPanel createBiomesPanel() {
final JPanel biomesPanel = new JPanel();
biomesPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets(1, 1, 1, 1);
Configuration config = Configuration.getInstance();
constraints.anchor = GridBagConstraints.FIRST_LINE_START;
constraints.weightx = 0.0;
biomesCheckBox = new JCheckBox("Show:");
biomesCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
biomesCheckBox.setToolTipText("Uncheck to hide biomes from view (it will still be exported)");
biomesCheckBox.addActionListener(e -> {
if (biomesCheckBox.isSelected()) {
hiddenLayers.remove(Biome.INSTANCE);
} else {
hiddenLayers.add(Biome.INSTANCE);
}
updateLayerVisibility();
});
if (!config.isEasyMode()) {
constraints.gridwidth = 1;
constraints.weightx = 0.0;
biomesPanel.add(biomesCheckBox, constraints);
}
biomesSoloCheckBox = new JCheckBox("Solo:");
biomesSoloCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
biomesSoloCheckBox.setToolTipText("<html>Check to show <em>only</em> the biomes (the other layers are still exported)</html>");
biomesSoloCheckBox.addActionListener(e -> {
if (biomesSoloCheckBox.isSelected()) {
layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != biomesSoloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
soloLayer = Biome.INSTANCE;
} else {
soloLayer = null;
}
updateLayerVisibility();
});
layerSoloCheckBoxes.put(Biome.INSTANCE, biomesSoloCheckBox);
if (!config.isEasyMode()) {
constraints.gridwidth = GridBagConstraints.REMAINDER;
biomesPanel.add(biomesSoloCheckBox, constraints);
}
biomesPanel.add(new BiomesPanel(defaultColourScheme, customBiomeManager, biomeId -> {
paintUpdater = () -> {
paint = PaintFactory.createDiscreteLayerPaint(Biome.INSTANCE, biomeId);
paintChanged();
};
paintUpdater.updatePaint();
}, paintButtonGroup), constraints);
return biomesPanel;
}
use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.
the class App method createLayerButton.
private List<Component> createLayerButton(final Layer layer, char mnemonic, boolean createSoloCheckbox, boolean createButton) {
boolean readOnlyOperation = layer.equals(ReadOnly.INSTANCE);
List<Component> components = new ArrayList<>(3);
final JCheckBox checkBox = new JCheckBox();
if (readOnlyOperation) {
readOnlyCheckBox = checkBox;
}
checkBox.setToolTipText(strings.getString("whether.or.not.to.display.this.layer"));
checkBox.setSelected(true);
checkBox.addChangeListener(e -> {
if (checkBox.isSelected()) {
hiddenLayers.remove(layer);
} else {
hiddenLayers.add(layer);
}
updateLayerVisibility();
});
components.add(checkBox);
if (createSoloCheckbox) {
final JCheckBox soloCheckBox = new JCheckBox();
if (readOnlyOperation) {
readOnlySoloCheckBox = soloCheckBox;
}
layerSoloCheckBoxes.put(layer, soloCheckBox);
soloCheckBox.setToolTipText("<html>Check to show <em>only</em> this layer (the other layers are still exported)</html>");
soloCheckBox.addChangeListener(e -> {
if (soloCheckBox.isSelected()) {
layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != soloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
soloLayer = layer;
} else {
soloLayer = null;
}
updateLayerVisibility();
});
components.add(soloCheckBox);
} else {
components.add(Box.createGlue());
}
if (createButton) {
final JToggleButton button = new JToggleButton();
if (readOnlyOperation) {
readOnlyToggleButton = button;
}
button.setMargin(new Insets(2, 2, 2, 2));
if (layer.getIcon() != null) {
button.setIcon(new ImageIcon(layer.getIcon()));
}
button.setToolTipText(layer.getName() + ": " + layer.getDescription());
// TODO: make this work again, but with Ctrl + Alt or something
// if (mnemonic != 0) {
// button.setMnemonic(mnemonic);
// }
button.addItemListener(event -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
paintUpdater = () -> {
paint = PaintFactory.createLayerPaint(layer);
paintChanged();
};
paintUpdater.updatePaint();
}
});
paintButtonGroup.add(button);
button.setText(layer.getName());
button.putClientProperty(HELP_KEY_KEY, "Layer/" + layer.getId());
components.add(button);
} else {
JLabel label = new JLabel(layer.getName(), new ImageIcon(layer.getIcon()), JLabel.LEADING);
label.putClientProperty(HELP_KEY_KEY, "Layer/" + layer.getId());
components.add(label);
}
return components;
}
use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.
the class App method updateStatusBar.
public void updateStatusBar(int x, int y) {
setTextIfDifferent(locationLabel, MessageFormat.format(strings.getString("location.0.1"), x, y));
if (dimension == null) {
setTextIfDifferent(heightLabel, " ");
setTextIfDifferent(waterLabel, " ");
setTextIfDifferent(materialLabel, " ");
setTextIfDifferent(biomeLabel, " ");
return;
}
Tile tile = dimension.getTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS);
if (tile == null) {
// Not on a tile
setTextIfDifferent(heightLabel, " ");
setTextIfDifferent(slopeLabel, " ");
setTextIfDifferent(waterLabel, " ");
if (dimension.isBorderTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS)) {
setTextIfDifferent(materialLabel, "Border");
} else {
setTextIfDifferent(materialLabel, "Minecraft Generated");
}
setTextIfDifferent(biomeLabel, " ");
return;
}
final int xInTile = x & TILE_SIZE_MASK, yInTile = y & TILE_SIZE_MASK;
if (tile.getBitLayerValue(NotPresent.INSTANCE, xInTile, yInTile)) {
// Marked as not present
setTextIfDifferent(heightLabel, " ");
setTextIfDifferent(slopeLabel, " ");
setTextIfDifferent(waterLabel, " ");
setTextIfDifferent(materialLabel, "Minecraft Generated");
setTextIfDifferent(biomeLabel, " ");
return;
}
int height = tile.getIntHeight(xInTile, yInTile);
setTextIfDifferent(heightLabel, MessageFormat.format(strings.getString("height.0.of.1"), height, dimension.getMaxHeight() - 1));
setTextIfDifferent(slopeLabel, MessageFormat.format("Slope: {0}°", (int) (Math.atan(dimension.getSlope(x, y)) * 180 / Math.PI + 0.5)));
if ((activeOperation instanceof PaintOperation) && (paint instanceof LayerPaint)) {
Layer layer = ((LayerPaint) paint).getLayer();
switch(layer.getDataSize()) {
case BIT:
case BIT_PER_CHUNK:
setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.on.off"), layer.getName(), (tile.getBitLayerValue(layer, xInTile, yInTile) ? 1 : 0)));
break;
case NIBBLE:
int value, strength;
if (!layer.equals(Annotations.INSTANCE)) {
value = tile.getLayerValue(layer, xInTile, yInTile);
strength = (value > 0) ? ((value - 1) * 100 / 14 + 1) : 0;
if ((strength == 51) || (strength == 101)) {
strength--;
}
setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
} else {
setTextIfDifferent(waterLabel, " ");
}
break;
case BYTE:
if (!layer.equals(Biome.INSTANCE)) {
value = tile.getLayerValue(layer, xInTile, yInTile);
strength = (value > 0) ? ((value - 1) * 100 / 254 + 1) : 0;
setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
} else {
setTextIfDifferent(waterLabel, " ");
}
break;
default:
// Do nothing
break;
}
} else if (activeOperation instanceof GardenOfEdenOperation) {
setTextIfDifferent(waterLabel, strings.getString("structure") + ": " + GardenCategory.getLabel(strings, tile.getLayerValue(GardenCategory.INSTANCE, xInTile, yInTile)));
} else {
int waterLevel = tile.getWaterLevel(xInTile, yInTile);
if (waterLevel > height) {
setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("fluid.level.1.depth.2"), tile.getBitLayerValue(FloodWithLava.INSTANCE, xInTile, yInTile) ? 1 : 0, waterLevel, waterLevel - height));
} else {
setTextIfDifferent(waterLabel, " ");
}
}
Terrain terrain = tile.getTerrain(xInTile, yInTile);
if (terrain.isCustom()) {
int index = terrain.getCustomTerrainIndex();
setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.custom.1.0"), getCustomMaterial(index), index + 1));
} else {
setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.0"), terrain.getName()));
}
// with biomeNames being null, causing a NPE. How is this possible?
if (dimension.getDim() == 0) {
int biome = tile.getLayerValue(Biome.INSTANCE, xInTile, yInTile);
// TODO: is this too slow?
if (biome == 255) {
biome = dimension.getAutoBiome(x, y);
if (biome != -1) {
if (biomeNames[biome] == null) {
setTextIfDifferent(biomeLabel, "Auto biome: biome " + biome);
} else {
setTextIfDifferent(biomeLabel, "Auto biome: " + biomeNames[biome]);
}
}
} else if (biome != -1) {
if (biomeNames[biome] == null) {
setTextIfDifferent(biomeLabel, MessageFormat.format(strings.getString("biome.0"), biome));
} else {
setTextIfDifferent(biomeLabel, MessageFormat.format(strings.getString("biome.0"), biomeNames[biome]));
}
}
} else {
setTextIfDifferent(biomeLabel, strings.getString("biome-"));
}
}
use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.
the class App method createAnnotationsPanel.
private JPanel createAnnotationsPanel() {
final JPanel layerPanel = new JPanel();
layerPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets(1, 1, 1, 1);
Configuration config = Configuration.getInstance();
constraints.anchor = GridBagConstraints.FIRST_LINE_START;
constraints.weightx = 0.0;
annotationsCheckBox = new JCheckBox("Show:");
annotationsCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
annotationsCheckBox.setSelected(true);
annotationsCheckBox.setToolTipText("Uncheck to hide annotations from view");
annotationsCheckBox.addActionListener(e -> {
if (annotationsCheckBox.isSelected()) {
hiddenLayers.remove(Annotations.INSTANCE);
} else {
hiddenLayers.add(Annotations.INSTANCE);
}
updateLayerVisibility();
});
if (!config.isEasyMode()) {
constraints.gridwidth = 1;
constraints.weightx = 0.0;
layerPanel.add(annotationsCheckBox, constraints);
}
annotationsSoloCheckBox = new JCheckBox("Solo:");
annotationsSoloCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
annotationsSoloCheckBox.setToolTipText("<html>Check to show <em>only</em> the annotations (the other layers are still exported)</html>");
annotationsSoloCheckBox.addActionListener(e -> {
if (annotationsSoloCheckBox.isSelected()) {
layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != annotationsSoloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
soloLayer = Annotations.INSTANCE;
} else {
soloLayer = null;
}
updateLayerVisibility();
});
layerSoloCheckBoxes.put(Annotations.INSTANCE, annotationsSoloCheckBox);
if (!config.isEasyMode()) {
constraints.gridwidth = GridBagConstraints.REMAINDER;
layerPanel.add(annotationsSoloCheckBox, constraints);
}
JPanel colourGrid = new JPanel(new GridLayout(0, 4));
for (int i = 1; i < 16; i++) {
final int selectedColour = i, dataValue = i - ((i < 8) ? 1 : 0);
JToggleButton button = new JToggleButton(IconUtils.createScaledColourIcon(defaultColourScheme.getColour(BLK_WOOL, dataValue)));
button.setToolTipText(COLOUR_NAMES[dataValue]);
button.setMargin(App.BUTTON_INSETS);
if (i == 1) {
button.setSelected(true);
}
paintButtonGroup.add(button);
button.addActionListener(e -> {
paintUpdater = () -> {
paint = PaintFactory.createDiscreteLayerPaint(Annotations.INSTANCE, selectedColour);
paintChanged();
};
paintUpdater.updatePaint();
});
colourGrid.add(button);
}
layerPanel.add(colourGrid, constraints);
return layerPanel;
}
use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.
the class App method showCustomTerrainButtonPopup.
public void showCustomTerrainButtonPopup(final AWTEvent event, final int customMaterialIndex) {
final JToggleButton button = (customMaterialIndex >= 0) ? customMaterialButtons[customMaterialIndex] : null;
JPopupMenu popupMenu = new JPopupMenu();
final MixedMaterial material = (customMaterialIndex >= 0) ? getCustomMaterial(customMaterialIndex) : null;
// JLabel label = new JLabel(MessageFormat.format(strings.getString("current.material.0"), (material != null) ? material : "none"));
// popupMenu.add(label);
JMenuItem menuItem;
if (button == null) {
menuItem = new JMenuItem(strings.getString("select.custom.material") + "...");
menuItem.addActionListener(e -> {
MixedMaterial newMaterial = MixedMaterial.create(BLK_DIRT);
CustomMaterialDialog dialog = new CustomMaterialDialog(App.this, newMaterial, world.isExtendedBlockIds(), selectedColourScheme);
dialog.setVisible(true);
if (!dialog.isCancelled()) {
newMaterial = MixedMaterialManager.getInstance().register(newMaterial);
int index = findNextCustomTerrainIndex();
addButtonForNewCustomTerrain(index, newMaterial, true);
}
});
popupMenu.add(menuItem);
}
MixedMaterial[] customMaterials = MixedMaterialManager.getInstance().getMaterials();
if (customMaterials.length > 0) {
JMenu existingMaterialsMenu = new JMenu("Select existing material");
Set<MixedMaterial> customTerrainMaterials = new HashSet<>();
for (int i = 0; i < CUSTOM_TERRAIN_COUNT; i++) {
if (getCustomTerrain(i).isConfigured()) {
customTerrainMaterials.add(getCustomMaterial(i));
}
}
for (final MixedMaterial customMaterial : customMaterials) {
if (customTerrainMaterials.contains(customMaterial)) {
continue;
}
menuItem = new JMenuItem(customMaterial.getName());
menuItem.setIcon(new ImageIcon(customMaterial.getIcon(selectedColourScheme)));
menuItem.addActionListener(e -> {
if (button != null) {
setCustomMaterial(customMaterialIndex, customMaterial);
button.setIcon(new ImageIcon(customMaterial.getIcon(selectedColourScheme)));
button.setToolTipText(MessageFormat.format(strings.getString("customMaterial.0.right.click.to.change"), customMaterial));
view.refreshTiles();
} else {
addButtonForNewCustomTerrain(findNextCustomTerrainIndex(), customMaterial, true);
}
});
existingMaterialsMenu.add(menuItem);
}
if (existingMaterialsMenu.getMenuComponentCount() > 0) {
popupMenu.add(existingMaterialsMenu);
}
}
if (button != null) {
menuItem = new JMenuItem(((material != null) ? "Edit custom material" : strings.getString("select.custom.material")) + "...");
menuItem.addActionListener(e -> {
if (editCustomMaterial(customMaterialIndex)) {
button.setSelected(true);
paintUpdater = () -> {
paint = PaintFactory.createTerrainPaint(getCustomTerrain(customMaterialIndex));
paintChanged();
};
paintUpdater.updatePaint();
}
});
popupMenu.add(menuItem);
}
menuItem = new JMenuItem("Import from file...");
menuItem.addActionListener(e -> {
if (button != null) {
if (importCustomMaterial(customMaterialIndex)) {
button.setSelected(true);
paintUpdater = () -> {
paint = PaintFactory.createTerrainPaint(getCustomTerrain(customMaterialIndex));
paintChanged();
};
paintUpdater.updatePaint();
}
} else {
MixedMaterial customMaterial = MixedMaterialHelper.load(this);
if (customMaterial != null) {
addButtonForNewCustomTerrain(findNextCustomTerrainIndex(), customMaterial, true);
}
}
});
popupMenu.add(menuItem);
menuItem = new JMenuItem("Import from another world...");
menuItem.addActionListener(e -> importCustomItemsFromWorld(CustomItemsTreeModel.ItemType.TERRAIN));
popupMenu.add(menuItem);
if (button != null) {
if (material != null) {
menuItem = new JMenuItem("Export to file...");
menuItem.addActionListener(e -> exportCustomMaterial(customMaterialIndex));
popupMenu.add(menuItem);
}
popupMenu.show(button, button.getWidth(), 0);
} else {
Component invoker = (Component) event.getSource();
popupMenu.show(invoker, invoker.getWidth(), 0);
}
}
Aggregations