From 718ca0de17fc86266492a191541acdec35f06f39 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 17 Feb 2002 23:48:38 +0000 Subject: [PATCH] Test application for the scrolling isometric view. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1014 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- tests/rsrc/config/miso/scrolling.properties | 59 +++++++ .../miso/client/ScrollingFrame.java | 61 +++++++ .../miso/client/ScrollingScene.java | 55 ++++++ .../miso/client/ScrollingTestApp.java | 160 ++++++++++++++++++ 4 files changed, 335 insertions(+) create mode 100644 tests/rsrc/config/miso/scrolling.properties create mode 100644 tests/src/java/com/threerings/miso/client/ScrollingFrame.java create mode 100644 tests/src/java/com/threerings/miso/client/ScrollingScene.java create mode 100644 tests/src/java/com/threerings/miso/client/ScrollingTestApp.java diff --git a/tests/rsrc/config/miso/scrolling.properties b/tests/rsrc/config/miso/scrolling.properties new file mode 100644 index 000000000..d18c7187b --- /dev/null +++ b/tests/rsrc/config/miso/scrolling.properties @@ -0,0 +1,59 @@ +# +# $Id: scrolling.properties,v 1.1 2002/02/17 23:48:37 mdb Exp $ +# +# Initial test config values for miso development. +# + +# the tile set repository class that handles tile set storage +tilesetrepo = com.threerings.miso.tile.XMLTileSetRepository + +# the scene repository class that handles scene storage +scenerepo = com.threerings.miso.scene.xml.XMLSceneRepository + +# the directory containing scene description files +sceneroot = rsrc/scenes + +# the tileset descriptions +tilesets = rsrc/config/miso/tilesets.xml + +# the component descriptions +components = rsrc/config/miso/components.xml + +# the list of building types +buildings = Inn, Hall, Bank, Agent, Palace + +# the tileset id for the building icon images +buildings_icon_tsid = 1007 + +# ---------------------------------- +# 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 = 14 +scene_height = 14 + +# scene viewport dimensions in tile counts +scene_view_width = 5 +scene_view_height = 6 + +# vertical offset for scene display origin in tile count +scene_offset_y = -4 + +# 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 +# ---------------------------------- diff --git a/tests/src/java/com/threerings/miso/client/ScrollingFrame.java b/tests/src/java/com/threerings/miso/client/ScrollingFrame.java new file mode 100644 index 000000000..496271193 --- /dev/null +++ b/tests/src/java/com/threerings/miso/client/ScrollingFrame.java @@ -0,0 +1,61 @@ +// +// $Id: ScrollingFrame.java,v 1.1 2002/02/17 23:48:37 mdb Exp $ + +package com.threerings.miso.scene; + +import java.awt.Color; +import java.awt.Component; +import java.awt.GraphicsConfiguration; + +import javax.swing.JFrame; + +import com.samskivert.swing.GroupLayout; +import com.samskivert.swing.VGroupLayout; + +/** + * The main application window. + */ +public class ScrollingFrame extends JFrame +{ + /** + * Creates a frame in which the scrolling test app can operate. + */ + public ScrollingFrame (GraphicsConfiguration gc) + { + super(gc); + + // set up the frame options + setTitle("Scene scrolling test"); + // setUndecorated(true); + setIgnoreRepaint(true); + setResizable(false); + setDefaultCloseOperation(EXIT_ON_CLOSE); + + // center the scene view within the frame + GroupLayout gl = new VGroupLayout(); + gl.setJustification(GroupLayout.CENTER); + gl.setOffAxisJustification(GroupLayout.CENTER); + getContentPane().setLayout(gl); + + // set the frame and content panel background to black + setBackground(Color.black); + getContentPane().setBackground(Color.black); + } + + /** + * Sets the panel displayed by this frame. + */ + public void setPanel (Component panel) + { + // if we had an old panel, remove it + if (_panel != null) { + getContentPane().remove(_panel); + } + + // now add the new one + _panel = panel; + getContentPane().add(_panel); + } + + protected Component _panel; +} diff --git a/tests/src/java/com/threerings/miso/client/ScrollingScene.java b/tests/src/java/com/threerings/miso/client/ScrollingScene.java new file mode 100644 index 000000000..f6e1c944b --- /dev/null +++ b/tests/src/java/com/threerings/miso/client/ScrollingScene.java @@ -0,0 +1,55 @@ +// +// $Id: ScrollingScene.java,v 1.1 2002/02/17 23:48:38 mdb Exp $ + +package com.threerings.miso.scene; + +import com.threerings.media.tile.NoSuchTileException; +import com.threerings.media.tile.NoSuchTileSetException; +import com.threerings.media.tile.ObjectTile; +import com.threerings.media.tile.Tile; + +import com.threerings.miso.tile.BaseTile; +import com.threerings.miso.util.MisoContext; + +/** + * Provides an infinite array of tiles in which to scroll. + */ +public class ScrollingScene implements DisplayMisoScene +{ + public ScrollingScene (MisoContext ctx) + throws NoSuchTileSetException, NoSuchTileException + { + // grab our four repeating tiles + _tiles[0] = (BaseTile)ctx.getTileManager().getTile(11, 0); + _tiles[1] = (BaseTile)ctx.getTileManager().getTile(12, 0); + _tiles[2] = (BaseTile)ctx.getTileManager().getTile(13, 0); + _tiles[3] = (BaseTile)ctx.getTileManager().getTile(14, 0); + } + + // documentation inherited from interface + public BaseTile getBaseTile (int x, int y) + { + int tidx = 2 * (Math.abs(x) % 2) + Math.abs(y) % 2; + return _tiles[tidx]; + } + + // documentation inherited from interface + public Tile getFringeTile (int x, int y) + { + return null; + } + + // documentation inherited from interface + public ObjectTile getObjectTile (int x, int y) + { + return null; + } + + // documentation inherited from interface + public String getObjectAction (int column, int row) + { + return null; + } + + protected BaseTile[] _tiles = new BaseTile[4]; +} diff --git a/tests/src/java/com/threerings/miso/client/ScrollingTestApp.java b/tests/src/java/com/threerings/miso/client/ScrollingTestApp.java new file mode 100644 index 000000000..c37dd3ccd --- /dev/null +++ b/tests/src/java/com/threerings/miso/client/ScrollingTestApp.java @@ -0,0 +1,160 @@ +// +// $Id: ScrollingTestApp.java,v 1.1 2002/02/17 23:48:38 mdb Exp $ + +package com.threerings.miso.scene; + +import java.awt.DisplayMode; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.io.IOException; + +import com.samskivert.swing.util.SwingUtil; +import com.samskivert.util.Config; + +import com.threerings.resource.ResourceManager; +import com.threerings.media.ImageManager; + +import com.threerings.media.sprite.SpriteManager; +import com.threerings.media.tile.TileManager; +import com.threerings.media.tile.bundle.BundledTileSetRepository; + +import com.threerings.miso.Log; +import com.threerings.miso.scene.SceneViewPanel; +import com.threerings.miso.util.MisoContext; +import com.threerings.miso.util.MisoUtil; + +/** + * Tests the scrolling capabilities of the IsoSceneView. + */ +public class ScrollingTestApp +{ + /** + * Construct and initialize the scrolling test app. + */ + public ScrollingTestApp (String[] args) + throws IOException + { + // get the graphics environment + GraphicsEnvironment env = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + + // get the target graphics device + GraphicsDevice gd = env.getDefaultScreenDevice(); + Log.info("Graphics device [dev=" + gd + + ", mem=" + gd.getAvailableAcceleratedMemory() + + ", displayChange=" + gd.isDisplayChangeSupported() + + ", fullScreen=" + gd.isFullScreenSupported() + "]."); + + // get the graphics configuration and display mode information + GraphicsConfiguration gc = gd.getDefaultConfiguration(); + DisplayMode dm = gd.getDisplayMode(); + Log.info("Display mode [bits=" + dm.getBitDepth() + + ", wid=" + dm.getWidth() + ", hei=" + dm.getHeight() + + ", refresh=" + dm.getRefreshRate() + "]."); + + // create the window + _frame = new ScrollingFrame(gc); + + // we don't need to configure anything + _config = new Config(); + ResourceManager rmgr = new ResourceManager( + "rsrc", null, "config/resource/manager.properties"); + ImageManager imgr = new ImageManager(rmgr, _frame); + _tilemgr = new TileManager(imgr); + _tilemgr.setTileSetRepository( + new BundledTileSetRepository(rmgr, imgr, "tilesets")); + + // bind our miso properties + _config.bindProperties("miso", "rsrc/config/miso/scrolling"); + + // create the context object + MisoContext ctx = new ContextImpl(); + + // create the various managers + SpriteManager spritemgr = new SpriteManager(); + + // create our scene view panel + _panel = new SceneViewPanel(_config, spritemgr); + _frame.setPanel(_panel); + + // set the scene to our scrolling scene + try { + _panel.setScene(new ScrollingScene(ctx)); + _panel.setScrolling(30, -30); + _panel.getModel().showCoords = true; + + } catch (Exception e) { + Log.warning("Error creating scene: " + e); + } + + // size and position the window, entering full-screen exclusive + // mode if available +// if (gd.isFullScreenSupported()) { +// Log.info("Entering full-screen exclusive mode."); +// gd.setFullScreenWindow(_frame); + +// } else { + Log.warning("Full-screen exclusive mode not available."); + _frame.pack(); + SwingUtil.centerWindow(_frame); +// } + } + + /** + * The implementation of the MisoContext interface that provides + * handles to the config and manager objects that offer commonly used + * services. + */ + protected class ContextImpl implements MisoContext + { + public Config getConfig () + { + return _config; + } + + public TileManager getTileManager () + { + return _tilemgr; + } + } + + /** + * Run the application. + */ + public void run () + { + // show the window + _frame.show(); + } + + /** + * Instantiate the application object and start it running. + */ + public static void main (String[] args) + { + try { + ScrollingTestApp app = new ScrollingTestApp(args); + app.run(); + } catch (IOException ioe) { + System.err.println("Error initializing scrolling app."); + ioe.printStackTrace(); + } + } + + /** The desired width and height for the main application window. */ + protected static final int WIDTH = 800; + protected static final int HEIGHT = 622; + + /** The config object. */ + protected Config _config; + + /** The tile manager object. */ + protected TileManager _tilemgr; + + /** The main application window. */ + protected ScrollingFrame _frame; + + /** The main panel. */ + protected SceneViewPanel _panel; +}