-
Notifications
You must be signed in to change notification settings - Fork 290
input_hud: Hide when paused & during transitions #2097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| extends CanvasLayer | ||
|
|
||
| var player: Player | ||
| var sokoban_ruleset: RuleEngine | ||
|
|
||
| @onready var normal_controls := %NormalControls | ||
| @onready var interact_input_hint := %InteractInputHint | ||
|
|
@@ -17,6 +18,9 @@ var player: Player | |
| func _ready() -> void: | ||
| get_tree().scene_changed.connect(_on_scene_changed) | ||
|
|
||
| Transitions.started.connect(_update_visibility) | ||
| Transitions.finished.connect(_update_visibility) | ||
|
|
||
| # When running a scene that contains a player directly, this node becomes | ||
| # ready before the player. Defer the initial setup so that we can assume the | ||
| # whole scene (and in particular the player) is ready in | ||
|
|
@@ -28,10 +32,11 @@ func _ready() -> void: | |
|
|
||
| func _on_scene_changed() -> void: | ||
| player = get_tree().get_first_node_in_group("player") | ||
| var sokoban_ruleset: RuleEngine = get_tree().get_first_node_in_group("sokoban_ruleset") | ||
| sokoban_ruleset = get_tree().get_first_node_in_group("sokoban_ruleset") | ||
|
|
||
| _update_visibility() | ||
|
|
||
| if player: | ||
| visible = true | ||
| normal_controls.visible = true | ||
|
|
||
| player.player_interaction.can_interact_changed.connect(_update_player_state) | ||
|
|
@@ -40,12 +45,19 @@ func _on_scene_changed() -> void: | |
|
|
||
| _update_player_state() | ||
| elif sokoban_ruleset: | ||
| visible = true | ||
| sokoban_controls.visible = true | ||
| skip_input_hint.visible = false | ||
| sokoban_ruleset.skip_enabled.connect(_display_skip) | ||
| else: | ||
| visible = false | ||
|
|
||
|
|
||
| func _update_visibility() -> void: | ||
| visible = not get_tree().paused and not Transitions.is_running() and (player or sokoban_ruleset) | ||
|
|
||
|
|
||
| func _notification(what: int) -> void: | ||
| match what: | ||
| NOTIFICATION_PAUSED, NOTIFICATION_UNPAUSED: | ||
| _update_visibility() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't aware of these notifications, nice. This does the job.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nor was I, till I searched while writing this. I like this because it keeps InputHud & PauseOverlay ignorant of each other. Of course… you might imagine in future we could put the InputHud over the PauseOverlay and show the arrow keys plus "[ space ] Click" or something. Another day. |
||
|
|
||
|
|
||
| func _update_player_state() -> void: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