Skip to content

Commit c70c38e

Browse files
add toggle to hide NPCs
1 parent 21c8b64 commit c70c38e

File tree

4 files changed

+73
-21
lines changed

4 files changed

+73
-21
lines changed

Game.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func _ready():
7373

7474
$CanvasLayer/GameModeSelection.visible = false
7575
var _err = $CanvasLayer/UI/Settings.connect("on_toggle_laser", self, "toggle_robots_lasers")
76+
_err = $CanvasLayer/UI/Settings.connect("on_toggle_npcs", self, "toggle_npcs")
77+
toggle_npcs($CanvasLayer/UI/Settings.NPCsBtn.pressed)
7678

7779
set_physics_process(false)
7880

@@ -327,6 +329,9 @@ func compute_visible_humans(robot):
327329
return robot.players_in_fov
328330

329331
func is_object_visible(object, camera):
332+
if not object.visible:
333+
return null
334+
330335
var target = object.global_transform.origin
331336
if is_point_in_frustum(target, camera):
332337
var space_state = get_world().direct_space_state
@@ -508,6 +513,11 @@ func toggle_robots_lasers(state):
508513
for robot in $Robots.get_children():
509514
robot.get_node("LaserScanner").visible = state
510515

516+
func toggle_npcs(state):
517+
for npc_path in $NPCPath.get_children():
518+
npc_path.get_child(0).get_child(0).visible = state
519+
npc_path.get_child(0).get_child(0).face.visible = state
520+
511521
remote func pre_configure_game():
512522

513523
var selfPeerID = "myself" # used in STANDALONE mode

Game.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.808762, 0, -0.378852 )
180180
curve = SubResource( 2 )
181181

182182
[node name="NPC1" parent="NPCPath/NPCPath1" instance=ExtResource( 7 )]
183-
transform = Transform( 0.330899, 0, 0.943662, 0, 1, 0, -0.943667, 0, 0.330898, -5.06129, 1.52588e-05, 4.86618 )
183+
transform = Transform( 0.330899, 0, 0.943661, 0, 1, 0, -0.943667, 0, 0.330897, -5.06129, 1.52588e-05, 4.86618 )
184184
skin = ExtResource( 9 )
185185
npc_name = "Anna"
186186

@@ -189,7 +189,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -11.427, 0, -1.33055 )
189189
curve = SubResource( 3 )
190190

191191
[node name="NPC2" parent="NPCPath/NPCPath2" instance=ExtResource( 7 )]
192-
transform = Transform( 0.990202, 0, 0.139646, 0, 1, 0, -0.139646, 0, 0.990198, 4.22644, 0, 0.860942 )
192+
transform = Transform( 0.990202, 0, 0.139645, 0, 1, 0, -0.139646, 0, 0.990197, 4.22644, 0, 0.860942 )
193193
skin = ExtResource( 8 )
194194
npc_name = "Nicky"
195195

Settings.gd

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

33
signal on_toggle_laser
4+
signal on_toggle_npcs
5+
6+
onready var NPCsBtn = $CenterContainer/VBoxContainer/HBoxContainer3/NPCsEnabled
47

58
# used when pressing 'cancel'
69
var original_state_laser
10+
var original_state_npcs
711

812
func _ready():
913
visible = false
@@ -13,10 +17,13 @@ func _ready():
1317
_err = $CenterContainer/VBoxContainer/HBoxContainer2/ok.connect("pressed", self, "on_ok")
1418
_err = $CenterContainer/VBoxContainer/HBoxContainer2/cancel.connect("pressed", self, "on_cancel")
1519
_err = $CenterContainer/VBoxContainer/HBoxContainer/LaserEnabled.connect("toggled", self, "on_toggle_laser")
20+
_err = NPCsBtn.connect("toggled", self, "on_toggle_npcs")
21+
1622

1723
func show(msg = null):
1824

1925
original_state_laser = $CenterContainer/VBoxContainer/HBoxContainer/LaserEnabled.pressed
26+
original_state_npcs = NPCsBtn.pressed
2027

2128
if msg:
2229
$CenterContainer/VBoxContainer/Label.text = msg
@@ -31,6 +38,10 @@ func on_toggle_laser(state):
3138

3239
emit_signal("on_toggle_laser", state)
3340

41+
func on_toggle_npcs(state):
42+
43+
emit_signal("on_toggle_npcs", state)
44+
3445
func on_ok():
3546

3647
$Tween.remove_all()
@@ -45,6 +56,8 @@ func on_cancel():
4556

4657
$CenterContainer/VBoxContainer/HBoxContainer/LaserEnabled.pressed = original_state_laser
4758
on_toggle_laser(original_state_laser)
59+
NPCsBtn.pressed = original_state_npcs
60+
on_toggle_npcs(original_state_npcs)
4861

