about summary refs log tree commit diff stats
path: root/client/Archipelago/textclient.gd
blob: 85cc6d2a271fa91f3459a0ac5d8084c32dc631e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Ty
extends CanvasLayer

var panel
var label
var entry
var is_open = false


func _ready():
	process_mode = ProcessMode.PROCESS_MODE_ALWAYS

	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")
	ap.client.say(cmd)
	entry.text = ""