v0.7.0: added generic icontab class, added icons to journal tabs

This commit is contained in:
Evan Debenham 2018-10-01 02:10:57 -04:00
parent 6e8fe2089d
commit 0f4dadc229
3 changed files with 67 additions and 45 deletions

View File

@ -62,7 +62,6 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.RectF;
public class WndBag extends WndTabbed {
@ -280,43 +279,7 @@ public class WndBag extends WndTabbed {
return 20;
}
private class BagTab extends Tab {
private Image icon;
private Bag bag;
public BagTab( Bag bag ) {
super();
this.bag = bag;
icon = icon();
add( icon );
}
@Override
protected void select( boolean value ) {
super.select( value );
icon.am = selected ? 1.0f : 0.6f;
}
@Override
protected void layout() {
super.layout();
icon.copy( icon() );
icon.x = x + (width - icon.width) / 2;
icon.y = y + (height - icon.height) / 2 - 2 - (selected ? 0 : 1);
if (!selected && icon.y < y + CUT) {
RectF frame = icon.frame();
frame.top += (y + CUT - icon.y) / icon.texture.height;
icon.frame( frame );
icon.y = y + CUT;
}
}
private Image icon() {
private Image icon( Bag bag ) {
if (bag instanceof VelvetPouch) {
return Icons.get( Icons.SEED_POUCH );
} else if (bag instanceof ScrollHolder) {
@ -329,6 +292,17 @@ public class WndBag extends WndTabbed {
return Icons.get( Icons.BACKPACK );
}
}
private class BagTab extends IconTab {
private Bag bag;
public BagTab( Bag bag ) {
super( icon(bag) );
this.bag = bag;
}
}
public static class Placeholder extends Item {

View File

@ -90,21 +90,21 @@ public class WndJournal extends WndTabbed {
catalogTab.updateList();
Tab[] tabs = {
new LabeledTab( Messages.get(this, "guide") ) {
new IconTab( new ItemSprite(ItemSpriteSheet.GUIDE_PAGE, null) ) {
protected void select( boolean value ) {
super.select( value );
guideTab.active = guideTab.visible = value;
if (value) last_index = 0;
}
},
new LabeledTab( Messages.get(this, "notes") ) {
new IconTab( Icons.get(Icons.DEPTH) ) {
protected void select( boolean value ) {
super.select( value );
notesTab.active = notesTab.visible = value;
if (value) last_index = 1;
}
},
new LabeledTab( Messages.get(this, "items") ) {
new IconTab( new ItemSprite(ItemSpriteSheet.WEAPON_HOLDER, null) ) {
protected void select( boolean value ) {
super.select( value );
catalogTab.active = catalogTab.visible = value;

View File

@ -26,10 +26,12 @@ import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.RectF;
import java.util.ArrayList;
@ -230,4 +232,50 @@ public class WndTabbed extends Window {
}
}
protected class IconTab extends Tab {
private Image icon;
private RectF defaultFrame;
public IconTab( Image icon ){
super();
this.icon.copy(icon);
this.defaultFrame = icon.frame();
}
@Override
protected void createChildren() {
super.createChildren();
icon = new Image();
add( icon );
}
@Override
protected void layout() {
super.layout();
icon.frame(defaultFrame);
icon.x = x + (width - icon.width) / 2;
icon.y = y + (height - icon.height) / 2 - 1;
if (!selected) {
icon.y -= 2;
//if some of the icon is going into the window, cut it off
if (icon.y < y + CUT) {
RectF frame = icon.frame();
frame.top += (y + CUT - icon.y) / icon.texture.height;
icon.frame( frame );
icon.y = y + CUT;
}
}
}
@Override
protected void select( boolean value ) {
super.select( value );
icon.am = selected ? 1.0f : 0.6f;
}
}
}