4962
$Tween.remove_all()
5063
$Tween.interpolate_property(self, "modulate:a", null, 0.0, 0.5, Tween.TRANS_QUART, Tween.EASE_IN)

Settings.tscn

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,42 @@ __meta__ = {
3131

3232
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
3333
margin_left = 344.0
34-
margin_top = 128.0
34+
margin_top = 92.0
3535
margin_right = 679.0
36-
margin_bottom = 471.0
36+
margin_bottom = 508.0
3737
custom_constants/separation = 20
3838

3939
[node name="Settings" type="Label" parent="CenterContainer/VBoxContainer"]
4040
margin_right = 335.0
41-
margin_bottom = 17.0
41+
margin_bottom = 20.0
4242
theme = ExtResource( 1 )
4343
text = "Settings"
4444
align = 1
4545

4646
[node name="Control3" type="Control" parent="CenterContainer/VBoxContainer"]
47-
margin_top = 37.0
47+
margin_top = 40.0
4848
margin_right = 335.0
49-
margin_bottom = 87.0
49+
margin_bottom = 90.0
5050
rect_min_size = Vector2( 50, 50 )
5151
size_flags_horizontal = 3
5252
__meta__ = {
5353
"_edit_use_anchors_": false
5454
}
5555

5656
[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
57-
margin_top = 107.0
57+
margin_top = 110.0
5858
margin_right = 335.0
59-
margin_bottom = 157.0
59+
margin_bottom = 160.0
6060

6161
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/HBoxContainer"]
62-
margin_top = 16.0
63-
margin_right = 75.0
64-
margin_bottom = 33.0
62+
margin_top = 15.0
63+
margin_right = 96.0
64+
margin_bottom = 35.0
6565
theme = ExtResource( 1 )
6666
text = "Laser visible"
6767

6868
[node name="Control" type="Control" parent="CenterContainer/VBoxContainer/HBoxContainer"]
69-
margin_left = 79.0
69+
margin_left = 100.0
7070
margin_right = 281.0
7171
margin_bottom = 50.0
7272
rect_min_size = Vector2( 50, 50 )
@@ -82,17 +82,46 @@ texture_normal = ExtResource( 10 )
8282
texture_pressed = ExtResource( 11 )
8383
expand = true
8484

85+
[node name="HBoxContainer3" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
86+
margin_top = 180.0
87+
margin_right = 335.0
88+
margin_bottom = 230.0
89+
90+
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/HBoxContainer3"]
91+
margin_top = 15.0
92+
margin_right = 98.0
93+
margin_bottom = 35.0
94+
theme = ExtResource( 1 )
95+
text = "Enable NPCs"
96+
97+
[node name="Control" type="Control" parent="CenterContainer/VBoxContainer/HBoxContainer3"]
98+
margin_left = 102.0
99+
margin_right = 281.0
100+
margin_bottom = 50.0
101+
rect_min_size = Vector2( 50, 50 )
102+
size_flags_horizontal = 3
103+
104+
[node name="NPCsEnabled" type="TextureButton" parent="CenterContainer/VBoxContainer/HBoxContainer3"]
105+
margin_left = 285.0
106+
margin_right = 335.0
107+
margin_bottom = 50.0
108+
rect_min_size = Vector2( 50, 50 )
109+
toggle_mode = true
110+
texture_normal = ExtResource( 10 )
111+
texture_pressed = ExtResource( 11 )
112+
expand = true
113+
85114
[node name="Control2" type="Control" parent="CenterContainer/VBoxContainer"]
86-
margin_top = 177.0
115+
margin_top = 250.0
87116
margin_right = 335.0
88-
margin_bottom = 227.0
117+
margin_bottom = 300.0
89118
rect_min_size = Vector2( 50, 50 )
90119
size_flags_horizontal = 3
91120

92121
[node name="HBoxContainer2" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
93-
margin_top = 247.0
122+
margin_top = 320.0
94123
margin_right = 335.0
95-
margin_bottom = 343.0
124+
margin_bottom = 416.0
96125
alignment = 1
97126
__meta__ = {
98127
"_edit_use_anchors_": false
@@ -155,10 +184,10 @@ __meta__ = {
155184
}
156185

157186
[node name="VBoxContainer" type="VBoxContainer" parent="ModalMessage/CenterContainer"]
158-
margin_left = 414.0
159-
margin_top = 245.0
160-
margin_right = 609.0
161-
margin_bottom = 354.0
187+
margin_left = 385.0
188+
margin_top = 244.0
189+
margin_right = 639.0
190+
margin_bottom = 356.0
162191
custom_constants/separation = 20
163192

164193
[node name="Label" type="Label" parent="ModalMessage/CenterContainer/VBoxContainer"]

0 commit comments

Comments
 (0)