summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/HUD.gd79
-rw-r--r--ui/HUD.tscn206
2 files changed, 285 insertions, 0 deletions
diff --git a/ui/HUD.gd b/ui/HUD.gd
new file mode 100644
index 0000000..4c5506b
--- /dev/null
+++ b/ui/HUD.gd
@@ -0,0 +1,79 @@
+extends Control
+
+
+var world
+onready var character_list = $CharacterSelect/VBoxContainer
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ world = get_tree().get_root().get_node("GAMEWORLD")
+
+func _input(_event):
+ if Input.is_action_just_pressed("menu"): #toggle mouse capture on esc
+ $ServerJoinMenu.visible = false
+ $CharacterSelect.visible = false
+ $ChatPrompt.visible = false
+ $HUDAnim.play("close_chat")
+ world.is_chatting = false
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+ if Input.is_action_just_pressed("server_menu"):
+ world.is_chatting = true
+ $CharacterSelect.visible = false
+ $ServerJoinMenu.visible = true
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ if Input.is_action_just_pressed("game_menu"):
+ update_characters()
+ world.is_chatting = true
+ $ServerJoinMenu.visible = false
+ $CharacterSelect.visible = true
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ if Input.is_action_just_pressed("chat") and !$ChatPrompt.visible:
+ world.is_chatting = true
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ $Chat.visible = true
+ $ChatPrompt.visible = true
+ $ChatPrompt.grab_focus()
+ yield(get_tree(), "idle_frame")
+ $ChatPrompt.text = ""
+
+func send_chat_msg(txt):
+ world.is_chatting = false
+ world.rpc_id(1, "_call_on_server", "_send_chat", {"id" : world.client_id, "msg" : txt})
+ $ChatPrompt.visible = false
+ $ChatPrompt.text = ""
+
+func ui_chat_msg(msg):
+ $HUDAnim.stop()
+ $Chat.visible = true
+ var textlabel = Label.new()
+ textlabel.text = msg
+ textlabel.autowrap = true
+ textlabel.set_h_size_flags(SIZE_EXPAND_FILL)
+ $Chat/ChatLines.add_child(textlabel)
+ yield(get_tree().create_timer(0.05), "timeout")
+ $Chat.ensure_control_visible(textlabel)
+ $HUDAnim.play("close_chat")
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+
+func ui_hide_chat():
+ if !$ChatPrompt.visible:
+ $Chat.visible = false
+
+func update_characters():
+ for btn in character_list.get_children():
+ btn.queue_free()
+ for character in world.get_node("PLAYERS").get_children():
+ if world.player_team == character.team:
+ var select_button = Button.new()
+ select_button.connect("pressed", world, "select_character", [character.name])
+ select_button.text = character.name + " (" + str(character.get_network_master()) + ")"
+ character_list.add_child(select_button)
+
+func _ui_disconnect():
+ get_tree().get_root().get_node("GAMEWORLD").client_disconnect()
+
+func ui_join_red():
+ world.join_team("RED")
+
+func ui_join_blue():
+ world.join_team("BLUE")
diff --git a/ui/HUD.tscn b/ui/HUD.tscn
new file mode 100644
index 0000000..35c6cb7
--- /dev/null
+++ b/ui/HUD.tscn
@@ -0,0 +1,206 @@
+[gd_scene load_steps=8 format=2]
+
+[ext_resource path="res://ui/HUD.gd" type="Script" id=1]
+[ext_resource path="res://textures/FreeMono.otf" type="DynamicFontData" id=2]
+
+[sub_resource type="DynamicFont" id=1]
+size = 42
+outline_size = 2
+outline_color = Color( 0, 0, 0, 1 )
+font_data = ExtResource( 2 )
+
+[sub_resource type="DynamicFont" id=2]
+size = 18
+outline_size = 1
+outline_color = Color( 0, 0, 0, 1 )
+font_data = ExtResource( 2 )
+
+[sub_resource type="DynamicFont" id=3]
+font_data = ExtResource( 2 )
+
+[sub_resource type="Animation" id=4]
+resource_name = "close_chat"
+length = 4.0
+tracks/0/type = "method"
+tracks/0/path = NodePath(".")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 4 ),
+"transitions": PoolRealArray( 1 ),
+"values": [ {
+"args": [ ],
+"method": "ui_hide_chat"
+} ]
+}
+
+[sub_resource type="DynamicFont" id=5]
+font_data = ExtResource( 2 )
+
+[node name="HUD" type="Control"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+script = ExtResource( 1 )
+
+[node name="Crosshair" type="Label" parent="."]
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+text = "+"
+
+[node name="ServerJoinMenu" type="Control" parent="."]
+visible = false
+anchor_left = 0.15
+anchor_top = 0.15
+anchor_right = 0.85
+anchor_bottom = 1.0
+
+[node name="ServerName" type="Label" parent="ServerJoinMenu"]
+anchor_right = 1.0
+custom_fonts/font = SubResource( 1 )
+text = "SERVER NAME"
+align = 1
+
+[node name="MOTD" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.073
+anchor_right = 0.95
+anchor_bottom = 0.266
+custom_fonts/font = SubResource( 2 )
+text = "This is where the MOTD goes."
+align = 1
+
+[node name="Team1Label" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.266
+anchor_right = 0.05
+anchor_bottom = 0.275
+margin_right = 40.0
+margin_bottom = 14.0
+custom_fonts/font = SubResource( 3 )
+text = "RED TEAM:"
+
+[node name="Team1Players" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.266
+anchor_right = 0.05
+anchor_bottom = 0.275
+margin_left = 86.56
+margin_top = 0.339996
+margin_right = 697.56
+margin_bottom = 33.75
+custom_fonts/font = SubResource( 3 )
+autowrap = true
+
+[node name="Team2Label" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.266
+anchor_right = 0.05
+anchor_bottom = 0.275
+margin_left = -0.440002
+margin_top = 74.34
+margin_right = 69.56
+margin_bottom = 88.34
+custom_fonts/font = SubResource( 3 )
+text = "BLUE TEAM:"
+
+[node name="Team2Players" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.266
+anchor_right = 0.05
+anchor_bottom = 0.275
+margin_left = 99.56
+margin_top = 74.34
+margin_right = 710.56
+margin_bottom = 105.75
+custom_fonts/font = SubResource( 3 )
+autowrap = true
+
+[node name="Spectators" type="Label" parent="ServerJoinMenu"]
+anchor_left = 0.05
+anchor_top = 0.266
+anchor_right = 0.05
+anchor_bottom = 0.275
+margin_left = 26.56
+margin_top = 193.34
+margin_right = 637.56
+margin_bottom = 224.75
+custom_fonts/font = SubResource( 3 )
+autowrap = true
+
+[node name="JoinTeam1" type="Button" parent="ServerJoinMenu"]
+margin_left = 52.4
+margin_top = 154.0
+margin_right = 87.4
+margin_bottom = 174.0
+text = "Join"
+
+[node name="JoinTeam2" type="Button" parent="ServerJoinMenu"]
+margin_left = 52.4
+margin_top = 229.0
+margin_right = 87.4
+margin_bottom = 249.0
+text = "Join"
+
+[node name="Disconnect" type="Button" parent="ServerJoinMenu"]
+margin_left = 35.0
+margin_top = 287.0
+margin_right = 149.0
+margin_bottom = 307.0
+text = "DISCONNECT"
+
+[node name="CharacterSelect" type="ScrollContainer" parent="."]
+visible = false
+margin_left = 82.0
+margin_top = 20.0
+margin_right = 298.0
+margin_bottom = 580.0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="CharacterSelect"]
+
+[node name="Chat" type="ScrollContainer" parent="."]
+anchor_left = 0.018
+anchor_top = 0.651
+anchor_right = 0.23
+anchor_bottom = 0.834
+margin_left = -0.431999
+margin_top = 0.399994
+margin_right = 5.48
+margin_bottom = 0.600006
+follow_focus = true
+scroll_horizontal_enabled = false
+
+[node name="ChatLines" type="VBoxContainer" parent="Chat"]
+margin_right = 223.0
+margin_bottom = 110.0
+size_flags_horizontal = 3
+size_flags_vertical = 3
+
+[node name="ChatPrompt" type="LineEdit" parent="."]
+visible = false
+margin_left = 12.0
+margin_top = 519.0
+margin_right = 241.0
+margin_bottom = 543.0
+
+[node name="HUDAnim" type="AnimationPlayer" parent="."]
+anims/close_chat = SubResource( 4 )
+
+[node name="Health" type="Label" parent="."]
+visible = false
+anchor_left = 0.018
+anchor_top = 0.954
+anchor_right = 0.129
+anchor_bottom = 0.972
+custom_fonts/font = SubResource( 5 )
+text = "HEALTH: "
+
+[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
+
+[connection signal="pressed" from="ServerJoinMenu/JoinTeam1" to="." method="ui_join_red"]
+[connection signal="pressed" from="ServerJoinMenu/JoinTeam2" to="." method="ui_join_blue"]
+[connection signal="pressed" from="ServerJoinMenu/Disconnect" to="." method="_ui_disconnect"]
+[connection signal="text_entered" from="ChatPrompt" to="." method="send_chat_msg"]