diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-28 15:51:23 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-08-28 15:51:23 -0400 |
commit | 5a2d1f6f2462636d8389adb46ba3ff237ffe32c7 (patch) | |
tree | 1d42273b7010150e2702b1347f58c6af5ad506c3 /client | |
parent | 6fd6d493cd16b41bf88742ff6f4b7635ec3fa67c (diff) | |
download | lingo2-archipelago-5a2d1f6f2462636d8389adb46ba3ff237ffe32c7.tar.gz lingo2-archipelago-5a2d1f6f2462636d8389adb46ba3ff237ffe32c7.tar.bz2 lingo2-archipelago-5a2d1f6f2462636d8389adb46ba3ff237ffe32c7.zip |
[Client] Added messages overlay
Diffstat (limited to 'client')
-rw-r--r-- | client/Archipelago/client.gd | 4 | ||||
-rw-r--r-- | client/Archipelago/manager.gd | 102 | ||||
-rw-r--r-- | client/Archipelago/messages.gd | 61 | ||||
-rw-r--r-- | client/Archipelago/settings_screen.gd | 5 |
4 files changed, 166 insertions, 6 deletions
diff --git a/client/Archipelago/client.gd b/client/Archipelago/client.gd index 5c4bc51..d394b6c 100644 --- a/client/Archipelago/client.gd +++ b/client/Archipelago/client.gd | |||
@@ -310,11 +310,11 @@ func processDatapackages(): | |||
310 | 310 | ||
311 | _item_id_to_name[game] = {} | 311 | _item_id_to_name[game] = {} |
312 | for item_name in package["item_name_to_id"].keys(): | 312 | for item_name in package["item_name_to_id"].keys(): |
313 | _item_id_to_name[game][package["item_name_to_id"][item_name]] = item_name | 313 | _item_id_to_name[game][int(package["item_name_to_id"][item_name])] = item_name |
314 | 314 | ||
315 | _location_id_to_name[game] = {} | 315 | _location_id_to_name[game] = {} |
316 | for location_name in package["location_name_to_id"].keys(): | 316 | for location_name in package["location_name_to_id"].keys(): |
317 | _location_id_to_name[game][package["location_name_to_id"][location_name]] = location_name | 317 | _location_id_to_name[game][int(package["location_name_to_id"][location_name])] = location_name |
318 | 318 | ||
319 | if _datapackages.has("Lingo 2"): | 319 | if _datapackages.has("Lingo 2"): |
320 | _item_name_to_id = _datapackages["Lingo 2"]["item_name_to_id"] | 320 | _item_name_to_id = _datapackages["Lingo 2"]["item_name_to_id"] |
diff --git a/client/Archipelago/manager.gd b/client/Archipelago/manager.gd index 35fc8e3..99cb47b 100644 --- a/client/Archipelago/manager.gd +++ b/client/Archipelago/manager.gd | |||
@@ -13,6 +13,9 @@ var connection_history = [] | |||
13 | 13 | ||
14 | var client | 14 | var client |
15 | 15 | ||
16 | var _received_indexes = [] | ||
17 | var _last_new_item = -1 | ||
18 | |||
16 | signal could_not_connect | 19 | signal could_not_connect |
17 | signal connect_status | 20 | signal connect_status |
18 | signal ap_connected | 21 | signal ap_connected |
@@ -35,6 +38,9 @@ func saveSettings(): | |||
35 | 38 | ||
36 | 39 | ||
37 | func connectToServer(): | 40 | func connectToServer(): |
41 | _received_indexes = [] | ||
42 | _last_new_item = -1 | ||
43 | |||
38 | client.connectToServer(ap_server, ap_user, ap_pass) | 44 | client.connectToServer(ap_server, ap_user, ap_pass) |
39 | 45 | ||
40 | 46 | ||
@@ -62,9 +68,20 @@ func has_item(item_id): | |||
62 | return client.hasItem(item_id) | 68 | return client.hasItem(item_id) |
63 | 69 | ||
64 | 70 | ||
65 | func _process_item(item_id, _index, _player, _flags): | 71 | func _process_item(item, index, from, flags): |
72 | if index != null: | ||
73 | if _received_indexes.has(index): | ||
74 | # Do not re-process items. | ||
75 | return | ||
76 | |||
77 | _received_indexes.append(index) | ||
78 | |||
79 | var item_name = "Unknown" | ||
80 | if client._item_id_to_name["Lingo 2"].has(item): | ||
81 | item_name = client._item_id_to_name["Lingo 2"][item] | ||
82 | |||
66 | var gamedata = global.get_node("Gamedata") | 83 | var gamedata = global.get_node("Gamedata") |
67 | var door_id = gamedata.door_id_by_ap_id.get(item_id, null) | 84 | var door_id = gamedata.door_id_by_ap_id.get(item, null) |
68 | if door_id != null and gamedata.get_door_map_name(door_id) == global.map: | 85 | if door_id != null and gamedata.get_door_map_name(door_id) == global.map: |
69 | var receivers = gamedata.get_door_receivers(door_id) | 86 | var receivers = gamedata.get_door_receivers(door_id) |
70 | var scene = get_tree().get_root().get_node_or_null("scene") | 87 | var scene = get_tree().get_root().get_node_or_null("scene") |
@@ -79,9 +96,71 @@ func _process_item(item_id, _index, _player, _flags): | |||
79 | if pnode != null: | 96 | if pnode != null: |
80 | pnode.handleTriggered() | 97 | pnode.handleTriggered() |
81 | 98 | ||
99 | # Show a message about the item if it's new. | ||
100 | if index != null and index > _last_new_item: | ||
101 | _last_new_item = index | ||
102 | #saveLocaldata() | ||
82 | 103 | ||
83 | func _process_message(_message): | 104 | var player_name = "Unknown" |
84 | pass | 105 | if client._player_name_by_slot.has(from): |
106 | player_name = client._player_name_by_slot[from] | ||
107 | |||
108 | var item_color = colorForItemType(flags) | ||
109 | |||
110 | var message | ||
111 | if from == client._slot: | ||
112 | message = "Found [color=%s]%s[/color]" % [item_color, item_name] | ||
113 | else: | ||
114 | message = "Received [color=%s]%s[/color] from %s" % [item_color, item_name, player_name] | ||
115 | |||
116 | global._print(message) | ||
117 | |||
118 | global.get_node("Messages").showMessage(message) | ||
119 | |||
120 | |||
121 | func _process_message(message): | ||
122 | if ( | ||
123 | !message.has("receiving") | ||
124 | or !message.has("item") | ||
125 | or message["item"]["player"] != client._slot | ||
126 | ): | ||
127 | return | ||
128 | |||
129 | var item_name = "Unknown" | ||
130 | var item_player_game = client._game_by_player[message["receiving"]] | ||
131 | if client._item_id_to_name[item_player_game].has(message["item"]["item"]): | ||
132 | item_name = client._item_id_to_name[item_player_game][message["item"]["item"]] | ||
133 | |||
134 | var location_name = "Unknown" | ||
135 | var location_player_game = client._game_by_player[message["item"]["player"]] | ||
136 | if client._location_id_to_name[location_player_game].has(message["item"]["location"]): | ||
137 | location_name = ( | ||
138 | client._location_id_to_name[location_player_game][message["item"]["location"]] | ||
139 | ) | ||
140 | |||
141 | var player_name = "Unknown" | ||
142 | if client._player_name_by_slot.has(message["receiving"]): | ||
143 | player_name = client._player_name_by_slot[message["receiving"]] | ||
144 | |||
145 | var item_color = colorForItemType(message["item"]["flags"]) | ||
146 | |||
147 | if message["type"] == "Hint": | ||
148 | var is_for = "" | ||
149 | if message["receiving"] != client._slot: | ||
150 | is_for = " for %s" % player_name | ||
151 | if !message.has("found") || !message["found"]: | ||
152 | global.get_node("Messages").showMessage( | ||
153 | ( | ||
154 | "Hint: [color=%s]%s[/color]%s is on %s" | ||
155 | % [item_color, item_name, is_for, location_name] | ||
156 | ) | ||
157 | ) | ||
158 | else: | ||
159 | if message["receiving"] != client._slot: | ||
160 | var sentMsg = "Sent [color=%s]%s[/color] to %s" % [item_color, item_name, player_name] | ||
161 | #if _hinted_locations.has(message["item"]["location"]): | ||
162 | # sentMsg += " ([color=#fafad2]Hinted![/color])" | ||
163 | global.get_node("Messages").showMessage(sentMsg) | ||
85 | 164 | ||
86 | 165 | ||
87 | func _client_could_not_connect(): | 166 | func _client_could_not_connect(): |
@@ -98,3 +177,18 @@ func _client_connected(): | |||
98 | 177 | ||
99 | func send_location(loc_id): | 178 | func send_location(loc_id): |
100 | client.sendLocation(loc_id) | 179 | client.sendLocation(loc_id) |
180 | |||
181 | |||
182 | func colorForItemType(flags): | ||
183 | var int_flags = int(flags) | ||
184 | if int_flags & 1: # progression | ||
185 | if int_flags & 2: # proguseful | ||
186 | return "#f0d200" | ||
187 | else: | ||
188 | return "#bc51e0" | ||
189 | elif int_flags & 2: # useful | ||
190 | return "#2b67ff" | ||
191 | elif int_flags & 4: # trap | ||
192 | return "#d63a22" | ||
193 | else: # filler | ||
194 | return "#14de9e" | ||
diff --git a/client/Archipelago/messages.gd b/client/Archipelago/messages.gd new file mode 100644 index 0000000..52f38b9 --- /dev/null +++ b/client/Archipelago/messages.gd | |||
@@ -0,0 +1,61 @@ | |||
1 | extends CanvasLayer | ||
2 | |||
3 | var _message_queue = [] | ||
4 | var _font | ||
5 | var _container | ||
6 | var _ordered_labels = [] | ||
7 | |||
8 | |||
9 | func _ready(): | ||
10 | _container = VBoxContainer.new() | ||
11 | _container.set_name("Container") | ||
12 | _container.anchor_bottom = 1 | ||
13 | _container.offset_left = 20.0 | ||
14 | _container.offset_right = 1920.0 | ||
15 | _container.offset_top = 0.0 | ||
16 | _container.offset_bottom = -20.0 | ||
17 | _container.alignment = BoxContainer.ALIGNMENT_END | ||
18 | _container.mouse_filter = Control.MOUSE_FILTER_IGNORE | ||
19 | self.add_child(_container) | ||
20 | |||
21 | _font = load("res://assets/fonts/Lingo2.ttf") | ||
22 | |||
23 | |||
24 | func _add_message(text): | ||
25 | var new_label = RichTextLabel.new() | ||
26 | new_label.push_font(_font) | ||
27 | new_label.push_font_size(36) | ||
28 | new_label.push_outline_color(Color(0, 0, 0, 1)) | ||
29 | new_label.push_outline_size(2) | ||
30 | new_label.append_text(text) | ||
31 | new_label.fit_content = true | ||
32 | |||
33 | _container.add_child(new_label) | ||
34 | _ordered_labels.push_back(new_label) | ||
35 | |||
36 | |||
37 | func showMessage(text): | ||
38 | if _ordered_labels.size() >= 9: | ||
39 | _message_queue.append(text) | ||
40 | return | ||
41 | |||
42 | _add_message(text) | ||
43 | |||
44 | if _ordered_labels.size() > 1: | ||
45 | return | ||
46 | |||
47 | var timeout = 10.0 | ||
48 | while !_ordered_labels.is_empty(): | ||
49 | await get_tree().create_timer(timeout).timeout | ||
50 | |||
51 | var to_remove = _ordered_labels.pop_front() | ||
52 | var to_tween = get_tree().create_tween().bind_node(to_remove) | ||
53 | to_tween.tween_property(to_remove, "modulate:a", 0.0, 0.5) | ||
54 | to_tween.tween_callback(to_remove.queue_free) | ||
55 | |||
56 | if !_message_queue.is_empty(): | ||
57 | var next_msg = _message_queue.pop_front() | ||
58 | _add_message(next_msg) | ||
59 | |||
60 | if timeout > 4: | ||
61 | timeout -= 3 | ||
diff --git a/client/Archipelago/settings_screen.gd b/client/Archipelago/settings_screen.gd index 90d5437..a675f8e 100644 --- a/client/Archipelago/settings_screen.gd +++ b/client/Archipelago/settings_screen.gd | |||
@@ -49,6 +49,11 @@ func _ready(): | |||
49 | gamedata_instance.name = "Gamedata" | 49 | gamedata_instance.name = "Gamedata" |
50 | global.add_child(gamedata_instance) | 50 | global.add_child(gamedata_instance) |
51 | 51 | ||
52 | var messages_script = load("user://maps/Archipelago/messages.gd") | ||
53 | var messages_instance = messages_script.new() | ||
54 | messages_instance.name = "Messages" | ||
55 | global.add_child(messages_instance) | ||
56 | |||
52 | var ap = global.get_node("Archipelago") | 57 | var ap = global.get_node("Archipelago") |
53 | ap.connect("ap_connected", connectionSuccessful) | 58 | ap.connect("ap_connected", connectionSuccessful) |
54 | ap.connect("could_not_connect", connectionUnsuccessful) | 59 | ap.connect("could_not_connect", connectionUnsuccessful) |