Skip to content

Commit 31b7486

Browse files
committed
Refactor ScreenTransition to autoload, add a (fixed) roaming encounter
1 parent fff10fe commit 31b7486

File tree

17 files changed

+204
-221
lines changed

17 files changed

+204
-221
lines changed
-1.15 MB
Binary file not shown.

assets/gui/screen_transitions/wipe_horizontal.png.import

Lines changed: 0 additions & 34 deletions
This file was deleted.

maps/opening_cutscene.gd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ extends Cutscene
22

33
@export var timeline: DialogicTimeline
44

5-
@onready var _screen_transition: = $CanvasLayer/ScreenTransition as ScreenTransition
6-
75

86
func _execute() -> void:
9-
_screen_transition.cover()
7+
Transition.cover()
108

119
Dialogic.start_timeline(timeline)
1210
await Dialogic.timeline_ended
1311

1412
Music.play(load("res://assets/music/Apple Cider.mp3"))
15-
_screen_transition.reveal(2.0)
16-
await _screen_transition.finished
13+
Transition.clear(2.0)
14+
await Transition.finished
1715

1816
queue_free.call_deferred()

project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CombatEvents="*res://src/common/combat_events.gd"
2222
Dialogic="*res://addons/dialogic/Other/DialogicGameHandler.gd"
2323
FieldEvents="*res://src/common/field_events.gd"
2424
Music="*res://src/common/music/music_player.tscn"
25+
Transition="*res://src/common/screen_transitions/ScreenTransition.tscn"
2526

2627
[dialogic]
2728

src/combat/combat_arena.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class_name CombatArena extends Control
88
func _unhandled_input(event: InputEvent) -> void:
99
if event.is_action_released("back"):
1010
CombatEvents.combat_lost.emit()
11-
CombatEvents.combat_finished.emit()
1211

1312
elif event.is_action_released("interact"):
1413
CombatEvents.combat_won.emit()
15-
CombatEvents.combat_finished.emit()

src/common/combat_events.gd

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ extends Node
44
## Emitted whenever a combat is triggered. Technically, this event occurs within the field state.
55
signal combat_initiated(arena: PackedScene)
66

7-
## Emitted immediately after the player has won combat and all animations have finished.
8-
## This is used to transition to the combat results screen and notify the combat-starting-trigger
9-
## of the combat result.
7+
## Emitted immediately after the player has won combat and all animations have finished. Also, the
8+
## the battle results screen has been displayed and dismissed.
9+
## This is used to fade the screen post-combat and notify the combat-starting-trigger of the result.
1010
signal combat_won
1111

1212
## Emitted immediately after the player has lost combat and all animations have finished.
1313
## This is used to fade the screen post-combat and notify the combat-starting-trigger of the result.
1414
signal combat_lost
1515

1616
## Emitted whenever the player has finished with the combat state regardless of whether or not the
17-
## combat was won by the player.
18-
## If the player won the combat, the battle results screen has been displayed and dismissed and the
19-
## screen has faded to black.
20-
## If the player lost combat, the screen has faded to black. In most places, the "gameover" screen
21-
## will be displayed next.
17+
## combat was won by the player. At this point the screen has faded to black and any events that
18+
## immediately follow the combat may occur.
2219
signal combat_finished
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://cmoqpuygxc5w8"]
2+
3+
[ext_resource type="Script" path="res://src/common/screen_transitions/screen_transition.gd" id="1_vr13h"]
4+
5+
[node name="ScreenTransition" type="CanvasLayer"]
6+
script = ExtResource("1_vr13h")
7+
8+
[node name="ColorRect" type="ColorRect" parent="."]
9+
anchors_preset = 15
10+
anchor_right = 1.0
11+
anchor_bottom = 1.0
12+
grow_horizontal = 2
13+
grow_vertical = 2
14+
color = Color(0, 0, 0, 1)

src/common/screen_transitions/screen_transition.gd

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## animation before transitioning (see [method reveal]) to gameplay.
77
##
88
## [br][br]ScreenTransitions cover or reveal the screen uniformly as a fade animation.
9-
class_name ScreenTransition extends ColorRect
9+
class_name ScreenTransition extends CanvasLayer
1010

1111
## Emitted when the screen has finished the current animation, whether that is to [method cover] the
1212
## screen or [method reveal] the screen.
@@ -23,47 +23,63 @@ const COVERED: = Color.WHITE
2323

2424
var _tween: Tween
2525

26+
@onready var _color_rect: = $ColorRect as ColorRect
27+
2628

2729
func _ready() -> void:
28-
mouse_filter = Control.MOUSE_FILTER_IGNORE
30+
# The screen transitions need to run over the gameplay, which is instantiated below all
31+
# autoloads (including this class). Therefore, we want to move the ScreenTransition object to
32+
# the very bottom of the SceneTree's child list.
33+
# We cannot do so during ready, in which this node's parents are not yet ready. Therefore the
34+
# call to move_child must be deferred a frame.
35+
get_parent().move_child.call_deferred(self, get_parent().get_child_count()-1)
36+
37+
# Allow the mouse through the transition GUI elements.
38+
_color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
2939

3040
# By default, do NOT have the ColorRect covering the screen.
3141
show()
32-
reveal()
42+
clear()
3343

3444

3545
## Hide the ColorRect instantly, unless the duration argument is non-zero.
36-
func reveal(duration: = 0.0) -> void:
46+
## This method is a coroutine that will finish once the screen has been cleared.
47+
func clear(duration: = 0.0) -> void:
3748
if _tween:
3849
_tween.kill()
3950
_tween = null
4051
finished.emit()
4152

42-
if is_equal_approx(duration, 0.0):
43-
modulate = CLEAR
53+
if is_equal_approx(duration, 0.0) or _color_rect.modulate.is_equal_approx(CLEAR):
54+
_color_rect.modulate = CLEAR
4455
call_deferred("emit_signal", "finished")
4556

4657
else:
4758
_tween_transition(duration, CLEAR)
59+
60+
await finished
4861

4962

5063
## Cover the screen instantly, unless the duration argument is non-zero.
64+
## This method is a coroutine that will finish once the screen has been covered.
5165
func cover(duration: = 0.0) -> void:
5266
if _tween:
5367
_tween.kill()
5468
_tween = null
5569
finished.emit()
5670

57-
if is_equal_approx(duration, 0.0):
58-
modulate = COVERED
71+
if is_equal_approx(duration, 0.0) or _color_rect.modulate.is_equal_approx(COVERED):
72+
_color_rect.modulate = COVERED
5973
call_deferred("emit_signal", "finished")
6074

6175
else:
6276
_tween_transition(duration, COVERED)
77+
78+
await finished
6379

6480

6581
# Relegate the tween creation to a method so that derived classes can easily change transition type.
6682
func _tween_transition(duration: float, target_colour: Color) -> void:
6783
_tween = create_tween()
68-
_tween.tween_property(self, "modulate", target_colour, duration)
84+
_tween.tween_property(_color_rect, "modulate", target_colour, duration)
6985
_tween.tween_callback(func(): finished.emit())

src/common/screen_transitions/shader_screen_transition.gd

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/common/screen_transitions/texture_fade.gdshader

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)