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/client.gd | 44 +++++++++++++++++++++ Archipelago/load.gd | 6 +++ Archipelago/pause_menu.gd | 5 +++ Archipelago/settings_screen.gd | 1 + Archipelago/textclient.gd | 88 ++++++++++++++++++++++++++++++++++++++++++ README.md | 3 ++ 6 files changed, 147 insertions(+) create mode 100644 Archipelago/textclient.gd diff --git a/Archipelago/client.gd b/Archipelago/client.gd index aa50069..f58b3d6 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -8,6 +8,7 @@ var SCRIPT_mypainting var SCRIPT_notifier var SCRIPT_panel var SCRIPT_pilgrimage_terminator +var SCRIPT_textclient var SCRIPT_uuid var ap_server = "" @@ -451,6 +452,8 @@ func _on_data(): i += 1 elif cmd == "PrintJSON": + parse_printjson(message) + if ( !message.has("receiving") or !message.has("item") @@ -684,6 +687,10 @@ func setValue(key, value, operation = "replace"): ) +func say(textdata): + sendMessage([{"cmd": "Say", "text": textdata}]) + + func completedGoal(): sendMessage([{"cmd": "StatusUpdate", "status": 30}]) # CLIENT_GOAL @@ -855,6 +862,43 @@ func colorForItemType(flags): return "#14de9e" +func parse_printjson(message): + var parts = [] + for message_part in message["data"]: + if !message_part.has("type") and message_part.has("text"): + parts.append(message_part["text"]) + elif message_part["type"] == "player_id": + if int(message_part["text"]) == _slot: + parts.append("[color=#ee00ee]%s[/color]" % _player_name_by_slot[_slot]) + else: + var from = float(message_part["text"]) + parts.append("[color=#fafad2]%s[/color]" % _player_name_by_slot[from]) + elif message_part["type"] == "item_id": + var item_name = "Unknown" + var item_player_game = _game_by_player[message_part["player"]] + if _item_id_to_name[item_player_game].has(float(message_part["text"])): + item_name = _item_id_to_name[item_player_game][float(message_part["text"])] + + parts.append( + "[color=%s]%s[/color]" % [colorForItemType(message_part["flags"]), item_name] + ) + elif message_part["type"] == "location_id": + var location_name = "Unknown" + var location_player_game = _game_by_player[message_part["player"]] + if _location_id_to_name[location_player_game].has(float(message_part["text"])): + location_name = _location_id_to_name[location_player_game][float( + message_part["text"] + )] + + parts.append("[color=#00ff7f]%s[/color]" % location_name) + elif message_part.has("text"): + parts.append(message_part["text"]) + + var textclient_node = get_tree().get_root().get_node_or_null("Spatial/AP_TextClient") + if textclient_node != null: + textclient_node.parse_printjson("".join(parts)) + + func compareVersion(lhs, rhs): if lhs["major"] == rhs["major"]: if lhs["minor"] == rhs["minor"]: diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 931dfde..c35525b 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -663,6 +663,12 @@ func _load(): effects.set_name("AP_Effects") self.add_child(effects) + # Create the textclient node. + var textclient_script = apclient.SCRIPT_textclient + var textclient = textclient_script.new() + textclient.set_name("AP_TextClient") + self.add_child(textclient) + # Create the multiplayer node, if needed. if apclient.enable_multiplayer: var multiplayer_node = apclient.SCRIPT_multiplayer.new() diff --git a/Archipelago/pause_menu.gd b/Archipelago/pause_menu.gd index 40994d9..62ba6c3 100644 --- a/Archipelago/pause_menu.gd +++ b/Archipelago/pause_menu.gd @@ -6,3 +6,8 @@ func _main_menu(): apclient.disconnect_from_ap() ._main_menu() + + +func _pause_game(): + get_tree().get_root().get_node("Spatial/AP_TextClient").dismiss() + ._pause_game() diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 6c64b15..2ed8594 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd @@ -32,6 +32,7 @@ func _ready(): apclient_instance.SCRIPT_panel = load("user://maps/Archipelago/panel.gd") var pilg_term = load("user://maps/Archipelago/pilgrimage_terminator.gd") apclient_instance.SCRIPT_pilgrimage_terminator = pilg_term + apclient_instance.SCRIPT_textclient = load("user://maps/Archipelago/textclient.gd") apclient_instance.SCRIPT_uuid = load("user://maps/Archipelago/vendor/uuid.gd") var apdata = ResourceLoader.load("user://maps/Archipelago/gamedata.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 = "" diff --git a/README.md b/README.md index a242f95..a8491d6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ pick and choose which ones you would like to use. the numbering can change. You can also specify whether access to the sunwarps should be locked behind receiving certain items. +There is also a built-in text client you can use to talk to other players and +issue commands. You can open and close it by pressing tab. + ## Frequently Asked Questions ### What are location checks in this game? -- cgit 1.4.1