Added code to display tiles as images.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@442 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 158 KiB |
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: AtlantiBoard.java,v 1.14 2001/11/07 18:03:33 mdb Exp $
|
// $Id: AtlantiBoard.java,v 1.15 2001/11/08 08:00:22 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.venison;
|
package com.threerings.venison;
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public class VenisonBoard
|
|||||||
// the necessary claim group adjustments can be made)
|
// the necessary claim group adjustments can be made)
|
||||||
tile.setPiecen(piecen, _tiles);
|
tile.setPiecen(piecen, _tiles);
|
||||||
// and repaint
|
// and repaint
|
||||||
repaint();
|
repaintTile(tile);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.warning("Requested to place piecen for which we could " +
|
Log.warning("Requested to place piecen for which we could " +
|
||||||
@@ -166,7 +166,7 @@ public class VenisonBoard
|
|||||||
// clear the piecen out of the tile
|
// clear the piecen out of the tile
|
||||||
tile.clearPiecen();
|
tile.clearPiecen();
|
||||||
// and repaint
|
// and repaint
|
||||||
repaint();
|
repaintTile(tile);
|
||||||
// and get on out
|
// and get on out
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,9 +223,6 @@ public class VenisonBoard
|
|||||||
if (_placingTile != null) {
|
if (_placingTile != null) {
|
||||||
updatePlacingInfo(true);
|
updatePlacingInfo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// and repaint
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,10 +243,21 @@ public class VenisonBoard
|
|||||||
_ty = (getHeight() - TILE_HEIGHT * _height)/2;
|
_ty = (getHeight() - TILE_HEIGHT * _height)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the supplied tile to be repainted.
|
||||||
|
*/
|
||||||
|
public void repaintTile (VenisonTile tile)
|
||||||
|
{
|
||||||
|
int offx = _tx + (tile.x + _origX) * TILE_WIDTH;
|
||||||
|
int offy = _ty + (tile.y + _origY) * TILE_HEIGHT;
|
||||||
|
repaint(offx, offy, TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void paintComponent (Graphics g)
|
public void paintComponent (Graphics g)
|
||||||
{
|
{
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D)g;
|
Graphics2D g2 = (Graphics2D)g;
|
||||||
|
|
||||||
// center the tile display if we are bigger than we need to be
|
// center the tile display if we are bigger than we need to be
|
||||||
@@ -271,7 +279,7 @@ public class VenisonBoard
|
|||||||
g.setColor(Color.blue);
|
g.setColor(Color.blue);
|
||||||
int sx = (_placingTile.x + _origX) * TILE_WIDTH;
|
int sx = (_placingTile.x + _origX) * TILE_WIDTH;
|
||||||
int sy = (_placingTile.y + _origY) * TILE_HEIGHT;
|
int sy = (_placingTile.y + _origY) * TILE_HEIGHT;
|
||||||
g.drawRect(sx, sy, TILE_WIDTH, TILE_HEIGHT);
|
g.drawRect(sx, sy, TILE_WIDTH-1, TILE_HEIGHT-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a recently placed tile, draw that one as well
|
// if we have a recently placed tile, draw that one as well
|
||||||
@@ -283,7 +291,7 @@ public class VenisonBoard
|
|||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
int sx = (_placedTile.x + _origX) * TILE_WIDTH;
|
int sx = (_placedTile.x + _origX) * TILE_WIDTH;
|
||||||
int sy = (_placedTile.y + _origY) * TILE_HEIGHT;
|
int sy = (_placedTile.y + _origY) * TILE_HEIGHT;
|
||||||
g.drawRect(sx, sy, TILE_WIDTH, TILE_HEIGHT);
|
g.drawRect(sx, sy, TILE_WIDTH-1, TILE_HEIGHT-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw a white rectangle around the last placed
|
// draw a white rectangle around the last placed
|
||||||
@@ -291,7 +299,7 @@ public class VenisonBoard
|
|||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
int sx = (_lastPlacedTile.x + _origX) * TILE_WIDTH;
|
int sx = (_lastPlacedTile.x + _origX) * TILE_WIDTH;
|
||||||
int sy = (_lastPlacedTile.y + _origY) * TILE_HEIGHT;
|
int sy = (_lastPlacedTile.y + _origY) * TILE_HEIGHT;
|
||||||
g.drawRect(sx, sy, TILE_WIDTH, TILE_HEIGHT);
|
g.drawRect(sx, sy, TILE_WIDTH-1, TILE_HEIGHT-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// undo our translations
|
// undo our translations
|
||||||
@@ -306,10 +314,9 @@ public class VenisonBoard
|
|||||||
_mouseY = evt.getY() - _ty;
|
_mouseY = evt.getY() - _ty;
|
||||||
|
|
||||||
if (_placingTile != null) {
|
if (_placingTile != null) {
|
||||||
// if we have a tile to be placed, update its coordinates
|
// if we have a tile to be placed, update its coordinates (it
|
||||||
if (updatePlacingInfo(false)) {
|
// will automatically be repainted)
|
||||||
repaint();
|
updatePlacingInfo(false);
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_placedTile != null && _placingPiecen) {
|
} else if (_placedTile != null && _placingPiecen) {
|
||||||
// if we have a recently placed tile, we're doing piecen
|
// if we have a recently placed tile, we're doing piecen
|
||||||
@@ -349,7 +356,7 @@ public class VenisonBoard
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
repaint();
|
repaintTile(_placedTile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +374,7 @@ public class VenisonBoard
|
|||||||
// clear out any placed piecen because we're placing nothing
|
// clear out any placed piecen because we're placing nothing
|
||||||
if (_placedTile != null && _placedTile.piecen != null) {
|
if (_placedTile != null && _placedTile.piecen != null) {
|
||||||
_placedTile.piecen = null;
|
_placedTile.piecen = null;
|
||||||
repaint();
|
repaintTile(_placedTile);
|
||||||
}
|
}
|
||||||
// post the action
|
// post the action
|
||||||
Controller.postAction(this, PLACE_NOTHING);
|
Controller.postAction(this, PLACE_NOTHING);
|
||||||
@@ -416,12 +423,12 @@ public class VenisonBoard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the coordinates and orientation of the placing tile based
|
* Updates the coordinates and orientation of the placing tile based
|
||||||
* on the last known coordinates of the mouse and returns true if the
|
* on the last known coordinates of the mouse and causes it to be
|
||||||
* coordinates or orientation changed from their previous values.
|
* repainted.
|
||||||
*/
|
*/
|
||||||
protected boolean updatePlacingInfo (boolean force)
|
protected void updatePlacingInfo (boolean force)
|
||||||
{
|
{
|
||||||
boolean changed = false;
|
boolean updated = false;
|
||||||
|
|
||||||
// convert mouse coordinates into tile coordinates and offset them
|
// convert mouse coordinates into tile coordinates and offset them
|
||||||
// by the origin
|
// by the origin
|
||||||
@@ -431,12 +438,18 @@ public class VenisonBoard
|
|||||||
// if these are different than the values currently in the placing
|
// if these are different than the values currently in the placing
|
||||||
// tile, update the tile coordinates
|
// tile, update the tile coordinates
|
||||||
if (_placingTile.x != x || _placingTile.y != y || force) {
|
if (_placingTile.x != x || _placingTile.y != y || force) {
|
||||||
|
// if we have a valid orientation presently, and we're moving,
|
||||||
|
// we need to clear out the old orientation
|
||||||
|
if (_validPlacement) {
|
||||||
|
repaintTile(_placingTile);
|
||||||
|
}
|
||||||
|
|
||||||
// update the coordinates of the tile
|
// update the coordinates of the tile
|
||||||
_placingTile.x = x;
|
_placingTile.x = x;
|
||||||
_placingTile.y = y;
|
_placingTile.y = y;
|
||||||
|
|
||||||
// we've changed the display, so make a note of it
|
// make a note that we moved
|
||||||
changed = true;
|
updated = true;
|
||||||
|
|
||||||
// we also need to recompute the valid orientations for the
|
// we also need to recompute the valid orientations for the
|
||||||
// tile in this new position
|
// tile in this new position
|
||||||
@@ -460,14 +473,19 @@ public class VenisonBoard
|
|||||||
if (_validOrients[candOrient]) {
|
if (_validOrients[candOrient]) {
|
||||||
if (_placingTile.orientation != candOrient) {
|
if (_placingTile.orientation != candOrient) {
|
||||||
_placingTile.orientation = candOrient;
|
_placingTile.orientation = candOrient;
|
||||||
changed = true;
|
// make a note that we moved
|
||||||
|
updated = true;
|
||||||
}
|
}
|
||||||
_validPlacement = true;
|
_validPlacement = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
// if we now have a valid orientation and something was changed,
|
||||||
|
// we want to repaint at the new tile location
|
||||||
|
if (_validPlacement && updated) {
|
||||||
|
repaintTile(_placingTile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,13 +6,20 @@ package com.threerings.venison;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.Frame;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.AncestorEvent;
|
||||||
|
import javax.swing.event.AncestorListener;
|
||||||
|
|
||||||
import com.samskivert.swing.Controller;
|
import com.samskivert.swing.Controller;
|
||||||
import com.samskivert.swing.ControllerProvider;
|
import com.samskivert.swing.ControllerProvider;
|
||||||
import com.samskivert.swing.HGroupLayout;
|
import com.samskivert.swing.HGroupLayout;
|
||||||
import com.samskivert.swing.VGroupLayout;
|
import com.samskivert.swing.VGroupLayout;
|
||||||
|
|
||||||
|
import com.threerings.resource.ResourceManager;
|
||||||
|
import com.threerings.media.ImageManager;
|
||||||
|
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
import com.threerings.crowd.client.PlaceView;
|
import com.threerings.crowd.client.PlaceView;
|
||||||
|
|
||||||
@@ -93,6 +100,21 @@ public class VenisonPanel
|
|||||||
|
|
||||||
// we'll need this later to provide it
|
// we'll need this later to provide it
|
||||||
_controller = controller;
|
_controller = controller;
|
||||||
|
|
||||||
|
// we can't create our image manager until we have access to our
|
||||||
|
// containing frame
|
||||||
|
addAncestorListener(new AncestorListener() {
|
||||||
|
public void ancestorAdded (AncestorEvent event) {
|
||||||
|
// create our image manager
|
||||||
|
JRootPane rpane = getRootPane();
|
||||||
|
VenisonTile.setImageManager(
|
||||||
|
new ImageManager(_rmgr, (Frame)rpane.getParent()));
|
||||||
|
}
|
||||||
|
public void ancestorMoved (AncestorEvent event) {
|
||||||
|
}
|
||||||
|
public void ancestorRemoved (AncestorEvent event) {
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -116,4 +138,14 @@ public class VenisonPanel
|
|||||||
/** A reference to our controller that we need to implement the {@link
|
/** A reference to our controller that we need to implement the {@link
|
||||||
* ControllerProvider} interface. */
|
* ControllerProvider} interface. */
|
||||||
protected VenisonController _controller;
|
protected VenisonController _controller;
|
||||||
|
|
||||||
|
// this stuff is all a bit of a hack right now. by all rights, the
|
||||||
|
// venison app should set up the resource manager, because it knows
|
||||||
|
// about that sort of stuff, and make it available via the venison
|
||||||
|
// context and we may have some better place for the image manager to
|
||||||
|
// live and the tile set would be fetched through the tile
|
||||||
|
// manager. but it's late and i want to get this working, so fooey.
|
||||||
|
|
||||||
|
/** Our resource manager. */
|
||||||
|
protected static ResourceManager _rmgr = new ResourceManager("rsrc");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
//
|
//
|
||||||
// $Id: AtlantiTile.java,v 1.10 2001/10/18 20:56:45 mdb Exp $
|
// $Id: AtlantiTile.java,v 1.11 2001/11/08 08:00:22 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.venison;
|
package com.threerings.venison;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@@ -15,6 +17,11 @@ import java.util.List;
|
|||||||
import com.samskivert.util.IntTuple;
|
import com.samskivert.util.IntTuple;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
|
import com.threerings.media.ImageManager;
|
||||||
|
import com.threerings.media.tile.NoSuchTileException;
|
||||||
|
import com.threerings.media.tile.Tile;
|
||||||
|
import com.threerings.media.tile.UniformTileSet;
|
||||||
|
|
||||||
import com.threerings.presents.dobj.DSet;
|
import com.threerings.presents.dobj.DSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,6 +265,11 @@ public class VenisonTile
|
|||||||
{
|
{
|
||||||
int tidx = type-1;
|
int tidx = type-1;
|
||||||
|
|
||||||
|
// obtain our tile image
|
||||||
|
if (_tileImage == null) {
|
||||||
|
_tileImage = getTileImage(type);
|
||||||
|
}
|
||||||
|
|
||||||
// compute our screen coordinates
|
// compute our screen coordinates
|
||||||
int sx = (x + xoff) * TILE_WIDTH;
|
int sx = (x + xoff) * TILE_WIDTH;
|
||||||
int sy = (y + yoff) * TILE_HEIGHT;
|
int sy = (y + yoff) * TILE_HEIGHT;
|
||||||
@@ -265,10 +277,23 @@ public class VenisonTile
|
|||||||
// translate to our screen coordinates
|
// translate to our screen coordinates
|
||||||
g.translate(sx, sy);
|
g.translate(sx, sy);
|
||||||
|
|
||||||
|
// render our tile image
|
||||||
|
if (_tileImage != null) {
|
||||||
|
if (orientation > 0) {
|
||||||
|
g.drawImage(_tileImage, _xforms[orientation], null);
|
||||||
|
} else {
|
||||||
|
g.drawImage(_tileImage, 0, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.warning("No tile image!? [type=" + type +
|
||||||
|
", img=" + _tileImage + "].");
|
||||||
|
}
|
||||||
|
|
||||||
// render our features and piecen
|
// render our features and piecen
|
||||||
for (int i = 0; i < features.length; i++) {
|
for (int i = 0; i < features.length; i++) {
|
||||||
// paint the feature
|
// paint the feature
|
||||||
features[i].paint(g, orientation, claims[i]);
|
// features[i].paint(g, orientation, claims[i]);
|
||||||
|
|
||||||
// if we have a piecen on this tile, render it as well
|
// if we have a piecen on this tile, render it as well
|
||||||
if (piecen != null && piecen.featureIndex == i) {
|
if (piecen != null && piecen.featureIndex == i) {
|
||||||
@@ -277,9 +302,9 @@ public class VenisonTile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw a rectangular outline
|
// // draw a rectangular outline
|
||||||
g.setColor(Color.black);
|
// g.setColor(Color.black);
|
||||||
g.drawRect(0, 0, TILE_WIDTH, TILE_HEIGHT);
|
// g.drawRect(0, 0, TILE_WIDTH-1, TILE_HEIGHT-1);
|
||||||
|
|
||||||
// if we have a shield, draw a square in the lower right
|
// if we have a shield, draw a square in the lower right
|
||||||
if (hasShield) {
|
if (hasShield) {
|
||||||
@@ -393,4 +418,70 @@ public class VenisonTile
|
|||||||
", claims=" + StringUtil.toString(claims) +
|
", claims=" + StringUtil.toString(claims) +
|
||||||
", piecen=" + piecen + "]";
|
", piecen=" + piecen + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Someone needs to configure this so that we can display tiles on
|
||||||
|
* screen.
|
||||||
|
*/
|
||||||
|
public static void setImageManager (ImageManager imgr)
|
||||||
|
{
|
||||||
|
_imgr = imgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the image for the tile of the specified type.
|
||||||
|
*/
|
||||||
|
protected static Image getTileImage (int type)
|
||||||
|
{
|
||||||
|
// load up the tile set if we haven't already
|
||||||
|
if (_tset == null) {
|
||||||
|
_tset = new UniformTileSet(
|
||||||
|
_imgr, TILES_IMG_PATH, TILE_TYPES, TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch the tile
|
||||||
|
try {
|
||||||
|
Tile tile = _tset.getTile(type-1);
|
||||||
|
if (tile != null) {
|
||||||
|
return tile.img;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (NoSuchTileException nste) {
|
||||||
|
// fall through
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.warning("Unable to load tile image [type=" + type + "].");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The tile image that we use to render this tile. */
|
||||||
|
protected Image _tileImage;
|
||||||
|
|
||||||
|
/** Our image manager. */
|
||||||
|
protected static ImageManager _imgr;
|
||||||
|
|
||||||
|
/** Our tileset. */
|
||||||
|
protected static UniformTileSet _tset;
|
||||||
|
|
||||||
|
/** The path to our tileset image. */
|
||||||
|
protected static final String TILES_IMG_PATH = "media/tiles.png";
|
||||||
|
|
||||||
|
/** Three affine transforms for rendering an image in three rotated
|
||||||
|
* orientations. */
|
||||||
|
protected static AffineTransform[] _xforms;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// the first element will be left blank
|
||||||
|
_xforms = new AffineTransform[4];
|
||||||
|
|
||||||
|
// create our three orientation transforms
|
||||||
|
AffineTransform xform = new AffineTransform();
|
||||||
|
for (int orient = 1; orient < 4; orient++) {
|
||||||
|
// rotate the xform into the next orientation
|
||||||
|
xform.translate(TILE_WIDTH, 0);
|
||||||
|
xform.rotate(Math.PI/2);
|
||||||
|
// and save it
|
||||||
|
_xforms[orient] = (AffineTransform)xform.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileUtil.java,v 1.14 2001/11/07 10:39:00 mdb Exp $
|
// $Id: TileUtil.java,v 1.15 2001/11/08 08:00:22 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.venison;
|
package com.threerings.venison;
|
||||||
|
|
||||||
import java.awt.Polygon;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
Reference in New Issue
Block a user