Funkin/source/funkin/PauseSubState.hx

283 lines
7.2 KiB
Haxe
Raw Normal View History

package funkin;
2020-10-09 17:24:20 -04:00
import flixel.FlxSprite;
2021-02-12 01:20:20 -05:00
import flixel.addons.transition.FlxTransitionableState;
2020-11-17 20:50:09 -05:00
import flixel.group.FlxGroup.FlxTypedGroup;
2020-11-20 07:21:04 -05:00
import flixel.system.FlxSound;
2021-03-01 23:00:02 -05:00
import flixel.text.FlxText;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
2020-10-09 17:24:20 -04:00
import flixel.util.FlxColor;
import funkin.play.PlayState;
2022-09-22 06:34:03 -04:00
import funkin.play.song.SongData.SongDataParser;
2020-10-09 17:24:20 -04:00
2020-11-17 20:50:09 -05:00
class PauseSubState extends MusicBeatSubstate
2020-10-09 17:24:20 -04:00
{
2020-11-17 20:50:09 -05:00
var grpMenuShit:FlxTypedGroup<Alphabet>;
2021-03-08 18:38:58 -05:00
var pauseOG:Array<String> = [
'Resume',
'Restart Song',
'Change Difficulty',
'Toggle Practice Mode',
'Exit to menu'
];
2021-03-07 15:34:21 -05:00
var difficultyChoices:Array<String> = ['EASY', 'NORMAL', 'HARD', 'BACK'];
var menuItems:Array<String> = [];
2020-11-17 20:50:09 -05:00
var curSelected:Int = 0;
2020-11-20 07:21:04 -05:00
var pauseMusic:FlxSound;
2021-03-08 18:38:58 -05:00
var practiceText:FlxText;
var exitingToMenu:Bool = false;
var bg:FlxSprite;
2022-04-18 13:53:48 -04:00
var metaDataGrp:FlxTypedGroup<FlxSprite>;
2020-10-27 06:35:23 -04:00
public function new(x:Float, y:Float)
2020-10-09 17:24:20 -04:00
{
super();
2020-11-20 07:21:04 -05:00
2021-03-07 15:34:21 -05:00
menuItems = pauseOG;
2022-03-23 14:29:02 -04:00
if (PlayState.storyWeek == 6) // consistent with logic that decides asset lib!!
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast-pixel'), true, true);
else
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast'), true, true);
2020-11-20 07:21:04 -05:00
pauseMusic.volume = 0;
pauseMusic.play(false, FlxG.random.int(0, Std.int(pauseMusic.length / 2)));
FlxG.sound.list.add(pauseMusic);
bg = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
2021-03-01 23:00:02 -05:00
bg.alpha = 0;
2020-10-09 17:24:20 -04:00
bg.scrollFactor.set();
add(bg);
2022-04-18 13:53:48 -04:00
metaDataGrp = new FlxTypedGroup<FlxSprite>();
add(metaDataGrp);
2021-03-01 23:00:02 -05:00
var levelInfo:FlxText = new FlxText(20, 15, 0, "", 32);
2022-09-22 06:34:03 -04:00
if (PlayState.instance.currentChart != null)
{
levelInfo.text += '${PlayState.instance.currentChart.songName} - ${PlayState.instance.currentChart.songArtist}';
}
else
{
levelInfo.text += PlayState.currentSong.song;
}
2021-03-01 23:00:02 -05:00
levelInfo.scrollFactor.set();
levelInfo.setFormat(Paths.font("vcr.ttf"), 32);
levelInfo.updateHitbox();
2022-04-18 13:53:48 -04:00
metaDataGrp.add(levelInfo);
var levelDifficulty:FlxText = new FlxText(20, 15 + 32, 0, "", 32);
levelDifficulty.text += CoolUtil.difficultyString();
levelDifficulty.scrollFactor.set();
levelDifficulty.setFormat(Paths.font('vcr.ttf'), 32);
levelDifficulty.updateHitbox();
2022-04-18 13:53:48 -04:00
metaDataGrp.add(levelDifficulty);
2021-03-04 14:30:35 -05:00
var deathCounter:FlxText = new FlxText(20, 15 + 64, 0, "", 32);
deathCounter.text = "Blue balled: " + PlayState.deathCounter;
deathCounter.scrollFactor.set();
deathCounter.setFormat(Paths.font('vcr.ttf'), 32);
deathCounter.updateHitbox();
2022-04-18 13:53:48 -04:00
metaDataGrp.add(deathCounter);
2021-03-04 14:30:35 -05:00
2021-03-08 18:38:58 -05:00
practiceText = new FlxText(20, 15 + 64 + 32, 0, "PRACTICE MODE", 32);
practiceText.scrollFactor.set();
practiceText.setFormat(Paths.font('vcr.ttf'), 32);
practiceText.updateHitbox();
practiceText.x = FlxG.width - (practiceText.width + 20);
practiceText.visible = PlayState.isPracticeMode;
2022-04-18 13:53:48 -04:00
metaDataGrp.add(practiceText);
2021-03-08 18:38:58 -05:00
levelDifficulty.alpha = 0;
2021-03-01 23:00:02 -05:00
levelInfo.alpha = 0;
2021-03-04 14:30:35 -05:00
deathCounter.alpha = 0;
2021-03-01 23:00:02 -05:00
levelInfo.x = FlxG.width - (levelInfo.width + 20);
levelDifficulty.x = FlxG.width - (levelDifficulty.width + 20);
2021-03-04 14:30:35 -05:00
deathCounter.x = FlxG.width - (deathCounter.width + 20);
2021-03-01 23:00:02 -05:00
FlxTween.tween(bg, {alpha: 0.6}, 0.4, {ease: FlxEase.quartInOut});
FlxTween.tween(levelInfo, {alpha: 1, y: 20}, 0.4, {ease: FlxEase.quartInOut, startDelay: 0.3});
FlxTween.tween(levelDifficulty, {alpha: 1, y: levelDifficulty.y + 5}, 0.4, {ease: FlxEase.quartInOut, startDelay: 0.5});
2021-03-04 14:30:35 -05:00
FlxTween.tween(deathCounter, {alpha: 1, y: deathCounter.y + 5}, 0.4, {ease: FlxEase.quartInOut, startDelay: 0.7});
2021-03-01 23:00:02 -05:00
2020-11-17 20:50:09 -05:00
grpMenuShit = new FlxTypedGroup<Alphabet>();
add(grpMenuShit);
2021-03-07 15:34:21 -05:00
regenMenu();
2021-03-13 23:41:29 -05:00
// cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
2021-03-07 15:34:21 -05:00
}
private function regenMenu():Void
{
2021-03-08 18:38:58 -05:00
while (grpMenuShit.members.length > 0)
2021-03-07 15:34:21 -05:00
{
2021-03-08 18:38:58 -05:00
grpMenuShit.remove(grpMenuShit.members[0], true);
}
2021-03-07 15:34:21 -05:00
2020-11-17 20:50:09 -05:00
for (i in 0...menuItems.length)
{
var songText:Alphabet = new Alphabet(0, (70 * i) + 30, menuItems[i], true, false);
songText.isMenuItem = true;
songText.targetY = i;
grpMenuShit.add(songText);
}
2020-10-27 06:35:23 -04:00
2021-03-07 15:34:21 -05:00
curSelected = 0;
2020-11-17 20:50:09 -05:00
changeSelection();
2020-10-09 17:24:20 -04:00
}
override function update(elapsed:Float)
{
2020-11-20 07:21:04 -05:00
if (pauseMusic.volume < 0.5)
pauseMusic.volume += 0.01 * elapsed;
2020-10-09 17:24:20 -04:00
super.update(elapsed);
2021-03-13 21:11:56 -05:00
var upP = controls.UI_UP_P;
var downP = controls.UI_DOWN_P;
2020-11-17 20:50:09 -05:00
var accepted = controls.ACCEPT;
2022-04-18 13:53:48 -04:00
#if debug
// to pause the game and get screenshots easy, press H on pause menu!
if (FlxG.keys.justPressed.H)
{
bg.visible = !bg.visible;
grpMenuShit.visible = !grpMenuShit.visible;
metaDataGrp.visible = !metaDataGrp.visible;
}
#end
if (!exitingToMenu)
2020-11-17 20:50:09 -05:00
{
if (upP)
{
changeSelection(-1);
}
if (downP)
{
changeSelection(1);
}
2021-08-22 16:54:22 -04:00
var androidPause:Bool = false;
2021-08-22 16:54:22 -04:00
#if android
androidPause = FlxG.android.justPressed.BACK;
#end
2021-08-22 16:54:22 -04:00
if (androidPause)
close();
2020-11-17 20:50:09 -05:00
if (accepted)
2020-11-17 20:50:09 -05:00
{
var daSelected:String = menuItems[curSelected];
switch (daSelected)
{
case "Resume":
close();
case "EASY" | 'NORMAL' | "HARD":
PlayState.currentSong = SongLoad.loadFromJson(PlayState.currentSong.song.toLowerCase(), PlayState.currentSong.song.toLowerCase());
2022-09-22 06:34:03 -04:00
PlayState.currentSong_NEW = SongDataParser.fetchSong(PlayState.currentSong.song.toLowerCase());
SongLoad.curDiff = daSelected.toLowerCase();
PlayState.storyDifficulty = curSelected;
2022-09-22 06:34:03 -04:00
PlayState.storyDifficulty_NEW = 'easy';
PlayState.needsReset = true;
close();
case 'Toggle Practice Mode':
PlayState.isPracticeMode = !PlayState.isPracticeMode;
practiceText.visible = PlayState.isPracticeMode;
case 'Change Difficulty':
menuItems = difficultyChoices;
regenMenu();
case 'BACK':
menuItems = pauseOG;
regenMenu();
case "Restart Song":
PlayState.needsReset = true;
close();
// FlxG.resetState();
case "Exit to menu":
exitingToMenu = true;
PlayState.seenCutscene = false;
PlayState.deathCounter = 0;
for (item in grpMenuShit.members)
{
item.targetY = -3;
item.alpha = 0.6;
}
FlxTween.tween(bg, {alpha: 1}, 0.4, {
ease: FlxEase.quartInOut,
onComplete: function(_)
{
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
FlxG.cameras.list[1].alpha = 0; // bullshit for the UI camera???
if (PlayState.isStoryMode)
FlxG.switchState(new StoryMenuState());
else
FlxG.switchState(new FreeplayState());
}
});
}
2020-11-17 20:50:09 -05:00
}
if (FlxG.keys.justPressed.J)
{
// for reference later!
// PlayerSettings.player1.controls.replaceBinding(Control.LEFT, Keys, FlxKey.J, null);
}
2020-10-21 20:22:12 -04:00
}
2020-11-17 20:50:09 -05:00
}
2020-11-20 07:21:04 -05:00
override function destroy()
{
pauseMusic.destroy();
super.destroy();
}
2020-11-17 20:50:09 -05:00
function changeSelection(change:Int = 0):Void
{
2021-04-08 20:56:17 -04:00
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
2020-11-17 20:50:09 -05:00
curSelected += change;
2020-10-21 20:22:12 -04:00
2020-11-17 20:50:09 -05:00
if (curSelected < 0)
curSelected = menuItems.length - 1;
if (curSelected >= menuItems.length)
curSelected = 0;
for (index => item in grpMenuShit.members)
2020-11-17 20:50:09 -05:00
{
item.targetY = index - curSelected;
2020-11-17 20:50:09 -05:00
item.alpha = 0.6;
// item.setGraphicSize(Std.int(item.width * 0.8));
if (item.targetY == 0)
{
item.alpha = 1;
// item.setGraphicSize(Std.int(item.width));
}
}
2020-10-09 17:24:20 -04:00
}
}