about summary refs log tree commit diff stats
path: root/apworld/client/textclient.gd
blob: 26831b40ed36069510ea7d4c8747efdd987a1517 (plain) (blame)
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
extends CanvasLayer

var panel
var label
var entry
var is_open = false


func _ready():
	process_mode = ProcessMode.PROCESS_MODE_ALWAYS
	layer = 2

	panel = Panel.new()
	panel.set_name("Panel")
	panel.offset_left = 100
	panel.offset_right = 1820
	panel.offset_top = 100
	panel.offset_bottom = 980
	panel.visible = false
	add_child(panel)

	label = RichTextLabel.new()
	label.set_name("Label")
	label.offset_left = 80
	label.offset_right = 1640
	label.offset_top = 80
	label.offset_bottom = 720
	label.scroll_following = true
	label.selection_enabled = true
	panel.add_child(label)

	label.push_font(load("res://assets/fonts/Lingo2.ttf"))
	label.push_font_size(36)

	var entry_style = StyleBoxFlat.new()
	entry_style.bg_color = Color(0.9, 0.9, 0.9, 1)

	entry = LineEdit.new()
	entry.set_name("Entry")
	entry.offset_left = 80
	entry.offset_right = 1640
	entry.offset_top = 760
	entry.offset_bottom = 840
	entry.add_theme_font_override("font", load("res://assets/fonts/Lingo2.ttf"))
	entry.add_theme_font_size_override("font_size", 36)
	entry.add_theme_color_override("font_color", Color(0, 0, 0, 1))
	entry.add_theme_color_override("cursor_color", Color(0, 0, 0, 1))
	entry.add_theme_stylebox_override("focus", entry_style)
	panel.add_child(entry)
	entry.connect("text_submitted", text_entered)


func _input(event):
	if global.loaded and event is InputEventKey and event.pressed:
		if event.keycode == KEY_TAB and !Input.is_key_pressed(KEY_SHIFT):
			if !get_tree().paused:
				is_open = true
				get_tree().paused = true
				Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
				panel.visible = true
				entry.grab_focus()
				get_viewport().set_input_as_handled()
			else:
				dismiss()
		elif event.keycode == KEY_ESCAPE:
			if is_open:
				dismiss()
				get_viewport().set_input_as_handled()


func dismiss():
	if is_open:
		get_tree().paused = false
		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
		panel.visible = false
		is_open = false


func parse_printjson(text):
	label.append_text("[p]" + text + "[/p]")


func text_entered(text):
	var ap = global.get_node("Archipelago")
	var cmd = text.trim_suffix("\n")
	entry.text = ""
	if OS.is_debug_build():
		if cmd.begins_with("/tp_map "):
			var new_map = cmd.substr(8)
			global.map = new_map
			global.sets_entry_point = false
			switcher.switch_map("res://objects/scenes/%s.tscn" % new_map)
			return

	ap.client.say(cmd)
ass="w"> 704.0 credit4.offset_right = 485.0 credit4.offset_bottom = 768.0 credit4.add_theme_stylebox_override("normal", simple_style_box) credit4.text = "PASSWORD" credit4.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT credit4.theme = theme panel.add_child(credit4) var credit5 = Label.new() credit5.name = "credit5" credit5.offset_left = 1239.0 credit5.offset_top = 422.0 credit5.offset_right = 1829.0 credit5.offset_bottom = 486.0 credit5.add_theme_stylebox_override("normal", simple_style_box) credit5.text = "OPTIONS" credit5.theme = theme panel.add_child(credit5) var server_box = LineEdit.new() server_box.name = "server_box" server_box.offset_left = 502.0 server_box.offset_top = 295.0 server_box.offset_right = 1144.0 server_box.offset_bottom = 445.0 server_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER server_box.caret_blink = true panel.add_child(server_box) var player_box = LineEdit.new() player_box.name = "player_box" player_box.offset_left = 502.0 player_box.offset_top = 477.0 player_box.offset_right = 1144.0 player_box.offset_bottom = 627.0 player_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER player_box.caret_blink = true panel.add_child(player_box) var password_box = LineEdit.new() password_box.name = "password_box" password_box.offset_left = 502.0 password_box.offset_top = 659.0 password_box.offset_right = 1144.0 password_box.offset_bottom = 809.0 password_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER password_box.caret_blink = true panel.add_child(password_box) var accept_dialog = AcceptDialog.new() accept_dialog.name = "AcceptDialog" accept_dialog.offset_right = 83.0 accept_dialog.offset_bottom = 58.0 panel.add_child(accept_dialog) var version_mismatch = ConfirmationDialog.new() version_mismatch.name = "VersionMismatch" version_mismatch.offset_right = 83.0 version_mismatch.offset_bottom = 58.0 panel.add_child(version_mismatch) var connection_history = MenuButton.new() connection_history.name = "connection_history" connection_history.offset_left = 1239.0 connection_history.offset_top = 276.0 connection_history.offset_right = 1829.0 connection_history.offset_bottom = 372.0 connection_history.text = "connection history" connection_history.flat = false panel.add_child(connection_history) var runtime = global.get_node("Runtime") var main_script = runtime.load_script("main.gd") var main_node = main_script.new() main_node.name = "Main" add_child(main_node)