improve transition base
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.core.state.transitions;
|
||||
|
||||
public class EmptyTransitionState extends TransitionState {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,17 +18,13 @@
|
||||
package yugecin.opsudance.core.state.transitions;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import yugecin.opsudance.core.Demux;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
|
||||
public class FadeInTransitionState extends FadeTransitionState {
|
||||
|
||||
private final Demux demux;
|
||||
|
||||
@Inject
|
||||
public FadeInTransitionState(DisplayContainer container, Demux demux) {
|
||||
super(container, 300);
|
||||
this.demux = demux;
|
||||
public FadeInTransitionState(DisplayContainer container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,15 +32,4 @@ public class FadeInTransitionState extends FadeTransitionState {
|
||||
return 1f - fadeProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
super.enter();
|
||||
applicableState.enter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTransitionFinished() {
|
||||
demux.switchStateNow(applicableState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,13 @@
|
||||
package yugecin.opsudance.core.state.transitions;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import yugecin.opsudance.core.Demux;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
|
||||
public class FadeOutTransitionState extends FadeTransitionState {
|
||||
|
||||
private final Demux demux;
|
||||
private final FadeInTransitionState fadeInTransitionState;
|
||||
|
||||
@Inject
|
||||
public FadeOutTransitionState(DisplayContainer container, Demux demux, FadeInTransitionState fadeInTransitionState) {
|
||||
super(container, 200);
|
||||
this.demux = demux;
|
||||
this.fadeInTransitionState = fadeInTransitionState;
|
||||
public FadeOutTransitionState(DisplayContainer container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,11 +32,4 @@ public class FadeOutTransitionState extends FadeTransitionState {
|
||||
return fadeProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTransitionFinished() {
|
||||
applicableState.leave();
|
||||
demux.switchStateNow(fadeInTransitionState);
|
||||
fadeInTransitionState.enter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,55 +20,26 @@ package yugecin.opsudance.core.state.transitions;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.state.OpsuState;
|
||||
|
||||
public abstract class FadeTransitionState extends TransitionState {
|
||||
|
||||
protected OpsuState applicableState;
|
||||
|
||||
private final DisplayContainer container;
|
||||
|
||||
protected final int fadeTargetTime;
|
||||
protected int fadeTime;
|
||||
|
||||
private final Color black;
|
||||
|
||||
public FadeTransitionState(DisplayContainer container, int fadeTargetTime) {
|
||||
super(fadeTargetTime);
|
||||
public FadeTransitionState(DisplayContainer container) {
|
||||
this.container = container;
|
||||
this.fadeTargetTime = fadeTargetTime;
|
||||
black = new Color(Color.black);
|
||||
}
|
||||
|
||||
public void setApplicableState(OpsuState 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);
|
||||
black.a = getMaskAlphaLevel((float) transitionTime / transitionTargetTime);
|
||||
g.setColor(black);
|
||||
g.fillRect(0, 0, container.width, container.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
fadeTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() { }
|
||||
|
||||
protected abstract float getMaskAlphaLevel(float fadeProgress);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.core.state.transitions;
|
||||
|
||||
public interface TransitionFinishedListener {
|
||||
|
||||
void onFinish();
|
||||
|
||||
}
|
||||
@@ -25,15 +25,20 @@ public abstract class TransitionState extends BaseOpsuState {
|
||||
|
||||
protected OpsuState applicableState;
|
||||
|
||||
protected final int transitionTargetTime;
|
||||
protected int transitionTargetTime;
|
||||
protected int transitionTime;
|
||||
|
||||
public TransitionState(int transitionTargetTime) {
|
||||
this.transitionTargetTime = transitionTargetTime;
|
||||
private TransitionFinishedListener listener;
|
||||
|
||||
public final TransitionState set(OpsuState applicableState, int targetTime, TransitionFinishedListener listener) {
|
||||
this.applicableState = applicableState;
|
||||
this.transitionTargetTime = targetTime;
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setApplicableState(OpsuState applicableState) {
|
||||
this.applicableState = applicableState;
|
||||
public final OpsuState getApplicableState() {
|
||||
return applicableState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +46,7 @@ public abstract class TransitionState extends BaseOpsuState {
|
||||
applicableState.update(delta);
|
||||
transitionTime += delta;
|
||||
if (transitionTime >= transitionTargetTime) {
|
||||
onTransitionFinished();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +67,8 @@ public abstract class TransitionState extends BaseOpsuState {
|
||||
@Override
|
||||
public void leave() { }
|
||||
|
||||
protected abstract void onTransitionFinished();
|
||||
protected final void finish() {
|
||||
listener.onFinish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user