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 From e92ae750012d37733ef803e882eb8191ad530e11 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 20 Sep 2024 21:29:42 -0400 Subject: Added proximity chat --- Archipelago/client.gd | 4 ++++ Archipelago/load.gd | 1 + Archipelago/multiplayer.gd | 55 ++++++++++++++++++++++++++++++++++++++++++++++ Archipelago/textclient.gd | 13 ++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) (limited to 'Archipelago/textclient.gd') diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 6621194..a636bec 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -912,6 +912,10 @@ func parse_printjson(message): textclient_node.parse_printjson("".join(parts)) +func get_player_name(): + return _player_name_by_slot[_slot] + + 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 c35525b..09aaee2 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -672,6 +672,7 @@ func _load(): # Create the multiplayer node, if needed. if apclient.enable_multiplayer: var multiplayer_node = apclient.SCRIPT_multiplayer.new() + multiplayer_node.name = "Multiplayer" multiplayer_node.ghost_mode = true add_child(multiplayer_node) diff --git a/Archipelago/multiplayer.gd b/Archipelago/multiplayer.gd index 0bc2241..c2d9875 100644 --- a/Archipelago/multiplayer.gd +++ b/Archipelago/multiplayer.gd @@ -1,5 +1,8 @@ extends "res://scripts/multiplayer.gd" +var queued_messages = [] +var queued_messages_mutex = Mutex.new() + func _request_lobby_list(): var apclient = global.get_node("Archipelago") @@ -41,3 +44,55 @@ func _update_lobby_members(): if member_id != player_steam_id and member_id in active_lobby_members: var slot_name = Steam.getLobbyMemberData(active_lobby_id, member_id, "slot_name") active_lobby_members[member_id].steam_name = slot_name + + +func say(text): + queued_messages_mutex.lock() + queued_messages.append(text) + queued_messages_mutex.unlock() + + +func _physics_process(_delta): + if queued_messages_mutex.try_lock() == OK: + if queued_messages.empty(): + queued_messages_mutex.unlock() + else: + var messages = queued_messages.duplicate() + queued_messages = [] + queued_messages_mutex.unlock() + + var player = get_tree().get_root().get_node("Spatial/player") + var space_state = get_tree().get_root().get_world().direct_space_state + var nearby_members = [] + for member_id in active_lobby_members.keys(): + var other_member = active_lobby_members[member_id] + var ray = space_state.intersect_ray( + player.global_translation, other_member.global_translation, [player], 0b0101 + ) + if !("collider" in ray) or ray["collider"] == other_member: + # Visible! + nearby_members.append(member_id) + + var apclient = global.get_node("Archipelago") + var player_name = apclient.get_player_name() + for member_id in nearby_members: + for msg in messages: + _send_p2p_packet( + {"solves": [{"say": msg, "from": player_name}]}, + member_id, + Steam.P2P_SEND_RELIABLE, + true + ) + + +# I'm completely hijacking this callback, since we're in ghost mode and it won't be called normally. +func _receive_solve(data): + if "say" in data: + get_tree().get_root().get_node("Spatial/AP_TextClient").parse_printjson( + "[LOCAL] [color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]] + ) + messages.showMessage("[color=#fafad2]%s[/color]: %s" % [data["from"], data["say"]]) + + +func _send_hi(_discard): + pass diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd index 7bddf38..f100776 100644 --- a/Archipelago/textclient.gd +++ b/Archipelago/textclient.gd @@ -84,5 +84,16 @@ func parse_printjson(text): func text_entered(text): var apclient = global.get_node("Archipelago") - apclient.say(text.trim_suffix("\n")) + var cmd = text.trim_suffix("\n") + if cmd.begins_with("/say "): + if apclient.enable_multiplayer: + var msg = cmd.trim_prefix("/say ") + parse_printjson( + "[LOCAL] [color=#ee00ee]%s[/color]: %s" % [apclient.get_player_name(), msg] + ) + get_tree().get_root().get_node("Spatial/Multiplayer").say(msg) + else: + parse_printjson("Multiplayer must be enabled to use /say") + else: + apclient.say(cmd) entry.text = "" -- cgit 1.4.1 From 439588d5e04eb296f5a3be609127579bf616c27a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Sep 2024 07:47:50 -0400 Subject: Prevent text client from opening if SHIFT is held --- Archipelago/textclient.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Archipelago/textclient.gd') diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd index f100776..003ef8d 100644 --- a/Archipelago/textclient.gd +++ b/Archipelago/textclient.gd @@ -51,7 +51,7 @@ func _ready(): func _input(event): if event is InputEventKey and event.pressed: - if event.scancode == KEY_TAB: + if event.scancode == KEY_TAB and !Input.is_key_pressed(KEY_SHIFT): if !get_tree().paused: is_open = true get_tree().paused = true -- cgit 1.4.1 From 5d4df9284173c457dfa70da67f3274a4069abc92 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 27 Oct 2024 13:36:16 -0400 Subject: Made text client selectable --- Archipelago/textclient.gd | 1 + 1 file changed, 1 insertion(+) (limited to 'Archipelago/textclient.gd') diff --git a/Archipelago/textclient.gd b/Archipelago/textclient.gd index 003ef8d..3abd9e0 100644 --- a/Archipelago/textclient.gd +++ b/Archipelago/textclient.gd @@ -25,6 +25,7 @@ func _ready(): label.margin_top = 80 label.margin_bottom = 720 label.scroll_following = true + label.selection_enabled = true panel.add_child(label) var dynamic_font = DynamicFont.new() -- cgit 1.4.1