Add GUI to Arrive demo

This commit is contained in:
Francois Belair 2019-12-22 14:23:25 -05:00
parent 87aef48251
commit 35d9b2e1a6
7 changed files with 204 additions and 11 deletions

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://demos/arrive/Arriver.gd" type="Script" id=1]
[ext_resource path="res://demos/arrive/ArriveDemo.gd" type="Script" id=2]
[ext_resource path="res://demos/arrive/Target.gd" type="Script" id=3]
[ext_resource path="res://demos/arrive/GUI.tscn" type="PackedScene" id=4]
[sub_resource type="CircleShape2D" id=1]
radius = 15.0
@ -18,3 +19,7 @@ shape = SubResource( 1 )
[node name="Target" type="Node2D" parent="."]
script = ExtResource( 3 )
[node name="GUI" parent="." instance=ExtResource( 4 )]
margin_right = 227.0
margin_bottom = 184.0

View File

@ -2,7 +2,36 @@ extends Node2D
onready var _target: = $Target
onready var _arriver: = $Arriver
onready var _gui: = $GUI
func _ready() -> void:
_gui.connect("align_tolerance_changed", self, "_on_GUI_align_tolerance_changed")
_gui.connect("decel_radius_changed", self, "_on_GUI_decel_radius_changed")
_gui.connect("max_speed_changed", self, "_on_GUI_max_speed_changed")
_gui.connect("max_accel_changed", self, "_on_GUI_max_accel_changed")
_gui.max_speed.text = str(_arriver._agent.max_linear_speed)
_gui.max_accel.text = str(_arriver._agent.max_linear_acceleration)
_gui.arrival_tolerance.text = str(_arriver._arrive.arrival_tolerance)
_gui.deceleration_radius.text = str(_arriver._arrive.deceleration_radius)
func draw(location: Vector2) -> void:
_target.draw(location)
func _on_GUI_align_tolerance_changed(value: int) -> void:
_arriver._arrive.arrival_tolerance = value
func _on_GUI_decel_radius_changed(value: int) -> void:
_arriver._arrive.deceleration_radius = value
func _on_GUI_max_speed_changed(value: int) -> void:
_arriver._agent.max_linear_speed = value
func _on_GUI_max_accel_changed(value: int) -> void:
_arriver._agent.max_linear_acceleration = value

View File

@ -0,0 +1,47 @@
extends MarginContainer
signal max_speed_changed(value)
signal max_accel_changed(value)
signal align_tolerance_changed(value)
signal decel_radius_changed(value)
onready var max_speed: = $Controls/MaxSpeed/LineEdit
onready var max_accel: = $Controls/MaxAccel/LineEdit
onready var arrival_tolerance: = $Controls/ArrivalTolerance/LineEdit
onready var deceleration_radius: = $Controls/DecelRadius/LineEdit
func _ready() -> void:
max_speed.connect("text_changed", self, "_on_MaxSpeed_text_changed")
max_accel.connect("text_changed", self, "_on_MaxAccel_text_changed")
arrival_tolerance.connect("text_changed", self, "_on_ArrivalTolerance_text_changed")
deceleration_radius.connect("text_changed", self, "_on_DecelerationRadius_text_changed")
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
max_speed.release_focus()
max_accel.release_focus()
arrival_tolerance.release_focus()
deceleration_radius.release_focus()
func _on_MaxSpeed_text_changed(new_text: String) -> void:
if new_text.is_valid_integer():
emit_signal("max_speed_changed", int(float(new_text)))
func _on_MaxAccel_text_changed(new_text: String) -> void:
if new_text.is_valid_integer():
emit_signal("max_accel_changed", int(float(new_text)))
func _on_ArrivalTolerance_text_changed(new_text: String) -> void:
if new_text.is_valid_integer():
emit_signal("align_tolerance_changed", int(float(new_text)))
func _on_DecelerationRadius_text_changed(new_text: String) -> void:
if new_text.is_valid_integer():
emit_signal("decel_radius_changed", int(float(new_text)))

View File

