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.Demux;
|
||||
|
||||
public class FadeInTransitionState extends TransitionState {
|
||||
public class FadeInTransitionState extends FadeTransitionState {
|
||||
|
||||
private final Demux demux;
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class FadeInTransitionState extends TransitionState {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected float getMaskAlphaLevel() {
|
||||
return 1f - (float) fadeTime / fadeTargetTime;
|
||||
protected float getMaskAlphaLevel(float fadeProgress) {
|
||||
return 1f - fadeProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +43,7 @@ public class FadeInTransitionState extends TransitionState {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onFadeFinished() {
|
||||
protected void onTransitionFinished() {
|
||||
demux.switchStateNow(applicableState);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.google.inject.Inject;
|
|||
import yugecin.opsudance.core.Container;
|
||||
import yugecin.opsudance.core.Demux;
|
||||
|
||||
public class FadeOutTransitionState extends TransitionState {
|
||||
public class FadeOutTransitionState extends FadeTransitionState {
|
||||
|
||||
private final Demux demux;
|
||||
private final FadeInTransitionState fadeInTransitionState;
|
||||
|
@ -34,14 +34,15 @@ public class FadeOutTransitionState extends TransitionState {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected float getMaskAlphaLevel() {
|
||||
return (float) fadeTime / fadeTargetTime;
|
||||
protected float getMaskAlphaLevel(float fadeProgress) {
|
||||
return fadeProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFadeFinished() {
|
||||
protected void onTransitionFinished() {
|
||||
applicableState.leave();
|
||||
demux.switchStateNow(fadeInTransitionState);
|
||||
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;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import yugecin.opsudance.core.Container;
|
||||
import yugecin.opsudance.states.GameState;
|
||||
|
||||
public abstract class TransitionState implements GameState {
|
||||
|
||||
protected GameState applicableState;
|
||||
|
||||
private final Container container;
|
||||
protected final int transitionTargetTime;
|
||||
protected int transitionTime;
|
||||
|
||||
protected final int fadeTargetTime;
|
||||
protected int fadeTime;
|
||||
|
||||
private final Color black;
|
||||
|
||||
public TransitionState(Container container, int fadeTargetTime) {
|
||||
this.container = container;
|
||||
this.fadeTargetTime = fadeTargetTime;
|
||||
black = new Color(Color.black);
|
||||
public TransitionState(int transitionTargetTime) {
|
||||
this.transitionTargetTime = transitionTargetTime;
|
||||
}
|
||||
|
||||
public void setApplicableState(GameState applicableState) {
|
||||
|
@ -46,29 +38,25 @@ public abstract class TransitionState implements GameState {
|
|||
@Override
|
||||
public void update(int delta) {
|
||||
applicableState.update(delta);
|
||||
fadeTime += delta;
|
||||
if (fadeTime >= fadeTargetTime) {
|
||||
onFadeFinished();
|
||||
transitionTime += delta;
|
||||
if (transitionTime >= transitionTargetTime) {
|
||||
onTransitionFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics g) {
|
||||
applicableState.render(g);
|
||||
black.a = getMaskAlphaLevel();
|
||||
g.setColor(black);
|
||||
g.fillRect(0, 0, container.getWidth(), container.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
fadeTime = 0;
|
||||
transitionTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() { }
|
||||
|
||||
protected abstract float getMaskAlphaLevel();
|
||||
protected abstract void onFadeFinished();
|
||||
protected abstract void onTransitionFinished();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user