Skip to content

Commit 5dd8f7d

Browse files
Add a side panel that updates with room info when the room changes (part #18 - finale)
1 parent 759687a commit 5dd8f7d

File tree

7 files changed

+180
-17
lines changed

7 files changed

+180
-17
lines changed

CommandProcessor.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
extends Node
22

33

4+
signal room_changed(new_room)
5+
signal room_updated(current_room)
6+
47
var current_room = null
58
var player = null
69

@@ -64,6 +67,7 @@ func take(second_word: String) -> String:
6467
if second_word.to_lower() == item.item_name.to_lower():
6568
current_room.remove_item(item)
6669
player.take_item(item)
70+
emit_signal("room_updated", current_room)
6771
return "You take the " + Types.wrap_item_text(second_word) + "."
6872

6973
return "There is no " + Types.wrap_item_text(second_word) + " here."
@@ -77,6 +81,7 @@ func drop(second_word: String) -> String:
7781
if second_word.to_lower() == item.item_name.to_lower():
7882
player.drop_item(item)
7983
current_room.add_item(item)
84+
emit_signal("room_updated", current_room)
8085
return "You drop the " + Types.wrap_item_text(item.item_name) + "."
8186

8287
return "You don't have anything called " + Types.wrap_item_text(second_word) + "."
@@ -163,4 +168,5 @@ func help() -> String:
163168

164169
func change_room(new_room: GameRoom) -> String:
165170
current_room = new_room
171+
emit_signal("room_changed", new_room)
166172
return new_room.get_full_description()

Game.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
extends Control
22

33

4-
onready var game_info = $Background/MarginContainer/Rows/GameInfo
4+
onready var game_info = $Background/MarginContainer/Columns/Rows/GameInfo
55
onready var command_processor = $CommandProcessor
66
onready var room_manager = $RoomManager
77
onready var player = $Player
88

99

1010
func _ready() -> void:
11+
var side_panel = $Background/MarginContainer/Columns/SidePanel
12+
command_processor.connect("room_changed", side_panel, "handle_room_changed")
13+
command_processor.connect("room_updated", side_panel, "handle_room_updated")
14+
1115
game_info.create_response(Types.wrap_system_text("Welcome to the retro text adventure! You can type 'help' to see available commands."))
1216

1317
var starting_room_response = command_processor.initialize(room_manager.get_child(0), player)
1418
game_info.create_response(starting_room_response)
1519

1620

21+
1722
func _on_Input_text_entered(new_text: String) -> void:
1823
if new_text.empty():
1924
return

Game.tscn

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=13 format=2]
1+
[gd_scene load_steps=14 format=2]
22

33
[ext_resource path="res://input/Input.gd" type="Script" id=1]
44
[ext_resource path="res://fonts/plex_mono_28.tres" type="DynamicFont" id=2]
@@ -8,6 +8,7 @@
88
[ext_resource path="res://rooms/RoomManager.gd" type="Script" id=6]
99
[ext_resource path="res://Player.gd" type="Script" id=7]
1010
[ext_resource path="res://GameInfo.tscn" type="PackedScene" id=8]
11+
[ext_resource path="res://SidePanel.tscn" type="PackedScene" id=9]
1112

1213
[sub_resource type="StyleBoxFlat" id=1]
1314
bg_color = Color( 0.0784314, 0.0784314, 0.0784314, 1 )
@@ -129,36 +130,43 @@ custom_constants/margin_top = 20
129130
custom_constants/margin_left = 20
130131
custom_constants/margin_bottom = 20
131132

132-
[node name="Rows" type="VBoxContainer" parent="Background/MarginContainer"]
133+
[node name="Columns" type="HBoxContainer" parent="Background/MarginContainer"]
133134
margin_left = 20.0
134135
margin_top = 20.0
135136
margin_right = 1004.0
136137
margin_bottom = 580.0
137138
custom_constants/separation = 20
138139

139-
[node name="GameInfo" parent="Background/MarginContainer/Rows" instance=ExtResource( 8 )]
140+
[node name="Rows" type="VBoxContainer" parent="Background/MarginContainer/Columns"]
141+
margin_right = 644.0
142+
margin_bottom = 560.0
143+
size_flags_horizontal = 3
144+
custom_constants/separation = 20
140145

