From c86b802cbbc3c93c0086f9a320db15085b364aac Mon Sep 17 00:00:00 2001 From: Julian Murgia Date: Thu, 11 Nov 2021 22:20:36 +0100 Subject: [PATCH] Add show_menu and hide_menu ESC commands Fixes godot-escoria/escoria-issues#48 Fix: tween was stopped_all before starting Fix: reload locale from settings in ESCGame Since main menu and pause menu are now loaded from ESCGame and not from escoria.gd, this must be done here. Fix: small crash in load game But save and load are broken at the moment... Fix: check save and load after main menu changes Required fixes Fix: manage the game scene better in show and hide_menu Enh: transition back in to the previous room if there was one Fix a bug occurring where change_scene awaits forever for setup to end Reworked change_scene and esc_room implementation to avoid yielding Added a controller variable to allow new event run in events_manager Don't empty the events queue if the running_event was interrupted Fixed transitions and automatic transitions in change_scene Added trace log level (for esc_compiler in particular) Fixed various bugs in ESC scripts Fix a bug where exit_scene happened multiple times where fast walking Needed to clear the event queue Fixes ready event was run because BYPASS_LAST_SCENE wrongly set Inverted parameter "disable_automatic_transitions" for change_scene, hide_menu, show_menu commands Fix broken sched_event Fixes as requested in PR --- .../core-scripts/behaviors/esc_movable.gd | 5 +- .../core-scripts/esc/commands/change_scene.gd | 88 +++++---- .../core-scripts/esc/commands/hide_menu.gd | 65 +++++++ .../core-scripts/esc/commands/play_snd.gd | 8 +- .../core-scripts/esc/commands/show_menu.gd | 72 ++++++++ .../core-scripts/esc/commands/transition.gd | 11 +- .../game/core-scripts/esc/commands/wait.gd | 8 +- .../game/core-scripts/esc/esc_compiler.gd | 22 +-- .../core-scripts/esc/esc_event_manager.gd | 29 ++- .../game/core-scripts/esc/types/esc_event.gd | 2 +- .../game/core-scripts/esc/types/esc_object.gd | 2 +- .../core-scripts/esc/types/esc_statement.gd | 22 ++- .../game/core-scripts/esc_game.gd | 38 +++- .../game/core-scripts/esc_item.gd | 5 +- .../game/core-scripts/esc_room.gd | 171 ++++++++++++++---- .../game/core-scripts/log/esc_logger.gd | 14 +- .../save_data/esc_save_manager.gd | 35 +++- addons/escoria-core/game/escoria.gd | 4 +- addons/escoria-core/game/main.gd | 7 +- .../transitions/esc_transition_player.gd | 25 ++- .../game/scenes/transitions/transition.tscn | 2 - .../ui_library/menus/options/options.gd | 10 +- .../ui_library/menus/pause_menu/pause_menu.gd | 2 +- .../tools/room_select/room_select.gd | 9 +- addons/escoria-ui-9verbs/game.gd | 28 ++- addons/escoria-ui-9verbs/game.tscn | 8 +- addons/escoria-ui-simplemouse/game.gd | 26 ++- addons/escoria-ui-simplemouse/game.tscn | 8 +- game/rooms/room01/esc/room01.esc | 4 +- game/rooms/room01/room01.tscn | 19 +- game/rooms/room02/esc/room02_bridge.esc | 5 +- game/rooms/room04/esc/room04.esc | 2 + game/rooms/room05/esc/room05.esc | 1 + game/rooms/room06/esc/room06.esc | 1 + game/rooms/room10/esc/room10.esc | 1 + game/rooms/room11/esc/right_exit.esc | 2 +- game/rooms/room11/esc/room11.esc | 1 + game/rooms/room12/esc/room12.esc | 4 + game/rooms/room13/esc/right_exit.esc | 2 +- game/rooms/room13/esc/room13.esc | 1 + game/rooms/room13/room13.tscn | 13 +- game/rooms/room14/background.tscn | 30 +++ game/rooms/room14/esc/button_main_menu.esc | 13 ++ .../esc/button_main_menu_change_scene.esc | 37 ++++ game/rooms/room14/esc/button_pause_menu.esc | 13 ++ game/rooms/room14/esc/left_exit.esc | 5 + game/rooms/room14/esc/right_exit.esc | 3 + game/rooms/room14/esc/room14.esc | 29 +++ game/rooms/room14/r_door.tscn | 25 +++ game/rooms/room14/room14.tscn | 151 ++++++++++++++++ game/rooms/room14/walkable_area.tscn | 18 ++ game/start_game.esc | 14 +- project.godot | 17 +- saves/save_001.tres | 29 +-- saves/save_002.tres | 61 ++++--- saves/save_003.tres | 88 --------- 56 files changed, 998 insertions(+), 317 deletions(-) create mode 100644 addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd create mode 100644 addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd mode change 100755 => 100644 game/rooms/room11/esc/right_exit.esc create mode 100644 game/rooms/room14/background.tscn create mode 100644 game/rooms/room14/esc/button_main_menu.esc create mode 100644 game/rooms/room14/esc/button_main_menu_change_scene.esc create mode 100644 game/rooms/room14/esc/button_pause_menu.esc create mode 100644 game/rooms/room14/esc/left_exit.esc create mode 100644 game/rooms/room14/esc/right_exit.esc create mode 100644 game/rooms/room14/esc/room14.esc create mode 100644 game/rooms/room14/r_door.tscn create mode 100644 game/rooms/room14/room14.tscn create mode 100644 game/rooms/room14/walkable_area.tscn delete mode 100644 saves/save_003.tres diff --git a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd b/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd index f3b5ae18..ca9e3ee4 100644 --- a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd +++ b/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd @@ -106,7 +106,7 @@ func _calculate_movement(delta: float): # Movement speed calculation var movement_speed: float = parent.speed * delta * pow(last_scale.x, 2) * \ - parent.terrain.player_speed_multiplier + parent.terrain.player_speed_multiplier if walk_context.fast: movement_speed *= parent.terrain.player_doubleclick_speed_multiplier @@ -226,7 +226,8 @@ func walk_to(pos: Vector2, p_walk_context: ESCWalkContext = null) -> void: if task == MovableTask.WALK: if walk_context.target_object == p_walk_context.target_object \ - or walk_context.target_position == p_walk_context.target_position: + or walk_context.target_position \ + == p_walk_context.target_position: walk_context.fast = p_walk_context.fast walk_context = p_walk_context diff --git a/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd b/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd index bbf40e54..6b272bd1 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd @@ -1,8 +1,8 @@ -# `change_scene path [disable_automatic_transition] [run_events]` +# `change_scene path [enable_automatic_transition=true] [run_events=true]` # # Loads a new scene, specified by "path". -# The `disable_automatic_transition` is a boolean (default false) can be set -# to true to disable automatic transitions between scenes, to allow you +# The `enable_automatic_transition` is a boolean (default true) can be set +# to false to disable automatic transitions between scenes, to allow you # to control your transitions manually using the `transition` command. # The `run_events` variable is a boolean (default true) which you never want # to set manually! It's there only to benefit save games, so they don't @@ -18,7 +18,7 @@ func configure() -> ESCCommandArgumentDescriptor: return ESCCommandArgumentDescriptor.new( 1, [TYPE_STRING, TYPE_BOOL, TYPE_BOOL], - [null, false, true] + [null, true, true] ) @@ -47,35 +47,51 @@ func validate(arguments: Array) -> bool: # Run the command func run(command_params: Array) -> int: escoria.logger.info( - "Changing scene to %s (disable_automatic_transition = %s, run_events = %s)" % [ - command_params[0], - command_params[1], - command_params[2] + "Changing scene to %s (enable_automatic_transition = %s, run_events = %s)" % [ + command_params[0], # scene file + command_params[1], # enable_automatic_transition + command_params[2] # run_events ]) - if escoria.main.current_scene \ - and not escoria.globals_manager.get_global("BYPASS_LAST_SCENE"): - escoria.globals_manager.set_global( - "ESC_LAST_SCENE", - escoria.main.current_scene.global_id, - true - ) - - escoria.event_manager.interrupt_running_event() - if escoria.dialog_player: - escoria.dialog_player.interrupt() + # Clear the event queue to remove other events (there could be duplicate + # events in there so we avoid running these multiple times) + escoria.event_manager.clear_event_queue() - if !command_params[1]: + var exited_previous_room = false + + if command_params[1] \ + and escoria.event_manager._running_event.name \ + in ["exit_scene", "room_selector"]: + exited_previous_room = true escoria.main.scene_transition.transition( "", ESCTransitionPlayer.TRANSITION_MODE.OUT ) yield(escoria.main.scene_transition, "transition_done") + + # If BYPASS_LAST_SCENE is false, set ESC_LAST_SCENE = current room id + if escoria.main.current_scene \ + and not escoria.globals_manager.get_global("BYPASS_LAST_SCENE"): + escoria.globals_manager.set_global( + "ESC_LAST_SCENE", + escoria.main.current_scene.global_id, + true + ) + + if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"): + escoria.globals_manager.set_global( + "ESC_LAST_SCENE", + null, + true + ) + + if escoria.dialog_player: + escoria.dialog_player.interrupt() escoria.inputs_manager.clear_stack() var res_room = escoria.resource_cache.get_resource(command_params[0]) - + # Load game scene if not escoria.game_scene: escoria.logger.report_errors( @@ -87,22 +103,32 @@ func run(command_params: Array) -> int: ) if escoria.main.current_scene \ - and escoria.game_scene.get_parent() == escoria.main.current_scene: + and escoria.game_scene.get_parent() == escoria.main.current_scene: escoria.main.current_scene.remove_child(escoria.game_scene) # Load room scene var room_scene = res_room.instance() if room_scene: + if command_params[1] \ + and escoria.event_manager._running_event.name \ + == "room_selector": + room_scene.enabled_automatic_transitions = true + else: + room_scene.enabled_automatic_transitions = command_params[1] + room_scene.exited_previous_room = exited_previous_room + + # If the game scene is already in the tree but not a child of the room + # we remove it + if escoria.game_scene.is_inside_tree() \ + and escoria.game_scene.get_parent() != room_scene: + var game_parent = escoria.game_scene.get_parent() + game_parent.remove_child(escoria.game_scene) + room_scene.add_child(escoria.game_scene) room_scene.move_child(escoria.game_scene, 0) room_scene.game = escoria.game_scene escoria.main.set_scene(room_scene) - # If automatic transition is not disabled, play the transition - if not command_params[1]: - escoria.main.scene_transition.transition() - yield(escoria.main.scene_transition, "transition_done") - # Clear queued resources escoria.resource_cache.clear() @@ -116,12 +142,4 @@ func run(command_params: Array) -> int: ) return ESCExecution.RC_ERROR - # If the ESC_LAST_SCENE global was bypassed, reset bypass variable to false - if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"): - escoria.globals_manager.set_global( - "BYPASS_LAST_SCENE", - false, - true - ) - return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd b/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd new file mode 100644 index 00000000..216bdf44 --- /dev/null +++ b/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd @@ -0,0 +1,65 @@ +# `hide_menu main|pause=main [enable_automatic_transition: true|false=false]` +# +# Hides the main or pause menu. +# The `enable_automatic_transition` is a boolean (default false) can be set +# to false to disable automatic transitions between scenes, to allow you +# to control your transitions manually using the `transition` command. +# +# @ESC +extends ESCBaseCommand +class_name HideMenuCommand + + +# Return the descriptor of the arguments of this command +func configure() -> ESCCommandArgumentDescriptor: + return ESCCommandArgumentDescriptor.new( + 0, + [TYPE_STRING, TYPE_BOOL], + ["main", false] + ) + + +# Validate wether the given arguments match the command descriptor +func validate(arguments: Array): + if not arguments[0] in ["main", "pause"]: + escoria.logger.report_errors( + "hide_menu: invalid menu ", + [ + "menu %s is invalid" % arguments[0] + ] + ) + return false + return .validate(arguments) + + +# Run the command +func run(command_params: Array) -> int: + var transition_id: int + if command_params[1]: + # Transition out from menu + transition_id = escoria.main.scene_transition.transition( + "", + ESCTransitionPlayer.TRANSITION_MODE.OUT + ) + while yield( + escoria.main.scene_transition, + "transition_done" + ) != transition_id: + pass + + if command_params[0] == "main": + escoria.game_scene.hide_main_menu() + elif command_params[0] == "pause": + escoria.game_scene.unpause_game() + + if command_params[1] and escoria.main.current_scene != null: + transition_id = escoria.main.scene_transition.transition() + + if command_params[1] and escoria.main.current_scene != null: + while yield( + escoria.main.scene_transition, + "transition_done" + ) != transition_id: + pass + + return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd b/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd index 3a442c50..e7a199fe 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd @@ -19,16 +19,16 @@ func configure() -> ESCCommandArgumentDescriptor: # Validate wether the given arguments match the command descriptor func validate(arguments: Array): - if not escoria.object_manager.has(arguments[0]): + if not escoria.object_manager.has(arguments[1]): escoria.logger.report_errors( "play_snd: invalid sound player", - ["Sound player %s not registered" % arguments[0]] + ["Sound player %s not registered" % arguments[1]] ) return false - if not ResourceLoader.exists(arguments[1]): + if not ResourceLoader.exists(arguments[0]): escoria.logger.report_errors( "play_snd: invalid parameter", - ["File %s not found" % arguments[1]] + ["File %s not found" % arguments[0]] ) return false return .validate(arguments) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd b/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd new file mode 100644 index 00000000..1a3580bf --- /dev/null +++ b/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd @@ -0,0 +1,72 @@ +# `show_menu main|pause=main [enable_automatic_transition: true|false=false]` +# +# Shows the main or pause menu. +# The `enable_automatic_transition` is a boolean (default false) can be set +# to false to disable automatic transitions between scenes, to allow you +# to control your transitions manually using the `transition` command. +# +# @ESC +extends ESCBaseCommand +class_name ShowMenuCommand + + +# Return the descriptor of the arguments of this command +func configure() -> ESCCommandArgumentDescriptor: + return ESCCommandArgumentDescriptor.new( + 0, + [TYPE_STRING, TYPE_BOOL], + ["main", false] + ) + + +# Validate wether the given arguments match the command descriptor +func validate(arguments: Array): + if not arguments[0] in ["main", "pause"]: + escoria.logger.report_errors( + "show_menu: invalid menu ", + [ + "menu %s is invalid" % arguments[0] + ] + ) + return false + return .validate(arguments) + + +# Run the command +func run(command_params: Array) -> int: + if not escoria.game_scene.is_inside_tree(): + escoria.add_child(escoria.game_scene) + + if command_params[1]: + # Transition out from current scene + var transition_id = escoria.main.scene_transition.transition( + "", + ESCTransitionPlayer.TRANSITION_MODE.OUT + ) + while yield( + escoria.main.scene_transition, + "transition_done" + ) != transition_id: + pass + + if command_params[0] == "main": + escoria.game_scene.show_main_menu() + elif command_params[0] == "pause": + escoria.game_scene.pause_game() + + # Transition in to menu + transition_id = escoria.main.scene_transition.transition() + + while yield( + escoria.main.scene_transition, + "transition_done" + ) != transition_id: + pass + + else: + if command_params[0] == "main": + escoria.game_scene.show_main_menu() + elif command_params[0] == "pause": + escoria.game_scene.pause_game() + + return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/transition.gd b/addons/escoria-core/game/core-scripts/esc/commands/transition.gd index 7b7b78f9..9d8a09c3 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/transition.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/transition.gd @@ -45,14 +45,19 @@ func validate(arguments: Array): # Run the command func run(command_params: Array) -> int: - escoria.main.scene_transition.transition( + var transition_id = escoria.main.scene_transition.transition( command_params[0], ESCTransitionPlayer.TRANSITION_MODE.OUT if command_params[1] == "out" \ else ESCTransitionPlayer.TRANSITION_MODE.IN, command_params[2] ) - yield( + escoria.logger.debug("Starting transition #%s [%s, %s]" + % [transition_id, command_params[0], command_params[1]]) + while yield( escoria.main.scene_transition, "transition_done" - ) + ) != transition_id: + pass + escoria.logger.debug("Ending transition #%s [%s, %s]" + % [transition_id, command_params[0], command_params[1]]) return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd b/addons/escoria-core/game/core-scripts/esc/commands/wait.gd index 6ad40186..3901bd42 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/wait.gd @@ -1,6 +1,8 @@ # `wait seconds` # -# Blocks execution of the current script for a number of seconds specified by the "seconds" parameter. +# Blocks execution of the current script for a number of seconds specified by +# the "seconds" parameter. +# - seconds can be either and integer or a floating value # # @ESC extends ESCBaseCommand @@ -11,12 +13,12 @@ class_name WaitCommand func configure() -> ESCCommandArgumentDescriptor: return ESCCommandArgumentDescriptor.new( 1, - [TYPE_INT], + [[TYPE_INT, TYPE_REAL]], [null] ) # Run the command func run(command_params: Array) -> int: - yield(escoria.get_tree().create_timer(command_params[0]), "timeout") + yield(escoria.get_tree().create_timer(float(command_params[0])), "timeout") return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd index da955d50..39357651 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd @@ -104,10 +104,10 @@ func _compile(lines: Array) -> Array: while lines.size() > 0: var line = lines.pop_front() - escoria.logger.debug("Parsing line %s" % line) + escoria.logger.trace("Parsing line %s" % line) if comment_regex.search(line) or empty_regex.search(line): # Ignore comments and empty lines - escoria.logger.debug("Line is empty or a comment. Skipping.") + escoria.logger.trace("Line is empty or a comment. Skipping.") continue var indent = \ escoria.utils.get_re_group( @@ -117,7 +117,7 @@ func _compile(lines: Array) -> Array: if event_regex.search(line): var event = ESCEvent.new(line) - escoria.logger.debug("Line is the event %s" % event.name) + escoria.logger.trace("Line is the event %s" % event.name) var event_lines = [] while lines.size() > 0: var next_line = lines.pop_front() @@ -127,7 +127,7 @@ func _compile(lines: Array) -> Array: lines.push_front(next_line) break if event_lines.size() > 0: - escoria.logger.debug( + escoria.logger.trace( "Compiling the next %d lines into the event" % \ event_lines.size() ) @@ -135,7 +135,7 @@ func _compile(lines: Array) -> Array: returned.append(event) elif group_regex.search(line): var group = ESCGroup.new(line) - escoria.logger.debug("Line is a group") + escoria.logger.trace("Line is a group") var group_lines = [] while lines.size() > 0: var next_line = lines.pop_front() @@ -153,7 +153,7 @@ func _compile(lines: Array) -> Array: lines.push_front(next_line) break if group_lines.size() > 0: - escoria.logger.debug( + escoria.logger.trace( "Compiling the next %d lines into the group" % \ group_lines.size() ) @@ -161,7 +161,7 @@ func _compile(lines: Array) -> Array: returned.append(group) elif dialog_regex.search(line): var dialog = ESCDialog.new(line) - escoria.logger.debug("Line is a dialog") + escoria.logger.trace("Line is a dialog") var dialog_lines = [] while lines.size() > 0: var next_line = lines.pop_front() @@ -178,7 +178,7 @@ func _compile(lines: Array) -> Array: else: dialog_lines.append(next_line) if dialog_lines.size() > 0: - escoria.logger.debug( + escoria.logger.trace( "Compiling the next %d lines into the dialog" % \ dialog_lines.size() ) @@ -188,7 +188,7 @@ func _compile(lines: Array) -> Array: returned.append(dialog) elif dialog_option_regex.search(line): var dialog_option = ESCDialogOption.new(line) - escoria.logger.debug( + escoria.logger.trace( "Line is the dialog option %s" % \ dialog_option.option ) @@ -209,7 +209,7 @@ func _compile(lines: Array) -> Array: lines.push_front(next_line) break if dialog_option_lines.size() > 0: - escoria.logger.debug( + escoria.logger.trace( "Compiling the next %d lines into the event" % \ dialog_option_lines.size() ) @@ -217,7 +217,7 @@ func _compile(lines: Array) -> Array: returned.append(dialog_option) elif command_regex.search(line): var command = ESCCommand.new(line) - escoria.logger.debug("Line is the command %s" % command.name) + escoria.logger.trace("Line is the command %s" % command.name) returned.append(command) else: escoria.logger.report_errors( diff --git a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd index 2898d338..4397797e 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd @@ -2,6 +2,8 @@ extends Node class_name ESCEventManager +# Emitted when the event started execution +signal event_started(event_name) # Emitted when the event did finish running signal event_finished(event_name, return_code) @@ -19,6 +21,9 @@ var scheduled_events: Array = [] # Currently running event var _running_event: ESCEvent +# Whether the event manager is allowed to proceed with next event. +var can_process_next_event = true + func _ready(): self.pause_mode = Node.PAUSE_MODE_STOP @@ -26,8 +31,17 @@ func _ready(): # Handle the events queue and scheduled events func _process(delta: float) -> void: - if events_queue.size() > 0: + if events_queue.size() > 0 and can_process_next_event: + can_process_next_event = false _running_event = events_queue.pop_front() + escoria.logger.debug( + "esc_event_manager", + [ + "Popping event %s from event_queue" \ + % _running_event.name if _running_event.get("name") != null \ + else str(_running_event) + ] + ) if not _running_event.is_connected( "finished", self, "_on_event_finished" ): @@ -47,12 +61,13 @@ func _process(delta: float) -> void: [_running_event] ) + emit_signal("event_started", _running_event.name) _running_event.run() for event in self.scheduled_events: (event as ESCScheduledEvent).timeout -= delta if (event as ESCScheduledEvent).timeout <= 0: self.scheduled_events.erase(event) - self.events_queue.append(event) + self.events_queue.append(event.event) # Queue a new event to run @@ -73,10 +88,9 @@ func _on_event_finished(return_code: int, event: ESCEvent) -> void: event.disconnect("finished", self, "_on_event_finished") event.disconnect("interrupted", self, "_on_event_finished") _running_event = null + can_process_next_event = true match(return_code): ESCExecution.RC_CANCEL: - self.scheduled_events = [] - self.events_queue = [] return_code = ESCExecution.RC_OK emit_signal("event_finished", return_code, event.name) @@ -85,7 +99,8 @@ func _on_event_finished(return_code: int, event: ESCEvent) -> void: func interrupt_running_event(): if _running_event == null: return - for event in events_queue: - event.interrupt() - events_queue.clear() _running_event.interrupt() + +# Clears the event queue. +func clear_event_queue(): + events_queue.clear() diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_event.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_event.gd index a17be15b..b1ca2e8c 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_event.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_event.gd @@ -77,5 +77,5 @@ func _init(event_string: String): # Execute this statement and return its return code func run() -> int: - escoria.logger.debug("Starting event %s" % name) + escoria.logger.debug("Event %s started" % name) return .run() diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd index 6ed2f4c8..10f14b69 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd @@ -40,7 +40,7 @@ func set_state(p_state: String, immediate: bool = false): if node.has_method("get_animation_player"): var animation_node: ESCAnimationPlayer = node.get_animation_player() - if animation_node.is_valid(): + if animation_node != null and animation_node.is_valid(): animation_node.stop() var actual_animator if animation_node.has_animation(p_state): diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd index 98a26853..fc2c89cf 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd @@ -12,9 +12,12 @@ signal interrupted(return_code) # The list of ESC commands var statements: Array = [] -# Indicated whether this event was interrupted. +# Indicates whether this event was interrupted. var _is_interrupted: bool = false +# Indicates whether this event was finished. +var is_finished: bool = false + # Check wether the statement should be run based on its conditions func is_valid() -> bool: @@ -37,8 +40,16 @@ func run() -> int: var rc = statement.run() if rc is GDScriptFunctionState: rc = yield(rc, "completed") + escoria.logger.debug( + "esc_statement", + ["Statement (%s) was completed." + % statement] + ) + statement.is_finished = true if rc == ESCExecution.RC_REPEAT: return self.run() + elif rc == ESCExecution.RC_OK: + statement.is_finished = true elif rc != ESCExecution.RC_OK: final_rc = rc break @@ -52,4 +63,11 @@ func interrupt(): escoria.logger.info("Interrupting event %s" % str(self)) _is_interrupted = true for statement in statements: - statement.interrupt() + if statement.is_finished: + escoria.logger.debug( + "event manager", + ["Event %s (%s) is already finished. Won't interrupt." + % [statement.name, str(statement)]] + ) + else: + statement.interrupt() diff --git a/addons/escoria-core/game/core-scripts/esc_game.gd b/addons/escoria-core/game/core-scripts/esc_game.gd index 5ecff4d4..9682876b 100644 --- a/addons/escoria-core/game/core-scripts/esc_game.gd +++ b/addons/escoria-core/game/core-scripts/esc_game.gd @@ -14,18 +14,28 @@ enum EDITOR_GAME_DEBUG_DISPLAY { } +# The main menu node +export(NodePath) var main_menu + +# The main menu node +export(NodePath) var pause_menu + # The safe margin around tooltips export(float) var mouse_tooltip_margin = 50.0 +# Which (if any) debug mode for the editor is used +export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = \ + EDITOR_GAME_DEBUG_DISPLAY.NONE setget _set_editor_debug_mode + # A reference to the node handling tooltips var tooltip_node: Object -# Which (if any) debug mode for the editor is used -export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = \ - EDITOR_GAME_DEBUG_DISPLAY.NONE setget _set_editor_debug_mode - +# Ready function +func _ready(): + escoria.apply_settings(escoria.settings) + # Handle debugging visualizations func _draw(): @@ -273,3 +283,23 @@ func update_tooltip_following_mouse_position(p_position: Vector2): func _set_editor_debug_mode(p_editor_debug_mode: int) -> void: editor_debug_mode = p_editor_debug_mode update() + + +# Pauses the game. Reimplement to eventually show a specific UI. +func pause_game(): + pass + + +# Unpause the game. Reimplement to eventually hide a specific UI. +func unpause_game(): + pass + + +# Shows the main menu. Reimplement to show a specific UI. +func show_main_menu(): + pass + + +# Hides the main menu. Reimplement to hide a specific UI. +func hide_main_menu(): + pass diff --git a/addons/escoria-core/game/core-scripts/esc_item.gd b/addons/escoria-core/game/core-scripts/esc_item.gd index d241f5d9..bc5c5291 100644 --- a/addons/escoria-core/game/core-scripts/esc_item.gd +++ b/addons/escoria-core/game/core-scripts/esc_item.gd @@ -307,7 +307,10 @@ func get_animation_player() -> Node: escoria.logger.warning( "Can not find node at path %s" % player_node_path ) - _animation_player = ESCAnimationPlayer.new(get_node(player_node_path)) + else: + _animation_player = ESCAnimationPlayer.new( + get_node(player_node_path) + ) return _animation_player diff --git a/addons/escoria-core/game/core-scripts/esc_room.gd b/addons/escoria-core/game/core-scripts/esc_room.gd index 61514826..e007cf2c 100644 --- a/addons/escoria-core/game/core-scripts/esc_room.gd +++ b/addons/escoria-core/game/core-scripts/esc_room.gd @@ -4,6 +4,13 @@ extends Node2D class_name ESCRoom, "res://addons/escoria-core/design/esc_room.svg" +# Emitted when room has finished ":setup" event. +signal room_setup_done + +# Emitted when room has finished ":ready" event. +signal room_ready_done + + # Debugging displays for a room # NONE: No debug display # CAMERA_LIMITS: Display the camera limits @@ -23,22 +30,31 @@ export(String, FILE, "*.esc") var esc_script = "" export(PackedScene) var player_scene # The camera limits available in this room -export(Array, Rect2) var camera_limits: Array = [Rect2()] setget set_camera_limits +export(Array, Rect2) var camera_limits: Array \ + = [Rect2()] setget set_camera_limits # The editor debug display mode -export(EditorRoomDebugDisplay) var editor_debug_mode = EditorRoomDebugDisplay.NONE setget set_editor_debug_mode +export(EditorRoomDebugDisplay) var editor_debug_mode \ + = EditorRoomDebugDisplay.NONE setget set_editor_debug_mode # The player scene instance var player - # The game scene instance var game - # Compiled ESCScript -var compiled_script: ESCScript +var compiled_script: ESCScript + +# Whether automatic transition are enabled or not +var enabled_automatic_transitions = true + +# Whether this room was run directly with Play Scene (F6) +var is_run_directly = false + +# Whether this room was accessed from an exit in a previous room +var exited_previous_room = false # Start the random number generator when the camera limits should be displayed @@ -59,7 +75,8 @@ func _ready(): if Engine.is_editor_hint(): return - game = $game + if has_node("game"): + game = $game if game == null: game = escoria.game_scene add_child(game) @@ -89,31 +106,121 @@ func _ready(): if global_id.empty(): global_id = name + + # Determine whether this room was run from change_scene or directly + if escoria.main.has_node(name): + is_run_directly = false + else: + is_run_directly = true + + perform_script_events() + + +func perform_script_events(): + if esc_script and escoria.event_manager._running_event == null \ + or (escoria.event_manager._running_event != null \ + and escoria.event_manager._running_event.name != "load"): - if esc_script: - run_script_event("setup") - var rc = yield(escoria.event_manager, "event_finished") - while rc[1] != "setup": - rc = yield(escoria.event_manager, "event_finished") - if rc[0] != ESCExecution.RC_OK: - return rc[0] - + # Manage player location at room start if (escoria.globals_manager.get_global("ESC_LAST_SCENE") == null \ - or escoria.globals_manager.get_global("ESC_LAST_SCENE").empty()) \ - and player != null \ - and escoria.object_manager.get_start_location() != null: + or escoria.globals_manager \ + .get_global("ESC_LAST_SCENE").empty()) \ + and player != null \ + and escoria.object_manager.get_start_location() != null: player.teleport(escoria.object_manager.get_start_location().node) + + # If the room was loaded from change_scene and automatic transitions + # are not disabled, do the transition out now + if enabled_automatic_transitions \ + and not is_run_directly \ + and not exited_previous_room: + var script_transition_out = escoria.esc_compiler.compile([ + ":transition_out", + "transition %s out" % ProjectSettings.get_setting( + "escoria/ui/default_transition" + ), + "hide_menu main" + ]) + escoria.event_manager.queue_event( + script_transition_out.events['transition_out'] + ) - escoria.main.scene_transition.transition() - yield(escoria.main.scene_transition, "transition_done") + # Run the setup event + _run_script_event("setup") + + if enabled_automatic_transitions \ + or ( + not enabled_automatic_transitions \ + and escoria.globals_manager.get_global("BYPASS_LAST_SCENE") + ): + var script_transition_in = escoria.esc_compiler.compile([ + ":transition_in", + "transition %s in" % ProjectSettings.get_setting( + "escoria/ui/default_transition" + ), + "wait 0.1" + ]) + escoria.event_manager.queue_event( + script_transition_in.events['transition_in'] + ) + + var ready_event_added: bool = false + # Run the ready event, if there is one. + if escoria.event_manager._running_event == null \ + or (escoria.event_manager._running_event != null \ + and escoria.event_manager._running_event.name != "load"): + ready_event_added = _run_script_event("ready") + + if ready_event_added: + # Wait for ready event to be done + var rc = yield(escoria.event_manager, "event_finished") + while rc[1] != "ready": + rc = yield(escoria.event_manager, "event_finished") + if rc[0] != ESCExecution.RC_OK: + return rc[0] + + # Now that :ready is finished, if BYPASS_LAST_SCENE was true, reset it + # to false and set ESC_LAST_SCENE to current scene + if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"): + escoria.globals_manager.set_global( + "BYPASS_LAST_SCENE", + false, + true + ) + escoria.globals_manager.set_global( + "ESC_LAST_SCENE", + escoria.main.current_scene.global_id, + true + ) + +# Runs the script event from the script attached, if any. +# +# #### Parameters +# +# - event_name: the name of the event to run +# +# *Returns* true if the event was correctly added. Will be false if the event +# does not exist in the script. +func _run_script_event(event_name: String): + if !esc_script: + return false + if compiled_script == null: + compiled_script = escoria.esc_compiler.load_esc_file(esc_script) - run_script_event("ready") - rc = yield(escoria.event_manager, "event_finished") - while rc[1] != "ready": - rc = yield(escoria.event_manager, "event_finished") - if rc[0] != ESCExecution.RC_OK: - return rc[0] + if compiled_script.events.has(event_name): + escoria.logger.debug( + "esc_room:_run_script_event", + [ + "Queuing room script event %s" % event_name, + "Composed of %s statements" % str(compiled_script.events[event_name].statements.size()) + ] + ) + escoria.event_manager.queue_event(compiled_script.events[event_name]) + return true + else: + return false + # Draw the camera limits visualization if enabled func _draw(): @@ -160,16 +267,4 @@ func set_editor_debug_mode(p_editor_debug_mode: int) -> void: update() -# Runs the script event from the script attached, if any -# -# #### Parameters -# -# - event_name: the name of the event to run -func run_script_event(event_name: String): - if !esc_script: - return - if compiled_script == null: - compiled_script = escoria.esc_compiler.load_esc_file(esc_script) - - if compiled_script.events.has(event_name): - escoria.event_manager.queue_event(compiled_script.events[event_name]) + diff --git a/addons/escoria-core/game/core-scripts/log/esc_logger.gd b/addons/escoria-core/game/core-scripts/log/esc_logger.gd index 9a6b0df6..55ea93bd 100644 --- a/addons/escoria-core/game/core-scripts/log/esc_logger.gd +++ b/addons/escoria-core/game/core-scripts/log/esc_logger.gd @@ -9,7 +9,7 @@ var warning_path: String # Valid log levels -enum { LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG } +enum { LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_TRACE } # A map of log level names to log level ints @@ -18,9 +18,21 @@ var _level_map: Dictionary = { "WARNING": LOG_WARNING, "INFO": LOG_INFO, "DEBUG": LOG_DEBUG, + "TRACE": LOG_TRACE, } +# Log a trace message +# +# #### Parameters +# +# * string: Text to log +# * args: Additional information +func trace(string: String, args = []): + if _get_log_level() >= LOG_TRACE: + var argsstr = str(args) if !args.empty() else "" + printerr("(T)\t" + string + " \t" + argsstr) + # Log a debug message # # #### Parameters diff --git a/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd b/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd index bc07d1e2..d5038b17 100644 --- a/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd +++ b/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd @@ -124,17 +124,24 @@ func load_game(id: int): var load_event = ESCEvent.new(":load") var load_statements = [] + load_statements.append( + ESCCommand.new( + "transition %s out" % + [ProjectSettings.get_setting("escoria/ui/default_transition")] + ) + ) + ## GLOBALS for k in save_game.globals.keys(): load_statements.append( ESCCommand.new("set_global %s \"%s\"\n" \ - % [k, save_game.globals[k]]) + % [k, save_game.globals[k]]) ) ## ROOM load_statements.append( ESCCommand.new("change_scene %s true" \ - % save_game.main["current_scene_filename"]) + % save_game.main["current_scene_filename"]) ) ## OBJECTS @@ -147,36 +154,43 @@ func load_game(id: int): if save_game.objects[object_global_id].has("interactive"): load_statements.append(ESCCommand.new("set_interactive %s %s" \ - % [object_global_id, + % [object_global_id, save_game.objects[object_global_id]["interactive"]]) ) if save_game.objects[object_global_id].has("state"): load_statements.append(ESCCommand.new("set_state %s %s true" \ - % [object_global_id, + % [object_global_id, save_game.objects[object_global_id]["state"]]) ) if save_game.objects[object_global_id].has("global_transform"): load_statements.append(ESCCommand.new("teleport_pos %s %s %s" \ - % [object_global_id, + % [object_global_id, int(save_game.objects[object_global_id] \ - ["global_transform"].origin.x), + ["global_transform"].origin.x), int(save_game.objects[object_global_id] \ - ["global_transform"].origin.y)] + ["global_transform"].origin.y)] ) ) load_statements.append(ESCCommand.new("set_angle %s %s" \ - % [object_global_id, + % [object_global_id, save_game.objects[object_global_id]["last_deg"]]) ) if object_global_id == "_music" or object_global_id == "_sound": load_statements.append(ESCCommand.new("set_sound_state %s %s true" \ - % [object_global_id, + % [object_global_id, save_game.objects[object_global_id]["state"]]) ) + load_statements.append( + ESCCommand.new( + "transition %s in" % + [ProjectSettings.get_setting("escoria/ui/default_transition")] + ) + ) + load_event.statements = load_statements escoria.set_game_paused(false) @@ -212,7 +226,8 @@ func save_settings(): # Load the game settings from the settings file # **Returns** The Resource structure loaded from settings file func load_settings() -> Resource: - var save_settings_path: String = settings_folder.plus_file(SETTINGS_TEMPLATE) + var save_settings_path: String = \ + settings_folder.plus_file(SETTINGS_TEMPLATE) var file: File = File.new() if not file.file_exists(save_settings_path): escoria.logger.report_warnings( diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd index 29bfd123..d9aee33e 100644 --- a/addons/escoria-core/game/escoria.gd +++ b/addons/escoria-core/game/escoria.gd @@ -122,7 +122,7 @@ func _init(): # Load settings func _ready(): settings = save_manager.load_settings() - _on_settings_loaded(settings) + apply_settings(settings) inputs_manager.register_core() if ProjectSettings.get_setting("escoria/main/game_start_script").empty(): logger.report_errors("escoria.gd", @@ -265,7 +265,7 @@ func do(action: String, params: Array = [], can_interrupt: bool = false) -> void # #### Parameters # # * p_settings: Loaded settings -func _on_settings_loaded(p_settings: ESCSaveSettings) -> void: +func apply_settings(p_settings: ESCSaveSettings) -> void: logger.info("******* settings loaded") if p_settings != null: settings = p_settings diff --git a/addons/escoria-core/game/main.gd b/addons/escoria-core/game/main.gd index 9f1c6648..5e40b138 100644 --- a/addons/escoria-core/game/main.gd +++ b/addons/escoria-core/game/main.gd @@ -40,9 +40,10 @@ func set_scene(p_scene: Node) -> void: if current_scene != null: clear_scene() - if not p_scene in get_children(): + if not p_scene.is_inside_tree() or not p_scene in get_children(): add_child(p_scene) - move_child(p_scene, 0) + elif p_scene in get_children(): + move_child(p_scene, 0) current_scene = p_scene check_game_scene_methods() @@ -62,7 +63,7 @@ func clear_scene() -> void: if escoria.game_scene.get_parent() == current_scene: current_scene.remove_child(escoria.game_scene) - remove_child(current_scene) + current_scene.get_parent().remove_child(current_scene) current_scene.free() current_scene = null diff --git a/addons/escoria-core/game/scenes/transitions/esc_transition_player.gd b/addons/escoria-core/game/scenes/transitions/esc_transition_player.gd index 5671e851..67d0671d 100644 --- a/addons/escoria-core/game/scenes/transitions/esc_transition_player.gd +++ b/addons/escoria-core/game/scenes/transitions/esc_transition_player.gd @@ -3,8 +3,11 @@ extends ColorRect class_name ESCTransitionPlayer # Emitted when the transition was played -signal transition_done +signal transition_done(transition_id) +# Id of the transition. Allows keeping track of the actual transition +# being played or finished +var transition_id: int = 0 # The valid transition modes enum TRANSITION_MODE { @@ -47,26 +50,28 @@ func transition( transition_name: String = "", mode: int = TRANSITION_MODE.IN, duration: float = 1.0 -) -> void: +) -> int: if not has_transition(transition_name): escoria.logger.report_errors( "transition: Transition %s not found" % transition_name, [] ) - - material = ResourceLoader.load(get_transition(transition_name)) - var start = 0 - var end = 1 + material = ResourceLoader.load(get_transition(transition_name)) + transition_id += 1 + + var start = 0.0 + var end = 1.0 if mode == TRANSITION_MODE.OUT: - start = 1 - end = 0 + start = 1.0 + end = 0.0 if _tween.is_active(): _was_canceled = true _tween.stop_all() _tween.remove_all() + emit_signal("transition_done", transition_id-1) _tween.interpolate_property( $".", @@ -77,7 +82,7 @@ func transition( ) _was_canceled = false _tween.start() - + return transition_id # Returns the full path for a transition shader based on its name @@ -112,6 +117,6 @@ func has_transition(name: String) -> bool: func _on_tween_completed(): if not _was_canceled: - emit_signal("transition_done") _tween.stop_all() _tween.remove_all() + emit_signal("transition_done", transition_id) diff --git a/addons/escoria-core/game/scenes/transitions/transition.tscn b/addons/escoria-core/game/scenes/transitions/transition.tscn index 4ba2bd7e..1bc0e81b 100644 --- a/addons/escoria-core/game/scenes/transitions/transition.tscn +++ b/addons/escoria-core/game/scenes/transitions/transition.tscn @@ -12,5 +12,3 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } - -[node name="Tween" type="Tween" parent="."] diff --git a/addons/escoria-core/ui_library/menus/options/options.gd b/addons/escoria-core/ui_library/menus/options/options.gd index 3b172d27..16055809 100644 --- a/addons/escoria-core/ui_library/menus/options/options.gd +++ b/addons/escoria-core/ui_library/menus/options/options.gd @@ -76,7 +76,7 @@ func _on_language_input(event: InputEvent, language: String): # - value: The new volume level func _on_sound_volume_changed(value): escoria.settings["sfx_volume"] = value - escoria._on_settings_loaded(escoria.settings) + escoria.apply_settings(escoria.settings) settings_changed = true @@ -86,7 +86,7 @@ func _on_sound_volume_changed(value): # - value: The new volume level func _on_music_volume_changed(value): escoria.settings["music_volume"] = value - escoria._on_settings_loaded(escoria.settings) + escoria.apply_settings(escoria.settings) settings_changed = true @@ -96,7 +96,7 @@ func _on_music_volume_changed(value): # - value: The new volume level func _on_general_volume_changed(value): escoria.settings["master_volume"] = value - escoria._on_settings_loaded(escoria.settings) + escoria.apply_settings(escoria.settings) settings_changed = true @@ -106,7 +106,7 @@ func _on_general_volume_changed(value): # - value: The new volume level func _on_speech_volume_value_changed(value: float) -> void: escoria.settings["speech_volume"] = value - escoria._on_settings_loaded(escoria.settings) + escoria.apply_settings(escoria.settings) settings_changed = true @@ -120,5 +120,5 @@ func _on_apply_pressed(): # The back button was pressed func _on_back_pressed(): escoria.settings = backup_settings - escoria._on_settings_loaded(escoria.settings) + escoria.apply_settings(escoria.settings) emit_signal("back_button_pressed") diff --git a/addons/escoria-core/ui_library/menus/pause_menu/pause_menu.gd b/addons/escoria-core/ui_library/menus/pause_menu/pause_menu.gd index 5f4742e4..cb948f97 100644 --- a/addons/escoria-core/ui_library/menus/pause_menu/pause_menu.gd +++ b/addons/escoria-core/ui_library/menus/pause_menu/pause_menu.gd @@ -10,7 +10,7 @@ func _ready(): # Continue the game func _on_continue_pressed(): - escoria.main.current_scene.game.pause_game() + escoria.main.current_scene.game.unpause_game() # Show the save slots diff --git a/addons/escoria-core/ui_library/tools/room_select/room_select.gd b/addons/escoria-core/ui_library/tools/room_select/room_select.gd index 6f9ddd3f..a00f4b0d 100644 --- a/addons/escoria-core/ui_library/tools/room_select/room_select.gd +++ b/addons/escoria-core/ui_library/tools/room_select/room_select.gd @@ -16,7 +16,9 @@ func _ready(): "escoria/debug/room_selector_room_dir" ) if rooms_folder == "" or \ - not ProjectSettings.get_setting("escoria/debug/enable_room_selector"): + not ProjectSettings.get_setting( + "escoria/debug/enable_room_selector" + ): return var dir = Directory.new() var rooms_list: Array = [] @@ -50,11 +52,12 @@ func _ready(): func _on_button_pressed(): escoria.globals_manager.set_global("BYPASS_LAST_SCENE", true, true) var script = escoria.esc_compiler.compile([ - ":debug", + ":room_selector", "change_scene %s" % _options_paths[_selected_id] ]) escoria.event_manager.interrupt_running_event() - escoria.event_manager.queue_event(script.events['debug']) + escoria.event_manager.clear_event_queue() + escoria.event_manager.queue_event(script.events['room_selector']) diff --git a/addons/escoria-ui-9verbs/game.gd b/addons/escoria-ui-9verbs/game.gd index e612c91b..7c1b3d90 100644 --- a/addons/escoria-ui-9verbs/game.gd +++ b/addons/escoria-ui-9verbs/game.gd @@ -27,6 +27,11 @@ Implement methods to react to inputs. - hide_ui() - show_ui() +- pause_game() +- unpause_game() +- show_main_menu() +- hide_main_menu() + - _on_event_done(event_name: String) """ @@ -36,7 +41,6 @@ onready var tooltip = $ui/Control/panel_down/VBoxContainer/MarginContainer\ /tooltip onready var room_select = $ui/Control/panel_down/VBoxContainer/HBoxContainer\ /MainMargin/VBoxContainer/room_select -onready var pause_menu = $ui/pause_menu onready var inventory_ui = $ui/Control/panel_down/VBoxContainer/HBoxContainer\ /InventoryMargin/inventory_ui @@ -195,23 +199,31 @@ func _on_event_done(_event_name: String): escoria.action_manager.clear_current_action() verbs_menu.unselect_actions() +func hide_main_menu(): + if get_node(main_menu).visible: + get_node(main_menu).hide() -func pause_game(): - if pause_menu.visible: - pause_menu.hide() +func show_main_menu(): + if not get_node(main_menu).visible: + get_node(main_menu).show() + +func unpause_game(): + if get_node(pause_menu).visible: + get_node(pause_menu).hide() escoria.object_manager.get_object("_camera").node.current = true escoria.main.current_scene.game.show_ui() escoria.main.current_scene.show() escoria.set_game_paused(false) - else: - pause_menu.set_save_enabled(escoria.save_manager.save_enabled) - pause_menu.show() + +func pause_game(): + if not get_node(pause_menu).visible: + get_node(pause_menu).set_save_enabled(escoria.save_manager.save_enabled) + get_node(pause_menu).show() escoria.object_manager.get_object("_camera").node.current = false escoria.main.current_scene.game.hide_ui() escoria.main.current_scene.hide() escoria.set_game_paused(true) - func _on_MenuButton_pressed() -> void: pause_game() diff --git a/addons/escoria-ui-9verbs/game.tscn b/addons/escoria-ui-9verbs/game.tscn index ce3a7731..44ec4dc6 100644 --- a/addons/escoria-ui-9verbs/game.tscn +++ b/addons/escoria-ui-9verbs/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://addons/escoria-ui-9verbs/tooltip/action_target_tooltip.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/escoria-ui-9verbs/inventory/inventory_ui.tscn" type="PackedScene" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" type="Script" id=4] [ext_resource path="res://addons/escoria-ui-9verbs/game.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-core/game/scenes/camera_player/camera.tscn" type="PackedScene" id=6] +[ext_resource path="res://addons/escoria-core/ui_library/menus/main_menu/main_menu.tscn" type="PackedScene" id=7] [ext_resource path="res://addons/escoria-ui-9verbs/tooltip/tooltip_action_target.gd" type="Script" id=8] [ext_resource path="res://addons/escoria-core/ui_library/menus/pause_menu/pause_menu.tscn" type="PackedScene" id=9] [ext_resource path="res://addons/escoria-ui-9verbs/theme.tres" type="Theme" id=10] @@ -15,6 +16,8 @@ bg_color = Color( 0.6, 0.6, 0.6, 0.5 ) [node name="game" type="Node2D"] script = ExtResource( 5 ) +main_menu = NodePath("ui/main_menu") +pause_menu = NodePath("ui/pause_menu") [node name="ui" type="CanvasLayer" parent="."] @@ -153,6 +156,9 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="main_menu" parent="ui" instance=ExtResource( 7 )] +visible = false + [node name="pause_menu" parent="ui" instance=ExtResource( 9 )] visible = false theme = ExtResource( 10 ) diff --git a/addons/escoria-ui-simplemouse/game.gd b/addons/escoria-ui-simplemouse/game.gd index b6b68f83..3297b111 100644 --- a/addons/escoria-ui-simplemouse/game.gd +++ b/addons/escoria-ui-simplemouse/game.gd @@ -27,6 +27,11 @@ Implement methods to react to inputs. - hide_ui() - show_ui() +- pause_game() +- unpause_game() +- show_main_menu() +- hide_main_menu() + - _on_event_done(event_name: String) """ @@ -171,18 +176,27 @@ func _on_event_done(event_name: String): escoria.action_manager.clear_current_action() $CanvasLayer/ui/HBoxContainer/verbs_menu.clear_tool_texture() +func hide_main_menu(): + if get_node(main_menu).visible: + get_node(main_menu).hide() -func pause_game(): - if $CanvasLayer/pause_menu.visible: - $CanvasLayer/pause_menu.hide() +func show_main_menu(): + if not get_node(main_menu).visible: + get_node(main_menu).show() + +func unpause_game(): + if get_node(pause_menu).visible: + get_node(pause_menu).hide() escoria.object_manager.get_object("_camera").node.current = true escoria.main.current_scene.game.show_ui() escoria.main.current_scene.show() - else: - $CanvasLayer/pause_menu.set_save_enabled( + +func pause_game(): + if not get_node(pause_menu).visible: + get_node(pause_menu).set_save_enabled( escoria.save_manager.save_enabled ) - $CanvasLayer/pause_menu.show() + get_node(pause_menu).show() escoria.object_manager.get_object("_camera").node.current = false escoria.main.current_scene.game.hide_ui() escoria.main.current_scene.hide() diff --git a/addons/escoria-ui-simplemouse/game.tscn b/addons/escoria-ui-simplemouse/game.tscn index 8a6677b5..91ef52e6 100644 --- a/addons/escoria-ui-simplemouse/game.tscn +++ b/addons/escoria-ui-simplemouse/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://addons/escoria-ui-simplemouse/inventory/inventory_ui.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" type="Script" id=2] @@ -6,11 +6,14 @@ [ext_resource path="res://addons/escoria-ui-simplemouse/verbs_mouseicons.tscn" type="PackedScene" id=4] [ext_resource path="res://addons/escoria-ui-simplemouse/game.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-ui-simplemouse/tooltip/target_tooltip.tscn" type="PackedScene" id=6] +[ext_resource path="res://addons/escoria-core/ui_library/menus/main_menu/main_menu.tscn" type="PackedScene" id=7] [ext_resource path="res://addons/escoria-core/ui_library/menus/pause_menu/pause_menu.tscn" type="PackedScene" id=8] [ext_resource path="res://addons/escoria-ui-simplemouse/theme.tres" type="Theme" id=9] [node name="game" type="Node2D"] script = ExtResource( 5 ) +main_menu = NodePath("CanvasLayer/main_menu") +pause_menu = NodePath("CanvasLayer/pause_menu") editor_debug_mode = 1 [node name="camera" parent="." instance=ExtResource( 3 )] @@ -69,6 +72,9 @@ rect_scale = Vector2( 1, 1 ) visible = false theme = ExtResource( 9 ) +[node name="main_menu" parent="CanvasLayer" instance=ExtResource( 7 )] +visible = false + [node name="dialog_layer" type="CanvasLayer" parent="."] layer = 3 diff --git a/game/rooms/room01/esc/room01.esc b/game/rooms/room01/esc/room01.esc index 82903288..2d8e0d40 100644 --- a/game/rooms/room01/esc/room01.esc +++ b/game/rooms/room01/esc/room01.esc @@ -1,4 +1,6 @@ :setup + + > [eq ESC_LAST_SCENE room2] teleport player r1_r_exit # Set player look left @@ -6,8 +8,8 @@ stop - :ready + set_sound_state _music res://game/sfx/contemplation.ogg true > [!room1_visited] diff --git a/game/rooms/room01/room01.tscn b/game/rooms/room01/room01.tscn index 6caca5a9..6ce91917 100644 --- a/game/rooms/room01/room01.tscn +++ b/game/rooms/room01/room01.tscn @@ -26,10 +26,25 @@ editor_debug_mode = 1 [node name="advice" type="Label" parent="background"] anchor_right = 0.023274 anchor_bottom = 0.018018 +margin_left = 90.0 +margin_top = 59.0 +margin_right = 338.0 +margin_bottom = 118.0 +custom_fonts/font = ExtResource( 3 ) +text = "Don't click immediately! +Player will walk around the room, +but you can interrupt him if you want." +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="advice2" type="Label" parent="background"] +anchor_right = 0.023274 +anchor_bottom = 0.018018 margin_left = 90.2752 -margin_top = 120.824 +margin_top = 170.824 margin_right = 270.275 -margin_bottom = 155.824 +margin_bottom = 205.824 custom_fonts/font = ExtResource( 3 ) text = "Move : left click Fast move : double left click" diff --git a/game/rooms/room02/esc/room02_bridge.esc b/game/rooms/room02/esc/room02_bridge.esc index 4c305b87..3804f426 100644 --- a/game/rooms/room02/esc/room02_bridge.esc +++ b/game/rooms/room02/esc/room02_bridge.esc @@ -2,6 +2,7 @@ :setup + > [r2_bridge_closed] # Make set_state IMMEDIATE to reach the final frame immediately set_state r2_bridge bridge_close true @@ -13,6 +14,7 @@ # Set player look left set_angle player 180 stop + > [eq ESC_LAST_SCENE room3] teleport player r2_r_exit # Set player look left @@ -25,7 +27,8 @@ set_interactive r2_right_platform false #set_interactive r2_bridge false stop - + + :ready diff --git a/game/rooms/room04/esc/room04.esc b/game/rooms/room04/esc/room04.esc index 94925cfd..a5c75000 100644 --- a/game/rooms/room04/esc/room04.esc +++ b/game/rooms/room04/esc/room04.esc @@ -1,4 +1,6 @@ :setup + + > [eq ESC_LAST_SCENE room3] teleport player l_exit # Set player look right diff --git a/game/rooms/room05/esc/room05.esc b/game/rooms/room05/esc/room05.esc index e563357c..209d314e 100644 --- a/game/rooms/room05/esc/room05.esc +++ b/game/rooms/room05/esc/room05.esc @@ -1,5 +1,6 @@ :setup + # Disable wrench item if present in the inventory > [i/r5_wrench] set_active r5_wrench false diff --git a/game/rooms/room06/esc/room06.esc b/game/rooms/room06/esc/room06.esc index 02c0f2b1..1a013417 100644 --- a/game/rooms/room06/esc/room06.esc +++ b/game/rooms/room06/esc/room06.esc @@ -1,4 +1,5 @@ :setup + > [eq ESC_LAST_SCENE room5] teleport player r6_l_exit # Set player look right diff --git a/game/rooms/room10/esc/room10.esc b/game/rooms/room10/esc/room10.esc index 91d8530b..a7f49ff2 100644 --- a/game/rooms/room10/esc/room10.esc +++ b/game/rooms/room10/esc/room10.esc @@ -1,5 +1,6 @@ :setup + > [eq ESC_LAST_SCENE room9] teleport player r10_l_exit # Set player look right diff --git a/game/rooms/room11/esc/right_exit.esc b/game/rooms/room11/esc/right_exit.esc old mode 100755 new mode 100644 index a3827d76..00b5360f --- a/game/rooms/room11/esc/right_exit.esc +++ b/game/rooms/room11/esc/right_exit.esc @@ -1,5 +1,5 @@ :exit_scene set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false transition fade_black out -change_scene "res://game/rooms/room12/room12.tscn" true +change_scene "res://game/rooms/room12/room12.tscn" false diff --git a/game/rooms/room11/esc/room11.esc b/game/rooms/room11/esc/room11.esc index 28d4f42a..d333a34b 100644 --- a/game/rooms/room11/esc/room11.esc +++ b/game/rooms/room11/esc/room11.esc @@ -1,5 +1,6 @@ :setup + set_state _music off false > [eq ESC_LAST_SCENE room10] diff --git a/game/rooms/room12/esc/room12.esc b/game/rooms/room12/esc/room12.esc index 22a0f8a9..acca1dd4 100644 --- a/game/rooms/room12/esc/room12.esc +++ b/game/rooms/room12/esc/room12.esc @@ -5,6 +5,10 @@ teleport player r12_l_exit # Set player look right set_angle player 180 + + # Transition in + transition curtain in + stop > [eq ESC_LAST_SCENE room13] teleport player r12_r_exit diff --git a/game/rooms/room13/esc/right_exit.esc b/game/rooms/room13/esc/right_exit.esc index 2e1d39f2..cf038e01 100644 --- a/game/rooms/room13/esc/right_exit.esc +++ b/game/rooms/room13/esc/right_exit.esc @@ -1,3 +1,3 @@ :exit_scene #set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false -#change_scene "res://game/rooms/room14/room14.tscn" +change_scene "res://game/rooms/room14/room14.tscn" diff --git a/game/rooms/room13/esc/room13.esc b/game/rooms/room13/esc/room13.esc index faf6fe70..1ea27482 100644 --- a/game/rooms/room13/esc/room13.esc +++ b/game/rooms/room13/esc/room13.esc @@ -2,4 +2,5 @@ :setup + :ready diff --git a/game/rooms/room13/room13.tscn b/game/rooms/room13/room13.tscn index 008458e5..8611d25d 100644 --- a/game/rooms/room13/room13.tscn +++ b/game/rooms/room13/room13.tscn @@ -1,13 +1,12 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1] -[ext_resource path="res://game/rooms/room12/background.tscn" type="PackedScene" id=2] +[ext_resource path="res://game/rooms/room13/background.tscn" type="PackedScene" id=2] [ext_resource path="res://game/fonts/caslonantique.tres" type="DynamicFont" id=3] -[ext_resource path="res://game/characters/mark/mark.tscn" type="PackedScene" id=4] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=7] -[ext_resource path="res://game/rooms/room12/r_door.tscn" type="PackedScene" id=8] +[ext_resource path="res://game/rooms/room13/r_door.tscn" type="PackedScene" id=8] [sub_resource type="NavigationPolygon" id=1] vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 864.626, 613.518, 1143.08, 613.35, -9.16094, 803.802, 386.666, 618.012, 129.634, 615.792, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 ) @@ -70,7 +69,7 @@ global_id = "r12_l_exit" [node name="r_door" parent="Hotspots" instance=ExtResource( 8 )] global_id = "r13_r_exit" -esc_script = "res://game/rooms/room12/esc/right_exit.esc" +esc_script = "res://game/rooms/room13/esc/right_exit.esc" default_action = "use" [node name="ESCLocation" type="Position2D" parent="Hotspots/r_door"] @@ -102,7 +101,3 @@ __meta__ = { [node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/Hint"] position = Vector2( 651.176, 177.775 ) shape = SubResource( 2 ) - -[node name="mark" parent="." instance=ExtResource( 4 )] -visible = false -position = Vector2( 620.216, 504.362 ) diff --git a/game/rooms/room14/background.tscn b/game/rooms/room14/background.tscn new file mode 100644 index 00000000..fa42fc10 --- /dev/null +++ b/game/rooms/room14/background.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_background.gd" type="Script" id=1] + +[node name="background" type="TextureRect"] +margin_right = 1289.0 +margin_bottom = 555.0 +mouse_filter = 2 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="l_platform" type="Line2D" parent="."] +position = Vector2( 2, -266 ) +points = PoolVector2Array( -2.96298, 712.01, 129.973, 614.429, 1167.5, 612.894, 1274.59, 669.705, 1273.25, 812.694, 2.36697, 811.043, 2.36697, 713.389 ) + +[node name="l_door" type="Line2D" parent="."] +position = Vector2( 0, -266 ) +points = PoolVector2Array( 6.61201, 704.409, 6.61203, 389.558, 87.755, 339.775, 87.5463, 649.784 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="r_door" type="Line2D" parent="."] +position = Vector2( 0, -267.828 ) +points = PoolVector2Array( 1175.07, 620.086, 1171.24, 311.267, 1274.8, 356.87, 1278.31, 672.412, 1188.64, 624.843 ) +__meta__ = { +"_editor_description_": "" +} diff --git a/game/rooms/room14/esc/button_main_menu.esc b/game/rooms/room14/esc/button_main_menu.esc new file mode 100644 index 00000000..abd4f935 --- /dev/null +++ b/game/rooms/room14/esc/button_main_menu.esc @@ -0,0 +1,13 @@ + +:use + + +# Show main menu, automatic transitions ENABLED +show_menu main true + +# wait 2 seconds +wait 2 + +# Hide main menu, automatic transitions ENABLED +hide_menu main true + diff --git a/game/rooms/room14/esc/button_main_menu_change_scene.esc b/game/rooms/room14/esc/button_main_menu_change_scene.esc new file mode 100644 index 00000000..ed14a8db --- /dev/null +++ b/game/rooms/room14/esc/button_main_menu_change_scene.esc @@ -0,0 +1,37 @@ + +:use + +# This event demonstrates the following: +#- fade out to black +#- show the main menu (automatic transition disabled to manage those manually) +#- wait 2 seconds +#- change scene (automatic transition disabled to managed those manually) to reload this same room + + +# Fade out to black +transition fade_black out +wait 2 + +# Show main menu, automatic transition DISABLED +show_menu pause + +# Showing menu +transition shards in + +# Wait 2 seconds on menu +wait 2 + +# Transition out before hiding menu +transition fade_black out + +# Hide the menu +hide_menu pause +wait 1 + +# Do NOT transition IN as this transition will be managed by the room's :setup event! +# If you transition IN here instead of room's :setup event, you will show the previous room + +# Change scene to same scene, disabled automatic transition +change_scene res://game/rooms/room14/room14.tscn true + +# Do not transition here either, as change_scene ends the execution of this script diff --git a/game/rooms/room14/esc/button_pause_menu.esc b/game/rooms/room14/esc/button_pause_menu.esc new file mode 100644 index 00000000..d0ca65d5 --- /dev/null +++ b/game/rooms/room14/esc/button_pause_menu.esc @@ -0,0 +1,13 @@ + +:use + +# Show pause menu, automatic transition are disabled by default +# So we can manage them manually using `transition` ESC command +show_menu pause + +# wait 2 seconds +wait 2 + +# Hide pause menu, automatic transition are disabled by default +# So we can manage them manually using `transition` ESC command +hide_menu pause diff --git a/game/rooms/room14/esc/left_exit.esc b/game/rooms/room14/esc/left_exit.esc new file mode 100644 index 00000000..ccd7945a --- /dev/null +++ b/game/rooms/room14/esc/left_exit.esc @@ -0,0 +1,5 @@ +:exit_scene +set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false +change_scene "res://game/rooms/room13/room13.tscn" + + diff --git a/game/rooms/room14/esc/right_exit.esc b/game/rooms/room14/esc/right_exit.esc new file mode 100644 index 00000000..a73b2437 --- /dev/null +++ b/game/rooms/room14/esc/right_exit.esc @@ -0,0 +1,3 @@ +:exit_scene +#set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false +#change_scene "res://game/rooms/room15/room15.tscn" diff --git a/game/rooms/room14/esc/room14.esc b/game/rooms/room14/esc/room14.esc new file mode 100644 index 00000000..3fa40dbf --- /dev/null +++ b/game/rooms/room14/esc/room14.esc @@ -0,0 +1,29 @@ + +:setup + +> [eq ESC_LAST_SCENE room13] + teleport player r14_l_exit + # Set player look right + set_angle player 90 + stop + +> [eq ESC_LAST_SCENE room15] + teleport player r14_r_exit + # Set player look left + set_angle player 270 + stop + +# If we're coming from the same room as this one, we manage the player's position +# AND the transition IN manually +> [eq ESC_LAST_SCENE room14] + teleport player start + + # Set player look left + set_angle player 270 + + # Fade in from black + transition fade_black in + stop + + +:ready diff --git a/game/rooms/room14/r_door.tscn b/game/rooms/room14/r_door.tscn new file mode 100644 index 00000000..39b4fa38 --- /dev/null +++ b/game/rooms/room14/r_door.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=1] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=2] + +[node name="r_door" type="Area2D"] +pause_mode = 1 +script = ExtResource( 1 ) +__meta__ = { +"_editor_description_": "" +} +global_id = "r1_r_exit" +esc_script = "res://game/rooms/room01/esc/right_exit.esc" +is_exit = true +tooltip_name = "Exit" +default_action = "walk" +dialog_color = Color( 1, 1, 1, 1 ) +animations = null + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] +polygon = PoolVector2Array( 1177.94, 348.61, 1175.95, 45.3759, 1276.06, 92.0953, 1277.95, 399.407 ) + +[node name="Position2D" type="Position2D" parent="."] +position = Vector2( 1225.47, 353.99 ) +script = ExtResource( 2 ) diff --git a/game/rooms/room14/room14.tscn b/game/rooms/room14/room14.tscn new file mode 100644 index 00000000..dc6810fd --- /dev/null +++ b/game/rooms/room14/room14.tscn @@ -0,0 +1,151 @@ +[gd_scene load_steps=11 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1] +[ext_resource path="res://game/rooms/room14/background.tscn" type="PackedScene" id=2] +[ext_resource path="res://game/fonts/caslonantique.tres" type="DynamicFont" id=3] +[ext_resource path="res://game/characters/mark/mark.tscn" type="PackedScene" id=4] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=5] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=7] +[ext_resource path="res://game/rooms/room14/r_door.tscn" type="PackedScene" id=8] +[ext_resource path="res://game/items/escitems/button.tscn" type="PackedScene" id=9] + +[sub_resource type="NavigationPolygon" id=1] +vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 864.626, 613.518, 1143.08, 613.35, -9.16094, 803.802, 386.666, 618.012, 129.634, 615.792, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 ) +polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 4, 5, 0, 3, 6, 7 ), PoolIntArray( 8, 7, 6, 9 ), PoolIntArray( 9, 6, 10, 11, 12 ) ] +outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 386.666, 618.012, 864.626, 613.518, 1143.08, 613.35, 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, -9.16094, 803.802 ) ] + +[node name="room14" type="Node2D"] +script = ExtResource( 6 ) +__meta__ = { +"_edit_vertical_guides_": [ ] +} +global_id = "room14" +esc_script = "res://game/rooms/room14/esc/room14.esc" +player_scene = ExtResource( 4 ) +camera_limits = [ Rect2( 0, 0, 1289, 555 ) ] + +[node name="background" parent="." instance=ExtResource( 2 )] + +[node name="room_label" type="Label" parent="background"] +margin_right = 92.0 +margin_bottom = 21.0 +custom_fonts/font = ExtResource( 3 ) +text = "ROOM 14" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="walkable_area" type="Navigation2D" parent="."] +script = ExtResource( 1 ) + +[node name="platform" type="NavigationPolygonInstance" parent="walkable_area"] +position = Vector2( 6.73163, -264.779 ) +navpoly = SubResource( 1 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="Hotspots" type="Node" parent="."] + +[node name="l_door" type="Area2D" parent="Hotspots"] +pause_mode = 1 +script = ExtResource( 7 ) +global_id = "r14_l_exit" +esc_script = "res://game/rooms/room14/esc/left_exit.esc" +is_exit = true +tooltip_name = "Left exit" +default_action = "use" +dialog_color = Color( 1, 1, 1, 1 ) +animations = null + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/l_door"] +polygon = PoolVector2Array( 0.328762, 440.897, 1.85199, 119.926, 85.9517, 74.6212, 87.1409, 377.869 ) + +[node name="Position2D" type="Position2D" parent="Hotspots/l_door"] +position = Vector2( 37.4521, 392.045 ) +script = ExtResource( 5 ) +global_id = "r12_l_exit" + +[node name="r_door" parent="Hotspots" instance=ExtResource( 8 )] +global_id = "r14_r_exit" +esc_script = "res://game/rooms/room14/esc/right_exit.esc" +default_action = "use" + +[node name="ESCLocation" type="Position2D" parent="Hotspots/r_door"] +position = Vector2( 1231.78, 360.624 ) +script = ExtResource( 5 ) + +[node name="start" type="Position2D" parent="Hotspots"] +position = Vector2( 243.677, 455.569 ) +script = ExtResource( 5 ) +global_id = "start" +is_start_location = true +interaction_direction = 180 + +[node name="show_main_menu" parent="." instance=ExtResource( 9 )] +global_id = "button_main_menu" +esc_script = "res://game/rooms/room14/esc/button_main_menu.esc" + +[node name="ESCLocation" type="Position2D" parent="show_main_menu"] +position = Vector2( 343.887, 381.305 ) +script = ExtResource( 5 ) + +[node name="Label" type="Label" parent="show_main_menu"] +margin_left = 285.569 +margin_top = 194.216 +margin_right = 408.569 +margin_bottom = 259.216 +text = "Show main menu +with autmatic +transitions enabled +" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="show_pause_menu" parent="." instance=ExtResource( 9 )] +position = Vector2( 233.415, 0 ) +global_id = "button_pause_menu" +esc_script = "res://game/rooms/room14/esc/button_pause_menu.esc" + +[node name="ESCLocation" type="Position2D" parent="show_pause_menu"] +position = Vector2( 343.887, 381.305 ) +script = ExtResource( 5 ) + +[node name="Label" type="Label" parent="show_pause_menu"] +margin_left = 273.915 +margin_top = 194.216 +margin_right = 413.915 +margin_bottom = 242.216 +text = "Show pause menu +with NO transition +(manual or automatic)" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="show_main_change_scene" parent="." instance=ExtResource( 9 )] +position = Vector2( 463.318, 0 ) +global_id = "button_main_change_scene" +esc_script = "res://game/rooms/room14/esc/button_main_menu_change_scene.esc" + +[node name="ESCLocation" type="Position2D" parent="show_main_change_scene"] +position = Vector2( 343.887, 381.305 ) +script = ExtResource( 5 ) + +[node name="Label" type="Label" parent="show_main_change_scene"] +margin_left = 277.027 +margin_top = 194.0 +margin_right = 428.027 +margin_bottom = 259.0 +text = "Show main menu with +manual transition +and change_scene with +manual transition" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/game/rooms/room14/walkable_area.tscn b/game/rooms/room14/walkable_area.tscn new file mode 100644 index 00000000..2d6b73ec --- /dev/null +++ b/game/rooms/room14/walkable_area.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1] + +[sub_resource type="NavigationPolygon" id=1] +vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 129.634, 615.792, 1143.08, 613.35, -9.16094, 803.802, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 ) +polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 4, 5, 0, 3, 6, 7 ), PoolIntArray( 7, 6, 8, 9, 10 ) ] +outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 1143.08, 613.35, 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, -9.16094, 803.802 ) ] + +[node name="walkable_area" type="Navigation2D"] +script = ExtResource( 1 ) + +[node name="platform" type="NavigationPolygonInstance" parent="."] +position = Vector2( 6.73163, -264.779 ) +navpoly = SubResource( 1 ) +__meta__ = { +"_editor_description_": "" +} diff --git a/game/start_game.esc b/game/start_game.esc index 515f2b6a..35e9208c 100644 --- a/game/start_game.esc +++ b/game/start_game.esc @@ -1,15 +1,14 @@ :init set_sound_state _music res://game/sfx/Game-Menu_Looping.mp3 true -spawn _main_menu res://addons/escoria-core/ui_library/menus/main_menu/main_menu.tscn false -set_active _main_menu true + +# Showing main menu with automatic transition DISABLED +show_menu main + :newgame -# Hide main menu -set_active _main_menu false - # 1/ Simple scene change_scene res://game/rooms/room01/room01.tscn @@ -47,4 +46,9 @@ change_scene res://game/rooms/room01/room01.tscn # 12/ Event flags tests 2 #change_scene res://game/rooms/room12/room12.tscn +# 13/ +#change_scene res://game/rooms/room13/room13.tscn + +# 14/ +#change_scene res://game/rooms/room14/room14.tscn diff --git a/project.godot b/project.godot index decedda0..c56a8a77 100644 --- a/project.godot +++ b/project.godot @@ -365,6 +365,11 @@ _global_script_classes=[ { "path": "res://addons/escoria-core/game/core-scripts/esc/commands/enable_terrain.gd" }, { "base": "ESCBaseCommand", +"class": "HideMenuCommand", +"language": "GDScript", +"path": "res://addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd" +}, { +"base": "ESCBaseCommand", "class": "IncGlobalCommand", "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/commands/inc_global.gd" @@ -459,6 +464,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/commands/set_state.gd" }, { +"base": "ESCBaseCommand", +"class": "ShowMenuCommand", +"language": "GDScript", +"path": "res://addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd" +}, { "base": "SlideCommand", "class": "SlideBlockCommand", "language": "GDScript", @@ -596,6 +606,7 @@ _global_script_class_icons={ "ESCUtils": "", "ESCWalkContext": "", "EnableTerrainCommand": "", +"HideMenuCommand": "", "IncGlobalCommand": "", "InventoryAddCommand": "", "InventoryRemoveCommand": "", @@ -615,6 +626,7 @@ _global_script_class_icons={ "SetSoundStateCommand": "", "SetSpeedCommand": "", "SetStateCommand": "", +"ShowMenuCommand": "", "SlideBlockCommand": "", "SlideCommand": "", "SpawnCommand": "", @@ -671,6 +683,7 @@ debug/terminate_on_warnings=false debug/terminate_on_errors=true debug/development_lang="en" ui/tooltip_follows_mouse=false +ui/default_dialog_scene="res://addons/escoria-core/ui_library/dialogs/floating_dialog_player.tscn" main/text_lang="fr_FR" main/voice_lang="fr_FR" sound/music_volume=1 @@ -696,8 +709,8 @@ ui/transition_paths=[ "res://addons/escoria-core/game/scenes/transitions/shaders ui/inventory_item_size=Vector2( 72, 72 ) debug/enable_room_selector=true debug/room_selector_room_dir="res://game/rooms" -ui/dialog_managers=[ "res://addons/escoria-dialog-simple/esc_dialog_simple.gd" ] ui/default_dialog_type="floating" +ui/dialog_managers=[ "res://addons/escoria-dialog-simple/esc_dialog_simple.gd" ] dialog_simple/avatars_path="res://game/dialog_avatars" dialog_simple/text_speed_per_character=0.1 dialog_simple/fast_text_speed_per_character=0.25 @@ -707,7 +720,7 @@ dialog_simple/max_time_to_disappear=1.0 esc_show_debug_prompt={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } switch_action_verb={ diff --git a/saves/save_001.tres b/saves/save_001.tres index 839b17f6..ccf356f6 100644 --- a/saves/save_001.tres +++ b/saves/save_001.tres @@ -6,8 +6,8 @@ script = ExtResource( 1 ) escoria_version = "0.1.0" game_version = "0.1.0" -name = "3" -date = "11/08/2021 21:14" +name = "Testtt1" +date = "04/11/2021 22:13" main = { "current_scene_filename": "res://game/rooms/room01/room01.tscn", "last_scene_global_id": "" @@ -18,24 +18,29 @@ globals = { "room1_visited": true } objects = { -"bg_music": { -"active": true, -"interactive": true, -"state": "res://game/sfx/contemplation.ogg" -}, -"bg_sound": { +"_camera": { "active": true, "interactive": true, "state": "default" }, -"camera": { +"_music": { +"active": true, +"interactive": true, +"state": "res://game/sfx/contemplation.ogg" +}, +"_sound": { +"active": true, +"interactive": true, +"state": "default" +}, +"_speech": { "active": true, "interactive": true, "state": "default" }, "player": { "active": true, -"global_transform": Transform2D( 1, 0, 0, 1, 621.898, 479.227 ), +"global_transform": Transform2D( 1, 0, 0, 1, 399, 480 ), "interactive": true, "last_deg": 71, "last_dir": 2, @@ -56,7 +61,7 @@ objects = { "interactive": true, "state": "default" }, -"r1_left_object_interaction": { +"r1_destination_point3": { "active": true, "interactive": true, "state": "default" @@ -81,7 +86,7 @@ objects = { "interactive": true, "state": "default" }, -"r2_left_object_interaction": { +"trigger_talk": { "active": true, "interactive": true, "state": "default" diff --git a/saves/save_002.tres b/saves/save_002.tres index 5530a9d5..96d7d637 100644 --- a/saves/save_002.tres +++ b/saves/save_002.tres @@ -6,39 +6,45 @@ script = ExtResource( 1 ) escoria_version = "0.1.0" game_version = "0.1.0" -name = "4" -date = "11/08/2021 21:20" +name = "Test2" +date = "04/11/2021 22:59" main = { -"current_scene_filename": "res://game/rooms/room01/room01.tscn", +"current_scene_filename": "res://game/rooms/room02/room02.tscn", "last_scene_global_id": "" } globals = { "dialog_advance": 0, "dialog_popup_advance": 0, +"r2_bridge_closed": true, "room1_visited": true } objects = { -"bg_music": { -"active": true, -"interactive": true, -"state": "res://game/sfx/contemplation.ogg" -}, -"bg_sound": { +"_camera": { "active": true, "interactive": true, "state": "default" }, -"camera": { +"_music": { +"active": true, +"interactive": true, +"state": "res://game/sfx/contemplation.ogg" +}, +"_sound": { +"active": true, +"interactive": true, +"state": "default" +}, +"_speech": { "active": true, "interactive": true, "state": "default" }, "player": { "active": true, -"global_transform": Transform2D( 1, 0, 0, 1, 994.586, 458.862 ), +"global_transform": Transform2D( 1, 0, 0, 1, 1051, 434 ), "interactive": true, -"last_deg": 71, -"last_dir": 2, +"last_deg": 111, +"last_dir": 3, "state": "default" }, "player_start": { @@ -46,44 +52,39 @@ objects = { "interactive": true, "state": "default" }, -"r1_destination_point": { +"r2_bridge": { +"active": true, +"interactive": false, +"state": "bridge_close" +}, +"r2_button": { "active": true, "interactive": true, "state": "default" }, -"r1_destination_point2": { +"r2_button_right": { "active": true, "interactive": true, "state": "default" }, -"r1_left_object_interaction": { +"r2_l_exit": { "active": true, "interactive": true, "state": "default" }, -"r1_r_exit": { +"r2_player_start": { "active": true, "interactive": true, "state": "default" }, -"r1_start": { +"r2_r_exit": { "active": true, "interactive": true, "state": "default" }, -"r1_wall_item1": { +"r2_right_platform": { "active": true, -"interactive": true, -"state": "default" -}, -"r1_wall_item2": { -"active": true, -"interactive": true, -"state": "default" -}, -"r2_left_object_interaction": { -"active": true, -"interactive": true, +"interactive": false, "state": "default" } } diff --git a/saves/save_003.tres b/saves/save_003.tres deleted file mode 100644 index 7d86ec69..00000000 --- a/saves/save_003.tres +++ /dev/null @@ -1,88 +0,0 @@ -[gd_resource type="Resource" load_steps=2 format=2] - -[ext_resource path="res://addons/escoria-core/game/core-scripts/save_data/esc_savegame.gd" type="Script" id=1] - -[resource] -script = ExtResource( 1 ) -escoria_version = "0.1.0" -game_version = "0.1.0" -name = "5" -date = "26/08/2021 08:59" -main = { -"current_scene_filename": "res://game/rooms/room01/room01.tscn", -"last_scene_global_id": "" -} -globals = { -"dialog_advance": 0, -"dialog_popup_advance": 0, -"room1_visited": true -} -objects = { -"bg_music": { -"active": true, -"interactive": true, -"state": "res://game/sfx/contemplation.ogg" -}, -"bg_sound": { -"active": true, -"interactive": true, -"state": "default" -}, -"camera": { -"active": true, -"interactive": true, -"state": "default" -}, -"player": { -"active": true, -"global_transform": Transform2D( 1, 0, 0, 1, 994.586, 458.862 ), -"interactive": true, -"last_dir": 2, -"state": "default" -}, -"player_start": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_destination_point": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_destination_point2": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_left_object_interaction": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_r_exit": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_start": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_wall_item1": { -"active": true, -"interactive": true, -"state": "default" -}, -"r1_wall_item2": { -"active": true, -"interactive": true, -"state": "default" -}, -"r2_left_object_interaction": { -"active": true, -"interactive": true, -"state": "default" -} -}