📄 mapeditor.java
字号:
private void updateLayerOperations() { int nrLayers = 0; if (currentMap != null) { nrLayers = currentMap.getTotalLayers(); } boolean validSelection = currentLayer >= 0; boolean notBottom = currentLayer > 0; boolean notTop = currentLayer < nrLayers - 1 && validSelection; cloneLayerAction.setEnabled(validSelection); deleteLayerAction.setEnabled(validSelection); moveLayerUpAction.setEnabled(notTop); moveLayerDownAction.setEnabled(notBottom); mergeLayerDownAction.setEnabled(notBottom); mergeAllLayersAction.setEnabled(nrLayers > 1); opacitySlider.setEnabled(validSelection); } private JMenuItem createMenuItem(String name, Icon icon, String tt) { JMenuItem menuItem = new JMenuItem(name); menuItem.addActionListener(this); if (icon != null) { menuItem.setIcon(icon); } if (tt != null) { menuItem.setToolTipText(tt); } return menuItem; } private JMenuItem createMenuItem(String name, Icon icon, String tt, String keyStroke) { JMenuItem menuItem = createMenuItem(name, icon, tt); menuItem.setAccelerator(KeyStroke.getKeyStroke(keyStroke)); return menuItem; } private AbstractButton createToggleButton(Icon icon, String command, String tt) { AbstractButton button; button = new JToggleButton("", icon); button.setMargin(new Insets(0, 0, 0, 0)); button.setActionCommand(command); button.addActionListener(this); if (tt != null) { button.setToolTipText(tt); } return button; } /** * Returns the currently selected tile. * * @return the currently selected tile */ public Tile getCurrentTile() { return currentTile; } /** * Returns the current map. * * @return the currently selected map * @see #setCurrentMap(Map) */ public Map getCurrentMap() { return currentMap; } /** * Returns the currently selected layer. * * @return the currently selected layer */ public MapLayer getCurrentLayer() { return currentMap.getLayer(currentLayer); } /** * Returns the currently selected layer index. * * @return the currently selected layer index */ public int getCurrentLayerIndex() { return currentLayer; } /** * Returns the {@link UndoableEditSupport} instance. * @return the undo support */ public UndoableEditSupport getUndoSupport() { return undoSupport; } /** * Returns the {@link UndoHandler} instance. * @return the undo stack */ public UndoHandler getUndoHandler() { return undoHandler; } /** * Returns the {@link PluginClassLoader} instance. * @return the plugin class loader */ public PluginClassLoader getPluginLoader() { return pluginLoader; } /** * Returns the main application frame. * * @return the frame of the main application */ public Frame getAppFrame() { return appFrame; } private void doMouse(MouseEvent event) { if (currentMap == null || currentLayer < 0) { return; } Point tile = mapView.screenToTileCoords(event.getX(), event.getY()); MapLayer layer = getCurrentLayer(); if (layer == null) { return; } else if (mouseButton == MouseEvent.BUTTON3) { if (layer instanceof TileLayer) { if (!bMouseIsDragging) { Tile newTile = ((TileLayer)layer).getTileAt(tile.x, tile.y); setCurrentTile(newTile); } else if (currentPointerState == PS_PAINT) { //in case we are dragging to create a custom brush, let the user //know where we are creating it from if (marqueeSelection == null) { marqueeSelection = new SelectionLayer( currentMap.getWidth(), currentMap.getHeight()); currentMap.addLayerSpecial(marqueeSelection); } Point limp = mouseInitialPressLocation; Rectangle oldArea = marqueeSelection.getSelectedAreaBounds(); int minx = Math.min(limp.x, tile.x); int miny = Math.min(limp.y, tile.y); Rectangle selRect = new Rectangle( minx, miny, (Math.max(limp.x, tile.x) - minx)+1, (Math.max(limp.y, tile.y) - miny)+1); marqueeSelection.selectRegion(selRect); if (oldArea != null) { oldArea.add( marqueeSelection.getSelectedAreaBounds()); mapView.repaintRegion(oldArea); } } } else if (layer instanceof ObjectGroup && !bMouseIsDragging) { // TODO: Add support for ObjectGroups here } } else if (mouseButton == MouseEvent.BUTTON1) { switch (currentPointerState) { case PS_PAINT: paintEdit.setPresentationName(TOOL_PAINT); if (layer instanceof TileLayer) { try { mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y)); } catch (Exception e) { e.printStackTrace(); } } break; case PS_ERASE: paintEdit.setPresentationName(TOOL_ERASE); if (layer instanceof TileLayer) { ((TileLayer) layer).setTileAt(tile.x, tile.y, null); } mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1)); break; case PS_POUR: // POUR only works on TileLayers paintEdit = null; if (layer instanceof TileLayer) { Tile oldTile = ((TileLayer)layer).getTileAt(tile.x, tile.y); pour((TileLayer) layer, tile.x, tile.y, currentTile, oldTile); mapView.repaint(); } break; case PS_EYED: if (layer instanceof TileLayer) { Tile newTile = ((TileLayer)layer).getTileAt( tile.x, tile.y); setCurrentTile(newTile); } else if (layer instanceof ObjectGroup) { // TODO: Add support for ObjectGroups here } break; case PS_MOVE: Point translation = new Point( tile.x - mousePressLocation.x, tile.y - mousePressLocation.y); layer.translate(translation.x, translation.y); moveDist.translate(translation.x, translation.y); mapView.repaint(); break; case PS_MARQUEE: if (marqueeSelection != null) { Point limp = mouseInitialPressLocation; Rectangle oldArea = marqueeSelection.getSelectedAreaBounds(); int minx = Math.min(limp.x, tile.x); int miny = Math.min(limp.y, tile.y); Rectangle selRect = new Rectangle( minx, miny, (Math.max(limp.x, tile.x) - minx)+1, (Math.max(limp.y, tile.y) - miny)+1); if (event.isShiftDown()) { marqueeSelection.add(new Area(selRect)); } else if (event.isControlDown()) { marqueeSelection.subtract(new Area(selRect)); } else { marqueeSelection.selectRegion(selRect); } if (oldArea != null) { oldArea.add( marqueeSelection.getSelectedAreaBounds()); mapView.repaintRegion(oldArea); } } break; } } } public void mouseExited(MouseEvent e) { tileCoordsLabel.setText(" "); } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mousePressed(MouseEvent e) { Point tile = mapView.screenToTileCoords(e.getX(), e.getY()); mouseButton = e.getButton(); bMouseIsDown = true; bMouseIsDragging = false; mousePressLocation = mapView.screenToTileCoords(e.getX(), e.getY()); mouseInitialPressLocation = mousePressLocation; if (mouseButton == MouseEvent.BUTTON1) { switch (currentPointerState) { case PS_PAINT: currentBrush.startPaint(currentMap, tile.x, tile.y, mouseButton, currentLayer); case PS_ERASE: case PS_POUR: MapLayer layer = getCurrentLayer(); paintEdit = new MapLayerEdit(layer, createLayerCopy(layer), null); break; default: } } if (currentPointerState == PS_MARQUEE) { if (marqueeSelection == null) { marqueeSelection = new SelectionLayer( currentMap.getWidth(), currentMap.getHeight()); currentMap.addLayerSpecial(marqueeSelection); } } else if (currentPointerState == PS_MOVE) { // Initialize move distance to (0, 0) moveDist = new Point(0, 0); } doMouse(e); } public void mouseReleased(MouseEvent event) { MapLayer layer = getCurrentLayer(); Point limp = mouseInitialPressLocation; if (currentPointerState == PS_MARQUEE) { Point tile = mapView.screenToTileCoords(event.getX(), event.getY()); if (tile.y - limp.y == 0 && tile.x - limp.x == 0) { if (marqueeSelection != null) { currentMap.removeLayerSpecial(marqueeSelection); marqueeSelection = null; } } } else if (currentPointerState == PS_MOVE) { if (layer != null && moveDist.x != 0 || moveDist.x != 0) { undoSupport.postEdit(new MoveLayerEdit(layer, moveDist)); } } else if (currentPointerState == PS_PAINT) { currentBrush.endPaint(); } //STAMP if (bMouseIsDragging && mouseButton == MouseEvent.BUTTON3 && getCurrentLayer() instanceof TileLayer && currentPointerState == PS_PAINT) { Point tile = mapView.screenToTileCoords(event.getX(), event.getY()); int minx = Math.min(limp.x, tile.x); int miny = Math.min(limp.y, tile.y); Rectangle bounds = new Rectangle( minx, miny, (Math.max(limp.x, tile.x) - minx)+1, (Math.max(limp.y, tile.y) - miny)+1); // Right mouse button dragged: create and set custom brush
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -