diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 13e7a1bc6..e02d63f36 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -58,6 +58,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.PlantSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; +import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.Banner; import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator; @@ -135,6 +136,7 @@ public class GameScene extends PixelScene { private AttackIndicator attack; private LootIndicator loot; + private ActionIndicator action; private ResumeIndicator resume; @Override @@ -265,6 +267,10 @@ public class GameScene extends PixelScene { loot.camera = uiCamera; add( loot ); + action = new ActionIndicator(); + action.camera = uiCamera; + add( action ); + resume = new ResumeIndicator(); resume.camera = uiCamera; add( resume ); @@ -408,25 +414,31 @@ public class GameScene extends PixelScene { log.newLine(); } - if (tagAttack != attack.active || tagLoot != loot.visible || tagResume != resume.visible) { + if (tagAttack != attack.active || + tagLoot != loot.visible || + tagAction != action.visible || + tagResume != resume.visible) { - boolean atkAppearing = attack.active && !tagAttack; - boolean lootAppearing = loot.visible && !tagLoot; - boolean resAppearing = resume.visible && !tagResume; + //we only want to change the layout when new tags pop in, not when existing ones leave. + boolean tagAppearing = (attack.active && !tagAttack) || + (loot.visible && !tagLoot) || + (action.visible && !tagAction) || + (resume.visible && !tagResume); tagAttack = attack.active; tagLoot = loot.visible; + tagAction = action.visible; tagResume = resume.visible; - if (atkAppearing || lootAppearing || resAppearing) - layoutTags(); + if (tagAppearing) layoutTags(); } cellSelector.enable(Dungeon.hero.ready); } private boolean tagAttack = false; - private boolean tagLoot = false; + private boolean tagLoot = false; + private boolean tagAction = false; private boolean tagResume = false; public static void layoutTags() { @@ -455,6 +467,12 @@ public class GameScene extends PixelScene { pos = scene.loot.top(); } + if (scene.tagAction) { + scene.action.setPos( tagLeft, pos - scene.action.height() ); + scene.action.flip(tagLeft == 0); + pos = scene.action.top(); + } + if (scene.tagResume) { scene.resume.setPos( tagLeft, pos - scene.resume.height() ); scene.resume.flip(tagLeft == 0); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java new file mode 100644 index 000000000..59dd322b5 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java @@ -0,0 +1,88 @@ +package com.shatteredpixel.shatteredpixeldungeon.ui; + +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.watabou.noosa.Image; + +public class ActionIndicator extends Tag { + + Image icon; + + public static Action action; + public static ActionIndicator instance; + + public ActionIndicator() { + super( 0xFFFF4C ); + + instance = this; + + setSize( 24, 24 ); + visible = false; + } + + @Override + protected void layout() { + super.layout(); + + if (icon != null){ + icon.x = x + (width - icon.width()) / 2; + icon.y = y + (height - icon.height()) / 2; + PixelScene.align(icon); + } + } + + @Override + public void update() { + super.update(); + + if (!Dungeon.hero.ready){ + if (icon != null) icon.alpha(0.5f); + } else { + if (icon != null) icon.alpha(1f); + } + + if (!visible && action != null){ + visible = true; + flash(); + } else { + visible = action != null; + } + } + + @Override + protected void onClick() { + if (action != null && Dungeon.hero.ready) + action.doAction(); + } + + public static void setAction(Action action){ + ActionIndicator.action = action; + updateIcon(); + } + + public static void clearAction(){ + action = null; + } + + public static void updateIcon(){ + if (instance != null){ + if (instance.icon != null){ + instance.icon.killAndErase(); + instance.icon = null; + } + if (action != null){ + instance.icon = action.getIcon(); + instance.layout(); + } + } + } + + public interface Action{ + + public Image getIcon(); + + public void doAction(); + + } + +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java index b6b2732c9..a748c7217 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java @@ -36,7 +36,7 @@ public class AttackIndicator extends Tag { private static final float ENABLED = 1.0f; private static final float DISABLED = 0.3f; - private static float delay = 0.75f; + private static float delay; private static AttackIndicator instance; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Tag.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Tag.java index 5186cf755..ba469558c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Tag.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Tag.java @@ -20,10 +20,10 @@ */ package com.shatteredpixel.shatteredpixeldungeon.ui; +import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.watabou.noosa.Game; import com.watabou.noosa.NinePatch; import com.watabou.noosa.ui.Button; -import com.shatteredpixel.shatteredpixeldungeon.Chrome; public class Tag extends Button { @@ -48,6 +48,7 @@ public class Tag extends Button { super.createChildren(); bg = Chrome.get( Chrome.Type.TAG ); + bg.hardlight( r, g, b ); add( bg ); }