From 0f4dadc2297035a1e20b98630f3cb36f15063edc Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 1 Oct 2018 02:10:57 -0400 Subject: [PATCH] v0.7.0: added generic icontab class, added icons to journal tabs --- .../shatteredpixeldungeon/windows/WndBag.java | 58 +++++-------------- .../windows/WndJournal.java | 6 +- .../windows/WndTabbed.java | 48 +++++++++++++++ 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index a8284b9ca..041a03499 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -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,55 +279,30 @@ public class WndBag extends WndTabbed { return 20; } - private class BagTab extends Tab { - - private Image icon; + private Image icon( Bag bag ) { + if (bag instanceof VelvetPouch) { + return Icons.get( Icons.SEED_POUCH ); + } else if (bag instanceof ScrollHolder) { + return Icons.get( Icons.SCROLL_HOLDER ); + } else if (bag instanceof MagicalHolster) { + return Icons.get( Icons.WAND_HOLSTER ); + } else if (bag instanceof PotionBandolier) { + return Icons.get( Icons.POTION_BANDOLIER ); + } else { + return Icons.get( Icons.BACKPACK ); + } + } + + private class BagTab extends IconTab { private Bag bag; public BagTab( Bag bag ) { - super(); + super( icon(bag) ); 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() { - if (bag instanceof VelvetPouch) { - return Icons.get( Icons.SEED_POUCH ); - } else if (bag instanceof ScrollHolder) { - return Icons.get( Icons.SCROLL_HOLDER ); - } else if (bag instanceof MagicalHolster) { - return Icons.get( Icons.WAND_HOLSTER ); - } else if (bag instanceof PotionBandolier) { - return Icons.get( Icons.POTION_BANDOLIER ); - } else { - return Icons.get( Icons.BACKPACK ); - } - } } public static class Placeholder extends Item { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java index 92ab857df..67fb1877b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java @@ -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; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java index 0dd0e67d0..e7edab8d2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java @@ -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; @@ -229,5 +231,51 @@ public class WndTabbed extends Window { btLabel.am = selected ? 1.0f : 0.6f; } } + + 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; + } + } }