From 131563d3125dc7ce13e3b0ea3d043c16d1eb3971 Mon Sep 17 00:00:00 2001 From: Michael Short Date: Thu, 29 Oct 2015 21:31:46 -0500 Subject: [PATCH] Map coords and grid --- src/net/buddat/wgenerator/MainWindow.java | 101 ++++++++++++++++------ src/net/buddat/wgenerator/MapPanel.java | 40 ++++++++- src/net/buddat/wgenerator/TileMap.java | 2 +- 3 files changed, 113 insertions(+), 30 deletions(-) diff --git a/src/net/buddat/wgenerator/MainWindow.java b/src/net/buddat/wgenerator/MainWindow.java index 67e57a5..ab22b05 100644 --- a/src/net/buddat/wgenerator/MainWindow.java +++ b/src/net/buddat/wgenerator/MainWindow.java @@ -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; @@ -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) { @@ -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); @@ -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))); } @@ -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"); + } + } } diff --git a/src/net/buddat/wgenerator/MapPanel.java b/src/net/buddat/wgenerator/MapPanel.java index 7324c61..ad88da2 100644 --- a/src/net/buddat/wgenerator/MapPanel.java +++ b/src/net/buddat/wgenerator/MapPanel.java @@ -15,7 +15,7 @@ public class MapPanel extends JPanel { private static final long serialVersionUID = -6072723167611034006L; - + private BufferedImage mapImage; private int mapSize; @@ -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) { @@ -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(); + } } }); @@ -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()) @@ -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) { diff --git a/src/net/buddat/wgenerator/TileMap.java b/src/net/buddat/wgenerator/TileMap.java index e7fdbc9..1af6073 100644 --- a/src/net/buddat/wgenerator/TileMap.java +++ b/src/net/buddat/wgenerator/TileMap.java @@ -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);