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