From a1f49a3e10065cfe4e79318591f8432f8599aaf7 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Thu, 10 Nov 2022 17:52:23 +0100 Subject: [PATCH] code --- source/funkin/menus/PauseSubState.hx | 4 +-- source/funkin/menus/StoryMenuState.hx | 32 +++++++++++++---- .../scripting/events/MenuChangeEvent.hx | 30 ++++++++++++++++ ...PauseSelectOptionEvent.hx => NameEvent.hx} | 4 +-- .../scripting/events/WeekSelectEvent.hx | 34 +++++++++++++++++++ 5 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 source/funkin/scripting/events/MenuChangeEvent.hx rename source/funkin/scripting/events/{PauseSelectOptionEvent.hx => NameEvent.hx} (62%) create mode 100644 source/funkin/scripting/events/WeekSelectEvent.hx diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index 21881d20..68193070 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -1,7 +1,7 @@ package funkin.menus; import funkin.scripting.events.PauseCreationEvent; -import funkin.scripting.events.PauseSelectOptionEvent; +import funkin.scripting.events.NameEvent; import funkin.scripting.Script; import flixel.FlxG; import flixel.FlxSprite; @@ -124,7 +124,7 @@ class PauseSubState extends MusicBeatSubstate } public function selectOption() { - var event = new PauseSelectOptionEvent(menuItems[curSelected]); + var event = new NameEvent(menuItems[curSelected]); pauseScript.call("onSelectOption", [event]); if (event.cancelled) return; diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index 3ec87496..ee2a7186 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -1,5 +1,6 @@ package funkin.menus; +import funkin.scripting.events.*; import flixel.util.FlxTimer; import flixel.math.FlxPoint; import funkin.system.XMLUtil; @@ -132,11 +133,12 @@ class StoryMenuState extends MusicBeatState { scoreText.text = 'WEEK SCORE:${Math.round(lerpScore)}'; if (canSelect) { - leftArrow.animation.play(controls.LEFT ? 'press' : 'idle'); - rightArrow.animation.play(controls.RIGHT ? 'press' : 'idle'); + if (leftArrow != null && leftArrow.exists) leftArrow.animation.play(controls.LEFT ? 'press' : 'idle'); + if (rightArrow != null && rightArrow.exists) rightArrow.animation.play(controls.RIGHT ? 'press' : 'idle'); - if (controls.BACK) - FlxG.switchState(new MainMenuState()); + if (controls.BACK) { + goBack(); + } changeDifficulty((controls.LEFT_P ? -1 : 0) + (controls.RIGHT_P ? 1 : 0)); @@ -146,14 +148,23 @@ class StoryMenuState extends MusicBeatState { selectWeek(); } else { for(e in [leftArrow, rightArrow]) - e.animation.play('idle'); + if (e != null && e.exists) + e.animation.play('idle'); } } + public function goBack() { + var event = event("onGoBack", new CancellableEvent()); + if (!event.cancelled) + FlxG.switchState(new MainMenuState()); + } + public function changeWeek(change:Int, force:Bool = false) { if (change == 0 && !force) return; - curWeek = FlxMath.wrap(curWeek + change, 0, weeks.length-1); + var event = event("onChangeWeek", new MenuChangeEvent(curWeek, FlxMath.wrap(curWeek + change, 0, weeks.length-1), change)); + if (event.cancelled) return; + curWeek = event.value; if (!force) CoolUtil.playMenuSFX(); for(k=>e in weekSprites.members) { @@ -171,7 +182,9 @@ class StoryMenuState extends MusicBeatState { public function changeDifficulty(change:Int, force:Bool = false) { if (change == 0 && !force) return; - curDifficulty = FlxMath.wrap(curDifficulty + change, 0, weeks[curWeek].difficulties.length-1); + var event = event("onChangeDifficulty", new MenuChangeEvent(curDifficulty, FlxMath.wrap(curDifficulty + change, 0, weeks[curWeek].difficulties.length-1), change)); + if (event.cancelled) return; + curDifficulty = event.value; if (__oldDiffName != (__oldDiffName = weeks[curWeek].difficulties[curDifficulty].toLowerCase())) { for(e in difficultySprites) e.visible = false; @@ -204,6 +217,11 @@ class StoryMenuState extends MusicBeatState { } public function selectWeek() { + + + var event = event("onWeekSelect", new WeekSelectEvent(weeks[curWeek], weeks[curWeek].difficulties[curDifficulty], curWeek, curDifficulty)); + if (event.cancelled) return; + canSelect = false; CoolUtil.playMenuSFX(1); diff --git a/source/funkin/scripting/events/MenuChangeEvent.hx b/source/funkin/scripting/events/MenuChangeEvent.hx new file mode 100644 index 00000000..e132c723 --- /dev/null +++ b/source/funkin/scripting/events/MenuChangeEvent.hx @@ -0,0 +1,30 @@ +package funkin.scripting.events; + +class MenuChangeEvent extends CancellableEvent { + /** + * Value after the change + */ + public var value:Int; + + /** + * Value before the change + */ + public var oldValue:Int; + + /** + * Amount of change + */ + public var change:Int; + + /** + * Whenever the menu SFX should be played. + */ + public var playMenuSFX:Bool = true; + + public function new(oldValue:Int, value:Int, change:Int) { + super(); + this.value = value; + this.oldValue = value; + this.change = change; + } +} \ No newline at end of file diff --git a/source/funkin/scripting/events/PauseSelectOptionEvent.hx b/source/funkin/scripting/events/NameEvent.hx similarity index 62% rename from source/funkin/scripting/events/PauseSelectOptionEvent.hx rename to source/funkin/scripting/events/NameEvent.hx index 603c5c53..5e4d4db2 100644 --- a/source/funkin/scripting/events/PauseSelectOptionEvent.hx +++ b/source/funkin/scripting/events/NameEvent.hx @@ -1,8 +1,8 @@ package funkin.scripting.events; -class PauseSelectOptionEvent extends CancellableEvent { +class NameEvent extends CancellableEvent { /** - * Option name thats going to be selected + * Name */ public var name:String; diff --git a/source/funkin/scripting/events/WeekSelectEvent.hx b/source/funkin/scripting/events/WeekSelectEvent.hx new file mode 100644 index 00000000..5f1ae9a8 --- /dev/null +++ b/source/funkin/scripting/events/WeekSelectEvent.hx @@ -0,0 +1,34 @@ +package funkin.scripting.events; + +import funkin.menus.StoryMenuState.WeekData; + +class WeekSelectEvent extends CancellableEvent { + /** + * Week that is going to be selected + */ + public var week:WeekData; + + /** + * The difficulty that has been selected + */ + public var difficulty:String; + + /** + * At which emplacement the week is. Goes from 0 to the number of weeks - 1. + */ + public var weekID:Int; + + /** + * At which emplacement the difficulty is. Goes from 0 to the number of weeks - 1. + */ + public var difficultyID:Int; + + public override function new(week:WeekData, difficulty:String, weekID:Int, difficultyID:Int) { + super(); + + this.week = week; + this.difficulty = difficulty; + this.weekID = weekID; + this.difficultyID = difficultyID; + } +} \ No newline at end of file