more oop shit for state transitions
This commit is contained in:
parent
6d8f48a03f
commit
31a25b297f
|
@ -21,7 +21,7 @@ import com.google.inject.Inject;
|
||||||
import yugecin.opsudance.core.Container;
|
import yugecin.opsudance.core.Container;
|
||||||
import yugecin.opsudance.core.Demux;
|
import yugecin.opsudance.core.Demux;
|
||||||
|
|
||||||
public class FadeInTransitionState extends TransitionState {
|
public class FadeInTransitionState extends FadeTransitionState {
|
||||||
|
|
||||||
private final Demux demux;
|
private final Demux demux;
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class FadeInTransitionState extends TransitionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getMaskAlphaLevel() {
|
protected float getMaskAlphaLevel(float fadeProgress) {
|
||||||
return 1f - (float) fadeTime / fadeTargetTime;
|
return 1f - fadeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,7 +43,7 @@ public class FadeInTransitionState extends TransitionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFadeFinished() {
|
protected void onTransitionFinished() {
|
||||||
demux.switchStateNow(applicableState);
|
demux.switchStateNow(applicableState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.google.inject.Inject;
|
||||||
import yugecin.opsudance.core.Container;
|
import yugecin.opsudance.core.Container;
|
||||||
import yugecin.opsudance.core.Demux;
|
import yugecin.opsudance.core.Demux;
|
||||||
|
|
||||||
public class FadeOutTransitionState extends TransitionState {
|
public class FadeOutTransitionState extends FadeTransitionState {
|
||||||
|
|
||||||
private final Demux demux;
|
private final Demux demux;
|
||||||
private final FadeInTransitionState fadeInTransitionState;
|
private final FadeInTransitionState fadeInTransitionState;
|
||||||
|
@ -34,14 +34,15 @@ public class FadeOutTransitionState extends TransitionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getMaskAlphaLevel() {
|
protected float getMaskAlphaLevel(float fadeProgress) {
|
||||||
return (float) fadeTime / fadeTargetTime;
|
return fadeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFadeFinished() {
|
protected void onTransitionFinished() {
|
||||||
applicableState.leave();
|
applicableState.leave();
|
||||||
demux.switchStateNow(fadeInTransitionState);
|
demux.switchStateNow(fadeInTransitionState);
|
||||||
fadeInTransitionState.enter();
|
fadeInTransitionState.enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* opsu!dance - fork of opsu! with cursordance auto
|
||||||
|
* Copyright (C) 2017 yugecin
|
||||||
|
*
|
||||||
|
* opsu!dance is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* opsu!dance is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package yugecin.opsudance.states.transitions;
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.Graphics;
|
||||||
|
import yugecin.opsudance.core.Container;
|
||||||
|
import yugecin.opsudance.states.GameState;
|
||||||
|
|
||||||
|
public abstract class FadeTransitionState extends TransitionState {
|
||||||
|
|
||||||
|
protected GameState applicableState;
|
||||||
|
|
||||||
|
private final Container container;
|
||||||
|
|
||||||
|
protected final int fadeTargetTime;
|
||||||
|
protected int fadeTime;
|
||||||
|
|
||||||
|
private final Color black;
|
||||||
|
|
||||||
|
public FadeTransitionState(Container container, int fadeTargetTime) {
|
||||||
|
super(fadeTargetTime);
|
||||||
|
this.container = container;
|
||||||
|
this.fadeTargetTime = fadeTargetTime;
|
||||||
|
black = new Color(Color.black);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicableState(GameState applicableState) {
|
||||||
|
this.applicableState = applicableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(int delta) {
|
||||||
|
applicableState.update(delta);
|
||||||
|
fadeTime += delta;
|
||||||
|
if (fadeTime >= fadeTargetTime) {
|
||||||
|
onTransitionFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Graphics g) {
|
||||||
|
applicableState.render(g);
|
||||||
|
black.a = getMaskAlphaLevel((float) fadeTime / fadeTargetTime);
|
||||||
|
g.setColor(black);
|
||||||
|
g.fillRect(0, 0, container.getWidth(), container.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter() {
|
||||||
|
fadeTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leave() { }
|
||||||
|
|
||||||
|
protected abstract float getMaskAlphaLevel(float fadeProgress);
|
||||||
|
|
||||||
|
}
|
|
@ -17,26 +17,18 @@
|
||||||
*/
|
*/
|
||||||
package yugecin.opsudance.states.transitions;
|
package yugecin.opsudance.states.transitions;
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
import yugecin.opsudance.core.Container;
|
|
||||||
import yugecin.opsudance.states.GameState;
|
import yugecin.opsudance.states.GameState;
|
||||||
|
|
||||||
public abstract class TransitionState implements GameState {
|
public abstract class TransitionState implements GameState {
|
||||||
|
|
||||||
protected GameState applicableState;
|
protected GameState applicableState;
|
||||||
|
|
||||||
private final Container container;
|
protected final int transitionTargetTime;
|
||||||
|
protected int transitionTime;
|
||||||
|
|
||||||
protected final int fadeTargetTime;
|
public TransitionState(int transitionTargetTime) {
|
||||||
protected int fadeTime;
|
this.transitionTargetTime = transitionTargetTime;
|
||||||
|
|
||||||
private final Color black;
|
|
||||||
|
|
||||||
public TransitionState(Container container, int fadeTargetTime) {
|
|
||||||
this.container = container;
|
|
||||||
this.fadeTargetTime = fadeTargetTime;
|
|
||||||
black = new Color(Color.black);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicableState(GameState applicableState) {
|
public void setApplicableState(GameState applicableState) {
|
||||||
|
@ -46,29 +38,25 @@ public abstract class TransitionState implements GameState {
|
||||||
@Override
|
@Override
|
||||||
public void update(int delta) {
|
public void update(int delta) {
|
||||||
applicableState.update(delta);
|
applicableState.update(delta);
|
||||||
fadeTime += delta;
|
transitionTime += delta;
|
||||||
if (fadeTime >= fadeTargetTime) {
|
if (transitionTime >= transitionTargetTime) {
|
||||||
onFadeFinished();
|
onTransitionFinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Graphics g) {
|
public void render(Graphics g) {
|
||||||
applicableState.render(g);
|
applicableState.render(g);
|
||||||
black.a = getMaskAlphaLevel();
|
|
||||||
g.setColor(black);
|
|
||||||
g.fillRect(0, 0, container.getWidth(), container.getHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
fadeTime = 0;
|
transitionTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leave() { }
|
public void leave() { }
|
||||||
|
|
||||||
protected abstract float getMaskAlphaLevel();
|
protected abstract void onTransitionFinished();
|
||||||
protected abstract void onFadeFinished();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user