Commit aa80ade5 authored by Luboš Horáček's avatar Luboš Horáček

Merge branch 'devel' of gitlab.labs.nic.cz:labs/tablexia into devel

parents 87e73080 0d1a9a67
obb/potme/gfx/info/start_arrow.png

37.3 KB | W: | H:

obb/potme/gfx/info/start_arrow.png

36.5 KB | W: | H:

obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<string name="game_potme_loading_text_2">Přetahuj správné úkony do pásu vpravo a dávej pozor na všechny překážky. Teprve až budeš mít naplánovanou celou trasu, stiskni tlačítko HOTOVO.</string> <string name="game_potme_loading_text_2">Přetahuj správné úkony do pásu vpravo a dávej pozor na všechny překážky. Teprve až budeš mít naplánovanou celou trasu, stiskni tlačítko HOTOVO.</string>
<string name="game_potme_start">HOTOVO</string> <string name="game_potme_start">HOTOVO</string>
<string name="game_potme_floor">Patro</string> <string name="game_potme_floor">Patro</string>
<string name="game_potme_victory_tutorial">Gratuluji! A teď to zkus sám&#8230;</string>
<string name="game_potme_victory_0">Au au, tolik chyb! To muselo bolet.</string> <string name="game_potme_victory_0">Au au, tolik chyb! To muselo bolet.</string>
<string name="game_potme_victory_1">Krůček za krůčkem. To chce klid, soustředit se a úspěchy se brzy dostaví.</string> <string name="game_potme_victory_1">Krůček za krůčkem. To chce klid, soustředit se a úspěchy se brzy dostaví.</string>
<string name="game_potme_victory_2">Chybička se vždycky vloudí, ale dobrému detektivovi by se to stávat nemělo.</string> <string name="game_potme_victory_2">Chybička se vždycky vloudí, ale dobrému detektivovi by se to stávat nemělo.</string>
......
...@@ -116,6 +116,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -116,6 +116,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
protected boolean afterResume = false; protected boolean afterResume = false;
protected boolean paused = false; protected boolean paused = false;
private boolean playVictorySpeech = false; private boolean playVictorySpeech = false;
private boolean useGameManager = true;
private static final int STEPS_PER_SECOUND = 60; private static final int STEPS_PER_SECOUND = 60;
protected static final int VICTORY_SCREEN_STARS_COUNT = 3; protected static final int VICTORY_SCREEN_STARS_COUNT = 3;
...@@ -169,6 +170,10 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -169,6 +170,10 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
public boolean isGameActive(GamesDefinition gameDefinitionToCheck) { public boolean isGameActive(GamesDefinition gameDefinitionToCheck) {
return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED); return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED);
} }
protected void disableGameManagerForCurrentGame() {
useGameManager = false;
}
/* //////////////////////////////////////////// TABLEXIA LIFECYCLE */ /* //////////////////////////////////////////// TABLEXIA LIFECYCLE */
...@@ -220,6 +225,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -220,6 +225,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
scene.clearTouchAreas(); scene.clearTouchAreas();
clearScene(); clearScene();
useGameManager = true;
gameManager = null; gameManager = null;
} }
...@@ -252,7 +258,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -252,7 +258,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
*/ */
protected void initGame() { protected void initGame() {
getTablexiaContext().showScreenContent(null); getTablexiaContext().showScreenContent(null);
if (gameManager == null) { if (gameManager == null && useGameManager) {
gameManager = new GameManager(gamesDefinition, getTablexiaContext().getSelectedUser(), getDifficulty()); gameManager = new GameManager(gamesDefinition, getTablexiaContext().getSelectedUser(), getDifficulty());
} }
} }
...@@ -302,8 +308,11 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -302,8 +308,11 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
if (gameTrophy == null) { if (gameTrophy == null) {
gameTrophy = GameTrophy.createGameTrophyAndSave(userId, gameNumber); gameTrophy = GameTrophy.createGameTrophyAndSave(userId, gameNumber);
} }
List<TrophyEnum> trophies = gameTrophy.nextGameComplete(getDifficulty(), score); List<TrophyEnum> trophies = null;
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser)); if (score >= 0) {
trophies = gameTrophy.nextGameComplete(getDifficulty(), score);
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser));
}
showVictoryScreen(score, trophies); showVictoryScreen(score, trophies);
GameTrophy.logAllGameTrophysForUser(userId); GameTrophy.logAllGameTrophysForUser(userId);
} }
...@@ -906,7 +915,9 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -906,7 +915,9 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
@Override @Override
public void run() { public void run() {
if (playVictorySpeech == true) { if (playVictorySpeech == true) {
soundControl.playSound(getVictorySpeech()[score], false); if (score >= 0 && score < getVictorySpeech().length) {
soundControl.playSound(getVictorySpeech()[score], false);
}
} }
} }
...@@ -952,12 +963,13 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -952,12 +963,13 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param trophies game trophies * @param trophies game trophies
*/ */
private void showTrophies(List<TrophyEnum> trophies) { private void showTrophies(List<TrophyEnum> trophies) {
if (trophies != null) {
for (int i = 0; i < trophies.size(); i++) { for (int i = 0; i < trophies.size(); i++) {
if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) { if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) {
showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i)); showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i));
} }
} }
}
} }
/** /**
...@@ -1008,15 +1020,24 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -1008,15 +1020,24 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show in victory screen (number of stars) * @param score score to show in victory screen (number of stars)
*/ */
private void setVictoryScreenScore(int score) { private void setVictoryScreenScore(int score) {
if (score > 0) { if (score < 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY); victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.GONE);
} victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.GONE);
if (score > 1) { victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.GONE);
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY); } else {
} victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.VISIBLE);
if (score > 2) { victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.VISIBLE);
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY); victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.VISIBLE);
} if (score > 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY);
}
if (score > 1) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY);
}
if (score > 2) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY);
}
}
} }
/** /**
...@@ -1074,14 +1095,14 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -1074,14 +1095,14 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show on victory screen * @param score score to show on victory screen
*/ */
public void setVictoriousTextsAndProgress(int score) { public void setVictoriousTextsAndProgress(int score) {
TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message); TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message);
txtvVictory.setText(getVictoryText(score)); txtvVictory.setText(getVictoryText(score));
TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result); TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result);
tvStats.setText(getStatsText()); tvStats.setText(getStatsText());
resetVictoryScreenScore(); resetVictoryScreenScore();
setVictoryScreenScore(score); setVictoryScreenScore(score);
} }
/** /**
......
...@@ -3,8 +3,13 @@ package cz.nic.tablexia.game.games.potme; ...@@ -3,8 +3,13 @@ package cz.nic.tablexia.game.games.potme;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import android.util.Log;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.potme.action.ActionType; import cz.nic.tablexia.game.games.potme.action.ActionType;
import cz.nic.tablexia.game.games.potme.map.IMapProvider;
import cz.nic.tablexia.game.games.potme.map.MapGenerator;
import cz.nic.tablexia.game.games.potme.map.MapTutorial;
/** /**
* Game potme difficulty definition and mapping to game difficulty * Game potme difficulty definition and mapping to game difficulty
...@@ -14,18 +19,27 @@ import cz.nic.tablexia.game.games.potme.action.ActionType; ...@@ -14,18 +19,27 @@ import cz.nic.tablexia.game.games.potme.action.ActionType;
*/ */
public enum PotmeDifficulty { public enum PotmeDifficulty {
EASY (GameDifficulty.EASY, 1, Arrays.asList(new ActionType[]{})), TUTORIAL(null, false, MapTutorial.class, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, 1, Arrays.asList(new ActionType[]{ActionType.KEY})), EASY (GameDifficulty.EASY, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{})),
HARD (GameDifficulty.HARD, 2, Arrays.asList(new ActionType[]{ActionType.KEY})); MEDIUM (GameDifficulty.MEDIUM, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{ActionType.KEY})),
HARD (GameDifficulty.HARD, true, MapGenerator.class, 2, Arrays.asList(new ActionType[]{ActionType.KEY}));
private GameDifficulty gameDifficulty; private GameDifficulty gameDifficulty;
private int floorCount; private int floorCount;
private List<ActionType> difficultyActionTypes; private List<ActionType> difficultyActionTypes;
private Class<? extends IMapProvider> mapProviderClass;
private boolean hasResults;
private PotmeDifficulty(GameDifficulty gameDifficulty, int floorCount, List<ActionType> difficultyActionTypes) { private PotmeDifficulty(GameDifficulty gameDifficulty, boolean hasResults, Class<? extends IMapProvider> mapProviderClass, int floorCount, List<ActionType> difficultyActionTypes) {
this.gameDifficulty = gameDifficulty; this.gameDifficulty = gameDifficulty;
this.floorCount = floorCount; this.hasResults = hasResults;
this.difficultyActionTypes = difficultyActionTypes; this.mapProviderClass = mapProviderClass;
this.floorCount = floorCount;
this.difficultyActionTypes = difficultyActionTypes;
}
public boolean hasResults() {
return hasResults;
} }
public int getFloorCount() { public int getFloorCount() {
...@@ -36,7 +50,10 @@ public enum PotmeDifficulty { ...@@ -36,7 +50,10 @@ public enum PotmeDifficulty {
return difficultyActionTypes.contains(actionType); return difficultyActionTypes.contains(actionType);
} }
public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty) { public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty, boolean isFirstGame) {
if (isFirstGame) {
return TUTORIAL;
}
for (PotmeDifficulty potmeDifficulty : PotmeDifficulty.values()) { for (PotmeDifficulty potmeDifficulty : PotmeDifficulty.values()) {
if (potmeDifficulty.gameDifficulty == gameDifficulty) { if (potmeDifficulty.gameDifficulty == gameDifficulty) {
return potmeDifficulty; return potmeDifficulty;
...@@ -45,4 +62,13 @@ public enum PotmeDifficulty { ...@@ -45,4 +62,13 @@ public enum PotmeDifficulty {
return null; return null;
} }
public IMapProvider getMapProviderNewInstance(RandomAccess randomAccess) {
try {
return mapProviderClass.getConstructor(RandomAccess.class).newInstance(randomAccess);
} catch (Exception e) {
Log.e(PotmeDifficulty.class.getCanonicalName(), "Cannot create instance for IMapProvider class: " + mapProviderClass, e);
}
return null;
}
} }
...@@ -167,13 +167,16 @@ public class Action extends Sprite { ...@@ -167,13 +167,16 @@ public class Action extends Sprite {
/* //////////////////////////////////////////// ACTION STATE */ /* //////////////////////////////////////////// ACTION STATE */
public void setEnbaled(boolean enabled) {
clickable = enabled;
}
public void disable() { public void disable() {
clickable = false; setEnbaled(false);
} }
public void enable() { public void enable() {
clickable = true; setEnbaled(true);
} }
......
...@@ -38,9 +38,9 @@ import org.andengine.util.modifier.ease.EaseBackOut; ...@@ -38,9 +38,9 @@ import org.andengine.util.modifier.ease.EaseBackOut;
import org.andengine.util.modifier.ease.EaseLinear; import org.andengine.util.modifier.ease.EaseLinear;
import cz.nic.tablexia.game.games.potme.PotmeActivity; import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.ResourceManager; import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.UtilityAccess; import cz.nic.tablexia.game.games.potme.UtilityAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.action.Action; import cz.nic.tablexia.game.games.potme.action.Action;
import cz.nic.tablexia.game.games.potme.action.Action.ActionListener; import cz.nic.tablexia.game.games.potme.action.Action.ActionListener;
import cz.nic.tablexia.game.games.potme.action.ActionContainer; import cz.nic.tablexia.game.games.potme.action.ActionContainer;
...@@ -79,6 +79,8 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -79,6 +79,8 @@ public class ActionsStripWidget extends Entity implements ActionListener {
private MoveModifier nextActionFieldMoveModifier; private MoveModifier nextActionFieldMoveModifier;
private MoveModifier scrollPaneMoveModifier; private MoveModifier scrollPaneMoveModifier;
private int actionOffsetX; private int actionOffsetX;
private boolean startButtonControl;
private boolean enableActionSorting;
public ActionsStripWidget(int positionX, public ActionsStripWidget(int positionX,
int positionY, int positionY,
...@@ -95,6 +97,9 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -95,6 +97,9 @@ public class ActionsStripWidget extends Entity implements ActionListener {
this.vertexBufferObjectManager = vertexBufferObjectManager; this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actionOffsetX = width / 8; this.actionOffsetX = width / 8;
enableActionSorting = true;
startButtonControl = true;
actualSelectedActionPosition = NO_SELECTED_POSITION; actualSelectedActionPosition = NO_SELECTED_POSITION;
selectedActions = new ArrayList<ActionContainer>(); selectedActions = new ArrayList<ActionContainer>();
...@@ -130,6 +135,14 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -130,6 +135,14 @@ public class ActionsStripWidget extends Entity implements ActionListener {
return selectedActions.size() < MAXIMUM_ACTIONS_COUNT; return selectedActions.size() < MAXIMUM_ACTIONS_COUNT;
} }
public void enableStartButtonControl(boolean startButtonControl) {
this.startButtonControl = startButtonControl;
}
public void enableActionSorting(boolean enableActionSorting) {
this.enableActionSorting = enableActionSorting;
}
/* //////////////////////////////////////////// BACKGROUND AND SCROLLING */ /* //////////////////////////////////////////// BACKGROUND AND SCROLLING */
...@@ -382,7 +395,7 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -382,7 +395,7 @@ public class ActionsStripWidget extends Entity implements ActionListener {
} }
public void performCollisionWithNumberStart(int collisionNumber) { public void performCollisionWithNumberStart(int collisionNumber) {
if (isNotFull()) { if (isNotFull() && enableActionSorting) {
if (collisionNumber > 0 && collisionNumber < selectedActions.size()) { if (collisionNumber > 0 && collisionNumber < selectedActions.size()) {
moveNextActionTemporalyHalfUp(); moveNextActionTemporalyHalfUp();
moveActionsFromPositionHalfDown(collisionNumber); moveActionsFromPositionHalfDown(collisionNumber);
...@@ -421,10 +434,12 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -421,10 +434,12 @@ public class ActionsStripWidget extends Entity implements ActionListener {
} }
public void setStartButtonState() { public void setStartButtonState() {
if (selectedActions.size() > 0) { if (startButtonControl) {
enableStartButton(); if (selectedActions.size() > 0) {
} else { enableStartButton();
disableStartButton(); } else {
disableStartButton();
}
} }
} }
...@@ -458,7 +473,8 @@ public class ActionsStripWidget extends Entity implements ActionListener { ...@@ -458,7 +473,8 @@ public class ActionsStripWidget extends Entity implements ActionListener {
// add new action // add new action
ActionContainer actionContainer = createActionContainer(createAction(selectedActionType, selectedActionPosition)); ActionContainer actionContainer = createActionContainer(createAction(selectedActionType, selectedActionPosition));
if (selectedActionPosition > selectedActions.size()) { actionContainer.getAction().setEnbaled(enableActionSorting);
if (selectedActionPosition > selectedActions.size() || !enableActionSorting) {
selectedActions.add(actionContainer); selectedActions.add(actionContainer);
} else { } else {
selectedActions.add(selectedActionPosition, actionContainer); selectedActions.add(selectedActionPosition, actionContainer);
......
...@@ -23,13 +23,17 @@ import java.util.ArrayList; ...@@ -23,13 +23,17 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.andengine.entity.Entity; import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene; import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite; import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion; import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager; import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;
import android.os.Handler; import android.os.Handler;
import cz.nic.tablexia.game.games.potme.PotmeActivity; 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; import cz.nic.tablexia.game.games.potme.PotmeDifficulty;
import cz.nic.tablexia.game.games.potme.ResourceManager; import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.action.Action; import cz.nic.tablexia.game.games.potme.action.Action;
...@@ -43,28 +47,85 @@ import cz.nic.tablexia.game.games.potme.action.ActionType; ...@@ -43,28 +47,85 @@ import cz.nic.tablexia.game.games.potme.action.ActionType;
* *
*/ */
public class ActionsWidget extends Entity implements ActionListener { public class ActionsWidget extends Entity implements ActionListener {
public enum ActionLayer {
BACKGROUND_LAYER (0),
ACTIONS_LAYER (1),
INFO_LAYER (2);
private Entity layerEntity;
private int layerZIndex;
private ActionLayer(int layerZIndex) {
this.layerZIndex = layerZIndex;
}
private void setLayerEntity(Entity layerEntity) {
this.layerEntity = layerEntity;
}
public Entity getLayerEntity() {
return layerEntity;
}
public int getLayerZIndex() {
return layerZIndex;
}
public static void attachLayersToEntity(IEntity conteinerEntity) {
for (ActionLayer actionLayer : ActionLayer.values()) {
Entity entity = new Entity();
actionLayer.setLayerEntity(entity);
conteinerEntity.attachChild(entity);
entity.setZIndex(actionLayer.getLayerZIndex());
}
conteinerEntity.sortChildren();
}
}
private static final int TOP_Z_INDEX = ActionType.values().length + 1;
private static final float BACKGROUND_WIDTH_RATIO = 1.3f; private static final float BACKGROUND_WIDTH_RATIO = 1.3f;
private static final double BACKGROUND_Y_POSITION_RATIO = 0.9; private static final double BACKGROUND_Y_POSITION_RATIO = 0.9;
private static final int START_ANIMATION_DELAY = 200; private static final int START_ANIMATION_DELAY = 200;
private static final int NUMBER_OF_COLUMNS = 2; private static final int NUMBER_OF_COLUMNS = 2;
public static final int ACTION_OFFSET = PotmeActivity.ACTION_SIZE_SMALLER / 10; public static final int ACTION_OFFSET = PotmeActivity.ACTION_SIZE_SMALLER / 10;
private static final float DIMMER_ALPHA = 0.5f;
private static final Color DIMMER_COLOR = Color.BLACK;
private static final float START_ARROW_WIDTH = PotmeActivity.TILE_SIZE * 1.2f;
private static final float START_ARROW_HEIGHT = PotmeActivity.TILE_SIZE;
private ActionsStripWidget actionsStripWidget; private ActionsStripWidget actionsStripWidget;
private List<Action> actions; private List<Action> actions;
private VertexBufferObjectManager vertexBufferObjectManager; private VertexBufferObjectManager vertexBufferObjectManager;
private final Scene scene; private final Scene scene;
private Rectangle dimmer;
private PotmeDifficulty potmeDifficulty;
private int currentStepNumber;
private StartButton startButton;
public ActionsWidget(float positionX, float positionY, PotmeDifficulty potmeDifficulty, Scene scene, ActionsStripWidget actionsStripWidget, VertexBufferObjectManager vertexBufferObjectManager) { public ActionsWidget(float positionX,
float positionY,
float displaySizeX,
float displaySizeY,
PotmeDifficulty potmeDifficulty,
Scene scene,
ActionsStripWidget actionsStripWidget,
float actionStripWidgetWidth,
VertexBufferObjectManager vertexBufferObjectManager) {
super(positionX, positionY); super(positionX, positionY);
this.potmeDifficulty = potmeDifficulty;
this.scene = scene; this.scene = scene;
this.actionsStripWidget = actionsStripWidget; this.actionsStripWidget = actionsStripWidget;
this.vertexBufferObjectManager = vertexBufferObjectManager; this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actions = new ArrayList<Action>(); this.actions = new ArrayList<Action>();
currentStepNumber = 0;
List<ActionType> actionTypes = ActionType.getActionTypesForGameDifficulty(potmeDifficulty); List<ActionType> actionTypes = ActionType.getActionTypesForGameDifficulty(potmeDifficulty);
// BACKGROUND
ITextureRegion backgroundTexture = ResourceManager.getInstance().getTexture(ResourceManager.BACKGROUND_ACTIONS_TEXTURE); ITextureRegion backgroundTexture = ResourceManager.getInstance().getTexture(ResourceManager.BACKGROUND_ACTIONS_TEXTURE);
int backgroundWidth = (int)((NUMBER_OF_COLUMNS * PotmeActivity.ACTION_SIZE_SMALLER) * BACKGROUND_WIDTH_RATIO); int backgroundWidth = (int)((NUMBER_OF_COLUMNS * PotmeActivity.ACTION_SIZE_SMALLER) * BACKGROUND_WIDTH_RATIO);
int backgroundHeight = (int)(backgroundWidth * (backgroundTexture.getHeight() / backgroundTexture.getWidth())); int backgroundHeight = (int)(backgroundWidth * (backgroundTexture.getHeight() / backgroundTexture.getWidth()));
...@@ -73,11 +134,31 @@ public class ActionsWidget extends Entity implements ActionListener { ...@@ -73,11 +134,31 @@ public class ActionsWidget extends Entity implements ActionListener {
backgroundWidth, backgroundWidth,
backgroundHeight, backgroundHeight,
backgroundTexture, vertexBufferObjectManager); backgroundTexture, vertexBufferObjectManager);
attachChild(actionsBackground);
for (int i = 0; i < actionTypes.size(); i++) {
createAction(actionTypes.get(i), i, false, scene); // DIMMER
float actionStripWidgetOffset = (actionStripWidgetWidth / 2) * 0.95f;
dimmer = new Rectangle(-positionX + (displaySizeX / 2) - actionStripWidgetOffset,
-positionY + (displaySizeY / 2),
displaySizeX - actionStripWidgetOffset,
displaySizeY,
vertexBufferObjectManager);
dimmer.setColor(DIMMER_COLOR);
dimmer.setAlpha(DIMMER_ALPHA);
dimmer.setVisible(false);
ActionLayer.attachLayersToEntity(this);
for (ActionType actionType : actionTypes) {
createAction(actionType, actionType.ordinal(), false, scene);
} }
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(dimmer);
ActionLayer.BACKGROUND_LAYER.getLayerEntity().attachChild(actionsBackground);
tryToPerformNextTutorialStep();
}
public void setStartButton(StartButton startButton) {
this.startButton = startButton;
} }
private Action createAction(ActionType actionType, int orderNumber, boolean visible, Scene scene) { private Action createAction(ActionType actionType, int orderNumber, boolean visible, Scene scene) {
...@@ -91,11 +172,12 @@ public class ActionsWidget extends Entity implements ActionListener { ...@@ -91,11 +172,12 @@ public class ActionsWidget extends Entity implements ActionListener {
action.addActionListener(this); action.addActionListener(this);
action.setClickable(scene); action.setClickable(scene);
attachChild(action); ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(action);
actions.add(action); actions.add(action.getOrderNumber(), action);
return action; return action;
} }
/* //////////////////////////////////////////// COLLISIONS */ /* //////////////////////////////////////////// COLLISIONS */
private void prepareActionsCollisionEntity(Action action) { private void prepareActionsCollisionEntity(Action action) {
...@@ -125,8 +207,10 @@ public class ActionsWidget extends Entity implements ActionListener { ...@@ -125,8 +207,10 @@ public class ActionsWidget extends Entity implements ActionListener {
/* //////////////////////////////////////////// ACTION STATE */ /* //////////////////////////////////////////// ACTION STATE */
public void enableActions() { public void enableActions() {
for (Action action : actions) { if (potmeDifficulty != PotmeDifficulty.TUTORIAL) {
action.enable(); for (Action action : actions) {
action.enable();
}
} }
} }
...@@ -147,14 +231,73 @@ public class ActionsWidget extends Entity implements ActionListener { ...@@ -147,14 +231,73 @@ public class ActionsWidget extends Entity implements ActionListener {
action.showWithAnimation(); action.showWithAnimation();
prepareActionsCollisionEntity(action); prepareActionsCollisionEntity(action);
disableActions(); disableActions();
hideArrowSprite();
} }
@Override @Override
public void onActionDrop(Action action, int collidesWithNumber) { public void onActionDrop(Action action, int collidesWithNumber) {
PotmeActivity.GameLayer.resetLayersZIndexes(scene); PotmeActivity.GameLayer.resetLayersZIndexes(scene);
enableActions();
if (collidesWithNumber != Action.NO_COLLISION_NUMBER) { if (collidesWithNumber != Action.NO_COLLISION_NUMBER) {
actionsStripWidget.addSelectedAction(action.getActionType(), collidesWithNumber); actionsStripWidget.addSelectedAction(action.getActionType(), collidesWithNumber);
currentStepNumber++;
} }
tryToPerformNextTutorialStep();
}
/* //////////////////////////////////////////// TUTORIAL STEPS */
private void tryToPerformNextTutorialStep() {
if (potmeDifficulty == PotmeDifficulty.TUTORIAL) {
if (currentStepNumber < PotmeActivity.TUTORIAL_STEPS.size()) {
highliteAction(PotmeActivity.TUTORIAL_STEPS.get(currentStepNumber));
if (startButton != null) {
startButton.disable();
}
} else {
PotmeActivity.GameLayer.BUTTON_LAYER.sendToFront(scene);
if (startButton != null) {