1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-09 16:24:42 +00:00
Funkin/source/PauseSubState.hx

234 lines
5.7 KiB
Haxe
Raw Normal View History

2020-10-09 21:24:20 +00:00
package;
2020-10-22 00:22:12 +00:00
import Controls.Control;
2020-10-09 21:24:20 +00:00
import flixel.FlxSprite;
import flixel.FlxSubState;
2021-02-12 06:20:20 +00:00
import flixel.addons.transition.FlxTransitionableState;
2020-11-18 01:50:09 +00:00
import flixel.group.FlxGroup.FlxTypedGroup;
2020-10-22 00:22:12 +00:00
import flixel.input.keyboard.FlxKey;
2020-11-20 12:21:04 +00:00
import flixel.system.FlxSound;
2021-03-02 04:00:02 +00:00
import flixel.text.FlxText;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
2020-10-09 21:24:20 +00:00
import flixel.util.FlxColor;
2020-11-18 01:50:09 +00:00
class PauseSubState extends MusicBeatSubstate
2020-10-09 21:24:20 +00:00
{
2020-11-18 01:50:09 +00:00
var grpMenuShit:FlxTypedGroup<Alphabet>;
2021-03-08 23:38:58 +00:00
var pauseOG:Array<String> = [
'Resume',
'Restart Song',
'Change Difficulty',
'Toggle Practice Mode',
'Exit to menu'
];
2021-03-07 20:34:21 +00:00
var difficultyChoices:Array<String> = ['EASY', 'NORMAL', 'HARD', 'BACK'];
var menuItems:Array<String> = [];
2020-11-18 01:50:09 +00:00
var curSelected:Int = 0;
2020-11-20 12:21:04 +00:00
var pauseMusic:FlxSound;
2021-03-08 23:38:58 +00:00
var practiceText:FlxText;
2020-10-27 10:35:23 +00:00
public function new(x:Float, y:Float)
2020-10-09 21:24:20 +00:00
{
super();
2020-11-20 12:21:04 +00:00
2021-03-07 20:34:21 +00:00
menuItems = pauseOG;
2021-02-08 21:34:48 +00:00
pauseMusic = new FlxSound().loadEmbedded(Paths.music('breakfast'), true, true);
2020-11-20 12:21:04 +00:00
pauseMusic.volume = 0;
pauseMusic.play(false, FlxG.random.int(0, Std.int(pauseMusic.length / 2)));
FlxG.sound.list.add(pauseMusic);
2020-10-09 21:24:20 +00:00
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
2021-03-02 04:00:02 +00:00
bg.alpha = 0;
2020-10-09 21:24:20 +00:00
bg.scrollFactor.set();
add(bg);
2021-03-02 04:00:02 +00:00
var levelInfo:FlxText = new FlxText(20, 15, 0, "", 32);
levelInfo.text += PlayState.SONG.song;
levelInfo.scrollFactor.set();
levelInfo.setFormat(Paths.font("vcr.ttf"), 32);
levelInfo.updateHitbox();
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();
add(levelDifficulty);
2021-03-04 19:30:35 +00: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();
add(deathCounter);
2021-03-08 23:38:58 +00: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.practiceMode;
add(practiceText);
levelDifficulty.alpha = 0;
2021-03-02 04:00:02 +00:00
levelInfo.alpha = 0;
2021-03-04 19:30:35 +00:00
deathCounter.alpha = 0;
2021-03-02 04:00:02 +00:00
levelInfo.x = FlxG.width - (levelInfo.width + 20);
levelDifficulty.x = FlxG.width - (levelDifficulty.width + 20);
2021-03-04 19:30:35 +00:00
deathCounter.x = FlxG.width - (deathCounter.width + 20);
2021-03-02 04:00:02 +00: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 19:30:35 +00:00
FlxTween.tween(deathCounter, {alpha: 1, y: deathCounter.y + 5}, 0.4, {ease: FlxEase.quartInOut, startDelay: 0.7});
2021-03-02 04:00:02 +00:00
2020-11-18 01:50:09 +00:00
grpMenuShit = new FlxTypedGroup<Alphabet>();
add(grpMenuShit);
2021-03-07 20:34:21 +00:00
regenMenu();
2021-03-14 04:41:29 +00:00
// cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
2021-03-07 20:34:21 +00:00
}
private function regenMenu():Void
{
2021-03-08 23:38:58 +00:00
while (grpMenuShit.members.length > 0)
2021-03-07 20:34:21 +00:00
{
2021-03-08 23:38:58 +00:00
grpMenuShit.remove(grpMenuShit.members[0], true);
}
2021-03-07 20:34:21 +00:00
2020-11-18 01:50:09 +00: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 10:35:23 +00:00
2021-03-07 20:34:21 +00:00
curSelected = 0;
2020-11-18 01:50:09 +00:00
changeSelection();
2020-10-09 21:24:20 +00:00
}
override function update(elapsed:Float)
{
2020-11-20 12:21:04 +00:00
if (pauseMusic.volume < 0.5)
pauseMusic.volume += 0.01 * elapsed;
2020-10-09 21:24:20 +00:00
super.update(elapsed);
2021-03-14 02:11:56 +00:00
var upP = controls.UI_UP_P;
var downP = controls.UI_DOWN_P;
2020-11-18 01:50:09 +00:00
var accepted = controls.ACCEPT;
if (upP)
{
changeSelection(-1);
}
if (downP)
{
changeSelection(1);
}
2021-08-22 20:54:22 +00:00
var androidPause:Bool = false;
#if android
androidPause = FlxG.android.justPressed.BACK;
#end
if (androidPause)
close();
2020-11-18 01:50:09 +00:00
if (accepted)
{
var daSelected:String = menuItems[curSelected];
switch (daSelected)
{
case "Resume":
close();
2021-03-07 20:34:21 +00:00
case "EASY" | 'NORMAL' | "HARD":
2021-12-07 02:33:55 +00:00
PlayState.SONG = SongLoad.loadFromJson(PlayState.SONG.song.toLowerCase(), PlayState.SONG.song.toLowerCase());
SongLoad.curDiff = daSelected.toLowerCase();
2021-03-07 20:34:21 +00:00
PlayState.storyDifficulty = curSelected;
FlxG.resetState();
2021-03-08 23:38:58 +00:00
case 'Toggle Practice Mode':
PlayState.practiceMode = !PlayState.practiceMode;
practiceText.visible = PlayState.practiceMode;
2021-03-07 20:34:21 +00:00
case 'Change Difficulty':
menuItems = difficultyChoices;
regenMenu();
case 'BACK':
menuItems = pauseOG;
regenMenu();
2020-11-18 02:20:27 +00:00
case "Restart Song":
PlayState.needsReset = true;
close();
// FlxG.resetState();
2020-11-18 01:50:09 +00:00
case "Exit to menu":
2021-04-09 20:37:54 +00:00
PlayState.seenCutscene = false;
2021-03-07 20:34:21 +00:00
PlayState.deathCounter = 0;
if (PlayState.isStoryMode)
FlxG.switchState(new StoryMenuState());
else
FlxG.switchState(new FreeplayState());
2020-11-18 01:50:09 +00:00
}
}
2020-10-22 00:22:12 +00:00
if (FlxG.keys.justPressed.J)
{
2020-11-18 01:50:09 +00:00
// for reference later!
// PlayerSettings.player1.controls.replaceBinding(Control.LEFT, Keys, FlxKey.J, null);
2020-10-22 00:22:12 +00:00
}
2020-11-18 01:50:09 +00:00
}
2020-11-20 12:21:04 +00:00
override function destroy()
{
pauseMusic.destroy();
super.destroy();
}
2020-11-18 01:50:09 +00:00
function changeSelection(change:Int = 0):Void
{
2021-04-09 00:56:17 +00:00
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
2020-11-18 01:50:09 +00:00
curSelected += change;
2020-10-22 00:22:12 +00:00
2020-11-18 01:50:09 +00:00
if (curSelected < 0)
curSelected = menuItems.length - 1;
if (curSelected >= menuItems.length)
curSelected = 0;
var bullShit:Int = 0;
for (item in grpMenuShit.members)
{
item.targetY = bullShit - curSelected;
bullShit++;
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 21:24:20 +00:00
}
}