Commit 40914262 authored by Matyáš Latner's avatar Matyáš Latner

#83 Plynulé zobrazení šipek nápovědy a blikající tlačítko start

parent aa80ade5
......@@ -33,7 +33,9 @@ import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.entity.modifier.DelayModifier;
import org.andengine.entity.modifier.LoopEntityModifier;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
......@@ -213,6 +215,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private boolean enabled = true;
private Entity backgroundLayer;
private Entity blinkerLayer;
private Entity textLayer;
private Rectangle touchArea;
......@@ -221,6 +224,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private Sprite unpressedButtonSprite;
private Sprite disabledButtonSprite;
private Sprite blinkerButtonSprite;
private Text buttonText;
private float textUnpressedPositionX;
......@@ -228,17 +232,25 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private float textPressedPositionX;
private float textPressedPositionY;
private LoopEntityModifier blinkerModifier;
public StartButton(VertexBufferObjectManager vertexBufferObject) {
// layers
backgroundLayer = new Entity();
blinkerLayer = new Entity();
textLayer = new Entity();
attachChild(backgroundLayer);
attachChild(blinkerLayer);
attachChild(textLayer);
// backgrounds
unpressedButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_UNPRESSED), vertexBufferObject);
disabledButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_DISABLED), vertexBufferObject);
blinkerButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_BLINKER), vertexBufferObject);
disablePulsing();
blinkerLayer.attachChild(blinkerButtonSprite);
// touch area
touchArea = new Rectangle(0, 0, unpressedButtonSprite.getWidth(), unpressedButtonSprite.getHeight(), vertexBufferObject) {
......@@ -273,11 +285,31 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
}
public void disable() {
disablePulsing();
enabled = false;
changeActualButtonSprite(disabledButtonSprite);
buttonText.setPosition(textPressedPositionX, textPressedPositionY);
}
public void enablePulsing() {
AlphaModifier fadeIn = new AlphaModifier(1f, 0f, 1f);
fadeIn.setAutoUnregisterWhenFinished(true);
AlphaModifier fadeOut = new AlphaModifier(1f, 1f, 0f);
fadeOut.setAutoUnregisterWhenFinished(true);
SequenceEntityModifier sequenceModifier = new SequenceEntityModifier(fadeOut, fadeIn);
sequenceModifier.setAutoUnregisterWhenFinished(true);
blinkerModifier = new LoopEntityModifier(sequenceModifier);
blinkerButtonSprite.registerEntityModifier(blinkerModifier);
}
public void disablePulsing() {
if (blinkerModifier != null) {
blinkerButtonSprite.unregisterEntityModifier(blinkerModifier);
blinkerModifier = null;
}
blinkerButtonSprite.setAlpha(0);
}
public boolean isEnbleda() {
return enabled;
}
......
......@@ -84,6 +84,7 @@ public class ResourceManager {
public static final String CONTROL_NEXT = ASSET_CONTROL + "next.png";
public static final String CONTROL_START_UNPRESSED = ASSET_CONTROL + "start_button_unpressed.png";
public static final String CONTROL_START_DISABLED = ASSET_CONTROL + "start_button_disabled.png";
public static final String CONTROL_START_BLINKER = ASSET_CONTROL + "start_button_blinker.png";
public static final String CONTROL_ACTUAL = ASSET_CONTROL + "actual.png";
public static final String CONTROL_KEY = ASSET_CONTROL + "key_icon.png";
......@@ -205,6 +206,7 @@ public class ResourceManager {
loadTexture(engine, context, CONTROL_NEXT);
loadTexture(engine, context, CONTROL_START_UNPRESSED);
loadTexture(engine, context, CONTROL_START_DISABLED);
loadTexture(engine, context, CONTROL_START_BLINKER);
loadTexture(engine, context, CONTROL_ACTUAL);
loadTexture(engine, context, CONTROL_KEY);
......
......@@ -24,14 +24,18 @@ import java.util.List;
import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.DelayModifier;
import org.andengine.entity.modifier.FadeInModifier;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.IModifier;
import android.os.Handler;
import cz.nic.tablexia.game.common.EntityModifierListenerAdapter;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.PotmeDifficulty;
......@@ -83,6 +87,7 @@ public class ActionsWidget extends Entity implements ActionListener {
}
}
private static final float TUTORIAL_INFO_ARROW_FADEIN_DELAY = 0.5f;
private static final int TOP_Z_INDEX = ActionType.values().length + 1;
private static final float BACKGROUND_WIDTH_RATIO = 1.3f;
private static final double BACKGROUND_Y_POSITION_RATIO = 0.9;
......@@ -153,8 +158,7 @@ public class ActionsWidget extends Entity implements ActionListener {
}
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(dimmer);
ActionLayer.BACKGROUND_LAYER.getLayerEntity().attachChild(actionsBackground);
tryToPerformNextTutorialStep();
tryDimmAllActions();
}
public void setStartButton(StartButton startButton) {
......@@ -201,6 +205,14 @@ public class ActionsWidget extends Entity implements ActionListener {
}, actualDelay);
actualDelay = actualDelay + START_ANIMATION_DELAY;
}
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
tryToPerformNextTutorialStep();
}
}, actualDelay + START_ANIMATION_DELAY);
}
......@@ -258,6 +270,7 @@ public class ActionsWidget extends Entity implements ActionListener {
PotmeActivity.GameLayer.BUTTON_LAYER.sendToFront(scene);
if (startButton != null) {
startButton.enable();
startButton.enablePulsing();
}
}
} else {
......@@ -265,7 +278,8 @@ public class ActionsWidget extends Entity implements ActionListener {
}
}
private void dimmAllActions() {
private void tryDimmAllActions() {
if (potmeDifficulty == PotmeDifficulty.TUTORIAL) {
dimmer.setVisible(true);
for (Action action : actions) {
action.setZIndex(action.getOrderNumber());
......@@ -274,10 +288,11 @@ public class ActionsWidget extends Entity implements ActionListener {
dimmer.setZIndex(actions.size());
ActionLayer.ACTIONS_LAYER.getLayerEntity().sortChildren();
}
}
private void highliteAction(ActionType actionType) {
if (actionType.ordinal() < actions.size()) {
dimmAllActions();
tryDimmAllActions();
Action action = actions.get(actionType.ordinal());
action.setZIndex(TOP_Z_INDEX);
action.enable();
......@@ -288,13 +303,28 @@ public class ActionsWidget extends Entity implements ActionListener {
private void showArrowSprite(float positionX, float positionY, VertexBufferObjectManager vertexBufferObjectManager) {
hideArrowSprite();
Sprite infoArrowSprite = new Sprite(positionX + (PotmeActivity.ACTION_SIZE_SMALLER * 1.2f),
final Sprite infoArrowSprite = new Sprite(positionX + (PotmeActivity.ACTION_SIZE_SMALLER * 1.2f),
positionY - (PotmeActivity.ACTION_SIZE_SMALLER / 2),
START_ARROW_WIDTH,
START_ARROW_HEIGHT,
ResourceManager.getInstance().getTexture(ResourceManager.INFO_START_ARROW),
vertexBufferObjectManager);
infoArrowSprite.setAlpha(0);
ActionLayer.INFO_LAYER.getLayerEntity().attachChild(infoArrowSprite);
DelayModifier delayModifier = new DelayModifier(TUTORIAL_INFO_ARROW_FADEIN_DELAY);
delayModifier.setAutoUnregisterWhenFinished(true);
delayModifier.addModifierListener(new EntityModifierListenerAdapter() {
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
FadeInModifier fadeInModifier = new FadeInModifier(TUTORIAL_INFO_ARROW_FADEIN_DELAY);
fadeInModifier.setAutoUnregisterWhenFinished(true);
infoArrowSprite.registerEntityModifier(fadeInModifier);
}
});
infoArrowSprite.registerEntityModifier(delayModifier);
}
private void hideArrowSprite() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment