Skip to content
Snippets Groups Projects
Commit af20fab2 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

Merge branch 'feature-loadingscreen' into 'V3.2.1'

Feature loadingscreen



See merge request !375
parents c7f5f86e 1dee8b92
No related branches found
No related tags found
No related merge requests found
package cz.nic.tablexia; package cz.nic.tablexia;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
...@@ -522,4 +523,11 @@ public class TablexiaSettings { ...@@ -522,4 +523,11 @@ public class TablexiaSettings {
public static float getActorSceneVerticalCenter(Stage stage, Actor actor) { public static float getActorSceneVerticalCenter(Stage stage, Actor actor) {
return getViewportHeight(stage) / 2f - actor.getHeight() / 2f + getViewportBottomY(stage); return getViewportHeight(stage) / 2f - actor.getHeight() / 2f + getViewportBottomY(stage);
} }
//////////////////////////// DEVICE INFO
public boolean isRunningOnMobileDevice() {
return Gdx.app.getType() == Application.ApplicationType.Android ||
Gdx.app.getType() == Application.ApplicationType.iOS;
}
} }
\ No newline at end of file
...@@ -3,14 +3,11 @@ package cz.nic.tablexia.game.games.pursuit; ...@@ -3,14 +3,11 @@ package cz.nic.tablexia.game.games.pursuit;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.CatmullRomSpline;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Action; import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
...@@ -31,11 +28,11 @@ import cz.nic.tablexia.game.GameDefinition; ...@@ -31,11 +28,11 @@ import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.pursuit.action.RotateAndMovePieceInPosition; import cz.nic.tablexia.game.games.pursuit.action.RotateAndMovePieceInPosition;
import cz.nic.tablexia.game.games.pursuit.action.RotatePieceToClosestAngle; import cz.nic.tablexia.game.games.pursuit.action.RotatePieceToClosestAngle;
import cz.nic.tablexia.game.games.pursuit.action.VehicleMoveAction;
import cz.nic.tablexia.game.games.pursuit.assets.PursuitAssets; import cz.nic.tablexia.game.games.pursuit.assets.PursuitAssets;
import cz.nic.tablexia.game.games.pursuit.helper.ArithmeticsHelper; import cz.nic.tablexia.game.games.pursuit.helper.ArithmeticsHelper;
import cz.nic.tablexia.game.games.pursuit.helper.GameRulesHelper; import cz.nic.tablexia.game.games.pursuit.helper.GameRulesHelper;
import cz.nic.tablexia.game.games.pursuit.helper.TextureHelper; import cz.nic.tablexia.game.games.pursuit.helper.TextureHelper;
import cz.nic.tablexia.game.games.pursuit.listener.VehicleDragListener;
import cz.nic.tablexia.game.games.pursuit.model.Grid; import cz.nic.tablexia.game.games.pursuit.model.Grid;
import cz.nic.tablexia.game.games.pursuit.model.Maps; import cz.nic.tablexia.game.games.pursuit.model.Maps;
import cz.nic.tablexia.game.games.pursuit.model.PuzzlePiece; import cz.nic.tablexia.game.games.pursuit.model.PuzzlePiece;
...@@ -122,9 +119,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -122,9 +119,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
private static final String SCORE_KEY_LAST_MAP = "last_map_index"; private static final String SCORE_KEY_LAST_MAP = "last_map_index";
private static final float OVERLAP_PIECE_SCALE = 1.2f; private static final float OVERLAP_PIECE_SCALE = 1.2f;
private static final float ANIMATION_MOVING_DURATION = 5f;
private static final float ANIMATION_DELAY_DURATION = 1.5f;
private static final int MAPS_COUNT = Maps.values().length; private static final int MAPS_COUNT = Maps.values().length;
...@@ -155,6 +149,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -155,6 +149,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
private String clickMapTextureName; private String clickMapTextureName;
private String mapTextureName; private String mapTextureName;
@Override @Override
protected Viewport createViewport() { protected Viewport createViewport() {
return new ExtendViewport(0, TablexiaSettings.getMinWorldHeight()); return new ExtendViewport(0, TablexiaSettings.getMinWorldHeight());
...@@ -359,6 +354,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -359,6 +354,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
private void checkEndGameCondition() { private void checkEndGameCondition() {
if (grid.allPiecesInCorrectPositions() && !gameFinished.get()) { if (grid.allPiecesInCorrectPositions() && !gameFinished.get()) {
backgroundImage.removeListener(dragAndRotateActorListener); backgroundImage.removeListener(dragAndRotateActorListener);
endGame();
showCheckpoints(); showCheckpoints();
gameFinished.set(true); gameFinished.set(true);
} }
...@@ -403,12 +399,26 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -403,12 +399,26 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
private void prepareVehicle() { private void prepareVehicle() {
VehicleType vehicleType = TextureHelper.getVehicleTextureName(getRandom(), mapNumber); VehicleType vehicleType = TextureHelper.getVehicleTextureName(getRandom(), mapNumber);
final Point vehiclePosition = new Point(0, 0); Point vehiclePosition = new Point(0, 0);
Point vehicleSize = new Point(vehicleType.getVehicleSize().x, vehicleType.getVehicleSize().y); Point vehicleSize = new Point(vehicleType.getVehicleSize().x, vehicleType.getVehicleSize().y);
Music[] vehicleSounds = getVehicleSounds(vehicleType);
vehicle = new Vehicle(getScreenTextureRegion(vehicleType.getTextureName()), vehiclePosition, vehicleSize); vehicle = new Vehicle(getScreenTextureRegion(vehicleType.getTextureName()), vehiclePosition, vehicleSize);
vehicle.addListener(new VehicleDragListener(vehicle, vehicleSounds, getData(), new Point(roadMap.getWidth(), roadMap.getHeight()), finishFlag, new VehicleDragListener.OnVehicleDragCompleteListener() {
@Override
public void onVehicleDragComplete() {
showGameResultDialog();
//remove all actor listeners
vehicle.clear();
vehicle.remove();
finishFlag.clear();
finishFlag.remove();
}
}));
vehicle.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes()); vehicle.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
grid.addActor(vehicle);
vehicle.setVisible(false); vehicle.setVisible(false);
grid.addActor(vehicle);
} }
private void prepareFinishFlag() { private void prepareFinishFlag() {
...@@ -416,8 +426,8 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -416,8 +426,8 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
finishFlag.setSize(TextureHelper.FINISH_FLAG_SIZE.x, TextureHelper.FINISH_FLAG_SIZE.y); finishFlag.setSize(TextureHelper.FINISH_FLAG_SIZE.x, TextureHelper.FINISH_FLAG_SIZE.y);
finishFlag.setOrigin(finishFlag.getWidth() / 2, finishFlag.getHeight() / 2); finishFlag.setOrigin(finishFlag.getWidth() / 2, finishFlag.getHeight() / 2);
finishFlag.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes()); finishFlag.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
finishFlag.setVisible(false);
grid.addActor(finishFlag); grid.addActor(finishFlag);
finishFlag.setVisible(false);
} }
...@@ -460,7 +470,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -460,7 +470,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
//sets the position according to completed map rotation //sets the position according to completed map rotation
private void showCheckpoints() { private void showCheckpoints() {
Point gridRotationCenter = new Point(grid.getWidth() / 2, grid.getHeight() / 2); Point gridRotationCenter = new Point(grid.getWidth() / 2, grid.getHeight() / 2);
Log.debug(getClass(),"grid rotation: " + grid.getRotation());
//flag //flag
Point flagPosition = TextureHelper.getFinishFlagPosition(grid.getWidth(), mapNumber); Point flagPosition = TextureHelper.getFinishFlagPosition(grid.getWidth(), mapNumber);
Point flagPositonConsideringMapRotation = ArithmeticsHelper.translatePositionAccordingToRotation(flagPosition, grid.getRotation(), gridRotationCenter); Point flagPositonConsideringMapRotation = ArithmeticsHelper.translatePositionAccordingToRotation(flagPosition, grid.getRotation(), gridRotationCenter);
...@@ -475,26 +484,8 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { ...@@ -475,26 +484,8 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
vehicle.setPosition(vehiclePositionConsideringRotation.x - vehicle.getWidth() / 2, vehiclePositionConsideringRotation.y - vehicle.getHeight() / 2); vehicle.setPosition(vehiclePositionConsideringRotation.x - vehicle.getWidth() / 2, vehiclePositionConsideringRotation.y - vehicle.getHeight() / 2);
vehicle.setRotation(grid.getRotation()); vehicle.setRotation(grid.getRotation());
vehicle.setVisible(true);
finishFlag.setVisible(true); finishFlag.setVisible(true);
final Music[] vehicleSounds = getVehicleSounds( TextureHelper.getVehicleTextureName(getRandom(), mapNumber));
final CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(Maps.values()[mapNumber].getPursuitPositionDefinition().getPointsWithRotation(grid.getRotation(), vehiclePosition.x,vehiclePosition.y),false);
VehicleMoveAction vehicleMoveAlongAction = new VehicleMoveAction(path, ANIMATION_MOVING_DURATION, grid.getWidth(), vehicleSounds);
vehicle.addAction(Actions.sequence(Actions.show(),Actions.delay(ANIMATION_DELAY_DURATION),vehicleMoveAlongAction,new RunnableAction() {
@Override
public void run() {
for(Music snd : vehicleSounds) {
snd.stop();
snd.dispose();
}
endGame();
showGameResultDialog();
vehicle.clear();
vehicle.remove();
finishFlag.clear();
finishFlag.remove();
}
}));
} }
@Override @Override
......
package cz.nic.tablexia.game.games.pursuit.action;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Path;
import com.badlogic.gdx.math.Vector2;
import cz.nic.tablexia.util.actions.MoveAlongAction;
/**
* Created by Vitaliy Vashchenko on 24.6.16.
*/
public class VehicleMoveAction extends MoveAlongAction {
private float parentSize;
private Path<Vector2> path;
private float duration;
private Music[] vehicleMusic;
private int soundIndex;
public VehicleMoveAction(Path<Vector2> path, float duration, float parentSize, Music[] vehicleMusic) {
super(path, duration);
setRotate(true);
this.path = path;
this.duration = duration;
this.parentSize = parentSize;
this.vehicleMusic = vehicleMusic;
soundIndex = MathUtils.random(0,vehicleMusic.length-1);
}
@Override
protected void update(float percent) {
Vector2 value = new Vector2();
path.valueAt(value, percent);
actor.setPosition(parentSize*value.x-actor.getWidth()/2,parentSize*value.y - actor.getHeight()/2);
actor.setRotation(path.derivativeAt(value, percent).angle() - 90);
}
@Override
protected void begin() {
vehicleMusic[soundIndex].setVolume(1);
vehicleMusic[soundIndex].setLooping(true);
vehicleMusic[soundIndex].play();
super.begin();
}
@Override
protected void end() {
vehicleMusic[soundIndex].stop();
super.end();
}
}
package cz.nic.tablexia.game.games.pursuit.helper;
import com.badlogic.gdx.math.Vector2;
import cz.nic.tablexia.util.Point;
/**
* Created by Vitaliy Vashchenko on 20.6.16.
*/
public class PositionHelper {
enum RotationDefinition {
ZERO(0f),
LEFT(90f),
UP(270f),
REVERSE(180f);
float rotation;
RotationDefinition(float rotation) {
this.rotation = rotation;
}
public static RotationDefinition getRotationDefinition(float rotation) {
for (RotationDefinition rotationDefinition : RotationDefinition.values()) {
if (rotationDefinition.getRotation() == rotation) return rotationDefinition;
}
return null;
}
public float getRotation() {
return rotation;
}
}
public enum PursuitPositionDefinition {
// TODO: 21.6.16 correct some positions
MAP_1(new Point(0.866f, 0.1f),new Point(0.866f, 0.1f), new Point(0.859f, 0.211f), new Point(0.824f, 0.276f), new Point(0.792f, 0.312f), new Point(0.719f, 0.268f), new Point(0.666f, 0.241f), new Point(0.608f, 0.221f), new Point(0.534f, 0.203f), new Point(0.448f, 0.194f), new Point(0.374f, 0.224f), new Point(0.328f, 0.286f), new Point(0.293f, 0.37f), new Point(0.265f, 0.469f), new Point(0.237f, 0.575f), new Point(0.215f, 0.671f), new Point(0.228f, 0.772f), new Point(0.258f, 0.846f), new Point(0.26f, 0.85f)),
MAP_2(new Point(0.64f, 0.11f),new Point(0.64f, 0.11f), new Point(0.68f, 0.214f), new Point(0.738f, 0.308f), new Point(0.777f, 0.395f), new Point(0.683f, 0.449f), new Point(0.613f, 0.509f), new Point(0.54f, 0.573f), new Point(0.473f, 0.658f), new Point(0.4f, 0.728f), new Point(0.322f, 0.711f), new Point(0.26f, 0.666f), new Point(0.208f, 0.757f), new Point(0.22f, 0.75f)),
MAP_3(new Point(0.08f, 0.41f),new Point(0.08f, 0.41f), new Point(0.182f, 0.461f), new Point(0.271f, 0.466f), new Point(0.368f, 0.475f), new Point(0.376f, 0.599f), new Point(0.387f, 0.698f), new Point(0.398f, 0.755f), new Point(0.361f, 0.824f), new Point(0.394f, 0.868f), new Point(0.461f, 0.877f), new Point(0.531f, 0.85f), new Point(0.627f, 0.897f), new Point(0.691f, 0.899f), new Point(0.77f, 0.903f), new Point(0.776f, 0.855f), new Point(0.758f, 0.811f), new Point(0.776f, 0.754f), new Point(0.79f, 0.71f)),
MAP_4(new Point(0.95f, 0.33f),new Point(0.95f, 0.33f), new Point(0.866f, 0.307f), new Point(0.766f, 0.342f), new Point(0.709f, 0.391f), new Point(0.588f, 0.452f), new Point(0.512f, 0.497f), new Point(0.425f, 0.588f), new Point(0.355f, 0.667f), new Point(0.278f, 0.595f), new Point(0.19f, 0.574f), new Point(0.18f, 0.57f)),
MAP_5(new Point(0.94f, 0.12f),new Point(0.94f, 0.12f), new Point(0.928f, 0.333f), new Point(0.784f, 0.373f), new Point(0.678f, 0.412f), new Point(0.645f, 0.525f), new Point(0.578f, 0.582f), new Point(0.549f, 0.649f), new Point(0.597f, 0.733f), new Point(0.68f, 0.77f), new Point(0.784f, 0.793f), new Point(0.863f, 0.843f), new Point(0.86f, 0.82f)),
MAP_6(new Point(0.95f, 0.17f),new Point(0.95f, 0.17f), new Point(0.85f, 0.18f), new Point(0.763f, 0.171f), new Point(0.68f, 0.136f), new Point(0.602f, 0.092f), new Point(0.538f, 0.036f), new Point(0.509f, 0.081f), new Point(0.438f, 0.077f), new Point(0.392f, 0.142f), new Point(0.369f, 0.199f), new Point(0.377f, 0.251f), new Point(0.436f, 0.306f), new Point(0.45f, 0.32f)),
MAP_7(new Point(0.56f, 0.07f),new Point(0.56f, 0.07f), new Point(0.43f, 0.16f), new Point(0.347f, 0.246f), new Point(0.373f, 0.36f), new Point(0.443f, 0.465f), new Point(0.499f, 0.58f), new Point(0.431f, 0.657f), new Point(0.379f, 0.738f), new Point(0.356f, 0.825f), new Point(0.36f, 0.83f)),
MAP_8(new Point(0.16f, 0.19f),new Point(0.16f, 0.19f), new Point(0.237f, 0.255f), new Point(0.287f, 0.316f), new Point(0.351f, 0.354f), new Point(0.285f, 0.44f), new Point(0.212f, 0.521f), new Point(0.134f, 0.597f), new Point(0.071f, 0.679f), new Point(0.118f, 0.718f), new Point(0.204f, 0.754f), new Point(0.272f, 0.733f), new Point(0.343f, 0.798f), new Point(0.425f, 0.856f), new Point(0.496f, 0.919f), new Point(0.596f, 0.853f), new Point(0.672f, 0.823f), new Point(0.759f, 0.82f), new Point(0.818f, 0.828f), new Point(0.825f, 0.801f), new Point(0.83f, 0.79f)),
MAP_9(new Point(0.15f, 0.11f),new Point(0.15f, 0.11f), new Point(0.193f, 0.179f), new Point(0.255f, 0.19f), new Point(0.164f, 0.426f), new Point(0.234f, 0.494f), new Point(0.307f, 0.661f), new Point(0.356f, 0.723f), new Point(0.435f, 0.776f), new Point(0.509f, 0.805f), new Point(0.622f, 0.831f), new Point(0.719f, 0.837f), new Point(0.808f, 0.834f), new Point(0.81f, 0.83f)),
MAP_10(new Point(0.22f, 0.07f),new Point(0.22f, 0.07f), new Point(0.214f, 0.293f), new Point(0.204f, 0.421f), new Point(0.449f, 0.422f), new Point(0.574f, 0.561f), new Point(0.678f, 0.49f), new Point(0.806f, 0.75f), new Point(0.761f, 0.838f), new Point(0.76f, 0.84f)),
MAP_11(new Point(0.61f, 0.11f),new Point(0.61f, 0.11f), new Point(0.582f, 0.258f), new Point(0.571f, 0.364f), new Point(0.599f, 0.442f), new Point(0.641f, 0.499f), new Point(0.646f, 0.584f), new Point(0.702f, 0.626f), new Point(0.81f, 0.644f), new Point(0.801f, 0.693f), new Point(0.678f, 0.683f), new Point(0.553f, 0.688f), new Point(0.366f, 0.697f), new Point(0.302f, 0.688f), new Point(0.214f, 0.697f), new Point(0.21f, 0.69f)),
MAP_12(new Point(0.89f, 0.17f),new Point(0.89f, 0.17f), new Point(0.806f, 0.118f), new Point(0.565f, 0.111f), new Point(0.43f, 0.102f), new Point(0.385f, 0.164f), new Point(0.436f, 0.294f), new Point(0.473f, 0.442f), new Point(0.492f, 0.562f), new Point(0.444f, 0.676f), new Point(0.385f, 0.792f), new Point(0.278f, 0.803f), new Point(0.223f, 0.843f), new Point(0.208f, 0.868f), new Point(0.2f, 0.85f)),
MAP_13(new Point(0.08f, 0.06f),new Point(0.08f, 0.06f), new Point(0.189f, 0.227f), new Point(0.414f, 0.316f), new Point(0.665f, 0.51f), new Point(0.797f, 0.632f), new Point(0.88f, 0.735f), new Point(0.88f, 0.73f)),
MAP_14(new Point(0.18f, 0.08f),new Point(0.18f, 0.08f), new Point(0.212f, 0.239f), new Point(0.29f, 0.321f), new Point(0.399f, 0.382f), new Point(0.342f, 0.503f), new Point(0.311f, 0.659f), new Point(0.308f, 0.773f), new Point(0.324f, 0.843f), new Point(0.32f, 0.84f));
private Point[] points;
PursuitPositionDefinition(Point... points) {
this.points = points;
}
public Point[] getPoints() {
return points;
}
public Vector2[] getPointsWithRotation(float rotation, float x, float y) {
RotationDefinition rotationDefinition = RotationDefinition.getRotationDefinition(rotation);
Vector2[] rotatedPositions = new Vector2[points.length];
for (int i = 0; i < getPoints().length; i++) {
rotatedPositions[i] = getRotatedPosition(rotationDefinition, getPoints()[i]);
}
return rotatedPositions;
}
private Vector2 getRotatedPosition(RotationDefinition rotationDefinition, Point position) {
switch (rotationDefinition) {
case UP:
//x = y, y = 1-x
return new Vector2(position.y, 1 - position.x);
case LEFT:
//x=1-y, y=x
return new Vector2(1 - position.y, position.x);
case REVERSE:
//x = 1-x,y=1-y
return new Vector2(1 - position.x, 1 - position.y);
default:
return new Vector2(position.x, position.y);
}
}
}
}
package cz.nic.tablexia.game.games.pursuit.listener;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import cz.nic.tablexia.game.games.pursuit.helper.ArithmeticsHelper;
import cz.nic.tablexia.util.MusicUtil;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.game.games.pursuit.model.Vehicle;
import cz.nic.tablexia.util.listener.DragActorListener;
/**
* Created by Václav Tarantík on 10.8.15.
*/
public class VehicleDragListener extends DragActorListener implements Music.OnCompletionListener{
private static final int POINTS_CACHE_SIZE = 5;
private Point[] touchedPointsCache;
private int currentTouchPointCacheElementPointer;
private int[][] roadColorData;
private Point roadMapSize;
private Actor goalActor;
private OnVehicleDragCompleteListener onVehicleDragCompleteListener;
private final float moveTolerance;
private Music[] sounds;
private boolean playingSounds = false;
private int currentSoundIndex = 0;
//goalActor is the actor that marks the finish of the vehicle path, here finish flag
public VehicleDragListener(Actor actor, Music[] sounds, int[][] roadColorData, Point roadMapSize, Actor goalActor, OnVehicleDragCompleteListener onVehicleDragCompleteListener) {
super(actor);
this.sounds = sounds;
this.roadColorData = roadColorData;
this.roadMapSize = roadMapSize;
this.goalActor = goalActor;
this.onVehicleDragCompleteListener = onVehicleDragCompleteListener;
touchedPointsCache = new Point[POINTS_CACHE_SIZE];
// vehicle move tolerance is two times size of bigger side of vehicle (width / height of actor)
moveTolerance = 2 * Math.max(actor.getWidth(), actor.getHeight());
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
touchedPointsCache[currentTouchPointCacheElementPointer] = new Point(x, y);
playingSounds = true;
sounds[currentSoundIndex].setVolume(1);
sounds[currentSoundIndex].play();
sounds[currentSoundIndex].setOnCompletionListener(this);
return super.touchDown(event, x, y, pointer, button);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
Vector2 recalculatedCoords = new Vector2(x, y);
actor.localToParentCoordinates(recalculatedCoords);
Point touchPoint = new Point(recalculatedCoords.x, recalculatedCoords.y);
if (isPointOnMap(touchPoint)) {
Color touchedColor = getTouchedColor(recalculatedCoords.x, recalculatedCoords.y);
if (touchedColor.r == 1 && touchedColor.a == 1) {
currentTouchPointCacheElementPointer = (currentTouchPointCacheElementPointer + 1) % touchedPointsCache.length;
touchedPointsCache[currentTouchPointCacheElementPointer] = new Point(recalculatedCoords.x, recalculatedCoords.y);
if (currentTouchPointCacheElementPointer == POINTS_CACHE_SIZE - 1) {
actor.setRotation((float) ArithmeticsHelper.getAngleBetweenTwoPoints(touchedPointsCache[0], touchedPointsCache[touchedPointsCache.length - 1]));
}
double distance = Math.hypot(touchPoint.x - actor.getX(), touchPoint.y - actor.getY());
// finger or cursor is too far from vehicle to move it
if (distance > moveTolerance) {
return;
}
super.touchDragged(event, x, y, pointer);
if (((Vehicle) actor).intersectsWith(goalActor)) {
onVehicleDragCompleteListener.onVehicleDragComplete();
for(Music snd : sounds) {
snd.stop();
snd.dispose();
}
}
}
}
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
playingSounds = false;
if(sounds[currentSoundIndex].isPlaying()) {
MusicUtil.fadeOut(sounds[currentSoundIndex], 0.5f, false);
}
super.touchUp(event, x, y, pointer, button);
}
@Override
public void onCompletion(Music music) {
if(!playingSounds)
return;
currentSoundIndex++;
if(currentSoundIndex >= sounds.length)
currentSoundIndex = 0;
sounds[currentSoundIndex].setVolume(1);
sounds[currentSoundIndex].play();
sounds[currentSoundIndex].setOnCompletionListener(this);
}
private Color getTouchedColor(float x, float y) {
Point mapRotationCenter = new Point(actor.getParent().getWidth() / 2, actor.getParent().getHeight() / 2);
Point pointOnRotatedMap = ArithmeticsHelper.translatePositionAccordingToRotation(new Point(x, y), 360 - actor.getParent().getRotation(), mapRotationCenter);
float clickX = (pointOnRotatedMap.x / actor.getParent().getWidth() * roadMapSize.x);
float clickY = roadMapSize.y - (pointOnRotatedMap.y / actor.getParent().getHeight() * roadMapSize.y);
Point clickedPoint = new Point(clickX, clickY);
return new Color(roadColorData[(int) clickedPoint.x][(int) (clickedPoint.y)]);
}
private boolean isPointOnMap(Point p) {
return ((p.x >= 0) && (p.x <= actor.getParent().getWidth()) && (p.y >= 0) && (p.y <= actor.getParent().getHeight()));
}
public interface OnVehicleDragCompleteListener {
void onVehicleDragComplete();
}
}
package cz.nic.tablexia.game.games.pursuit.model; package cz.nic.tablexia.game.games.pursuit.model;
import cz.nic.tablexia.game.games.pursuit.helper.PositionHelper;
import cz.nic.tablexia.util.Point; import cz.nic.tablexia.util.Point;
/** /**
* Created by Václav Tarantík on 10.8.15. * Created by Václav Tarantík on 10.8.15.
*/ */
public enum Maps { public enum Maps {
// TODO add car initial rotation
MAP1("map1", new Point(0.866f, 0.1f), new Point(0.26f, 0.85f), PositionHelper.PursuitPositionDefinition.MAP_1), MAP1("map1", new Point(0.866f, 0.1f), new Point(0.26f, 0.85f)),
MAP2("map2", new Point(0.64f, 0.11f), new Point(0.22f, 0.75f), PositionHelper.PursuitPositionDefinition.MAP_2), MAP2("map2", new Point(0.64f, 0.11f), new Point(0.22f, 0.75f)),
MAP3("map3", new Point(0.08f, 0.41f), new Point(0.79f, 0.71f), PositionHelper.PursuitPositionDefinition.MAP_3), MAP3("map3", new Point(0.08f, 0.41f), new Point(0.79f, 0.71f)),// TODO add car initial rotation
MAP4("map4", new Point(0.95f, 0.33f), new Point(0.18f, 0.57f), PositionHelper.PursuitPositionDefinition.MAP_4), MAP4("map4", new Point(0.95f, 0.33f), new Point(0.18f, 0.57f)),
MAP5("map5", new Point(0.94f, 0.12f), new Point(0.86f, 0.82f), PositionHelper.PursuitPositionDefinition.MAP_5), MAP5("map5", new Point(0.94f, 0.12f), new Point(0.86f, 0.82f)),
MAP6("map6", new Point(0.95f, 0.17f), new Point(0.45f, 0.32f), PositionHelper.PursuitPositionDefinition.MAP_6), MAP6("map6", new Point(0.95f, 0.17f), new Point(0.45f, 0.32f)),
MAP7("map7", new Point(0.56f, 0.07f), new Point(0.36f, 0.83f), PositionHelper.PursuitPositionDefinition.MAP_7), MAP7("map7", new Point(0.56f, 0.07f), new Point(0.36f, 0.83f)),
MAP8("map8", new Point(0.16f, 0.19f), new Point(0.83f, 0.79f), PositionHelper.PursuitPositionDefinition.MAP_8), MAP8("map8", new Point(0.16f, 0.19f), new Point(0.83f, 0.79f)),
MAP9("map9", new Point(0.15f, 0.11f), new Point(0.81f, 0.83f), PositionHelper.PursuitPositionDefinition.MAP_9), MAP9("map9", new Point(0.15f, 0.11f), new Point(0.81f, 0.83f)),
MAP10("map10", new Point(0.22f, 0.07f), new Point(0.76f, 0.84f),PositionHelper.PursuitPositionDefinition.MAP_10), MAP10("map10", new Point(0.22f, 0.07f), new Point(0.76f, 0.84f)),
MAP11("map11", new Point(0.61f, 0.11f), new Point(0.21f, 0.69f),PositionHelper.PursuitPositionDefinition.MAP_11), MAP11("map11", new Point(0.61f, 0.11f), new Point(0.21f, 0.69f)),
MAP12("map12", new Point(0.89f, 0.17f), new Point(0.2f, 0.85f),PositionHelper.PursuitPositionDefinition.MAP_12), MAP12("map12", new Point(0.89f, 0.17f), new Point(0.2f, 0.85f)),
MAP13("map13", new Point(0.08f, 0.06f), new Point(0.88f, 0.73f),PositionHelper.PursuitPositionDefinition.MAP_13), MAP13("map13", new Point(0.08f, 0.06f), new Point(0.88f, 0.73f)),
MAP14("map14", new Point(0.18f, 0.08f), new Point(0.32f, 0.84f),PositionHelper.PursuitPositionDefinition.MAP_14); MAP14("map14", new Point(0.18f, 0.08f), new Point(0.32f, 0.84f));
private String textureRegionName; private String textureRegionName;
//relatives position of checkpoints on map //relatives position of checkpoints on map
private Point startPointCoords; private Point startPointCoords;
private Point endPointCoords; private Point endPointCoords;
private PositionHelper.PursuitPositionDefinition pursuitPositionDefinition;
Maps(String textureRegionName, Point startPointCoords, Point endPointCoords, PositionHelper.PursuitPositionDefinition positionDefinition){ Maps(String textureRegionName, Point startPointCoords, Point endPointCoords){
this.textureRegionName = textureRegionName; this.textureRegionName = textureRegionName;
this.startPointCoords = startPointCoords; this.startPointCoords = startPointCoords;
this.endPointCoords = endPointCoords; this.endPointCoords = endPointCoords;
this.pursuitPositionDefinition = positionDefinition;
} }
public String getTextureRegionName(){ public String getTextureRegionName(){
...@@ -48,8 +44,4 @@ public enum Maps { ...@@ -48,8 +44,4 @@ public enum Maps {
public cz.nic.tablexia.util.Point getEndPointCoords(){ public cz.nic.tablexia.util.Point getEndPointCoords(){
return endPointCoords; return endPointCoords;
} }
public PositionHelper.PursuitPositionDefinition getPursuitPositionDefinition() {
return pursuitPositionDefinition;
}
} }
...@@ -31,6 +31,7 @@ import cz.nic.tablexia.sync.work.DownloadUser; ...@@ -31,6 +31,7 @@ import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.PushDataToServer; import cz.nic.tablexia.sync.work.PushDataToServer;
import cz.nic.tablexia.sync.work.SyncWork; import cz.nic.tablexia.sync.work.SyncWork;
import cz.nic.tablexia.util.ui.ClickListenerWithSound; import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory; import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory;
import cz.nic.tablexia.util.ui.dialog.components.AdaptiveSizeDialogComponent; import cz.nic.tablexia.util.ui.dialog.components.AdaptiveSizeDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.BackButtonHideComponent; import cz.nic.tablexia.util.ui.dialog.components.BackButtonHideComponent;
...@@ -148,12 +149,13 @@ public class UserMenu extends AbstractMenu { ...@@ -148,12 +149,13 @@ public class UserMenu extends AbstractMenu {
public void performAction() { public void performAction() {
final TextFiledDialogComponent textFiledDialogComponent = new TextFiledDialogComponent(SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH, SYNC_REQUEST_DIALOG_PLACEHOLDER_TEXT); final TextFiledDialogComponent textFiledDialogComponent = new TextFiledDialogComponent(SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH, SYNC_REQUEST_DIALOG_PLACEHOLDER_TEXT);
textFiledDialogComponent.setTextFieldWidthPercent(DOWNLOAD_DIALOG_INPUT_WIDTH_PERCENT); textFiledDialogComponent.setTextFieldWidthPercent(DOWNLOAD_DIALOG_INPUT_WIDTH_PERCENT);
textFiledDialogComponent.setRepositionOnFocusOnMobileDevices(true);
TablexiaComponentDialogFactory.getInstance().createDialog( TablexiaComponentDialogFactory.getInstance().createDialog(
new CenterPositionDialogComponent(), new CenterPositionDialogComponent(),
new DimmerDialogComponent(), new DimmerDialogComponent(),
new ViewportMaximumSizeComponent(), new ViewportMaximumSizeComponent(),
new AdaptiveSizeDialogComponent(), new AdaptiveSizeDialogComponent(),
new ResizableSpaceContentDialogComponent(), new ResizableSpaceContentDialogComponent(),
new TextContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_DIALOG_TEXT)), new TextContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_DIALOG_TEXT)),
new ResizableSpaceContentDialogComponent(), new ResizableSpaceContentDialogComponent(),
...@@ -171,6 +173,16 @@ public class UserMenu extends AbstractMenu { ...@@ -171,6 +173,16 @@ public class UserMenu extends AbstractMenu {
} }
}); });
RestSynchronizationService.doSyncWork(syncWork); RestSynchronizationService.doSyncWork(syncWork);
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
}
},
new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
} }
}, },
PositiveNegativeButtonContentDialogComponent.PositiveNegativeButtonType.CONFIRM_DECLINE), PositiveNegativeButtonContentDialogComponent.PositiveNegativeButtonType.CONFIRM_DECLINE),
......
...@@ -2,21 +2,25 @@ package cz.nic.tablexia.util.ui.dialog.components; ...@@ -2,21 +2,25 @@ package cz.nic.tablexia.util.ui.dialog.components;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Cell; import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager; import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.ui.ComponentScaleUtil; import cz.nic.tablexia.util.ui.ComponentScaleUtil;
import cz.nic.tablexia.util.ui.TextFieldWithPlaceholder; import cz.nic.tablexia.util.ui.TextFieldWithPlaceholder;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
/** /**
* Created by Matyáš Latner. * Created by Matyáš Latner.
*/ */
public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
private static final Color DEFAULT_FONT_COLOR = Color.BLACK; private static final Color DEFAULT_FONT_COLOR = Color.BLACK;
private static final ApplicationFontManager.FontType_NEW DEFAULT_FONT_TYPE = ApplicationFontManager.FontType_NEW.REGULAR_20; private static final ApplicationFontManager.FontType_NEW DEFAULT_FONT_TYPE = ApplicationFontManager.FontType_NEW.REGULAR_20;
private static final int FONT_SIZE_RESIZE_THRESHOLD_STEP = 10; private static final int FONT_SIZE_RESIZE_THRESHOLD_STEP = 10;
...@@ -32,9 +36,11 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { ...@@ -32,9 +36,11 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
private ApplicationFontManager.FontType_NEW actualFontType; private ApplicationFontManager.FontType_NEW actualFontType;
private float textFieldWidthPercent = DEFAULT_TEXT_FIELD_WIDTH_PERCENT; private float textFieldWidthPercent = DEFAULT_TEXT_FIELD_WIDTH_PERCENT;
private TextFieldWithPlaceholder uuidTextField; private TextFieldWithPlaceholder textField;
private Cell content; private Cell content;
private FocusListener changePositionFocusListener;
public TextFiledDialogComponent() { public TextFiledDialogComponent() {
this(null, DEFAULT_PLACEHOLDER_TEXT, DEFAULT_FONT_TYPE, DEFAULT_FONT_COLOR); this(null, DEFAULT_PLACEHOLDER_TEXT, DEFAULT_FONT_TYPE, DEFAULT_FONT_COLOR);
} }
...@@ -53,10 +59,12 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { ...@@ -53,10 +59,12 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
this.actualFontType = fontType; this.actualFontType = fontType;
this.fontColor = fontColor; this.fontColor = fontColor;
this.maximumLength = maximumLength; this.maximumLength = maximumLength;
textField = prepareTextField(placeholderText);
} }
public String getText() { public String getText() {
return uuidTextField.getText(); return textField.getText();
} }
public float getTextFieldWidthPercent() { public float getTextFieldWidthPercent() {
...@@ -70,9 +78,8 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { ...@@ -70,9 +78,8 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
@Override @Override
public void prepareContent(Cell content) { public void prepareContent(Cell content) {
this.content = content; this.content = content;
uuidTextField = prepareTextField(placeholderText);
content.width(getDialog().getWidth() * getTextFieldWidthPercent()); content.width(getDialog().getWidth() * getTextFieldWidthPercent());
content.setActor(uuidTextField); content.setActor(textField);
} }
@Override @Override
...@@ -88,7 +95,7 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { ...@@ -88,7 +95,7 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
isScaled = false; isScaled = false;
} }
} }
uuidTextField.setTablexiaTextFieldStyle(prepareTextFieldStyle()); textField.setTablexiaTextFieldStyle(prepareTextFieldStyle());
content.width(getDialog().getWidth() * getTextFieldWidthPercent()); content.width(getDialog().getWidth() * getTextFieldWidthPercent());
} }
...@@ -109,4 +116,34 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter { ...@@ -109,4 +116,34 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
Texture texture = ApplicationAtlasManager.getInstance().getColorTexture(Color.BLACK); Texture texture = ApplicationAtlasManager.getInstance().getColorTexture(Color.BLACK);
return new Image(texture).getDrawable(); return new Image(texture).getDrawable();
} }
public void setRepositionOnFocusOnMobileDevices(boolean repositionOnFocus) {
if(repositionOnFocus && TablexiaSettings.getInstance().isRunningOnMobileDevice()) {
if(changePositionFocusListener == null) prepareChangePositionFocusListener();
textField.addListener(changePositionFocusListener);
}
else {
if(changePositionFocusListener != null) textField.removeListener(changePositionFocusListener);
}
}
private void prepareChangePositionFocusListener() {
this.changePositionFocusListener = new FocusListener() {
@Override
public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
if(focused) repositionDialog();
}
};
}
private void repositionDialog() {
TablexiaComponentDialog dialog = getDialog();
Stage stage = getStage();
if(dialog == null || (stage == null)) return;
dialog.setPosition(
TablexiaSettings.getViewportLeftX(stage) + TablexiaSettings.getViewportWidth(stage) / 2f - dialog.getInnerWidth()/2f,
TablexiaSettings.getViewportBottomY(stage) + TablexiaSettings.getViewportHeight(stage) - dialog.getOutterHeight()
);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment