Skip to content
Snippets Groups Projects
Commit ff3e50d6 authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#81 Code refactoring

parent b271ffb2
Branches
Tags
No related merge requests found
......@@ -89,6 +89,10 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
private Stack newspaperStages;
private boolean newspapersOpened = false;
private Image hintFinger;
private float lastScroll = Float.NEGATIVE_INFINITY;
private Action lastHintFingerAction;
@Override
public boolean canBePaused() {
return false;
......@@ -592,48 +596,49 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
}
private void prepareSwipeStreetFingerHint() {
final Image leftFinger = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/left_finger"), getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH, getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_X - getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH / 2, 0);
leftFinger.setVisible(false);
leftFinger.setTouchable(Touchable.disabled);
panel.addActor(leftFinger);
hintFinger = ScaleUtil.createImageWidthPosition(getScreenTextureRegion(GFX_PATH + "newspaper/left_finger"), getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH, getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_X - getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH / 2, 0);
hintFinger.setVisible(false);
hintFinger.setTouchable(Touchable.disabled);
panel.addActor(hintFinger);
scrollpane.addListener(new EventListener() { // animate finger after 3s 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 (scrollpane.getScrollX() != lastScroll) {
final Action oldAction = action;
leftFinger.addAction(Actions.sequence(Actions.fadeOut(PanoramaActorsLayout.FINGER_FADE_OUT), Actions.run(new Runnable() {
@Override
public void run() {
leftFinger.removeAction(oldAction);
leftFinger.setScale(PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO);
leftFinger.setPosition(getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_X - getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH / 2, 0);
}
})));
//ScrollPanes getScrollPercentX method returns NaN if scroll pane wasn't touched yet...
float percentScrollX = Float.isNaN(scrollpane.getScrollPercentX()) ? 0 : scrollpane.getScrollPercentX();
if (percentScrollX < PanoramaActorsLayout.STREET_HINT_END) {
leftFinger.addAction(action = Actions.sequence(
Actions.delay(PanoramaActorsLayout.STREET_HINT_DELAY)
, Actions.alpha(0)
, Actions.visible(true)
, Actions.fadeIn(PanoramaActorsLayout.FINGER_FADE_IN)
, Actions.forever(Actions.sequence(
Actions.moveTo(getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_MOVE_TO - leftFinger.getWidth() / 2, leftFinger.getY(), PanoramaActorsLayout.FINGER_MOVE_DURATION)
, Actions.scaleTo(PanoramaActorsLayout.FINGER_SCALE_TO, PanoramaActorsLayout.FINGER_SCALE_TO, PanoramaActorsLayout.FINGER_SCALE_DURATION)
, Actions.moveTo(-leftFinger.getWidth(), leftFinger.getY(), PanoramaActorsLayout.FINGER_MOVE_DURATION)
, Actions.scaleTo(PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO, PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO, PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_DURATION)))));
}
}
lastScroll = scrollpane.getScrollX();
return false;
return handleHintFinger();
}
});
//We need to run scroll panes listener handle method at least once
scrollpane.fire(new Event());
handleHintFinger();
}
private boolean handleHintFinger() {
if (scrollpane.getScrollX() != lastScroll) {
final Action oldAction = lastHintFingerAction;
hintFinger.addAction(Actions.sequence(Actions.fadeOut(PanoramaActorsLayout.FINGER_FADE_OUT), Actions.run(new Runnable() {
@Override
public void run() {
hintFinger.removeAction(oldAction);
hintFinger.setScale(PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO);
hintFinger.setPosition(getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_X - getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_FINGER_WIDTH / 2, 0);
}
})));
//ScrollPanes getScrollPercentX method returns NaN if scroll pane wasn't touched yet...
float percentScrollX = Float.isNaN(scrollpane.getScrollPercentX()) ? 0 : scrollpane.getScrollPercentX();
if (percentScrollX < PanoramaActorsLayout.STREET_HINT_END) {
hintFinger.addAction(lastHintFingerAction = Actions.sequence(
Actions.delay(PanoramaActorsLayout.STREET_HINT_DELAY)
, Actions.alpha(0)
, Actions.visible(true)
, Actions.fadeIn(PanoramaActorsLayout.FINGER_FADE_IN)
, Actions.forever(Actions.sequence(
Actions.moveTo(getStage().getWidth() * PanoramaActorsLayout.STREET_HINT_MOVE_TO - hintFinger.getWidth() / 2, hintFinger.getY(), PanoramaActorsLayout.FINGER_MOVE_DURATION)
, Actions.scaleTo(PanoramaActorsLayout.FINGER_SCALE_TO, PanoramaActorsLayout.FINGER_SCALE_TO, PanoramaActorsLayout.FINGER_SCALE_DURATION)
, Actions.moveTo(-hintFinger.getWidth(), hintFinger.getY(), PanoramaActorsLayout.FINGER_MOVE_DURATION)
, Actions.scaleTo(PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO, PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_TO, PanoramaActorsLayout.FINGER_ORIGINAL_SCALE_DURATION)))));
}
}
lastScroll = scrollpane.getScrollX();
return false;
}
protected void screenResized(int width, int height) {
......
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