From 00c19d55bdebcf927c58e261b4fb6d8a57a67e0c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 7 Apr 2015 01:52:17 -0400 Subject: [PATCH] v0.3.0: added functionality for full buff descriptions (need to write them still) --- .../actors/buffs/Buff.java | 4 ++ .../ui/BuffIndicator.java | 51 ++++++++++---- .../windows/WndHero.java | 66 +++++++++++++------ .../windows/WndInfoBuff.java | 51 ++++++++++++++ 4 files changed, 139 insertions(+), 33 deletions(-) create mode 100644 src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoBuff.java diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java index 3e1755ce7..7aefbab41 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java @@ -103,4 +103,8 @@ public class Buff extends Actor { public static void detach( Char target, Class cl ) { detach( target.buff( cl ) ); } + + public String desc(){ + return ""; + } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java index f7672942e..274d94a31 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java @@ -17,11 +17,14 @@ */ package com.shatteredpixel.shatteredpixeldungeon.ui; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoBuff; import com.watabou.gltextures.SmartTexture; import com.watabou.gltextures.TextureCache; import com.watabou.noosa.Image; import com.watabou.noosa.TextureFilm; import com.watabou.noosa.tweeners.AlphaTweener; +import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Component; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; @@ -77,7 +80,7 @@ public class BuffIndicator extends Component { private SmartTexture texture; private TextureFilm film; - private SparseArray icons = new SparseArray(); + private SparseArray icons = new SparseArray(); private Char ch; @@ -109,24 +112,20 @@ public class BuffIndicator extends Component { protected void layout() { clear(); - SparseArray newIcons = new SparseArray(); + SparseArray newIcons = new SparseArray(); for (Buff buff : ch.buffs()) { - int icon = buff.icon(); - if (icon != NONE) { - Image img = new Image( texture ); - img.frame( film.get( icon ) ); - img.x = x + members.size() * (SIZE + 2); - img.y = y; - add( img ); - - newIcons.put( icon, img ); + if (buff.icon() != NONE) { + BuffIcon icon = new BuffIcon( buff ); + icon.setRect(x + members.size() * (SIZE + 2), y, 7, 7); + add(icon); + newIcons.put( buff.icon(), icon ); } } for (Integer key : icons.keyArray()) { if (newIcons.get( key ) == null) { - Image icon = icons.get( key ); + Image icon = icons.get( key ).icon; icon.origin.set( SIZE / 2 ); add( icon ); add( new AlphaTweener( icon, 0, 0.6f ) { @@ -141,6 +140,34 @@ public class BuffIndicator extends Component { icons = newIcons; } + + private class BuffIcon extends Button { + + private Buff buff; + + public Image icon; + + public BuffIcon( Buff buff ){ + super(); + this.buff = buff; + + icon = new Image( texture ); + icon.frame( film.get( buff.icon() ) ); + add( icon ); + } + + @Override + protected void layout() { + super.layout(); + icon.x = this.x; + icon.y = this.y; + } + + @Override + protected void onClick() { + GameScene.show(new WndInfoBuff(buff)); + } + } public static void refreshHero() { if (heroInstance != null) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java index 1353187f7..491bfa3b6 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndHero.java @@ -37,6 +37,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.noosa.ui.Button; public class WndHero extends WndTabbed { @@ -180,32 +181,55 @@ public class WndHero extends WndTabbed { public BuffsTab() { for (Buff buff : Dungeon.hero.buffs()) { - buffSlot( buff ); - } - } - - private void buffSlot( Buff buff ) { - - int index = buff.icon(); - - if (index != BuffIndicator.NONE) { - - Image icon = new Image( icons ); - icon.frame( film.get( index ) ); - icon.y = pos; - add( icon ); - - BitmapText txt = PixelScene.createText( buff.toString(), 8 ); - txt.x = icon.width + GAP; - txt.y = pos + (int)(icon.height - txt.baseLine()) / 2; - add( txt ); - - pos += GAP + icon.height; + if (buff.icon() != BuffIndicator.NONE) { + BuffSlot slot = new BuffSlot(buff); + slot.setRect(0, pos, WIDTH, slot.icon.height()); + add(slot); + pos += GAP + slot.height(); + } } } public float height() { return pos; } + + private class BuffSlot extends Button{ + + private Buff buff; + + Image icon; + BitmapText txt; + + public BuffSlot( Buff buff ){ + super(); + this.buff = buff; + int index = buff.icon(); + + icon = new Image( icons ); + icon.frame( film.get( index ) ); + icon.y = this.y; + add( icon ); + + txt = PixelScene.createText( buff.toString(), 8 ); + txt.x = icon.width + GAP; + txt.y = this.y + (int)(icon.height - txt.baseLine()) / 2; + add( txt ); + + } + + @Override + protected void layout() { + super.layout(); + icon.y = this.y; + txt.x = icon.width + GAP; + txt.y = pos + (int)(icon.height - txt.baseLine()) / 2; + } + + @Override + protected void onClick() { + GameScene.show( new WndInfoBuff( buff )); + } + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoBuff.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoBuff.java new file mode 100644 index 000000000..d7e47ece8 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoBuff.java @@ -0,0 +1,51 @@ +package com.shatteredpixel.shatteredpixeldungeon.windows; + +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.shatteredpixel.shatteredpixeldungeon.ui.Window; +import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.watabou.gltextures.SmartTexture; +import com.watabou.gltextures.TextureCache; +import com.watabou.noosa.BitmapTextMultiline; +import com.watabou.noosa.Image; +import com.watabou.noosa.TextureFilm; + +/** + * Created by debenhame on 06/04/2015. + */ +public class WndInfoBuff extends Window { + + private static final float GAP = 2; + + private static final int WIDTH = 120; + + private SmartTexture icons; + private TextureFilm film; + + public WndInfoBuff(Buff buff){ + super(); + + IconTitle titlebar = new IconTitle(); + + icons = TextureCache.get( Assets.BUFFS_LARGE ); + film = new TextureFilm( icons, 16, 16 ); + + Image buffIcon = new Image( icons ); + buffIcon.frame( film.get(buff.icon()) ); + + titlebar.icon( buffIcon ); + titlebar.label( Utils.capitalize(buff.toString()), Window.TITLE_COLOR ); + titlebar.setRect( 0, 0, WIDTH, 0 ); + add( titlebar ); + + BitmapTextMultiline txtInfo = PixelScene.createMultiline(buff.desc(), 6); + txtInfo.maxWidth = WIDTH; + txtInfo.measure(); + txtInfo.x = titlebar.left(); + txtInfo.y = titlebar.bottom() + GAP; + add( txtInfo ); + + resize( WIDTH, (int)(txtInfo.y + txtInfo.height()) ); + } +}