Skip to content

Commit

Permalink
Map coords and grid
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-short committed Oct 30, 2015
1 parent 1540bb7 commit 131563d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 30 deletions.
101 changes: 75 additions & 26 deletions src/net/buddat/wgenerator/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MainWindow extends JFrame {

private static final long serialVersionUID = -407206109473532425L;

private static final String version = "2.0.0";
private static final String version = "2.1";
private WurmAPI api;
private HeightMap heightMap;
private TileMap tileMap;
Expand Down Expand Up @@ -137,6 +137,8 @@ public class MainWindow extends JFrame {
private JTextField textField_erodeMaxSlope;
private JCheckBox checkBox_landSlide;
private JButton btnUpdateMapName;
private static JLabel lblMapCoords;
private JCheckBox checkbox_ShowGrid;


public static void main(String[] args) {
Expand Down Expand Up @@ -186,34 +188,74 @@ public MainWindow() {
progressBar.setValue(100);

JPanel viewPanel = new JPanel();

JPanel mapCoordsPanel = new JPanel();
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(progressBar, GroupLayout.DEFAULT_SIZE, 862, Short.MAX_VALUE)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(viewPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
.addComponent(mapPanel, GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(optionsPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(progressBar, GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(mapPanel, GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE)
.addComponent(mapCoordsPanel, GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE)
.addComponent(viewPanel, GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(optionsPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(mapPanel, GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(viewPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(optionsPane, GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
.addContainerGap())
);
.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(mapCoordsPanel, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(mapPanel, GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(viewPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(optionsPane, GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE))
.addGap(5))
);

JLabel lblNewLabel_4 = new JLabel("Map Coords:");
lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);

lblMapCoords = new JLabel("");
lblMapCoords.setHorizontalAlignment(SwingConstants.LEFT);

checkbox_ShowGrid = new JCheckBox("Show Grid");
checkbox_ShowGrid.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
mapPanel.showGrid(checkbox_ShowGrid.isSelected());
}
});
checkbox_ShowGrid.setHorizontalAlignment(SwingConstants.CENTER);
GroupLayout gl_mapCoordsPanel = new GroupLayout(mapCoordsPanel);
gl_mapCoordsPanel.setHorizontalGroup(
gl_mapCoordsPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_mapCoordsPanel.createSequentialGroup()
.addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblMapCoords, GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(checkbox_ShowGrid, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE)
.addGap(1))
);
gl_mapCoordsPanel.setVerticalGroup(
gl_mapCoordsPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_mapCoordsPanel.createSequentialGroup()
.addGroup(gl_mapCoordsPanel.createParallelGroup(Alignment.LEADING)
.addComponent(checkbox_ShowGrid)
.addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
.addComponent(lblMapCoords, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
mapCoordsPanel.setLayout(gl_mapCoordsPanel);

btnViewMap = new JButton("View Map");
viewPanel.add(btnViewMap);
Expand Down Expand Up @@ -1002,7 +1044,7 @@ public void actionPerformed(ActionEvent arg0) {
private void init() {
setupButtonActions();
setRockTotal();

updateMapCoords(0,0,false);
System.setErr(new PrintStream(new StreamCapturer(System.err)));
}

Expand Down Expand Up @@ -2006,5 +2048,12 @@ private void setRockTotal() {

}
}


static void updateMapCoords (int x, int y, boolean show) {
if (show) {
lblMapCoords.setText("Tile ("+x+","+y+"), Player ("+(x*4)+","+(y*4)+")");
} else {
lblMapCoords.setText("Right click to place a marker");
}
}
}
40 changes: 37 additions & 3 deletions src/net/buddat/wgenerator/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class MapPanel extends JPanel {

private static final long serialVersionUID = -6072723167611034006L;

private BufferedImage mapImage;

private int mapSize;
Expand All @@ -25,14 +25,18 @@ public class MapPanel extends JPanel {
private int imageY = 0;
private int startX = 0;
private int startY = 0;

private int markerOffsetX = 0;
private int markerOffsetY = 0;
private boolean showMarker = false;
private boolean showGrid = false;

public MapPanel() {
super();

// this.setSize(width, height);
this.setMapSize(1024);

addMouseWheelListener(new MouseAdapter() {
this.addMouseWheelListener(new MouseAdapter() {

@Override
public void mouseWheelMoved(MouseWheelEvent e) {
Expand Down Expand Up @@ -68,6 +72,14 @@ public void mousePressed(MouseEvent e) {
super.mousePressed(e);
startX = e.getX();
startY = e.getY();

if (e.getButton() == MouseEvent.BUTTON3) {
markerOffsetX = (int)((startX-imageX)/scale);
markerOffsetY = (int)((startY-imageY)/scale);
showMarker = !showMarker;
MainWindow.updateMapCoords((int)((markerOffsetX)), (int)(mapSize-(markerOffsetY)), showMarker);
repaint();
}
}
});

Expand All @@ -90,6 +102,11 @@ else if(e.getY() > startY)
});

}

public void showGrid(boolean show) {
showGrid = show;
repaint();
}

public void updateScale() {
if(this.getWidth() < this.getHeight())
Expand Down Expand Up @@ -136,6 +153,23 @@ public void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.drawImage(this.mapImage, imageX, imageY, getImageWidth(), getImageHeight(), null);

if (showMarker) {
g.setColor(Color.RED);
g.fillOval((int)((markerOffsetX*scale)+imageX)-4, (int)((markerOffsetY*scale)+imageY)-4, 8, 8);
}

if (showGrid) {
int gridCount = 10;
double gridSize = mapSize/gridCount*scale;
g.setColor(Color.CYAN);
for (int x = 0; x <= gridCount; x++) {
g.drawLine(imageX, imageY+(int)(x*gridSize), imageX+(int)(mapSize*scale), (int)(imageY+x*gridSize));
}
for (int y = 0; y <= gridCount; y++) {
g.drawLine((int)(imageX+y*gridSize), imageY, (int)(imageX+y*gridSize), imageY+(int)(mapSize*scale));
}
}
}

public void setMapSize(int newMapSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/net/buddat/wgenerator/TileMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void dropDirt(int dirtCount, int maxSlope, int maxDiagSlope, int maxDirtH

for (int x = 0; x < heightMap.getMapSize(); x++) {

if (x%100 == 0) {
if (x%50 == 0) {
int progressValue = (int)((float)x/heightMap.getMapSize()*100f);
long predict = (int)((System.currentTimeMillis()-startTime)/1000.0*(100.0/progressValue-1));
progress.setValue(progressValue);
Expand Down

0 comments on commit 131563d

Please sign in to comment.