Skip to content

Commit 106e722

Browse files
authored
Merge pull request #1263 from endlessm/StorybookManuq
Add non-placeholder storybook
2 parents f77516f + ff09177 commit 106e722

22 files changed

Lines changed: 1242 additions & 47 deletions

scenes/menus/storybook/components/storybook.gd

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ const QUEST_RESOURCE_NAME := "quest.tres"
2626
## have a [code]quest.tres[/code] file within.
2727
@export_dir var quest_directory: String = "res://scenes/quests/story_quests"
2828

29+
var _current_page_index: int = -1
30+
var _navigation_locked: bool = false
31+
2932
@onready var quest_list: VBoxContainer = %QuestList
3033
@onready var storybook_page: StorybookPage = %StorybookPage
3134
@onready var back_button: Button = %BackButton
35+
@onready var animated_book: AnimatedSprite2D = %AnimatedSprite2D
36+
@onready var ui_container: Control = %StoryBookContent
37+
@onready var left_button: Button = %Left_Button
38+
@onready var right_button: Button = %Right_Button
3239

3340

3441
func _enumerate_quests() -> Array[Quest]:
3542
var has_template: bool = false
36-
var quests: Array[Quest]
43+
var quests: Array[Quest] = []
3744

3845
for dir in ResourceLoader.list_directory(quest_directory):
3946
var quest_path := quest_directory.path_join(dir).path_join(QUEST_RESOURCE_NAME)
@@ -51,12 +58,15 @@ func _enumerate_quests() -> Array[Quest]:
5158

5259

5360
func _ready() -> void:
61+
animated_book.animation_finished.connect(_on_animation_finished)
62+
5463
var previous_button: Button = null
5564
for quest in _enumerate_quests():
5665
var button := Button.new()
5766
button.text = quest.get_title()
5867
button.theme_type_variation = "FlatButton"
5968
quest_list.add_child(button)
69+
button.set_meta("quest", quest)
6070

6171
button.focus_entered.connect(_on_button_focused.bind(button, quest))
6272
button.focus_next = back_button.get_path()
@@ -68,24 +78,97 @@ func _ready() -> void:
6878

6979
previous_button = button
7080

71-
previous_button.focus_neighbor_bottom = back_button.get_path()
72-
back_button.focus_neighbor_top = previous_button.get_path()
81+
if previous_button:
82+
previous_button.focus_neighbor_bottom = back_button.get_path()
83+
back_button.focus_neighbor_top = previous_button.get_path()
7384

85+
left_button.pressed.connect(_on_left_button_pressed)
86+
right_button.pressed.connect(_on_right_button_pressed)
7487
reset_focus()
7588

7689

90+
func _switch_to_page(page_index: int) -> void:
91+
if _navigation_locked:
92+
return
93+
94+
var total := quest_list.get_child_count()
95+
if total == 0:
96+
return
97+
if page_index < 0 or page_index >= total:
98+
return
99+
if page_index == _current_page_index:
100+
return
101+
102+
_navigation_locked = true
103+
104+
var button: Button = quest_list.get_child(page_index)
105+
if not is_instance_valid(button):
106+
_navigation_locked = false
107+
return
108+
109+
var quest: Quest = button.get_meta("quest") if button.has_meta("quest") else null
110+
111+
back_button.focus_previous = button.get_path()
112+
storybook_page.play_button.focus_next = button.get_path()
113+
storybook_page.play_button.focus_neighbor_left = button.get_path()
114+
if quest:
115+
storybook_page.quest = quest
116+
117+
if _current_page_index != -1:
118+
if page_index > _current_page_index:
119+
animated_book.play("book_right")
120+
else:
121+
animated_book.play("book_left")
122+
ui_container.visible = false
123+
else:
124+
if not button.has_focus():
125+
button.grab_focus()
126+
_navigation_locked = false
127+
128+
_current_page_index = page_index
129+
130+
131+
func _on_animation_finished() -> void:
132+
_navigation_locked = false
133+
ui_container.visible = true
134+
135+
var button: Button = quest_list.get_child(_current_page_index)
136+
if button and is_instance_valid(button) and not button.has_focus():
137+
button.grab_focus()
138+
139+
140+
func _on_left_button_pressed() -> void:
141+
if _navigation_locked:
142+
return
143+
var target := _current_page_index - 1
144+
if target < 0:
145+
target = max(0, quest_list.get_child_count() - 1)
146+
_switch_to_page(target)
147+
148+
149+
func _on_right_button_pressed() -> void:
150+
if _navigation_locked:
151+
return
152+
var target := _current_page_index + 1
153+
if target >= quest_list.get_child_count():
154+
target = 0
155+
_switch_to_page(target)
156+
157+
77158
func _input(event: InputEvent) -> void:
78159
if event.is_action_pressed("ui_cancel"):
79160
# Go back
80161
get_viewport().set_input_as_handled()
81162
selected.emit(null)
82163

