v0.3.0: some refactoring to item sprites to better use an item as a parameter

This commit is contained in:
Evan Debenham
2015-05-11 20:14:13 -04:00
parent 097852207d
commit 0a78b2dc28
6 changed files with 23 additions and 13 deletions
@@ -59,7 +59,13 @@ public class ItemSprite extends MovieClip {
} }
public ItemSprite( Item item ) { public ItemSprite( Item item ) {
this( item.image(), item.glowing() ); super(Assets.ITEMS);
if (film == null) {
film = new TextureFilm( texture, SIZE, SIZE );
}
view (item);
} }
public ItemSprite( int image, Glowing glowing ) { public ItemSprite( int image, Glowing glowing ) {
@@ -69,21 +75,21 @@ public class ItemSprite extends MovieClip {
film = new TextureFilm( texture, SIZE, SIZE ); film = new TextureFilm( texture, SIZE, SIZE );
} }
view( image, glowing ); view(image, glowing);
} }
public void originToCenter() { public void originToCenter() {
origin.set(SIZE / 2 ); origin.set(SIZE / 2);
} }
public void link() { public void link() {
link( heap ); link(heap);
} }
public void link( Heap heap ) { public void link( Heap heap ) {
this.heap = heap; this.heap = heap;
view( heap.image(), heap.glowing() ); view( heap.image(), heap.glowing() );
place( heap.pos ); place(heap.pos);
} }
@Override @Override
@@ -119,7 +125,7 @@ public class ItemSprite extends MovieClip {
dropInterval = DROP_INTERVAL; dropInterval = DROP_INTERVAL;
speed.set( 0, -100 ); speed.set( 0, -100 );
acc.set( 0, -speed.y / DROP_INTERVAL * 2 ); acc.set(0, -speed.y / DROP_INTERVAL * 2);
if (visible && heap != null && heap.peek() instanceof Gold) { if (visible && heap != null && heap.peek() instanceof Gold) {
CellEmitter.center( heap.pos ).burst( Speck.factory( Speck.COIN ), 5 ); CellEmitter.center( heap.pos ).burst( Speck.factory( Speck.COIN ), 5 );
@@ -137,12 +143,16 @@ public class ItemSprite extends MovieClip {
float py = y; float py = y;
drop(); drop();
place( from ); place(from);
speed.offset( (px-x) / DROP_INTERVAL, (py-y) / DROP_INTERVAL ); speed.offset((px - x) / DROP_INTERVAL, (py - y) / DROP_INTERVAL);
} }
} }
public ItemSprite view(Item item){
return view(item.image(), item.glowing());
}
public ItemSprite view( int image, Glowing glowing ) { public ItemSprite view( int image, Glowing glowing ) {
frame( film.get( image ) ); frame( film.get( image ) );
if ((this.glowing = glowing) == null) { if ((this.glowing = glowing) == null) {
@@ -140,7 +140,7 @@ public class ItemSlot extends Button {
active = true; active = true;
icon.visible = topLeft.visible = topRight.visible = bottomRight.visible = true; icon.visible = topLeft.visible = topRight.visible = bottomRight.visible = true;
icon.view( item.image(), item.glowing() ); icon.view( item );
topLeft.text( item.status() ); topLeft.text( item.status() );
@@ -341,7 +341,7 @@ public class Toolbar extends Component {
} }
public void reset( Item item, float dstX, float dstY ) { public void reset( Item item, float dstX, float dstY ) {
view( item.image(), item.glowing() ); view( item );
active = active =
visible = visible =
@@ -45,7 +45,7 @@ public class IconTitle extends Component {
public IconTitle( Item item ) { public IconTitle( Item item ) {
this( this(
new ItemSprite( item.image(), item.glowing() ), new ItemSprite( item ),
Utils.capitalize( item.toString() ) ); Utils.capitalize( item.toString() ) );
} }
@@ -41,7 +41,7 @@ public class WndItem extends Window {
super(); super();
IconTitle titlebar = new IconTitle(); IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) ); titlebar.icon( new ItemSprite( item ) );
titlebar.label( Utils.capitalize( item.toString() ) ); titlebar.label( Utils.capitalize( item.toString() ) );
titlebar.setRect( 0, 0, WIDTH, 0 ); titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar ); add( titlebar );
@@ -205,7 +205,7 @@ public class WndTradeItem extends Window {
// Title // Title
IconTitle titlebar = new IconTitle(); IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) ); titlebar.icon( new ItemSprite( item ) );
titlebar.label( forSale ? titlebar.label( forSale ?
Utils.format( TXT_SALE, item.toString(), price( item ) ) : Utils.format( TXT_SALE, item.toString(), price( item ) ) :
Utils.capitalize( item.toString() ) ); Utils.capitalize( item.toString() ) );