📄 mapeditor.java
字号:
MultilayerPlane mlp = new MultilayerPlane(bounds.width, bounds.height); TileLayer brushLayer = new TileLayer(bounds); brushLayer.copyFrom(getCurrentLayer()); //do a quick check to make sure the selection is not empty if(brushLayer.isEmpty()) { JOptionPane.showMessageDialog(appFrame, Resources.getString("dialog.selection.empty"), Resources.getString("dialog.selection.empty"), JOptionPane.WARNING_MESSAGE); } else { mlp.addLayer(brushLayer); setBrush(new CustomBrush(mlp)); } //get rid of any visible marquee if (marqueeSelection != null) { currentMap.removeLayerSpecial(marqueeSelection); marqueeSelection = null; } } if (paintEdit != null) { if (layer != null) { try { MapLayer endLayer = paintEdit.getStart().createDiff(layer); paintEdit.end(endLayer); undoSupport.postEdit(paintEdit); } catch (Exception e) { e.printStackTrace(); } } paintEdit = null; } mouseButton = MouseEvent.NOBUTTON; bMouseIsDown = false; bMouseIsDragging = false; } public void mouseMoved(MouseEvent e) { if (bMouseIsDown) { doMouse(e); } Point tile = mapView.screenToTileCoords(e.getX(), e.getY()); if (currentMap.inBounds(tile.x, tile.y)) { tileCoordsLabel.setText(String.valueOf(tile.x) + ", " + tile.y); } else { tileCoordsLabel.setText(" "); } updateCursorHighlight(tile); } public void mouseDragged(MouseEvent e) { bMouseIsDragging = true; doMouse(e); mousePressLocation = mapView.screenToTileCoords(e.getX(), e.getY()); Point tile = mapView.screenToTileCoords(e.getX(), e.getY()); if (currentMap.inBounds(tile.x, tile.y)) { tileCoordsLabel.setText(String.valueOf(tile.x) + ", " + tile.y); } else { tileCoordsLabel.setText(" "); } updateCursorHighlight(tile); } private void updateCursorHighlight(Point tile) { if (prefs.getBoolean("cursorhighlight", true)) { Rectangle redraw = cursorHighlight.getBounds(); Rectangle brushRedraw = currentBrush.getBounds(); brushRedraw.x = tile.x - brushRedraw.width / 2; brushRedraw.y = tile.y - brushRedraw.height / 2; if (!redraw.equals(brushRedraw)) { mapView.repaintRegion(redraw); cursorHighlight.setOffset(brushRedraw.x, brushRedraw.y); //cursorHighlight.selectRegion(currentBrush.getShape()); mapView.repaintRegion(brushRedraw); /*if(currentBrush instanceof CustomBrush) { mapView.paintSubMap(currentBrush, null, 0.5f); }*/ } } } public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("paint")) { setCurrentPointerState(PS_PAINT); resetBrush(); } else if (command.equals("erase")) { setCurrentPointerState(PS_ERASE); resetBrush(); } else if (command.equals("point")) { setCurrentPointerState(PS_POINT); resetBrush(); } else if (command.equals("pour")) { setCurrentPointerState(PS_POUR); resetBrush(); } else if (command.equals("eyed")) { setCurrentPointerState(PS_EYED); resetBrush(); } else if (command.equals("marquee")) { setCurrentPointerState(PS_MARQUEE); resetBrush(); } else if (command.equals("move")) { setCurrentPointerState(PS_MOVE); resetBrush(); } else if (command.equals("moveobject")) { setCurrentPointerState(PS_MOVEOBJ); resetBrush(); } else if (command.equals("palette")) { if (currentMap != null) { if (tilePaletteDialog == null) { tilePaletteDialog = new TilePaletteDialog(this, currentMap); } tilePaletteDialog.setVisible(true); } } else { handleEvent(event); } } // TODO: Most if not all of the below should be moved into action objects, // TODO: and properly internationalized. private void handleEvent(ActionEvent event) { String command = event.getActionCommand(); if (command.equals(Resources.getString("menu.edit.brush"))) { BrushDialog bd = new BrushDialog(this, appFrame, currentBrush); bd.setVisible(true); } else if (command.equals(Resources.getString("menu.tilesets.new"))) { if (currentMap != null) { NewTilesetDialog dialog = new NewTilesetDialog(appFrame, currentMap); TileSet newSet = dialog.create(); if (newSet != null) { currentMap.addTileset(newSet); } } } else if (command.equals(Resources.getString("menu.tilesets.import"))) { if (currentMap != null) { JFileChooser ch = new JFileChooser(currentMap.getFilename()); MapReader[] readers = pluginLoader.getReaders(); for (int i = 0; i < readers.length; i++) { try { ch.addChoosableFileFilter(new TiledFileFilter( readers[i].getFilter(), readers[i].getName())); } catch (Exception e) { e.printStackTrace(); } } ch.addChoosableFileFilter( new TiledFileFilter(TiledFileFilter.FILTER_TSX)); int ret = ch.showOpenDialog(appFrame); if (ret == JFileChooser.APPROVE_OPTION) { String filename = ch.getSelectedFile().getAbsolutePath(); try { TileSet set = MapHelper.loadTileset(filename); currentMap.addTileset(set); } catch (Exception e) { e.printStackTrace(); } } } } else if (command.equals(Resources.getString("menu.tilesets.manager"))) { if (currentMap != null) { TilesetManager manager = new TilesetManager(appFrame, currentMap); manager.setVisible(true); } } else if (command.equals(Resources.getString("menu.file.image"))) { if (currentMap != null) { saveMapImage(null); } } else if (command.equals(Resources.getString("menu.map.properties"))) { PropertiesDialog pd = new PropertiesDialog(appFrame, currentMap.getProperties()); pd.setTitle(Resources.getString("dialog.properties.map.title")); pd.getProps(); } else if (command.equals(Resources.getString("menu.layer.properties"))) { MapLayer layer = getCurrentLayer(); PropertiesDialog lpd = new PropertiesDialog(appFrame, layer.getProperties()); lpd.setTitle(layer.getName() + " " + Resources.getString("dialog.properties.title")); lpd.getProps(); } else if (command.equals(Resources.getString("menu.view.boundaries")) || command.equals("Hide Boundaries")) { mapView.toggleMode(MapView.PF_BOUNDARYMODE); } else if (command.equals(Resources.getString("menu.view.grid"))) { // Toggle grid Preferences displayPrefs = prefs.node("display"); boolean showGrid = displayPrefs.getBoolean("showGrid", false); displayPrefs.putBoolean("showGrid", !showGrid); } else if (command.equals(Resources.getString("menu.view.coordinates"))) { // Toggle coordinates mapView.toggleMode(MapView.PF_COORDINATES); } else if (command.equals(Resources.getString("menu.view.cursor"))) { prefs.putBoolean("cursorhighlight", cursorMenuItem.isSelected()); cursorHighlight.setVisible(cursorMenuItem.isSelected()); } else if (command.equals(Resources.getString("menu.map.resize"))) { ResizeDialog rd = new ResizeDialog(appFrame, this); rd.setVisible(true); } else if (command.equals(Resources.getString("menu.map.search"))) { SearchDialog sd = new SearchDialog(appFrame, currentMap); sd.setVisible(true); } else if (command.equals(Resources.getString("menu.help.about"))) { if (aboutDialog == null) { aboutDialog = new AboutDialog(appFrame); } aboutDialog.setVisible(true); } else if (command.equals(Resources.getString("menu.help.plugins"))) { PluginDialog pluginDialog = new PluginDialog(appFrame, pluginLoader); pluginDialog.setVisible(true); } else if (command.equals(Resources.getString("menu.edit.preferences"))) { ConfigurationDialog d = new ConfigurationDialog(appFrame); d.configure(); } else { System.out.println(event); } } public void componentHidden(ComponentEvent event) { } public void componentMoved(ComponentEvent event) { } public void componentResized(ComponentEvent event) { // This can currently only happen when the map changes size String s = String.valueOf((int) (mapView.getZoom() * 100)) + "%"; zoomLabel.setText(s); // Restore the midpoint JViewport mapViewPort = mapScrollPane.getViewport(); Rectangle viewRect = mapViewPort.getViewRect(); int absMidX = Math.max(0, Math.round(relativeMidX * mapView.getWidth()) - viewRect.width / 2); int absMidY = Math.max(0, Math.round(relativeMidY * mapView.getHeight()) - viewRect.height / 2); mapViewPort.setViewPosition(new Point(absMidX, absMidY)); } public void componentShown(ComponentEvent event) { } public void mapChanged(MapChangedEvent e) { if (e.getMap() == currentMap) { mapScrollPane.setViewportView(mapView); updateLayerTable(); if (tilePaletteDialog != null) { tilePaletteDialog.setMap(currentMap); } mapView.repaint(); } } public void valueChanged(ListSelectionEvent e) { int selectedRow = layerTable.getSelectedRow(); // At the moment, this can only be a new layer selection if (currentMap != null && selectedRow >= 0) { currentLayer = currentMap.getTotalLayers() - selectedRow - 1; float opacity = getCurrentLayer().getOpacity(); opacitySlider.setValue((int)(opacity * 100)); } else { currentLayer = -1; } updateLayerOperations(); } public void stateChanged(ChangeEvent e) { JViewport mapViewport = mapScrollPane.getViewport(); if (e.getSource() == opacitySlider) { if (currentMap != null && currentLayer >= 0) { MapLayer layer = getCurrentLayer(); layer.setOpacity(opacitySlider.getValue() / 100.0f); /* MapLayerStateEdit mlse = new MapLayerStateEdit(currentMap); mlse.setPresentationName("Opacity Change"); undoSupport.postEdit(mlse); */ } } else if (e.getSource() == mapViewport && mapView != null) { // Store the point in the middle for zooming purposes Rectangle viewRect = mapViewport.getViewRect(); relativeMidX = Math.min(1, (viewRect.x + viewRect.width / 2) / (float)mapView.getWidth()); relativeMidY = Math.min(1, (viewRect.y + viewRect.height / 2) / (float)mapView.getHeight()); } } /** * Returns the map view. Currently only used by the {@link UndoHandler} * to be able to order a repaint when doing an undo or redo. This should * become obsolete when we add automatic repainting based on layer * changes. * * @return the map view. */ public MapView getMapView() { return mapView; } /** * Called when the editor is exiting. */ public void shutdown() { // Save the extended window state if the window isn't minimized int extendedState = appFrame.getExtendedState(); prefs.node("dialog/main").putInt("state", extendedState);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -