org.pepsoft.worldpainter.operations.SetSpawnPoint Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pepsoft.worldpainter.operations;
import org.pepsoft.worldpainter.Dimension;
import org.pepsoft.worldpainter.World2;
import org.pepsoft.worldpainter.WorldPainter;
import javax.swing.*;
import java.awt.*;
import static org.pepsoft.worldpainter.Constants.DIM_NORMAL;
/**
*
* @author pepijn
*/
public class SetSpawnPoint extends MouseOrTabletOperation {
public SetSpawnPoint(WorldPainter view) {
super("Spawn", "Change the spawn point", view, "operation.setSpawnPoint", "spawn");
}
@Override
public JPanel getOptionsPanel() {
return OPTIONS_PANEL;
}
@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
if (first) {
final Dimension dimension = getDimension();
if (dimension == null) {
// Probably some kind of race condition
return;
}
if (dimension.getAnchor().dim != DIM_NORMAL) {
throw new IllegalArgumentException("Cannot set spawn point on dimensions other than DIM_NORMAL");
}
World2 world = dimension.getWorld();
int spawnHeight = dimension.getIntHeightAt(centreX, centreY);
if (spawnHeight == Integer.MIN_VALUE) {
// No tile
if (JOptionPane.showConfirmDialog(getView(), "Are you sure you want to set the spawn outside the boundary of the world?") != JOptionPane.OK_OPTION) {
return;
}
}
world.setSpawnPoint(new Point(centreX, centreY));
}
}
private static final JPanel OPTIONS_PANEL = new StandardOptionsPanel("Spawn", "Click to set the location of the initial spawn point");
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy