Commit 58be33a6 authored by Matyáš Latner's avatar Matyáš Latner

#83 Oprava AIOFB pro střední obtížnost hry "Potmě"

parent 1e7006f3
......@@ -19,7 +19,6 @@
package cz.nic.tablexia.game.games.potme.action.widget;
import java.util.ArrayList;
import java.util.List;
import org.andengine.entity.Entity;
......@@ -38,6 +37,7 @@ import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.IModifier;
import android.os.Handler;
import android.util.SparseArray;
import cz.nic.tablexia.game.common.EntityModifierListenerAdapter;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
......@@ -106,7 +106,7 @@ public class ActionsWidget extends Entity implements ActionListener {
private static final float START_ARROW_HEIGHT = PotmeActivity.TILE_SIZE;
private ActionsStripWidget actionsStripWidget;
private List<Action> actions;
private SparseArray<Action> actions;
private VertexBufferObjectManager vertexBufferObjectManager;
private final Scene scene;
private Rectangle dimmer;
......@@ -130,7 +130,7 @@ public class ActionsWidget extends Entity implements ActionListener {
this.scene = scene;
this.actionsStripWidget = actionsStripWidget;
this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actions = new ArrayList<Action>();
this.actions = new SparseArray<Action>();
currentStepNumber = 0;
......@@ -159,8 +159,9 @@ public class ActionsWidget extends Entity implements ActionListener {
dimmer.setVisible(false);
ActionLayer.attachLayersToEntity(this);
for (ActionType actionType : actionTypes) {
createAction(actionType, actionType.ordinal(), false, scene);
for (int i = 0; i < actionTypes.size(); i++) {
ActionType actionType = actionTypes.get(i);
createAction(actionType, i, actionType.ordinal(), false, scene);
}
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(dimmer);
ActionLayer.BACKGROUND_LAYER.getLayerEntity().attachChild(actionsBackground);
......@@ -171,19 +172,19 @@ public class ActionsWidget extends Entity implements ActionListener {
this.startButton = startButton;
}
private Action createAction(ActionType actionType, int orderNumber, boolean visible, Scene scene) {
private Action createAction(ActionType actionType, int position, int orderNumber, boolean visible, Scene scene) {
Action action = new Action(actionType,
orderNumber,
PotmeActivity.ACTION_SIZE_SMALLER,
2 * ACTION_OFFSET + PotmeActivity.ACTION_SIZE_SMALLER / 2 + (orderNumber % NUMBER_OF_COLUMNS) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET),
- 2 * ACTION_OFFSET - (((int) (orderNumber / NUMBER_OF_COLUMNS)) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET)),
2 * ACTION_OFFSET + PotmeActivity.ACTION_SIZE_SMALLER / 2 + (position % NUMBER_OF_COLUMNS) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET),
- 2 * ACTION_OFFSET - (((int) (position / NUMBER_OF_COLUMNS)) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET)),
visible,
vertexBufferObjectManager);
action.addActionListener(this);
action.setClickable(scene);
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(action);
actions.add(action.getOrderNumber(), action);
actions.put(action.getOrderNumber(), action);
return action;
}
......@@ -199,7 +200,8 @@ public class ActionsWidget extends Entity implements ActionListener {
public void showActions() {
int actualDelay = 0;
for (final Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
final Action action = actions.get(actions.keyAt(i));
(new Handler()).postDelayed(new Runnable() {
@Override
......@@ -226,14 +228,16 @@ public class ActionsWidget extends Entity implements ActionListener {
public void enableActions() {
if (potmeDifficulty != PotmeDifficulty.TUTORIAL) {
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.enable();
}
}
}
public void disableActions() {
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.disable();
}
}
......@@ -244,8 +248,7 @@ public class ActionsWidget extends Entity implements ActionListener {
@Override
public void onActionDrag(Action lastAction) {
PotmeActivity.GameLayer.ACTIONS_LAYER.sendToFront(scene);
actions.remove(lastAction);
Action action = createAction(lastAction.getActionType(), lastAction.getOrderNumber(), false, scene);
Action action = createAction(lastAction.getActionType(), actions.indexOfKey(lastAction.getOrderNumber()), lastAction.getOrderNumber(), false, scene);
action.showWithAnimation();
prepareActionsCollisionEntity(action);
disableActions();
......@@ -284,7 +287,8 @@ public class ActionsWidget extends Entity implements ActionListener {
private void tryDimmAllActions() {
if (potmeDifficulty == PotmeDifficulty.TUTORIAL) {
dimmer.setVisible(true);
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.setZIndex(action.getOrderNumber());
action.disable();
}
......
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