More work on character components.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@579 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// $Id: TestApp.java,v 1.1 2001/10/30 16:16:01 shaper Exp $
|
||||
|
||||
package com.threerings.cast.builder.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
import com.threerings.cast.Log;
|
||||
import com.threerings.cast.CharacterManager;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
import com.threerings.miso.util.MisoContext;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
public class TestApp
|
||||
{
|
||||
public TestApp (String[] args)
|
||||
{
|
||||
_frame = new TestFrame();
|
||||
_frame.setSize(800, 600);
|
||||
SwingUtil.centerWindow(_frame);
|
||||
|
||||
// create the handles on our various services
|
||||
_config = MisoUtil.createConfig();
|
||||
_tilemgr = MisoUtil.createTileManager(_config, _frame);
|
||||
|
||||
CharacterManager charmgr =
|
||||
MisoUtil.createCharacterManager(_config, _tilemgr);
|
||||
|
||||
// create the context object
|
||||
_ctx = new TestContextImpl();
|
||||
|
||||
// initialize the frame
|
||||
((TestFrame)_frame).init(charmgr);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
_frame.pack();
|
||||
_frame.show();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
TestApp app = new TestApp(args);
|
||||
app.run();
|
||||
}
|
||||
|
||||
protected class TestContextImpl implements MisoContext
|
||||
{
|
||||
public Config getConfig ()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public TileManager getTileManager ()
|
||||
{
|
||||
return _tilemgr;
|
||||
}
|
||||
}
|
||||
|
||||
/** The test frame. */
|
||||
protected JFrame _frame;
|
||||
|
||||
/** The test context. */
|
||||
protected MisoContext _ctx;
|
||||
|
||||
/** The config object. */
|
||||
protected Config _config;
|
||||
|
||||
/** The tile manager object. */
|
||||
protected TileManager _tilemgr;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// $Id: TestFrame.java,v 1.1 2001/10/30 16:16:01 shaper Exp $
|
||||
|
||||
package com.threerings.cast.builder.test;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.threerings.cast.CharacterManager;
|
||||
import com.threerings.cast.builder.BuilderPanel;
|
||||
|
||||
public class TestFrame extends JFrame
|
||||
{
|
||||
public TestFrame ()
|
||||
{
|
||||
super("Character Builder");
|
||||
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
public void init (CharacterManager charmgr)
|
||||
{
|
||||
getContentPane().add(new BuilderPanel(charmgr));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ViewerApp.java,v 1.9 2001/10/17 22:16:04 shaper Exp $
|
||||
// $Id: ViewerApp.java,v 1.10 2001/10/30 16:16:01 shaper Exp $
|
||||
|
||||
package com.threerings.miso.viewer;
|
||||
|
||||
@@ -32,7 +32,8 @@ public class ViewerApp
|
||||
SwingUtil.centerWindow(_frame);
|
||||
|
||||
// create the handles on our various services
|
||||
_config = createConfig();
|
||||
_config = MisoUtil.createConfig(
|
||||
ViewerModel.CONFIG_KEY, "rsrc/config/miso/viewer");
|
||||
_model = createModel(_config, args);
|
||||
_tilemgr = MisoUtil.createTileManager(_config, _frame);
|
||||
_screpo = MisoUtil.createSceneRepository(_config, _tilemgr);
|
||||
@@ -44,28 +45,6 @@ public class ViewerApp
|
||||
((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(
|
||||
ViewerModel.CONFIG_KEY, "rsrc/config/miso/viewer");
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Error loading config information [e=" + ioe + "].");
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
protected ViewerModel createModel (Config config, String args[])
|
||||
{
|
||||
ViewerModel model = new ViewerModel(config);
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
//
|
||||
// $Id: ViewerSceneViewPanel.java,v 1.24 2001/10/27 01:35:21 shaper Exp $
|
||||
// $Id: ViewerSceneViewPanel.java,v 1.25 2001/10/30 16:16:01 shaper Exp $
|
||||
|
||||
package com.threerings.miso.viewer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.samskivert.util.CollectionUtil;
|
||||
import com.samskivert.util.Config;
|
||||
|
||||
import com.threerings.cast.*;
|
||||
@@ -47,8 +50,12 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
||||
CharacterManager charmgr = MisoUtil.createCharacterManager(
|
||||
ctx.getConfig(), ctx.getTileManager());
|
||||
|
||||
// create the character descriptors
|
||||
_descUser = createCharacterDescriptor(charmgr);
|
||||
_descDecoy = createCharacterDescriptor(charmgr);
|
||||
|
||||
// create the manipulable sprite
|
||||
_sprite = createSprite(spritemgr, charmgr, TSID_CHAR_USER);
|
||||
_sprite = createSprite(spritemgr, charmgr, _descUser);
|
||||
|
||||
// create the decoy sprites
|
||||
createDecoys(spritemgr, charmgr);
|
||||
@@ -67,10 +74,9 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
||||
* Creates a new sprite.
|
||||
*/
|
||||
protected MisoCharacterSprite createSprite (
|
||||
SpriteManager spritemgr, CharacterManager charmgr, int tsid)
|
||||
SpriteManager spritemgr, CharacterManager charmgr,
|
||||
CharacterDescriptor desc)
|
||||
{
|
||||
int dummy[] = { tsid };
|
||||
CharacterDescriptor desc = new CharacterDescriptor(dummy);
|
||||
MisoCharacterSprite s =
|
||||
(MisoCharacterSprite)charmgr.getCharacter(desc);
|
||||
if (s != null) {
|
||||
@@ -91,7 +97,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
||||
{
|
||||
_decoys = new MisoCharacterSprite[NUM_DECOYS];
|
||||
for (int ii = 0; ii < NUM_DECOYS; ii++) {
|
||||
_decoys[ii] = createSprite(spritemgr, charmgr, TSID_CHAR);
|
||||
_decoys[ii] = createSprite(spritemgr, charmgr, _descDecoy);
|
||||
if (_decoys[ii] != null) {
|
||||
createRandomPath(_decoys[ii]);
|
||||
}
|
||||
@@ -179,6 +185,42 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
||||
} while (!createPath(s, x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link CharacterDescriptor} suitable for use in
|
||||
* creating character sprites via {@link
|
||||
* CharacterManager#getCharacter}.
|
||||
*/
|
||||
protected CharacterDescriptor
|
||||
createCharacterDescriptor (CharacterManager charmgr)
|
||||
{
|
||||
// get the base component type (always the first type for now).
|
||||
// TODO: change this to retrieve component type by name
|
||||
Iterator iter = charmgr.enumerateComponentTypes();
|
||||
ComponentType ctype = (ComponentType)iter.next();
|
||||
|
||||
// get all available classes
|
||||
ArrayList classes = new ArrayList();
|
||||
CollectionUtil.addAll(classes, charmgr.enumerateComponentClasses());
|
||||
|
||||
// select the components
|
||||
int size = classes.size();
|
||||
int components[] = new int[size];
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
ComponentClass cclass = (ComponentClass)classes.get(ii);
|
||||
|
||||
// get the components available for this class
|
||||
ArrayList choices = new ArrayList();
|
||||
iter = charmgr.enumerateComponentsByClass(ctype.ctid, cclass.clid);
|
||||
CollectionUtil.addAll(choices, iter);
|
||||
|
||||
// choose a random component
|
||||
int idx = RandomUtil.getInt(choices.size());
|
||||
components[cclass.clid] = ((Integer)choices.get(idx)).intValue();
|
||||
}
|
||||
|
||||
return new CharacterDescriptor(ctype, components);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void handleEvent (SpriteEvent event)
|
||||
{
|
||||
@@ -193,13 +235,13 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
||||
}
|
||||
|
||||
/** The number of decoy characters milling about. */
|
||||
protected static final int NUM_DECOYS = 2;
|
||||
protected static final int NUM_DECOYS = 10;
|
||||
|
||||
/** The tileset id for the decoy character tiles. */
|
||||
protected static final int TSID_CHAR = 1011;
|
||||
/** The character descriptor for the user character. */
|
||||
protected CharacterDescriptor _descUser;
|
||||
|
||||
/** The tileset id for the user character tiles. */
|
||||
protected static final int TSID_CHAR_USER = 1012;
|
||||
/** The character descriptor for the decoy characters. */
|
||||
protected CharacterDescriptor _descDecoy;
|
||||
|
||||
/** The animation manager. */
|
||||
protected AnimationManager _animmgr;
|
||||
|
||||
Reference in New Issue
Block a user