v0.3.5: added an action indicator for new functionality

This commit is contained in:
Evan Debenham 2016-04-16 17:24:06 -04:00
parent 1f40d6289c
commit 2ed6fc9857
4 changed files with 116 additions and 9 deletions

View File

@ -58,6 +58,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.PlantSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.PlantSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.Banner; import com.shatteredpixel.shatteredpixeldungeon.ui.Banner;
import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator;
@ -135,6 +136,7 @@ public class GameScene extends PixelScene {
private AttackIndicator attack; private AttackIndicator attack;
private LootIndicator loot; private LootIndicator loot;
private ActionIndicator action;
private ResumeIndicator resume; private ResumeIndicator resume;
@Override @Override
@ -265,6 +267,10 @@ public class GameScene extends PixelScene {
loot.camera = uiCamera; loot.camera = uiCamera;
add( loot ); add( loot );
action = new ActionIndicator();
action.camera = uiCamera;
add( action );
resume = new ResumeIndicator(); resume = new ResumeIndicator();
resume.camera = uiCamera; resume.camera = uiCamera;
add( resume ); add( resume );
@ -408,18 +414,23 @@ public class GameScene extends PixelScene {
log.newLine(); 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; //we only want to change the layout when new tags pop in, not when existing ones leave.
boolean lootAppearing = loot.visible && !tagLoot; boolean tagAppearing = (attack.active && !tagAttack) ||
boolean resAppearing = resume.visible && !tagResume; (loot.visible && !tagLoot) ||
(action.visible && !tagAction) ||
(resume.visible && !tagResume);
tagAttack = attack.active; tagAttack = attack.active;
tagLoot = loot.visible; tagLoot = loot.visible;
tagAction = action.visible;
tagResume = resume.visible; tagResume = resume.visible;
if (atkAppearing || lootAppearing || resAppearing) if (tagAppearing) layoutTags();
layoutTags();
} }
cellSelector.enable(Dungeon.hero.ready); cellSelector.enable(Dungeon.hero.ready);
@ -427,6 +438,7 @@ public class GameScene extends PixelScene {
private boolean tagAttack = false; private boolean tagAttack = false;
private boolean tagLoot = false; private boolean tagLoot = false;
private boolean tagAction = false;
private boolean tagResume = false; private boolean tagResume = false;
public static void layoutTags() { public static void layoutTags() {
@ -455,6 +467,12 @@ public class GameScene extends PixelScene {
pos = scene.loot.top(); 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) { if (scene.tagResume) {
scene.resume.setPos( tagLeft, pos - scene.resume.height() ); scene.resume.setPos( tagLeft, pos - scene.resume.height() );
scene.resume.flip(tagLeft == 0); scene.resume.flip(tagLeft == 0);

View File

@ -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();
}
}

View File

@ -36,7 +36,7 @@ public class AttackIndicator extends Tag {
private static final float ENABLED = 1.0f; private static final float ENABLED = 1.0f;
private static final float DISABLED = 0.3f; private static final float DISABLED = 0.3f;
private static float delay = 0.75f; private static float delay;
private static AttackIndicator instance; private static AttackIndicator instance;

View File

@ -20,10 +20,10 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.ui; package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
public class Tag extends Button { public class Tag extends Button {
@ -48,6 +48,7 @@ public class Tag extends Button {
super.createChildren(); super.createChildren();
bg = Chrome.get( Chrome.Type.TAG ); bg = Chrome.get( Chrome.Type.TAG );
bg.hardlight( r, g, b );
add( bg ); add( bg );
} }