v0.7.5: improved itemsprite construction for heaps and various UI elements

This commit is contained in:
Evan Debenham 2019-09-29 03:37:12 -04:00
parent 868ace78b1
commit 92f198a9b0
5 changed files with 78 additions and 67 deletions

View File

@ -84,33 +84,6 @@ public class Heap implements Bundlable {
public LinkedList<Item> items = new LinkedList<Item>();
public int image() {
switch (type) {
case HEAP:
case FOR_SALE:
return size() > 0 ? items.peek().image() : 0;
case CHEST:
case MIMIC:
return ItemSpriteSheet.CHEST;
case LOCKED_CHEST:
return ItemSpriteSheet.LOCKED_CHEST;
case CRYSTAL_CHEST:
return ItemSpriteSheet.CRYSTAL_CHEST;
case TOMB:
return ItemSpriteSheet.TOMB;
case SKELETON:
return ItemSpriteSheet.BONES;
case REMAINS:
return ItemSpriteSheet.REMAINS;
default:
return 0;
}
}
public ItemSprite.Glowing glowing() {
return (type == Type.HEAP || type == Type.FOR_SALE) && items.size() > 0 ? items.peek().glowing() : null;
}
public void open( Hero hero ) {
switch (type) {
case MIMIC:
@ -180,8 +153,7 @@ public class Heap implements Bundlable {
if (items.isEmpty()) {
destroy();
} else if (sprite != null) {
sprite.view( image(), glowing() );
sprite.place( pos );
sprite.view(this).place( pos );
}
return item;
@ -212,11 +184,7 @@ public class Heap implements Bundlable {
}
if (sprite != null) {
if (type == Type.HEAP || type == Type.FOR_SALE)
sprite.view( items.peek() );
else
sprite.view( image(), glowing() );
sprite.place( pos );
sprite.view(this).place( pos );
}
}
@ -232,9 +200,8 @@ public class Heap implements Bundlable {
items.remove(a);
if (items.isEmpty()){
destroy();
} else {
sprite.view( image(), glowing() );
sprite.place( pos );
} else if (sprite != null) {
sprite.view(this).place( pos );
}
}
@ -292,7 +259,7 @@ public class Heap implements Bundlable {
if (isEmpty()) {
destroy();
} else if (sprite != null) {
sprite.view( items.peek() );
sprite.view(this).place( pos );
}
}
@ -339,7 +306,7 @@ public class Heap implements Bundlable {
if (isEmpty()){
destroy();
} else if (sprite != null) {
sprite.view( items.peek() );
sprite.view(this).place( pos );
}
}
}
@ -377,7 +344,7 @@ public class Heap implements Bundlable {
if (isEmpty()) {
destroy();
} else if (sprite != null) {
sprite.view( items.peek() );
sprite.view(this).place( pos );
}
}
}

View File

@ -74,10 +74,14 @@ public class ItemSprite extends MovieClip {
this( ItemSpriteSheet.SOMETHING, null );
}
public ItemSprite( Heap heap ){
super(Assets.ITEMS);
view( heap );
}
public ItemSprite( Item item ) {
super(Assets.ITEMS);
view (item);
view( item );
}
public ItemSprite( int image ){
@ -100,7 +104,7 @@ public class ItemSprite extends MovieClip {
public void link( Heap heap ) {
this.heap = heap;
view( heap.image(), heap.glowing() );
view(heap);
renderShadow = true;
place(heap.pos);
}
@ -182,7 +186,7 @@ public class ItemSprite extends MovieClip {
}
}
public ItemSprite view(Item item){
public ItemSprite view( Item item ){
view(item.image(), item.glowing());
Emitter emitter = item.emitter();
if (emitter != null && parent != null) {
@ -193,6 +197,32 @@ public class ItemSprite extends MovieClip {
return this;
}
public ItemSprite view( Heap heap ){
if (heap.size() <= 0 || heap.items == null){
return view( 0, null );
}
switch (heap.type) {
case HEAP: case FOR_SALE:
return view( heap.peek() );
case CHEST:
case MIMIC:
return view( ItemSpriteSheet.CHEST, null );
case LOCKED_CHEST:
return view( ItemSpriteSheet.LOCKED_CHEST, null );
case CRYSTAL_CHEST:
return view( ItemSpriteSheet.CRYSTAL_CHEST, null );
case TOMB:
return view( ItemSpriteSheet.TOMB, null );
case SKELETON:
return view( ItemSpriteSheet.BONES, null );
case REMAINS:
return view( ItemSpriteSheet.REMAINS, null );
default:
return view( 0, null );
}
}
public ItemSprite view( int image, Glowing glowing ) {
if (this.emitter != null) this.emitter.killAndErase();
emitter = null;

View File

@ -70,7 +70,7 @@ public class MissileSprite extends ItemSprite implements Tweener.Listener {
revive();
if (item == null) view(0, null);
else view(item.image(), item.glowing());
else view( item );
setup( from,
to,

View File

@ -21,6 +21,7 @@
package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
@ -53,6 +54,13 @@ public class IconTitle extends Component {
label( Messages.titleCase( item.toString() ) );
icon.view( item );
}
public IconTitle( Heap heap ){
ItemSprite icon = new ItemSprite();
icon( icon );
label( Messages.titleCase( heap.toString() ) );
icon.view( heap );
}
public IconTitle( Image icon, String label ) {
super();

View File

@ -43,28 +43,40 @@ public class WndInfoItem extends Window {
super();
if (heap.type == Heap.Type.HEAP || heap.type == Heap.Type.FOR_SALE) {
Item item = heap.peek();
int color = TITLE_COLOR;
if (item.levelKnown && item.level() > 0) {
color = ItemSlot.UPGRADED;
} else if (item.levelKnown && item.level() < 0) {
color = ItemSlot.DEGRADED;
}
fillFields( item.image(), item.glowing(), color, item.toString(), item.info() );
fillFields( heap.peek() );
} else {
fillFields( heap.image(), heap.glowing(), TITLE_COLOR, heap.toString(), heap.info() );
fillFields( heap );
}
}
public WndInfoItem( Item item ) {
super();
fillFields( item );
}
private void fillFields( Heap heap ) {
int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P;
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite(heap) );
titlebar.color( TITLE_COLOR );
titlebar.setRect( 0, 0, width, 0 );
add( titlebar );
RenderedTextMultiline txtInfo = PixelScene.renderMultiline( heap.info(), 6 );
txtInfo.maxWidth(width);
txtInfo.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( txtInfo );
resize( width, (int)(txtInfo.top() + txtInfo.height()) );
}
private void fillFields( Item item ) {
int color = TITLE_COLOR;
if (item.levelKnown && item.level() > 0) {
color = ItemSlot.UPGRADED;
@ -72,20 +84,14 @@ public class WndInfoItem extends Window {
color = ItemSlot.DEGRADED;
}
fillFields( item.image(), item.glowing(), color, item.toString(), item.info() );
}
private void fillFields( int image, ItemSprite.Glowing glowing, int titleColor, String title, String info ) {
int width = SPDSettings.landscape() ? WIDTH_L : WIDTH_P;
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( image, glowing ) );
titlebar.label( Messages.titleCase( title ), titleColor );
IconTitle titlebar = new IconTitle( item );
titlebar.color( color );
titlebar.setRect( 0, 0, width, 0 );
add( titlebar );
RenderedTextMultiline txtInfo = PixelScene.renderMultiline( info, 6 );
RenderedTextMultiline txtInfo = PixelScene.renderMultiline( item.info(), 6 );
txtInfo.maxWidth(width);
txtInfo.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( txtInfo );