let the base state listen to the resolution change events
This commit is contained in:
parent
a1e5c3d30f
commit
c467e9b34e
|
@ -22,11 +22,14 @@ import org.newdawn.slick.Graphics;
|
||||||
import org.newdawn.slick.Input;
|
import org.newdawn.slick.Input;
|
||||||
import org.newdawn.slick.KeyListener;
|
import org.newdawn.slick.KeyListener;
|
||||||
import org.newdawn.slick.MouseListener;
|
import org.newdawn.slick.MouseListener;
|
||||||
import yugecin.opsudance.core.state.BaseOpsuState;
|
|
||||||
import yugecin.opsudance.core.state.transitions.*;
|
import yugecin.opsudance.core.state.transitions.*;
|
||||||
import yugecin.opsudance.kernel.InstanceContainer;
|
import yugecin.opsudance.kernel.InstanceContainer;
|
||||||
import yugecin.opsudance.core.state.OpsuState;
|
import yugecin.opsudance.core.state.OpsuState;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* state demultiplexer, sends events to current state
|
* state demultiplexer, sends events to current state
|
||||||
*/
|
*/
|
||||||
|
@ -46,24 +49,12 @@ public class Demux implements KeyListener, MouseListener {
|
||||||
public Demux(final InstanceContainer instanceContainer) {
|
public Demux(final InstanceContainer instanceContainer) {
|
||||||
this.instanceContainer = instanceContainer;
|
this.instanceContainer = instanceContainer;
|
||||||
|
|
||||||
state = new BaseOpsuState() {
|
state = (OpsuState) Proxy.newProxyInstance(OpsuState.class.getClassLoader(), new Class[]{OpsuState.class}, new InvocationHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int delta) { }
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public void preRenderUpdate(int delta) { }
|
});
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(Graphics g) { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enter() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void leave() { }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
outTransitionListener = new TransitionFinishedListener() {
|
outTransitionListener = new TransitionFinishedListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,49 @@
|
||||||
*/
|
*/
|
||||||
package yugecin.opsudance.core.state;
|
package yugecin.opsudance.core.state;
|
||||||
|
|
||||||
public abstract class BaseOpsuState implements OpsuState {
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
|
import yugecin.opsudance.core.ResolutionChangeListener;
|
||||||
|
|
||||||
|
public abstract class BaseOpsuState implements OpsuState, ResolutionChangeListener {
|
||||||
|
|
||||||
|
protected final DisplayContainer displayContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* state is dirty when resolution or skin changed but hasn't rendered yet
|
||||||
|
*/
|
||||||
|
private boolean isDirty;
|
||||||
|
private boolean isCurrentState;
|
||||||
|
|
||||||
|
public BaseOpsuState(DisplayContainer displayContainer) {
|
||||||
|
this.displayContainer = displayContainer;
|
||||||
|
displayContainer.addResolutionChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void revalidate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisplayResolutionChanged(int width, int height) {
|
||||||
|
if (isCurrentState) {
|
||||||
|
revalidate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter() {
|
||||||
|
isCurrentState = true;
|
||||||
|
if (isDirty) {
|
||||||
|
revalidate();
|
||||||
|
isDirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leave() {
|
||||||
|
isCurrentState = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCloseRequest() {
|
public boolean onCloseRequest() {
|
||||||
|
|
|
@ -17,8 +17,16 @@
|
||||||
*/
|
*/
|
||||||
package yugecin.opsudance.core.state.transitions;
|
package yugecin.opsudance.core.state.transitions;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
|
|
||||||
public class EmptyTransitionState extends TransitionState {
|
public class EmptyTransitionState extends TransitionState {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public EmptyTransitionState(DisplayContainer displayContainer) {
|
||||||
|
super(displayContainer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -23,12 +23,10 @@ import yugecin.opsudance.core.DisplayContainer;
|
||||||
|
|
||||||
public abstract class FadeTransitionState extends TransitionState {
|
public abstract class FadeTransitionState extends TransitionState {
|
||||||
|
|
||||||
private final DisplayContainer container;
|
|
||||||
|
|
||||||
private final Color black;
|
private final Color black;
|
||||||
|
|
||||||
public FadeTransitionState(DisplayContainer container) {
|
public FadeTransitionState(DisplayContainer displayContainer) {
|
||||||
this.container = container;
|
super(displayContainer);
|
||||||
black = new Color(Color.black);
|
black = new Color(Color.black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ public abstract class FadeTransitionState extends TransitionState {
|
||||||
applicableState.render(g);
|
applicableState.render(g);
|
||||||
black.a = getMaskAlphaLevel((float) transitionTime / transitionTargetTime);
|
black.a = getMaskAlphaLevel((float) transitionTime / transitionTargetTime);
|
||||||
g.setColor(black);
|
g.setColor(black);
|
||||||
g.fillRect(0, 0, container.width, container.height);
|
g.fillRect(0, 0, displayContainer.width, displayContainer.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract float getMaskAlphaLevel(float fadeProgress);
|
protected abstract float getMaskAlphaLevel(float fadeProgress);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package yugecin.opsudance.core.state.transitions;
|
package yugecin.opsudance.core.state.transitions;
|
||||||
|
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
import yugecin.opsudance.core.state.BaseOpsuState;
|
import yugecin.opsudance.core.state.BaseOpsuState;
|
||||||
import yugecin.opsudance.core.state.OpsuState;
|
import yugecin.opsudance.core.state.OpsuState;
|
||||||
|
|
||||||
|
@ -30,6 +31,10 @@ public abstract class TransitionState extends BaseOpsuState {
|
||||||
|
|
||||||
private TransitionFinishedListener listener;
|
private TransitionFinishedListener listener;
|
||||||
|
|
||||||
|
public TransitionState(DisplayContainer displayContainer) {
|
||||||
|
super(displayContainer);
|
||||||
|
}
|
||||||
|
|
||||||
public final TransitionState set(OpsuState applicableState, int targetTime, TransitionFinishedListener listener) {
|
public final TransitionState set(OpsuState applicableState, int targetTime, TransitionFinishedListener listener) {
|
||||||
this.applicableState = applicableState;
|
this.applicableState = applicableState;
|
||||||
this.transitionTargetTime = targetTime;
|
this.transitionTargetTime = targetTime;
|
||||||
|
@ -61,12 +66,10 @@ public abstract class TransitionState extends BaseOpsuState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
super.enter();
|
||||||
transitionTime = 0;
|
transitionTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void leave() { }
|
|
||||||
|
|
||||||
protected final void finish() {
|
protected final void finish() {
|
||||||
listener.onFinish();
|
listener.onFinish();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user