83164

84-
func _on_button_focused(button: Button, quest: Quest) -> void:
85-
back_button.focus_previous = button.get_path()
86-
storybook_page.play_button.focus_next = button.get_path()
87-
storybook_page.play_button.focus_neighbor_left = button.get_path()
88-
storybook_page.quest = quest
165+
func _on_button_focused(button: Button, _quest: Quest) -> void:
166+
if _navigation_locked:
167+
return
168+
var current_index: int = quest_list.get_children().find(button)
169+
if current_index == -1:
170+
return
171+
_switch_to_page(current_index)
89172

90173

91174
func _on_storybook_page_selected(quest: Quest) -> void:
@@ -98,4 +181,4 @@ func _on_back_button_pressed() -> void:
98181

99182
func reset_focus() -> void:
100183
if quest_list and quest_list.get_child_count() > 0:
101-
quest_list.get_child(0).grab_focus()
184+
_switch_to_page(0)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
[gd_resource type="SpriteFrames" load_steps=24 format=3 uid="uid://dne3cxrhbjuno"]
2+
3+
[ext_resource type="Texture2D" uid="uid://dakvpilaqdm3b" path="res://scenes/ui_elements/story_quest_progress/Textures/book_turn_left.png" id="1_rrloo"]
4+
[ext_resource type="Texture2D" uid="uid://cabmo1e1xm6um" path="res://scenes/ui_elements/story_quest_progress/Textures/book_turn_right.png" id="2_100cn"]
5+
6+
[sub_resource type="AtlasTexture" id="AtlasTexture_dg0bn"]
7+
atlas = ExtResource("1_rrloo")
8+
region = Rect2(0, 0, 999, 720)
9+
10+
[sub_resource type="AtlasTexture" id="AtlasTexture_x501c"]
11+
atlas = ExtResource("1_rrloo")
12+
region = Rect2(999, 0, 999, 720)
13+
14+
[sub_resource type="AtlasTexture" id="AtlasTexture_ofgxb"]
15+
atlas = ExtResource("1_rrloo")
16+
region = Rect2(1998, 0, 999, 720)
17+
18+
[sub_resource type="AtlasTexture" id="AtlasTexture_y0b3i"]
19+
atlas = ExtResource("1_rrloo")
20+
region = Rect2(2997, 0, 999, 720)
21+
22+
[sub_resource type="AtlasTexture" id="AtlasTexture_8qcyx"]
23+
atlas = ExtResource("1_rrloo")
24+
region = Rect2(3996, 0, 999, 720)
25+
26+
[sub_resource type="AtlasTexture" id="AtlasTexture_xkl6m"]
27+
atlas = ExtResource("1_rrloo")
28+
region = Rect2(4995, 0, 999, 720)
29+
30+
[sub_resource type="AtlasTexture" id="AtlasTexture_p0vqm"]
31+
atlas = ExtResource("1_rrloo")
32+
region = Rect2(5994, 0, 999, 720)
33+
34+
[sub_resource type="AtlasTexture" id="AtlasTexture_nkrro"]
35+
atlas = ExtResource("1_rrloo")
36+
region = Rect2(6993, 0, 999, 720)
37+
38+
[sub_resource type="AtlasTexture" id="AtlasTexture_bnrpt"]
39+
atlas = ExtResource("1_rrloo")
40+
region = Rect2(7992, 0, 999, 720)
41+
42+
[sub_resource type="AtlasTexture" id="AtlasTexture_mwfoq"]
43+
atlas = ExtResource("1_rrloo")
44+
region = Rect2(8991, 0, 999, 720)
45+
46+
[sub_resource type="AtlasTexture" id="AtlasTexture_f7prj"]
47+
atlas = ExtResource("2_100cn")
48+
region = Rect2(0, 0, 999, 720)
49+
50+
[sub_resource type="AtlasTexture" id="AtlasTexture_m2ghf"]
51+
atlas = ExtResource("2_100cn")
52+
region = Rect2(999, 0, 999, 720)
53+
54+
[sub_resource type="AtlasTexture" id="AtlasTexture_jl72s"]
55+
atlas = ExtResource("2_100cn")
56+
region = Rect2(1998, 0, 999, 720)
57+
58+
[sub_resource type="AtlasTexture" id="AtlasTexture_b2xx3"]
59+
atlas = ExtResource("2_100cn")
60+
region = Rect2(2997, 0, 999, 720)
61+
62+
[sub_resource type="AtlasTexture" id="AtlasTexture_21r2o"]
63+
atlas = ExtResource("2_100cn")
64+
region = Rect2(3996, 0, 999, 720)
65+
66+
[sub_resource type="AtlasTexture" id="AtlasTexture_ywp77"]
67+
atlas = ExtResource("2_100cn")
68+
region = Rect2(4995, 0, 999, 720)
69+
70+
[sub_resource type="AtlasTexture" id="AtlasTexture_x5pjn"]
71+
atlas = ExtResource("2_100cn")
72+
region = Rect2(5994, 0, 999, 720)
73+
74+
[sub_resource type="AtlasTexture" id="AtlasTexture_4q417"]
75+
atlas = ExtResource("2_100cn")
76+
region = Rect2(6993, 0, 999, 720)
77+
78+
[sub_resource type="AtlasTexture" id="AtlasTexture_ln7yb"]
79+
atlas = ExtResource("2_100cn")
80+
region = Rect2(7992, 0, 999, 720)
81+
82+
[sub_resource type="AtlasTexture" id="AtlasTexture_emw6c"]
83+
atlas = ExtResource("2_100cn")
84+
region = Rect2(8991, 0, 999, 720)
85+
86+
[sub_resource type="AtlasTexture" id="AtlasTexture_e4w0c"]
87+
atlas = ExtResource("1_rrloo")
88+
region = Rect2(0, 0, 999, 720)
89+
90+
[resource]
91+
animations = [{
92+
"frames": [{
93+
"duration": 1.0,
94+
"texture": SubResource("AtlasTexture_dg0bn")
95+
}, {
96+
"duration": 1.0,
97+
"texture": SubResource("AtlasTexture_x501c")
98+
}, {
99+
"duration": 1.0,
100+
"texture": SubResource("AtlasTexture_ofgxb")
101+
}, {
102+
"duration": 1.0,
103+
"texture": SubResource("AtlasTexture_y0b3i")
104+
}, {
105+
"duration": 1.0,
106+
"texture": SubResource("AtlasTexture_8qcyx")
107+
}, {
108+
"duration": 1.0,
109+
"texture": SubResource("AtlasTexture_xkl6m")
110+
}, {
111+
"duration": 1.0,
112+
"texture": SubResource("AtlasTexture_p0vqm")
113+
}, {
114+
"duration": 1.0,
115+
"texture": SubResource("AtlasTexture_nkrro")
116+
}, {
117+
"duration": 1.0,
118+
"texture": SubResource("AtlasTexture_bnrpt")
119+
}, {
120+
"duration": 1.0,
121+
"texture": SubResource("AtlasTexture_mwfoq")
122+
}],
123+
"loop": false,
124+
"name": &"book_left",
125+
"speed": 24.0
126+
}, {
127+
"frames": [{
128+
"duration": 1.0,
129+
"texture": SubResource("AtlasTexture_f7prj")
130+
}, {
131+
"duration": 1.0,
132+
"texture": SubResource("AtlasTexture_m2ghf")
133+
}, {
134+
"duration": 1.0,
135+
"texture": SubResource("AtlasTexture_jl72s")
136+
}, {
137+
"duration": 1.0,
138+
"texture": SubResource("AtlasTexture_b2xx3")
139+
}, {
140+
"duration": 1.0,
141+
"texture": SubResource("AtlasTexture_21r2o")
142+
}, {
143+
"duration": 1.0,
144+
"texture": SubResource("AtlasTexture_ywp77")
145+
}, {
146+
"duration": 1.0,
147+
"texture": SubResource("AtlasTexture_x5pjn")
148+
}, {
149+
"duration": 1.0,
150+
"texture": SubResource("AtlasTexture_4q417")
151+
}, {
152+
"duration": 1.0,
153+
"texture": SubResource("AtlasTexture_ln7yb")
154+
}, {
155+
"duration": 1.0,
156+
"texture": SubResource("AtlasTexture_emw6c")
157+
}],
158+
"loop": false,
159+
"name": &"book_right",
160+
"speed": 24.0
161+
}, {
162+
"frames": [{
163+
"duration": 1.0,
164+
"texture": SubResource("AtlasTexture_e4w0c")
165+
}],
166+
"loop": false,
167+
"name": &"idle",
168+
"speed": 5.0
169+
}]

0 commit comments

Comments
 (0)