Skip to content

Commit

Permalink
Stop NUI animations on ESC
Browse files Browse the repository at this point in the history
  • Loading branch information
msteiger committed May 1, 2016
1 parent 6f8e227 commit 4df7a2a
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public boolean canBeFocus() {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ public void onMouseWheelEvent(MouseWheelEvent event) {

@Override
public boolean onKeyEvent(NUIKeyEvent event) {
if (isEscapeToCloseAllowed() && event.isDown() && event.getKey() == Keyboard.Key.ESCAPE) {
triggerBackAnimation();
if (event.isDown() && event.getKey() == Keyboard.Key.ESCAPE) {
animationSystem.stop();
if (isEscapeToCloseAllowed()) {
triggerBackAnimation();
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public interface MenuAnimationSystem {
* @return the transformed rectangle
*/
Rect2i animateRegion(Rect2i rc);

/**
* Stops animation and plays the animation in reverse, if needed
*/
void stop();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public void update(float delta) {
// ignore
}

@Override
public void stop() {
// ignore
}

@Override
public Rect2i animateRegion(Rect2i rc) {
return rc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,53 @@ public SwipeMenuAnimationSystem(float duration, Direction direction) {
*/
@Override
public void triggerFromPrev() {
flyIn.setForwardMode();
flyIn.start();
if (flyOut.isStopped()) {
flyIn.setForwardMode();
flyIn.start();
}
}

/**
* Trigger animation from this one back to the previous screen
*/
@Override
public void triggerToPrev() {
flyIn.setReverseMode();
flyIn.start();
if (flyOut.isStopped()) {
flyIn.setReverseMode();
flyIn.start();
}
}

/**
* Trigger animation from the next screen to this one
*/
@Override
public void triggerFromNext() {
flyOut.setReverseMode();
flyOut.start();
if (flyIn.isStopped()) {
flyOut.setReverseMode();
flyOut.start();
}
}

/**
* Trigger animation from this one to the next screen
*/
@Override
public void triggerToNext() {
flyOut.setForwardMode();
flyOut.start();
if (flyIn.isStopped()) {
flyOut.setForwardMode();
flyOut.start();
}
}

@Override
public void stop() {
if (flyOut.isRunning()) {
flyOut.setReverseMode();
}
if (flyIn.isRunning()) {
flyIn.setForwardMode();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean isReleasingMouse() {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class DeathScreen extends CoreScreenLayer {

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public boolean isModal() {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.terasology.rendering.nui.CoreScreenLayer;
import org.terasology.rendering.nui.WidgetUtil;
import org.terasology.rendering.nui.animation.MenuAnimationSystems;
import org.terasology.rendering.nui.animation.SwipeMenuAnimationSystem;
import org.terasology.rendering.nui.layers.mainMenu.settings.SettingsMenuScreen;
import org.terasology.rendering.nui.widgets.UILabel;
import org.terasology.version.TerasologyVersion;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void update(float delta) {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void updateStatus(String message, float v) {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down

0 comments on commit 4df7a2a

Please sign in to comment.