Skip to content

Commit 2a3f4a5

Browse files
authored
Quest Separator: Add Play & Back buttons (#2389)
This screen previously automatically advanced to the first scene of the quest after a few seconds, unconditionally. Increase that timeout slightly. Add a “Play” button. Show a progress bar over the top of it that follows the timer. Stop the timer on any input event except a mouse movement. Add a “Back” button which abandons the quest before it has even started. Add some margins to the scene as a whole. Ignore mouse input in the TextureRect which covers the whole scene, so that the buttons can be clicked. #2281 (comment)
1 parent f9ffbac commit 2a3f4a5

5 files changed

Lines changed: 108 additions & 9 deletions

File tree

scenes/globals/pause/pause_overlay.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ func toggle_pause() -> void:
4747

4848
func _on_abandon_quest_pressed() -> void:
4949
toggle_pause()
50+
abandon_quest()
51+
52+
53+
func abandon_quest() -> void:
54+
if not GameState.quest:
55+
push_warning("No quest to abandon")
56+
return
5057

5158
var quest := GameState.quest.quest
5259
var abandon_scene := GameState.quest.abandon_scene_path

scenes/menus/quest_separator/components/quest_separator.gd

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ extends Control
55
@onready var title: Label = %Title
66
@onready var animated_texture_rect: AnimatedTextureRect = %AnimatedTextureRect
77
@onready var rich_text_label: RichTextLabel = %RichTextLabel
8+
@onready var back_button: Button = %BackButton
9+
@onready var play_button: Button = %PlayButton
10+
@onready var auto_play_progress_bar: ProgressBar = %AutoPlayProgressBar
11+
@onready var auto_play_timer: Timer = %AutoPlayTimer
812

913

1014
func _ready() -> void:
@@ -15,14 +19,29 @@ func _ready() -> void:
1519
animated_texture_rect.animation_name = quest.animation_name
1620
rich_text_label.text = quest.description
1721

18-
await get_tree().create_timer(3).timeout
22+
play_button.grab_focus()
23+
play_button.focus_exited.connect(stop_timer, CONNECT_ONE_SHOT)
24+
play_button.pressed.connect(play)
1925

20-
(
21-
SceneSwitcher
22-
. change_to_file_with_transition(
23-
quest.first_scene,
24-
^"",
25-
Transition.Effect.RADIAL,
26-
Transition.Effect.FADE,
27-
)
26+
back_button.pressed.connect(back)
27+
28+
auto_play_timer.timeout.connect(play)
29+
30+
31+
func stop_timer() -> void:
32+
auto_play_timer.stop()
33+
34+
35+
func back() -> void:
36+
stop_timer()
37+
# TODO: it is weird to call into the pause overlay from here.
38+
# Perhaps this separator should itself be part of the "pause" menu hierarchy?
39+
PauseOverlay.abandon_quest()
40+
41+
42+
func play() -> void:
43+
stop_timer()
44+
var quest := GameState.quest.quest
45+
SceneSwitcher.change_to_file_with_transition(
46+
quest.first_scene, ^"", Transition.Effect.RADIAL, Transition.Effect.FADE
2847
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: The Threadbare Authors
2+
# SPDX-License-Identifier: MPL-2.0
3+
extends ProgressBar
4+
## Visualises the progress of a Timer.
5+
##
6+
## Removes itself from the tree when the timer expires or is stopped.
7+
8+
@export var timer: Timer
9+
10+
11+
func _ready() -> void:
12+
max_value = timer.wait_time
13+
14+
15+
func _process(_delta: float) -> void:
16+
if timer.paused or timer.is_stopped():
17+
queue_free()
18+
else:
19+
value = timer.wait_time - timer.time_left
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://b78blxbleps14

scenes/menus/quest_separator/quest_separator.tscn

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[ext_resource type="Script" uid="uid://dccjkvox5cjsy" path="res://scenes/menus/quest_separator/components/quest_separator.gd" id="2_ayaqs"]
55
[ext_resource type="Texture2D" uid="uid://csbhg24hsxecd" path="res://scenes/quests/lore_quests/quest_002/Void.png" id="4_fqr5p"]
66
[ext_resource type="Script" uid="uid://dfx8s2ybd11mt" path="res://scenes/menus/storybook/components/animated_texture_rect.gd" id="4_olqir"]
7+
[ext_resource type="Shortcut" uid="uid://c5pwgp1w8p3y1" path="res://scenes/ui_elements/shortcuts/back_shortcut.tres" id="5_wq0a1"]
8+
[ext_resource type="Script" uid="uid://b78blxbleps14" path="res://scenes/menus/quest_separator/components/timer_progress_bar.gd" id="6_amr4g"]
79
[ext_resource type="Texture2D" uid="uid://dcwmaoqgu5t84" path="res://scenes/globals/scene_switcher/transitions/Radial.png" id="6_wq0a1"]
810

911
[sub_resource type="SpriteFrames" id="SpriteFrames_l1xe8"]
@@ -17,6 +19,8 @@ animations = [{
1719
"speed": 5.0
1820
}]
1921

22+
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_amr4g"]
23+
2024
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_wq0a1"]
2125
blend_mode = 2
2226

@@ -48,6 +52,10 @@ anchor_right = 1.0
4852
anchor_bottom = 1.0
4953
grow_horizontal = 2
5054
grow_vertical = 2
55+
theme_override_constants/margin_left = 192
56+
theme_override_constants/margin_top = 64
57+
theme_override_constants/margin_right = 192
58+
theme_override_constants/margin_bottom = 64
5159

5260
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer" unique_id=1354617346]
5361
layout_mode = 2
@@ -82,6 +90,44 @@ layout_mode = 2
8290
text = "StoryWeaver runs away from a growing emptiness that spreads across the land, smothering and swallowing everything it covers."
8391
fit_content = true
8492

93+
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer" unique_id=175954450]
94+
layout_mode = 2
95+
alignment = 2
96+
97+
[node name="BackButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer" unique_id=1588571350]
98+
unique_name_in_owner = true
99+
layout_mode = 2
100+
size_flags_vertical = 0
101+
theme_type_variation = &"FlatButton"
102+
shortcut = ExtResource("5_wq0a1")
103+
text = "Back"
104+
flat = true
105+
106+
[node name="PlayButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer" unique_id=327046167]
107+
unique_name_in_owner = true
108+
layout_mode = 2
109+
theme_type_variation = &"FlatButton"
110+
text = "Play"
111+
flat = true
112+
113+
[node name="AutoPlayProgressBar" type="ProgressBar" parent="MarginContainer/VBoxContainer/HBoxContainer/PlayButton" unique_id=1528838248 node_paths=PackedStringArray("timer")]
114+
unique_name_in_owner = true
115+
custom_minimum_size = Vector2(0, 20)
116+
layout_mode = 1
117+
anchors_preset = 14
118+
anchor_top = 0.5
119+
anchor_right = 1.0
120+
anchor_bottom = 0.5
121+
offset_top = -2.0
122+
offset_bottom = 2.0
123+
grow_horizontal = 2
124+
grow_vertical = 2
125+
theme_override_styles/background = SubResource("StyleBoxEmpty_amr4g")
126+
value = 50.0
127+
show_percentage = false
128+
script = ExtResource("6_amr4g")
129+
timer = NodePath("../../../../../AutoPlayTimer")
130+
85131
[node name="TextureRect" type="TextureRect" parent="." unique_id=279230856]
86132
material = SubResource("CanvasItemMaterial_wq0a1")
87133
layout_mode = 1
@@ -90,4 +136,11 @@ anchor_right = 1.0
90136
anchor_bottom = 1.0
91137
grow_horizontal = 2
92138
grow_vertical = 2
139+
mouse_filter = 2
93140
texture = ExtResource("6_wq0a1")
141+
142+
[node name="AutoPlayTimer" type="Timer" parent="." unique_id=229639968]
143+
unique_name_in_owner = true
144+
wait_time = 5.0
145+
one_shot = true
146+
autostart = true

0 commit comments

Comments
 (0)