@ -0,0 +1,108 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://demos/arrive/GUI.gd" type="Script" id=1]
[node name="GUI" type="MarginContainer"]
anchor_bottom = 1.0
margin_right = 40.0
custom_constants/margin_right = 20
custom_constants/margin_top = 20
custom_constants/margin_left = 20
custom_constants/margin_bottom = 20
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Controls" type="VBoxContainer" parent="."]
margin_left = 20.0
margin_top = 20.0
margin_right = 207.0
margin_bottom = 580.0
[node name="MaxSpeed" type="HBoxContainer" parent="Controls"]
margin_right = 187.0
margin_bottom = 24.0
[node name="Label" type="Label" parent="Controls/MaxSpeed"]
margin_top = 4.0
margin_right = 125.0
margin_bottom = 19.0
rect_min_size = Vector2( 125, 15 )
text = "Max speed"
[node name="LineEdit" type="LineEdit" parent="Controls/MaxSpeed"]
margin_left = 129.0
margin_right = 187.0
margin_bottom = 24.0
focus_mode = 1
[node name="MaxAccel" type="HBoxContainer" parent="Controls"]
margin_top = 28.0
margin_right = 187.0
margin_bottom = 52.0
[node name="Label" type="Label" parent="Controls/MaxAccel"]
margin_top = 4.0
margin_right = 125.0
margin_bottom = 19.0
rect_min_size = Vector2( 125, 15 )
text = "Max acceleration"
[node name="LineEdit" type="LineEdit" parent="Controls/MaxAccel"]
margin_left = 129.0
margin_right = 187.0
margin_bottom = 24.0
focus_mode = 1
[node name="ArrivalTolerance" type="HBoxContainer" parent="Controls"]
margin_top = 56.0
margin_right = 187.0
margin_bottom = 80.0
[node name="Label" type="Label" parent="Controls/ArrivalTolerance"]
margin_top = 4.0
margin_right = 125.0
margin_bottom = 19.0
rect_min_size = Vector2( 125, 15 )
text = "Arrival tolerance"
[node name="LineEdit" type="LineEdit" parent="Controls/ArrivalTolerance"]
margin_left = 129.0
margin_right = 187.0
margin_bottom = 24.0
focus_mode = 1
[node name="DecelRadius" type="HBoxContainer" parent="Controls"]
margin_top = 84.0
margin_right = 187.0
margin_bottom = 108.0
[node name="Label" type="Label" parent="Controls/DecelRadius"]
margin_top = 4.0
margin_right = 125.0
margin_bottom = 19.0
rect_min_size = Vector2( 125, 15 )
text = "Deceleration radius"
[node name="LineEdit" type="LineEdit" parent="Controls/DecelRadius"]
margin_left = 129.0
margin_right = 187.0
margin_bottom = 24.0
focus_mode = 1
[node name="Help" type="VBoxContainer" parent="Controls"]
margin_top = 112.0
margin_right = 187.0
margin_bottom = 144.0
[node name="Controls" type="Label" parent="Controls/Help"]
margin_right = 187.0
margin_bottom = 14.0
text = "Controls"
[node name="Label" type="Label" parent="Controls/Help"]
margin_top = 18.0
margin_right = 187.0
margin_bottom = 32.0
text = "Mouse click"

View File

@ -17,8 +17,6 @@ __meta__ = {
"_editor_description_": "A demo showing the usage of the Face steering behavior."
}
[node name="GUI" parent="." instance=ExtResource( 4 )]
[node name="Player" type="KinematicBody2D" parent="."]
position = Vector2( 512, 450 )
script = ExtResource( 1 )
@ -32,3 +30,7 @@ script = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Turret"]
shape = SubResource( 2 )
[node name="GUI" parent="." instance=ExtResource( 4 )]
margin_right = 232.0
margin_bottom = 204.0

View File

@ -12,8 +12,6 @@ __meta__ = {
"_editor_description_": "Toy demo to demonstrate the use of the Pursue contrasted to the more naive Seek steering behavior."
}
[node name="GUI" parent="." instance=ExtResource( 4 )]
[node name="BoundaryManager" type="Node2D" parent="."]
script = ExtResource( 2 )
@ -47,3 +45,7 @@ use_seek = true
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BoundaryManager/Seeker"]
modulate = Color( 0.317647, 0.317647, 0.317647, 1 )
polygon = PoolVector2Array( 0, -30, -25, 25, 25, 25 )
[node name="GUI" parent="." instance=ExtResource( 4 )]
margin_right = 261.0
margin_bottom = 150.0

View File

@ -22,12 +22,6 @@ __meta__ = {
"_editor_description_": "A toy demo to demonstrate the usage for the Seek and Flee steering behaviors."
}
[node name="GUI" parent="." instance=ExtResource( 7 )]
margin_left = -512.0
margin_top = -300.0
margin_right = -414.0
margin_bottom = -208.0
[node name="Camera2D" type="Camera2D" parent="."]
current = true
@ -77,3 +71,9 @@ shape = SubResource( 3 )
[node name="Spawner" type="Node2D" parent="."]
script = ExtResource( 2 )
Entity = ExtResource( 4 )
[node name="GUI" parent="." instance=ExtResource( 7 )]
margin_left = -512.0
margin_top = -300.0
margin_right = -414.0
margin_bottom = -152.0