2023-11-07 04:04:22 -05:00
|
|
|
package funkin.play;
|
2020-10-09 17:24:20 -04:00
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
import funkin.play.PlayStatePlaylist;
|
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;
|
2023-11-07 04:04:22 -05:00
|
|
|
import funkin.ui.MusicBeatSubState;
|
2024-02-12 20:06:43 -05:00
|
|
|
import funkin.ui.debug.latency.LatencyState;
|
2023-07-02 15:34:07 -04:00
|
|
|
import flixel.sound.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;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.play.PlayState;
|
2023-09-08 17:46:44 -04:00
|
|
|
import funkin.data.song.SongRegistry;
|
2023-11-07 04:04:22 -05:00
|
|
|
import funkin.ui.Alphabet;
|
2020-10-09 17:24:20 -04:00
|
|
|
|
2023-06-01 18:52:58 -04:00
|
|
|
class PauseSubState extends MusicBeatSubState
|
2020-10-09 17:24:20 -04:00
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
var grpMenuShit:FlxTypedGroup<Alphabet>;
|
|
|
|
|
2024-02-12 20:06:43 -05:00
|
|
|
// todo: maybe make these enums or somethin?
|
2023-10-11 17:33:55 -04:00
|
|
|
final pauseOptionsBase:Array<String> = [
|
2023-01-22 22:25:45 -05:00
|
|
|
'Resume',
|
|
|
|
'Restart Song',
|
|
|
|
'Change Difficulty',
|
|
|
|
'Toggle Practice Mode',
|
2024-02-12 20:06:43 -05:00
|
|
|
'Adjust Input Offsets',
|
2023-06-06 17:38:31 -04:00
|
|
|
'Exit to Menu'
|
2023-01-22 22:25:45 -05:00
|
|
|
];
|
2024-02-12 20:06:43 -05:00
|
|
|
final pauseOptionsCharting:Array<String> = ['Resume', 'Restart Song', 'Adjust Input Offsets', 'Exit to Chart Editor'];
|
2023-07-26 16:52:58 -04:00
|
|
|
|
2023-10-11 17:33:55 -04:00
|
|
|
final pauseOptionsDifficultyBase:Array<String> = ['BACK'];
|
2023-07-26 16:52:58 -04:00
|
|
|
|
2023-10-11 17:33:55 -04:00
|
|
|
var pauseOptionsDifficulty:Array<String> = []; // AUTO-POPULATED
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
var menuItems:Array<String> = [];
|
|
|
|
var curSelected:Int = 0;
|
|
|
|
|
|
|
|
var pauseMusic:FlxSound;
|
|
|
|
|
|
|
|
var practiceText:FlxText;
|
|
|
|
|
2024-02-13 01:38:11 -05:00
|
|
|
public var exitingToMenu:Bool = false;
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var bg:FlxSprite;
|
|
|
|
var metaDataGrp:FlxTypedGroup<FlxSprite>;
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
var isChartingMode:Bool;
|
|
|
|
|
2023-08-28 15:03:29 -04:00
|
|
|
public function new(isChartingMode:Bool = false)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
this.isChartingMode = isChartingMode;
|
|
|
|
|
|
|
|
menuItems = this.isChartingMode ? pauseOptionsCharting : pauseOptionsBase;
|
2023-10-11 17:33:55 -04:00
|
|
|
var difficultiesInVariation = PlayState.instance.currentSong.listDifficulties(PlayState.instance.currentChart.variation);
|
|
|
|
trace('DIFFICULTIES: ${difficultiesInVariation}');
|
|
|
|
|
|
|
|
pauseOptionsDifficulty = difficultiesInVariation.map(function(item:String):String {
|
|
|
|
return item.toUpperCase();
|
|
|
|
}).concat(pauseOptionsDifficultyBase);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
if (PlayStatePlaylist.campaignId == 'week6')
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast-pixel'), true, true);
|
2023-06-06 17:38:31 -04:00
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
else
|
2023-06-06 17:38:31 -04:00
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast'), true, true);
|
2023-06-06 17:38:31 -04:00
|
|
|
}
|
2023-01-22 22:25:45 -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);
|
|
|
|
bg.alpha = 0;
|
|
|
|
bg.scrollFactor.set();
|
|
|
|
add(bg);
|
|
|
|
|
|
|
|
metaDataGrp = new FlxTypedGroup<FlxSprite>();
|
|
|
|
add(metaDataGrp);
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
var levelInfo:FlxText = new FlxText(20, 15, 0, '', 32);
|
2023-01-22 22:25:45 -05:00
|
|
|
if (PlayState.instance.currentChart != null)
|
|
|
|
{
|
|
|
|
levelInfo.text += '${PlayState.instance.currentChart.songName} - ${PlayState.instance.currentChart.songArtist}';
|
|
|
|
}
|
|
|
|
levelInfo.scrollFactor.set();
|
2023-06-06 17:38:31 -04:00
|
|
|
levelInfo.setFormat(Paths.font('vcr.ttf'), 32);
|
2023-01-22 22:25:45 -05:00
|
|
|
levelInfo.updateHitbox();
|
|
|
|
metaDataGrp.add(levelInfo);
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
var levelDifficulty:FlxText = new FlxText(20, 15 + 32, 0, '', 32);
|
|
|
|
levelDifficulty.text += PlayState.instance.currentDifficulty.toTitleCase();
|
2023-01-22 22:25:45 -05:00
|
|
|
levelDifficulty.scrollFactor.set();
|
|
|
|
levelDifficulty.setFormat(Paths.font('vcr.ttf'), 32);
|
|
|
|
levelDifficulty.updateHitbox();
|
|
|
|
metaDataGrp.add(levelDifficulty);
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
var deathCounter:FlxText = new FlxText(20, 15 + 64, 0, '', 32);
|
|
|
|
deathCounter.text = 'Blue balled: ${PlayState.instance.deathCounter}';
|
|
|
|
FlxG.watch.addQuick('totalNotesHit', Highscore.tallies.totalNotesHit);
|
|
|
|
FlxG.watch.addQuick('totalNotes', Highscore.tallies.totalNotes);
|
2023-01-22 22:25:45 -05:00
|
|
|
deathCounter.scrollFactor.set();
|
|
|
|
deathCounter.setFormat(Paths.font('vcr.ttf'), 32);
|
|
|
|
deathCounter.updateHitbox();
|
|
|
|
metaDataGrp.add(deathCounter);
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
practiceText = new FlxText(20, 15 + 64 + 32, 0, 'PRACTICE MODE', 32);
|
2023-01-22 22:25:45 -05:00
|
|
|
practiceText.scrollFactor.set();
|
|
|
|
practiceText.setFormat(Paths.font('vcr.ttf'), 32);
|
|
|
|
practiceText.updateHitbox();
|
|
|
|
practiceText.x = FlxG.width - (practiceText.width + 20);
|
2023-06-06 17:38:31 -04:00
|
|
|
practiceText.visible = PlayState.instance.isPracticeMode;
|
2023-01-22 22:25:45 -05:00
|
|
|
metaDataGrp.add(practiceText);
|
|
|
|
|
|
|
|
levelDifficulty.alpha = 0;
|
|
|
|
levelInfo.alpha = 0;
|
|
|
|
deathCounter.alpha = 0;
|
|
|
|
|
|
|
|
levelInfo.x = FlxG.width - (levelInfo.width + 20);
|
|
|
|
levelDifficulty.x = FlxG.width - (levelDifficulty.width + 20);
|
|
|
|
deathCounter.x = FlxG.width - (deathCounter.width + 20);
|
|
|
|
|
|
|
|
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});
|
|
|
|
FlxTween.tween(deathCounter, {alpha: 1, y: deathCounter.y + 5}, 0.4, {ease: FlxEase.quartInOut, startDelay: 0.7});
|
|
|
|
|
|
|
|
grpMenuShit = new FlxTypedGroup<Alphabet>();
|
|
|
|
add(grpMenuShit);
|
|
|
|
|
|
|
|
regenMenu();
|
|
|
|
|
|
|
|
// cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
function regenMenu():Void
|
|
|
|
{
|
|
|
|
while (grpMenuShit.members.length > 0)
|
|
|
|
{
|
|
|
|
grpMenuShit.remove(grpMenuShit.members[0], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
curSelected = 0;
|
|
|
|
changeSelection();
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
override function update(elapsed:Float):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
if (pauseMusic.volume < 0.5) pauseMusic.volume += 0.01 * elapsed;
|
|
|
|
|
|
|
|
super.update(elapsed);
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
handleInputs();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleInputs():Void
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
var upP = controls.UI_UP_P;
|
|
|
|
var downP = controls.UI_DOWN_P;
|
|
|
|
var accepted = controls.ACCEPT;
|
|
|
|
|
2024-02-13 00:29:46 -05:00
|
|
|
#if (debug || FORCE_DEBUG_VERSION)
|
2023-01-22 22:25:45 -05:00
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
if (upP)
|
|
|
|
{
|
|
|
|
changeSelection(-1);
|
|
|
|
}
|
|
|
|
if (downP)
|
|
|
|
{
|
|
|
|
changeSelection(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var androidPause:Bool = false;
|
|
|
|
|
|
|
|
#if android
|
|
|
|
androidPause = FlxG.android.justPressed.BACK;
|
|
|
|
#end
|
|
|
|
|
|
|
|
if (androidPause) close();
|
|
|
|
|
|
|
|
if (accepted)
|
|
|
|
{
|
|
|
|
var daSelected:String = menuItems[curSelected];
|
|
|
|
|
|
|
|
switch (daSelected)
|
|
|
|
{
|
2023-06-06 17:38:31 -04:00
|
|
|
case 'Resume':
|
2023-01-22 22:25:45 -05:00
|
|
|
close();
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
case 'Change Difficulty':
|
2023-07-26 16:52:58 -04:00
|
|
|
menuItems = pauseOptionsDifficulty;
|
2023-06-06 17:38:31 -04:00
|
|
|
regenMenu();
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
case 'Toggle Practice Mode':
|
|
|
|
PlayState.instance.isPracticeMode = true;
|
|
|
|
practiceText.visible = PlayState.instance.isPracticeMode;
|
|
|
|
|
|
|
|
case 'Restart Song':
|
|
|
|
PlayState.instance.needsReset = true;
|
2023-01-22 22:25:45 -05:00
|
|
|
close();
|
2023-06-06 17:38:31 -04:00
|
|
|
|
|
|
|
case 'Exit to Menu':
|
2023-01-22 22:25:45 -05:00
|
|
|
exitingToMenu = true;
|
2023-06-06 17:38:31 -04:00
|
|
|
PlayState.instance.deathCounter = 0;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
for (item in grpMenuShit.members)
|
|
|
|
{
|
|
|
|
item.targetY = -3;
|
|
|
|
item.alpha = 0.6;
|
|
|
|
}
|
|
|
|
|
2023-04-10 14:44:32 -04:00
|
|
|
FlxTransitionableState.skipNextTransIn = true;
|
|
|
|
FlxTransitionableState.skipNextTransOut = true;
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
if (PlayStatePlaylist.isStoryMode)
|
|
|
|
{
|
2023-11-24 00:42:07 -05:00
|
|
|
PlayStatePlaylist.reset();
|
2024-02-12 23:34:40 -05:00
|
|
|
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.story.StoryMenuState(sticker)));
|
2023-10-17 00:38:28 -04:00
|
|
|
}
|
2023-04-10 14:44:32 -04:00
|
|
|
else
|
2023-10-17 00:38:28 -04:00
|
|
|
{
|
2024-02-05 21:35:58 -05:00
|
|
|
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.freeplay.FreeplayState(null, sticker)));
|
2023-10-17 00:38:28 -04:00
|
|
|
}
|
2024-02-12 20:06:43 -05:00
|
|
|
case 'Adjust Input Offsets':
|
|
|
|
openSubState(new LatencyState());
|
2023-07-26 16:52:58 -04:00
|
|
|
case 'Exit to Chart Editor':
|
|
|
|
this.close();
|
2023-10-18 01:02:10 -04:00
|
|
|
if (FlxG.sound.music != null) FlxG.sound.music.pause(); // Don't reset song position!
|
2023-07-26 16:52:58 -04:00
|
|
|
PlayState.instance.close(); // This only works because PlayState is a substate!
|
2023-10-11 17:33:55 -04:00
|
|
|
|
|
|
|
case 'BACK':
|
|
|
|
menuItems = this.isChartingMode ? pauseOptionsCharting : pauseOptionsBase;
|
|
|
|
regenMenu();
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (pauseOptionsDifficulty.contains(daSelected))
|
|
|
|
{
|
|
|
|
PlayState.instance.currentSong = SongRegistry.instance.fetchEntry(PlayState.instance.currentSong.id.toLowerCase());
|
|
|
|
|
|
|
|
// Reset campaign score when changing difficulty
|
|
|
|
// So if you switch difficulty on the last song of a week you get a really low overall score.
|
|
|
|
PlayStatePlaylist.campaignScore = 0;
|
|
|
|
PlayStatePlaylist.campaignDifficulty = daSelected.toLowerCase();
|
|
|
|
PlayState.instance.currentDifficulty = PlayStatePlaylist.campaignDifficulty;
|
|
|
|
|
|
|
|
PlayState.instance.needsReset = true;
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('[WARN] Unhandled pause menu option: ${daSelected}');
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.J)
|
|
|
|
{
|
|
|
|
// for reference later!
|
|
|
|
// PlayerSettings.player1.controls.replaceBinding(Control.LEFT, Keys, FlxKey.J, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:38:31 -04:00
|
|
|
override function destroy():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
pauseMusic.destroy();
|
|
|
|
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeSelection(change:Int = 0):Void
|
|
|
|
{
|
|
|
|
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
|
|
|
|
|
|
|
|
curSelected += change;
|
|
|
|
|
|
|
|
if (curSelected < 0) curSelected = menuItems.length - 1;
|
|
|
|
if (curSelected >= menuItems.length) curSelected = 0;
|
|
|
|
|
|
|
|
for (index => item in grpMenuShit.members)
|
|
|
|
{
|
|
|
|
item.targetY = index - curSelected;
|
|
|
|
|
|
|
|
item.alpha = 0.6;
|
|
|
|
|
|
|
|
if (item.targetY == 0)
|
|
|
|
{
|
|
|
|
item.alpha = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 17:24:20 -04:00
|
|
|
}
|