handle close request per state

This commit is contained in:
yugecin 2017-01-11 23:04:50 +01:00
parent 4ba32c44f2
commit 66ee2a0979
6 changed files with 26 additions and 1 deletions

View File

@ -120,7 +120,7 @@ public class Demux implements KeyListener, MouseListener {
} }
public boolean onCloseRequest() { public boolean onCloseRequest() {
return !isTransitioning(); return state.onCloseRequest();
} }
/* /*

View File

@ -19,6 +19,11 @@ package yugecin.opsudance.core.state;
public abstract class BaseOpsuState implements OpsuState { public abstract class BaseOpsuState implements OpsuState {
@Override
public boolean onCloseRequest() {
return true;
}
@Override @Override
public boolean keyPressed(int key, char c) { public boolean keyPressed(int key, char c) {
return false; return false;

View File

@ -27,6 +27,11 @@ public interface OpsuState {
void enter(); void enter();
void leave(); void leave();
/**
* @return true if closing is allowed
*/
boolean onCloseRequest();
/** /**
* @return false to stop event bubbling * @return false to stop event bubbling
*/ */

View File

@ -71,4 +71,9 @@ public abstract class TransitionState extends BaseOpsuState {
listener.onFinish(); listener.onFinish();
} }
@Override
public boolean onCloseRequest() {
return false;
}
} }

View File

@ -65,6 +65,11 @@ public class EmptyRedState implements OpsuState {
public void leave() { public void leave() {
} }
@Override
public boolean onCloseRequest() {
return true;
}
@Override @Override
public boolean keyPressed(int key, char c) { public boolean keyPressed(int key, char c) {
System.out.println("pressed"); System.out.println("pressed");

View File

@ -62,6 +62,11 @@ public class EmptyState implements OpsuState {
public void leave() { public void leave() {
} }
@Override
public boolean onCloseRequest() {
return true;
}
@Override @Override
public boolean keyPressed(int key, char c) { public boolean keyPressed(int key, char c) {
return false; return false;