From c232b92e2dde1277324d1f89d0e75ae641e4ac3b Mon Sep 17 00:00:00 2001 From: Anson Bridges Date: Wed, 7 Sep 2022 14:07:30 -0400 Subject: reorganized, ladders, vehicle control --- godot/ui/HUD.gd | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 godot/ui/HUD.gd (limited to 'godot/ui/HUD.gd') diff --git a/godot/ui/HUD.gd b/godot/ui/HUD.gd new file mode 100644 index 0000000..9bbcae1 --- /dev/null +++ b/godot/ui/HUD.gd @@ -0,0 +1,85 @@ +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 ui_play_hitsound(): + $AudioCues/Hitsound.play() + +func ui_play_killsound(): + $AudioCues/Killsound.play() + +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") -- cgit v1.2.3