Skip to content
Snippets Groups Projects
Commit 7fe2bb04 authored by Frantisek Simon's avatar Frantisek Simon
Browse files

Create user - changed street viewport back to XFillViewport

parent e4923f25
No related branches found
No related tags found
No related merge requests found
package cz.nic.tablexia.screen.createuser;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import java.util.List;
import java.util.Map;
......@@ -74,6 +70,7 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
private TextureRegion clickmap;
private Group panel;
private ScrollPane scrollpane;
@Override
public boolean canBePaused() {
......@@ -184,7 +181,7 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
final Image leftFinger = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/left_finger"), getStage().getWidth() * 0.2f, getStage().getWidth() * 0.2f - getStage().getWidth() * 0.2f / 2, getViewportBottomY());
final Image rightFinger = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/right_finger"), getStage().getWidth() * 0.2f, getStage().getWidth() * 0.8f - getStage().getWidth() * 0.2f / 2, getViewportBottomY());
final Image hint = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/stretchhint"), getStage().getWidth() * 0.5f, getStage().getWidth() / 2 - getStage().getWidth() * 0.5f / 2, getStage().getHeight() * 0.1f);
final Image hint = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/stretchhint"), getStage().getWidth() * 0.5f, getStage().getWidth() / 2 - getStage().getWidth() * 0.5f / 2, getViewportBottomY() + leftFinger.getHeight() / 2);
leftFinger.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions.forever(Actions.sequence(Actions.moveTo(getStage().getWidth() * 0.4f - leftFinger.getWidth() / 2, leftFinger.getY(), 0.5f), Actions.scaleTo(0.8f, 0.8f, 0.2f), Actions.moveTo(-leftFinger.getWidth(), leftFinger.getY(), 0.5f), Actions.scaleTo(1f, 1f, 0.1f)))));
rightFinger.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions.forever(Actions.sequence(Actions.moveTo(getStage().getWidth() * 0.6f - rightFinger.getWidth() / 2, rightFinger.getY(), 0.5f), Actions.scaleTo(0.8f, 0.8f, 0.2f), Actions.moveTo(getStage().getWidth() + rightFinger.getWidth(), rightFinger.getY(), 0.5f), Actions.scaleTo(1f, 1f, 0.1f)))));
......@@ -304,11 +301,11 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
((TablexiaDialog)event.getListenerActor()).hide();
for (Actor a : getStage().getActors()) {
a.addAction(Actions.sequence(Actions.moveBy(-getStage().getWidth(), 0, 0.5f), Actions.removeActor()));
}
Actor street = prepareSwipeStreet();
getStage().clear();
getStage().addActor(street);
street.setX(getStage().getWidth());
street.addAction(Actions.moveBy(-getStage().getWidth(), 0, 0.5f));
......@@ -435,125 +432,26 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
* @return
*/
private Actor prepareSwipeStreet() {
switchToExtendedViewport();
panel = new Group();
ScaleUtil.setFullScreen(panel, getStage());
panel.setCullingArea(new Rectangle(0, 0, panel.getWidth(), panel.getHeight()));
Group group = new HorizontalGroup();
group.setHeight(getStage().getHeight());
final ScrollPane pane = new ScrollPane(group);
pane.setFillParent(true);
pane.setScrollingDisabled(false, true);
panel.addActor(pane);
final Image leftFinger = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/left_finger"), getStage().getWidth() * 0.2f, getStage().getWidth() * 0.2f - getStage().getWidth() * 0.2f / 2, 0);
leftFinger.setVisible(false);
leftFinger.setTouchable(Touchable.disabled);
panel.addActor(leftFinger);
pane.addListener(new EventListener() { // animate finger after 5s of inactivity and only if scrolled to less than 0.7 of maxX
private float lastScroll = Float.NEGATIVE_INFINITY;
private Action action = null;
@Override
public boolean handle(Event event) {
if (pane.getScrollX() != lastScroll) {
final Action oldAction = action;
leftFinger.addAction(Actions.sequence(Actions.fadeOut(0.2f), Actions.run(new Runnable() {
@Override
public void run() {
leftFinger.removeAction(oldAction);
leftFinger.setScale(1);
leftFinger.setPosition(getStage().getWidth() * 0.2f - getStage().getWidth() * 0.2f / 2, 0);
}
})));
if ((pane.getScrollX() / pane.getMaxX()) < 0.7f) {
leftFinger.addAction(action = Actions.sequence(Actions.delay(5), Actions.alpha(0), Actions.visible(true), Actions.fadeIn(0.5f), Actions.forever(Actions.sequence(Actions.moveTo(getStage().getWidth() * 0.4f - leftFinger.getWidth() / 2, leftFinger.getY(), 0.5f), Actions.scaleTo(0.8f, 0.8f, 0.2f), Actions.moveTo(-leftFinger.getWidth(), leftFinger.getY(), 0.5f), Actions.scaleTo(1f, 1f, 0.1f)))));
}
}
lastScroll = pane.getScrollX();
return false;
}
});
//tile0, tile1
group.addActor(ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile0"), getStage().getHeight()));
group.addActor(ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile1"), getStage().getHeight()));
//tile2
Stack tile2 = new Stack();
tile2.add(ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile2"), getStage().getHeight()));
tile2.add(ScaleUtil.createImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile2_title"), getStage().getHeight()));
group.addActor(tile2);
//tile3
final Image tile3Background = ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile3"), getStage().getHeight());
final Image tile3Title = ScaleUtil.createImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile3_title"), getStage().getHeight());
final Group detectiveDoor = new Group();
tile3Title.addListener(new ClickListener() {
private int knockCount = 0;
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if (x > tile3Background.getWidth() * 0.3f) {
knockCount++;
Image knock = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "swipe/knock"), getStage().getWidth() * 0.2f, x, y);
detectiveDoor.addActor(knock);
RunnableAction showKnock = new RunnableAction();
showKnock.setRunnable(new Runnable() {
@Override
public void run() {
if (knockCount > 2) {
Actor office = prepareOffice();
panel.addAction(Actions.sequence(Actions.moveBy(-getStage().getWidth(), 0, 0.5f), Actions.removeActor()));
office.setPosition(getStage().getWidth(), 0);
RunnableAction showDialog = new RunnableAction();
showDialog.setRunnable(new Runnable() {
@Override
public void run() {
showDialog(1);
}
});
office.addAction(Actions.sequence(Actions.moveTo(0, 0, 0.5f), Actions.delay(0.25f), showDialog));
getStage().clear();
getStage().addActor(office);
}
}
});
knock.setTouchable(Touchable.disabled);
getSound("sfx/tuk_" + knockCount + ".mp3").play();
knock.addAction(Actions.sequence(Actions.delay(0.25f), Actions.fadeOut(0.2f), showKnock, Actions.removeActor()));
}
}
});
detectiveDoor.addActor(tile3Background);
detectiveDoor.addActor(tile3Title);
detectiveDoor.setSize(tile3Background.getWidth(), tile3Background.getHeight());
group.addActor(detectiveDoor);
ScaleUtil.setFullScreen(panel, getStage());
panel.setY(getViewportBottomY());
panel.addActor(prepareStreetGroup());
return panel;
}
/**
* Prapare detective office with dialogs and playing voice
* Prepare detective office with dialogs and playing voice
*
* @return
*/
private Actor prepareOffice() {
switchToXFillViewport();
Group group = new Group();
Image background = new TablexiaNoBlendingImage(getScreenTextureRegion(GFX_PATH + "detectiveoffice"));
setActorToFullScene(background);
group.addActor(background);
ScaleUtil.setFullscreenBounds(group, getStage());
ScaleUtil.setFullScene(group, getStage());
return group;
}
......@@ -582,19 +480,93 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
dialog.show(getStage());
}
private void switchToExtendedViewport() {
getStage().setViewport(new ExtendViewport(0, TablexiaSettings.getMinWorldHeight()));
getStage().getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
}
private Group prepareStreetGroup() {
Table group = new Table();
group.setBounds(getSceneLeftX(), getSceneOuterBottomY(), getSceneWidth(), getSceneOuterHeight());
TablexiaNoBlendingImage tile00 = ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile0"), panel.getHeight());
TablexiaNoBlendingImage tile01 = ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile1"), panel.getHeight());
group.add(tile00).height(tile00.getHeight()).width(tile00.getWidth());
group.add(tile01).height(tile01.getHeight()).width(tile01.getWidth());
//tile2
Stack tile2 = new Stack();
TablexiaNoBlendingImage tile02 = ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile2"), panel.getHeight());
tile2.add(tile02);
tile2.add(ScaleUtil.createImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile2_title"), panel.getHeight()));
group.add(tile2).width(tile02.getWidth()).height(tile02.getHeight());
//tile3
final Image tile3Background = ScaleUtil.createNoBlendingImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile3"), getStage().getHeight());
final Image tile3Title = ScaleUtil.createImageToHeight(getScreenTextureRegion(GFX_PATH + "swipe/tile3_title"), getStage().getHeight());
final Group detectiveDoor = new Group();
tile3Title.addListener(new ClickListener() {
private int knockCount = 0;
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if (x > tile3Background.getWidth() * 0.3f && knockCount < 4) {
knockCount++;
Image knock = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "swipe/knock"), getStage().getWidth() * 0.2f, x, y);
detectiveDoor.addActor(knock);
RunnableAction moveToOffice = new RunnableAction();
moveToOffice.setRunnable(new Runnable() {
@Override
public void run() {
Actor office = prepareOffice();
office.setPosition(getStage().getWidth(), 0);
getStage().addActor(office);
panel.addAction(Actions.sequence(Actions.moveBy(-getStage().getWidth(), 0, 0.5f), Actions.removeActor()));
final RunnableAction showDialog = new RunnableAction();
showDialog.setRunnable(new Runnable() {
@Override
public void run() {
showDialog(1);
}
});
office.addAction(Actions.sequence(Actions.moveTo(0, 0, 0.5f), Actions.delay(0.25f), showDialog));
}
});
knock.setTouchable(Touchable.disabled);
getSound("sfx/tuk_" + knockCount + ".mp3").play();
SequenceAction knockActions;
if (knockCount != 3) {
knockActions = Actions.sequence(Actions.delay(0.25f), Actions.fadeOut(0.2f), Actions.removeActor());
} else {
knockActions = Actions.sequence(Actions.delay(0.25f), Actions.fadeOut(0.2f), moveToOffice, Actions.removeActor());
}
knock.addAction(knockActions);
}
}
});
detectiveDoor.addActor(tile3Background);
detectiveDoor.addActor(tile3Title);
detectiveDoor.setSize(tile3Background.getWidth(), tile3Background.getHeight());
group.add(detectiveDoor);
scrollpane = new ScrollPane(group);
scrollpane.setFillParent(true);
scrollpane.setScrollingDisabled(false, true);
private void switchToXFillViewport() {
getStage().setViewport(new XFillViewport());
getStage().getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
return scrollpane;
}
protected void screenResized(int width, int height) {
if (panel != null) {
if (panel != null && scrollpane != null) {
ScaleUtil.setFullScreen(panel, getStage());
float scrollX = scrollpane.getScrollPercentX();
panel.setY(getViewportBottomY());
panel.clear();
panel.addActor(prepareStreetGroup());
scrollpane.pack();
scrollpane.setScrollPercentX(scrollX);
scrollpane.updateVisualScroll();
}
}
}
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