1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
extends Control
var world
onready var character_list = $CharacterSelect/VBoxContainer
onready var progress_bar: ProgressBar = $UseProgress
# 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: String):
world.is_chatting = false
$ChatPrompt.visible = false
$ChatPrompt.text = ""
if !txt.begins_with("/"):
world.rpc_id(1, "_call_on_server", "_send_chat", {"id" : world.client_id, "msg" : txt})
return
#command process
var end_ind = txt.find(" ")-1
if end_ind < -1: end_ind = -1
var cmd: String = txt.get_slice(" ", 0).substr(1).to_lower()
var args = txt.substr(end_ind+1, -1).split(" ", false)
match cmd:
"goto":
var pos: Vector3 = str2var("Vector3("+txt.get_slice(" ", 1)+")")
if world.player_char:
world.player_char.ai_set_path_target(pos)
"find":
var item: String = txt.get_slice(" ", 1)
if world.player_char:
CharacterAIManager.request_find_object(world.player_char, item, 50, true)
"setaistate":
world.rpc_id(1,"_call_on_server", "_set_ai_state", [args[0], args[1]])
for i in range(2,13):
world.rpc_id(1,"_call_on_server", "_set_ai_state", [args[0]+str(i), args[1]])
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, "request_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_team(team_i):
world.join_team(team_i)
func ui_join_blue():
world.join_team("BLUE")
func set_progress(delta: float)-> void:
progress_bar.visible = true
progress_bar.set_value(delta)
func hide_progress() -> void:
progress_bar.set_value(0)
progress_bar.visible = false
|