Skip to content

Commit

Permalink
Screen Manager Fixes 'n Additions
Browse files Browse the repository at this point in the history
- Fixed oneshot snappy menus due to wrong values in the RESET animation in the AnimationPlayer

- Added 2 new methods to allow for more customisability in logic
-- on_enter() [which runs after the transition animation of a screen has finished], got a counterpart on_load() [which runs before the transition animation starts]
-- on_exit() got the same treatment with its new buddy on_gone()
  • Loading branch information
Charpurrr committed Oct 26, 2024
1 parent 7bb9266 commit 4567da9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
22 changes: 18 additions & 4 deletions ui/screen_manager/screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ var enabled: bool = false
var manager: ScreenManager


## Ran once when this screen is transitioned to.
func _on_enter() -> void:
## Ran as soon as this screen starts being transitioned to.
## (Does not wait for the transition animation to finish first.)
func on_load() -> void:
pass


## Ran once when this screen is transitioned from.
func _on_exit() -> void:
## Ran once when this screen has been transitioned to.
## (Waits for the transition animation to finish first.)
func on_enter() -> void:
pass


## Ran once when this screen starts being transitioned from.
## (Does not wait for the transition animation to finish first.)
func on_exit() -> void:
pass


## Ran once when this screen has been transitioned from.
## (Waits for the transition animation to finish first.)
func on_gone() -> void:
pass
16 changes: 11 additions & 5 deletions ui/screen_manager/screen_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func _ready() -> void:

## Leave from or to as null if wanting to transition out of or into gameplay.
func switch_screen(from: Screen = null, to: Screen = null) -> void:
#region FROM
if not from == null:
from.call_deferred(&"_on_exit")

SFX.play_sfx(from.close_sfx, &"UI", self)

if from.close_anim == &"BACKWARDS":
Expand All @@ -44,24 +43,31 @@ func switch_screen(from: Screen = null, to: Screen = null) -> void:

get_viewport().gui_release_focus()

from.on_exit()

await anime_player.animation_finished

from.on_gone()
from.visible = false
#endregion

#region TO
if to == null:
return

SFX.play_sfx(to.open_sfx, &"UI", self)

to.visible = true

anime_player.play(to.open_anim)

to.visible = true
to.focus_grabber.grab_focus()

to.on_load()

await anime_player.animation_finished

to.call_deferred(&"_on_enter")
to.on_enter()
#endregion


#func _on_animation_player_animation_finished(anim_name: StringName) -> void:
Expand Down
2 changes: 1 addition & 1 deletion ui/screen_manager/warning_screen/warning_screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var text: String
var confirm_behaviour: Callable


func _on_enter():
func on_load():
warning_text.text = text


Expand Down
9 changes: 5 additions & 4 deletions ui/ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
"values": [832]
}
tracks/1/type = "value"
tracks/1/imported = false
Expand All @@ -73,7 +73,7 @@ tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 0)]
"values": [Vector2(0, 360)]
}

[sub_resource type="Animation" id="Animation_3o3ms"]
Expand Down Expand Up @@ -471,14 +471,13 @@ grow_horizontal = 2
grow_vertical = 2

[node name="PauseScreen" type="HBoxContainer" parent="ScreenManager" node_paths=PackedStringArray("focus_grabber")]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 0
theme_override_constants/separation = 832
script = ExtResource("17_372ku")
open_anim = &"pause_peek"
close_anim = &"BACKWARDS"
Expand Down Expand Up @@ -1061,6 +1060,8 @@ layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 360.0
offset_bottom = 360.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("15_uxr3e")
Expand Down

0 comments on commit 4567da9

Please sign in to comment.