Commit db0ab749 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

Merge branch 'desktop-resize' into 'V3.7'

Desktop resize for Safe

See merge request !649
parents 6f3ca8f1 992b834f
......@@ -35,7 +35,7 @@ public abstract class AbstractMechanics extends Group {
abstract void prepare(SafeGame safeGame, SafeSequence sequence);
public void dispose(){
public void dispose() {
}
......@@ -44,7 +44,7 @@ public abstract class AbstractMechanics extends Group {
boolean foundValid = false;
for (SafeLightImage lightImage : listOfLights) {
float testedAngle = lightImage.getAngle();
if(testedAngle<0) testedAngle+=360;
if (testedAngle < 0) testedAngle += 360;
if (testedAngle - ANGLE_SPREAD <= angle && testedAngle + ANGLE_SPREAD > angle) {
foundValid = true;
if (!lightImage.equals(safeGame.getSelectedLight())) {
......@@ -79,7 +79,7 @@ public abstract class AbstractMechanics extends Group {
public void setButtonsEnabled(SafeGame safeGame) {
safeGame.getReplayButton().setEnabled();
if(!safeGame.isUsedHelpButton()) safeGame.getHelpButton().setEnabled();
if (!safeGame.isUsedHelpButton()) safeGame.getHelpButton().setEnabled();
}
public abstract void setDoneButtonDisOrEnabled(SafeGame safeGame);
......
......@@ -47,7 +47,7 @@ public class Cable extends Group {
private static final int CNT_PARTS_MIN_SHAPING = 5;
private static final int MIN_CABLE_LENGTH = 30;
public static final int CABLE_WIDTH = 20;
public static final int CABLE_WIDTH = 20;
private static final float UV_TEXTURE_BLEEDING_FIX = 0.003f;
......@@ -62,7 +62,7 @@ public class Cable extends Group {
//Cable rendering fields
private CatmullRomSpline<Vector2> spline;
private int cableParts = 1;
private int cableParts = 1;
private Long lastTimeBuild = 0L;
private boolean changed = true;
......@@ -91,12 +91,12 @@ public class Cable extends Group {
}
public void setStartingPoint(Vector2 point) {
if(point == null) return;
if (point == null) return;
if(splineVectors[0] == null) splineVectors[0] = new Vector2();
if (splineVectors[0] == null) splineVectors[0] = new Vector2();
splineVectors[0].set(point.x - MIN_SHAPING_FORCE, point.y);
if(splineVectors[1] == null) splineVectors[1] = new Vector2();
if (splineVectors[1] == null) splineVectors[1] = new Vector2();
splineVectors[1].set(point.x, point.y);
startingPointsSet = true;
......@@ -104,26 +104,26 @@ public class Cable extends Group {
}
public void setEndingPoint(Vector2 point) {
if(point == null) return;
if (point == null) return;
int shaping = getShapingByParts();
if(splineVectors[0] != null && splineVectors[1] !=null) {
if (splineVectors[0] != null && splineVectors[1] != null) {
splineVectors[0].x = splineVectors[1].x - shaping;
}
if(splineVectors[3] == null) splineVectors[3] = new Vector2();
if (splineVectors[3] == null) splineVectors[3] = new Vector2();
splineVectors[3].set(point.x + shaping, point.y);
if(splineVectors[2] == null) splineVectors[2] = new Vector2();
if (splineVectors[2] == null) splineVectors[2] = new Vector2();
splineVectors[2].set(point.x, point.y);
endingPointsSet = true;
changed = true;
}
public double getCableLength(){
if(!startingPointsSet || !endingPointsSet) {
public double getCableLength() {
if (!startingPointsSet || !endingPointsSet) {
return 0;
}
......@@ -142,14 +142,14 @@ public class Cable extends Group {
}
public void setCableParts() {
cableParts = (int) (getCableLength()/CABLE_WIDTH) + 1;
cableParts = (int) (getCableLength() / CABLE_WIDTH) + 1;
if(cableParts >= maxCableParts) cableParts = maxCableParts;
else if(cableParts < 0) cableParts = 1;
if (cableParts >= maxCableParts) cableParts = maxCableParts;
else if (cableParts < 0) cableParts = 1;
}
private int getShapingByParts(){
if(cableParts < CNT_PARTS_MIN_SHAPING)
private int getShapingByParts() {
if (cableParts < CNT_PARTS_MIN_SHAPING)
return MINUMUM_CABLE_PARTS;
int shaping = (cableParts * INC_SHAPING);
......@@ -164,7 +164,7 @@ public class Cable extends Group {
public void act(float delta) {
super.act(delta);
if(changed && System.currentTimeMillis() - lastTimeBuild >= BUILD_INTERVAL_IN_MS) {
if (changed && System.currentTimeMillis() - lastTimeBuild >= BUILD_INTERVAL_IN_MS) {
buildCable();
}
}
......@@ -181,7 +181,7 @@ public class Cable extends Group {
}
private void buildCable() {
if(!startingPointsSet || !endingPointsSet) {
if (!startingPointsSet || !endingPointsSet) {
Log.debug(getClass(), "Can't build a cable. Set Starting and Ending points first!");
return;
}
......@@ -193,37 +193,37 @@ public class Cable extends Group {
int minParts = getCableLength() > MIN_CABLE_LENGTH ? MINUMUM_CABLE_PARTS : 2;
int cableSegments = (int) (approxLength / PREFFERED_CABLE_PART_LENGTH);
cableSegments = MathUtils.clamp(cableSegments, minParts, getCableParts() - PREGENERATED_CABLE_PARTS);
cableSegments = MathUtils.clamp(cableSegments, minParts, getCableParts() - PREGENERATED_CABLE_PARTS);
float part = 1f / cableSegments;
//FIRST POINT
spline.valueAt(tempPoint, 0);
verticesList.add(new Vector2(tempPoint.x, tempPoint.y + CABLE_WIDTH/2));
verticesList.add(new Vector2(tempPoint.x , tempPoint.y - CABLE_WIDTH/2));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y + CABLE_WIDTH / 2));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y - CABLE_WIDTH / 2));
for(int i = 1; i < cableSegments; i++) {
float progress = MathUtils.clamp(i*part, 0, 1);
prevPoint.set(tempPoint.x,tempPoint.y);
for (int i = 1; i < cableSegments; i++) {
float progress = MathUtils.clamp(i * part, 0, 1);
prevPoint.set(tempPoint.x, tempPoint.y);
spline.valueAt(tempPoint, progress);
spline.derivativeAt(tempDir, progress);
distances.add(prevPoint.dst(tempPoint));
float angle = (tempDir.angle() + 90) % 360;
float cos = MathUtils.cosDeg(angle) * CABLE_WIDTH/2;
float sin = MathUtils.sinDeg(angle) * CABLE_WIDTH/2;
float cos = MathUtils.cosDeg(angle) * CABLE_WIDTH / 2;
float sin = MathUtils.sinDeg(angle) * CABLE_WIDTH / 2;
verticesList.add(new Vector2(tempPoint.x + cos, tempPoint.y + sin));
verticesList.add(new Vector2(tempPoint.x - cos, tempPoint.y - sin));
verticesList.add(new Vector2(tempPoint.x + cos, tempPoint.y + sin));
verticesList.add(new Vector2(tempPoint.x - cos, tempPoint.y - sin));
}
//LAST POINT
prevPoint.set(tempPoint.x,tempPoint.y);
prevPoint.set(tempPoint.x, tempPoint.y);
spline.valueAt(tempPoint, 1);
distances.add(prevPoint.dst(tempPoint));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y + CABLE_WIDTH/2));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y - CABLE_WIDTH/2));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y + CABLE_WIDTH / 2));
verticesList.add(new Vector2(tempPoint.x, tempPoint.y - CABLE_WIDTH / 2));
buildMeshFromVertices();
lastTimeBuild = System.currentTimeMillis();
......@@ -242,36 +242,36 @@ public class Cable extends Group {
int y = 0;
int distanceIndex = 0;
for(int i = 0; i < verticesList.size()-2; i+=2) {
for (int i = 0; i < verticesList.size() - 2; i += 2) {
Vector2 vec1 = verticesList.get(i);
Vector2 vec2 = verticesList.get(i+1);
Vector2 vec3 = verticesList.get(i+2);
Vector2 vec4 = verticesList.get(i+3);
Vector2 vec2 = verticesList.get(i + 1);
Vector2 vec3 = verticesList.get(i + 2);
Vector2 vec4 = verticesList.get(i + 3);
int distance = (distances.get(distanceIndex).intValue());
texturePart.setRegionHeight(distance);
texturePart.setRegionY(y);
distanceIndex++;
cableSpriteBatch.draw( new float[] {
vec1.x, vec1.y,
color,
texturePart.getU(),texturePart.getV(),
vec2.x, vec2.y,
color,
texturePart.getU2(), texturePart.getV(),
vec4.x, vec4.y,
color,
texturePart.getU2(),texturePart .getV2(),
vec3.x, vec3.y,
color,
texturePart.getU(), texturePart .getV2()
},
0,
CableSpriteBatch.CABLE_PART_SIZE);
cableSpriteBatch.draw(new float[]{
vec1.x, vec1.y,
color,
texturePart.getU(), texturePart.getV(),
vec2.x, vec2.y,
color,
texturePart.getU2(), texturePart.getV(),
vec4.x, vec4.y,
color,
texturePart.getU2(), texturePart.getV2(),
vec3.x, vec3.y,
color,
texturePart.getU(), texturePart.getV2()
},
0,
CableSpriteBatch.CABLE_PART_SIZE);
y += distance;
}
......@@ -280,7 +280,7 @@ public class Cable extends Group {
}
public void dispose() {
if(cableSpriteBatch != null){
if (cableSpriteBatch != null) {
cableSpriteBatch.dispose();
}
}
......
......@@ -61,12 +61,13 @@ public class CableSpriteBatch {
private float color = Color.WHITE.toFloatBits();
private Color tempColor = new Color(1, 1, 1, 1);
public CableSpriteBatch (Cable cable) {
public CableSpriteBatch(Cable cable) {
int size = cable.getMaxCableParts() * CABLE_VERTICES_PER_PART;
Log.info(getClass(), "Created CableSpriteBatch with size: " + size + " for up to " + cable.getMaxCableParts() + " cable parts!");
// 32767 is max vertex index, so 32767 / 4 vertices per sprite = 8191 sprites max.
if (size > 8191) throw new IllegalArgumentException("Can't have more than 8191 cable part vertices per batch: " + size);
if (size > 8191)
throw new IllegalArgumentException("Can't have more than 8191 cable part vertices per batch: " + size);
Mesh.VertexDataType vertexDataType = (Gdx.gl30 != null) ? Mesh.VertexDataType.VertexBufferObjectWithVAO : defaultVertexDataType;
......@@ -84,10 +85,10 @@ public class CableSpriteBatch {
short j = 0;
for (int i = 0; i < len; i += 6, j += 4) {
indices[i] = j;
indices[i + 1] = (short)(j + 1);
indices[i + 2] = (short)(j + 2);
indices[i + 3] = (short)(j + 2);
indices[i + 4] = (short)(j + 3);
indices[i + 1] = (short) (j + 1);
indices[i + 2] = (short) (j + 2);
indices[i + 3] = (short) (j + 2);
indices[i + 4] = (short) (j + 3);
indices[i + 5] = j;
}
mesh.setIndices(indices);
......@@ -96,7 +97,7 @@ public class CableSpriteBatch {
switchTexture(cable.getCableTextureRegion().getTexture());
}
static public ShaderProgram createDefaultShader () {
static public ShaderProgram createDefaultShader() {
String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
+ "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
......@@ -126,24 +127,25 @@ public class CableSpriteBatch {
+ "}";
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
if (!shader.isCompiled()) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
if (!shader.isCompiled())
throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
return shader;
}
public void begin () {
public void begin() {
shader.begin();
setupMatrices();
}
public void end () {
public void end() {
shader.end();
}
public void setColor (Color tint) {
public void setColor(Color tint) {
color = tint.toFloatBits();
}
public Color getColor () {
public Color getColor() {
int intBits = NumberUtils.floatToIntColor(color);
Color color = tempColor;
color.r = (intBits & 0xff) / 255f;
......@@ -153,7 +155,7 @@ public class CableSpriteBatch {
return color;
}
public void draw (float[] spriteVertices, int offset, int count) {
public void draw(float[] spriteVertices, int offset, int count) {
int verticesLength = vertices.length;
int remainingVertices = verticesLength;
......@@ -169,7 +171,7 @@ public class CableSpriteBatch {
idx += copyCount;
}
public void reset () {
public void reset() {
idx = 0;
}
......@@ -191,26 +193,26 @@ public class CableSpriteBatch {
mesh.render(shader, GL20.GL_TRIANGLES, 0, count);
}
public void dispose () {
public void dispose() {
mesh.dispose();
shader.dispose();
}
public void setProjectionMatrix (Matrix4 projection) {
public void setProjectionMatrix(Matrix4 projection) {
projectionMatrix.set(projection);
}
public void setTransformMatrix (Matrix4 transform) {
public void setTransformMatrix(Matrix4 transform) {
transformMatrix.set(transform);
}
private void setupMatrices () {
private void setupMatrices() {
combinedMatrix.set(projectionMatrix).mul(transformMatrix);
shader.setUniformMatrix("u_projTrans", combinedMatrix);
shader.setUniformi("u_texture", 0);
}
private void switchTexture (Texture texture) {
private void switchTexture(Texture texture) {
lastTexture = texture;
}
}
\ No newline at end of file
......@@ -37,12 +37,12 @@ import cz.nic.tablexia.util.Point;
public class SafeMechanicsEasy extends AbstractMechanics {
private static final int SAFE_BACKGROUND_OFFSET = 230;
private static final int SAFE_SIDE_OFFSET = 250;
private static final int SAFE_LIGHT_OFFSET = 30;
private static final int SAFE_LIGHT_SIZE = 50;
private static final float ANGLE_INCREASE = 45;
private static final float STARTING_ANGLE = 60;
private static final int SAFE_BACKGROUND_OFFSET = 230;
private static final int SAFE_SIDE_OFFSET = 250;
private static final int SAFE_LIGHT_OFFSET = 30;
private static final int SAFE_LIGHT_SIZE = 50;
private static final float ANGLE_INCREASE = 45;
private static final float STARTING_ANGLE = 60;
private List<SafeLightImage> listOfLights;
private Image safeCircle;
......@@ -53,26 +53,26 @@ public class SafeMechanicsEasy extends AbstractMechanics {
safeGame.setSelectedLight(null, listOfLights, false);
listOfLights = null;
Image safeBackground = new Image(safeGame.getScreenTextureRegion(SafeAssets.CIRCLE_BACKGROUND));
safeBackground.setSize(getHeight()-SAFE_BACKGROUND_OFFSET, getHeight()-SAFE_BACKGROUND_OFFSET);
safeBackground.setPosition(getWidth()/2 - safeBackground.getWidth()/2, getHeight()/2 - safeBackground.getHeight()/2);
safeBackground.setSize(getHeight() - SAFE_BACKGROUND_OFFSET, getHeight() - SAFE_BACKGROUND_OFFSET);
safeBackground.setPosition(getWidth() / 2 - safeBackground.getWidth() / 2, getHeight() / 2 - safeBackground.getHeight() / 2);
addActor(safeBackground);
safeCircle = new Image(safeGame.getScreenTextureRegion(SafeAssets.CIRCLE));
safeCircle.setSize(getHeight()-SAFE_SIDE_OFFSET, getHeight()-SAFE_SIDE_OFFSET);
safeCircle.setPosition(getWidth()/2 - safeCircle.getWidth()/2, getHeight()/2 - safeCircle.getHeight()/2);
safeCircle.setSize(getHeight() - SAFE_SIDE_OFFSET, getHeight() - SAFE_SIDE_OFFSET);
safeCircle.setPosition(getWidth() / 2 - safeCircle.getWidth() / 2, getHeight() / 2 - safeCircle.getHeight() / 2);
safeCircle.setOrigin(safeCircle.getWidth() / 2, safeCircle.getWidth() / 2);
safeCircle.addListener(dragListenerForSafeCircle = new DragListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button){
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
holding = true;
setButtonsDisabled(safeGame);
return super.touchDown(event, x, y, pointer, button);
}
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
super.drag(event, x, y, pointer);
......@@ -87,19 +87,20 @@ public class SafeMechanicsEasy extends AbstractMechanics {
holding = false;
setButtonsEnabled(safeGame);
if (safeGame.getSelectedLight() != null) {
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth()/2, safeGame.getSelectedLight().getHeight()/2)), safeCircle);
safeGame.getDoneButton().setEnabled();;
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth() / 2, safeGame.getSelectedLight().getHeight() / 2)), safeCircle);
safeGame.getDoneButton().setEnabled();
;
}
}
});
addActor(safeCircle);
listOfLights = new ArrayList<>();
Point circleCenter = new Point(safeCircle.getX() + safeCircle.getOriginX(), safeCircle.getY() + safeCircle.getOriginY());
for (int i = 0; i < safeSequence.getSoundsToLights().length; i++) {
float angle = STARTING_ANGLE - ANGLE_INCREASE * i;
SafeLightImageTypeDefinition safeLightImageTypeDefinition = SafeLightImageTypeDefinition.values()[i%SafeLightImageTypeDefinition.values().length];
SafeLightImageTypeDefinition safeLightImageTypeDefinition = SafeLightImageTypeDefinition.values()[i % SafeLightImageTypeDefinition.values().length];
SafeLightImage lightImage = new SafeLightImage(
safeGame,
safeLightImageTypeDefinition.getGreyTextureRegion(),
......@@ -108,7 +109,7 @@ public class SafeMechanicsEasy extends AbstractMechanics {
safeLightImageTypeDefinition.getBlueTextureRegion(),
safeGame.getMusic(safeSequence.getSoundsToLights()[i].getSoundPath()),
angle);
lightImage.setSize(SAFE_LIGHT_SIZE, SAFE_LIGHT_SIZE);
Point lightPosition = ArithmeticsHelper.getPointOnCircle(circleCenter, safeBackground.getWidth() / 2 + SAFE_LIGHT_OFFSET, angle);
lightImage.setPosition(lightPosition.x - lightImage.getWidth() / 2, lightPosition.y - lightImage.getHeight() / 2);
......@@ -125,7 +126,7 @@ public class SafeMechanicsEasy extends AbstractMechanics {
}
});
lightImage.addListener(lightImage.getInputListener());
lightImage.setName(LIGHT_NAME+i);
lightImage.setName(LIGHT_NAME + i);
listOfLights.add(lightImage);
addActor(lightImage);
}
......@@ -133,7 +134,7 @@ public class SafeMechanicsEasy extends AbstractMechanics {
@Override
public void setSafeActorsUntouchable() {
for(SafeLightImage safeLightImage:listOfLights){
for (SafeLightImage safeLightImage : listOfLights) {
safeLightImage.clearListeners();
}
safeCircle.clearListeners();
......@@ -141,7 +142,7 @@ public class SafeMechanicsEasy extends AbstractMechanics {
@Override
public void setSafeActorsTouchable() {
for(SafeLightImage safeLightImage:listOfLights){
for (SafeLightImage safeLightImage : listOfLights) {
safeLightImage.addListener(safeLightImage.getInputListener());
}
safeCircle.addListener(dragListenerForSafeCircle);
......@@ -150,15 +151,16 @@ public class SafeMechanicsEasy extends AbstractMechanics {
@Override
public void setDoneButtonDisOrEnabled(SafeGame safeGame) {
if (safeGame.getSelectedLight() != null) {
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth()/2, safeGame.getSelectedLight().getHeight()/2)), safeCircle);
safeGame.getDoneButton().setEnabled();;
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth() / 2, safeGame.getSelectedLight().getHeight() / 2)), safeCircle);
safeGame.getDoneButton().setEnabled();
;
}
}
public void lightTheLight(SafeGame safeGame, SafeLightImage lightImage){
public void lightTheLight(SafeGame safeGame, SafeLightImage lightImage) {
safeGame.setSelectedLight(lightImage, listOfLights, true);
Vector2 lightImageCoords = lightImage.localToStageCoordinates(new Vector2(lightImage.getWidth()/2, lightImage.getHeight()/2));
Vector2 lightImageCoords = lightImage.localToStageCoordinates(new Vector2(lightImage.getWidth() / 2, lightImage.getHeight() / 2));
rotateSafeCircleTo(lightImageCoords, safeCircle);
AbstractTablexiaScreen.triggerScenarioStepEvent(LIGHT_LIGHTED_UP);
}
......
......@@ -40,12 +40,12 @@ import cz.nic.tablexia.util.Point;
*/
public class SafeMechanicsHard extends AbstractMechanics {
private static final int SAFE_POINTER_WIDTH = 50;
private static final int SAFE_POINTER_HEIGHT = 250;
private static final int SAFE_LIGHT_SIZE = 50;
private static final int SAFE_LIGHT_OFFSET = 20;
private static final int MIN_POINTER_Y = 130;
private static final int SAFE_POINTER_CENTER = 2;
private static final int SAFE_POINTER_WIDTH = 50;
private static final int SAFE_POINTER_HEIGHT = 250;
private static final int SAFE_LIGHT_SIZE = 50;
private static final int SAFE_LIGHT_OFFSET = 20;
private static final int MIN_POINTER_Y = 130;
private static final int SAFE_POINTER_CENTER = 2;
private static final float SAFE_POINTER_ORIGIN = 0.1f;
private static final float SAFE_POINTER_HEIGH = 0.6f;
......@@ -57,16 +57,16 @@ public class SafeMechanicsHard extends AbstractMechanics {
@Override
void prepare(SafeGame safeGame, SafeSequence safeSequence) {
Image safePeak = new Image(safeGame.getScreenTextureRegion(SafeAssets.PEAK));
safePeak.setPosition(getWidth()/2 - safePeak.getWidth()/2, safeGame.getSceneOuterBottomY());
safePeak.setPosition(getWidth() / 2 - safePeak.getWidth() / 2, safeGame.getSceneOuterBottomY());
addActor(safePeak);
safePointer = new Image(safeGame.getScreenTextureRegion(SafeAssets.POINTER));
safePointer.setSize(SAFE_POINTER_WIDTH, SAFE_POINTER_HEIGHT);
safePointer.setOrigin(safePointer.getWidth() / 2, safePointer.getHeight()*SAFE_POINTER_ORIGIN);
safePointer.setPosition((safePeak.getX() + safePeak.getWidth()/2 - safePointer.getWidth()/2) - SAFE_POINTER_CENTER, safePeak.getY()+safePeak.getHeight()*SAFE_POINTER_HEIGH);
safePointer.setOrigin(safePointer.getWidth() / 2, safePointer.getHeight() * SAFE_POINTER_ORIGIN);
safePointer.setPosition((safePeak.getX() + safePeak.getWidth() / 2 - safePointer.getWidth() / 2) - SAFE_POINTER_CENTER, safePeak.getY() + safePeak.getHeight() * SAFE_POINTER_HEIGH);
safePointer.addListener(dragListener = new DragListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button){
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
holding = true;
setButtonsDisabled(safeGame);
return super.touchDown(event, x, y, pointer, button);
......@@ -76,7 +76,7 @@ public class SafeMechanicsHard extends AbstractMechanics {
public void drag(InputEvent event, float x, float y, int pointer) {
super.drag(event, x, y, pointer);
Vector2 fingerCoords = safePointer.localToStageCoordinates(new Vector2(x, y));
if(fingerCoords.y > MIN_POINTER_Y){
if (fingerCoords.y > MIN_POINTER_Y) {
rotateSafeCircleTo(fingerCoords, safePointer);
compareFingerCoordsWithLightPositions(fingerCoords, safeGame, listOfLights);
}
......@@ -85,16 +85,16 @@ public class SafeMechanicsHard extends AbstractMechanics {
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button);
holding=false;
holding = false;
setButtonsEnabled(safeGame);
if (safeGame.getSelectedLight() != null) {
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth()/2, safeGame.getSelectedLight().getHeight()/2)), safePointer);
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth() / 2, safeGame.getSelectedLight().getHeight() / 2)), safePointer);
safeGame.getDoneButton().setEnabled();
}
}
});
Point circleCenter = new Point(safePointer.getX() + safePointer.getWidth()/2, safePointer.getY() + 10);
Point circleCenter = new Point(safePointer.getX() + safePointer.getWidth() / 2, safePointer.getY() + 10);
listOfLights = new ArrayList<>();
for (int i = 0; i < safeSequence.getSoundsToLights().length; i++) {
SafeLightHardDefinition safeLightHardDefinition = SafeLightHardDefinition.values()[i];
......@@ -112,7 +112,7 @@ public class SafeMechanicsHard extends AbstractMechanics {
safeGame.getMusic(safeSequence.getSoundsToLights()[i].getSoundPath()),
angle);
lightImage.setSize(SAFE_LIGHT_SIZE, SAFE_LIGHT_SIZE);
lightImage.setPosition(safeLight.getX() + safeLight.getWidth()/2 - lightImage.getWidth()/2, safeLight.getY() + safeLight.getHeight()/2 - lightImage.getHeight()/2);
lightImage.setPosition(safeLight.getX() + safeLight.getWidth() / 2 - lightImage.getWidth() / 2, safeLight.getY() + safeLight.getHeight() / 2 - lightImage.getHeight() / 2);
lightImage.setInputListener(new InputListener() {
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
......@@ -126,7 +126,7 @@ public class SafeMechanicsHard extends AbstractMechanics {
}
});
lightImage.addListener(lightImage.getInputListener());
lightImage.setName(LIGHT_NAME+i);
lightImage.setName(LIGHT_NAME + i);
listOfLights.add(lightImage);
addActor(safeLight);
addActor(lightImage);
......@@ -137,7 +137,7 @@ public class SafeMechanicsHard extends AbstractMechanics {
@Override
public void setSafeActorsUntouchable() {
for(SafeLightImage safeLightImage:listOfLights){
for (SafeLightImage safeLightImage : listOfLights) {
safeLightImage.clearListeners();
}
safePointer.clearListeners();
......@@ -145,7 +145,7 @@ public class SafeMechanicsHard extends AbstractMechanics {
@Override
public void setSafeActorsTouchable() {
for(SafeLightImage safeLightImage:listOfLights){
for (SafeLightImage safeLightImage : listOfLights) {
safeLightImage.addListener(safeLightImage.getInputListener());
}
safePointer.addListener(dragListener);
......@@ -154,15 +154,15 @@ public class SafeMechanicsHard extends AbstractMechanics {
@Override
public void setDoneButtonDisOrEnabled(SafeGame safeGame) {
if (safeGame.getSelectedLight() != null) {
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth()/2, safeGame.getSelectedLight().getHeight()/2)), safePointer);
rotateSafeCircleTo(safeGame.getSelectedLight().localToStageCoordinates(new Vector2(safeGame.getSelectedLight().getWidth() / 2, safeGame.getSelectedLight().getHeight() / 2)), safePointer);
safeGame.getDoneButton().setEnabled();
}
}
public void lightTheLight(SafeGame safeGame, SafeLightImage lightImage){
public void lightTheLight(SafeGame safeGame, SafeLightImage lightImage) {
safeGame.setSelectedLight(lightImage, listOfLights, true);
Vector2 lightImageCoords = lightImage.localToStageCoordinates(new Vector2(lightImage.getWidth()/2, lightImage.getHeight()/2));
Vector2 lightImageCoords = lightImage.localToStageCoordinates(new Vector2(lightImage.getWidth() / 2, lightImage.getHeight() / 2));
rotateSafeCircleTo(lightImageCoords, safePointer);
AbstractTablexiaScreen.triggerScenarioStepEvent(LIGHT_LIGHTED_UP);
}
......
......@@ -43,16 +43,16 @@ public class SafeMechanicsMedium extends AbstractMechanics {
private List<SafeLightImage> listOfLights;
private List<CableGroup> cableGroups;
private Image finalSocket;
private Rectangle finalSocketDetect;
private Image finalSocket;
private Rectangle finalSocketDetect;
private int socketCableID ; // -1 empty : >= 0 cable ID
private int socketCableID; // -1 empty : >= 0 cable ID
@Override
public void dispose() {
super.dispose();
if(cableGroups!=null) {
if (cableGroups != null)