diff --git a/source/funkin/backend/scripting/events/EnterPressedEvent.hx b/source/funkin/backend/scripting/events/EnterPressedEvent.hx new file mode 100644 index 000000000..a273f6490 --- /dev/null +++ b/source/funkin/backend/scripting/events/EnterPressedEvent.hx @@ -0,0 +1,31 @@ +package funkin.backend.scripting.events; + +import funkin.backend.utils.CoolUtil.CoolSfx; +import flixel.util.FlxColor; + +final class EnterPressedEvent extends CancellableEvent { + /** + * Whether the screen should flash on PRESS ENTER TO START + */ + public var flash:Bool; + + /** + * The color that the screen flashes + */ + public var flashColor:FlxColor; + + /** + * Whether PRESS ENTER TO START should play a menu sfx + */ + public var playSfx:Bool; + + /** + * The menu sound to play + */ + public var menuSound:CoolSfx; + + /** + * The time between enter being pressed and the transition into MainMenuState + */ + public var timerLength:Float; +} diff --git a/source/funkin/backend/scripting/events/StartIntroEvent.hx b/source/funkin/backend/scripting/events/StartIntroEvent.hx new file mode 100644 index 000000000..8d248b76b --- /dev/null +++ b/source/funkin/backend/scripting/events/StartIntroEvent.hx @@ -0,0 +1,30 @@ +package funkin.backend.scripting.events; + + + +final class StartIntroEvent extends CancellableEvent { + /** + * Whether StoryMenuState should play the menu song + */ + public var playMenuSong:Bool; + + /** + * Whether StoryMenuState should use the title screen's XML file + */ + public var titleScreenXML:Bool; + + /** + * The path for the title sprite (PRESS ENTER TO PLAY) + */ + public var titleSprite:String; + + /** + * The path for the Newgrounds sprite + */ + public var ngSprite:String; + + /** + * Whether the mouse should be visible + */ + public var showMouse:Bool; +} diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 7a57c1eac..1540dc1f6 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1515,7 +1515,9 @@ class PlayState extends MusicBeatState */ public function endSong():Void { - scripts.call("onSongEnd"); + var event = scripts.event("onSongEnd", new CancellableEvent()); + if (event.cancelled) return; + canPause = false; inst.volume = 0; vocals.volume = 0; diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index 968494f17..f798a4e36 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -8,6 +8,7 @@ import flixel.effects.FlxFlicker; import flixel.text.FlxText; import flixel.tweens.FlxTween; import flixel.util.FlxColor; +import flixel.util.FlxTimer; import lime.app.Application; import funkin.backend.scripting.events.*; @@ -150,17 +151,23 @@ class MainMenuState extends MusicBeatState } function selectItem() { - selectedSomethin = true; - CoolUtil.playMenuSFX(CONFIRM); + var primevent = event("onInitialSelection", EventManager.get(AmountEvent).recycle(1)); + if (!primevent.cancelled) { + selectedSomethin = true; + + CoolUtil.playMenuSFX(CONFIRM); - if (Options.flashingMenu) FlxFlicker.flicker(magenta, 1.1, 0.15, false); + if (Options.flashingMenu) FlxFlicker.flicker(magenta, 1.1, 0.15, false); - FlxFlicker.flicker(menuItems.members[curSelected], 1, Options.flashingMenu ? 0.06 : 0.15, false, false, function(flick:FlxFlicker) - { + FlxFlicker.flicker(menuItems.members[curSelected], primevent.amount, Options.flashingMenu ? 0.06 : 0.15, false, false); + } + + new FlxTimer().start(primevent.amount, function(timer:FlxTimer) { var daChoice:String = optionShit[curSelected]; var event = event("onSelectItem", EventManager.get(NameEvent).recycle(daChoice)); if (event.cancelled) return; + switch (event.name) { case 'story mode': FlxG.switchState(new StoryMenuState()); @@ -169,6 +176,7 @@ class MainMenuState extends MusicBeatState case 'options': FlxG.switchState(new OptionsMenu()); } }); + } function changeItem(huh:Int = 0) { diff --git a/source/funkin/menus/TitleState.hx b/source/funkin/menus/TitleState.hx index 4aca30dbf..828e12fa5 100644 --- a/source/funkin/menus/TitleState.hx +++ b/source/funkin/menus/TitleState.hx @@ -2,6 +2,11 @@ package funkin.menus; import funkin.backend.MusicBeatGroup; import funkin.backend.utils.XMLUtil; +import funkin.backend.scripting.EventManager; +import funkin.backend.scripting.events.StartIntroEvent; +import funkin.backend.scripting.events.NameEvent; +import funkin.backend.scripting.events.EnterPressedEvent; +import funkin.backend.scripting.events.CancellableEvent; import flixel.util.typeLimit.OneOfTwo; import flixel.group.FlxGroup; import flixel.input.gamepad.FlxGamepad; @@ -48,7 +53,10 @@ class TitleState extends MusicBeatState function startIntro() { - if (!initialized) + var event = event("onStartIntro", EventManager.get(StartIntroEvent).recycle(true, true, 'menus/titlescreen/titleEnter', 'newgrounds_logo', false)); + if (event.cancelled) return; + + if (!initialized && event.playMenuSong) CoolUtil.playMenuSong(true); persistentUpdate = true; @@ -57,14 +65,16 @@ class TitleState extends MusicBeatState add(bg); #if TITLESCREEN_XML - titleScreenSprites = new MusicBeatGroup(); - add(titleScreenSprites); - loadXML(); + if (event.titleScreenXML) { + titleScreenSprites = new MusicBeatGroup(); + add(titleScreenSprites); + loadXML(); + } #end if (titleText == null) { titleText = new FlxSprite(100, FlxG.height * 0.8); - titleText.frames = Paths.getFrames('menus/titlescreen/titleEnter'); + titleText.frames = Paths.getFrames(event.titleSprite); titleText.animation.addByPrefix('idle', "Press Enter to Begin", 24); titleText.animation.addByPrefix('press', "ENTER PRESSED", 24); titleText.antialiasing = true; @@ -79,7 +89,7 @@ class TitleState extends MusicBeatState add(blackScreen); #if !TITLESCREEN_XML - ngSpr = new FlxSprite(0, FlxG.height * 0.52).loadAnimatedGraphic(Paths.image('newgrounds_logo')); + ngSpr = new FlxSprite(0, FlxG.height * 0.52).loadAnimatedGraphic(Paths.image(event.ngSprite)); add(ngSpr); ngSpr.visible = false; ngSpr.setGraphicSize(Std.int(ngSpr.width * 0.8)); @@ -88,7 +98,7 @@ class TitleState extends MusicBeatState ngSpr.antialiasing = true; #end - FlxG.mouse.visible = false; + FlxG.mouse.visible = event.showMouse; if (initialized) skipIntro(); @@ -97,10 +107,12 @@ class TitleState extends MusicBeatState add(textGroup); } - + public function getIntroTextShit():Array> - { - var fullText:String = Assets.getText(Paths.txt('titlescreen/introText')); + { + var event = event("onGetIntroText", EventManager.get(NameEvent).recycle('introText')); + + var fullText:String = Assets.getText(Paths.txt(Assets.exists(Paths.txt('titlescreen/${event.name}')) ? 'titlescreen/${event.name}' : 'titlescreen/introText')); var firstArray:Array = fullText.split('\n'); var swagGoodArray:Array> = []; @@ -109,7 +121,7 @@ class TitleState extends MusicBeatState { swagGoodArray.push(i.split('--')); } - + return swagGoodArray; } @@ -161,15 +173,18 @@ class TitleState extends MusicBeatState } public function pressEnter() { + var event = event("onEnterPressed", EventManager.get(EnterPressedEvent).recycle(true, 0xFFFFFFFF, true, CONFIRM, 2)); + if (event.cancelled) return; + titleText.animation.play('press'); - FlxG.camera.flash(FlxColor.WHITE, 1); - CoolUtil.playMenuSFX(CONFIRM, 0.7); + if (event.flash) FlxG.camera.flash(event.flashColor, 1); + if (event.playSfx) CoolUtil.playMenuSFX(event.menuSound, 0.7); transitioning = true; // FlxG.sound.music.stop(); - new FlxTimer().start(2, (_) -> goToMainMenu()); + new FlxTimer().start(event.timerLength, (_) -> goToMainMenu()); } function goToMainMenu() { @@ -189,10 +204,15 @@ class TitleState extends MusicBeatState public function createCoolText(textArray:Array) { + var money:Alphabet; + + var event = event("onCreateText", new CancellableEvent()); + if (!event.cancelled) return; + for (i=>text in textArray) { if (text == "" || text == null) continue; - var money:Alphabet = new Alphabet(0, (i * 60) + 200, text, true, false); + money = new Alphabet(0, (i * 60) + 200, text, true, false); money.screenCenter(X); textGroup.add(money); } @@ -200,13 +220,21 @@ class TitleState extends MusicBeatState public function addMoreText(text:String) { - var coolText:Alphabet = new Alphabet(0, (textGroup.length * 60) + 200, text, true, false); + var coolText:Alphabet; + + var event = event("onMoreText", new CancellableEvent()); + if (event.cancelled) return; + + coolText = new Alphabet(0, (textGroup.length * 60) + 200, text, true, false); coolText.screenCenter(X); textGroup.add(coolText); } public function deleteCoolText() { + var event = event("onDeleteText", new CancellableEvent()); + if (event.cancelled) return; + while (textGroup.members.length > 0) { textGroup.members[0].destroy(); textGroup.remove(textGroup.members[0], true); @@ -326,6 +354,9 @@ class TitleState extends MusicBeatState public function skipIntro():Void { + var event = event("onIntroSkipped", new CancellableEvent()); + if (event.cancelled) return; + if (!skippedIntro) { #if !TITLESCREEN_XML @@ -387,4 +418,4 @@ typedef TitleStateImage = { @:optional var scale:Null; @:optional var flipX:Null; @:optional var flipY:Null; -} \ No newline at end of file +}