Made iso scene view configuration part of the miso properties file.

Standardized config key member data names to match those used in the
cocktail code.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@318 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-29 18:41:46 +00:00
parent b882283cd3
commit 8c7efb79fe
9 changed files with 165 additions and 60 deletions
+30 -1
View File
@@ -1,5 +1,5 @@
# #
# $Id: miso.properties,v 1.9 2001/07/24 16:10:19 shaper Exp $ # $Id: miso.properties,v 1.10 2001/08/29 18:41:46 shaper Exp $
# #
# Initial test config values for miso development. # Initial test config values for miso development.
# #
@@ -15,3 +15,32 @@ sceneroot = rsrc/scenes
# the tileset descriptions # the tileset descriptions
tilesets = rsrc/config/miso/tilesets.xml tilesets = rsrc/config/miso/tilesets.xml
# ----------------------------------
# begin isometric view configuration
# tile dimensions in pixels
tile_width = 64
tile_height = 48
# fine coordinate system granularity in intra-tile count
fine_granularity = 4
# scene dimensions in tile counts
scene_width = 10
scene_height = 12
# vertical offset for scene display origin in tile count
scene_offset_y = -5
# whether to show tile coordinates
show_coords = false
# whether to show locations
show_locs = false
# whether to show sprite paths
show_paths = false
# end isometric view configuration
# --------------------------------
@@ -1,22 +1,24 @@
// //
// $Id: IsoSceneViewModel.java,v 1.9 2001/08/15 22:16:43 shaper Exp $ // $Id: IsoSceneViewModel.java,v 1.10 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import com.samskivert.util.Config;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.util.MisoUtil;
/** /**
* The <code>IsoSceneViewModel</code> class provides a holding place * This class provides a holding place for the myriad parameters and
* for the myriad parameters and bits of data that describe the * bits of data that describe the details of an isometric view of a
* details of an isometric view of a scene. * scene.
* *
* <p> The member data are public to facilitate speedy referencing by * <p> The member data are public to facilitate speedy referencing by
* the <code>IsoSceneView</code> class. Those wishing to set up an * the {@link IsoSceneView} class. The model should only be
* IsoSceneViewModel object should do so solely via the constructor and * configured through the constructor's passed-in {@link
* accessor methods. * com.samskivert.util.Config} object and the accessor methods.
*/ */
public class IsoSceneViewModel public class IsoSceneViewModel
{ {
@@ -69,17 +71,34 @@ public class IsoSceneViewModel
public boolean showPaths; public boolean showPaths;
/** /**
* Construct an <code>IsoSceneViewModel</code> with reasonable * Construct an iso scene view model with view parameters as
* default values. * specified in the given config object.
*
* @param config the config object.
*/ */
public IsoSceneViewModel () public IsoSceneViewModel (Config config)
{ {
setTileDimensions(32, 16); // set tile dimensions
setFineGranularity(4); int twid = config.getValue(TILE_WIDTH_KEY, DEF_TILE_WIDTH);
setBounds(600, 600); int thei = config.getValue(TILE_HEIGHT_KEY, DEF_TILE_HEIGHT);
setOrigin(bounds.width / 2, -(9 * tilehei)); setTileDimensions(twid, thei);
showCoords = false;
showLocs = false; // set the fine coordinate granularity
setFineGranularity(config.getValue(FINE_GRAN_KEY, DEF_FINE_GRAN));
// set the desired scene view bounds
int swid = config.getValue(SCENE_WIDTH_KEY, DEF_SCENE_WIDTH);
int shei = config.getValue(SCENE_HEIGHT_KEY, DEF_SCENE_HEIGHT);
setBounds(swid * twid, shei * thei);
// set the scene display origin
int offy = config.getValue(SCENE_OFFSET_Y_KEY, DEF_OFFSET_Y);
setOrigin(bounds.width / 2, offy * thei);
// set our various flags
showCoords = config.getValue(SHOW_COORDS_KEY, DEF_SHOW_COORDS);
showLocs = config.getValue(SHOW_COORDS_KEY, DEF_SHOW_COORDS);
showPaths = config.getValue(SHOW_PATHS_KEY, DEF_SHOW_PATHS);
} }
/** /**
@@ -244,4 +263,51 @@ public class IsoSceneViewModel
finehwid = (int)((float)tilehwid / (float)finegran); finehwid = (int)((float)tilehwid / (float)finegran);
finehhei = (int)((float)tilehhei / (float)finegran); finehhei = (int)((float)tilehhei / (float)finegran);
} }
/** The config key for tile width in pixels. */
protected static final String TILE_WIDTH_KEY =
MisoUtil.CONFIG_KEY + ".tile_width";
/** The config key for tile height in pixels. */
protected static final String TILE_HEIGHT_KEY =
MisoUtil.CONFIG_KEY + ".tile_height";
/** The config key for tile fine coordinate granularity. */
protected static final String FINE_GRAN_KEY =
MisoUtil.CONFIG_KEY + ".fine_granularity";
/** The config key for scene width in tile count. */
protected static final String SCENE_WIDTH_KEY =
MisoUtil.CONFIG_KEY + ".scene_width";
/** The config key for scene height in tile count. */
protected static final String SCENE_HEIGHT_KEY =
MisoUtil.CONFIG_KEY + ".scene_height";
/** The config key for scene origin vertical offset in tile count. */
protected static final String SCENE_OFFSET_Y_KEY =
MisoUtil.CONFIG_KEY + ".scene_offset_y";
/** The config key for whether to show tile coordinates. */
protected static final String SHOW_COORDS_KEY =
MisoUtil.CONFIG_KEY + ".show_coords";
/** The config key for whether to show locations. */
protected static final String SHOW_LOCS_KEY =
MisoUtil.CONFIG_KEY + ".show_locs";
/** The config key for whether to show sprite paths. */
protected static final String SHOW_PATHS_KEY =
MisoUtil.CONFIG_KEY + ".show_paths";
/** Default scene view parameters. */
protected static final int DEF_TILE_WIDTH = 32;
protected static final int DEF_TILE_HEIGHT = 16;
protected static final int DEF_FINE_GRAN = 4;
protected static final int DEF_SCENE_WIDTH = 20;
protected static final int DEF_SCENE_HEIGHT = 20;
protected static final int DEF_OFFSET_Y = 9;
protected static final boolean DEF_SHOW_COORDS = false;
protected static final boolean DEF_SHOW_LOCS = false;
protected static final boolean DEF_SHOW_PATHS = false;
} }
@@ -1,5 +1,5 @@
// //
// $Id: SceneViewPanel.java,v 1.12 2001/08/23 00:23:58 shaper Exp $ // $Id: SceneViewPanel.java,v 1.13 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -7,13 +7,15 @@ import java.awt.*;
import java.util.List; import java.util.List;
import javax.swing.*; import javax.swing.*;
import com.samskivert.util.Config;
import com.threerings.media.sprite.*; import com.threerings.media.sprite.*;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
import com.threerings.miso.util.MisoUtil;
/** /**
* The <code>SceneViewPanel</code> class is responsible for managing a * The scene view panel is responsible for managing a {@link
* <code>SceneView</code>, rendering it to the screen, and handling * SceneView}, rendering it to the screen, and handling view-related
* view-related UI events. * UI events.
*/ */
public class SceneViewPanel public class SceneViewPanel
extends JPanel implements AnimatedView extends JPanel implements AnimatedView
@@ -21,13 +23,11 @@ public class SceneViewPanel
/** /**
* Construct the panel and initialize it with a context. * Construct the panel and initialize it with a context.
*/ */
public SceneViewPanel (TileManager tilemgr, SpriteManager spritemgr) public SceneViewPanel (Config config, TileManager tilemgr,
SpriteManager spritemgr)
{ {
// create the data model for the scene view // create the data model for the scene view
_smodel = new IsoSceneViewModel(); _smodel = new IsoSceneViewModel(config);
_smodel.setTileDimensions(TWIDTH, THEIGHT);
_smodel.setBounds((HTILES * TWIDTH), (VTILES * THEIGHT));
_smodel.setOrigin(_smodel.bounds.width / 2, VOFFSET);
// create the scene view // create the scene view
_view = new IsoSceneView(tilemgr, spritemgr, _smodel); _view = new IsoSceneView(tilemgr, spritemgr, _smodel);
@@ -125,21 +125,6 @@ public class SceneViewPanel
return psize; return psize;
} }
/** Tile width in pixels. */
protected static final int TWIDTH = 64;
/** Tile height in pixels. */
protected static final int THEIGHT = 48;
/** Number of horizontal tiles in the scene. */
protected static final int HTILES = 10;
/** Number of vertical tiles in the scene. */
protected static final int VTILES = 12;
/** Origin vertical offset in pixels. */
protected static final int VOFFSET = -(5 * THEIGHT);
/** The offscreen image used for double-buffering. */ /** The offscreen image used for double-buffering. */
protected Image _offimg; protected Image _offimg;
@@ -1,5 +1,5 @@
// //
// $Id: EditableTileSetManager.java,v 1.9 2001/08/16 23:14:21 mdb Exp $ // $Id: EditableTileSetManager.java,v 1.10 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
@@ -12,6 +12,7 @@ import com.threerings.media.ImageManager;
import com.threerings.media.tile.*; import com.threerings.media.tile.*;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.util.MisoUtil;
/** /**
* Extends general tileset manager functionality to allow reading * Extends general tileset manager functionality to allow reading
@@ -26,7 +27,7 @@ public class EditableTileSetManager extends TileSetManagerImpl
super.init(config, imgmgr); super.init(config, imgmgr);
// load the tilesets from the XML description file // load the tilesets from the XML description file
String fname = config.getValue("miso.tilesets", (String)null); String fname = config.getValue(TILESETS_KEY, (String)null);
ArrayList tilesets = null; ArrayList tilesets = null;
try { try {
tilesets = new XMLTileSetParser().loadTileSets(fname); tilesets = new XMLTileSetParser().loadTileSets(fname);
@@ -50,4 +51,8 @@ public class EditableTileSetManager extends TileSetManagerImpl
Log.info("Adding tileset to cache [tset=" + tset + "]."); Log.info("Adding tileset to cache [tset=" + tset + "].");
} }
} }
/** The config key for the tileset description file. */
protected static final String TILESETS_KEY =
MisoUtil.CONFIG_KEY + ".tilesets";
} }
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneRepository.java,v 1.9 2001/08/16 23:14:21 mdb Exp $ // $Id: XMLSceneRepository.java,v 1.10 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -11,6 +11,7 @@ import com.samskivert.util.Config;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.scene.MisoScene; import com.threerings.miso.scene.MisoScene;
import com.threerings.miso.util.MisoUtil;
/** /**
* The <code>XMLFileSceneRepository</code> provides a mechanism for * The <code>XMLFileSceneRepository</code> provides a mechanism for
@@ -35,7 +36,7 @@ public class XMLFileSceneRepository
// get path-related information // get path-related information
_root = System.getProperty("root", ""); _root = System.getProperty("root", "");
_sceneRoot = _config.getValue(CFG_SROOT, DEF_SROOT); _sceneRoot = _config.getValue(SCENEROOT_KEY, DEF_SCENEROOT);
// create the parser and writer objects // create the parser and writer objects
_parser = new XMLSceneParser(_tilemgr); _parser = new XMLSceneParser(_tilemgr);
@@ -101,8 +102,9 @@ public class XMLFileSceneRepository
protected XMLSceneWriter _writer; protected XMLSceneWriter _writer;
/** The config key for the root scene directory. */ /** The config key for the root scene directory. */
protected static final String CFG_SROOT = "miso.sceneroot"; protected static final String SCENEROOT_KEY =
MisoUtil.CONFIG_KEY + ".sceneroot";
/** The default root scene directory path. */ /** The default root scene directory path. */
protected static final String DEF_SROOT = "rsrc/scenes"; protected static final String DEF_SCENEROOT = "rsrc/scenes";
} }
@@ -1,5 +1,5 @@
// //
// $Id: MisoUtil.java,v 1.8 2001/08/16 23:14:21 mdb Exp $ // $Id: MisoUtil.java,v 1.9 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.util; package com.threerings.miso.util;
@@ -24,6 +24,9 @@ import com.threerings.miso.tile.*;
*/ */
public class MisoUtil public class MisoUtil
{ {
/** The config key prefix for miso properties. */
public static final String CONFIG_KEY = "miso";
/** /**
* Populate the config object with miso configuration values. * Populate the config object with miso configuration values.
* *
@@ -31,7 +34,7 @@ public class MisoUtil
*/ */
public static void bindProperties (Config config) throws IOException public static void bindProperties (Config config) throws IOException
{ {
config.bindProperties("miso", "rsrc/config/miso/miso"); config.bindProperties(CONFIG_KEY, "rsrc/config/miso/miso");
} }
/** /**
@@ -48,7 +51,7 @@ public class MisoUtil
{ {
try { try {
XMLFileSceneRepository scenerepo = (XMLFileSceneRepository) XMLFileSceneRepository scenerepo = (XMLFileSceneRepository)
config.instantiateValue("miso.scenerepo", DEF_SCENEREPO); config.instantiateValue(SCENEREPO_KEY, DEF_SCENEREPO);
scenerepo.init(config, tilemgr); scenerepo.init(config, tilemgr);
return scenerepo; return scenerepo;
@@ -102,7 +105,7 @@ public class MisoUtil
TileSetManagerImpl tilesetmgr = null; TileSetManagerImpl tilesetmgr = null;
try { try {
tilesetmgr = (TileSetManagerImpl) tilesetmgr = (TileSetManagerImpl)
config.instantiateValue("miso.tilesetmgr", DEF_TILESETMGR); config.instantiateValue(TILESETMGR_KEY, DEF_TILESETMGR);
tilesetmgr.init(config, imgmgr); tilesetmgr.init(config, imgmgr);
} catch (Exception e) { } catch (Exception e) {
@@ -120,4 +123,10 @@ public class MisoUtil
/** The default tileset manager class name. */ /** The default tileset manager class name. */
protected static final String DEF_TILESETMGR = protected static final String DEF_TILESETMGR =
EditableTileSetManager.class.getName(); EditableTileSetManager.class.getName();
/** The config key for the scene repository class. */
protected static final String SCENEREPO_KEY = CONFIG_KEY + ".scenerepo";
/** The config key for the tileset manager class. */
protected static final String TILESETMGR_KEY = CONFIG_KEY + ".tilesetmgr";
} }
@@ -1,5 +1,5 @@
// //
// $Id: ViewerApp.java,v 1.6 2001/08/16 23:14:21 mdb Exp $ // $Id: ViewerApp.java,v 1.7 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.viewer; package com.threerings.miso.viewer;
@@ -53,7 +53,8 @@ public class ViewerApp
MisoUtil.bindProperties(config); MisoUtil.bindProperties(config);
// load the viewer-specific config info // load the viewer-specific config info
config.bindProperties("miso-viewer", "rsrc/config/miso/viewer"); config.bindProperties(
ViewerModel.CONFIG_KEY, "rsrc/config/miso/viewer");
} catch (IOException ioe) { } catch (IOException ioe) {
Log.warning("Error loading config information [e=" + ioe + "]."); Log.warning("Error loading config information [e=" + ioe + "].");
@@ -0,0 +1,10 @@
//
// $Id: ViewerModel.java,v 1.1 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.viewer;
public class ViewerModel
{
/** The config key prefix for miso viewer properties. */
public static final String CONFIG_KEY = "miso-viewer";
}
@@ -1,5 +1,5 @@
// //
// $Id: ViewerSceneViewPanel.java,v 1.13 2001/08/23 00:23:58 shaper Exp $ // $Id: ViewerSceneViewPanel.java,v 1.14 2001/08/29 18:41:46 shaper Exp $
package com.threerings.miso.viewer; package com.threerings.miso.viewer;
@@ -26,7 +26,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
public ViewerSceneViewPanel ( public ViewerSceneViewPanel (
ViewerContext ctx, SpriteManager spritemgr, AmbulatorySprite sprite) ViewerContext ctx, SpriteManager spritemgr, AmbulatorySprite sprite)
{ {
super(ctx.getTileManager(), spritemgr); super(ctx.getConfig(), ctx.getTileManager(), spritemgr);
_ctx = ctx; _ctx = ctx;
_sprite = sprite; _sprite = sprite;
@@ -41,9 +41,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel
// load up the initial scene // load up the initial scene
prepareStartingScene(); prepareStartingScene();
_smodel.setShowCoordinates(true);
_smodel.setShowSpritePaths(true);
PerformanceMonitor.register(this, "paint", 1000); PerformanceMonitor.register(this, "paint", 1000);
} }
@@ -56,7 +53,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
// get the starting scene filename // get the starting scene filename
Config config = _ctx.getConfig(); Config config = _ctx.getConfig();
String fname = config.getValue(CFG_SCENE, DEF_SCENE); String fname = config.getValue(SCENE_KEY, DEF_SCENE);
try { try {
// load and set up the scene // load and set up the scene
@@ -104,7 +101,8 @@ public class ViewerSceneViewPanel extends SceneViewPanel
public void mouseDragged (MouseEvent e) { } public void mouseDragged (MouseEvent e) { }
/** The config key to obtain the default scene filename. */ /** The config key to obtain the default scene filename. */
protected static final String CFG_SCENE = "miso-viewer.default_scene"; protected static final String SCENE_KEY =
ViewerModel.CONFIG_KEY + ".default_scene";
/** The default scene to load and display. */ /** The default scene to load and display. */
protected static final String DEF_SCENE = "rsrc/scenes/default.xml"; protected static final String DEF_SCENE = "rsrc/scenes/default.xml";