class_name MenuManager extends Node @export var savefile : SaveFileManager @export var cursor : CursorManager @export var animator_intro : AnimationPlayer @export var speaker_music : AudioStreamPlayer2D @export var speaker_start : AudioStreamPlayer2D @export var buttons : Array[ButtonClass] @export var buttons_options : Array[ButtonClass] @export var screens : Array[Control] @export var parent_main : Control @export var parent_creds : Control @export var parent_suboptions : Control @export var parent_audiovideo : Control @export var parent_language : Control @export var parent_controller : Control @export var parent_rebinding : Control @export var title : Node3D @export var waterfalls : Array[AnimationPlayer] @export var optionmanager : OptionsManager @export var controller : ControllerManager @export var mouseblocker : Control @export var anim_creds : AnimationPlayer @export var version : Label func _ready(): Show("main") buttons[0].connect("is_pressed", Start) buttons[1].connect("is_pressed", SubOptions) buttons[2].connect("is_pressed", Credits) buttons[3].connect("is_pressed", Exit) buttons[4].connect("is_pressed", ReturnToLastScreen) buttons[5].connect("is_pressed", ReturnToLastScreen) buttons[6].connect("is_pressed", ReturnToLastScreen) buttons[7].connect("is_pressed", Options_AudioVideo) buttons[8].connect("is_pressed", Options_Language) buttons[9].connect("is_pressed", Options_Controller) buttons[10].connect("is_pressed", ReturnToLastScreen) buttons[11].connect("is_pressed", ReturnToLastScreen) buttons[16].connect("is_pressed", RebindControls) buttons[17].connect("is_pressed", ReturnToLastScreen) buttons[18].connect("is_pressed", ResetControls) buttons[19].connect("is_pressed", DiscordLink) buttons_options[0].connect("is_pressed", IncreaseVol) buttons_options[1].connect("is_pressed", DecreaseVol) buttons_options[2].connect("is_pressed", SetFull) buttons_options[3].connect("is_pressed", SetWindowed) buttons_options[4].connect("is_pressed", ControllerEnable) buttons_options[5].connect("is_pressed", ControllerDisable) buttons_options[6].connect("is_pressed", ToggleColorblind) buttons_options[7].connect("is_pressed", ToggleMusic) version.text = GlobalVariables.currentVersion Intro() var failsafed = true func _input(event): if (event.is_action_pressed("ui_cancel") && failsafed): if (currentScreen != "main"): ReturnToLastScreen() if (event.is_action_pressed("exit game") && failsafed): if (currentScreen != "main"): ReturnToLastScreen() func Intro(): cursor.SetCursor(false, false) await get_tree().create_timer(.5, false).timeout speaker_music.play() animator_intro.play("splash screen") await get_tree().create_timer(9, false).timeout mouseblocker.visible = false cursor.SetCursor(true, false) controller.settingFilter = true controller.SetMainControllerState(controller.controller_currently_enabled) if (cursor.controller_active): firstFocus_main.grab_focus() controller.previousFocus = firstFocus_main assigningFocus = true func Buttons(state : bool): if (!state): for i in buttons: i.isActive = false i.SetFilter("ignore") else: for i in buttons: i.isActive = true i.SetFilter("stop") @export var firstFocus_main : Control @export var firstFocus_subOptions : Control @export var firstFocus_credits : Control @export var firstFocus_audioVideo : Control @export var firstFocus_language : Control @export var firstFocus_controller : Control @export var firstFocus_rebinding : Control var assigningFocus = false var lastScreen = "main" var currentScreen = "main" func Show(what : String): lastScreen = currentScreen currentScreen = what var focus title.visible = false for screen in screens: screen.visible = false if (what == "main" or what == "sub options"): title.visible = true match(what): "main": parent_main.visible = true focus = firstFocus_main "sub options": parent_suboptions.visible = true focus = firstFocus_subOptions "credits": parent_creds.visible = true focus = firstFocus_credits anim_creds.play("RESET") anim_creds.play("show credits") "audio video": parent_audiovideo.visible = true focus = firstFocus_audioVideo "language": parent_language.visible = true focus = firstFocus_language "controller": parent_controller.visible = true focus = firstFocus_controller "rebind controls": parent_rebinding.visible = true focus = firstFocus_rebinding if (assigningFocus): if (cursor.controller_active): focus.grab_focus() controller.previousFocus = focus func ReturnToLastScreen(): print("return to last screen") if (currentScreen) == "sub options": lastScreen = "main" if (currentScreen) == "rebind controls": lastScreen = "sub options" if (currentScreen == "audio video" or currentScreen == "language" or currentScreen == "controller" or currentScreen == "rebind controls"): optionmanager.SaveSettings() Show(lastScreen) ResetButtons() func ResetButtons(): #for b in buttons: # b.ui.modulate.a = 1 cursor.SetCursorImage("point") func Start(): Buttons(false) ResetButtons() for screen in screens: screen.visible = false title.visible = false controller.previousFocus = null speaker_music.stop() animator_intro.play("snap") for w in waterfalls: w.pause() speaker_start.play() cursor.SetCursor(false, false) savefile.ClearSave() await get_tree().create_timer(4, false).timeout print("changing scene to: main") get_tree().change_scene_to_file("res://scenes/main.tscn") func Credits(): Show("credits") ResetButtons() func Exit(): Buttons(false) ResetButtons() speaker_music.stop() animator_intro.play("snap2") cursor.SetCursor(false, false) await get_tree().create_timer(.5, false).timeout get_tree().quit() func ResetControls(): optionmanager.ResetControls() ResetButtons() func ToggleMusic(): optionmanager.AdjustSettings_music() func ToggleColorblind(): optionmanager.ToggleColorblind() func DiscordLink(): OS.shell_open("https://discord.gg/cr-channel-1158444754325999747") func RebindControls(): Show("rebind controls") ResetButtons() func SubOptions(): Show("sub options") ResetButtons() func Options_AudioVideo(): Show("audio video") ResetButtons() func Options_Language(): Show("language") ResetButtons() func Options_Controller(): Show("controller") ResetButtons() pass func IncreaseVol(): optionmanager.Adjust("increase") func DecreaseVol(): optionmanager.Adjust("decrease") func SetWindowed(): optionmanager.Adjust("windowed") func SetFull(): optionmanager.Adjust("fullscreen") func ControllerEnable(): optionmanager.Adjust("controller enable") func ControllerDisable(): optionmanager.Adjust("controller disable")