Make computer UI disappear when clicking elsewhere

This commit is contained in:
Hamcha 2020-07-07 00:09:37 +02:00
parent 97784eb24e
commit 958e91df75
Signed by: hamcha
GPG Key ID: 41467804B19A3315
3 changed files with 20 additions and 4 deletions

View File

@ -44,14 +44,22 @@ func set_direction(dir):
$computer.region_rect.position = Vector2(32, 0)
$computer/screen.region_rect.position = screen_region_offset + Vector2(64, 0)
func open_controls():
func manage_controls(show: bool):
match computer_type:
ComputerType.ShipCommand:
$Control/ControlComp.visible = true
$Control/ControlComp.visible = show
func _input(event):
if event is InputEventMouseButton and event.pressed and not is_inside:
manage_controls(false)
func _input_event(viewport, event, shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
print(event)
open_controls()
manage_controls(true)
var is_inside = false
func _ui_focus_changed(entered):
print(entered)
is_inside = entered

View File

@ -76,3 +76,5 @@ margin_top = -78.3109
margin_right = 166.851
margin_bottom = 53.6891
rect_scale = Vector2( 0.5, 0.5 )
[connection signal="mouse_entered" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ true ]]
[connection signal="mouse_exited" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ false ]]

View File

@ -7,6 +7,7 @@ margin_left = -100.0
margin_top = -150.0
margin_right = 100.0
margin_bottom = -20.0
mouse_filter = 1
script = ExtResource( 1 )
[node name="Panel" type="Panel" parent="."]
@ -15,6 +16,7 @@ margin_top = 90.0
margin_right = 140.0
margin_bottom = 130.0
rect_rotation = 45.0
mouse_filter = 1
__meta__ = {
"_edit_use_anchors_": false
}
@ -47,12 +49,14 @@ __meta__ = {
margin_top = 5.0
margin_right = 180.0
margin_bottom = 19.0
mouse_filter = 1
text = "Ship velocity"
[node name="HSlider" type="HSlider" parent="Container/VelocityBox"]
margin_top = 23.0
margin_right = 180.0
margin_bottom = 39.0
mouse_filter = 1
max_value = 1000.0
value = 1000.0
tick_count = 10
@ -73,12 +77,14 @@ __meta__ = {
margin_top = 5.0
margin_right = 180.0
margin_bottom = 19.0
mouse_filter = 1
text = "Ship direction"
[node name="HSlider" type="HSlider" parent="Container/DirectionBox"]
margin_top = 23.0
margin_right = 180.0
margin_bottom = 39.0
mouse_filter = 1
max_value = 360.0
tick_count = 18
ticks_on_borders = true