Ver Fonte

Display default controls on start screen

DricomDragon há 3 anos atrás
pai
commit
200f960bf4
5 ficheiros alterados com 60 adições e 5 exclusões
  1. 27 2
      godot/Scenes/Game.tscn
  2. 0 1
      godot/Scenes/Hub.tscn
  3. 2 2
      godot/Scenes/Player.tscn
  4. 23 0
      godot/Scripts/Hub.gd
  5. 8 0
      godot/Scripts/UI.gd

+ 27 - 2
godot/Scenes/Game.tscn

@@ -1,9 +1,10 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=6 format=2]
 
 [ext_resource path="res://Scripts/MainCamera.gd" type="Script" id=1]
 [ext_resource path="res://Scripts/LevelSwap.gd" type="Script" id=2]
 [ext_resource path="res://Scripts/Game.gd" type="Script" id=3]
 [ext_resource path="res://Scenes/Hub.tscn" type="PackedScene" id=4]
+[ext_resource path="res://Scripts/UI.gd" type="Script" id=5]
 
 [node name="Game" type="Node2D"]
 script = ExtResource( 3 )
@@ -21,6 +22,7 @@ one_shot = true
 [node name="Ui" type="Control" parent="."]
 margin_right = 40.0
 margin_bottom = 40.0
+script = ExtResource( 5 )
 __meta__ = {
 "_edit_use_anchors_": false
 }
@@ -36,9 +38,32 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
+[node name="PressButton" type="Label" parent="Ui"]
+margin_left = -502.476
+margin_top = -260.0
+margin_right = 497.524
+margin_bottom = -246.0
+text = "Click on left button to spawn player"
+align = 1
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="InputList" type="Label" parent="Ui"]
+margin_left = -502.476
+margin_top = -238.0
+margin_right = 497.524
+margin_bottom = -224.0
+text = "List of player controls"
+align = 1
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
 [node name="Hub" parent="." instance=ExtResource( 4 )]
 
 [node name="LevelSwap" type="Tween" parent="."]
 script = ExtResource( 2 )
-[connection signal="timeout" from="StartTimer" to="." method="_on_start_game"]
 [connection signal="timeout" from="StartTimer" to="Ui" method="hide"]
+[connection signal="timeout" from="StartTimer" to="." method="_on_start_game"]
+[connection signal="input_list_updated" from="Hub" to="Ui" method="_on_Hub_input_list_updated"]

+ 0 - 1
godot/Scenes/Hub.tscn

@@ -2,7 +2,6 @@
 
 [ext_resource path="res://Scripts/Hub.gd" type="Script" id=1]
 
-
 [node name="Hub" type="Node2D"]
 script = ExtResource( 1 )
 __meta__ = {

+ 2 - 2
godot/Scenes/Player.tscn

@@ -36,8 +36,8 @@ __meta__ = {
 
 [node name="Tween" type="Tween" parent="."]
 script = ExtResource( 2 )
-[connection signal="arena_removed" from="." to="Crash" method="hide"]
 [connection signal="arena_removed" from="." to="Liner" method="show"]
+[connection signal="arena_removed" from="." to="Crash" method="hide"]
 [connection signal="body_entered" from="." to="." method="_on_crash"]
-[connection signal="crash" from="." to="Crash" method="show"]
 [connection signal="crash" from="." to="Liner" method="hide"]
+[connection signal="crash" from="." to="Crash" method="show"]

+ 23 - 0
godot/Scripts/Hub.gd

@@ -3,11 +3,13 @@ extends Node2D
 # User interface to create liners
 
 signal hub_finished
+signal input_list_updated
 
 const ACTION_PLAYER_PREFIX = "p"
 const ACTION_LEFT_SUFFIX = "_left"
 const ACTION_RIGHT_SUFFIX = "_right"
 const MAX_PLAYERS = 8
+const TXT_FORMAT_INPUT_LINE = "Player %d > left : %s | right : %s"
 
 export (Array, Color) var playerColors = [
 	Color.red,
@@ -26,9 +28,12 @@ var _playerActionsRight
 
 var _hub_enabled = true
 
+var _input_list_text = "";
+
 
 func _ready():
 	_fill_action_arrays()
+	_update_input_list_text()
 
 
 func _unhandled_input(event):
@@ -63,3 +68,21 @@ func _fill_action_arrays():
 	for k in MAX_PLAYERS:
 		_playerActionsLeft.append(ACTION_PLAYER_PREFIX + str(k) + ACTION_LEFT_SUFFIX)
 		_playerActionsRight.append(ACTION_PLAYER_PREFIX + str(k) + ACTION_RIGHT_SUFFIX)
+
+
+func _update_input_list_text():
+	var input_text_array = PoolStringArray()
+	for k in _playerActionsLeft.size():
+		var values = [k]
+		values.append(_get_label_from_action_name(_playerActionsLeft[k]))
+		values.append(_get_label_from_action_name(_playerActionsRight[k]))
+		input_text_array.append(TXT_FORMAT_INPUT_LINE % values)
+	_input_list_text = input_text_array.join("\n")
+	emit_signal("input_list_updated", _input_list_text)
+
+
+func _get_label_from_action_name(action:String):
+	var default_event = InputMap.get_action_list(action)[0]
+	if default_event is InputEventMouseButton:
+		return "Mouse button %s" % default_event.button_index
+	return default_event.as_text()

+ 8 - 0
godot/Scripts/UI.gd

@@ -0,0 +1,8 @@
+extends Control
+
+
+onready var inputListLabel = $InputList
+
+
+func _on_Hub_input_list_updated(input_list_text):
+	inputListLabel.set_text(input_list_text)