new transitions (skippable)

This commit is contained in:
Yoshman29
2023-04-13 19:12:57 +02:00
parent 1825d4b775
commit 50cb615c26
5 changed files with 103 additions and 4 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

+1 -1
View File
@@ -13,7 +13,7 @@ import flixel.FlxState;
*/
class MainState extends FlxState {
public static var initiated:Bool = false;
public static var betaWarningShown:Bool = false;
public static var betaWarningShown:Bool = true;
public override function create() {
super.create();
if (!initiated)
+11 -2
View File
@@ -11,7 +11,7 @@ import funkin.system.interfaces.IBeatReceiver;
import funkin.system.Conductor;
import funkin.options.PlayerSettings;
class MusicBeatState extends FlxTransitionableState implements IBeatReceiver
class MusicBeatState extends FlxState implements IBeatReceiver
{
private var lastBeat:Float = 0;
private var lastStep:Float = 0;
@@ -93,6 +93,9 @@ class MusicBeatState extends FlxTransitionableState implements IBeatReceiver
public var scriptName:String = null;
public var skipTransOut:Bool = true;
public var skipTransIn:Bool = true;
inline function get_controls():Controls
return PlayerSettings.solo.controls;
inline function get_controlsP1():Controls
@@ -150,6 +153,7 @@ class MusicBeatState extends FlxTransitionableState implements IBeatReceiver
super.createPost();
persistentUpdate = true;
call("postCreate");
openSubState(new MusicBeatTransition(null));
}
public function call(name:String, ?args:Array<Dynamic>, ?defaultVal:Dynamic):Dynamic {
// calls the function on the assigned script
@@ -239,7 +243,12 @@ class MusicBeatState extends FlxTransitionableState implements IBeatReceiver
var e = event("onStateSwitch", EventManager.get(StateEvent).recycle(nextState));
if (e.cancelled)
return false;
return super.switchTo(nextState);
if (subState is MusicBeatTransition && cast(subState, MusicBeatTransition).newState != null)
return true;
openSubState(new MusicBeatTransition(nextState));
persistentUpdate = false;
return false;
}
public override function onFocus() {
+3 -1
View File
@@ -250,10 +250,12 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
}
public override function resetSubState() {
super.resetSubState();
if (subState != null && subState is MusicBeatSubstate) {
cast(subState, MusicBeatSubstate).parent = this;
super.resetSubState();
cast(subState, MusicBeatSubstate).onSubstateOpen();
return;
}
super.resetSubState();
}
}
@@ -0,0 +1,88 @@
package funkin.system;
import flixel.tweens.FlxTween;
import flixel.FlxState;
import funkin.utils.FunkinParentDisabler;
class MusicBeatTransition extends MusicBeatSubstate {
var nextFrameSkip:Bool = false;
public var transitionCamera:FlxCamera;
public var newState:FlxState;
public function new(?newState:FlxState) {
super();
this.newState = newState;
}
public override function create() {
super.create();
if (newState != null)
add(new FunkinParentDisabler(true));
transitionCamera = new FlxCamera();
transitionCamera.bgColor = 0;
FlxG.cameras.add(transitionCamera, false);
cameras = [transitionCamera];
var out = newState != null;
var blackSpr = new FlxSprite(0, out ? -transitionCamera.height : transitionCamera.height).makeGraphic(1, 1, -1);
blackSpr.scale.set(transitionCamera.width, transitionCamera.height);
blackSpr.color = 0xFF000000;
blackSpr.updateHitbox();
add(blackSpr);
var transitionSprite = new FunkinSprite();
transitionSprite.loadSprite(Paths.image('menus/transitionSpr'));
if (transitionSprite.animateAtlas == null) {
transitionSprite.setGraphicSize(transitionCamera.width, transitionCamera.height);
transitionSprite.updateHitbox();
} else {
transitionSprite.screenCenter();
}
transitionCamera.flipY = !out;
add(transitionSprite);
transitionCamera.scroll.y = transitionCamera.height;
FlxTween.tween(transitionCamera.scroll, {y: -transitionCamera.height}, 2/3, {
ease: FlxEase.sineOut,
onComplete: function(_) {
finish();
}
});
}
public override function update(elapsed:Float) {
super.update(elapsed);
if (nextFrameSkip) {
finish();
return;
}
if (!parent.persistentUpdate && controls.ACCEPT) {
// skip
if (newState != null) {
nextFrameSkip = true;
parent.persistentDraw = false;
} else {
finish();
}
}
}
public function finish() {
if (newState != null)
FlxG.switchState(newState);
close();
}
public override function destroy() {
if (newState == null && FlxG.cameras.list.contains(transitionCamera))
FlxG.cameras.remove(transitionCamera);
else
transitionCamera.bgColor = 0xFF000000;
super.destroy();
}
}