1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-27 07:27:12 +00:00
Funkin/source/funkin/ui/freeplay/backcards/BackingCard.hx
2024-08-30 01:02:32 +01:00

250 lines
6.8 KiB
Haxe

package funkin.ui.freeplay.backcards;
import funkin.ui.freeplay.FreeplayState;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.group.FlxGroup;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.math.FlxAngle;
import flixel.math.FlxPoint;
import flixel.text.FlxText;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxSpriteUtil;
import flixel.util.FlxTimer;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.ui.freeplay.charselect.PlayableCharacter;
import funkin.ui.MusicBeatSubState;
import lime.utils.Assets;
import openfl.display.BlendMode;
import flixel.group.FlxSpriteGroup;
/**
* A class for the backing cards so they dont have to be part of freeplayState......
*/
class BackingCard extends FlxSpriteGroup
{
public var backingTextYeah:FlxAtlasSprite;
public var orangeBackShit:FunkinSprite;
public var alsoOrangeLOL:FunkinSprite;
public var pinkBack:FunkinSprite;
public var confirmGlow:FlxSprite;
public var confirmGlow2:FlxSprite;
public var confirmTextGlow:FlxSprite;
public var cardGlow:FlxSprite;
var _exitMovers:Null<FreeplayState.ExitMoverData>;
var _exitMoversCharSel:Null<FreeplayState.ExitMoverData>;
public var instance:FreeplayState;
public function new(currentCharacter:PlayableCharacter, ?_instance:FreeplayState)
{
super();
if (_instance != null) instance = _instance;
cardGlow = new FlxSprite(-30, -30).loadGraphic(Paths.image('freeplay/cardGlow'));
confirmGlow = new FlxSprite(-30, 240).loadGraphic(Paths.image('freeplay/confirmGlow'));
confirmTextGlow = new FlxSprite(-8, 115).loadGraphic(Paths.image('freeplay/glowingText'));
pinkBack = FunkinSprite.create('freeplay/pinkBack');
orangeBackShit = new FunkinSprite(84, 440).makeSolidColor(Std.int(pinkBack.width), 75, 0xFFFEDA00);
alsoOrangeLOL = new FunkinSprite(0, orangeBackShit.y).makeSolidColor(100, Std.int(orangeBackShit.height), 0xFFFFD400);
confirmGlow2 = new FlxSprite(confirmGlow.x, confirmGlow.y).loadGraphic(Paths.image('freeplay/confirmGlow2'));
backingTextYeah = new FlxAtlasSprite(640, 370, Paths.animateAtlas("freeplay/backing-text-yeah"),
{
FrameRate: 24.0,
Reversed: false,
// ?OnComplete:Void -> Void,
ShowPivot: false,
Antialiasing: true,
ScrollFactor: new FlxPoint(1, 1),
});
pinkBack.color = 0xFFFFD4E9; // sets it to pink!
pinkBack.x -= pinkBack.width;
}
/**
* Apply exit movers for the pieces of the backing card.
* @param exitMovers The exit movers to apply.
*/
public function applyExitMovers(?exitMovers:FreeplayState.ExitMoverData, ?exitMoversCharSel:FreeplayState.ExitMoverData):Void
{
if (exitMovers == null)
{
exitMovers = _exitMovers;
}
else
{
_exitMovers = exitMovers;
}
if (exitMovers == null) return;
if (exitMoversCharSel == null)
{
exitMoversCharSel = _exitMoversCharSel;
}
else
{
_exitMoversCharSel = exitMoversCharSel;
}
if (exitMoversCharSel == null) return;
exitMovers.set([pinkBack, orangeBackShit, alsoOrangeLOL],
{
x: -pinkBack.width,
y: pinkBack.y,
speed: 0.4,
wait: 0
});
exitMoversCharSel.set([pinkBack],
{
y: -100,
speed: 0.8,
wait: 0.1
});
exitMoversCharSel.set([orangeBackShit, alsoOrangeLOL],
{
y: -40,
speed: 0.8,
wait: 0.1
});
}
/**
* Helper function to snap the back of the card to its final position.
* Used when returning from character select, as we dont want to play the full animation of everything sliding in.
*/
public function skipIntroTween():Void
{
FlxTween.cancelTweensOf(pinkBack);
pinkBack.x = 0;
}
/**
* Called in create. Adds sprites and tweens.
*/
public function init():Void
{
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
add(orangeBackShit);
add(alsoOrangeLOL);
FlxSpriteUtil.alphaMaskFlxSprite(orangeBackShit, pinkBack, orangeBackShit);
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
confirmTextGlow.blend = BlendMode.ADD;
confirmTextGlow.visible = false;
confirmGlow.blend = BlendMode.ADD;
confirmGlow.visible = false;
confirmGlow2.visible = false;
add(confirmGlow2);
add(confirmGlow);
add(confirmTextGlow);
add(backingTextYeah);
cardGlow.blend = BlendMode.ADD;
cardGlow.visible = false;
add(cardGlow);
}
/**
* Called after the dj finishes their start animation.
*/
public function introDone():Void
{
pinkBack.color = 0xFFFFD863;
orangeBackShit.visible = true;
alsoOrangeLOL.visible = true;
cardGlow.visible = true;
FlxTween.tween(cardGlow, {alpha: 0, "scale.x": 1.2, "scale.y": 1.2}, 0.45, {ease: FlxEase.sineOut});
}
/**
* Called when selecting a song.
*/
public function confirm():Void
{
FlxTween.color(pinkBack, 0.33, 0xFFFFD0D5, 0xFF171831, {ease: FlxEase.quadOut});
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
confirmGlow.visible = true;
confirmGlow2.visible = true;
backingTextYeah.anim.play("");
confirmGlow2.alpha = 0;
confirmGlow.alpha = 0;
FlxTween.color(instance.bgDad, 0.5, 0xFFA8A8A8, 0xFF646464,
{
onUpdate: function(_) {
instance.angleMaskShader.extraColor = instance.bgDad.color;
}
});
FlxTween.tween(confirmGlow2, {alpha: 0.5}, 0.33,
{
ease: FlxEase.quadOut,
onComplete: function(_) {
confirmGlow2.alpha = 0.6;
confirmGlow.alpha = 1;
confirmTextGlow.visible = true;
confirmTextGlow.alpha = 1;
FlxTween.tween(confirmTextGlow, {alpha: 0.4}, 0.5);
FlxTween.tween(confirmGlow, {alpha: 0}, 0.5);
FlxTween.color(instance.bgDad, 2, 0xFFCDCDCD, 0xFF555555,
{
ease: FlxEase.expoOut,
onUpdate: function(_) {
instance.angleMaskShader.extraColor = instance.bgDad.color;
}
});
}
});
}
/**
* Called when entering character select, does nothing by default.
*/
public function enterCharSel():Void {}
/**
* Called on each beat in freeplay state.
*/
public function beatHit():Void {}
/**
* Called when exiting the freeplay menu.
*/
public function disappear():Void
{
FlxTween.color(pinkBack, 0.25, 0xFFFFD863, 0xFFFFD0D5, {ease: FlxEase.quadOut});
cardGlow.visible = true;
cardGlow.alpha = 1;
cardGlow.scale.set(1, 1);
FlxTween.tween(cardGlow, {alpha: 0, "scale.x": 1.2, "scale.y": 1.2}, 0.25, {ease: FlxEase.sineOut});
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
}
}