From cccc3a308ef56b40feca2a8a4fed235b05d76d8f Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Wed, 11 Apr 2007 17:15:39 +0000 Subject: [PATCH] Fix the scene editor's test tile functionality - we need to place any loaded test tiles into the tile manager so they can show up in the actual scene. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@278 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../stage/tools/editor/EditorApp.java | 8 +- .../stage/tools/editor/EditorTileManager.java | 76 +++++++++++++++++++ .../stage/tools/editor/TileInfoPanel.java | 16 +++- 3 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/java/com/threerings/stage/tools/editor/EditorTileManager.java diff --git a/src/java/com/threerings/stage/tools/editor/EditorApp.java b/src/java/com/threerings/stage/tools/editor/EditorApp.java index 8343b622..0d0fe76f 100644 --- a/src/java/com/threerings/stage/tools/editor/EditorApp.java +++ b/src/java/com/threerings/stage/tools/editor/EditorApp.java @@ -156,7 +156,7 @@ public class EditorApp implements Runnable { _msgmgr = new MessageManager("rsrc.i18n"); _imgr = new ImageManager(_rmgr, _frame); - _tilemgr = new MisoTileManager(_rmgr, _imgr); + _tilemgr = new EditorTileManager(_rmgr, _imgr); try { _tsrepo = new BundledTileSetRepository(_rmgr, _imgr, "tilesets"); @@ -172,7 +172,7 @@ public class EditorApp implements Runnable _colpos = ColorPository.loadColorPository(_rmgr); _kbdmgr = new KeyboardManager(); _keydisp = new KeyDispatcher(_frame); - + _ctx = new EditorContextImpl(); // initialize the frame with the now-prepared context @@ -306,7 +306,7 @@ public class EditorApp implements Runnable return _msgmgr; } - public KeyboardManager getKeyboardManager() { + public KeyboardManager getKeyboardManager () { return _kbdmgr; } @@ -317,7 +317,7 @@ public class EditorApp implements Runnable public KeyDispatcher getKeyDispatcher () { return _keydisp; } - + public String xlate (String message) { return xlate("stage.editor", message); } diff --git a/src/java/com/threerings/stage/tools/editor/EditorTileManager.java b/src/java/com/threerings/stage/tools/editor/EditorTileManager.java new file mode 100644 index 00000000..bf2e220c --- /dev/null +++ b/src/java/com/threerings/stage/tools/editor/EditorTileManager.java @@ -0,0 +1,76 @@ +// +// $Id$ +// +// Vilya library - tools for developing networked games +// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/vilya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.stage.tools.editor; + +import com.samskivert.util.HashIntMap; + +import com.threerings.media.tile.NoSuchTileSetException; +import com.threerings.media.tile.TileSet; +import com.threerings.media.image.ImageManager; + +import com.threerings.miso.tile.MisoTileManager; +import com.threerings.resource.ResourceManager; + +/** + * Extends the normal Miso Tile Manager to allow the use of a set of test tiles that can be used in + * the editor. These are loaded through the TestTileLoader. + */ +public class EditorTileManager extends MisoTileManager +{ + public EditorTileManager (ResourceManager rmgr, ImageManager imgr) + { + super(rmgr, imgr); + } + + @Override //Documentation inherited + public TileSet getTileSet (int tileSetId) + throws NoSuchTileSetException + { + TileSet testSet = _testSets.get(tileSetId); + if (testSet != null) { + return testSet; + } else { + return super.getTileSet(tileSetId); + } + } + + /** + * Add a test tile set to search before normal tilesets. + */ + public void addTestTileSet (int id, TileSet set) + { + _testSets.put(id, set); + } + + /** + * Clear all of our existing test tile sets. + */ + public void clearTestTileSets () + { + _testSets.clear(); + } + + /** + * All the test tile sets we have available. + */ + protected HashIntMap _testSets = new HashIntMap(); +} diff --git a/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java b/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java index ebc156cb..0a181bd3 100644 --- a/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java +++ b/src/java/com/threerings/stage/tools/editor/TileInfoPanel.java @@ -60,6 +60,7 @@ import com.samskivert.util.StringUtil; import com.threerings.media.SafeScrollPane; +import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSetRepository; @@ -84,6 +85,7 @@ public class TileInfoPanel extends JSplitPane registerKeyListener(ctx); _model = model; + _ctx = ctx; // we're going to sort all of the available tilesets into those // which are applicable to each layer @@ -321,6 +323,11 @@ public class TileInfoPanel extends JSplitPane } } + TileManager tileMgr = _ctx.getTileManager(); + if (tileMgr instanceof EditorTileManager) { + ((EditorTileManager)tileMgr).clearTestTileSets(); + } + // insert the new test tiles Iterator iter = tests.keys(); while (iter.hasNext()) { @@ -333,7 +340,11 @@ public class TileInfoPanel extends JSplitPane if (lidx != -1) { // make up a negative number to refer to this temporary tileset _layerSets[lidx].add( - new TileSetRecord(lidx, tsid.intValue(), set)); + new TileSetRecord(lidx, tsid, set)); + } + + if (tileMgr instanceof EditorTileManager) { + ((EditorTileManager)tileMgr).addTestTileSet(tsid, set); } } @@ -720,6 +731,9 @@ public class TileInfoPanel extends JSplitPane /** The editor model. */ protected EditorModel _model; + /** Our editor client context. */ + protected EditorContext _ctx; + /** The tile table data model. */ protected TileTableModel _tablemodel; }