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
@@ -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;
import java.awt.Dimension;
import java.awt.Point;
import com.samskivert.util.Config;
import com.threerings.miso.Log;
import com.threerings.miso.util.MisoUtil;
/**
* The <code>IsoSceneViewModel</code> class provides a holding place
* for the myriad parameters and bits of data that describe the
* details of an isometric view of a scene.
* This class provides a holding place for the myriad parameters and
* bits of data that describe the details of an isometric view of a
* scene.
*
* <p> The member data are public to facilitate speedy referencing by
* the <code>IsoSceneView</code> class. Those wishing to set up an
* IsoSceneViewModel object should do so solely via the constructor and
* accessor methods.
* the {@link IsoSceneView} class. The model should only be
* configured through the constructor's passed-in {@link
* com.samskivert.util.Config} object and the accessor methods.
*/
public class IsoSceneViewModel
{
@@ -69,17 +71,34 @@ public class IsoSceneViewModel
public boolean showPaths;
/**
* Construct an <code>IsoSceneViewModel</code> with reasonable
* default values.
* Construct an iso scene view model with view parameters as
* specified in the given config object.
*
* @param config the config object.
*/
public IsoSceneViewModel ()
public IsoSceneViewModel (Config config)
{
setTileDimensions(32, 16);
setFineGranularity(4);
setBounds(600, 600);
setOrigin(bounds.width / 2, -(9 * tilehei));
showCoords = false;
showLocs = false;
// set tile dimensions
int twid = config.getValue(TILE_WIDTH_KEY, DEF_TILE_WIDTH);
int thei = config.getValue(TILE_HEIGHT_KEY, DEF_TILE_HEIGHT);
setTileDimensions(twid, thei);
// 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);
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;
@@ -7,13 +7,15 @@ import java.awt.*;
import java.util.List;
import javax.swing.*;
import com.samskivert.util.Config;
import com.threerings.media.sprite.*;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.util.MisoUtil;
/**
* The <code>SceneViewPanel</code> class is responsible for managing a
* <code>SceneView</code>, rendering it to the screen, and handling
* view-related UI events.
* The scene view panel is responsible for managing a {@link
* SceneView}, rendering it to the screen, and handling view-related
* UI events.
*/
public class SceneViewPanel
extends JPanel implements AnimatedView
@@ -21,13 +23,11 @@ public class SceneViewPanel
/**
* 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
_smodel = new IsoSceneViewModel();
_smodel.setTileDimensions(TWIDTH, THEIGHT);
_smodel.setBounds((HTILES * TWIDTH), (VTILES * THEIGHT));
_smodel.setOrigin(_smodel.bounds.width / 2, VOFFSET);
_smodel = new IsoSceneViewModel(config);
// create the scene view
_view = new IsoSceneView(tilemgr, spritemgr, _smodel);
@@ -125,21 +125,6 @@ public class SceneViewPanel
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. */
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;
@@ -12,6 +12,7 @@ import com.threerings.media.ImageManager;
import com.threerings.media.tile.*;
import com.threerings.miso.Log;
import com.threerings.miso.util.MisoUtil;
/**
* Extends general tileset manager functionality to allow reading
@@ -26,7 +27,7 @@ public class EditableTileSetManager extends TileSetManagerImpl
super.init(config, imgmgr);
// 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;
try {
tilesets = new XMLTileSetParser().loadTileSets(fname);
@@ -50,4 +51,8 @@ public class EditableTileSetManager extends TileSetManagerImpl
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;
@@ -11,6 +11,7 @@ import com.samskivert.util.Config;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log;
import com.threerings.miso.scene.MisoScene;
import com.threerings.miso.util.MisoUtil;
/**
* The <code>XMLFileSceneRepository</code> provides a mechanism for
@@ -35,7 +36,7 @@ public class XMLFileSceneRepository
// get path-related information
_root = System.getProperty("root", "");
_sceneRoot = _config.getValue(CFG_SROOT, DEF_SROOT);
_sceneRoot = _config.getValue(SCENEROOT_KEY, DEF_SCENEROOT);
// create the parser and writer objects
_parser = new XMLSceneParser(_tilemgr);
@@ -101,8 +102,9 @@ public class XMLFileSceneRepository
protected XMLSceneWriter _writer;
/** 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. */
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;
@@ -24,6 +24,9 @@ import com.threerings.miso.tile.*;
*/
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.
*
@@ -31,7 +34,7 @@ public class MisoUtil
*/
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 {
XMLFileSceneRepository scenerepo = (XMLFileSceneRepository)
config.instantiateValue("miso.scenerepo", DEF_SCENEREPO);
config.instantiateValue(SCENEREPO_KEY, DEF_SCENEREPO);
scenerepo.init(config, tilemgr);
return scenerepo;
@@ -102,7 +105,7 @@ public class MisoUtil
TileSetManagerImpl tilesetmgr = null;
try {
tilesetmgr = (TileSetManagerImpl)
config.instantiateValue("miso.tilesetmgr", DEF_TILESETMGR);
config.instantiateValue(TILESETMGR_KEY, DEF_TILESETMGR);
tilesetmgr.init(config, imgmgr);
} catch (Exception e) {
@@ -120,4 +123,10 @@ public class MisoUtil
/** The default tileset manager class name. */
protected static final String DEF_TILESETMGR =
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";
}