Commit f89d898f authored by Anton Danilov's avatar Anton Danilov

Merge branch 'feature-desktop-double-click' into feature-inthedarkness-doubleclick

# Conflicts:
#	core/src/cz/nic/tablexia/util/ui/actionwidget/Action.java
parents f6d7ebe0 af82ab97
......@@ -39,27 +39,31 @@ import java.util.Timer;
import java.util.TimerTask;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.crime_scene.actors.PlaySoundScreen;
import cz.nic.tablexia.game.games.crime_scene.assets.CrimeSceneAssets;
import cz.nic.tablexia.game.games.crime_scene.listeners.CrimeSceneDragListener;
import cz.nic.tablexia.game.games.crime_scene.gameobject.GameObject;
import cz.nic.tablexia.game.games.crime_scene.gameobject.GameObjectType;
import cz.nic.tablexia.game.games.crime_scene.model.*;
import cz.nic.tablexia.game.games.crime_scene.listeners.CrimeSceneDragListener;
import cz.nic.tablexia.game.games.crime_scene.listeners.DesktopCrimeSceneDragListener;
import cz.nic.tablexia.game.games.crime_scene.model.CrimeSceneDifficulty;
import cz.nic.tablexia.game.games.crime_scene.model.CrimeSceneGameState;
import cz.nic.tablexia.game.games.crime_scene.model.LevelDefinition;
import cz.nic.tablexia.game.games.crime_scene.model.ResultMapping;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.resolvers.CrimeSceneScoreResolver;
import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.actionwidget.Action;
import cz.nic.tablexia.util.ui.actionwidget.ActionContainer;
import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget;
import cz.nic.tablexia.util.ui.button.GameImageTablexiaButton;
import cz.nic.tablexia.util.ui.button.TablexiaButton;
import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.util.ui.dialog.components.AnimatedImageContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.FixedSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TablexiaDialogComponentAdapter;
......@@ -319,6 +323,15 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
}
}
}
@Override
public void onActionDoubleTap(Action action) {
if (!TablexiaSettings.getInstance().isRunningOnMobileDevice()) {
removeActionAndUpdateView(action.getOrderNumber());
addGameObject(createGameObject(GameObjectType.getGameObjectTypeForActionNumber(action.getActionNumber())));
if (actionsStripWidget.isNotFull()) startButton.setEnabled(false);
}
}
};
actionsStripWidget.setPosition(getViewportWidth() - ACTIONS_PANEL_WIDTH, getViewportBottomY());
actionsStripWidget.setSize(ACTIONS_PANEL_WIDTH, getViewportHeight());
......@@ -423,7 +436,9 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
}
private void setHighLightGameObjectListener(GameObject gameObject) {
gameObject.addListener(new CrimeSceneDragListener(gameObject, this));
gameObject.addListener(TablexiaSettings.getInstance().isRunningOnMobileDevice() ?
new CrimeSceneDragListener(gameObject, this) :
new DesktopCrimeSceneDragListener(gameObject, this));
}
public void resolveClickOnGameObject(GameObject gameObject, float clickX, float clickY) {
......@@ -605,6 +620,13 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
music.dispose();
}
}
public void addGameObjectToStrip(GameObject gameObject){
removeDuplicateObject(gameObject);
gameObject.changeToCardDrawable();
actionsStripWidget.addSelectedAction(GameObjectType.getGameObjectTypeForActionNumber(gameObject.getAction().getActionNumber()).getActionTexturePath(), actionsStripWidget.getSelectedActions().size(), this, gameObject.getAction().getActionNumber());
}
////////////////////// SET EVENT FOR TESTING
public void setPlayStopEvent(){
......@@ -652,7 +674,7 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
return highlightedGameObject;
}
private void setHighlightedGameObject(GameObject highlightedGameObject) {
public void setHighlightedGameObject(GameObject highlightedGameObject) {
this.highlightedGameObject = highlightedGameObject;
}
......
......@@ -28,8 +28,8 @@ import cz.nic.tablexia.util.ui.actionwidget.Action;
*/
class CrimeSceneAction extends Action {
private final GameObject gameObject;
private final int actionCardSize;
protected final GameObject gameObject;
protected final int actionCardSize;
public CrimeSceneAction(String texturePath, int orderNumber, int actionSize, AbstractTablexiaGame tablexiaGame, int actionNumber, GameObject gameObject) {
super(texturePath, orderNumber, actionSize, 0, 0, true, tablexiaGame, actionNumber);
......
/*
*
* * Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*
*/
package cz.nic.tablexia.game.games.crime_scene.gameobject;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.DragListener;
import com.badlogic.gdx.utils.Timer;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.util.entity.Touch;
class DesktopCrimeSceneAction extends CrimeSceneAction {
private static final float DELAY = 0.15f;
private Touch lastRecordedTouchDown;
private boolean lastTapValid;
private Touch lastRecordedTap;
private Timer timer;
private boolean delayedActionStarted = false;
public DesktopCrimeSceneAction(String texturePath, int orderNumber, int actionSize, AbstractTablexiaGame tablexiaGame, int actionNumber, GameObject gameObject) {
super(texturePath, orderNumber, actionSize, tablexiaGame, actionNumber, gameObject);
timer = new Timer();
}
@Override
public void setDragListener() {
addListener(new DragListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
lastRecordedTouchDown = new Touch(event.getListenerActor(), System.currentTimeMillis());
setDelayedActionStarted(false);
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
setDelayedActionStarted(true);
downAction(x, y, true);
}
}, DELAY);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
timer.clear();
Touch touchUp = new Touch(event.getListenerActor(), System.currentTimeMillis());
lastTapValid = Touch.isTap(lastRecordedTouchDown, touchUp);
if (lastTapValid) {
if (lastRecordedTap == null) {
lastRecordedTap = touchUp;
} else {
if (Touch.isDoubleTap(lastRecordedTap, touchUp)) {
timer.clear();
lastRecordedTap = null;
} else {
lastRecordedTap = touchUp;
resetDelayedUpAction();
}
}
} else {
if (gameObject.isDragging()) {
if (isDelayedActionStarted()) {
upAction(false);
} else {
gameObject.resetPosition();
}
}
}
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
dragAction(x, y);
}
});
}
private void resetDelayedUpAction() {
timer.clear();
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
upAction(false);
}
}, DELAY);
}
private synchronized void setDelayedActionStarted(boolean value) {
delayedActionStarted = value;
}
private synchronized boolean isDelayedActionStarted() {
return delayedActionStarted;
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ package cz.nic.tablexia.game.games.crime_scene.gameobject;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.games.crime_scene.CrimeSceneGame;
import cz.nic.tablexia.util.ui.actionwidget.Action;
import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget;
......@@ -51,7 +52,8 @@ public class GameObject extends Group implements Action.ActionListener {
}
private void createGameObject(final int actionCardSize) {
action = new CrimeSceneAction(gameObjectType.getResource(), 0, actionCardSize, crimeSceneGame, gameObjectType.getActionNumber(), this);
action = TablexiaSettings.getInstance().isRunningOnMobileDevice() ? new CrimeSceneAction(gameObjectType.getResource(), 0, actionCardSize, crimeSceneGame, gameObjectType.getActionNumber(), this) :
new DesktopCrimeSceneAction(gameObjectType.getResource(), 0, actionCardSize, crimeSceneGame, gameObjectType.getActionNumber(), this);
action.getListeners().removeAll(action.getListeners(), false);
action.setDragListener();
action.addActionListener(this);
......@@ -66,6 +68,10 @@ public class GameObject extends Group implements Action.ActionListener {
changeToCardDrawable();
}
@Override
public void onActionDoubleTap(Action action) {
}
@Override
public void onActionDrop(Action action, int collidesWithNumber) {
......@@ -91,10 +97,16 @@ public class GameObject extends Group implements Action.ActionListener {
}
private void changeToCardDrawable() {
public void changeToCardDrawable() {
action.setDrawable(new TextureRegionDrawable(crimeSceneGame.getScreenTextureRegion(gameObjectType.getActionTexturePath())));
action.setSize(CrimeSceneGame.ACTION_CARD_DRAG_SIZE, CrimeSceneGame.ACTION_CARD_DRAG_SIZE);
}
public void resetPosition(){
crimeSceneGame.setHighlightedGameObject(this);
crimeSceneGame.highlightGameObject(this);
onActionDrop(action, Action.NO_COLLISION_NUMBER);
}
public Action getAction() {
return action;
......@@ -125,4 +137,5 @@ public class GameObject extends Group implements Action.ActionListener {
public Position getMapPosition() {
return mapPosition;
}
}
\ No newline at end of file
......@@ -30,8 +30,8 @@ public class CrimeSceneDragListener extends DragListener {
private static final int DRAG_THRESHOLD = 10;
private int dragDeltaTime = 0;
private GameObject gameObject;
private CrimeSceneGame crimeSceneGame;
protected GameObject gameObject;
protected CrimeSceneGame crimeSceneGame;
public CrimeSceneDragListener(GameObject gameObject, CrimeSceneGame crimeSceneGame) {
this.gameObject = gameObject;
......@@ -61,13 +61,13 @@ public class CrimeSceneDragListener extends DragListener {
* users touch or drag on screen
* @param gameObject dragged game object
*/
private void increaseDragDeltaTime(GameObject gameObject) {
protected void increaseDragDeltaTime(GameObject gameObject) {
if(dragDeltaTime++ == DRAG_THRESHOLD) {
gameObject.setDragging(true);
}
}
private void resetDragDeltaTime() {
protected void resetDragDeltaTime() {
dragDeltaTime = 0;
}
}
/*
*
* * Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*
*/
package cz.nic.tablexia.game.games.crime_scene.listeners;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.utils.Timer;
import cz.nic.tablexia.game.games.crime_scene.CrimeSceneGame;
import cz.nic.tablexia.game.games.crime_scene.gameobject.GameObject;
import cz.nic.tablexia.util.entity.Touch;
public class DesktopCrimeSceneDragListener extends CrimeSceneDragListener {
private Timer timer;
private static final float DELAY = 0.15f;
Touch lastRecordedTouchDown;
boolean lastTapValid;
Touch lastRecordedTap;
public DesktopCrimeSceneDragListener(GameObject gameObject, CrimeSceneGame crimeSceneGame) {
super(gameObject, crimeSceneGame);
timer = new Timer();
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
lastRecordedTouchDown = new Touch(event.getListenerActor(), System.currentTimeMillis());
timer.clear();
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
crimeSceneGame.resolveClickOnGameObject(gameObject, x, y);
}
}, DELAY);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
timer.clear();
Touch touchUp = new Touch(event.getListenerActor(), System.currentTimeMillis());
lastTapValid = Touch.isTap(lastRecordedTouchDown, touchUp);
if (lastTapValid) {
if (lastRecordedTap == null) {
lastRecordedTap = touchUp;
timer.clear();
resetHighlightTask();
} else {
if (Touch.isDoubleTap(lastRecordedTap, touchUp)) {
timer.clear();
crimeSceneGame.addGameObjectToStrip(gameObject);
lastRecordedTap = null;
} else {
lastRecordedTap = touchUp;
resetHighlightTask();
}
}
} else {
if (!gameObject.isDragging()) crimeSceneGame.highlightGameObject(gameObject);
gameObject.setDragging(false);
resetDragDeltaTime();
}
}
@Override
public void touchDragged (InputEvent event, float x, float y, int pointer) {
increaseDragDeltaTime(gameObject);
}
private void resetHighlightTask(){
timer.clear();
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
gameObject.changeToCardDrawable();
crimeSceneGame.setHighlightedGameObject(gameObject);
crimeSceneGame.highlightGameObject(gameObject);
}
}, DELAY);
}
}
......@@ -252,9 +252,13 @@ public class ActionsWidget extends Group implements ActionListener {
}
tryToPerformNextTutorialStep();
}
//////////////////////////////////////////// TUTORIAL STEPS
@Override
public void onActionDoubleTap(Action action) {
}
//////////////////////////////////////////// TUTORIAL STEPS
private void tryToPerformNextTutorialStep() {
if (inTheDarknessDifficulty == InTheDarknessDifficulty.TUTORIAL) {
......
......@@ -30,8 +30,8 @@ import com.badlogic.gdx.utils.Align;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.util.entity.Touch;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut;
......@@ -68,6 +68,7 @@ public class Action extends Image {
public interface ActionListener {
void onActionDrag(Action action);
void onActionDrop(Action action, int collidesWithNumber);
void onActionDoubleTap(Action action);
}
private List<ActionListener> actionListeners;
......@@ -84,22 +85,37 @@ public class Action extends Image {
protected ActionsStripWidget actionsStripWidget;
private String texturePath;
private final int actionNumber;
private boolean dragged;
private DragListener dragListener = new DragListener() {
Touch lastRecordedTouchDown;
boolean lastTapValid;
Touch lastRecordedTap;
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
lastRecordedTouchDown = new Touch(event.getListenerActor(), System.currentTimeMillis());
return downAction(x, y, true);
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Touch touchUp = new Touch(event.getListenerActor(), System.currentTimeMillis());
lastTapValid = Touch.isTap(lastRecordedTouchDown, touchUp);
if (lastTapValid) {
if (lastRecordedTap == null) lastRecordedTap = touchUp;
else if (Touch.isDoubleTap(lastRecordedTap, touchUp)) {
onDoubleTap();
lastRecordedTap = null;
} else {
lastRecordedTap = touchUp;
}
}
upAction(true);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
dragged = true;
dragAction(x, y);
}
};
......@@ -228,7 +244,7 @@ public class Action extends Image {
protected void dragAction(float dragPositionX, float dragPositionY) {
moveBy(dragPositionX - getWidth() / 2, dragPositionY - getHeight() / 2);
}
protected void upAction(boolean hideWithAnimation) {
clickable = false;
draggable = false;
......@@ -239,30 +255,20 @@ public class Action extends Image {
performDropAction();
detachFromScene();
} else {
if(TablexiaSettings.getInstance().getPlatform() == TablexiaSettings.Platform.DESKTOP) {
if(dragged) {
hideAction(hideWithAnimation);
} else {
collidesWithNumber = actionsStripWidget.getSelectedActions().size();
performDropAction();
detachFromScene();
}
if(hideWithAnimation) {
hideWithAnimation();
} else {
hideAction(hideWithAnimation);
hide();
}
}
collidesWithNumber = NO_COLLISION_NUMBER;
}
private void hideAction(boolean hideWithAnimation) {
if(hideWithAnimation) {
hideWithAnimation();
} else {
hide();
}
protected void onDoubleTap(){
actionsStripWidget.onActionDoubleTap(this);
}
//////////////////////////////////////////// COLLISION
public void onCollision(int orderNumber, int actionSizeBigger, int actionSizeSmaller) {
......
......@@ -582,6 +582,11 @@ public class ActionsStripWidget extends Group implements ActionListener {
actionContainer.setVisible(actionContainer.getY() > bottomPositionY && actionContainer.getY() < topPositionY);
}
}
public void removeActionAndUpdateView(int orderNumber){
removeAction(orderNumber);
resetSelectedActionsPositions();
}
public void removeAction(int orderNumber) {
for(com.badlogic.gdx.scenes.scene2d.Action action : selectedActions.get(orderNumber).getActions()) {
......@@ -760,8 +765,12 @@ public class ActionsStripWidget extends Group implements ActionListener {
public void onActionDrag(Action lastAction) {
// nothing needed
}
@Override
@Override
public void onActionDoubleTap(Action action) {
}
@Override
public void onActionDrop(Action action, int collidesWithNumber) {
if (collidesWithNumber != Action.NO_COLLISION_NUMBER) {
addSelectedAction(action.getTexturePath(), collidesWithNumber, tablexiaGame, action.getActionNumber());
......
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