From 400ad1ed74166d3f01adf6d97f07a16ec391f2a9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 2 Sep 2024 11:49:12 -0400 Subject: Added text client --- Archipelago/textclient.gd | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Archipelago/textclient.gd (limited to 'Archipelago/textclient.gd') diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd new file mode 100644 index 0000000..7bddf38 --- /dev/null +++ b/Archipelago/textclient.gd @@ -0,0 +1,88 @@ +extends Node + +var panel +var label +var entry +var is_open = false + + +func _ready(): + pause_mode = PAUSE_MODE_PROCESS + + panel = Panel.new() + panel.set_name("Panel") + panel.margin_left = 100 + panel.margin_right = 1820 + panel.margin_top = 100 + panel.margin_bottom = 980 + panel.visible = false + add_child(panel) + + label = RichTextLabel.new() + label.set_name("Label") + label.margin_left = 80 + label.margin_right = 1640 + label.margin_top = 80 + label.margin_bottom = 720 + label.scroll_following = true + panel.add_child(label) + + var dynamic_font = DynamicFont.new() + dynamic_font.font_data = load("res://fonts/Lingo.ttf") + dynamic_font.size = 36 + label.push_font(dynamic_font) + + 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.margin_left = 80 + entry.margin_right = 1640 + entry.margin_top = 760 + entry.margin_bottom = 840 + entry.add_font_override("font", dynamic_font) + entry.add_color_override("font_color", Color(0, 0, 0, 1)) + entry.add_color_override("cursor_color", Color(0, 0, 0, 1)) + entry.add_stylebox_override("focus", entry_style) + panel.add_child(entry) + entry.connect("text_entered", self, "text_entered") + + +func _input(event): + if event is InputEventKey and event.pressed: + if event.scancode == KEY_TAB: + 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_tree().set_input_as_handled() + else: + dismiss() + elif event.scancode == KEY_ESCAPE: + if is_open: + dismiss() + get_tree().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): + if !label.text.empty(): + label.append_bbcode("\n") + + label.append_bbcode(text) + + +func text_entered(text): + var apclient = global.get_node("Archipelago") + apclient.say(text.trim_suffix("\n")) + entry.text = "" -- cgit 1.4.1