From 78f56f881a753ee2bec45844a31f2075a25951e9 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Thu, 14 Oct 2010 00:59:11 +0000 Subject: [PATCH] Add a new wacky feature to the editor - ctrl-clicking in add tile mode will select the tile you've clicked on as the new selected tile for future placement. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@977 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../stage/tools/editor/EditorFrame.java | 5 +++ .../stage/tools/editor/EditorScenePanel.java | 24 +++++++++++-- .../stage/tools/editor/TileInfoPanel.java | 34 +++++++++++++++++-- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/java/com/threerings/stage/tools/editor/EditorFrame.java b/src/java/com/threerings/stage/tools/editor/EditorFrame.java index 3ba95387..96b39212 100644 --- a/src/java/com/threerings/stage/tools/editor/EditorFrame.java +++ b/src/java/com/threerings/stage/tools/editor/EditorFrame.java @@ -525,6 +525,11 @@ public class EditorFrame extends ManagedJFrame _svpanel.redo(); } + public void updateTileInfo () + { + _tpanel.updateTileTable(); + } + /** * Handles a request to open the preferences dialog. */ diff --git a/src/java/com/threerings/stage/tools/editor/EditorScenePanel.java b/src/java/com/threerings/stage/tools/editor/EditorScenePanel.java index 9bd39fcc..44d34c0a 100644 --- a/src/java/com/threerings/stage/tools/editor/EditorScenePanel.java +++ b/src/java/com/threerings/stage/tools/editor/EditorScenePanel.java @@ -334,6 +334,20 @@ public class EditorScenePanel extends StageScenePanel EditorDialogUtil.display(_frame, _objEditor); } + protected void selectTile (int x, int y) + { + // bail if we're not hovering over a scene object + if (_hobject == null || !(_hobject instanceof SceneObject)) { + return; + } + + SceneObject scObj = (SceneObject)_hobject; + int tileSetId = TileUtil.getTileSetId(scObj.info.tileId); + int tileIndex = TileUtil.getTileIndex(scObj.info.tileId); + _emodel.setTile(scObj.tile.key.tileSet, tileSetId, tileIndex); + _emodel.setLayerIndex(EditorModel.OBJECT_LAYER); + } + /** * Called by the {@link ObjectEditorDialog} when it is dismissed. */ @@ -459,8 +473,14 @@ public class EditorScenePanel extends StageScenePanel case EditorModel.ACTION_PLACE_TILE: switch (e.getButton()) { case MouseEvent.BUTTON1: - placeTile(tc.x, tc.y); - _refreshBox = true; + if ((e.getModifiers() & MouseEvent.CTRL_MASK) != 0) { + // They've got ctrl down, let's select that tile instead. + clearTileSelectRegion(tc.x, tc.y); + selectTile(tc.x, tc.y); + } else { + placeTile(tc.x, tc.y); + _refreshBox = true; + } break; case MouseEvent.BUTTON2: diff --git a/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java b/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java index 2147d2a4..28ea00ba 100644 --- a/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java +++ b/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java @@ -79,7 +79,7 @@ import static com.threerings.stage.Log.log; * tile to be applied to the scene. */ public class TileInfoPanel extends JSplitPane - implements ListSelectionListener, TreeSelectionListener + implements ListSelectionListener, TreeSelectionListener, EditorModelListener { /** * Constructs the tile info panel. @@ -92,6 +92,7 @@ public class TileInfoPanel extends JSplitPane registerKeyListener(ctx); _model = model; + _model.addListener(this); _ctx = ctx; // we're going to sort all of the available tilesets into those @@ -110,7 +111,8 @@ public class TileInfoPanel extends JSplitPane // determine which layer to which this tileset applies int lidx = TileSetUtil.getLayerIndex(set); if (lidx != -1) { - _layerSets.get(lidx).add(new TileSetRecord(lidx, tsid.intValue(), set)); + TileSetRecord rec = new TileSetRecord(lidx, tsid.intValue(), set); + _layerSets.get(lidx).add(rec); } } @@ -195,6 +197,19 @@ public class TileInfoPanel extends JSplitPane setDividerLocation(230); } + // documentation inherited + public void modelChanged (int event) + { + if (event == TILE_CHANGED && !_settingTileOurselves) { + updateTileTable(); + + // Find the selected tileset and select it. + TreePath path = _idToTreePathMap.get(_model.getTileSetId()); + _tsettree.setSelectionPath(path); + _tsettree.scrollPathToVisible(path); + } + } + /** * Register key listeners to do things with the quick list. */ @@ -300,7 +315,9 @@ public class TileInfoPanel extends JSplitPane // update the model to reflect new tile set and select tile // zero by default + _settingTileOurselves = true; _model.setTile(trec.tileSet, trec.tileSetId, 0); + _settingTileOurselves = false; // update the tile table to reflect the new tileset updateTileTable(); @@ -342,7 +359,8 @@ public class TileInfoPanel extends JSplitPane int lidx = TileSetUtil.getLayerIndex(set); if (lidx != -1) { // make up a negative number to refer to this temporary tileset - _layerSets.get(lidx).add(new TileSetRecord(lidx, tsid, set)); + TileSetRecord rec = new TileSetRecord(lidx, tsid, set); + _layerSets.get(lidx).add(rec); } if (tileMgr instanceof EditorTileManager) { @@ -359,6 +377,7 @@ public class TileInfoPanel extends JSplitPane */ public void updateTileSetTree () { + _idToTreePathMap.clear(); // first clear out the tree DefaultTreeModel model = (DefaultTreeModel) _tsettree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); @@ -448,6 +467,8 @@ public class TileInfoPanel extends JSplitPane _selected = item; } + _idToTreePathMap.put(list[ii].tileSetId, new TreePath(item.getPath())); + ii++; } else { @@ -537,7 +558,9 @@ public class TileInfoPanel extends JSplitPane // otherwise they clicked on the tile table. ListSelectionModel lsm = (ListSelectionModel) src; if (!lsm.isSelectionEmpty()) { + _settingTileOurselves = true; _model.setTileId(lsm.getMinSelectionIndex()); + _settingTileOurselves = false; } } } @@ -711,6 +734,9 @@ public class TileInfoPanel extends JSplitPane /** An ArrayList of TileSetRecords for each layer. */ protected Map> _layerSets = Maps.newHashMap(); + /** Map of tileset ID to TreePath. */ + protected Map _idToTreePathMap = Maps.newHashMap(); + /** The original number of TileSetRecords for each layer. */ protected int[] _layerLengths; @@ -743,4 +769,6 @@ public class TileInfoPanel extends JSplitPane /** The tile table data model. */ protected TileTableModel _tablemodel; + + protected boolean _settingTileOurselves; }