141-
[node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Rows"]
146+
[node name="GameInfo" parent="Background/MarginContainer/Columns/Rows" instance=ExtResource( 8 )]
147+
margin_right = 644.0
148+
149+
[node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Columns/Rows"]
142150
margin_top = 500.0
143-
margin_right = 984.0
151+
margin_right = 644.0
144152
margin_bottom = 560.0
145153
rect_min_size = Vector2( 0, 60 )
146154
custom_styles/panel = SubResource( 3 )
147155

148-
[node name="HBoxContainer" type="HBoxContainer" parent="Background/MarginContainer/Rows/InputArea"]
149-
margin_right = 984.0
156+
[node name="HBoxContainer" type="HBoxContainer" parent="Background/MarginContainer/Columns/Rows/InputArea"]
157+
margin_right = 644.0
150158
margin_bottom = 60.0
151159

152-
[node name="Caret" type="Label" parent="Background/MarginContainer/Rows/InputArea/HBoxContainer"]
160+
[node name="Caret" type="Label" parent="Background/MarginContainer/Columns/Rows/InputArea/HBoxContainer"]
153161
margin_top = 11.0
154162
margin_right = 51.0
155163
margin_bottom = 48.0
156164
custom_fonts/font = ExtResource( 2 )
157165
text = " > "
158166

159-
[node name="Input" type="LineEdit" parent="Background/MarginContainer/Rows/InputArea/HBoxContainer"]
167+
[node name="Input" type="LineEdit" parent="Background/MarginContainer/Columns/Rows/InputArea/HBoxContainer"]
160168
margin_left = 55.0
161-
margin_right = 984.0
169+
margin_right = 644.0
162170
margin_bottom = 60.0
163171
size_flags_horizontal = 3
164172
custom_fonts/font = ExtResource( 2 )
@@ -167,5 +175,8 @@ custom_styles/normal = SubResource( 5 )
167175
max_length = 48
168176
script = ExtResource( 1 )
169177

170-
[connection signal="text_entered" from="Background/MarginContainer/Rows/InputArea/HBoxContainer/Input" to="." method="_on_Input_text_entered"]
171-
[connection signal="text_entered" from="Background/MarginContainer/Rows/InputArea/HBoxContainer/Input" to="Background/MarginContainer/Rows/InputArea/HBoxContainer/Input" method="_on_Input_text_entered"]
178+
[node name="SidePanel" parent="Background/MarginContainer/Columns" instance=ExtResource( 9 )]
179+
margin_left = 664.0
180+
181+
[connection signal="text_entered" from="Background/MarginContainer/Columns/Rows/InputArea/HBoxContainer/Input" to="." method="_on_Input_text_entered"]
182+
[connection signal="text_entered" from="Background/MarginContainer/Columns/Rows/InputArea/HBoxContainer/Input" to="Background/MarginContainer/Columns/Rows/InputArea/HBoxContainer/Input" method="_on_Input_text_entered"]

GameInfo.tscn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://GameInfo.gd" type="Script" id=1]
4-
5-
[sub_resource type="StyleBoxFlat" id=2]
6-
bg_color = Color( 0.215686, 0.215686, 0.215686, 1 )
4+
[ext_resource path="res://main_panel.tres" type="StyleBox" id=2]
75

86
[node name="GameInfo" type="PanelContainer"]
97
margin_right = 984.0
108
margin_bottom = 480.0
119
size_flags_vertical = 3
12-
custom_styles/panel = SubResource( 2 )
10+
custom_styles/panel = ExtResource( 2 )
1311
script = ExtResource( 1 )
1412
__meta__ = {
1513
"_edit_use_anchors_": false

SidePanel.gd

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
extends PanelContainer
2+
3+
4+
onready var room_name = $MarginContainer/Rows/TitleSection/RoomNameLabel
5+
onready var room_description = $MarginContainer/Rows/RoomDescriptionLabel
6+
7+
onready var exit_label = $MarginContainer/Rows/ListArea/ExitLabel
8+
onready var npc_label = $MarginContainer/Rows/ListArea/NpcLabel
9+
onready var item_label = $MarginContainer/Rows/ListArea/ItemLabel
10+
11+
12+
func handle_room_changed(new_room):
13+
room_name.text = new_room.room_name
14+
room_description.text = new_room.room_description
15+
16+
exit_label.bbcode_text = new_room.get_exit_description()
17+
18+
var npc_string = new_room.get_npc_description()
19+
if npc_string == "":
20+
npc_label.hide()
21+
else:
22+
npc_label.show()
23+
npc_label.bbcode_text = npc_string
24+
25+
var item_string = new_room.get_item_description()
26+
if item_string == "":
27+
item_label.hide()
28+
else:
29+
item_label.show()
30+
item_label.bbcode_text = item_string
31+
32+
33+
func handle_room_updated(current_room):
34+
handle_room_changed(current_room)

SidePanel.tscn

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
[gd_scene load_steps=5 format=2]
2+
3+
[ext_resource path="res://main_panel.tres" type="StyleBox" id=1]
4+
[ext_resource path="res://fonts/plex_mono_24.tres" type="DynamicFont" id=2]
5+
[ext_resource path="res://fonts/plex_mono_16.tres" type="DynamicFont" id=3]
6+
[ext_resource path="res://SidePanel.gd" type="Script" id=4]
7+
8+
[node name="SidePanel" type="PanelContainer"]
9+
margin_left = 856.0
10+
margin_right = 984.0
11+
margin_bottom = 560.0
12+
rect_min_size = Vector2( 320, 0 )
13+
custom_styles/panel = ExtResource( 1 )
14+
script = ExtResource( 4 )
15+
__meta__ = {
16+
"_edit_use_anchors_": false
17+
}
18+
19+
[node name="MarginContainer" type="MarginContainer" parent="."]
20+
margin_right = 320.0
21+
margin_bottom = 560.0
22+
custom_constants/margin_right = 5
23+
custom_constants/margin_top = 5
24+
custom_constants/margin_left = 5
25+
custom_constants/margin_bottom = 5
26+
27+
[node name="Rows" type="VBoxContainer" parent="MarginContainer"]
28+
margin_left = 5.0
29+
margin_top = 5.0
30+
margin_right = 315.0
31+
margin_bottom = 555.0
32+
custom_constants/separation = 20
33+
34+
[node name="TitleSection" type="VBoxContainer" parent="MarginContainer/Rows"]
35+
margin_right = 310.0
36+
margin_bottom = 54.0
37+
custom_constants/separation = 0
38+
39+
[node name="InfoLabel" type="Label" parent="MarginContainer/Rows/TitleSection"]
40+
margin_right = 310.0
41+
margin_bottom = 22.0
42+
custom_colors/font_color = Color( 0.631373, 0.631373, 0.631373, 1 )
43+
custom_fonts/font = ExtResource( 3 )
44+
text = "You are in..."
45+
46+
[node name="RoomNameLabel" type="Label" parent="MarginContainer/Rows/TitleSection"]
47+
margin_top = 22.0
48+
margin_right = 310.0
49+
margin_bottom = 54.0
50+
custom_colors/font_color = Color( 0.980392, 1, 0.580392, 1 )
51+
custom_fonts/font = ExtResource( 2 )
52+
text = "A Room"
53+
autowrap = true
54+
55+
[node name="RoomDescriptionLabel" type="Label" parent="MarginContainer/Rows"]
56+
margin_top = 74.0
57+
margin_right = 310.0
58+
margin_bottom = 121.0
59+
custom_fonts/font = ExtResource( 3 )
60+
text = "This will be where the room's description goes."
61+
autowrap = true
62+
63+
[node name="ListArea" type="VBoxContainer" parent="MarginContainer/Rows"]
64+
margin_top = 141.0
65+
margin_right = 310.0
66+
margin_bottom = 483.0
67+
size_flags_vertical = 3
68+
69+
[node name="ExitLabel" type="RichTextLabel" parent="MarginContainer/Rows/ListArea"]
70+
margin_right = 310.0
71+
margin_bottom = 23.0
72+
custom_fonts/normal_font = ExtResource( 3 )
73+
bbcode_enabled = true
74+
bbcode_text = "Exits: Option"
75+
text = "Exits: Option"
76+
fit_content_height = true
77+
78+
[node name="NpcLabel" type="RichTextLabel" parent="MarginContainer/Rows/ListArea"]
79+
margin_top = 27.0
80+
margin_right = 310.0
81+
margin_bottom = 50.0
82+
custom_fonts/normal_font = ExtResource( 3 )
83+
bbcode_enabled = true
84+
bbcode_text = "Exits: Option"
85+
text = "Exits: Option"
86+
fit_content_height = true
87+
88+
[node name="ItemLabel" type="RichTextLabel" parent="MarginContainer/Rows/ListArea"]
89+
margin_top = 54.0
90+
margin_right = 310.0
91+
margin_bottom = 77.0
92+
custom_fonts/normal_font = ExtResource( 3 )
93+
bbcode_enabled = true
94+
bbcode_text = "Exits: Option"
95+
text = "Exits: Option"
96+
fit_content_height = true
97+
98+
[node name="HelpLabel" type="Label" parent="MarginContainer/Rows"]
99+
margin_top = 503.0
100+
margin_right = 310.0
101+
margin_bottom = 550.0
102+
custom_colors/font_color = Color( 1, 0.827451, 0.580392, 1 )
103+
custom_fonts/font = ExtResource( 3 )
104+
text = "You can type 'help' to see all possible commands."
105+
autowrap = true

main_panel.tres

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[gd_resource type="StyleBoxFlat" format=2]
2+
3+
[resource]
4+
bg_color = Color( 0.215686, 0.215686, 0.215686, 1 )

0 commit comments

Comments
 (0)