v0.6.1: buffs in the hero window now scroll if there are many of them

This commit is contained in:
Evan Debenham 2017-07-14 20:09:27 -04:00
parent 61fb79d9ab
commit 17c3f501a8

View File

@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.gltextures.SmartTexture; import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
@ -38,13 +39,15 @@ import com.watabou.noosa.Group;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TextureFilm; import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
public class WndHero extends WndTabbed { public class WndHero extends WndTabbed {
private static final int WIDTH = 115; private static final int WIDTH = 115;
private static final int HEIGHT = 100;
private StatsTab stats; private StatsTab stats;
private BuffsTab buffs; private BuffsTab buffs;
@ -56,6 +59,8 @@ public class WndHero extends WndTabbed {
super(); super();
resize( WIDTH, HEIGHT );
icons = TextureCache.get( Assets.BUFFS_LARGE ); icons = TextureCache.get( Assets.BUFFS_LARGE );
film = new TextureFilm( icons, 16, 16 ); film = new TextureFilm( icons, 16, 16 );
@ -64,6 +69,8 @@ public class WndHero extends WndTabbed {
buffs = new BuffsTab(); buffs = new BuffsTab();
add( buffs ); add( buffs );
buffs.setRect(0, 0, WIDTH, HEIGHT);
buffs.setupList();
add( new LabeledTab( Messages.get(this, "stats") ) { add( new LabeledTab( Messages.get(this, "stats") ) {
protected void select( boolean value ) { protected void select( boolean value ) {
@ -78,8 +85,6 @@ public class WndHero extends WndTabbed {
}; };
} ); } );
resize( WIDTH, (int)Math.max( stats.height(), buffs.height() ) );
layoutTabs(); layoutTabs();
select( 0 ); select( 0 );
@ -144,28 +149,51 @@ public class WndHero extends WndTabbed {
} }
} }
private class BuffsTab extends Group { private class BuffsTab extends Component {
private static final int GAP = 2; private static final int GAP = 2;
private float pos; private float pos;
private ScrollPane buffList;
private ArrayList<BuffSlot> slots = new ArrayList<>();
public BuffsTab() { public BuffsTab() {
buffList = new ScrollPane( new Component() ){
@Override
public void onClick( float x, float y ) {
int size = slots.size();
for (int i=0; i < size; i++) {
if (slots.get( i ).onClick( x, y )) {
break;
}
}
}
};
add(buffList);
}
@Override
protected void layout() {
super.layout();
buffList.setRect(0, 0, width, height);
}
private void setupList() {
Component content = buffList.content();
for (Buff buff : Dungeon.hero.buffs()) { for (Buff buff : Dungeon.hero.buffs()) {
if (buff.icon() != BuffIndicator.NONE) { if (buff.icon() != BuffIndicator.NONE) {
BuffSlot slot = new BuffSlot(buff); BuffSlot slot = new BuffSlot(buff);
slot.setRect(0, pos, WIDTH, slot.icon.height()); slot.setRect(0, pos, WIDTH, slot.icon.height());
add(slot); content.add(slot);
slots.add(slot);
pos += GAP + slot.height(); pos += GAP + slot.height();
} }
} }
content.setSize(buffList.width(), pos);
buffList.setSize(buffList.width(), buffList.height());
} }
public float height() { private class BuffSlot extends Component {
return pos;
}
private class BuffSlot extends Button{
private Buff buff; private Buff buff;
@ -197,9 +225,13 @@ public class WndHero extends WndTabbed {
txt.y = pos + (int)(icon.height - txt.baseLine()) / 2; txt.y = pos + (int)(icon.height - txt.baseLine()) / 2;
} }
@Override protected boolean onClick ( float x, float y ) {
protected void onClick() { if (inside( x, y )) {
GameScene.show( new WndInfoBuff( buff )); GameScene.show(new WndInfoBuff(buff));
return true;
} else {
return false;
}
} }
} }
} }