From 9eba46d7007a78575637f7492dda298cab89fc3d Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Wed, 25 Jul 2001 17:38:15 +0000 Subject: [PATCH] Initial version of viewer application to allow playtesting of scenes. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@124 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/miso/client/IsoSceneView.java | 3 +- tests/bin/miso-viewer | 3 + tests/rsrc/config/miso/viewer.properties | 7 + .../miso/viewer/SceneViewPanel.java | 104 +++++++++++++++ .../com/threerings/miso/viewer/ViewerApp.java | 122 ++++++++++++++++++ .../threerings/miso/viewer/ViewerFrame.java | 91 +++++++++++++ .../miso/viewer/util/ViewerContext.java | 16 +++ 7 files changed, 345 insertions(+), 1 deletion(-) create mode 100755 tests/bin/miso-viewer create mode 100644 tests/rsrc/config/miso/viewer.properties create mode 100644 tests/src/java/com/threerings/miso/viewer/SceneViewPanel.java create mode 100644 tests/src/java/com/threerings/miso/viewer/ViewerApp.java create mode 100644 tests/src/java/com/threerings/miso/viewer/ViewerFrame.java create mode 100644 tests/src/java/com/threerings/miso/viewer/util/ViewerContext.java diff --git a/src/java/com/threerings/miso/client/IsoSceneView.java b/src/java/com/threerings/miso/client/IsoSceneView.java index 810f0e4d8..7c5f9449c 100644 --- a/src/java/com/threerings/miso/client/IsoSceneView.java +++ b/src/java/com/threerings/miso/client/IsoSceneView.java @@ -1,5 +1,5 @@ // -// $Id: IsoSceneView.java,v 1.14 2001/07/23 18:52:51 shaper Exp $ +// $Id: IsoSceneView.java,v 1.15 2001/07/25 17:38:15 shaper Exp $ package com.threerings.miso.scene; @@ -156,6 +156,7 @@ public class IsoSceneView implements EditableSceneView Stroke ostroke = gfx.getStroke(); gfx.setStroke(_hstroke); + gfx.setColor(_hcolor); gfx.drawLine(x, y + Tile.HALF_HEIGHT, diff --git a/tests/bin/miso-viewer b/tests/bin/miso-viewer new file mode 100755 index 000000000..be5f5a1a9 --- /dev/null +++ b/tests/bin/miso-viewer @@ -0,0 +1,3 @@ +#!/bin/sh + +`dirname $0`/runjava $* com.threerings.miso.viewer.ViewerApp diff --git a/tests/rsrc/config/miso/viewer.properties b/tests/rsrc/config/miso/viewer.properties new file mode 100644 index 000000000..d04ec3588 --- /dev/null +++ b/tests/rsrc/config/miso/viewer.properties @@ -0,0 +1,7 @@ +# +# $Id: viewer.properties,v 1.1 2001/07/25 17:38:15 shaper Exp $ +# +# Miso scene viewer application config values. +# + +default_scene = /home/shaper/workspace/cocktail/rsrc/scenes/default.xml diff --git a/tests/src/java/com/threerings/miso/viewer/SceneViewPanel.java b/tests/src/java/com/threerings/miso/viewer/SceneViewPanel.java new file mode 100644 index 000000000..b9eea6c1f --- /dev/null +++ b/tests/src/java/com/threerings/miso/viewer/SceneViewPanel.java @@ -0,0 +1,104 @@ +// +// $Id: SceneViewPanel.java,v 1.1 2001/07/25 17:38:15 shaper Exp $ + +package com.threerings.miso.viewer; + +import java.awt.*; +import java.awt.event.*; +import java.io.IOException; +import javax.swing.JPanel; + +import com.samskivert.util.Config; +import com.threerings.miso.Log; +import com.threerings.miso.viewer.util.ViewerContext; +import com.threerings.miso.scene.*; +import com.threerings.miso.scene.xml.XMLFileSceneRepository; + +/** + * The SceneViewPanel class is responsible for managing a SceneView, + * rendering it to the screen, and handling view-related UI events. + */ +public class SceneViewPanel extends JPanel + implements MouseListener, MouseMotionListener +{ + /** + * Construct the panel and initialize it with a context. + */ + public SceneViewPanel (ViewerContext ctx) + { + _ctx = ctx; + _view = new IsoSceneView(_ctx.getTileManager()); + + addMouseListener(this); + addMouseMotionListener(this); + + // get the scene repository + XMLFileSceneRepository repo = (XMLFileSceneRepository) + _ctx.getSceneManager().getSceneRepository(); + + // load the starting scene + Config config = _ctx.getConfig(); + String fname = config.getValue(CONF_SCENE, (String)DEF_SCENE); + try { + _view.setScene(repo.loadScene(fname)); + } catch (IOException ioe) { + Log.warning("Exception loading scene [fname=" + fname + + ", ioe=" + ioe + "]."); + } + } + + /** + * Set the scene managed by the panel. + */ + public void setScene (Scene scene) + { + _view.setScene(scene); + } + + /** + * Render the panel and the scene view to the given graphics object. + */ + public void paint (Graphics g) + { + super.paint(g); + _view.paint(g); + } + + /** MouseListener interface methods */ + + public void mouseClicked (MouseEvent e) + { + } + + public void mouseEntered (MouseEvent e) { } + + public void mouseExited (MouseEvent e) { } + + public void mousePressed (MouseEvent e) + { + } + + public void mouseReleased (MouseEvent e) { } + + /** MouseMotionListener interface methods */ + + public void mouseMoved (MouseEvent e) + { + } + + public void mouseDragged (MouseEvent e) + { + } + + /** The config key to obtain the default scene filename. */ + protected static final String CONF_SCENE = "miso-viewer.default_scene"; + + /** The default scene to load and display. */ + protected static final String DEF_SCENE = "rsrc/scenes/default.xml"; + + /** The context object. */ + protected ViewerContext _ctx; + + /** The scene view we're managing. */ + protected SceneView _view; +} diff --git a/tests/src/java/com/threerings/miso/viewer/ViewerApp.java b/tests/src/java/com/threerings/miso/viewer/ViewerApp.java new file mode 100644 index 000000000..cf42dddb3 --- /dev/null +++ b/tests/src/java/com/threerings/miso/viewer/ViewerApp.java @@ -0,0 +1,122 @@ +// +// $Id: ViewerApp.java,v 1.1 2001/07/25 17:38:15 shaper Exp $ + +package com.threerings.miso.viewer; + +import java.awt.Frame; +import java.io.IOException; + +import com.samskivert.swing.util.SwingUtil; +import com.samskivert.util.Config; +import com.threerings.miso.Log; +import com.threerings.miso.scene.SceneManager; +import com.threerings.miso.tile.TileManager; +import com.threerings.miso.util.MisoUtil; +import com.threerings.miso.viewer.util.ViewerContext; + +/** + * The ViewerApp is a scene viewing application that allows for trying + * out game scenes in a pseudo-runtime environment. + */ +public class ViewerApp +{ + /** + * Construct and initialize the ViewerApp object. + */ + public ViewerApp () + { + // create and size the main application frame + _frame = new ViewerFrame(); + _frame.setSize(WIDTH, HEIGHT); +// SwingUtil.centerFrame(_frame); + + // create the handles on our various services + _config = createConfig(); + _tilemgr = MisoUtil.createTileManager(_config, _frame); + _scenemgr = MisoUtil.createSceneManager(_config, _tilemgr); + _ctx = new ViewerContextImpl(); + + // initialize the frame with the now-prepared context + ((ViewerFrame)_frame).init(_ctx); + } + + /** + * Create the config object that contains configuration parameters + * for the application and other utilized packages. + */ + protected Config createConfig () + { + Config config = new Config(); + try { + // load the miso config info + MisoUtil.bindProperties(config); + + // load the viewer-specific config info + config.bindProperties("miso-viewer", "rsrc/config/miso/viewer"); + + } catch (IOException ioe) { + Log.warning("Error loading config information [e=" + ioe + "]."); + } + + return config; + } + + /** + * The implementation of the ViewerContext interface that provides + * handles to the config and manager objects that offer commonly + * used services. + */ + protected class ViewerContextImpl implements ViewerContext + { + public Config getConfig () + { + return _config; + } + + public SceneManager getSceneManager () + { + return _scenemgr; + } + + public TileManager getTileManager () + { + return _tilemgr; + } + } + + /** + * Run the application. + */ + public void run () + { + _frame.show(); + } + + /** + * Instantiate the application object and start it running. + */ + public static void main (String[] args) + { + ViewerApp app = new ViewerApp(); + app.run(); + } + + /** The desired width and height for the main application window. */ + protected static final int WIDTH = 800; + protected static final int HEIGHT = 600; + + /** The config object. */ + protected Config _config; + + /** The scene manager object. */ + protected SceneManager _scenemgr; + + /** The tile manager object. */ + protected TileManager _tilemgr; + + /** The context object. */ + protected ViewerContext _ctx; + + /** The main application window. */ + protected Frame _frame; +} diff --git a/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java b/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java new file mode 100644 index 000000000..47675ee21 --- /dev/null +++ b/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java @@ -0,0 +1,91 @@ +// +// $Id: ViewerFrame.java,v 1.1 2001/07/25 17:38:15 shaper Exp $ + +package com.threerings.miso.viewer; + +import com.samskivert.swing.*; +import com.samskivert.swing.util.MenuUtil; +import com.threerings.miso.Log; +import com.threerings.miso.viewer.util.ViewerContext; +import com.threerings.miso.scene.Scene; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; + +/** + * The ViewerFrame is the main application window that constructs and + * contains the application menu bar and panels and responds to menu + * events. + */ +class ViewerFrame extends JFrame implements ActionListener +{ + public ViewerFrame () + { + super("Scene Viewer"); + } + + /** + * Initialize the frame with the context object. + */ + public void init (ViewerContext ctx) + { + _ctx = ctx; + + // set up the menu bar + createMenuBar(); + + // create a top-level panel to manage everything + JPanel top = new JPanel(); + GroupLayout gl = new HGroupLayout(GroupLayout.STRETCH); + gl.setOffAxisPolicy(GroupLayout.STRETCH); + top.setLayout(gl); + + // set up the scene view panel with a default scene + SceneViewPanel svpanel = new SceneViewPanel(_ctx); +// setScene(new Scene(_tilemgr, Scene.SID_INVALID)); + top.add(svpanel); + + // now add our top-level panel + getContentPane().add(top, BorderLayout.CENTER); + } + + /** + * Create the menu bar and menu items and add them to the frame. + */ + public void createMenuBar () + { + KeyStroke accel = null; + + // create the "File" menu + JMenu menuFile = new JMenu("File"); + accel = KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK); + MenuUtil.addMenuItem(this, menuFile, "Quit", KeyEvent.VK_Q, accel); + + // create the menu bar + JMenuBar bar = new JMenuBar(); + bar.add(menuFile); + + // add the menu bar to the frame + setJMenuBar(bar); + } + + /** + * Handle menu item selections. + */ + public void actionPerformed (ActionEvent e) + { + String cmd = e.getActionCommand(); + + if (cmd.equals("Quit")) { + System.exit(0); + + } else { + Log.warning("Unknown action command [cmd=" + cmd + "]."); + } + } + + /** The context object. */ + protected ViewerContext _ctx; +} diff --git a/tests/src/java/com/threerings/miso/viewer/util/ViewerContext.java b/tests/src/java/com/threerings/miso/viewer/util/ViewerContext.java new file mode 100644 index 000000000..51d94c95a --- /dev/null +++ b/tests/src/java/com/threerings/miso/viewer/util/ViewerContext.java @@ -0,0 +1,16 @@ +// +// $Id: ViewerContext.java,v 1.1 2001/07/25 17:38:15 shaper Exp $ + +package com.threerings.miso.viewer.util; + +import com.samskivert.util.Context; +import com.threerings.miso.util.MisoContext; + +/** + * A mix-in interface that combines the MisoContext and Context + * interfaces to provide an interface with the best of both worlds. + */ +public interface ViewerContext extends MisoContext, Context +{ + // nothing for now. +}