Setup boundaries on sliders and added GUI functionality

pull/1/head
DAMO238 2020-04-18 18:26:09 +01:00
parent 8e4a264711
commit 8a4fedddfa
4 changed files with 208 additions and 66 deletions

View File

@ -14,6 +14,7 @@ mesh = SubResource( 1 )
material/0 = null
[node name="MainPanel" type="Panel" parent="."]
visible = false
anchor_left = 0.5
anchor_right = 0.5
margin_left = -390.0
@ -31,6 +32,10 @@ anchor_right = 0.6
anchor_bottom = 0.5
margin_left = 10.0
grow_vertical = 2
max_value = 5.0
step = 0.01
tick_count = 6
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
@ -93,75 +98,11 @@ anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -300.0
margin_top = -175.0
margin_top = -300.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="XLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.05
anchor_right = 0.4
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="XRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.55
anchor_right = 0.4
anchor_bottom = 0.95
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="YLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.05
anchor_right = 0.6
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="YRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.55
anchor_right = 0.6
anchor_bottom = 0.95
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="ZLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.05
anchor_right = 0.8
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="ZRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.55
anchor_right = 0.8
anchor_bottom = 0.95
margin_top = -0.263489
margin_bottom = -0.263489
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="LabelHolder" type="Control" parent="ThrustPanel"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -233,3 +174,109 @@ margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "Vernier Thrust"
[node name="XLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.05
anchor_right = 0.4
anchor_bottom = 0.45
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.01
tick_count = 3
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="XRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.55
anchor_right = 0.4
anchor_bottom = 0.95
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
tick_count = 3
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="YLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.05
anchor_right = 0.6
anchor_bottom = 0.45
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
tick_count = 3
ticks_on_borders = true
[node name="YRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.55
anchor_right = 0.6
anchor_bottom = 0.95
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
tick_count = 3
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ZLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.05
anchor_right = 0.8
anchor_bottom = 0.45
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
tick_count = 3
ticks_on_borders = true
[node name="ZRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.55
anchor_right = 0.8
anchor_bottom = 0.95
margin_left = -8.0
margin_top = -0.263489
margin_right = 8.0
margin_bottom = -0.263489
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
tick_count = 3
ticks_on_borders = true
[connection signal="value_changed" from="MainPanel/TimeBar" to="." method="_on_TimeBar_value_changed"]
[connection signal="pressed" from="MainPanel/AddButton" to="." method="_on_AddButton_pressed"]
[connection signal="pressed" from="MainPanel/RemoveButton" to="." method="_on_RemoveButton_pressed"]
[connection signal="pressed" from="MainPanel/ClearButton" to="." method="_on_ClearButton_pressed"]
[connection signal="pressed" from="MainPanel/EndTurnButton" to="." method="_on_EndTurnButton_pressed"]
[connection signal="value_changed" from="ThrustPanel/XLin" to="." method="_on_XLin_value_changed"]
[connection signal="value_changed" from="ThrustPanel/XRot" to="." method="_on_XRot_value_changed"]
[connection signal="value_changed" from="ThrustPanel/YLin" to="." method="_on_YLin_value_changed"]
[connection signal="value_changed" from="ThrustPanel/YRot" to="." method="_on_YRot_value_changed"]
[connection signal="value_changed" from="ThrustPanel/ZLin" to="." method="_on_ZLin_value_changed"]
[connection signal="value_changed" from="ThrustPanel/ZRot" to="." method="_on_ZRot_value_changed"]

View File

@ -11,6 +11,10 @@ remote func place_player(player_id : int, position : Vector3, rotation : Vector3
player.rotation = rotation
add_child(player)
players[player_id] = player
if player_id == get_tree().get_network_unique_id():
player.is_local = true
get_parent().console_print('Setting player with id (' + String(player_id) + ') as local')
player.init()
func init():
get_parent().arena_ready()

View File

@ -5,11 +5,15 @@ const TURN_TIME : float = 5.0
var elements = [] # All elements of the plan thus far
var current_elements = [] # All elements of the next 5 seconds
func add_element(element : PlanElement) -> bool:
func current_time() -> float:
var total_time : float = 0.0
for current_element in current_elements:
var _element : PlanElement = (current_element as PlanElement)
total_time += _element.time
return total_time
func add_element(element : PlanElement) -> bool:
var total_time : float = self.current_time()
if total_time + element.time > TURN_TIME:
return false
current_elements.append(element)

View File

@ -1,5 +1,92 @@
extends Spatial
var plan : Plan = Plan.new()
var is_local : bool = false
func init() -> void:
get_parent().get_parent().console_print("Player is set to local? " + String(is_local))
if is_local:
$MainPanel.visible = true
$ThrustPanel.visible = true
func _on_TimeBar_value_changed(value : float) -> void:
var min_time : float = plan.current_time()
get_parent().get_parent().console_print("Current plan time is " + String(min_time))
if value <= min_time:
$MainPanel/TimeBar.value = min_time
func _on_AddButton_pressed() -> void:
var new_thrust_element : ThrustElement = ThrustElement.new()
new_thrust_element.linear_thrust = get_linear_vector()
new_thrust_element.rotational_thrust = get_rotational_vector()
new_thrust_element.time = $MainPanel/TimeBar.value - plan.current_time()
if (plan.add_element(new_thrust_element)):
get_parent().get_parent().console_print("Added thrust element")
else:
get_parent().get_parent().console_print("Failed to add thrust element")
func _on_RemoveButton_pressed() -> void:
plan.remove_last_element()
func _on_ClearButton_pressed() -> void:
plan.remove_all_elements()
func _on_EndTurnButton_pressed() -> void:
plan.new_turn()
# TODO: Add the rest functionality
func get_linear_vector() -> Vector3:
return Vector3($ThrustPanel/XLin.value, $ThrustPanel/YLin.value, $ThrustPanel/ZLin.value)
func get_rotational_vector() -> Vector3:
return Vector3($ThrustPanel/XRot.value, $ThrustPanel/YRot.value, $ThrustPanel/ZRot.value)
func _on_XLin_value_changed(value : float) -> void:
get_parent().get_parent().console_print("Length of vector = " + String(get_linear_vector().length()))
if get_linear_vector().length() < 1.0:
return
$ThrustPanel/XLin.value = sign($ThrustPanel/XLin.value) * \
sqrt(1 - pow($ThrustPanel/YLin.value, 2) - pow($ThrustPanel/ZLin.value, 2))
func _on_XRot_value_changed(value : float) -> void:
if get_rotational_vector().length() < 1.0:
return
$ThrustPanel/XRot.value = sign($ThrustPanel/XRot.value) * \
sqrt(1 - pow($ThrustPanel/YRot.value, 2) - pow($ThrustPanel/ZRot.value, 2))
func _on_YLin_value_changed(value : float) -> void:
if get_linear_vector().length() < 1.0:
return
$ThrustPanel/YLin.value = sign($ThrustPanel/YLin.value) * \
sqrt(1 - pow($ThrustPanel/XLin.value, 2) - pow($ThrustPanel/ZLin.value, 2))
func _on_YRot_value_changed(value : float) -> void:
if get_rotational_vector().length() < 1.0:
return
$ThrustPanel/YRot.value = sign($ThrustPanel/YRot.value) * \
sqrt(1 - pow($ThrustPanel/XRot.value, 2) - pow($ThrustPanel/ZRot.value, 2))
func _on_ZLin_value_changed(value : float) -> void:
if get_linear_vector().length() < 1.0:
return
$ThrustPanel/ZLin.value = sign($ThrustPanel/ZLin.value) * \
sqrt(1 - pow($ThrustPanel/YLin.value, 2) - pow($ThrustPanel/XLin.value, 2))
func _on_ZRot_value_changed(value : float) -> void:
if get_rotational_vector().length() < 1.0:
return
$ThrustPanel/ZRot.value = sign($ThrustPanel/ZRot.value) * \
sqrt(1 - pow($ThrustPanel/YRot.value, 2) - pow($ThrustPanel/XRot.value, 2))